2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
27 struct genl_info
*info
);
28 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
29 struct genl_info
*info
);
31 /* the netlink family */
32 static struct genl_family nl80211_fam
= {
33 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
34 .name
= "nl80211", /* have users key off the name instead */
35 .hdrsize
= 0, /* no private header */
36 .version
= 1, /* no particular meaning now */
37 .maxattr
= NL80211_ATTR_MAX
,
39 .pre_doit
= nl80211_pre_doit
,
40 .post_doit
= nl80211_post_doit
,
43 /* internal helper: get rdev and dev */
44 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
45 struct cfg80211_registered_device
**rdev
,
46 struct net_device
**dev
)
48 struct nlattr
**attrs
= info
->attrs
;
51 if (!attrs
[NL80211_ATTR_IFINDEX
])
54 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
55 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
59 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
62 return PTR_ERR(*rdev
);
68 /* policy for the attributes */
69 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
70 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
73 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
74 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
77 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
78 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
79 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
80 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
82 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
83 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
84 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
86 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
87 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
89 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
90 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
91 .len
= WLAN_MAX_KEY_LEN
},
92 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
93 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
94 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
95 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
96 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
98 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
99 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
101 .len
= IEEE80211_MAX_DATA_LEN
},
102 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
103 .len
= IEEE80211_MAX_DATA_LEN
},
104 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
105 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
106 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
107 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
108 .len
= NL80211_MAX_SUPP_RATES
},
109 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
110 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
111 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
112 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
113 .len
= IEEE80211_MAX_MESH_ID_LEN
},
114 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
116 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
117 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
119 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
120 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
122 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
123 .len
= NL80211_MAX_SUPP_RATES
},
124 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
126 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
128 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
129 .len
= NL80211_HT_CAPABILITY_LEN
},
131 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
132 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
133 .len
= IEEE80211_MAX_DATA_LEN
},
134 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
135 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
137 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
138 .len
= IEEE80211_MAX_SSID_LEN
},
139 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
140 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
141 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
142 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
143 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
144 [NL80211_ATTR_STA_FLAGS2
] = {
145 .len
= sizeof(struct nl80211_sta_flag_update
),
147 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
148 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
149 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
150 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
151 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
152 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
153 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
154 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
155 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
156 .len
= WLAN_PMKID_LEN
},
157 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
158 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
159 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
160 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
161 .len
= IEEE80211_MAX_DATA_LEN
},
162 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
163 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
164 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
165 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
166 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
167 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
168 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
169 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
170 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
171 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
172 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
173 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
174 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
177 /* policy for the key attributes */
178 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
179 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
180 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
181 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
182 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
183 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
184 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
185 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
186 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
189 /* policy for the key default flags */
190 static const struct nla_policy
191 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
192 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
193 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
196 /* ifidx get helper */
197 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
201 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
202 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
207 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
210 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
216 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
217 struct netlink_callback
*cb
,
218 struct cfg80211_registered_device
**rdev
,
219 struct net_device
**dev
)
221 int ifidx
= cb
->args
[0];
225 ifidx
= nl80211_get_ifidx(cb
);
233 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
239 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
241 err
= PTR_ERR(*rdev
);
251 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
253 cfg80211_unlock_rdev(rdev
);
258 static bool is_valid_ie_attr(const struct nlattr
*attr
)
266 pos
= nla_data(attr
);
287 /* message building helper */
288 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
291 /* since there is no private header just add the generic one */
292 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
295 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
296 struct ieee80211_channel
*chan
)
298 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
301 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
302 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
303 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
304 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
305 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
306 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
307 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
308 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
310 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
311 DBM_TO_MBM(chan
->max_power
));
319 /* netlink command implementations */
326 bool def_uni
, def_multi
;
329 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
331 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
332 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
337 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
338 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
347 if (tb
[NL80211_KEY_IDX
])
348 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
350 if (tb
[NL80211_KEY_DATA
]) {
351 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
352 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
355 if (tb
[NL80211_KEY_SEQ
]) {
356 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
357 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
360 if (tb
[NL80211_KEY_CIPHER
])
361 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
363 if (tb
[NL80211_KEY_TYPE
]) {
364 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
365 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
369 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
370 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
371 int err
= nla_parse_nested(kdt
,
372 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
373 tb
[NL80211_KEY_DEFAULT_TYPES
],
374 nl80211_key_default_policy
);
378 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
379 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
385 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
387 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
388 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
389 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
392 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
393 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
394 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
397 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
398 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
400 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
401 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
403 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
404 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
413 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
414 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
415 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
419 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
420 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
421 int err
= nla_parse_nested(
422 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
423 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
424 nl80211_key_default_policy
);
428 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
429 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
435 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
439 memset(k
, 0, sizeof(*k
));
443 if (info
->attrs
[NL80211_ATTR_KEY
])
444 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
446 err
= nl80211_parse_key_old(info
, k
);
451 if (k
->def
&& k
->defmgmt
)
455 if (k
->def_uni
|| !k
->def_multi
)
461 if (k
->idx
< 4 || k
->idx
> 5)
464 if (k
->idx
< 0 || k
->idx
> 3)
467 if (k
->idx
< 0 || k
->idx
> 5)
475 static struct cfg80211_cached_keys
*
476 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
479 struct key_parse parse
;
481 struct cfg80211_cached_keys
*result
;
482 int rem
, err
, def
= 0;
484 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
486 return ERR_PTR(-ENOMEM
);
489 result
->defmgmt
= -1;
491 nla_for_each_nested(key
, keys
, rem
) {
492 memset(&parse
, 0, sizeof(parse
));
495 err
= nl80211_parse_key_new(key
, &parse
);
501 if (parse
.idx
< 0 || parse
.idx
> 4)
507 result
->def
= parse
.idx
;
508 if (!parse
.def_uni
|| !parse
.def_multi
)
510 } else if (parse
.defmgmt
)
512 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
513 parse
.idx
, false, NULL
);
516 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
517 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
518 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
519 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
528 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
530 ASSERT_WDEV_LOCK(wdev
);
532 switch (wdev
->iftype
) {
533 case NL80211_IFTYPE_AP
:
534 case NL80211_IFTYPE_AP_VLAN
:
535 case NL80211_IFTYPE_P2P_GO
:
537 case NL80211_IFTYPE_ADHOC
:
538 if (!wdev
->current_bss
)
541 case NL80211_IFTYPE_STATION
:
542 case NL80211_IFTYPE_P2P_CLIENT
:
543 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
553 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
554 struct cfg80211_registered_device
*dev
)
557 struct nlattr
*nl_bands
, *nl_band
;
558 struct nlattr
*nl_freqs
, *nl_freq
;
559 struct nlattr
*nl_rates
, *nl_rate
;
560 struct nlattr
*nl_modes
;
561 struct nlattr
*nl_cmds
;
562 enum ieee80211_band band
;
563 struct ieee80211_channel
*chan
;
564 struct ieee80211_rate
*rate
;
566 u16 ifmodes
= dev
->wiphy
.interface_modes
;
567 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
568 dev
->wiphy
.mgmt_stypes
;
570 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
574 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
575 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
577 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
578 cfg80211_rdev_list_generation
);
580 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
581 dev
->wiphy
.retry_short
);
582 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
583 dev
->wiphy
.retry_long
);
584 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
585 dev
->wiphy
.frag_threshold
);
586 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
587 dev
->wiphy
.rts_threshold
);
588 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
589 dev
->wiphy
.coverage_class
);
590 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
591 dev
->wiphy
.max_scan_ssids
);
592 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
593 dev
->wiphy
.max_scan_ie_len
);
595 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
596 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
598 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
599 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
600 dev
->wiphy
.cipher_suites
);
602 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
603 dev
->wiphy
.max_num_pmkids
);
605 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
606 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
608 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
609 dev
->wiphy
.available_antennas_tx
);
610 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
611 dev
->wiphy
.available_antennas_rx
);
613 if ((dev
->wiphy
.available_antennas_tx
||
614 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
615 u32 tx_ant
= 0, rx_ant
= 0;
617 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
619 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
620 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
624 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
626 goto nla_put_failure
;
631 NLA_PUT_FLAG(msg
, i
);
636 nla_nest_end(msg
, nl_modes
);
638 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
640 goto nla_put_failure
;
642 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
643 if (!dev
->wiphy
.bands
[band
])
646 nl_band
= nla_nest_start(msg
, band
);
648 goto nla_put_failure
;
651 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
652 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
653 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
654 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
655 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
656 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
657 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
658 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
659 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
660 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
663 /* add frequencies */
664 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
666 goto nla_put_failure
;
668 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
669 nl_freq
= nla_nest_start(msg
, i
);
671 goto nla_put_failure
;
673 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
675 if (nl80211_msg_put_channel(msg
, chan
))
676 goto nla_put_failure
;
678 nla_nest_end(msg
, nl_freq
);
681 nla_nest_end(msg
, nl_freqs
);
684 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
686 goto nla_put_failure
;
688 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
689 nl_rate
= nla_nest_start(msg
, i
);
691 goto nla_put_failure
;
693 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
694 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
696 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
698 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
700 nla_nest_end(msg
, nl_rate
);
703 nla_nest_end(msg
, nl_rates
);
705 nla_nest_end(msg
, nl_band
);
707 nla_nest_end(msg
, nl_bands
);
709 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
711 goto nla_put_failure
;
716 if (dev->ops->op) { \
718 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
722 CMD(add_virtual_intf
, NEW_INTERFACE
);
723 CMD(change_virtual_intf
, SET_INTERFACE
);
724 CMD(add_key
, NEW_KEY
);
725 CMD(add_beacon
, NEW_BEACON
);
726 CMD(add_station
, NEW_STATION
);
727 CMD(add_mpath
, NEW_MPATH
);
728 CMD(update_mesh_config
, SET_MESH_CONFIG
);
729 CMD(change_bss
, SET_BSS
);
730 CMD(auth
, AUTHENTICATE
);
731 CMD(assoc
, ASSOCIATE
);
732 CMD(deauth
, DEAUTHENTICATE
);
733 CMD(disassoc
, DISASSOCIATE
);
734 CMD(join_ibss
, JOIN_IBSS
);
735 CMD(join_mesh
, JOIN_MESH
);
736 CMD(set_pmksa
, SET_PMKSA
);
737 CMD(del_pmksa
, DEL_PMKSA
);
738 CMD(flush_pmksa
, FLUSH_PMKSA
);
739 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
740 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
742 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
743 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
745 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
747 CMD(set_channel
, SET_CHANNEL
);
748 CMD(set_wds_peer
, SET_WDS_PEER
);
752 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
754 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
757 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
759 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
762 nla_nest_end(msg
, nl_cmds
);
764 if (dev
->ops
->remain_on_channel
)
765 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
766 dev
->wiphy
.max_remain_on_channel_duration
);
768 /* for now at least assume all drivers have it */
769 if (dev
->ops
->mgmt_tx
)
770 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
774 struct nlattr
*nl_ftypes
, *nl_ifs
;
775 enum nl80211_iftype ift
;
777 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
779 goto nla_put_failure
;
781 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
782 nl_ftypes
= nla_nest_start(msg
, ift
);
784 goto nla_put_failure
;
786 stypes
= mgmt_stypes
[ift
].tx
;
789 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
790 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
794 nla_nest_end(msg
, nl_ftypes
);
797 nla_nest_end(msg
, nl_ifs
);
799 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
801 goto nla_put_failure
;
803 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
804 nl_ftypes
= nla_nest_start(msg
, ift
);
806 goto nla_put_failure
;
808 stypes
= mgmt_stypes
[ift
].rx
;
811 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
812 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
816 nla_nest_end(msg
, nl_ftypes
);
818 nla_nest_end(msg
, nl_ifs
);
821 return genlmsg_end(msg
, hdr
);
824 genlmsg_cancel(msg
, hdr
);
828 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
831 int start
= cb
->args
[0];
832 struct cfg80211_registered_device
*dev
;
834 mutex_lock(&cfg80211_mutex
);
835 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
836 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
840 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
841 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
847 mutex_unlock(&cfg80211_mutex
);
854 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
857 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
859 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
863 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
868 return genlmsg_reply(msg
, info
);
871 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
872 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
873 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
874 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
875 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
876 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
879 static int parse_txq_params(struct nlattr
*tb
[],
880 struct ieee80211_txq_params
*txq_params
)
882 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
883 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
884 !tb
[NL80211_TXQ_ATTR_AIFS
])
887 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
888 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
889 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
890 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
891 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
896 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
899 * You can only set the channel explicitly for AP, mesh
900 * and WDS type interfaces; all others have their channel
901 * managed via their respective "establish a connection"
902 * command (connect, join, ...)
904 * Monitors are special as they are normally slaved to
905 * whatever else is going on, so they behave as though
906 * you tried setting the wiphy channel itself.
909 wdev
->iftype
== NL80211_IFTYPE_AP
||
910 wdev
->iftype
== NL80211_IFTYPE_WDS
||
911 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
912 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
913 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
916 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
917 struct wireless_dev
*wdev
,
918 struct genl_info
*info
)
920 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
924 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
927 if (!nl80211_can_set_dev_channel(wdev
))
930 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
931 channel_type
= nla_get_u32(info
->attrs
[
932 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
933 if (channel_type
!= NL80211_CHAN_NO_HT
&&
934 channel_type
!= NL80211_CHAN_HT20
&&
935 channel_type
!= NL80211_CHAN_HT40PLUS
&&
936 channel_type
!= NL80211_CHAN_HT40MINUS
)
940 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
942 mutex_lock(&rdev
->devlist_mtx
);
945 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
948 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
950 mutex_unlock(&rdev
->devlist_mtx
);
955 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
957 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
958 struct net_device
*netdev
= info
->user_ptr
[1];
960 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
963 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
965 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
966 struct net_device
*dev
= info
->user_ptr
[1];
967 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
970 if (!info
->attrs
[NL80211_ATTR_MAC
])
973 if (netif_running(dev
))
976 if (!rdev
->ops
->set_wds_peer
)
979 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
982 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
983 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
987 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
989 struct cfg80211_registered_device
*rdev
;
990 struct net_device
*netdev
= NULL
;
991 struct wireless_dev
*wdev
;
992 int result
= 0, rem_txq_params
= 0;
993 struct nlattr
*nl_txq_params
;
995 u8 retry_short
= 0, retry_long
= 0;
996 u32 frag_threshold
= 0, rts_threshold
= 0;
997 u8 coverage_class
= 0;
1000 * Try to find the wiphy and netdev. Normally this
1001 * function shouldn't need the netdev, but this is
1002 * done for backward compatibility -- previously
1003 * setting the channel was done per wiphy, but now
1004 * it is per netdev. Previous userland like hostapd
1005 * also passed a netdev to set_wiphy, so that it is
1006 * possible to let that go to the right netdev!
1008 mutex_lock(&cfg80211_mutex
);
1010 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1011 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1013 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1014 if (netdev
&& netdev
->ieee80211_ptr
) {
1015 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1016 mutex_lock(&rdev
->mtx
);
1022 rdev
= __cfg80211_rdev_from_info(info
);
1024 mutex_unlock(&cfg80211_mutex
);
1025 return PTR_ERR(rdev
);
1031 mutex_lock(&rdev
->mtx
);
1032 } else if (netif_running(netdev
) &&
1033 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1034 wdev
= netdev
->ieee80211_ptr
;
1039 * end workaround code, by now the rdev is available
1040 * and locked, and wdev may or may not be NULL.
1043 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1044 result
= cfg80211_dev_rename(
1045 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1047 mutex_unlock(&cfg80211_mutex
);
1052 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1053 struct ieee80211_txq_params txq_params
;
1054 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1056 if (!rdev
->ops
->set_txq_params
) {
1057 result
= -EOPNOTSUPP
;
1061 nla_for_each_nested(nl_txq_params
,
1062 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1064 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1065 nla_data(nl_txq_params
),
1066 nla_len(nl_txq_params
),
1068 result
= parse_txq_params(tb
, &txq_params
);
1072 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1079 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1080 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1085 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1086 enum nl80211_tx_power_setting type
;
1089 if (!rdev
->ops
->set_tx_power
) {
1090 result
= -EOPNOTSUPP
;
1094 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1095 type
= nla_get_u32(info
->attrs
[idx
]);
1097 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1098 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1103 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1104 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1105 mbm
= nla_get_u32(info
->attrs
[idx
]);
1108 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1113 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1114 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1116 if ((!rdev
->wiphy
.available_antennas_tx
&&
1117 !rdev
->wiphy
.available_antennas_rx
) ||
1118 !rdev
->ops
->set_antenna
) {
1119 result
= -EOPNOTSUPP
;
1123 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1124 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1126 /* reject antenna configurations which don't match the
1127 * available antenna masks, except for the "all" mask */
1128 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1129 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1134 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1135 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1137 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1144 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1145 retry_short
= nla_get_u8(
1146 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1147 if (retry_short
== 0) {
1151 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1154 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1155 retry_long
= nla_get_u8(
1156 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1157 if (retry_long
== 0) {
1161 changed
|= WIPHY_PARAM_RETRY_LONG
;
1164 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1165 frag_threshold
= nla_get_u32(
1166 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1167 if (frag_threshold
< 256) {
1171 if (frag_threshold
!= (u32
) -1) {
1173 * Fragments (apart from the last one) are required to
1174 * have even length. Make the fragmentation code
1175 * simpler by stripping LSB should someone try to use
1176 * odd threshold value.
1178 frag_threshold
&= ~0x1;
1180 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1183 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1184 rts_threshold
= nla_get_u32(
1185 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1186 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1189 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1190 coverage_class
= nla_get_u8(
1191 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1192 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1196 u8 old_retry_short
, old_retry_long
;
1197 u32 old_frag_threshold
, old_rts_threshold
;
1198 u8 old_coverage_class
;
1200 if (!rdev
->ops
->set_wiphy_params
) {
1201 result
= -EOPNOTSUPP
;
1205 old_retry_short
= rdev
->wiphy
.retry_short
;
1206 old_retry_long
= rdev
->wiphy
.retry_long
;
1207 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1208 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1209 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1211 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1212 rdev
->wiphy
.retry_short
= retry_short
;
1213 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1214 rdev
->wiphy
.retry_long
= retry_long
;
1215 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1216 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1217 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1218 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1219 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1220 rdev
->wiphy
.coverage_class
= coverage_class
;
1222 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1224 rdev
->wiphy
.retry_short
= old_retry_short
;
1225 rdev
->wiphy
.retry_long
= old_retry_long
;
1226 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1227 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1228 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1233 mutex_unlock(&rdev
->mtx
);
1240 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1241 struct cfg80211_registered_device
*rdev
,
1242 struct net_device
*dev
)
1246 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1250 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1251 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1252 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1253 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1255 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1256 rdev
->devlist_generation
^
1257 (cfg80211_rdev_list_generation
<< 2));
1259 return genlmsg_end(msg
, hdr
);
1262 genlmsg_cancel(msg
, hdr
);
1266 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1270 int wp_start
= cb
->args
[0];
1271 int if_start
= cb
->args
[1];
1272 struct cfg80211_registered_device
*rdev
;
1273 struct wireless_dev
*wdev
;
1275 mutex_lock(&cfg80211_mutex
);
1276 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1277 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1279 if (wp_idx
< wp_start
) {
1285 mutex_lock(&rdev
->devlist_mtx
);
1286 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1287 if (if_idx
< if_start
) {
1291 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1292 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1293 rdev
, wdev
->netdev
) < 0) {
1294 mutex_unlock(&rdev
->devlist_mtx
);
1299 mutex_unlock(&rdev
->devlist_mtx
);
1304 mutex_unlock(&cfg80211_mutex
);
1306 cb
->args
[0] = wp_idx
;
1307 cb
->args
[1] = if_idx
;
1312 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1314 struct sk_buff
*msg
;
1315 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1316 struct net_device
*netdev
= info
->user_ptr
[1];
1318 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1322 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1328 return genlmsg_reply(msg
, info
);
1331 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1332 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1333 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1334 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1335 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1336 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1339 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1341 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1349 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1350 nla
, mntr_flags_policy
))
1353 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1355 *mntrflags
|= (1<<flag
);
1360 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1361 struct net_device
*netdev
, u8 use_4addr
,
1362 enum nl80211_iftype iftype
)
1365 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1371 case NL80211_IFTYPE_AP_VLAN
:
1372 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1375 case NL80211_IFTYPE_STATION
:
1376 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1386 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1388 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1389 struct vif_params params
;
1391 enum nl80211_iftype otype
, ntype
;
1392 struct net_device
*dev
= info
->user_ptr
[1];
1393 u32 _flags
, *flags
= NULL
;
1394 bool change
= false;
1396 memset(¶ms
, 0, sizeof(params
));
1398 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1400 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1401 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1404 if (ntype
> NL80211_IFTYPE_MAX
)
1408 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1409 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1411 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1413 if (netif_running(dev
))
1417 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1418 IEEE80211_MAX_MESH_ID_LEN
);
1419 wdev
->mesh_id_up_len
=
1420 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1421 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1422 wdev
->mesh_id_up_len
);
1426 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1427 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1429 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1433 params
.use_4addr
= -1;
1436 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1437 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1439 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1449 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1453 if (!err
&& params
.use_4addr
!= -1)
1454 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1459 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1461 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1462 struct vif_params params
;
1463 struct net_device
*dev
;
1465 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1468 memset(¶ms
, 0, sizeof(params
));
1470 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1473 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1474 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1475 if (type
> NL80211_IFTYPE_MAX
)
1479 if (!rdev
->ops
->add_virtual_intf
||
1480 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1483 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1484 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1485 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1490 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1491 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1493 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1494 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1495 type
, err
? NULL
: &flags
, ¶ms
);
1497 return PTR_ERR(dev
);
1499 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1500 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1501 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1504 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1505 IEEE80211_MAX_MESH_ID_LEN
);
1506 wdev
->mesh_id_up_len
=
1507 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1508 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1509 wdev
->mesh_id_up_len
);
1516 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1518 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1519 struct net_device
*dev
= info
->user_ptr
[1];
1521 if (!rdev
->ops
->del_virtual_intf
)
1524 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1527 struct get_key_cookie
{
1528 struct sk_buff
*msg
;
1533 static void get_key_callback(void *c
, struct key_params
*params
)
1536 struct get_key_cookie
*cookie
= c
;
1539 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1540 params
->key_len
, params
->key
);
1543 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1544 params
->seq_len
, params
->seq
);
1547 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1550 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1552 goto nla_put_failure
;
1555 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1556 params
->key_len
, params
->key
);
1559 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1560 params
->seq_len
, params
->seq
);
1563 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1566 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1568 nla_nest_end(cookie
->msg
, key
);
1575 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1577 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1579 struct net_device
*dev
= info
->user_ptr
[1];
1581 const u8
*mac_addr
= NULL
;
1583 struct get_key_cookie cookie
= {
1587 struct sk_buff
*msg
;
1589 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1590 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1595 if (info
->attrs
[NL80211_ATTR_MAC
])
1596 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1598 pairwise
= !!mac_addr
;
1599 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1600 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1601 if (kt
>= NUM_NL80211_KEYTYPES
)
1603 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1604 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1606 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1609 if (!rdev
->ops
->get_key
)
1612 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1616 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1617 NL80211_CMD_NEW_KEY
);
1619 return PTR_ERR(hdr
);
1622 cookie
.idx
= key_idx
;
1624 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1625 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1627 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1629 if (pairwise
&& mac_addr
&&
1630 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1633 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1634 mac_addr
, &cookie
, get_key_callback
);
1640 goto nla_put_failure
;
1642 genlmsg_end(msg
, hdr
);
1643 return genlmsg_reply(msg
, info
);
1652 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1654 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1655 struct key_parse key
;
1657 struct net_device
*dev
= info
->user_ptr
[1];
1659 err
= nl80211_parse_key(info
, &key
);
1666 /* only support setting default key */
1667 if (!key
.def
&& !key
.defmgmt
)
1670 wdev_lock(dev
->ieee80211_ptr
);
1673 if (!rdev
->ops
->set_default_key
) {
1678 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1682 if (!(rdev
->wiphy
.flags
&
1683 WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS
)) {
1684 if (!key
.def_uni
|| !key
.def_multi
) {
1690 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1691 key
.def_uni
, key
.def_multi
);
1696 #ifdef CONFIG_CFG80211_WEXT
1697 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1700 if (key
.def_uni
|| !key
.def_multi
) {
1705 if (!rdev
->ops
->set_default_mgmt_key
) {
1710 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1714 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1719 #ifdef CONFIG_CFG80211_WEXT
1720 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1725 wdev_unlock(dev
->ieee80211_ptr
);
1730 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1732 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1734 struct net_device
*dev
= info
->user_ptr
[1];
1735 struct key_parse key
;
1736 const u8
*mac_addr
= NULL
;
1738 err
= nl80211_parse_key(info
, &key
);
1745 if (info
->attrs
[NL80211_ATTR_MAC
])
1746 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1748 if (key
.type
== -1) {
1750 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1752 key
.type
= NL80211_KEYTYPE_GROUP
;
1756 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1757 key
.type
!= NL80211_KEYTYPE_GROUP
)
1760 if (!rdev
->ops
->add_key
)
1763 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1764 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1768 wdev_lock(dev
->ieee80211_ptr
);
1769 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1771 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1772 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1774 wdev_unlock(dev
->ieee80211_ptr
);
1779 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1783 struct net_device
*dev
= info
->user_ptr
[1];
1784 u8
*mac_addr
= NULL
;
1785 struct key_parse key
;
1787 err
= nl80211_parse_key(info
, &key
);
1791 if (info
->attrs
[NL80211_ATTR_MAC
])
1792 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1794 if (key
.type
== -1) {
1796 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1798 key
.type
= NL80211_KEYTYPE_GROUP
;
1802 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1803 key
.type
!= NL80211_KEYTYPE_GROUP
)
1806 if (!rdev
->ops
->del_key
)
1809 wdev_lock(dev
->ieee80211_ptr
);
1810 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1812 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
1813 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1817 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
1818 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1821 #ifdef CONFIG_CFG80211_WEXT
1823 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1824 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1825 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1826 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1829 wdev_unlock(dev
->ieee80211_ptr
);
1834 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1836 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1837 struct beacon_parameters
*info
);
1838 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1839 struct net_device
*dev
= info
->user_ptr
[1];
1840 struct beacon_parameters params
;
1843 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1846 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1847 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1850 switch (info
->genlhdr
->cmd
) {
1851 case NL80211_CMD_NEW_BEACON
:
1852 /* these are required for NEW_BEACON */
1853 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1854 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1855 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
1858 call
= rdev
->ops
->add_beacon
;
1860 case NL80211_CMD_SET_BEACON
:
1861 call
= rdev
->ops
->set_beacon
;
1871 memset(¶ms
, 0, sizeof(params
));
1873 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1875 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1879 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1880 params
.dtim_period
=
1881 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1885 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1886 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1888 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1892 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1893 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1895 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1902 return call(&rdev
->wiphy
, dev
, ¶ms
);
1905 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1907 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1908 struct net_device
*dev
= info
->user_ptr
[1];
1910 if (!rdev
->ops
->del_beacon
)
1913 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1914 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1917 return rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1920 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1921 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1922 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1923 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1924 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1927 static int parse_station_flags(struct genl_info
*info
,
1928 struct station_parameters
*params
)
1930 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1935 * Try parsing the new attribute first so userspace
1936 * can specify both for older kernels.
1938 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1940 struct nl80211_sta_flag_update
*sta_flags
;
1942 sta_flags
= nla_data(nla
);
1943 params
->sta_flags_mask
= sta_flags
->mask
;
1944 params
->sta_flags_set
= sta_flags
->set
;
1945 if ((params
->sta_flags_mask
|
1946 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1951 /* if present, parse the old attribute */
1953 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1957 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1958 nla
, sta_flags_policy
))
1961 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1962 params
->sta_flags_mask
&= ~1;
1964 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1966 params
->sta_flags_set
|= (1<<flag
);
1971 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1972 int flags
, struct net_device
*dev
,
1973 const u8
*mac_addr
, struct station_info
*sinfo
)
1976 struct nlattr
*sinfoattr
, *txrate
;
1979 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1983 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1984 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1986 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1988 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1990 goto nla_put_failure
;
1991 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1992 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1993 sinfo
->inactive_time
);
1994 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1995 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1997 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1998 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2000 if (sinfo
->filled
& STATION_INFO_LLID
)
2001 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2003 if (sinfo
->filled
& STATION_INFO_PLID
)
2004 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2006 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2007 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2008 sinfo
->plink_state
);
2009 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2010 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2012 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2013 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2015 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2016 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
2018 goto nla_put_failure
;
2020 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2021 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
2023 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2025 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
2026 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
2028 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2029 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2030 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
2031 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2033 nla_nest_end(msg
, txrate
);
2035 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2036 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2038 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2039 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2041 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2042 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2044 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2045 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2047 nla_nest_end(msg
, sinfoattr
);
2049 return genlmsg_end(msg
, hdr
);
2052 genlmsg_cancel(msg
, hdr
);
2056 static int nl80211_dump_station(struct sk_buff
*skb
,
2057 struct netlink_callback
*cb
)
2059 struct station_info sinfo
;
2060 struct cfg80211_registered_device
*dev
;
2061 struct net_device
*netdev
;
2062 u8 mac_addr
[ETH_ALEN
];
2063 int sta_idx
= cb
->args
[1];
2066 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2070 if (!dev
->ops
->dump_station
) {
2076 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2083 if (nl80211_send_station(skb
,
2084 NETLINK_CB(cb
->skb
).pid
,
2085 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2095 cb
->args
[1] = sta_idx
;
2098 nl80211_finish_netdev_dump(dev
);
2103 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2105 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2106 struct net_device
*dev
= info
->user_ptr
[1];
2107 struct station_info sinfo
;
2108 struct sk_buff
*msg
;
2109 u8
*mac_addr
= NULL
;
2112 memset(&sinfo
, 0, sizeof(sinfo
));
2114 if (!info
->attrs
[NL80211_ATTR_MAC
])
2117 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2119 if (!rdev
->ops
->get_station
)
2122 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2126 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2130 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2131 dev
, mac_addr
, &sinfo
) < 0) {
2136 return genlmsg_reply(msg
, info
);
2140 * Get vlan interface making sure it is running and on the right wiphy.
2142 static int get_vlan(struct genl_info
*info
,
2143 struct cfg80211_registered_device
*rdev
,
2144 struct net_device
**vlan
)
2146 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2150 *vlan
= dev_get_by_index(genl_info_net(info
),
2151 nla_get_u32(vlanattr
));
2154 if (!(*vlan
)->ieee80211_ptr
)
2156 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2158 if (!netif_running(*vlan
))
2164 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2166 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2168 struct net_device
*dev
= info
->user_ptr
[1];
2169 struct station_parameters params
;
2170 u8
*mac_addr
= NULL
;
2172 memset(¶ms
, 0, sizeof(params
));
2174 params
.listen_interval
= -1;
2176 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2179 if (!info
->attrs
[NL80211_ATTR_MAC
])
2182 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2184 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2185 params
.supported_rates
=
2186 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2187 params
.supported_rates_len
=
2188 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2191 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2192 params
.listen_interval
=
2193 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2195 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2197 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2199 if (parse_station_flags(info
, ¶ms
))
2202 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2203 params
.plink_action
=
2204 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2206 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2210 /* validate settings */
2213 switch (dev
->ieee80211_ptr
->iftype
) {
2214 case NL80211_IFTYPE_AP
:
2215 case NL80211_IFTYPE_AP_VLAN
:
2216 case NL80211_IFTYPE_P2P_GO
:
2217 /* disallow mesh-specific things */
2218 if (params
.plink_action
)
2221 case NL80211_IFTYPE_P2P_CLIENT
:
2222 case NL80211_IFTYPE_STATION
:
2223 /* disallow everything but AUTHORIZED flag */
2224 if (params
.plink_action
)
2228 if (params
.supported_rates
)
2232 if (params
.listen_interval
>= 0)
2234 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2237 case NL80211_IFTYPE_MESH_POINT
:
2238 /* disallow things mesh doesn't support */
2243 if (params
.listen_interval
>= 0)
2245 if (params
.supported_rates
)
2247 if (params
.sta_flags_mask
)
2257 if (!rdev
->ops
->change_station
) {
2262 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2266 dev_put(params
.vlan
);
2271 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2273 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2275 struct net_device
*dev
= info
->user_ptr
[1];
2276 struct station_parameters params
;
2277 u8
*mac_addr
= NULL
;
2279 memset(¶ms
, 0, sizeof(params
));
2281 if (!info
->attrs
[NL80211_ATTR_MAC
])
2284 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2287 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2290 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2293 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2294 params
.supported_rates
=
2295 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2296 params
.supported_rates_len
=
2297 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2298 params
.listen_interval
=
2299 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2301 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2302 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2305 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2307 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2309 if (parse_station_flags(info
, ¶ms
))
2312 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2313 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2314 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2317 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2321 /* validate settings */
2324 if (!rdev
->ops
->add_station
) {
2329 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2333 dev_put(params
.vlan
);
2337 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2339 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2340 struct net_device
*dev
= info
->user_ptr
[1];
2341 u8
*mac_addr
= NULL
;
2343 if (info
->attrs
[NL80211_ATTR_MAC
])
2344 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2346 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2347 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2348 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2349 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2352 if (!rdev
->ops
->del_station
)
2355 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2358 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2359 int flags
, struct net_device
*dev
,
2360 u8
*dst
, u8
*next_hop
,
2361 struct mpath_info
*pinfo
)
2364 struct nlattr
*pinfoattr
;
2366 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2370 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2371 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2372 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2374 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2376 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2378 goto nla_put_failure
;
2379 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2380 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2382 if (pinfo
->filled
& MPATH_INFO_SN
)
2383 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2385 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2386 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2388 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2389 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2391 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2392 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2394 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2395 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2396 pinfo
->discovery_timeout
);
2397 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2398 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2399 pinfo
->discovery_retries
);
2401 nla_nest_end(msg
, pinfoattr
);
2403 return genlmsg_end(msg
, hdr
);
2406 genlmsg_cancel(msg
, hdr
);
2410 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2411 struct netlink_callback
*cb
)
2413 struct mpath_info pinfo
;
2414 struct cfg80211_registered_device
*dev
;
2415 struct net_device
*netdev
;
2417 u8 next_hop
[ETH_ALEN
];
2418 int path_idx
= cb
->args
[1];
2421 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2425 if (!dev
->ops
->dump_mpath
) {
2430 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2436 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2437 dst
, next_hop
, &pinfo
);
2443 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2444 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2445 netdev
, dst
, next_hop
,
2454 cb
->args
[1] = path_idx
;
2457 nl80211_finish_netdev_dump(dev
);
2461 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2463 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2465 struct net_device
*dev
= info
->user_ptr
[1];
2466 struct mpath_info pinfo
;
2467 struct sk_buff
*msg
;
2469 u8 next_hop
[ETH_ALEN
];
2471 memset(&pinfo
, 0, sizeof(pinfo
));
2473 if (!info
->attrs
[NL80211_ATTR_MAC
])
2476 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2478 if (!rdev
->ops
->get_mpath
)
2481 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2484 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2488 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2492 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2493 dev
, dst
, next_hop
, &pinfo
) < 0) {
2498 return genlmsg_reply(msg
, info
);
2501 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2503 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2504 struct net_device
*dev
= info
->user_ptr
[1];
2506 u8
*next_hop
= NULL
;
2508 if (!info
->attrs
[NL80211_ATTR_MAC
])
2511 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2514 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2515 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2517 if (!rdev
->ops
->change_mpath
)
2520 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2523 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2526 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2528 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2529 struct net_device
*dev
= info
->user_ptr
[1];
2531 u8
*next_hop
= NULL
;
2533 if (!info
->attrs
[NL80211_ATTR_MAC
])
2536 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2539 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2540 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2542 if (!rdev
->ops
->add_mpath
)
2545 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2548 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2551 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2553 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2554 struct net_device
*dev
= info
->user_ptr
[1];
2557 if (info
->attrs
[NL80211_ATTR_MAC
])
2558 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2560 if (!rdev
->ops
->del_mpath
)
2563 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2566 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2568 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2569 struct net_device
*dev
= info
->user_ptr
[1];
2570 struct bss_parameters params
;
2572 memset(¶ms
, 0, sizeof(params
));
2573 /* default to not changing parameters */
2574 params
.use_cts_prot
= -1;
2575 params
.use_short_preamble
= -1;
2576 params
.use_short_slot_time
= -1;
2577 params
.ap_isolate
= -1;
2578 params
.ht_opmode
= -1;
2580 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2581 params
.use_cts_prot
=
2582 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2583 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2584 params
.use_short_preamble
=
2585 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2586 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2587 params
.use_short_slot_time
=
2588 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2589 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2590 params
.basic_rates
=
2591 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2592 params
.basic_rates_len
=
2593 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2595 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2596 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2597 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2599 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2601 if (!rdev
->ops
->change_bss
)
2604 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2605 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2608 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2611 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2612 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2613 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2614 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2615 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2616 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2617 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2620 static int parse_reg_rule(struct nlattr
*tb
[],
2621 struct ieee80211_reg_rule
*reg_rule
)
2623 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2624 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2626 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2628 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2630 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2632 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2634 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2637 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2639 freq_range
->start_freq_khz
=
2640 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2641 freq_range
->end_freq_khz
=
2642 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2643 freq_range
->max_bandwidth_khz
=
2644 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2646 power_rule
->max_eirp
=
2647 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2649 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2650 power_rule
->max_antenna_gain
=
2651 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2656 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2662 * You should only get this when cfg80211 hasn't yet initialized
2663 * completely when built-in to the kernel right between the time
2664 * window between nl80211_init() and regulatory_init(), if that is
2667 mutex_lock(&cfg80211_mutex
);
2668 if (unlikely(!cfg80211_regdomain
)) {
2669 mutex_unlock(&cfg80211_mutex
);
2670 return -EINPROGRESS
;
2672 mutex_unlock(&cfg80211_mutex
);
2674 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2677 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2679 r
= regulatory_hint_user(data
);
2684 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
2685 struct genl_info
*info
)
2687 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2688 struct net_device
*dev
= info
->user_ptr
[1];
2689 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2690 struct mesh_config cur_params
;
2693 struct nlattr
*pinfoattr
;
2694 struct sk_buff
*msg
;
2696 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2699 if (!rdev
->ops
->get_mesh_config
)
2703 /* If not connected, get default parameters */
2704 if (!wdev
->mesh_id_len
)
2705 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
2707 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
2714 /* Draw up a netlink message to send back */
2715 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2718 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2719 NL80211_CMD_GET_MESH_CONFIG
);
2721 goto nla_put_failure
;
2722 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
2724 goto nla_put_failure
;
2725 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2726 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2727 cur_params
.dot11MeshRetryTimeout
);
2728 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2729 cur_params
.dot11MeshConfirmTimeout
);
2730 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2731 cur_params
.dot11MeshHoldingTimeout
);
2732 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2733 cur_params
.dot11MeshMaxPeerLinks
);
2734 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2735 cur_params
.dot11MeshMaxRetries
);
2736 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2737 cur_params
.dot11MeshTTL
);
2738 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
2739 cur_params
.element_ttl
);
2740 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2741 cur_params
.auto_open_plinks
);
2742 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2743 cur_params
.dot11MeshHWMPmaxPREQretries
);
2744 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2745 cur_params
.path_refresh_time
);
2746 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2747 cur_params
.min_discovery_timeout
);
2748 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2749 cur_params
.dot11MeshHWMPactivePathTimeout
);
2750 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2751 cur_params
.dot11MeshHWMPpreqMinInterval
);
2752 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2753 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2754 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2755 cur_params
.dot11MeshHWMPRootMode
);
2756 nla_nest_end(msg
, pinfoattr
);
2757 genlmsg_end(msg
, hdr
);
2758 return genlmsg_reply(msg
, info
);
2761 genlmsg_cancel(msg
, hdr
);
2766 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
2767 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2768 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2769 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2770 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2771 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2772 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2773 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
2774 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2776 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2777 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2778 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2779 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2780 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2781 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2784 static const struct nla_policy
2785 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
2786 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
2787 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
2788 [NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE
] = { .type
= NLA_BINARY
,
2789 .len
= IEEE80211_MAX_DATA_LEN
},
2792 static int nl80211_parse_mesh_config(struct genl_info
*info
,
2793 struct mesh_config
*cfg
,
2796 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2799 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2801 if (table[attr_num]) {\
2802 cfg->param = nla_fn(table[attr_num]); \
2803 mask |= (1 << (attr_num - 1)); \
2808 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
2810 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2811 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
2812 nl80211_meshconf_params_policy
))
2815 /* This makes sure that there aren't more than 32 mesh config
2816 * parameters (otherwise our bitfield scheme would not work.) */
2817 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2819 /* Fill in the params struct */
2820 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2821 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2822 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2823 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2824 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2825 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2826 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2827 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2828 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2829 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2830 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2831 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2832 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
2833 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
2834 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2835 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2836 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2837 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2839 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2840 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2841 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2842 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2844 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2845 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2847 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2848 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2850 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2851 dot11MeshHWMPnetDiameterTraversalTime
,
2852 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2854 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2855 dot11MeshHWMPRootMode
, mask
,
2856 NL80211_MESHCONF_HWMP_ROOTMODE
,
2863 #undef FILL_IN_MESH_PARAM_IF_SET
2866 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
2867 struct mesh_setup
*setup
)
2869 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
2871 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
2873 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
2874 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
2875 nl80211_mesh_setup_params_policy
))
2878 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
2879 setup
->path_sel_proto
=
2880 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
2881 IEEE80211_PATH_PROTOCOL_VENDOR
:
2882 IEEE80211_PATH_PROTOCOL_HWMP
;
2884 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
2885 setup
->path_metric
=
2886 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
2887 IEEE80211_PATH_METRIC_VENDOR
:
2888 IEEE80211_PATH_METRIC_AIRTIME
;
2890 if (tb
[NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE
]) {
2891 struct nlattr
*ieattr
=
2892 tb
[NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE
];
2893 if (!is_valid_ie_attr(ieattr
))
2895 setup
->vendor_ie
= nla_data(ieattr
);
2896 setup
->vendor_ie_len
= nla_len(ieattr
);
2902 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
2903 struct genl_info
*info
)
2905 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2906 struct net_device
*dev
= info
->user_ptr
[1];
2907 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2908 struct mesh_config cfg
;
2912 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2915 if (!rdev
->ops
->update_mesh_config
)
2918 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
2923 if (!wdev
->mesh_id_len
)
2927 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
2935 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2937 struct sk_buff
*msg
;
2939 struct nlattr
*nl_reg_rules
;
2943 mutex_lock(&cfg80211_mutex
);
2945 if (!cfg80211_regdomain
)
2948 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2954 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2955 NL80211_CMD_GET_REG
);
2957 goto nla_put_failure
;
2959 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2960 cfg80211_regdomain
->alpha2
);
2962 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2964 goto nla_put_failure
;
2966 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2967 struct nlattr
*nl_reg_rule
;
2968 const struct ieee80211_reg_rule
*reg_rule
;
2969 const struct ieee80211_freq_range
*freq_range
;
2970 const struct ieee80211_power_rule
*power_rule
;
2972 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2973 freq_range
= ®_rule
->freq_range
;
2974 power_rule
= ®_rule
->power_rule
;
2976 nl_reg_rule
= nla_nest_start(msg
, i
);
2978 goto nla_put_failure
;
2980 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2982 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2983 freq_range
->start_freq_khz
);
2984 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2985 freq_range
->end_freq_khz
);
2986 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2987 freq_range
->max_bandwidth_khz
);
2988 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2989 power_rule
->max_antenna_gain
);
2990 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2991 power_rule
->max_eirp
);
2993 nla_nest_end(msg
, nl_reg_rule
);
2996 nla_nest_end(msg
, nl_reg_rules
);
2998 genlmsg_end(msg
, hdr
);
2999 err
= genlmsg_reply(msg
, info
);
3003 genlmsg_cancel(msg
, hdr
);
3007 mutex_unlock(&cfg80211_mutex
);
3011 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3013 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3014 struct nlattr
*nl_reg_rule
;
3015 char *alpha2
= NULL
;
3016 int rem_reg_rules
= 0, r
= 0;
3017 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3018 struct ieee80211_regdomain
*rd
= NULL
;
3020 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3023 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3026 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3028 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3031 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3035 mutex_lock(&cfg80211_mutex
);
3037 if (!reg_is_valid_request(alpha2
)) {
3042 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3043 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3045 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3051 rd
->n_reg_rules
= num_rules
;
3052 rd
->alpha2
[0] = alpha2
[0];
3053 rd
->alpha2
[1] = alpha2
[1];
3055 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3057 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3058 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3060 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3066 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3072 BUG_ON(rule_idx
!= num_rules
);
3076 mutex_unlock(&cfg80211_mutex
);
3081 mutex_unlock(&cfg80211_mutex
);
3086 static int validate_scan_freqs(struct nlattr
*freqs
)
3088 struct nlattr
*attr1
, *attr2
;
3089 int n_channels
= 0, tmp1
, tmp2
;
3091 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3094 * Some hardware has a limited channel list for
3095 * scanning, and it is pretty much nonsensical
3096 * to scan for a channel twice, so disallow that
3097 * and don't require drivers to check that the
3098 * channel list they get isn't longer than what
3099 * they can scan, as long as they can scan all
3100 * the channels they registered at once.
3102 nla_for_each_nested(attr2
, freqs
, tmp2
)
3103 if (attr1
!= attr2
&&
3104 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3111 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3113 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3114 struct net_device
*dev
= info
->user_ptr
[1];
3115 struct cfg80211_scan_request
*request
;
3116 struct cfg80211_ssid
*ssid
;
3117 struct ieee80211_channel
*channel
;
3118 struct nlattr
*attr
;
3119 struct wiphy
*wiphy
;
3120 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3121 enum ieee80211_band band
;
3124 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3127 wiphy
= &rdev
->wiphy
;
3129 if (!rdev
->ops
->scan
)
3135 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3136 n_channels
= validate_scan_freqs(
3137 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3143 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3144 if (wiphy
->bands
[band
])
3145 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3148 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3149 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3152 if (n_ssids
> wiphy
->max_scan_ssids
)
3155 if (info
->attrs
[NL80211_ATTR_IE
])
3156 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3160 if (ie_len
> wiphy
->max_scan_ie_len
)
3163 request
= kzalloc(sizeof(*request
)
3164 + sizeof(*ssid
) * n_ssids
3165 + sizeof(channel
) * n_channels
3166 + ie_len
, GFP_KERNEL
);
3171 request
->ssids
= (void *)&request
->channels
[n_channels
];
3172 request
->n_ssids
= n_ssids
;
3175 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3177 request
->ie
= (void *)(request
->channels
+ n_channels
);
3181 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3182 /* user specified, bail out if channel not found */
3183 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3184 struct ieee80211_channel
*chan
;
3186 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3193 /* ignore disabled channels */
3194 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3197 request
->channels
[i
] = chan
;
3202 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3204 if (!wiphy
->bands
[band
])
3206 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3207 struct ieee80211_channel
*chan
;
3209 chan
= &wiphy
->bands
[band
]->channels
[j
];
3211 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3214 request
->channels
[i
] = chan
;
3225 request
->n_channels
= i
;
3228 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3229 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3230 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3234 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3235 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3240 if (info
->attrs
[NL80211_ATTR_IE
]) {
3241 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3242 memcpy((void *)request
->ie
,
3243 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3248 request
->wiphy
= &rdev
->wiphy
;
3250 rdev
->scan_req
= request
;
3251 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3254 nl80211_send_scan_start(rdev
, dev
);
3258 rdev
->scan_req
= NULL
;
3265 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3266 struct cfg80211_registered_device
*rdev
,
3267 struct wireless_dev
*wdev
,
3268 struct cfg80211_internal_bss
*intbss
)
3270 struct cfg80211_bss
*res
= &intbss
->pub
;
3275 ASSERT_WDEV_LOCK(wdev
);
3277 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3278 NL80211_CMD_NEW_SCAN_RESULTS
);
3282 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3283 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3285 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3287 goto nla_put_failure
;
3288 if (!is_zero_ether_addr(res
->bssid
))
3289 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3290 if (res
->information_elements
&& res
->len_information_elements
)
3291 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3292 res
->len_information_elements
,
3293 res
->information_elements
);
3294 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3295 res
->beacon_ies
!= res
->information_elements
)
3296 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3297 res
->len_beacon_ies
, res
->beacon_ies
);
3299 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3300 if (res
->beacon_interval
)
3301 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3302 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3303 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3304 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3305 jiffies_to_msecs(jiffies
- intbss
->ts
));
3307 switch (rdev
->wiphy
.signal_type
) {
3308 case CFG80211_SIGNAL_TYPE_MBM
:
3309 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3311 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3312 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3318 switch (wdev
->iftype
) {
3319 case NL80211_IFTYPE_P2P_CLIENT
:
3320 case NL80211_IFTYPE_STATION
:
3321 if (intbss
== wdev
->current_bss
)
3322 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3323 NL80211_BSS_STATUS_ASSOCIATED
);
3324 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3325 if (intbss
!= wdev
->auth_bsses
[i
])
3327 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3328 NL80211_BSS_STATUS_AUTHENTICATED
);
3332 case NL80211_IFTYPE_ADHOC
:
3333 if (intbss
== wdev
->current_bss
)
3334 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3335 NL80211_BSS_STATUS_IBSS_JOINED
);
3341 nla_nest_end(msg
, bss
);
3343 return genlmsg_end(msg
, hdr
);
3346 genlmsg_cancel(msg
, hdr
);
3350 static int nl80211_dump_scan(struct sk_buff
*skb
,
3351 struct netlink_callback
*cb
)
3353 struct cfg80211_registered_device
*rdev
;
3354 struct net_device
*dev
;
3355 struct cfg80211_internal_bss
*scan
;
3356 struct wireless_dev
*wdev
;
3357 int start
= cb
->args
[1], idx
= 0;
3360 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
3364 wdev
= dev
->ieee80211_ptr
;
3367 spin_lock_bh(&rdev
->bss_lock
);
3368 cfg80211_bss_expire(rdev
);
3370 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3373 if (nl80211_send_bss(skb
,
3374 NETLINK_CB(cb
->skb
).pid
,
3375 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3376 rdev
, wdev
, scan
) < 0) {
3382 spin_unlock_bh(&rdev
->bss_lock
);
3386 nl80211_finish_netdev_dump(rdev
);
3391 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3392 int flags
, struct net_device
*dev
,
3393 struct survey_info
*survey
)
3396 struct nlattr
*infoattr
;
3398 /* Survey without a channel doesn't make sense */
3399 if (!survey
->channel
)
3402 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3403 NL80211_CMD_NEW_SURVEY_RESULTS
);
3407 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3409 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3411 goto nla_put_failure
;
3413 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3414 survey
->channel
->center_freq
);
3415 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3416 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3418 if (survey
->filled
& SURVEY_INFO_IN_USE
)
3419 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
3420 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
3421 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
3422 survey
->channel_time
);
3423 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
3424 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
3425 survey
->channel_time_busy
);
3426 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
3427 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
3428 survey
->channel_time_ext_busy
);
3429 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
3430 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
3431 survey
->channel_time_rx
);
3432 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
3433 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
3434 survey
->channel_time_tx
);
3436 nla_nest_end(msg
, infoattr
);
3438 return genlmsg_end(msg
, hdr
);
3441 genlmsg_cancel(msg
, hdr
);
3445 static int nl80211_dump_survey(struct sk_buff
*skb
,
3446 struct netlink_callback
*cb
)
3448 struct survey_info survey
;
3449 struct cfg80211_registered_device
*dev
;
3450 struct net_device
*netdev
;
3451 int survey_idx
= cb
->args
[1];
3454 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3458 if (!dev
->ops
->dump_survey
) {
3464 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3471 if (nl80211_send_survey(skb
,
3472 NETLINK_CB(cb
->skb
).pid
,
3473 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3481 cb
->args
[1] = survey_idx
;
3484 nl80211_finish_netdev_dump(dev
);
3488 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3490 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3493 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3495 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3496 NL80211_WPA_VERSION_2
));
3499 static bool nl80211_valid_akm_suite(u32 akm
)
3501 return akm
== WLAN_AKM_SUITE_8021X
||
3502 akm
== WLAN_AKM_SUITE_PSK
;
3505 static bool nl80211_valid_cipher_suite(u32 cipher
)
3507 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3508 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3509 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3510 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3511 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3515 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3517 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3518 struct net_device
*dev
= info
->user_ptr
[1];
3519 struct ieee80211_channel
*chan
;
3520 const u8
*bssid
, *ssid
, *ie
= NULL
;
3521 int err
, ssid_len
, ie_len
= 0;
3522 enum nl80211_auth_type auth_type
;
3523 struct key_parse key
;
3524 bool local_state_change
;
3526 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3529 if (!info
->attrs
[NL80211_ATTR_MAC
])
3532 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3535 if (!info
->attrs
[NL80211_ATTR_SSID
])
3538 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3541 err
= nl80211_parse_key(info
, &key
);
3546 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
3548 if (!key
.p
.key
|| !key
.p
.key_len
)
3550 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3551 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3552 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3553 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3565 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
3566 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
3575 if (!rdev
->ops
->auth
)
3578 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3579 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3582 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3583 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3584 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3585 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
3588 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3589 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3591 if (info
->attrs
[NL80211_ATTR_IE
]) {
3592 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3593 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3596 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3597 if (!nl80211_valid_auth_type(auth_type
))
3600 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3602 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3603 ssid
, ssid_len
, ie
, ie_len
,
3604 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3605 local_state_change
);
3608 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
3609 struct genl_info
*info
,
3610 struct cfg80211_crypto_settings
*settings
,
3613 memset(settings
, 0, sizeof(*settings
));
3615 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3617 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
3619 proto
= nla_get_u16(
3620 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
3621 settings
->control_port_ethertype
= cpu_to_be16(proto
);
3622 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
3625 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
3626 settings
->control_port_no_encrypt
= true;
3628 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
3630 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3634 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3635 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3636 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3638 if (len
% sizeof(u32
))
3641 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3644 memcpy(settings
->ciphers_pairwise
, data
, len
);
3646 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3647 if (!nl80211_valid_cipher_suite(
3648 settings
->ciphers_pairwise
[i
]))
3652 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3653 settings
->cipher_group
=
3654 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3655 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3659 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3660 settings
->wpa_versions
=
3661 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3662 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3666 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3670 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3671 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3672 settings
->n_akm_suites
= len
/ sizeof(u32
);
3674 if (len
% sizeof(u32
))
3677 memcpy(settings
->akm_suites
, data
, len
);
3679 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3680 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3687 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3689 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3690 struct net_device
*dev
= info
->user_ptr
[1];
3691 struct cfg80211_crypto_settings crypto
;
3692 struct ieee80211_channel
*chan
;
3693 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3694 int err
, ssid_len
, ie_len
= 0;
3695 bool use_mfp
= false;
3697 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3700 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3701 !info
->attrs
[NL80211_ATTR_SSID
] ||
3702 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3705 if (!rdev
->ops
->assoc
)
3708 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3709 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3712 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3714 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3715 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3716 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
3719 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3720 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3722 if (info
->attrs
[NL80211_ATTR_IE
]) {
3723 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3724 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3727 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3728 enum nl80211_mfp mfp
=
3729 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3730 if (mfp
== NL80211_MFP_REQUIRED
)
3732 else if (mfp
!= NL80211_MFP_NO
)
3736 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3737 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3739 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
3741 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3742 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3748 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3750 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3751 struct net_device
*dev
= info
->user_ptr
[1];
3752 const u8
*ie
= NULL
, *bssid
;
3755 bool local_state_change
;
3757 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3760 if (!info
->attrs
[NL80211_ATTR_MAC
])
3763 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3766 if (!rdev
->ops
->deauth
)
3769 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3770 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3773 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3775 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3776 if (reason_code
== 0) {
3777 /* Reason Code 0 is reserved */
3781 if (info
->attrs
[NL80211_ATTR_IE
]) {
3782 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3783 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3786 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3788 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3789 local_state_change
);
3792 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3794 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3795 struct net_device
*dev
= info
->user_ptr
[1];
3796 const u8
*ie
= NULL
, *bssid
;
3799 bool local_state_change
;
3801 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3804 if (!info
->attrs
[NL80211_ATTR_MAC
])
3807 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3810 if (!rdev
->ops
->disassoc
)
3813 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3814 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3817 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3819 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3820 if (reason_code
== 0) {
3821 /* Reason Code 0 is reserved */
3825 if (info
->attrs
[NL80211_ATTR_IE
]) {
3826 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3827 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3830 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3832 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3833 local_state_change
);
3837 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
3838 int mcast_rate
[IEEE80211_NUM_BANDS
],
3841 struct wiphy
*wiphy
= &rdev
->wiphy
;
3845 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3846 struct ieee80211_supported_band
*sband
;
3848 sband
= wiphy
->bands
[band
];
3852 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3853 if (sband
->bitrates
[i
].bitrate
== rateval
) {
3854 mcast_rate
[band
] = i
+ 1;
3864 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3866 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3867 struct net_device
*dev
= info
->user_ptr
[1];
3868 struct cfg80211_ibss_params ibss
;
3869 struct wiphy
*wiphy
;
3870 struct cfg80211_cached_keys
*connkeys
= NULL
;
3873 memset(&ibss
, 0, sizeof(ibss
));
3875 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3878 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3879 !info
->attrs
[NL80211_ATTR_SSID
] ||
3880 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3883 ibss
.beacon_interval
= 100;
3885 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3886 ibss
.beacon_interval
=
3887 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3888 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3892 if (!rdev
->ops
->join_ibss
)
3895 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
3898 wiphy
= &rdev
->wiphy
;
3900 if (info
->attrs
[NL80211_ATTR_MAC
])
3901 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3902 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3903 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3905 if (info
->attrs
[NL80211_ATTR_IE
]) {
3906 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3907 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3910 ibss
.channel
= ieee80211_get_channel(wiphy
,
3911 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3912 if (!ibss
.channel
||
3913 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3914 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
3917 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3918 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3920 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3922 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3924 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3925 struct ieee80211_supported_band
*sband
=
3926 wiphy
->bands
[ibss
.channel
->band
];
3932 for (i
= 0; i
< n_rates
; i
++) {
3933 int rate
= (rates
[i
] & 0x7f) * 5;
3936 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
3937 if (sband
->bitrates
[j
].bitrate
== rate
) {
3939 ibss
.basic_rates
|= BIT(j
);
3948 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
3949 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
3950 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
3953 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3954 connkeys
= nl80211_parse_connkeys(rdev
,
3955 info
->attrs
[NL80211_ATTR_KEYS
]);
3956 if (IS_ERR(connkeys
))
3957 return PTR_ERR(connkeys
);
3960 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3966 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3968 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3969 struct net_device
*dev
= info
->user_ptr
[1];
3971 if (!rdev
->ops
->leave_ibss
)
3974 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
3977 return cfg80211_leave_ibss(rdev
, dev
, false);
3980 #ifdef CONFIG_NL80211_TESTMODE
3981 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
3985 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
3987 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3990 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
3994 if (rdev
->ops
->testmode_cmd
) {
3995 rdev
->testmode_info
= info
;
3996 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
3997 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
3998 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
3999 rdev
->testmode_info
= NULL
;
4005 static struct sk_buff
*
4006 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4007 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4009 struct sk_buff
*skb
;
4011 struct nlattr
*data
;
4013 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4017 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4023 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4024 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4026 ((void **)skb
->cb
)[0] = rdev
;
4027 ((void **)skb
->cb
)[1] = hdr
;
4028 ((void **)skb
->cb
)[2] = data
;
4037 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4040 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4042 if (WARN_ON(!rdev
->testmode_info
))
4045 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4046 rdev
->testmode_info
->snd_pid
,
4047 rdev
->testmode_info
->snd_seq
,
4050 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4052 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4054 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4055 void *hdr
= ((void **)skb
->cb
)[1];
4056 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4058 if (WARN_ON(!rdev
->testmode_info
)) {
4063 nla_nest_end(skb
, data
);
4064 genlmsg_end(skb
, hdr
);
4065 return genlmsg_reply(skb
, rdev
->testmode_info
);
4067 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4069 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4070 int approxlen
, gfp_t gfp
)
4072 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4074 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4076 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4078 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4080 void *hdr
= ((void **)skb
->cb
)[1];
4081 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4083 nla_nest_end(skb
, data
);
4084 genlmsg_end(skb
, hdr
);
4085 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4087 EXPORT_SYMBOL(cfg80211_testmode_event
);
4090 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4092 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4093 struct net_device
*dev
= info
->user_ptr
[1];
4094 struct cfg80211_connect_params connect
;
4095 struct wiphy
*wiphy
;
4096 struct cfg80211_cached_keys
*connkeys
= NULL
;
4099 memset(&connect
, 0, sizeof(connect
));
4101 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4104 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4105 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4108 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4110 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4111 if (!nl80211_valid_auth_type(connect
.auth_type
))
4114 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4116 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4118 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4119 NL80211_MAX_NR_CIPHER_SUITES
);
4123 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4124 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4127 wiphy
= &rdev
->wiphy
;
4129 if (info
->attrs
[NL80211_ATTR_MAC
])
4130 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4131 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4132 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4134 if (info
->attrs
[NL80211_ATTR_IE
]) {
4135 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4136 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4139 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4141 ieee80211_get_channel(wiphy
,
4142 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4143 if (!connect
.channel
||
4144 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4148 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4149 connkeys
= nl80211_parse_connkeys(rdev
,
4150 info
->attrs
[NL80211_ATTR_KEYS
]);
4151 if (IS_ERR(connkeys
))
4152 return PTR_ERR(connkeys
);
4155 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4161 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4163 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4164 struct net_device
*dev
= info
->user_ptr
[1];
4167 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4168 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4170 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4175 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4176 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4179 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4182 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4184 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4189 if (!info
->attrs
[NL80211_ATTR_PID
])
4192 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4194 net
= get_net_ns_by_pid(pid
);
4196 return PTR_ERR(net
);
4200 /* check if anything to do */
4201 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4202 err
= cfg80211_switch_netns(rdev
, net
);
4208 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4210 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4211 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4212 struct cfg80211_pmksa
*pmksa
) = NULL
;
4213 struct net_device
*dev
= info
->user_ptr
[1];
4214 struct cfg80211_pmksa pmksa
;
4216 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4218 if (!info
->attrs
[NL80211_ATTR_MAC
])
4221 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4224 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4225 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4227 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4228 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4231 switch (info
->genlhdr
->cmd
) {
4232 case NL80211_CMD_SET_PMKSA
:
4233 rdev_ops
= rdev
->ops
->set_pmksa
;
4235 case NL80211_CMD_DEL_PMKSA
:
4236 rdev_ops
= rdev
->ops
->del_pmksa
;
4246 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4249 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4251 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4252 struct net_device
*dev
= info
->user_ptr
[1];
4254 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4255 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4258 if (!rdev
->ops
->flush_pmksa
)
4261 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4264 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4265 struct genl_info
*info
)
4267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4268 struct net_device
*dev
= info
->user_ptr
[1];
4269 struct ieee80211_channel
*chan
;
4270 struct sk_buff
*msg
;
4273 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4277 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4278 !info
->attrs
[NL80211_ATTR_DURATION
])
4281 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4284 * We should be on that channel for at least one jiffie,
4285 * and more than 5 seconds seems excessive.
4287 if (!duration
|| !msecs_to_jiffies(duration
) ||
4288 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
4291 if (!rdev
->ops
->remain_on_channel
)
4294 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4295 channel_type
= nla_get_u32(
4296 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4297 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4298 channel_type
!= NL80211_CHAN_HT20
&&
4299 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4300 channel_type
!= NL80211_CHAN_HT40MINUS
)
4304 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4305 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4309 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4313 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4314 NL80211_CMD_REMAIN_ON_CHANNEL
);
4321 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4322 channel_type
, duration
, &cookie
);
4327 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4329 genlmsg_end(msg
, hdr
);
4331 return genlmsg_reply(msg
, info
);
4340 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4341 struct genl_info
*info
)
4343 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4344 struct net_device
*dev
= info
->user_ptr
[1];
4347 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4350 if (!rdev
->ops
->cancel_remain_on_channel
)
4353 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4355 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4358 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4359 u8
*rates
, u8 rates_len
)
4364 for (i
= 0; i
< rates_len
; i
++) {
4365 int rate
= (rates
[i
] & 0x7f) * 5;
4367 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4368 struct ieee80211_rate
*srate
=
4369 &sband
->bitrates
[ridx
];
4370 if (rate
== srate
->bitrate
) {
4375 if (ridx
== sband
->n_bitrates
)
4376 return 0; /* rate not found */
4382 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4383 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4384 .len
= NL80211_MAX_SUPP_RATES
},
4387 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4388 struct genl_info
*info
)
4390 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4391 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4392 struct cfg80211_bitrate_mask mask
;
4394 struct net_device
*dev
= info
->user_ptr
[1];
4395 struct nlattr
*tx_rates
;
4396 struct ieee80211_supported_band
*sband
;
4398 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4401 if (!rdev
->ops
->set_bitrate_mask
)
4404 memset(&mask
, 0, sizeof(mask
));
4405 /* Default to all rates enabled */
4406 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4407 sband
= rdev
->wiphy
.bands
[i
];
4408 mask
.control
[i
].legacy
=
4409 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4413 * The nested attribute uses enum nl80211_band as the index. This maps
4414 * directly to the enum ieee80211_band values used in cfg80211.
4416 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4418 enum ieee80211_band band
= nla_type(tx_rates
);
4419 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
4421 sband
= rdev
->wiphy
.bands
[band
];
4424 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4425 nla_len(tx_rates
), nl80211_txattr_policy
);
4426 if (tb
[NL80211_TXRATE_LEGACY
]) {
4427 mask
.control
[band
].legacy
= rateset_to_mask(
4429 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4430 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4431 if (mask
.control
[band
].legacy
== 0)
4436 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4439 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4441 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4442 struct net_device
*dev
= info
->user_ptr
[1];
4443 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
4445 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4448 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
4449 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
4451 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4452 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4453 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4454 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4455 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4456 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4457 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4460 /* not much point in registering if we can't reply */
4461 if (!rdev
->ops
->mgmt_tx
)
4464 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
4466 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4467 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4470 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4472 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4473 struct net_device
*dev
= info
->user_ptr
[1];
4474 struct ieee80211_channel
*chan
;
4475 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4476 bool channel_type_valid
= false;
4481 struct sk_buff
*msg
;
4482 unsigned int wait
= 0;
4485 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4486 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4489 if (!rdev
->ops
->mgmt_tx
)
4492 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4493 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4494 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4495 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4496 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4497 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4498 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4501 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
4502 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4504 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4507 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4508 channel_type
= nla_get_u32(
4509 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4510 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4511 channel_type
!= NL80211_CHAN_HT20
&&
4512 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4513 channel_type
!= NL80211_CHAN_HT40MINUS
)
4515 channel_type_valid
= true;
4518 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
4520 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4521 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4525 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4529 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4536 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
4537 channel_type_valid
, wait
,
4538 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4539 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4544 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4546 genlmsg_end(msg
, hdr
);
4547 return genlmsg_reply(msg
, info
);
4556 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
4558 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4559 struct net_device
*dev
= info
->user_ptr
[1];
4562 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4565 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4568 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4569 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4570 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4571 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4572 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4573 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4576 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4578 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
4581 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4583 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4584 struct wireless_dev
*wdev
;
4585 struct net_device
*dev
= info
->user_ptr
[1];
4590 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
4593 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4595 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
4598 wdev
= dev
->ieee80211_ptr
;
4600 if (!rdev
->ops
->set_power_mgmt
)
4603 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4605 if (state
== wdev
->ps
)
4608 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
4615 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4617 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4618 enum nl80211_ps_state ps_state
;
4619 struct wireless_dev
*wdev
;
4620 struct net_device
*dev
= info
->user_ptr
[1];
4621 struct sk_buff
*msg
;
4625 wdev
= dev
->ieee80211_ptr
;
4627 if (!rdev
->ops
->set_power_mgmt
)
4630 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4634 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4635 NL80211_CMD_GET_POWER_SAVE
);
4642 ps_state
= NL80211_PS_ENABLED
;
4644 ps_state
= NL80211_PS_DISABLED
;
4646 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4648 genlmsg_end(msg
, hdr
);
4649 return genlmsg_reply(msg
, info
);
4658 static struct nla_policy
4659 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4660 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4661 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4662 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4665 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4666 s32 threshold
, u32 hysteresis
)
4668 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4669 struct wireless_dev
*wdev
;
4670 struct net_device
*dev
= info
->user_ptr
[1];
4675 wdev
= dev
->ieee80211_ptr
;
4677 if (!rdev
->ops
->set_cqm_rssi_config
)
4680 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
4681 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4684 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
4685 threshold
, hysteresis
);
4688 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
4690 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
4694 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
4700 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
4701 nl80211_attr_cqm_policy
);
4705 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
4706 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
4709 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
4710 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
4711 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
4719 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
4721 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4722 struct net_device
*dev
= info
->user_ptr
[1];
4723 struct mesh_config cfg
;
4724 struct mesh_setup setup
;
4727 /* start with default */
4728 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
4729 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
4731 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
4732 /* and parse parameters if given */
4733 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
4738 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
4739 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
4742 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
4743 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
4745 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
4746 /* parse additional setup parameters if given */
4747 err
= nl80211_parse_mesh_setup(info
, &setup
);
4752 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
4755 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
4757 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4758 struct net_device
*dev
= info
->user_ptr
[1];
4760 return cfg80211_leave_mesh(rdev
, dev
);
4763 #define NL80211_FLAG_NEED_WIPHY 0x01
4764 #define NL80211_FLAG_NEED_NETDEV 0x02
4765 #define NL80211_FLAG_NEED_RTNL 0x04
4766 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
4767 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
4768 NL80211_FLAG_CHECK_NETDEV_UP)
4770 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
4771 struct genl_info
*info
)
4773 struct cfg80211_registered_device
*rdev
;
4774 struct net_device
*dev
;
4776 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
4781 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
4782 rdev
= cfg80211_get_dev_from_info(info
);
4786 return PTR_ERR(rdev
);
4788 info
->user_ptr
[0] = rdev
;
4789 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
4790 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4796 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
4797 !netif_running(dev
)) {
4798 cfg80211_unlock_rdev(rdev
);
4804 info
->user_ptr
[0] = rdev
;
4805 info
->user_ptr
[1] = dev
;
4811 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
4812 struct genl_info
*info
)
4814 if (info
->user_ptr
[0])
4815 cfg80211_unlock_rdev(info
->user_ptr
[0]);
4816 if (info
->user_ptr
[1])
4817 dev_put(info
->user_ptr
[1]);
4818 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
4822 static struct genl_ops nl80211_ops
[] = {
4824 .cmd
= NL80211_CMD_GET_WIPHY
,
4825 .doit
= nl80211_get_wiphy
,
4826 .dumpit
= nl80211_dump_wiphy
,
4827 .policy
= nl80211_policy
,
4828 /* can be retrieved by unprivileged users */
4829 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
4832 .cmd
= NL80211_CMD_SET_WIPHY
,
4833 .doit
= nl80211_set_wiphy
,
4834 .policy
= nl80211_policy
,
4835 .flags
= GENL_ADMIN_PERM
,
4836 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
4839 .cmd
= NL80211_CMD_GET_INTERFACE
,
4840 .doit
= nl80211_get_interface
,
4841 .dumpit
= nl80211_dump_interface
,
4842 .policy
= nl80211_policy
,
4843 /* can be retrieved by unprivileged users */
4844 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
4847 .cmd
= NL80211_CMD_SET_INTERFACE
,
4848 .doit
= nl80211_set_interface
,
4849 .policy
= nl80211_policy
,
4850 .flags
= GENL_ADMIN_PERM
,
4851 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4852 NL80211_FLAG_NEED_RTNL
,
4855 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4856 .doit
= nl80211_new_interface
,
4857 .policy
= nl80211_policy
,
4858 .flags
= GENL_ADMIN_PERM
,
4859 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
4860 NL80211_FLAG_NEED_RTNL
,
4863 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4864 .doit
= nl80211_del_interface
,
4865 .policy
= nl80211_policy
,
4866 .flags
= GENL_ADMIN_PERM
,
4867 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4868 NL80211_FLAG_NEED_RTNL
,
4871 .cmd
= NL80211_CMD_GET_KEY
,
4872 .doit
= nl80211_get_key
,
4873 .policy
= nl80211_policy
,
4874 .flags
= GENL_ADMIN_PERM
,
4875 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4876 NL80211_FLAG_NEED_RTNL
,
4879 .cmd
= NL80211_CMD_SET_KEY
,
4880 .doit
= nl80211_set_key
,
4881 .policy
= nl80211_policy
,
4882 .flags
= GENL_ADMIN_PERM
,
4883 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4884 NL80211_FLAG_NEED_RTNL
,
4887 .cmd
= NL80211_CMD_NEW_KEY
,
4888 .doit
= nl80211_new_key
,
4889 .policy
= nl80211_policy
,
4890 .flags
= GENL_ADMIN_PERM
,
4891 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4892 NL80211_FLAG_NEED_RTNL
,
4895 .cmd
= NL80211_CMD_DEL_KEY
,
4896 .doit
= nl80211_del_key
,
4897 .policy
= nl80211_policy
,
4898 .flags
= GENL_ADMIN_PERM
,
4899 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4900 NL80211_FLAG_NEED_RTNL
,
4903 .cmd
= NL80211_CMD_SET_BEACON
,
4904 .policy
= nl80211_policy
,
4905 .flags
= GENL_ADMIN_PERM
,
4906 .doit
= nl80211_addset_beacon
,
4907 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4908 NL80211_FLAG_NEED_RTNL
,
4911 .cmd
= NL80211_CMD_NEW_BEACON
,
4912 .policy
= nl80211_policy
,
4913 .flags
= GENL_ADMIN_PERM
,
4914 .doit
= nl80211_addset_beacon
,
4915 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4916 NL80211_FLAG_NEED_RTNL
,
4919 .cmd
= NL80211_CMD_DEL_BEACON
,
4920 .policy
= nl80211_policy
,
4921 .flags
= GENL_ADMIN_PERM
,
4922 .doit
= nl80211_del_beacon
,
4923 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4924 NL80211_FLAG_NEED_RTNL
,
4927 .cmd
= NL80211_CMD_GET_STATION
,
4928 .doit
= nl80211_get_station
,
4929 .dumpit
= nl80211_dump_station
,
4930 .policy
= nl80211_policy
,
4931 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4932 NL80211_FLAG_NEED_RTNL
,
4935 .cmd
= NL80211_CMD_SET_STATION
,
4936 .doit
= nl80211_set_station
,
4937 .policy
= nl80211_policy
,
4938 .flags
= GENL_ADMIN_PERM
,
4939 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4940 NL80211_FLAG_NEED_RTNL
,
4943 .cmd
= NL80211_CMD_NEW_STATION
,
4944 .doit
= nl80211_new_station
,
4945 .policy
= nl80211_policy
,
4946 .flags
= GENL_ADMIN_PERM
,
4947 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4948 NL80211_FLAG_NEED_RTNL
,
4951 .cmd
= NL80211_CMD_DEL_STATION
,
4952 .doit
= nl80211_del_station
,
4953 .policy
= nl80211_policy
,
4954 .flags
= GENL_ADMIN_PERM
,
4955 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4956 NL80211_FLAG_NEED_RTNL
,
4959 .cmd
= NL80211_CMD_GET_MPATH
,
4960 .doit
= nl80211_get_mpath
,
4961 .dumpit
= nl80211_dump_mpath
,
4962 .policy
= nl80211_policy
,
4963 .flags
= GENL_ADMIN_PERM
,
4964 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4965 NL80211_FLAG_NEED_RTNL
,
4968 .cmd
= NL80211_CMD_SET_MPATH
,
4969 .doit
= nl80211_set_mpath
,
4970 .policy
= nl80211_policy
,
4971 .flags
= GENL_ADMIN_PERM
,
4972 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4973 NL80211_FLAG_NEED_RTNL
,
4976 .cmd
= NL80211_CMD_NEW_MPATH
,
4977 .doit
= nl80211_new_mpath
,
4978 .policy
= nl80211_policy
,
4979 .flags
= GENL_ADMIN_PERM
,
4980 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4981 NL80211_FLAG_NEED_RTNL
,
4984 .cmd
= NL80211_CMD_DEL_MPATH
,
4985 .doit
= nl80211_del_mpath
,
4986 .policy
= nl80211_policy
,
4987 .flags
= GENL_ADMIN_PERM
,
4988 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4989 NL80211_FLAG_NEED_RTNL
,
4992 .cmd
= NL80211_CMD_SET_BSS
,
4993 .doit
= nl80211_set_bss
,
4994 .policy
= nl80211_policy
,
4995 .flags
= GENL_ADMIN_PERM
,
4996 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4997 NL80211_FLAG_NEED_RTNL
,
5000 .cmd
= NL80211_CMD_GET_REG
,
5001 .doit
= nl80211_get_reg
,
5002 .policy
= nl80211_policy
,
5003 /* can be retrieved by unprivileged users */
5006 .cmd
= NL80211_CMD_SET_REG
,
5007 .doit
= nl80211_set_reg
,
5008 .policy
= nl80211_policy
,
5009 .flags
= GENL_ADMIN_PERM
,
5012 .cmd
= NL80211_CMD_REQ_SET_REG
,
5013 .doit
= nl80211_req_set_reg
,
5014 .policy
= nl80211_policy
,
5015 .flags
= GENL_ADMIN_PERM
,
5018 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
5019 .doit
= nl80211_get_mesh_config
,
5020 .policy
= nl80211_policy
,
5021 /* can be retrieved by unprivileged users */
5022 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5023 NL80211_FLAG_NEED_RTNL
,
5026 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
5027 .doit
= nl80211_update_mesh_config
,
5028 .policy
= nl80211_policy
,
5029 .flags
= GENL_ADMIN_PERM
,
5030 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5031 NL80211_FLAG_NEED_RTNL
,
5034 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5035 .doit
= nl80211_trigger_scan
,
5036 .policy
= nl80211_policy
,
5037 .flags
= GENL_ADMIN_PERM
,
5038 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5039 NL80211_FLAG_NEED_RTNL
,
5042 .cmd
= NL80211_CMD_GET_SCAN
,
5043 .policy
= nl80211_policy
,
5044 .dumpit
= nl80211_dump_scan
,
5047 .cmd
= NL80211_CMD_AUTHENTICATE
,
5048 .doit
= nl80211_authenticate
,
5049 .policy
= nl80211_policy
,
5050 .flags
= GENL_ADMIN_PERM
,
5051 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5052 NL80211_FLAG_NEED_RTNL
,
5055 .cmd
= NL80211_CMD_ASSOCIATE
,
5056 .doit
= nl80211_associate
,
5057 .policy
= nl80211_policy
,
5058 .flags
= GENL_ADMIN_PERM
,
5059 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5060 NL80211_FLAG_NEED_RTNL
,
5063 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5064 .doit
= nl80211_deauthenticate
,
5065 .policy
= nl80211_policy
,
5066 .flags
= GENL_ADMIN_PERM
,
5067 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5068 NL80211_FLAG_NEED_RTNL
,
5071 .cmd
= NL80211_CMD_DISASSOCIATE
,
5072 .doit
= nl80211_disassociate
,
5073 .policy
= nl80211_policy
,
5074 .flags
= GENL_ADMIN_PERM
,
5075 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5076 NL80211_FLAG_NEED_RTNL
,
5079 .cmd
= NL80211_CMD_JOIN_IBSS
,
5080 .doit
= nl80211_join_ibss
,
5081 .policy
= nl80211_policy
,
5082 .flags
= GENL_ADMIN_PERM
,
5083 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5084 NL80211_FLAG_NEED_RTNL
,
5087 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5088 .doit
= nl80211_leave_ibss
,
5089 .policy
= nl80211_policy
,
5090 .flags
= GENL_ADMIN_PERM
,
5091 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5092 NL80211_FLAG_NEED_RTNL
,
5094 #ifdef CONFIG_NL80211_TESTMODE
5096 .cmd
= NL80211_CMD_TESTMODE
,
5097 .doit
= nl80211_testmode_do
,
5098 .policy
= nl80211_policy
,
5099 .flags
= GENL_ADMIN_PERM
,
5100 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5101 NL80211_FLAG_NEED_RTNL
,
5105 .cmd
= NL80211_CMD_CONNECT
,
5106 .doit
= nl80211_connect
,
5107 .policy
= nl80211_policy
,
5108 .flags
= GENL_ADMIN_PERM
,
5109 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5110 NL80211_FLAG_NEED_RTNL
,
5113 .cmd
= NL80211_CMD_DISCONNECT
,
5114 .doit
= nl80211_disconnect
,
5115 .policy
= nl80211_policy
,
5116 .flags
= GENL_ADMIN_PERM
,
5117 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5118 NL80211_FLAG_NEED_RTNL
,
5121 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5122 .doit
= nl80211_wiphy_netns
,
5123 .policy
= nl80211_policy
,
5124 .flags
= GENL_ADMIN_PERM
,
5125 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5126 NL80211_FLAG_NEED_RTNL
,
5129 .cmd
= NL80211_CMD_GET_SURVEY
,
5130 .policy
= nl80211_policy
,
5131 .dumpit
= nl80211_dump_survey
,
5134 .cmd
= NL80211_CMD_SET_PMKSA
,
5135 .doit
= nl80211_setdel_pmksa
,
5136 .policy
= nl80211_policy
,
5137 .flags
= GENL_ADMIN_PERM
,
5138 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5139 NL80211_FLAG_NEED_RTNL
,
5142 .cmd
= NL80211_CMD_DEL_PMKSA
,
5143 .doit
= nl80211_setdel_pmksa
,
5144 .policy
= nl80211_policy
,
5145 .flags
= GENL_ADMIN_PERM
,
5146 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5147 NL80211_FLAG_NEED_RTNL
,
5150 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5151 .doit
= nl80211_flush_pmksa
,
5152 .policy
= nl80211_policy
,
5153 .flags
= GENL_ADMIN_PERM
,
5154 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5155 NL80211_FLAG_NEED_RTNL
,
5158 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5159 .doit
= nl80211_remain_on_channel
,
5160 .policy
= nl80211_policy
,
5161 .flags
= GENL_ADMIN_PERM
,
5162 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5163 NL80211_FLAG_NEED_RTNL
,
5166 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5167 .doit
= nl80211_cancel_remain_on_channel
,
5168 .policy
= nl80211_policy
,
5169 .flags
= GENL_ADMIN_PERM
,
5170 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5171 NL80211_FLAG_NEED_RTNL
,
5174 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5175 .doit
= nl80211_set_tx_bitrate_mask
,
5176 .policy
= nl80211_policy
,
5177 .flags
= GENL_ADMIN_PERM
,
5178 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5179 NL80211_FLAG_NEED_RTNL
,
5182 .cmd
= NL80211_CMD_REGISTER_FRAME
,
5183 .doit
= nl80211_register_mgmt
,
5184 .policy
= nl80211_policy
,
5185 .flags
= GENL_ADMIN_PERM
,
5186 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5187 NL80211_FLAG_NEED_RTNL
,
5190 .cmd
= NL80211_CMD_FRAME
,
5191 .doit
= nl80211_tx_mgmt
,
5192 .policy
= nl80211_policy
,
5193 .flags
= GENL_ADMIN_PERM
,
5194 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5195 NL80211_FLAG_NEED_RTNL
,
5198 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
5199 .doit
= nl80211_tx_mgmt_cancel_wait
,
5200 .policy
= nl80211_policy
,
5201 .flags
= GENL_ADMIN_PERM
,
5202 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5203 NL80211_FLAG_NEED_RTNL
,
5206 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5207 .doit
= nl80211_set_power_save
,
5208 .policy
= nl80211_policy
,
5209 .flags
= GENL_ADMIN_PERM
,
5210 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5211 NL80211_FLAG_NEED_RTNL
,
5214 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5215 .doit
= nl80211_get_power_save
,
5216 .policy
= nl80211_policy
,
5217 /* can be retrieved by unprivileged users */
5218 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5219 NL80211_FLAG_NEED_RTNL
,
5222 .cmd
= NL80211_CMD_SET_CQM
,
5223 .doit
= nl80211_set_cqm
,
5224 .policy
= nl80211_policy
,
5225 .flags
= GENL_ADMIN_PERM
,
5226 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5227 NL80211_FLAG_NEED_RTNL
,
5230 .cmd
= NL80211_CMD_SET_CHANNEL
,
5231 .doit
= nl80211_set_channel
,
5232 .policy
= nl80211_policy
,
5233 .flags
= GENL_ADMIN_PERM
,
5234 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5235 NL80211_FLAG_NEED_RTNL
,
5238 .cmd
= NL80211_CMD_SET_WDS_PEER
,
5239 .doit
= nl80211_set_wds_peer
,
5240 .policy
= nl80211_policy
,
5241 .flags
= GENL_ADMIN_PERM
,
5242 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5243 NL80211_FLAG_NEED_RTNL
,
5246 .cmd
= NL80211_CMD_JOIN_MESH
,
5247 .doit
= nl80211_join_mesh
,
5248 .policy
= nl80211_policy
,
5249 .flags
= GENL_ADMIN_PERM
,
5250 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5251 NL80211_FLAG_NEED_RTNL
,
5254 .cmd
= NL80211_CMD_LEAVE_MESH
,
5255 .doit
= nl80211_leave_mesh
,
5256 .policy
= nl80211_policy
,
5257 .flags
= GENL_ADMIN_PERM
,
5258 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5259 NL80211_FLAG_NEED_RTNL
,
5263 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5267 /* multicast groups */
5268 static struct genl_multicast_group nl80211_config_mcgrp
= {
5271 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5274 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5275 .name
= "regulatory",
5278 /* notification functions */
5280 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5282 struct sk_buff
*msg
;
5284 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5288 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5293 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5294 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5297 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5298 struct cfg80211_registered_device
*rdev
)
5300 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5301 struct nlattr
*nest
;
5304 ASSERT_RDEV_LOCK(rdev
);
5309 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5311 goto nla_put_failure
;
5312 for (i
= 0; i
< req
->n_ssids
; i
++)
5313 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5314 nla_nest_end(msg
, nest
);
5316 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5318 goto nla_put_failure
;
5319 for (i
= 0; i
< req
->n_channels
; i
++)
5320 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5321 nla_nest_end(msg
, nest
);
5324 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5331 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5332 struct cfg80211_registered_device
*rdev
,
5333 struct net_device
*netdev
,
5334 u32 pid
, u32 seq
, int flags
,
5339 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5343 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5344 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5346 /* ignore errors and send incomplete event anyway */
5347 nl80211_add_scan_req(msg
, rdev
);
5349 return genlmsg_end(msg
, hdr
);
5352 genlmsg_cancel(msg
, hdr
);
5356 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5357 struct net_device
*netdev
)
5359 struct sk_buff
*msg
;
5361 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5365 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5366 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5371 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5372 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5375 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5376 struct net_device
*netdev
)
5378 struct sk_buff
*msg
;
5380 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5384 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5385 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5390 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5391 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5394 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5395 struct net_device
*netdev
)
5397 struct sk_buff
*msg
;
5399 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5403 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5404 NL80211_CMD_SCAN_ABORTED
) < 0) {
5409 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5410 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5414 * This can happen on global regulatory changes or device specific settings
5415 * based on custom world regulatory domains.
5417 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5419 struct sk_buff
*msg
;
5422 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5426 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5432 /* Userspace can always count this one always being set */
5433 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5435 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5436 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5437 NL80211_REGDOM_TYPE_WORLD
);
5438 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5439 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5440 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5441 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5443 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5444 NL80211_REGDOM_TYPE_INTERSECTION
);
5446 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5447 NL80211_REGDOM_TYPE_COUNTRY
);
5448 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5451 if (wiphy_idx_valid(request
->wiphy_idx
))
5452 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5454 if (genlmsg_end(msg
, hdr
) < 0) {
5460 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5467 genlmsg_cancel(msg
, hdr
);
5471 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5472 struct net_device
*netdev
,
5473 const u8
*buf
, size_t len
,
5474 enum nl80211_commands cmd
, gfp_t gfp
)
5476 struct sk_buff
*msg
;
5479 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5483 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5489 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5490 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5491 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5493 if (genlmsg_end(msg
, hdr
) < 0) {
5498 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5499 nl80211_mlme_mcgrp
.id
, gfp
);
5503 genlmsg_cancel(msg
, hdr
);
5507 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5508 struct net_device
*netdev
, const u8
*buf
,
5509 size_t len
, gfp_t gfp
)
5511 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5512 NL80211_CMD_AUTHENTICATE
, gfp
);
5515 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5516 struct net_device
*netdev
, const u8
*buf
,
5517 size_t len
, gfp_t gfp
)
5519 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5520 NL80211_CMD_ASSOCIATE
, gfp
);
5523 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5524 struct net_device
*netdev
, const u8
*buf
,
5525 size_t len
, gfp_t gfp
)
5527 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5528 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5531 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5532 struct net_device
*netdev
, const u8
*buf
,
5533 size_t len
, gfp_t gfp
)
5535 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5536 NL80211_CMD_DISASSOCIATE
, gfp
);
5539 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
5540 struct net_device
*netdev
, const u8
*buf
,
5541 size_t len
, gfp_t gfp
)
5543 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5544 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
5547 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
5548 struct net_device
*netdev
, const u8
*buf
,
5549 size_t len
, gfp_t gfp
)
5551 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5552 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
5555 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5556 struct net_device
*netdev
, int cmd
,
5557 const u8
*addr
, gfp_t gfp
)
5559 struct sk_buff
*msg
;
5562 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5566 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5572 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5573 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5574 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5575 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5577 if (genlmsg_end(msg
, hdr
) < 0) {
5582 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5583 nl80211_mlme_mcgrp
.id
, gfp
);
5587 genlmsg_cancel(msg
, hdr
);
5591 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5592 struct net_device
*netdev
, const u8
*addr
,
5595 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5599 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5600 struct net_device
*netdev
, const u8
*addr
,
5603 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5607 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5608 struct net_device
*netdev
, const u8
*bssid
,
5609 const u8
*req_ie
, size_t req_ie_len
,
5610 const u8
*resp_ie
, size_t resp_ie_len
,
5611 u16 status
, gfp_t gfp
)
5613 struct sk_buff
*msg
;
5616 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5620 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5626 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5627 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5629 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5630 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5632 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5634 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5636 if (genlmsg_end(msg
, hdr
) < 0) {
5641 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5642 nl80211_mlme_mcgrp
.id
, gfp
);
5646 genlmsg_cancel(msg
, hdr
);
5651 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5652 struct net_device
*netdev
, const u8
*bssid
,
5653 const u8
*req_ie
, size_t req_ie_len
,
5654 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5656 struct sk_buff
*msg
;
5659 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5663 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5669 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5670 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5671 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5673 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5675 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5677 if (genlmsg_end(msg
, hdr
) < 0) {
5682 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5683 nl80211_mlme_mcgrp
.id
, gfp
);
5687 genlmsg_cancel(msg
, hdr
);
5692 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5693 struct net_device
*netdev
, u16 reason
,
5694 const u8
*ie
, size_t ie_len
, bool from_ap
)
5696 struct sk_buff
*msg
;
5699 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5703 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5709 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5710 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5711 if (from_ap
&& reason
)
5712 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5714 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5716 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5718 if (genlmsg_end(msg
, hdr
) < 0) {
5723 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5724 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5728 genlmsg_cancel(msg
, hdr
);
5733 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5734 struct net_device
*netdev
, const u8
*bssid
,
5737 struct sk_buff
*msg
;
5740 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5744 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5750 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5751 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5752 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5754 if (genlmsg_end(msg
, hdr
) < 0) {
5759 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5760 nl80211_mlme_mcgrp
.id
, gfp
);
5764 genlmsg_cancel(msg
, hdr
);
5768 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5769 struct net_device
*netdev
, const u8
*addr
,
5770 enum nl80211_key_type key_type
, int key_id
,
5771 const u8
*tsc
, gfp_t gfp
)
5773 struct sk_buff
*msg
;
5776 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5780 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5786 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5787 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5789 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5790 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5791 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5793 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5795 if (genlmsg_end(msg
, hdr
) < 0) {
5800 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5801 nl80211_mlme_mcgrp
.id
, gfp
);
5805 genlmsg_cancel(msg
, hdr
);
5809 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5810 struct ieee80211_channel
*channel_before
,
5811 struct ieee80211_channel
*channel_after
)
5813 struct sk_buff
*msg
;
5815 struct nlattr
*nl_freq
;
5817 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5821 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5828 * Since we are applying the beacon hint to a wiphy we know its
5829 * wiphy_idx is valid
5831 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5834 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5836 goto nla_put_failure
;
5837 if (nl80211_msg_put_channel(msg
, channel_before
))
5838 goto nla_put_failure
;
5839 nla_nest_end(msg
, nl_freq
);
5842 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5844 goto nla_put_failure
;
5845 if (nl80211_msg_put_channel(msg
, channel_after
))
5846 goto nla_put_failure
;
5847 nla_nest_end(msg
, nl_freq
);
5849 if (genlmsg_end(msg
, hdr
) < 0) {
5855 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5862 genlmsg_cancel(msg
, hdr
);
5866 static void nl80211_send_remain_on_chan_event(
5867 int cmd
, struct cfg80211_registered_device
*rdev
,
5868 struct net_device
*netdev
, u64 cookie
,
5869 struct ieee80211_channel
*chan
,
5870 enum nl80211_channel_type channel_type
,
5871 unsigned int duration
, gfp_t gfp
)
5873 struct sk_buff
*msg
;
5876 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5880 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5886 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5887 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5888 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5889 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5890 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5892 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5893 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5895 if (genlmsg_end(msg
, hdr
) < 0) {
5900 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5901 nl80211_mlme_mcgrp
.id
, gfp
);
5905 genlmsg_cancel(msg
, hdr
);
5909 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
5910 struct net_device
*netdev
, u64 cookie
,
5911 struct ieee80211_channel
*chan
,
5912 enum nl80211_channel_type channel_type
,
5913 unsigned int duration
, gfp_t gfp
)
5915 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
5916 rdev
, netdev
, cookie
, chan
,
5917 channel_type
, duration
, gfp
);
5920 void nl80211_send_remain_on_channel_cancel(
5921 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
5922 u64 cookie
, struct ieee80211_channel
*chan
,
5923 enum nl80211_channel_type channel_type
, gfp_t gfp
)
5925 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5926 rdev
, netdev
, cookie
, chan
,
5927 channel_type
, 0, gfp
);
5930 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
5931 struct net_device
*dev
, const u8
*mac_addr
,
5932 struct station_info
*sinfo
, gfp_t gfp
)
5934 struct sk_buff
*msg
;
5936 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5940 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
5945 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5946 nl80211_mlme_mcgrp
.id
, gfp
);
5949 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
5950 struct net_device
*netdev
, u32 nlpid
,
5951 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
5953 struct sk_buff
*msg
;
5957 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5961 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
5967 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5968 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5969 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5970 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5972 err
= genlmsg_end(msg
, hdr
);
5978 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
5984 genlmsg_cancel(msg
, hdr
);
5989 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
5990 struct net_device
*netdev
, u64 cookie
,
5991 const u8
*buf
, size_t len
, bool ack
,
5994 struct sk_buff
*msg
;
5997 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6001 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
6007 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6008 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6009 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6010 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6012 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6014 if (genlmsg_end(msg
, hdr
) < 0) {
6019 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6023 genlmsg_cancel(msg
, hdr
);
6028 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6029 struct net_device
*netdev
,
6030 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6033 struct sk_buff
*msg
;
6034 struct nlattr
*pinfoattr
;
6037 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6041 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6047 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6048 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6050 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6052 goto nla_put_failure
;
6054 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6057 nla_nest_end(msg
, pinfoattr
);
6059 if (genlmsg_end(msg
, hdr
) < 0) {
6064 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6065 nl80211_mlme_mcgrp
.id
, gfp
);
6069 genlmsg_cancel(msg
, hdr
);
6074 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
6075 struct net_device
*netdev
, const u8
*peer
,
6076 u32 num_packets
, gfp_t gfp
)
6078 struct sk_buff
*msg
;
6079 struct nlattr
*pinfoattr
;
6082 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6086 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6092 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6093 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6094 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
6096 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6098 goto nla_put_failure
;
6100 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
6102 nla_nest_end(msg
, pinfoattr
);
6104 if (genlmsg_end(msg
, hdr
) < 0) {
6109 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6110 nl80211_mlme_mcgrp
.id
, gfp
);
6114 genlmsg_cancel(msg
, hdr
);
6118 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6119 unsigned long state
,
6122 struct netlink_notify
*notify
= _notify
;
6123 struct cfg80211_registered_device
*rdev
;
6124 struct wireless_dev
*wdev
;
6126 if (state
!= NETLINK_URELEASE
)
6131 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6132 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6133 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
6140 static struct notifier_block nl80211_netlink_notifier
= {
6141 .notifier_call
= nl80211_netlink_notify
,
6144 /* initialisation/exit functions */
6146 int nl80211_init(void)
6150 err
= genl_register_family_with_ops(&nl80211_fam
,
6151 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6155 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6159 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6163 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6167 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6171 #ifdef CONFIG_NL80211_TESTMODE
6172 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6177 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6183 genl_unregister_family(&nl80211_fam
);
6187 void nl80211_exit(void)
6189 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6190 genl_unregister_family(&nl80211_fam
);