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 bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
27 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
28 struct genl_info *info,
29 struct cfg80211_crypto_settings *settings,
32 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
35 struct genl_info *info);
37 /* the netlink family */
38 static struct genl_family nl80211_fam = {
39 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
40 .name = "nl80211", /* have users key off the name instead */
41 .hdrsize = 0, /* no private header */
42 .version = 1, /* no particular meaning now */
43 .maxattr = NL80211_ATTR_MAX,
45 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
49 /* returns ERR_PTR values */
50 static struct wireless_dev *
51 __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
53 struct cfg80211_registered_device *rdev;
54 struct wireless_dev *result = NULL;
55 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
56 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
61 assert_cfg80211_lock();
63 if (!have_ifidx && !have_wdev_id)
64 return ERR_PTR(-EINVAL);
67 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
70 wiphy_idx = wdev_id >> 32;
73 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
74 struct wireless_dev *wdev;
76 if (wiphy_net(&rdev->wiphy) != netns)
79 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
82 mutex_lock(&rdev->devlist_mtx);
83 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
94 mutex_unlock(&rdev->devlist_mtx);
102 return ERR_PTR(-ENODEV);
105 static struct cfg80211_registered_device *
106 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
108 struct cfg80211_registered_device *rdev = NULL, *tmp;
109 struct net_device *netdev;
111 assert_cfg80211_lock();
113 if (!attrs[NL80211_ATTR_WIPHY] &&
114 !attrs[NL80211_ATTR_IFINDEX] &&
115 !attrs[NL80211_ATTR_WDEV])
116 return ERR_PTR(-EINVAL);
118 if (attrs[NL80211_ATTR_WIPHY])
119 rdev = cfg80211_rdev_by_wiphy_idx(
120 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
122 if (attrs[NL80211_ATTR_WDEV]) {
123 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
124 struct wireless_dev *wdev;
127 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
129 /* make sure wdev exists */
130 mutex_lock(&tmp->devlist_mtx);
131 list_for_each_entry(wdev, &tmp->wdev_list, list) {
132 if (wdev->identifier != (u32)wdev_id)
137 mutex_unlock(&tmp->devlist_mtx);
142 if (rdev && tmp != rdev)
143 return ERR_PTR(-EINVAL);
148 if (attrs[NL80211_ATTR_IFINDEX]) {
149 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
150 netdev = dev_get_by_index(netns, ifindex);
152 if (netdev->ieee80211_ptr)
154 netdev->ieee80211_ptr->wiphy);
160 /* not wireless device -- return error */
162 return ERR_PTR(-EINVAL);
164 /* mismatch -- return error */
165 if (rdev && tmp != rdev)
166 return ERR_PTR(-EINVAL);
173 return ERR_PTR(-ENODEV);
175 if (netns != wiphy_net(&rdev->wiphy))
176 return ERR_PTR(-ENODEV);
182 * This function returns a pointer to the driver
183 * that the genl_info item that is passed refers to.
184 * If successful, it returns non-NULL and also locks
185 * the driver's mutex!
187 * This means that you need to call cfg80211_unlock_rdev()
188 * before being allowed to acquire &cfg80211_mutex!
190 * This is necessary because we need to lock the global
191 * mutex to get an item off the list safely, and then
192 * we lock the rdev mutex so it doesn't go away under us.
194 * We don't want to keep cfg80211_mutex locked
195 * for all the time in order to allow requests on
196 * other interfaces to go through at the same time.
198 * The result of this can be a PTR_ERR and hence must
199 * be checked with IS_ERR() for errors.
201 static struct cfg80211_registered_device *
202 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
204 struct cfg80211_registered_device *rdev;
206 mutex_lock(&cfg80211_mutex);
207 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
209 /* if it is not an error we grab the lock on
210 * it to assure it won't be going away while
211 * we operate on it */
213 mutex_lock(&rdev->mtx);
215 mutex_unlock(&cfg80211_mutex);
220 /* policy for the attributes */
221 static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
222 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
223 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
225 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
226 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
229 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
230 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
231 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
232 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
234 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
235 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
236 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
238 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
239 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
241 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
242 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
243 .len = WLAN_MAX_KEY_LEN },
244 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
245 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
246 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
247 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
248 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
250 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
251 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
252 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
254 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
255 .len = IEEE80211_MAX_DATA_LEN },
256 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
258 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
259 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
260 .len = NL80211_MAX_SUPP_RATES },
261 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
262 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
263 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
264 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
265 .len = IEEE80211_MAX_MESH_ID_LEN },
266 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
268 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
269 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
271 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
272 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
273 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
274 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
275 .len = NL80211_MAX_SUPP_RATES },
276 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
278 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
279 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
281 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
283 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
284 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_DATA_LEN },
286 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
287 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
289 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
290 .len = IEEE80211_MAX_SSID_LEN },
291 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
292 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
293 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
294 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
295 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
296 [NL80211_ATTR_STA_FLAGS2] = {
297 .len = sizeof(struct nl80211_sta_flag_update),
299 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
301 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
302 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
303 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
304 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
305 [NL80211_ATTR_PID] = { .type = NLA_U32 },
306 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
307 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
308 .len = WLAN_PMKID_LEN },
309 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
310 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
311 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
312 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
313 .len = IEEE80211_MAX_DATA_LEN },
314 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
315 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
316 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
317 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
318 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
319 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
321 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
322 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
323 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
324 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
325 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
326 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
327 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
328 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
329 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
330 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
331 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
332 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
333 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
335 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
336 .len = IEEE80211_MAX_DATA_LEN },
337 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
338 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
339 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
340 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
343 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
344 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
345 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
346 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
347 .len = IEEE80211_MAX_DATA_LEN },
348 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
349 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
351 .len = NL80211_HT_CAPABILITY_LEN
353 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
354 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
355 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
356 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
359 /* policy for the key attributes */
360 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
361 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
362 [NL80211_KEY_IDX] = { .type = NLA_U8 },
363 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
364 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
365 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
366 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
367 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
368 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
371 /* policy for the key default flags */
372 static const struct nla_policy
373 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
374 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
375 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
378 /* policy for WoWLAN attributes */
379 static const struct nla_policy
380 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
381 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
385 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
391 /* policy for GTK rekey offload attributes */
392 static const struct nla_policy
393 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
394 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
395 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
396 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
399 static const struct nla_policy
400 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
401 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
402 .len = IEEE80211_MAX_SSID_LEN },
403 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
406 /* ifidx get helper */
407 static int nl80211_get_ifidx(struct netlink_callback *cb)
411 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
412 nl80211_fam.attrbuf, nl80211_fam.maxattr,
417 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
420 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
426 static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
427 struct netlink_callback *cb,
428 struct cfg80211_registered_device **rdev,
429 struct net_device **dev)
431 int ifidx = cb->args[0];
435 ifidx = nl80211_get_ifidx(cb);
443 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
449 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
451 err = PTR_ERR(*rdev);
461 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
463 cfg80211_unlock_rdev(rdev);
468 static bool is_valid_ie_attr(const struct nlattr *attr)
476 pos = nla_data(attr);
497 /* message building helper */
498 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
501 /* since there is no private header just add the generic one */
502 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
505 static int nl80211_msg_put_channel(struct sk_buff *msg,
506 struct ieee80211_channel *chan)
508 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
510 goto nla_put_failure;
512 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
513 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
514 goto nla_put_failure;
515 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
516 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
517 goto nla_put_failure;
518 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
519 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
520 goto nla_put_failure;
521 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
522 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
523 goto nla_put_failure;
525 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
526 DBM_TO_MBM(chan->max_power)))
527 goto nla_put_failure;
535 /* netlink command implementations */
542 bool def_uni, def_multi;
545 static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
547 struct nlattr *tb[NL80211_KEY_MAX + 1];
548 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
553 k->def = !!tb[NL80211_KEY_DEFAULT];
554 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
563 if (tb[NL80211_KEY_IDX])
564 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
566 if (tb[NL80211_KEY_DATA]) {
567 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
568 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
571 if (tb[NL80211_KEY_SEQ]) {
572 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
573 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
576 if (tb[NL80211_KEY_CIPHER])
577 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
579 if (tb[NL80211_KEY_TYPE]) {
580 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
581 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
585 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
586 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
587 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
588 tb[NL80211_KEY_DEFAULT_TYPES],
589 nl80211_key_default_policy);
593 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
594 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
600 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
602 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
603 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
604 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
607 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
608 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
609 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
612 if (info->attrs[NL80211_ATTR_KEY_IDX])
613 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
615 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
616 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
618 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
619 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
628 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
629 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
630 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
634 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
635 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
636 int err = nla_parse_nested(
637 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
638 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
639 nl80211_key_default_policy);
643 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
644 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
650 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
654 memset(k, 0, sizeof(*k));
658 if (info->attrs[NL80211_ATTR_KEY])
659 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
661 err = nl80211_parse_key_old(info, k);
666 if (k->def && k->defmgmt)
670 if (k->def_uni || !k->def_multi)
676 if (k->idx < 4 || k->idx > 5)
679 if (k->idx < 0 || k->idx > 3)
682 if (k->idx < 0 || k->idx > 5)
690 static struct cfg80211_cached_keys *
691 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
694 struct key_parse parse;
696 struct cfg80211_cached_keys *result;
697 int rem, err, def = 0;
699 result = kzalloc(sizeof(*result), GFP_KERNEL);
701 return ERR_PTR(-ENOMEM);
704 result->defmgmt = -1;
706 nla_for_each_nested(key, keys, rem) {
707 memset(&parse, 0, sizeof(parse));
710 err = nl80211_parse_key_new(key, &parse);
716 if (parse.idx < 0 || parse.idx > 4)
722 result->def = parse.idx;
723 if (!parse.def_uni || !parse.def_multi)
725 } else if (parse.defmgmt)
727 err = cfg80211_validate_key_settings(rdev, &parse.p,
728 parse.idx, false, NULL);
731 result->params[parse.idx].cipher = parse.p.cipher;
732 result->params[parse.idx].key_len = parse.p.key_len;
733 result->params[parse.idx].key = result->data[parse.idx];
734 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
743 static int nl80211_key_allowed(struct wireless_dev *wdev)
745 ASSERT_WDEV_LOCK(wdev);
747 switch (wdev->iftype) {
748 case NL80211_IFTYPE_AP:
749 case NL80211_IFTYPE_AP_VLAN:
750 case NL80211_IFTYPE_P2P_GO:
751 case NL80211_IFTYPE_MESH_POINT:
753 case NL80211_IFTYPE_ADHOC:
754 if (!wdev->current_bss)
757 case NL80211_IFTYPE_STATION:
758 case NL80211_IFTYPE_P2P_CLIENT:
759 if (wdev->sme_state != CFG80211_SME_CONNECTED)
769 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
771 struct nlattr *nl_modes = nla_nest_start(msg, attr);
775 goto nla_put_failure;
779 if ((ifmodes & 1) && nla_put_flag(msg, i))
780 goto nla_put_failure;
785 nla_nest_end(msg, nl_modes);
792 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
795 struct nlattr *nl_combis;
798 nl_combis = nla_nest_start(msg,
799 NL80211_ATTR_INTERFACE_COMBINATIONS);
801 goto nla_put_failure;
803 for (i = 0; i < wiphy->n_iface_combinations; i++) {
804 const struct ieee80211_iface_combination *c;
805 struct nlattr *nl_combi, *nl_limits;
807 c = &wiphy->iface_combinations[i];
809 nl_combi = nla_nest_start(msg, i + 1);
811 goto nla_put_failure;
813 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
815 goto nla_put_failure;
817 for (j = 0; j < c->n_limits; j++) {
818 struct nlattr *nl_limit;
820 nl_limit = nla_nest_start(msg, j + 1);
822 goto nla_put_failure;
823 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
825 goto nla_put_failure;
826 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
828 goto nla_put_failure;
829 nla_nest_end(msg, nl_limit);
832 nla_nest_end(msg, nl_limits);
834 if (c->beacon_int_infra_match &&
835 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
836 goto nla_put_failure;
837 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
838 c->num_different_channels) ||
839 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
841 goto nla_put_failure;
843 nla_nest_end(msg, nl_combi);
846 nla_nest_end(msg, nl_combis);
853 static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
854 struct cfg80211_registered_device *dev)
857 struct nlattr *nl_bands, *nl_band;
858 struct nlattr *nl_freqs, *nl_freq;
859 struct nlattr *nl_rates, *nl_rate;
860 struct nlattr *nl_cmds;
861 enum ieee80211_band band;
862 struct ieee80211_channel *chan;
863 struct ieee80211_rate *rate;
865 const struct ieee80211_txrx_stypes *mgmt_stypes =
866 dev->wiphy.mgmt_stypes;
868 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
872 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
873 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
874 nla_put_u32(msg, NL80211_ATTR_GENERATION,
875 cfg80211_rdev_list_generation) ||
876 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
877 dev->wiphy.retry_short) ||
878 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
879 dev->wiphy.retry_long) ||
880 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
881 dev->wiphy.frag_threshold) ||
882 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
883 dev->wiphy.rts_threshold) ||
884 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
885 dev->wiphy.coverage_class) ||
886 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
887 dev->wiphy.max_scan_ssids) ||
888 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
889 dev->wiphy.max_sched_scan_ssids) ||
890 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
891 dev->wiphy.max_scan_ie_len) ||
892 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
893 dev->wiphy.max_sched_scan_ie_len) ||
894 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
895 dev->wiphy.max_match_sets))
896 goto nla_put_failure;
898 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
899 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
900 goto nla_put_failure;
901 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
902 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
903 goto nla_put_failure;
904 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
905 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
906 goto nla_put_failure;
907 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
908 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
909 goto nla_put_failure;
910 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
911 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
912 goto nla_put_failure;
913 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
914 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
915 goto nla_put_failure;
917 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
918 sizeof(u32) * dev->wiphy.n_cipher_suites,
919 dev->wiphy.cipher_suites))
920 goto nla_put_failure;
922 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
923 dev->wiphy.max_num_pmkids))
924 goto nla_put_failure;
926 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
927 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
928 goto nla_put_failure;
930 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
931 dev->wiphy.available_antennas_tx) ||
932 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
933 dev->wiphy.available_antennas_rx))
934 goto nla_put_failure;
936 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
937 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
938 dev->wiphy.probe_resp_offload))
939 goto nla_put_failure;
941 if ((dev->wiphy.available_antennas_tx ||
942 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
943 u32 tx_ant = 0, rx_ant = 0;
945 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
947 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
949 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
951 goto nla_put_failure;
955 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
956 dev->wiphy.interface_modes))
957 goto nla_put_failure;
959 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
961 goto nla_put_failure;
963 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
964 if (!dev->wiphy.bands[band])
967 nl_band = nla_nest_start(msg, band);
969 goto nla_put_failure;
972 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
973 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
974 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
975 &dev->wiphy.bands[band]->ht_cap.mcs) ||
976 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
977 dev->wiphy.bands[band]->ht_cap.cap) ||
978 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
979 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
980 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
981 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
982 goto nla_put_failure;
985 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
986 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
987 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
988 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
989 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
990 dev->wiphy.bands[band]->vht_cap.cap)))
991 goto nla_put_failure;
993 /* add frequencies */
994 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
996 goto nla_put_failure;
998 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
999 nl_freq = nla_nest_start(msg, i);
1001 goto nla_put_failure;
1003 chan = &dev->wiphy.bands[band]->channels[i];
1005 if (nl80211_msg_put_channel(msg, chan))
1006 goto nla_put_failure;
1008 nla_nest_end(msg, nl_freq);
1011 nla_nest_end(msg, nl_freqs);
1014 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1016 goto nla_put_failure;
1018 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1019 nl_rate = nla_nest_start(msg, i);
1021 goto nla_put_failure;
1023 rate = &dev->wiphy.bands[band]->bitrates[i];
1024 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1026 goto nla_put_failure;
1027 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1029 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1030 goto nla_put_failure;
1032 nla_nest_end(msg, nl_rate);
1035 nla_nest_end(msg, nl_rates);
1037 nla_nest_end(msg, nl_band);
1039 nla_nest_end(msg, nl_bands);
1041 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1043 goto nla_put_failure;
1046 #define CMD(op, n) \
1048 if (dev->ops->op) { \
1050 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1051 goto nla_put_failure; \
1055 CMD(add_virtual_intf, NEW_INTERFACE);
1056 CMD(change_virtual_intf, SET_INTERFACE);
1057 CMD(add_key, NEW_KEY);
1058 CMD(start_ap, START_AP);
1059 CMD(add_station, NEW_STATION);
1060 CMD(add_mpath, NEW_MPATH);
1061 CMD(update_mesh_config, SET_MESH_CONFIG);
1062 CMD(change_bss, SET_BSS);
1063 CMD(auth, AUTHENTICATE);
1064 CMD(assoc, ASSOCIATE);
1065 CMD(deauth, DEAUTHENTICATE);
1066 CMD(disassoc, DISASSOCIATE);
1067 CMD(join_ibss, JOIN_IBSS);
1068 CMD(join_mesh, JOIN_MESH);
1069 CMD(set_pmksa, SET_PMKSA);
1070 CMD(del_pmksa, DEL_PMKSA);
1071 CMD(flush_pmksa, FLUSH_PMKSA);
1072 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1073 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1074 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1075 CMD(mgmt_tx, FRAME);
1076 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1077 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1079 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1080 goto nla_put_failure;
1082 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1083 dev->ops->join_mesh) {
1085 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1086 goto nla_put_failure;
1088 CMD(set_wds_peer, SET_WDS_PEER);
1089 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1090 CMD(tdls_mgmt, TDLS_MGMT);
1091 CMD(tdls_oper, TDLS_OPER);
1093 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1094 CMD(sched_scan_start, START_SCHED_SCAN);
1095 CMD(probe_client, PROBE_CLIENT);
1096 CMD(set_noack_map, SET_NOACK_MAP);
1097 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1099 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1100 goto nla_put_failure;
1103 #ifdef CONFIG_NL80211_TESTMODE
1104 CMD(testmode_cmd, TESTMODE);
1109 if (dev->ops->connect || dev->ops->auth) {
1111 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1112 goto nla_put_failure;
1115 if (dev->ops->disconnect || dev->ops->deauth) {
1117 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1118 goto nla_put_failure;
1121 nla_nest_end(msg, nl_cmds);
1123 if (dev->ops->remain_on_channel &&
1124 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1125 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1126 dev->wiphy.max_remain_on_channel_duration))
1127 goto nla_put_failure;
1129 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1130 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1131 goto nla_put_failure;
1135 struct nlattr *nl_ftypes, *nl_ifs;
1136 enum nl80211_iftype ift;
1138 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1140 goto nla_put_failure;
1142 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1143 nl_ftypes = nla_nest_start(msg, ift);
1145 goto nla_put_failure;
1147 stypes = mgmt_stypes[ift].tx;
1150 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1151 (i << 4) | IEEE80211_FTYPE_MGMT))
1152 goto nla_put_failure;
1156 nla_nest_end(msg, nl_ftypes);
1159 nla_nest_end(msg, nl_ifs);
1161 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1163 goto nla_put_failure;
1165 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1166 nl_ftypes = nla_nest_start(msg, ift);
1168 goto nla_put_failure;
1170 stypes = mgmt_stypes[ift].rx;
1173 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1174 (i << 4) | IEEE80211_FTYPE_MGMT))
1175 goto nla_put_failure;
1179 nla_nest_end(msg, nl_ftypes);
1181 nla_nest_end(msg, nl_ifs);
1185 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1186 struct nlattr *nl_wowlan;
1188 nl_wowlan = nla_nest_start(msg,
1189 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1191 goto nla_put_failure;
1193 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1194 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1195 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1196 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1197 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1198 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1199 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1200 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1201 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1202 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1203 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1204 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1205 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1206 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1207 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1208 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1209 goto nla_put_failure;
1210 if (dev->wiphy.wowlan.n_patterns) {
1211 struct nl80211_wowlan_pattern_support pat = {
1212 .max_patterns = dev->wiphy.wowlan.n_patterns,
1214 dev->wiphy.wowlan.pattern_min_len,
1216 dev->wiphy.wowlan.pattern_max_len,
1218 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1220 goto nla_put_failure;
1223 nla_nest_end(msg, nl_wowlan);
1227 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1228 dev->wiphy.software_iftypes))
1229 goto nla_put_failure;
1231 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1232 goto nla_put_failure;
1234 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1235 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1236 dev->wiphy.ap_sme_capa))
1237 goto nla_put_failure;
1239 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1240 dev->wiphy.features))
1241 goto nla_put_failure;
1243 if (dev->wiphy.ht_capa_mod_mask &&
1244 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1245 sizeof(*dev->wiphy.ht_capa_mod_mask),
1246 dev->wiphy.ht_capa_mod_mask))
1247 goto nla_put_failure;
1249 return genlmsg_end(msg, hdr);
1252 genlmsg_cancel(msg, hdr);
1256 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1259 int start = cb->args[0];
1260 struct cfg80211_registered_device *dev;
1262 mutex_lock(&cfg80211_mutex);
1263 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
1264 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1268 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1269 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1275 mutex_unlock(&cfg80211_mutex);
1282 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1284 struct sk_buff *msg;
1285 struct cfg80211_registered_device *dev = info->user_ptr[0];
1287 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1291 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1296 return genlmsg_reply(msg, info);
1299 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1300 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1301 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1302 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1303 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1304 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1307 static int parse_txq_params(struct nlattr *tb[],
1308 struct ieee80211_txq_params *txq_params)
1310 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1311 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1312 !tb[NL80211_TXQ_ATTR_AIFS])
1315 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
1316 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1317 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1318 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1319 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1321 if (txq_params->ac >= NL80211_NUM_ACS)
1327 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1330 * You can only set the channel explicitly for WDS interfaces,
1331 * all others have their channel managed via their respective
1332 * "establish a connection" command (connect, join, ...)
1334 * For AP/GO and mesh mode, the channel can be set with the
1335 * channel userspace API, but is only stored and passed to the
1336 * low-level driver when the AP starts or the mesh is joined.
1337 * This is for backward compatibility, userspace can also give
1338 * the channel in the start-ap or join-mesh commands instead.
1340 * Monitors are special as they are normally slaved to
1341 * whatever else is going on, so they have their own special
1342 * operation to set the monitor channel if possible.
1345 wdev->iftype == NL80211_IFTYPE_AP ||
1346 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
1347 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1348 wdev->iftype == NL80211_IFTYPE_P2P_GO;
1351 static bool nl80211_valid_channel_type(struct genl_info *info,
1352 enum nl80211_channel_type *channel_type)
1354 enum nl80211_channel_type tmp;
1356 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1359 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1360 if (tmp != NL80211_CHAN_NO_HT &&
1361 tmp != NL80211_CHAN_HT20 &&
1362 tmp != NL80211_CHAN_HT40PLUS &&
1363 tmp != NL80211_CHAN_HT40MINUS)
1367 *channel_type = tmp;
1372 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1373 struct wireless_dev *wdev,
1374 struct genl_info *info)
1376 struct ieee80211_channel *channel;
1377 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1380 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1383 iftype = wdev->iftype;
1385 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1388 if (!nl80211_can_set_dev_channel(wdev))
1391 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1392 !nl80211_valid_channel_type(info, &channel_type))
1395 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1397 mutex_lock(&rdev->devlist_mtx);
1399 case NL80211_IFTYPE_AP:
1400 case NL80211_IFTYPE_P2P_GO:
1401 if (wdev->beacon_interval) {
1405 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1406 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1412 wdev->preset_chan = channel;
1413 wdev->preset_chantype = channel_type;
1416 case NL80211_IFTYPE_MESH_POINT:
1417 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1419 case NL80211_IFTYPE_MONITOR:
1420 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1425 mutex_unlock(&rdev->devlist_mtx);
1430 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1433 struct net_device *netdev = info->user_ptr[1];
1435 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
1438 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1441 struct net_device *dev = info->user_ptr[1];
1442 struct wireless_dev *wdev = dev->ieee80211_ptr;
1445 if (!info->attrs[NL80211_ATTR_MAC])
1448 if (netif_running(dev))
1451 if (!rdev->ops->set_wds_peer)
1454 if (wdev->iftype != NL80211_IFTYPE_WDS)
1457 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
1458 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
1462 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1464 struct cfg80211_registered_device *rdev;
1465 struct net_device *netdev = NULL;
1466 struct wireless_dev *wdev;
1467 int result = 0, rem_txq_params = 0;
1468 struct nlattr *nl_txq_params;
1470 u8 retry_short = 0, retry_long = 0;
1471 u32 frag_threshold = 0, rts_threshold = 0;
1472 u8 coverage_class = 0;
1475 * Try to find the wiphy and netdev. Normally this
1476 * function shouldn't need the netdev, but this is
1477 * done for backward compatibility -- previously
1478 * setting the channel was done per wiphy, but now
1479 * it is per netdev. Previous userland like hostapd
1480 * also passed a netdev to set_wiphy, so that it is
1481 * possible to let that go to the right netdev!
1483 mutex_lock(&cfg80211_mutex);
1485 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1486 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1488 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1489 if (netdev && netdev->ieee80211_ptr) {
1490 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1491 mutex_lock(&rdev->mtx);
1497 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1500 mutex_unlock(&cfg80211_mutex);
1501 return PTR_ERR(rdev);
1507 mutex_lock(&rdev->mtx);
1508 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1509 wdev = netdev->ieee80211_ptr;
1514 * end workaround code, by now the rdev is available
1515 * and locked, and wdev may or may not be NULL.
1518 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
1519 result = cfg80211_dev_rename(
1520 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
1522 mutex_unlock(&cfg80211_mutex);
1527 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1528 struct ieee80211_txq_params txq_params;
1529 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1531 if (!rdev->ops->set_txq_params) {
1532 result = -EOPNOTSUPP;
1541 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1542 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1547 if (!netif_running(netdev)) {
1552 nla_for_each_nested(nl_txq_params,
1553 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1555 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1556 nla_data(nl_txq_params),
1557 nla_len(nl_txq_params),
1559 result = parse_txq_params(tb, &txq_params);
1563 result = rdev->ops->set_txq_params(&rdev->wiphy,
1571 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
1572 result = __nl80211_set_channel(rdev, wdev, info);
1577 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1578 enum nl80211_tx_power_setting type;
1581 if (!rdev->ops->set_tx_power) {
1582 result = -EOPNOTSUPP;
1586 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1587 type = nla_get_u32(info->attrs[idx]);
1589 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1590 (type != NL80211_TX_POWER_AUTOMATIC)) {
1595 if (type != NL80211_TX_POWER_AUTOMATIC) {
1596 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1597 mbm = nla_get_u32(info->attrs[idx]);
1600 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1605 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1606 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1608 if ((!rdev->wiphy.available_antennas_tx &&
1609 !rdev->wiphy.available_antennas_rx) ||
1610 !rdev->ops->set_antenna) {
1611 result = -EOPNOTSUPP;
1615 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1616 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1618 /* reject antenna configurations which don't match the
1619 * available antenna masks, except for the "all" mask */
1620 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1621 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
1626 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1627 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
1629 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1636 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1637 retry_short = nla_get_u8(
1638 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1639 if (retry_short == 0) {
1643 changed |= WIPHY_PARAM_RETRY_SHORT;
1646 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1647 retry_long = nla_get_u8(
1648 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1649 if (retry_long == 0) {
1653 changed |= WIPHY_PARAM_RETRY_LONG;
1656 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1657 frag_threshold = nla_get_u32(
1658 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1659 if (frag_threshold < 256) {
1663 if (frag_threshold != (u32) -1) {
1665 * Fragments (apart from the last one) are required to
1666 * have even length. Make the fragmentation code
1667 * simpler by stripping LSB should someone try to use
1668 * odd threshold value.
1670 frag_threshold &= ~0x1;
1672 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1675 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1676 rts_threshold = nla_get_u32(
1677 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1678 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1681 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1682 coverage_class = nla_get_u8(
1683 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1684 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1688 u8 old_retry_short, old_retry_long;
1689 u32 old_frag_threshold, old_rts_threshold;
1690 u8 old_coverage_class;
1692 if (!rdev->ops->set_wiphy_params) {
1693 result = -EOPNOTSUPP;
1697 old_retry_short = rdev->wiphy.retry_short;
1698 old_retry_long = rdev->wiphy.retry_long;
1699 old_frag_threshold = rdev->wiphy.frag_threshold;
1700 old_rts_threshold = rdev->wiphy.rts_threshold;
1701 old_coverage_class = rdev->wiphy.coverage_class;
1703 if (changed & WIPHY_PARAM_RETRY_SHORT)
1704 rdev->wiphy.retry_short = retry_short;
1705 if (changed & WIPHY_PARAM_RETRY_LONG)
1706 rdev->wiphy.retry_long = retry_long;
1707 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1708 rdev->wiphy.frag_threshold = frag_threshold;
1709 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1710 rdev->wiphy.rts_threshold = rts_threshold;
1711 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1712 rdev->wiphy.coverage_class = coverage_class;
1714 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1716 rdev->wiphy.retry_short = old_retry_short;
1717 rdev->wiphy.retry_long = old_retry_long;
1718 rdev->wiphy.frag_threshold = old_frag_threshold;
1719 rdev->wiphy.rts_threshold = old_rts_threshold;
1720 rdev->wiphy.coverage_class = old_coverage_class;
1725 mutex_unlock(&rdev->mtx);
1731 static inline u64 wdev_id(struct wireless_dev *wdev)
1733 return (u64)wdev->identifier |
1734 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
1737 static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
1738 struct cfg80211_registered_device *rdev,
1739 struct wireless_dev *wdev)
1741 struct net_device *dev = wdev->netdev;
1744 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1749 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1750 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1751 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dev->dev_addr)))
1752 goto nla_put_failure;
1754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1755 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
1756 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
1757 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1758 rdev->devlist_generation ^
1759 (cfg80211_rdev_list_generation << 2)))
1760 goto nla_put_failure;
1762 if (rdev->ops->get_channel) {
1763 struct ieee80211_channel *chan;
1764 enum nl80211_channel_type channel_type;
1766 chan = rdev->ops->get_channel(&rdev->wiphy, wdev,
1769 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1770 chan->center_freq) ||
1771 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1773 goto nla_put_failure;
1776 return genlmsg_end(msg, hdr);
1779 genlmsg_cancel(msg, hdr);
1783 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1787 int wp_start = cb->args[0];
1788 int if_start = cb->args[1];
1789 struct cfg80211_registered_device *rdev;
1790 struct wireless_dev *wdev;
1792 mutex_lock(&cfg80211_mutex);
1793 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1794 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
1796 if (wp_idx < wp_start) {
1802 mutex_lock(&rdev->devlist_mtx);
1803 list_for_each_entry(wdev, &rdev->wdev_list, list) {
1804 if (if_idx < if_start) {
1808 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1809 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1811 mutex_unlock(&rdev->devlist_mtx);
1816 mutex_unlock(&rdev->devlist_mtx);
1821 mutex_unlock(&cfg80211_mutex);
1823 cb->args[0] = wp_idx;
1824 cb->args[1] = if_idx;
1829 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1831 struct sk_buff *msg;
1832 struct cfg80211_registered_device *dev = info->user_ptr[0];
1833 struct wireless_dev *wdev = info->user_ptr[1];
1835 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1839 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
1845 return genlmsg_reply(msg, info);
1848 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1849 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1850 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1851 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1852 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1853 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1856 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1858 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1866 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1867 nla, mntr_flags_policy))
1870 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1872 *mntrflags |= (1<<flag);
1877 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
1878 struct net_device *netdev, u8 use_4addr,
1879 enum nl80211_iftype iftype)
1882 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
1888 case NL80211_IFTYPE_AP_VLAN:
1889 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1892 case NL80211_IFTYPE_STATION:
1893 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1903 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1906 struct vif_params params;
1908 enum nl80211_iftype otype, ntype;
1909 struct net_device *dev = info->user_ptr[1];
1910 u32 _flags, *flags = NULL;
1911 bool change = false;
1913 memset(¶ms, 0, sizeof(params));
1915 otype = ntype = dev->ieee80211_ptr->iftype;
1917 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1918 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1921 if (ntype > NL80211_IFTYPE_MAX)
1925 if (info->attrs[NL80211_ATTR_MESH_ID]) {
1926 struct wireless_dev *wdev = dev->ieee80211_ptr;
1928 if (ntype != NL80211_IFTYPE_MESH_POINT)
1930 if (netif_running(dev))
1934 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1935 IEEE80211_MAX_MESH_ID_LEN);
1936 wdev->mesh_id_up_len =
1937 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1938 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1939 wdev->mesh_id_up_len);
1943 if (info->attrs[NL80211_ATTR_4ADDR]) {
1944 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1946 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
1950 params.use_4addr = -1;
1953 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
1954 if (ntype != NL80211_IFTYPE_MONITOR)
1956 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1966 err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms);
1970 if (!err && params.use_4addr != -1)
1971 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1976 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1979 struct vif_params params;
1980 struct wireless_dev *wdev;
1981 struct sk_buff *msg;
1983 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
1986 memset(¶ms, 0, sizeof(params));
1988 if (!info->attrs[NL80211_ATTR_IFNAME])
1991 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1992 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1993 if (type > NL80211_IFTYPE_MAX)
1997 if (!rdev->ops->add_virtual_intf ||
1998 !(rdev->wiphy.interface_modes & (1 << type)))
2001 if (info->attrs[NL80211_ATTR_4ADDR]) {
2002 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2003 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
2008 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2012 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2013 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2015 wdev = rdev->ops->add_virtual_intf(&rdev->wiphy,
2016 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2017 type, err ? NULL : &flags, ¶ms);
2020 return PTR_ERR(wdev);
2023 if (type == NL80211_IFTYPE_MESH_POINT &&
2024 info->attrs[NL80211_ATTR_MESH_ID]) {
2026 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2027 IEEE80211_MAX_MESH_ID_LEN);
2028 wdev->mesh_id_up_len =
2029 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2030 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2031 wdev->mesh_id_up_len);
2035 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
2041 return genlmsg_reply(msg, info);
2044 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2046 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2047 struct wireless_dev *wdev = info->user_ptr[1];
2049 if (!rdev->ops->del_virtual_intf)
2053 * If we remove a wireless device without a netdev then clear
2054 * user_ptr[1] so that nl80211_post_doit won't dereference it
2055 * to check if it needs to do dev_put(). Otherwise it crashes
2056 * since the wdev has been freed, unlike with a netdev where
2057 * we need the dev_put() for the netdev to really be freed.
2060 info->user_ptr[1] = NULL;
2062 return rdev->ops->del_virtual_intf(&rdev->wiphy, wdev);
2065 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2068 struct net_device *dev = info->user_ptr[1];
2071 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2074 if (!rdev->ops->set_noack_map)
2077 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2079 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
2082 struct get_key_cookie {
2083 struct sk_buff *msg;
2088 static void get_key_callback(void *c, struct key_params *params)
2091 struct get_key_cookie *cookie = c;
2094 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2095 params->key_len, params->key)) ||
2097 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2098 params->seq_len, params->seq)) ||
2100 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2102 goto nla_put_failure;
2104 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2106 goto nla_put_failure;
2109 nla_put(cookie->msg, NL80211_KEY_DATA,
2110 params->key_len, params->key)) ||
2112 nla_put(cookie->msg, NL80211_KEY_SEQ,
2113 params->seq_len, params->seq)) ||
2115 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2117 goto nla_put_failure;
2119 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2120 goto nla_put_failure;
2122 nla_nest_end(cookie->msg, key);
2129 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2133 struct net_device *dev = info->user_ptr[1];
2135 const u8 *mac_addr = NULL;
2137 struct get_key_cookie cookie = {
2141 struct sk_buff *msg;
2143 if (info->attrs[NL80211_ATTR_KEY_IDX])
2144 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2149 if (info->attrs[NL80211_ATTR_MAC])
2150 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2152 pairwise = !!mac_addr;
2153 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2154 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2155 if (kt >= NUM_NL80211_KEYTYPES)
2157 if (kt != NL80211_KEYTYPE_GROUP &&
2158 kt != NL80211_KEYTYPE_PAIRWISE)
2160 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2163 if (!rdev->ops->get_key)
2166 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2170 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2171 NL80211_CMD_NEW_KEY);
2173 return PTR_ERR(hdr);
2176 cookie.idx = key_idx;
2178 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2179 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2180 goto nla_put_failure;
2182 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2183 goto nla_put_failure;
2185 if (pairwise && mac_addr &&
2186 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2189 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2190 mac_addr, &cookie, get_key_callback);
2196 goto nla_put_failure;
2198 genlmsg_end(msg, hdr);
2199 return genlmsg_reply(msg, info);
2208 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2211 struct key_parse key;
2213 struct net_device *dev = info->user_ptr[1];
2215 err = nl80211_parse_key(info, &key);
2222 /* only support setting default key */
2223 if (!key.def && !key.defmgmt)
2226 wdev_lock(dev->ieee80211_ptr);
2229 if (!rdev->ops->set_default_key) {
2234 err = nl80211_key_allowed(dev->ieee80211_ptr);
2238 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2239 key.def_uni, key.def_multi);
2244 #ifdef CONFIG_CFG80211_WEXT
2245 dev->ieee80211_ptr->wext.default_key = key.idx;
2248 if (key.def_uni || !key.def_multi) {
2253 if (!rdev->ops->set_default_mgmt_key) {
2258 err = nl80211_key_allowed(dev->ieee80211_ptr);
2262 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2267 #ifdef CONFIG_CFG80211_WEXT
2268 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2273 wdev_unlock(dev->ieee80211_ptr);
2278 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2282 struct net_device *dev = info->user_ptr[1];
2283 struct key_parse key;
2284 const u8 *mac_addr = NULL;
2286 err = nl80211_parse_key(info, &key);
2293 if (info->attrs[NL80211_ATTR_MAC])
2294 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2296 if (key.type == -1) {
2298 key.type = NL80211_KEYTYPE_PAIRWISE;
2300 key.type = NL80211_KEYTYPE_GROUP;
2304 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2305 key.type != NL80211_KEYTYPE_GROUP)
2308 if (!rdev->ops->add_key)
2311 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2312 key.type == NL80211_KEYTYPE_PAIRWISE,
2316 wdev_lock(dev->ieee80211_ptr);
2317 err = nl80211_key_allowed(dev->ieee80211_ptr);
2319 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
2320 key.type == NL80211_KEYTYPE_PAIRWISE,
2322 wdev_unlock(dev->ieee80211_ptr);
2327 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2331 struct net_device *dev = info->user_ptr[1];
2332 u8 *mac_addr = NULL;
2333 struct key_parse key;
2335 err = nl80211_parse_key(info, &key);
2339 if (info->attrs[NL80211_ATTR_MAC])
2340 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2342 if (key.type == -1) {
2344 key.type = NL80211_KEYTYPE_PAIRWISE;
2346 key.type = NL80211_KEYTYPE_GROUP;
2350 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2351 key.type != NL80211_KEYTYPE_GROUP)
2354 if (!rdev->ops->del_key)
2357 wdev_lock(dev->ieee80211_ptr);
2358 err = nl80211_key_allowed(dev->ieee80211_ptr);
2360 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2361 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2365 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2366 key.type == NL80211_KEYTYPE_PAIRWISE,
2369 #ifdef CONFIG_CFG80211_WEXT
2371 if (key.idx == dev->ieee80211_ptr->wext.default_key)
2372 dev->ieee80211_ptr->wext.default_key = -1;
2373 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
2374 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2377 wdev_unlock(dev->ieee80211_ptr);
2382 static int nl80211_parse_beacon(struct genl_info *info,
2383 struct cfg80211_beacon_data *bcn)
2385 bool haveinfo = false;
2387 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2388 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2389 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2390 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
2393 memset(bcn, 0, sizeof(*bcn));
2395 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2396 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2397 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2403 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2404 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2406 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2413 if (info->attrs[NL80211_ATTR_IE]) {
2414 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2415 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2418 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
2419 bcn->proberesp_ies =
2420 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2421 bcn->proberesp_ies_len =
2422 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2425 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
2426 bcn->assocresp_ies =
2427 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2428 bcn->assocresp_ies_len =
2429 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2432 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
2434 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
2435 bcn->probe_resp_len =
2436 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2442 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2443 struct cfg80211_ap_settings *params)
2445 struct wireless_dev *wdev;
2448 mutex_lock(&rdev->devlist_mtx);
2450 list_for_each_entry(wdev, &rdev->wdev_list, list) {
2451 if (wdev->iftype != NL80211_IFTYPE_AP &&
2452 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2455 if (!wdev->preset_chan)
2458 params->channel = wdev->preset_chan;
2459 params->channel_type = wdev->preset_chantype;
2464 mutex_unlock(&rdev->devlist_mtx);
2469 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2471 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2472 struct net_device *dev = info->user_ptr[1];
2473 struct wireless_dev *wdev = dev->ieee80211_ptr;
2474 struct cfg80211_ap_settings params;
2477 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2478 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2481 if (!rdev->ops->start_ap)
2484 if (wdev->beacon_interval)
2487 memset(¶ms, 0, sizeof(params));
2489 /* these are required for START_AP */
2490 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2491 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2492 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2495 err = nl80211_parse_beacon(info, ¶ms.beacon);
2499 params.beacon_interval =
2500 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2501 params.dtim_period =
2502 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2504 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2509 * In theory, some of these attributes should be required here
2510 * but since they were not used when the command was originally
2511 * added, keep them optional for old user space programs to let
2512 * them continue to work with drivers that do not need the
2513 * additional information -- drivers must check!
2515 if (info->attrs[NL80211_ATTR_SSID]) {
2516 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2518 nla_len(info->attrs[NL80211_ATTR_SSID]);
2519 if (params.ssid_len == 0 ||
2520 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2524 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2525 params.hidden_ssid = nla_get_u32(
2526 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2527 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2528 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2529 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2533 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2535 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2536 params.auth_type = nla_get_u32(
2537 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2538 if (!nl80211_valid_auth_type(params.auth_type))
2541 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2543 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
2544 NL80211_MAX_NR_CIPHER_SUITES);
2548 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2549 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2551 params.inactivity_timeout = nla_get_u16(
2552 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2555 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2556 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2558 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2559 !nl80211_valid_channel_type(info, &channel_type))
2562 params.channel = rdev_freq_to_chan(rdev,
2563 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2565 if (!params.channel)
2567 params.channel_type = channel_type;
2568 } else if (wdev->preset_chan) {
2569 params.channel = wdev->preset_chan;
2570 params.channel_type = wdev->preset_chantype;
2571 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
2574 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2575 params.channel_type))
2578 mutex_lock(&rdev->devlist_mtx);
2579 err = cfg80211_can_use_chan(rdev, wdev, params.channel,
2581 mutex_unlock(&rdev->devlist_mtx);
2586 err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms);
2588 wdev->preset_chan = params.channel;
2589 wdev->preset_chantype = params.channel_type;
2590 wdev->beacon_interval = params.beacon_interval;
2591 wdev->channel = params.channel;
2596 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2598 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2599 struct net_device *dev = info->user_ptr[1];
2600 struct wireless_dev *wdev = dev->ieee80211_ptr;
2601 struct cfg80211_beacon_data params;
2604 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2605 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2608 if (!rdev->ops->change_beacon)
2611 if (!wdev->beacon_interval)
2614 err = nl80211_parse_beacon(info, ¶ms);
2618 return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms);
2621 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
2623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2624 struct net_device *dev = info->user_ptr[1];
2626 return cfg80211_stop_ap(rdev, dev);
2629 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2630 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2631 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2632 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
2633 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
2634 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
2635 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
2638 static int parse_station_flags(struct genl_info *info,
2639 enum nl80211_iftype iftype,
2640 struct station_parameters *params)
2642 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
2647 * Try parsing the new attribute first so userspace
2648 * can specify both for older kernels.
2650 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2652 struct nl80211_sta_flag_update *sta_flags;
2654 sta_flags = nla_data(nla);
2655 params->sta_flags_mask = sta_flags->mask;
2656 params->sta_flags_set = sta_flags->set;
2657 if ((params->sta_flags_mask |
2658 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2663 /* if present, parse the old attribute */
2665 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
2669 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2670 nla, sta_flags_policy))
2674 * Only allow certain flags for interface types so that
2675 * other attributes are silently ignored. Remember that
2676 * this is backward compatibility code with old userspace
2677 * and shouldn't be hit in other cases anyway.
2680 case NL80211_IFTYPE_AP:
2681 case NL80211_IFTYPE_AP_VLAN:
2682 case NL80211_IFTYPE_P2P_GO:
2683 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2684 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2685 BIT(NL80211_STA_FLAG_WME) |
2686 BIT(NL80211_STA_FLAG_MFP);
2688 case NL80211_IFTYPE_P2P_CLIENT:
2689 case NL80211_IFTYPE_STATION:
2690 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2691 BIT(NL80211_STA_FLAG_TDLS_PEER);
2693 case NL80211_IFTYPE_MESH_POINT:
2694 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2695 BIT(NL80211_STA_FLAG_MFP) |
2696 BIT(NL80211_STA_FLAG_AUTHORIZED);
2701 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2703 params->sta_flags_set |= (1<<flag);
2705 /* no longer support new API additions in old API */
2706 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2714 static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2717 struct nlattr *rate;
2721 rate = nla_nest_start(msg, attr);
2723 goto nla_put_failure;
2725 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2726 bitrate = cfg80211_calculate_bitrate(info);
2727 /* report 16-bit bitrate only if we can */
2728 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
2730 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) ||
2731 (bitrate_compat > 0 &&
2732 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) ||
2733 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2734 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2735 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2736 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2737 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2738 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2739 goto nla_put_failure;
2741 nla_nest_end(msg, rate);
2748 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2750 struct cfg80211_registered_device *rdev,
2751 struct net_device *dev,
2752 const u8 *mac_addr, struct station_info *sinfo)
2755 struct nlattr *sinfoattr, *bss_param;
2757 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2761 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2762 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2763 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2764 goto nla_put_failure;
2766 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2768 goto nla_put_failure;
2769 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2770 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2771 sinfo->connected_time))
2772 goto nla_put_failure;
2773 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2774 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2775 sinfo->inactive_time))
2776 goto nla_put_failure;
2777 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2778 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2780 goto nla_put_failure;
2781 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2782 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2784 goto nla_put_failure;
2785 if ((sinfo->filled & STATION_INFO_LLID) &&
2786 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2787 goto nla_put_failure;
2788 if ((sinfo->filled & STATION_INFO_PLID) &&
2789 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2790 goto nla_put_failure;
2791 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2792 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2793 sinfo->plink_state))
2794 goto nla_put_failure;
2795 switch (rdev->wiphy.signal_type) {
2796 case CFG80211_SIGNAL_TYPE_MBM:
2797 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2798 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2800 goto nla_put_failure;
2801 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2802 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2804 goto nla_put_failure;
2809 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
2810 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2811 NL80211_STA_INFO_TX_BITRATE))
2812 goto nla_put_failure;
2814 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2815 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2816 NL80211_STA_INFO_RX_BITRATE))
2817 goto nla_put_failure;
2819 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2820 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2822 goto nla_put_failure;
2823 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2824 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2826 goto nla_put_failure;
2827 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2828 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2830 goto nla_put_failure;
2831 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2832 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2834 goto nla_put_failure;
2835 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2836 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2837 sinfo->beacon_loss_count))
2838 goto nla_put_failure;
2839 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2840 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2842 goto nla_put_failure;
2844 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2845 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2846 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2847 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2848 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2849 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2850 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2851 sinfo->bss_param.dtim_period) ||
2852 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2853 sinfo->bss_param.beacon_interval))
2854 goto nla_put_failure;
2856 nla_nest_end(msg, bss_param);
2858 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2859 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2860 sizeof(struct nl80211_sta_flag_update),
2862 goto nla_put_failure;
2863 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2864 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2866 goto nla_put_failure;
2867 nla_nest_end(msg, sinfoattr);
2869 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2870 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2871 sinfo->assoc_req_ies))
2872 goto nla_put_failure;
2874 return genlmsg_end(msg, hdr);
2877 genlmsg_cancel(msg, hdr);
2881 static int nl80211_dump_station(struct sk_buff *skb,
2882 struct netlink_callback *cb)
2884 struct station_info sinfo;
2885 struct cfg80211_registered_device *dev;
2886 struct net_device *netdev;
2887 u8 mac_addr[ETH_ALEN];
2888 int sta_idx = cb->args[1];
2891 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2895 if (!dev->ops->dump_station) {
2901 memset(&sinfo, 0, sizeof(sinfo));
2902 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2909 if (nl80211_send_station(skb,
2910 NETLINK_CB(cb->skb).pid,
2911 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2912 dev, netdev, mac_addr,
2921 cb->args[1] = sta_idx;
2924 nl80211_finish_netdev_dump(dev);
2929 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2932 struct net_device *dev = info->user_ptr[1];
2933 struct station_info sinfo;
2934 struct sk_buff *msg;
2935 u8 *mac_addr = NULL;
2938 memset(&sinfo, 0, sizeof(sinfo));
2940 if (!info->attrs[NL80211_ATTR_MAC])
2943 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2945 if (!rdev->ops->get_station)
2948 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
2952 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2956 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
2957 rdev, dev, mac_addr, &sinfo) < 0) {
2962 return genlmsg_reply(msg, info);
2966 * Get vlan interface making sure it is running and on the right wiphy.
2968 static struct net_device *get_vlan(struct genl_info *info,
2969 struct cfg80211_registered_device *rdev)
2971 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
2972 struct net_device *v;
2978 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2980 return ERR_PTR(-ENODEV);
2982 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2987 if (!netif_running(v)) {
2995 return ERR_PTR(ret);
2998 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3002 struct net_device *dev = info->user_ptr[1];
3003 struct station_parameters params;
3004 u8 *mac_addr = NULL;
3006 memset(¶ms, 0, sizeof(params));
3008 params.listen_interval = -1;
3009 params.plink_state = -1;
3011 if (info->attrs[NL80211_ATTR_STA_AID])
3014 if (!info->attrs[NL80211_ATTR_MAC])
3017 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3019 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3020 params.supported_rates =
3021 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3022 params.supported_rates_len =
3023 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3026 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3027 params.listen_interval =
3028 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3030 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3032 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3034 if (!rdev->ops->change_station)
3037 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3040 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3041 params.plink_action =
3042 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3044 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
3045 params.plink_state =
3046 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3048 switch (dev->ieee80211_ptr->iftype) {
3049 case NL80211_IFTYPE_AP:
3050 case NL80211_IFTYPE_AP_VLAN:
3051 case NL80211_IFTYPE_P2P_GO:
3052 /* disallow mesh-specific things */
3053 if (params.plink_action)
3056 /* TDLS can't be set, ... */
3057 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3060 * ... but don't bother the driver with it. This works around
3061 * a hostapd/wpa_supplicant issue -- it always includes the
3062 * TLDS_PEER flag in the mask even for AP mode.
3064 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3066 /* accept only the listed bits */
3067 if (params.sta_flags_mask &
3068 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3069 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3070 BIT(NL80211_STA_FLAG_WME) |
3071 BIT(NL80211_STA_FLAG_MFP)))
3074 /* must be last in here for error handling */
3075 params.vlan = get_vlan(info, rdev);
3076 if (IS_ERR(params.vlan))
3077 return PTR_ERR(params.vlan);
3079 case NL80211_IFTYPE_P2P_CLIENT:
3080 case NL80211_IFTYPE_STATION:
3082 * Don't allow userspace to change the TDLS_PEER flag,
3083 * but silently ignore attempts to change it since we
3084 * don't have state here to verify that it doesn't try
3085 * to change the flag.
3087 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3089 case NL80211_IFTYPE_ADHOC:
3090 /* disallow things sta doesn't support */
3091 if (params.plink_action)
3095 if (params.listen_interval >= 0)
3097 /* reject any changes other than AUTHORIZED */
3098 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3101 case NL80211_IFTYPE_MESH_POINT:
3102 /* disallow things mesh doesn't support */
3107 if (params.listen_interval >= 0)
3110 * No special handling for TDLS here -- the userspace
3111 * mesh code doesn't have this bug.
3113 if (params.sta_flags_mask &
3114 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3115 BIT(NL80211_STA_FLAG_MFP) |
3116 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3123 /* be aware of params.vlan when changing code here */
3125 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms);
3128 dev_put(params.vlan);
3133 static struct nla_policy
3134 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3135 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3136 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3139 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3143 struct net_device *dev = info->user_ptr[1];
3144 struct station_parameters params;
3145 u8 *mac_addr = NULL;
3147 memset(¶ms, 0, sizeof(params));
3149 if (!info->attrs[NL80211_ATTR_MAC])
3152 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3155 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3158 if (!info->attrs[NL80211_ATTR_STA_AID])
3161 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3162 params.supported_rates =
3163 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3164 params.supported_rates_len =
3165 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3166 params.listen_interval =
3167 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3169 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3170 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3173 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3175 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3177 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3178 params.plink_action =
3179 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3181 if (!rdev->ops->add_station)
3184 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3187 switch (dev->ieee80211_ptr->iftype) {
3188 case NL80211_IFTYPE_AP:
3189 case NL80211_IFTYPE_AP_VLAN:
3190 case NL80211_IFTYPE_P2P_GO:
3191 /* parse WME attributes if sta is WME capable */
3192 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3193 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3194 info->attrs[NL80211_ATTR_STA_WME]) {
3195 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3198 nla = info->attrs[NL80211_ATTR_STA_WME];
3199 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3200 nl80211_sta_wme_policy);
3204 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3205 params.uapsd_queues =
3206 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3207 if (params.uapsd_queues &
3208 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3211 if (tb[NL80211_STA_WME_MAX_SP])
3213 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3216 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3219 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3221 /* TDLS peers cannot be added */
3222 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3224 /* but don't bother the driver with it */
3225 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3227 /* must be last in here for error handling */
3228 params.vlan = get_vlan(info, rdev);
3229 if (IS_ERR(params.vlan))
3230 return PTR_ERR(params.vlan);
3232 case NL80211_IFTYPE_MESH_POINT:
3233 /* TDLS peers cannot be added */
3234 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3237 case NL80211_IFTYPE_STATION:
3238 /* Only TDLS peers can be added */
3239 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3241 /* Can only add if TDLS ... */
3242 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3244 /* ... with external setup is supported */
3245 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3252 /* be aware of params.vlan when changing code here */
3254 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms);
3257 dev_put(params.vlan);
3261 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3264 struct net_device *dev = info->user_ptr[1];
3265 u8 *mac_addr = NULL;
3267 if (info->attrs[NL80211_ATTR_MAC])
3268 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3270 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3271 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3272 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
3273 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3276 if (!rdev->ops->del_station)
3279 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
3282 static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3283 int flags, struct net_device *dev,
3284 u8 *dst, u8 *next_hop,
3285 struct mpath_info *pinfo)
3288 struct nlattr *pinfoattr;
3290 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3294 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3295 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3296 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3297 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3298 goto nla_put_failure;
3300 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3302 goto nla_put_failure;
3303 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3304 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3306 goto nla_put_failure;
3307 if (((pinfo->filled & MPATH_INFO_SN) &&
3308 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3309 ((pinfo->filled & MPATH_INFO_METRIC) &&
3310 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3312 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3313 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3315 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3316 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3318 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3319 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3320 pinfo->discovery_timeout)) ||
3321 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3322 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3323 pinfo->discovery_retries)))
3324 goto nla_put_failure;
3326 nla_nest_end(msg, pinfoattr);
3328 return genlmsg_end(msg, hdr);
3331 genlmsg_cancel(msg, hdr);
3335 static int nl80211_dump_mpath(struct sk_buff *skb,
3336 struct netlink_callback *cb)
3338 struct mpath_info pinfo;
3339 struct cfg80211_registered_device *dev;
3340 struct net_device *netdev;
3342 u8 next_hop[ETH_ALEN];
3343 int path_idx = cb->args[1];
3346 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3350 if (!dev->ops->dump_mpath) {
3355 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3361 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3362 dst, next_hop, &pinfo);
3368 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3369 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3370 netdev, dst, next_hop,
3379 cb->args[1] = path_idx;
3382 nl80211_finish_netdev_dump(dev);
3386 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3388 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3390 struct net_device *dev = info->user_ptr[1];
3391 struct mpath_info pinfo;
3392 struct sk_buff *msg;
3394 u8 next_hop[ETH_ALEN];
3396 memset(&pinfo, 0, sizeof(pinfo));
3398 if (!info->attrs[NL80211_ATTR_MAC])
3401 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3403 if (!rdev->ops->get_mpath)
3406 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3409 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
3413 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3417 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
3418 dev, dst, next_hop, &pinfo) < 0) {
3423 return genlmsg_reply(msg, info);
3426 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3429 struct net_device *dev = info->user_ptr[1];
3431 u8 *next_hop = NULL;
3433 if (!info->attrs[NL80211_ATTR_MAC])
3436 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3439 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3440 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3442 if (!rdev->ops->change_mpath)
3445 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3448 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
3451 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3454 struct net_device *dev = info->user_ptr[1];
3456 u8 *next_hop = NULL;
3458 if (!info->attrs[NL80211_ATTR_MAC])
3461 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3464 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3465 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3467 if (!rdev->ops->add_mpath)
3470 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3473 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
3476 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3479 struct net_device *dev = info->user_ptr[1];
3482 if (info->attrs[NL80211_ATTR_MAC])
3483 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3485 if (!rdev->ops->del_mpath)
3488 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
3491 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3494 struct net_device *dev = info->user_ptr[1];
3495 struct bss_parameters params;
3497 memset(¶ms, 0, sizeof(params));
3498 /* default to not changing parameters */
3499 params.use_cts_prot = -1;
3500 params.use_short_preamble = -1;
3501 params.use_short_slot_time = -1;
3502 params.ap_isolate = -1;
3503 params.ht_opmode = -1;
3505 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3506 params.use_cts_prot =
3507 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3508 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3509 params.use_short_preamble =
3510 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3511 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3512 params.use_short_slot_time =
3513 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
3514 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3515 params.basic_rates =
3516 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3517 params.basic_rates_len =
3518 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3520 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3521 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
3522 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3524 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
3526 if (!rdev->ops->change_bss)
3529 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3530 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3533 return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms);
3536 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
3537 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3538 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3539 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3540 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3541 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3542 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3545 static int parse_reg_rule(struct nlattr *tb[],
3546 struct ieee80211_reg_rule *reg_rule)
3548 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
3549 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
3551 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3553 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3555 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3557 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3559 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3562 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3564 freq_range->start_freq_khz =
3565 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3566 freq_range->end_freq_khz =
3567 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3568 freq_range->max_bandwidth_khz =
3569 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3571 power_rule->max_eirp =
3572 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3574 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3575 power_rule->max_antenna_gain =
3576 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3581 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3587 * You should only get this when cfg80211 hasn't yet initialized
3588 * completely when built-in to the kernel right between the time
3589 * window between nl80211_init() and regulatory_init(), if that is
3592 mutex_lock(&cfg80211_mutex);
3593 if (unlikely(!cfg80211_regdomain)) {
3594 mutex_unlock(&cfg80211_mutex);
3595 return -EINPROGRESS;
3597 mutex_unlock(&cfg80211_mutex);
3599 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3602 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3604 r = regulatory_hint_user(data);
3609 static int nl80211_get_mesh_config(struct sk_buff *skb,
3610 struct genl_info *info)
3612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3613 struct net_device *dev = info->user_ptr[1];
3614 struct wireless_dev *wdev = dev->ieee80211_ptr;
3615 struct mesh_config cur_params;
3618 struct nlattr *pinfoattr;
3619 struct sk_buff *msg;
3621 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3624 if (!rdev->ops->get_mesh_config)
3628 /* If not connected, get default parameters */
3629 if (!wdev->mesh_id_len)
3630 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3632 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
3639 /* Draw up a netlink message to send back */
3640 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3643 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3644 NL80211_CMD_GET_MESH_CONFIG);
3647 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
3649 goto nla_put_failure;
3650 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3651 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3652 cur_params.dot11MeshRetryTimeout) ||
3653 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3654 cur_params.dot11MeshConfirmTimeout) ||
3655 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3656 cur_params.dot11MeshHoldingTimeout) ||
3657 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3658 cur_params.dot11MeshMaxPeerLinks) ||
3659 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3660 cur_params.dot11MeshMaxRetries) ||
3661 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3662 cur_params.dot11MeshTTL) ||
3663 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3664 cur_params.element_ttl) ||
3665 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3666 cur_params.auto_open_plinks) ||
3667 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3668 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
3669 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3670 cur_params.dot11MeshHWMPmaxPREQretries) ||
3671 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3672 cur_params.path_refresh_time) ||
3673 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3674 cur_params.min_discovery_timeout) ||
3675 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3676 cur_params.dot11MeshHWMPactivePathTimeout) ||
3677 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3678 cur_params.dot11MeshHWMPpreqMinInterval) ||
3679 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3680 cur_params.dot11MeshHWMPperrMinInterval) ||
3681 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3682 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3683 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3684 cur_params.dot11MeshHWMPRootMode) ||
3685 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3686 cur_params.dot11MeshHWMPRannInterval) ||
3687 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3688 cur_params.dot11MeshGateAnnouncementProtocol) ||
3689 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3690 cur_params.dot11MeshForwarding) ||
3691 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
3692 cur_params.rssi_threshold) ||
3693 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
3694 cur_params.ht_opmode) ||
3695 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3696 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3697 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3698 cur_params.dot11MeshHWMProotInterval) ||
3699 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3700 cur_params.dot11MeshHWMPconfirmationInterval))
3701 goto nla_put_failure;
3702 nla_nest_end(msg, pinfoattr);
3703 genlmsg_end(msg, hdr);
3704 return genlmsg_reply(msg, info);
3707 genlmsg_cancel(msg, hdr);
3713 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
3714 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3715 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3716 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3717 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3718 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3719 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
3720 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
3721 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
3722 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
3723 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3724 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3725 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3726 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3727 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
3728 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
3729 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
3730 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
3731 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
3732 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
3733 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
3734 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3735 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
3736 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3737 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
3738 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
3741 static const struct nla_policy
3742 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
3743 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
3744 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3745 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
3746 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
3747 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
3748 .len = IEEE80211_MAX_DATA_LEN },
3749 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
3752 static int nl80211_parse_mesh_config(struct genl_info *info,
3753 struct mesh_config *cfg,
3756 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
3759 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3761 if (table[attr_num]) {\
3762 cfg->param = nla_fn(table[attr_num]); \
3763 mask |= (1 << (attr_num - 1)); \
3768 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3770 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
3771 info->attrs[NL80211_ATTR_MESH_CONFIG],
3772 nl80211_meshconf_params_policy))
3775 /* This makes sure that there aren't more than 32 mesh config
3776 * parameters (otherwise our bitfield scheme would not work.) */
3777 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3779 /* Fill in the params struct */
3780 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3781 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3783 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3784 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3786 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3787 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3789 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3790 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3792 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3793 mask, NL80211_MESHCONF_MAX_RETRIES,
3795 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3796 mask, NL80211_MESHCONF_TTL, nla_get_u8);
3797 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3798 mask, NL80211_MESHCONF_ELEMENT_TTL,
3800 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3801 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3803 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3804 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3806 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3807 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3809 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3810 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3812 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3813 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3815 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3816 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3819 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
3822 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3824 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3825 dot11MeshHWMPnetDiameterTraversalTime, mask,
3826 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3828 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3829 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3830 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3831 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3833 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3834 dot11MeshGateAnnouncementProtocol, mask,
3835 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3837 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
3838 mask, NL80211_MESHCONF_FORWARDING,
3840 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
3841 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3843 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
3844 mask, NL80211_MESHCONF_HT_OPMODE,
3846 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3848 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3851 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3854 dot11MeshHWMPconfirmationInterval, mask,
3855 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3862 #undef FILL_IN_MESH_PARAM_IF_SET
3865 static int nl80211_parse_mesh_setup(struct genl_info *info,
3866 struct mesh_setup *setup)
3868 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3870 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3872 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3873 info->attrs[NL80211_ATTR_MESH_SETUP],
3874 nl80211_mesh_setup_params_policy))
3877 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3878 setup->sync_method =
3879 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3880 IEEE80211_SYNC_METHOD_VENDOR :
3881 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3883 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3884 setup->path_sel_proto =
3885 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3886 IEEE80211_PATH_PROTOCOL_VENDOR :
3887 IEEE80211_PATH_PROTOCOL_HWMP;
3889 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3890 setup->path_metric =
3891 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3892 IEEE80211_PATH_METRIC_VENDOR :
3893 IEEE80211_PATH_METRIC_AIRTIME;
3896 if (tb[NL80211_MESH_SETUP_IE]) {
3897 struct nlattr *ieattr =
3898 tb[NL80211_MESH_SETUP_IE];
3899 if (!is_valid_ie_attr(ieattr))
3901 setup->ie = nla_data(ieattr);
3902 setup->ie_len = nla_len(ieattr);
3904 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3905 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
3910 static int nl80211_update_mesh_config(struct sk_buff *skb,
3911 struct genl_info *info)
3913 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3914 struct net_device *dev = info->user_ptr[1];
3915 struct wireless_dev *wdev = dev->ieee80211_ptr;
3916 struct mesh_config cfg;
3920 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3923 if (!rdev->ops->update_mesh_config)
3926 err = nl80211_parse_mesh_config(info, &cfg, &mask);
3931 if (!wdev->mesh_id_len)
3935 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
3943 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3945 struct sk_buff *msg;
3947 struct nlattr *nl_reg_rules;
3951 mutex_lock(&cfg80211_mutex);
3953 if (!cfg80211_regdomain)
3956 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3962 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3963 NL80211_CMD_GET_REG);
3967 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3968 cfg80211_regdomain->alpha2) ||
3969 (cfg80211_regdomain->dfs_region &&
3970 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3971 cfg80211_regdomain->dfs_region)))
3972 goto nla_put_failure;
3974 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3976 goto nla_put_failure;
3978 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3979 struct nlattr *nl_reg_rule;
3980 const struct ieee80211_reg_rule *reg_rule;
3981 const struct ieee80211_freq_range *freq_range;
3982 const struct ieee80211_power_rule *power_rule;
3984 reg_rule = &cfg80211_regdomain->reg_rules[i];
3985 freq_range = ®_rule->freq_range;
3986 power_rule = ®_rule->power_rule;
3988 nl_reg_rule = nla_nest_start(msg, i);
3990 goto nla_put_failure;
3992 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3994 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3995 freq_range->start_freq_khz) ||
3996 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3997 freq_range->end_freq_khz) ||
3998 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3999 freq_range->max_bandwidth_khz) ||
4000 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4001 power_rule->max_antenna_gain) ||
4002 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4003 power_rule->max_eirp))
4004 goto nla_put_failure;
4006 nla_nest_end(msg, nl_reg_rule);
4009 nla_nest_end(msg, nl_reg_rules);
4011 genlmsg_end(msg, hdr);
4012 err = genlmsg_reply(msg, info);
4016 genlmsg_cancel(msg, hdr);
4021 mutex_unlock(&cfg80211_mutex);
4025 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4027 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4028 struct nlattr *nl_reg_rule;
4029 char *alpha2 = NULL;
4030 int rem_reg_rules = 0, r = 0;
4031 u32 num_rules = 0, rule_idx = 0, size_of_regd;
4033 struct ieee80211_regdomain *rd = NULL;
4035 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4038 if (!info->attrs[NL80211_ATTR_REG_RULES])
4041 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4043 if (info->attrs[NL80211_ATTR_DFS_REGION])
4044 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4046 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4049 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
4053 mutex_lock(&cfg80211_mutex);
4055 if (!reg_is_valid_request(alpha2)) {
4060 size_of_regd = sizeof(struct ieee80211_regdomain) +
4061 (num_rules * sizeof(struct ieee80211_reg_rule));
4063 rd = kzalloc(size_of_regd, GFP_KERNEL);
4069 rd->n_reg_rules = num_rules;
4070 rd->alpha2[0] = alpha2[0];
4071 rd->alpha2[1] = alpha2[1];
4074 * Disable DFS master mode if the DFS region was
4075 * not supported or known on this kernel.
4077 if (reg_supported_dfs_region(dfs_region))
4078 rd->dfs_region = dfs_region;
4080 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4082 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4083 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4085 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4091 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4097 BUG_ON(rule_idx != num_rules);
4101 mutex_unlock(&cfg80211_mutex);
4106 mutex_unlock(&cfg80211_mutex);
4111 static int validate_scan_freqs(struct nlattr *freqs)
4113 struct nlattr *attr1, *attr2;
4114 int n_channels = 0, tmp1, tmp2;
4116 nla_for_each_nested(attr1, freqs, tmp1) {
4119 * Some hardware has a limited channel list for
4120 * scanning, and it is pretty much nonsensical
4121 * to scan for a channel twice, so disallow that
4122 * and don't require drivers to check that the
4123 * channel list they get isn't longer than what
4124 * they can scan, as long as they can scan all
4125 * the channels they registered at once.
4127 nla_for_each_nested(attr2, freqs, tmp2)
4128 if (attr1 != attr2 &&
4129 nla_get_u32(attr1) == nla_get_u32(attr2))
4136 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4139 struct wireless_dev *wdev = info->user_ptr[1];
4140 struct cfg80211_scan_request *request;
4141 struct nlattr *attr;
4142 struct wiphy *wiphy;
4143 int err, tmp, n_ssids = 0, n_channels, i;
4146 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4149 wiphy = &rdev->wiphy;
4151 if (!rdev->ops->scan)
4157 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4158 n_channels = validate_scan_freqs(
4159 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4163 enum ieee80211_band band;
4166 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4167 if (wiphy->bands[band])
4168 n_channels += wiphy->bands[band]->n_channels;
4171 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4172 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4175 if (n_ssids > wiphy->max_scan_ssids)
4178 if (info->attrs[NL80211_ATTR_IE])
4179 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4183 if (ie_len > wiphy->max_scan_ie_len)
4186 request = kzalloc(sizeof(*request)
4187 + sizeof(*request->ssids) * n_ssids
4188 + sizeof(*request->channels) * n_channels
4189 + ie_len, GFP_KERNEL);
4194 request->ssids = (void *)&request->channels[n_channels];
4195 request->n_ssids = n_ssids;
4198 request->ie = (void *)(request->ssids + n_ssids);
4200 request->ie = (void *)(request->channels + n_channels);
4204 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4205 /* user specified, bail out if channel not found */
4206 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
4207 struct ieee80211_channel *chan;
4209 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4216 /* ignore disabled channels */
4217 if (chan->flags & IEEE80211_CHAN_DISABLED)
4220 request->channels[i] = chan;
4224 enum ieee80211_band band;
4227 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4229 if (!wiphy->bands[band])
4231 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4232 struct ieee80211_channel *chan;
4234 chan = &wiphy->bands[band]->channels[j];
4236 if (chan->flags & IEEE80211_CHAN_DISABLED)
4239 request->channels[i] = chan;
4250 request->n_channels = i;
4253 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4254 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
4255 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
4259 request->ssids[i].ssid_len = nla_len(attr);
4260 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
4265 if (info->attrs[NL80211_ATTR_IE]) {
4266 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4267 memcpy((void *)request->ie,
4268 nla_data(info->attrs[NL80211_ATTR_IE]),
4272 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4273 if (wiphy->bands[i])
4275 (1 << wiphy->bands[i]->n_bitrates) - 1;
4277 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4278 nla_for_each_nested(attr,
4279 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4281 enum ieee80211_band band = nla_type(attr);
4283 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
4287 err = ieee80211_get_ratemask(wiphy->bands[band],
4290 &request->rates[band]);
4297 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4299 request->wdev = wdev;
4300 request->wiphy = &rdev->wiphy;
4302 rdev->scan_req = request;
4303 err = rdev->ops->scan(&rdev->wiphy, request);
4306 nl80211_send_scan_start(rdev, wdev);
4308 dev_hold(wdev->netdev);
4311 rdev->scan_req = NULL;
4318 static int nl80211_start_sched_scan(struct sk_buff *skb,
4319 struct genl_info *info)
4321 struct cfg80211_sched_scan_request *request;
4322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4323 struct net_device *dev = info->user_ptr[1];
4324 struct nlattr *attr;
4325 struct wiphy *wiphy;
4326 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
4328 enum ieee80211_band band;
4330 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
4332 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4333 !rdev->ops->sched_scan_start)
4336 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4339 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4342 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4346 wiphy = &rdev->wiphy;
4348 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4349 n_channels = validate_scan_freqs(
4350 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4356 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4357 if (wiphy->bands[band])
4358 n_channels += wiphy->bands[band]->n_channels;
4361 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4362 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4366 if (n_ssids > wiphy->max_sched_scan_ssids)
4369 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4370 nla_for_each_nested(attr,
4371 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4375 if (n_match_sets > wiphy->max_match_sets)
4378 if (info->attrs[NL80211_ATTR_IE])
4379 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4383 if (ie_len > wiphy->max_sched_scan_ie_len)
4386 mutex_lock(&rdev->sched_scan_mtx);
4388 if (rdev->sched_scan_req) {
4393 request = kzalloc(sizeof(*request)
4394 + sizeof(*request->ssids) * n_ssids
4395 + sizeof(*request->match_sets) * n_match_sets
4396 + sizeof(*request->channels) * n_channels
4397 + ie_len, GFP_KERNEL);
4404 request->ssids = (void *)&request->channels[n_channels];
4405 request->n_ssids = n_ssids;
4408 request->ie = (void *)(request->ssids + n_ssids);
4410 request->ie = (void *)(request->channels + n_channels);
4415 request->match_sets = (void *)(request->ie + ie_len);
4416 else if (request->ssids)
4417 request->match_sets =
4418 (void *)(request->ssids + n_ssids);
4420 request->match_sets =
4421 (void *)(request->channels + n_channels);
4423 request->n_match_sets = n_match_sets;
4426 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4427 /* user specified, bail out if channel not found */
4428 nla_for_each_nested(attr,
4429 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4431 struct ieee80211_channel *chan;
4433 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4440 /* ignore disabled channels */
4441 if (chan->flags & IEEE80211_CHAN_DISABLED)
4444 request->channels[i] = chan;
4449 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4451 if (!wiphy->bands[band])
4453 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4454 struct ieee80211_channel *chan;
4456 chan = &wiphy->bands[band]->channels[j];
4458 if (chan->flags & IEEE80211_CHAN_DISABLED)
4461 request->channels[i] = chan;
4472 request->n_channels = i;
4475 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4476 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4478 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
4482 request->ssids[i].ssid_len = nla_len(attr);
4483 memcpy(request->ssids[i].ssid, nla_data(attr),
4490 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4491 nla_for_each_nested(attr,
4492 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4494 struct nlattr *ssid, *rssi;
4496 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4497 nla_data(attr), nla_len(attr),
4498 nl80211_match_policy);
4499 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
4501 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4505 memcpy(request->match_sets[i].ssid.ssid,
4506 nla_data(ssid), nla_len(ssid));
4507 request->match_sets[i].ssid.ssid_len =
4510 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4512 request->rssi_thold = nla_get_u32(rssi);
4514 request->rssi_thold =
4515 NL80211_SCAN_RSSI_THOLD_OFF;
4520 if (info->attrs[NL80211_ATTR_IE]) {
4521 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4522 memcpy((void *)request->ie,
4523 nla_data(info->attrs[NL80211_ATTR_IE]),
4528 request->wiphy = &rdev->wiphy;
4529 request->interval = interval;
4531 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4533 rdev->sched_scan_req = request;
4534 nl80211_send_sched_scan(rdev, dev,
4535 NL80211_CMD_START_SCHED_SCAN);
4542 mutex_unlock(&rdev->sched_scan_mtx);
4546 static int nl80211_stop_sched_scan(struct sk_buff *skb,
4547 struct genl_info *info)
4549 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4552 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4553 !rdev->ops->sched_scan_stop)
4556 mutex_lock(&rdev->sched_scan_mtx);
4557 err = __cfg80211_stop_sched_scan(rdev, false);
4558 mutex_unlock(&rdev->sched_scan_mtx);
4563 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4565 struct cfg80211_registered_device *rdev,
4566 struct wireless_dev *wdev,
4567 struct cfg80211_internal_bss *intbss)
4569 struct cfg80211_bss *res = &intbss->pub;
4573 ASSERT_WDEV_LOCK(wdev);
4575 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
4576 NL80211_CMD_NEW_SCAN_RESULTS);
4580 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4582 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4583 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4584 goto nla_put_failure;
4586 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4588 goto nla_put_failure;
4589 if ((!is_zero_ether_addr(res->bssid) &&
4590 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4591 (res->information_elements && res->len_information_elements &&
4592 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4593 res->len_information_elements,
4594 res->information_elements)) ||
4595 (res->beacon_ies && res->len_beacon_ies &&
4596 res->beacon_ies != res->information_elements &&
4597 nla_put(msg, NL80211_BSS_BEACON_IES,
4598 res->len_beacon_ies, res->beacon_ies)))
4599 goto nla_put_failure;
4601 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4602 goto nla_put_failure;
4603 if (res->beacon_interval &&
4604 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4605 goto nla_put_failure;
4606 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4607 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4608 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4609 jiffies_to_msecs(jiffies - intbss->ts)))
4610 goto nla_put_failure;
4612 switch (rdev->wiphy.signal_type) {
4613 case CFG80211_SIGNAL_TYPE_MBM:
4614 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4615 goto nla_put_failure;
4617 case CFG80211_SIGNAL_TYPE_UNSPEC:
4618 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4619 goto nla_put_failure;
4625 switch (wdev->iftype) {
4626 case NL80211_IFTYPE_P2P_CLIENT:
4627 case NL80211_IFTYPE_STATION:
4628 if (intbss == wdev->current_bss &&
4629 nla_put_u32(msg, NL80211_BSS_STATUS,
4630 NL80211_BSS_STATUS_ASSOCIATED))
4631 goto nla_put_failure;
4633 case NL80211_IFTYPE_ADHOC:
4634 if (intbss == wdev->current_bss &&
4635 nla_put_u32(msg, NL80211_BSS_STATUS,
4636 NL80211_BSS_STATUS_IBSS_JOINED))
4637 goto nla_put_failure;
4643 nla_nest_end(msg, bss);
4645 return genlmsg_end(msg, hdr);
4648 genlmsg_cancel(msg, hdr);
4652 static int nl80211_dump_scan(struct sk_buff *skb,
4653 struct netlink_callback *cb)
4655 struct cfg80211_registered_device *rdev;
4656 struct net_device *dev;
4657 struct cfg80211_internal_bss *scan;
4658 struct wireless_dev *wdev;
4659 int start = cb->args[1], idx = 0;
4662 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4666 wdev = dev->ieee80211_ptr;
4669 spin_lock_bh(&rdev->bss_lock);
4670 cfg80211_bss_expire(rdev);
4672 cb->seq = rdev->bss_generation;
4674 list_for_each_entry(scan, &rdev->bss_list, list) {
4677 if (nl80211_send_bss(skb, cb,
4678 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4679 rdev, wdev, scan) < 0) {
4685 spin_unlock_bh(&rdev->bss_lock);
4689 nl80211_finish_netdev_dump(rdev);
4694 static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4695 int flags, struct net_device *dev,
4696 struct survey_info *survey)
4699 struct nlattr *infoattr;
4701 hdr = nl80211hdr_put(msg, pid, seq, flags,
4702 NL80211_CMD_NEW_SURVEY_RESULTS);
4706 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4707 goto nla_put_failure;
4709 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4711 goto nla_put_failure;
4713 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4714 survey->channel->center_freq))
4715 goto nla_put_failure;
4717 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4718 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4719 goto nla_put_failure;
4720 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4721 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4722 goto nla_put_failure;
4723 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4724 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4725 survey->channel_time))
4726 goto nla_put_failure;
4727 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4728 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4729 survey->channel_time_busy))
4730 goto nla_put_failure;
4731 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4732 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4733 survey->channel_time_ext_busy))
4734 goto nla_put_failure;
4735 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4736 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4737 survey->channel_time_rx))
4738 goto nla_put_failure;
4739 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4740 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4741 survey->channel_time_tx))
4742 goto nla_put_failure;
4744 nla_nest_end(msg, infoattr);
4746 return genlmsg_end(msg, hdr);
4749 genlmsg_cancel(msg, hdr);
4753 static int nl80211_dump_survey(struct sk_buff *skb,
4754 struct netlink_callback *cb)
4756 struct survey_info survey;
4757 struct cfg80211_registered_device *dev;
4758 struct net_device *netdev;
4759 int survey_idx = cb->args[1];
4762 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4766 if (!dev->ops->dump_survey) {
4772 struct ieee80211_channel *chan;
4774 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4781 /* Survey without a channel doesn't make sense */
4782 if (!survey.channel) {
4787 chan = ieee80211_get_channel(&dev->wiphy,
4788 survey.channel->center_freq);
4789 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4794 if (nl80211_send_survey(skb,
4795 NETLINK_CB(cb->skb).pid,
4796 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4804 cb->args[1] = survey_idx;
4807 nl80211_finish_netdev_dump(dev);
4811 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4813 return auth_type <= NL80211_AUTHTYPE_MAX;
4816 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4818 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4819 NL80211_WPA_VERSION_2));
4822 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4825 struct net_device *dev = info->user_ptr[1];
4826 struct ieee80211_channel *chan;
4827 const u8 *bssid, *ssid, *ie = NULL;
4828 int err, ssid_len, ie_len = 0;
4829 enum nl80211_auth_type auth_type;
4830 struct key_parse key;
4831 bool local_state_change;
4833 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4836 if (!info->attrs[NL80211_ATTR_MAC])
4839 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4842 if (!info->attrs[NL80211_ATTR_SSID])
4845 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4848 err = nl80211_parse_key(info, &key);
4853 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4855 if (!key.p.key || !key.p.key_len)
4857 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4858 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4859 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4860 key.p.key_len != WLAN_KEY_LEN_WEP104))
4872 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4873 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4882 if (!rdev->ops->auth)
4885 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4886 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4889 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4890 chan = ieee80211_get_channel(&rdev->wiphy,
4891 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4892 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4895 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4896 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4898 if (info->attrs[NL80211_ATTR_IE]) {
4899 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4900 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4903 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4904 if (!nl80211_valid_auth_type(auth_type))
4907 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4910 * Since we no longer track auth state, ignore
4911 * requests to only change local state.
4913 if (local_state_change)
4916 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4917 ssid, ssid_len, ie, ie_len,
4918 key.p.key, key.p.key_len, key.idx);
4921 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4922 struct genl_info *info,
4923 struct cfg80211_crypto_settings *settings,
4926 memset(settings, 0, sizeof(*settings));
4928 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4930 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4932 proto = nla_get_u16(
4933 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4934 settings->control_port_ethertype = cpu_to_be16(proto);
4935 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4938 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4939 settings->control_port_no_encrypt = true;
4941 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4943 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4947 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4948 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4949 settings->n_ciphers_pairwise = len / sizeof(u32);
4951 if (len % sizeof(u32))
4954 if (settings->n_ciphers_pairwise > cipher_limit)
4957 memcpy(settings->ciphers_pairwise, data, len);
4959 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4960 if (!cfg80211_supported_cipher_suite(
4962 settings->ciphers_pairwise[i]))
4966 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4967 settings->cipher_group =
4968 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
4969 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4970 settings->cipher_group))
4974 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4975 settings->wpa_versions =
4976 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4977 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4981 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4985 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4986 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4987 settings->n_akm_suites = len / sizeof(u32);
4989 if (len % sizeof(u32))
4992 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4995 memcpy(settings->akm_suites, data, len);
5001 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5004 struct net_device *dev = info->user_ptr[1];
5005 struct cfg80211_crypto_settings crypto;
5006 struct ieee80211_channel *chan;
5007 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
5008 int err, ssid_len, ie_len = 0;
5009 bool use_mfp = false;
5011 struct ieee80211_ht_cap *ht_capa = NULL;
5012 struct ieee80211_ht_cap *ht_capa_mask = NULL;
5014 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5017 if (!info->attrs[NL80211_ATTR_MAC] ||
5018 !info->attrs[NL80211_ATTR_SSID] ||
5019 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5022 if (!rdev->ops->assoc)
5025 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5026 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5029 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5031 chan = ieee80211_get_channel(&rdev->wiphy,
5032 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5033 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5036 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5037 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5039 if (info->attrs[NL80211_ATTR_IE]) {
5040 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5041 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5044 if (info->attrs[NL80211_ATTR_USE_MFP]) {
5045 enum nl80211_mfp mfp =
5046 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
5047 if (mfp == NL80211_MFP_REQUIRED)
5049 else if (mfp != NL80211_MFP_NO)
5053 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5054 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5056 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5057 flags |= ASSOC_REQ_DISABLE_HT;
5059 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5061 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5063 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5066 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5069 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
5071 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5072 ssid, ssid_len, ie, ie_len, use_mfp,
5073 &crypto, flags, ht_capa,
5079 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5082 struct net_device *dev = info->user_ptr[1];
5083 const u8 *ie = NULL, *bssid;
5086 bool local_state_change;
5088 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5091 if (!info->attrs[NL80211_ATTR_MAC])
5094 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5097 if (!rdev->ops->deauth)
5100 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5101 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5104 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5106 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5107 if (reason_code == 0) {
5108 /* Reason Code 0 is reserved */
5112 if (info->attrs[NL80211_ATTR_IE]) {
5113 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5114 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5117 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5119 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5120 local_state_change);
5123 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5126 struct net_device *dev = info->user_ptr[1];
5127 const u8 *ie = NULL, *bssid;
5130 bool local_state_change;
5132 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5135 if (!info->attrs[NL80211_ATTR_MAC])
5138 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5141 if (!rdev->ops->disassoc)
5144 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5145 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5148 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5150 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5151 if (reason_code == 0) {
5152 /* Reason Code 0 is reserved */
5156 if (info->attrs[NL80211_ATTR_IE]) {
5157 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5158 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5161 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5163 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5164 local_state_change);
5168 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5169 int mcast_rate[IEEE80211_NUM_BANDS],
5172 struct wiphy *wiphy = &rdev->wiphy;
5176 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5177 struct ieee80211_supported_band *sband;
5179 sband = wiphy->bands[band];
5183 for (i = 0; i < sband->n_bitrates; i++) {
5184 if (sband->bitrates[i].bitrate == rateval) {
5185 mcast_rate[band] = i + 1;
5195 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5198 struct net_device *dev = info->user_ptr[1];
5199 struct cfg80211_ibss_params ibss;
5200 struct wiphy *wiphy;
5201 struct cfg80211_cached_keys *connkeys = NULL;
5204 memset(&ibss, 0, sizeof(ibss));
5206 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5209 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5210 !info->attrs[NL80211_ATTR_SSID] ||
5211 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5214 ibss.beacon_interval = 100;
5216 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5217 ibss.beacon_interval =
5218 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5219 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5223 if (!rdev->ops->join_ibss)
5226 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5229 wiphy = &rdev->wiphy;
5231 if (info->attrs[NL80211_ATTR_MAC]) {
5232 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5234 if (!is_valid_ether_addr(ibss.bssid))
5237 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5238 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5240 if (info->attrs[NL80211_ATTR_IE]) {
5241 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5242 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5245 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5246 enum nl80211_channel_type channel_type;
5248 if (!nl80211_valid_channel_type(info, &channel_type))
5251 if (channel_type != NL80211_CHAN_NO_HT &&
5252 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5255 ibss.channel_type = channel_type;
5257 ibss.channel_type = NL80211_CHAN_NO_HT;
5260 ibss.channel = rdev_freq_to_chan(rdev,
5261 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5263 if (!ibss.channel ||
5264 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
5265 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5268 /* Both channels should be able to initiate communication */
5269 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5270 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5271 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5275 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
5276 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5278 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5280 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5282 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5283 struct ieee80211_supported_band *sband =
5284 wiphy->bands[ibss.channel->band];
5286 err = ieee80211_get_ratemask(sband, rates, n_rates,
5292 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5293 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5294 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5297 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5298 connkeys = nl80211_parse_connkeys(rdev,
5299 info->attrs[NL80211_ATTR_KEYS]);
5300 if (IS_ERR(connkeys))
5301 return PTR_ERR(connkeys);
5305 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5307 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
5313 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5315 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5316 struct net_device *dev = info->user_ptr[1];
5318 if (!rdev->ops->leave_ibss)
5321 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5324 return cfg80211_leave_ibss(rdev, dev, false);
5327 #ifdef CONFIG_NL80211_TESTMODE
5328 static struct genl_multicast_group nl80211_testmode_mcgrp = {
5332 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5337 if (!info->attrs[NL80211_ATTR_TESTDATA])
5341 if (rdev->ops->testmode_cmd) {
5342 rdev->testmode_info = info;
5343 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5344 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5345 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5346 rdev->testmode_info = NULL;
5352 static int nl80211_testmode_dump(struct sk_buff *skb,
5353 struct netlink_callback *cb)
5355 struct cfg80211_registered_device *rdev;
5363 * 0 is a valid index, but not valid for args[0],
5364 * so we need to offset by 1.
5366 phy_idx = cb->args[0] - 1;
5368 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5369 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5374 mutex_lock(&cfg80211_mutex);
5375 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5376 nl80211_fam.attrbuf);
5378 mutex_unlock(&cfg80211_mutex);
5379 return PTR_ERR(rdev);
5381 phy_idx = rdev->wiphy_idx;
5383 mutex_unlock(&cfg80211_mutex);
5385 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5387 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5391 data = nla_data((void *)cb->args[1]);
5392 data_len = nla_len((void *)cb->args[1]);
5395 mutex_lock(&cfg80211_mutex);
5396 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5398 mutex_unlock(&cfg80211_mutex);
5401 cfg80211_lock_rdev(rdev);
5402 mutex_unlock(&cfg80211_mutex);
5404 if (!rdev->ops->testmode_dump) {
5410 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5411 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5412 NL80211_CMD_TESTMODE);
5413 struct nlattr *tmdata;
5415 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
5416 genlmsg_cancel(skb, hdr);
5420 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5422 genlmsg_cancel(skb, hdr);
5425 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5427 nla_nest_end(skb, tmdata);
5429 if (err == -ENOBUFS || err == -ENOENT) {
5430 genlmsg_cancel(skb, hdr);
5433 genlmsg_cancel(skb, hdr);
5437 genlmsg_end(skb, hdr);
5442 cb->args[0] = phy_idx + 1;
5444 cfg80211_unlock_rdev(rdev);
5448 static struct sk_buff *
5449 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5450 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5452 struct sk_buff *skb;
5454 struct nlattr *data;
5456 skb = nlmsg_new(approxlen + 100, gfp);
5460 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5466 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5467 goto nla_put_failure;
5468 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5470 ((void **)skb->cb)[0] = rdev;
5471 ((void **)skb->cb)[1] = hdr;
5472 ((void **)skb->cb)[2] = data;
5481 struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5484 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5486 if (WARN_ON(!rdev->testmode_info))
5489 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5490 rdev->testmode_info->snd_pid,
5491 rdev->testmode_info->snd_seq,
5494 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5496 int cfg80211_testmode_reply(struct sk_buff *skb)
5498 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5499 void *hdr = ((void **)skb->cb)[1];
5500 struct nlattr *data = ((void **)skb->cb)[2];
5502 if (WARN_ON(!rdev->testmode_info)) {
5507 nla_nest_end(skb, data);
5508 genlmsg_end(skb, hdr);
5509 return genlmsg_reply(skb, rdev->testmode_info);
5511 EXPORT_SYMBOL(cfg80211_testmode_reply);
5513 struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5514 int approxlen, gfp_t gfp)
5516 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5518 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5520 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5522 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5524 void *hdr = ((void **)skb->cb)[1];
5525 struct nlattr *data = ((void **)skb->cb)[2];
5527 nla_nest_end(skb, data);
5528 genlmsg_end(skb, hdr);
5529 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5531 EXPORT_SYMBOL(cfg80211_testmode_event);
5534 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5537 struct net_device *dev = info->user_ptr[1];
5538 struct cfg80211_connect_params connect;
5539 struct wiphy *wiphy;
5540 struct cfg80211_cached_keys *connkeys = NULL;
5543 memset(&connect, 0, sizeof(connect));
5545 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5548 if (!info->attrs[NL80211_ATTR_SSID] ||
5549 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5552 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5554 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5555 if (!nl80211_valid_auth_type(connect.auth_type))
5558 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5560 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5562 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
5563 NL80211_MAX_NR_CIPHER_SUITES);
5567 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5568 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5571 wiphy = &rdev->wiphy;
5573 connect.bg_scan_period = -1;
5574 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5575 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5576 connect.bg_scan_period =
5577 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5580 if (info->attrs[NL80211_ATTR_MAC])
5581 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5582 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5583 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5585 if (info->attrs[NL80211_ATTR_IE]) {
5586 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5587 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5590 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5592 ieee80211_get_channel(wiphy,
5593 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5594 if (!connect.channel ||
5595 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5599 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5600 connkeys = nl80211_parse_connkeys(rdev,
5601 info->attrs[NL80211_ATTR_KEYS]);
5602 if (IS_ERR(connkeys))
5603 return PTR_ERR(connkeys);
5606 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5607 connect.flags |= ASSOC_REQ_DISABLE_HT;
5609 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5610 memcpy(&connect.ht_capa_mask,
5611 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5612 sizeof(connect.ht_capa_mask));
5614 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5615 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5617 memcpy(&connect.ht_capa,
5618 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5619 sizeof(connect.ht_capa));
5622 err = cfg80211_connect(rdev, dev, &connect, connkeys);
5628 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5630 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5631 struct net_device *dev = info->user_ptr[1];
5634 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5635 reason = WLAN_REASON_DEAUTH_LEAVING;
5637 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5642 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5643 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5646 return cfg80211_disconnect(rdev, dev, reason, true);
5649 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5656 if (!info->attrs[NL80211_ATTR_PID])
5659 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5661 net = get_net_ns_by_pid(pid);
5663 return PTR_ERR(net);
5667 /* check if anything to do */
5668 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5669 err = cfg80211_switch_netns(rdev, net);
5675 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5678 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5679 struct cfg80211_pmksa *pmksa) = NULL;
5680 struct net_device *dev = info->user_ptr[1];
5681 struct cfg80211_pmksa pmksa;
5683 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5685 if (!info->attrs[NL80211_ATTR_MAC])
5688 if (!info->attrs[NL80211_ATTR_PMKID])
5691 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5692 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5694 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5695 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5698 switch (info->genlhdr->cmd) {
5699 case NL80211_CMD_SET_PMKSA:
5700 rdev_ops = rdev->ops->set_pmksa;
5702 case NL80211_CMD_DEL_PMKSA:
5703 rdev_ops = rdev->ops->del_pmksa;
5713 return rdev_ops(&rdev->wiphy, dev, &pmksa);
5716 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5718 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5719 struct net_device *dev = info->user_ptr[1];
5721 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5722 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5725 if (!rdev->ops->flush_pmksa)
5728 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
5731 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5733 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5734 struct net_device *dev = info->user_ptr[1];
5735 u8 action_code, dialog_token;
5739 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5740 !rdev->ops->tdls_mgmt)
5743 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5744 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5745 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5746 !info->attrs[NL80211_ATTR_IE] ||
5747 !info->attrs[NL80211_ATTR_MAC])
5750 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5751 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5752 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5753 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5755 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5756 dialog_token, status_code,
5757 nla_data(info->attrs[NL80211_ATTR_IE]),
5758 nla_len(info->attrs[NL80211_ATTR_IE]));
5761 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5764 struct net_device *dev = info->user_ptr[1];
5765 enum nl80211_tdls_operation operation;
5768 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5769 !rdev->ops->tdls_oper)
5772 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5773 !info->attrs[NL80211_ATTR_MAC])
5776 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5777 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5779 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5782 static int nl80211_remain_on_channel(struct sk_buff *skb,
5783 struct genl_info *info)
5785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5786 struct wireless_dev *wdev = info->user_ptr[1];
5787 struct ieee80211_channel *chan;
5788 struct sk_buff *msg;
5791 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5795 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5796 !info->attrs[NL80211_ATTR_DURATION])
5799 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5801 if (!rdev->ops->remain_on_channel ||
5802 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
5806 * We should be on that channel for at least a minimum amount of
5807 * time (10ms) but no longer than the driver supports.
5809 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5810 duration > rdev->wiphy.max_remain_on_channel_duration)
5813 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5814 !nl80211_valid_channel_type(info, &channel_type))
5817 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5818 chan = rdev_freq_to_chan(rdev, freq, channel_type);
5822 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5826 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5827 NL80211_CMD_REMAIN_ON_CHANNEL);
5834 err = rdev->ops->remain_on_channel(&rdev->wiphy, wdev, chan,
5835 channel_type, duration, &cookie);
5840 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5841 goto nla_put_failure;
5843 genlmsg_end(msg, hdr);
5845 return genlmsg_reply(msg, info);
5854 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5855 struct genl_info *info)
5857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5858 struct wireless_dev *wdev = info->user_ptr[1];
5861 if (!info->attrs[NL80211_ATTR_COOKIE])
5864 if (!rdev->ops->cancel_remain_on_channel)
5867 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5869 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie);
5872 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5873 u8 *rates, u8 rates_len)
5878 for (i = 0; i < rates_len; i++) {
5879 int rate = (rates[i] & 0x7f) * 5;
5881 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5882 struct ieee80211_rate *srate =
5883 &sband->bitrates[ridx];
5884 if (rate == srate->bitrate) {
5889 if (ridx == sband->n_bitrates)
5890 return 0; /* rate not found */
5896 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5897 u8 *rates, u8 rates_len,
5898 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5902 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5904 for (i = 0; i < rates_len; i++) {
5907 ridx = rates[i] / 8;
5908 rbit = BIT(rates[i] % 8);
5910 /* check validity */
5911 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
5914 /* check availability */
5915 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5924 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
5925 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5926 .len = NL80211_MAX_SUPP_RATES },
5927 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5928 .len = NL80211_MAX_SUPP_HT_RATES },
5931 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5932 struct genl_info *info)
5934 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
5935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5936 struct cfg80211_bitrate_mask mask;
5938 struct net_device *dev = info->user_ptr[1];
5939 struct nlattr *tx_rates;
5940 struct ieee80211_supported_band *sband;
5942 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5945 if (!rdev->ops->set_bitrate_mask)
5948 memset(&mask, 0, sizeof(mask));
5949 /* Default to all rates enabled */
5950 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5951 sband = rdev->wiphy.bands[i];
5952 mask.control[i].legacy =
5953 sband ? (1 << sband->n_bitrates) - 1 : 0;
5955 memcpy(mask.control[i].mcs,
5956 sband->ht_cap.mcs.rx_mask,
5957 sizeof(mask.control[i].mcs));
5959 memset(mask.control[i].mcs, 0,
5960 sizeof(mask.control[i].mcs));
5964 * The nested attribute uses enum nl80211_band as the index. This maps
5965 * directly to the enum ieee80211_band values used in cfg80211.
5967 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
5968 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5970 enum ieee80211_band band = nla_type(tx_rates);
5971 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5973 sband = rdev->wiphy.bands[band];
5976 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5977 nla_len(tx_rates), nl80211_txattr_policy);
5978 if (tb[NL80211_TXRATE_LEGACY]) {
5979 mask.control[band].legacy = rateset_to_mask(
5981 nla_data(tb[NL80211_TXRATE_LEGACY]),
5982 nla_len(tb[NL80211_TXRATE_LEGACY]));
5983 if ((mask.control[band].legacy == 0) &&
5984 nla_len(tb[NL80211_TXRATE_LEGACY]))
5987 if (tb[NL80211_TXRATE_MCS]) {
5988 if (!ht_rateset_to_mask(
5990 nla_data(tb[NL80211_TXRATE_MCS]),
5991 nla_len(tb[NL80211_TXRATE_MCS]),
5992 mask.control[band].mcs))
5996 if (mask.control[band].legacy == 0) {
5997 /* don't allow empty legacy rates if HT
5998 * is not even supported. */
5999 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6002 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6003 if (mask.control[band].mcs[i])
6006 /* legacy and mcs rates may not be both empty */
6007 if (i == IEEE80211_HT_MCS_MASK_LEN)
6012 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
6015 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
6017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6018 struct wireless_dev *wdev = info->user_ptr[1];
6019 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
6021 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6024 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6025 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
6027 switch (wdev->iftype) {
6028 case NL80211_IFTYPE_STATION:
6029 case NL80211_IFTYPE_ADHOC:
6030 case NL80211_IFTYPE_P2P_CLIENT:
6031 case NL80211_IFTYPE_AP:
6032 case NL80211_IFTYPE_AP_VLAN:
6033 case NL80211_IFTYPE_MESH_POINT:
6034 case NL80211_IFTYPE_P2P_GO:
6040 /* not much point in registering if we can't reply */
6041 if (!rdev->ops->mgmt_tx)
6044 return cfg80211_mlme_register_mgmt(wdev, info->snd_pid, frame_type,
6045 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6046 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
6049 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
6051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6052 struct wireless_dev *wdev = info->user_ptr[1];
6053 struct ieee80211_channel *chan;
6054 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6055 bool channel_type_valid = false;
6060 struct sk_buff *msg = NULL;
6061 unsigned int wait = 0;
6062 bool offchan, no_cck, dont_wait_for_ack;
6064 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
6066 if (!info->attrs[NL80211_ATTR_FRAME] ||
6067 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
6070 if (!rdev->ops->mgmt_tx)
6073 switch (wdev->iftype) {
6074 case NL80211_IFTYPE_STATION:
6075 case NL80211_IFTYPE_ADHOC:
6076 case NL80211_IFTYPE_P2P_CLIENT:
6077 case NL80211_IFTYPE_AP:
6078 case NL80211_IFTYPE_AP_VLAN:
6079 case NL80211_IFTYPE_MESH_POINT:
6080 case NL80211_IFTYPE_P2P_GO:
6086 if (info->attrs[NL80211_ATTR_DURATION]) {
6087 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6089 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6092 * We should wait on the channel for at least a minimum amount
6093 * of time (10ms) but no longer than the driver supports.
6095 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6096 wait > rdev->wiphy.max_remain_on_channel_duration)
6101 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
6102 if (!nl80211_valid_channel_type(info, &channel_type))
6104 channel_type_valid = true;
6107 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6109 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6112 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6114 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6115 chan = rdev_freq_to_chan(rdev, freq, channel_type);
6119 if (!dont_wait_for_ack) {
6120 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6124 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6133 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type,
6134 channel_type_valid, wait,
6135 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6136 nla_len(info->attrs[NL80211_ATTR_FRAME]),
6137 no_cck, dont_wait_for_ack, &cookie);
6142 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6143 goto nla_put_failure;
6145 genlmsg_end(msg, hdr);
6146 return genlmsg_reply(msg, info);
6158 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6161 struct wireless_dev *wdev = info->user_ptr[1];
6164 if (!info->attrs[NL80211_ATTR_COOKIE])
6167 if (!rdev->ops->mgmt_tx_cancel_wait)
6170 switch (wdev->iftype) {
6171 case NL80211_IFTYPE_STATION:
6172 case NL80211_IFTYPE_ADHOC:
6173 case NL80211_IFTYPE_P2P_CLIENT:
6174 case NL80211_IFTYPE_AP:
6175 case NL80211_IFTYPE_AP_VLAN:
6176 case NL80211_IFTYPE_P2P_GO:
6182 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6184 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie);
6187 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6190 struct wireless_dev *wdev;
6191 struct net_device *dev = info->user_ptr[1];
6196 if (!info->attrs[NL80211_ATTR_PS_STATE])
6199 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6201 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6204 wdev = dev->ieee80211_ptr;
6206 if (!rdev->ops->set_power_mgmt)
6209 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6211 if (state == wdev->ps)
6214 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6221 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6224 enum nl80211_ps_state ps_state;
6225 struct wireless_dev *wdev;
6226 struct net_device *dev = info->user_ptr[1];
6227 struct sk_buff *msg;
6231 wdev = dev->ieee80211_ptr;
6233 if (!rdev->ops->set_power_mgmt)
6236 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6240 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6241 NL80211_CMD_GET_POWER_SAVE);
6248 ps_state = NL80211_PS_ENABLED;
6250 ps_state = NL80211_PS_DISABLED;
6252 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6253 goto nla_put_failure;
6255 genlmsg_end(msg, hdr);
6256 return genlmsg_reply(msg, info);
6265 static struct nla_policy
6266 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6267 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6268 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6269 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6270 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6271 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6272 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
6275 static int nl80211_set_cqm_txe(struct genl_info *info,
6276 u32 rate, u32 pkts, u32 intvl)
6278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6279 struct wireless_dev *wdev;
6280 struct net_device *dev = info->user_ptr[1];
6282 if ((rate < 0 || rate > 100) ||
6283 (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL))
6286 wdev = dev->ieee80211_ptr;
6288 if (!rdev->ops->set_cqm_txe_config)
6291 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6292 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6295 return rdev->ops->set_cqm_txe_config(wdev->wiphy, dev,
6299 static int nl80211_set_cqm_rssi(struct genl_info *info,
6300 s32 threshold, u32 hysteresis)
6302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6303 struct wireless_dev *wdev;
6304 struct net_device *dev = info->user_ptr[1];
6309 wdev = dev->ieee80211_ptr;
6311 if (!rdev->ops->set_cqm_rssi_config)
6314 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6315 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6318 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6319 threshold, hysteresis);
6322 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6324 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6328 cqm = info->attrs[NL80211_ATTR_CQM];
6334 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6335 nl80211_attr_cqm_policy);
6339 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6340 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6343 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6344 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6345 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6346 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
6347 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
6348 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
6349 u32 rate, pkts, intvl;
6350 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
6351 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
6352 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
6353 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
6361 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6364 struct net_device *dev = info->user_ptr[1];
6365 struct mesh_config cfg;
6366 struct mesh_setup setup;
6369 /* start with default */
6370 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
6371 memcpy(&setup, &default_mesh_setup, sizeof(setup));
6373 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
6374 /* and parse parameters if given */
6375 err = nl80211_parse_mesh_config(info, &cfg, NULL);
6380 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6381 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6384 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6385 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6387 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6388 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6389 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6392 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6393 /* parse additional setup parameters if given */
6394 err = nl80211_parse_mesh_setup(info, &setup);
6399 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6400 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6402 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6403 !nl80211_valid_channel_type(info, &channel_type))
6406 setup.channel = rdev_freq_to_chan(rdev,
6407 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6411 setup.channel_type = channel_type;
6413 /* cfg80211_join_mesh() will sort it out */
6414 setup.channel = NULL;
6417 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
6420 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6422 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6423 struct net_device *dev = info->user_ptr[1];
6425 return cfg80211_leave_mesh(rdev, dev);
6429 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6432 struct sk_buff *msg;
6435 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6442 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6443 NL80211_CMD_GET_WOWLAN);
6445 goto nla_put_failure;
6448 struct nlattr *nl_wowlan;
6450 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6452 goto nla_put_failure;
6454 if ((rdev->wowlan->any &&
6455 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6456 (rdev->wowlan->disconnect &&
6457 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6458 (rdev->wowlan->magic_pkt &&
6459 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6460 (rdev->wowlan->gtk_rekey_failure &&
6461 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6462 (rdev->wowlan->eap_identity_req &&
6463 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6464 (rdev->wowlan->four_way_handshake &&
6465 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6466 (rdev->wowlan->rfkill_release &&
6467 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6468 goto nla_put_failure;
6469 if (rdev->wowlan->n_patterns) {
6470 struct nlattr *nl_pats, *nl_pat;
6473 nl_pats = nla_nest_start(msg,
6474 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6476 goto nla_put_failure;
6478 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6479 nl_pat = nla_nest_start(msg, i + 1);
6481 goto nla_put_failure;
6482 pat_len = rdev->wowlan->patterns[i].pattern_len;
6483 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6484 DIV_ROUND_UP(pat_len, 8),
6485 rdev->wowlan->patterns[i].mask) ||
6486 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6488 rdev->wowlan->patterns[i].pattern))
6489 goto nla_put_failure;
6490 nla_nest_end(msg, nl_pat);
6492 nla_nest_end(msg, nl_pats);
6495 nla_nest_end(msg, nl_wowlan);
6498 genlmsg_end(msg, hdr);
6499 return genlmsg_reply(msg, info);
6506 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6509 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6510 struct cfg80211_wowlan new_triggers = {};
6511 struct cfg80211_wowlan *ntrig;
6512 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6514 bool prev_enabled = rdev->wowlan;
6516 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6519 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
6520 cfg80211_rdev_free_wowlan(rdev);
6521 rdev->wowlan = NULL;
6525 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6526 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6527 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6528 nl80211_wowlan_policy);
6532 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6533 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6535 new_triggers.any = true;
6538 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6539 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6541 new_triggers.disconnect = true;
6544 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6545 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6547 new_triggers.magic_pkt = true;
6550 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6553 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6554 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6556 new_triggers.gtk_rekey_failure = true;
6559 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6560 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6562 new_triggers.eap_identity_req = true;
6565 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6566 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6568 new_triggers.four_way_handshake = true;
6571 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6572 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6574 new_triggers.rfkill_release = true;
6577 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6580 int rem, pat_len, mask_len;
6581 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6583 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6586 if (n_patterns > wowlan->n_patterns)
6589 new_triggers.patterns = kcalloc(n_patterns,
6590 sizeof(new_triggers.patterns[0]),
6592 if (!new_triggers.patterns)
6595 new_triggers.n_patterns = n_patterns;
6598 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6600 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6601 nla_data(pat), nla_len(pat), NULL);
6603 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6604 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6606 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6607 mask_len = DIV_ROUND_UP(pat_len, 8);
6608 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6611 if (pat_len > wowlan->pattern_max_len ||
6612 pat_len < wowlan->pattern_min_len)
6615 new_triggers.patterns[i].mask =
6616 kmalloc(mask_len + pat_len, GFP_KERNEL);
6617 if (!new_triggers.patterns[i].mask) {
6621 new_triggers.patterns[i].pattern =
6622 new_triggers.patterns[i].mask + mask_len;
6623 memcpy(new_triggers.patterns[i].mask,
6624 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6626 new_triggers.patterns[i].pattern_len = pat_len;
6627 memcpy(new_triggers.patterns[i].pattern,
6628 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6634 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
6639 cfg80211_rdev_free_wowlan(rdev);
6640 rdev->wowlan = ntrig;
6643 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6644 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6648 for (i = 0; i < new_triggers.n_patterns; i++)
6649 kfree(new_triggers.patterns[i].mask);
6650 kfree(new_triggers.patterns);
6655 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6658 struct net_device *dev = info->user_ptr[1];
6659 struct wireless_dev *wdev = dev->ieee80211_ptr;
6660 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6661 struct cfg80211_gtk_rekey_data rekey_data;
6664 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6667 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6668 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6669 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6670 nl80211_rekey_policy);
6674 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6676 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6678 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6681 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6683 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6685 memcpy(rekey_data.replay_ctr,
6686 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6687 NL80211_REPLAY_CTR_LEN);
6690 if (!wdev->current_bss) {
6695 if (!rdev->ops->set_rekey_data) {
6700 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6706 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6707 struct genl_info *info)
6709 struct net_device *dev = info->user_ptr[1];
6710 struct wireless_dev *wdev = dev->ieee80211_ptr;
6712 if (wdev->iftype != NL80211_IFTYPE_AP &&
6713 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6716 if (wdev->ap_unexpected_nlpid)
6719 wdev->ap_unexpected_nlpid = info->snd_pid;
6723 static int nl80211_probe_client(struct sk_buff *skb,
6724 struct genl_info *info)
6726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6727 struct net_device *dev = info->user_ptr[1];
6728 struct wireless_dev *wdev = dev->ieee80211_ptr;
6729 struct sk_buff *msg;
6735 if (wdev->iftype != NL80211_IFTYPE_AP &&
6736 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6739 if (!info->attrs[NL80211_ATTR_MAC])
6742 if (!rdev->ops->probe_client)
6745 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6749 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6750 NL80211_CMD_PROBE_CLIENT);
6757 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6759 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6763 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6764 goto nla_put_failure;
6766 genlmsg_end(msg, hdr);
6768 return genlmsg_reply(msg, info);
6777 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6781 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6784 if (rdev->ap_beacons_nlpid)
6787 rdev->ap_beacons_nlpid = info->snd_pid;
6792 #define NL80211_FLAG_NEED_WIPHY 0x01
6793 #define NL80211_FLAG_NEED_NETDEV 0x02
6794 #define NL80211_FLAG_NEED_RTNL 0x04
6795 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6796 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6797 NL80211_FLAG_CHECK_NETDEV_UP)
6798 #define NL80211_FLAG_NEED_WDEV 0x10
6799 /* If a netdev is associated, it must be UP */
6800 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6801 NL80211_FLAG_CHECK_NETDEV_UP)
6803 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6804 struct genl_info *info)
6806 struct cfg80211_registered_device *rdev;
6807 struct wireless_dev *wdev;
6808 struct net_device *dev;
6809 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6814 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
6815 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6819 return PTR_ERR(rdev);
6821 info->user_ptr[0] = rdev;
6822 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
6823 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
6824 mutex_lock(&cfg80211_mutex);
6825 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
6828 mutex_unlock(&cfg80211_mutex);
6831 return PTR_ERR(wdev);
6835 rdev = wiphy_to_dev(wdev->wiphy);
6837 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
6839 mutex_unlock(&cfg80211_mutex);
6845 info->user_ptr[1] = dev;
6847 info->user_ptr[1] = wdev;
6851 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6852 !netif_running(dev)) {
6853 mutex_unlock(&cfg80211_mutex);
6862 cfg80211_lock_rdev(rdev);
6864 mutex_unlock(&cfg80211_mutex);
6866 info->user_ptr[0] = rdev;
6872 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6873 struct genl_info *info)
6875 if (info->user_ptr[0])
6876 cfg80211_unlock_rdev(info->user_ptr[0]);
6877 if (info->user_ptr[1]) {
6878 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
6879 struct wireless_dev *wdev = info->user_ptr[1];
6882 dev_put(wdev->netdev);
6884 dev_put(info->user_ptr[1]);
6887 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6891 static struct genl_ops nl80211_ops[] = {
6893 .cmd = NL80211_CMD_GET_WIPHY,
6894 .doit = nl80211_get_wiphy,
6895 .dumpit = nl80211_dump_wiphy,
6896 .policy = nl80211_policy,
6897 /* can be retrieved by unprivileged users */
6898 .internal_flags = NL80211_FLAG_NEED_WIPHY,
6901 .cmd = NL80211_CMD_SET_WIPHY,
6902 .doit = nl80211_set_wiphy,
6903 .policy = nl80211_policy,
6904 .flags = GENL_ADMIN_PERM,
6905 .internal_flags = NL80211_FLAG_NEED_RTNL,
6908 .cmd = NL80211_CMD_GET_INTERFACE,
6909 .doit = nl80211_get_interface,
6910 .dumpit = nl80211_dump_interface,
6911 .policy = nl80211_policy,
6912 /* can be retrieved by unprivileged users */
6913 .internal_flags = NL80211_FLAG_NEED_WDEV,
6916 .cmd = NL80211_CMD_SET_INTERFACE,
6917 .doit = nl80211_set_interface,
6918 .policy = nl80211_policy,
6919 .flags = GENL_ADMIN_PERM,
6920 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6921 NL80211_FLAG_NEED_RTNL,
6924 .cmd = NL80211_CMD_NEW_INTERFACE,
6925 .doit = nl80211_new_interface,
6926 .policy = nl80211_policy,
6927 .flags = GENL_ADMIN_PERM,
6928 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6929 NL80211_FLAG_NEED_RTNL,
6932 .cmd = NL80211_CMD_DEL_INTERFACE,
6933 .doit = nl80211_del_interface,
6934 .policy = nl80211_policy,
6935 .flags = GENL_ADMIN_PERM,
6936 .internal_flags = NL80211_FLAG_NEED_WDEV |
6937 NL80211_FLAG_NEED_RTNL,
6940 .cmd = NL80211_CMD_GET_KEY,
6941 .doit = nl80211_get_key,
6942 .policy = nl80211_policy,
6943 .flags = GENL_ADMIN_PERM,
6944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6945 NL80211_FLAG_NEED_RTNL,
6948 .cmd = NL80211_CMD_SET_KEY,
6949 .doit = nl80211_set_key,
6950 .policy = nl80211_policy,
6951 .flags = GENL_ADMIN_PERM,
6952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6953 NL80211_FLAG_NEED_RTNL,
6956 .cmd = NL80211_CMD_NEW_KEY,
6957 .doit = nl80211_new_key,
6958 .policy = nl80211_policy,
6959 .flags = GENL_ADMIN_PERM,
6960 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6961 NL80211_FLAG_NEED_RTNL,
6964 .cmd = NL80211_CMD_DEL_KEY,
6965 .doit = nl80211_del_key,
6966 .policy = nl80211_policy,
6967 .flags = GENL_ADMIN_PERM,
6968 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6969 NL80211_FLAG_NEED_RTNL,
6972 .cmd = NL80211_CMD_SET_BEACON,
6973 .policy = nl80211_policy,
6974 .flags = GENL_ADMIN_PERM,
6975 .doit = nl80211_set_beacon,
6976 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6977 NL80211_FLAG_NEED_RTNL,
6980 .cmd = NL80211_CMD_START_AP,
6981 .policy = nl80211_policy,
6982 .flags = GENL_ADMIN_PERM,
6983 .doit = nl80211_start_ap,
6984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6985 NL80211_FLAG_NEED_RTNL,
6988 .cmd = NL80211_CMD_STOP_AP,
6989 .policy = nl80211_policy,
6990 .flags = GENL_ADMIN_PERM,
6991 .doit = nl80211_stop_ap,
6992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6993 NL80211_FLAG_NEED_RTNL,
6996 .cmd = NL80211_CMD_GET_STATION,
6997 .doit = nl80211_get_station,
6998 .dumpit = nl80211_dump_station,
6999 .policy = nl80211_policy,
7000 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7001 NL80211_FLAG_NEED_RTNL,
7004 .cmd = NL80211_CMD_SET_STATION,
7005 .doit = nl80211_set_station,
7006 .policy = nl80211_policy,
7007 .flags = GENL_ADMIN_PERM,
7008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7009 NL80211_FLAG_NEED_RTNL,
7012 .cmd = NL80211_CMD_NEW_STATION,
7013 .doit = nl80211_new_station,
7014 .policy = nl80211_policy,
7015 .flags = GENL_ADMIN_PERM,
7016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7017 NL80211_FLAG_NEED_RTNL,
7020 .cmd = NL80211_CMD_DEL_STATION,
7021 .doit = nl80211_del_station,
7022 .policy = nl80211_policy,
7023 .flags = GENL_ADMIN_PERM,
7024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7025 NL80211_FLAG_NEED_RTNL,
7028 .cmd = NL80211_CMD_GET_MPATH,
7029 .doit = nl80211_get_mpath,
7030 .dumpit = nl80211_dump_mpath,
7031 .policy = nl80211_policy,
7032 .flags = GENL_ADMIN_PERM,
7033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7034 NL80211_FLAG_NEED_RTNL,
7037 .cmd = NL80211_CMD_SET_MPATH,
7038 .doit = nl80211_set_mpath,
7039 .policy = nl80211_policy,
7040 .flags = GENL_ADMIN_PERM,
7041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7042 NL80211_FLAG_NEED_RTNL,
7045 .cmd = NL80211_CMD_NEW_MPATH,
7046 .doit = nl80211_new_mpath,
7047 .policy = nl80211_policy,
7048 .flags = GENL_ADMIN_PERM,
7049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7050 NL80211_FLAG_NEED_RTNL,
7053 .cmd = NL80211_CMD_DEL_MPATH,
7054 .doit = nl80211_del_mpath,
7055 .policy = nl80211_policy,
7056 .flags = GENL_ADMIN_PERM,
7057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7058 NL80211_FLAG_NEED_RTNL,
7061 .cmd = NL80211_CMD_SET_BSS,
7062 .doit = nl80211_set_bss,
7063 .policy = nl80211_policy,
7064 .flags = GENL_ADMIN_PERM,
7065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7066 NL80211_FLAG_NEED_RTNL,
7069 .cmd = NL80211_CMD_GET_REG,
7070 .doit = nl80211_get_reg,
7071 .policy = nl80211_policy,
7072 /* can be retrieved by unprivileged users */
7075 .cmd = NL80211_CMD_SET_REG,
7076 .doit = nl80211_set_reg,
7077 .policy = nl80211_policy,
7078 .flags = GENL_ADMIN_PERM,
7081 .cmd = NL80211_CMD_REQ_SET_REG,
7082 .doit = nl80211_req_set_reg,
7083 .policy = nl80211_policy,
7084 .flags = GENL_ADMIN_PERM,
7087 .cmd = NL80211_CMD_GET_MESH_CONFIG,
7088 .doit = nl80211_get_mesh_config,
7089 .policy = nl80211_policy,
7090 /* can be retrieved by unprivileged users */
7091 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7092 NL80211_FLAG_NEED_RTNL,
7095 .cmd = NL80211_CMD_SET_MESH_CONFIG,
7096 .doit = nl80211_update_mesh_config,
7097 .policy = nl80211_policy,
7098 .flags = GENL_ADMIN_PERM,
7099 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7100 NL80211_FLAG_NEED_RTNL,
7103 .cmd = NL80211_CMD_TRIGGER_SCAN,
7104 .doit = nl80211_trigger_scan,
7105 .policy = nl80211_policy,
7106 .flags = GENL_ADMIN_PERM,
7107 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7108 NL80211_FLAG_NEED_RTNL,
7111 .cmd = NL80211_CMD_GET_SCAN,
7112 .policy = nl80211_policy,
7113 .dumpit = nl80211_dump_scan,
7116 .cmd = NL80211_CMD_START_SCHED_SCAN,
7117 .doit = nl80211_start_sched_scan,
7118 .policy = nl80211_policy,
7119 .flags = GENL_ADMIN_PERM,
7120 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7121 NL80211_FLAG_NEED_RTNL,
7124 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
7125 .doit = nl80211_stop_sched_scan,
7126 .policy = nl80211_policy,
7127 .flags = GENL_ADMIN_PERM,
7128 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7129 NL80211_FLAG_NEED_RTNL,
7132 .cmd = NL80211_CMD_AUTHENTICATE,
7133 .doit = nl80211_authenticate,
7134 .policy = nl80211_policy,
7135 .flags = GENL_ADMIN_PERM,
7136 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7137 NL80211_FLAG_NEED_RTNL,
7140 .cmd = NL80211_CMD_ASSOCIATE,
7141 .doit = nl80211_associate,
7142 .policy = nl80211_policy,
7143 .flags = GENL_ADMIN_PERM,
7144 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7145 NL80211_FLAG_NEED_RTNL,
7148 .cmd = NL80211_CMD_DEAUTHENTICATE,
7149 .doit = nl80211_deauthenticate,
7150 .policy = nl80211_policy,
7151 .flags = GENL_ADMIN_PERM,
7152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7153 NL80211_FLAG_NEED_RTNL,
7156 .cmd = NL80211_CMD_DISASSOCIATE,
7157 .doit = nl80211_disassociate,
7158 .policy = nl80211_policy,
7159 .flags = GENL_ADMIN_PERM,
7160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7161 NL80211_FLAG_NEED_RTNL,
7164 .cmd = NL80211_CMD_JOIN_IBSS,
7165 .doit = nl80211_join_ibss,
7166 .policy = nl80211_policy,
7167 .flags = GENL_ADMIN_PERM,
7168 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7169 NL80211_FLAG_NEED_RTNL,
7172 .cmd = NL80211_CMD_LEAVE_IBSS,
7173 .doit = nl80211_leave_ibss,
7174 .policy = nl80211_policy,
7175 .flags = GENL_ADMIN_PERM,
7176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7177 NL80211_FLAG_NEED_RTNL,
7179 #ifdef CONFIG_NL80211_TESTMODE
7181 .cmd = NL80211_CMD_TESTMODE,
7182 .doit = nl80211_testmode_do,
7183 .dumpit = nl80211_testmode_dump,
7184 .policy = nl80211_policy,
7185 .flags = GENL_ADMIN_PERM,
7186 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7187 NL80211_FLAG_NEED_RTNL,
7191 .cmd = NL80211_CMD_CONNECT,
7192 .doit = nl80211_connect,
7193 .policy = nl80211_policy,
7194 .flags = GENL_ADMIN_PERM,
7195 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7196 NL80211_FLAG_NEED_RTNL,
7199 .cmd = NL80211_CMD_DISCONNECT,
7200 .doit = nl80211_disconnect,
7201 .policy = nl80211_policy,
7202 .flags = GENL_ADMIN_PERM,
7203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7204 NL80211_FLAG_NEED_RTNL,
7207 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7208 .doit = nl80211_wiphy_netns,
7209 .policy = nl80211_policy,
7210 .flags = GENL_ADMIN_PERM,
7211 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7212 NL80211_FLAG_NEED_RTNL,
7215 .cmd = NL80211_CMD_GET_SURVEY,
7216 .policy = nl80211_policy,
7217 .dumpit = nl80211_dump_survey,
7220 .cmd = NL80211_CMD_SET_PMKSA,
7221 .doit = nl80211_setdel_pmksa,
7222 .policy = nl80211_policy,
7223 .flags = GENL_ADMIN_PERM,
7224 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7225 NL80211_FLAG_NEED_RTNL,
7228 .cmd = NL80211_CMD_DEL_PMKSA,
7229 .doit = nl80211_setdel_pmksa,
7230 .policy = nl80211_policy,
7231 .flags = GENL_ADMIN_PERM,
7232 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7233 NL80211_FLAG_NEED_RTNL,
7236 .cmd = NL80211_CMD_FLUSH_PMKSA,
7237 .doit = nl80211_flush_pmksa,
7238 .policy = nl80211_policy,
7239 .flags = GENL_ADMIN_PERM,
7240 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7241 NL80211_FLAG_NEED_RTNL,
7244 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7245 .doit = nl80211_remain_on_channel,
7246 .policy = nl80211_policy,
7247 .flags = GENL_ADMIN_PERM,
7248 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7249 NL80211_FLAG_NEED_RTNL,
7252 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7253 .doit = nl80211_cancel_remain_on_channel,
7254 .policy = nl80211_policy,
7255 .flags = GENL_ADMIN_PERM,
7256 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7257 NL80211_FLAG_NEED_RTNL,
7260 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7261 .doit = nl80211_set_tx_bitrate_mask,
7262 .policy = nl80211_policy,
7263 .flags = GENL_ADMIN_PERM,
7264 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7265 NL80211_FLAG_NEED_RTNL,
7268 .cmd = NL80211_CMD_REGISTER_FRAME,
7269 .doit = nl80211_register_mgmt,
7270 .policy = nl80211_policy,
7271 .flags = GENL_ADMIN_PERM,
7272 .internal_flags = NL80211_FLAG_NEED_WDEV |
7273 NL80211_FLAG_NEED_RTNL,
7276 .cmd = NL80211_CMD_FRAME,
7277 .doit = nl80211_tx_mgmt,
7278 .policy = nl80211_policy,
7279 .flags = GENL_ADMIN_PERM,
7280 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7281 NL80211_FLAG_NEED_RTNL,
7284 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7285 .doit = nl80211_tx_mgmt_cancel_wait,
7286 .policy = nl80211_policy,
7287 .flags = GENL_ADMIN_PERM,
7288 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7289 NL80211_FLAG_NEED_RTNL,
7292 .cmd = NL80211_CMD_SET_POWER_SAVE,
7293 .doit = nl80211_set_power_save,
7294 .policy = nl80211_policy,
7295 .flags = GENL_ADMIN_PERM,
7296 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7297 NL80211_FLAG_NEED_RTNL,
7300 .cmd = NL80211_CMD_GET_POWER_SAVE,
7301 .doit = nl80211_get_power_save,
7302 .policy = nl80211_policy,
7303 /* can be retrieved by unprivileged users */
7304 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7305 NL80211_FLAG_NEED_RTNL,
7308 .cmd = NL80211_CMD_SET_CQM,
7309 .doit = nl80211_set_cqm,
7310 .policy = nl80211_policy,
7311 .flags = GENL_ADMIN_PERM,
7312 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7313 NL80211_FLAG_NEED_RTNL,
7316 .cmd = NL80211_CMD_SET_CHANNEL,
7317 .doit = nl80211_set_channel,
7318 .policy = nl80211_policy,
7319 .flags = GENL_ADMIN_PERM,
7320 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7321 NL80211_FLAG_NEED_RTNL,
7324 .cmd = NL80211_CMD_SET_WDS_PEER,
7325 .doit = nl80211_set_wds_peer,
7326 .policy = nl80211_policy,
7327 .flags = GENL_ADMIN_PERM,
7328 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7329 NL80211_FLAG_NEED_RTNL,
7332 .cmd = NL80211_CMD_JOIN_MESH,
7333 .doit = nl80211_join_mesh,
7334 .policy = nl80211_policy,
7335 .flags = GENL_ADMIN_PERM,
7336 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7337 NL80211_FLAG_NEED_RTNL,
7340 .cmd = NL80211_CMD_LEAVE_MESH,
7341 .doit = nl80211_leave_mesh,
7342 .policy = nl80211_policy,
7343 .flags = GENL_ADMIN_PERM,
7344 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7345 NL80211_FLAG_NEED_RTNL,
7349 .cmd = NL80211_CMD_GET_WOWLAN,
7350 .doit = nl80211_get_wowlan,
7351 .policy = nl80211_policy,
7352 /* can be retrieved by unprivileged users */
7353 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7354 NL80211_FLAG_NEED_RTNL,
7357 .cmd = NL80211_CMD_SET_WOWLAN,
7358 .doit = nl80211_set_wowlan,
7359 .policy = nl80211_policy,
7360 .flags = GENL_ADMIN_PERM,
7361 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7362 NL80211_FLAG_NEED_RTNL,
7366 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7367 .doit = nl80211_set_rekey_data,
7368 .policy = nl80211_policy,
7369 .flags = GENL_ADMIN_PERM,
7370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7371 NL80211_FLAG_NEED_RTNL,
7374 .cmd = NL80211_CMD_TDLS_MGMT,
7375 .doit = nl80211_tdls_mgmt,
7376 .policy = nl80211_policy,
7377 .flags = GENL_ADMIN_PERM,
7378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7379 NL80211_FLAG_NEED_RTNL,
7382 .cmd = NL80211_CMD_TDLS_OPER,
7383 .doit = nl80211_tdls_oper,
7384 .policy = nl80211_policy,
7385 .flags = GENL_ADMIN_PERM,
7386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7387 NL80211_FLAG_NEED_RTNL,
7390 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7391 .doit = nl80211_register_unexpected_frame,
7392 .policy = nl80211_policy,
7393 .flags = GENL_ADMIN_PERM,
7394 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7395 NL80211_FLAG_NEED_RTNL,
7398 .cmd = NL80211_CMD_PROBE_CLIENT,
7399 .doit = nl80211_probe_client,
7400 .policy = nl80211_policy,
7401 .flags = GENL_ADMIN_PERM,
7402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7403 NL80211_FLAG_NEED_RTNL,
7406 .cmd = NL80211_CMD_REGISTER_BEACONS,
7407 .doit = nl80211_register_beacons,
7408 .policy = nl80211_policy,
7409 .flags = GENL_ADMIN_PERM,
7410 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7411 NL80211_FLAG_NEED_RTNL,
7414 .cmd = NL80211_CMD_SET_NOACK_MAP,
7415 .doit = nl80211_set_noack_map,
7416 .policy = nl80211_policy,
7417 .flags = GENL_ADMIN_PERM,
7418 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7419 NL80211_FLAG_NEED_RTNL,
7424 static struct genl_multicast_group nl80211_mlme_mcgrp = {
7428 /* multicast groups */
7429 static struct genl_multicast_group nl80211_config_mcgrp = {
7432 static struct genl_multicast_group nl80211_scan_mcgrp = {
7435 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7436 .name = "regulatory",
7439 /* notification functions */
7441 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7443 struct sk_buff *msg;
7445 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7449 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7454 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7455 nl80211_config_mcgrp.id, GFP_KERNEL);
7458 static int nl80211_add_scan_req(struct sk_buff *msg,
7459 struct cfg80211_registered_device *rdev)
7461 struct cfg80211_scan_request *req = rdev->scan_req;
7462 struct nlattr *nest;
7465 ASSERT_RDEV_LOCK(rdev);
7470 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7472 goto nla_put_failure;
7473 for (i = 0; i < req->n_ssids; i++) {
7474 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7475 goto nla_put_failure;
7477 nla_nest_end(msg, nest);
7479 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7481 goto nla_put_failure;
7482 for (i = 0; i < req->n_channels; i++) {
7483 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7484 goto nla_put_failure;
7486 nla_nest_end(msg, nest);
7489 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7490 goto nla_put_failure;
7497 static int nl80211_send_scan_msg(struct sk_buff *msg,
7498 struct cfg80211_registered_device *rdev,
7499 struct wireless_dev *wdev,
7500 u32 pid, u32 seq, int flags,
7505 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7509 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7510 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
7511 wdev->netdev->ifindex)) ||
7512 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
7513 goto nla_put_failure;
7515 /* ignore errors and send incomplete event anyway */
7516 nl80211_add_scan_req(msg, rdev);
7518 return genlmsg_end(msg, hdr);
7521 genlmsg_cancel(msg, hdr);
7526 nl80211_send_sched_scan_msg(struct sk_buff *msg,
7527 struct cfg80211_registered_device *rdev,
7528 struct net_device *netdev,
7529 u32 pid, u32 seq, int flags, u32 cmd)
7533 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7537 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7538 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7539 goto nla_put_failure;
7541 return genlmsg_end(msg, hdr);
7544 genlmsg_cancel(msg, hdr);
7548 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7549 struct wireless_dev *wdev)
7551 struct sk_buff *msg;
7553 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7557 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
7558 NL80211_CMD_TRIGGER_SCAN) < 0) {
7563 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7564 nl80211_scan_mcgrp.id, GFP_KERNEL);
7567 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7568 struct wireless_dev *wdev)
7570 struct sk_buff *msg;
7572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7576 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
7577 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
7582 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7583 nl80211_scan_mcgrp.id, GFP_KERNEL);
7586 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7587 struct wireless_dev *wdev)
7589 struct sk_buff *msg;
7591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7595 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
7596 NL80211_CMD_SCAN_ABORTED) < 0) {
7601 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7602 nl80211_scan_mcgrp.id, GFP_KERNEL);
7605 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7606 struct net_device *netdev)
7608 struct sk_buff *msg;
7610 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7614 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7615 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7620 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7621 nl80211_scan_mcgrp.id, GFP_KERNEL);
7624 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7625 struct net_device *netdev, u32 cmd)
7627 struct sk_buff *msg;
7629 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7633 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7638 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7639 nl80211_scan_mcgrp.id, GFP_KERNEL);
7643 * This can happen on global regulatory changes or device specific settings
7644 * based on custom world regulatory domains.
7646 void nl80211_send_reg_change_event(struct regulatory_request *request)
7648 struct sk_buff *msg;
7651 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7655 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7661 /* Userspace can always count this one always being set */
7662 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7663 goto nla_put_failure;
7665 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7666 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7667 NL80211_REGDOM_TYPE_WORLD))
7668 goto nla_put_failure;
7669 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7670 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7671 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7672 goto nla_put_failure;
7673 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7674 request->intersect) {
7675 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7676 NL80211_REGDOM_TYPE_INTERSECTION))
7677 goto nla_put_failure;
7679 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7680 NL80211_REGDOM_TYPE_COUNTRY) ||
7681 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7683 goto nla_put_failure;
7686 if (wiphy_idx_valid(request->wiphy_idx) &&
7687 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7688 goto nla_put_failure;
7690 genlmsg_end(msg, hdr);
7693 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7700 genlmsg_cancel(msg, hdr);
7704 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7705 struct net_device *netdev,
7706 const u8 *buf, size_t len,
7707 enum nl80211_commands cmd, gfp_t gfp)
7709 struct sk_buff *msg;
7712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7716 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7722 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7723 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7724 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7725 goto nla_put_failure;
7727 genlmsg_end(msg, hdr);
7729 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7730 nl80211_mlme_mcgrp.id, gfp);
7734 genlmsg_cancel(msg, hdr);
7738 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
7739 struct net_device *netdev, const u8 *buf,
7740 size_t len, gfp_t gfp)
7742 nl80211_send_mlme_event(rdev, netdev, buf, len,
7743 NL80211_CMD_AUTHENTICATE, gfp);
7746 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7747 struct net_device *netdev, const u8 *buf,
7748 size_t len, gfp_t gfp)
7750 nl80211_send_mlme_event(rdev, netdev, buf, len,
7751 NL80211_CMD_ASSOCIATE, gfp);
7754 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
7755 struct net_device *netdev, const u8 *buf,
7756 size_t len, gfp_t gfp)
7758 nl80211_send_mlme_event(rdev, netdev, buf, len,
7759 NL80211_CMD_DEAUTHENTICATE, gfp);
7762 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7763 struct net_device *netdev, const u8 *buf,
7764 size_t len, gfp_t gfp)
7766 nl80211_send_mlme_event(rdev, netdev, buf, len,
7767 NL80211_CMD_DISASSOCIATE, gfp);
7770 void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7771 struct net_device *netdev, const u8 *buf,
7772 size_t len, gfp_t gfp)
7774 nl80211_send_mlme_event(rdev, netdev, buf, len,
7775 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7778 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7779 struct net_device *netdev, const u8 *buf,
7780 size_t len, gfp_t gfp)
7782 nl80211_send_mlme_event(rdev, netdev, buf, len,
7783 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7786 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7787 struct net_device *netdev, int cmd,
7788 const u8 *addr, gfp_t gfp)
7790 struct sk_buff *msg;
7793 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7797 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7803 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7804 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7805 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7806 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7807 goto nla_put_failure;
7809 genlmsg_end(msg, hdr);
7811 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7812 nl80211_mlme_mcgrp.id, gfp);
7816 genlmsg_cancel(msg, hdr);
7820 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
7821 struct net_device *netdev, const u8 *addr,
7824 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
7828 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
7829 struct net_device *netdev, const u8 *addr,
7832 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7836 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7837 struct net_device *netdev, const u8 *bssid,
7838 const u8 *req_ie, size_t req_ie_len,
7839 const u8 *resp_ie, size_t resp_ie_len,
7840 u16 status, gfp_t gfp)
7842 struct sk_buff *msg;
7845 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7849 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7855 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7857 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7858 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7860 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7862 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7863 goto nla_put_failure;
7865 genlmsg_end(msg, hdr);
7867 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7868 nl80211_mlme_mcgrp.id, gfp);
7872 genlmsg_cancel(msg, hdr);
7877 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7878 struct net_device *netdev, const u8 *bssid,
7879 const u8 *req_ie, size_t req_ie_len,
7880 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7882 struct sk_buff *msg;
7885 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7889 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7895 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7896 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7897 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7899 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7901 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7902 goto nla_put_failure;
7904 genlmsg_end(msg, hdr);
7906 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7907 nl80211_mlme_mcgrp.id, gfp);
7911 genlmsg_cancel(msg, hdr);
7916 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7917 struct net_device *netdev, u16 reason,
7918 const u8 *ie, size_t ie_len, bool from_ap)
7920 struct sk_buff *msg;
7923 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7927 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7933 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7934 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7935 (from_ap && reason &&
7936 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7938 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7939 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7940 goto nla_put_failure;
7942 genlmsg_end(msg, hdr);
7944 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7945 nl80211_mlme_mcgrp.id, GFP_KERNEL);
7949 genlmsg_cancel(msg, hdr);
7954 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7955 struct net_device *netdev, const u8 *bssid,
7958 struct sk_buff *msg;
7961 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7965 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7971 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7972 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7973 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7974 goto nla_put_failure;
7976 genlmsg_end(msg, hdr);
7978 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7979 nl80211_mlme_mcgrp.id, gfp);
7983 genlmsg_cancel(msg, hdr);
7987 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7988 struct net_device *netdev,
7989 const u8 *macaddr, const u8* ie, u8 ie_len,
7992 struct sk_buff *msg;
7995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7999 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
8005 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8006 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8007 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
8009 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
8010 goto nla_put_failure;
8012 genlmsg_end(msg, hdr);
8014 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8015 nl80211_mlme_mcgrp.id, gfp);
8019 genlmsg_cancel(msg, hdr);
8023 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
8024 struct net_device *netdev, const u8 *addr,
8025 enum nl80211_key_type key_type, int key_id,
8026 const u8 *tsc, gfp_t gfp)
8028 struct sk_buff *msg;
8031 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8035 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
8041 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8042 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8043 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
8044 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
8046 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
8047 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
8048 goto nla_put_failure;
8050 genlmsg_end(msg, hdr);
8052 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8053 nl80211_mlme_mcgrp.id, gfp);
8057 genlmsg_cancel(msg, hdr);
8061 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
8062 struct ieee80211_channel *channel_before,
8063 struct ieee80211_channel *channel_after)
8065 struct sk_buff *msg;
8067 struct nlattr *nl_freq;
8069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
8073 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
8080 * Since we are applying the beacon hint to a wiphy we know its
8081 * wiphy_idx is valid
8083 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8084 goto nla_put_failure;
8087 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
8089 goto nla_put_failure;
8090 if (nl80211_msg_put_channel(msg, channel_before))
8091 goto nla_put_failure;
8092 nla_nest_end(msg, nl_freq);
8095 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
8097 goto nla_put_failure;
8098 if (nl80211_msg_put_channel(msg, channel_after))
8099 goto nla_put_failure;
8100 nla_nest_end(msg, nl_freq);
8102 genlmsg_end(msg, hdr);
8105 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8112 genlmsg_cancel(msg, hdr);
8116 static void nl80211_send_remain_on_chan_event(
8117 int cmd, struct cfg80211_registered_device *rdev,
8118 struct wireless_dev *wdev, u64 cookie,
8119 struct ieee80211_channel *chan,
8120 enum nl80211_channel_type channel_type,
8121 unsigned int duration, gfp_t gfp)
8123 struct sk_buff *msg;
8126 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8130 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8136 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8137 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8138 wdev->netdev->ifindex)) ||
8139 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
8140 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
8141 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
8142 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8143 goto nla_put_failure;
8145 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
8146 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
8147 goto nla_put_failure;
8149 genlmsg_end(msg, hdr);
8151 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8152 nl80211_mlme_mcgrp.id, gfp);
8156 genlmsg_cancel(msg, hdr);
8160 void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
8161 struct wireless_dev *wdev, u64 cookie,
8162 struct ieee80211_channel *chan,
8163 enum nl80211_channel_type channel_type,
8164 unsigned int duration, gfp_t gfp)
8166 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
8167 rdev, wdev, cookie, chan,
8168 channel_type, duration, gfp);
8171 void nl80211_send_remain_on_channel_cancel(
8172 struct cfg80211_registered_device *rdev,
8173 struct wireless_dev *wdev,
8174 u64 cookie, struct ieee80211_channel *chan,
8175 enum nl80211_channel_type channel_type, gfp_t gfp)
8177 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8178 rdev, wdev, cookie, chan,
8179 channel_type, 0, gfp);
8182 void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
8183 struct net_device *dev, const u8 *mac_addr,
8184 struct station_info *sinfo, gfp_t gfp)
8186 struct sk_buff *msg;
8188 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8192 if (nl80211_send_station(msg, 0, 0, 0,
8193 rdev, dev, mac_addr, sinfo) < 0) {
8198 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8199 nl80211_mlme_mcgrp.id, gfp);
8202 void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8203 struct net_device *dev, const u8 *mac_addr,
8206 struct sk_buff *msg;
8209 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8213 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8219 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8220 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8221 goto nla_put_failure;
8223 genlmsg_end(msg, hdr);
8225 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8226 nl80211_mlme_mcgrp.id, gfp);
8230 genlmsg_cancel(msg, hdr);
8234 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8235 const u8 *addr, gfp_t gfp)
8237 struct wireless_dev *wdev = dev->ieee80211_ptr;
8238 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8239 struct sk_buff *msg;
8242 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8247 msg = nlmsg_new(100, gfp);
8251 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8257 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8258 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8259 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8260 goto nla_put_failure;
8262 err = genlmsg_end(msg, hdr);
8268 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8272 genlmsg_cancel(msg, hdr);
8277 bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8279 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8283 bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8284 const u8 *addr, gfp_t gfp)
8286 return __nl80211_unexpected_frame(dev,
8287 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8291 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8292 struct wireless_dev *wdev, u32 nlpid,
8293 int freq, int sig_dbm,
8294 const u8 *buf, size_t len, gfp_t gfp)
8296 struct net_device *netdev = wdev->netdev;
8297 struct sk_buff *msg;
8300 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8304 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8310 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8311 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8312 netdev->ifindex)) ||
8313 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8315 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8316 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8317 goto nla_put_failure;
8319 genlmsg_end(msg, hdr);
8321 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8324 genlmsg_cancel(msg, hdr);
8329 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8330 struct wireless_dev *wdev, u64 cookie,
8331 const u8 *buf, size_t len, bool ack,
8334 struct net_device *netdev = wdev->netdev;
8335 struct sk_buff *msg;
8338 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8342 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
8348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8349 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8350 netdev->ifindex)) ||
8351 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8352 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8353 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8354 goto nla_put_failure;
8356 genlmsg_end(msg, hdr);
8358 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8362 genlmsg_cancel(msg, hdr);
8367 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8368 struct net_device *netdev,
8369 enum nl80211_cqm_rssi_threshold_event rssi_event,
8372 struct sk_buff *msg;
8373 struct nlattr *pinfoattr;
8376 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8380 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8386 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8387 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8388 goto nla_put_failure;
8390 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8392 goto nla_put_failure;
8394 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8396 goto nla_put_failure;
8398 nla_nest_end(msg, pinfoattr);
8400 genlmsg_end(msg, hdr);
8402 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8403 nl80211_mlme_mcgrp.id, gfp);
8407 genlmsg_cancel(msg, hdr);
8411 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8412 struct net_device *netdev, const u8 *bssid,
8413 const u8 *replay_ctr, gfp_t gfp)
8415 struct sk_buff *msg;
8416 struct nlattr *rekey_attr;
8419 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8423 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8430 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8431 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8432 goto nla_put_failure;
8434 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8436 goto nla_put_failure;
8438 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8439 NL80211_REPLAY_CTR_LEN, replay_ctr))
8440 goto nla_put_failure;
8442 nla_nest_end(msg, rekey_attr);
8444 genlmsg_end(msg, hdr);
8446 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8447 nl80211_mlme_mcgrp.id, gfp);
8451 genlmsg_cancel(msg, hdr);
8455 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8456 struct net_device *netdev, int index,
8457 const u8 *bssid, bool preauth, gfp_t gfp)
8459 struct sk_buff *msg;
8460 struct nlattr *attr;
8463 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8467 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8473 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8474 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8475 goto nla_put_failure;
8477 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8479 goto nla_put_failure;
8481 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8482 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8484 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8485 goto nla_put_failure;
8487 nla_nest_end(msg, attr);
8489 genlmsg_end(msg, hdr);
8491 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8492 nl80211_mlme_mcgrp.id, gfp);
8496 genlmsg_cancel(msg, hdr);
8500 void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8501 struct net_device *netdev, int freq,
8502 enum nl80211_channel_type type, gfp_t gfp)
8504 struct sk_buff *msg;
8507 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8511 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8517 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8518 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8519 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8520 goto nla_put_failure;
8522 genlmsg_end(msg, hdr);
8524 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8525 nl80211_mlme_mcgrp.id, gfp);
8529 genlmsg_cancel(msg, hdr);
8534 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
8535 struct net_device *netdev, const u8 *peer,
8536 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
8538 struct sk_buff *msg;
8539 struct nlattr *pinfoattr;
8542 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8546 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8552 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8553 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8554 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8555 goto nla_put_failure;
8557 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8559 goto nla_put_failure;
8561 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
8562 goto nla_put_failure;
8564 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
8565 goto nla_put_failure;
8567 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
8568 goto nla_put_failure;
8570 nla_nest_end(msg, pinfoattr);
8572 genlmsg_end(msg, hdr);
8574 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8575 nl80211_mlme_mcgrp.id, gfp);
8579 genlmsg_cancel(msg, hdr);
8584 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8585 struct net_device *netdev, const u8 *peer,
8586 u32 num_packets, gfp_t gfp)
8588 struct sk_buff *msg;
8589 struct nlattr *pinfoattr;
8592 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8596 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8602 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8603 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8604 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8605 goto nla_put_failure;
8607 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8609 goto nla_put_failure;
8611 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8612 goto nla_put_failure;
8614 nla_nest_end(msg, pinfoattr);
8616 genlmsg_end(msg, hdr);
8618 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8619 nl80211_mlme_mcgrp.id, gfp);
8623 genlmsg_cancel(msg, hdr);
8627 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8628 u64 cookie, bool acked, gfp_t gfp)
8630 struct wireless_dev *wdev = dev->ieee80211_ptr;
8631 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8632 struct sk_buff *msg;
8636 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8640 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8646 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8647 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8648 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8649 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8650 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8651 goto nla_put_failure;
8653 err = genlmsg_end(msg, hdr);
8659 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8660 nl80211_mlme_mcgrp.id, gfp);
8664 genlmsg_cancel(msg, hdr);
8667 EXPORT_SYMBOL(cfg80211_probe_status);
8669 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8670 const u8 *frame, size_t len,
8671 int freq, int sig_dbm, gfp_t gfp)
8673 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8674 struct sk_buff *msg;
8676 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8681 msg = nlmsg_new(len + 100, gfp);
8685 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8691 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8693 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8695 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8696 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8697 goto nla_put_failure;
8699 genlmsg_end(msg, hdr);
8701 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8705 genlmsg_cancel(msg, hdr);
8708 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8710 static int nl80211_netlink_notify(struct notifier_block * nb,
8711 unsigned long state,
8714 struct netlink_notify *notify = _notify;
8715 struct cfg80211_registered_device *rdev;
8716 struct wireless_dev *wdev;
8718 if (state != NETLINK_URELEASE)
8723 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
8724 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
8725 cfg80211_mlme_unregister_socket(wdev, notify->pid);
8726 if (rdev->ap_beacons_nlpid == notify->pid)
8727 rdev->ap_beacons_nlpid = 0;
8735 static struct notifier_block nl80211_netlink_notifier = {
8736 .notifier_call = nl80211_netlink_notify,
8739 /* initialisation/exit functions */
8741 int nl80211_init(void)
8745 err = genl_register_family_with_ops(&nl80211_fam,
8746 nl80211_ops, ARRAY_SIZE(nl80211_ops));
8750 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8754 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8758 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8762 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8766 #ifdef CONFIG_NL80211_TESTMODE
8767 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8772 err = netlink_register_notifier(&nl80211_netlink_notifier);
8778 genl_unregister_family(&nl80211_fam);
8782 void nl80211_exit(void)
8784 netlink_unregister_notifier(&nl80211_netlink_notifier);
8785 genl_unregister_family(&nl80211_fam);