1 // SPDX-License-Identifier: GPL-2.0-only
3 * This is the new netlink-based wireless configuration interface.
5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright 2015-2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2019 Intel Corporation
12 #include <linux/module.h>
13 #include <linux/err.h>
14 #include <linux/slab.h>
15 #include <linux/list.h>
16 #include <linux/if_ether.h>
17 #include <linux/ieee80211.h>
18 #include <linux/nl80211.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/netlink.h>
21 #include <linux/nospec.h>
22 #include <linux/etherdevice.h>
23 #include <net/net_namespace.h>
24 #include <net/genetlink.h>
25 #include <net/cfg80211.h>
27 #include <net/inet_connection_sock.h>
33 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
34 struct genl_info *info,
35 struct cfg80211_crypto_settings *settings,
38 /* the netlink family */
39 static struct genl_family nl80211_fam;
41 /* multicast groups */
42 enum nl80211_multicast_groups {
45 NL80211_MCGRP_REGULATORY,
49 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
52 static const struct genl_multicast_group nl80211_mcgrps[] = {
53 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
54 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
55 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
56 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
57 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
58 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
59 #ifdef CONFIG_NL80211_TESTMODE
60 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
64 /* returns ERR_PTR values */
65 static struct wireless_dev *
66 __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
68 struct cfg80211_registered_device *rdev;
69 struct wireless_dev *result = NULL;
70 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
71 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
78 if (!have_ifidx && !have_wdev_id)
79 return ERR_PTR(-EINVAL);
82 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
84 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
85 wiphy_idx = wdev_id >> 32;
88 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
89 struct wireless_dev *wdev;
91 if (wiphy_net(&rdev->wiphy) != netns)
94 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
97 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
98 if (have_ifidx && wdev->netdev &&
99 wdev->netdev->ifindex == ifidx) {
103 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
115 return ERR_PTR(-ENODEV);
118 static struct cfg80211_registered_device *
119 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
121 struct cfg80211_registered_device *rdev = NULL, *tmp;
122 struct net_device *netdev;
126 if (!attrs[NL80211_ATTR_WIPHY] &&
127 !attrs[NL80211_ATTR_IFINDEX] &&
128 !attrs[NL80211_ATTR_WDEV])
129 return ERR_PTR(-EINVAL);
131 if (attrs[NL80211_ATTR_WIPHY])
132 rdev = cfg80211_rdev_by_wiphy_idx(
133 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
135 if (attrs[NL80211_ATTR_WDEV]) {
136 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
137 struct wireless_dev *wdev;
140 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
142 /* make sure wdev exists */
143 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
144 if (wdev->identifier != (u32)wdev_id)
153 if (rdev && tmp != rdev)
154 return ERR_PTR(-EINVAL);
159 if (attrs[NL80211_ATTR_IFINDEX]) {
160 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
162 netdev = __dev_get_by_index(netns, ifindex);
164 if (netdev->ieee80211_ptr)
166 netdev->ieee80211_ptr->wiphy);
170 /* not wireless device -- return error */
172 return ERR_PTR(-EINVAL);
174 /* mismatch -- return error */
175 if (rdev && tmp != rdev)
176 return ERR_PTR(-EINVAL);
183 return ERR_PTR(-ENODEV);
185 if (netns != wiphy_net(&rdev->wiphy))
186 return ERR_PTR(-ENODEV);
192 * This function returns a pointer to the driver
193 * that the genl_info item that is passed refers to.
195 * The result of this can be a PTR_ERR and hence must
196 * be checked with IS_ERR() for errors.
198 static struct cfg80211_registered_device *
199 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
201 return __cfg80211_rdev_from_attrs(netns, info->attrs);
204 static int validate_beacon_head(const struct nlattr *attr,
205 struct netlink_ext_ack *extack)
207 const u8 *data = nla_data(attr);
208 unsigned int len = nla_len(attr);
209 const struct element *elem;
210 const struct ieee80211_mgmt *mgmt = (void *)data;
211 unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
217 if (ieee80211_hdrlen(mgmt->frame_control) !=
218 offsetof(struct ieee80211_mgmt, u.beacon))
224 for_each_element(elem, data, len) {
228 if (for_each_element_completed(elem, data, len))
232 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
236 static int validate_ie_attr(const struct nlattr *attr,
237 struct netlink_ext_ack *extack)
239 const u8 *data = nla_data(attr);
240 unsigned int len = nla_len(attr);
241 const struct element *elem;
243 for_each_element(elem, data, len) {
247 if (for_each_element_completed(elem, data, len))
250 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
254 /* policy for the attributes */
255 static const struct nla_policy
256 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = {
257 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, },
258 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY,
260 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY,
264 static const struct nla_policy
265 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
266 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG },
267 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 },
268 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] =
269 NLA_POLICY_MAX(NLA_U8, 15),
270 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 },
271 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] =
272 NLA_POLICY_MAX(NLA_U8, 15),
273 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] =
274 NLA_POLICY_MAX(NLA_U8, 31),
275 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 },
276 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG },
277 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG },
280 static const struct nla_policy
281 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
282 [NL80211_PMSR_TYPE_FTM] =
283 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
286 static const struct nla_policy
287 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
288 [NL80211_PMSR_REQ_ATTR_DATA] =
289 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
290 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
293 static const struct nla_policy
294 nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
295 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
297 * we could specify this again to be the top-level policy,
298 * but that would open us up to recursion problems ...
300 [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED },
301 [NL80211_PMSR_PEER_ATTR_REQ] =
302 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
303 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
306 static const struct nla_policy
307 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
308 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
309 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
310 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
311 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
312 [NL80211_PMSR_ATTR_PEERS] =
313 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy),
316 static const struct nla_policy
317 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = {
318 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] =
319 NLA_POLICY_RANGE(NLA_U8, 1, 20),
320 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] =
321 NLA_POLICY_RANGE(NLA_U8, 1, 20),
324 const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
325 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
326 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
327 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
329 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
331 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
332 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
333 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
334 NL80211_EDMG_CHANNELS_MIN,
335 NL80211_EDMG_CHANNELS_MAX),
336 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
337 NL80211_EDMG_BW_CONFIG_MIN,
338 NL80211_EDMG_BW_CONFIG_MAX),
340 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
341 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
342 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
344 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
345 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
346 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
347 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
348 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
349 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
351 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
352 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
353 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
355 [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
356 [NL80211_ATTR_PREV_BSSID] = {
357 .type = NLA_EXACT_LEN_WARN,
361 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
362 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
363 .len = WLAN_MAX_KEY_LEN },
364 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5),
365 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
366 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
368 [NL80211_ATTR_KEY_TYPE] =
369 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
371 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
372 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
373 [NL80211_ATTR_BEACON_HEAD] =
374 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
375 IEEE80211_MAX_DATA_LEN),
376 [NL80211_ATTR_BEACON_TAIL] =
377 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
378 IEEE80211_MAX_DATA_LEN),
379 [NL80211_ATTR_STA_AID] =
380 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
381 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
382 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
383 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
384 .len = NL80211_MAX_SUPP_RATES },
385 [NL80211_ATTR_STA_PLINK_ACTION] =
386 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
387 [NL80211_ATTR_STA_TX_POWER_SETTING] =
388 NLA_POLICY_RANGE(NLA_U8,
389 NL80211_TX_POWER_AUTOMATIC,
390 NL80211_TX_POWER_FIXED),
391 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
392 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
393 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
394 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
395 .len = IEEE80211_MAX_MESH_ID_LEN },
396 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
398 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
399 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
401 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
402 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
403 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
404 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
405 .len = NL80211_MAX_SUPP_RATES },
406 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
408 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
409 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
411 [NL80211_ATTR_HT_CAPABILITY] = {
412 .type = NLA_EXACT_LEN_WARN,
413 .len = NL80211_HT_CAPABILITY_LEN
416 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
417 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
419 IEEE80211_MAX_DATA_LEN),
420 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
421 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
423 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
424 .len = IEEE80211_MAX_SSID_LEN },
425 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
426 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
427 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
428 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
429 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
431 NL80211_MFP_OPTIONAL),
432 [NL80211_ATTR_STA_FLAGS2] = {
433 .len = sizeof(struct nl80211_sta_flag_update),
435 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
436 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
437 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
438 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
439 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
440 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
441 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
442 [NL80211_ATTR_PID] = { .type = NLA_U32 },
443 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
444 [NL80211_ATTR_PMKID] = {
445 .type = NLA_EXACT_LEN_WARN,
446 .len = WLAN_PMKID_LEN
448 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
449 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
450 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
451 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
452 .len = IEEE80211_MAX_DATA_LEN },
453 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
454 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
457 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
458 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
459 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
460 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
461 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
462 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
463 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
464 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
465 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
466 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
467 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
468 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
469 [NL80211_ATTR_STA_PLINK_STATE] =
470 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
471 [NL80211_ATTR_MESH_PEER_AID] =
472 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
473 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
474 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
475 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
476 [NL80211_ATTR_HIDDEN_SSID] =
477 NLA_POLICY_RANGE(NLA_U32,
478 NL80211_HIDDEN_SSID_NOT_IN_USE,
479 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
480 [NL80211_ATTR_IE_PROBE_RESP] =
481 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
482 IEEE80211_MAX_DATA_LEN),
483 [NL80211_ATTR_IE_ASSOC_RESP] =
484 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
485 IEEE80211_MAX_DATA_LEN),
486 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
487 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
488 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
489 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
490 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
491 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
492 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
493 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
494 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
495 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
496 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
497 .len = IEEE80211_MAX_DATA_LEN },
498 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
499 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
500 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
501 .len = NL80211_HT_CAPABILITY_LEN
503 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
504 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
505 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
506 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
507 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
508 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
509 [NL80211_ATTR_VHT_CAPABILITY] = {
510 .type = NLA_EXACT_LEN_WARN,
511 .len = NL80211_VHT_CAPABILITY_LEN
513 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
514 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
515 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
516 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
517 NLA_POLICY_RANGE(NLA_U32,
518 NL80211_MESH_POWER_UNKNOWN + 1,
519 NL80211_MESH_POWER_MAX),
520 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
521 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
522 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
523 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
524 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
525 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
526 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
527 .len = NL80211_VHT_CAPABILITY_LEN,
529 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
530 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
531 .len = IEEE80211_MAX_DATA_LEN },
532 [NL80211_ATTR_PEER_AID] =
533 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
534 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
535 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
536 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
537 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
538 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
539 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
540 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
541 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
542 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
543 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
544 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
545 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
546 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
547 .len = IEEE80211_QOS_MAP_LEN_MAX },
548 [NL80211_ATTR_MAC_HINT] = {
549 .type = NLA_EXACT_LEN_WARN,
552 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
553 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
554 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
555 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
556 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
557 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
558 [NL80211_ATTR_USER_PRIO] =
559 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
560 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
561 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
562 [NL80211_ATTR_MAC_MASK] = {
563 .type = NLA_EXACT_LEN_WARN,
566 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
567 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
568 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
569 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
570 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
571 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
572 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
573 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
574 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
575 .len = VHT_MUMIMO_GROUPS_DATA_LEN
577 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = {
578 .type = NLA_EXACT_LEN_WARN,
581 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
582 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
583 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
584 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
585 .len = FILS_MAX_KEK_LEN },
586 [NL80211_ATTR_FILS_NONCES] = {
587 .type = NLA_EXACT_LEN_WARN,
588 .len = 2 * FILS_NONCE_LEN
590 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
591 [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
592 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
593 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
594 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
596 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
597 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
598 .len = FILS_ERP_MAX_USERNAME_LEN },
599 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
600 .len = FILS_ERP_MAX_REALM_LEN },
601 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
602 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
603 .len = FILS_ERP_MAX_RRK_LEN },
604 [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 },
605 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
606 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
607 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
609 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
610 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
611 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
612 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
613 .len = NL80211_HE_MAX_CAPABILITY_LEN },
615 [NL80211_ATTR_FTM_RESPONDER] = {
617 .validation_data = nl80211_ftm_responder_policy,
619 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
620 [NL80211_ATTR_PEER_MEASUREMENTS] =
621 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
622 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
623 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
624 .len = SAE_PASSWORD_MAX_LEN },
625 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
626 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
627 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
630 /* policy for the key attributes */
631 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
632 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
633 [NL80211_KEY_IDX] = { .type = NLA_U8 },
634 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
635 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
636 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
637 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
638 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
639 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
640 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
643 /* policy for the key default flags */
644 static const struct nla_policy
645 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
646 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
647 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
651 /* policy for WoWLAN attributes */
652 static const struct nla_policy
653 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
654 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
655 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
656 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
657 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
658 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
659 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
660 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
661 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
662 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
663 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
666 static const struct nla_policy
667 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
668 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
669 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
670 [NL80211_WOWLAN_TCP_DST_MAC] = {
671 .type = NLA_EXACT_LEN_WARN,
674 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
675 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
676 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
677 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
678 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
680 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
681 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
683 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
684 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
685 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 },
687 #endif /* CONFIG_PM */
689 /* policy for coalesce rule attributes */
690 static const struct nla_policy
691 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
692 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
693 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
694 NLA_POLICY_RANGE(NLA_U32,
695 NL80211_COALESCE_CONDITION_MATCH,
696 NL80211_COALESCE_CONDITION_NO_MATCH),
697 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
700 /* policy for GTK rekey offload attributes */
701 static const struct nla_policy
702 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
703 [NL80211_REKEY_DATA_KEK] = {
704 .type = NLA_EXACT_LEN_WARN,
705 .len = NL80211_KEK_LEN,
707 [NL80211_REKEY_DATA_KCK] = {
708 .type = NLA_EXACT_LEN_WARN,
709 .len = NL80211_KCK_LEN,
711 [NL80211_REKEY_DATA_REPLAY_CTR] = {
712 .type = NLA_EXACT_LEN_WARN,
713 .len = NL80211_REPLAY_CTR_LEN
717 static const struct nla_policy
718 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
719 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
720 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
721 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
722 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
725 static const struct nla_policy
726 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
727 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
728 .len = IEEE80211_MAX_SSID_LEN },
729 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = {
730 .type = NLA_EXACT_LEN_WARN,
733 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
734 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
735 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
738 static const struct nla_policy
739 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
740 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
741 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
744 static const struct nla_policy
745 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
746 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
747 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
748 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
749 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
753 /* policy for NAN function attributes */
754 static const struct nla_policy
755 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
756 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
757 [NL80211_NAN_FUNC_SERVICE_ID] = {
758 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
759 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
760 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
761 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
762 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
763 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
764 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = {
765 .type = NLA_EXACT_LEN_WARN,
768 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
769 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
770 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
771 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
772 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
773 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
774 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
775 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
776 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
779 /* policy for Service Response Filter attributes */
780 static const struct nla_policy
781 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
782 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
783 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
784 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
785 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
786 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
789 /* policy for packet pattern attributes */
790 static const struct nla_policy
791 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
792 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
793 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
794 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
797 int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
798 struct cfg80211_registered_device **rdev,
799 struct wireless_dev **wdev)
804 struct nlattr **attrbuf;
806 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
811 err = nlmsg_parse_deprecated(cb->nlh,
812 GENL_HDRLEN + nl80211_fam.hdrsize,
813 attrbuf, nl80211_fam.maxattr,
814 nl80211_policy, NULL);
820 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
824 return PTR_ERR(*wdev);
825 *rdev = wiphy_to_rdev((*wdev)->wiphy);
826 /* 0 is the first index - add 1 to parse only once */
827 cb->args[0] = (*rdev)->wiphy_idx + 1;
828 cb->args[1] = (*wdev)->identifier;
830 /* subtract the 1 again here */
831 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
832 struct wireless_dev *tmp;
836 *rdev = wiphy_to_rdev(wiphy);
839 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
840 if (tmp->identifier == cb->args[1]) {
853 /* message building helper */
854 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
857 /* since there is no private header just add the generic one */
858 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
861 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
862 const struct ieee80211_reg_rule *rule)
865 struct nlattr *nl_wmm_rules =
866 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
869 goto nla_put_failure;
871 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
872 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
875 goto nla_put_failure;
877 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
878 rule->wmm_rule.client[j].cw_min) ||
879 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
880 rule->wmm_rule.client[j].cw_max) ||
881 nla_put_u8(msg, NL80211_WMMR_AIFSN,
882 rule->wmm_rule.client[j].aifsn) ||
883 nla_put_u16(msg, NL80211_WMMR_TXOP,
884 rule->wmm_rule.client[j].cot))
885 goto nla_put_failure;
887 nla_nest_end(msg, nl_wmm_rule);
889 nla_nest_end(msg, nl_wmm_rules);
897 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
898 struct ieee80211_channel *chan,
901 /* Some channels must be completely excluded from the
902 * list to protect old user-space tools from breaking
904 if (!large && chan->flags &
905 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
908 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
910 goto nla_put_failure;
912 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
913 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
914 goto nla_put_failure;
915 if (chan->flags & IEEE80211_CHAN_NO_IR) {
916 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
917 goto nla_put_failure;
918 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
919 goto nla_put_failure;
921 if (chan->flags & IEEE80211_CHAN_RADAR) {
922 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
923 goto nla_put_failure;
927 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
929 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
931 goto nla_put_failure;
932 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
934 goto nla_put_failure;
936 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
938 goto nla_put_failure;
943 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
944 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
945 goto nla_put_failure;
946 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
947 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
948 goto nla_put_failure;
949 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
950 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
951 goto nla_put_failure;
952 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
953 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
954 goto nla_put_failure;
955 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
956 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
957 goto nla_put_failure;
958 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
959 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
960 goto nla_put_failure;
961 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
962 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
963 goto nla_put_failure;
964 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
965 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
966 goto nla_put_failure;
969 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
970 DBM_TO_MBM(chan->max_power)))
971 goto nla_put_failure;
974 const struct ieee80211_reg_rule *rule =
975 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
977 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
978 if (nl80211_msg_put_wmm_rules(msg, rule))
979 goto nla_put_failure;
989 static bool nl80211_put_txq_stats(struct sk_buff *msg,
990 struct cfg80211_txq_stats *txqstats,
993 struct nlattr *txqattr;
995 #define PUT_TXQVAL_U32(attr, memb) do { \
996 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
997 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1001 txqattr = nla_nest_start_noflag(msg, attrtype);
1005 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1006 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1007 PUT_TXQVAL_U32(FLOWS, flows);
1008 PUT_TXQVAL_U32(DROPS, drops);
1009 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1010 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1011 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1012 PUT_TXQVAL_U32(COLLISIONS, collisions);
1013 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1014 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1015 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1016 nla_nest_end(msg, txqattr);
1018 #undef PUT_TXQVAL_U32
1022 /* netlink command implementations */
1025 struct key_params p;
1029 bool def_uni, def_multi;
1032 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1033 struct key_parse *k)
1035 struct nlattr *tb[NL80211_KEY_MAX + 1];
1036 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1042 k->def = !!tb[NL80211_KEY_DEFAULT];
1043 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1047 k->def_multi = true;
1050 k->def_multi = true;
1052 if (tb[NL80211_KEY_IDX])
1053 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1055 if (tb[NL80211_KEY_DATA]) {
1056 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1057 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1060 if (tb[NL80211_KEY_SEQ]) {
1061 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1062 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1065 if (tb[NL80211_KEY_CIPHER])
1066 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1068 if (tb[NL80211_KEY_TYPE])
1069 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
1071 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1072 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1074 err = nla_parse_nested_deprecated(kdt,
1075 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1076 tb[NL80211_KEY_DEFAULT_TYPES],
1077 nl80211_key_default_policy,
1082 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1083 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1086 if (tb[NL80211_KEY_MODE])
1087 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1092 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1094 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1095 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1096 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1099 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1100 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1101 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1104 if (info->attrs[NL80211_ATTR_KEY_IDX])
1105 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1107 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1108 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1110 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1111 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1115 k->def_multi = true;
1118 k->def_multi = true;
1120 if (info->attrs[NL80211_ATTR_KEY_TYPE])
1121 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1123 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1124 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1125 int err = nla_parse_nested_deprecated(kdt,
1126 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1127 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1128 nl80211_key_default_policy,
1133 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1134 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1140 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1144 memset(k, 0, sizeof(*k));
1148 if (info->attrs[NL80211_ATTR_KEY])
1149 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
1151 err = nl80211_parse_key_old(info, k);
1156 if (k->def && k->defmgmt) {
1157 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
1162 if (k->def_uni || !k->def_multi) {
1163 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
1170 if (k->idx < 4 || k->idx > 5) {
1171 GENL_SET_ERR_MSG(info,
1172 "defmgmt key idx not 4 or 5");
1175 } else if (k->def) {
1176 if (k->idx < 0 || k->idx > 3) {
1177 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
1181 if (k->idx < 0 || k->idx > 5) {
1182 GENL_SET_ERR_MSG(info, "key idx not 0-5");
1191 static struct cfg80211_cached_keys *
1192 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
1193 struct genl_info *info, bool *no_ht)
1195 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
1196 struct key_parse parse;
1198 struct cfg80211_cached_keys *result;
1199 int rem, err, def = 0;
1200 bool have_key = false;
1202 nla_for_each_nested(key, keys, rem) {
1210 result = kzalloc(sizeof(*result), GFP_KERNEL);
1212 return ERR_PTR(-ENOMEM);
1216 nla_for_each_nested(key, keys, rem) {
1217 memset(&parse, 0, sizeof(parse));
1220 err = nl80211_parse_key_new(info, key, &parse);
1226 if (parse.idx < 0 || parse.idx > 3) {
1227 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
1232 GENL_SET_ERR_MSG(info,
1233 "only one key can be default");
1237 result->def = parse.idx;
1238 if (!parse.def_uni || !parse.def_multi)
1240 } else if (parse.defmgmt)
1242 err = cfg80211_validate_key_settings(rdev, &parse.p,
1243 parse.idx, false, NULL);
1246 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1247 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
1248 GENL_SET_ERR_MSG(info, "connect key must be WEP");
1252 result->params[parse.idx].cipher = parse.p.cipher;
1253 result->params[parse.idx].key_len = parse.p.key_len;
1254 result->params[parse.idx].key = result->data[parse.idx];
1255 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
1257 /* must be WEP key if we got here */
1262 if (result->def < 0) {
1264 GENL_SET_ERR_MSG(info, "need a default/TX key");
1271 return ERR_PTR(err);
1274 static int nl80211_key_allowed(struct wireless_dev *wdev)
1276 ASSERT_WDEV_LOCK(wdev);
1278 switch (wdev->iftype) {
1279 case NL80211_IFTYPE_AP:
1280 case NL80211_IFTYPE_AP_VLAN:
1281 case NL80211_IFTYPE_P2P_GO:
1282 case NL80211_IFTYPE_MESH_POINT:
1284 case NL80211_IFTYPE_ADHOC:
1285 case NL80211_IFTYPE_STATION:
1286 case NL80211_IFTYPE_P2P_CLIENT:
1287 if (!wdev->current_bss)
1290 case NL80211_IFTYPE_UNSPECIFIED:
1291 case NL80211_IFTYPE_OCB:
1292 case NL80211_IFTYPE_MONITOR:
1293 case NL80211_IFTYPE_NAN:
1294 case NL80211_IFTYPE_P2P_DEVICE:
1295 case NL80211_IFTYPE_WDS:
1296 case NUM_NL80211_IFTYPES:
1303 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1306 struct ieee80211_channel *chan;
1310 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1311 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1316 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1318 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
1322 goto nla_put_failure;
1326 if ((ifmodes & 1) && nla_put_flag(msg, i))
1327 goto nla_put_failure;
1332 nla_nest_end(msg, nl_modes);
1339 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1340 struct sk_buff *msg,
1343 struct nlattr *nl_combis;
1346 nl_combis = nla_nest_start_noflag(msg,
1347 NL80211_ATTR_INTERFACE_COMBINATIONS);
1349 goto nla_put_failure;
1351 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1352 const struct ieee80211_iface_combination *c;
1353 struct nlattr *nl_combi, *nl_limits;
1355 c = &wiphy->iface_combinations[i];
1357 nl_combi = nla_nest_start_noflag(msg, i + 1);
1359 goto nla_put_failure;
1361 nl_limits = nla_nest_start_noflag(msg,
1362 NL80211_IFACE_COMB_LIMITS);
1364 goto nla_put_failure;
1366 for (j = 0; j < c->n_limits; j++) {
1367 struct nlattr *nl_limit;
1369 nl_limit = nla_nest_start_noflag(msg, j + 1);
1371 goto nla_put_failure;
1372 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1374 goto nla_put_failure;
1375 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1376 c->limits[j].types))
1377 goto nla_put_failure;
1378 nla_nest_end(msg, nl_limit);
1381 nla_nest_end(msg, nl_limits);
1383 if (c->beacon_int_infra_match &&
1384 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1385 goto nla_put_failure;
1386 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1387 c->num_different_channels) ||
1388 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1390 goto nla_put_failure;
1392 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1393 c->radar_detect_widths) ||
1394 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1395 c->radar_detect_regions)))
1396 goto nla_put_failure;
1397 if (c->beacon_int_min_gcd &&
1398 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1399 c->beacon_int_min_gcd))
1400 goto nla_put_failure;
1402 nla_nest_end(msg, nl_combi);
1405 nla_nest_end(msg, nl_combis);
1413 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1414 struct sk_buff *msg)
1416 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
1417 struct nlattr *nl_tcp;
1422 nl_tcp = nla_nest_start_noflag(msg,
1423 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1427 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1428 tcp->data_payload_max))
1431 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1432 tcp->data_payload_max))
1435 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1438 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1439 sizeof(*tcp->tok), tcp->tok))
1442 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1443 tcp->data_interval_max))
1446 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1447 tcp->wake_payload_max))
1450 nla_nest_end(msg, nl_tcp);
1454 static int nl80211_send_wowlan(struct sk_buff *msg,
1455 struct cfg80211_registered_device *rdev,
1458 struct nlattr *nl_wowlan;
1460 if (!rdev->wiphy.wowlan)
1463 nl_wowlan = nla_nest_start_noflag(msg,
1464 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1468 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
1469 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1470 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
1471 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1472 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1473 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1474 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1475 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1476 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1477 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1478 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1479 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1480 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1481 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1482 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1483 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1486 if (rdev->wiphy.wowlan->n_patterns) {
1487 struct nl80211_pattern_support pat = {
1488 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1489 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1490 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1491 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
1494 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1499 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1500 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1501 rdev->wiphy.wowlan->max_nd_match_sets))
1504 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
1507 nla_nest_end(msg, nl_wowlan);
1513 static int nl80211_send_coalesce(struct sk_buff *msg,
1514 struct cfg80211_registered_device *rdev)
1516 struct nl80211_coalesce_rule_support rule;
1518 if (!rdev->wiphy.coalesce)
1521 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1522 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1523 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1524 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1525 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1526 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
1528 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1535 nl80211_send_iftype_data(struct sk_buff *msg,
1536 const struct ieee80211_sband_iftype_data *iftdata)
1538 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1540 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1541 iftdata->types_mask))
1544 if (he_cap->has_he) {
1545 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1546 sizeof(he_cap->he_cap_elem.mac_cap_info),
1547 he_cap->he_cap_elem.mac_cap_info) ||
1548 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1549 sizeof(he_cap->he_cap_elem.phy_cap_info),
1550 he_cap->he_cap_elem.phy_cap_info) ||
1551 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1552 sizeof(he_cap->he_mcs_nss_supp),
1553 &he_cap->he_mcs_nss_supp) ||
1554 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1555 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1562 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1563 struct ieee80211_supported_band *sband)
1565 struct nlattr *nl_rates, *nl_rate;
1566 struct ieee80211_rate *rate;
1570 if (sband->ht_cap.ht_supported &&
1571 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1572 sizeof(sband->ht_cap.mcs),
1573 &sband->ht_cap.mcs) ||
1574 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1575 sband->ht_cap.cap) ||
1576 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1577 sband->ht_cap.ampdu_factor) ||
1578 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1579 sband->ht_cap.ampdu_density)))
1583 if (sband->vht_cap.vht_supported &&
1584 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1585 sizeof(sband->vht_cap.vht_mcs),
1586 &sband->vht_cap.vht_mcs) ||
1587 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1588 sband->vht_cap.cap)))
1591 if (sband->n_iftype_data) {
1592 struct nlattr *nl_iftype_data =
1593 nla_nest_start_noflag(msg,
1594 NL80211_BAND_ATTR_IFTYPE_DATA);
1597 if (!nl_iftype_data)
1600 for (i = 0; i < sband->n_iftype_data; i++) {
1601 struct nlattr *iftdata;
1603 iftdata = nla_nest_start_noflag(msg, i + 1);
1607 err = nl80211_send_iftype_data(msg,
1608 &sband->iftype_data[i]);
1612 nla_nest_end(msg, iftdata);
1615 nla_nest_end(msg, nl_iftype_data);
1619 if (sband->edmg_cap.channels &&
1620 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1621 sband->edmg_cap.channels) ||
1622 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1623 sband->edmg_cap.bw_config)))
1628 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
1632 for (i = 0; i < sband->n_bitrates; i++) {
1633 nl_rate = nla_nest_start_noflag(msg, i);
1637 rate = &sband->bitrates[i];
1638 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1641 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1643 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1646 nla_nest_end(msg, nl_rate);
1649 nla_nest_end(msg, nl_rates);
1655 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1656 const struct ieee80211_txrx_stypes *mgmt_stypes)
1659 struct nlattr *nl_ftypes, *nl_ifs;
1660 enum nl80211_iftype ift;
1666 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
1670 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1671 nl_ftypes = nla_nest_start_noflag(msg, ift);
1675 stypes = mgmt_stypes[ift].tx;
1678 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1679 (i << 4) | IEEE80211_FTYPE_MGMT))
1684 nla_nest_end(msg, nl_ftypes);
1687 nla_nest_end(msg, nl_ifs);
1689 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
1693 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1694 nl_ftypes = nla_nest_start_noflag(msg, ift);
1698 stypes = mgmt_stypes[ift].rx;
1701 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1702 (i << 4) | IEEE80211_FTYPE_MGMT))
1707 nla_nest_end(msg, nl_ftypes);
1709 nla_nest_end(msg, nl_ifs);
1714 #define CMD(op, n) \
1716 if (rdev->ops->op) { \
1718 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1719 goto nla_put_failure; \
1723 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1724 struct sk_buff *msg)
1729 * do *NOT* add anything into this function, new things need to be
1730 * advertised only to new versions of userspace that can deal with
1731 * the split (and they can't possibly care about new features...
1733 CMD(add_virtual_intf, NEW_INTERFACE);
1734 CMD(change_virtual_intf, SET_INTERFACE);
1735 CMD(add_key, NEW_KEY);
1736 CMD(start_ap, START_AP);
1737 CMD(add_station, NEW_STATION);
1738 CMD(add_mpath, NEW_MPATH);
1739 CMD(update_mesh_config, SET_MESH_CONFIG);
1740 CMD(change_bss, SET_BSS);
1741 CMD(auth, AUTHENTICATE);
1742 CMD(assoc, ASSOCIATE);
1743 CMD(deauth, DEAUTHENTICATE);
1744 CMD(disassoc, DISASSOCIATE);
1745 CMD(join_ibss, JOIN_IBSS);
1746 CMD(join_mesh, JOIN_MESH);
1747 CMD(set_pmksa, SET_PMKSA);
1748 CMD(del_pmksa, DEL_PMKSA);
1749 CMD(flush_pmksa, FLUSH_PMKSA);
1750 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1751 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1752 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1753 CMD(mgmt_tx, FRAME);
1754 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1755 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1757 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1758 goto nla_put_failure;
1760 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1761 rdev->ops->join_mesh) {
1763 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1764 goto nla_put_failure;
1766 CMD(set_wds_peer, SET_WDS_PEER);
1767 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1768 CMD(tdls_mgmt, TDLS_MGMT);
1769 CMD(tdls_oper, TDLS_OPER);
1771 if (rdev->wiphy.max_sched_scan_reqs)
1772 CMD(sched_scan_start, START_SCHED_SCAN);
1773 CMD(probe_client, PROBE_CLIENT);
1774 CMD(set_noack_map, SET_NOACK_MAP);
1775 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1777 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1778 goto nla_put_failure;
1780 CMD(start_p2p_device, START_P2P_DEVICE);
1781 CMD(set_mcast_rate, SET_MCAST_RATE);
1782 #ifdef CONFIG_NL80211_TESTMODE
1783 CMD(testmode_cmd, TESTMODE);
1786 if (rdev->ops->connect || rdev->ops->auth) {
1788 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1789 goto nla_put_failure;
1792 if (rdev->ops->disconnect || rdev->ops->deauth) {
1794 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1795 goto nla_put_failure;
1804 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1805 struct sk_buff *msg)
1809 if (!cap->ftm.supported)
1812 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
1816 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1818 if (cap->ftm.non_asap &&
1819 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1821 if (cap->ftm.request_lci &&
1822 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1824 if (cap->ftm.request_civicloc &&
1825 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1827 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1828 cap->ftm.preambles))
1830 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1831 cap->ftm.bandwidths))
1833 if (cap->ftm.max_bursts_exponent >= 0 &&
1834 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1835 cap->ftm.max_bursts_exponent))
1837 if (cap->ftm.max_ftms_per_burst &&
1838 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1839 cap->ftm.max_ftms_per_burst))
1842 nla_nest_end(msg, ftm);
1846 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1847 struct sk_buff *msg)
1849 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1850 struct nlattr *pmsr, *caps;
1856 * we don't need to clean up anything here since the caller
1857 * will genlmsg_cancel() if we fail
1860 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
1864 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1867 if (cap->report_ap_tsf &&
1868 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1871 if (cap->randomize_mac_addr &&
1872 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1875 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
1879 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1882 nla_nest_end(msg, caps);
1883 nla_nest_end(msg, pmsr);
1888 struct nl80211_dump_wiphy_state {
1891 long split_start, band_start, chan_start, capa_start;
1895 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1896 enum nl80211_commands cmd,
1897 struct sk_buff *msg, u32 portid, u32 seq,
1898 int flags, struct nl80211_dump_wiphy_state *state)
1901 struct nlattr *nl_bands, *nl_band;
1902 struct nlattr *nl_freqs, *nl_freq;
1903 struct nlattr *nl_cmds;
1904 enum nl80211_band band;
1905 struct ieee80211_channel *chan;
1907 const struct ieee80211_txrx_stypes *mgmt_stypes =
1908 rdev->wiphy.mgmt_stypes;
1911 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
1915 if (WARN_ON(!state))
1918 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1919 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1920 wiphy_name(&rdev->wiphy)) ||
1921 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1922 cfg80211_rdev_list_generation))
1923 goto nla_put_failure;
1925 if (cmd != NL80211_CMD_NEW_WIPHY)
1928 switch (state->split_start) {
1930 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1931 rdev->wiphy.retry_short) ||
1932 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1933 rdev->wiphy.retry_long) ||
1934 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1935 rdev->wiphy.frag_threshold) ||
1936 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1937 rdev->wiphy.rts_threshold) ||
1938 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1939 rdev->wiphy.coverage_class) ||
1940 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1941 rdev->wiphy.max_scan_ssids) ||
1942 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1943 rdev->wiphy.max_sched_scan_ssids) ||
1944 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1945 rdev->wiphy.max_scan_ie_len) ||
1946 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1947 rdev->wiphy.max_sched_scan_ie_len) ||
1948 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1949 rdev->wiphy.max_match_sets) ||
1950 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1951 rdev->wiphy.max_sched_scan_plans) ||
1952 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1953 rdev->wiphy.max_sched_scan_plan_interval) ||
1954 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1955 rdev->wiphy.max_sched_scan_plan_iterations))
1956 goto nla_put_failure;
1958 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1959 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1960 goto nla_put_failure;
1961 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1962 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1963 goto nla_put_failure;
1964 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1965 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1966 goto nla_put_failure;
1967 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1968 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1969 goto nla_put_failure;
1970 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1971 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1972 goto nla_put_failure;
1973 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1974 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
1975 goto nla_put_failure;
1976 state->split_start++;
1981 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1982 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1983 rdev->wiphy.cipher_suites))
1984 goto nla_put_failure;
1986 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1987 rdev->wiphy.max_num_pmkids))
1988 goto nla_put_failure;
1990 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1991 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1992 goto nla_put_failure;
1994 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1995 rdev->wiphy.available_antennas_tx) ||
1996 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1997 rdev->wiphy.available_antennas_rx))
1998 goto nla_put_failure;
2000 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
2001 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
2002 rdev->wiphy.probe_resp_offload))
2003 goto nla_put_failure;
2005 if ((rdev->wiphy.available_antennas_tx ||
2006 rdev->wiphy.available_antennas_rx) &&
2007 rdev->ops->get_antenna) {
2008 u32 tx_ant = 0, rx_ant = 0;
2011 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
2013 if (nla_put_u32(msg,
2014 NL80211_ATTR_WIPHY_ANTENNA_TX,
2017 NL80211_ATTR_WIPHY_ANTENNA_RX,
2019 goto nla_put_failure;
2023 state->split_start++;
2028 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
2029 rdev->wiphy.interface_modes))
2030 goto nla_put_failure;
2031 state->split_start++;
2036 nl_bands = nla_nest_start_noflag(msg,
2037 NL80211_ATTR_WIPHY_BANDS);
2039 goto nla_put_failure;
2041 for (band = state->band_start;
2042 band < NUM_NL80211_BANDS; band++) {
2043 struct ieee80211_supported_band *sband;
2045 sband = rdev->wiphy.bands[band];
2050 nl_band = nla_nest_start_noflag(msg, band);
2052 goto nla_put_failure;
2054 switch (state->chan_start) {
2056 if (nl80211_send_band_rateinfo(msg, sband))
2057 goto nla_put_failure;
2058 state->chan_start++;
2063 /* add frequencies */
2064 nl_freqs = nla_nest_start_noflag(msg,
2065 NL80211_BAND_ATTR_FREQS);
2067 goto nla_put_failure;
2069 for (i = state->chan_start - 1;
2070 i < sband->n_channels;
2072 nl_freq = nla_nest_start_noflag(msg,
2075 goto nla_put_failure;
2077 chan = &sband->channels[i];
2079 if (nl80211_msg_put_channel(
2080 msg, &rdev->wiphy, chan,
2082 goto nla_put_failure;
2084 nla_nest_end(msg, nl_freq);
2088 if (i < sband->n_channels)
2089 state->chan_start = i + 2;
2091 state->chan_start = 0;
2092 nla_nest_end(msg, nl_freqs);
2095 nla_nest_end(msg, nl_band);
2098 /* start again here */
2099 if (state->chan_start)
2104 nla_nest_end(msg, nl_bands);
2106 if (band < NUM_NL80211_BANDS)
2107 state->band_start = band + 1;
2109 state->band_start = 0;
2111 /* if bands & channels are done, continue outside */
2112 if (state->band_start == 0 && state->chan_start == 0)
2113 state->split_start++;
2118 nl_cmds = nla_nest_start_noflag(msg,
2119 NL80211_ATTR_SUPPORTED_COMMANDS);
2121 goto nla_put_failure;
2123 i = nl80211_add_commands_unsplit(rdev, msg);
2125 goto nla_put_failure;
2127 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2128 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
2129 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
2130 CMD(channel_switch, CHANNEL_SWITCH);
2131 CMD(set_qos_map, SET_QOS_MAP);
2132 if (rdev->wiphy.features &
2133 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
2134 CMD(add_tx_ts, ADD_TX_TS);
2135 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
2136 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
2137 CMD(update_ft_ies, UPDATE_FT_IES);
2141 nla_nest_end(msg, nl_cmds);
2142 state->split_start++;
2147 if (rdev->ops->remain_on_channel &&
2148 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
2150 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
2151 rdev->wiphy.max_remain_on_channel_duration))
2152 goto nla_put_failure;
2154 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
2155 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2156 goto nla_put_failure;
2158 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2159 goto nla_put_failure;
2160 state->split_start++;
2166 if (nl80211_send_wowlan(msg, rdev, state->split))
2167 goto nla_put_failure;
2168 state->split_start++;
2172 state->split_start++;
2176 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
2177 rdev->wiphy.software_iftypes))
2178 goto nla_put_failure;
2180 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
2182 goto nla_put_failure;
2184 state->split_start++;
2189 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
2190 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
2191 rdev->wiphy.ap_sme_capa))
2192 goto nla_put_failure;
2194 features = rdev->wiphy.features;
2196 * We can only add the per-channel limit information if the
2197 * dump is split, otherwise it makes it too big. Therefore
2198 * only advertise it in that case.
2201 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2202 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
2203 goto nla_put_failure;
2205 if (rdev->wiphy.ht_capa_mod_mask &&
2206 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
2207 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2208 rdev->wiphy.ht_capa_mod_mask))
2209 goto nla_put_failure;
2211 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2212 rdev->wiphy.max_acl_mac_addrs &&
2213 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
2214 rdev->wiphy.max_acl_mac_addrs))
2215 goto nla_put_failure;
2218 * Any information below this point is only available to
2219 * applications that can deal with it being split. This
2220 * helps ensure that newly added capabilities don't break
2221 * older tools by overrunning their buffers.
2223 * We still increment split_start so that in the split
2224 * case we'll continue with more data in the next round,
2225 * but break unconditionally so unsplit data stops here.
2227 state->split_start++;
2230 if (rdev->wiphy.extended_capabilities &&
2231 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
2232 rdev->wiphy.extended_capabilities_len,
2233 rdev->wiphy.extended_capabilities) ||
2234 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2235 rdev->wiphy.extended_capabilities_len,
2236 rdev->wiphy.extended_capabilities_mask)))
2237 goto nla_put_failure;
2239 if (rdev->wiphy.vht_capa_mod_mask &&
2240 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
2241 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2242 rdev->wiphy.vht_capa_mod_mask))
2243 goto nla_put_failure;
2245 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2246 rdev->wiphy.perm_addr))
2247 goto nla_put_failure;
2249 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2250 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2251 rdev->wiphy.addr_mask))
2252 goto nla_put_failure;
2254 if (rdev->wiphy.n_addresses > 1) {
2257 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2259 goto nla_put_failure;
2261 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2262 if (nla_put(msg, i + 1, ETH_ALEN,
2263 rdev->wiphy.addresses[i].addr))
2264 goto nla_put_failure;
2266 nla_nest_end(msg, attr);
2269 state->split_start++;
2272 if (nl80211_send_coalesce(msg, rdev))
2273 goto nla_put_failure;
2275 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
2276 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2277 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2278 goto nla_put_failure;
2280 if (rdev->wiphy.max_ap_assoc_sta &&
2281 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
2282 rdev->wiphy.max_ap_assoc_sta))
2283 goto nla_put_failure;
2285 state->split_start++;
2288 if (rdev->wiphy.n_vendor_commands) {
2289 const struct nl80211_vendor_cmd_info *info;
2290 struct nlattr *nested;
2292 nested = nla_nest_start_noflag(msg,
2293 NL80211_ATTR_VENDOR_DATA);
2295 goto nla_put_failure;
2297 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2298 info = &rdev->wiphy.vendor_commands[i].info;
2299 if (nla_put(msg, i + 1, sizeof(*info), info))
2300 goto nla_put_failure;
2302 nla_nest_end(msg, nested);
2305 if (rdev->wiphy.n_vendor_events) {
2306 const struct nl80211_vendor_cmd_info *info;
2307 struct nlattr *nested;
2309 nested = nla_nest_start_noflag(msg,
2310 NL80211_ATTR_VENDOR_EVENTS);
2312 goto nla_put_failure;
2314 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2315 info = &rdev->wiphy.vendor_events[i];
2316 if (nla_put(msg, i + 1, sizeof(*info), info))
2317 goto nla_put_failure;
2319 nla_nest_end(msg, nested);
2321 state->split_start++;
2324 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2325 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2326 rdev->wiphy.max_num_csa_counters))
2327 goto nla_put_failure;
2329 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2330 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2331 goto nla_put_failure;
2333 if (rdev->wiphy.max_sched_scan_reqs &&
2334 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2335 rdev->wiphy.max_sched_scan_reqs))
2336 goto nla_put_failure;
2338 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2339 sizeof(rdev->wiphy.ext_features),
2340 rdev->wiphy.ext_features))
2341 goto nla_put_failure;
2343 if (rdev->wiphy.bss_select_support) {
2344 struct nlattr *nested;
2345 u32 bss_select_support = rdev->wiphy.bss_select_support;
2347 nested = nla_nest_start_noflag(msg,
2348 NL80211_ATTR_BSS_SELECT);
2350 goto nla_put_failure;
2353 while (bss_select_support) {
2354 if ((bss_select_support & 1) &&
2355 nla_put_flag(msg, i))
2356 goto nla_put_failure;
2358 bss_select_support >>= 1;
2360 nla_nest_end(msg, nested);
2363 state->split_start++;
2366 if (rdev->wiphy.num_iftype_ext_capab &&
2367 rdev->wiphy.iftype_ext_capab) {
2368 struct nlattr *nested_ext_capab, *nested;
2370 nested = nla_nest_start_noflag(msg,
2371 NL80211_ATTR_IFTYPE_EXT_CAPA);
2373 goto nla_put_failure;
2375 for (i = state->capa_start;
2376 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2377 const struct wiphy_iftype_ext_capab *capab;
2379 capab = &rdev->wiphy.iftype_ext_capab[i];
2381 nested_ext_capab = nla_nest_start_noflag(msg,
2383 if (!nested_ext_capab ||
2384 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2386 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2387 capab->extended_capabilities_len,
2388 capab->extended_capabilities) ||
2389 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2390 capab->extended_capabilities_len,
2391 capab->extended_capabilities_mask))
2392 goto nla_put_failure;
2394 nla_nest_end(msg, nested_ext_capab);
2398 nla_nest_end(msg, nested);
2399 if (i < rdev->wiphy.num_iftype_ext_capab) {
2400 state->capa_start = i + 1;
2405 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2406 rdev->wiphy.nan_supported_bands))
2407 goto nla_put_failure;
2409 if (wiphy_ext_feature_isset(&rdev->wiphy,
2410 NL80211_EXT_FEATURE_TXQS)) {
2411 struct cfg80211_txq_stats txqstats = {};
2414 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2416 !nl80211_put_txq_stats(msg, &txqstats,
2417 NL80211_ATTR_TXQ_STATS))
2418 goto nla_put_failure;
2420 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2421 rdev->wiphy.txq_limit))
2422 goto nla_put_failure;
2423 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2424 rdev->wiphy.txq_memory_limit))
2425 goto nla_put_failure;
2426 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2427 rdev->wiphy.txq_quantum))
2428 goto nla_put_failure;
2431 state->split_start++;
2434 if (nl80211_send_pmsr_capa(rdev, msg))
2435 goto nla_put_failure;
2437 state->split_start++;
2440 if (rdev->wiphy.akm_suites &&
2441 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2442 sizeof(u32) * rdev->wiphy.n_akm_suites,
2443 rdev->wiphy.akm_suites))
2444 goto nla_put_failure;
2447 state->split_start = 0;
2451 genlmsg_end(msg, hdr);
2455 genlmsg_cancel(msg, hdr);
2459 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2460 struct netlink_callback *cb,
2461 struct nl80211_dump_wiphy_state *state)
2463 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2469 ret = nlmsg_parse_deprecated(cb->nlh,
2470 GENL_HDRLEN + nl80211_fam.hdrsize,
2471 tb, nl80211_fam.maxattr,
2472 nl80211_policy, NULL);
2473 /* ignore parse errors for backward compatibility */
2479 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2480 if (tb[NL80211_ATTR_WIPHY])
2481 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2482 if (tb[NL80211_ATTR_WDEV])
2483 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2484 if (tb[NL80211_ATTR_IFINDEX]) {
2485 struct net_device *netdev;
2486 struct cfg80211_registered_device *rdev;
2487 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2489 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
2494 if (netdev->ieee80211_ptr) {
2495 rdev = wiphy_to_rdev(
2496 netdev->ieee80211_ptr->wiphy);
2497 state->filter_wiphy = rdev->wiphy_idx;
2507 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2510 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
2511 struct cfg80211_registered_device *rdev;
2515 state = kzalloc(sizeof(*state), GFP_KERNEL);
2520 state->filter_wiphy = -1;
2521 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2527 cb->args[0] = (long)state;
2530 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2531 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
2533 if (++idx <= state->start)
2535 if (state->filter_wiphy != -1 &&
2536 state->filter_wiphy != rdev->wiphy_idx)
2538 /* attempt to fit multiple wiphy data chunks into the skb */
2540 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2542 NETLINK_CB(cb->skb).portid,
2544 NLM_F_MULTI, state);
2547 * If sending the wiphy data didn't fit (ENOBUFS
2548 * or EMSGSIZE returned), this SKB is still
2549 * empty (so it's not too big because another
2550 * wiphy dataset is already in the skb) and
2551 * we've not tried to adjust the dump allocation
2552 * yet ... then adjust the alloc size to be
2553 * bigger, and return 1 but with the empty skb.
2554 * This results in an empty message being RX'ed
2555 * in userspace, but that is ignored.
2557 * We can then retry with the larger buffer.
2559 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
2560 !skb->len && !state->split &&
2561 cb->min_dump_alloc < 4096) {
2562 cb->min_dump_alloc = 4096;
2563 state->split_start = 0;
2570 } while (state->split_start > 0);
2580 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2582 kfree((void *)cb->args[0]);
2586 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2588 struct sk_buff *msg;
2589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2590 struct nl80211_dump_wiphy_state state = {};
2592 msg = nlmsg_new(4096, GFP_KERNEL);
2596 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2597 info->snd_portid, info->snd_seq, 0,
2603 return genlmsg_reply(msg, info);
2606 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2607 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2608 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2609 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2610 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2611 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2614 static int parse_txq_params(struct nlattr *tb[],
2615 struct ieee80211_txq_params *txq_params)
2619 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
2620 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2621 !tb[NL80211_TXQ_ATTR_AIFS])
2624 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
2625 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2626 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2627 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2628 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2630 if (ac >= NL80211_NUM_ACS)
2632 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
2636 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2639 * You can only set the channel explicitly for WDS interfaces,
2640 * all others have their channel managed via their respective
2641 * "establish a connection" command (connect, join, ...)
2643 * For AP/GO and mesh mode, the channel can be set with the
2644 * channel userspace API, but is only stored and passed to the
2645 * low-level driver when the AP starts or the mesh is joined.
2646 * This is for backward compatibility, userspace can also give
2647 * the channel in the start-ap or join-mesh commands instead.
2649 * Monitors are special as they are normally slaved to
2650 * whatever else is going on, so they have their own special
2651 * operation to set the monitor channel if possible.
2654 wdev->iftype == NL80211_IFTYPE_AP ||
2655 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
2656 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2657 wdev->iftype == NL80211_IFTYPE_P2P_GO;
2660 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2661 struct genl_info *info,
2662 struct cfg80211_chan_def *chandef)
2664 struct netlink_ext_ack *extack = info->extack;
2665 struct nlattr **attrs = info->attrs;
2668 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
2671 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
2673 memset(chandef, 0, sizeof(*chandef));
2675 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
2676 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2677 chandef->center_freq1 = control_freq;
2678 chandef->center_freq2 = 0;
2680 /* Primary channel not allowed */
2681 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2682 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2683 "Channel is disabled");
2687 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2688 enum nl80211_channel_type chantype;
2690 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2693 case NL80211_CHAN_NO_HT:
2694 case NL80211_CHAN_HT20:
2695 case NL80211_CHAN_HT40PLUS:
2696 case NL80211_CHAN_HT40MINUS:
2697 cfg80211_chandef_create(chandef, chandef->chan,
2699 /* user input for center_freq is incorrect */
2700 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2701 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2702 NL_SET_ERR_MSG_ATTR(extack,
2703 attrs[NL80211_ATTR_CENTER_FREQ1],
2704 "bad center frequency 1");
2707 /* center_freq2 must be zero */
2708 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2709 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2710 NL_SET_ERR_MSG_ATTR(extack,
2711 attrs[NL80211_ATTR_CENTER_FREQ2],
2712 "center frequency 2 can't be used");
2717 NL_SET_ERR_MSG_ATTR(extack,
2718 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2719 "invalid channel type");
2722 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2724 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2725 if (attrs[NL80211_ATTR_CENTER_FREQ1])
2726 chandef->center_freq1 =
2727 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2728 if (attrs[NL80211_ATTR_CENTER_FREQ2])
2729 chandef->center_freq2 =
2730 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
2733 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
2734 chandef->edmg.channels =
2735 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
2737 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
2738 chandef->edmg.bw_config =
2739 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
2741 chandef->edmg.bw_config = 0;
2742 chandef->edmg.channels = 0;
2745 if (!cfg80211_chandef_valid(chandef)) {
2746 NL_SET_ERR_MSG(extack, "invalid channel definition");
2750 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2751 IEEE80211_CHAN_DISABLED)) {
2752 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
2756 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2757 chandef->width == NL80211_CHAN_WIDTH_10) &&
2758 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2759 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
2766 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
2767 struct net_device *dev,
2768 struct genl_info *info)
2770 struct cfg80211_chan_def chandef;
2772 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
2773 struct wireless_dev *wdev = NULL;
2776 wdev = dev->ieee80211_ptr;
2777 if (!nl80211_can_set_dev_channel(wdev))
2780 iftype = wdev->iftype;
2782 result = nl80211_parse_chandef(rdev, info, &chandef);
2787 case NL80211_IFTYPE_AP:
2788 case NL80211_IFTYPE_P2P_GO:
2789 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2794 if (wdev->beacon_interval) {
2795 if (!dev || !rdev->ops->set_ap_chanwidth ||
2796 !(rdev->wiphy.features &
2797 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2802 /* Only allow dynamic channel width changes */
2803 if (chandef.chan != wdev->preset_chandef.chan) {
2807 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2811 wdev->preset_chandef = chandef;
2814 case NL80211_IFTYPE_MESH_POINT:
2815 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
2817 case NL80211_IFTYPE_MONITOR:
2818 result = cfg80211_set_monitor_channel(rdev, &chandef);
2827 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2830 struct net_device *netdev = info->user_ptr[1];
2832 return __nl80211_set_channel(rdev, netdev, info);
2835 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2838 struct net_device *dev = info->user_ptr[1];
2839 struct wireless_dev *wdev = dev->ieee80211_ptr;
2842 if (!info->attrs[NL80211_ATTR_MAC])
2845 if (netif_running(dev))
2848 if (!rdev->ops->set_wds_peer)
2851 if (wdev->iftype != NL80211_IFTYPE_WDS)
2854 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
2855 return rdev_set_wds_peer(rdev, dev, bssid);
2858 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2860 struct cfg80211_registered_device *rdev;
2861 struct net_device *netdev = NULL;
2862 struct wireless_dev *wdev;
2863 int result = 0, rem_txq_params = 0;
2864 struct nlattr *nl_txq_params;
2866 u8 retry_short = 0, retry_long = 0;
2867 u32 frag_threshold = 0, rts_threshold = 0;
2868 u8 coverage_class = 0;
2869 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
2874 * Try to find the wiphy and netdev. Normally this
2875 * function shouldn't need the netdev, but this is
2876 * done for backward compatibility -- previously
2877 * setting the channel was done per wiphy, but now
2878 * it is per netdev. Previous userland like hostapd
2879 * also passed a netdev to set_wiphy, so that it is
2880 * possible to let that go to the right netdev!
2883 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2884 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2886 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
2887 if (netdev && netdev->ieee80211_ptr)
2888 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
2894 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2897 return PTR_ERR(rdev);
2902 wdev = netdev->ieee80211_ptr;
2905 * end workaround code, by now the rdev is available
2906 * and locked, and wdev may or may not be NULL.
2909 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
2910 result = cfg80211_dev_rename(
2911 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
2916 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2917 struct ieee80211_txq_params txq_params;
2918 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2920 if (!rdev->ops->set_txq_params)
2926 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2927 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2930 if (!netif_running(netdev))
2933 nla_for_each_nested(nl_txq_params,
2934 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2936 result = nla_parse_nested_deprecated(tb,
2937 NL80211_TXQ_ATTR_MAX,
2943 result = parse_txq_params(tb, &txq_params);
2947 result = rdev_set_txq_params(rdev, netdev,
2954 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2955 result = __nl80211_set_channel(
2957 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2963 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
2964 struct wireless_dev *txp_wdev = wdev;
2965 enum nl80211_tx_power_setting type;
2968 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2971 if (!rdev->ops->set_tx_power)
2974 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2975 type = nla_get_u32(info->attrs[idx]);
2977 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2978 (type != NL80211_TX_POWER_AUTOMATIC))
2981 if (type != NL80211_TX_POWER_AUTOMATIC) {
2982 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2983 mbm = nla_get_u32(info->attrs[idx]);
2986 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
2991 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2992 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2995 if ((!rdev->wiphy.available_antennas_tx &&
2996 !rdev->wiphy.available_antennas_rx) ||
2997 !rdev->ops->set_antenna)
3000 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3001 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3003 /* reject antenna configurations which don't match the
3004 * available antenna masks, except for the "all" mask */
3005 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
3006 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
3009 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3010 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
3012 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
3019 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3020 retry_short = nla_get_u8(
3021 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
3023 changed |= WIPHY_PARAM_RETRY_SHORT;
3026 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3027 retry_long = nla_get_u8(
3028 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
3030 changed |= WIPHY_PARAM_RETRY_LONG;
3033 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3034 frag_threshold = nla_get_u32(
3035 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
3036 if (frag_threshold < 256)
3039 if (frag_threshold != (u32) -1) {
3041 * Fragments (apart from the last one) are required to
3042 * have even length. Make the fragmentation code
3043 * simpler by stripping LSB should someone try to use
3044 * odd threshold value.
3046 frag_threshold &= ~0x1;
3048 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3051 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3052 rts_threshold = nla_get_u32(
3053 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3054 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3057 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
3058 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
3061 coverage_class = nla_get_u8(
3062 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3063 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3066 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3067 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
3070 changed |= WIPHY_PARAM_DYN_ACK;
3073 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3074 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3075 NL80211_EXT_FEATURE_TXQS))
3077 txq_limit = nla_get_u32(
3078 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3079 changed |= WIPHY_PARAM_TXQ_LIMIT;
3082 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3083 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3084 NL80211_EXT_FEATURE_TXQS))
3086 txq_memory_limit = nla_get_u32(
3087 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3088 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3091 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3092 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3093 NL80211_EXT_FEATURE_TXQS))
3095 txq_quantum = nla_get_u32(
3096 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3097 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3101 u8 old_retry_short, old_retry_long;
3102 u32 old_frag_threshold, old_rts_threshold;
3103 u8 old_coverage_class;
3104 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
3106 if (!rdev->ops->set_wiphy_params)
3109 old_retry_short = rdev->wiphy.retry_short;
3110 old_retry_long = rdev->wiphy.retry_long;
3111 old_frag_threshold = rdev->wiphy.frag_threshold;
3112 old_rts_threshold = rdev->wiphy.rts_threshold;
3113 old_coverage_class = rdev->wiphy.coverage_class;
3114 old_txq_limit = rdev->wiphy.txq_limit;
3115 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3116 old_txq_quantum = rdev->wiphy.txq_quantum;
3118 if (changed & WIPHY_PARAM_RETRY_SHORT)
3119 rdev->wiphy.retry_short = retry_short;
3120 if (changed & WIPHY_PARAM_RETRY_LONG)
3121 rdev->wiphy.retry_long = retry_long;
3122 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3123 rdev->wiphy.frag_threshold = frag_threshold;
3124 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3125 rdev->wiphy.rts_threshold = rts_threshold;
3126 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3127 rdev->wiphy.coverage_class = coverage_class;
3128 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3129 rdev->wiphy.txq_limit = txq_limit;
3130 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3131 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3132 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3133 rdev->wiphy.txq_quantum = txq_quantum;
3135 result = rdev_set_wiphy_params(rdev, changed);
3137 rdev->wiphy.retry_short = old_retry_short;
3138 rdev->wiphy.retry_long = old_retry_long;
3139 rdev->wiphy.frag_threshold = old_frag_threshold;
3140 rdev->wiphy.rts_threshold = old_rts_threshold;
3141 rdev->wiphy.coverage_class = old_coverage_class;
3142 rdev->wiphy.txq_limit = old_txq_limit;
3143 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3144 rdev->wiphy.txq_quantum = old_txq_quantum;
3151 static int nl80211_send_chandef(struct sk_buff *msg,
3152 const struct cfg80211_chan_def *chandef)
3154 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3157 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3158 chandef->chan->center_freq))
3160 switch (chandef->width) {
3161 case NL80211_CHAN_WIDTH_20_NOHT:
3162 case NL80211_CHAN_WIDTH_20:
3163 case NL80211_CHAN_WIDTH_40:
3164 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3165 cfg80211_get_chandef_type(chandef)))
3171 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3173 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3175 if (chandef->center_freq2 &&
3176 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
3181 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
3182 struct cfg80211_registered_device *rdev,
3183 struct wireless_dev *wdev,
3184 enum nl80211_commands cmd)
3186 struct net_device *dev = wdev->netdev;
3189 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3190 cmd != NL80211_CMD_DEL_INTERFACE &&
3191 cmd != NL80211_CMD_SET_INTERFACE);
3193 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
3198 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3199 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
3200 goto nla_put_failure;
3202 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3203 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
3204 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3205 NL80211_ATTR_PAD) ||
3206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
3207 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3208 rdev->devlist_generation ^
3209 (cfg80211_rdev_list_generation << 2)) ||
3210 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
3211 goto nla_put_failure;
3213 if (rdev->ops->get_channel) {
3215 struct cfg80211_chan_def chandef = {};
3217 ret = rdev_get_channel(rdev, wdev, &chandef);
3219 if (nl80211_send_chandef(msg, &chandef))
3220 goto nla_put_failure;
3224 if (rdev->ops->get_tx_power) {
3227 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3229 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3231 goto nla_put_failure;
3235 switch (wdev->iftype) {
3236 case NL80211_IFTYPE_AP:
3237 if (wdev->ssid_len &&
3238 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
3239 goto nla_put_failure_locked;
3241 case NL80211_IFTYPE_STATION:
3242 case NL80211_IFTYPE_P2P_CLIENT:
3243 case NL80211_IFTYPE_ADHOC: {
3245 if (!wdev->current_bss)
3248 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3251 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3252 goto nla_put_failure_rcu_locked;
3262 if (rdev->ops->get_txq_stats) {
3263 struct cfg80211_txq_stats txqstats = {};
3264 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3267 !nl80211_put_txq_stats(msg, &txqstats,
3268 NL80211_ATTR_TXQ_STATS))
3269 goto nla_put_failure;
3272 genlmsg_end(msg, hdr);
3275 nla_put_failure_rcu_locked:
3277 nla_put_failure_locked:
3280 genlmsg_cancel(msg, hdr);
3284 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3288 int wp_start = cb->args[0];
3289 int if_start = cb->args[1];
3290 int filter_wiphy = -1;
3291 struct cfg80211_registered_device *rdev;
3292 struct wireless_dev *wdev;
3297 struct nl80211_dump_wiphy_state state = {
3301 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3305 filter_wiphy = state.filter_wiphy;
3308 * if filtering, set cb->args[2] to +1 since 0 is the default
3309 * value needed to determine that parsing is necessary.
3311 if (filter_wiphy >= 0)
3312 cb->args[2] = filter_wiphy + 1;
3315 } else if (cb->args[2] > 0) {
3316 filter_wiphy = cb->args[2] - 1;
3319 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3320 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3322 if (wp_idx < wp_start) {
3327 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3332 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
3333 if (if_idx < if_start) {
3337 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
3338 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3340 NL80211_CMD_NEW_INTERFACE) < 0) {
3349 cb->args[0] = wp_idx;
3350 cb->args[1] = if_idx;
3359 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3361 struct sk_buff *msg;
3362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3363 struct wireless_dev *wdev = info->user_ptr[1];
3365 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3369 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3370 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
3375 return genlmsg_reply(msg, info);
3378 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3379 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3380 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3381 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3382 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3383 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
3384 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
3387 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3389 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3397 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
3400 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3402 *mntrflags |= (1<<flag);
3404 *mntrflags |= MONITOR_FLAG_CHANGED;
3409 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3410 enum nl80211_iftype type,
3411 struct genl_info *info,
3412 struct vif_params *params)
3414 bool change = false;
3417 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3418 if (type != NL80211_IFTYPE_MONITOR)
3421 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3429 if (params->flags & MONITOR_FLAG_ACTIVE &&
3430 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3433 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3434 const u8 *mumimo_groups;
3435 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3437 if (type != NL80211_IFTYPE_MONITOR)
3440 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3444 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3446 /* bits 0 and 63 are reserved and must be zero */
3447 if ((mumimo_groups[0] & BIT(0)) ||
3448 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
3451 params->vht_mumimo_groups = mumimo_groups;
3455 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3456 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3458 if (type != NL80211_IFTYPE_MONITOR)
3461 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3464 params->vht_mumimo_follow_addr =
3465 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3469 return change ? 1 : 0;
3472 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
3473 struct net_device *netdev, u8 use_4addr,
3474 enum nl80211_iftype iftype)
3477 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
3483 case NL80211_IFTYPE_AP_VLAN:
3484 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3487 case NL80211_IFTYPE_STATION:
3488 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3498 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3501 struct vif_params params;
3503 enum nl80211_iftype otype, ntype;
3504 struct net_device *dev = info->user_ptr[1];
3505 bool change = false;
3507 memset(¶ms, 0, sizeof(params));
3509 otype = ntype = dev->ieee80211_ptr->iftype;
3511 if (info->attrs[NL80211_ATTR_IFTYPE]) {
3512 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3517 if (info->attrs[NL80211_ATTR_MESH_ID]) {
3518 struct wireless_dev *wdev = dev->ieee80211_ptr;
3520 if (ntype != NL80211_IFTYPE_MESH_POINT)
3522 if (netif_running(dev))
3526 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3527 IEEE80211_MAX_MESH_ID_LEN);
3528 wdev->mesh_id_up_len =
3529 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3530 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3531 wdev->mesh_id_up_len);
3535 if (info->attrs[NL80211_ATTR_4ADDR]) {
3536 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3538 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
3542 params.use_4addr = -1;
3545 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms);
3552 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms);
3556 if (!err && params.use_4addr != -1)
3557 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3559 if (change && !err) {
3560 struct wireless_dev *wdev = dev->ieee80211_ptr;
3562 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3568 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3571 struct vif_params params;
3572 struct wireless_dev *wdev;
3573 struct sk_buff *msg;
3575 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3577 /* to avoid failing a new interface creation due to pending removal */
3578 cfg80211_destroy_ifaces(rdev);
3580 memset(¶ms, 0, sizeof(params));
3582 if (!info->attrs[NL80211_ATTR_IFNAME])
3585 if (info->attrs[NL80211_ATTR_IFTYPE])
3586 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3588 if (!rdev->ops->add_virtual_intf)
3591 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
3592 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3593 info->attrs[NL80211_ATTR_MAC]) {
3594 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3596 if (!is_valid_ether_addr(params.macaddr))
3597 return -EADDRNOTAVAIL;
3600 if (info->attrs[NL80211_ATTR_4ADDR]) {
3601 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3602 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
3607 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
3610 err = nl80211_parse_mon_options(rdev, type, info, ¶ms);
3614 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3618 wdev = rdev_add_virtual_intf(rdev,
3619 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
3620 NET_NAME_USER, type, ¶ms);
3621 if (WARN_ON(!wdev)) {
3624 } else if (IS_ERR(wdev)) {
3626 return PTR_ERR(wdev);
3629 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
3630 wdev->owner_nlportid = info->snd_portid;
3633 case NL80211_IFTYPE_MESH_POINT:
3634 if (!info->attrs[NL80211_ATTR_MESH_ID])
3637 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3638 IEEE80211_MAX_MESH_ID_LEN);
3639 wdev->mesh_id_up_len =
3640 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3641 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3642 wdev->mesh_id_up_len);
3645 case NL80211_IFTYPE_NAN:
3646 case NL80211_IFTYPE_P2P_DEVICE:
3648 * P2P Device and NAN do not have a netdev, so don't go
3649 * through the netdev notifier and must be added here
3651 cfg80211_init_wdev(rdev, wdev);
3657 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3658 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
3663 return genlmsg_reply(msg, info);
3666 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3669 struct wireless_dev *wdev = info->user_ptr[1];
3671 if (!rdev->ops->del_virtual_intf)
3675 * If we remove a wireless device without a netdev then clear
3676 * user_ptr[1] so that nl80211_post_doit won't dereference it
3677 * to check if it needs to do dev_put(). Otherwise it crashes
3678 * since the wdev has been freed, unlike with a netdev where
3679 * we need the dev_put() for the netdev to really be freed.
3682 info->user_ptr[1] = NULL;
3684 return rdev_del_virtual_intf(rdev, wdev);
3687 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3690 struct net_device *dev = info->user_ptr[1];
3693 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3696 if (!rdev->ops->set_noack_map)
3699 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3701 return rdev_set_noack_map(rdev, dev, noack_map);
3704 struct get_key_cookie {
3705 struct sk_buff *msg;
3710 static void get_key_callback(void *c, struct key_params *params)
3713 struct get_key_cookie *cookie = c;
3716 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3717 params->key_len, params->key)) ||
3719 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3720 params->seq_len, params->seq)) ||
3722 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3724 goto nla_put_failure;
3726 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
3728 goto nla_put_failure;
3731 nla_put(cookie->msg, NL80211_KEY_DATA,
3732 params->key_len, params->key)) ||
3734 nla_put(cookie->msg, NL80211_KEY_SEQ,
3735 params->seq_len, params->seq)) ||
3737 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3739 goto nla_put_failure;
3741 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
3742 goto nla_put_failure;
3744 nla_nest_end(cookie->msg, key);
3751 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3755 struct net_device *dev = info->user_ptr[1];
3757 const u8 *mac_addr = NULL;
3759 struct get_key_cookie cookie = {
3763 struct sk_buff *msg;
3765 if (info->attrs[NL80211_ATTR_KEY_IDX])
3766 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3768 if (info->attrs[NL80211_ATTR_MAC])
3769 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3771 pairwise = !!mac_addr;
3772 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3773 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
3775 if (kt != NL80211_KEYTYPE_GROUP &&
3776 kt != NL80211_KEYTYPE_PAIRWISE)
3778 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3781 if (!rdev->ops->get_key)
3784 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3787 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3791 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
3792 NL80211_CMD_NEW_KEY);
3794 goto nla_put_failure;
3797 cookie.idx = key_idx;
3799 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3800 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3801 goto nla_put_failure;
3803 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3804 goto nla_put_failure;
3806 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3813 goto nla_put_failure;
3815 genlmsg_end(msg, hdr);
3816 return genlmsg_reply(msg, info);
3825 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3828 struct key_parse key;
3830 struct net_device *dev = info->user_ptr[1];
3832 err = nl80211_parse_key(info, &key);
3839 /* Only support setting default key and
3840 * Extended Key ID action NL80211_KEY_SET_TX.
3842 if (!key.def && !key.defmgmt &&
3843 !(key.p.mode == NL80211_KEY_SET_TX))
3846 wdev_lock(dev->ieee80211_ptr);
3849 if (!rdev->ops->set_default_key) {
3854 err = nl80211_key_allowed(dev->ieee80211_ptr);
3858 err = rdev_set_default_key(rdev, dev, key.idx,
3859 key.def_uni, key.def_multi);
3864 #ifdef CONFIG_CFG80211_WEXT
3865 dev->ieee80211_ptr->wext.default_key = key.idx;
3867 } else if (key.defmgmt) {
3868 if (key.def_uni || !key.def_multi) {
3873 if (!rdev->ops->set_default_mgmt_key) {
3878 err = nl80211_key_allowed(dev->ieee80211_ptr);
3882 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
3886 #ifdef CONFIG_CFG80211_WEXT
3887 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3889 } else if (key.p.mode == NL80211_KEY_SET_TX &&
3890 wiphy_ext_feature_isset(&rdev->wiphy,
3891 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
3892 u8 *mac_addr = NULL;
3894 if (info->attrs[NL80211_ATTR_MAC])
3895 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3897 if (!mac_addr || key.idx < 0 || key.idx > 1) {
3902 err = rdev_add_key(rdev, dev, key.idx,
3903 NL80211_KEYTYPE_PAIRWISE,
3909 wdev_unlock(dev->ieee80211_ptr);
3914 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3916 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3918 struct net_device *dev = info->user_ptr[1];
3919 struct key_parse key;
3920 const u8 *mac_addr = NULL;
3922 err = nl80211_parse_key(info, &key);
3929 if (info->attrs[NL80211_ATTR_MAC])
3930 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3932 if (key.type == -1) {
3934 key.type = NL80211_KEYTYPE_PAIRWISE;
3936 key.type = NL80211_KEYTYPE_GROUP;
3940 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3941 key.type != NL80211_KEYTYPE_GROUP)
3944 if (key.type == NL80211_KEYTYPE_GROUP &&
3945 info->attrs[NL80211_ATTR_VLAN_ID])
3946 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
3948 if (!rdev->ops->add_key)
3951 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3952 key.type == NL80211_KEYTYPE_PAIRWISE,
3956 wdev_lock(dev->ieee80211_ptr);
3957 err = nl80211_key_allowed(dev->ieee80211_ptr);
3959 err = rdev_add_key(rdev, dev, key.idx,
3960 key.type == NL80211_KEYTYPE_PAIRWISE,
3962 wdev_unlock(dev->ieee80211_ptr);
3967 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3971 struct net_device *dev = info->user_ptr[1];
3972 u8 *mac_addr = NULL;
3973 struct key_parse key;
3975 err = nl80211_parse_key(info, &key);
3979 if (info->attrs[NL80211_ATTR_MAC])
3980 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3982 if (key.type == -1) {
3984 key.type = NL80211_KEYTYPE_PAIRWISE;
3986 key.type = NL80211_KEYTYPE_GROUP;
3990 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3991 key.type != NL80211_KEYTYPE_GROUP)
3994 if (!rdev->ops->del_key)
3997 wdev_lock(dev->ieee80211_ptr);
3998 err = nl80211_key_allowed(dev->ieee80211_ptr);
4000 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
4001 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4005 err = rdev_del_key(rdev, dev, key.idx,
4006 key.type == NL80211_KEYTYPE_PAIRWISE,
4009 #ifdef CONFIG_CFG80211_WEXT
4011 if (key.idx == dev->ieee80211_ptr->wext.default_key)
4012 dev->ieee80211_ptr->wext.default_key = -1;
4013 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
4014 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
4017 wdev_unlock(dev->ieee80211_ptr);
4022 /* This function returns an error or the number of nested attributes */
4023 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4025 struct nlattr *attr;
4026 int n_entries = 0, tmp;
4028 nla_for_each_nested(attr, nl_attr, tmp) {
4029 if (nla_len(attr) != ETH_ALEN)
4039 * This function parses ACL information and allocates memory for ACL data.
4040 * On successful return, the calling function is responsible to free the
4041 * ACL buffer returned by this function.
4043 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4044 struct genl_info *info)
4046 enum nl80211_acl_policy acl_policy;
4047 struct nlattr *attr;
4048 struct cfg80211_acl_data *acl;
4049 int i = 0, n_entries, tmp;
4051 if (!wiphy->max_acl_mac_addrs)
4052 return ERR_PTR(-EOPNOTSUPP);
4054 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4055 return ERR_PTR(-EINVAL);
4057 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4058 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4059 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4060 return ERR_PTR(-EINVAL);
4062 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4063 return ERR_PTR(-EINVAL);
4065 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4067 return ERR_PTR(n_entries);
4069 if (n_entries > wiphy->max_acl_mac_addrs)
4070 return ERR_PTR(-ENOTSUPP);
4072 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
4074 return ERR_PTR(-ENOMEM);
4076 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4077 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4081 acl->n_acl_entries = n_entries;
4082 acl->acl_policy = acl_policy;
4087 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4090 struct net_device *dev = info->user_ptr[1];
4091 struct cfg80211_acl_data *acl;
4094 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4095 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4098 if (!dev->ieee80211_ptr->beacon_interval)
4101 acl = parse_acl_data(&rdev->wiphy, info);
4103 return PTR_ERR(acl);
4105 err = rdev_set_mac_acl(rdev, dev, acl);
4112 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4113 u8 *rates, u8 rates_len)
4118 for (i = 0; i < rates_len; i++) {
4119 int rate = (rates[i] & 0x7f) * 5;
4122 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4123 struct ieee80211_rate *srate =
4124 &sband->bitrates[ridx];
4125 if (rate == srate->bitrate) {
4130 if (ridx == sband->n_bitrates)
4131 return 0; /* rate not found */
4137 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4138 u8 *rates, u8 rates_len,
4139 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4143 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4145 for (i = 0; i < rates_len; i++) {
4148 ridx = rates[i] / 8;
4149 rbit = BIT(rates[i] % 8);
4151 /* check validity */
4152 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4155 /* check availability */
4156 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
4157 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4166 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4170 switch (vht_mcs_map) {
4171 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4173 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4176 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4179 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4189 static void vht_build_mcs_mask(u16 vht_mcs_map,
4190 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4194 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4195 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4200 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4201 struct nl80211_txrate_vht *txrate,
4202 u16 mcs[NL80211_VHT_NSS_MAX])
4204 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4205 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4208 if (!sband->vht_cap.vht_supported)
4211 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4213 /* Build vht_mcs_mask from VHT capabilities */
4214 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4216 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4217 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4218 mcs[i] = txrate->mcs[i];
4226 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4227 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4228 .len = NL80211_MAX_SUPP_RATES },
4229 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4230 .len = NL80211_MAX_SUPP_HT_RATES },
4231 [NL80211_TXRATE_VHT] = {
4232 .type = NLA_EXACT_LEN_WARN,
4233 .len = sizeof(struct nl80211_txrate_vht),
4235 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4238 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4239 struct cfg80211_bitrate_mask *mask)
4241 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4242 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4244 struct nlattr *tx_rates;
4245 struct ieee80211_supported_band *sband;
4248 memset(mask, 0, sizeof(*mask));
4249 /* Default to all rates enabled */
4250 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4251 sband = rdev->wiphy.bands[i];
4256 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4257 memcpy(mask->control[i].ht_mcs,
4258 sband->ht_cap.mcs.rx_mask,
4259 sizeof(mask->control[i].ht_mcs));
4261 if (!sband->vht_cap.vht_supported)
4264 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4265 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4268 /* if no rates are given set it back to the defaults */
4269 if (!info->attrs[NL80211_ATTR_TX_RATES])
4272 /* The nested attribute uses enum nl80211_band as the index. This maps
4273 * directly to the enum nl80211_band values used in cfg80211.
4275 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4276 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4277 enum nl80211_band band = nla_type(tx_rates);
4280 if (band < 0 || band >= NUM_NL80211_BANDS)
4282 sband = rdev->wiphy.bands[band];
4285 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4287 nl80211_txattr_policy,
4291 if (tb[NL80211_TXRATE_LEGACY]) {
4292 mask->control[band].legacy = rateset_to_mask(
4294 nla_data(tb[NL80211_TXRATE_LEGACY]),
4295 nla_len(tb[NL80211_TXRATE_LEGACY]));
4296 if ((mask->control[band].legacy == 0) &&
4297 nla_len(tb[NL80211_TXRATE_LEGACY]))
4300 if (tb[NL80211_TXRATE_HT]) {
4301 if (!ht_rateset_to_mask(
4303 nla_data(tb[NL80211_TXRATE_HT]),
4304 nla_len(tb[NL80211_TXRATE_HT]),
4305 mask->control[band].ht_mcs))
4308 if (tb[NL80211_TXRATE_VHT]) {
4309 if (!vht_set_mcs_mask(
4311 nla_data(tb[NL80211_TXRATE_VHT]),
4312 mask->control[band].vht_mcs))
4315 if (tb[NL80211_TXRATE_GI]) {
4316 mask->control[band].gi =
4317 nla_get_u8(tb[NL80211_TXRATE_GI]);
4318 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4322 if (mask->control[band].legacy == 0) {
4323 /* don't allow empty legacy rates if HT or VHT
4324 * are not even supported.
4326 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4327 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4330 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4331 if (mask->control[band].ht_mcs[i])
4334 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4335 if (mask->control[band].vht_mcs[i])
4338 /* legacy and mcs rates may not be both empty */
4347 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4348 enum nl80211_band band,
4349 struct cfg80211_bitrate_mask *beacon_rate)
4351 u32 count_ht, count_vht, i;
4352 u32 rate = beacon_rate->control[band].legacy;
4354 /* Allow only one rate */
4355 if (hweight32(rate) > 1)
4359 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4360 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
4362 } else if (beacon_rate->control[band].ht_mcs[i]) {
4367 if (count_ht && rate)
4372 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4373 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
4375 } else if (beacon_rate->control[band].vht_mcs[i]) {
4380 if (count_vht && rate)
4384 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4388 !wiphy_ext_feature_isset(&rdev->wiphy,
4389 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4392 !wiphy_ext_feature_isset(&rdev->wiphy,
4393 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4396 !wiphy_ext_feature_isset(&rdev->wiphy,
4397 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4403 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4404 struct nlattr *attrs[],
4405 struct cfg80211_beacon_data *bcn)
4407 bool haveinfo = false;
4410 memset(bcn, 0, sizeof(*bcn));
4412 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4413 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4414 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
4420 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4421 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4422 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
4429 if (attrs[NL80211_ATTR_IE]) {
4430 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4431 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
4434 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
4435 bcn->proberesp_ies =
4436 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
4437 bcn->proberesp_ies_len =
4438 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
4441 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
4442 bcn->assocresp_ies =
4443 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
4444 bcn->assocresp_ies_len =
4445 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
4448 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4449 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4450 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
4453 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4454 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4456 err = nla_parse_nested_deprecated(tb,
4457 NL80211_FTM_RESP_ATTR_MAX,
4458 attrs[NL80211_ATTR_FTM_RESPONDER],
4463 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4464 wiphy_ext_feature_isset(&rdev->wiphy,
4465 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4466 bcn->ftm_responder = 1;
4470 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4471 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4472 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4475 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4476 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4477 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4480 bcn->ftm_responder = -1;
4486 static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
4487 struct ieee80211_he_obss_pd *he_obss_pd)
4489 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
4492 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
4493 he_obss_pd_policy, NULL);
4497 if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] ||
4498 !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
4501 he_obss_pd->min_offset =
4502 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
4503 he_obss_pd->max_offset =
4504 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
4506 if (he_obss_pd->min_offset >= he_obss_pd->max_offset)
4509 he_obss_pd->enable = true;
4514 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4522 for (i = 0; i < rates[1]; i++) {
4523 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4524 params->ht_required = true;
4525 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4526 params->vht_required = true;
4531 * Since the nl80211 API didn't include, from the beginning, attributes about
4532 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4533 * benefit of drivers that rebuild IEs in the firmware.
4535 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4537 const struct cfg80211_beacon_data *bcn = ¶ms->beacon;
4538 size_t ies_len = bcn->tail_len;
4539 const u8 *ies = bcn->tail;
4543 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4544 nl80211_check_ap_rate_selectors(params, rates);
4546 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4547 nl80211_check_ap_rate_selectors(params, rates);
4549 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4550 if (cap && cap[1] >= sizeof(*params->ht_cap))
4551 params->ht_cap = (void *)(cap + 2);
4552 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4553 if (cap && cap[1] >= sizeof(*params->vht_cap))
4554 params->vht_cap = (void *)(cap + 2);
4555 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4556 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4557 params->he_cap = (void *)(cap + 3);
4560 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4561 struct cfg80211_ap_settings *params)
4563 struct wireless_dev *wdev;
4566 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
4567 if (wdev->iftype != NL80211_IFTYPE_AP &&
4568 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4571 if (!wdev->preset_chandef.chan)
4574 params->chandef = wdev->preset_chandef;
4582 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4583 enum nl80211_auth_type auth_type,
4584 enum nl80211_commands cmd)
4586 if (auth_type > NL80211_AUTHTYPE_MAX)
4590 case NL80211_CMD_AUTHENTICATE:
4591 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4592 auth_type == NL80211_AUTHTYPE_SAE)
4594 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4595 NL80211_EXT_FEATURE_FILS_STA) &&
4596 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4597 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4598 auth_type == NL80211_AUTHTYPE_FILS_PK))
4601 case NL80211_CMD_CONNECT:
4602 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4603 !wiphy_ext_feature_isset(&rdev->wiphy,
4604 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
4605 auth_type == NL80211_AUTHTYPE_SAE)
4608 /* FILS with SK PFS or PK not supported yet */
4609 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4610 auth_type == NL80211_AUTHTYPE_FILS_PK)
4612 if (!wiphy_ext_feature_isset(
4614 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4615 auth_type == NL80211_AUTHTYPE_FILS_SK)
4618 case NL80211_CMD_START_AP:
4619 /* SAE not supported yet */
4620 if (auth_type == NL80211_AUTHTYPE_SAE)
4622 /* FILS not supported yet */
4623 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4624 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4625 auth_type == NL80211_AUTHTYPE_FILS_PK)
4633 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4636 struct net_device *dev = info->user_ptr[1];
4637 struct wireless_dev *wdev = dev->ieee80211_ptr;
4638 struct cfg80211_ap_settings params;
4641 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4642 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4645 if (!rdev->ops->start_ap)
4648 if (wdev->beacon_interval)
4651 memset(¶ms, 0, sizeof(params));
4653 /* these are required for START_AP */
4654 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4655 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4656 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4659 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon);
4663 params.beacon_interval =
4664 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4665 params.dtim_period =
4666 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4668 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4669 params.beacon_interval);
4674 * In theory, some of these attributes should be required here
4675 * but since they were not used when the command was originally
4676 * added, keep them optional for old user space programs to let
4677 * them continue to work with drivers that do not need the
4678 * additional information -- drivers must check!
4680 if (info->attrs[NL80211_ATTR_SSID]) {
4681 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4683 nla_len(info->attrs[NL80211_ATTR_SSID]);
4684 if (params.ssid_len == 0 ||
4685 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4689 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
4690 params.hidden_ssid = nla_get_u32(
4691 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
4693 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4695 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4696 params.auth_type = nla_get_u32(
4697 info->attrs[NL80211_ATTR_AUTH_TYPE]);
4698 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4699 NL80211_CMD_START_AP))
4702 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4704 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
4705 NL80211_MAX_NR_CIPHER_SUITES);
4709 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4710 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4712 params.inactivity_timeout = nla_get_u16(
4713 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4716 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4717 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4719 params.p2p_ctwindow =
4720 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4721 if (params.p2p_ctwindow != 0 &&
4722 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4726 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4729 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4731 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4732 params.p2p_opp_ps = tmp;
4733 if (params.p2p_opp_ps != 0 &&
4734 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4738 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4739 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
4742 } else if (wdev->preset_chandef.chan) {
4743 params.chandef = wdev->preset_chandef;
4744 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
4747 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
4751 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4752 err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate);
4756 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4757 ¶ms.beacon_rate);
4762 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4764 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4765 switch (params.smps_mode) {
4766 case NL80211_SMPS_OFF:
4768 case NL80211_SMPS_STATIC:
4769 if (!(rdev->wiphy.features &
4770 NL80211_FEATURE_STATIC_SMPS))
4773 case NL80211_SMPS_DYNAMIC:
4774 if (!(rdev->wiphy.features &
4775 NL80211_FEATURE_DYNAMIC_SMPS))
4782 params.smps_mode = NL80211_SMPS_OFF;
4785 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4786 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4789 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4790 params.acl = parse_acl_data(&rdev->wiphy, info);
4791 if (IS_ERR(params.acl))
4792 return PTR_ERR(params.acl);
4795 params.twt_responder =
4796 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
4798 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
4799 err = nl80211_parse_he_obss_pd(
4800 info->attrs[NL80211_ATTR_HE_OBSS_PD],
4801 ¶ms.he_obss_pd);
4806 nl80211_calculate_ap_params(¶ms);
4808 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
4809 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
4812 err = rdev_start_ap(rdev, dev, ¶ms);
4814 wdev->preset_chandef = params.chandef;
4815 wdev->beacon_interval = params.beacon_interval;
4816 wdev->chandef = params.chandef;
4817 wdev->ssid_len = params.ssid_len;
4818 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
4820 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4821 wdev->conn_owner_nlportid = info->snd_portid;
4830 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4833 struct net_device *dev = info->user_ptr[1];
4834 struct wireless_dev *wdev = dev->ieee80211_ptr;
4835 struct cfg80211_beacon_data params;
4838 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4839 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4842 if (!rdev->ops->change_beacon)
4845 if (!wdev->beacon_interval)
4848 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms);
4853 err = rdev_change_beacon(rdev, dev, ¶ms);
4859 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
4861 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4862 struct net_device *dev = info->user_ptr[1];
4864 return cfg80211_stop_ap(rdev, dev, false);
4867 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4868 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4869 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4870 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
4871 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
4872 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
4873 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
4876 static int parse_station_flags(struct genl_info *info,
4877 enum nl80211_iftype iftype,
4878 struct station_parameters *params)
4880 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
4885 * Try parsing the new attribute first so userspace
4886 * can specify both for older kernels.
4888 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4890 struct nl80211_sta_flag_update *sta_flags;
4892 sta_flags = nla_data(nla);
4893 params->sta_flags_mask = sta_flags->mask;
4894 params->sta_flags_set = sta_flags->set;
4895 params->sta_flags_set &= params->sta_flags_mask;
4896 if ((params->sta_flags_mask |
4897 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4902 /* if present, parse the old attribute */
4904 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
4908 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
4912 * Only allow certain flags for interface types so that
4913 * other attributes are silently ignored. Remember that
4914 * this is backward compatibility code with old userspace
4915 * and shouldn't be hit in other cases anyway.
4918 case NL80211_IFTYPE_AP:
4919 case NL80211_IFTYPE_AP_VLAN:
4920 case NL80211_IFTYPE_P2P_GO:
4921 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4922 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4923 BIT(NL80211_STA_FLAG_WME) |
4924 BIT(NL80211_STA_FLAG_MFP);
4926 case NL80211_IFTYPE_P2P_CLIENT:
4927 case NL80211_IFTYPE_STATION:
4928 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4929 BIT(NL80211_STA_FLAG_TDLS_PEER);
4931 case NL80211_IFTYPE_MESH_POINT:
4932 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4933 BIT(NL80211_STA_FLAG_MFP) |
4934 BIT(NL80211_STA_FLAG_AUTHORIZED);
4940 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4942 params->sta_flags_set |= (1<<flag);
4944 /* no longer support new API additions in old API */
4945 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4953 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
4955 struct nlattr *rate;
4958 enum nl80211_rate_info rate_flg;
4960 rate = nla_nest_start_noflag(msg, attr);
4964 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4965 bitrate = cfg80211_calculate_bitrate(info);
4966 /* report 16-bit bitrate only if we can */
4967 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
4969 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4971 if (bitrate_compat > 0 &&
4972 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4976 case RATE_INFO_BW_5:
4977 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4979 case RATE_INFO_BW_10:
4980 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4985 case RATE_INFO_BW_20:
4988 case RATE_INFO_BW_40:
4989 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4991 case RATE_INFO_BW_80:
4992 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4994 case RATE_INFO_BW_160:
4995 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4997 case RATE_INFO_BW_HE_RU:
4999 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
5002 if (rate_flg && nla_put_flag(msg, rate_flg))
5005 if (info->flags & RATE_INFO_FLAGS_MCS) {
5006 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
5008 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5009 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5011 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
5012 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
5014 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
5016 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5017 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5019 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
5020 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
5022 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
5024 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
5026 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
5028 if (info->bw == RATE_INFO_BW_HE_RU &&
5029 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
5034 nla_nest_end(msg, rate);
5038 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
5047 attr = nla_nest_start_noflag(msg, id);
5051 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
5052 if (!(mask & BIT(i)))
5055 if (nla_put_u8(msg, i, signal[i]))
5059 nla_nest_end(msg, attr);
5064 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
5066 struct cfg80211_registered_device *rdev,
5067 struct net_device *dev,
5068 const u8 *mac_addr, struct station_info *sinfo)
5071 struct nlattr *sinfoattr, *bss_param;
5073 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
5075 cfg80211_sinfo_release_content(sinfo);
5079 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5080 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
5081 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
5082 goto nla_put_failure;
5084 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
5086 goto nla_put_failure;
5088 #define PUT_SINFO(attr, memb, type) do { \
5089 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
5090 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5091 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5093 goto nla_put_failure; \
5095 #define PUT_SINFO_U64(attr, memb) do { \
5096 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5097 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5098 sinfo->memb, NL80211_STA_INFO_PAD)) \
5099 goto nla_put_failure; \
5102 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5103 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
5104 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
5106 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5107 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
5108 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
5109 (u32)sinfo->rx_bytes))
5110 goto nla_put_failure;
5112 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5113 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
5114 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5115 (u32)sinfo->tx_bytes))
5116 goto nla_put_failure;
5118 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5119 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
5120 PUT_SINFO(LLID, llid, u16);
5121 PUT_SINFO(PLID, plid, u16);
5122 PUT_SINFO(PLINK_STATE, plink_state, u8);
5123 PUT_SINFO_U64(RX_DURATION, rx_duration);
5124 PUT_SINFO_U64(TX_DURATION, tx_duration);
5126 if (wiphy_ext_feature_isset(&rdev->wiphy,
5127 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5128 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
5130 switch (rdev->wiphy.signal_type) {
5131 case CFG80211_SIGNAL_TYPE_MBM:
5132 PUT_SINFO(SIGNAL, signal, u8);
5133 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
5138 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
5139 if (!nl80211_put_signal(msg, sinfo->chains,
5140 sinfo->chain_signal,
5141 NL80211_STA_INFO_CHAIN_SIGNAL))
5142 goto nla_put_failure;
5144 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
5145 if (!nl80211_put_signal(msg, sinfo->chains,
5146 sinfo->chain_signal_avg,
5147 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
5148 goto nla_put_failure;
5150 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
5151 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5152 NL80211_STA_INFO_TX_BITRATE))
5153 goto nla_put_failure;
5155 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
5156 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5157 NL80211_STA_INFO_RX_BITRATE))
5158 goto nla_put_failure;
5161 PUT_SINFO(RX_PACKETS, rx_packets, u32);
5162 PUT_SINFO(TX_PACKETS, tx_packets, u32);
5163 PUT_SINFO(TX_RETRIES, tx_retries, u32);
5164 PUT_SINFO(TX_FAILED, tx_failed, u32);
5165 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
5166 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
5167 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
5168 PUT_SINFO(LOCAL_PM, local_pm, u32);
5169 PUT_SINFO(PEER_PM, peer_pm, u32);
5170 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
5171 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
5173 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
5174 bss_param = nla_nest_start_noflag(msg,
5175 NL80211_STA_INFO_BSS_PARAM);
5177 goto nla_put_failure;
5179 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5180 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5181 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5182 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5183 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5184 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5185 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5186 sinfo->bss_param.dtim_period) ||
5187 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5188 sinfo->bss_param.beacon_interval))
5189 goto nla_put_failure;
5191 nla_nest_end(msg, bss_param);
5193 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
5194 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5195 sizeof(struct nl80211_sta_flag_update),
5197 goto nla_put_failure;
5199 PUT_SINFO_U64(T_OFFSET, t_offset);
5200 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5201 PUT_SINFO_U64(BEACON_RX, rx_beacon);
5202 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
5203 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5204 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
5205 if (wiphy_ext_feature_isset(&rdev->wiphy,
5206 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5207 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5208 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5212 #undef PUT_SINFO_U64
5214 if (sinfo->pertid) {
5215 struct nlattr *tidsattr;
5218 tidsattr = nla_nest_start_noflag(msg,
5219 NL80211_STA_INFO_TID_STATS);
5221 goto nla_put_failure;
5223 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5224 struct cfg80211_tid_stats *tidstats;
5225 struct nlattr *tidattr;
5227 tidstats = &sinfo->pertid[tid];
5229 if (!tidstats->filled)
5232 tidattr = nla_nest_start_noflag(msg, tid + 1);
5234 goto nla_put_failure;
5236 #define PUT_TIDVAL_U64(attr, memb) do { \
5237 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
5238 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5239 tidstats->memb, NL80211_TID_STATS_PAD)) \
5240 goto nla_put_failure; \
5243 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5244 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5245 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5246 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
5248 #undef PUT_TIDVAL_U64
5249 if ((tidstats->filled &
5250 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5251 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5252 NL80211_TID_STATS_TXQ_STATS))
5253 goto nla_put_failure;
5255 nla_nest_end(msg, tidattr);
5258 nla_nest_end(msg, tidsattr);
5261 nla_nest_end(msg, sinfoattr);
5263 if (sinfo->assoc_req_ies_len &&
5264 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5265 sinfo->assoc_req_ies))
5266 goto nla_put_failure;
5268 cfg80211_sinfo_release_content(sinfo);
5269 genlmsg_end(msg, hdr);
5273 cfg80211_sinfo_release_content(sinfo);
5274 genlmsg_cancel(msg, hdr);
5278 static int nl80211_dump_station(struct sk_buff *skb,
5279 struct netlink_callback *cb)
5281 struct station_info sinfo;
5282 struct cfg80211_registered_device *rdev;
5283 struct wireless_dev *wdev;
5284 u8 mac_addr[ETH_ALEN];
5285 int sta_idx = cb->args[2];
5289 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
5293 if (!wdev->netdev) {
5298 if (!rdev->ops->dump_station) {
5304 memset(&sinfo, 0, sizeof(sinfo));
5305 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
5312 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
5313 NETLINK_CB(cb->skb).portid,
5314 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5315 rdev, wdev->netdev, mac_addr,
5323 cb->args[2] = sta_idx;
5331 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5334 struct net_device *dev = info->user_ptr[1];
5335 struct station_info sinfo;
5336 struct sk_buff *msg;
5337 u8 *mac_addr = NULL;
5340 memset(&sinfo, 0, sizeof(sinfo));
5342 if (!info->attrs[NL80211_ATTR_MAC])
5345 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5347 if (!rdev->ops->get_station)
5350 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
5354 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5356 cfg80211_sinfo_release_content(&sinfo);
5360 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5361 info->snd_portid, info->snd_seq, 0,
5362 rdev, dev, mac_addr, &sinfo) < 0) {
5367 return genlmsg_reply(msg, info);
5370 int cfg80211_check_station_change(struct wiphy *wiphy,
5371 struct station_parameters *params,
5372 enum cfg80211_station_type statype)
5374 if (params->listen_interval != -1 &&
5375 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5378 if (params->support_p2p_ps != -1 &&
5379 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5383 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5384 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5387 /* When you run into this, adjust the code below for the new flag */
5388 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5391 case CFG80211_STA_MESH_PEER_KERNEL:
5392 case CFG80211_STA_MESH_PEER_USER:
5394 * No ignoring the TDLS flag here -- the userspace mesh
5395 * code doesn't have the bug of including TDLS in the
5398 if (params->sta_flags_mask &
5399 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5400 BIT(NL80211_STA_FLAG_MFP) |
5401 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5404 case CFG80211_STA_TDLS_PEER_SETUP:
5405 case CFG80211_STA_TDLS_PEER_ACTIVE:
5406 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5408 /* ignore since it can't change */
5409 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5412 /* disallow mesh-specific things */
5413 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5415 if (params->local_pm)
5417 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5421 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5422 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5423 /* TDLS can't be set, ... */
5424 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5427 * ... but don't bother the driver with it. This works around
5428 * a hostapd/wpa_supplicant issue -- it always includes the
5429 * TLDS_PEER flag in the mask even for AP mode.
5431 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5434 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5435 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
5436 /* reject other things that can't change */
5437 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5439 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5441 if (params->supported_rates)
5443 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5448 if (statype != CFG80211_STA_AP_CLIENT &&
5449 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
5455 case CFG80211_STA_AP_MLME_CLIENT:
5456 /* Use this only for authorizing/unauthorizing a station */
5457 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5460 case CFG80211_STA_AP_CLIENT:
5461 case CFG80211_STA_AP_CLIENT_UNASSOC:
5462 /* accept only the listed bits */
5463 if (params->sta_flags_mask &
5464 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5465 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5466 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5467 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5468 BIT(NL80211_STA_FLAG_WME) |
5469 BIT(NL80211_STA_FLAG_MFP)))
5472 /* but authenticated/associated only if driver handles it */
5473 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5474 params->sta_flags_mask &
5475 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5476 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5479 case CFG80211_STA_IBSS:
5480 case CFG80211_STA_AP_STA:
5481 /* reject any changes other than AUTHORIZED */
5482 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5485 case CFG80211_STA_TDLS_PEER_SETUP:
5486 /* reject any changes other than AUTHORIZED or WME */
5487 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5488 BIT(NL80211_STA_FLAG_WME)))
5490 /* force (at least) rates when authorizing */
5491 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5492 !params->supported_rates)
5495 case CFG80211_STA_TDLS_PEER_ACTIVE:
5496 /* reject any changes */
5498 case CFG80211_STA_MESH_PEER_KERNEL:
5499 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5502 case CFG80211_STA_MESH_PEER_USER:
5503 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5504 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
5510 * Older kernel versions ignored this attribute entirely, so don't
5511 * reject attempts to update it but mark it as unused instead so the
5512 * driver won't look at the data.
5514 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5515 statype != CFG80211_STA_TDLS_PEER_SETUP)
5516 params->opmode_notif_used = false;
5520 EXPORT_SYMBOL(cfg80211_check_station_change);
5523 * Get vlan interface making sure it is running and on the right wiphy.
5525 static struct net_device *get_vlan(struct genl_info *info,
5526 struct cfg80211_registered_device *rdev)
5528 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
5529 struct net_device *v;
5535 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5537 return ERR_PTR(-ENODEV);
5539 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5544 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5545 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5546 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5551 if (!netif_running(v)) {
5559 return ERR_PTR(ret);
5562 static const struct nla_policy
5563 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
5564 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5565 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5568 static int nl80211_parse_sta_wme(struct genl_info *info,
5569 struct station_parameters *params)
5571 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5575 /* parse WME attributes if present */
5576 if (!info->attrs[NL80211_ATTR_STA_WME])
5579 nla = info->attrs[NL80211_ATTR_STA_WME];
5580 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5581 nl80211_sta_wme_policy,
5586 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5587 params->uapsd_queues = nla_get_u8(
5588 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5589 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5592 if (tb[NL80211_STA_WME_MAX_SP])
5593 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5595 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5598 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5603 static int nl80211_parse_sta_channel_info(struct genl_info *info,
5604 struct station_parameters *params)
5606 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5607 params->supported_channels =
5608 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5609 params->supported_channels_len =
5610 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5612 * Need to include at least one (first channel, number of
5613 * channels) tuple for each subband, and must have proper
5614 * tuples for the rest of the data as well.
5616 if (params->supported_channels_len < 2)
5618 if (params->supported_channels_len % 2)
5622 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5623 params->supported_oper_classes =
5624 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5625 params->supported_oper_classes_len =
5626 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5628 * The value of the Length field of the Supported Operating
5629 * Classes element is between 2 and 253.
5631 if (params->supported_oper_classes_len < 2 ||
5632 params->supported_oper_classes_len > 253)
5638 static int nl80211_set_station_tdls(struct genl_info *info,
5639 struct station_parameters *params)
5642 /* Dummy STA entry gets updated once the peer capabilities are known */
5643 if (info->attrs[NL80211_ATTR_PEER_AID])
5644 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
5645 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5647 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5648 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5650 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5651 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5653 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5654 params->he_capa_len =
5655 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5657 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5661 err = nl80211_parse_sta_channel_info(info, params);
5665 return nl80211_parse_sta_wme(info, params);
5668 static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5669 struct station_parameters *params)
5671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5674 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5675 if (!rdev->ops->set_tx_power ||
5676 !wiphy_ext_feature_isset(&rdev->wiphy,
5677 NL80211_EXT_FEATURE_STA_TX_PWR))
5680 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5681 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5683 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5684 idx = NL80211_ATTR_STA_TX_POWER;
5686 if (info->attrs[idx])
5687 params->txpwr.power =
5688 nla_get_s16(info->attrs[idx]);
5692 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5698 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5701 struct net_device *dev = info->user_ptr[1];
5702 struct station_parameters params;
5706 memset(¶ms, 0, sizeof(params));
5708 if (!rdev->ops->change_station)
5712 * AID and listen_interval properties can be set only for unassociated
5713 * station. Include these parameters here and will check them in
5714 * cfg80211_check_station_change().
5716 if (info->attrs[NL80211_ATTR_STA_AID])
5717 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
5719 if (info->attrs[NL80211_ATTR_VLAN_ID])
5720 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
5722 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5723 params.listen_interval =
5724 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5726 params.listen_interval = -1;
5728 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5729 params.support_p2p_ps =
5730 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5732 params.support_p2p_ps = -1;
5734 if (!info->attrs[NL80211_ATTR_MAC])
5737 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5739 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5740 params.supported_rates =
5741 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5742 params.supported_rates_len =
5743 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5746 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5748 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5749 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5752 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5754 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5755 params.ext_capab_len =
5756 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5759 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
5762 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
5763 params.plink_action =
5764 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5766 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
5767 params.plink_state =
5768 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
5769 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
5770 params.peer_aid = nla_get_u16(
5771 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
5772 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5775 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5776 params.local_pm = nla_get_u32(
5777 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5779 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5780 params.opmode_notif_used = true;
5781 params.opmode_notif =
5782 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5785 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5786 params.airtime_weight =
5787 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5789 if (params.airtime_weight &&
5790 !wiphy_ext_feature_isset(&rdev->wiphy,
5791 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5794 err = nl80211_parse_sta_txpower_setting(info, ¶ms);
5798 /* Include parameters for TDLS peer (will check later) */
5799 err = nl80211_set_station_tdls(info, ¶ms);
5803 params.vlan = get_vlan(info, rdev);
5804 if (IS_ERR(params.vlan))
5805 return PTR_ERR(params.vlan);
5807 switch (dev->ieee80211_ptr->iftype) {
5808 case NL80211_IFTYPE_AP:
5809 case NL80211_IFTYPE_AP_VLAN:
5810 case NL80211_IFTYPE_P2P_GO:
5811 case NL80211_IFTYPE_P2P_CLIENT:
5812 case NL80211_IFTYPE_STATION:
5813 case NL80211_IFTYPE_ADHOC:
5814 case NL80211_IFTYPE_MESH_POINT:
5821 /* driver will call cfg80211_check_station_change() */
5822 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
5826 dev_put(params.vlan);
5831 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5835 struct net_device *dev = info->user_ptr[1];
5836 struct station_parameters params;
5837 u8 *mac_addr = NULL;
5838 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5839 BIT(NL80211_STA_FLAG_ASSOCIATED);
5841 memset(¶ms, 0, sizeof(params));
5843 if (!rdev->ops->add_station)
5846 if (!info->attrs[NL80211_ATTR_MAC])
5849 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5852 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5855 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5856 !info->attrs[NL80211_ATTR_PEER_AID])
5859 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5860 params.supported_rates =
5861 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5862 params.supported_rates_len =
5863 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5864 params.listen_interval =
5865 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5867 if (info->attrs[NL80211_ATTR_VLAN_ID])
5868 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
5870 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5871 params.support_p2p_ps =
5872 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5875 * if not specified, assume it's supported for P2P GO interface,
5876 * and is NOT supported for AP interface
5878 params.support_p2p_ps =
5879 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5882 if (info->attrs[NL80211_ATTR_PEER_AID])
5883 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
5885 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
5887 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5889 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5890 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5893 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5895 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5896 params.ext_capab_len =
5897 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5900 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5902 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5904 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5906 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5908 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5910 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5911 params.he_capa_len =
5912 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5914 /* max len is validated in nla policy */
5915 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5919 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5920 params.opmode_notif_used = true;
5921 params.opmode_notif =
5922 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5925 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
5926 params.plink_action =
5927 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5929 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5930 params.airtime_weight =
5931 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5933 if (params.airtime_weight &&
5934 !wiphy_ext_feature_isset(&rdev->wiphy,
5935 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5938 err = nl80211_parse_sta_txpower_setting(info, ¶ms);
5942 err = nl80211_parse_sta_channel_info(info, ¶ms);
5946 err = nl80211_parse_sta_wme(info, ¶ms);
5950 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
5953 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5954 * as userspace might just pass through the capabilities from the IEs
5955 * directly, rather than enforcing this restriction and returning an
5956 * error in this case.
5958 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5959 params.ht_capa = NULL;
5960 params.vht_capa = NULL;
5962 /* HE requires WME */
5963 if (params.he_capa_len)
5967 /* When you run into this, adjust the code below for the new flag */
5968 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5970 switch (dev->ieee80211_ptr->iftype) {
5971 case NL80211_IFTYPE_AP:
5972 case NL80211_IFTYPE_AP_VLAN:
5973 case NL80211_IFTYPE_P2P_GO:
5974 /* ignore WME attributes if iface/sta is not capable */
5975 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5976 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5977 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5979 /* TDLS peers cannot be added */
5980 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5981 info->attrs[NL80211_ATTR_PEER_AID])
5983 /* but don't bother the driver with it */
5984 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5986 /* allow authenticated/associated only if driver handles it */
5987 if (!(rdev->wiphy.features &
5988 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5989 params.sta_flags_mask & auth_assoc)
5992 /* Older userspace, or userspace wanting to be compatible with
5993 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5994 * and assoc flags in the mask, but assumes the station will be
5995 * added as associated anyway since this was the required driver
5996 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5998 * In order to not bother drivers with this quirk in the API
5999 * set the flags in both the mask and set for new stations in
6002 if (!(params.sta_flags_mask & auth_assoc)) {
6003 params.sta_flags_mask |= auth_assoc;
6004 params.sta_flags_set |= auth_assoc;
6007 /* must be last in here for error handling */
6008 params.vlan = get_vlan(info, rdev);
6009 if (IS_ERR(params.vlan))
6010 return PTR_ERR(params.vlan);
6012 case NL80211_IFTYPE_MESH_POINT:
6013 /* ignore uAPSD data */
6014 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6016 /* associated is disallowed */
6017 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
6019 /* TDLS peers cannot be added */
6020 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6021 info->attrs[NL80211_ATTR_PEER_AID])
6024 case NL80211_IFTYPE_STATION:
6025 case NL80211_IFTYPE_P2P_CLIENT:
6026 /* ignore uAPSD data */
6027 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6029 /* these are disallowed */
6030 if (params.sta_flags_mask &
6031 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
6032 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
6034 /* Only TDLS peers can be added */
6035 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6037 /* Can only add if TDLS ... */
6038 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
6040 /* ... with external setup is supported */
6041 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
6044 * Older wpa_supplicant versions always mark the TDLS peer
6045 * as authorized, but it shouldn't yet be.
6047 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
6053 /* be aware of params.vlan when changing code here */
6055 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
6058 dev_put(params.vlan);
6062 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
6064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6065 struct net_device *dev = info->user_ptr[1];
6066 struct station_del_parameters params;
6068 memset(¶ms, 0, sizeof(params));
6070 if (info->attrs[NL80211_ATTR_MAC])
6071 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
6073 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6074 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6075 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
6076 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6079 if (!rdev->ops->del_station)
6082 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
6084 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
6085 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
6086 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
6089 /* Default to Deauthentication frame */
6090 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
6093 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
6094 params.reason_code =
6095 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6096 if (params.reason_code == 0)
6097 return -EINVAL; /* 0 is reserved */
6099 /* Default to reason code 2 */
6100 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
6103 return rdev_del_station(rdev, dev, ¶ms);
6106 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
6107 int flags, struct net_device *dev,
6108 u8 *dst, u8 *next_hop,
6109 struct mpath_info *pinfo)
6112 struct nlattr *pinfoattr;
6114 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
6118 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6119 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
6120 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
6121 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
6122 goto nla_put_failure;
6124 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
6126 goto nla_put_failure;
6127 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
6128 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
6130 goto nla_put_failure;
6131 if (((pinfo->filled & MPATH_INFO_SN) &&
6132 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
6133 ((pinfo->filled & MPATH_INFO_METRIC) &&
6134 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
6136 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
6137 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
6139 ((pinfo->filled & MPATH_INFO_FLAGS) &&
6140 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
6142 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
6143 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
6144 pinfo->discovery_timeout)) ||
6145 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
6146 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
6147 pinfo->discovery_retries)) ||
6148 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6149 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
6150 pinfo->hop_count)) ||
6151 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
6152 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
6153 pinfo->path_change_count)))
6154 goto nla_put_failure;
6156 nla_nest_end(msg, pinfoattr);
6158 genlmsg_end(msg, hdr);
6162 genlmsg_cancel(msg, hdr);
6166 static int nl80211_dump_mpath(struct sk_buff *skb,
6167 struct netlink_callback *cb)
6169 struct mpath_info pinfo;
6170 struct cfg80211_registered_device *rdev;
6171 struct wireless_dev *wdev;
6173 u8 next_hop[ETH_ALEN];
6174 int path_idx = cb->args[2];
6178 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
6182 if (!rdev->ops->dump_mpath) {
6187 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6193 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
6200 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6201 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6202 wdev->netdev, dst, next_hop,
6210 cb->args[2] = path_idx;
6217 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6221 struct net_device *dev = info->user_ptr[1];
6222 struct mpath_info pinfo;
6223 struct sk_buff *msg;
6225 u8 next_hop[ETH_ALEN];
6227 memset(&pinfo, 0, sizeof(pinfo));
6229 if (!info->attrs[NL80211_ATTR_MAC])
6232 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6234 if (!rdev->ops->get_mpath)
6237 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6240 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
6244 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6248 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6249 dev, dst, next_hop, &pinfo) < 0) {
6254 return genlmsg_reply(msg, info);
6257 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6260 struct net_device *dev = info->user_ptr[1];
6262 u8 *next_hop = NULL;
6264 if (!info->attrs[NL80211_ATTR_MAC])
6267 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6270 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6271 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6273 if (!rdev->ops->change_mpath)
6276 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6279 return rdev_change_mpath(rdev, dev, dst, next_hop);
6282 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6285 struct net_device *dev = info->user_ptr[1];
6287 u8 *next_hop = NULL;
6289 if (!info->attrs[NL80211_ATTR_MAC])
6292 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6295 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6296 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6298 if (!rdev->ops->add_mpath)
6301 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6304 return rdev_add_mpath(rdev, dev, dst, next_hop);
6307 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6310 struct net_device *dev = info->user_ptr[1];
6313 if (info->attrs[NL80211_ATTR_MAC])
6314 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6316 if (!rdev->ops->del_mpath)
6319 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6322 return rdev_del_mpath(rdev, dev, dst);
6325 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6329 struct net_device *dev = info->user_ptr[1];
6330 struct mpath_info pinfo;
6331 struct sk_buff *msg;
6335 memset(&pinfo, 0, sizeof(pinfo));
6337 if (!info->attrs[NL80211_ATTR_MAC])
6340 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6342 if (!rdev->ops->get_mpp)
6345 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6348 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6352 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6356 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6357 dev, dst, mpp, &pinfo) < 0) {
6362 return genlmsg_reply(msg, info);
6365 static int nl80211_dump_mpp(struct sk_buff *skb,
6366 struct netlink_callback *cb)
6368 struct mpath_info pinfo;
6369 struct cfg80211_registered_device *rdev;
6370 struct wireless_dev *wdev;
6373 int path_idx = cb->args[2];
6377 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
6381 if (!rdev->ops->dump_mpp) {
6386 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6392 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6399 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6400 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6401 wdev->netdev, dst, mpp,
6409 cb->args[2] = path_idx;
6416 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6418 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6419 struct net_device *dev = info->user_ptr[1];
6420 struct wireless_dev *wdev = dev->ieee80211_ptr;
6421 struct bss_parameters params;
6424 memset(¶ms, 0, sizeof(params));
6425 /* default to not changing parameters */
6426 params.use_cts_prot = -1;
6427 params.use_short_preamble = -1;
6428 params.use_short_slot_time = -1;
6429 params.ap_isolate = -1;
6430 params.ht_opmode = -1;
6431 params.p2p_ctwindow = -1;
6432 params.p2p_opp_ps = -1;
6434 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6435 params.use_cts_prot =
6436 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6437 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6438 params.use_short_preamble =
6439 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6440 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6441 params.use_short_slot_time =
6442 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
6443 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6444 params.basic_rates =
6445 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6446 params.basic_rates_len =
6447 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6449 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6450 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
6451 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6453 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
6455 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6456 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6458 params.p2p_ctwindow =
6459 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
6460 if (params.p2p_ctwindow != 0 &&
6461 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6465 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6468 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6470 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
6471 params.p2p_opp_ps = tmp;
6472 if (params.p2p_opp_ps &&
6473 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6477 if (!rdev->ops->change_bss)
6480 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6481 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6485 err = rdev_change_bss(rdev, dev, ¶ms);
6491 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6495 enum nl80211_user_reg_hint_type user_reg_hint_type;
6499 * You should only get this when cfg80211 hasn't yet initialized
6500 * completely when built-in to the kernel right between the time
6501 * window between nl80211_init() and regulatory_init(), if that is
6504 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
6505 return -EINPROGRESS;
6507 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6508 user_reg_hint_type =
6509 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6511 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6513 switch (user_reg_hint_type) {
6514 case NL80211_USER_REG_HINT_USER:
6515 case NL80211_USER_REG_HINT_CELL_BASE:
6516 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6519 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6520 return regulatory_hint_user(data, user_reg_hint_type);
6521 case NL80211_USER_REG_HINT_INDOOR:
6522 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6523 owner_nlportid = info->snd_portid;
6524 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6530 return regulatory_hint_indoor(is_indoor, owner_nlportid);
6536 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6538 return reg_reload_regdb();
6541 static int nl80211_get_mesh_config(struct sk_buff *skb,
6542 struct genl_info *info)
6544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6545 struct net_device *dev = info->user_ptr[1];
6546 struct wireless_dev *wdev = dev->ieee80211_ptr;
6547 struct mesh_config cur_params;
6550 struct nlattr *pinfoattr;
6551 struct sk_buff *msg;
6553 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6556 if (!rdev->ops->get_mesh_config)
6560 /* If not connected, get default parameters */
6561 if (!wdev->mesh_id_len)
6562 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6564 err = rdev_get_mesh_config(rdev, dev, &cur_params);
6570 /* Draw up a netlink message to send back */
6571 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6574 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6575 NL80211_CMD_GET_MESH_CONFIG);
6578 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
6580 goto nla_put_failure;
6581 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6582 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6583 cur_params.dot11MeshRetryTimeout) ||
6584 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6585 cur_params.dot11MeshConfirmTimeout) ||
6586 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6587 cur_params.dot11MeshHoldingTimeout) ||
6588 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6589 cur_params.dot11MeshMaxPeerLinks) ||
6590 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6591 cur_params.dot11MeshMaxRetries) ||
6592 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6593 cur_params.dot11MeshTTL) ||
6594 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6595 cur_params.element_ttl) ||
6596 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6597 cur_params.auto_open_plinks) ||
6598 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6599 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
6600 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6601 cur_params.dot11MeshHWMPmaxPREQretries) ||
6602 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6603 cur_params.path_refresh_time) ||
6604 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6605 cur_params.min_discovery_timeout) ||
6606 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6607 cur_params.dot11MeshHWMPactivePathTimeout) ||
6608 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6609 cur_params.dot11MeshHWMPpreqMinInterval) ||
6610 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6611 cur_params.dot11MeshHWMPperrMinInterval) ||
6612 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6613 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6614 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6615 cur_params.dot11MeshHWMPRootMode) ||
6616 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6617 cur_params.dot11MeshHWMPRannInterval) ||
6618 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6619 cur_params.dot11MeshGateAnnouncementProtocol) ||
6620 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6621 cur_params.dot11MeshForwarding) ||
6622 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
6623 cur_params.rssi_threshold) ||
6624 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
6625 cur_params.ht_opmode) ||
6626 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6627 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6628 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6629 cur_params.dot11MeshHWMProotInterval) ||
6630 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
6631 cur_params.dot11MeshHWMPconfirmationInterval) ||
6632 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6633 cur_params.power_mode) ||
6634 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
6635 cur_params.dot11MeshAwakeWindowDuration) ||
6636 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
6637 cur_params.plink_timeout) ||
6638 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6639 cur_params.dot11MeshConnectedToMeshGate))
6640 goto nla_put_failure;
6641 nla_nest_end(msg, pinfoattr);
6642 genlmsg_end(msg, hdr);
6643 return genlmsg_reply(msg, info);
6651 static const struct nla_policy
6652 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6653 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6654 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6655 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6656 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6657 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6658 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6659 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6660 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6661 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6662 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6663 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6664 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6665 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6666 NLA_POLICY_RANGE(NLA_U32, 1, 255),
6667 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6668 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
6669 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
6670 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
6671 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6672 NLA_POLICY_MIN(NLA_U16, 1),
6673 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6674 NLA_POLICY_MIN(NLA_U16, 1),
6675 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6676 NLA_POLICY_MIN(NLA_U16, 1),
6677 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6678 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6679 NLA_POLICY_MIN(NLA_U16, 1),
6680 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6681 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6682 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6683 NLA_POLICY_RANGE(NLA_S32, -255, 0),
6684 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
6685 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
6686 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6687 NLA_POLICY_MIN(NLA_U16, 1),
6688 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6689 NLA_POLICY_MIN(NLA_U16, 1),
6690 [NL80211_MESHCONF_POWER_MODE] =
6691 NLA_POLICY_RANGE(NLA_U32,
6692 NL80211_MESH_POWER_ACTIVE,
6693 NL80211_MESH_POWER_MAX),
6694 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
6695 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
6696 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
6699 static const struct nla_policy
6700 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
6701 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
6702 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6703 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
6704 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
6705 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
6706 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
6707 [NL80211_MESH_SETUP_IE] =
6708 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6709 IEEE80211_MAX_DATA_LEN),
6710 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
6713 static int nl80211_parse_mesh_config(struct genl_info *info,
6714 struct mesh_config *cfg,
6717 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
6721 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6724 cfg->param = fn(tb[attr]); \
6725 mask |= BIT((attr) - 1); \
6729 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
6731 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
6734 /* This makes sure that there aren't more than 32 mesh config
6735 * parameters (otherwise our bitfield scheme would not work.) */
6736 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6738 /* Fill in the params struct */
6739 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6740 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6742 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6744 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6745 NL80211_MESHCONF_HOLDING_TIMEOUT,
6747 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6748 NL80211_MESHCONF_MAX_PEER_LINKS,
6750 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6751 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6752 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6753 NL80211_MESHCONF_TTL, nla_get_u8);
6754 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6755 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6756 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6757 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6759 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
6761 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6763 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6764 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6766 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6767 NL80211_MESHCONF_PATH_REFRESH_TIME,
6769 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6770 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6772 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6773 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6775 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
6777 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6779 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6780 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6781 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6783 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
6784 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6786 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
6787 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6789 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
6790 dot11MeshHWMPnetDiameterTraversalTime, mask,
6791 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6793 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6794 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6795 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6796 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6798 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
6799 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6801 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6802 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6803 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6804 NL80211_MESHCONF_RSSI_THRESHOLD,
6806 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6807 NL80211_MESHCONF_CONNECTED_TO_GATE,
6810 * Check HT operation mode based on
6811 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
6813 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6814 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6816 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6817 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6818 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6821 /* NON_HT_STA bit is reserved, but some programs set it */
6822 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
6824 cfg->ht_opmode = ht_opmode;
6825 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
6827 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
6828 dot11MeshHWMPactivePathToRootTimeout, mask,
6829 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6831 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
6832 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
6833 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
6835 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
6836 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6838 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
6840 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
6842 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
6843 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
6844 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
6845 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
6846 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
6847 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
6853 #undef FILL_IN_MESH_PARAM_IF_SET
6856 static int nl80211_parse_mesh_setup(struct genl_info *info,
6857 struct mesh_setup *setup)
6859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6860 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6862 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6864 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack))
6867 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6868 setup->sync_method =
6869 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6870 IEEE80211_SYNC_METHOD_VENDOR :
6871 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6873 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6874 setup->path_sel_proto =
6875 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6876 IEEE80211_PATH_PROTOCOL_VENDOR :
6877 IEEE80211_PATH_PROTOCOL_HWMP;
6879 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6880 setup->path_metric =
6881 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6882 IEEE80211_PATH_METRIC_VENDOR :
6883 IEEE80211_PATH_METRIC_AIRTIME;
6885 if (tb[NL80211_MESH_SETUP_IE]) {
6886 struct nlattr *ieattr =
6887 tb[NL80211_MESH_SETUP_IE];
6888 setup->ie = nla_data(ieattr);
6889 setup->ie_len = nla_len(ieattr);
6891 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6892 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6894 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
6895 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6896 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
6897 if (setup->is_secure)
6898 setup->user_mpm = true;
6900 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6901 if (!setup->user_mpm)
6904 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6910 static int nl80211_update_mesh_config(struct sk_buff *skb,
6911 struct genl_info *info)
6913 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6914 struct net_device *dev = info->user_ptr[1];
6915 struct wireless_dev *wdev = dev->ieee80211_ptr;
6916 struct mesh_config cfg;
6920 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6923 if (!rdev->ops->update_mesh_config)
6926 err = nl80211_parse_mesh_config(info, &cfg, &mask);
6931 if (!wdev->mesh_id_len)
6935 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
6942 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6943 struct sk_buff *msg)
6945 struct nlattr *nl_reg_rules;
6948 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6949 (regdom->dfs_region &&
6950 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
6951 goto nla_put_failure;
6953 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
6955 goto nla_put_failure;
6957 for (i = 0; i < regdom->n_reg_rules; i++) {
6958 struct nlattr *nl_reg_rule;
6959 const struct ieee80211_reg_rule *reg_rule;
6960 const struct ieee80211_freq_range *freq_range;
6961 const struct ieee80211_power_rule *power_rule;
6962 unsigned int max_bandwidth_khz;
6964 reg_rule = ®dom->reg_rules[i];
6965 freq_range = ®_rule->freq_range;
6966 power_rule = ®_rule->power_rule;
6968 nl_reg_rule = nla_nest_start_noflag(msg, i);
6970 goto nla_put_failure;
6972 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6973 if (!max_bandwidth_khz)
6974 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6977 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6979 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6980 freq_range->start_freq_khz) ||
6981 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6982 freq_range->end_freq_khz) ||
6983 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
6984 max_bandwidth_khz) ||
6985 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6986 power_rule->max_antenna_gain) ||
6987 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
6988 power_rule->max_eirp) ||
6989 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6990 reg_rule->dfs_cac_ms))
6991 goto nla_put_failure;
6993 nla_nest_end(msg, nl_reg_rule);
6996 nla_nest_end(msg, nl_reg_rules);
7003 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
7005 const struct ieee80211_regdomain *regdom = NULL;
7006 struct cfg80211_registered_device *rdev;
7007 struct wiphy *wiphy = NULL;
7008 struct sk_buff *msg;
7011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7015 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7016 NL80211_CMD_GET_REG);
7020 if (info->attrs[NL80211_ATTR_WIPHY]) {
7023 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7026 return PTR_ERR(rdev);
7029 wiphy = &rdev->wiphy;
7030 self_managed = wiphy->regulatory_flags &
7031 REGULATORY_WIPHY_SELF_MANAGED;
7032 regdom = get_wiphy_regdom(wiphy);
7034 /* a self-managed-reg device must have a private regdom */
7035 if (WARN_ON(!regdom && self_managed)) {
7041 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7042 goto nla_put_failure;
7045 if (!wiphy && reg_last_request_cell_base() &&
7046 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7047 NL80211_USER_REG_HINT_CELL_BASE))
7048 goto nla_put_failure;
7053 regdom = rcu_dereference(cfg80211_regdomain);
7055 if (nl80211_put_regdom(regdom, msg))
7056 goto nla_put_failure_rcu;
7060 genlmsg_end(msg, hdr);
7061 return genlmsg_reply(msg, info);
7063 nla_put_failure_rcu:
7071 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
7072 u32 seq, int flags, struct wiphy *wiphy,
7073 const struct ieee80211_regdomain *regdom)
7075 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
7076 NL80211_CMD_GET_REG);
7081 genl_dump_check_consistent(cb, hdr);
7083 if (nl80211_put_regdom(regdom, msg))
7084 goto nla_put_failure;
7086 if (!wiphy && reg_last_request_cell_base() &&
7087 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7088 NL80211_USER_REG_HINT_CELL_BASE))
7089 goto nla_put_failure;
7092 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7093 goto nla_put_failure;
7095 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
7096 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
7097 goto nla_put_failure;
7099 genlmsg_end(msg, hdr);
7103 genlmsg_cancel(msg, hdr);
7107 static int nl80211_get_reg_dump(struct sk_buff *skb,
7108 struct netlink_callback *cb)
7110 const struct ieee80211_regdomain *regdom = NULL;
7111 struct cfg80211_registered_device *rdev;
7112 int err, reg_idx, start = cb->args[2];
7116 if (cfg80211_regdomain && start == 0) {
7117 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7119 rtnl_dereference(cfg80211_regdomain));
7124 /* the global regdom is idx 0 */
7126 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7127 regdom = get_wiphy_regdom(&rdev->wiphy);
7131 if (++reg_idx <= start)
7134 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7135 NLM_F_MULTI, &rdev->wiphy, regdom);
7142 cb->args[2] = reg_idx;
7149 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
7150 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
7151 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
7152 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
7153 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
7154 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
7155 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
7156 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
7157 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
7160 static int parse_reg_rule(struct nlattr *tb[],
7161 struct ieee80211_reg_rule *reg_rule)
7163 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
7164 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
7166 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
7168 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
7170 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
7172 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
7174 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
7177 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
7179 freq_range->start_freq_khz =
7180 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
7181 freq_range->end_freq_khz =
7182 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7183 freq_range->max_bandwidth_khz =
7184 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7186 power_rule->max_eirp =
7187 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7189 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7190 power_rule->max_antenna_gain =
7191 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7193 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7194 reg_rule->dfs_cac_ms =
7195 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7200 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7202 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7203 struct nlattr *nl_reg_rule;
7205 int rem_reg_rules, r;
7206 u32 num_rules = 0, rule_idx = 0;
7207 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
7208 struct ieee80211_regdomain *rd;
7210 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7213 if (!info->attrs[NL80211_ATTR_REG_RULES])
7216 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7218 if (info->attrs[NL80211_ATTR_DFS_REGION])
7219 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7221 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
7224 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
7228 if (!reg_is_valid_request(alpha2))
7231 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
7235 rd->n_reg_rules = num_rules;
7236 rd->alpha2[0] = alpha2[0];
7237 rd->alpha2[1] = alpha2[1];
7240 * Disable DFS master mode if the DFS region was
7241 * not supported or known on this kernel.
7243 if (reg_supported_dfs_region(dfs_region))
7244 rd->dfs_region = dfs_region;
7246 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
7248 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7249 nl_reg_rule, reg_rule_policy,
7253 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7259 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7265 /* set_regdom takes ownership of rd */
7266 return set_regdom(rd, REGD_SOURCE_CRDA);
7271 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
7273 static int validate_scan_freqs(struct nlattr *freqs)
7275 struct nlattr *attr1, *attr2;
7276 int n_channels = 0, tmp1, tmp2;
7278 nla_for_each_nested(attr1, freqs, tmp1)
7279 if (nla_len(attr1) != sizeof(u32))
7282 nla_for_each_nested(attr1, freqs, tmp1) {
7285 * Some hardware has a limited channel list for
7286 * scanning, and it is pretty much nonsensical
7287 * to scan for a channel twice, so disallow that
7288 * and don't require drivers to check that the
7289 * channel list they get isn't longer than what
7290 * they can scan, as long as they can scan all
7291 * the channels they registered at once.
7293 nla_for_each_nested(attr2, freqs, tmp2)
7294 if (attr1 != attr2 &&
7295 nla_get_u32(attr1) == nla_get_u32(attr2))
7302 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
7304 return b < NUM_NL80211_BANDS && wiphy->bands[b];
7307 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7308 struct cfg80211_bss_selection *bss_select)
7310 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7311 struct nlattr *nest;
7316 /* only process one nested attribute */
7317 nest = nla_data(nla);
7318 if (!nla_ok(nest, nla_len(nest)))
7321 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7322 nest, nl80211_bss_select_policy,
7327 /* only one attribute may be given */
7328 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7336 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7338 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7339 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7341 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7342 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7343 bss_select->param.band_pref =
7344 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7345 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7349 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7350 struct nl80211_bss_select_rssi_adjust *adj_param;
7352 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7353 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7354 bss_select->param.adjust.band = adj_param->band;
7355 bss_select->param.adjust.delta = adj_param->delta;
7356 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7360 /* user-space did not provide behaviour attribute */
7361 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7364 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7370 int nl80211_parse_random_mac(struct nlattr **attrs,
7371 u8 *mac_addr, u8 *mac_addr_mask)
7375 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
7376 eth_zero_addr(mac_addr);
7377 eth_zero_addr(mac_addr_mask);
7379 mac_addr_mask[0] = 0x3;
7384 /* need both or none */
7385 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7388 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7389 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7391 /* don't allow or configure an mcast address */
7392 if (!is_multicast_ether_addr(mac_addr_mask) ||
7393 is_multicast_ether_addr(mac_addr))
7397 * allow users to pass a MAC address that has bits set outside
7398 * of the mask, but don't bother drivers with having to deal
7401 for (i = 0; i < ETH_ALEN; i++)
7402 mac_addr[i] &= mac_addr_mask[i];
7407 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7409 ASSERT_WDEV_LOCK(wdev);
7411 if (!cfg80211_beaconing_iface_active(wdev))
7414 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7417 return regulatory_pre_cac_allowed(wdev->wiphy);
7420 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7421 enum nl80211_ext_feature_index feat)
7423 if (!(flags & flag))
7425 if (wiphy_ext_feature_isset(wiphy, feat))
7431 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7432 void *request, struct nlattr **attrs,
7435 u8 *mac_addr, *mac_addr_mask;
7437 enum nl80211_feature_flags randomness_flag;
7439 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7442 if (is_sched_scan) {
7443 struct cfg80211_sched_scan_request *req = request;
7445 randomness_flag = wdev ?
7446 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7447 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7448 flags = &req->flags;
7449 mac_addr = req->mac_addr;
7450 mac_addr_mask = req->mac_addr_mask;
7452 struct cfg80211_scan_request *req = request;
7454 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7455 flags = &req->flags;
7456 mac_addr = req->mac_addr;
7457 mac_addr_mask = req->mac_addr_mask;
7460 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7462 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7463 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
7464 !nl80211_check_scan_feat(wiphy, *flags,
7465 NL80211_SCAN_FLAG_LOW_SPAN,
7466 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7467 !nl80211_check_scan_feat(wiphy, *flags,
7468 NL80211_SCAN_FLAG_LOW_POWER,
7469 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7470 !nl80211_check_scan_feat(wiphy, *flags,
7471 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7472 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7473 !nl80211_check_scan_feat(wiphy, *flags,
7474 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7475 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7476 !nl80211_check_scan_feat(wiphy, *flags,
7477 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7478 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7479 !nl80211_check_scan_feat(wiphy, *flags,
7480 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7481 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7482 !nl80211_check_scan_feat(wiphy, *flags,
7483 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
7484 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7485 !nl80211_check_scan_feat(wiphy, *flags,
7486 NL80211_SCAN_FLAG_RANDOM_SN,
7487 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7488 !nl80211_check_scan_feat(wiphy, *flags,
7489 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7490 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
7493 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7496 if (!(wiphy->features & randomness_flag) ||
7497 (wdev && wdev->current_bss))
7500 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7508 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7511 struct wireless_dev *wdev = info->user_ptr[1];
7512 struct cfg80211_scan_request *request;
7513 struct nlattr *attr;
7514 struct wiphy *wiphy;
7515 int err, tmp, n_ssids = 0, n_channels, i;
7518 wiphy = &rdev->wiphy;
7520 if (wdev->iftype == NL80211_IFTYPE_NAN)
7523 if (!rdev->ops->scan)
7526 if (rdev->scan_req || rdev->scan_msg) {
7531 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7532 n_channels = validate_scan_freqs(
7533 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
7539 n_channels = ieee80211_get_num_supported_channels(wiphy);
7542 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7543 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7546 if (n_ssids > wiphy->max_scan_ssids) {
7551 if (info->attrs[NL80211_ATTR_IE])
7552 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7556 if (ie_len > wiphy->max_scan_ie_len) {
7561 request = kzalloc(sizeof(*request)
7562 + sizeof(*request->ssids) * n_ssids
7563 + sizeof(*request->channels) * n_channels
7564 + ie_len, GFP_KERNEL);
7571 request->ssids = (void *)&request->channels[n_channels];
7572 request->n_ssids = n_ssids;
7575 request->ie = (void *)(request->ssids + n_ssids);
7577 request->ie = (void *)(request->channels + n_channels);
7581 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7582 /* user specified, bail out if channel not found */
7583 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
7584 struct ieee80211_channel *chan;
7586 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7593 /* ignore disabled channels */
7594 if (chan->flags & IEEE80211_CHAN_DISABLED)
7597 request->channels[i] = chan;
7601 enum nl80211_band band;
7604 for (band = 0; band < NUM_NL80211_BANDS; band++) {
7607 if (!wiphy->bands[band])
7609 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7610 struct ieee80211_channel *chan;
7612 chan = &wiphy->bands[band]->channels[j];
7614 if (chan->flags & IEEE80211_CHAN_DISABLED)
7617 request->channels[i] = chan;
7628 request->n_channels = i;
7631 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7632 struct ieee80211_channel *chan;
7634 if (request->n_channels != 1) {
7640 chan = request->channels[0];
7641 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7651 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
7652 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
7656 request->ssids[i].ssid_len = nla_len(attr);
7657 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
7662 if (info->attrs[NL80211_ATTR_IE]) {
7663 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7664 memcpy((void *)request->ie,
7665 nla_data(info->attrs[NL80211_ATTR_IE]),
7669 for (i = 0; i < NUM_NL80211_BANDS; i++)
7670 if (wiphy->bands[i])
7672 (1 << wiphy->bands[i]->n_bitrates) - 1;
7674 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7675 nla_for_each_nested(attr,
7676 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7678 enum nl80211_band band = nla_type(attr);
7680 if (band < 0 || band >= NUM_NL80211_BANDS) {
7685 if (!wiphy->bands[band])
7688 err = ieee80211_get_ratemask(wiphy->bands[band],
7691 &request->rates[band]);
7697 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7698 if (!wiphy_ext_feature_isset(wiphy,
7699 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7705 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7706 request->duration_mandatory =
7707 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7710 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7716 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7718 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7719 * BSSID to scan for. This was problematic because that same attribute
7720 * was already used for another purpose (local random MAC address). The
7721 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7722 * compatibility with older userspace components, also use the
7723 * NL80211_ATTR_MAC value here if it can be determined to be used for
7724 * the specific BSSID use case instead of the random MAC address
7725 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7727 if (info->attrs[NL80211_ATTR_BSSID])
7728 memcpy(request->bssid,
7729 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7730 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7731 info->attrs[NL80211_ATTR_MAC])
7732 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7735 eth_broadcast_addr(request->bssid);
7737 request->wdev = wdev;
7738 request->wiphy = &rdev->wiphy;
7739 request->scan_start = jiffies;
7741 rdev->scan_req = request;
7742 err = rdev_scan(rdev, request);
7745 nl80211_send_scan_start(rdev, wdev);
7747 dev_hold(wdev->netdev);
7750 rdev->scan_req = NULL;
7758 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7761 struct wireless_dev *wdev = info->user_ptr[1];
7763 if (!rdev->ops->abort_scan)
7769 if (!rdev->scan_req)
7772 rdev_abort_scan(rdev, wdev);
7777 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7778 struct cfg80211_sched_scan_request *request,
7779 struct nlattr **attrs)
7781 int tmp, err, i = 0;
7782 struct nlattr *attr;
7784 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7788 * If scan plans are not specified,
7789 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
7790 * case one scan plan will be set with the specified scan
7791 * interval and infinite number of iterations.
7793 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7797 request->scan_plans[0].interval =
7798 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7799 if (!request->scan_plans[0].interval)
7802 if (request->scan_plans[0].interval >
7803 wiphy->max_sched_scan_plan_interval)
7804 request->scan_plans[0].interval =
7805 wiphy->max_sched_scan_plan_interval;
7810 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7811 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7813 if (WARN_ON(i >= n_plans))
7816 err = nla_parse_nested_deprecated(plan,
7817 NL80211_SCHED_SCAN_PLAN_MAX,
7818 attr, nl80211_plan_policy,
7823 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7826 request->scan_plans[i].interval =
7827 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7828 if (!request->scan_plans[i].interval ||
7829 request->scan_plans[i].interval >
7830 wiphy->max_sched_scan_plan_interval)
7833 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7834 request->scan_plans[i].iterations =
7835 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7836 if (!request->scan_plans[i].iterations ||
7837 (request->scan_plans[i].iterations >
7838 wiphy->max_sched_scan_plan_iterations))
7840 } else if (i < n_plans - 1) {
7842 * All scan plans but the last one must specify
7843 * a finite number of iterations
7852 * The last scan plan must not specify the number of
7853 * iterations, it is supposed to run infinitely
7855 if (request->scan_plans[n_plans - 1].iterations)
7862 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
7863 struct cfg80211_match_set *match_sets,
7864 struct nlattr *tb_band_rssi,
7867 struct nlattr *attr;
7868 int i, tmp, ret = 0;
7870 if (!wiphy_ext_feature_isset(wiphy,
7871 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
7875 for (i = 0; i < NUM_NL80211_BANDS; i++)
7876 match_sets->per_band_rssi_thold[i] =
7877 NL80211_SCAN_RSSI_THOLD_OFF;
7881 for (i = 0; i < NUM_NL80211_BANDS; i++)
7882 match_sets->per_band_rssi_thold[i] = rssi_thold;
7884 nla_for_each_nested(attr, tb_band_rssi, tmp) {
7885 enum nl80211_band band = nla_type(attr);
7887 if (band < 0 || band >= NUM_NL80211_BANDS)
7890 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
7896 static struct cfg80211_sched_scan_request *
7897 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
7898 struct nlattr **attrs, int max_match_sets)
7900 struct cfg80211_sched_scan_request *request;
7901 struct nlattr *attr;
7902 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
7903 enum nl80211_band band;
7905 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
7906 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
7908 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7909 n_channels = validate_scan_freqs(
7910 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
7912 return ERR_PTR(-EINVAL);
7914 n_channels = ieee80211_get_num_supported_channels(wiphy);
7917 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7918 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
7922 if (n_ssids > wiphy->max_sched_scan_ssids)
7923 return ERR_PTR(-EINVAL);
7926 * First, count the number of 'real' matchsets. Due to an issue with
7927 * the old implementation, matchsets containing only the RSSI attribute
7928 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7929 * RSSI for all matchsets, rather than their own matchset for reporting
7930 * all APs with a strong RSSI. This is needed to be compatible with
7931 * older userspace that treated a matchset with only the RSSI as the
7932 * global RSSI for all other matchsets - if there are other matchsets.
7934 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
7935 nla_for_each_nested(attr,
7936 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
7938 struct nlattr *rssi;
7940 err = nla_parse_nested_deprecated(tb,
7941 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7943 nl80211_match_policy,
7946 return ERR_PTR(err);
7948 /* SSID and BSSID are mutually exclusive */
7949 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7950 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7951 return ERR_PTR(-EINVAL);
7953 /* add other standalone attributes here */
7954 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7955 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
7959 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7961 default_match_rssi = nla_get_s32(rssi);
7965 /* However, if there's no other matchset, add the RSSI one */
7966 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7969 if (n_match_sets > max_match_sets)
7970 return ERR_PTR(-EINVAL);
7972 if (attrs[NL80211_ATTR_IE])
7973 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
7977 if (ie_len > wiphy->max_sched_scan_ie_len)
7978 return ERR_PTR(-EINVAL);
7980 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7982 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7983 * each scan plan already specifies its own interval
7985 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7986 return ERR_PTR(-EINVAL);
7988 nla_for_each_nested(attr,
7989 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7993 * The scan interval attribute is kept for backward
7994 * compatibility. If no scan plans are specified and sched scan
7995 * interval is specified, one scan plan will be set with this
7996 * scan interval and infinite number of iterations.
7998 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7999 return ERR_PTR(-EINVAL);
8004 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
8005 return ERR_PTR(-EINVAL);
8007 if (!wiphy_ext_feature_isset(
8008 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
8009 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
8010 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
8011 return ERR_PTR(-EINVAL);
8013 request = kzalloc(sizeof(*request)
8014 + sizeof(*request->ssids) * n_ssids
8015 + sizeof(*request->match_sets) * n_match_sets
8016 + sizeof(*request->scan_plans) * n_plans
8017 + sizeof(*request->channels) * n_channels
8018 + ie_len, GFP_KERNEL);
8020 return ERR_PTR(-ENOMEM);
8023 request->ssids = (void *)&request->channels[n_channels];
8024 request->n_ssids = n_ssids;
8027 request->ie = (void *)(request->ssids + n_ssids);
8029 request->ie = (void *)(request->channels + n_channels);
8034 request->match_sets = (void *)(request->ie + ie_len);
8036 request->match_sets =
8037 (void *)(request->ssids + n_ssids);
8039 request->match_sets =
8040 (void *)(request->channels + n_channels);
8042 request->n_match_sets = n_match_sets;
8045 request->scan_plans = (void *)(request->match_sets +
8047 else if (request->ie)
8048 request->scan_plans = (void *)(request->ie + ie_len);
8050 request->scan_plans = (void *)(request->ssids + n_ssids);
8052 request->scan_plans = (void *)(request->channels + n_channels);
8054 request->n_scan_plans = n_plans;
8057 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
8058 /* user specified, bail out if channel not found */
8059 nla_for_each_nested(attr,
8060 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
8062 struct ieee80211_channel *chan;
8064 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
8071 /* ignore disabled channels */
8072 if (chan->flags & IEEE80211_CHAN_DISABLED)
8075 request->channels[i] = chan;
8080 for (band = 0; band < NUM_NL80211_BANDS; band++) {
8083 if (!wiphy->bands[band])
8085 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8086 struct ieee80211_channel *chan;
8088 chan = &wiphy->bands[band]->channels[j];
8090 if (chan->flags & IEEE80211_CHAN_DISABLED)
8093 request->channels[i] = chan;
8104 request->n_channels = i;
8108 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
8110 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
8114 request->ssids[i].ssid_len = nla_len(attr);
8115 memcpy(request->ssids[i].ssid, nla_data(attr),
8122 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
8123 nla_for_each_nested(attr,
8124 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
8126 struct nlattr *ssid, *bssid, *rssi;
8128 err = nla_parse_nested_deprecated(tb,
8129 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8131 nl80211_match_policy,
8135 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
8136 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
8138 if (!ssid && !bssid) {
8143 if (WARN_ON(i >= n_match_sets)) {
8144 /* this indicates a programming error,
8145 * the loop above should have verified
8153 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
8157 memcpy(request->match_sets[i].ssid.ssid,
8158 nla_data(ssid), nla_len(ssid));
8159 request->match_sets[i].ssid.ssid_len =
8163 if (nla_len(bssid) != ETH_ALEN) {
8167 memcpy(request->match_sets[i].bssid,
8168 nla_data(bssid), ETH_ALEN);
8171 /* special attribute - old implementation w/a */
8172 request->match_sets[i].rssi_thold = default_match_rssi;
8173 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8175 request->match_sets[i].rssi_thold =
8178 /* Parse per band RSSI attribute */
8179 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
8180 &request->match_sets[i],
8181 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
8182 request->match_sets[i].rssi_thold);
8189 /* there was no other matchset, so the RSSI one is alone */
8190 if (i == 0 && n_match_sets)
8191 request->match_sets[0].rssi_thold = default_match_rssi;
8193 request->min_rssi_thold = INT_MAX;
8194 for (i = 0; i < n_match_sets; i++)
8195 request->min_rssi_thold =
8196 min(request->match_sets[i].rssi_thold,
8197 request->min_rssi_thold);
8199 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
8203 request->ie_len = ie_len;
8204 memcpy((void *)request->ie,
8205 nla_data(attrs[NL80211_ATTR_IE]),
8209 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8213 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8215 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8217 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8218 request->relative_rssi = nla_get_s8(
8219 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8220 request->relative_rssi_set = true;
8223 if (request->relative_rssi_set &&
8224 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8225 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8227 rssi_adjust = nla_data(
8228 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8229 request->rssi_adjust.band = rssi_adjust->band;
8230 request->rssi_adjust.delta = rssi_adjust->delta;
8231 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8237 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8241 request->scan_start = jiffies;
8247 return ERR_PTR(err);
8250 static int nl80211_start_sched_scan(struct sk_buff *skb,
8251 struct genl_info *info)
8253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8254 struct net_device *dev = info->user_ptr[1];
8255 struct wireless_dev *wdev = dev->ieee80211_ptr;
8256 struct cfg80211_sched_scan_request *sched_scan_req;
8260 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
8263 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8264 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8268 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
8270 rdev->wiphy.max_match_sets);
8272 err = PTR_ERR_OR_ZERO(sched_scan_req);
8276 /* leave request id zero for legacy request
8277 * or if driver does not support multi-scheduled scan
8279 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
8280 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
8282 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
8286 sched_scan_req->dev = dev;
8287 sched_scan_req->wiphy = &rdev->wiphy;
8289 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8290 sched_scan_req->owner_nlportid = info->snd_portid;
8292 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
8294 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
8298 kfree(sched_scan_req);
8303 static int nl80211_stop_sched_scan(struct sk_buff *skb,
8304 struct genl_info *info)
8306 struct cfg80211_sched_scan_request *req;
8307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8310 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
8313 if (info->attrs[NL80211_ATTR_COOKIE]) {
8314 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8315 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8318 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8319 struct cfg80211_sched_scan_request,
8321 if (!req || req->reqid ||
8322 (req->owner_nlportid &&
8323 req->owner_nlportid != info->snd_portid))
8326 return cfg80211_stop_sched_scan_req(rdev, req, false);
8329 static int nl80211_start_radar_detection(struct sk_buff *skb,
8330 struct genl_info *info)
8332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8333 struct net_device *dev = info->user_ptr[1];
8334 struct wireless_dev *wdev = dev->ieee80211_ptr;
8335 struct wiphy *wiphy = wdev->wiphy;
8336 struct cfg80211_chan_def chandef;
8337 enum nl80211_dfs_regions dfs_region;
8338 unsigned int cac_time_ms;
8341 dfs_region = reg_get_dfs_region(wiphy);
8342 if (dfs_region == NL80211_DFS_UNSET)
8345 err = nl80211_parse_chandef(rdev, info, &chandef);
8349 if (netif_carrier_ok(dev))
8352 if (wdev->cac_started)
8355 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8362 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
8365 /* CAC start is offloaded to HW and can't be started manually */
8366 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8369 if (!rdev->ops->start_radar_detection)
8372 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8373 if (WARN_ON(!cac_time_ms))
8374 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8376 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
8378 wdev->chandef = chandef;
8379 wdev->cac_started = true;
8380 wdev->cac_start_time = jiffies;
8381 wdev->cac_time_ms = cac_time_ms;
8386 static int nl80211_notify_radar_detection(struct sk_buff *skb,
8387 struct genl_info *info)
8389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8390 struct net_device *dev = info->user_ptr[1];
8391 struct wireless_dev *wdev = dev->ieee80211_ptr;
8392 struct wiphy *wiphy = wdev->wiphy;
8393 struct cfg80211_chan_def chandef;
8394 enum nl80211_dfs_regions dfs_region;
8397 dfs_region = reg_get_dfs_region(wiphy);
8398 if (dfs_region == NL80211_DFS_UNSET) {
8399 GENL_SET_ERR_MSG(info,
8400 "DFS Region is not set. Unexpected Radar indication");
8404 err = nl80211_parse_chandef(rdev, info, &chandef);
8406 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8410 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8412 GENL_SET_ERR_MSG(info, "chandef is invalid");
8417 GENL_SET_ERR_MSG(info,
8418 "Unexpected Radar indication for chandef/iftype");
8422 /* Do not process this notification if radar is already detected
8423 * by kernel on this channel, and return success.
8425 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8428 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8430 cfg80211_sched_dfs_chan_update(rdev);
8432 rdev->radar_chandef = chandef;
8434 /* Propagate this notification to other radios as well */
8435 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8440 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8443 struct net_device *dev = info->user_ptr[1];
8444 struct wireless_dev *wdev = dev->ieee80211_ptr;
8445 struct cfg80211_csa_settings params;
8446 /* csa_attrs is defined static to avoid waste of stack size - this
8447 * function is called under RTNL lock, so this should not be a problem.
8449 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
8451 bool need_new_beacon = false;
8452 bool need_handle_dfs_flag = true;
8456 if (!rdev->ops->channel_switch ||
8457 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8460 switch (dev->ieee80211_ptr->iftype) {
8461 case NL80211_IFTYPE_AP:
8462 case NL80211_IFTYPE_P2P_GO:
8463 need_new_beacon = true;
8464 /* For all modes except AP the handle_dfs flag needs to be
8465 * supplied to tell the kernel that userspace will handle radar
8466 * events when they happen. Otherwise a switch to a channel
8467 * requiring DFS will be rejected.
8469 need_handle_dfs_flag = false;
8471 /* useless if AP is not running */
8472 if (!wdev->beacon_interval)
8475 case NL80211_IFTYPE_ADHOC:
8476 if (!wdev->ssid_len)
8479 case NL80211_IFTYPE_MESH_POINT:
8480 if (!wdev->mesh_id_len)
8487 memset(¶ms, 0, sizeof(params));
8488 params.beacon_csa.ftm_responder = -1;
8490 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8491 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8494 /* only important for AP, IBSS and mesh create IEs internally */
8495 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
8498 /* Even though the attribute is u32, the specification says
8499 * u8, so let's make sure we don't overflow.
8501 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8505 params.count = cs_count;
8507 if (!need_new_beacon)
8510 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after);
8514 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8515 info->attrs[NL80211_ATTR_CSA_IES],
8516 nl80211_policy, info->extack);
8520 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa);
8524 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8527 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8528 if (!len || (len % sizeof(u16)))
8531 params.n_counter_offsets_beacon = len / sizeof(u16);
8532 if (rdev->wiphy.max_num_csa_counters &&
8533 (params.n_counter_offsets_beacon >
8534 rdev->wiphy.max_num_csa_counters))
8537 params.counter_offsets_beacon =
8538 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8540 /* sanity checks - counters should fit and be the same */
8541 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8542 u16 offset = params.counter_offsets_beacon[i];
8544 if (offset >= params.beacon_csa.tail_len)
8547 if (params.beacon_csa.tail[offset] != params.count)
8551 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
8552 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8553 if (!len || (len % sizeof(u16)))
8556 params.n_counter_offsets_presp = len / sizeof(u16);
8557 if (rdev->wiphy.max_num_csa_counters &&
8558 (params.n_counter_offsets_presp >
8559 rdev->wiphy.max_num_csa_counters))
8562 params.counter_offsets_presp =
8563 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8565 /* sanity checks - counters should fit and be the same */
8566 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8567 u16 offset = params.counter_offsets_presp[i];
8569 if (offset >= params.beacon_csa.probe_resp_len)
8572 if (params.beacon_csa.probe_resp[offset] !=
8579 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
8583 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
8587 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8594 params.radar_required = true;
8595 if (need_handle_dfs_flag &&
8596 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8601 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8602 params.block_tx = true;
8605 err = rdev_channel_switch(rdev, dev, ¶ms);
8611 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8613 struct cfg80211_registered_device *rdev,
8614 struct wireless_dev *wdev,
8615 struct cfg80211_internal_bss *intbss)
8617 struct cfg80211_bss *res = &intbss->pub;
8618 const struct cfg80211_bss_ies *ies;
8622 ASSERT_WDEV_LOCK(wdev);
8624 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
8625 NL80211_CMD_NEW_SCAN_RESULTS);
8629 genl_dump_check_consistent(cb, hdr);
8631 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8632 goto nla_put_failure;
8634 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8635 goto nla_put_failure;
8636 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8638 goto nla_put_failure;
8640 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
8642 goto nla_put_failure;
8643 if ((!is_zero_ether_addr(res->bssid) &&
8644 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
8645 goto nla_put_failure;
8648 /* indicate whether we have probe response data or not */
8649 if (rcu_access_pointer(res->proberesp_ies) &&
8650 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8651 goto fail_unlock_rcu;
8653 /* this pointer prefers to be pointed to probe response data
8654 * but is always valid
8656 ies = rcu_dereference(res->ies);
8658 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8660 goto fail_unlock_rcu;
8661 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8662 ies->len, ies->data))
8663 goto fail_unlock_rcu;
8666 /* and this pointer is always (unless driver didn't know) beacon data */
8667 ies = rcu_dereference(res->beacon_ies);
8668 if (ies && ies->from_beacon) {
8669 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8671 goto fail_unlock_rcu;
8672 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8673 ies->len, ies->data))
8674 goto fail_unlock_rcu;
8678 if (res->beacon_interval &&
8679 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8680 goto nla_put_failure;
8681 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8682 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
8683 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
8684 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8685 jiffies_to_msecs(jiffies - intbss->ts)))
8686 goto nla_put_failure;
8688 if (intbss->parent_tsf &&
8689 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8690 intbss->parent_tsf, NL80211_BSS_PAD) ||
8691 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8692 intbss->parent_bssid)))
8693 goto nla_put_failure;
8695 if (intbss->ts_boottime &&
8696 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8697 intbss->ts_boottime, NL80211_BSS_PAD))
8698 goto nla_put_failure;
8700 if (!nl80211_put_signal(msg, intbss->pub.chains,
8701 intbss->pub.chain_signal,
8702 NL80211_BSS_CHAIN_SIGNAL))
8703 goto nla_put_failure;
8705 switch (rdev->wiphy.signal_type) {
8706 case CFG80211_SIGNAL_TYPE_MBM:
8707 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8708 goto nla_put_failure;
8710 case CFG80211_SIGNAL_TYPE_UNSPEC:
8711 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8712 goto nla_put_failure;
8718 switch (wdev->iftype) {
8719 case NL80211_IFTYPE_P2P_CLIENT:
8720 case NL80211_IFTYPE_STATION:
8721 if (intbss == wdev->current_bss &&
8722 nla_put_u32(msg, NL80211_BSS_STATUS,
8723 NL80211_BSS_STATUS_ASSOCIATED))
8724 goto nla_put_failure;
8726 case NL80211_IFTYPE_ADHOC:
8727 if (intbss == wdev->current_bss &&
8728 nla_put_u32(msg, NL80211_BSS_STATUS,
8729 NL80211_BSS_STATUS_IBSS_JOINED))
8730 goto nla_put_failure;
8736 nla_nest_end(msg, bss);
8738 genlmsg_end(msg, hdr);
8744 genlmsg_cancel(msg, hdr);
8748 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
8750 struct cfg80211_registered_device *rdev;
8751 struct cfg80211_internal_bss *scan;
8752 struct wireless_dev *wdev;
8753 int start = cb->args[2], idx = 0;
8757 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
8764 spin_lock_bh(&rdev->bss_lock);
8767 * dump_scan will be called multiple times to break up the scan results
8768 * into multiple messages. It is unlikely that any more bss-es will be
8769 * expired after the first call, so only call only call this on the
8770 * first dump_scan invocation.
8773 cfg80211_bss_expire(rdev);
8775 cb->seq = rdev->bss_generation;
8777 list_for_each_entry(scan, &rdev->bss_list, list) {
8780 if (nl80211_send_bss(skb, cb,
8781 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8782 rdev, wdev, scan) < 0) {
8788 spin_unlock_bh(&rdev->bss_lock);
8797 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
8798 int flags, struct net_device *dev,
8799 bool allow_radio_stats,
8800 struct survey_info *survey)
8803 struct nlattr *infoattr;
8805 /* skip radio stats if userspace didn't request them */
8806 if (!survey->channel && !allow_radio_stats)
8809 hdr = nl80211hdr_put(msg, portid, seq, flags,
8810 NL80211_CMD_NEW_SURVEY_RESULTS);
8814 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8815 goto nla_put_failure;
8817 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
8819 goto nla_put_failure;
8821 if (survey->channel &&
8822 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
8823 survey->channel->center_freq))
8824 goto nla_put_failure;
8826 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
8827 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
8828 goto nla_put_failure;
8829 if ((survey->filled & SURVEY_INFO_IN_USE) &&
8830 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
8831 goto nla_put_failure;
8832 if ((survey->filled & SURVEY_INFO_TIME) &&
8833 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
8834 survey->time, NL80211_SURVEY_INFO_PAD))
8835 goto nla_put_failure;
8836 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
8837 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
8838 survey->time_busy, NL80211_SURVEY_INFO_PAD))
8839 goto nla_put_failure;
8840 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
8841 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
8842 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
8843 goto nla_put_failure;
8844 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
8845 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
8846 survey->time_rx, NL80211_SURVEY_INFO_PAD))
8847 goto nla_put_failure;
8848 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
8849 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
8850 survey->time_tx, NL80211_SURVEY_INFO_PAD))
8851 goto nla_put_failure;
8852 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
8853 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
8854 survey->time_scan, NL80211_SURVEY_INFO_PAD))
8855 goto nla_put_failure;
8856 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
8857 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
8858 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
8859 goto nla_put_failure;
8861 nla_nest_end(msg, infoattr);
8863 genlmsg_end(msg, hdr);
8867 genlmsg_cancel(msg, hdr);
8871 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
8873 struct nlattr **attrbuf;
8874 struct survey_info survey;
8875 struct cfg80211_registered_device *rdev;
8876 struct wireless_dev *wdev;
8877 int survey_idx = cb->args[2];
8881 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
8886 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
8890 /* prepare_wdev_dump parsed the attributes */
8891 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
8893 if (!wdev->netdev) {
8898 if (!rdev->ops->dump_survey) {
8904 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
8910 /* don't send disabled channels, but do send non-channel data */
8911 if (survey.channel &&
8912 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
8917 if (nl80211_send_survey(skb,
8918 NETLINK_CB(cb->skb).portid,
8919 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8920 wdev->netdev, radio_stats, &survey) < 0)
8926 cb->args[2] = survey_idx;
8934 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8936 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8937 NL80211_WPA_VERSION_2 |
8938 NL80211_WPA_VERSION_3));
8941 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8944 struct net_device *dev = info->user_ptr[1];
8945 struct ieee80211_channel *chan;
8946 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8947 int err, ssid_len, ie_len = 0, auth_data_len = 0;
8948 enum nl80211_auth_type auth_type;
8949 struct key_parse key;
8950 bool local_state_change;
8952 if (!info->attrs[NL80211_ATTR_MAC])
8955 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8958 if (!info->attrs[NL80211_ATTR_SSID])
8961 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8964 err = nl80211_parse_key(info, &key);
8969 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8971 if (!key.p.key || !key.p.key_len)
8973 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8974 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8975 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8976 key.p.key_len != WLAN_KEY_LEN_WEP104))
8989 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8990 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8999 if (!rdev->ops->auth)
9002 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9003 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9006 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9007 chan = nl80211_get_valid_chan(&rdev->wiphy,
9008 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9012 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9013 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9015 if (info->attrs[NL80211_ATTR_IE]) {
9016 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9017 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9020 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9021 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
9024 if ((auth_type == NL80211_AUTHTYPE_SAE ||
9025 auth_type == NL80211_AUTHTYPE_FILS_SK ||
9026 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
9027 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
9028 !info->attrs[NL80211_ATTR_AUTH_DATA])
9031 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
9032 if (auth_type != NL80211_AUTHTYPE_SAE &&
9033 auth_type != NL80211_AUTHTYPE_FILS_SK &&
9034 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
9035 auth_type != NL80211_AUTHTYPE_FILS_PK)
9037 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
9038 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
9039 /* need to include at least Auth Transaction and Status Code */
9040 if (auth_data_len < 4)
9044 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9047 * Since we no longer track auth state, ignore
9048 * requests to only change local state.
9050 if (local_state_change)
9053 wdev_lock(dev->ieee80211_ptr);
9054 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
9055 ssid, ssid_len, ie, ie_len,
9056 key.p.key, key.p.key_len, key.idx,
9057 auth_data, auth_data_len);
9058 wdev_unlock(dev->ieee80211_ptr);
9062 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
9063 struct genl_info *info)
9065 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9066 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
9070 if (!rdev->ops->tx_control_port ||
9071 !wiphy_ext_feature_isset(&rdev->wiphy,
9072 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
9078 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
9079 struct genl_info *info,
9080 struct cfg80211_crypto_settings *settings,
9083 memset(settings, 0, sizeof(*settings));
9085 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9087 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9090 proto = nla_get_u16(
9091 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
9092 settings->control_port_ethertype = cpu_to_be16(proto);
9093 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
9096 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
9097 settings->control_port_no_encrypt = true;
9099 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
9101 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9102 int r = validate_pae_over_nl80211(rdev, info);
9107 settings->control_port_over_nl80211 = true;
9110 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
9114 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9115 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9116 settings->n_ciphers_pairwise = len / sizeof(u32);
9118 if (len % sizeof(u32))
9121 if (settings->n_ciphers_pairwise > cipher_limit)
9124 memcpy(settings->ciphers_pairwise, data, len);
9126 for (i = 0; i < settings->n_ciphers_pairwise; i++)
9127 if (!cfg80211_supported_cipher_suite(
9129 settings->ciphers_pairwise[i]))
9133 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
9134 settings->cipher_group =
9135 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
9136 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9137 settings->cipher_group))
9141 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
9142 settings->wpa_versions =
9143 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
9144 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
9148 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
9152 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
9153 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
9154 settings->n_akm_suites = len / sizeof(u32);
9156 if (len % sizeof(u32))
9159 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9162 memcpy(settings->akm_suites, data, len);
9165 if (info->attrs[NL80211_ATTR_PMK]) {
9166 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
9168 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9169 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
9171 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9174 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9175 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9176 NL80211_EXT_FEATURE_SAE_OFFLOAD))
9179 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9180 settings->sae_pwd_len =
9181 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9187 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9190 struct net_device *dev = info->user_ptr[1];
9191 struct ieee80211_channel *chan;
9192 struct cfg80211_assoc_request req = {};
9193 const u8 *bssid, *ssid;
9194 int err, ssid_len = 0;
9196 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9197 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9200 if (!info->attrs[NL80211_ATTR_MAC] ||
9201 !info->attrs[NL80211_ATTR_SSID] ||
9202 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
9205 if (!rdev->ops->assoc)
9208 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9209 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9212 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9214 chan = nl80211_get_valid_chan(&rdev->wiphy,
9215 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9219 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9220 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9222 if (info->attrs[NL80211_ATTR_IE]) {
9223 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9224 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9227 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9228 enum nl80211_mfp mfp =
9229 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
9230 if (mfp == NL80211_MFP_REQUIRED)
9232 else if (mfp != NL80211_MFP_NO)
9236 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9237 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9239 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9240 req.flags |= ASSOC_REQ_DISABLE_HT;
9242 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9243 memcpy(&req.ht_capa_mask,
9244 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9245 sizeof(req.ht_capa_mask));
9247 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9248 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9250 memcpy(&req.ht_capa,
9251 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9252 sizeof(req.ht_capa));
9255 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9256 req.flags |= ASSOC_REQ_DISABLE_VHT;
9258 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9259 memcpy(&req.vht_capa_mask,
9260 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9261 sizeof(req.vht_capa_mask));
9263 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9264 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9266 memcpy(&req.vht_capa,
9267 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9268 sizeof(req.vht_capa));
9271 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
9272 if (!((rdev->wiphy.features &
9273 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9274 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9275 !wiphy_ext_feature_isset(&rdev->wiphy,
9276 NL80211_EXT_FEATURE_RRM))
9278 req.flags |= ASSOC_REQ_USE_RRM;
9281 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9282 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9283 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9284 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9287 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9290 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
9292 wdev_lock(dev->ieee80211_ptr);
9294 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9295 ssid, ssid_len, &req);
9297 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9298 dev->ieee80211_ptr->conn_owner_nlportid =
9300 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9304 wdev_unlock(dev->ieee80211_ptr);
9310 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9313 struct net_device *dev = info->user_ptr[1];
9314 const u8 *ie = NULL, *bssid;
9315 int ie_len = 0, err;
9317 bool local_state_change;
9319 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9320 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9323 if (!info->attrs[NL80211_ATTR_MAC])
9326 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9329 if (!rdev->ops->deauth)
9332 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9333 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9336 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9338 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9339 if (reason_code == 0) {
9340 /* Reason Code 0 is reserved */
9344 if (info->attrs[NL80211_ATTR_IE]) {
9345 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9346 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9349 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9351 wdev_lock(dev->ieee80211_ptr);
9352 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9353 local_state_change);
9354 wdev_unlock(dev->ieee80211_ptr);
9358 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9361 struct net_device *dev = info->user_ptr[1];
9362 const u8 *ie = NULL, *bssid;
9363 int ie_len = 0, err;
9365 bool local_state_change;
9367 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9368 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9371 if (!info->attrs[NL80211_ATTR_MAC])
9374 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9377 if (!rdev->ops->disassoc)
9380 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9381 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9384 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9386 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9387 if (reason_code == 0) {
9388 /* Reason Code 0 is reserved */
9392 if (info->attrs[NL80211_ATTR_IE]) {
9393 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9394 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9397 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9399 wdev_lock(dev->ieee80211_ptr);
9400 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9401 local_state_change);
9402 wdev_unlock(dev->ieee80211_ptr);
9407 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
9408 int mcast_rate[NUM_NL80211_BANDS],
9411 struct wiphy *wiphy = &rdev->wiphy;
9415 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9416 struct ieee80211_supported_band *sband;
9418 sband = wiphy->bands[band];
9422 for (i = 0; i < sband->n_bitrates; i++) {
9423 if (sband->bitrates[i].bitrate == rateval) {
9424 mcast_rate[band] = i + 1;
9434 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9437 struct net_device *dev = info->user_ptr[1];
9438 struct cfg80211_ibss_params ibss;
9439 struct wiphy *wiphy;
9440 struct cfg80211_cached_keys *connkeys = NULL;
9443 memset(&ibss, 0, sizeof(ibss));
9445 if (!info->attrs[NL80211_ATTR_SSID] ||
9446 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9449 ibss.beacon_interval = 100;
9451 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
9452 ibss.beacon_interval =
9453 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9455 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9456 ibss.beacon_interval);
9460 if (!rdev->ops->join_ibss)
9463 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9466 wiphy = &rdev->wiphy;
9468 if (info->attrs[NL80211_ATTR_MAC]) {
9469 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9471 if (!is_valid_ether_addr(ibss.bssid))
9474 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9475 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9477 if (info->attrs[NL80211_ATTR_IE]) {
9478 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9479 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9482 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9486 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9487 NL80211_IFTYPE_ADHOC))
9490 switch (ibss.chandef.width) {
9491 case NL80211_CHAN_WIDTH_5:
9492 case NL80211_CHAN_WIDTH_10:
9493 case NL80211_CHAN_WIDTH_20_NOHT:
9495 case NL80211_CHAN_WIDTH_20:
9496 case NL80211_CHAN_WIDTH_40:
9497 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9500 case NL80211_CHAN_WIDTH_80:
9501 case NL80211_CHAN_WIDTH_80P80:
9502 case NL80211_CHAN_WIDTH_160:
9503 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9505 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9506 NL80211_EXT_FEATURE_VHT_IBSS))
9513 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
9514 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
9516 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9518 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9520 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9521 struct ieee80211_supported_band *sband =
9522 wiphy->bands[ibss.chandef.chan->band];
9524 err = ieee80211_get_ratemask(sband, rates, n_rates,
9530 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9531 memcpy(&ibss.ht_capa_mask,
9532 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9533 sizeof(ibss.ht_capa_mask));
9535 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9536 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9538 memcpy(&ibss.ht_capa,
9539 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9540 sizeof(ibss.ht_capa));
9543 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9544 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9545 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9548 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
9551 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
9552 if (IS_ERR(connkeys))
9553 return PTR_ERR(connkeys);
9555 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9563 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9565 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9566 int r = validate_pae_over_nl80211(rdev, info);
9573 ibss.control_port_over_nl80211 = true;
9576 ibss.userspace_handles_dfs =
9577 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9579 wdev_lock(dev->ieee80211_ptr);
9580 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
9583 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9584 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9585 wdev_unlock(dev->ieee80211_ptr);
9590 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9593 struct net_device *dev = info->user_ptr[1];
9595 if (!rdev->ops->leave_ibss)
9598 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9601 return cfg80211_leave_ibss(rdev, dev, false);
9604 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9607 struct net_device *dev = info->user_ptr[1];
9608 int mcast_rate[NUM_NL80211_BANDS];
9612 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
9613 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9614 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
9617 if (!rdev->ops->set_mcast_rate)
9620 memset(mcast_rate, 0, sizeof(mcast_rate));
9622 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9625 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9626 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9629 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
9634 static struct sk_buff *
9635 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
9636 struct wireless_dev *wdev, int approxlen,
9637 u32 portid, u32 seq, enum nl80211_commands cmd,
9638 enum nl80211_attrs attr,
9639 const struct nl80211_vendor_cmd_info *info,
9642 struct sk_buff *skb;
9644 struct nlattr *data;
9646 skb = nlmsg_new(approxlen + 100, gfp);
9650 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9656 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9657 goto nla_put_failure;
9660 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9662 goto nla_put_failure;
9663 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9665 goto nla_put_failure;
9669 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9670 wdev_id(wdev), NL80211_ATTR_PAD))
9671 goto nla_put_failure;
9673 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9674 wdev->netdev->ifindex))
9675 goto nla_put_failure;
9678 data = nla_nest_start_noflag(skb, attr);
9680 goto nla_put_failure;
9682 ((void **)skb->cb)[0] = rdev;
9683 ((void **)skb->cb)[1] = hdr;
9684 ((void **)skb->cb)[2] = data;
9693 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
9694 struct wireless_dev *wdev,
9695 enum nl80211_commands cmd,
9696 enum nl80211_attrs attr,
9697 unsigned int portid,
9698 int vendor_event_idx,
9699 int approxlen, gfp_t gfp)
9701 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
9702 const struct nl80211_vendor_cmd_info *info;
9705 case NL80211_CMD_TESTMODE:
9706 if (WARN_ON(vendor_event_idx != -1))
9710 case NL80211_CMD_VENDOR:
9711 if (WARN_ON(vendor_event_idx < 0 ||
9712 vendor_event_idx >= wiphy->n_vendor_events))
9714 info = &wiphy->vendor_events[vendor_event_idx];
9721 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
9722 cmd, attr, info, gfp);
9724 EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9726 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9728 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9729 void *hdr = ((void **)skb->cb)[1];
9730 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
9731 struct nlattr *data = ((void **)skb->cb)[2];
9732 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9734 /* clear CB data for netlink core to own from now on */
9735 memset(skb->cb, 0, sizeof(skb->cb));
9737 nla_nest_end(skb, data);
9738 genlmsg_end(skb, hdr);
9740 if (nlhdr->nlmsg_pid) {
9741 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
9744 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9745 mcgrp = NL80211_MCGRP_VENDOR;
9747 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
9748 skb, 0, mcgrp, gfp);
9751 EXPORT_SYMBOL(__cfg80211_send_event_skb);
9753 #ifdef CONFIG_NL80211_TESTMODE
9754 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9757 struct wireless_dev *wdev =
9758 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9761 if (!rdev->ops->testmode_cmd)
9765 err = PTR_ERR(wdev);
9769 } else if (wdev->wiphy != &rdev->wiphy) {
9773 if (!info->attrs[NL80211_ATTR_TESTDATA])
9776 rdev->cur_cmd_info = info;
9777 err = rdev_testmode_cmd(rdev, wdev,
9778 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9779 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
9780 rdev->cur_cmd_info = NULL;
9785 static int nl80211_testmode_dump(struct sk_buff *skb,
9786 struct netlink_callback *cb)
9788 struct cfg80211_registered_device *rdev;
9789 struct nlattr **attrbuf = NULL;
9799 * 0 is a valid index, but not valid for args[0],
9800 * so we need to offset by 1.
9802 phy_idx = cb->args[0] - 1;
9804 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9810 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
9817 err = nlmsg_parse_deprecated(cb->nlh,
9818 GENL_HDRLEN + nl80211_fam.hdrsize,
9819 attrbuf, nl80211_fam.maxattr,
9820 nl80211_policy, NULL);
9824 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
9826 err = PTR_ERR(rdev);
9829 phy_idx = rdev->wiphy_idx;
9831 if (attrbuf[NL80211_ATTR_TESTDATA])
9832 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
9836 data = nla_data((void *)cb->args[1]);
9837 data_len = nla_len((void *)cb->args[1]);
9840 if (!rdev->ops->testmode_dump) {
9846 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
9847 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9848 NL80211_CMD_TESTMODE);
9849 struct nlattr *tmdata;
9854 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
9855 genlmsg_cancel(skb, hdr);
9859 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
9861 genlmsg_cancel(skb, hdr);
9864 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
9865 nla_nest_end(skb, tmdata);
9867 if (err == -ENOBUFS || err == -ENOENT) {
9868 genlmsg_cancel(skb, hdr);
9871 genlmsg_cancel(skb, hdr);
9875 genlmsg_end(skb, hdr);
9880 cb->args[0] = phy_idx + 1;
9888 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
9890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9891 struct net_device *dev = info->user_ptr[1];
9892 struct cfg80211_connect_params connect;
9893 struct wiphy *wiphy;
9894 struct cfg80211_cached_keys *connkeys = NULL;
9897 memset(&connect, 0, sizeof(connect));
9899 if (!info->attrs[NL80211_ATTR_SSID] ||
9900 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9903 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
9905 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9906 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
9907 NL80211_CMD_CONNECT))
9910 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
9912 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
9914 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
9915 !wiphy_ext_feature_isset(&rdev->wiphy,
9916 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
9918 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
9920 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
9921 NL80211_MAX_NR_CIPHER_SUITES);
9925 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9926 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9929 wiphy = &rdev->wiphy;
9931 connect.bg_scan_period = -1;
9932 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
9933 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
9934 connect.bg_scan_period =
9935 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
9938 if (info->attrs[NL80211_ATTR_MAC])
9939 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9940 else if (info->attrs[NL80211_ATTR_MAC_HINT])
9941 connect.bssid_hint =
9942 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
9943 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9944 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9946 if (info->attrs[NL80211_ATTR_IE]) {
9947 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9948 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9951 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9952 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
9953 if (connect.mfp == NL80211_MFP_OPTIONAL &&
9954 !wiphy_ext_feature_isset(&rdev->wiphy,
9955 NL80211_EXT_FEATURE_MFP_OPTIONAL))
9958 connect.mfp = NL80211_MFP_NO;
9961 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9962 connect.prev_bssid =
9963 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9965 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9966 connect.channel = nl80211_get_valid_chan(
9967 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9968 if (!connect.channel)
9970 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
9971 connect.channel_hint = nl80211_get_valid_chan(
9972 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9973 if (!connect.channel_hint)
9977 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
9978 connect.edmg.channels =
9979 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
9981 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
9982 connect.edmg.bw_config =
9983 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
9986 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
9987 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
9988 if (IS_ERR(connkeys))
9989 return PTR_ERR(connkeys);
9992 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9993 connect.flags |= ASSOC_REQ_DISABLE_HT;
9995 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9996 memcpy(&connect.ht_capa_mask,
9997 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9998 sizeof(connect.ht_capa_mask));
10000 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
10001 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
10005 memcpy(&connect.ht_capa,
10006 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10007 sizeof(connect.ht_capa));
10010 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
10011 connect.flags |= ASSOC_REQ_DISABLE_VHT;
10013 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
10014 memcpy(&connect.vht_capa_mask,
10015 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
10016 sizeof(connect.vht_capa_mask));
10018 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
10019 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
10023 memcpy(&connect.vht_capa,
10024 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
10025 sizeof(connect.vht_capa));
10028 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
10029 if (!((rdev->wiphy.features &
10030 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
10031 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
10032 !wiphy_ext_feature_isset(&rdev->wiphy,
10033 NL80211_EXT_FEATURE_RRM)) {
10037 connect.flags |= ASSOC_REQ_USE_RRM;
10040 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
10041 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
10043 return -EOPNOTSUPP;
10046 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
10047 /* bss selection makes no sense if bssid is set */
10048 if (connect.bssid) {
10053 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
10054 wiphy, &connect.bss_select);
10061 if (wiphy_ext_feature_isset(&rdev->wiphy,
10062 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10063 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10064 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10065 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10066 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10067 connect.fils_erp_username =
10068 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10069 connect.fils_erp_username_len =
10070 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10071 connect.fils_erp_realm =
10072 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10073 connect.fils_erp_realm_len =
10074 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10075 connect.fils_erp_next_seq_num =
10077 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10078 connect.fils_erp_rrk =
10079 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10080 connect.fils_erp_rrk_len =
10081 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10082 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10083 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10084 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10085 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10090 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10091 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10093 GENL_SET_ERR_MSG(info,
10094 "external auth requires connection ownership");
10097 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
10100 wdev_lock(dev->ieee80211_ptr);
10102 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10103 connect.prev_bssid);
10107 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10108 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10110 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10111 connect.bssid, ETH_ALEN);
10113 memset(dev->ieee80211_ptr->disconnect_bssid,
10117 wdev_unlock(dev->ieee80211_ptr);
10122 static int nl80211_update_connect_params(struct sk_buff *skb,
10123 struct genl_info *info)
10125 struct cfg80211_connect_params connect = {};
10126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10127 struct net_device *dev = info->user_ptr[1];
10128 struct wireless_dev *wdev = dev->ieee80211_ptr;
10129 bool fils_sk_offload;
10134 if (!rdev->ops->update_connect_params)
10135 return -EOPNOTSUPP;
10137 if (info->attrs[NL80211_ATTR_IE]) {
10138 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10139 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10140 changed |= UPDATE_ASSOC_IES;
10143 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
10144 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
10147 * when driver supports fils-sk offload all attributes must be
10148 * provided. So the else covers "fils-sk-not-all" and
10149 * "no-fils-sk-any".
10151 if (fils_sk_offload &&
10152 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10153 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10154 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10155 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10156 connect.fils_erp_username =
10157 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10158 connect.fils_erp_username_len =
10159 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10160 connect.fils_erp_realm =
10161 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10162 connect.fils_erp_realm_len =
10163 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10164 connect.fils_erp_next_seq_num =
10166 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10167 connect.fils_erp_rrk =
10168 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10169 connect.fils_erp_rrk_len =
10170 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10171 changed |= UPDATE_FILS_ERP_INFO;
10172 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10173 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10174 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10175 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10179 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10180 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10181 if (!nl80211_valid_auth_type(rdev, auth_type,
10182 NL80211_CMD_CONNECT))
10185 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
10186 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
10189 connect.auth_type = auth_type;
10190 changed |= UPDATE_AUTH_TYPE;
10193 wdev_lock(dev->ieee80211_ptr);
10194 if (!wdev->current_bss)
10197 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
10198 wdev_unlock(dev->ieee80211_ptr);
10203 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10205 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10206 struct net_device *dev = info->user_ptr[1];
10210 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10211 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10214 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10215 reason = WLAN_REASON_DEAUTH_LEAVING;
10217 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10222 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10223 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10224 return -EOPNOTSUPP;
10226 wdev_lock(dev->ieee80211_ptr);
10227 ret = cfg80211_disconnect(rdev, dev, reason, true);
10228 wdev_unlock(dev->ieee80211_ptr);
10232 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10234 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10238 if (info->attrs[NL80211_ATTR_PID]) {
10239 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10241 net = get_net_ns_by_pid(pid);
10242 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10243 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10245 net = get_net_ns_by_fd(fd);
10251 return PTR_ERR(net);
10255 /* check if anything to do */
10256 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10257 err = cfg80211_switch_netns(rdev, net);
10263 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10266 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10267 struct cfg80211_pmksa *pmksa) = NULL;
10268 struct net_device *dev = info->user_ptr[1];
10269 struct cfg80211_pmksa pmksa;
10271 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10273 if (!info->attrs[NL80211_ATTR_PMKID])
10276 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
10278 if (info->attrs[NL80211_ATTR_MAC]) {
10279 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10280 } else if (info->attrs[NL80211_ATTR_SSID] &&
10281 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10282 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10283 info->attrs[NL80211_ATTR_PMK])) {
10284 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10285 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10287 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10291 if (info->attrs[NL80211_ATTR_PMK]) {
10292 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10293 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10296 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10297 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10298 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10299 wiphy_ext_feature_isset(&rdev->wiphy,
10300 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
10301 return -EOPNOTSUPP;
10303 switch (info->genlhdr->cmd) {
10304 case NL80211_CMD_SET_PMKSA:
10305 rdev_ops = rdev->ops->set_pmksa;
10307 case NL80211_CMD_DEL_PMKSA:
10308 rdev_ops = rdev->ops->del_pmksa;
10316 return -EOPNOTSUPP;
10318 return rdev_ops(&rdev->wiphy, dev, &pmksa);
10321 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10324 struct net_device *dev = info->user_ptr[1];
10326 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10327 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10328 return -EOPNOTSUPP;
10330 if (!rdev->ops->flush_pmksa)
10331 return -EOPNOTSUPP;
10333 return rdev_flush_pmksa(rdev, dev);
10336 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10339 struct net_device *dev = info->user_ptr[1];
10340 u8 action_code, dialog_token;
10341 u32 peer_capability = 0;
10346 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10347 !rdev->ops->tdls_mgmt)
10348 return -EOPNOTSUPP;
10350 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10351 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10352 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10353 !info->attrs[NL80211_ATTR_IE] ||
10354 !info->attrs[NL80211_ATTR_MAC])
10357 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10358 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10359 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10360 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
10361 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
10362 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10364 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
10366 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
10367 dialog_token, status_code, peer_capability,
10369 nla_data(info->attrs[NL80211_ATTR_IE]),
10370 nla_len(info->attrs[NL80211_ATTR_IE]));
10373 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10376 struct net_device *dev = info->user_ptr[1];
10377 enum nl80211_tdls_operation operation;
10380 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10381 !rdev->ops->tdls_oper)
10382 return -EOPNOTSUPP;
10384 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10385 !info->attrs[NL80211_ATTR_MAC])
10388 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10389 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10391 return rdev_tdls_oper(rdev, dev, peer, operation);
10394 static int nl80211_remain_on_channel(struct sk_buff *skb,
10395 struct genl_info *info)
10397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10398 struct wireless_dev *wdev = info->user_ptr[1];
10399 struct cfg80211_chan_def chandef;
10400 const struct cfg80211_chan_def *compat_chandef;
10401 struct sk_buff *msg;
10407 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10408 !info->attrs[NL80211_ATTR_DURATION])
10411 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10413 if (!rdev->ops->remain_on_channel ||
10414 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
10415 return -EOPNOTSUPP;
10418 * We should be on that channel for at least a minimum amount of
10419 * time (10ms) but no longer than the driver supports.
10421 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10422 duration > rdev->wiphy.max_remain_on_channel_duration)
10425 err = nl80211_parse_chandef(rdev, info, &chandef);
10430 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10431 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10432 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10434 if (compat_chandef != &chandef) {
10441 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10445 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10446 NL80211_CMD_REMAIN_ON_CHANNEL);
10452 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10453 duration, &cookie);
10458 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10460 goto nla_put_failure;
10462 genlmsg_end(msg, hdr);
10464 return genlmsg_reply(msg, info);
10473 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10474 struct genl_info *info)
10476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10477 struct wireless_dev *wdev = info->user_ptr[1];
10480 if (!info->attrs[NL80211_ATTR_COOKIE])
10483 if (!rdev->ops->cancel_remain_on_channel)
10484 return -EOPNOTSUPP;
10486 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10488 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
10491 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10492 struct genl_info *info)
10494 struct cfg80211_bitrate_mask mask;
10495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10496 struct net_device *dev = info->user_ptr[1];
10499 if (!rdev->ops->set_bitrate_mask)
10500 return -EOPNOTSUPP;
10502 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10506 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
10509 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
10511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10512 struct wireless_dev *wdev = info->user_ptr[1];
10513 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
10515 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10518 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10519 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
10521 switch (wdev->iftype) {
10522 case NL80211_IFTYPE_STATION:
10523 case NL80211_IFTYPE_ADHOC:
10524 case NL80211_IFTYPE_P2P_CLIENT:
10525 case NL80211_IFTYPE_AP:
10526 case NL80211_IFTYPE_AP_VLAN:
10527 case NL80211_IFTYPE_MESH_POINT:
10528 case NL80211_IFTYPE_P2P_GO:
10529 case NL80211_IFTYPE_P2P_DEVICE:
10531 case NL80211_IFTYPE_NAN:
10533 return -EOPNOTSUPP;
10536 /* not much point in registering if we can't reply */
10537 if (!rdev->ops->mgmt_tx)
10538 return -EOPNOTSUPP;
10540 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
10541 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10542 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
10545 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
10547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10548 struct wireless_dev *wdev = info->user_ptr[1];
10549 struct cfg80211_chan_def chandef;
10553 struct sk_buff *msg = NULL;
10554 struct cfg80211_mgmt_tx_params params = {
10555 .dont_wait_for_ack =
10556 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10559 if (!info->attrs[NL80211_ATTR_FRAME])
10562 if (!rdev->ops->mgmt_tx)
10563 return -EOPNOTSUPP;
10565 switch (wdev->iftype) {
10566 case NL80211_IFTYPE_P2P_DEVICE:
10567 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10569 case NL80211_IFTYPE_STATION:
10570 case NL80211_IFTYPE_ADHOC:
10571 case NL80211_IFTYPE_P2P_CLIENT:
10572 case NL80211_IFTYPE_AP:
10573 case NL80211_IFTYPE_AP_VLAN:
10574 case NL80211_IFTYPE_MESH_POINT:
10575 case NL80211_IFTYPE_P2P_GO:
10577 case NL80211_IFTYPE_NAN:
10579 return -EOPNOTSUPP;
10582 if (info->attrs[NL80211_ATTR_DURATION]) {
10583 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
10585 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10588 * We should wait on the channel for at least a minimum amount
10589 * of time (10ms) but no longer than the driver supports.
10591 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10592 params.wait > rdev->wiphy.max_remain_on_channel_duration)
10596 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
10598 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
10601 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
10603 /* get the channel if any has been specified, otherwise pass NULL to
10604 * the driver. The latter will use the current one
10606 chandef.chan = NULL;
10607 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10608 err = nl80211_parse_chandef(rdev, info, &chandef);
10613 if (!chandef.chan && params.offchan)
10617 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10623 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10624 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10626 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10627 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10630 if (len % sizeof(u16))
10633 params.n_csa_offsets = len / sizeof(u16);
10634 params.csa_offsets =
10635 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10637 /* check that all the offsets fit the frame */
10638 for (i = 0; i < params.n_csa_offsets; i++) {
10639 if (params.csa_offsets[i] >= params.len)
10644 if (!params.dont_wait_for_ack) {
10645 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10649 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10650 NL80211_CMD_FRAME);
10657 params.chan = chandef.chan;
10658 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie);
10663 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10665 goto nla_put_failure;
10667 genlmsg_end(msg, hdr);
10668 return genlmsg_reply(msg, info);
10680 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10683 struct wireless_dev *wdev = info->user_ptr[1];
10686 if (!info->attrs[NL80211_ATTR_COOKIE])
10689 if (!rdev->ops->mgmt_tx_cancel_wait)
10690 return -EOPNOTSUPP;
10692 switch (wdev->iftype) {
10693 case NL80211_IFTYPE_STATION:
10694 case NL80211_IFTYPE_ADHOC:
10695 case NL80211_IFTYPE_P2P_CLIENT:
10696 case NL80211_IFTYPE_AP:
10697 case NL80211_IFTYPE_AP_VLAN:
10698 case NL80211_IFTYPE_P2P_GO:
10699 case NL80211_IFTYPE_P2P_DEVICE:
10701 case NL80211_IFTYPE_NAN:
10703 return -EOPNOTSUPP;
10706 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10708 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
10711 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10714 struct wireless_dev *wdev;
10715 struct net_device *dev = info->user_ptr[1];
10720 if (!info->attrs[NL80211_ATTR_PS_STATE])
10723 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10725 wdev = dev->ieee80211_ptr;
10727 if (!rdev->ops->set_power_mgmt)
10728 return -EOPNOTSUPP;
10730 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10732 if (state == wdev->ps)
10735 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
10741 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10744 enum nl80211_ps_state ps_state;
10745 struct wireless_dev *wdev;
10746 struct net_device *dev = info->user_ptr[1];
10747 struct sk_buff *msg;
10751 wdev = dev->ieee80211_ptr;
10753 if (!rdev->ops->set_power_mgmt)
10754 return -EOPNOTSUPP;
10756 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10760 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10761 NL80211_CMD_GET_POWER_SAVE);
10768 ps_state = NL80211_PS_ENABLED;
10770 ps_state = NL80211_PS_DISABLED;
10772 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10773 goto nla_put_failure;
10775 genlmsg_end(msg, hdr);
10776 return genlmsg_reply(msg, info);
10785 static const struct nla_policy
10786 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
10787 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
10788 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10789 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
10790 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10791 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10792 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
10793 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
10796 static int nl80211_set_cqm_txe(struct genl_info *info,
10797 u32 rate, u32 pkts, u32 intvl)
10799 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10800 struct net_device *dev = info->user_ptr[1];
10801 struct wireless_dev *wdev = dev->ieee80211_ptr;
10803 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
10806 if (!rdev->ops->set_cqm_txe_config)
10807 return -EOPNOTSUPP;
10809 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10810 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10811 return -EOPNOTSUPP;
10813 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
10816 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10817 struct net_device *dev)
10819 struct wireless_dev *wdev = dev->ieee80211_ptr;
10820 s32 last, low, high;
10822 int i, n, low_index;
10825 /* RSSI reporting disabled? */
10826 if (!wdev->cqm_config)
10827 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
10830 * Obtain current RSSI value if possible, if not and no RSSI threshold
10831 * event has been received yet, we should receive an event after a
10832 * connection is established and enough beacons received to calculate
10835 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
10836 rdev->ops->get_station) {
10837 struct station_info sinfo = {};
10840 mac_addr = wdev->current_bss->pub.bssid;
10842 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
10846 cfg80211_sinfo_release_content(&sinfo);
10847 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
10848 wdev->cqm_config->last_rssi_event_value =
10849 (s8) sinfo.rx_beacon_signal_avg;
10852 last = wdev->cqm_config->last_rssi_event_value;
10853 hyst = wdev->cqm_config->rssi_hyst;
10854 n = wdev->cqm_config->n_rssi_thresholds;
10856 for (i = 0; i < n; i++) {
10857 i = array_index_nospec(i, n);
10858 if (last < wdev->cqm_config->rssi_thresholds[i])
10863 if (low_index >= 0) {
10864 low_index = array_index_nospec(low_index, n);
10865 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
10870 i = array_index_nospec(i, n);
10871 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
10876 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
10879 static int nl80211_set_cqm_rssi(struct genl_info *info,
10880 const s32 *thresholds, int n_thresholds,
10883 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10884 struct net_device *dev = info->user_ptr[1];
10885 struct wireless_dev *wdev = dev->ieee80211_ptr;
10887 s32 prev = S32_MIN;
10889 /* Check all values negative and sorted */
10890 for (i = 0; i < n_thresholds; i++) {
10891 if (thresholds[i] > 0 || thresholds[i] <= prev)
10894 prev = thresholds[i];
10897 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10898 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10899 return -EOPNOTSUPP;
10902 cfg80211_cqm_config_free(wdev);
10905 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
10906 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
10907 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
10909 return rdev_set_cqm_rssi_config(rdev, dev,
10910 thresholds[0], hysteresis);
10913 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10914 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
10915 return -EOPNOTSUPP;
10917 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
10921 if (n_thresholds) {
10922 struct cfg80211_cqm_config *cqm_config;
10924 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
10925 n_thresholds * sizeof(s32), GFP_KERNEL);
10931 cqm_config->rssi_hyst = hysteresis;
10932 cqm_config->n_rssi_thresholds = n_thresholds;
10933 memcpy(cqm_config->rssi_thresholds, thresholds,
10934 n_thresholds * sizeof(s32));
10936 wdev->cqm_config = cqm_config;
10939 err = cfg80211_cqm_rssi_update(rdev, dev);
10947 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10949 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
10950 struct nlattr *cqm;
10953 cqm = info->attrs[NL80211_ATTR_CQM];
10957 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
10958 nl80211_attr_cqm_policy,
10963 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
10964 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
10965 const s32 *thresholds =
10966 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10967 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
10968 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
10973 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
10977 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
10978 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
10979 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
10980 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
10981 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
10982 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
10984 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
10990 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
10992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10993 struct net_device *dev = info->user_ptr[1];
10994 struct ocb_setup setup = {};
10997 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11001 return cfg80211_join_ocb(rdev, dev, &setup);
11004 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
11006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11007 struct net_device *dev = info->user_ptr[1];
11009 return cfg80211_leave_ocb(rdev, dev);
11012 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
11014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11015 struct net_device *dev = info->user_ptr[1];
11016 struct mesh_config cfg;
11017 struct mesh_setup setup;
11020 /* start with default */
11021 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
11022 memcpy(&setup, &default_mesh_setup, sizeof(setup));
11024 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
11025 /* and parse parameters if given */
11026 err = nl80211_parse_mesh_config(info, &cfg, NULL);
11031 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
11032 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
11035 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
11036 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
11038 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11039 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
11040 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11043 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
11044 setup.beacon_interval =
11045 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
11047 err = cfg80211_validate_beacon_int(rdev,
11048 NL80211_IFTYPE_MESH_POINT,
11049 setup.beacon_interval);
11054 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
11055 setup.dtim_period =
11056 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
11057 if (setup.dtim_period < 1 || setup.dtim_period > 100)
11061 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
11062 /* parse additional setup parameters if given */
11063 err = nl80211_parse_mesh_setup(info, &setup);
11068 if (setup.user_mpm)
11069 cfg.auto_open_plinks = false;
11071 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
11072 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11076 /* __cfg80211_join_mesh() will sort it out */
11077 setup.chandef.chan = NULL;
11080 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11081 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11083 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11084 struct ieee80211_supported_band *sband;
11086 if (!setup.chandef.chan)
11089 sband = rdev->wiphy.bands[setup.chandef.chan->band];
11091 err = ieee80211_get_ratemask(sband, rates, n_rates,
11092 &setup.basic_rates);
11097 if (info->attrs[NL80211_ATTR_TX_RATES]) {
11098 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
11102 if (!setup.chandef.chan)
11105 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11106 &setup.beacon_rate);
11111 setup.userspace_handles_dfs =
11112 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11114 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11115 int r = validate_pae_over_nl80211(rdev, info);
11120 setup.control_port_over_nl80211 = true;
11123 wdev_lock(dev->ieee80211_ptr);
11124 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
11125 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
11126 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11127 wdev_unlock(dev->ieee80211_ptr);
11132 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
11134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11135 struct net_device *dev = info->user_ptr[1];
11137 return cfg80211_leave_mesh(rdev, dev);
11141 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11142 struct cfg80211_registered_device *rdev)
11144 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
11145 struct nlattr *nl_pats, *nl_pat;
11148 if (!wowlan->n_patterns)
11151 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
11155 for (i = 0; i < wowlan->n_patterns; i++) {
11156 nl_pat = nla_nest_start_noflag(msg, i + 1);
11159 pat_len = wowlan->patterns[i].pattern_len;
11160 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
11161 wowlan->patterns[i].mask) ||
11162 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11163 wowlan->patterns[i].pattern) ||
11164 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11165 wowlan->patterns[i].pkt_offset))
11167 nla_nest_end(msg, nl_pat);
11169 nla_nest_end(msg, nl_pats);
11174 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
11175 struct cfg80211_wowlan_tcp *tcp)
11177 struct nlattr *nl_tcp;
11182 nl_tcp = nla_nest_start_noflag(msg,
11183 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
11187 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
11188 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
11189 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
11190 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
11191 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
11192 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
11193 tcp->payload_len, tcp->payload) ||
11194 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
11195 tcp->data_interval) ||
11196 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
11197 tcp->wake_len, tcp->wake_data) ||
11198 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
11199 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
11202 if (tcp->payload_seq.len &&
11203 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
11204 sizeof(tcp->payload_seq), &tcp->payload_seq))
11207 if (tcp->payload_tok.len &&
11208 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11209 sizeof(tcp->payload_tok) + tcp->tokens_size,
11210 &tcp->payload_tok))
11213 nla_nest_end(msg, nl_tcp);
11218 static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11219 struct cfg80211_sched_scan_request *req)
11221 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
11227 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
11231 if (req->n_scan_plans == 1 &&
11232 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11233 req->scan_plans[0].interval * 1000))
11236 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11239 if (req->relative_rssi_set) {
11240 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11242 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11243 req->relative_rssi))
11246 rssi_adjust.band = req->rssi_adjust.band;
11247 rssi_adjust.delta = req->rssi_adjust.delta;
11248 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11249 sizeof(rssi_adjust), &rssi_adjust))
11253 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11257 for (i = 0; i < req->n_channels; i++) {
11258 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11262 nla_nest_end(msg, freqs);
11264 if (req->n_match_sets) {
11265 matches = nla_nest_start_noflag(msg,
11266 NL80211_ATTR_SCHED_SCAN_MATCH);
11270 for (i = 0; i < req->n_match_sets; i++) {
11271 match = nla_nest_start_noflag(msg, i);
11275 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11276 req->match_sets[i].ssid.ssid_len,
11277 req->match_sets[i].ssid.ssid))
11279 nla_nest_end(msg, match);
11281 nla_nest_end(msg, matches);
11284 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
11288 for (i = 0; i < req->n_scan_plans; i++) {
11289 scan_plan = nla_nest_start_noflag(msg, i + 1);
11293 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
11294 req->scan_plans[i].interval) ||
11295 (req->scan_plans[i].iterations &&
11296 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11297 req->scan_plans[i].iterations)))
11299 nla_nest_end(msg, scan_plan);
11301 nla_nest_end(msg, scan_plans);
11303 nla_nest_end(msg, nd);
11308 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11311 struct sk_buff *msg;
11313 u32 size = NLMSG_DEFAULT_SIZE;
11315 if (!rdev->wiphy.wowlan)
11316 return -EOPNOTSUPP;
11318 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
11319 /* adjust size to have room for all the data */
11320 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11321 rdev->wiphy.wowlan_config->tcp->payload_len +
11322 rdev->wiphy.wowlan_config->tcp->wake_len +
11323 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
11326 msg = nlmsg_new(size, GFP_KERNEL);
11330 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11331 NL80211_CMD_GET_WOWLAN);
11333 goto nla_put_failure;
11335 if (rdev->wiphy.wowlan_config) {
11336 struct nlattr *nl_wowlan;
11338 nl_wowlan = nla_nest_start_noflag(msg,
11339 NL80211_ATTR_WOWLAN_TRIGGERS);
11341 goto nla_put_failure;
11343 if ((rdev->wiphy.wowlan_config->any &&
11344 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
11345 (rdev->wiphy.wowlan_config->disconnect &&
11346 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
11347 (rdev->wiphy.wowlan_config->magic_pkt &&
11348 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
11349 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
11350 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
11351 (rdev->wiphy.wowlan_config->eap_identity_req &&
11352 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
11353 (rdev->wiphy.wowlan_config->four_way_handshake &&
11354 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
11355 (rdev->wiphy.wowlan_config->rfkill_release &&
11356 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11357 goto nla_put_failure;
11359 if (nl80211_send_wowlan_patterns(msg, rdev))
11360 goto nla_put_failure;
11362 if (nl80211_send_wowlan_tcp(msg,
11363 rdev->wiphy.wowlan_config->tcp))
11364 goto nla_put_failure;
11366 if (nl80211_send_wowlan_nd(
11368 rdev->wiphy.wowlan_config->nd_config))
11369 goto nla_put_failure;
11371 nla_nest_end(msg, nl_wowlan);
11374 genlmsg_end(msg, hdr);
11375 return genlmsg_reply(msg, info);
11382 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11383 struct nlattr *attr,
11384 struct cfg80211_wowlan *trig)
11386 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11387 struct cfg80211_wowlan_tcp *cfg;
11388 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11389 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11391 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11394 if (!rdev->wiphy.wowlan->tcp)
11397 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11398 nl80211_wowlan_tcp_policy, NULL);
11402 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11403 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11404 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11405 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11406 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11407 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11408 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11409 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11412 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
11413 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
11416 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
11417 rdev->wiphy.wowlan->tcp->data_interval_max ||
11418 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
11421 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
11422 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
11425 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11426 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11429 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11430 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11432 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11433 tokens_size = tokln - sizeof(*tok);
11435 if (!tok->len || tokens_size % tok->len)
11437 if (!rdev->wiphy.wowlan->tcp->tok)
11439 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
11441 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
11443 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
11445 if (tok->offset + tok->len > data_size)
11449 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11450 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
11451 if (!rdev->wiphy.wowlan->tcp->seq)
11453 if (seq->len == 0 || seq->len > 4)
11455 if (seq->len + seq->offset > data_size)
11459 size = sizeof(*cfg);
11461 size += wake_size + wake_mask_size;
11462 size += tokens_size;
11464 cfg = kzalloc(size, GFP_KERNEL);
11467 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11468 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
11469 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11471 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11472 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11476 /* allocate a socket and port for it and use it */
11477 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11478 IPPROTO_TCP, &cfg->sock, 1);
11483 if (inet_csk_get_port(cfg->sock->sk, port)) {
11484 sock_release(cfg->sock);
11486 return -EADDRINUSE;
11488 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11494 cfg->src_port = port;
11497 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11498 cfg->payload_len = data_size;
11499 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11500 memcpy((void *)cfg->payload,
11501 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11504 cfg->payload_seq = *seq;
11505 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11506 cfg->wake_len = wake_size;
11507 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11508 memcpy((void *)cfg->wake_data,
11509 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11511 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11512 data_size + wake_size;
11513 memcpy((void *)cfg->wake_mask,
11514 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11517 cfg->tokens_size = tokens_size;
11518 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11526 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11527 const struct wiphy_wowlan_support *wowlan,
11528 struct nlattr *attr,
11529 struct cfg80211_wowlan *trig)
11531 struct nlattr **tb;
11534 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
11538 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11543 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11544 nl80211_policy, NULL);
11548 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11549 wowlan->max_nd_match_sets);
11550 err = PTR_ERR_OR_ZERO(trig->nd_config);
11552 trig->nd_config = NULL;
11559 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11562 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
11563 struct cfg80211_wowlan new_triggers = {};
11564 struct cfg80211_wowlan *ntrig;
11565 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
11567 bool prev_enabled = rdev->wiphy.wowlan_config;
11568 bool regular = false;
11571 return -EOPNOTSUPP;
11573 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11574 cfg80211_rdev_free_wowlan(rdev);
11575 rdev->wiphy.wowlan_config = NULL;
11579 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11580 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11581 nl80211_wowlan_policy, info->extack);
11585 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11586 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11588 new_triggers.any = true;
11591 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11592 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11594 new_triggers.disconnect = true;
11598 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11599 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11601 new_triggers.magic_pkt = true;
11605 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11608 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11609 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11611 new_triggers.gtk_rekey_failure = true;
11615 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11616 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11618 new_triggers.eap_identity_req = true;
11622 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11623 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11625 new_triggers.four_way_handshake = true;
11629 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11630 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11632 new_triggers.rfkill_release = true;
11636 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11637 struct nlattr *pat;
11638 int n_patterns = 0;
11639 int rem, pat_len, mask_len, pkt_offset;
11640 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11644 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11647 if (n_patterns > wowlan->n_patterns)
11650 new_triggers.patterns = kcalloc(n_patterns,
11651 sizeof(new_triggers.patterns[0]),
11653 if (!new_triggers.patterns)
11656 new_triggers.n_patterns = n_patterns;
11659 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11663 err = nla_parse_nested_deprecated(pat_tb,
11664 MAX_NL80211_PKTPAT,
11666 nl80211_packet_pattern_policy,
11672 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11673 !pat_tb[NL80211_PKTPAT_PATTERN])
11675 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11676 mask_len = DIV_ROUND_UP(pat_len, 8);
11677 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11679 if (pat_len > wowlan->pattern_max_len ||
11680 pat_len < wowlan->pattern_min_len)
11683 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11686 pkt_offset = nla_get_u32(
11687 pat_tb[NL80211_PKTPAT_OFFSET]);
11688 if (pkt_offset > wowlan->max_pkt_offset)
11690 new_triggers.patterns[i].pkt_offset = pkt_offset;
11692 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11697 new_triggers.patterns[i].mask = mask_pat;
11698 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11700 mask_pat += mask_len;
11701 new_triggers.patterns[i].pattern = mask_pat;
11702 new_triggers.patterns[i].pattern_len = pat_len;
11704 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11710 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
11712 err = nl80211_parse_wowlan_tcp(
11713 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11719 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
11721 err = nl80211_parse_wowlan_nd(
11722 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11728 /* The 'any' trigger means the device continues operating more or less
11729 * as in its normal operation mode and wakes up the host on most of the
11730 * normal interrupts (like packet RX, ...)
11731 * It therefore makes little sense to combine with the more constrained
11732 * wakeup trigger modes.
11734 if (new_triggers.any && regular) {
11739 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11744 cfg80211_rdev_free_wowlan(rdev);
11745 rdev->wiphy.wowlan_config = ntrig;
11748 if (rdev->ops->set_wakeup &&
11749 prev_enabled != !!rdev->wiphy.wowlan_config)
11750 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
11754 for (i = 0; i < new_triggers.n_patterns; i++)
11755 kfree(new_triggers.patterns[i].mask);
11756 kfree(new_triggers.patterns);
11757 if (new_triggers.tcp && new_triggers.tcp->sock)
11758 sock_release(new_triggers.tcp->sock);
11759 kfree(new_triggers.tcp);
11760 kfree(new_triggers.nd_config);
11765 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11766 struct cfg80211_registered_device *rdev)
11768 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11770 struct cfg80211_coalesce_rules *rule;
11772 if (!rdev->coalesce->n_rules)
11775 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
11779 for (i = 0; i < rdev->coalesce->n_rules; i++) {
11780 nl_rule = nla_nest_start_noflag(msg, i + 1);
11784 rule = &rdev->coalesce->rules[i];
11785 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11789 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11793 nl_pats = nla_nest_start_noflag(msg,
11794 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
11798 for (j = 0; j < rule->n_patterns; j++) {
11799 nl_pat = nla_nest_start_noflag(msg, j + 1);
11802 pat_len = rule->patterns[j].pattern_len;
11803 if (nla_put(msg, NL80211_PKTPAT_MASK,
11804 DIV_ROUND_UP(pat_len, 8),
11805 rule->patterns[j].mask) ||
11806 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11807 rule->patterns[j].pattern) ||
11808 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11809 rule->patterns[j].pkt_offset))
11811 nla_nest_end(msg, nl_pat);
11813 nla_nest_end(msg, nl_pats);
11814 nla_nest_end(msg, nl_rule);
11816 nla_nest_end(msg, nl_rules);
11821 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
11823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11824 struct sk_buff *msg;
11827 if (!rdev->wiphy.coalesce)
11828 return -EOPNOTSUPP;
11830 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11834 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11835 NL80211_CMD_GET_COALESCE);
11837 goto nla_put_failure;
11839 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
11840 goto nla_put_failure;
11842 genlmsg_end(msg, hdr);
11843 return genlmsg_reply(msg, info);
11850 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
11852 struct cfg80211_coalesce *coalesce = rdev->coalesce;
11854 struct cfg80211_coalesce_rules *rule;
11859 for (i = 0; i < coalesce->n_rules; i++) {
11860 rule = &coalesce->rules[i];
11861 for (j = 0; j < rule->n_patterns; j++)
11862 kfree(rule->patterns[j].mask);
11863 kfree(rule->patterns);
11865 kfree(coalesce->rules);
11867 rdev->coalesce = NULL;
11870 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11871 struct nlattr *rule,
11872 struct cfg80211_coalesce_rules *new_rule)
11875 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11876 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
11877 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11878 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11880 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
11881 rule, nl80211_coalesce_policy, NULL);
11885 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
11887 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
11888 if (new_rule->delay > coalesce->max_delay)
11891 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
11892 new_rule->condition =
11893 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
11895 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
11898 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11901 if (n_patterns > coalesce->n_patterns)
11904 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
11906 if (!new_rule->patterns)
11909 new_rule->n_patterns = n_patterns;
11912 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
11916 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
11918 nl80211_packet_pattern_policy,
11923 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11924 !pat_tb[NL80211_PKTPAT_PATTERN])
11926 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11927 mask_len = DIV_ROUND_UP(pat_len, 8);
11928 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11930 if (pat_len > coalesce->pattern_max_len ||
11931 pat_len < coalesce->pattern_min_len)
11934 if (!pat_tb[NL80211_PKTPAT_OFFSET])
11937 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
11938 if (pkt_offset > coalesce->max_pkt_offset)
11940 new_rule->patterns[i].pkt_offset = pkt_offset;
11942 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11946 new_rule->patterns[i].mask = mask_pat;
11947 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
11950 mask_pat += mask_len;
11951 new_rule->patterns[i].pattern = mask_pat;
11952 new_rule->patterns[i].pattern_len = pat_len;
11953 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
11961 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
11963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11964 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
11965 struct cfg80211_coalesce new_coalesce = {};
11966 struct cfg80211_coalesce *n_coalesce;
11967 int err, rem_rule, n_rules = 0, i, j;
11968 struct nlattr *rule;
11969 struct cfg80211_coalesce_rules *tmp_rule;
11971 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
11972 return -EOPNOTSUPP;
11974 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
11975 cfg80211_rdev_free_coalesce(rdev);
11976 rdev_set_coalesce(rdev, NULL);
11980 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11983 if (n_rules > coalesce->n_rules)
11986 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
11988 if (!new_coalesce.rules)
11991 new_coalesce.n_rules = n_rules;
11994 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
11996 err = nl80211_parse_coalesce_rule(rdev, rule,
11997 &new_coalesce.rules[i]);
12004 err = rdev_set_coalesce(rdev, &new_coalesce);
12008 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
12013 cfg80211_rdev_free_coalesce(rdev);
12014 rdev->coalesce = n_coalesce;
12018 for (i = 0; i < new_coalesce.n_rules; i++) {
12019 tmp_rule = &new_coalesce.rules[i];
12020 for (j = 0; j < tmp_rule->n_patterns; j++)
12021 kfree(tmp_rule->patterns[j].mask);
12022 kfree(tmp_rule->patterns);
12024 kfree(new_coalesce.rules);
12029 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
12031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12032 struct net_device *dev = info->user_ptr[1];
12033 struct wireless_dev *wdev = dev->ieee80211_ptr;
12034 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
12035 struct cfg80211_gtk_rekey_data rekey_data;
12038 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
12041 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
12042 info->attrs[NL80211_ATTR_REKEY_DATA],
12043 nl80211_rekey_policy, info->extack);
12047 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
12048 !tb[NL80211_REKEY_DATA_KCK])
12050 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
12052 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
12054 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
12057 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
12058 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
12059 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
12062 if (!wdev->current_bss) {
12067 if (!rdev->ops->set_rekey_data) {
12072 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
12078 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
12079 struct genl_info *info)
12081 struct net_device *dev = info->user_ptr[1];
12082 struct wireless_dev *wdev = dev->ieee80211_ptr;
12084 if (wdev->iftype != NL80211_IFTYPE_AP &&
12085 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12088 if (wdev->ap_unexpected_nlportid)
12091 wdev->ap_unexpected_nlportid = info->snd_portid;
12095 static int nl80211_probe_client(struct sk_buff *skb,
12096 struct genl_info *info)
12098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12099 struct net_device *dev = info->user_ptr[1];
12100 struct wireless_dev *wdev = dev->ieee80211_ptr;
12101 struct sk_buff *msg;
12107 if (wdev->iftype != NL80211_IFTYPE_AP &&
12108 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12109 return -EOPNOTSUPP;
12111 if (!info->attrs[NL80211_ATTR_MAC])
12114 if (!rdev->ops->probe_client)
12115 return -EOPNOTSUPP;
12117 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12121 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12122 NL80211_CMD_PROBE_CLIENT);
12128 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12130 err = rdev_probe_client(rdev, dev, addr, &cookie);
12134 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12136 goto nla_put_failure;
12138 genlmsg_end(msg, hdr);
12140 return genlmsg_reply(msg, info);
12149 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12152 struct cfg80211_beacon_registration *reg, *nreg;
12155 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12156 return -EOPNOTSUPP;
12158 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12162 /* First, check if already registered. */
12163 spin_lock_bh(&rdev->beacon_registrations_lock);
12164 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12165 if (reg->nlportid == info->snd_portid) {
12170 /* Add it to the list */
12171 nreg->nlportid = info->snd_portid;
12172 list_add(&nreg->list, &rdev->beacon_registrations);
12174 spin_unlock_bh(&rdev->beacon_registrations_lock);
12178 spin_unlock_bh(&rdev->beacon_registrations_lock);
12183 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
12185 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12186 struct wireless_dev *wdev = info->user_ptr[1];
12189 if (!rdev->ops->start_p2p_device)
12190 return -EOPNOTSUPP;
12192 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12193 return -EOPNOTSUPP;
12195 if (wdev_running(wdev))
12198 if (rfkill_blocked(rdev->rfkill))
12201 err = rdev_start_p2p_device(rdev, wdev);
12205 wdev->is_running = true;
12211 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12214 struct wireless_dev *wdev = info->user_ptr[1];
12216 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12217 return -EOPNOTSUPP;
12219 if (!rdev->ops->stop_p2p_device)
12220 return -EOPNOTSUPP;
12222 cfg80211_stop_p2p_device(rdev, wdev);
12227 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12230 struct wireless_dev *wdev = info->user_ptr[1];
12231 struct cfg80211_nan_conf conf = {};
12234 if (wdev->iftype != NL80211_IFTYPE_NAN)
12235 return -EOPNOTSUPP;
12237 if (wdev_running(wdev))
12240 if (rfkill_blocked(rdev->rfkill))
12243 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12247 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12249 if (info->attrs[NL80211_ATTR_BANDS]) {
12250 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12252 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12253 return -EOPNOTSUPP;
12255 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12258 conf.bands = bands;
12261 err = rdev_start_nan(rdev, wdev, &conf);
12265 wdev->is_running = true;
12271 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12274 struct wireless_dev *wdev = info->user_ptr[1];
12276 if (wdev->iftype != NL80211_IFTYPE_NAN)
12277 return -EOPNOTSUPP;
12279 cfg80211_stop_nan(rdev, wdev);
12284 static int validate_nan_filter(struct nlattr *filter_attr)
12286 struct nlattr *attr;
12287 int len = 0, n_entries = 0, rem;
12289 nla_for_each_nested(attr, filter_attr, rem) {
12290 len += nla_len(attr);
12300 static int handle_nan_filter(struct nlattr *attr_filter,
12301 struct cfg80211_nan_func *func,
12304 struct nlattr *attr;
12305 int n_entries, rem, i;
12306 struct cfg80211_nan_func_filter *filter;
12308 n_entries = validate_nan_filter(attr_filter);
12312 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12314 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12319 nla_for_each_nested(attr, attr_filter, rem) {
12320 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
12321 filter[i].len = nla_len(attr);
12325 func->num_tx_filters = n_entries;
12326 func->tx_filters = filter;
12328 func->num_rx_filters = n_entries;
12329 func->rx_filters = filter;
12335 static int nl80211_nan_add_func(struct sk_buff *skb,
12336 struct genl_info *info)
12338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12339 struct wireless_dev *wdev = info->user_ptr[1];
12340 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12341 struct cfg80211_nan_func *func;
12342 struct sk_buff *msg = NULL;
12346 if (wdev->iftype != NL80211_IFTYPE_NAN)
12347 return -EOPNOTSUPP;
12349 if (!wdev_running(wdev))
12352 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12355 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12356 info->attrs[NL80211_ATTR_NAN_FUNC],
12357 nl80211_nan_func_policy,
12362 func = kzalloc(sizeof(*func), GFP_KERNEL);
12366 func->cookie = cfg80211_assign_cookie(rdev);
12368 if (!tb[NL80211_NAN_FUNC_TYPE] ||
12369 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
12375 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12377 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12382 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12383 sizeof(func->service_id));
12385 func->close_range =
12386 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12388 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12389 func->serv_spec_info_len =
12390 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12391 func->serv_spec_info =
12392 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12393 func->serv_spec_info_len,
12395 if (!func->serv_spec_info) {
12401 if (tb[NL80211_NAN_FUNC_TTL])
12402 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12404 switch (func->type) {
12405 case NL80211_NAN_FUNC_PUBLISH:
12406 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12411 func->publish_type =
12412 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12413 func->publish_bcast =
12414 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12416 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12417 func->publish_bcast) {
12422 case NL80211_NAN_FUNC_SUBSCRIBE:
12423 func->subscribe_active =
12424 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12426 case NL80211_NAN_FUNC_FOLLOW_UP:
12427 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
12428 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12429 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
12434 func->followup_id =
12435 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12436 func->followup_reqid =
12437 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12438 memcpy(func->followup_dest.addr,
12439 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12440 sizeof(func->followup_dest.addr));
12451 if (tb[NL80211_NAN_FUNC_SRF]) {
12452 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12454 err = nla_parse_nested_deprecated(srf_tb,
12455 NL80211_NAN_SRF_ATTR_MAX,
12456 tb[NL80211_NAN_FUNC_SRF],
12457 nl80211_nan_srf_policy,
12462 func->srf_include =
12463 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12465 if (srf_tb[NL80211_NAN_SRF_BF]) {
12466 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12467 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12473 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12475 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12476 func->srf_bf_len, GFP_KERNEL);
12477 if (!func->srf_bf) {
12483 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12485 struct nlattr *attr, *mac_attr =
12486 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12487 int n_entries, rem, i = 0;
12494 n_entries = validate_acl_mac_addrs(mac_attr);
12495 if (n_entries <= 0) {
12500 func->srf_num_macs = n_entries;
12502 kcalloc(n_entries, sizeof(*func->srf_macs),
12504 if (!func->srf_macs) {
12509 nla_for_each_nested(attr, mac_attr, rem)
12510 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12511 sizeof(*func->srf_macs));
12515 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12516 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12522 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12523 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12529 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12535 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12536 NL80211_CMD_ADD_NAN_FUNCTION);
12537 /* This can't really happen - we just allocated 4KB */
12538 if (WARN_ON(!hdr)) {
12543 err = rdev_add_nan_func(rdev, wdev, func);
12546 cfg80211_free_nan_func(func);
12551 /* propagate the instance id and cookie to userspace */
12552 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12554 goto nla_put_failure;
12556 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
12558 goto nla_put_failure;
12560 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12561 func->instance_id))
12562 goto nla_put_failure;
12564 nla_nest_end(msg, func_attr);
12566 genlmsg_end(msg, hdr);
12567 return genlmsg_reply(msg, info);
12574 static int nl80211_nan_del_func(struct sk_buff *skb,
12575 struct genl_info *info)
12577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12578 struct wireless_dev *wdev = info->user_ptr[1];
12581 if (wdev->iftype != NL80211_IFTYPE_NAN)
12582 return -EOPNOTSUPP;
12584 if (!wdev_running(wdev))
12587 if (!info->attrs[NL80211_ATTR_COOKIE])
12590 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12592 rdev_del_nan_func(rdev, wdev, cookie);
12597 static int nl80211_nan_change_config(struct sk_buff *skb,
12598 struct genl_info *info)
12600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12601 struct wireless_dev *wdev = info->user_ptr[1];
12602 struct cfg80211_nan_conf conf = {};
12605 if (wdev->iftype != NL80211_IFTYPE_NAN)
12606 return -EOPNOTSUPP;
12608 if (!wdev_running(wdev))
12611 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12613 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12614 if (conf.master_pref <= 1 || conf.master_pref == 255)
12617 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12620 if (info->attrs[NL80211_ATTR_BANDS]) {
12621 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12623 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12624 return -EOPNOTSUPP;
12626 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12629 conf.bands = bands;
12630 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
12636 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12639 void cfg80211_nan_match(struct wireless_dev *wdev,
12640 struct cfg80211_nan_match_params *match, gfp_t gfp)
12642 struct wiphy *wiphy = wdev->wiphy;
12643 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12644 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12645 struct sk_buff *msg;
12648 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12651 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12655 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12661 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12662 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12663 wdev->netdev->ifindex)) ||
12664 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12666 goto nla_put_failure;
12668 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12669 NL80211_ATTR_PAD) ||
12670 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12671 goto nla_put_failure;
12673 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
12675 goto nla_put_failure;
12677 local_func_attr = nla_nest_start_noflag(msg,
12678 NL80211_NAN_MATCH_FUNC_LOCAL);
12679 if (!local_func_attr)
12680 goto nla_put_failure;
12682 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12683 goto nla_put_failure;
12685 nla_nest_end(msg, local_func_attr);
12687 peer_func_attr = nla_nest_start_noflag(msg,
12688 NL80211_NAN_MATCH_FUNC_PEER);
12689 if (!peer_func_attr)
12690 goto nla_put_failure;
12692 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12693 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12694 goto nla_put_failure;
12696 if (match->info && match->info_len &&
12697 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12699 goto nla_put_failure;
12701 nla_nest_end(msg, peer_func_attr);
12702 nla_nest_end(msg, match_attr);
12703 genlmsg_end(msg, hdr);
12705 if (!wdev->owner_nlportid)
12706 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12707 msg, 0, NL80211_MCGRP_NAN, gfp);
12709 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12710 wdev->owner_nlportid);
12717 EXPORT_SYMBOL(cfg80211_nan_match);
12719 void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12721 enum nl80211_nan_func_term_reason reason,
12722 u64 cookie, gfp_t gfp)
12724 struct wiphy *wiphy = wdev->wiphy;
12725 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12726 struct sk_buff *msg;
12727 struct nlattr *func_attr;
12730 if (WARN_ON(!inst_id))
12733 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12737 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12743 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12744 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12745 wdev->netdev->ifindex)) ||
12746 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12748 goto nla_put_failure;
12750 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12752 goto nla_put_failure;
12754 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
12756 goto nla_put_failure;
12758 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12759 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12760 goto nla_put_failure;
12762 nla_nest_end(msg, func_attr);
12763 genlmsg_end(msg, hdr);
12765 if (!wdev->owner_nlportid)
12766 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12767 msg, 0, NL80211_MCGRP_NAN, gfp);
12769 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12770 wdev->owner_nlportid);
12777 EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12779 static int nl80211_get_protocol_features(struct sk_buff *skb,
12780 struct genl_info *info)
12783 struct sk_buff *msg;
12785 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12789 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12790 NL80211_CMD_GET_PROTOCOL_FEATURES);
12792 goto nla_put_failure;
12794 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12795 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12796 goto nla_put_failure;
12798 genlmsg_end(msg, hdr);
12799 return genlmsg_reply(msg, info);
12806 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12809 struct cfg80211_update_ft_ies_params ft_params;
12810 struct net_device *dev = info->user_ptr[1];
12812 if (!rdev->ops->update_ft_ies)
12813 return -EOPNOTSUPP;
12815 if (!info->attrs[NL80211_ATTR_MDID] ||
12816 !info->attrs[NL80211_ATTR_IE])
12819 memset(&ft_params, 0, sizeof(ft_params));
12820 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
12821 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12822 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12824 return rdev_update_ft_ies(rdev, dev, &ft_params);
12827 static int nl80211_crit_protocol_start(struct sk_buff *skb,
12828 struct genl_info *info)
12830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12831 struct wireless_dev *wdev = info->user_ptr[1];
12832 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
12836 if (!rdev->ops->crit_proto_start)
12837 return -EOPNOTSUPP;
12839 if (WARN_ON(!rdev->ops->crit_proto_stop))
12842 if (rdev->crit_proto_nlportid)
12845 /* determine protocol if provided */
12846 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
12847 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
12849 if (proto >= NUM_NL80211_CRIT_PROTO)
12852 /* timeout must be provided */
12853 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
12857 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
12859 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
12862 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
12864 rdev->crit_proto_nlportid = info->snd_portid;
12869 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
12870 struct genl_info *info)
12872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12873 struct wireless_dev *wdev = info->user_ptr[1];
12875 if (!rdev->ops->crit_proto_stop)
12876 return -EOPNOTSUPP;
12878 if (rdev->crit_proto_nlportid) {
12879 rdev->crit_proto_nlportid = 0;
12880 rdev_crit_proto_stop(rdev, wdev);
12885 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
12886 struct nlattr *attr,
12887 struct netlink_ext_ack *extack)
12889 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
12890 if (attr->nla_type & NLA_F_NESTED) {
12891 NL_SET_ERR_MSG_ATTR(extack, attr,
12892 "unexpected nested data");
12899 if (!(attr->nla_type & NLA_F_NESTED)) {
12900 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
12904 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
12907 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
12909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12910 struct wireless_dev *wdev =
12911 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
12915 if (!rdev->wiphy.vendor_commands)
12916 return -EOPNOTSUPP;
12918 if (IS_ERR(wdev)) {
12919 err = PTR_ERR(wdev);
12920 if (err != -EINVAL)
12923 } else if (wdev->wiphy != &rdev->wiphy) {
12927 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
12928 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
12931 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
12932 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
12933 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
12934 const struct wiphy_vendor_command *vcmd;
12938 vcmd = &rdev->wiphy.vendor_commands[i];
12940 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
12943 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12944 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12947 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12951 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
12952 if (!wdev_running(wdev))
12957 return -EOPNOTSUPP;
12962 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
12963 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12964 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
12966 err = nl80211_vendor_check_policy(vcmd,
12967 info->attrs[NL80211_ATTR_VENDOR_DATA],
12973 rdev->cur_cmd_info = info;
12974 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
12975 rdev->cur_cmd_info = NULL;
12979 return -EOPNOTSUPP;
12982 static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12983 struct netlink_callback *cb,
12984 struct cfg80211_registered_device **rdev,
12985 struct wireless_dev **wdev)
12987 struct nlattr **attrbuf;
12993 unsigned int data_len = 0;
12996 /* subtract the 1 again here */
12997 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
12998 struct wireless_dev *tmp;
13002 *rdev = wiphy_to_rdev(wiphy);
13006 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
13007 if (tmp->identifier == cb->args[1] - 1) {
13014 /* keep rtnl locked in successful case */
13018 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
13022 err = nlmsg_parse_deprecated(cb->nlh,
13023 GENL_HDRLEN + nl80211_fam.hdrsize,
13024 attrbuf, nl80211_fam.maxattr,
13025 nl80211_policy, NULL);
13029 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
13030 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
13035 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
13039 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
13040 if (IS_ERR(*rdev)) {
13041 err = PTR_ERR(*rdev);
13045 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
13046 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
13048 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
13049 const struct wiphy_vendor_command *vcmd;
13051 vcmd = &(*rdev)->wiphy.vendor_commands[i];
13053 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13056 if (!vcmd->dumpit) {
13065 if (vcmd_idx < 0) {
13070 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
13071 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13072 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13074 err = nl80211_vendor_check_policy(
13075 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
13076 attrbuf[NL80211_ATTR_VENDOR_DATA],
13082 /* 0 is the first index - add 1 to parse only once */
13083 cb->args[0] = (*rdev)->wiphy_idx + 1;
13084 /* add 1 to know if it was NULL */
13085 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
13086 cb->args[2] = vcmd_idx;
13087 cb->args[3] = (unsigned long)data;
13088 cb->args[4] = data_len;
13090 /* keep rtnl locked in successful case */
13097 static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
13098 struct netlink_callback *cb)
13100 struct cfg80211_registered_device *rdev;
13101 struct wireless_dev *wdev;
13102 unsigned int vcmd_idx;
13103 const struct wiphy_vendor_command *vcmd;
13107 struct nlattr *vendor_data;
13110 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13114 vcmd_idx = cb->args[2];
13115 data = (void *)cb->args[3];
13116 data_len = cb->args[4];
13117 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
13119 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13120 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
13125 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
13131 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
13132 if (!wdev_running(wdev)) {
13140 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
13141 cb->nlh->nlmsg_seq, NLM_F_MULTI,
13142 NL80211_CMD_VENDOR);
13146 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13147 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13149 NL80211_ATTR_PAD))) {
13150 genlmsg_cancel(skb, hdr);
13154 vendor_data = nla_nest_start_noflag(skb,
13155 NL80211_ATTR_VENDOR_DATA);
13156 if (!vendor_data) {
13157 genlmsg_cancel(skb, hdr);
13161 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
13162 (unsigned long *)&cb->args[5]);
13163 nla_nest_end(skb, vendor_data);
13165 if (err == -ENOBUFS || err == -ENOENT) {
13166 genlmsg_cancel(skb, hdr);
13169 genlmsg_cancel(skb, hdr);
13173 genlmsg_end(skb, hdr);
13182 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13183 enum nl80211_commands cmd,
13184 enum nl80211_attrs attr,
13187 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13189 if (WARN_ON(!rdev->cur_cmd_info))
13192 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
13193 rdev->cur_cmd_info->snd_portid,
13194 rdev->cur_cmd_info->snd_seq,
13195 cmd, attr, NULL, GFP_KERNEL);
13197 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13199 int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
13201 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
13202 void *hdr = ((void **)skb->cb)[1];
13203 struct nlattr *data = ((void **)skb->cb)[2];
13205 /* clear CB data for netlink core to own from now on */
13206 memset(skb->cb, 0, sizeof(skb->cb));
13208 if (WARN_ON(!rdev->cur_cmd_info)) {
13213 nla_nest_end(skb, data);
13214 genlmsg_end(skb, hdr);
13215 return genlmsg_reply(skb, rdev->cur_cmd_info);
13217 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13219 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
13221 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13223 if (WARN_ON(!rdev->cur_cmd_info))
13226 return rdev->cur_cmd_info->snd_portid;
13228 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13230 static int nl80211_set_qos_map(struct sk_buff *skb,
13231 struct genl_info *info)
13233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13234 struct cfg80211_qos_map *qos_map = NULL;
13235 struct net_device *dev = info->user_ptr[1];
13236 u8 *pos, len, num_des, des_len, des;
13239 if (!rdev->ops->set_qos_map)
13240 return -EOPNOTSUPP;
13242 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13243 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13244 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13246 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
13247 len > IEEE80211_QOS_MAP_LEN_MAX)
13250 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13254 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13256 des_len = num_des *
13257 sizeof(struct cfg80211_dscp_exception);
13258 memcpy(qos_map->dscp_exception, pos, des_len);
13259 qos_map->num_des = num_des;
13260 for (des = 0; des < num_des; des++) {
13261 if (qos_map->dscp_exception[des].up > 7) {
13268 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13271 wdev_lock(dev->ieee80211_ptr);
13272 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13274 ret = rdev_set_qos_map(rdev, dev, qos_map);
13275 wdev_unlock(dev->ieee80211_ptr);
13281 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13284 struct net_device *dev = info->user_ptr[1];
13285 struct wireless_dev *wdev = dev->ieee80211_ptr;
13288 u16 admitted_time = 0;
13291 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
13292 return -EOPNOTSUPP;
13294 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13295 !info->attrs[NL80211_ATTR_USER_PRIO])
13298 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13299 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
13301 /* WMM uses TIDs 0-7 even for TSPEC */
13302 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
13303 /* TODO: handle 802.11 TSPEC/admission control
13304 * need more attributes for that (e.g. BA session requirement);
13305 * change the WMM adminssion test above to allow both then
13310 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13312 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13314 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13315 if (!admitted_time)
13320 switch (wdev->iftype) {
13321 case NL80211_IFTYPE_STATION:
13322 case NL80211_IFTYPE_P2P_CLIENT:
13323 if (wdev->current_bss)
13332 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13339 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13342 struct net_device *dev = info->user_ptr[1];
13343 struct wireless_dev *wdev = dev->ieee80211_ptr;
13348 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13351 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13352 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13355 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13361 static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13362 struct genl_info *info)
13364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13365 struct net_device *dev = info->user_ptr[1];
13366 struct wireless_dev *wdev = dev->ieee80211_ptr;
13367 struct cfg80211_chan_def chandef = {};
13372 if (!rdev->ops->tdls_channel_switch ||
13373 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13374 return -EOPNOTSUPP;
13376 switch (dev->ieee80211_ptr->iftype) {
13377 case NL80211_IFTYPE_STATION:
13378 case NL80211_IFTYPE_P2P_CLIENT:
13381 return -EOPNOTSUPP;
13384 if (!info->attrs[NL80211_ATTR_MAC] ||
13385 !info->attrs[NL80211_ATTR_OPER_CLASS])
13388 err = nl80211_parse_chandef(rdev, info, &chandef);
13393 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13394 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13395 * specification is not defined for them.
13397 if (chandef.chan->band == NL80211_BAND_2GHZ &&
13398 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13399 chandef.width != NL80211_CHAN_WIDTH_20)
13402 /* we will be active on the TDLS link */
13403 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13407 /* don't allow switching to DFS channels */
13408 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13411 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13412 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13415 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13421 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13422 struct genl_info *info)
13424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13425 struct net_device *dev = info->user_ptr[1];
13426 struct wireless_dev *wdev = dev->ieee80211_ptr;
13429 if (!rdev->ops->tdls_channel_switch ||
13430 !rdev->ops->tdls_cancel_channel_switch ||
13431 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13432 return -EOPNOTSUPP;
13434 switch (dev->ieee80211_ptr->iftype) {
13435 case NL80211_IFTYPE_STATION:
13436 case NL80211_IFTYPE_P2P_CLIENT:
13439 return -EOPNOTSUPP;
13442 if (!info->attrs[NL80211_ATTR_MAC])
13445 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13448 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13454 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13455 struct genl_info *info)
13457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13458 struct net_device *dev = info->user_ptr[1];
13459 struct wireless_dev *wdev = dev->ieee80211_ptr;
13460 const struct nlattr *nla;
13463 if (!rdev->ops->set_multicast_to_unicast)
13464 return -EOPNOTSUPP;
13466 if (wdev->iftype != NL80211_IFTYPE_AP &&
13467 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13468 return -EOPNOTSUPP;
13470 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13471 enabled = nla_get_flag(nla);
13473 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13476 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13479 struct net_device *dev = info->user_ptr[1];
13480 struct wireless_dev *wdev = dev->ieee80211_ptr;
13481 struct cfg80211_pmk_conf pmk_conf = {};
13484 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13485 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13486 return -EOPNOTSUPP;
13488 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13489 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13490 return -EOPNOTSUPP;
13492 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13496 if (!wdev->current_bss) {
13501 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13502 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13507 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13508 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13509 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13510 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13515 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13516 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13518 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13523 pmk_conf.pmk_r0_name =
13524 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13527 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13533 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13535 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13536 struct net_device *dev = info->user_ptr[1];
13537 struct wireless_dev *wdev = dev->ieee80211_ptr;
13541 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13542 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13543 return -EOPNOTSUPP;
13545 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13546 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13547 return -EOPNOTSUPP;
13549 if (!info->attrs[NL80211_ATTR_MAC])
13553 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13554 ret = rdev_del_pmk(rdev, dev, aa);
13560 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13563 struct net_device *dev = info->user_ptr[1];
13564 struct cfg80211_external_auth_params params;
13566 if (!rdev->ops->external_auth)
13567 return -EOPNOTSUPP;
13569 if (!info->attrs[NL80211_ATTR_SSID] &&
13570 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13571 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
13574 if (!info->attrs[NL80211_ATTR_BSSID])
13577 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13580 memset(¶ms, 0, sizeof(params));
13582 if (info->attrs[NL80211_ATTR_SSID]) {
13583 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13584 if (params.ssid.ssid_len == 0 ||
13585 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13587 memcpy(params.ssid.ssid,
13588 nla_data(info->attrs[NL80211_ATTR_SSID]),
13589 params.ssid.ssid_len);
13592 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13595 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13597 if (info->attrs[NL80211_ATTR_PMKID])
13598 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13600 return rdev_external_auth(rdev, dev, ¶ms);
13603 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13605 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13606 struct net_device *dev = info->user_ptr[1];
13607 struct wireless_dev *wdev = dev->ieee80211_ptr;
13615 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13616 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13617 return -EOPNOTSUPP;
13619 if (!rdev->ops->tx_control_port)
13620 return -EOPNOTSUPP;
13622 if (!info->attrs[NL80211_ATTR_FRAME] ||
13623 !info->attrs[NL80211_ATTR_MAC] ||
13624 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13625 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13631 switch (wdev->iftype) {
13632 case NL80211_IFTYPE_AP:
13633 case NL80211_IFTYPE_P2P_GO:
13634 case NL80211_IFTYPE_MESH_POINT:
13636 case NL80211_IFTYPE_ADHOC:
13637 case NL80211_IFTYPE_STATION:
13638 case NL80211_IFTYPE_P2P_CLIENT:
13639 if (wdev->current_bss)
13650 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13651 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13652 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13653 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13655 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13657 return rdev_tx_control_port(rdev, dev, buf, len,
13658 dest, cpu_to_be16(proto), noencrypt);
13665 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13666 struct genl_info *info)
13668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13669 struct net_device *dev = info->user_ptr[1];
13670 struct wireless_dev *wdev = dev->ieee80211_ptr;
13671 struct cfg80211_ftm_responder_stats ftm_stats = {};
13672 struct sk_buff *msg;
13674 struct nlattr *ftm_stats_attr;
13677 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13678 return -EOPNOTSUPP;
13680 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13684 if (!ftm_stats.filled)
13687 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13691 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13692 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13694 goto nla_put_failure;
13696 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13697 goto nla_put_failure;
13699 ftm_stats_attr = nla_nest_start_noflag(msg,
13700 NL80211_ATTR_FTM_RESPONDER_STATS);
13701 if (!ftm_stats_attr)
13702 goto nla_put_failure;
13704 #define SET_FTM(field, name, type) \
13705 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13706 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13707 ftm_stats.field)) \
13708 goto nla_put_failure; } while (0)
13709 #define SET_FTM_U64(field, name) \
13710 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13711 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13712 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13713 goto nla_put_failure; } while (0)
13715 SET_FTM(success_num, SUCCESS_NUM, u32);
13716 SET_FTM(partial_num, PARTIAL_NUM, u32);
13717 SET_FTM(failed_num, FAILED_NUM, u32);
13718 SET_FTM(asap_num, ASAP_NUM, u32);
13719 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13720 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13721 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13722 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13723 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13726 nla_nest_end(msg, ftm_stats_attr);
13728 genlmsg_end(msg, hdr);
13729 return genlmsg_reply(msg, info);
13736 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
13738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13739 struct cfg80211_update_owe_info owe_info;
13740 struct net_device *dev = info->user_ptr[1];
13742 if (!rdev->ops->update_owe_info)
13743 return -EOPNOTSUPP;
13745 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
13746 !info->attrs[NL80211_ATTR_MAC])
13749 memset(&owe_info, 0, sizeof(owe_info));
13750 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13751 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
13753 if (info->attrs[NL80211_ATTR_IE]) {
13754 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13755 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13758 return rdev_update_owe_info(rdev, dev, &owe_info);
13761 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
13763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13764 struct net_device *dev = info->user_ptr[1];
13765 struct wireless_dev *wdev = dev->ieee80211_ptr;
13766 struct station_info sinfo = {};
13772 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
13773 return -EOPNOTSUPP;
13775 if (!info->attrs[NL80211_ATTR_MAC] ||
13776 !info->attrs[NL80211_ATTR_FRAME]) {
13777 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
13781 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
13782 return -EOPNOTSUPP;
13784 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13785 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13786 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13788 if (len < sizeof(struct ethhdr))
13791 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
13792 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
13795 err = rdev_get_station(rdev, dev, dest, &sinfo);
13799 cfg80211_sinfo_release_content(&sinfo);
13801 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
13804 #define NL80211_FLAG_NEED_WIPHY 0x01
13805 #define NL80211_FLAG_NEED_NETDEV 0x02
13806 #define NL80211_FLAG_NEED_RTNL 0x04
13807 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13808 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13809 NL80211_FLAG_CHECK_NETDEV_UP)
13810 #define NL80211_FLAG_NEED_WDEV 0x10
13811 /* If a netdev is associated, it must be UP, P2P must be started */
13812 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13813 NL80211_FLAG_CHECK_NETDEV_UP)
13814 #define NL80211_FLAG_CLEAR_SKB 0x20
13816 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
13817 struct genl_info *info)
13819 struct cfg80211_registered_device *rdev;
13820 struct wireless_dev *wdev;
13821 struct net_device *dev;
13822 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
13827 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
13828 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
13829 if (IS_ERR(rdev)) {
13832 return PTR_ERR(rdev);
13834 info->user_ptr[0] = rdev;
13835 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
13836 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13839 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
13841 if (IS_ERR(wdev)) {
13844 return PTR_ERR(wdev);
13847 dev = wdev->netdev;
13848 rdev = wiphy_to_rdev(wdev->wiphy);
13850 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
13857 info->user_ptr[1] = dev;
13859 info->user_ptr[1] = wdev;
13862 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
13863 !wdev_running(wdev)) {
13872 info->user_ptr[0] = rdev;
13878 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
13879 struct genl_info *info)
13881 if (info->user_ptr[1]) {
13882 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
13883 struct wireless_dev *wdev = info->user_ptr[1];
13886 dev_put(wdev->netdev);
13888 dev_put(info->user_ptr[1]);
13892 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
13895 /* If needed, clear the netlink message payload from the SKB
13896 * as it might contain key data that shouldn't stick around on
13897 * the heap after the SKB is freed. The netlink message header
13898 * is still needed for further processing, so leave it intact.
13900 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
13901 struct nlmsghdr *nlh = nlmsg_hdr(skb);
13903 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
13907 static const struct genl_ops nl80211_ops[] = {
13909 .cmd = NL80211_CMD_GET_WIPHY,
13910 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13911 .doit = nl80211_get_wiphy,
13912 .dumpit = nl80211_dump_wiphy,
13913 .done = nl80211_dump_wiphy_done,
13914 /* can be retrieved by unprivileged users */
13915 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13916 NL80211_FLAG_NEED_RTNL,
13919 .cmd = NL80211_CMD_SET_WIPHY,
13920 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13921 .doit = nl80211_set_wiphy,
13922 .flags = GENL_UNS_ADMIN_PERM,
13923 .internal_flags = NL80211_FLAG_NEED_RTNL,
13926 .cmd = NL80211_CMD_GET_INTERFACE,
13927 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13928 .doit = nl80211_get_interface,
13929 .dumpit = nl80211_dump_interface,
13930 /* can be retrieved by unprivileged users */
13931 .internal_flags = NL80211_FLAG_NEED_WDEV |
13932 NL80211_FLAG_NEED_RTNL,
13935 .cmd = NL80211_CMD_SET_INTERFACE,
13936 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13937 .doit = nl80211_set_interface,
13938 .flags = GENL_UNS_ADMIN_PERM,
13939 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13940 NL80211_FLAG_NEED_RTNL,
13943 .cmd = NL80211_CMD_NEW_INTERFACE,
13944 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13945 .doit = nl80211_new_interface,
13946 .flags = GENL_UNS_ADMIN_PERM,
13947 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13948 NL80211_FLAG_NEED_RTNL,
13951 .cmd = NL80211_CMD_DEL_INTERFACE,
13952 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13953 .doit = nl80211_del_interface,
13954 .flags = GENL_UNS_ADMIN_PERM,
13955 .internal_flags = NL80211_FLAG_NEED_WDEV |
13956 NL80211_FLAG_NEED_RTNL,
13959 .cmd = NL80211_CMD_GET_KEY,
13960 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13961 .doit = nl80211_get_key,
13962 .flags = GENL_UNS_ADMIN_PERM,
13963 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13964 NL80211_FLAG_NEED_RTNL,
13967 .cmd = NL80211_CMD_SET_KEY,
13968 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13969 .doit = nl80211_set_key,
13970 .flags = GENL_UNS_ADMIN_PERM,
13971 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13972 NL80211_FLAG_NEED_RTNL |
13973 NL80211_FLAG_CLEAR_SKB,
13976 .cmd = NL80211_CMD_NEW_KEY,
13977 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13978 .doit = nl80211_new_key,
13979 .flags = GENL_UNS_ADMIN_PERM,
13980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13981 NL80211_FLAG_NEED_RTNL |
13982 NL80211_FLAG_CLEAR_SKB,
13985 .cmd = NL80211_CMD_DEL_KEY,
13986 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13987 .doit = nl80211_del_key,
13988 .flags = GENL_UNS_ADMIN_PERM,
13989 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13990 NL80211_FLAG_NEED_RTNL,
13993 .cmd = NL80211_CMD_SET_BEACON,
13994 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13995 .flags = GENL_UNS_ADMIN_PERM,
13996 .doit = nl80211_set_beacon,
13997 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13998 NL80211_FLAG_NEED_RTNL,
14001 .cmd = NL80211_CMD_START_AP,
14002 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14003 .flags = GENL_UNS_ADMIN_PERM,
14004 .doit = nl80211_start_ap,
14005 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14006 NL80211_FLAG_NEED_RTNL,
14009 .cmd = NL80211_CMD_STOP_AP,
14010 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14011 .flags = GENL_UNS_ADMIN_PERM,
14012 .doit = nl80211_stop_ap,
14013 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14014 NL80211_FLAG_NEED_RTNL,
14017 .cmd = NL80211_CMD_GET_STATION,
14018 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14019 .doit = nl80211_get_station,
14020 .dumpit = nl80211_dump_station,
14021 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14022 NL80211_FLAG_NEED_RTNL,
14025 .cmd = NL80211_CMD_SET_STATION,
14026 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14027 .doit = nl80211_set_station,
14028 .flags = GENL_UNS_ADMIN_PERM,
14029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14030 NL80211_FLAG_NEED_RTNL,
14033 .cmd = NL80211_CMD_NEW_STATION,
14034 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14035 .doit = nl80211_new_station,
14036 .flags = GENL_UNS_ADMIN_PERM,
14037 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14038 NL80211_FLAG_NEED_RTNL,
14041 .cmd = NL80211_CMD_DEL_STATION,
14042 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14043 .doit = nl80211_del_station,
14044 .flags = GENL_UNS_ADMIN_PERM,
14045 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14046 NL80211_FLAG_NEED_RTNL,
14049 .cmd = NL80211_CMD_GET_MPATH,
14050 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14051 .doit = nl80211_get_mpath,
14052 .dumpit = nl80211_dump_mpath,
14053 .flags = GENL_UNS_ADMIN_PERM,
14054 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14055 NL80211_FLAG_NEED_RTNL,
14058 .cmd = NL80211_CMD_GET_MPP,
14059 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14060 .doit = nl80211_get_mpp,
14061 .dumpit = nl80211_dump_mpp,
14062 .flags = GENL_UNS_ADMIN_PERM,
14063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14064 NL80211_FLAG_NEED_RTNL,
14067 .cmd = NL80211_CMD_SET_MPATH,
14068 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14069 .doit = nl80211_set_mpath,
14070 .flags = GENL_UNS_ADMIN_PERM,
14071 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14072 NL80211_FLAG_NEED_RTNL,
14075 .cmd = NL80211_CMD_NEW_MPATH,
14076 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14077 .doit = nl80211_new_mpath,
14078 .flags = GENL_UNS_ADMIN_PERM,
14079 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14080 NL80211_FLAG_NEED_RTNL,
14083 .cmd = NL80211_CMD_DEL_MPATH,
14084 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14085 .doit = nl80211_del_mpath,
14086 .flags = GENL_UNS_ADMIN_PERM,
14087 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14088 NL80211_FLAG_NEED_RTNL,
14091 .cmd = NL80211_CMD_SET_BSS,
14092 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14093 .doit = nl80211_set_bss,
14094 .flags = GENL_UNS_ADMIN_PERM,
14095 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14096 NL80211_FLAG_NEED_RTNL,
14099 .cmd = NL80211_CMD_GET_REG,
14100 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14101 .doit = nl80211_get_reg_do,
14102 .dumpit = nl80211_get_reg_dump,
14103 .internal_flags = NL80211_FLAG_NEED_RTNL,
14104 /* can be retrieved by unprivileged users */
14106 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
14108 .cmd = NL80211_CMD_SET_REG,
14109 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14110 .doit = nl80211_set_reg,
14111 .flags = GENL_ADMIN_PERM,
14112 .internal_flags = NL80211_FLAG_NEED_RTNL,
14116 .cmd = NL80211_CMD_REQ_SET_REG,
14117 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14118 .doit = nl80211_req_set_reg,
14119 .flags = GENL_ADMIN_PERM,
14122 .cmd = NL80211_CMD_RELOAD_REGDB,
14123 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14124 .doit = nl80211_reload_regdb,
14125 .flags = GENL_ADMIN_PERM,
14128 .cmd = NL80211_CMD_GET_MESH_CONFIG,
14129 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14130 .doit = nl80211_get_mesh_config,
14131 /* can be retrieved by unprivileged users */
14132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14133 NL80211_FLAG_NEED_RTNL,
14136 .cmd = NL80211_CMD_SET_MESH_CONFIG,
14137 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14138 .doit = nl80211_update_mesh_config,
14139 .flags = GENL_UNS_ADMIN_PERM,
14140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14141 NL80211_FLAG_NEED_RTNL,
14144 .cmd = NL80211_CMD_TRIGGER_SCAN,
14145 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14146 .doit = nl80211_trigger_scan,
14147 .flags = GENL_UNS_ADMIN_PERM,
14148 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14149 NL80211_FLAG_NEED_RTNL,
14152 .cmd = NL80211_CMD_ABORT_SCAN,
14153 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14154 .doit = nl80211_abort_scan,
14155 .flags = GENL_UNS_ADMIN_PERM,
14156 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14157 NL80211_FLAG_NEED_RTNL,
14160 .cmd = NL80211_CMD_GET_SCAN,
14161 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14162 .dumpit = nl80211_dump_scan,
14165 .cmd = NL80211_CMD_START_SCHED_SCAN,
14166 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14167 .doit = nl80211_start_sched_scan,
14168 .flags = GENL_UNS_ADMIN_PERM,
14169 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14170 NL80211_FLAG_NEED_RTNL,
14173 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
14174 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14175 .doit = nl80211_stop_sched_scan,
14176 .flags = GENL_UNS_ADMIN_PERM,
14177 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14178 NL80211_FLAG_NEED_RTNL,
14181 .cmd = NL80211_CMD_AUTHENTICATE,
14182 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14183 .doit = nl80211_authenticate,
14184 .flags = GENL_UNS_ADMIN_PERM,
14185 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14186 NL80211_FLAG_NEED_RTNL |
14187 NL80211_FLAG_CLEAR_SKB,
14190 .cmd = NL80211_CMD_ASSOCIATE,
14191 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14192 .doit = nl80211_associate,
14193 .flags = GENL_UNS_ADMIN_PERM,
14194 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14195 NL80211_FLAG_NEED_RTNL |
14196 NL80211_FLAG_CLEAR_SKB,
14199 .cmd = NL80211_CMD_DEAUTHENTICATE,
14200 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14201 .doit = nl80211_deauthenticate,
14202 .flags = GENL_UNS_ADMIN_PERM,
14203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14204 NL80211_FLAG_NEED_RTNL,
14207 .cmd = NL80211_CMD_DISASSOCIATE,
14208 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14209 .doit = nl80211_disassociate,
14210 .flags = GENL_UNS_ADMIN_PERM,
14211 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14212 NL80211_FLAG_NEED_RTNL,
14215 .cmd = NL80211_CMD_JOIN_IBSS,
14216 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14217 .doit = nl80211_join_ibss,
14218 .flags = GENL_UNS_ADMIN_PERM,
14219 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14220 NL80211_FLAG_NEED_RTNL,
14223 .cmd = NL80211_CMD_LEAVE_IBSS,
14224 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14225 .doit = nl80211_leave_ibss,
14226 .flags = GENL_UNS_ADMIN_PERM,
14227 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14228 NL80211_FLAG_NEED_RTNL,
14230 #ifdef CONFIG_NL80211_TESTMODE
14232 .cmd = NL80211_CMD_TESTMODE,
14233 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14234 .doit = nl80211_testmode_do,
14235 .dumpit = nl80211_testmode_dump,
14236 .flags = GENL_UNS_ADMIN_PERM,
14237 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14238 NL80211_FLAG_NEED_RTNL,
14242 .cmd = NL80211_CMD_CONNECT,
14243 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14244 .doit = nl80211_connect,
14245 .flags = GENL_UNS_ADMIN_PERM,
14246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14247 NL80211_FLAG_NEED_RTNL |
14248 NL80211_FLAG_CLEAR_SKB,
14251 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
14252 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14253 .doit = nl80211_update_connect_params,
14254 .flags = GENL_ADMIN_PERM,
14255 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14256 NL80211_FLAG_NEED_RTNL |
14257 NL80211_FLAG_CLEAR_SKB,
14260 .cmd = NL80211_CMD_DISCONNECT,
14261 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14262 .doit = nl80211_disconnect,
14263 .flags = GENL_UNS_ADMIN_PERM,
14264 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14265 NL80211_FLAG_NEED_RTNL,
14268 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
14269 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14270 .doit = nl80211_wiphy_netns,
14271 .flags = GENL_UNS_ADMIN_PERM,
14272 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14273 NL80211_FLAG_NEED_RTNL,
14276 .cmd = NL80211_CMD_GET_SURVEY,
14277 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14278 .dumpit = nl80211_dump_survey,
14281 .cmd = NL80211_CMD_SET_PMKSA,
14282 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14283 .doit = nl80211_setdel_pmksa,
14284 .flags = GENL_UNS_ADMIN_PERM,
14285 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14286 NL80211_FLAG_NEED_RTNL |
14287 NL80211_FLAG_CLEAR_SKB,
14290 .cmd = NL80211_CMD_DEL_PMKSA,
14291 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14292 .doit = nl80211_setdel_pmksa,
14293 .flags = GENL_UNS_ADMIN_PERM,
14294 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14295 NL80211_FLAG_NEED_RTNL,
14298 .cmd = NL80211_CMD_FLUSH_PMKSA,
14299 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14300 .doit = nl80211_flush_pmksa,
14301 .flags = GENL_UNS_ADMIN_PERM,
14302 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14303 NL80211_FLAG_NEED_RTNL,
14306 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
14307 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14308 .doit = nl80211_remain_on_channel,
14309 .flags = GENL_UNS_ADMIN_PERM,
14310 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14311 NL80211_FLAG_NEED_RTNL,
14314 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
14315 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14316 .doit = nl80211_cancel_remain_on_channel,
14317 .flags = GENL_UNS_ADMIN_PERM,
14318 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14319 NL80211_FLAG_NEED_RTNL,
14322 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
14323 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14324 .doit = nl80211_set_tx_bitrate_mask,
14325 .flags = GENL_UNS_ADMIN_PERM,
14326 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14327 NL80211_FLAG_NEED_RTNL,
14330 .cmd = NL80211_CMD_REGISTER_FRAME,
14331 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14332 .doit = nl80211_register_mgmt,
14333 .flags = GENL_UNS_ADMIN_PERM,
14334 .internal_flags = NL80211_FLAG_NEED_WDEV |
14335 NL80211_FLAG_NEED_RTNL,
14338 .cmd = NL80211_CMD_FRAME,
14339 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14340 .doit = nl80211_tx_mgmt,
14341 .flags = GENL_UNS_ADMIN_PERM,
14342 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14343 NL80211_FLAG_NEED_RTNL,
14346 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
14347 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14348 .doit = nl80211_tx_mgmt_cancel_wait,
14349 .flags = GENL_UNS_ADMIN_PERM,
14350 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14351 NL80211_FLAG_NEED_RTNL,
14354 .cmd = NL80211_CMD_SET_POWER_SAVE,
14355 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14356 .doit = nl80211_set_power_save,
14357 .flags = GENL_UNS_ADMIN_PERM,
14358 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14359 NL80211_FLAG_NEED_RTNL,
14362 .cmd = NL80211_CMD_GET_POWER_SAVE,
14363 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14364 .doit = nl80211_get_power_save,
14365 /* can be retrieved by unprivileged users */
14366 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14367 NL80211_FLAG_NEED_RTNL,
14370 .cmd = NL80211_CMD_SET_CQM,
14371 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14372 .doit = nl80211_set_cqm,
14373 .flags = GENL_UNS_ADMIN_PERM,
14374 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14375 NL80211_FLAG_NEED_RTNL,
14378 .cmd = NL80211_CMD_SET_CHANNEL,
14379 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14380 .doit = nl80211_set_channel,
14381 .flags = GENL_UNS_ADMIN_PERM,
14382 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14383 NL80211_FLAG_NEED_RTNL,
14386 .cmd = NL80211_CMD_SET_WDS_PEER,
14387 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14388 .doit = nl80211_set_wds_peer,
14389 .flags = GENL_UNS_ADMIN_PERM,
14390 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14391 NL80211_FLAG_NEED_RTNL,
14394 .cmd = NL80211_CMD_JOIN_MESH,
14395 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14396 .doit = nl80211_join_mesh,
14397 .flags = GENL_UNS_ADMIN_PERM,
14398 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14399 NL80211_FLAG_NEED_RTNL,
14402 .cmd = NL80211_CMD_LEAVE_MESH,
14403 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14404 .doit = nl80211_leave_mesh,
14405 .flags = GENL_UNS_ADMIN_PERM,
14406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14407 NL80211_FLAG_NEED_RTNL,
14410 .cmd = NL80211_CMD_JOIN_OCB,
14411 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14412 .doit = nl80211_join_ocb,
14413 .flags = GENL_UNS_ADMIN_PERM,
14414 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14415 NL80211_FLAG_NEED_RTNL,
14418 .cmd = NL80211_CMD_LEAVE_OCB,
14419 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14420 .doit = nl80211_leave_ocb,
14421 .flags = GENL_UNS_ADMIN_PERM,
14422 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14423 NL80211_FLAG_NEED_RTNL,
14427 .cmd = NL80211_CMD_GET_WOWLAN,
14428 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14429 .doit = nl80211_get_wowlan,
14430 /* can be retrieved by unprivileged users */
14431 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14432 NL80211_FLAG_NEED_RTNL,
14435 .cmd = NL80211_CMD_SET_WOWLAN,
14436 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14437 .doit = nl80211_set_wowlan,
14438 .flags = GENL_UNS_ADMIN_PERM,
14439 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14440 NL80211_FLAG_NEED_RTNL,
14444 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
14445 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14446 .doit = nl80211_set_rekey_data,
14447 .flags = GENL_UNS_ADMIN_PERM,
14448 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14449 NL80211_FLAG_NEED_RTNL |
14450 NL80211_FLAG_CLEAR_SKB,
14453 .cmd = NL80211_CMD_TDLS_MGMT,
14454 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14455 .doit = nl80211_tdls_mgmt,
14456 .flags = GENL_UNS_ADMIN_PERM,
14457 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14458 NL80211_FLAG_NEED_RTNL,
14461 .cmd = NL80211_CMD_TDLS_OPER,
14462 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14463 .doit = nl80211_tdls_oper,
14464 .flags = GENL_UNS_ADMIN_PERM,
14465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14466 NL80211_FLAG_NEED_RTNL,
14469 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
14470 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14471 .doit = nl80211_register_unexpected_frame,
14472 .flags = GENL_UNS_ADMIN_PERM,
14473 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14474 NL80211_FLAG_NEED_RTNL,
14477 .cmd = NL80211_CMD_PROBE_CLIENT,
14478 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14479 .doit = nl80211_probe_client,
14480 .flags = GENL_UNS_ADMIN_PERM,
14481 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14482 NL80211_FLAG_NEED_RTNL,
14485 .cmd = NL80211_CMD_REGISTER_BEACONS,
14486 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14487 .doit = nl80211_register_beacons,
14488 .flags = GENL_UNS_ADMIN_PERM,
14489 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14490 NL80211_FLAG_NEED_RTNL,
14493 .cmd = NL80211_CMD_SET_NOACK_MAP,
14494 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14495 .doit = nl80211_set_noack_map,
14496 .flags = GENL_UNS_ADMIN_PERM,
14497 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14498 NL80211_FLAG_NEED_RTNL,
14501 .cmd = NL80211_CMD_START_P2P_DEVICE,
14502 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14503 .doit = nl80211_start_p2p_device,
14504 .flags = GENL_UNS_ADMIN_PERM,
14505 .internal_flags = NL80211_FLAG_NEED_WDEV |
14506 NL80211_FLAG_NEED_RTNL,
14509 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
14510 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14511 .doit = nl80211_stop_p2p_device,
14512 .flags = GENL_UNS_ADMIN_PERM,
14513 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14514 NL80211_FLAG_NEED_RTNL,
14517 .cmd = NL80211_CMD_START_NAN,
14518 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14519 .doit = nl80211_start_nan,
14520 .flags = GENL_ADMIN_PERM,
14521 .internal_flags = NL80211_FLAG_NEED_WDEV |
14522 NL80211_FLAG_NEED_RTNL,
14525 .cmd = NL80211_CMD_STOP_NAN,
14526 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14527 .doit = nl80211_stop_nan,
14528 .flags = GENL_ADMIN_PERM,
14529 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14530 NL80211_FLAG_NEED_RTNL,
14533 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
14534 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14535 .doit = nl80211_nan_add_func,
14536 .flags = GENL_ADMIN_PERM,
14537 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14538 NL80211_FLAG_NEED_RTNL,
14541 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
14542 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14543 .doit = nl80211_nan_del_func,
14544 .flags = GENL_ADMIN_PERM,
14545 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14546 NL80211_FLAG_NEED_RTNL,
14549 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
14550 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14551 .doit = nl80211_nan_change_config,
14552 .flags = GENL_ADMIN_PERM,
14553 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14554 NL80211_FLAG_NEED_RTNL,
14557 .cmd = NL80211_CMD_SET_MCAST_RATE,
14558 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14559 .doit = nl80211_set_mcast_rate,
14560 .flags = GENL_UNS_ADMIN_PERM,
14561 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14562 NL80211_FLAG_NEED_RTNL,
14565 .cmd = NL80211_CMD_SET_MAC_ACL,
14566 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14567 .doit = nl80211_set_mac_acl,
14568 .flags = GENL_UNS_ADMIN_PERM,
14569 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14570 NL80211_FLAG_NEED_RTNL,
14573 .cmd = NL80211_CMD_RADAR_DETECT,
14574 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14575 .doit = nl80211_start_radar_detection,
14576 .flags = GENL_UNS_ADMIN_PERM,
14577 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14578 NL80211_FLAG_NEED_RTNL,
14581 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
14582 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14583 .doit = nl80211_get_protocol_features,
14586 .cmd = NL80211_CMD_UPDATE_FT_IES,
14587 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14588 .doit = nl80211_update_ft_ies,
14589 .flags = GENL_UNS_ADMIN_PERM,
14590 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14591 NL80211_FLAG_NEED_RTNL,
14594 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
14595 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14596 .doit = nl80211_crit_protocol_start,
14597 .flags = GENL_UNS_ADMIN_PERM,
14598 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14599 NL80211_FLAG_NEED_RTNL,
14602 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
14603 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14604 .doit = nl80211_crit_protocol_stop,
14605 .flags = GENL_UNS_ADMIN_PERM,
14606 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14607 NL80211_FLAG_NEED_RTNL,
14610 .cmd = NL80211_CMD_GET_COALESCE,
14611 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14612 .doit = nl80211_get_coalesce,
14613 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14614 NL80211_FLAG_NEED_RTNL,
14617 .cmd = NL80211_CMD_SET_COALESCE,
14618 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14619 .doit = nl80211_set_coalesce,
14620 .flags = GENL_UNS_ADMIN_PERM,
14621 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14622 NL80211_FLAG_NEED_RTNL,
14625 .cmd = NL80211_CMD_CHANNEL_SWITCH,
14626 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14627 .doit = nl80211_channel_switch,
14628 .flags = GENL_UNS_ADMIN_PERM,
14629 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14630 NL80211_FLAG_NEED_RTNL,
14633 .cmd = NL80211_CMD_VENDOR,
14634 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14635 .doit = nl80211_vendor_cmd,
14636 .dumpit = nl80211_vendor_cmd_dump,
14637 .flags = GENL_UNS_ADMIN_PERM,
14638 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14639 NL80211_FLAG_NEED_RTNL |
14640 NL80211_FLAG_CLEAR_SKB,
14643 .cmd = NL80211_CMD_SET_QOS_MAP,
14644 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14645 .doit = nl80211_set_qos_map,
14646 .flags = GENL_UNS_ADMIN_PERM,
14647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14648 NL80211_FLAG_NEED_RTNL,
14651 .cmd = NL80211_CMD_ADD_TX_TS,
14652 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14653 .doit = nl80211_add_tx_ts,
14654 .flags = GENL_UNS_ADMIN_PERM,
14655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14656 NL80211_FLAG_NEED_RTNL,
14659 .cmd = NL80211_CMD_DEL_TX_TS,
14660 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14661 .doit = nl80211_del_tx_ts,
14662 .flags = GENL_UNS_ADMIN_PERM,
14663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14664 NL80211_FLAG_NEED_RTNL,
14667 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
14668 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14669 .doit = nl80211_tdls_channel_switch,
14670 .flags = GENL_UNS_ADMIN_PERM,
14671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14672 NL80211_FLAG_NEED_RTNL,
14675 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
14676 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14677 .doit = nl80211_tdls_cancel_channel_switch,
14678 .flags = GENL_UNS_ADMIN_PERM,
14679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14680 NL80211_FLAG_NEED_RTNL,
14683 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
14684 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14685 .doit = nl80211_set_multicast_to_unicast,
14686 .flags = GENL_UNS_ADMIN_PERM,
14687 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14688 NL80211_FLAG_NEED_RTNL,
14691 .cmd = NL80211_CMD_SET_PMK,
14692 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14693 .doit = nl80211_set_pmk,
14694 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14695 NL80211_FLAG_NEED_RTNL |
14696 NL80211_FLAG_CLEAR_SKB,
14699 .cmd = NL80211_CMD_DEL_PMK,
14700 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14701 .doit = nl80211_del_pmk,
14702 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14703 NL80211_FLAG_NEED_RTNL,
14706 .cmd = NL80211_CMD_EXTERNAL_AUTH,
14707 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14708 .doit = nl80211_external_auth,
14709 .flags = GENL_ADMIN_PERM,
14710 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14711 NL80211_FLAG_NEED_RTNL,
14714 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
14715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14716 .doit = nl80211_tx_control_port,
14717 .flags = GENL_UNS_ADMIN_PERM,
14718 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14719 NL80211_FLAG_NEED_RTNL,
14722 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
14723 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14724 .doit = nl80211_get_ftm_responder_stats,
14725 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14726 NL80211_FLAG_NEED_RTNL,
14729 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
14730 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14731 .doit = nl80211_pmsr_start,
14732 .flags = GENL_UNS_ADMIN_PERM,
14733 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14734 NL80211_FLAG_NEED_RTNL,
14737 .cmd = NL80211_CMD_NOTIFY_RADAR,
14738 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14739 .doit = nl80211_notify_radar_detection,
14740 .flags = GENL_UNS_ADMIN_PERM,
14741 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14742 NL80211_FLAG_NEED_RTNL,
14745 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
14746 .doit = nl80211_update_owe_info,
14747 .flags = GENL_ADMIN_PERM,
14748 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14749 NL80211_FLAG_NEED_RTNL,
14752 .cmd = NL80211_CMD_PROBE_MESH_LINK,
14753 .doit = nl80211_probe_mesh_link,
14754 .flags = GENL_UNS_ADMIN_PERM,
14755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14756 NL80211_FLAG_NEED_RTNL,
14760 static struct genl_family nl80211_fam __ro_after_init = {
14761 .name = NL80211_GENL_NAME, /* have users key off the name instead */
14762 .hdrsize = 0, /* no private header */
14763 .version = 1, /* no particular meaning now */
14764 .maxattr = NL80211_ATTR_MAX,
14765 .policy = nl80211_policy,
14767 .pre_doit = nl80211_pre_doit,
14768 .post_doit = nl80211_post_doit,
14769 .module = THIS_MODULE,
14770 .ops = nl80211_ops,
14771 .n_ops = ARRAY_SIZE(nl80211_ops),
14772 .mcgrps = nl80211_mcgrps,
14773 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
14774 .parallel_ops = true,
14777 /* notification functions */
14779 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
14780 enum nl80211_commands cmd)
14782 struct sk_buff *msg;
14783 struct nl80211_dump_wiphy_state state = {};
14785 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
14786 cmd != NL80211_CMD_DEL_WIPHY);
14788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14792 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
14797 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14798 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14801 void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
14802 struct wireless_dev *wdev,
14803 enum nl80211_commands cmd)
14805 struct sk_buff *msg;
14807 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14811 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
14816 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14817 NL80211_MCGRP_CONFIG, GFP_KERNEL);
14820 static int nl80211_add_scan_req(struct sk_buff *msg,
14821 struct cfg80211_registered_device *rdev)
14823 struct cfg80211_scan_request *req = rdev->scan_req;
14824 struct nlattr *nest;
14830 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
14832 goto nla_put_failure;
14833 for (i = 0; i < req->n_ssids; i++) {
14834 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
14835 goto nla_put_failure;
14837 nla_nest_end(msg, nest);
14839 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
14841 goto nla_put_failure;
14842 for (i = 0; i < req->n_channels; i++) {
14843 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
14844 goto nla_put_failure;
14846 nla_nest_end(msg, nest);
14849 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
14850 goto nla_put_failure;
14853 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
14854 goto nla_put_failure;
14856 if (req->info.scan_start_tsf &&
14857 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
14858 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
14859 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
14860 req->info.tsf_bssid)))
14861 goto nla_put_failure;
14868 static int nl80211_prep_scan_msg(struct sk_buff *msg,
14869 struct cfg80211_registered_device *rdev,
14870 struct wireless_dev *wdev,
14871 u32 portid, u32 seq, int flags,
14876 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
14880 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14881 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14882 wdev->netdev->ifindex)) ||
14883 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14885 goto nla_put_failure;
14887 /* ignore errors and send incomplete event anyway */
14888 nl80211_add_scan_req(msg, rdev);
14890 genlmsg_end(msg, hdr);
14894 genlmsg_cancel(msg, hdr);
14899 nl80211_prep_sched_scan_msg(struct sk_buff *msg,
14900 struct cfg80211_sched_scan_request *req, u32 cmd)
14904 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14908 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
14909 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
14910 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
14911 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
14913 goto nla_put_failure;
14915 genlmsg_end(msg, hdr);
14919 genlmsg_cancel(msg, hdr);
14923 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
14924 struct wireless_dev *wdev)
14926 struct sk_buff *msg;
14928 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14932 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
14933 NL80211_CMD_TRIGGER_SCAN) < 0) {
14938 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14939 NL80211_MCGRP_SCAN, GFP_KERNEL);
14942 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
14943 struct wireless_dev *wdev, bool aborted)
14945 struct sk_buff *msg;
14947 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14951 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
14952 aborted ? NL80211_CMD_SCAN_ABORTED :
14953 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
14961 /* send message created by nl80211_build_scan_msg() */
14962 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
14963 struct sk_buff *msg)
14968 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14969 NL80211_MCGRP_SCAN, GFP_KERNEL);
14972 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
14974 struct sk_buff *msg;
14976 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14980 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
14985 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
14986 NL80211_MCGRP_SCAN, GFP_KERNEL);
14989 static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
14990 struct regulatory_request *request)
14992 /* Userspace can always count this one always being set */
14993 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
14994 goto nla_put_failure;
14996 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
14997 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
14998 NL80211_REGDOM_TYPE_WORLD))
14999 goto nla_put_failure;
15000 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
15001 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15002 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
15003 goto nla_put_failure;
15004 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
15005 request->intersect) {
15006 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15007 NL80211_REGDOM_TYPE_INTERSECTION))
15008 goto nla_put_failure;
15010 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15011 NL80211_REGDOM_TYPE_COUNTRY) ||
15012 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
15014 goto nla_put_failure;
15017 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
15018 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
15021 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
15022 goto nla_put_failure;
15025 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
15026 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
15027 goto nla_put_failure;
15037 * This can happen on global regulatory changes or device specific settings
15038 * based on custom regulatory domains.
15040 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
15041 struct regulatory_request *request)
15043 struct sk_buff *msg;
15046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15050 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
15052 goto nla_put_failure;
15054 if (!nl80211_reg_change_event_fill(msg, request))
15055 goto nla_put_failure;
15057 genlmsg_end(msg, hdr);
15060 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
15061 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
15070 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
15071 struct net_device *netdev,
15072 const u8 *buf, size_t len,
15073 enum nl80211_commands cmd, gfp_t gfp,
15074 int uapsd_queues, const u8 *req_ies,
15075 size_t req_ies_len)
15077 struct sk_buff *msg;
15080 msg = nlmsg_new(100 + len + req_ies_len, gfp);
15084 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15091 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15092 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15094 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
15095 goto nla_put_failure;
15097 if (uapsd_queues >= 0) {
15098 struct nlattr *nla_wmm =
15099 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
15101 goto nla_put_failure;
15103 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
15105 goto nla_put_failure;
15107 nla_nest_end(msg, nla_wmm);
15110 genlmsg_end(msg, hdr);
15112 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15113 NL80211_MCGRP_MLME, gfp);
15120 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
15121 struct net_device *netdev, const u8 *buf,
15122 size_t len, gfp_t gfp)
15124 nl80211_send_mlme_event(rdev, netdev, buf, len,
15125 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
15128 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15129 struct net_device *netdev, const u8 *buf,
15130 size_t len, gfp_t gfp, int uapsd_queues,
15131 const u8 *req_ies, size_t req_ies_len)
15133 nl80211_send_mlme_event(rdev, netdev, buf, len,
15134 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15135 req_ies, req_ies_len);
15138 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
15139 struct net_device *netdev, const u8 *buf,
15140 size_t len, gfp_t gfp)
15142 nl80211_send_mlme_event(rdev, netdev, buf, len,
15143 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
15146 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15147 struct net_device *netdev, const u8 *buf,
15148 size_t len, gfp_t gfp)
15150 nl80211_send_mlme_event(rdev, netdev, buf, len,
15151 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
15154 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15157 struct wireless_dev *wdev = dev->ieee80211_ptr;
15158 struct wiphy *wiphy = wdev->wiphy;
15159 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15160 const struct ieee80211_mgmt *mgmt = (void *)buf;
15163 if (WARN_ON(len < 2))
15166 if (ieee80211_is_deauth(mgmt->frame_control))
15167 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
15169 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
15171 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
15172 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15175 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
15177 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15178 struct net_device *netdev, int cmd,
15179 const u8 *addr, gfp_t gfp)
15181 struct sk_buff *msg;
15184 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15188 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15194 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15195 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15196 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15197 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15198 goto nla_put_failure;
15200 genlmsg_end(msg, hdr);
15202 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15203 NL80211_MCGRP_MLME, gfp);
15210 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
15211 struct net_device *netdev, const u8 *addr,
15214 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
15218 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
15219 struct net_device *netdev, const u8 *addr,
15222 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
15226 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
15227 struct net_device *netdev,
15228 struct cfg80211_connect_resp_params *cr,
15231 struct sk_buff *msg;
15234 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
15235 cr->fils.kek_len + cr->fils.pmk_len +
15236 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
15240 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
15246 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15247 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15249 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
15250 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
15251 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
15254 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15255 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
15256 cr->timeout_reason))) ||
15258 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
15260 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
15262 (cr->fils.update_erp_next_seq_num &&
15263 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15264 cr->fils.erp_next_seq_num)) ||
15265 (cr->status == WLAN_STATUS_SUCCESS &&
15267 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
15270 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
15272 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
15273 goto nla_put_failure;
15275 genlmsg_end(msg, hdr);
15277 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15278 NL80211_MCGRP_MLME, gfp);
15285 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
15286 struct net_device *netdev,
15287 struct cfg80211_roam_info *info, gfp_t gfp)
15289 struct sk_buff *msg;
15291 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
15293 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15294 info->fils.kek_len + info->fils.pmk_len +
15295 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
15299 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15305 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15306 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15307 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
15309 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15312 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
15314 (info->fils.update_erp_next_seq_num &&
15315 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15316 info->fils.erp_next_seq_num)) ||
15318 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15319 info->fils.kek)) ||
15321 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15322 (info->fils.pmkid &&
15323 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
15324 goto nla_put_failure;
15326 genlmsg_end(msg, hdr);
15328 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15329 NL80211_MCGRP_MLME, gfp);
15336 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
15337 struct net_device *netdev, const u8 *bssid)
15339 struct sk_buff *msg;
15342 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15346 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
15352 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15353 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15354 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15355 goto nla_put_failure;
15357 genlmsg_end(msg, hdr);
15359 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15360 NL80211_MCGRP_MLME, GFP_KERNEL);
15367 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
15368 struct net_device *netdev, u16 reason,
15369 const u8 *ie, size_t ie_len, bool from_ap)
15371 struct sk_buff *msg;
15374 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
15378 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
15384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15385 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15387 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
15389 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
15390 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
15391 goto nla_put_failure;
15393 genlmsg_end(msg, hdr);
15395 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15396 NL80211_MCGRP_MLME, GFP_KERNEL);
15403 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
15404 struct net_device *netdev, const u8 *bssid,
15407 struct sk_buff *msg;
15410 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15414 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
15420 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15421 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15422 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15423 goto nla_put_failure;
15425 genlmsg_end(msg, hdr);
15427 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15428 NL80211_MCGRP_MLME, gfp);
15435 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
15436 const u8 *ie, u8 ie_len,
15437 int sig_dbm, gfp_t gfp)
15439 struct wireless_dev *wdev = dev->ieee80211_ptr;
15440 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15441 struct sk_buff *msg;
15444 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
15447 trace_cfg80211_notify_new_peer_candidate(dev, addr);
15449 msg = nlmsg_new(100 + ie_len, gfp);
15453 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
15459 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15460 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15461 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15463 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
15465 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
15466 goto nla_put_failure;
15468 genlmsg_end(msg, hdr);
15470 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15471 NL80211_MCGRP_MLME, gfp);
15477 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
15479 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
15480 struct net_device *netdev, const u8 *addr,
15481 enum nl80211_key_type key_type, int key_id,
15482 const u8 *tsc, gfp_t gfp)
15484 struct sk_buff *msg;
15487 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15491 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
15497 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15498 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15499 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
15500 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
15502 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
15503 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
15504 goto nla_put_failure;
15506 genlmsg_end(msg, hdr);
15508 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15509 NL80211_MCGRP_MLME, gfp);
15516 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
15517 struct ieee80211_channel *channel_before,
15518 struct ieee80211_channel *channel_after)
15520 struct sk_buff *msg;
15522 struct nlattr *nl_freq;
15524 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
15528 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
15535 * Since we are applying the beacon hint to a wiphy we know its
15536 * wiphy_idx is valid
15538 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
15539 goto nla_put_failure;
15542 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
15544 goto nla_put_failure;
15546 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
15547 goto nla_put_failure;
15548 nla_nest_end(msg, nl_freq);
15551 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
15553 goto nla_put_failure;
15555 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
15556 goto nla_put_failure;
15557 nla_nest_end(msg, nl_freq);
15559 genlmsg_end(msg, hdr);
15562 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
15563 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
15572 static void nl80211_send_remain_on_chan_event(
15573 int cmd, struct cfg80211_registered_device *rdev,
15574 struct wireless_dev *wdev, u64 cookie,
15575 struct ieee80211_channel *chan,
15576 unsigned int duration, gfp_t gfp)
15578 struct sk_buff *msg;
15581 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15585 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15591 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15592 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15593 wdev->netdev->ifindex)) ||
15594 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15595 NL80211_ATTR_PAD) ||
15596 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
15597 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
15598 NL80211_CHAN_NO_HT) ||
15599 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15601 goto nla_put_failure;
15603 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
15604 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
15605 goto nla_put_failure;
15607 genlmsg_end(msg, hdr);
15609 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15610 NL80211_MCGRP_MLME, gfp);
15617 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
15618 struct ieee80211_channel *chan,
15619 unsigned int duration, gfp_t gfp)
15621 struct wiphy *wiphy = wdev->wiphy;
15622 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15624 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
15625 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
15626 rdev, wdev, cookie, chan,
15629 EXPORT_SYMBOL(cfg80211_ready_on_channel);
15631 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15632 struct ieee80211_channel *chan,
15635 struct wiphy *wiphy = wdev->wiphy;
15636 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15638 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
15639 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
15640 rdev, wdev, cookie, chan, 0, gfp);
15642 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
15644 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
15645 struct ieee80211_channel *chan,
15648 struct wiphy *wiphy = wdev->wiphy;
15649 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15651 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
15652 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
15653 rdev, wdev, cookie, chan, 0, gfp);
15655 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
15657 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15658 struct station_info *sinfo, gfp_t gfp)
15660 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
15661 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15662 struct sk_buff *msg;
15664 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15670 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
15671 rdev, dev, mac_addr, sinfo) < 0) {
15676 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15677 NL80211_MCGRP_MLME, gfp);
15679 EXPORT_SYMBOL(cfg80211_new_sta);
15681 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15682 struct station_info *sinfo, gfp_t gfp)
15684 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
15685 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15686 struct sk_buff *msg;
15687 struct station_info empty_sinfo = {};
15690 sinfo = &empty_sinfo;
15692 trace_cfg80211_del_sta(dev, mac_addr);
15694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15696 cfg80211_sinfo_release_content(sinfo);
15700 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
15701 rdev, dev, mac_addr, sinfo) < 0) {
15706 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15707 NL80211_MCGRP_MLME, gfp);
15709 EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
15711 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
15712 enum nl80211_connect_failed_reason reason,
15715 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
15716 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15717 struct sk_buff *msg;
15720 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
15724 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
15730 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15731 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
15732 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
15733 goto nla_put_failure;
15735 genlmsg_end(msg, hdr);
15737 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15738 NL80211_MCGRP_MLME, gfp);
15744 EXPORT_SYMBOL(cfg80211_conn_failed);
15746 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
15747 const u8 *addr, gfp_t gfp)
15749 struct wireless_dev *wdev = dev->ieee80211_ptr;
15750 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15751 struct sk_buff *msg;
15753 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
15758 msg = nlmsg_new(100, gfp);
15762 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15768 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15769 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15770 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15771 goto nla_put_failure;
15773 genlmsg_end(msg, hdr);
15774 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15782 bool cfg80211_rx_spurious_frame(struct net_device *dev,
15783 const u8 *addr, gfp_t gfp)
15785 struct wireless_dev *wdev = dev->ieee80211_ptr;
15788 trace_cfg80211_rx_spurious_frame(dev, addr);
15790 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15791 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
15792 trace_cfg80211_return_bool(false);
15795 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
15797 trace_cfg80211_return_bool(ret);
15800 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
15802 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
15803 const u8 *addr, gfp_t gfp)
15805 struct wireless_dev *wdev = dev->ieee80211_ptr;
15808 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
15810 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
15811 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
15812 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
15813 trace_cfg80211_return_bool(false);
15816 ret = __nl80211_unexpected_frame(dev,
15817 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
15819 trace_cfg80211_return_bool(ret);
15822 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
15824 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
15825 struct wireless_dev *wdev, u32 nlportid,
15826 int freq, int sig_dbm,
15827 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
15829 struct net_device *netdev = wdev->netdev;
15830 struct sk_buff *msg;
15833 msg = nlmsg_new(100 + len, gfp);
15837 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
15843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15844 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15845 netdev->ifindex)) ||
15846 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15847 NL80211_ATTR_PAD) ||
15848 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
15850 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
15851 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15853 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
15854 goto nla_put_failure;
15856 genlmsg_end(msg, hdr);
15858 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15865 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
15866 const u8 *buf, size_t len, bool ack, gfp_t gfp)
15868 struct wiphy *wiphy = wdev->wiphy;
15869 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15870 struct net_device *netdev = wdev->netdev;
15871 struct sk_buff *msg;
15874 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
15876 msg = nlmsg_new(100 + len, gfp);
15880 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
15886 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15887 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15888 netdev->ifindex)) ||
15889 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15890 NL80211_ATTR_PAD) ||
15891 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15892 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15893 NL80211_ATTR_PAD) ||
15894 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
15895 goto nla_put_failure;
15897 genlmsg_end(msg, hdr);
15899 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15900 NL80211_MCGRP_MLME, gfp);
15906 EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
15908 static int __nl80211_rx_control_port(struct net_device *dev,
15909 struct sk_buff *skb,
15910 bool unencrypted, gfp_t gfp)
15912 struct wireless_dev *wdev = dev->ieee80211_ptr;
15913 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15914 struct ethhdr *ehdr = eth_hdr(skb);
15915 const u8 *addr = ehdr->h_source;
15916 u16 proto = be16_to_cpu(skb->protocol);
15917 struct sk_buff *msg;
15919 struct nlattr *frame;
15921 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
15926 msg = nlmsg_new(100 + skb->len, gfp);
15930 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
15936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15937 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15938 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15939 NL80211_ATTR_PAD) ||
15940 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15941 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
15942 (unencrypted && nla_put_flag(msg,
15943 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
15944 goto nla_put_failure;
15946 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
15948 goto nla_put_failure;
15950 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
15951 genlmsg_end(msg, hdr);
15953 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15960 bool cfg80211_rx_control_port(struct net_device *dev,
15961 struct sk_buff *skb, bool unencrypted)
15965 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
15966 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
15967 trace_cfg80211_return_bool(ret == 0);
15970 EXPORT_SYMBOL(cfg80211_rx_control_port);
15972 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15973 const char *mac, gfp_t gfp)
15975 struct wireless_dev *wdev = dev->ieee80211_ptr;
15976 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15977 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15983 cb = (void **)msg->cb;
15985 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
15991 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15992 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15993 goto nla_put_failure;
15995 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
15996 goto nla_put_failure;
15998 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
16000 goto nla_put_failure;
16010 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
16012 void **cb = (void **)msg->cb;
16013 struct cfg80211_registered_device *rdev = cb[2];
16015 nla_nest_end(msg, cb[1]);
16016 genlmsg_end(msg, cb[0]);
16018 memset(msg->cb, 0, sizeof(msg->cb));
16020 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16021 NL80211_MCGRP_MLME, gfp);
16024 void cfg80211_cqm_rssi_notify(struct net_device *dev,
16025 enum nl80211_cqm_rssi_threshold_event rssi_event,
16026 s32 rssi_level, gfp_t gfp)
16028 struct sk_buff *msg;
16029 struct wireless_dev *wdev = dev->ieee80211_ptr;
16030 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16032 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
16034 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
16035 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
16038 if (wdev->cqm_config) {
16039 wdev->cqm_config->last_rssi_event_value = rssi_level;
16041 cfg80211_cqm_rssi_update(rdev, dev);
16043 if (rssi_level == 0)
16044 rssi_level = wdev->cqm_config->last_rssi_event_value;
16047 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16051 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
16053 goto nla_put_failure;
16055 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
16057 goto nla_put_failure;
16059 cfg80211_send_cqm(msg, gfp);
16066 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
16068 void cfg80211_cqm_txe_notify(struct net_device *dev,
16069 const u8 *peer, u32 num_packets,
16070 u32 rate, u32 intvl, gfp_t gfp)
16072 struct sk_buff *msg;
16074 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16078 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
16079 goto nla_put_failure;
16081 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
16082 goto nla_put_failure;
16084 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
16085 goto nla_put_failure;
16087 cfg80211_send_cqm(msg, gfp);
16093 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16095 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
16096 const u8 *peer, u32 num_packets, gfp_t gfp)
16098 struct sk_buff *msg;
16100 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
16102 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16106 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
16107 goto nla_put_failure;
16109 cfg80211_send_cqm(msg, gfp);
16115 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16117 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
16119 struct sk_buff *msg;
16121 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16125 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
16126 goto nla_put_failure;
16128 cfg80211_send_cqm(msg, gfp);
16134 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16136 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
16137 struct net_device *netdev, const u8 *bssid,
16138 const u8 *replay_ctr, gfp_t gfp)
16140 struct sk_buff *msg;
16141 struct nlattr *rekey_attr;
16144 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16148 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
16154 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16155 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16156 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16157 goto nla_put_failure;
16159 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
16161 goto nla_put_failure;
16163 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16164 NL80211_REPLAY_CTR_LEN, replay_ctr))
16165 goto nla_put_failure;
16167 nla_nest_end(msg, rekey_attr);
16169 genlmsg_end(msg, hdr);
16171 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16172 NL80211_MCGRP_MLME, gfp);
16179 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
16180 const u8 *replay_ctr, gfp_t gfp)
16182 struct wireless_dev *wdev = dev->ieee80211_ptr;
16183 struct wiphy *wiphy = wdev->wiphy;
16184 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16186 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16187 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
16189 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
16192 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
16193 struct net_device *netdev, int index,
16194 const u8 *bssid, bool preauth, gfp_t gfp)
16196 struct sk_buff *msg;
16197 struct nlattr *attr;
16200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16204 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
16210 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16211 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16212 goto nla_put_failure;
16214 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
16216 goto nla_put_failure;
16218 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
16219 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
16221 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
16222 goto nla_put_failure;
16224 nla_nest_end(msg, attr);
16226 genlmsg_end(msg, hdr);
16228 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16229 NL80211_MCGRP_MLME, gfp);
16236 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
16237 const u8 *bssid, bool preauth, gfp_t gfp)
16239 struct wireless_dev *wdev = dev->ieee80211_ptr;
16240 struct wiphy *wiphy = wdev->wiphy;
16241 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16243 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
16244 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
16246 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
16248 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
16249 struct net_device *netdev,
16250 struct cfg80211_chan_def *chandef,
16252 enum nl80211_commands notif,
16255 struct sk_buff *msg;
16258 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16262 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
16268 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16269 goto nla_put_failure;
16271 if (nl80211_send_chandef(msg, chandef))
16272 goto nla_put_failure;
16274 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
16275 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
16276 goto nla_put_failure;
16278 genlmsg_end(msg, hdr);
16280 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16281 NL80211_MCGRP_MLME, gfp);
16288 void cfg80211_ch_switch_notify(struct net_device *dev,
16289 struct cfg80211_chan_def *chandef)
16291 struct wireless_dev *wdev = dev->ieee80211_ptr;
16292 struct wiphy *wiphy = wdev->wiphy;
16293 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16295 ASSERT_WDEV_LOCK(wdev);
16297 trace_cfg80211_ch_switch_notify(dev, chandef);
16299 wdev->chandef = *chandef;
16300 wdev->preset_chandef = *chandef;
16302 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16303 !WARN_ON(!wdev->current_bss))
16304 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
16306 cfg80211_sched_dfs_chan_update(rdev);
16308 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16309 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
16311 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
16313 void cfg80211_ch_switch_started_notify(struct net_device *dev,
16314 struct cfg80211_chan_def *chandef,
16317 struct wireless_dev *wdev = dev->ieee80211_ptr;
16318 struct wiphy *wiphy = wdev->wiphy;
16319 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16321 trace_cfg80211_ch_switch_started_notify(dev, chandef);
16323 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16324 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
16326 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
16329 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
16330 const struct cfg80211_chan_def *chandef,
16331 enum nl80211_radar_event event,
16332 struct net_device *netdev, gfp_t gfp)
16334 struct sk_buff *msg;
16337 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16341 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
16347 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16348 goto nla_put_failure;
16350 /* NOP and radar events don't need a netdev parameter */
16352 struct wireless_dev *wdev = netdev->ieee80211_ptr;
16354 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16355 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16357 goto nla_put_failure;
16360 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
16361 goto nla_put_failure;
16363 if (nl80211_send_chandef(msg, chandef))
16364 goto nla_put_failure;
16366 genlmsg_end(msg, hdr);
16368 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16369 NL80211_MCGRP_MLME, gfp);
16376 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
16377 struct sta_opmode_info *sta_opmode,
16380 struct sk_buff *msg;
16381 struct wireless_dev *wdev = dev->ieee80211_ptr;
16382 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16388 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16392 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
16398 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16399 goto nla_put_failure;
16401 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16402 goto nla_put_failure;
16404 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16405 goto nla_put_failure;
16407 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
16408 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
16409 goto nla_put_failure;
16411 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
16412 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
16413 goto nla_put_failure;
16415 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
16416 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
16417 goto nla_put_failure;
16419 genlmsg_end(msg, hdr);
16421 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16422 NL80211_MCGRP_MLME, gfp);
16429 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
16431 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
16432 u64 cookie, bool acked, s32 ack_signal,
16433 bool is_valid_ack_signal, gfp_t gfp)
16435 struct wireless_dev *wdev = dev->ieee80211_ptr;
16436 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16437 struct sk_buff *msg;
16440 trace_cfg80211_probe_status(dev, addr, cookie, acked);
16442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
16453 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16454 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16455 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
16456 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16457 NL80211_ATTR_PAD) ||
16458 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
16459 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
16461 goto nla_put_failure;
16463 genlmsg_end(msg, hdr);
16465 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16466 NL80211_MCGRP_MLME, gfp);
16472 EXPORT_SYMBOL(cfg80211_probe_status);
16474 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
16475 const u8 *frame, size_t len,
16476 int freq, int sig_dbm)
16478 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16479 struct sk_buff *msg;
16481 struct cfg80211_beacon_registration *reg;
16483 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
16485 spin_lock_bh(&rdev->beacon_registrations_lock);
16486 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
16487 msg = nlmsg_new(len + 100, GFP_ATOMIC);
16489 spin_unlock_bh(&rdev->beacon_registrations_lock);
16493 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16495 goto nla_put_failure;
16497 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16499 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
16501 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16502 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
16503 goto nla_put_failure;
16505 genlmsg_end(msg, hdr);
16507 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
16509 spin_unlock_bh(&rdev->beacon_registrations_lock);
16513 spin_unlock_bh(&rdev->beacon_registrations_lock);
16516 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
16519 static int cfg80211_net_detect_results(struct sk_buff *msg,
16520 struct cfg80211_wowlan_wakeup *wakeup)
16522 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
16523 struct nlattr *nl_results, *nl_match, *nl_freqs;
16526 nl_results = nla_nest_start_noflag(msg,
16527 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
16531 for (i = 0; i < nd->n_matches; i++) {
16532 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
16534 nl_match = nla_nest_start_noflag(msg, i);
16538 /* The SSID attribute is optional in nl80211, but for
16539 * simplicity reasons it's always present in the
16540 * cfg80211 structure. If a driver can't pass the
16541 * SSID, that needs to be changed. A zero length SSID
16542 * is still a valid SSID (wildcard), so it cannot be
16543 * used for this purpose.
16545 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
16546 match->ssid.ssid)) {
16547 nla_nest_cancel(msg, nl_match);
16551 if (match->n_channels) {
16552 nl_freqs = nla_nest_start_noflag(msg,
16553 NL80211_ATTR_SCAN_FREQUENCIES);
16555 nla_nest_cancel(msg, nl_match);
16559 for (j = 0; j < match->n_channels; j++) {
16560 if (nla_put_u32(msg, j, match->channels[j])) {
16561 nla_nest_cancel(msg, nl_freqs);
16562 nla_nest_cancel(msg, nl_match);
16567 nla_nest_end(msg, nl_freqs);
16570 nla_nest_end(msg, nl_match);
16574 nla_nest_end(msg, nl_results);
16578 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
16579 struct cfg80211_wowlan_wakeup *wakeup,
16582 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16583 struct sk_buff *msg;
16587 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
16590 size += wakeup->packet_present_len;
16592 msg = nlmsg_new(size, gfp);
16596 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
16600 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16601 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16605 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16606 wdev->netdev->ifindex))
16610 struct nlattr *reasons;
16612 reasons = nla_nest_start_noflag(msg,
16613 NL80211_ATTR_WOWLAN_TRIGGERS);
16617 if (wakeup->disconnect &&
16618 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
16620 if (wakeup->magic_pkt &&
16621 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
16623 if (wakeup->gtk_rekey_failure &&
16624 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
16626 if (wakeup->eap_identity_req &&
16627 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
16629 if (wakeup->four_way_handshake &&
16630 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
16632 if (wakeup->rfkill_release &&
16633 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
16636 if (wakeup->pattern_idx >= 0 &&
16637 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
16638 wakeup->pattern_idx))
16641 if (wakeup->tcp_match &&
16642 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
16645 if (wakeup->tcp_connlost &&
16646 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16649 if (wakeup->tcp_nomoretokens &&
16651 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16654 if (wakeup->packet) {
16655 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16656 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16658 if (!wakeup->packet_80211) {
16660 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16662 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16665 if (wakeup->packet_len &&
16666 nla_put_u32(msg, len_attr, wakeup->packet_len))
16669 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16674 if (wakeup->net_detect &&
16675 cfg80211_net_detect_results(msg, wakeup))
16678 nla_nest_end(msg, reasons);
16681 genlmsg_end(msg, hdr);
16683 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16684 NL80211_MCGRP_MLME, gfp);
16690 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16693 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16694 enum nl80211_tdls_operation oper,
16695 u16 reason_code, gfp_t gfp)
16697 struct wireless_dev *wdev = dev->ieee80211_ptr;
16698 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16699 struct sk_buff *msg;
16702 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16705 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16709 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
16715 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16716 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16717 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
16718 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
16719 (reason_code > 0 &&
16720 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
16721 goto nla_put_failure;
16723 genlmsg_end(msg, hdr);
16725 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16726 NL80211_MCGRP_MLME, gfp);
16732 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
16734 static int nl80211_netlink_notify(struct notifier_block * nb,
16735 unsigned long state,
16738 struct netlink_notify *notify = _notify;
16739 struct cfg80211_registered_device *rdev;
16740 struct wireless_dev *wdev;
16741 struct cfg80211_beacon_registration *reg, *tmp;
16743 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
16744 return NOTIFY_DONE;
16748 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
16749 struct cfg80211_sched_scan_request *sched_scan_req;
16751 list_for_each_entry_rcu(sched_scan_req,
16752 &rdev->sched_scan_req_list,
16754 if (sched_scan_req->owner_nlportid == notify->portid) {
16755 sched_scan_req->nl_owner_dead = true;
16756 schedule_work(&rdev->sched_scan_stop_wk);
16760 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
16761 cfg80211_mlme_unregister_socket(wdev, notify->portid);
16763 if (wdev->owner_nlportid == notify->portid) {
16764 wdev->nl_owner_dead = true;
16765 schedule_work(&rdev->destroy_work);
16766 } else if (wdev->conn_owner_nlportid == notify->portid) {
16767 schedule_work(&wdev->disconnect_wk);
16770 cfg80211_release_pmsr(wdev, notify->portid);
16773 spin_lock_bh(&rdev->beacon_registrations_lock);
16774 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
16776 if (reg->nlportid == notify->portid) {
16777 list_del(®->list);
16782 spin_unlock_bh(&rdev->beacon_registrations_lock);
16788 * It is possible that the user space process that is controlling the
16789 * indoor setting disappeared, so notify the regulatory core.
16791 regulatory_netlink_notify(notify->portid);
16795 static struct notifier_block nl80211_netlink_notifier = {
16796 .notifier_call = nl80211_netlink_notify,
16799 void cfg80211_ft_event(struct net_device *netdev,
16800 struct cfg80211_ft_event_params *ft_event)
16802 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
16803 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16804 struct sk_buff *msg;
16807 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
16809 if (!ft_event->target_ap)
16812 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
16817 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
16821 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16822 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16823 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
16826 if (ft_event->ies &&
16827 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
16829 if (ft_event->ric_ies &&
16830 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
16831 ft_event->ric_ies))
16834 genlmsg_end(msg, hdr);
16836 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16837 NL80211_MCGRP_MLME, GFP_KERNEL);
16842 EXPORT_SYMBOL(cfg80211_ft_event);
16844 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
16846 struct cfg80211_registered_device *rdev;
16847 struct sk_buff *msg;
16851 rdev = wiphy_to_rdev(wdev->wiphy);
16852 if (!rdev->crit_proto_nlportid)
16855 nlportid = rdev->crit_proto_nlportid;
16856 rdev->crit_proto_nlportid = 0;
16858 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16862 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
16864 goto nla_put_failure;
16866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16867 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16869 goto nla_put_failure;
16871 genlmsg_end(msg, hdr);
16873 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16879 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
16881 void nl80211_send_ap_stopped(struct wireless_dev *wdev)
16883 struct wiphy *wiphy = wdev->wiphy;
16884 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16885 struct sk_buff *msg;
16888 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16892 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
16896 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16897 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
16898 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16902 genlmsg_end(msg, hdr);
16904 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
16905 NL80211_MCGRP_MLME, GFP_KERNEL);
16911 int cfg80211_external_auth_request(struct net_device *dev,
16912 struct cfg80211_external_auth_params *params,
16915 struct wireless_dev *wdev = dev->ieee80211_ptr;
16916 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16917 struct sk_buff *msg;
16920 if (!wdev->conn_owner_nlportid)
16923 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16927 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
16929 goto nla_put_failure;
16931 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16932 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16933 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
16934 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
16936 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
16937 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
16938 params->ssid.ssid))
16939 goto nla_put_failure;
16941 genlmsg_end(msg, hdr);
16942 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
16943 wdev->conn_owner_nlportid);
16950 EXPORT_SYMBOL(cfg80211_external_auth_request);
16952 void cfg80211_update_owe_info_event(struct net_device *netdev,
16953 struct cfg80211_update_owe_info *owe_info,
16956 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
16957 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16958 struct sk_buff *msg;
16961 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
16963 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16967 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
16969 goto nla_put_failure;
16971 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16972 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16973 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
16974 goto nla_put_failure;
16976 if (!owe_info->ie_len ||
16977 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
16978 goto nla_put_failure;
16980 genlmsg_end(msg, hdr);
16982 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16983 NL80211_MCGRP_MLME, gfp);
16987 genlmsg_cancel(msg, hdr);
16990 EXPORT_SYMBOL(cfg80211_update_owe_info_event);
16992 /* initialisation/exit functions */
16994 int __init nl80211_init(void)
16998 err = genl_register_family(&nl80211_fam);
17002 err = netlink_register_notifier(&nl80211_netlink_notifier);
17008 genl_unregister_family(&nl80211_fam);
17012 void nl80211_exit(void)
17014 netlink_unregister_notifier(&nl80211_netlink_notifier);
17015 genl_unregister_family(&nl80211_fam);