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-2023 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 <linux/if_vlan.h>
24 #include <net/net_namespace.h>
25 #include <net/genetlink.h>
26 #include <net/cfg80211.h>
28 #include <net/inet_connection_sock.h>
34 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
35 struct genl_info *info,
36 struct cfg80211_crypto_settings *settings,
39 /* the netlink family */
40 static struct genl_family nl80211_fam;
42 /* multicast groups */
43 enum nl80211_multicast_groups {
46 NL80211_MCGRP_REGULATORY,
50 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
53 static const struct genl_multicast_group nl80211_mcgrps[] = {
54 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
55 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
56 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
57 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
58 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
59 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
60 #ifdef CONFIG_NL80211_TESTMODE
61 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
65 /* returns ERR_PTR values */
66 static struct wireless_dev *
67 __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev,
68 struct net *netns, struct nlattr **attrs)
70 struct wireless_dev *result = NULL;
71 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
72 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
77 if (!have_ifidx && !have_wdev_id)
78 return ERR_PTR(-EINVAL);
81 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
83 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
84 wiphy_idx = wdev_id >> 32;
88 struct wireless_dev *wdev;
90 lockdep_assert_held(&rdev->wiphy.mtx);
92 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
93 if (have_ifidx && wdev->netdev &&
94 wdev->netdev->ifindex == ifidx) {
98 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
104 return result ?: ERR_PTR(-ENODEV);
109 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
110 struct wireless_dev *wdev;
112 if (wiphy_net(&rdev->wiphy) != netns)
115 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
118 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
119 if (have_ifidx && wdev->netdev &&
120 wdev->netdev->ifindex == ifidx) {
124 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
136 return ERR_PTR(-ENODEV);
139 static struct cfg80211_registered_device *
140 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
142 struct cfg80211_registered_device *rdev = NULL, *tmp;
143 struct net_device *netdev;
147 if (!attrs[NL80211_ATTR_WIPHY] &&
148 !attrs[NL80211_ATTR_IFINDEX] &&
149 !attrs[NL80211_ATTR_WDEV])
150 return ERR_PTR(-EINVAL);
152 if (attrs[NL80211_ATTR_WIPHY])
153 rdev = cfg80211_rdev_by_wiphy_idx(
154 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
156 if (attrs[NL80211_ATTR_WDEV]) {
157 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
158 struct wireless_dev *wdev;
161 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
163 /* make sure wdev exists */
164 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
165 if (wdev->identifier != (u32)wdev_id)
174 if (rdev && tmp != rdev)
175 return ERR_PTR(-EINVAL);
180 if (attrs[NL80211_ATTR_IFINDEX]) {
181 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
183 netdev = __dev_get_by_index(netns, ifindex);
185 if (netdev->ieee80211_ptr)
187 netdev->ieee80211_ptr->wiphy);
191 /* not wireless device -- return error */
193 return ERR_PTR(-EINVAL);
195 /* mismatch -- return error */
196 if (rdev && tmp != rdev)
197 return ERR_PTR(-EINVAL);
204 return ERR_PTR(-ENODEV);
206 if (netns != wiphy_net(&rdev->wiphy))
207 return ERR_PTR(-ENODEV);
213 * This function returns a pointer to the driver
214 * that the genl_info item that is passed refers to.
216 * The result of this can be a PTR_ERR and hence must
217 * be checked with IS_ERR() for errors.
219 static struct cfg80211_registered_device *
220 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
222 return __cfg80211_rdev_from_attrs(netns, info->attrs);
225 static int validate_beacon_head(const struct nlattr *attr,
226 struct netlink_ext_ack *extack)
228 const u8 *data = nla_data(attr);
229 unsigned int len = nla_len(attr);
230 const struct element *elem;
231 const struct ieee80211_mgmt *mgmt = (void *)data;
232 unsigned int fixedlen, hdrlen;
235 if (len < offsetofend(typeof(*mgmt), frame_control))
238 s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
240 fixedlen = offsetof(struct ieee80211_ext,
241 u.s1g_beacon.variable);
242 hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon);
244 fixedlen = offsetof(struct ieee80211_mgmt,
246 hdrlen = offsetof(struct ieee80211_mgmt, u.beacon);
252 if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen)
258 for_each_element(elem, data, len) {
262 if (for_each_element_completed(elem, data, len))
266 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
270 static int validate_ie_attr(const struct nlattr *attr,
271 struct netlink_ext_ack *extack)
273 const u8 *data = nla_data(attr);
274 unsigned int len = nla_len(attr);
275 const struct element *elem;
277 for_each_element(elem, data, len) {
281 if (for_each_element_completed(elem, data, len))
284 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
288 static int validate_he_capa(const struct nlattr *attr,
289 struct netlink_ext_ack *extack)
291 if (!ieee80211_he_capa_size_ok(nla_data(attr), nla_len(attr)))
297 /* policy for the attributes */
298 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR];
300 static const struct nla_policy
301 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = {
302 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, },
303 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY,
305 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY,
309 static const struct nla_policy
310 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
311 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG },
312 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 },
313 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] =
314 NLA_POLICY_MAX(NLA_U8, 15),
315 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 },
316 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] =
317 NLA_POLICY_MAX(NLA_U8, 15),
318 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] =
319 NLA_POLICY_MAX(NLA_U8, 31),
320 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 },
321 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG },
322 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG },
323 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG },
324 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG },
325 [NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK] = { .type = NLA_FLAG },
326 [NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR] = { .type = NLA_U8 },
329 static const struct nla_policy
330 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
331 [NL80211_PMSR_TYPE_FTM] =
332 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
335 static const struct nla_policy
336 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
337 [NL80211_PMSR_REQ_ATTR_DATA] =
338 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
339 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
342 static const struct nla_policy
343 nl80211_pmsr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
344 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
345 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy),
346 [NL80211_PMSR_PEER_ATTR_REQ] =
347 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
348 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
351 static const struct nla_policy
352 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
353 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
354 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
355 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
356 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
357 [NL80211_PMSR_ATTR_PEERS] =
358 NLA_POLICY_NESTED_ARRAY(nl80211_pmsr_peer_attr_policy),
361 static const struct nla_policy
362 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = {
363 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] =
364 NLA_POLICY_RANGE(NLA_U8, 1, 20),
365 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] =
366 NLA_POLICY_RANGE(NLA_U8, 1, 20),
367 [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] =
368 NLA_POLICY_RANGE(NLA_U8, 1, 20),
369 [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] =
370 NLA_POLICY_EXACT_LEN(8),
371 [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] =
372 NLA_POLICY_EXACT_LEN(8),
373 [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 },
376 static const struct nla_policy
377 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = {
378 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63),
379 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG },
380 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG },
383 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
384 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
385 .len = NL80211_MAX_SUPP_RATES },
386 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
387 .len = NL80211_MAX_SUPP_HT_RATES },
388 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)),
389 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
390 [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)),
391 [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8,
392 NL80211_RATE_INFO_HE_GI_0_8,
393 NL80211_RATE_INFO_HE_GI_3_2),
394 [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8,
395 NL80211_RATE_INFO_HE_1XLTF,
396 NL80211_RATE_INFO_HE_4XLTF),
399 static const struct nla_policy
400 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = {
401 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 },
402 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 },
403 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG },
404 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff),
405 [NL80211_TID_CONFIG_ATTR_NOACK] =
406 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
407 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
408 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
409 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] =
410 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
411 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] =
412 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
413 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] =
414 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
415 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] =
416 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED),
417 [NL80211_TID_CONFIG_ATTR_TX_RATE] =
418 NLA_POLICY_NESTED(nl80211_txattr_policy),
421 static const struct nla_policy
422 nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = {
423 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000),
424 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000),
425 [NL80211_FILS_DISCOVERY_ATTR_TMPL] =
426 NLA_POLICY_RANGE(NLA_BINARY,
427 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN,
428 IEEE80211_MAX_DATA_LEN),
431 static const struct nla_policy
432 nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = {
433 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20),
434 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY,
435 .len = IEEE80211_MAX_DATA_LEN }
438 static const struct nla_policy
439 sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = {
440 [NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_S32 },
441 [NL80211_SAR_ATTR_SPECS_RANGE_INDEX] = {.type = NLA_U32 },
444 static const struct nla_policy
445 sar_policy[NL80211_SAR_ATTR_MAX + 1] = {
446 [NL80211_SAR_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_SAR_TYPE),
447 [NL80211_SAR_ATTR_SPECS] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy),
450 static const struct nla_policy
451 nl80211_mbssid_config_policy[NL80211_MBSSID_CONFIG_ATTR_MAX + 1] = {
452 [NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES] = NLA_POLICY_MIN(NLA_U8, 2),
453 [NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY] =
454 NLA_POLICY_MIN(NLA_U8, 1),
455 [NL80211_MBSSID_CONFIG_ATTR_INDEX] = { .type = NLA_U8 },
456 [NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX] = { .type = NLA_U32 },
457 [NL80211_MBSSID_CONFIG_ATTR_EMA] = { .type = NLA_FLAG },
460 static const struct nla_policy
461 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
462 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
463 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
466 static struct netlink_range_validation nl80211_punct_bitmap_range = {
471 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
472 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
473 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
474 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
476 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
478 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
479 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
480 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
481 NL80211_EDMG_CHANNELS_MIN,
482 NL80211_EDMG_CHANNELS_MAX),
483 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
484 NL80211_EDMG_BW_CONFIG_MIN,
485 NL80211_EDMG_BW_CONFIG_MAX),
487 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
488 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
489 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
490 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
492 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
493 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
494 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
495 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
496 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
497 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
499 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
500 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
501 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
503 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
504 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
506 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
507 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
508 .len = WLAN_MAX_KEY_LEN },
509 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
510 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
511 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
512 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
513 [NL80211_ATTR_KEY_TYPE] =
514 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
516 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
517 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
518 [NL80211_ATTR_BEACON_HEAD] =
519 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
520 IEEE80211_MAX_DATA_LEN),
521 [NL80211_ATTR_BEACON_TAIL] =
522 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
523 IEEE80211_MAX_DATA_LEN),
524 [NL80211_ATTR_STA_AID] =
525 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
526 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
527 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
528 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
529 .len = NL80211_MAX_SUPP_RATES },
530 [NL80211_ATTR_STA_PLINK_ACTION] =
531 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
532 [NL80211_ATTR_STA_TX_POWER_SETTING] =
533 NLA_POLICY_RANGE(NLA_U8,
534 NL80211_TX_POWER_AUTOMATIC,
535 NL80211_TX_POWER_FIXED),
536 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
537 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
538 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
539 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
540 .len = IEEE80211_MAX_MESH_ID_LEN },
541 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
543 /* allow 3 for NUL-termination, we used to declare this NLA_STRING */
544 [NL80211_ATTR_REG_ALPHA2] = NLA_POLICY_RANGE(NLA_BINARY, 2, 3),
545 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
547 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
548 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
549 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
550 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
551 .len = NL80211_MAX_SUPP_RATES },
552 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
554 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
555 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
557 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN),
559 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
560 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
562 IEEE80211_MAX_DATA_LEN),
563 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
564 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
566 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
567 .len = IEEE80211_MAX_SSID_LEN },
568 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
569 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
570 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
571 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
572 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
574 NL80211_MFP_OPTIONAL),
575 [NL80211_ATTR_STA_FLAGS2] =
576 NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_sta_flag_update)),
577 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
578 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
579 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
580 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
581 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
582 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
583 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
584 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
585 [NL80211_ATTR_PID] = { .type = NLA_U32 },
586 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
587 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN),
588 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
589 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
590 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
591 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
592 .len = IEEE80211_MAX_DATA_LEN },
593 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
594 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
597 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
598 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
599 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
600 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
601 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
602 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
603 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
604 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
605 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
606 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
607 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
608 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
609 [NL80211_ATTR_STA_PLINK_STATE] =
610 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
611 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
612 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
613 [NL80211_ATTR_MESH_PEER_AID] =
614 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
615 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
616 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
617 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
618 [NL80211_ATTR_HIDDEN_SSID] =
619 NLA_POLICY_RANGE(NLA_U32,
620 NL80211_HIDDEN_SSID_NOT_IN_USE,
621 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
622 [NL80211_ATTR_IE_PROBE_RESP] =
623 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
624 IEEE80211_MAX_DATA_LEN),
625 [NL80211_ATTR_IE_ASSOC_RESP] =
626 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
627 IEEE80211_MAX_DATA_LEN),
628 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
629 [NL80211_ATTR_STA_WME] = NLA_POLICY_NESTED(nl80211_sta_wme_policy),
630 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
631 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
632 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
633 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
634 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
635 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
636 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
637 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
638 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
639 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
640 .len = IEEE80211_MAX_DATA_LEN },
641 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
642 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
643 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
644 .len = NL80211_HT_CAPABILITY_LEN
646 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
647 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
648 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
649 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
650 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
652 /* need to include at least Auth Transaction and Status Code */
653 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4),
655 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN),
656 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
657 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
658 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
659 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
660 NLA_POLICY_RANGE(NLA_U32,
661 NL80211_MESH_POWER_UNKNOWN + 1,
662 NL80211_MESH_POWER_MAX),
663 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
664 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
665 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
666 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
667 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
668 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
669 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
670 .len = NL80211_VHT_CAPABILITY_LEN,
672 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
673 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
674 .len = IEEE80211_MAX_DATA_LEN },
675 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
676 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] =
677 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION),
678 [NL80211_ATTR_PEER_AID] =
679 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
680 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
681 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
682 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
683 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY },
684 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY },
685 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2),
687 * The value of the Length field of the Supported Operating
688 * Classes element is between 2 and 253.
690 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] =
691 NLA_POLICY_RANGE(NLA_BINARY, 2, 253),
692 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
693 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
694 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
695 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
696 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
697 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY,
698 IEEE80211_QOS_MAP_LEN_MIN,
699 IEEE80211_QOS_MAP_LEN_MAX),
700 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
701 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
702 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
703 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
704 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
705 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
706 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
707 [NL80211_ATTR_USER_PRIO] =
708 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
709 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
710 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
711 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
712 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
713 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
714 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
715 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
716 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
717 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
718 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
719 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
720 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
721 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
722 .len = VHT_MUMIMO_GROUPS_DATA_LEN
724 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
725 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
726 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
727 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
728 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
729 .len = FILS_MAX_KEK_LEN },
730 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN),
731 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
732 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
733 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
734 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
735 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
737 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
738 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
739 .len = FILS_ERP_MAX_USERNAME_LEN },
740 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
741 .len = FILS_ERP_MAX_REALM_LEN },
742 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
743 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
744 .len = FILS_ERP_MAX_RRK_LEN },
745 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2),
746 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
747 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN),
748 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
749 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
751 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
752 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
753 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
754 [NL80211_ATTR_HE_CAPABILITY] =
755 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_he_capa,
756 NL80211_HE_MAX_CAPABILITY_LEN),
757 [NL80211_ATTR_FTM_RESPONDER] =
758 NLA_POLICY_NESTED(nl80211_ftm_responder_policy),
759 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
760 [NL80211_ATTR_PEER_MEASUREMENTS] =
761 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
762 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
763 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
764 .len = SAE_PASSWORD_MAX_LEN },
765 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
766 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
767 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
768 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
769 [NL80211_ATTR_TID_CONFIG] =
770 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
771 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG },
772 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1),
773 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100),
774 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG },
775 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
776 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED },
777 [NL80211_ATTR_HE_6GHZ_CAPABILITY] =
778 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)),
779 [NL80211_ATTR_FILS_DISCOVERY] =
780 NLA_POLICY_NESTED(nl80211_fils_discovery_policy),
781 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] =
782 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy),
783 [NL80211_ATTR_S1G_CAPABILITY] =
784 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
785 [NL80211_ATTR_S1G_CAPABILITY_MASK] =
786 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
787 [NL80211_ATTR_SAE_PWE] =
788 NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK,
789 NL80211_SAE_PWE_BOTH),
790 [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT },
791 [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy),
792 [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG },
793 [NL80211_ATTR_OBSS_COLOR_BITMAP] = { .type = NLA_U64 },
794 [NL80211_ATTR_COLOR_CHANGE_COUNT] = { .type = NLA_U8 },
795 [NL80211_ATTR_COLOR_CHANGE_COLOR] = { .type = NLA_U8 },
796 [NL80211_ATTR_COLOR_CHANGE_ELEMS] = NLA_POLICY_NESTED(nl80211_policy),
797 [NL80211_ATTR_MBSSID_CONFIG] =
798 NLA_POLICY_NESTED(nl80211_mbssid_config_policy),
799 [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED },
800 [NL80211_ATTR_RADAR_BACKGROUND] = { .type = NLA_FLAG },
801 [NL80211_ATTR_AP_SETTINGS_FLAGS] = { .type = NLA_U32 },
802 [NL80211_ATTR_EHT_CAPABILITY] =
803 NLA_POLICY_RANGE(NLA_BINARY,
804 NL80211_EHT_MIN_CAPABILITY_LEN,
805 NL80211_EHT_MAX_CAPABILITY_LEN),
806 [NL80211_ATTR_DISABLE_EHT] = { .type = NLA_FLAG },
807 [NL80211_ATTR_MLO_LINKS] =
808 NLA_POLICY_NESTED_ARRAY(nl80211_policy),
809 [NL80211_ATTR_MLO_LINK_ID] =
810 NLA_POLICY_RANGE(NLA_U8, 0, IEEE80211_MLD_MAX_NUM_LINKS),
811 [NL80211_ATTR_MLD_ADDR] = NLA_POLICY_EXACT_LEN(ETH_ALEN),
812 [NL80211_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG },
813 [NL80211_ATTR_MAX_NUM_AKM_SUITES] = { .type = NLA_REJECT },
814 [NL80211_ATTR_PUNCT_BITMAP] =
815 NLA_POLICY_FULL_RANGE(NLA_U32, &nl80211_punct_bitmap_range),
817 [NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS] = { .type = NLA_U16 },
818 [NL80211_ATTR_HW_TIMESTAMP_ENABLED] = { .type = NLA_FLAG },
819 [NL80211_ATTR_EMA_RNR_ELEMS] = { .type = NLA_NESTED },
820 [NL80211_ATTR_MLO_LINK_DISABLED] = { .type = NLA_FLAG },
823 /* policy for the key attributes */
824 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
825 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
826 [NL80211_KEY_IDX] = { .type = NLA_U8 },
827 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
828 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
829 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
830 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
831 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
832 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
833 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
836 /* policy for the key default flags */
837 static const struct nla_policy
838 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
839 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
840 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
844 /* policy for WoWLAN attributes */
845 static const struct nla_policy
846 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
847 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
848 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
849 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
850 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
851 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
852 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
853 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
854 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
855 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
856 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
859 static const struct nla_policy
860 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
861 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
862 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
863 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
864 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
865 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
866 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
867 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
868 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
870 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
871 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
873 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
874 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
875 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1),
877 #endif /* CONFIG_PM */
879 /* policy for coalesce rule attributes */
880 static const struct nla_policy
881 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
882 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
883 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
884 NLA_POLICY_RANGE(NLA_U32,
885 NL80211_COALESCE_CONDITION_MATCH,
886 NL80211_COALESCE_CONDITION_NO_MATCH),
887 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
890 /* policy for GTK rekey offload attributes */
891 static const struct nla_policy
892 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
893 [NL80211_REKEY_DATA_KEK] = {
895 .len = NL80211_KEK_EXT_LEN
897 [NL80211_REKEY_DATA_KCK] = {
899 .len = NL80211_KCK_EXT_LEN_32
901 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN),
902 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 },
905 static const struct nla_policy
906 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
907 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
908 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
909 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
910 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
911 [NL80211_BAND_LC] = { .type = NLA_S32 },
914 static const struct nla_policy
915 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
916 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
917 .len = IEEE80211_MAX_SSID_LEN },
918 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
919 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
920 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
921 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
924 static const struct nla_policy
925 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
926 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
927 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
930 static const struct nla_policy
931 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
932 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
933 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
934 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
935 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
939 /* policy for NAN function attributes */
940 static const struct nla_policy
941 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
942 [NL80211_NAN_FUNC_TYPE] =
943 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE),
944 [NL80211_NAN_FUNC_SERVICE_ID] = {
945 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
946 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
947 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
948 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
949 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
950 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
951 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
952 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
953 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
954 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
955 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
956 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
957 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
958 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
959 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
960 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
963 /* policy for Service Response Filter attributes */
964 static const struct nla_policy
965 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
966 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
967 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
968 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
969 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
970 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
973 /* policy for packet pattern attributes */
974 static const struct nla_policy
975 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
976 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
977 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
978 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
981 static int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
982 struct cfg80211_registered_device **rdev,
983 struct wireless_dev **wdev,
984 struct nlattr **attrbuf)
989 struct nlattr **attrbuf_free = NULL;
992 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
996 attrbuf_free = attrbuf;
999 err = nlmsg_parse_deprecated(cb->nlh,
1000 GENL_HDRLEN + nl80211_fam.hdrsize,
1001 attrbuf, nl80211_fam.maxattr,
1002 nl80211_policy, NULL);
1004 kfree(attrbuf_free);
1009 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk),
1011 kfree(attrbuf_free);
1012 if (IS_ERR(*wdev)) {
1014 return PTR_ERR(*wdev);
1016 *rdev = wiphy_to_rdev((*wdev)->wiphy);
1017 mutex_lock(&(*rdev)->wiphy.mtx);
1019 /* 0 is the first index - add 1 to parse only once */
1020 cb->args[0] = (*rdev)->wiphy_idx + 1;
1021 cb->args[1] = (*wdev)->identifier;
1023 /* subtract the 1 again here */
1024 struct wiphy *wiphy;
1025 struct wireless_dev *tmp;
1028 wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
1033 *rdev = wiphy_to_rdev(wiphy);
1036 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
1037 if (tmp->identifier == cb->args[1]) {
1047 mutex_lock(&(*rdev)->wiphy.mtx);
1054 /* message building helper */
1055 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
1058 /* since there is no private header just add the generic one */
1059 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
1062 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
1063 const struct ieee80211_reg_rule *rule)
1066 struct nlattr *nl_wmm_rules =
1067 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
1070 goto nla_put_failure;
1072 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
1073 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
1076 goto nla_put_failure;
1078 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
1079 rule->wmm_rule.client[j].cw_min) ||
1080 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
1081 rule->wmm_rule.client[j].cw_max) ||
1082 nla_put_u8(msg, NL80211_WMMR_AIFSN,
1083 rule->wmm_rule.client[j].aifsn) ||
1084 nla_put_u16(msg, NL80211_WMMR_TXOP,
1085 rule->wmm_rule.client[j].cot))
1086 goto nla_put_failure;
1088 nla_nest_end(msg, nl_wmm_rule);
1090 nla_nest_end(msg, nl_wmm_rules);
1098 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
1099 struct ieee80211_channel *chan,
1102 /* Some channels must be completely excluded from the
1103 * list to protect old user-space tools from breaking
1105 if (!large && chan->flags &
1106 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
1108 if (!large && chan->freq_offset)
1111 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
1113 goto nla_put_failure;
1115 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
1116 goto nla_put_failure;
1118 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
1119 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
1120 goto nla_put_failure;
1121 if (chan->flags & IEEE80211_CHAN_NO_IR) {
1122 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
1123 goto nla_put_failure;
1124 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
1125 goto nla_put_failure;
1127 if (chan->flags & IEEE80211_CHAN_RADAR) {
1128 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
1129 goto nla_put_failure;
1133 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
1135 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
1137 goto nla_put_failure;
1138 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
1140 goto nla_put_failure;
1141 if (nla_put_u32(msg,
1142 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
1144 goto nla_put_failure;
1149 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
1150 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
1151 goto nla_put_failure;
1152 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
1153 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
1154 goto nla_put_failure;
1155 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
1156 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
1157 goto nla_put_failure;
1158 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
1159 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
1160 goto nla_put_failure;
1161 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
1162 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
1163 goto nla_put_failure;
1164 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
1165 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
1166 goto nla_put_failure;
1167 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
1168 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
1169 goto nla_put_failure;
1170 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
1171 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
1172 goto nla_put_failure;
1173 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
1174 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
1175 goto nla_put_failure;
1176 if ((chan->flags & IEEE80211_CHAN_1MHZ) &&
1177 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ))
1178 goto nla_put_failure;
1179 if ((chan->flags & IEEE80211_CHAN_2MHZ) &&
1180 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ))
1181 goto nla_put_failure;
1182 if ((chan->flags & IEEE80211_CHAN_4MHZ) &&
1183 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ))
1184 goto nla_put_failure;
1185 if ((chan->flags & IEEE80211_CHAN_8MHZ) &&
1186 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ))
1187 goto nla_put_failure;
1188 if ((chan->flags & IEEE80211_CHAN_16MHZ) &&
1189 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ))
1190 goto nla_put_failure;
1191 if ((chan->flags & IEEE80211_CHAN_NO_320MHZ) &&
1192 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_320MHZ))
1193 goto nla_put_failure;
1194 if ((chan->flags & IEEE80211_CHAN_NO_EHT) &&
1195 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_EHT))
1196 goto nla_put_failure;
1199 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
1200 DBM_TO_MBM(chan->max_power)))
1201 goto nla_put_failure;
1204 const struct ieee80211_reg_rule *rule =
1205 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
1207 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
1208 if (nl80211_msg_put_wmm_rules(msg, rule))
1209 goto nla_put_failure;
1219 static bool nl80211_put_txq_stats(struct sk_buff *msg,
1220 struct cfg80211_txq_stats *txqstats,
1223 struct nlattr *txqattr;
1225 #define PUT_TXQVAL_U32(attr, memb) do { \
1226 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1227 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1231 txqattr = nla_nest_start_noflag(msg, attrtype);
1235 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1236 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1237 PUT_TXQVAL_U32(FLOWS, flows);
1238 PUT_TXQVAL_U32(DROPS, drops);
1239 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1240 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1241 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1242 PUT_TXQVAL_U32(COLLISIONS, collisions);
1243 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1244 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1245 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1246 nla_nest_end(msg, txqattr);
1248 #undef PUT_TXQVAL_U32
1252 /* netlink command implementations */
1255 * nl80211_link_id - return link ID
1256 * @attrs: attributes to look at
1258 * Returns: the link ID or 0 if not given
1260 * Note this function doesn't do any validation of the link
1261 * ID validity wrt. links that were actually added, so it must
1262 * be called only from ops with %NL80211_FLAG_MLO_VALID_LINK_ID
1263 * or if additional validation is done.
1265 static unsigned int nl80211_link_id(struct nlattr **attrs)
1267 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID];
1272 return nla_get_u8(linkid);
1275 static int nl80211_link_id_or_invalid(struct nlattr **attrs)
1277 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID];
1282 return nla_get_u8(linkid);
1286 struct key_params p;
1289 bool def, defmgmt, defbeacon;
1290 bool def_uni, def_multi;
1293 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1294 struct key_parse *k)
1296 struct nlattr *tb[NL80211_KEY_MAX + 1];
1297 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1303 k->def = !!tb[NL80211_KEY_DEFAULT];
1304 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1305 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
1309 k->def_multi = true;
1311 if (k->defmgmt || k->defbeacon)
1312 k->def_multi = true;
1314 if (tb[NL80211_KEY_IDX])
1315 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1317 if (tb[NL80211_KEY_DATA]) {
1318 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1319 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1322 if (tb[NL80211_KEY_SEQ]) {
1323 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1324 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1327 if (tb[NL80211_KEY_CIPHER])
1328 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1330 if (tb[NL80211_KEY_TYPE])
1331 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
1333 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1334 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1336 err = nla_parse_nested_deprecated(kdt,
1337 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1338 tb[NL80211_KEY_DEFAULT_TYPES],
1339 nl80211_key_default_policy,
1344 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1345 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1348 if (tb[NL80211_KEY_MODE])
1349 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1354 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1356 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1357 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1358 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1361 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1362 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1363 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1366 if (info->attrs[NL80211_ATTR_KEY_IDX])
1367 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1369 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1370 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1372 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1373 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1377 k->def_multi = true;
1380 k->def_multi = true;
1382 if (info->attrs[NL80211_ATTR_KEY_TYPE])
1383 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1385 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1386 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1387 int err = nla_parse_nested_deprecated(kdt,
1388 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1389 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1390 nl80211_key_default_policy,
1395 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1396 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1402 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1406 memset(k, 0, sizeof(*k));
1410 if (info->attrs[NL80211_ATTR_KEY])
1411 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
1413 err = nl80211_parse_key_old(info, k);
1418 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1419 (k->defbeacon ? 1 : 0) > 1) {
1420 GENL_SET_ERR_MSG(info,
1421 "key with multiple default flags is invalid");
1425 if (k->defmgmt || k->defbeacon) {
1426 if (k->def_uni || !k->def_multi) {
1427 GENL_SET_ERR_MSG(info,
1428 "defmgmt/defbeacon key must be mcast");
1435 if (k->idx < 4 || k->idx > 5) {
1436 GENL_SET_ERR_MSG(info,
1437 "defmgmt key idx not 4 or 5");
1440 } else if (k->defbeacon) {
1441 if (k->idx < 6 || k->idx > 7) {
1442 GENL_SET_ERR_MSG(info,
1443 "defbeacon key idx not 6 or 7");
1446 } else if (k->def) {
1447 if (k->idx < 0 || k->idx > 3) {
1448 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
1452 if (k->idx < 0 || k->idx > 7) {
1453 GENL_SET_ERR_MSG(info, "key idx not 0-7");
1462 static struct cfg80211_cached_keys *
1463 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
1464 struct genl_info *info, bool *no_ht)
1466 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
1467 struct key_parse parse;
1469 struct cfg80211_cached_keys *result;
1470 int rem, err, def = 0;
1471 bool have_key = false;
1473 nla_for_each_nested(key, keys, rem) {
1481 result = kzalloc(sizeof(*result), GFP_KERNEL);
1483 return ERR_PTR(-ENOMEM);
1487 nla_for_each_nested(key, keys, rem) {
1488 memset(&parse, 0, sizeof(parse));
1491 err = nl80211_parse_key_new(info, key, &parse);
1497 if (parse.idx < 0 || parse.idx > 3) {
1498 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
1503 GENL_SET_ERR_MSG(info,
1504 "only one key can be default");
1508 result->def = parse.idx;
1509 if (!parse.def_uni || !parse.def_multi)
1511 } else if (parse.defmgmt)
1513 err = cfg80211_validate_key_settings(rdev, &parse.p,
1514 parse.idx, false, NULL);
1517 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1518 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
1519 GENL_SET_ERR_MSG(info, "connect key must be WEP");
1523 result->params[parse.idx].cipher = parse.p.cipher;
1524 result->params[parse.idx].key_len = parse.p.key_len;
1525 result->params[parse.idx].key = result->data[parse.idx];
1526 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
1528 /* must be WEP key if we got here */
1533 if (result->def < 0) {
1535 GENL_SET_ERR_MSG(info, "need a default/TX key");
1542 return ERR_PTR(err);
1545 static int nl80211_key_allowed(struct wireless_dev *wdev)
1547 ASSERT_WDEV_LOCK(wdev);
1549 switch (wdev->iftype) {
1550 case NL80211_IFTYPE_AP:
1551 case NL80211_IFTYPE_AP_VLAN:
1552 case NL80211_IFTYPE_P2P_GO:
1553 case NL80211_IFTYPE_MESH_POINT:
1555 case NL80211_IFTYPE_ADHOC:
1556 if (wdev->u.ibss.current_bss)
1559 case NL80211_IFTYPE_STATION:
1560 case NL80211_IFTYPE_P2P_CLIENT:
1561 if (wdev->connected)
1564 case NL80211_IFTYPE_NAN:
1565 if (wiphy_ext_feature_isset(wdev->wiphy,
1566 NL80211_EXT_FEATURE_SECURE_NAN))
1569 case NL80211_IFTYPE_UNSPECIFIED:
1570 case NL80211_IFTYPE_OCB:
1571 case NL80211_IFTYPE_MONITOR:
1572 case NL80211_IFTYPE_P2P_DEVICE:
1573 case NL80211_IFTYPE_WDS:
1574 case NUM_NL80211_IFTYPES:
1581 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1584 struct ieee80211_channel *chan;
1586 chan = ieee80211_get_channel_khz(wiphy, freq);
1587 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1592 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1594 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
1598 goto nla_put_failure;
1602 if ((ifmodes & 1) && nla_put_flag(msg, i))
1603 goto nla_put_failure;
1608 nla_nest_end(msg, nl_modes);
1615 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1616 struct sk_buff *msg,
1619 struct nlattr *nl_combis;
1622 nl_combis = nla_nest_start_noflag(msg,
1623 NL80211_ATTR_INTERFACE_COMBINATIONS);
1625 goto nla_put_failure;
1627 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1628 const struct ieee80211_iface_combination *c;
1629 struct nlattr *nl_combi, *nl_limits;
1631 c = &wiphy->iface_combinations[i];
1633 nl_combi = nla_nest_start_noflag(msg, i + 1);
1635 goto nla_put_failure;
1637 nl_limits = nla_nest_start_noflag(msg,
1638 NL80211_IFACE_COMB_LIMITS);
1640 goto nla_put_failure;
1642 for (j = 0; j < c->n_limits; j++) {
1643 struct nlattr *nl_limit;
1645 nl_limit = nla_nest_start_noflag(msg, j + 1);
1647 goto nla_put_failure;
1648 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1650 goto nla_put_failure;
1651 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1652 c->limits[j].types))
1653 goto nla_put_failure;
1654 nla_nest_end(msg, nl_limit);
1657 nla_nest_end(msg, nl_limits);
1659 if (c->beacon_int_infra_match &&
1660 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1661 goto nla_put_failure;
1662 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1663 c->num_different_channels) ||
1664 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1666 goto nla_put_failure;
1668 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1669 c->radar_detect_widths) ||
1670 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1671 c->radar_detect_regions)))
1672 goto nla_put_failure;
1673 if (c->beacon_int_min_gcd &&
1674 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1675 c->beacon_int_min_gcd))
1676 goto nla_put_failure;
1678 nla_nest_end(msg, nl_combi);
1681 nla_nest_end(msg, nl_combis);
1689 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1690 struct sk_buff *msg)
1692 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
1693 struct nlattr *nl_tcp;
1698 nl_tcp = nla_nest_start_noflag(msg,
1699 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1703 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1704 tcp->data_payload_max))
1707 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1708 tcp->data_payload_max))
1711 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1714 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1715 sizeof(*tcp->tok), tcp->tok))
1718 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1719 tcp->data_interval_max))
1722 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1723 tcp->wake_payload_max))
1726 nla_nest_end(msg, nl_tcp);
1730 static int nl80211_send_wowlan(struct sk_buff *msg,
1731 struct cfg80211_registered_device *rdev,
1734 struct nlattr *nl_wowlan;
1736 if (!rdev->wiphy.wowlan)
1739 nl_wowlan = nla_nest_start_noflag(msg,
1740 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1744 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
1745 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1746 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
1747 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1748 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1749 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1750 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1751 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1752 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1753 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1754 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1755 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1756 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1757 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1758 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1759 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1762 if (rdev->wiphy.wowlan->n_patterns) {
1763 struct nl80211_pattern_support pat = {
1764 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1765 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1766 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1767 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
1770 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1775 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1776 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1777 rdev->wiphy.wowlan->max_nd_match_sets))
1780 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
1783 nla_nest_end(msg, nl_wowlan);
1789 static int nl80211_send_coalesce(struct sk_buff *msg,
1790 struct cfg80211_registered_device *rdev)
1792 struct nl80211_coalesce_rule_support rule;
1794 if (!rdev->wiphy.coalesce)
1797 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1798 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1799 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1800 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1801 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1802 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
1804 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1811 nl80211_send_iftype_data(struct sk_buff *msg,
1812 const struct ieee80211_supported_band *sband,
1813 const struct ieee80211_sband_iftype_data *iftdata)
1815 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1816 const struct ieee80211_sta_eht_cap *eht_cap = &iftdata->eht_cap;
1818 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1819 iftdata->types_mask))
1822 if (he_cap->has_he) {
1823 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1824 sizeof(he_cap->he_cap_elem.mac_cap_info),
1825 he_cap->he_cap_elem.mac_cap_info) ||
1826 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1827 sizeof(he_cap->he_cap_elem.phy_cap_info),
1828 he_cap->he_cap_elem.phy_cap_info) ||
1829 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1830 sizeof(he_cap->he_mcs_nss_supp),
1831 &he_cap->he_mcs_nss_supp) ||
1832 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1833 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1837 if (eht_cap->has_eht && he_cap->has_he) {
1838 u8 mcs_nss_size, ppe_thresh_size;
1842 is_ap = iftdata->types_mask & BIT(NL80211_IFTYPE_AP) ||
1843 iftdata->types_mask & BIT(NL80211_IFTYPE_P2P_GO);
1846 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
1847 &eht_cap->eht_cap_elem,
1850 ppe_thres_hdr = get_unaligned_le16(&eht_cap->eht_ppe_thres[0]);
1852 ieee80211_eht_ppe_size(ppe_thres_hdr,
1853 eht_cap->eht_cap_elem.phy_cap_info);
1855 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC,
1856 sizeof(eht_cap->eht_cap_elem.mac_cap_info),
1857 eht_cap->eht_cap_elem.mac_cap_info) ||
1858 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY,
1859 sizeof(eht_cap->eht_cap_elem.phy_cap_info),
1860 eht_cap->eht_cap_elem.phy_cap_info) ||
1861 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET,
1862 mcs_nss_size, &eht_cap->eht_mcs_nss_supp) ||
1863 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE,
1864 ppe_thresh_size, eht_cap->eht_ppe_thres))
1868 if (sband->band == NL80211_BAND_6GHZ &&
1869 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA,
1870 sizeof(iftdata->he_6ghz_capa),
1871 &iftdata->he_6ghz_capa))
1874 if (iftdata->vendor_elems.data && iftdata->vendor_elems.len &&
1875 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS,
1876 iftdata->vendor_elems.len, iftdata->vendor_elems.data))
1882 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1883 struct ieee80211_supported_band *sband,
1886 struct nlattr *nl_rates, *nl_rate;
1887 struct ieee80211_rate *rate;
1891 if (sband->ht_cap.ht_supported &&
1892 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1893 sizeof(sband->ht_cap.mcs),
1894 &sband->ht_cap.mcs) ||
1895 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1896 sband->ht_cap.cap) ||
1897 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1898 sband->ht_cap.ampdu_factor) ||
1899 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1900 sband->ht_cap.ampdu_density)))
1904 if (sband->vht_cap.vht_supported &&
1905 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1906 sizeof(sband->vht_cap.vht_mcs),
1907 &sband->vht_cap.vht_mcs) ||
1908 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1909 sband->vht_cap.cap)))
1912 if (large && sband->n_iftype_data) {
1913 struct nlattr *nl_iftype_data =
1914 nla_nest_start_noflag(msg,
1915 NL80211_BAND_ATTR_IFTYPE_DATA);
1918 if (!nl_iftype_data)
1921 for (i = 0; i < sband->n_iftype_data; i++) {
1922 struct nlattr *iftdata;
1924 iftdata = nla_nest_start_noflag(msg, i + 1);
1928 err = nl80211_send_iftype_data(msg, sband,
1929 &sband->iftype_data[i]);
1933 nla_nest_end(msg, iftdata);
1936 nla_nest_end(msg, nl_iftype_data);
1940 if (large && sband->edmg_cap.channels &&
1941 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1942 sband->edmg_cap.channels) ||
1943 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1944 sband->edmg_cap.bw_config)))
1949 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
1953 for (i = 0; i < sband->n_bitrates; i++) {
1954 nl_rate = nla_nest_start_noflag(msg, i);
1958 rate = &sband->bitrates[i];
1959 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1962 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1964 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1967 nla_nest_end(msg, nl_rate);
1970 nla_nest_end(msg, nl_rates);
1972 /* S1G capabilities */
1973 if (sband->band == NL80211_BAND_S1GHZ && sband->s1g_cap.s1g &&
1974 (nla_put(msg, NL80211_BAND_ATTR_S1G_CAPA,
1975 sizeof(sband->s1g_cap.cap),
1976 sband->s1g_cap.cap) ||
1977 nla_put(msg, NL80211_BAND_ATTR_S1G_MCS_NSS_SET,
1978 sizeof(sband->s1g_cap.nss_mcs),
1979 sband->s1g_cap.nss_mcs)))
1986 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1987 const struct ieee80211_txrx_stypes *mgmt_stypes)
1990 struct nlattr *nl_ftypes, *nl_ifs;
1991 enum nl80211_iftype ift;
1997 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
2001 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
2002 nl_ftypes = nla_nest_start_noflag(msg, ift);
2006 stypes = mgmt_stypes[ift].tx;
2009 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
2010 (i << 4) | IEEE80211_FTYPE_MGMT))
2015 nla_nest_end(msg, nl_ftypes);
2018 nla_nest_end(msg, nl_ifs);
2020 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
2024 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
2025 nl_ftypes = nla_nest_start_noflag(msg, ift);
2029 stypes = mgmt_stypes[ift].rx;
2032 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
2033 (i << 4) | IEEE80211_FTYPE_MGMT))
2038 nla_nest_end(msg, nl_ftypes);
2040 nla_nest_end(msg, nl_ifs);
2045 #define CMD(op, n) \
2047 if (rdev->ops->op) { \
2049 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
2050 goto nla_put_failure; \
2054 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
2055 struct sk_buff *msg)
2060 * do *NOT* add anything into this function, new things need to be
2061 * advertised only to new versions of userspace that can deal with
2062 * the split (and they can't possibly care about new features...
2064 CMD(add_virtual_intf, NEW_INTERFACE);
2065 CMD(change_virtual_intf, SET_INTERFACE);
2066 CMD(add_key, NEW_KEY);
2067 CMD(start_ap, START_AP);
2068 CMD(add_station, NEW_STATION);
2069 CMD(add_mpath, NEW_MPATH);
2070 CMD(update_mesh_config, SET_MESH_CONFIG);
2071 CMD(change_bss, SET_BSS);
2072 CMD(auth, AUTHENTICATE);
2073 CMD(assoc, ASSOCIATE);
2074 CMD(deauth, DEAUTHENTICATE);
2075 CMD(disassoc, DISASSOCIATE);
2076 CMD(join_ibss, JOIN_IBSS);
2077 CMD(join_mesh, JOIN_MESH);
2078 CMD(set_pmksa, SET_PMKSA);
2079 CMD(del_pmksa, DEL_PMKSA);
2080 CMD(flush_pmksa, FLUSH_PMKSA);
2081 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
2082 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
2083 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
2084 CMD(mgmt_tx, FRAME);
2085 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
2086 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
2088 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
2089 goto nla_put_failure;
2091 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
2092 rdev->ops->join_mesh) {
2094 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
2095 goto nla_put_failure;
2097 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2098 CMD(tdls_mgmt, TDLS_MGMT);
2099 CMD(tdls_oper, TDLS_OPER);
2101 if (rdev->wiphy.max_sched_scan_reqs)
2102 CMD(sched_scan_start, START_SCHED_SCAN);
2103 CMD(probe_client, PROBE_CLIENT);
2104 CMD(set_noack_map, SET_NOACK_MAP);
2105 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
2107 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
2108 goto nla_put_failure;
2110 CMD(start_p2p_device, START_P2P_DEVICE);
2111 CMD(set_mcast_rate, SET_MCAST_RATE);
2112 #ifdef CONFIG_NL80211_TESTMODE
2113 CMD(testmode_cmd, TESTMODE);
2116 if (rdev->ops->connect || rdev->ops->auth) {
2118 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
2119 goto nla_put_failure;
2122 if (rdev->ops->disconnect || rdev->ops->deauth) {
2124 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
2125 goto nla_put_failure;
2134 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
2135 struct sk_buff *msg)
2139 if (!cap->ftm.supported)
2142 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
2146 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
2148 if (cap->ftm.non_asap &&
2149 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
2151 if (cap->ftm.request_lci &&
2152 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
2154 if (cap->ftm.request_civicloc &&
2155 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
2157 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
2158 cap->ftm.preambles))
2160 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
2161 cap->ftm.bandwidths))
2163 if (cap->ftm.max_bursts_exponent >= 0 &&
2164 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
2165 cap->ftm.max_bursts_exponent))
2167 if (cap->ftm.max_ftms_per_burst &&
2168 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
2169 cap->ftm.max_ftms_per_burst))
2171 if (cap->ftm.trigger_based &&
2172 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED))
2174 if (cap->ftm.non_trigger_based &&
2175 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED))
2178 nla_nest_end(msg, ftm);
2182 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
2183 struct sk_buff *msg)
2185 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
2186 struct nlattr *pmsr, *caps;
2192 * we don't need to clean up anything here since the caller
2193 * will genlmsg_cancel() if we fail
2196 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
2200 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
2203 if (cap->report_ap_tsf &&
2204 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
2207 if (cap->randomize_mac_addr &&
2208 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
2211 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
2215 if (nl80211_send_pmsr_ftm_capa(cap, msg))
2218 nla_nest_end(msg, caps);
2219 nla_nest_end(msg, pmsr);
2225 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev,
2226 struct sk_buff *msg)
2229 struct nlattr *nested, *nested_akms;
2230 const struct wiphy_iftype_akm_suites *iftype_akms;
2232 if (!rdev->wiphy.num_iftype_akm_suites ||
2233 !rdev->wiphy.iftype_akm_suites)
2236 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES);
2240 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) {
2241 nested_akms = nla_nest_start(msg, i + 1);
2245 iftype_akms = &rdev->wiphy.iftype_akm_suites[i];
2247 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES,
2248 iftype_akms->iftypes_mask))
2251 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES,
2252 sizeof(u32) * iftype_akms->n_akm_suites,
2253 iftype_akms->akm_suites)) {
2256 nla_nest_end(msg, nested_akms);
2259 nla_nest_end(msg, nested);
2265 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev,
2266 struct sk_buff *msg)
2268 struct nlattr *supp;
2270 if (!rdev->wiphy.tid_config_support.vif &&
2271 !rdev->wiphy.tid_config_support.peer)
2274 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG);
2278 if (rdev->wiphy.tid_config_support.vif &&
2279 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP,
2280 rdev->wiphy.tid_config_support.vif,
2281 NL80211_TID_CONFIG_ATTR_PAD))
2284 if (rdev->wiphy.tid_config_support.peer &&
2285 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP,
2286 rdev->wiphy.tid_config_support.peer,
2287 NL80211_TID_CONFIG_ATTR_PAD))
2290 /* for now we just use the same value ... makes more sense */
2291 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT,
2292 rdev->wiphy.tid_config_support.max_retry))
2294 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG,
2295 rdev->wiphy.tid_config_support.max_retry))
2298 nla_nest_end(msg, supp);
2302 nla_nest_cancel(msg, supp);
2307 nl80211_put_sar_specs(struct cfg80211_registered_device *rdev,
2308 struct sk_buff *msg)
2310 struct nlattr *sar_capa, *specs, *sub_freq_range;
2314 if (!rdev->wiphy.sar_capa)
2317 num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges;
2319 sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC);
2323 if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type))
2326 specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS);
2330 /* report supported freq_ranges */
2331 for (i = 0; i < num_freq_ranges; i++) {
2332 sub_freq_range = nla_nest_start(msg, i + 1);
2333 if (!sub_freq_range)
2336 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ,
2337 rdev->wiphy.sar_capa->freq_ranges[i].start_freq))
2340 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ,
2341 rdev->wiphy.sar_capa->freq_ranges[i].end_freq))
2344 nla_nest_end(msg, sub_freq_range);
2347 nla_nest_end(msg, specs);
2348 nla_nest_end(msg, sar_capa);
2352 nla_nest_cancel(msg, sar_capa);
2356 static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg)
2358 struct nlattr *config;
2360 if (!wiphy->mbssid_max_interfaces)
2363 config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG);
2367 if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES,
2368 wiphy->mbssid_max_interfaces))
2371 if (wiphy->ema_max_profile_periodicity &&
2373 NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY,
2374 wiphy->ema_max_profile_periodicity))
2377 nla_nest_end(msg, config);
2381 nla_nest_cancel(msg, config);
2385 struct nl80211_dump_wiphy_state {
2388 long split_start, band_start, chan_start, capa_start;
2392 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2393 enum nl80211_commands cmd,
2394 struct sk_buff *msg, u32 portid, u32 seq,
2395 int flags, struct nl80211_dump_wiphy_state *state)
2398 struct nlattr *nl_bands, *nl_band;
2399 struct nlattr *nl_freqs, *nl_freq;
2400 struct nlattr *nl_cmds;
2401 enum nl80211_band band;
2402 struct ieee80211_channel *chan;
2404 const struct ieee80211_txrx_stypes *mgmt_stypes =
2405 rdev->wiphy.mgmt_stypes;
2408 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
2412 if (WARN_ON(!state))
2415 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2416 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
2417 wiphy_name(&rdev->wiphy)) ||
2418 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2419 cfg80211_rdev_list_generation))
2420 goto nla_put_failure;
2422 if (cmd != NL80211_CMD_NEW_WIPHY)
2425 switch (state->split_start) {
2427 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
2428 rdev->wiphy.retry_short) ||
2429 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
2430 rdev->wiphy.retry_long) ||
2431 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
2432 rdev->wiphy.frag_threshold) ||
2433 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
2434 rdev->wiphy.rts_threshold) ||
2435 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
2436 rdev->wiphy.coverage_class) ||
2437 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
2438 rdev->wiphy.max_scan_ssids) ||
2439 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
2440 rdev->wiphy.max_sched_scan_ssids) ||
2441 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
2442 rdev->wiphy.max_scan_ie_len) ||
2443 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
2444 rdev->wiphy.max_sched_scan_ie_len) ||
2445 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
2446 rdev->wiphy.max_match_sets))
2447 goto nla_put_failure;
2449 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
2450 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2451 goto nla_put_failure;
2452 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
2453 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2454 goto nla_put_failure;
2455 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2456 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2457 goto nla_put_failure;
2458 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
2459 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2460 goto nla_put_failure;
2461 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2462 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2463 goto nla_put_failure;
2464 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
2465 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
2466 goto nla_put_failure;
2467 state->split_start++;
2472 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
2473 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2474 rdev->wiphy.cipher_suites))
2475 goto nla_put_failure;
2477 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
2478 rdev->wiphy.max_num_pmkids))
2479 goto nla_put_failure;
2481 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
2482 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2483 goto nla_put_failure;
2485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
2486 rdev->wiphy.available_antennas_tx) ||
2487 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
2488 rdev->wiphy.available_antennas_rx))
2489 goto nla_put_failure;
2491 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
2492 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
2493 rdev->wiphy.probe_resp_offload))
2494 goto nla_put_failure;
2496 if ((rdev->wiphy.available_antennas_tx ||
2497 rdev->wiphy.available_antennas_rx) &&
2498 rdev->ops->get_antenna) {
2499 u32 tx_ant = 0, rx_ant = 0;
2502 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
2504 if (nla_put_u32(msg,
2505 NL80211_ATTR_WIPHY_ANTENNA_TX,
2508 NL80211_ATTR_WIPHY_ANTENNA_RX,
2510 goto nla_put_failure;
2514 state->split_start++;
2519 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
2520 rdev->wiphy.interface_modes))
2521 goto nla_put_failure;
2522 state->split_start++;
2527 nl_bands = nla_nest_start_noflag(msg,
2528 NL80211_ATTR_WIPHY_BANDS);
2530 goto nla_put_failure;
2532 for (band = state->band_start;
2533 band < (state->split ?
2535 NL80211_BAND_60GHZ + 1);
2537 struct ieee80211_supported_band *sband;
2539 /* omit higher bands for ancient software */
2540 if (band > NL80211_BAND_5GHZ && !state->split)
2543 sband = rdev->wiphy.bands[band];
2548 nl_band = nla_nest_start_noflag(msg, band);
2550 goto nla_put_failure;
2552 switch (state->chan_start) {
2554 if (nl80211_send_band_rateinfo(msg, sband,
2556 goto nla_put_failure;
2557 state->chan_start++;
2562 /* add frequencies */
2563 nl_freqs = nla_nest_start_noflag(msg,
2564 NL80211_BAND_ATTR_FREQS);
2566 goto nla_put_failure;
2568 for (i = state->chan_start - 1;
2569 i < sband->n_channels;
2571 nl_freq = nla_nest_start_noflag(msg,
2574 goto nla_put_failure;
2576 chan = &sband->channels[i];
2578 if (nl80211_msg_put_channel(
2579 msg, &rdev->wiphy, chan,
2581 goto nla_put_failure;
2583 nla_nest_end(msg, nl_freq);
2587 if (i < sband->n_channels)
2588 state->chan_start = i + 2;
2590 state->chan_start = 0;
2591 nla_nest_end(msg, nl_freqs);
2594 nla_nest_end(msg, nl_band);
2597 /* start again here */
2598 if (state->chan_start)
2603 nla_nest_end(msg, nl_bands);
2605 if (band < NUM_NL80211_BANDS)
2606 state->band_start = band + 1;
2608 state->band_start = 0;
2610 /* if bands & channels are done, continue outside */
2611 if (state->band_start == 0 && state->chan_start == 0)
2612 state->split_start++;
2617 nl_cmds = nla_nest_start_noflag(msg,
2618 NL80211_ATTR_SUPPORTED_COMMANDS);
2620 goto nla_put_failure;
2622 i = nl80211_add_commands_unsplit(rdev, msg);
2624 goto nla_put_failure;
2626 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2627 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
2628 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
2629 CMD(channel_switch, CHANNEL_SWITCH);
2630 CMD(set_qos_map, SET_QOS_MAP);
2631 if (rdev->wiphy.features &
2632 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
2633 CMD(add_tx_ts, ADD_TX_TS);
2634 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
2635 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
2636 CMD(update_ft_ies, UPDATE_FT_IES);
2637 if (rdev->wiphy.sar_capa)
2638 CMD(set_sar_specs, SET_SAR_SPECS);
2642 nla_nest_end(msg, nl_cmds);
2643 state->split_start++;
2648 if (rdev->ops->remain_on_channel &&
2649 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
2651 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
2652 rdev->wiphy.max_remain_on_channel_duration))
2653 goto nla_put_failure;
2655 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
2656 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2657 goto nla_put_failure;
2659 state->split_start++;
2665 if (nl80211_send_wowlan(msg, rdev, state->split))
2666 goto nla_put_failure;
2667 state->split_start++;
2671 state->split_start++;
2675 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
2676 rdev->wiphy.software_iftypes))
2677 goto nla_put_failure;
2679 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
2681 goto nla_put_failure;
2683 state->split_start++;
2688 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
2689 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
2690 rdev->wiphy.ap_sme_capa))
2691 goto nla_put_failure;
2693 features = rdev->wiphy.features;
2695 * We can only add the per-channel limit information if the
2696 * dump is split, otherwise it makes it too big. Therefore
2697 * only advertise it in that case.
2700 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2701 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
2702 goto nla_put_failure;
2704 if (rdev->wiphy.ht_capa_mod_mask &&
2705 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
2706 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2707 rdev->wiphy.ht_capa_mod_mask))
2708 goto nla_put_failure;
2710 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2711 rdev->wiphy.max_acl_mac_addrs &&
2712 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
2713 rdev->wiphy.max_acl_mac_addrs))
2714 goto nla_put_failure;
2717 * Any information below this point is only available to
2718 * applications that can deal with it being split. This
2719 * helps ensure that newly added capabilities don't break
2720 * older tools by overrunning their buffers.
2722 * We still increment split_start so that in the split
2723 * case we'll continue with more data in the next round,
2724 * but break unconditionally so unsplit data stops here.
2727 state->split_start++;
2729 state->split_start = 0;
2732 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2733 goto nla_put_failure;
2735 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
2736 rdev->wiphy.max_sched_scan_plans) ||
2737 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
2738 rdev->wiphy.max_sched_scan_plan_interval) ||
2739 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
2740 rdev->wiphy.max_sched_scan_plan_iterations))
2741 goto nla_put_failure;
2743 if (rdev->wiphy.extended_capabilities &&
2744 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
2745 rdev->wiphy.extended_capabilities_len,
2746 rdev->wiphy.extended_capabilities) ||
2747 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2748 rdev->wiphy.extended_capabilities_len,
2749 rdev->wiphy.extended_capabilities_mask)))
2750 goto nla_put_failure;
2752 if (rdev->wiphy.vht_capa_mod_mask &&
2753 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
2754 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2755 rdev->wiphy.vht_capa_mod_mask))
2756 goto nla_put_failure;
2758 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2759 rdev->wiphy.perm_addr))
2760 goto nla_put_failure;
2762 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2763 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2764 rdev->wiphy.addr_mask))
2765 goto nla_put_failure;
2767 if (rdev->wiphy.n_addresses > 1) {
2770 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2772 goto nla_put_failure;
2774 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2775 if (nla_put(msg, i + 1, ETH_ALEN,
2776 rdev->wiphy.addresses[i].addr))
2777 goto nla_put_failure;
2779 nla_nest_end(msg, attr);
2782 state->split_start++;
2785 if (nl80211_send_coalesce(msg, rdev))
2786 goto nla_put_failure;
2788 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
2789 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2790 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2791 goto nla_put_failure;
2793 if (rdev->wiphy.max_ap_assoc_sta &&
2794 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
2795 rdev->wiphy.max_ap_assoc_sta))
2796 goto nla_put_failure;
2798 state->split_start++;
2801 if (rdev->wiphy.n_vendor_commands) {
2802 const struct nl80211_vendor_cmd_info *info;
2803 struct nlattr *nested;
2805 nested = nla_nest_start_noflag(msg,
2806 NL80211_ATTR_VENDOR_DATA);
2808 goto nla_put_failure;
2810 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2811 info = &rdev->wiphy.vendor_commands[i].info;
2812 if (nla_put(msg, i + 1, sizeof(*info), info))
2813 goto nla_put_failure;
2815 nla_nest_end(msg, nested);
2818 if (rdev->wiphy.n_vendor_events) {
2819 const struct nl80211_vendor_cmd_info *info;
2820 struct nlattr *nested;
2822 nested = nla_nest_start_noflag(msg,
2823 NL80211_ATTR_VENDOR_EVENTS);
2825 goto nla_put_failure;
2827 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2828 info = &rdev->wiphy.vendor_events[i];
2829 if (nla_put(msg, i + 1, sizeof(*info), info))
2830 goto nla_put_failure;
2832 nla_nest_end(msg, nested);
2834 state->split_start++;
2837 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2838 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2839 rdev->wiphy.max_num_csa_counters))
2840 goto nla_put_failure;
2842 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2843 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2844 goto nla_put_failure;
2846 if (rdev->wiphy.max_sched_scan_reqs &&
2847 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2848 rdev->wiphy.max_sched_scan_reqs))
2849 goto nla_put_failure;
2851 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2852 sizeof(rdev->wiphy.ext_features),
2853 rdev->wiphy.ext_features))
2854 goto nla_put_failure;
2856 if (rdev->wiphy.bss_select_support) {
2857 struct nlattr *nested;
2858 u32 bss_select_support = rdev->wiphy.bss_select_support;
2860 nested = nla_nest_start_noflag(msg,
2861 NL80211_ATTR_BSS_SELECT);
2863 goto nla_put_failure;
2866 while (bss_select_support) {
2867 if ((bss_select_support & 1) &&
2868 nla_put_flag(msg, i))
2869 goto nla_put_failure;
2871 bss_select_support >>= 1;
2873 nla_nest_end(msg, nested);
2876 state->split_start++;
2879 if (rdev->wiphy.num_iftype_ext_capab &&
2880 rdev->wiphy.iftype_ext_capab) {
2881 struct nlattr *nested_ext_capab, *nested;
2883 nested = nla_nest_start_noflag(msg,
2884 NL80211_ATTR_IFTYPE_EXT_CAPA);
2886 goto nla_put_failure;
2888 for (i = state->capa_start;
2889 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2890 const struct wiphy_iftype_ext_capab *capab;
2892 capab = &rdev->wiphy.iftype_ext_capab[i];
2894 nested_ext_capab = nla_nest_start_noflag(msg,
2896 if (!nested_ext_capab ||
2897 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2899 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2900 capab->extended_capabilities_len,
2901 capab->extended_capabilities) ||
2902 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2903 capab->extended_capabilities_len,
2904 capab->extended_capabilities_mask))
2905 goto nla_put_failure;
2907 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO &&
2909 NL80211_ATTR_EML_CAPABILITY,
2910 capab->eml_capabilities) ||
2912 NL80211_ATTR_MLD_CAPA_AND_OPS,
2913 capab->mld_capa_and_ops)))
2914 goto nla_put_failure;
2916 nla_nest_end(msg, nested_ext_capab);
2920 nla_nest_end(msg, nested);
2921 if (i < rdev->wiphy.num_iftype_ext_capab) {
2922 state->capa_start = i + 1;
2927 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2928 rdev->wiphy.nan_supported_bands))
2929 goto nla_put_failure;
2931 if (wiphy_ext_feature_isset(&rdev->wiphy,
2932 NL80211_EXT_FEATURE_TXQS)) {
2933 struct cfg80211_txq_stats txqstats = {};
2936 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2938 !nl80211_put_txq_stats(msg, &txqstats,
2939 NL80211_ATTR_TXQ_STATS))
2940 goto nla_put_failure;
2942 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2943 rdev->wiphy.txq_limit))
2944 goto nla_put_failure;
2945 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2946 rdev->wiphy.txq_memory_limit))
2947 goto nla_put_failure;
2948 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2949 rdev->wiphy.txq_quantum))
2950 goto nla_put_failure;
2953 state->split_start++;
2956 if (nl80211_send_pmsr_capa(rdev, msg))
2957 goto nla_put_failure;
2959 state->split_start++;
2962 if (rdev->wiphy.akm_suites &&
2963 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2964 sizeof(u32) * rdev->wiphy.n_akm_suites,
2965 rdev->wiphy.akm_suites))
2966 goto nla_put_failure;
2968 if (nl80211_put_iftype_akm_suites(rdev, msg))
2969 goto nla_put_failure;
2971 if (nl80211_put_tid_config_support(rdev, msg))
2972 goto nla_put_failure;
2973 state->split_start++;
2976 if (nl80211_put_sar_specs(rdev, msg))
2977 goto nla_put_failure;
2979 if (nl80211_put_mbssid_support(&rdev->wiphy, msg))
2980 goto nla_put_failure;
2982 if (nla_put_u16(msg, NL80211_ATTR_MAX_NUM_AKM_SUITES,
2983 rdev->wiphy.max_num_akm_suites))
2984 goto nla_put_failure;
2986 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)
2987 nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT);
2989 if (rdev->wiphy.hw_timestamp_max_peers &&
2990 nla_put_u16(msg, NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS,
2991 rdev->wiphy.hw_timestamp_max_peers))
2992 goto nla_put_failure;
2995 state->split_start = 0;
2999 genlmsg_end(msg, hdr);
3003 genlmsg_cancel(msg, hdr);
3007 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
3008 struct netlink_callback *cb,
3009 struct nl80211_dump_wiphy_state *state)
3011 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
3017 ret = nlmsg_parse_deprecated(cb->nlh,
3018 GENL_HDRLEN + nl80211_fam.hdrsize,
3019 tb, nl80211_fam.maxattr,
3020 nl80211_policy, NULL);
3021 /* ignore parse errors for backward compatibility */
3027 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
3028 if (tb[NL80211_ATTR_WIPHY])
3029 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
3030 if (tb[NL80211_ATTR_WDEV])
3031 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
3032 if (tb[NL80211_ATTR_IFINDEX]) {
3033 struct net_device *netdev;
3034 struct cfg80211_registered_device *rdev;
3035 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
3037 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
3042 if (netdev->ieee80211_ptr) {
3043 rdev = wiphy_to_rdev(
3044 netdev->ieee80211_ptr->wiphy);
3045 state->filter_wiphy = rdev->wiphy_idx;
3055 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
3058 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
3059 struct cfg80211_registered_device *rdev;
3063 state = kzalloc(sizeof(*state), GFP_KERNEL);
3068 state->filter_wiphy = -1;
3069 ret = nl80211_dump_wiphy_parse(skb, cb, state);
3075 cb->args[0] = (long)state;
3078 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3079 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3081 if (++idx <= state->start)
3083 if (state->filter_wiphy != -1 &&
3084 state->filter_wiphy != rdev->wiphy_idx)
3086 wiphy_lock(&rdev->wiphy);
3087 /* attempt to fit multiple wiphy data chunks into the skb */
3089 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
3091 NETLINK_CB(cb->skb).portid,
3093 NLM_F_MULTI, state);
3096 * If sending the wiphy data didn't fit (ENOBUFS
3097 * or EMSGSIZE returned), this SKB is still
3098 * empty (so it's not too big because another
3099 * wiphy dataset is already in the skb) and
3100 * we've not tried to adjust the dump allocation
3101 * yet ... then adjust the alloc size to be
3102 * bigger, and return 1 but with the empty skb.
3103 * This results in an empty message being RX'ed
3104 * in userspace, but that is ignored.
3106 * We can then retry with the larger buffer.
3108 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
3109 !skb->len && !state->split &&
3110 cb->min_dump_alloc < 4096) {
3111 cb->min_dump_alloc = 4096;
3112 state->split_start = 0;
3113 wiphy_unlock(&rdev->wiphy);
3120 } while (state->split_start > 0);
3121 wiphy_unlock(&rdev->wiphy);
3131 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
3133 kfree((void *)cb->args[0]);
3137 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
3139 struct sk_buff *msg;
3140 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3141 struct nl80211_dump_wiphy_state state = {};
3143 msg = nlmsg_new(4096, GFP_KERNEL);
3147 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
3148 info->snd_portid, info->snd_seq, 0,
3154 return genlmsg_reply(msg, info);
3157 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
3158 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
3159 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
3160 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
3161 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
3162 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
3165 static int parse_txq_params(struct nlattr *tb[],
3166 struct ieee80211_txq_params *txq_params)
3170 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
3171 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
3172 !tb[NL80211_TXQ_ATTR_AIFS])
3175 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
3176 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
3177 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
3178 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
3179 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
3181 if (ac >= NL80211_NUM_ACS)
3183 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
3187 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
3190 * You can only set the channel explicitly for some interfaces,
3191 * most have their channel managed via their respective
3192 * "establish a connection" command (connect, join, ...)
3194 * For AP/GO and mesh mode, the channel can be set with the
3195 * channel userspace API, but is only stored and passed to the
3196 * low-level driver when the AP starts or the mesh is joined.
3197 * This is for backward compatibility, userspace can also give
3198 * the channel in the start-ap or join-mesh commands instead.
3200 * Monitors are special as they are normally slaved to
3201 * whatever else is going on, so they have their own special
3202 * operation to set the monitor channel if possible.
3205 wdev->iftype == NL80211_IFTYPE_AP ||
3206 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
3207 wdev->iftype == NL80211_IFTYPE_MONITOR ||
3208 wdev->iftype == NL80211_IFTYPE_P2P_GO;
3211 static int nl80211_parse_punct_bitmap(struct cfg80211_registered_device *rdev,
3212 struct genl_info *info,
3213 const struct cfg80211_chan_def *chandef,
3216 if (!wiphy_ext_feature_isset(&rdev->wiphy, NL80211_EXT_FEATURE_PUNCT))
3219 *punct_bitmap = nla_get_u32(info->attrs[NL80211_ATTR_PUNCT_BITMAP]);
3220 if (!cfg80211_valid_disable_subchannel_bitmap(punct_bitmap, chandef))
3226 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
3227 struct genl_info *info,
3228 struct cfg80211_chan_def *chandef)
3230 struct netlink_ext_ack *extack = info->extack;
3231 struct nlattr **attrs = info->attrs;
3234 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) {
3235 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
3236 "Frequency is missing");
3240 control_freq = MHZ_TO_KHZ(
3241 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3242 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
3244 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
3246 memset(chandef, 0, sizeof(*chandef));
3247 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq);
3248 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
3249 chandef->center_freq1 = KHZ_TO_MHZ(control_freq);
3250 chandef->freq1_offset = control_freq % 1000;
3251 chandef->center_freq2 = 0;
3253 /* Primary channel not allowed */
3254 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
3255 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
3256 "Channel is disabled");
3260 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
3261 enum nl80211_channel_type chantype;
3263 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
3266 case NL80211_CHAN_NO_HT:
3267 case NL80211_CHAN_HT20:
3268 case NL80211_CHAN_HT40PLUS:
3269 case NL80211_CHAN_HT40MINUS:
3270 cfg80211_chandef_create(chandef, chandef->chan,
3272 /* user input for center_freq is incorrect */
3273 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
3274 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
3275 NL_SET_ERR_MSG_ATTR(extack,
3276 attrs[NL80211_ATTR_CENTER_FREQ1],
3277 "bad center frequency 1");
3280 /* center_freq2 must be zero */
3281 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
3282 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
3283 NL_SET_ERR_MSG_ATTR(extack,
3284 attrs[NL80211_ATTR_CENTER_FREQ2],
3285 "center frequency 2 can't be used");
3290 NL_SET_ERR_MSG_ATTR(extack,
3291 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
3292 "invalid channel type");
3295 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
3297 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
3298 if (chandef->chan->band == NL80211_BAND_S1GHZ) {
3299 /* User input error for channel width doesn't match channel */
3300 if (chandef->width != ieee80211_s1g_channel_width(chandef->chan)) {
3301 NL_SET_ERR_MSG_ATTR(extack,
3302 attrs[NL80211_ATTR_CHANNEL_WIDTH],
3303 "bad channel width");
3307 if (attrs[NL80211_ATTR_CENTER_FREQ1]) {
3308 chandef->center_freq1 =
3309 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
3310 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET])
3311 chandef->freq1_offset = nla_get_u32(
3312 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]);
3314 chandef->freq1_offset = 0;
3316 if (attrs[NL80211_ATTR_CENTER_FREQ2])
3317 chandef->center_freq2 =
3318 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
3321 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
3322 chandef->edmg.channels =
3323 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
3325 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
3326 chandef->edmg.bw_config =
3327 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
3329 chandef->edmg.bw_config = 0;
3330 chandef->edmg.channels = 0;
3333 if (!cfg80211_chandef_valid(chandef)) {
3334 NL_SET_ERR_MSG(extack, "invalid channel definition");
3338 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
3339 IEEE80211_CHAN_DISABLED)) {
3340 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
3344 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
3345 chandef->width == NL80211_CHAN_WIDTH_10) &&
3346 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
3347 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
3354 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
3355 struct net_device *dev,
3356 struct genl_info *info,
3359 struct cfg80211_chan_def chandef;
3361 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
3362 struct wireless_dev *wdev = NULL;
3363 int link_id = _link_id;
3366 wdev = dev->ieee80211_ptr;
3367 if (!nl80211_can_set_dev_channel(wdev))
3370 iftype = wdev->iftype;
3373 if (wdev && wdev->valid_links)
3378 result = nl80211_parse_chandef(rdev, info, &chandef);
3383 case NL80211_IFTYPE_AP:
3384 case NL80211_IFTYPE_P2P_GO:
3385 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
3388 if (wdev->links[link_id].ap.beacon_interval) {
3389 struct ieee80211_channel *cur_chan;
3391 if (!dev || !rdev->ops->set_ap_chanwidth ||
3392 !(rdev->wiphy.features &
3393 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE))
3396 /* Only allow dynamic channel width changes */
3397 cur_chan = wdev->links[link_id].ap.chandef.chan;
3398 if (chandef.chan != cur_chan)
3401 result = rdev_set_ap_chanwidth(rdev, dev, link_id,
3405 wdev->links[link_id].ap.chandef = chandef;
3407 wdev->u.ap.preset_chandef = chandef;
3410 case NL80211_IFTYPE_MESH_POINT:
3411 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
3412 case NL80211_IFTYPE_MONITOR:
3413 return cfg80211_set_monitor_channel(rdev, &chandef);
3421 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
3423 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3424 int link_id = nl80211_link_id_or_invalid(info->attrs);
3425 struct net_device *netdev = info->user_ptr[1];
3428 wdev_lock(netdev->ieee80211_ptr);
3429 ret = __nl80211_set_channel(rdev, netdev, info, link_id);
3430 wdev_unlock(netdev->ieee80211_ptr);
3435 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
3437 struct cfg80211_registered_device *rdev = NULL;
3438 struct net_device *netdev = NULL;
3439 struct wireless_dev *wdev;
3440 int result = 0, rem_txq_params = 0;
3441 struct nlattr *nl_txq_params;
3443 u8 retry_short = 0, retry_long = 0;
3444 u32 frag_threshold = 0, rts_threshold = 0;
3445 u8 coverage_class = 0;
3446 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
3450 * Try to find the wiphy and netdev. Normally this
3451 * function shouldn't need the netdev, but this is
3452 * done for backward compatibility -- previously
3453 * setting the channel was done per wiphy, but now
3454 * it is per netdev. Previous userland like hostapd
3455 * also passed a netdev to set_wiphy, so that it is
3456 * possible to let that go to the right netdev!
3459 if (info->attrs[NL80211_ATTR_IFINDEX]) {
3460 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
3462 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
3463 if (netdev && netdev->ieee80211_ptr)
3464 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
3470 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3474 return PTR_ERR(rdev);
3480 wdev = netdev->ieee80211_ptr;
3482 wiphy_lock(&rdev->wiphy);
3485 * end workaround code, by now the rdev is available
3486 * and locked, and wdev may or may not be NULL.
3489 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
3490 result = cfg80211_dev_rename(
3491 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
3497 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
3498 struct ieee80211_txq_params txq_params;
3499 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
3501 if (!rdev->ops->set_txq_params) {
3502 result = -EOPNOTSUPP;
3511 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3512 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3517 if (!netif_running(netdev)) {
3522 nla_for_each_nested(nl_txq_params,
3523 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3525 result = nla_parse_nested_deprecated(tb,
3526 NL80211_TXQ_ATTR_MAX,
3532 result = parse_txq_params(tb, &txq_params);
3536 txq_params.link_id =
3537 nl80211_link_id_or_invalid(info->attrs);
3539 wdev_lock(netdev->ieee80211_ptr);
3540 if (txq_params.link_id >= 0 &&
3541 !(netdev->ieee80211_ptr->valid_links &
3542 BIT(txq_params.link_id)))
3544 else if (txq_params.link_id >= 0 &&
3545 !netdev->ieee80211_ptr->valid_links)
3548 result = rdev_set_txq_params(rdev, netdev,
3550 wdev_unlock(netdev->ieee80211_ptr);
3556 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3557 int link_id = nl80211_link_id_or_invalid(info->attrs);
3561 result = __nl80211_set_channel(
3563 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3567 result = __nl80211_set_channel(rdev, netdev, info, link_id);
3574 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
3575 struct wireless_dev *txp_wdev = wdev;
3576 enum nl80211_tx_power_setting type;
3579 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3582 if (!rdev->ops->set_tx_power) {
3583 result = -EOPNOTSUPP;
3587 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
3588 type = nla_get_u32(info->attrs[idx]);
3590 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
3591 (type != NL80211_TX_POWER_AUTOMATIC)) {
3596 if (type != NL80211_TX_POWER_AUTOMATIC) {
3597 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
3598 mbm = nla_get_u32(info->attrs[idx]);
3601 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
3606 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3607 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3610 if ((!rdev->wiphy.available_antennas_tx &&
3611 !rdev->wiphy.available_antennas_rx) ||
3612 !rdev->ops->set_antenna) {
3613 result = -EOPNOTSUPP;
3617 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3618 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3620 /* reject antenna configurations which don't match the
3621 * available antenna masks, except for the "all" mask */
3622 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
3623 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
3628 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3629 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
3631 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
3638 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3639 retry_short = nla_get_u8(
3640 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
3642 changed |= WIPHY_PARAM_RETRY_SHORT;
3645 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3646 retry_long = nla_get_u8(
3647 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
3649 changed |= WIPHY_PARAM_RETRY_LONG;
3652 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3653 frag_threshold = nla_get_u32(
3654 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
3655 if (frag_threshold < 256) {
3660 if (frag_threshold != (u32) -1) {
3662 * Fragments (apart from the last one) are required to
3663 * have even length. Make the fragmentation code
3664 * simpler by stripping LSB should someone try to use
3665 * odd threshold value.
3667 frag_threshold &= ~0x1;
3669 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3672 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3673 rts_threshold = nla_get_u32(
3674 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3675 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3678 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
3679 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3684 coverage_class = nla_get_u8(
3685 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3686 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3689 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3690 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) {
3691 result = -EOPNOTSUPP;
3695 changed |= WIPHY_PARAM_DYN_ACK;
3698 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3699 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3700 NL80211_EXT_FEATURE_TXQS)) {
3701 result = -EOPNOTSUPP;
3704 txq_limit = nla_get_u32(
3705 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3706 changed |= WIPHY_PARAM_TXQ_LIMIT;
3709 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3710 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3711 NL80211_EXT_FEATURE_TXQS)) {
3712 result = -EOPNOTSUPP;
3715 txq_memory_limit = nla_get_u32(
3716 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3717 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3720 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3721 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3722 NL80211_EXT_FEATURE_TXQS)) {
3723 result = -EOPNOTSUPP;
3726 txq_quantum = nla_get_u32(
3727 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3728 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3732 u8 old_retry_short, old_retry_long;
3733 u32 old_frag_threshold, old_rts_threshold;
3734 u8 old_coverage_class;
3735 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
3737 if (!rdev->ops->set_wiphy_params) {
3738 result = -EOPNOTSUPP;
3742 old_retry_short = rdev->wiphy.retry_short;
3743 old_retry_long = rdev->wiphy.retry_long;
3744 old_frag_threshold = rdev->wiphy.frag_threshold;
3745 old_rts_threshold = rdev->wiphy.rts_threshold;
3746 old_coverage_class = rdev->wiphy.coverage_class;
3747 old_txq_limit = rdev->wiphy.txq_limit;
3748 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3749 old_txq_quantum = rdev->wiphy.txq_quantum;
3751 if (changed & WIPHY_PARAM_RETRY_SHORT)
3752 rdev->wiphy.retry_short = retry_short;
3753 if (changed & WIPHY_PARAM_RETRY_LONG)
3754 rdev->wiphy.retry_long = retry_long;
3755 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3756 rdev->wiphy.frag_threshold = frag_threshold;
3757 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3758 rdev->wiphy.rts_threshold = rts_threshold;
3759 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3760 rdev->wiphy.coverage_class = coverage_class;
3761 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3762 rdev->wiphy.txq_limit = txq_limit;
3763 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3764 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3765 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3766 rdev->wiphy.txq_quantum = txq_quantum;
3768 result = rdev_set_wiphy_params(rdev, changed);
3770 rdev->wiphy.retry_short = old_retry_short;
3771 rdev->wiphy.retry_long = old_retry_long;
3772 rdev->wiphy.frag_threshold = old_frag_threshold;
3773 rdev->wiphy.rts_threshold = old_rts_threshold;
3774 rdev->wiphy.coverage_class = old_coverage_class;
3775 rdev->wiphy.txq_limit = old_txq_limit;
3776 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3777 rdev->wiphy.txq_quantum = old_txq_quantum;
3785 wiphy_unlock(&rdev->wiphy);
3789 int nl80211_send_chandef(struct sk_buff *msg, const struct cfg80211_chan_def *chandef)
3791 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3794 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3795 chandef->chan->center_freq))
3797 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
3798 chandef->chan->freq_offset))
3800 switch (chandef->width) {
3801 case NL80211_CHAN_WIDTH_20_NOHT:
3802 case NL80211_CHAN_WIDTH_20:
3803 case NL80211_CHAN_WIDTH_40:
3804 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3805 cfg80211_get_chandef_type(chandef)))
3811 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3813 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3815 if (chandef->center_freq2 &&
3816 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
3820 EXPORT_SYMBOL(nl80211_send_chandef);
3822 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
3823 struct cfg80211_registered_device *rdev,
3824 struct wireless_dev *wdev,
3825 enum nl80211_commands cmd)
3827 struct net_device *dev = wdev->netdev;
3830 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3831 cmd != NL80211_CMD_DEL_INTERFACE &&
3832 cmd != NL80211_CMD_SET_INTERFACE);
3834 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
3839 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3840 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
3841 goto nla_put_failure;
3843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3844 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
3845 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3846 NL80211_ATTR_PAD) ||
3847 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
3848 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3849 rdev->devlist_generation ^
3850 (cfg80211_rdev_list_generation << 2)) ||
3851 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
3852 goto nla_put_failure;
3854 if (rdev->ops->get_channel && !wdev->valid_links) {
3855 struct cfg80211_chan_def chandef = {};
3858 ret = rdev_get_channel(rdev, wdev, 0, &chandef);
3859 if (ret == 0 && nl80211_send_chandef(msg, &chandef))
3860 goto nla_put_failure;
3863 if (rdev->ops->get_tx_power) {
3866 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3868 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3870 goto nla_put_failure;
3874 switch (wdev->iftype) {
3875 case NL80211_IFTYPE_AP:
3876 case NL80211_IFTYPE_P2P_GO:
3877 if (wdev->u.ap.ssid_len &&
3878 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len,
3880 goto nla_put_failure_locked;
3882 case NL80211_IFTYPE_STATION:
3883 case NL80211_IFTYPE_P2P_CLIENT:
3884 if (wdev->u.client.ssid_len &&
3885 nla_put(msg, NL80211_ATTR_SSID, wdev->u.client.ssid_len,
3886 wdev->u.client.ssid))
3887 goto nla_put_failure_locked;
3889 case NL80211_IFTYPE_ADHOC:
3890 if (wdev->u.ibss.ssid_len &&
3891 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ibss.ssid_len,
3893 goto nla_put_failure_locked;
3901 if (rdev->ops->get_txq_stats) {
3902 struct cfg80211_txq_stats txqstats = {};
3903 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3906 !nl80211_put_txq_stats(msg, &txqstats,
3907 NL80211_ATTR_TXQ_STATS))
3908 goto nla_put_failure;
3911 if (wdev->valid_links) {
3912 unsigned int link_id;
3913 struct nlattr *links = nla_nest_start(msg,
3914 NL80211_ATTR_MLO_LINKS);
3917 goto nla_put_failure;
3919 for_each_valid_link(wdev, link_id) {
3920 struct nlattr *link = nla_nest_start(msg, link_id + 1);
3921 struct cfg80211_chan_def chandef = {};
3925 goto nla_put_failure;
3927 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
3928 goto nla_put_failure;
3929 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
3930 wdev->links[link_id].addr))
3931 goto nla_put_failure;
3933 ret = rdev_get_channel(rdev, wdev, link_id, &chandef);
3934 if (ret == 0 && nl80211_send_chandef(msg, &chandef))
3935 goto nla_put_failure;
3937 nla_nest_end(msg, link);
3940 nla_nest_end(msg, links);
3943 genlmsg_end(msg, hdr);
3946 nla_put_failure_locked:
3949 genlmsg_cancel(msg, hdr);
3953 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3957 int wp_start = cb->args[0];
3958 int if_start = cb->args[1];
3959 int filter_wiphy = -1;
3960 struct cfg80211_registered_device *rdev;
3961 struct wireless_dev *wdev;
3966 struct nl80211_dump_wiphy_state state = {
3970 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3974 filter_wiphy = state.filter_wiphy;
3977 * if filtering, set cb->args[2] to +1 since 0 is the default
3978 * value needed to determine that parsing is necessary.
3980 if (filter_wiphy >= 0)
3981 cb->args[2] = filter_wiphy + 1;
3984 } else if (cb->args[2] > 0) {
3985 filter_wiphy = cb->args[2] - 1;
3988 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3989 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3991 if (wp_idx < wp_start) {
3996 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
4001 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
4002 if (if_idx < if_start) {
4006 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
4007 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4009 NL80211_CMD_NEW_INTERFACE) < 0) {
4018 cb->args[0] = wp_idx;
4019 cb->args[1] = if_idx;
4028 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
4030 struct sk_buff *msg;
4031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4032 struct wireless_dev *wdev = info->user_ptr[1];
4034 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4038 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
4039 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
4044 return genlmsg_reply(msg, info);
4047 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
4048 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
4049 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
4050 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
4051 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
4052 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
4053 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
4056 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
4058 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
4066 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
4069 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
4071 *mntrflags |= (1<<flag);
4073 *mntrflags |= MONITOR_FLAG_CHANGED;
4078 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
4079 enum nl80211_iftype type,
4080 struct genl_info *info,
4081 struct vif_params *params)
4083 bool change = false;
4086 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
4087 if (type != NL80211_IFTYPE_MONITOR)
4090 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
4098 if (params->flags & MONITOR_FLAG_ACTIVE &&
4099 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
4102 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
4103 const u8 *mumimo_groups;
4104 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
4106 if (type != NL80211_IFTYPE_MONITOR)
4109 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
4113 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
4115 /* bits 0 and 63 are reserved and must be zero */
4116 if ((mumimo_groups[0] & BIT(0)) ||
4117 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
4120 params->vht_mumimo_groups = mumimo_groups;
4124 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
4125 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
4127 if (type != NL80211_IFTYPE_MONITOR)
4130 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
4133 params->vht_mumimo_follow_addr =
4134 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
4138 return change ? 1 : 0;
4141 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
4142 struct net_device *netdev, u8 use_4addr,
4143 enum nl80211_iftype iftype)
4146 if (netdev && netif_is_bridge_port(netdev))
4152 case NL80211_IFTYPE_AP_VLAN:
4153 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
4156 case NL80211_IFTYPE_STATION:
4157 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
4167 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
4169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4170 struct vif_params params;
4172 enum nl80211_iftype otype, ntype;
4173 struct net_device *dev = info->user_ptr[1];
4174 bool change = false;
4176 memset(¶ms, 0, sizeof(params));
4178 otype = ntype = dev->ieee80211_ptr->iftype;
4180 if (info->attrs[NL80211_ATTR_IFTYPE]) {
4181 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
4186 if (info->attrs[NL80211_ATTR_MESH_ID]) {
4187 struct wireless_dev *wdev = dev->ieee80211_ptr;
4189 if (ntype != NL80211_IFTYPE_MESH_POINT)
4191 if (netif_running(dev))
4195 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
4196 IEEE80211_MAX_MESH_ID_LEN);
4197 wdev->u.mesh.id_up_len =
4198 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
4199 memcpy(wdev->u.mesh.id,
4200 nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
4201 wdev->u.mesh.id_up_len);
4205 if (info->attrs[NL80211_ATTR_4ADDR]) {
4206 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
4208 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
4212 params.use_4addr = -1;
4215 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms);
4222 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms);
4226 if (!err && params.use_4addr != -1)
4227 dev->ieee80211_ptr->use_4addr = params.use_4addr;
4229 if (change && !err) {
4230 struct wireless_dev *wdev = dev->ieee80211_ptr;
4232 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
4238 static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
4240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4241 struct vif_params params;
4242 struct wireless_dev *wdev;
4243 struct sk_buff *msg;
4245 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
4247 memset(¶ms, 0, sizeof(params));
4249 if (!info->attrs[NL80211_ATTR_IFNAME])
4252 if (info->attrs[NL80211_ATTR_IFTYPE])
4253 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
4255 if (!rdev->ops->add_virtual_intf)
4258 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
4259 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
4260 info->attrs[NL80211_ATTR_MAC]) {
4261 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
4263 if (!is_valid_ether_addr(params.macaddr))
4264 return -EADDRNOTAVAIL;
4267 if (info->attrs[NL80211_ATTR_4ADDR]) {
4268 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
4269 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
4274 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
4277 err = nl80211_parse_mon_options(rdev, type, info, ¶ms);
4281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4285 wdev = rdev_add_virtual_intf(rdev,
4286 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
4287 NET_NAME_USER, type, ¶ms);
4288 if (WARN_ON(!wdev)) {
4291 } else if (IS_ERR(wdev)) {
4293 return PTR_ERR(wdev);
4296 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4297 wdev->owner_nlportid = info->snd_portid;
4300 case NL80211_IFTYPE_MESH_POINT:
4301 if (!info->attrs[NL80211_ATTR_MESH_ID])
4304 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
4305 IEEE80211_MAX_MESH_ID_LEN);
4306 wdev->u.mesh.id_up_len =
4307 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
4308 memcpy(wdev->u.mesh.id,
4309 nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
4310 wdev->u.mesh.id_up_len);
4313 case NL80211_IFTYPE_NAN:
4314 case NL80211_IFTYPE_P2P_DEVICE:
4316 * P2P Device and NAN do not have a netdev, so don't go
4317 * through the netdev notifier and must be added here
4319 cfg80211_init_wdev(wdev);
4320 cfg80211_register_wdev(rdev, wdev);
4326 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
4327 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
4332 return genlmsg_reply(msg, info);
4335 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
4337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4340 /* to avoid failing a new interface creation due to pending removal */
4341 cfg80211_destroy_ifaces(rdev);
4343 wiphy_lock(&rdev->wiphy);
4344 ret = _nl80211_new_interface(skb, info);
4345 wiphy_unlock(&rdev->wiphy);
4350 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
4352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4353 struct wireless_dev *wdev = info->user_ptr[1];
4355 if (!rdev->ops->del_virtual_intf)
4359 * We hold RTNL, so this is safe, without RTNL opencount cannot
4360 * reach 0, and thus the rdev cannot be deleted.
4362 * We need to do it for the dev_close(), since that will call
4363 * the netdev notifiers, and we need to acquire the mutex there
4364 * but don't know if we get there from here or from some other
4365 * place (e.g. "ip link set ... down").
4367 mutex_unlock(&rdev->wiphy.mtx);
4370 * If we remove a wireless device without a netdev then clear
4371 * user_ptr[1] so that nl80211_post_doit won't dereference it
4372 * to check if it needs to do dev_put(). Otherwise it crashes
4373 * since the wdev has been freed, unlike with a netdev where
4374 * we need the dev_put() for the netdev to really be freed.
4377 info->user_ptr[1] = NULL;
4379 dev_close(wdev->netdev);
4381 mutex_lock(&rdev->wiphy.mtx);
4383 return cfg80211_remove_virtual_intf(rdev, wdev);
4386 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
4388 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4389 struct net_device *dev = info->user_ptr[1];
4392 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
4395 if (!rdev->ops->set_noack_map)
4398 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
4400 return rdev_set_noack_map(rdev, dev, noack_map);
4403 static int nl80211_validate_key_link_id(struct genl_info *info,
4404 struct wireless_dev *wdev,
4405 int link_id, bool pairwise)
4408 if (link_id != -1) {
4409 GENL_SET_ERR_MSG(info,
4410 "link ID not allowed for pairwise key");
4417 if (wdev->valid_links) {
4418 if (link_id == -1) {
4419 GENL_SET_ERR_MSG(info,
4420 "link ID must for MLO group key");
4423 if (!(wdev->valid_links & BIT(link_id))) {
4424 GENL_SET_ERR_MSG(info, "invalid link ID for MLO group key");
4427 } else if (link_id != -1) {
4428 GENL_SET_ERR_MSG(info, "link ID not allowed for non-MLO group key");
4435 struct get_key_cookie {
4436 struct sk_buff *msg;
4441 static void get_key_callback(void *c, struct key_params *params)
4444 struct get_key_cookie *cookie = c;
4447 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
4448 params->key_len, params->key)) ||
4450 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
4451 params->seq_len, params->seq)) ||
4453 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
4455 goto nla_put_failure;
4457 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
4459 goto nla_put_failure;
4462 nla_put(cookie->msg, NL80211_KEY_DATA,
4463 params->key_len, params->key)) ||
4465 nla_put(cookie->msg, NL80211_KEY_SEQ,
4466 params->seq_len, params->seq)) ||
4468 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
4470 goto nla_put_failure;
4472 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
4473 goto nla_put_failure;
4475 nla_nest_end(cookie->msg, key);
4482 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
4484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4486 struct net_device *dev = info->user_ptr[1];
4488 const u8 *mac_addr = NULL;
4490 struct get_key_cookie cookie = {
4494 struct sk_buff *msg;
4495 bool bigtk_support = false;
4496 int link_id = nl80211_link_id_or_invalid(info->attrs);
4497 struct wireless_dev *wdev = dev->ieee80211_ptr;
4499 if (wiphy_ext_feature_isset(&rdev->wiphy,
4500 NL80211_EXT_FEATURE_BEACON_PROTECTION))
4501 bigtk_support = true;
4503 if ((wdev->iftype == NL80211_IFTYPE_STATION ||
4504 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
4505 wiphy_ext_feature_isset(&rdev->wiphy,
4506 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
4507 bigtk_support = true;
4509 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
4510 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
4512 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) {
4513 GENL_SET_ERR_MSG(info, "BIGTK not supported");
4518 if (info->attrs[NL80211_ATTR_MAC])
4519 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4521 pairwise = !!mac_addr;
4522 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
4523 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
4525 if (kt != NL80211_KEYTYPE_GROUP &&
4526 kt != NL80211_KEYTYPE_PAIRWISE)
4528 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
4531 if (!rdev->ops->get_key)
4534 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4537 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4541 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4542 NL80211_CMD_NEW_KEY);
4544 goto nla_put_failure;
4547 cookie.idx = key_idx;
4549 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4550 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
4551 goto nla_put_failure;
4553 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
4554 goto nla_put_failure;
4556 err = nl80211_validate_key_link_id(info, wdev, link_id, pairwise);
4560 err = rdev_get_key(rdev, dev, link_id, key_idx, pairwise, mac_addr,
4561 &cookie, get_key_callback);
4567 goto nla_put_failure;
4569 genlmsg_end(msg, hdr);
4570 return genlmsg_reply(msg, info);
4579 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
4581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4582 struct key_parse key;
4584 struct net_device *dev = info->user_ptr[1];
4585 int link_id = nl80211_link_id_or_invalid(info->attrs);
4586 struct wireless_dev *wdev = dev->ieee80211_ptr;
4588 err = nl80211_parse_key(info, &key);
4595 /* Only support setting default key and
4596 * Extended Key ID action NL80211_KEY_SET_TX.
4598 if (!key.def && !key.defmgmt && !key.defbeacon &&
4599 !(key.p.mode == NL80211_KEY_SET_TX))
4605 if (!rdev->ops->set_default_key) {
4610 err = nl80211_key_allowed(wdev);
4614 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4618 err = rdev_set_default_key(rdev, dev, link_id, key.idx,
4619 key.def_uni, key.def_multi);
4624 #ifdef CONFIG_CFG80211_WEXT
4625 wdev->wext.default_key = key.idx;
4627 } else if (key.defmgmt) {
4628 if (key.def_uni || !key.def_multi) {
4633 if (!rdev->ops->set_default_mgmt_key) {
4638 err = nl80211_key_allowed(wdev);
4642 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4646 err = rdev_set_default_mgmt_key(rdev, dev, link_id, key.idx);
4650 #ifdef CONFIG_CFG80211_WEXT
4651 wdev->wext.default_mgmt_key = key.idx;
4653 } else if (key.defbeacon) {
4654 if (key.def_uni || !key.def_multi) {
4659 if (!rdev->ops->set_default_beacon_key) {
4664 err = nl80211_key_allowed(wdev);
4668 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4672 err = rdev_set_default_beacon_key(rdev, dev, link_id, key.idx);
4675 } else if (key.p.mode == NL80211_KEY_SET_TX &&
4676 wiphy_ext_feature_isset(&rdev->wiphy,
4677 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
4678 u8 *mac_addr = NULL;
4680 if (info->attrs[NL80211_ATTR_MAC])
4681 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4683 if (!mac_addr || key.idx < 0 || key.idx > 1) {
4688 err = nl80211_validate_key_link_id(info, wdev, link_id, true);
4692 err = rdev_add_key(rdev, dev, link_id, key.idx,
4693 NL80211_KEYTYPE_PAIRWISE,
4704 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4708 struct net_device *dev = info->user_ptr[1];
4709 struct key_parse key;
4710 const u8 *mac_addr = NULL;
4711 int link_id = nl80211_link_id_or_invalid(info->attrs);
4712 struct wireless_dev *wdev = dev->ieee80211_ptr;
4714 err = nl80211_parse_key(info, &key);
4719 GENL_SET_ERR_MSG(info, "no key");
4723 if (info->attrs[NL80211_ATTR_MAC])
4724 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4726 if (key.type == -1) {
4728 key.type = NL80211_KEYTYPE_PAIRWISE;
4730 key.type = NL80211_KEYTYPE_GROUP;
4734 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4735 key.type != NL80211_KEYTYPE_GROUP) {
4736 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
4740 if (key.type == NL80211_KEYTYPE_GROUP &&
4741 info->attrs[NL80211_ATTR_VLAN_ID])
4742 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
4744 if (!rdev->ops->add_key)
4747 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4748 key.type == NL80211_KEYTYPE_PAIRWISE,
4750 GENL_SET_ERR_MSG(info, "key setting validation failed");
4755 err = nl80211_key_allowed(wdev);
4757 GENL_SET_ERR_MSG(info, "key not allowed");
4760 err = nl80211_validate_key_link_id(info, wdev, link_id,
4761 key.type == NL80211_KEYTYPE_PAIRWISE);
4764 err = rdev_add_key(rdev, dev, link_id, key.idx,
4765 key.type == NL80211_KEYTYPE_PAIRWISE,
4768 GENL_SET_ERR_MSG(info, "key addition failed");
4775 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4779 struct net_device *dev = info->user_ptr[1];
4780 u8 *mac_addr = NULL;
4781 struct key_parse key;
4782 int link_id = nl80211_link_id_or_invalid(info->attrs);
4783 struct wireless_dev *wdev = dev->ieee80211_ptr;
4785 err = nl80211_parse_key(info, &key);
4789 if (info->attrs[NL80211_ATTR_MAC])
4790 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4792 if (key.type == -1) {
4794 key.type = NL80211_KEYTYPE_PAIRWISE;
4796 key.type = NL80211_KEYTYPE_GROUP;
4800 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4801 key.type != NL80211_KEYTYPE_GROUP)
4804 if (!cfg80211_valid_key_idx(rdev, key.idx,
4805 key.type == NL80211_KEYTYPE_PAIRWISE))
4808 if (!rdev->ops->del_key)
4812 err = nl80211_key_allowed(wdev);
4814 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
4815 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4819 err = nl80211_validate_key_link_id(info, wdev, link_id,
4820 key.type == NL80211_KEYTYPE_PAIRWISE);
4823 err = rdev_del_key(rdev, dev, link_id, key.idx,
4824 key.type == NL80211_KEYTYPE_PAIRWISE,
4827 #ifdef CONFIG_CFG80211_WEXT
4829 if (key.idx == wdev->wext.default_key)
4830 wdev->wext.default_key = -1;
4831 else if (key.idx == wdev->wext.default_mgmt_key)
4832 wdev->wext.default_mgmt_key = -1;
4840 /* This function returns an error or the number of nested attributes */
4841 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4843 struct nlattr *attr;
4844 int n_entries = 0, tmp;
4846 nla_for_each_nested(attr, nl_attr, tmp) {
4847 if (nla_len(attr) != ETH_ALEN)
4857 * This function parses ACL information and allocates memory for ACL data.
4858 * On successful return, the calling function is responsible to free the
4859 * ACL buffer returned by this function.
4861 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4862 struct genl_info *info)
4864 enum nl80211_acl_policy acl_policy;
4865 struct nlattr *attr;
4866 struct cfg80211_acl_data *acl;
4867 int i = 0, n_entries, tmp;
4869 if (!wiphy->max_acl_mac_addrs)
4870 return ERR_PTR(-EOPNOTSUPP);
4872 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4873 return ERR_PTR(-EINVAL);
4875 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4876 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4877 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4878 return ERR_PTR(-EINVAL);
4880 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4881 return ERR_PTR(-EINVAL);
4883 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4885 return ERR_PTR(n_entries);
4887 if (n_entries > wiphy->max_acl_mac_addrs)
4888 return ERR_PTR(-ENOTSUPP);
4890 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
4892 return ERR_PTR(-ENOMEM);
4893 acl->n_acl_entries = n_entries;
4895 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4896 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4899 acl->acl_policy = acl_policy;
4904 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4907 struct net_device *dev = info->user_ptr[1];
4908 struct cfg80211_acl_data *acl;
4911 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4912 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4915 if (!dev->ieee80211_ptr->links[0].ap.beacon_interval)
4918 acl = parse_acl_data(&rdev->wiphy, info);
4920 return PTR_ERR(acl);
4922 err = rdev_set_mac_acl(rdev, dev, acl);
4929 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4930 u8 *rates, u8 rates_len)
4935 for (i = 0; i < rates_len; i++) {
4936 int rate = (rates[i] & 0x7f) * 5;
4939 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4940 struct ieee80211_rate *srate =
4941 &sband->bitrates[ridx];
4942 if (rate == srate->bitrate) {
4947 if (ridx == sband->n_bitrates)
4948 return 0; /* rate not found */
4954 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4955 u8 *rates, u8 rates_len,
4956 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4960 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4962 for (i = 0; i < rates_len; i++) {
4965 ridx = rates[i] / 8;
4966 rbit = BIT(rates[i] % 8);
4968 /* check validity */
4969 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4972 /* check availability */
4973 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
4974 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4983 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4987 switch (vht_mcs_map) {
4988 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4990 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4993 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4996 case IEEE80211_VHT_MCS_SUPPORT_0_9:
5006 static void vht_build_mcs_mask(u16 vht_mcs_map,
5007 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
5011 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
5012 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
5017 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
5018 struct nl80211_txrate_vht *txrate,
5019 u16 mcs[NL80211_VHT_NSS_MAX])
5021 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5022 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
5025 if (!sband->vht_cap.vht_supported)
5028 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
5030 /* Build vht_mcs_mask from VHT capabilities */
5031 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
5033 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5034 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
5035 mcs[i] = txrate->mcs[i];
5043 static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map)
5045 switch (he_mcs_map) {
5046 case IEEE80211_HE_MCS_NOT_SUPPORTED:
5048 case IEEE80211_HE_MCS_SUPPORT_0_7:
5050 case IEEE80211_HE_MCS_SUPPORT_0_9:
5052 case IEEE80211_HE_MCS_SUPPORT_0_11:
5060 static void he_build_mcs_mask(u16 he_mcs_map,
5061 u16 he_mcs_mask[NL80211_HE_NSS_MAX])
5065 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) {
5066 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03);
5071 static u16 he_get_txmcsmap(struct genl_info *info, unsigned int link_id,
5072 const struct ieee80211_sta_he_cap *he_cap)
5074 struct net_device *dev = info->user_ptr[1];
5075 struct wireless_dev *wdev = dev->ieee80211_ptr;
5076 struct cfg80211_chan_def *chandef;
5079 chandef = wdev_chandef(wdev, link_id);
5082 * This is probably broken, but we never maintained
5083 * a chandef in these cases, so it always was.
5085 return le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
5088 switch (chandef->width) {
5089 case NL80211_CHAN_WIDTH_80P80:
5090 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80;
5092 case NL80211_CHAN_WIDTH_160:
5093 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160;
5096 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80;
5100 return le16_to_cpu(tx_mcs);
5103 static bool he_set_mcs_mask(struct genl_info *info,
5104 struct wireless_dev *wdev,
5105 struct ieee80211_supported_band *sband,
5106 struct nl80211_txrate_he *txrate,
5107 u16 mcs[NL80211_HE_NSS_MAX],
5108 unsigned int link_id)
5110 const struct ieee80211_sta_he_cap *he_cap;
5111 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {};
5115 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
5119 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX);
5121 tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap);
5123 /* Build he_mcs_mask from HE capabilities */
5124 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
5126 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
5127 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
5128 mcs[i] = txrate->mcs[i];
5136 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
5137 struct nlattr *attrs[],
5138 enum nl80211_attrs attr,
5139 struct cfg80211_bitrate_mask *mask,
5140 struct net_device *dev,
5141 bool default_all_enabled,
5142 unsigned int link_id)
5144 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
5145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5146 struct wireless_dev *wdev = dev->ieee80211_ptr;
5148 struct nlattr *tx_rates;
5149 struct ieee80211_supported_band *sband;
5150 u16 vht_tx_mcs_map, he_tx_mcs_map;
5152 memset(mask, 0, sizeof(*mask));
5153 /* Default to all rates enabled */
5154 for (i = 0; i < NUM_NL80211_BANDS; i++) {
5155 const struct ieee80211_sta_he_cap *he_cap;
5157 if (!default_all_enabled)
5160 sband = rdev->wiphy.bands[i];
5165 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
5166 memcpy(mask->control[i].ht_mcs,
5167 sband->ht_cap.mcs.rx_mask,
5168 sizeof(mask->control[i].ht_mcs));
5170 if (sband->vht_cap.vht_supported) {
5171 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5172 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
5175 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
5179 he_tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap);
5180 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs);
5182 mask->control[i].he_gi = 0xFF;
5183 mask->control[i].he_ltf = 0xFF;
5186 /* if no rates are given set it back to the defaults */
5190 /* The nested attribute uses enum nl80211_band as the index. This maps
5191 * directly to the enum nl80211_band values used in cfg80211.
5193 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
5194 nla_for_each_nested(tx_rates, attrs[attr], rem) {
5195 enum nl80211_band band = nla_type(tx_rates);
5198 if (band < 0 || band >= NUM_NL80211_BANDS)
5200 sband = rdev->wiphy.bands[band];
5203 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
5205 nl80211_txattr_policy,
5209 if (tb[NL80211_TXRATE_LEGACY]) {
5210 mask->control[band].legacy = rateset_to_mask(
5212 nla_data(tb[NL80211_TXRATE_LEGACY]),
5213 nla_len(tb[NL80211_TXRATE_LEGACY]));
5214 if ((mask->control[band].legacy == 0) &&
5215 nla_len(tb[NL80211_TXRATE_LEGACY]))
5218 if (tb[NL80211_TXRATE_HT]) {
5219 if (!ht_rateset_to_mask(
5221 nla_data(tb[NL80211_TXRATE_HT]),
5222 nla_len(tb[NL80211_TXRATE_HT]),
5223 mask->control[band].ht_mcs))
5227 if (tb[NL80211_TXRATE_VHT]) {
5228 if (!vht_set_mcs_mask(
5230 nla_data(tb[NL80211_TXRATE_VHT]),
5231 mask->control[band].vht_mcs))
5235 if (tb[NL80211_TXRATE_GI]) {
5236 mask->control[band].gi =
5237 nla_get_u8(tb[NL80211_TXRATE_GI]);
5238 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
5241 if (tb[NL80211_TXRATE_HE] &&
5242 !he_set_mcs_mask(info, wdev, sband,
5243 nla_data(tb[NL80211_TXRATE_HE]),
5244 mask->control[band].he_mcs,
5248 if (tb[NL80211_TXRATE_HE_GI])
5249 mask->control[band].he_gi =
5250 nla_get_u8(tb[NL80211_TXRATE_HE_GI]);
5251 if (tb[NL80211_TXRATE_HE_LTF])
5252 mask->control[band].he_ltf =
5253 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]);
5255 if (mask->control[band].legacy == 0) {
5256 /* don't allow empty legacy rates if HT, VHT or HE
5257 * are not even supported.
5259 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
5260 rdev->wiphy.bands[band]->vht_cap.vht_supported ||
5261 ieee80211_get_he_iftype_cap(sband, wdev->iftype)))
5264 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5265 if (mask->control[band].ht_mcs[i])
5268 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5269 if (mask->control[band].vht_mcs[i])
5272 for (i = 0; i < NL80211_HE_NSS_MAX; i++)
5273 if (mask->control[band].he_mcs[i])
5276 /* legacy and mcs rates may not be both empty */
5285 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
5286 enum nl80211_band band,
5287 struct cfg80211_bitrate_mask *beacon_rate)
5289 u32 count_ht, count_vht, count_he, i;
5290 u32 rate = beacon_rate->control[band].legacy;
5292 /* Allow only one rate */
5293 if (hweight32(rate) > 1)
5297 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5298 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
5300 } else if (beacon_rate->control[band].ht_mcs[i]) {
5305 if (count_ht && rate)
5310 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5311 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
5313 } else if (beacon_rate->control[band].vht_mcs[i]) {
5318 if (count_vht && rate)
5323 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
5324 if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) {
5326 } else if (beacon_rate->control[band].he_mcs[i]) {
5331 if (count_he && rate)
5335 if ((count_ht && count_vht && count_he) ||
5336 (!rate && !count_ht && !count_vht && !count_he))
5340 !wiphy_ext_feature_isset(&rdev->wiphy,
5341 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
5344 !wiphy_ext_feature_isset(&rdev->wiphy,
5345 NL80211_EXT_FEATURE_BEACON_RATE_HT))
5348 !wiphy_ext_feature_isset(&rdev->wiphy,
5349 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
5352 !wiphy_ext_feature_isset(&rdev->wiphy,
5353 NL80211_EXT_FEATURE_BEACON_RATE_HE))
5359 static int nl80211_parse_mbssid_config(struct wiphy *wiphy,
5360 struct net_device *dev,
5361 struct nlattr *attrs,
5362 struct cfg80211_mbssid_config *config,
5365 struct nlattr *tb[NL80211_MBSSID_CONFIG_ATTR_MAX + 1];
5367 if (!wiphy->mbssid_max_interfaces)
5370 if (nla_parse_nested(tb, NL80211_MBSSID_CONFIG_ATTR_MAX, attrs, NULL,
5372 !tb[NL80211_MBSSID_CONFIG_ATTR_INDEX])
5375 config->ema = nla_get_flag(tb[NL80211_MBSSID_CONFIG_ATTR_EMA]);
5377 if (!wiphy->ema_max_profile_periodicity)
5380 if (num_elems > wiphy->ema_max_profile_periodicity)
5384 config->index = nla_get_u8(tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]);
5385 if (config->index >= wiphy->mbssid_max_interfaces ||
5386 (!config->index && !num_elems))
5389 if (tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]) {
5391 nla_get_u32(tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]);
5393 if ((!config->index && tx_ifindex != dev->ifindex) ||
5394 (config->index && tx_ifindex == dev->ifindex))
5397 if (tx_ifindex != dev->ifindex) {
5398 struct net_device *tx_netdev =
5399 dev_get_by_index(wiphy_net(wiphy), tx_ifindex);
5401 if (!tx_netdev || !tx_netdev->ieee80211_ptr ||
5402 tx_netdev->ieee80211_ptr->wiphy != wiphy ||
5403 tx_netdev->ieee80211_ptr->iftype !=
5404 NL80211_IFTYPE_AP) {
5409 config->tx_wdev = tx_netdev->ieee80211_ptr;
5411 config->tx_wdev = dev->ieee80211_ptr;
5413 } else if (!config->index) {
5414 config->tx_wdev = dev->ieee80211_ptr;
5422 static struct cfg80211_mbssid_elems *
5423 nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs)
5425 struct nlattr *nl_elems;
5426 struct cfg80211_mbssid_elems *elems;
5428 u8 i = 0, num_elems = 0;
5430 if (!wiphy->mbssid_max_interfaces)
5431 return ERR_PTR(-EINVAL);
5433 nla_for_each_nested(nl_elems, attrs, rem_elems) {
5434 if (num_elems >= 255)
5435 return ERR_PTR(-EINVAL);
5439 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
5441 return ERR_PTR(-ENOMEM);
5442 elems->cnt = num_elems;
5444 nla_for_each_nested(nl_elems, attrs, rem_elems) {
5445 elems->elem[i].data = nla_data(nl_elems);
5446 elems->elem[i].len = nla_len(nl_elems);
5452 static struct cfg80211_rnr_elems *
5453 nl80211_parse_rnr_elems(struct wiphy *wiphy, struct nlattr *attrs,
5454 struct netlink_ext_ack *extack)
5456 struct nlattr *nl_elems;
5457 struct cfg80211_rnr_elems *elems;
5459 u8 i = 0, num_elems = 0;
5461 nla_for_each_nested(nl_elems, attrs, rem_elems) {
5464 ret = validate_ie_attr(nl_elems, extack);
5466 return ERR_PTR(ret);
5471 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
5473 return ERR_PTR(-ENOMEM);
5474 elems->cnt = num_elems;
5476 nla_for_each_nested(nl_elems, attrs, rem_elems) {
5477 elems->elem[i].data = nla_data(nl_elems);
5478 elems->elem[i].len = nla_len(nl_elems);
5484 static int nl80211_parse_he_bss_color(struct nlattr *attrs,
5485 struct cfg80211_he_bss_color *he_bss_color)
5487 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1];
5490 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs,
5491 he_bss_color_policy, NULL);
5495 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR])
5498 he_bss_color->color =
5499 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]);
5500 he_bss_color->enabled =
5501 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]);
5502 he_bss_color->partial =
5503 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]);
5508 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
5509 struct nlattr *attrs[],
5510 struct cfg80211_beacon_data *bcn,
5511 struct netlink_ext_ack *extack)
5513 bool haveinfo = false;
5516 memset(bcn, 0, sizeof(*bcn));
5518 bcn->link_id = nl80211_link_id(attrs);
5520 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
5521 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
5522 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
5528 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
5529 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
5530 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
5537 if (attrs[NL80211_ATTR_IE]) {
5538 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
5539 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
5542 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
5543 bcn->proberesp_ies =
5544 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
5545 bcn->proberesp_ies_len =
5546 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
5549 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
5550 bcn->assocresp_ies =
5551 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
5552 bcn->assocresp_ies_len =
5553 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
5556 if (attrs[NL80211_ATTR_PROBE_RESP]) {
5557 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
5558 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
5561 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
5562 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
5564 err = nla_parse_nested_deprecated(tb,
5565 NL80211_FTM_RESP_ATTR_MAX,
5566 attrs[NL80211_ATTR_FTM_RESPONDER],
5571 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
5572 wiphy_ext_feature_isset(&rdev->wiphy,
5573 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
5574 bcn->ftm_responder = 1;
5578 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
5579 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
5580 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
5583 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
5584 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
5585 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
5588 bcn->ftm_responder = -1;
5591 if (attrs[NL80211_ATTR_HE_BSS_COLOR]) {
5592 err = nl80211_parse_he_bss_color(attrs[NL80211_ATTR_HE_BSS_COLOR],
5593 &bcn->he_bss_color);
5596 bcn->he_bss_color_valid = true;
5599 if (attrs[NL80211_ATTR_MBSSID_ELEMS]) {
5600 struct cfg80211_mbssid_elems *mbssid =
5601 nl80211_parse_mbssid_elems(&rdev->wiphy,
5602 attrs[NL80211_ATTR_MBSSID_ELEMS]);
5605 return PTR_ERR(mbssid);
5607 bcn->mbssid_ies = mbssid;
5609 if (bcn->mbssid_ies && attrs[NL80211_ATTR_EMA_RNR_ELEMS]) {
5610 struct cfg80211_rnr_elems *rnr =
5611 nl80211_parse_rnr_elems(&rdev->wiphy,
5612 attrs[NL80211_ATTR_EMA_RNR_ELEMS],
5616 return PTR_ERR(rnr);
5618 if (rnr && rnr->cnt < bcn->mbssid_ies->cnt)
5628 static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
5629 struct ieee80211_he_obss_pd *he_obss_pd)
5631 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
5634 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
5635 he_obss_pd_policy, NULL);
5639 if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL])
5642 he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]);
5644 if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET])
5645 he_obss_pd->min_offset =
5646 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
5647 if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
5648 he_obss_pd->max_offset =
5649 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
5650 if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET])
5651 he_obss_pd->non_srg_max_offset =
5652 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]);
5654 if (he_obss_pd->min_offset > he_obss_pd->max_offset)
5657 if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP])
5658 memcpy(he_obss_pd->bss_color_bitmap,
5659 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]),
5660 sizeof(he_obss_pd->bss_color_bitmap));
5662 if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP])
5663 memcpy(he_obss_pd->partial_bssid_bitmap,
5664 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]),
5665 sizeof(he_obss_pd->partial_bssid_bitmap));
5667 he_obss_pd->enable = true;
5672 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev,
5673 struct nlattr *attrs,
5674 struct cfg80211_ap_settings *params)
5676 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1];
5678 struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery;
5680 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5681 NL80211_EXT_FEATURE_FILS_DISCOVERY))
5684 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs,
5689 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] ||
5690 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] ||
5691 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL])
5694 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
5695 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
5696 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]);
5697 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]);
5703 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev,
5704 struct nlattr *attrs,
5705 struct cfg80211_ap_settings *params)
5707 struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1];
5709 struct cfg80211_unsol_bcast_probe_resp *presp =
5710 ¶ms->unsol_bcast_probe_resp;
5712 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5713 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP))
5716 ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX,
5721 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] ||
5722 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL])
5725 presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]);
5726 presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]);
5727 presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]);
5731 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
5732 const struct element *rates)
5739 for (i = 0; i < rates->datalen; i++) {
5740 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
5741 params->ht_required = true;
5742 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
5743 params->vht_required = true;
5744 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
5745 params->he_required = true;
5746 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E)
5747 params->sae_h2e_required = true;
5752 * Since the nl80211 API didn't include, from the beginning, attributes about
5753 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
5754 * benefit of drivers that rebuild IEs in the firmware.
5756 static int nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
5758 const struct cfg80211_beacon_data *bcn = ¶ms->beacon;
5759 size_t ies_len = bcn->tail_len;
5760 const u8 *ies = bcn->tail;
5761 const struct element *rates;
5762 const struct element *cap;
5764 rates = cfg80211_find_elem(WLAN_EID_SUPP_RATES, ies, ies_len);
5765 nl80211_check_ap_rate_selectors(params, rates);
5767 rates = cfg80211_find_elem(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
5768 nl80211_check_ap_rate_selectors(params, rates);
5770 cap = cfg80211_find_elem(WLAN_EID_HT_CAPABILITY, ies, ies_len);
5771 if (cap && cap->datalen >= sizeof(*params->ht_cap))
5772 params->ht_cap = (void *)cap->data;
5773 cap = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
5774 if (cap && cap->datalen >= sizeof(*params->vht_cap))
5775 params->vht_cap = (void *)cap->data;
5776 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
5777 if (cap && cap->datalen >= sizeof(*params->he_cap) + 1)
5778 params->he_cap = (void *)(cap->data + 1);
5779 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ies, ies_len);
5780 if (cap && cap->datalen >= sizeof(*params->he_oper) + 1)
5781 params->he_oper = (void *)(cap->data + 1);
5782 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_CAPABILITY, ies, ies_len);
5786 params->eht_cap = (void *)(cap->data + 1);
5787 if (!ieee80211_eht_capa_size_ok((const u8 *)params->he_cap,
5788 (const u8 *)params->eht_cap,
5789 cap->datalen - 1, true))
5792 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION, ies, ies_len);
5796 params->eht_oper = (void *)(cap->data + 1);
5797 if (!ieee80211_eht_oper_size_ok((const u8 *)params->eht_oper,
5804 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
5805 struct cfg80211_ap_settings *params)
5807 struct wireless_dev *wdev;
5809 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
5810 if (wdev->iftype != NL80211_IFTYPE_AP &&
5811 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5814 if (!wdev->u.ap.preset_chandef.chan)
5817 params->chandef = wdev->u.ap.preset_chandef;
5824 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
5825 enum nl80211_auth_type auth_type,
5826 enum nl80211_commands cmd)
5828 if (auth_type > NL80211_AUTHTYPE_MAX)
5832 case NL80211_CMD_AUTHENTICATE:
5833 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
5834 auth_type == NL80211_AUTHTYPE_SAE)
5836 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5837 NL80211_EXT_FEATURE_FILS_STA) &&
5838 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5839 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5840 auth_type == NL80211_AUTHTYPE_FILS_PK))
5843 case NL80211_CMD_CONNECT:
5844 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
5845 !wiphy_ext_feature_isset(&rdev->wiphy,
5846 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
5847 auth_type == NL80211_AUTHTYPE_SAE)
5850 /* FILS with SK PFS or PK not supported yet */
5851 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5852 auth_type == NL80211_AUTHTYPE_FILS_PK)
5854 if (!wiphy_ext_feature_isset(
5856 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
5857 auth_type == NL80211_AUTHTYPE_FILS_SK)
5860 case NL80211_CMD_START_AP:
5861 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5862 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) &&
5863 auth_type == NL80211_AUTHTYPE_SAE)
5865 /* FILS not supported yet */
5866 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5867 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5868 auth_type == NL80211_AUTHTYPE_FILS_PK)
5876 static void nl80211_send_ap_started(struct wireless_dev *wdev,
5877 unsigned int link_id)
5879 struct wiphy *wiphy = wdev->wiphy;
5880 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
5881 struct sk_buff *msg;
5884 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_START_AP);
5892 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
5893 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
5894 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
5895 NL80211_ATTR_PAD) ||
5896 (wdev->u.ap.ssid_len &&
5897 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len,
5898 wdev->u.ap.ssid)) ||
5899 (wdev->valid_links &&
5900 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)))
5903 genlmsg_end(msg, hdr);
5905 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
5906 NL80211_MCGRP_MLME, GFP_KERNEL);
5912 static int nl80211_validate_ap_phy_operation(struct cfg80211_ap_settings *params)
5914 struct ieee80211_channel *channel = params->chandef.chan;
5916 if ((params->he_cap || params->he_oper) &&
5917 (channel->flags & IEEE80211_CHAN_NO_HE))
5920 if ((params->eht_cap || params->eht_oper) &&
5921 (channel->flags & IEEE80211_CHAN_NO_EHT))
5927 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
5929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5930 unsigned int link_id = nl80211_link_id(info->attrs);
5931 struct net_device *dev = info->user_ptr[1];
5932 struct wireless_dev *wdev = dev->ieee80211_ptr;
5933 struct cfg80211_ap_settings *params;
5936 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5937 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5940 if (!rdev->ops->start_ap)
5943 if (wdev->links[link_id].ap.beacon_interval)
5946 /* these are required for START_AP */
5947 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
5948 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
5949 !info->attrs[NL80211_ATTR_BEACON_HEAD])
5952 params = kzalloc(sizeof(*params), GFP_KERNEL);
5956 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon,
5961 params->beacon_interval =
5962 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5963 params->dtim_period =
5964 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
5966 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
5967 params->beacon_interval);
5972 * In theory, some of these attributes should be required here
5973 * but since they were not used when the command was originally
5974 * added, keep them optional for old user space programs to let
5975 * them continue to work with drivers that do not need the
5976 * additional information -- drivers must check!
5978 if (info->attrs[NL80211_ATTR_SSID]) {
5979 params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5981 nla_len(info->attrs[NL80211_ATTR_SSID]);
5982 if (params->ssid_len == 0) {
5987 if (wdev->u.ap.ssid_len &&
5988 (wdev->u.ap.ssid_len != params->ssid_len ||
5989 memcmp(wdev->u.ap.ssid, params->ssid, params->ssid_len))) {
5990 /* require identical SSID for MLO */
5994 } else if (wdev->valid_links) {
5995 /* require SSID for MLO */
6000 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
6001 params->hidden_ssid = nla_get_u32(
6002 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
6004 params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
6006 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6007 params->auth_type = nla_get_u32(
6008 info->attrs[NL80211_ATTR_AUTH_TYPE]);
6009 if (!nl80211_valid_auth_type(rdev, params->auth_type,
6010 NL80211_CMD_START_AP)) {
6015 params->auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6017 err = nl80211_crypto_settings(rdev, info, ¶ms->crypto,
6018 NL80211_MAX_NR_CIPHER_SUITES);
6022 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
6023 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) {
6027 params->inactivity_timeout = nla_get_u16(
6028 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
6031 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6032 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
6036 params->p2p_ctwindow =
6037 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
6038 if (params->p2p_ctwindow != 0 &&
6039 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) {
6045 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6048 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
6052 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
6053 params->p2p_opp_ps = tmp;
6054 if (params->p2p_opp_ps != 0 &&
6055 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) {
6061 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6062 err = nl80211_parse_chandef(rdev, info, ¶ms->chandef);
6065 } else if (wdev->valid_links) {
6066 /* with MLD need to specify the channel configuration */
6069 } else if (wdev->u.ap.preset_chandef.chan) {
6070 params->chandef = wdev->u.ap.preset_chandef;
6071 } else if (!nl80211_get_ap_channel(rdev, params)) {
6076 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) {
6077 err = nl80211_parse_punct_bitmap(rdev, info,
6079 ¶ms->punct_bitmap);
6084 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef,
6092 if (info->attrs[NL80211_ATTR_TX_RATES]) {
6093 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
6094 NL80211_ATTR_TX_RATES,
6095 ¶ms->beacon_rate,
6096 dev, false, link_id);
6100 err = validate_beacon_tx_rate(rdev, params->chandef.chan->band,
6101 ¶ms->beacon_rate);
6106 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
6108 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
6109 switch (params->smps_mode) {
6110 case NL80211_SMPS_OFF:
6112 case NL80211_SMPS_STATIC:
6113 if (!(rdev->wiphy.features &
6114 NL80211_FEATURE_STATIC_SMPS)) {
6119 case NL80211_SMPS_DYNAMIC:
6120 if (!(rdev->wiphy.features &
6121 NL80211_FEATURE_DYNAMIC_SMPS)) {
6131 params->smps_mode = NL80211_SMPS_OFF;
6134 params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
6135 if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
6140 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
6141 params->acl = parse_acl_data(&rdev->wiphy, info);
6142 if (IS_ERR(params->acl)) {
6143 err = PTR_ERR(params->acl);
6149 params->twt_responder =
6150 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
6152 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
6153 err = nl80211_parse_he_obss_pd(
6154 info->attrs[NL80211_ATTR_HE_OBSS_PD],
6155 ¶ms->he_obss_pd);
6160 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) {
6161 err = nl80211_parse_fils_discovery(rdev,
6162 info->attrs[NL80211_ATTR_FILS_DISCOVERY],
6168 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) {
6169 err = nl80211_parse_unsol_bcast_probe_resp(
6170 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP],
6176 if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) {
6177 err = nl80211_parse_mbssid_config(&rdev->wiphy, dev,
6178 info->attrs[NL80211_ATTR_MBSSID_CONFIG],
6179 ¶ms->mbssid_config,
6180 params->beacon.mbssid_ies ?
6181 params->beacon.mbssid_ies->cnt :
6187 if (!params->mbssid_config.ema && params->beacon.rnr_ies) {
6192 err = nl80211_calculate_ap_params(params);
6196 err = nl80211_validate_ap_phy_operation(params);
6200 if (info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS])
6201 params->flags = nla_get_u32(
6202 info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]);
6203 else if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
6204 params->flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
6206 if (wdev->conn_owner_nlportid &&
6207 info->attrs[NL80211_ATTR_SOCKET_OWNER] &&
6208 wdev->conn_owner_nlportid != info->snd_portid) {
6213 /* FIXME: validate MLO/link-id against driver capabilities */
6215 err = rdev_start_ap(rdev, dev, params);
6217 wdev->links[link_id].ap.beacon_interval = params->beacon_interval;
6218 wdev->links[link_id].ap.chandef = params->chandef;
6219 wdev->u.ap.ssid_len = params->ssid_len;
6220 memcpy(wdev->u.ap.ssid, params->ssid,
6223 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6224 wdev->conn_owner_nlportid = info->snd_portid;
6226 nl80211_send_ap_started(wdev, link_id);
6232 kfree(params->beacon.mbssid_ies);
6233 if (params->mbssid_config.tx_wdev &&
6234 params->mbssid_config.tx_wdev->netdev &&
6235 params->mbssid_config.tx_wdev->netdev != dev)
6236 dev_put(params->mbssid_config.tx_wdev->netdev);
6237 kfree(params->beacon.rnr_ies);
6243 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
6245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6246 unsigned int link_id = nl80211_link_id(info->attrs);
6247 struct net_device *dev = info->user_ptr[1];
6248 struct wireless_dev *wdev = dev->ieee80211_ptr;
6249 struct cfg80211_beacon_data params;
6252 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6253 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6256 if (!rdev->ops->change_beacon)
6259 if (!wdev->links[link_id].ap.beacon_interval)
6262 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms, info->extack);
6267 err = rdev_change_beacon(rdev, dev, ¶ms);
6271 kfree(params.mbssid_ies);
6272 kfree(params.rnr_ies);
6276 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
6278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6279 unsigned int link_id = nl80211_link_id(info->attrs);
6280 struct net_device *dev = info->user_ptr[1];
6282 return cfg80211_stop_ap(rdev, dev, link_id, false);
6285 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
6286 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
6287 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
6288 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
6289 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
6290 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
6291 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
6294 static int parse_station_flags(struct genl_info *info,
6295 enum nl80211_iftype iftype,
6296 struct station_parameters *params)
6298 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
6303 * Try parsing the new attribute first so userspace
6304 * can specify both for older kernels.
6306 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
6308 struct nl80211_sta_flag_update *sta_flags;
6310 sta_flags = nla_data(nla);
6311 params->sta_flags_mask = sta_flags->mask;
6312 params->sta_flags_set = sta_flags->set;
6313 params->sta_flags_set &= params->sta_flags_mask;
6314 if ((params->sta_flags_mask |
6315 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
6320 /* if present, parse the old attribute */
6322 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
6326 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
6330 * Only allow certain flags for interface types so that
6331 * other attributes are silently ignored. Remember that
6332 * this is backward compatibility code with old userspace
6333 * and shouldn't be hit in other cases anyway.
6336 case NL80211_IFTYPE_AP:
6337 case NL80211_IFTYPE_AP_VLAN:
6338 case NL80211_IFTYPE_P2P_GO:
6339 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
6340 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
6341 BIT(NL80211_STA_FLAG_WME) |
6342 BIT(NL80211_STA_FLAG_MFP);
6344 case NL80211_IFTYPE_P2P_CLIENT:
6345 case NL80211_IFTYPE_STATION:
6346 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
6347 BIT(NL80211_STA_FLAG_TDLS_PEER);
6349 case NL80211_IFTYPE_MESH_POINT:
6350 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6351 BIT(NL80211_STA_FLAG_MFP) |
6352 BIT(NL80211_STA_FLAG_AUTHORIZED);
6358 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
6360 params->sta_flags_set |= (1<<flag);
6362 /* no longer support new API additions in old API */
6363 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
6371 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
6373 struct nlattr *rate;
6376 enum nl80211_rate_info rate_flg;
6378 rate = nla_nest_start_noflag(msg, attr);
6382 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
6383 bitrate = cfg80211_calculate_bitrate(info);
6384 /* report 16-bit bitrate only if we can */
6385 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
6387 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
6389 if (bitrate_compat > 0 &&
6390 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
6394 case RATE_INFO_BW_1:
6395 rate_flg = NL80211_RATE_INFO_1_MHZ_WIDTH;
6397 case RATE_INFO_BW_2:
6398 rate_flg = NL80211_RATE_INFO_2_MHZ_WIDTH;
6400 case RATE_INFO_BW_4:
6401 rate_flg = NL80211_RATE_INFO_4_MHZ_WIDTH;
6403 case RATE_INFO_BW_5:
6404 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
6406 case RATE_INFO_BW_8:
6407 rate_flg = NL80211_RATE_INFO_8_MHZ_WIDTH;
6409 case RATE_INFO_BW_10:
6410 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
6412 case RATE_INFO_BW_16:
6413 rate_flg = NL80211_RATE_INFO_16_MHZ_WIDTH;
6418 case RATE_INFO_BW_20:
6421 case RATE_INFO_BW_40:
6422 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
6424 case RATE_INFO_BW_80:
6425 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
6427 case RATE_INFO_BW_160:
6428 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
6430 case RATE_INFO_BW_HE_RU:
6432 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
6434 case RATE_INFO_BW_320:
6435 rate_flg = NL80211_RATE_INFO_320_MHZ_WIDTH;
6437 case RATE_INFO_BW_EHT_RU:
6439 WARN_ON(!(info->flags & RATE_INFO_FLAGS_EHT_MCS));
6443 if (rate_flg && nla_put_flag(msg, rate_flg))
6446 if (info->flags & RATE_INFO_FLAGS_MCS) {
6447 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
6449 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6450 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6452 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
6453 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
6455 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
6457 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6458 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6460 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
6461 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
6463 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
6465 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
6467 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
6469 if (info->bw == RATE_INFO_BW_HE_RU &&
6470 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
6473 } else if (info->flags & RATE_INFO_FLAGS_S1G_MCS) {
6474 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_MCS, info->mcs))
6476 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_NSS, info->nss))
6478 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6479 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6481 } else if (info->flags & RATE_INFO_FLAGS_EHT_MCS) {
6482 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_MCS, info->mcs))
6484 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_NSS, info->nss))
6486 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_GI, info->eht_gi))
6488 if (info->bw == RATE_INFO_BW_EHT_RU &&
6489 nla_put_u8(msg, NL80211_RATE_INFO_EHT_RU_ALLOC,
6490 info->eht_ru_alloc))
6494 nla_nest_end(msg, rate);
6498 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
6507 attr = nla_nest_start_noflag(msg, id);
6511 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
6512 if (!(mask & BIT(i)))
6515 if (nla_put_u8(msg, i, signal[i]))
6519 nla_nest_end(msg, attr);
6524 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
6526 struct cfg80211_registered_device *rdev,
6527 struct net_device *dev,
6528 const u8 *mac_addr, struct station_info *sinfo)
6531 struct nlattr *sinfoattr, *bss_param;
6533 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
6535 cfg80211_sinfo_release_content(sinfo);
6539 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6540 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
6541 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
6542 goto nla_put_failure;
6544 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
6546 goto nla_put_failure;
6548 #define PUT_SINFO(attr, memb, type) do { \
6549 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
6550 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
6551 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
6553 goto nla_put_failure; \
6555 #define PUT_SINFO_U64(attr, memb) do { \
6556 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
6557 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
6558 sinfo->memb, NL80211_STA_INFO_PAD)) \
6559 goto nla_put_failure; \
6562 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
6563 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
6564 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
6566 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
6567 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
6568 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
6569 (u32)sinfo->rx_bytes))
6570 goto nla_put_failure;
6572 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
6573 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
6574 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
6575 (u32)sinfo->tx_bytes))
6576 goto nla_put_failure;
6578 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
6579 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
6580 PUT_SINFO(LLID, llid, u16);
6581 PUT_SINFO(PLID, plid, u16);
6582 PUT_SINFO(PLINK_STATE, plink_state, u8);
6583 PUT_SINFO_U64(RX_DURATION, rx_duration);
6584 PUT_SINFO_U64(TX_DURATION, tx_duration);
6586 if (wiphy_ext_feature_isset(&rdev->wiphy,
6587 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6588 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
6590 switch (rdev->wiphy.signal_type) {
6591 case CFG80211_SIGNAL_TYPE_MBM:
6592 PUT_SINFO(SIGNAL, signal, u8);
6593 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
6598 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
6599 if (!nl80211_put_signal(msg, sinfo->chains,
6600 sinfo->chain_signal,
6601 NL80211_STA_INFO_CHAIN_SIGNAL))
6602 goto nla_put_failure;
6604 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
6605 if (!nl80211_put_signal(msg, sinfo->chains,
6606 sinfo->chain_signal_avg,
6607 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
6608 goto nla_put_failure;
6610 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
6611 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
6612 NL80211_STA_INFO_TX_BITRATE))
6613 goto nla_put_failure;
6615 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
6616 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
6617 NL80211_STA_INFO_RX_BITRATE))
6618 goto nla_put_failure;
6621 PUT_SINFO(RX_PACKETS, rx_packets, u32);
6622 PUT_SINFO(TX_PACKETS, tx_packets, u32);
6623 PUT_SINFO(TX_RETRIES, tx_retries, u32);
6624 PUT_SINFO(TX_FAILED, tx_failed, u32);
6625 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
6626 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
6627 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
6628 PUT_SINFO(LOCAL_PM, local_pm, u32);
6629 PUT_SINFO(PEER_PM, peer_pm, u32);
6630 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
6631 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
6632 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8);
6634 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
6635 bss_param = nla_nest_start_noflag(msg,
6636 NL80211_STA_INFO_BSS_PARAM);
6638 goto nla_put_failure;
6640 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
6641 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
6642 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
6643 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
6644 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
6645 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
6646 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
6647 sinfo->bss_param.dtim_period) ||
6648 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
6649 sinfo->bss_param.beacon_interval))
6650 goto nla_put_failure;
6652 nla_nest_end(msg, bss_param);
6654 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
6655 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
6656 sizeof(struct nl80211_sta_flag_update),
6658 goto nla_put_failure;
6660 PUT_SINFO_U64(T_OFFSET, t_offset);
6661 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
6662 PUT_SINFO_U64(BEACON_RX, rx_beacon);
6663 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
6664 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
6665 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
6666 if (wiphy_ext_feature_isset(&rdev->wiphy,
6667 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
6668 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
6669 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
6673 #undef PUT_SINFO_U64
6675 if (sinfo->pertid) {
6676 struct nlattr *tidsattr;
6679 tidsattr = nla_nest_start_noflag(msg,
6680 NL80211_STA_INFO_TID_STATS);
6682 goto nla_put_failure;
6684 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
6685 struct cfg80211_tid_stats *tidstats;
6686 struct nlattr *tidattr;
6688 tidstats = &sinfo->pertid[tid];
6690 if (!tidstats->filled)
6693 tidattr = nla_nest_start_noflag(msg, tid + 1);
6695 goto nla_put_failure;
6697 #define PUT_TIDVAL_U64(attr, memb) do { \
6698 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
6699 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
6700 tidstats->memb, NL80211_TID_STATS_PAD)) \
6701 goto nla_put_failure; \
6704 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
6705 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
6706 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
6707 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
6709 #undef PUT_TIDVAL_U64
6710 if ((tidstats->filled &
6711 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
6712 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
6713 NL80211_TID_STATS_TXQ_STATS))
6714 goto nla_put_failure;
6716 nla_nest_end(msg, tidattr);
6719 nla_nest_end(msg, tidsattr);
6722 nla_nest_end(msg, sinfoattr);
6724 if (sinfo->assoc_req_ies_len &&
6725 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
6726 sinfo->assoc_req_ies))
6727 goto nla_put_failure;
6729 if (sinfo->assoc_resp_ies_len &&
6730 nla_put(msg, NL80211_ATTR_RESP_IE, sinfo->assoc_resp_ies_len,
6731 sinfo->assoc_resp_ies))
6732 goto nla_put_failure;
6734 if (sinfo->mlo_params_valid) {
6735 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
6736 sinfo->assoc_link_id))
6737 goto nla_put_failure;
6739 if (!is_zero_ether_addr(sinfo->mld_addr) &&
6740 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN,
6742 goto nla_put_failure;
6745 cfg80211_sinfo_release_content(sinfo);
6746 genlmsg_end(msg, hdr);
6750 cfg80211_sinfo_release_content(sinfo);
6751 genlmsg_cancel(msg, hdr);
6755 static int nl80211_dump_station(struct sk_buff *skb,
6756 struct netlink_callback *cb)
6758 struct station_info sinfo;
6759 struct cfg80211_registered_device *rdev;
6760 struct wireless_dev *wdev;
6761 u8 mac_addr[ETH_ALEN];
6762 int sta_idx = cb->args[2];
6765 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
6768 /* nl80211_prepare_wdev_dump acquired it in the successful case */
6769 __acquire(&rdev->wiphy.mtx);
6771 if (!wdev->netdev) {
6776 if (!rdev->ops->dump_station) {
6782 memset(&sinfo, 0, sizeof(sinfo));
6783 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
6790 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
6791 NETLINK_CB(cb->skb).portid,
6792 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6793 rdev, wdev->netdev, mac_addr,
6801 cb->args[2] = sta_idx;
6804 wiphy_unlock(&rdev->wiphy);
6809 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
6811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6812 struct net_device *dev = info->user_ptr[1];
6813 struct station_info sinfo;
6814 struct sk_buff *msg;
6815 u8 *mac_addr = NULL;
6818 memset(&sinfo, 0, sizeof(sinfo));
6820 if (!info->attrs[NL80211_ATTR_MAC])
6823 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6825 if (!rdev->ops->get_station)
6828 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
6832 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6834 cfg80211_sinfo_release_content(&sinfo);
6838 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
6839 info->snd_portid, info->snd_seq, 0,
6840 rdev, dev, mac_addr, &sinfo) < 0) {
6845 return genlmsg_reply(msg, info);
6848 int cfg80211_check_station_change(struct wiphy *wiphy,
6849 struct station_parameters *params,
6850 enum cfg80211_station_type statype)
6852 if (params->listen_interval != -1 &&
6853 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6856 if (params->support_p2p_ps != -1 &&
6857 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6861 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
6862 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6865 /* When you run into this, adjust the code below for the new flag */
6866 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6869 case CFG80211_STA_MESH_PEER_KERNEL:
6870 case CFG80211_STA_MESH_PEER_USER:
6872 * No ignoring the TDLS flag here -- the userspace mesh
6873 * code doesn't have the bug of including TDLS in the
6876 if (params->sta_flags_mask &
6877 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6878 BIT(NL80211_STA_FLAG_MFP) |
6879 BIT(NL80211_STA_FLAG_AUTHORIZED)))
6882 case CFG80211_STA_TDLS_PEER_SETUP:
6883 case CFG80211_STA_TDLS_PEER_ACTIVE:
6884 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6886 /* ignore since it can't change */
6887 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6890 /* disallow mesh-specific things */
6891 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
6893 if (params->local_pm)
6895 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6899 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
6900 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
6901 /* TDLS can't be set, ... */
6902 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
6905 * ... but don't bother the driver with it. This works around
6906 * a hostapd/wpa_supplicant issue -- it always includes the
6907 * TLDS_PEER flag in the mask even for AP mode.
6909 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6912 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
6913 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
6914 /* reject other things that can't change */
6915 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
6917 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
6919 if (params->link_sta_params.supported_rates)
6921 if (params->ext_capab || params->link_sta_params.ht_capa ||
6922 params->link_sta_params.vht_capa ||
6923 params->link_sta_params.he_capa ||
6924 params->link_sta_params.eht_capa)
6928 if (statype != CFG80211_STA_AP_CLIENT &&
6929 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
6935 case CFG80211_STA_AP_MLME_CLIENT:
6936 /* Use this only for authorizing/unauthorizing a station */
6937 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
6940 case CFG80211_STA_AP_CLIENT:
6941 case CFG80211_STA_AP_CLIENT_UNASSOC:
6942 /* accept only the listed bits */
6943 if (params->sta_flags_mask &
6944 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
6945 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6946 BIT(NL80211_STA_FLAG_ASSOCIATED) |
6947 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
6948 BIT(NL80211_STA_FLAG_WME) |
6949 BIT(NL80211_STA_FLAG_MFP)))
6952 /* but authenticated/associated only if driver handles it */
6953 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
6954 params->sta_flags_mask &
6955 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6956 BIT(NL80211_STA_FLAG_ASSOCIATED)))
6959 case CFG80211_STA_IBSS:
6960 case CFG80211_STA_AP_STA:
6961 /* reject any changes other than AUTHORIZED */
6962 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
6965 case CFG80211_STA_TDLS_PEER_SETUP:
6966 /* reject any changes other than AUTHORIZED or WME */
6967 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
6968 BIT(NL80211_STA_FLAG_WME)))
6970 /* force (at least) rates when authorizing */
6971 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
6972 !params->link_sta_params.supported_rates)
6975 case CFG80211_STA_TDLS_PEER_ACTIVE:
6976 /* reject any changes */
6978 case CFG80211_STA_MESH_PEER_KERNEL:
6979 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6982 case CFG80211_STA_MESH_PEER_USER:
6983 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
6984 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
6990 * Older kernel versions ignored this attribute entirely, so don't
6991 * reject attempts to update it but mark it as unused instead so the
6992 * driver won't look at the data.
6994 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
6995 statype != CFG80211_STA_TDLS_PEER_SETUP)
6996 params->link_sta_params.opmode_notif_used = false;
7000 EXPORT_SYMBOL(cfg80211_check_station_change);
7003 * Get vlan interface making sure it is running and on the right wiphy.
7005 static struct net_device *get_vlan(struct genl_info *info,
7006 struct cfg80211_registered_device *rdev)
7008 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
7009 struct net_device *v;
7015 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
7017 return ERR_PTR(-ENODEV);
7019 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
7024 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
7025 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
7026 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
7031 if (!netif_running(v)) {
7039 return ERR_PTR(ret);
7042 static int nl80211_parse_sta_wme(struct genl_info *info,
7043 struct station_parameters *params)
7045 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
7049 /* parse WME attributes if present */
7050 if (!info->attrs[NL80211_ATTR_STA_WME])
7053 nla = info->attrs[NL80211_ATTR_STA_WME];
7054 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
7055 nl80211_sta_wme_policy,
7060 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
7061 params->uapsd_queues = nla_get_u8(
7062 tb[NL80211_STA_WME_UAPSD_QUEUES]);
7063 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
7066 if (tb[NL80211_STA_WME_MAX_SP])
7067 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
7069 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
7072 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
7077 static int nl80211_parse_sta_channel_info(struct genl_info *info,
7078 struct station_parameters *params)
7080 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
7081 params->supported_channels =
7082 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
7083 params->supported_channels_len =
7084 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
7086 * Need to include at least one (first channel, number of
7087 * channels) tuple for each subband (checked in policy),
7088 * and must have proper tuples for the rest of the data as well.
7090 if (params->supported_channels_len % 2)
7094 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
7095 params->supported_oper_classes =
7096 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
7097 params->supported_oper_classes_len =
7098 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
7103 static int nl80211_set_station_tdls(struct genl_info *info,
7104 struct station_parameters *params)
7107 /* Dummy STA entry gets updated once the peer capabilities are known */
7108 if (info->attrs[NL80211_ATTR_PEER_AID])
7109 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
7110 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
7111 params->link_sta_params.ht_capa =
7112 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
7113 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
7114 params->link_sta_params.vht_capa =
7115 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
7116 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
7117 params->link_sta_params.he_capa =
7118 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7119 params->link_sta_params.he_capa_len =
7120 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7122 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
7123 params->link_sta_params.eht_capa =
7124 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7125 params->link_sta_params.eht_capa_len =
7126 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7128 if (!ieee80211_eht_capa_size_ok((const u8 *)params->link_sta_params.he_capa,
7129 (const u8 *)params->link_sta_params.eht_capa,
7130 params->link_sta_params.eht_capa_len,
7136 err = nl80211_parse_sta_channel_info(info, params);
7140 return nl80211_parse_sta_wme(info, params);
7143 static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
7144 struct sta_txpwr *txpwr,
7147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7150 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
7151 if (!rdev->ops->set_tx_power ||
7152 !wiphy_ext_feature_isset(&rdev->wiphy,
7153 NL80211_EXT_FEATURE_STA_TX_PWR))
7156 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
7157 txpwr->type = nla_get_u8(info->attrs[idx]);
7159 if (txpwr->type == NL80211_TX_POWER_LIMITED) {
7160 idx = NL80211_ATTR_STA_TX_POWER;
7162 if (info->attrs[idx])
7163 txpwr->power = nla_get_s16(info->attrs[idx]);
7176 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
7178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7179 struct net_device *dev = info->user_ptr[1];
7180 struct station_parameters params;
7184 memset(¶ms, 0, sizeof(params));
7186 if (!rdev->ops->change_station)
7190 * AID and listen_interval properties can be set only for unassociated
7191 * station. Include these parameters here and will check them in
7192 * cfg80211_check_station_change().
7194 if (info->attrs[NL80211_ATTR_STA_AID])
7195 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
7197 if (info->attrs[NL80211_ATTR_VLAN_ID])
7198 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
7200 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
7201 params.listen_interval =
7202 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
7204 params.listen_interval = -1;
7206 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
7207 params.support_p2p_ps =
7208 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
7210 params.support_p2p_ps = -1;
7212 if (!info->attrs[NL80211_ATTR_MAC])
7215 params.link_sta_params.link_id =
7216 nl80211_link_id_or_invalid(info->attrs);
7218 if (info->attrs[NL80211_ATTR_MLD_ADDR]) {
7219 /* If MLD_ADDR attribute is set then this is an MLD station
7220 * and the MLD_ADDR attribute holds the MLD address and the
7221 * MAC attribute holds for the LINK address.
7222 * In that case, the link_id is also expected to be valid.
7224 if (params.link_sta_params.link_id < 0)
7227 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
7228 params.link_sta_params.mld_mac = mac_addr;
7229 params.link_sta_params.link_mac =
7230 nla_data(info->attrs[NL80211_ATTR_MAC]);
7231 if (!is_valid_ether_addr(params.link_sta_params.link_mac))
7234 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7238 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
7239 params.link_sta_params.supported_rates =
7240 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7241 params.link_sta_params.supported_rates_len =
7242 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7245 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
7247 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
7248 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
7251 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
7253 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7254 params.ext_capab_len =
7255 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7258 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
7261 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
7262 params.plink_action =
7263 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
7265 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
7266 params.plink_state =
7267 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
7268 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
7269 params.peer_aid = nla_get_u16(
7270 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
7271 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
7274 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
7275 params.local_pm = nla_get_u32(
7276 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
7278 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
7279 params.link_sta_params.opmode_notif_used = true;
7280 params.link_sta_params.opmode_notif =
7281 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
7284 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
7285 params.link_sta_params.he_6ghz_capa =
7286 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
7288 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
7289 params.airtime_weight =
7290 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
7292 if (params.airtime_weight &&
7293 !wiphy_ext_feature_isset(&rdev->wiphy,
7294 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
7297 err = nl80211_parse_sta_txpower_setting(info,
7298 ¶ms.link_sta_params.txpwr,
7299 ¶ms.link_sta_params.txpwr_set);
7303 /* Include parameters for TDLS peer (will check later) */
7304 err = nl80211_set_station_tdls(info, ¶ms);
7308 params.vlan = get_vlan(info, rdev);
7309 if (IS_ERR(params.vlan))
7310 return PTR_ERR(params.vlan);
7312 switch (dev->ieee80211_ptr->iftype) {
7313 case NL80211_IFTYPE_AP:
7314 case NL80211_IFTYPE_AP_VLAN:
7315 case NL80211_IFTYPE_P2P_GO:
7316 case NL80211_IFTYPE_P2P_CLIENT:
7317 case NL80211_IFTYPE_STATION:
7318 case NL80211_IFTYPE_ADHOC:
7319 case NL80211_IFTYPE_MESH_POINT:
7326 /* driver will call cfg80211_check_station_change() */
7327 wdev_lock(dev->ieee80211_ptr);
7328 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
7329 wdev_unlock(dev->ieee80211_ptr);
7332 dev_put(params.vlan);
7337 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
7339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7341 struct net_device *dev = info->user_ptr[1];
7342 struct wireless_dev *wdev = dev->ieee80211_ptr;
7343 struct station_parameters params;
7344 u8 *mac_addr = NULL;
7345 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
7346 BIT(NL80211_STA_FLAG_ASSOCIATED);
7348 memset(¶ms, 0, sizeof(params));
7350 if (!rdev->ops->add_station)
7353 if (!info->attrs[NL80211_ATTR_MAC])
7356 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
7359 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
7362 if (!info->attrs[NL80211_ATTR_STA_AID] &&
7363 !info->attrs[NL80211_ATTR_PEER_AID])
7366 params.link_sta_params.link_id =
7367 nl80211_link_id_or_invalid(info->attrs);
7369 if (info->attrs[NL80211_ATTR_MLD_ADDR]) {
7370 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
7371 params.link_sta_params.mld_mac = mac_addr;
7372 params.link_sta_params.link_mac =
7373 nla_data(info->attrs[NL80211_ATTR_MAC]);
7374 if (!is_valid_ether_addr(params.link_sta_params.link_mac))
7377 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7380 params.link_sta_params.supported_rates =
7381 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7382 params.link_sta_params.supported_rates_len =
7383 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7384 params.listen_interval =
7385 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
7387 if (info->attrs[NL80211_ATTR_VLAN_ID])
7388 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
7390 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
7391 params.support_p2p_ps =
7392 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
7395 * if not specified, assume it's supported for P2P GO interface,
7396 * and is NOT supported for AP interface
7398 params.support_p2p_ps =
7399 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
7402 if (info->attrs[NL80211_ATTR_PEER_AID])
7403 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
7405 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
7407 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
7409 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
7410 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
7413 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
7415 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7416 params.ext_capab_len =
7417 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7420 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
7421 params.link_sta_params.ht_capa =
7422 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
7424 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
7425 params.link_sta_params.vht_capa =
7426 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
7428 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
7429 params.link_sta_params.he_capa =
7430 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7431 params.link_sta_params.he_capa_len =
7432 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7434 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
7435 params.link_sta_params.eht_capa =
7436 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7437 params.link_sta_params.eht_capa_len =
7438 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7440 if (!ieee80211_eht_capa_size_ok((const u8 *)params.link_sta_params.he_capa,
7441 (const u8 *)params.link_sta_params.eht_capa,
7442 params.link_sta_params.eht_capa_len,
7448 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
7449 params.link_sta_params.he_6ghz_capa =
7450 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
7452 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
7453 params.link_sta_params.opmode_notif_used = true;
7454 params.link_sta_params.opmode_notif =
7455 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
7458 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
7459 params.plink_action =
7460 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
7462 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
7463 params.airtime_weight =
7464 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
7466 if (params.airtime_weight &&
7467 !wiphy_ext_feature_isset(&rdev->wiphy,
7468 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
7471 err = nl80211_parse_sta_txpower_setting(info,
7472 ¶ms.link_sta_params.txpwr,
7473 ¶ms.link_sta_params.txpwr_set);
7477 err = nl80211_parse_sta_channel_info(info, ¶ms);
7481 err = nl80211_parse_sta_wme(info, ¶ms);
7485 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
7488 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
7489 * as userspace might just pass through the capabilities from the IEs
7490 * directly, rather than enforcing this restriction and returning an
7491 * error in this case.
7493 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
7494 params.link_sta_params.ht_capa = NULL;
7495 params.link_sta_params.vht_capa = NULL;
7497 /* HE and EHT require WME */
7498 if (params.link_sta_params.he_capa_len ||
7499 params.link_sta_params.he_6ghz_capa ||
7500 params.link_sta_params.eht_capa_len)
7504 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
7505 if (params.link_sta_params.he_6ghz_capa &&
7506 (params.link_sta_params.ht_capa || params.link_sta_params.vht_capa))
7509 /* When you run into this, adjust the code below for the new flag */
7510 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
7512 switch (dev->ieee80211_ptr->iftype) {
7513 case NL80211_IFTYPE_AP:
7514 case NL80211_IFTYPE_AP_VLAN:
7515 case NL80211_IFTYPE_P2P_GO:
7516 /* ignore WME attributes if iface/sta is not capable */
7517 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
7518 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
7519 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7521 /* TDLS peers cannot be added */
7522 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
7523 info->attrs[NL80211_ATTR_PEER_AID])
7525 /* but don't bother the driver with it */
7526 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
7528 /* allow authenticated/associated only if driver handles it */
7529 if (!(rdev->wiphy.features &
7530 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
7531 params.sta_flags_mask & auth_assoc)
7534 /* Older userspace, or userspace wanting to be compatible with
7535 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
7536 * and assoc flags in the mask, but assumes the station will be
7537 * added as associated anyway since this was the required driver
7538 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
7540 * In order to not bother drivers with this quirk in the API
7541 * set the flags in both the mask and set for new stations in
7544 if (!(params.sta_flags_mask & auth_assoc)) {
7545 params.sta_flags_mask |= auth_assoc;
7546 params.sta_flags_set |= auth_assoc;
7549 /* must be last in here for error handling */
7550 params.vlan = get_vlan(info, rdev);
7551 if (IS_ERR(params.vlan))
7552 return PTR_ERR(params.vlan);
7554 case NL80211_IFTYPE_MESH_POINT:
7555 /* ignore uAPSD data */
7556 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7558 /* associated is disallowed */
7559 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
7561 /* TDLS peers cannot be added */
7562 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
7563 info->attrs[NL80211_ATTR_PEER_AID])
7566 case NL80211_IFTYPE_STATION:
7567 case NL80211_IFTYPE_P2P_CLIENT:
7568 /* ignore uAPSD data */
7569 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7571 /* these are disallowed */
7572 if (params.sta_flags_mask &
7573 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
7574 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
7576 /* Only TDLS peers can be added */
7577 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
7579 /* Can only add if TDLS ... */
7580 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
7582 /* ... with external setup is supported */
7583 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
7586 * Older wpa_supplicant versions always mark the TDLS peer
7587 * as authorized, but it shouldn't yet be.
7589 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
7595 /* be aware of params.vlan when changing code here */
7597 wdev_lock(dev->ieee80211_ptr);
7598 if (wdev->valid_links) {
7599 if (params.link_sta_params.link_id < 0) {
7603 if (!(wdev->valid_links & BIT(params.link_sta_params.link_id))) {
7608 if (params.link_sta_params.link_id >= 0) {
7613 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
7615 wdev_unlock(dev->ieee80211_ptr);
7616 dev_put(params.vlan);
7620 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
7622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7623 struct net_device *dev = info->user_ptr[1];
7624 struct station_del_parameters params;
7627 memset(¶ms, 0, sizeof(params));
7629 if (info->attrs[NL80211_ATTR_MAC])
7630 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
7632 switch (dev->ieee80211_ptr->iftype) {
7633 case NL80211_IFTYPE_AP:
7634 case NL80211_IFTYPE_AP_VLAN:
7635 case NL80211_IFTYPE_MESH_POINT:
7636 case NL80211_IFTYPE_P2P_GO:
7637 /* always accept these */
7639 case NL80211_IFTYPE_ADHOC:
7640 /* conditionally accept */
7641 if (wiphy_ext_feature_isset(&rdev->wiphy,
7642 NL80211_EXT_FEATURE_DEL_IBSS_STA))
7649 if (!rdev->ops->del_station)
7652 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
7654 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
7655 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
7656 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
7659 /* Default to Deauthentication frame */
7660 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
7663 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
7664 params.reason_code =
7665 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7666 if (params.reason_code == 0)
7667 return -EINVAL; /* 0 is reserved */
7669 /* Default to reason code 2 */
7670 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
7673 wdev_lock(dev->ieee80211_ptr);
7674 ret = rdev_del_station(rdev, dev, ¶ms);
7675 wdev_unlock(dev->ieee80211_ptr);
7680 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
7681 int flags, struct net_device *dev,
7682 u8 *dst, u8 *next_hop,
7683 struct mpath_info *pinfo)
7686 struct nlattr *pinfoattr;
7688 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
7692 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7693 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7694 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
7695 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
7696 goto nla_put_failure;
7698 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
7700 goto nla_put_failure;
7701 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
7702 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
7704 goto nla_put_failure;
7705 if (((pinfo->filled & MPATH_INFO_SN) &&
7706 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
7707 ((pinfo->filled & MPATH_INFO_METRIC) &&
7708 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
7710 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
7711 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
7713 ((pinfo->filled & MPATH_INFO_FLAGS) &&
7714 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
7716 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
7717 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
7718 pinfo->discovery_timeout)) ||
7719 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
7720 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
7721 pinfo->discovery_retries)) ||
7722 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
7723 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
7724 pinfo->hop_count)) ||
7725 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
7726 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
7727 pinfo->path_change_count)))
7728 goto nla_put_failure;
7730 nla_nest_end(msg, pinfoattr);
7732 genlmsg_end(msg, hdr);
7736 genlmsg_cancel(msg, hdr);
7740 static int nl80211_dump_mpath(struct sk_buff *skb,
7741 struct netlink_callback *cb)
7743 struct mpath_info pinfo;
7744 struct cfg80211_registered_device *rdev;
7745 struct wireless_dev *wdev;
7747 u8 next_hop[ETH_ALEN];
7748 int path_idx = cb->args[2];
7751 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
7754 /* nl80211_prepare_wdev_dump acquired it in the successful case */
7755 __acquire(&rdev->wiphy.mtx);
7757 if (!rdev->ops->dump_mpath) {
7762 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
7768 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
7775 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
7776 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7777 wdev->netdev, dst, next_hop,
7785 cb->args[2] = path_idx;
7788 wiphy_unlock(&rdev->wiphy);
7792 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
7794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7796 struct net_device *dev = info->user_ptr[1];
7797 struct mpath_info pinfo;
7798 struct sk_buff *msg;
7800 u8 next_hop[ETH_ALEN];
7802 memset(&pinfo, 0, sizeof(pinfo));
7804 if (!info->attrs[NL80211_ATTR_MAC])
7807 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7809 if (!rdev->ops->get_mpath)
7812 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7815 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
7819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7823 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
7824 dev, dst, next_hop, &pinfo) < 0) {
7829 return genlmsg_reply(msg, info);
7832 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
7834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7835 struct net_device *dev = info->user_ptr[1];
7837 u8 *next_hop = NULL;
7839 if (!info->attrs[NL80211_ATTR_MAC])
7842 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
7845 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7846 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
7848 if (!rdev->ops->change_mpath)
7851 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7854 return rdev_change_mpath(rdev, dev, dst, next_hop);
7857 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
7859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7860 struct net_device *dev = info->user_ptr[1];
7862 u8 *next_hop = NULL;
7864 if (!info->attrs[NL80211_ATTR_MAC])
7867 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
7870 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7871 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
7873 if (!rdev->ops->add_mpath)
7876 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7879 return rdev_add_mpath(rdev, dev, dst, next_hop);
7882 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
7884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7885 struct net_device *dev = info->user_ptr[1];
7888 if (info->attrs[NL80211_ATTR_MAC])
7889 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7891 if (!rdev->ops->del_mpath)
7894 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7897 return rdev_del_mpath(rdev, dev, dst);
7900 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
7902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7904 struct net_device *dev = info->user_ptr[1];
7905 struct mpath_info pinfo;
7906 struct sk_buff *msg;
7910 memset(&pinfo, 0, sizeof(pinfo));
7912 if (!info->attrs[NL80211_ATTR_MAC])
7915 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7917 if (!rdev->ops->get_mpp)
7920 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7923 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
7927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7931 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
7932 dev, dst, mpp, &pinfo) < 0) {
7937 return genlmsg_reply(msg, info);
7940 static int nl80211_dump_mpp(struct sk_buff *skb,
7941 struct netlink_callback *cb)
7943 struct mpath_info pinfo;
7944 struct cfg80211_registered_device *rdev;
7945 struct wireless_dev *wdev;
7948 int path_idx = cb->args[2];
7951 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
7954 /* nl80211_prepare_wdev_dump acquired it in the successful case */
7955 __acquire(&rdev->wiphy.mtx);
7957 if (!rdev->ops->dump_mpp) {
7962 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
7968 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
7975 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
7976 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7977 wdev->netdev, dst, mpp,
7985 cb->args[2] = path_idx;
7988 wiphy_unlock(&rdev->wiphy);
7992 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
7994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7995 struct net_device *dev = info->user_ptr[1];
7996 struct wireless_dev *wdev = dev->ieee80211_ptr;
7997 struct bss_parameters params;
8000 memset(¶ms, 0, sizeof(params));
8001 params.link_id = nl80211_link_id_or_invalid(info->attrs);
8002 /* default to not changing parameters */
8003 params.use_cts_prot = -1;
8004 params.use_short_preamble = -1;
8005 params.use_short_slot_time = -1;
8006 params.ap_isolate = -1;
8007 params.ht_opmode = -1;
8008 params.p2p_ctwindow = -1;
8009 params.p2p_opp_ps = -1;
8011 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
8012 params.use_cts_prot =
8013 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
8014 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
8015 params.use_short_preamble =
8016 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
8017 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
8018 params.use_short_slot_time =
8019 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
8020 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8021 params.basic_rates =
8022 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8023 params.basic_rates_len =
8024 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8026 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
8027 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
8028 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
8030 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
8032 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
8033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
8035 params.p2p_ctwindow =
8036 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
8037 if (params.p2p_ctwindow != 0 &&
8038 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
8042 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
8045 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
8047 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
8048 params.p2p_opp_ps = tmp;
8049 if (params.p2p_opp_ps &&
8050 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
8054 if (!rdev->ops->change_bss)
8057 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
8058 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
8062 err = rdev_change_bss(rdev, dev, ¶ms);
8068 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
8072 enum nl80211_user_reg_hint_type user_reg_hint_type;
8076 * You should only get this when cfg80211 hasn't yet initialized
8077 * completely when built-in to the kernel right between the time
8078 * window between nl80211_init() and regulatory_init(), if that is
8081 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
8082 return -EINPROGRESS;
8084 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
8085 user_reg_hint_type =
8086 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
8088 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
8090 switch (user_reg_hint_type) {
8091 case NL80211_USER_REG_HINT_USER:
8092 case NL80211_USER_REG_HINT_CELL_BASE:
8093 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
8096 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
8097 return regulatory_hint_user(data, user_reg_hint_type);
8098 case NL80211_USER_REG_HINT_INDOOR:
8099 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8100 owner_nlportid = info->snd_portid;
8101 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
8107 return regulatory_hint_indoor(is_indoor, owner_nlportid);
8113 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
8115 return reg_reload_regdb();
8118 static int nl80211_get_mesh_config(struct sk_buff *skb,
8119 struct genl_info *info)
8121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8122 struct net_device *dev = info->user_ptr[1];
8123 struct wireless_dev *wdev = dev->ieee80211_ptr;
8124 struct mesh_config cur_params;
8127 struct nlattr *pinfoattr;
8128 struct sk_buff *msg;
8130 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
8133 if (!rdev->ops->get_mesh_config)
8137 /* If not connected, get default parameters */
8138 if (!wdev->u.mesh.id_len)
8139 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
8141 err = rdev_get_mesh_config(rdev, dev, &cur_params);
8147 /* Draw up a netlink message to send back */
8148 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8151 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8152 NL80211_CMD_GET_MESH_CONFIG);
8155 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
8157 goto nla_put_failure;
8158 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8159 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
8160 cur_params.dot11MeshRetryTimeout) ||
8161 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
8162 cur_params.dot11MeshConfirmTimeout) ||
8163 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
8164 cur_params.dot11MeshHoldingTimeout) ||
8165 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
8166 cur_params.dot11MeshMaxPeerLinks) ||
8167 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
8168 cur_params.dot11MeshMaxRetries) ||
8169 nla_put_u8(msg, NL80211_MESHCONF_TTL,
8170 cur_params.dot11MeshTTL) ||
8171 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
8172 cur_params.element_ttl) ||
8173 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
8174 cur_params.auto_open_plinks) ||
8175 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
8176 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
8177 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
8178 cur_params.dot11MeshHWMPmaxPREQretries) ||
8179 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
8180 cur_params.path_refresh_time) ||
8181 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
8182 cur_params.min_discovery_timeout) ||
8183 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
8184 cur_params.dot11MeshHWMPactivePathTimeout) ||
8185 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
8186 cur_params.dot11MeshHWMPpreqMinInterval) ||
8187 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
8188 cur_params.dot11MeshHWMPperrMinInterval) ||
8189 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
8190 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
8191 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
8192 cur_params.dot11MeshHWMPRootMode) ||
8193 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
8194 cur_params.dot11MeshHWMPRannInterval) ||
8195 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
8196 cur_params.dot11MeshGateAnnouncementProtocol) ||
8197 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
8198 cur_params.dot11MeshForwarding) ||
8199 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
8200 cur_params.rssi_threshold) ||
8201 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
8202 cur_params.ht_opmode) ||
8203 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
8204 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
8205 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
8206 cur_params.dot11MeshHWMProotInterval) ||
8207 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
8208 cur_params.dot11MeshHWMPconfirmationInterval) ||
8209 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
8210 cur_params.power_mode) ||
8211 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
8212 cur_params.dot11MeshAwakeWindowDuration) ||
8213 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
8214 cur_params.plink_timeout) ||
8215 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
8216 cur_params.dot11MeshConnectedToMeshGate) ||
8217 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN,
8218 cur_params.dot11MeshNolearn) ||
8219 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS,
8220 cur_params.dot11MeshConnectedToAuthServer))
8221 goto nla_put_failure;
8222 nla_nest_end(msg, pinfoattr);
8223 genlmsg_end(msg, hdr);
8224 return genlmsg_reply(msg, info);
8232 static const struct nla_policy
8233 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
8234 [NL80211_MESHCONF_RETRY_TIMEOUT] =
8235 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8236 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
8237 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8238 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
8239 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8240 [NL80211_MESHCONF_MAX_PEER_LINKS] =
8241 NLA_POLICY_RANGE(NLA_U16, 0, 255),
8242 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
8243 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
8244 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
8245 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
8246 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
8247 NLA_POLICY_RANGE(NLA_U32, 1, 255),
8248 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
8249 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
8250 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
8251 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
8252 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
8253 NLA_POLICY_MIN(NLA_U16, 1),
8254 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
8255 NLA_POLICY_MIN(NLA_U16, 1),
8256 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
8257 NLA_POLICY_MIN(NLA_U16, 1),
8258 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
8259 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
8260 NLA_POLICY_MIN(NLA_U16, 1),
8261 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
8262 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
8263 [NL80211_MESHCONF_RSSI_THRESHOLD] =
8264 NLA_POLICY_RANGE(NLA_S32, -255, 0),
8265 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
8266 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
8267 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
8268 NLA_POLICY_MIN(NLA_U16, 1),
8269 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
8270 NLA_POLICY_MIN(NLA_U16, 1),
8271 [NL80211_MESHCONF_POWER_MODE] =
8272 NLA_POLICY_RANGE(NLA_U32,
8273 NL80211_MESH_POWER_ACTIVE,
8274 NL80211_MESH_POWER_MAX),
8275 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
8276 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
8277 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8278 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8279 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8282 static const struct nla_policy
8283 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
8284 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
8285 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
8286 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
8287 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
8288 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
8289 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
8290 [NL80211_MESH_SETUP_IE] =
8291 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
8292 IEEE80211_MAX_DATA_LEN),
8293 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
8296 static int nl80211_parse_mesh_config(struct genl_info *info,
8297 struct mesh_config *cfg,
8300 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
8304 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
8307 cfg->param = fn(tb[attr]); \
8308 mask |= BIT((attr) - 1); \
8312 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
8314 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
8317 /* This makes sure that there aren't more than 32 mesh config
8318 * parameters (otherwise our bitfield scheme would not work.) */
8319 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
8321 /* Fill in the params struct */
8322 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
8323 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
8324 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
8325 NL80211_MESHCONF_CONFIRM_TIMEOUT,
8327 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
8328 NL80211_MESHCONF_HOLDING_TIMEOUT,
8330 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
8331 NL80211_MESHCONF_MAX_PEER_LINKS,
8333 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
8334 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
8335 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
8336 NL80211_MESHCONF_TTL, nla_get_u8);
8337 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
8338 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
8339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
8340 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
8342 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
8344 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
8346 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
8347 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
8349 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
8350 NL80211_MESHCONF_PATH_REFRESH_TIME,
8352 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
8353 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
8355 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
8356 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
8358 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
8360 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
8362 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
8363 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
8364 cfg->dot11MeshHWMPactivePathTimeout > 65535))
8366 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
8367 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
8369 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
8370 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
8372 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
8373 dot11MeshHWMPnetDiameterTraversalTime, mask,
8374 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
8376 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
8377 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
8378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
8379 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
8381 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
8382 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
8384 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
8385 NL80211_MESHCONF_FORWARDING, nla_get_u8);
8386 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
8387 NL80211_MESHCONF_RSSI_THRESHOLD,
8389 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
8390 NL80211_MESHCONF_CONNECTED_TO_GATE,
8392 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask,
8393 NL80211_MESHCONF_CONNECTED_TO_AS,
8396 * Check HT operation mode based on
8397 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
8399 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
8400 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
8402 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
8403 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
8404 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
8407 /* NON_HT_STA bit is reserved, but some programs set it */
8408 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
8410 cfg->ht_opmode = ht_opmode;
8411 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
8413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
8414 dot11MeshHWMPactivePathToRootTimeout, mask,
8415 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
8417 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
8418 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
8419 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
8421 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
8422 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
8424 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
8426 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
8428 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
8429 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
8430 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
8431 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
8432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
8433 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
8434 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask,
8435 NL80211_MESHCONF_NOLEARN, nla_get_u8);
8441 #undef FILL_IN_MESH_PARAM_IF_SET
8444 static int nl80211_parse_mesh_setup(struct genl_info *info,
8445 struct mesh_setup *setup)
8447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8448 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
8450 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
8452 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack))
8455 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
8456 setup->sync_method =
8457 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
8458 IEEE80211_SYNC_METHOD_VENDOR :
8459 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
8461 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
8462 setup->path_sel_proto =
8463 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
8464 IEEE80211_PATH_PROTOCOL_VENDOR :
8465 IEEE80211_PATH_PROTOCOL_HWMP;
8467 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
8468 setup->path_metric =
8469 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
8470 IEEE80211_PATH_METRIC_VENDOR :
8471 IEEE80211_PATH_METRIC_AIRTIME;
8473 if (tb[NL80211_MESH_SETUP_IE]) {
8474 struct nlattr *ieattr =
8475 tb[NL80211_MESH_SETUP_IE];
8476 setup->ie = nla_data(ieattr);
8477 setup->ie_len = nla_len(ieattr);
8479 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
8480 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
8482 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
8483 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
8484 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
8485 if (setup->is_secure)
8486 setup->user_mpm = true;
8488 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
8489 if (!setup->user_mpm)
8492 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
8498 static int nl80211_update_mesh_config(struct sk_buff *skb,
8499 struct genl_info *info)
8501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8502 struct net_device *dev = info->user_ptr[1];
8503 struct wireless_dev *wdev = dev->ieee80211_ptr;
8504 struct mesh_config cfg = {};
8508 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
8511 if (!rdev->ops->update_mesh_config)
8514 err = nl80211_parse_mesh_config(info, &cfg, &mask);
8519 if (!wdev->u.mesh.id_len)
8523 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
8530 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
8531 struct sk_buff *msg)
8533 struct nlattr *nl_reg_rules;
8536 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
8537 (regdom->dfs_region &&
8538 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
8539 goto nla_put_failure;
8541 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
8543 goto nla_put_failure;
8545 for (i = 0; i < regdom->n_reg_rules; i++) {
8546 struct nlattr *nl_reg_rule;
8547 const struct ieee80211_reg_rule *reg_rule;
8548 const struct ieee80211_freq_range *freq_range;
8549 const struct ieee80211_power_rule *power_rule;
8550 unsigned int max_bandwidth_khz;
8552 reg_rule = ®dom->reg_rules[i];
8553 freq_range = ®_rule->freq_range;
8554 power_rule = ®_rule->power_rule;
8556 nl_reg_rule = nla_nest_start_noflag(msg, i);
8558 goto nla_put_failure;
8560 max_bandwidth_khz = freq_range->max_bandwidth_khz;
8561 if (!max_bandwidth_khz)
8562 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
8565 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
8567 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
8568 freq_range->start_freq_khz) ||
8569 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
8570 freq_range->end_freq_khz) ||
8571 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
8572 max_bandwidth_khz) ||
8573 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
8574 power_rule->max_antenna_gain) ||
8575 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
8576 power_rule->max_eirp) ||
8577 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
8578 reg_rule->dfs_cac_ms))
8579 goto nla_put_failure;
8581 nla_nest_end(msg, nl_reg_rule);
8584 nla_nest_end(msg, nl_reg_rules);
8591 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
8593 const struct ieee80211_regdomain *regdom = NULL;
8594 struct cfg80211_registered_device *rdev;
8595 struct wiphy *wiphy = NULL;
8596 struct sk_buff *msg;
8597 int err = -EMSGSIZE;
8600 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8604 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8605 NL80211_CMD_GET_REG);
8611 if (info->attrs[NL80211_ATTR_WIPHY]) {
8614 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
8616 err = PTR_ERR(rdev);
8617 goto nla_put_failure;
8620 wiphy = &rdev->wiphy;
8621 self_managed = wiphy->regulatory_flags &
8622 REGULATORY_WIPHY_SELF_MANAGED;
8626 regdom = get_wiphy_regdom(wiphy);
8628 /* a self-managed-reg device must have a private regdom */
8629 if (WARN_ON(!regdom && self_managed)) {
8631 goto nla_put_failure_rcu;
8635 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8636 goto nla_put_failure_rcu;
8641 if (!wiphy && reg_last_request_cell_base() &&
8642 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
8643 NL80211_USER_REG_HINT_CELL_BASE))
8644 goto nla_put_failure_rcu;
8647 regdom = rcu_dereference(cfg80211_regdomain);
8649 if (nl80211_put_regdom(regdom, msg))
8650 goto nla_put_failure_rcu;
8654 genlmsg_end(msg, hdr);
8656 return genlmsg_reply(msg, info);
8658 nla_put_failure_rcu:
8667 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
8668 u32 seq, int flags, struct wiphy *wiphy,
8669 const struct ieee80211_regdomain *regdom)
8671 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
8672 NL80211_CMD_GET_REG);
8677 genl_dump_check_consistent(cb, hdr);
8679 if (nl80211_put_regdom(regdom, msg))
8680 goto nla_put_failure;
8682 if (!wiphy && reg_last_request_cell_base() &&
8683 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
8684 NL80211_USER_REG_HINT_CELL_BASE))
8685 goto nla_put_failure;
8688 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8689 goto nla_put_failure;
8691 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
8692 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
8693 goto nla_put_failure;
8695 genlmsg_end(msg, hdr);
8699 genlmsg_cancel(msg, hdr);
8703 static int nl80211_get_reg_dump(struct sk_buff *skb,
8704 struct netlink_callback *cb)
8706 const struct ieee80211_regdomain *regdom = NULL;
8707 struct cfg80211_registered_device *rdev;
8708 int err, reg_idx, start = cb->args[2];
8712 if (cfg80211_regdomain && start == 0) {
8713 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
8715 rcu_dereference(cfg80211_regdomain));
8720 /* the global regdom is idx 0 */
8722 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
8723 regdom = get_wiphy_regdom(&rdev->wiphy);
8727 if (++reg_idx <= start)
8730 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
8731 NLM_F_MULTI, &rdev->wiphy, regdom);
8738 cb->args[2] = reg_idx;
8745 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
8746 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
8747 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
8748 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
8749 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
8750 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
8751 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
8752 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
8753 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
8756 static int parse_reg_rule(struct nlattr *tb[],
8757 struct ieee80211_reg_rule *reg_rule)
8759 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
8760 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
8762 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
8764 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
8766 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
8768 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
8770 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
8773 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
8775 freq_range->start_freq_khz =
8776 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
8777 freq_range->end_freq_khz =
8778 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
8779 freq_range->max_bandwidth_khz =
8780 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
8782 power_rule->max_eirp =
8783 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
8785 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
8786 power_rule->max_antenna_gain =
8787 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
8789 if (tb[NL80211_ATTR_DFS_CAC_TIME])
8790 reg_rule->dfs_cac_ms =
8791 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
8796 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
8798 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
8799 struct nlattr *nl_reg_rule;
8801 int rem_reg_rules, r;
8802 u32 num_rules = 0, rule_idx = 0;
8803 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
8804 struct ieee80211_regdomain *rd;
8806 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
8809 if (!info->attrs[NL80211_ATTR_REG_RULES])
8812 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
8814 if (info->attrs[NL80211_ATTR_DFS_REGION])
8815 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
8817 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
8820 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
8825 if (!reg_is_valid_request(alpha2)) {
8830 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
8836 rd->n_reg_rules = num_rules;
8837 rd->alpha2[0] = alpha2[0];
8838 rd->alpha2[1] = alpha2[1];
8841 * Disable DFS master mode if the DFS region was
8842 * not supported or known on this kernel.
8844 if (reg_supported_dfs_region(dfs_region))
8845 rd->dfs_region = dfs_region;
8847 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
8849 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
8850 nl_reg_rule, reg_rule_policy,
8854 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
8860 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
8866 r = set_regdom(rd, REGD_SOURCE_CRDA);
8867 /* set_regdom takes ownership of rd */
8875 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
8877 static int validate_scan_freqs(struct nlattr *freqs)
8879 struct nlattr *attr1, *attr2;
8880 int n_channels = 0, tmp1, tmp2;
8882 nla_for_each_nested(attr1, freqs, tmp1)
8883 if (nla_len(attr1) != sizeof(u32))
8886 nla_for_each_nested(attr1, freqs, tmp1) {
8889 * Some hardware has a limited channel list for
8890 * scanning, and it is pretty much nonsensical
8891 * to scan for a channel twice, so disallow that
8892 * and don't require drivers to check that the
8893 * channel list they get isn't longer than what
8894 * they can scan, as long as they can scan all
8895 * the channels they registered at once.
8897 nla_for_each_nested(attr2, freqs, tmp2)
8898 if (attr1 != attr2 &&
8899 nla_get_u32(attr1) == nla_get_u32(attr2))
8906 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
8908 return b < NUM_NL80211_BANDS && wiphy->bands[b];
8911 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
8912 struct cfg80211_bss_selection *bss_select)
8914 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
8915 struct nlattr *nest;
8920 /* only process one nested attribute */
8921 nest = nla_data(nla);
8922 if (!nla_ok(nest, nla_len(nest)))
8925 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
8926 nest, nl80211_bss_select_policy,
8931 /* only one attribute may be given */
8932 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
8940 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
8942 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
8943 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
8945 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
8946 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
8947 bss_select->param.band_pref =
8948 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
8949 if (!is_band_valid(wiphy, bss_select->param.band_pref))
8953 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
8954 struct nl80211_bss_select_rssi_adjust *adj_param;
8956 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
8957 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
8958 bss_select->param.adjust.band = adj_param->band;
8959 bss_select->param.adjust.delta = adj_param->delta;
8960 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
8964 /* user-space did not provide behaviour attribute */
8965 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
8968 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
8974 int nl80211_parse_random_mac(struct nlattr **attrs,
8975 u8 *mac_addr, u8 *mac_addr_mask)
8979 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
8980 eth_zero_addr(mac_addr);
8981 eth_zero_addr(mac_addr_mask);
8983 mac_addr_mask[0] = 0x3;
8988 /* need both or none */
8989 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
8992 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
8993 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
8995 /* don't allow or configure an mcast address */
8996 if (!is_multicast_ether_addr(mac_addr_mask) ||
8997 is_multicast_ether_addr(mac_addr))
9001 * allow users to pass a MAC address that has bits set outside
9002 * of the mask, but don't bother drivers with having to deal
9005 for (i = 0; i < ETH_ALEN; i++)
9006 mac_addr[i] &= mac_addr_mask[i];
9011 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev,
9012 struct ieee80211_channel *chan)
9014 unsigned int link_id;
9017 ASSERT_WDEV_LOCK(wdev);
9019 if (!cfg80211_beaconing_iface_active(wdev))
9023 * FIXME: check if we have a free HW resource/link for chan
9025 * This, as well as the FIXME below, requires knowing the link
9026 * capabilities of the hardware.
9029 /* we cannot leave radar channels */
9030 for_each_valid_link(wdev, link_id) {
9031 struct cfg80211_chan_def *chandef;
9033 chandef = wdev_chandef(wdev, link_id);
9034 if (!chandef || !chandef->chan)
9038 * FIXME: don't require all_ok, but rather check only the
9039 * correct HW resource/link onto which 'chan' falls,
9040 * as only that link leaves the channel for doing
9041 * the off-channel operation.
9044 if (chandef->chan->flags & IEEE80211_CHAN_RADAR)
9051 return regulatory_pre_cac_allowed(wdev->wiphy);
9054 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
9055 enum nl80211_ext_feature_index feat)
9057 if (!(flags & flag))
9059 if (wiphy_ext_feature_isset(wiphy, feat))
9065 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
9066 void *request, struct nlattr **attrs,
9069 u8 *mac_addr, *mac_addr_mask;
9071 enum nl80211_feature_flags randomness_flag;
9073 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
9076 if (is_sched_scan) {
9077 struct cfg80211_sched_scan_request *req = request;
9079 randomness_flag = wdev ?
9080 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
9081 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
9082 flags = &req->flags;
9083 mac_addr = req->mac_addr;
9084 mac_addr_mask = req->mac_addr_mask;
9086 struct cfg80211_scan_request *req = request;
9088 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
9089 flags = &req->flags;
9090 mac_addr = req->mac_addr;
9091 mac_addr_mask = req->mac_addr_mask;
9094 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
9096 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
9097 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
9098 !nl80211_check_scan_feat(wiphy, *flags,
9099 NL80211_SCAN_FLAG_LOW_SPAN,
9100 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
9101 !nl80211_check_scan_feat(wiphy, *flags,
9102 NL80211_SCAN_FLAG_LOW_POWER,
9103 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
9104 !nl80211_check_scan_feat(wiphy, *flags,
9105 NL80211_SCAN_FLAG_HIGH_ACCURACY,
9106 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
9107 !nl80211_check_scan_feat(wiphy, *flags,
9108 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
9109 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
9110 !nl80211_check_scan_feat(wiphy, *flags,
9111 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
9112 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
9113 !nl80211_check_scan_feat(wiphy, *flags,
9114 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
9115 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
9116 !nl80211_check_scan_feat(wiphy, *flags,
9117 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
9118 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
9119 !nl80211_check_scan_feat(wiphy, *flags,
9120 NL80211_SCAN_FLAG_RANDOM_SN,
9121 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
9122 !nl80211_check_scan_feat(wiphy, *flags,
9123 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
9124 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
9127 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
9130 if (!(wiphy->features & randomness_flag) ||
9131 (wdev && wdev->connected))
9134 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
9142 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
9144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9145 struct wireless_dev *wdev = info->user_ptr[1];
9146 struct cfg80211_scan_request *request;
9147 struct nlattr *scan_freqs = NULL;
9148 bool scan_freqs_khz = false;
9149 struct nlattr *attr;
9150 struct wiphy *wiphy;
9151 int err, tmp, n_ssids = 0, n_channels, i;
9152 size_t ie_len, size;
9154 wiphy = &rdev->wiphy;
9156 if (wdev->iftype == NL80211_IFTYPE_NAN)
9159 if (!rdev->ops->scan)
9162 if (rdev->scan_req || rdev->scan_msg)
9165 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) {
9166 if (!wiphy_ext_feature_isset(wiphy,
9167 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ))
9169 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ];
9170 scan_freqs_khz = true;
9171 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES])
9172 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES];
9175 n_channels = validate_scan_freqs(scan_freqs);
9179 n_channels = ieee80211_get_num_supported_channels(wiphy);
9182 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
9183 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
9186 if (n_ssids > wiphy->max_scan_ssids)
9189 if (info->attrs[NL80211_ATTR_IE])
9190 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9194 if (ie_len > wiphy->max_scan_ie_len)
9197 size = struct_size(request, channels, n_channels);
9198 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids));
9199 size = size_add(size, ie_len);
9200 request = kzalloc(size, GFP_KERNEL);
9205 request->ssids = (void *)&request->channels[n_channels];
9206 request->n_ssids = n_ssids;
9209 request->ie = (void *)(request->ssids + n_ssids);
9211 request->ie = (void *)(request->channels + n_channels);
9216 /* user specified, bail out if channel not found */
9217 nla_for_each_nested(attr, scan_freqs, tmp) {
9218 struct ieee80211_channel *chan;
9219 int freq = nla_get_u32(attr);
9221 if (!scan_freqs_khz)
9222 freq = MHZ_TO_KHZ(freq);
9224 chan = ieee80211_get_channel_khz(wiphy, freq);
9230 /* ignore disabled channels */
9231 if (chan->flags & IEEE80211_CHAN_DISABLED)
9234 request->channels[i] = chan;
9238 enum nl80211_band band;
9241 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9244 if (!wiphy->bands[band])
9246 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
9247 struct ieee80211_channel *chan;
9249 chan = &wiphy->bands[band]->channels[j];
9251 if (chan->flags & IEEE80211_CHAN_DISABLED)
9254 request->channels[i] = chan;
9265 request->n_channels = i;
9268 for (i = 0; i < request->n_channels; i++) {
9269 struct ieee80211_channel *chan = request->channels[i];
9271 /* if we can go off-channel to the target channel we're good */
9272 if (cfg80211_off_channel_oper_allowed(wdev, chan))
9275 if (!cfg80211_wdev_on_sub_chan(wdev, chan, true)) {
9285 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
9286 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
9290 request->ssids[i].ssid_len = nla_len(attr);
9291 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
9296 if (info->attrs[NL80211_ATTR_IE]) {
9297 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9298 memcpy((void *)request->ie,
9299 nla_data(info->attrs[NL80211_ATTR_IE]),
9303 for (i = 0; i < NUM_NL80211_BANDS; i++)
9304 if (wiphy->bands[i])
9306 (1 << wiphy->bands[i]->n_bitrates) - 1;
9308 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
9309 nla_for_each_nested(attr,
9310 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
9312 enum nl80211_band band = nla_type(attr);
9314 if (band < 0 || band >= NUM_NL80211_BANDS) {
9319 if (!wiphy->bands[band])
9322 err = ieee80211_get_ratemask(wiphy->bands[band],
9325 &request->rates[band]);
9331 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
9333 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
9334 request->duration_mandatory =
9335 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
9338 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
9344 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
9346 /* Initial implementation used NL80211_ATTR_MAC to set the specific
9347 * BSSID to scan for. This was problematic because that same attribute
9348 * was already used for another purpose (local random MAC address). The
9349 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
9350 * compatibility with older userspace components, also use the
9351 * NL80211_ATTR_MAC value here if it can be determined to be used for
9352 * the specific BSSID use case instead of the random MAC address
9353 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
9355 if (info->attrs[NL80211_ATTR_BSSID])
9356 memcpy(request->bssid,
9357 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
9358 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
9359 info->attrs[NL80211_ATTR_MAC])
9360 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
9363 eth_broadcast_addr(request->bssid);
9365 request->wdev = wdev;
9366 request->wiphy = &rdev->wiphy;
9367 request->scan_start = jiffies;
9369 rdev->scan_req = request;
9370 err = cfg80211_scan(rdev);
9375 nl80211_send_scan_start(rdev, wdev);
9376 dev_hold(wdev->netdev);
9381 rdev->scan_req = NULL;
9387 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
9389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9390 struct wireless_dev *wdev = info->user_ptr[1];
9392 if (!rdev->ops->abort_scan)
9398 if (!rdev->scan_req)
9401 rdev_abort_scan(rdev, wdev);
9406 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
9407 struct cfg80211_sched_scan_request *request,
9408 struct nlattr **attrs)
9410 int tmp, err, i = 0;
9411 struct nlattr *attr;
9413 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
9417 * If scan plans are not specified,
9418 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
9419 * case one scan plan will be set with the specified scan
9420 * interval and infinite number of iterations.
9422 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
9426 request->scan_plans[0].interval =
9427 DIV_ROUND_UP(interval, MSEC_PER_SEC);
9428 if (!request->scan_plans[0].interval)
9431 if (request->scan_plans[0].interval >
9432 wiphy->max_sched_scan_plan_interval)
9433 request->scan_plans[0].interval =
9434 wiphy->max_sched_scan_plan_interval;
9439 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
9440 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
9442 if (WARN_ON(i >= n_plans))
9445 err = nla_parse_nested_deprecated(plan,
9446 NL80211_SCHED_SCAN_PLAN_MAX,
9447 attr, nl80211_plan_policy,
9452 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
9455 request->scan_plans[i].interval =
9456 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
9457 if (!request->scan_plans[i].interval ||
9458 request->scan_plans[i].interval >
9459 wiphy->max_sched_scan_plan_interval)
9462 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
9463 request->scan_plans[i].iterations =
9464 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
9465 if (!request->scan_plans[i].iterations ||
9466 (request->scan_plans[i].iterations >
9467 wiphy->max_sched_scan_plan_iterations))
9469 } else if (i < n_plans - 1) {
9471 * All scan plans but the last one must specify
9472 * a finite number of iterations
9481 * The last scan plan must not specify the number of
9482 * iterations, it is supposed to run infinitely
9484 if (request->scan_plans[n_plans - 1].iterations)
9491 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
9492 struct cfg80211_match_set *match_sets,
9493 struct nlattr *tb_band_rssi,
9496 struct nlattr *attr;
9497 int i, tmp, ret = 0;
9499 if (!wiphy_ext_feature_isset(wiphy,
9500 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
9504 for (i = 0; i < NUM_NL80211_BANDS; i++)
9505 match_sets->per_band_rssi_thold[i] =
9506 NL80211_SCAN_RSSI_THOLD_OFF;
9510 for (i = 0; i < NUM_NL80211_BANDS; i++)
9511 match_sets->per_band_rssi_thold[i] = rssi_thold;
9513 nla_for_each_nested(attr, tb_band_rssi, tmp) {
9514 enum nl80211_band band = nla_type(attr);
9516 if (band < 0 || band >= NUM_NL80211_BANDS)
9519 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
9525 static struct cfg80211_sched_scan_request *
9526 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
9527 struct nlattr **attrs, int max_match_sets)
9529 struct cfg80211_sched_scan_request *request;
9530 struct nlattr *attr;
9531 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
9532 enum nl80211_band band;
9533 size_t ie_len, size;
9534 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
9535 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
9537 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
9538 n_channels = validate_scan_freqs(
9539 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
9541 return ERR_PTR(-EINVAL);
9543 n_channels = ieee80211_get_num_supported_channels(wiphy);
9546 if (attrs[NL80211_ATTR_SCAN_SSIDS])
9547 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
9551 if (n_ssids > wiphy->max_sched_scan_ssids)
9552 return ERR_PTR(-EINVAL);
9555 * First, count the number of 'real' matchsets. Due to an issue with
9556 * the old implementation, matchsets containing only the RSSI attribute
9557 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
9558 * RSSI for all matchsets, rather than their own matchset for reporting
9559 * all APs with a strong RSSI. This is needed to be compatible with
9560 * older userspace that treated a matchset with only the RSSI as the
9561 * global RSSI for all other matchsets - if there are other matchsets.
9563 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
9564 nla_for_each_nested(attr,
9565 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
9567 struct nlattr *rssi;
9569 err = nla_parse_nested_deprecated(tb,
9570 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
9572 nl80211_match_policy,
9575 return ERR_PTR(err);
9577 /* SSID and BSSID are mutually exclusive */
9578 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
9579 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
9580 return ERR_PTR(-EINVAL);
9582 /* add other standalone attributes here */
9583 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
9584 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
9588 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
9590 default_match_rssi = nla_get_s32(rssi);
9594 /* However, if there's no other matchset, add the RSSI one */
9595 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
9598 if (n_match_sets > max_match_sets)
9599 return ERR_PTR(-EINVAL);
9601 if (attrs[NL80211_ATTR_IE])
9602 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
9606 if (ie_len > wiphy->max_sched_scan_ie_len)
9607 return ERR_PTR(-EINVAL);
9609 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
9611 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
9612 * each scan plan already specifies its own interval
9614 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
9615 return ERR_PTR(-EINVAL);
9617 nla_for_each_nested(attr,
9618 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
9622 * The scan interval attribute is kept for backward
9623 * compatibility. If no scan plans are specified and sched scan
9624 * interval is specified, one scan plan will be set with this
9625 * scan interval and infinite number of iterations.
9627 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
9628 return ERR_PTR(-EINVAL);
9633 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
9634 return ERR_PTR(-EINVAL);
9636 if (!wiphy_ext_feature_isset(
9637 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
9638 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
9639 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
9640 return ERR_PTR(-EINVAL);
9642 size = struct_size(request, channels, n_channels);
9643 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids));
9644 size = size_add(size, array_size(sizeof(*request->match_sets),
9646 size = size_add(size, array_size(sizeof(*request->scan_plans),
9648 size = size_add(size, ie_len);
9649 request = kzalloc(size, GFP_KERNEL);
9651 return ERR_PTR(-ENOMEM);
9654 request->ssids = (void *)&request->channels[n_channels];
9655 request->n_ssids = n_ssids;
9658 request->ie = (void *)(request->ssids + n_ssids);
9660 request->ie = (void *)(request->channels + n_channels);
9665 request->match_sets = (void *)(request->ie + ie_len);
9667 request->match_sets =
9668 (void *)(request->ssids + n_ssids);
9670 request->match_sets =
9671 (void *)(request->channels + n_channels);
9673 request->n_match_sets = n_match_sets;
9676 request->scan_plans = (void *)(request->match_sets +
9678 else if (request->ie)
9679 request->scan_plans = (void *)(request->ie + ie_len);
9681 request->scan_plans = (void *)(request->ssids + n_ssids);
9683 request->scan_plans = (void *)(request->channels + n_channels);
9685 request->n_scan_plans = n_plans;
9688 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
9689 /* user specified, bail out if channel not found */
9690 nla_for_each_nested(attr,
9691 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
9693 struct ieee80211_channel *chan;
9695 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
9702 /* ignore disabled channels */
9703 if (chan->flags & IEEE80211_CHAN_DISABLED)
9706 request->channels[i] = chan;
9711 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9714 if (!wiphy->bands[band])
9716 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
9717 struct ieee80211_channel *chan;
9719 chan = &wiphy->bands[band]->channels[j];
9721 if (chan->flags & IEEE80211_CHAN_DISABLED)
9724 request->channels[i] = chan;
9735 request->n_channels = i;
9739 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
9741 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
9745 request->ssids[i].ssid_len = nla_len(attr);
9746 memcpy(request->ssids[i].ssid, nla_data(attr),
9753 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
9754 nla_for_each_nested(attr,
9755 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
9757 struct nlattr *ssid, *bssid, *rssi;
9759 err = nla_parse_nested_deprecated(tb,
9760 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
9762 nl80211_match_policy,
9766 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
9767 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
9769 if (!ssid && !bssid) {
9774 if (WARN_ON(i >= n_match_sets)) {
9775 /* this indicates a programming error,
9776 * the loop above should have verified
9784 memcpy(request->match_sets[i].ssid.ssid,
9785 nla_data(ssid), nla_len(ssid));
9786 request->match_sets[i].ssid.ssid_len =
9790 memcpy(request->match_sets[i].bssid,
9791 nla_data(bssid), ETH_ALEN);
9793 /* special attribute - old implementation w/a */
9794 request->match_sets[i].rssi_thold = default_match_rssi;
9795 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
9797 request->match_sets[i].rssi_thold =
9800 /* Parse per band RSSI attribute */
9801 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
9802 &request->match_sets[i],
9803 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
9804 request->match_sets[i].rssi_thold);
9811 /* there was no other matchset, so the RSSI one is alone */
9812 if (i == 0 && n_match_sets)
9813 request->match_sets[0].rssi_thold = default_match_rssi;
9815 request->min_rssi_thold = INT_MAX;
9816 for (i = 0; i < n_match_sets; i++)
9817 request->min_rssi_thold =
9818 min(request->match_sets[i].rssi_thold,
9819 request->min_rssi_thold);
9821 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
9825 request->ie_len = ie_len;
9826 memcpy((void *)request->ie,
9827 nla_data(attrs[NL80211_ATTR_IE]),
9831 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
9835 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
9837 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
9839 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
9840 request->relative_rssi = nla_get_s8(
9841 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
9842 request->relative_rssi_set = true;
9845 if (request->relative_rssi_set &&
9846 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
9847 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
9849 rssi_adjust = nla_data(
9850 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
9851 request->rssi_adjust.band = rssi_adjust->band;
9852 request->rssi_adjust.delta = rssi_adjust->delta;
9853 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
9859 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
9863 request->scan_start = jiffies;
9869 return ERR_PTR(err);
9872 static int nl80211_start_sched_scan(struct sk_buff *skb,
9873 struct genl_info *info)
9875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9876 struct net_device *dev = info->user_ptr[1];
9877 struct wireless_dev *wdev = dev->ieee80211_ptr;
9878 struct cfg80211_sched_scan_request *sched_scan_req;
9882 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
9885 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
9886 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
9890 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
9892 rdev->wiphy.max_match_sets);
9894 err = PTR_ERR_OR_ZERO(sched_scan_req);
9898 /* leave request id zero for legacy request
9899 * or if driver does not support multi-scheduled scan
9901 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
9902 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
9904 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
9908 sched_scan_req->dev = dev;
9909 sched_scan_req->wiphy = &rdev->wiphy;
9911 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9912 sched_scan_req->owner_nlportid = info->snd_portid;
9914 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
9916 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
9920 kfree(sched_scan_req);
9925 static int nl80211_stop_sched_scan(struct sk_buff *skb,
9926 struct genl_info *info)
9928 struct cfg80211_sched_scan_request *req;
9929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9932 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
9935 if (info->attrs[NL80211_ATTR_COOKIE]) {
9936 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9937 return __cfg80211_stop_sched_scan(rdev, cookie, false);
9940 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
9941 struct cfg80211_sched_scan_request,
9943 if (!req || req->reqid ||
9944 (req->owner_nlportid &&
9945 req->owner_nlportid != info->snd_portid))
9948 return cfg80211_stop_sched_scan_req(rdev, req, false);
9951 static int nl80211_start_radar_detection(struct sk_buff *skb,
9952 struct genl_info *info)
9954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9955 struct net_device *dev = info->user_ptr[1];
9956 struct wireless_dev *wdev = dev->ieee80211_ptr;
9957 struct wiphy *wiphy = wdev->wiphy;
9958 struct cfg80211_chan_def chandef;
9959 enum nl80211_dfs_regions dfs_region;
9960 unsigned int cac_time_ms;
9963 flush_delayed_work(&rdev->dfs_update_channels_wk);
9967 dfs_region = reg_get_dfs_region(wiphy);
9968 if (dfs_region == NL80211_DFS_UNSET)
9971 err = nl80211_parse_chandef(rdev, info, &chandef);
9975 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
9984 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) {
9989 if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) {
9990 err = cfg80211_start_background_radar_detection(rdev, wdev,
9995 if (netif_carrier_ok(dev)) {
10000 if (wdev->cac_started) {
10005 /* CAC start is offloaded to HW and can't be started manually */
10006 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) {
10011 if (!rdev->ops->start_radar_detection) {
10016 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
10017 if (WARN_ON(!cac_time_ms))
10018 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
10020 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
10022 wdev->links[0].ap.chandef = chandef;
10023 wdev->cac_started = true;
10024 wdev->cac_start_time = jiffies;
10025 wdev->cac_time_ms = cac_time_ms;
10028 wiphy_unlock(wiphy);
10033 static int nl80211_notify_radar_detection(struct sk_buff *skb,
10034 struct genl_info *info)
10036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10037 struct net_device *dev = info->user_ptr[1];
10038 struct wireless_dev *wdev = dev->ieee80211_ptr;
10039 struct wiphy *wiphy = wdev->wiphy;
10040 struct cfg80211_chan_def chandef;
10041 enum nl80211_dfs_regions dfs_region;
10044 dfs_region = reg_get_dfs_region(wiphy);
10045 if (dfs_region == NL80211_DFS_UNSET) {
10046 GENL_SET_ERR_MSG(info,
10047 "DFS Region is not set. Unexpected Radar indication");
10051 err = nl80211_parse_chandef(rdev, info, &chandef);
10053 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
10057 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
10059 GENL_SET_ERR_MSG(info, "chandef is invalid");
10064 GENL_SET_ERR_MSG(info,
10065 "Unexpected Radar indication for chandef/iftype");
10069 /* Do not process this notification if radar is already detected
10070 * by kernel on this channel, and return success.
10072 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
10075 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
10077 cfg80211_sched_dfs_chan_update(rdev);
10079 rdev->radar_chandef = chandef;
10081 /* Propagate this notification to other radios as well */
10082 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
10087 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
10089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10090 unsigned int link_id = nl80211_link_id(info->attrs);
10091 struct net_device *dev = info->user_ptr[1];
10092 struct wireless_dev *wdev = dev->ieee80211_ptr;
10093 struct cfg80211_csa_settings params;
10094 struct nlattr **csa_attrs = NULL;
10096 bool need_new_beacon = false;
10097 bool need_handle_dfs_flag = true;
10101 if (!rdev->ops->channel_switch ||
10102 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
10103 return -EOPNOTSUPP;
10105 switch (dev->ieee80211_ptr->iftype) {
10106 case NL80211_IFTYPE_AP:
10107 case NL80211_IFTYPE_P2P_GO:
10108 need_new_beacon = true;
10109 /* For all modes except AP the handle_dfs flag needs to be
10110 * supplied to tell the kernel that userspace will handle radar
10111 * events when they happen. Otherwise a switch to a channel
10112 * requiring DFS will be rejected.
10114 need_handle_dfs_flag = false;
10116 /* useless if AP is not running */
10117 if (!wdev->links[link_id].ap.beacon_interval)
10120 case NL80211_IFTYPE_ADHOC:
10121 if (!wdev->u.ibss.ssid_len)
10124 case NL80211_IFTYPE_MESH_POINT:
10125 if (!wdev->u.mesh.id_len)
10129 return -EOPNOTSUPP;
10132 memset(¶ms, 0, sizeof(params));
10133 params.beacon_csa.ftm_responder = -1;
10135 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10136 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
10139 /* only important for AP, IBSS and mesh create IEs internally */
10140 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
10143 /* Even though the attribute is u32, the specification says
10144 * u8, so let's make sure we don't overflow.
10146 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
10147 if (cs_count > 255)
10150 params.count = cs_count;
10152 if (!need_new_beacon)
10155 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after,
10160 csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs),
10167 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
10168 info->attrs[NL80211_ATTR_CSA_IES],
10169 nl80211_policy, info->extack);
10173 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa,
10178 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) {
10183 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
10184 if (!len || (len % sizeof(u16))) {
10189 params.n_counter_offsets_beacon = len / sizeof(u16);
10190 if (rdev->wiphy.max_num_csa_counters &&
10191 (params.n_counter_offsets_beacon >
10192 rdev->wiphy.max_num_csa_counters)) {
10197 params.counter_offsets_beacon =
10198 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
10200 /* sanity checks - counters should fit and be the same */
10201 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
10202 u16 offset = params.counter_offsets_beacon[i];
10204 if (offset >= params.beacon_csa.tail_len) {
10209 if (params.beacon_csa.tail[offset] != params.count) {
10215 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
10216 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
10217 if (!len || (len % sizeof(u16))) {
10222 params.n_counter_offsets_presp = len / sizeof(u16);
10223 if (rdev->wiphy.max_num_csa_counters &&
10224 (params.n_counter_offsets_presp >
10225 rdev->wiphy.max_num_csa_counters)) {
10230 params.counter_offsets_presp =
10231 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
10233 /* sanity checks - counters should fit and be the same */
10234 for (i = 0; i < params.n_counter_offsets_presp; i++) {
10235 u16 offset = params.counter_offsets_presp[i];
10237 if (offset >= params.beacon_csa.probe_resp_len) {
10242 if (params.beacon_csa.probe_resp[offset] !=
10251 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
10255 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
10261 err = cfg80211_chandef_dfs_required(wdev->wiphy,
10268 params.radar_required = true;
10269 if (need_handle_dfs_flag &&
10270 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
10276 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
10277 params.block_tx = true;
10279 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) {
10280 err = nl80211_parse_punct_bitmap(rdev, info,
10282 ¶ms.punct_bitmap);
10288 err = rdev_channel_switch(rdev, dev, ¶ms);
10292 kfree(params.beacon_after.mbssid_ies);
10293 kfree(params.beacon_csa.mbssid_ies);
10294 kfree(params.beacon_after.rnr_ies);
10295 kfree(params.beacon_csa.rnr_ies);
10300 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
10301 u32 seq, int flags,
10302 struct cfg80211_registered_device *rdev,
10303 struct wireless_dev *wdev,
10304 struct cfg80211_internal_bss *intbss)
10306 struct cfg80211_bss *res = &intbss->pub;
10307 const struct cfg80211_bss_ies *ies;
10308 unsigned int link_id;
10310 struct nlattr *bss;
10312 ASSERT_WDEV_LOCK(wdev);
10314 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
10315 NL80211_CMD_NEW_SCAN_RESULTS);
10319 genl_dump_check_consistent(cb, hdr);
10321 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
10322 goto nla_put_failure;
10323 if (wdev->netdev &&
10324 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
10325 goto nla_put_failure;
10326 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
10328 goto nla_put_failure;
10330 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
10332 goto nla_put_failure;
10333 if ((!is_zero_ether_addr(res->bssid) &&
10334 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
10335 goto nla_put_failure;
10338 /* indicate whether we have probe response data or not */
10339 if (rcu_access_pointer(res->proberesp_ies) &&
10340 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
10341 goto fail_unlock_rcu;
10343 /* this pointer prefers to be pointed to probe response data
10344 * but is always valid
10346 ies = rcu_dereference(res->ies);
10348 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
10350 goto fail_unlock_rcu;
10351 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
10352 ies->len, ies->data))
10353 goto fail_unlock_rcu;
10356 /* and this pointer is always (unless driver didn't know) beacon data */
10357 ies = rcu_dereference(res->beacon_ies);
10358 if (ies && ies->from_beacon) {
10359 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
10361 goto fail_unlock_rcu;
10362 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
10363 ies->len, ies->data))
10364 goto fail_unlock_rcu;
10368 if (res->beacon_interval &&
10369 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
10370 goto nla_put_failure;
10371 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
10372 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
10373 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET,
10374 res->channel->freq_offset) ||
10375 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
10376 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
10377 jiffies_to_msecs(jiffies - intbss->ts)))
10378 goto nla_put_failure;
10380 if (intbss->parent_tsf &&
10381 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
10382 intbss->parent_tsf, NL80211_BSS_PAD) ||
10383 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
10384 intbss->parent_bssid)))
10385 goto nla_put_failure;
10387 if (intbss->ts_boottime &&
10388 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
10389 intbss->ts_boottime, NL80211_BSS_PAD))
10390 goto nla_put_failure;
10392 if (!nl80211_put_signal(msg, intbss->pub.chains,
10393 intbss->pub.chain_signal,
10394 NL80211_BSS_CHAIN_SIGNAL))
10395 goto nla_put_failure;
10397 switch (rdev->wiphy.signal_type) {
10398 case CFG80211_SIGNAL_TYPE_MBM:
10399 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
10400 goto nla_put_failure;
10402 case CFG80211_SIGNAL_TYPE_UNSPEC:
10403 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
10404 goto nla_put_failure;
10410 switch (wdev->iftype) {
10411 case NL80211_IFTYPE_P2P_CLIENT:
10412 case NL80211_IFTYPE_STATION:
10413 for_each_valid_link(wdev, link_id) {
10414 if (intbss == wdev->links[link_id].client.current_bss &&
10415 (nla_put_u32(msg, NL80211_BSS_STATUS,
10416 NL80211_BSS_STATUS_ASSOCIATED) ||
10417 (wdev->valid_links &&
10418 (nla_put_u8(msg, NL80211_BSS_MLO_LINK_ID,
10420 nla_put(msg, NL80211_BSS_MLD_ADDR, ETH_ALEN,
10421 wdev->u.client.connected_addr)))))
10422 goto nla_put_failure;
10425 case NL80211_IFTYPE_ADHOC:
10426 if (intbss == wdev->u.ibss.current_bss &&
10427 nla_put_u32(msg, NL80211_BSS_STATUS,
10428 NL80211_BSS_STATUS_IBSS_JOINED))
10429 goto nla_put_failure;
10435 nla_nest_end(msg, bss);
10437 genlmsg_end(msg, hdr);
10443 genlmsg_cancel(msg, hdr);
10447 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
10449 struct cfg80211_registered_device *rdev;
10450 struct cfg80211_internal_bss *scan;
10451 struct wireless_dev *wdev;
10452 int start = cb->args[2], idx = 0;
10455 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
10458 /* nl80211_prepare_wdev_dump acquired it in the successful case */
10459 __acquire(&rdev->wiphy.mtx);
10462 spin_lock_bh(&rdev->bss_lock);
10465 * dump_scan will be called multiple times to break up the scan results
10466 * into multiple messages. It is unlikely that any more bss-es will be
10467 * expired after the first call, so only call only call this on the
10468 * first dump_scan invocation.
10471 cfg80211_bss_expire(rdev);
10473 cb->seq = rdev->bss_generation;
10475 list_for_each_entry(scan, &rdev->bss_list, list) {
10476 if (++idx <= start)
10478 if (nl80211_send_bss(skb, cb,
10479 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10480 rdev, wdev, scan) < 0) {
10486 spin_unlock_bh(&rdev->bss_lock);
10490 wiphy_unlock(&rdev->wiphy);
10495 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
10496 int flags, struct net_device *dev,
10497 bool allow_radio_stats,
10498 struct survey_info *survey)
10501 struct nlattr *infoattr;
10503 /* skip radio stats if userspace didn't request them */
10504 if (!survey->channel && !allow_radio_stats)
10507 hdr = nl80211hdr_put(msg, portid, seq, flags,
10508 NL80211_CMD_NEW_SURVEY_RESULTS);
10512 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
10513 goto nla_put_failure;
10515 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
10517 goto nla_put_failure;
10519 if (survey->channel &&
10520 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
10521 survey->channel->center_freq))
10522 goto nla_put_failure;
10524 if (survey->channel && survey->channel->freq_offset &&
10525 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET,
10526 survey->channel->freq_offset))
10527 goto nla_put_failure;
10529 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
10530 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
10531 goto nla_put_failure;
10532 if ((survey->filled & SURVEY_INFO_IN_USE) &&
10533 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
10534 goto nla_put_failure;
10535 if ((survey->filled & SURVEY_INFO_TIME) &&
10536 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
10537 survey->time, NL80211_SURVEY_INFO_PAD))
10538 goto nla_put_failure;
10539 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
10540 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
10541 survey->time_busy, NL80211_SURVEY_INFO_PAD))
10542 goto nla_put_failure;
10543 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
10544 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
10545 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
10546 goto nla_put_failure;
10547 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
10548 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
10549 survey->time_rx, NL80211_SURVEY_INFO_PAD))
10550 goto nla_put_failure;
10551 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
10552 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
10553 survey->time_tx, NL80211_SURVEY_INFO_PAD))
10554 goto nla_put_failure;
10555 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
10556 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
10557 survey->time_scan, NL80211_SURVEY_INFO_PAD))
10558 goto nla_put_failure;
10559 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
10560 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
10561 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
10562 goto nla_put_failure;
10564 nla_nest_end(msg, infoattr);
10566 genlmsg_end(msg, hdr);
10570 genlmsg_cancel(msg, hdr);
10574 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
10576 struct nlattr **attrbuf;
10577 struct survey_info survey;
10578 struct cfg80211_registered_device *rdev;
10579 struct wireless_dev *wdev;
10580 int survey_idx = cb->args[2];
10584 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
10588 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf);
10593 /* nl80211_prepare_wdev_dump acquired it in the successful case */
10594 __acquire(&rdev->wiphy.mtx);
10596 /* prepare_wdev_dump parsed the attributes */
10597 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
10599 if (!wdev->netdev) {
10604 if (!rdev->ops->dump_survey) {
10611 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
10613 if (res == -ENOENT)
10618 /* don't send disabled channels, but do send non-channel data */
10619 if (survey.channel &&
10620 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
10625 if (nl80211_send_survey(skb,
10626 NETLINK_CB(cb->skb).portid,
10627 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10628 wdev->netdev, radio_stats, &survey) < 0)
10634 cb->args[2] = survey_idx;
10638 wiphy_unlock(&rdev->wiphy);
10642 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
10644 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
10645 NL80211_WPA_VERSION_2 |
10646 NL80211_WPA_VERSION_3));
10649 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
10651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10652 struct net_device *dev = info->user_ptr[1];
10653 struct ieee80211_channel *chan;
10654 const u8 *bssid, *ssid;
10656 enum nl80211_auth_type auth_type;
10657 struct key_parse key;
10658 bool local_state_change;
10659 struct cfg80211_auth_request req = {};
10662 if (!info->attrs[NL80211_ATTR_MAC])
10665 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
10668 if (!info->attrs[NL80211_ATTR_SSID])
10671 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10674 err = nl80211_parse_key(info, &key);
10678 if (key.idx >= 0) {
10679 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
10681 if (!key.p.key || !key.p.key_len)
10683 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
10684 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
10685 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
10686 key.p.key_len != WLAN_KEY_LEN_WEP104))
10695 if (key.idx >= 0) {
10699 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
10700 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
10709 if (!rdev->ops->auth)
10710 return -EOPNOTSUPP;
10712 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10713 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10714 return -EOPNOTSUPP;
10716 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10717 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
10718 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10720 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10722 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
10726 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10727 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10729 if (info->attrs[NL80211_ATTR_IE]) {
10730 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10731 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10734 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10735 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
10738 if ((auth_type == NL80211_AUTHTYPE_SAE ||
10739 auth_type == NL80211_AUTHTYPE_FILS_SK ||
10740 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
10741 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
10742 !info->attrs[NL80211_ATTR_AUTH_DATA])
10745 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
10746 if (auth_type != NL80211_AUTHTYPE_SAE &&
10747 auth_type != NL80211_AUTHTYPE_FILS_SK &&
10748 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
10749 auth_type != NL80211_AUTHTYPE_FILS_PK)
10751 req.auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
10752 req.auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
10755 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
10758 * Since we no longer track auth state, ignore
10759 * requests to only change local state.
10761 if (local_state_change)
10764 req.auth_type = auth_type;
10765 req.key = key.p.key;
10766 req.key_len = key.p.key_len;
10767 req.key_idx = key.idx;
10768 req.link_id = nl80211_link_id_or_invalid(info->attrs);
10769 if (req.link_id >= 0) {
10770 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO))
10772 if (!info->attrs[NL80211_ATTR_MLD_ADDR])
10774 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
10775 if (!is_valid_ether_addr(req.ap_mld_addr))
10779 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
10780 IEEE80211_BSS_TYPE_ESS,
10781 IEEE80211_PRIVACY_ANY);
10785 wdev_lock(dev->ieee80211_ptr);
10786 err = cfg80211_mlme_auth(rdev, dev, &req);
10787 wdev_unlock(dev->ieee80211_ptr);
10789 cfg80211_put_bss(&rdev->wiphy, req.bss);
10794 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
10795 struct genl_info *info)
10797 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10798 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
10802 if (!rdev->ops->tx_control_port ||
10803 !wiphy_ext_feature_isset(&rdev->wiphy,
10804 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
10805 return -EOPNOTSUPP;
10810 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
10811 struct genl_info *info,
10812 struct cfg80211_crypto_settings *settings,
10815 memset(settings, 0, sizeof(*settings));
10817 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
10819 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
10822 proto = nla_get_u16(
10823 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
10824 settings->control_port_ethertype = cpu_to_be16(proto);
10825 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
10826 proto != ETH_P_PAE)
10828 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
10829 settings->control_port_no_encrypt = true;
10831 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
10833 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10834 int r = validate_pae_over_nl80211(rdev, info);
10839 settings->control_port_over_nl80211 = true;
10841 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH])
10842 settings->control_port_no_preauth = true;
10845 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
10849 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
10850 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
10851 settings->n_ciphers_pairwise = len / sizeof(u32);
10853 if (len % sizeof(u32))
10856 if (settings->n_ciphers_pairwise > cipher_limit)
10859 memcpy(settings->ciphers_pairwise, data, len);
10861 for (i = 0; i < settings->n_ciphers_pairwise; i++)
10862 if (!cfg80211_supported_cipher_suite(
10864 settings->ciphers_pairwise[i]))
10868 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
10869 settings->cipher_group =
10870 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
10871 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
10872 settings->cipher_group))
10876 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
10877 settings->wpa_versions =
10878 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
10879 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
10883 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
10887 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
10888 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
10889 settings->n_akm_suites = len / sizeof(u32);
10891 if (len % sizeof(u32))
10894 if (settings->n_akm_suites > rdev->wiphy.max_num_akm_suites)
10897 memcpy(settings->akm_suites, data, len);
10900 if (info->attrs[NL80211_ATTR_PMK]) {
10901 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
10903 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10904 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
10905 !wiphy_ext_feature_isset(&rdev->wiphy,
10906 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
10908 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10911 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
10912 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10913 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
10914 !wiphy_ext_feature_isset(&rdev->wiphy,
10915 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
10917 settings->sae_pwd =
10918 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
10919 settings->sae_pwd_len =
10920 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
10923 if (info->attrs[NL80211_ATTR_SAE_PWE])
10924 settings->sae_pwe =
10925 nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]);
10927 settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED;
10932 static struct cfg80211_bss *nl80211_assoc_bss(struct cfg80211_registered_device *rdev,
10933 const u8 *ssid, int ssid_len,
10934 struct nlattr **attrs)
10936 struct ieee80211_channel *chan;
10937 struct cfg80211_bss *bss;
10941 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_WIPHY_FREQ])
10942 return ERR_PTR(-EINVAL);
10944 bssid = nla_data(attrs[NL80211_ATTR_MAC]);
10946 freq = MHZ_TO_KHZ(nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]));
10947 if (attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10948 freq += nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10950 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
10952 return ERR_PTR(-EINVAL);
10954 bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid,
10956 IEEE80211_BSS_TYPE_ESS,
10957 IEEE80211_PRIVACY_ANY);
10959 return ERR_PTR(-ENOENT);
10964 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
10966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10967 struct net_device *dev = info->user_ptr[1];
10968 struct cfg80211_assoc_request req = {};
10969 struct nlattr **attrs = NULL;
10970 const u8 *ap_addr, *ssid;
10971 unsigned int link_id;
10974 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10975 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10978 if (!info->attrs[NL80211_ATTR_SSID])
10981 if (!rdev->ops->assoc)
10982 return -EOPNOTSUPP;
10984 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10985 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10986 return -EOPNOTSUPP;
10988 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10989 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10991 if (info->attrs[NL80211_ATTR_IE]) {
10992 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10993 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10995 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
10996 req.ie, req.ie_len)) {
10997 GENL_SET_ERR_MSG(info,
10998 "non-inheritance makes no sense");
11003 if (info->attrs[NL80211_ATTR_USE_MFP]) {
11004 enum nl80211_mfp mfp =
11005 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
11006 if (mfp == NL80211_MFP_REQUIRED)
11007 req.use_mfp = true;
11008 else if (mfp != NL80211_MFP_NO)
11012 if (info->attrs[NL80211_ATTR_PREV_BSSID])
11013 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
11015 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
11016 req.flags |= ASSOC_REQ_DISABLE_HT;
11018 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11019 memcpy(&req.ht_capa_mask,
11020 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11021 sizeof(req.ht_capa_mask));
11023 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11024 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11026 memcpy(&req.ht_capa,
11027 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11028 sizeof(req.ht_capa));
11031 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
11032 req.flags |= ASSOC_REQ_DISABLE_VHT;
11034 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE]))
11035 req.flags |= ASSOC_REQ_DISABLE_HE;
11037 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT]))
11038 req.flags |= ASSOC_REQ_DISABLE_EHT;
11040 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
11041 memcpy(&req.vht_capa_mask,
11042 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
11043 sizeof(req.vht_capa_mask));
11045 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
11046 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
11048 memcpy(&req.vht_capa,
11049 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
11050 sizeof(req.vht_capa));
11053 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
11054 if (!((rdev->wiphy.features &
11055 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
11056 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
11057 !wiphy_ext_feature_isset(&rdev->wiphy,
11058 NL80211_EXT_FEATURE_RRM))
11060 req.flags |= ASSOC_REQ_USE_RRM;
11063 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
11064 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
11065 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
11066 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
11069 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
11072 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) {
11073 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY])
11075 memcpy(&req.s1g_capa_mask,
11076 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]),
11077 sizeof(req.s1g_capa_mask));
11080 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) {
11081 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK])
11083 memcpy(&req.s1g_capa,
11084 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]),
11085 sizeof(req.s1g_capa));
11088 req.link_id = nl80211_link_id_or_invalid(info->attrs);
11090 if (info->attrs[NL80211_ATTR_MLO_LINKS]) {
11091 unsigned int attrsize = NUM_NL80211_ATTR * sizeof(*attrs);
11092 struct nlattr *link;
11095 if (req.link_id < 0)
11098 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO))
11101 if (info->attrs[NL80211_ATTR_MAC] ||
11102 info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
11103 !info->attrs[NL80211_ATTR_MLD_ADDR])
11106 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
11107 ap_addr = req.ap_mld_addr;
11109 attrs = kzalloc(attrsize, GFP_KERNEL);
11113 nla_for_each_nested(link,
11114 info->attrs[NL80211_ATTR_MLO_LINKS],
11116 memset(attrs, 0, attrsize);
11118 nla_parse_nested(attrs, NL80211_ATTR_MAX,
11121 if (!attrs[NL80211_ATTR_MLO_LINK_ID]) {
11126 link_id = nla_get_u8(attrs[NL80211_ATTR_MLO_LINK_ID]);
11127 /* cannot use the same link ID again */
11128 if (req.links[link_id].bss) {
11132 req.links[link_id].bss =
11133 nl80211_assoc_bss(rdev, ssid, ssid_len, attrs);
11134 if (IS_ERR(req.links[link_id].bss)) {
11135 err = PTR_ERR(req.links[link_id].bss);
11136 req.links[link_id].bss = NULL;
11140 if (attrs[NL80211_ATTR_IE]) {
11141 req.links[link_id].elems =
11142 nla_data(attrs[NL80211_ATTR_IE]);
11143 req.links[link_id].elems_len =
11144 nla_len(attrs[NL80211_ATTR_IE]);
11146 if (cfg80211_find_elem(WLAN_EID_FRAGMENT,
11147 req.links[link_id].elems,
11148 req.links[link_id].elems_len)) {
11149 GENL_SET_ERR_MSG(info,
11150 "cannot deal with fragmentation");
11155 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
11156 req.links[link_id].elems,
11157 req.links[link_id].elems_len)) {
11158 GENL_SET_ERR_MSG(info,
11159 "cannot deal with non-inheritance");
11165 req.links[link_id].disabled =
11166 nla_get_flag(attrs[NL80211_ATTR_MLO_LINK_DISABLED]);
11169 if (!req.links[req.link_id].bss) {
11174 if (req.links[req.link_id].elems_len) {
11175 GENL_SET_ERR_MSG(info,
11176 "cannot have per-link elems on assoc link");
11181 if (req.links[req.link_id].disabled) {
11182 GENL_SET_ERR_MSG(info,
11183 "cannot have assoc link disabled");
11191 if (req.link_id >= 0)
11194 req.bss = nl80211_assoc_bss(rdev, ssid, ssid_len, info->attrs);
11195 if (IS_ERR(req.bss))
11196 return PTR_ERR(req.bss);
11197 ap_addr = req.bss->bssid;
11200 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
11202 wdev_lock(dev->ieee80211_ptr);
11204 err = cfg80211_mlme_assoc(rdev, dev, &req);
11206 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
11207 dev->ieee80211_ptr->conn_owner_nlportid =
11209 memcpy(dev->ieee80211_ptr->disconnect_bssid,
11210 ap_addr, ETH_ALEN);
11213 wdev_unlock(dev->ieee80211_ptr);
11217 for (link_id = 0; link_id < ARRAY_SIZE(req.links); link_id++)
11218 cfg80211_put_bss(&rdev->wiphy, req.links[link_id].bss);
11219 cfg80211_put_bss(&rdev->wiphy, req.bss);
11225 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
11227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11228 struct net_device *dev = info->user_ptr[1];
11229 const u8 *ie = NULL, *bssid;
11230 int ie_len = 0, err;
11232 bool local_state_change;
11234 if (dev->ieee80211_ptr->conn_owner_nlportid &&
11235 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
11238 if (!info->attrs[NL80211_ATTR_MAC])
11241 if (!info->attrs[NL80211_ATTR_REASON_CODE])
11244 if (!rdev->ops->deauth)
11245 return -EOPNOTSUPP;
11247 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11248 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11249 return -EOPNOTSUPP;
11251 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11253 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
11254 if (reason_code == 0) {
11255 /* Reason Code 0 is reserved */
11259 if (info->attrs[NL80211_ATTR_IE]) {
11260 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11261 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11264 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
11266 wdev_lock(dev->ieee80211_ptr);
11267 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
11268 local_state_change);
11269 wdev_unlock(dev->ieee80211_ptr);
11273 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
11275 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11276 struct net_device *dev = info->user_ptr[1];
11277 const u8 *ie = NULL, *bssid;
11278 int ie_len = 0, err;
11280 bool local_state_change;
11282 if (dev->ieee80211_ptr->conn_owner_nlportid &&
11283 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
11286 if (!info->attrs[NL80211_ATTR_MAC])
11289 if (!info->attrs[NL80211_ATTR_REASON_CODE])
11292 if (!rdev->ops->disassoc)
11293 return -EOPNOTSUPP;
11295 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11296 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11297 return -EOPNOTSUPP;
11299 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11301 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
11302 if (reason_code == 0) {
11303 /* Reason Code 0 is reserved */
11307 if (info->attrs[NL80211_ATTR_IE]) {
11308 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11309 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11312 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
11314 wdev_lock(dev->ieee80211_ptr);
11315 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
11316 local_state_change);
11317 wdev_unlock(dev->ieee80211_ptr);
11322 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
11323 int mcast_rate[NUM_NL80211_BANDS],
11326 struct wiphy *wiphy = &rdev->wiphy;
11327 bool found = false;
11330 for (band = 0; band < NUM_NL80211_BANDS; band++) {
11331 struct ieee80211_supported_band *sband;
11333 sband = wiphy->bands[band];
11337 for (i = 0; i < sband->n_bitrates; i++) {
11338 if (sband->bitrates[i].bitrate == rateval) {
11339 mcast_rate[band] = i + 1;
11349 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
11351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11352 struct net_device *dev = info->user_ptr[1];
11353 struct cfg80211_ibss_params ibss;
11354 struct wiphy *wiphy;
11355 struct cfg80211_cached_keys *connkeys = NULL;
11358 memset(&ibss, 0, sizeof(ibss));
11360 if (!info->attrs[NL80211_ATTR_SSID] ||
11361 !nla_len(info->attrs[NL80211_ATTR_SSID]))
11364 ibss.beacon_interval = 100;
11366 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
11367 ibss.beacon_interval =
11368 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
11370 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
11371 ibss.beacon_interval);
11375 if (!rdev->ops->join_ibss)
11376 return -EOPNOTSUPP;
11378 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
11379 return -EOPNOTSUPP;
11381 wiphy = &rdev->wiphy;
11383 if (info->attrs[NL80211_ATTR_MAC]) {
11384 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11386 if (!is_valid_ether_addr(ibss.bssid))
11389 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
11390 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
11392 if (info->attrs[NL80211_ATTR_IE]) {
11393 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11394 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11397 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
11401 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
11402 NL80211_IFTYPE_ADHOC))
11405 switch (ibss.chandef.width) {
11406 case NL80211_CHAN_WIDTH_5:
11407 case NL80211_CHAN_WIDTH_10:
11408 case NL80211_CHAN_WIDTH_20_NOHT:
11410 case NL80211_CHAN_WIDTH_20:
11411 case NL80211_CHAN_WIDTH_40:
11412 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
11415 case NL80211_CHAN_WIDTH_80:
11416 case NL80211_CHAN_WIDTH_80P80:
11417 case NL80211_CHAN_WIDTH_160:
11418 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
11420 if (!wiphy_ext_feature_isset(&rdev->wiphy,
11421 NL80211_EXT_FEATURE_VHT_IBSS))
11424 case NL80211_CHAN_WIDTH_320:
11430 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
11431 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
11433 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11435 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11437 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11438 struct ieee80211_supported_band *sband =
11439 wiphy->bands[ibss.chandef.chan->band];
11441 err = ieee80211_get_ratemask(sband, rates, n_rates,
11442 &ibss.basic_rates);
11447 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11448 memcpy(&ibss.ht_capa_mask,
11449 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11450 sizeof(ibss.ht_capa_mask));
11452 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11453 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11455 memcpy(&ibss.ht_capa,
11456 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11457 sizeof(ibss.ht_capa));
11460 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11461 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
11462 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11465 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
11466 bool no_ht = false;
11468 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
11469 if (IS_ERR(connkeys))
11470 return PTR_ERR(connkeys);
11472 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
11474 kfree_sensitive(connkeys);
11479 ibss.control_port =
11480 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
11482 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11483 int r = validate_pae_over_nl80211(rdev, info);
11486 kfree_sensitive(connkeys);
11490 ibss.control_port_over_nl80211 = true;
11493 ibss.userspace_handles_dfs =
11494 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11496 wdev_lock(dev->ieee80211_ptr);
11497 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
11499 kfree_sensitive(connkeys);
11500 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
11501 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11502 wdev_unlock(dev->ieee80211_ptr);
11507 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
11509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11510 struct net_device *dev = info->user_ptr[1];
11512 if (!rdev->ops->leave_ibss)
11513 return -EOPNOTSUPP;
11515 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
11516 return -EOPNOTSUPP;
11518 return cfg80211_leave_ibss(rdev, dev, false);
11521 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
11523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11524 struct net_device *dev = info->user_ptr[1];
11525 int mcast_rate[NUM_NL80211_BANDS];
11528 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
11529 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
11530 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
11531 return -EOPNOTSUPP;
11533 if (!rdev->ops->set_mcast_rate)
11534 return -EOPNOTSUPP;
11536 memset(mcast_rate, 0, sizeof(mcast_rate));
11538 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
11541 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
11542 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
11545 return rdev_set_mcast_rate(rdev, dev, mcast_rate);
11548 static struct sk_buff *
11549 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
11550 struct wireless_dev *wdev, int approxlen,
11551 u32 portid, u32 seq, enum nl80211_commands cmd,
11552 enum nl80211_attrs attr,
11553 const struct nl80211_vendor_cmd_info *info,
11556 struct sk_buff *skb;
11558 struct nlattr *data;
11560 skb = nlmsg_new(approxlen + 100, gfp);
11564 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
11570 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11571 goto nla_put_failure;
11574 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
11576 goto nla_put_failure;
11577 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
11579 goto nla_put_failure;
11583 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11584 wdev_id(wdev), NL80211_ATTR_PAD))
11585 goto nla_put_failure;
11586 if (wdev->netdev &&
11587 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
11588 wdev->netdev->ifindex))
11589 goto nla_put_failure;
11592 data = nla_nest_start_noflag(skb, attr);
11594 goto nla_put_failure;
11596 ((void **)skb->cb)[0] = rdev;
11597 ((void **)skb->cb)[1] = hdr;
11598 ((void **)skb->cb)[2] = data;
11607 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
11608 struct wireless_dev *wdev,
11609 enum nl80211_commands cmd,
11610 enum nl80211_attrs attr,
11611 unsigned int portid,
11612 int vendor_event_idx,
11613 int approxlen, gfp_t gfp)
11615 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11616 const struct nl80211_vendor_cmd_info *info;
11619 case NL80211_CMD_TESTMODE:
11620 if (WARN_ON(vendor_event_idx != -1))
11624 case NL80211_CMD_VENDOR:
11625 if (WARN_ON(vendor_event_idx < 0 ||
11626 vendor_event_idx >= wiphy->n_vendor_events))
11628 info = &wiphy->vendor_events[vendor_event_idx];
11635 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
11636 cmd, attr, info, gfp);
11638 EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
11640 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
11642 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11643 void *hdr = ((void **)skb->cb)[1];
11644 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
11645 struct nlattr *data = ((void **)skb->cb)[2];
11646 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
11648 /* clear CB data for netlink core to own from now on */
11649 memset(skb->cb, 0, sizeof(skb->cb));
11651 nla_nest_end(skb, data);
11652 genlmsg_end(skb, hdr);
11654 if (nlhdr->nlmsg_pid) {
11655 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
11658 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
11659 mcgrp = NL80211_MCGRP_VENDOR;
11661 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11662 skb, 0, mcgrp, gfp);
11665 EXPORT_SYMBOL(__cfg80211_send_event_skb);
11667 #ifdef CONFIG_NL80211_TESTMODE
11668 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
11670 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11671 struct wireless_dev *wdev;
11674 lockdep_assert_held(&rdev->wiphy.mtx);
11676 wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info),
11679 if (!rdev->ops->testmode_cmd)
11680 return -EOPNOTSUPP;
11682 if (IS_ERR(wdev)) {
11683 err = PTR_ERR(wdev);
11684 if (err != -EINVAL)
11687 } else if (wdev->wiphy != &rdev->wiphy) {
11691 if (!info->attrs[NL80211_ATTR_TESTDATA])
11694 rdev->cur_cmd_info = info;
11695 err = rdev_testmode_cmd(rdev, wdev,
11696 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
11697 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
11698 rdev->cur_cmd_info = NULL;
11703 static int nl80211_testmode_dump(struct sk_buff *skb,
11704 struct netlink_callback *cb)
11706 struct cfg80211_registered_device *rdev;
11707 struct nlattr **attrbuf = NULL;
11717 * 0 is a valid index, but not valid for args[0],
11718 * so we need to offset by 1.
11720 phy_idx = cb->args[0] - 1;
11722 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
11728 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
11735 err = nlmsg_parse_deprecated(cb->nlh,
11736 GENL_HDRLEN + nl80211_fam.hdrsize,
11737 attrbuf, nl80211_fam.maxattr,
11738 nl80211_policy, NULL);
11742 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
11743 if (IS_ERR(rdev)) {
11744 err = PTR_ERR(rdev);
11747 phy_idx = rdev->wiphy_idx;
11749 if (attrbuf[NL80211_ATTR_TESTDATA])
11750 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
11754 data = nla_data((void *)cb->args[1]);
11755 data_len = nla_len((void *)cb->args[1]);
11758 if (!rdev->ops->testmode_dump) {
11764 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11765 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11766 NL80211_CMD_TESTMODE);
11767 struct nlattr *tmdata;
11772 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
11773 genlmsg_cancel(skb, hdr);
11777 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
11779 genlmsg_cancel(skb, hdr);
11782 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
11783 nla_nest_end(skb, tmdata);
11785 if (err == -ENOBUFS || err == -ENOENT) {
11786 genlmsg_cancel(skb, hdr);
11789 genlmsg_cancel(skb, hdr);
11793 genlmsg_end(skb, hdr);
11798 cb->args[0] = phy_idx + 1;
11806 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
11808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11809 struct net_device *dev = info->user_ptr[1];
11810 struct cfg80211_connect_params connect;
11811 struct wiphy *wiphy;
11812 struct cfg80211_cached_keys *connkeys = NULL;
11816 memset(&connect, 0, sizeof(connect));
11818 if (!info->attrs[NL80211_ATTR_SSID] ||
11819 !nla_len(info->attrs[NL80211_ATTR_SSID]))
11822 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
11823 connect.auth_type =
11824 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
11825 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
11826 NL80211_CMD_CONNECT))
11829 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
11831 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
11833 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
11834 !wiphy_ext_feature_isset(&rdev->wiphy,
11835 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
11837 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
11839 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
11840 NL80211_MAX_NR_CIPHER_SUITES);
11844 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11845 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11846 return -EOPNOTSUPP;
11848 wiphy = &rdev->wiphy;
11850 connect.bg_scan_period = -1;
11851 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
11852 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
11853 connect.bg_scan_period =
11854 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
11857 if (info->attrs[NL80211_ATTR_MAC])
11858 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11859 else if (info->attrs[NL80211_ATTR_MAC_HINT])
11860 connect.bssid_hint =
11861 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
11862 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
11863 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
11865 if (info->attrs[NL80211_ATTR_IE]) {
11866 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11867 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11870 if (info->attrs[NL80211_ATTR_USE_MFP]) {
11871 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
11872 if (connect.mfp == NL80211_MFP_OPTIONAL &&
11873 !wiphy_ext_feature_isset(&rdev->wiphy,
11874 NL80211_EXT_FEATURE_MFP_OPTIONAL))
11875 return -EOPNOTSUPP;
11877 connect.mfp = NL80211_MFP_NO;
11880 if (info->attrs[NL80211_ATTR_PREV_BSSID])
11881 connect.prev_bssid =
11882 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
11884 if (info->attrs[NL80211_ATTR_WIPHY_FREQ])
11885 freq = MHZ_TO_KHZ(nla_get_u32(
11886 info->attrs[NL80211_ATTR_WIPHY_FREQ]));
11887 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
11889 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
11892 connect.channel = nl80211_get_valid_chan(wiphy, freq);
11893 if (!connect.channel)
11895 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
11896 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
11897 freq = MHZ_TO_KHZ(freq);
11898 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq);
11899 if (!connect.channel_hint)
11903 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
11904 connect.edmg.channels =
11905 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
11907 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
11908 connect.edmg.bw_config =
11909 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
11912 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
11913 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
11914 if (IS_ERR(connkeys))
11915 return PTR_ERR(connkeys);
11918 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
11919 connect.flags |= ASSOC_REQ_DISABLE_HT;
11921 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11922 memcpy(&connect.ht_capa_mask,
11923 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11924 sizeof(connect.ht_capa_mask));
11926 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11927 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
11928 kfree_sensitive(connkeys);
11931 memcpy(&connect.ht_capa,
11932 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11933 sizeof(connect.ht_capa));
11936 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
11937 connect.flags |= ASSOC_REQ_DISABLE_VHT;
11939 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE]))
11940 connect.flags |= ASSOC_REQ_DISABLE_HE;
11942 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT]))
11943 connect.flags |= ASSOC_REQ_DISABLE_EHT;
11945 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
11946 memcpy(&connect.vht_capa_mask,
11947 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
11948 sizeof(connect.vht_capa_mask));
11950 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
11951 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
11952 kfree_sensitive(connkeys);
11955 memcpy(&connect.vht_capa,
11956 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
11957 sizeof(connect.vht_capa));
11960 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
11961 if (!((rdev->wiphy.features &
11962 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
11963 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
11964 !wiphy_ext_feature_isset(&rdev->wiphy,
11965 NL80211_EXT_FEATURE_RRM)) {
11966 kfree_sensitive(connkeys);
11969 connect.flags |= ASSOC_REQ_USE_RRM;
11972 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
11973 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
11974 kfree_sensitive(connkeys);
11975 return -EOPNOTSUPP;
11978 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
11979 /* bss selection makes no sense if bssid is set */
11980 if (connect.bssid) {
11981 kfree_sensitive(connkeys);
11985 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
11986 wiphy, &connect.bss_select);
11988 kfree_sensitive(connkeys);
11993 if (wiphy_ext_feature_isset(&rdev->wiphy,
11994 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
11995 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
11996 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
11997 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
11998 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
11999 connect.fils_erp_username =
12000 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
12001 connect.fils_erp_username_len =
12002 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
12003 connect.fils_erp_realm =
12004 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
12005 connect.fils_erp_realm_len =
12006 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
12007 connect.fils_erp_next_seq_num =
12009 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
12010 connect.fils_erp_rrk =
12011 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
12012 connect.fils_erp_rrk_len =
12013 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
12014 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
12015 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
12016 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
12017 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
12018 kfree_sensitive(connkeys);
12022 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
12023 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
12024 kfree_sensitive(connkeys);
12025 GENL_SET_ERR_MSG(info,
12026 "external auth requires connection ownership");
12029 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
12032 if (nla_get_flag(info->attrs[NL80211_ATTR_MLO_SUPPORT]))
12033 connect.flags |= CONNECT_REQ_MLO_SUPPORT;
12035 wdev_lock(dev->ieee80211_ptr);
12037 err = cfg80211_connect(rdev, dev, &connect, connkeys,
12038 connect.prev_bssid);
12040 kfree_sensitive(connkeys);
12042 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
12043 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
12045 memcpy(dev->ieee80211_ptr->disconnect_bssid,
12046 connect.bssid, ETH_ALEN);
12048 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid);
12051 wdev_unlock(dev->ieee80211_ptr);
12056 static int nl80211_update_connect_params(struct sk_buff *skb,
12057 struct genl_info *info)
12059 struct cfg80211_connect_params connect = {};
12060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12061 struct net_device *dev = info->user_ptr[1];
12062 struct wireless_dev *wdev = dev->ieee80211_ptr;
12063 bool fils_sk_offload;
12068 if (!rdev->ops->update_connect_params)
12069 return -EOPNOTSUPP;
12071 if (info->attrs[NL80211_ATTR_IE]) {
12072 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12073 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12074 changed |= UPDATE_ASSOC_IES;
12077 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
12078 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
12081 * when driver supports fils-sk offload all attributes must be
12082 * provided. So the else covers "fils-sk-not-all" and
12083 * "no-fils-sk-any".
12085 if (fils_sk_offload &&
12086 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
12087 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
12088 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
12089 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
12090 connect.fils_erp_username =
12091 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
12092 connect.fils_erp_username_len =
12093 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
12094 connect.fils_erp_realm =
12095 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
12096 connect.fils_erp_realm_len =
12097 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
12098 connect.fils_erp_next_seq_num =
12100 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
12101 connect.fils_erp_rrk =
12102 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
12103 connect.fils_erp_rrk_len =
12104 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
12105 changed |= UPDATE_FILS_ERP_INFO;
12106 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
12107 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
12108 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
12109 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
12113 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
12114 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
12115 if (!nl80211_valid_auth_type(rdev, auth_type,
12116 NL80211_CMD_CONNECT))
12119 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
12120 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
12123 connect.auth_type = auth_type;
12124 changed |= UPDATE_AUTH_TYPE;
12127 wdev_lock(dev->ieee80211_ptr);
12128 if (!wdev->connected)
12131 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
12132 wdev_unlock(dev->ieee80211_ptr);
12137 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
12139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12140 struct net_device *dev = info->user_ptr[1];
12144 if (dev->ieee80211_ptr->conn_owner_nlportid &&
12145 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
12148 if (!info->attrs[NL80211_ATTR_REASON_CODE])
12149 reason = WLAN_REASON_DEAUTH_LEAVING;
12151 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
12156 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12157 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
12158 return -EOPNOTSUPP;
12160 wdev_lock(dev->ieee80211_ptr);
12161 ret = cfg80211_disconnect(rdev, dev, reason, true);
12162 wdev_unlock(dev->ieee80211_ptr);
12166 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
12168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12172 if (info->attrs[NL80211_ATTR_PID]) {
12173 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
12175 net = get_net_ns_by_pid(pid);
12176 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
12177 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
12179 net = get_net_ns_by_fd(fd);
12185 return PTR_ERR(net);
12189 /* check if anything to do */
12190 if (!net_eq(wiphy_net(&rdev->wiphy), net))
12191 err = cfg80211_switch_netns(rdev, net);
12197 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
12199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12200 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
12201 struct cfg80211_pmksa *pmksa) = NULL;
12202 struct net_device *dev = info->user_ptr[1];
12203 struct cfg80211_pmksa pmksa;
12205 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
12207 if (!info->attrs[NL80211_ATTR_PMKID])
12210 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
12212 if (info->attrs[NL80211_ATTR_MAC]) {
12213 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
12214 } else if (info->attrs[NL80211_ATTR_SSID] &&
12215 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
12216 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
12217 info->attrs[NL80211_ATTR_PMK])) {
12218 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
12219 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
12221 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
12225 if (info->attrs[NL80211_ATTR_PMK]) {
12226 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12227 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12230 if (info->attrs[NL80211_ATTR_PMK_LIFETIME])
12231 pmksa.pmk_lifetime =
12232 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]);
12234 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD])
12235 pmksa.pmk_reauth_threshold =
12237 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]);
12239 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12240 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
12241 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
12242 wiphy_ext_feature_isset(&rdev->wiphy,
12243 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
12244 return -EOPNOTSUPP;
12246 switch (info->genlhdr->cmd) {
12247 case NL80211_CMD_SET_PMKSA:
12248 rdev_ops = rdev->ops->set_pmksa;
12250 case NL80211_CMD_DEL_PMKSA:
12251 rdev_ops = rdev->ops->del_pmksa;
12259 return -EOPNOTSUPP;
12261 return rdev_ops(&rdev->wiphy, dev, &pmksa);
12264 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
12266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12267 struct net_device *dev = info->user_ptr[1];
12269 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12270 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
12271 return -EOPNOTSUPP;
12273 if (!rdev->ops->flush_pmksa)
12274 return -EOPNOTSUPP;
12276 return rdev_flush_pmksa(rdev, dev);
12279 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
12281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12282 struct net_device *dev = info->user_ptr[1];
12283 u8 action_code, dialog_token;
12284 u32 peer_capability = 0;
12290 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
12291 !rdev->ops->tdls_mgmt)
12292 return -EOPNOTSUPP;
12294 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
12295 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
12296 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
12297 !info->attrs[NL80211_ATTR_IE] ||
12298 !info->attrs[NL80211_ATTR_MAC])
12301 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12302 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
12303 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12304 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
12305 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
12306 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
12308 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
12309 link_id = nl80211_link_id_or_invalid(info->attrs);
12311 return rdev_tdls_mgmt(rdev, dev, peer, link_id, action_code,
12312 dialog_token, status_code, peer_capability,
12314 nla_data(info->attrs[NL80211_ATTR_IE]),
12315 nla_len(info->attrs[NL80211_ATTR_IE]));
12318 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
12320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12321 struct net_device *dev = info->user_ptr[1];
12322 enum nl80211_tdls_operation operation;
12325 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
12326 !rdev->ops->tdls_oper)
12327 return -EOPNOTSUPP;
12329 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
12330 !info->attrs[NL80211_ATTR_MAC])
12333 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
12334 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12336 return rdev_tdls_oper(rdev, dev, peer, operation);
12339 static int nl80211_remain_on_channel(struct sk_buff *skb,
12340 struct genl_info *info)
12342 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12343 unsigned int link_id = nl80211_link_id(info->attrs);
12344 struct wireless_dev *wdev = info->user_ptr[1];
12345 struct cfg80211_chan_def chandef;
12346 struct sk_buff *msg;
12352 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
12353 !info->attrs[NL80211_ATTR_DURATION])
12356 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
12358 if (!rdev->ops->remain_on_channel ||
12359 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
12360 return -EOPNOTSUPP;
12363 * We should be on that channel for at least a minimum amount of
12364 * time (10ms) but no longer than the driver supports.
12366 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
12367 duration > rdev->wiphy.max_remain_on_channel_duration)
12370 err = nl80211_parse_chandef(rdev, info, &chandef);
12375 if (!cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) {
12376 const struct cfg80211_chan_def *oper_chandef, *compat_chandef;
12378 oper_chandef = wdev_chandef(wdev, link_id);
12380 if (WARN_ON(!oper_chandef)) {
12381 /* cannot happen since we must beacon to get here */
12387 /* note: returns first one if identical chandefs */
12388 compat_chandef = cfg80211_chandef_compatible(&chandef,
12391 if (compat_chandef != &chandef) {
12398 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12402 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12403 NL80211_CMD_REMAIN_ON_CHANNEL);
12409 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
12410 duration, &cookie);
12415 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12417 goto nla_put_failure;
12419 genlmsg_end(msg, hdr);
12421 return genlmsg_reply(msg, info);
12430 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
12431 struct genl_info *info)
12433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12434 struct wireless_dev *wdev = info->user_ptr[1];
12437 if (!info->attrs[NL80211_ATTR_COOKIE])
12440 if (!rdev->ops->cancel_remain_on_channel)
12441 return -EOPNOTSUPP;
12443 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12445 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
12448 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
12449 struct genl_info *info)
12451 struct cfg80211_bitrate_mask mask;
12452 unsigned int link_id = nl80211_link_id(info->attrs);
12453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12454 struct net_device *dev = info->user_ptr[1];
12455 struct wireless_dev *wdev = dev->ieee80211_ptr;
12458 if (!rdev->ops->set_bitrate_mask)
12459 return -EOPNOTSUPP;
12462 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
12463 NL80211_ATTR_TX_RATES, &mask,
12464 dev, true, link_id);
12468 err = rdev_set_bitrate_mask(rdev, dev, link_id, NULL, &mask);
12474 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
12476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12477 struct wireless_dev *wdev = info->user_ptr[1];
12478 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
12480 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
12483 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
12484 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
12486 switch (wdev->iftype) {
12487 case NL80211_IFTYPE_STATION:
12488 case NL80211_IFTYPE_ADHOC:
12489 case NL80211_IFTYPE_P2P_CLIENT:
12490 case NL80211_IFTYPE_AP:
12491 case NL80211_IFTYPE_AP_VLAN:
12492 case NL80211_IFTYPE_MESH_POINT:
12493 case NL80211_IFTYPE_P2P_GO:
12494 case NL80211_IFTYPE_P2P_DEVICE:
12496 case NL80211_IFTYPE_NAN:
12497 if (!wiphy_ext_feature_isset(wdev->wiphy,
12498 NL80211_EXT_FEATURE_SECURE_NAN))
12499 return -EOPNOTSUPP;
12502 return -EOPNOTSUPP;
12505 /* not much point in registering if we can't reply */
12506 if (!rdev->ops->mgmt_tx)
12507 return -EOPNOTSUPP;
12509 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] &&
12510 !wiphy_ext_feature_isset(&rdev->wiphy,
12511 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) {
12512 GENL_SET_ERR_MSG(info,
12513 "multicast RX registrations are not supported");
12514 return -EOPNOTSUPP;
12517 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
12518 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
12519 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
12520 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST],
12524 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
12526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12527 struct wireless_dev *wdev = info->user_ptr[1];
12528 struct cfg80211_chan_def chandef;
12532 struct sk_buff *msg = NULL;
12533 struct cfg80211_mgmt_tx_params params = {
12534 .dont_wait_for_ack =
12535 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
12538 if (!info->attrs[NL80211_ATTR_FRAME])
12541 if (!rdev->ops->mgmt_tx)
12542 return -EOPNOTSUPP;
12544 switch (wdev->iftype) {
12545 case NL80211_IFTYPE_P2P_DEVICE:
12546 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
12549 case NL80211_IFTYPE_STATION:
12550 case NL80211_IFTYPE_ADHOC:
12551 case NL80211_IFTYPE_P2P_CLIENT:
12552 case NL80211_IFTYPE_AP:
12553 case NL80211_IFTYPE_AP_VLAN:
12554 case NL80211_IFTYPE_MESH_POINT:
12555 case NL80211_IFTYPE_P2P_GO:
12557 case NL80211_IFTYPE_NAN:
12558 if (!wiphy_ext_feature_isset(wdev->wiphy,
12559 NL80211_EXT_FEATURE_SECURE_NAN))
12560 return -EOPNOTSUPP;
12563 return -EOPNOTSUPP;
12566 if (info->attrs[NL80211_ATTR_DURATION]) {
12567 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
12569 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
12572 * We should wait on the channel for at least a minimum amount
12573 * of time (10ms) but no longer than the driver supports.
12575 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
12576 params.wait > rdev->wiphy.max_remain_on_channel_duration)
12580 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
12582 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
12585 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
12587 /* get the channel if any has been specified, otherwise pass NULL to
12588 * the driver. The latter will use the current one
12590 chandef.chan = NULL;
12591 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
12592 err = nl80211_parse_chandef(rdev, info, &chandef);
12597 if (!chandef.chan && params.offchan)
12601 if (params.offchan &&
12602 !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) {
12607 params.link_id = nl80211_link_id_or_invalid(info->attrs);
12609 * This now races due to the unlock, but we cannot check
12610 * the valid links for the _station_ anyway, so that's up
12613 if (params.link_id >= 0 &&
12614 !(wdev->valid_links & BIT(params.link_id))) {
12620 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
12621 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
12623 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
12624 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
12627 if (len % sizeof(u16))
12630 params.n_csa_offsets = len / sizeof(u16);
12631 params.csa_offsets =
12632 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
12634 /* check that all the offsets fit the frame */
12635 for (i = 0; i < params.n_csa_offsets; i++) {
12636 if (params.csa_offsets[i] >= params.len)
12641 if (!params.dont_wait_for_ack) {
12642 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12646 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12647 NL80211_CMD_FRAME);
12654 params.chan = chandef.chan;
12655 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie);
12660 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12662 goto nla_put_failure;
12664 genlmsg_end(msg, hdr);
12665 return genlmsg_reply(msg, info);
12677 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
12679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12680 struct wireless_dev *wdev = info->user_ptr[1];
12683 if (!info->attrs[NL80211_ATTR_COOKIE])
12686 if (!rdev->ops->mgmt_tx_cancel_wait)
12687 return -EOPNOTSUPP;
12689 switch (wdev->iftype) {
12690 case NL80211_IFTYPE_STATION:
12691 case NL80211_IFTYPE_ADHOC:
12692 case NL80211_IFTYPE_P2P_CLIENT:
12693 case NL80211_IFTYPE_AP:
12694 case NL80211_IFTYPE_AP_VLAN:
12695 case NL80211_IFTYPE_P2P_GO:
12696 case NL80211_IFTYPE_P2P_DEVICE:
12698 case NL80211_IFTYPE_NAN:
12699 if (!wiphy_ext_feature_isset(wdev->wiphy,
12700 NL80211_EXT_FEATURE_SECURE_NAN))
12701 return -EOPNOTSUPP;
12704 return -EOPNOTSUPP;
12707 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12709 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
12712 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
12714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12715 struct wireless_dev *wdev;
12716 struct net_device *dev = info->user_ptr[1];
12721 if (!info->attrs[NL80211_ATTR_PS_STATE])
12724 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
12726 wdev = dev->ieee80211_ptr;
12728 if (!rdev->ops->set_power_mgmt)
12729 return -EOPNOTSUPP;
12731 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
12733 if (state == wdev->ps)
12736 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
12742 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
12744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12745 enum nl80211_ps_state ps_state;
12746 struct wireless_dev *wdev;
12747 struct net_device *dev = info->user_ptr[1];
12748 struct sk_buff *msg;
12752 wdev = dev->ieee80211_ptr;
12754 if (!rdev->ops->set_power_mgmt)
12755 return -EOPNOTSUPP;
12757 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12761 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12762 NL80211_CMD_GET_POWER_SAVE);
12769 ps_state = NL80211_PS_ENABLED;
12771 ps_state = NL80211_PS_DISABLED;
12773 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
12774 goto nla_put_failure;
12776 genlmsg_end(msg, hdr);
12777 return genlmsg_reply(msg, info);
12786 static const struct nla_policy
12787 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
12788 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
12789 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
12790 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
12791 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
12792 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
12793 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
12794 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
12797 static int nl80211_set_cqm_txe(struct genl_info *info,
12798 u32 rate, u32 pkts, u32 intvl)
12800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12801 struct net_device *dev = info->user_ptr[1];
12802 struct wireless_dev *wdev = dev->ieee80211_ptr;
12804 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
12807 if (!rdev->ops->set_cqm_txe_config)
12808 return -EOPNOTSUPP;
12810 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12811 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12812 return -EOPNOTSUPP;
12814 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
12817 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
12818 struct net_device *dev,
12819 struct cfg80211_cqm_config *cqm_config)
12821 struct wireless_dev *wdev = dev->ieee80211_ptr;
12822 s32 last, low, high;
12824 int i, n, low_index;
12827 /* RSSI reporting disabled? */
12829 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
12832 * Obtain current RSSI value if possible, if not and no RSSI threshold
12833 * event has been received yet, we should receive an event after a
12834 * connection is established and enough beacons received to calculate
12837 if (!cqm_config->last_rssi_event_value &&
12838 wdev->links[0].client.current_bss &&
12839 rdev->ops->get_station) {
12840 struct station_info sinfo = {};
12843 mac_addr = wdev->links[0].client.current_bss->pub.bssid;
12845 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
12849 cfg80211_sinfo_release_content(&sinfo);
12850 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
12851 cqm_config->last_rssi_event_value =
12852 (s8) sinfo.rx_beacon_signal_avg;
12855 last = cqm_config->last_rssi_event_value;
12856 hyst = cqm_config->rssi_hyst;
12857 n = cqm_config->n_rssi_thresholds;
12859 for (i = 0; i < n; i++) {
12860 i = array_index_nospec(i, n);
12861 if (last < cqm_config->rssi_thresholds[i])
12866 if (low_index >= 0) {
12867 low_index = array_index_nospec(low_index, n);
12868 low = cqm_config->rssi_thresholds[low_index] - hyst;
12873 i = array_index_nospec(i, n);
12874 high = cqm_config->rssi_thresholds[i] + hyst - 1;
12879 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
12882 static int nl80211_set_cqm_rssi(struct genl_info *info,
12883 const s32 *thresholds, int n_thresholds,
12886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12887 struct cfg80211_cqm_config *cqm_config = NULL, *old;
12888 struct net_device *dev = info->user_ptr[1];
12889 struct wireless_dev *wdev = dev->ieee80211_ptr;
12891 s32 prev = S32_MIN;
12893 /* Check all values negative and sorted */
12894 for (i = 0; i < n_thresholds; i++) {
12895 if (thresholds[i] > 0 || thresholds[i] <= prev)
12898 prev = thresholds[i];
12901 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12902 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12903 return -EOPNOTSUPP;
12905 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
12906 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
12907 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
12909 return rdev_set_cqm_rssi_config(rdev, dev,
12910 thresholds[0], hysteresis);
12913 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12914 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
12915 return -EOPNOTSUPP;
12917 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
12921 old = rcu_dereference_protected(wdev->cqm_config,
12922 lockdep_is_held(&wdev->mtx));
12924 if (n_thresholds) {
12925 cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds,
12933 cqm_config->rssi_hyst = hysteresis;
12934 cqm_config->n_rssi_thresholds = n_thresholds;
12935 memcpy(cqm_config->rssi_thresholds, thresholds,
12936 flex_array_size(cqm_config, rssi_thresholds,
12939 rcu_assign_pointer(wdev->cqm_config, cqm_config);
12941 RCU_INIT_POINTER(wdev->cqm_config, NULL);
12944 err = cfg80211_cqm_rssi_update(rdev, dev, cqm_config);
12946 rcu_assign_pointer(wdev->cqm_config, old);
12947 kfree_rcu(cqm_config, rcu_head);
12949 kfree_rcu(old, rcu_head);
12957 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
12959 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
12960 struct nlattr *cqm;
12963 cqm = info->attrs[NL80211_ATTR_CQM];
12967 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
12968 nl80211_attr_cqm_policy,
12973 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
12974 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
12975 const s32 *thresholds =
12976 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
12977 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
12978 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
12983 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
12987 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
12988 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
12989 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
12990 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
12991 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
12992 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
12994 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
13000 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
13002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13003 struct net_device *dev = info->user_ptr[1];
13004 struct ocb_setup setup = {};
13007 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
13011 return cfg80211_join_ocb(rdev, dev, &setup);
13014 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
13016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13017 struct net_device *dev = info->user_ptr[1];
13019 return cfg80211_leave_ocb(rdev, dev);
13022 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
13024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13025 struct net_device *dev = info->user_ptr[1];
13026 struct mesh_config cfg;
13027 struct mesh_setup setup;
13030 /* start with default */
13031 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
13032 memcpy(&setup, &default_mesh_setup, sizeof(setup));
13034 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
13035 /* and parse parameters if given */
13036 err = nl80211_parse_mesh_config(info, &cfg, NULL);
13041 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
13042 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
13045 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
13046 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
13048 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
13049 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
13050 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
13053 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
13054 setup.beacon_interval =
13055 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
13057 err = cfg80211_validate_beacon_int(rdev,
13058 NL80211_IFTYPE_MESH_POINT,
13059 setup.beacon_interval);
13064 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
13065 setup.dtim_period =
13066 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
13067 if (setup.dtim_period < 1 || setup.dtim_period > 100)
13071 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
13072 /* parse additional setup parameters if given */
13073 err = nl80211_parse_mesh_setup(info, &setup);
13078 if (setup.user_mpm)
13079 cfg.auto_open_plinks = false;
13081 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
13082 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
13086 /* __cfg80211_join_mesh() will sort it out */
13087 setup.chandef.chan = NULL;
13090 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
13091 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
13093 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
13094 struct ieee80211_supported_band *sband;
13096 if (!setup.chandef.chan)
13099 sband = rdev->wiphy.bands[setup.chandef.chan->band];
13101 err = ieee80211_get_ratemask(sband, rates, n_rates,
13102 &setup.basic_rates);
13107 if (info->attrs[NL80211_ATTR_TX_RATES]) {
13108 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
13109 NL80211_ATTR_TX_RATES,
13110 &setup.beacon_rate,
13115 if (!setup.chandef.chan)
13118 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
13119 &setup.beacon_rate);
13124 setup.userspace_handles_dfs =
13125 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
13127 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
13128 int r = validate_pae_over_nl80211(rdev, info);
13133 setup.control_port_over_nl80211 = true;
13136 wdev_lock(dev->ieee80211_ptr);
13137 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
13138 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
13139 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
13140 wdev_unlock(dev->ieee80211_ptr);
13145 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
13147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13148 struct net_device *dev = info->user_ptr[1];
13150 return cfg80211_leave_mesh(rdev, dev);
13154 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
13155 struct cfg80211_registered_device *rdev)
13157 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
13158 struct nlattr *nl_pats, *nl_pat;
13161 if (!wowlan->n_patterns)
13164 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
13168 for (i = 0; i < wowlan->n_patterns; i++) {
13169 nl_pat = nla_nest_start_noflag(msg, i + 1);
13172 pat_len = wowlan->patterns[i].pattern_len;
13173 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
13174 wowlan->patterns[i].mask) ||
13175 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
13176 wowlan->patterns[i].pattern) ||
13177 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
13178 wowlan->patterns[i].pkt_offset))
13180 nla_nest_end(msg, nl_pat);
13182 nla_nest_end(msg, nl_pats);
13187 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
13188 struct cfg80211_wowlan_tcp *tcp)
13190 struct nlattr *nl_tcp;
13195 nl_tcp = nla_nest_start_noflag(msg,
13196 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
13200 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
13201 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
13202 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
13203 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
13204 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
13205 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
13206 tcp->payload_len, tcp->payload) ||
13207 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
13208 tcp->data_interval) ||
13209 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
13210 tcp->wake_len, tcp->wake_data) ||
13211 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
13212 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
13215 if (tcp->payload_seq.len &&
13216 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
13217 sizeof(tcp->payload_seq), &tcp->payload_seq))
13220 if (tcp->payload_tok.len &&
13221 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
13222 sizeof(tcp->payload_tok) + tcp->tokens_size,
13223 &tcp->payload_tok))
13226 nla_nest_end(msg, nl_tcp);
13231 static int nl80211_send_wowlan_nd(struct sk_buff *msg,
13232 struct cfg80211_sched_scan_request *req)
13234 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
13240 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
13244 if (req->n_scan_plans == 1 &&
13245 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
13246 req->scan_plans[0].interval * 1000))
13249 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
13252 if (req->relative_rssi_set) {
13253 struct nl80211_bss_select_rssi_adjust rssi_adjust;
13255 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
13256 req->relative_rssi))
13259 rssi_adjust.band = req->rssi_adjust.band;
13260 rssi_adjust.delta = req->rssi_adjust.delta;
13261 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
13262 sizeof(rssi_adjust), &rssi_adjust))
13266 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13270 for (i = 0; i < req->n_channels; i++) {
13271 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13275 nla_nest_end(msg, freqs);
13277 if (req->n_match_sets) {
13278 matches = nla_nest_start_noflag(msg,
13279 NL80211_ATTR_SCHED_SCAN_MATCH);
13283 for (i = 0; i < req->n_match_sets; i++) {
13284 match = nla_nest_start_noflag(msg, i);
13288 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
13289 req->match_sets[i].ssid.ssid_len,
13290 req->match_sets[i].ssid.ssid))
13292 nla_nest_end(msg, match);
13294 nla_nest_end(msg, matches);
13297 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
13301 for (i = 0; i < req->n_scan_plans; i++) {
13302 scan_plan = nla_nest_start_noflag(msg, i + 1);
13306 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
13307 req->scan_plans[i].interval) ||
13308 (req->scan_plans[i].iterations &&
13309 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
13310 req->scan_plans[i].iterations)))
13312 nla_nest_end(msg, scan_plan);
13314 nla_nest_end(msg, scan_plans);
13316 nla_nest_end(msg, nd);
13321 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
13323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13324 struct sk_buff *msg;
13326 u32 size = NLMSG_DEFAULT_SIZE;
13328 if (!rdev->wiphy.wowlan)
13329 return -EOPNOTSUPP;
13331 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
13332 /* adjust size to have room for all the data */
13333 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
13334 rdev->wiphy.wowlan_config->tcp->payload_len +
13335 rdev->wiphy.wowlan_config->tcp->wake_len +
13336 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
13339 msg = nlmsg_new(size, GFP_KERNEL);
13343 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13344 NL80211_CMD_GET_WOWLAN);
13346 goto nla_put_failure;
13348 if (rdev->wiphy.wowlan_config) {
13349 struct nlattr *nl_wowlan;
13351 nl_wowlan = nla_nest_start_noflag(msg,
13352 NL80211_ATTR_WOWLAN_TRIGGERS);
13354 goto nla_put_failure;
13356 if ((rdev->wiphy.wowlan_config->any &&
13357 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
13358 (rdev->wiphy.wowlan_config->disconnect &&
13359 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
13360 (rdev->wiphy.wowlan_config->magic_pkt &&
13361 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
13362 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
13363 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
13364 (rdev->wiphy.wowlan_config->eap_identity_req &&
13365 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
13366 (rdev->wiphy.wowlan_config->four_way_handshake &&
13367 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
13368 (rdev->wiphy.wowlan_config->rfkill_release &&
13369 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
13370 goto nla_put_failure;
13372 if (nl80211_send_wowlan_patterns(msg, rdev))
13373 goto nla_put_failure;
13375 if (nl80211_send_wowlan_tcp(msg,
13376 rdev->wiphy.wowlan_config->tcp))
13377 goto nla_put_failure;
13379 if (nl80211_send_wowlan_nd(
13381 rdev->wiphy.wowlan_config->nd_config))
13382 goto nla_put_failure;
13384 nla_nest_end(msg, nl_wowlan);
13387 genlmsg_end(msg, hdr);
13388 return genlmsg_reply(msg, info);
13395 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
13396 struct nlattr *attr,
13397 struct cfg80211_wowlan *trig)
13399 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
13400 struct cfg80211_wowlan_tcp *cfg;
13401 struct nl80211_wowlan_tcp_data_token *tok = NULL;
13402 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
13404 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
13407 if (!rdev->wiphy.wowlan->tcp)
13410 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
13411 nl80211_wowlan_tcp_policy, NULL);
13415 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
13416 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
13417 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
13418 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
13419 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
13420 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
13421 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
13422 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
13425 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
13426 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
13429 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
13430 rdev->wiphy.wowlan->tcp->data_interval_max ||
13431 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
13434 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
13435 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
13438 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
13439 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
13442 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
13443 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
13445 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
13446 tokens_size = tokln - sizeof(*tok);
13448 if (!tok->len || tokens_size % tok->len)
13450 if (!rdev->wiphy.wowlan->tcp->tok)
13452 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
13454 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
13456 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
13458 if (tok->offset + tok->len > data_size)
13462 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
13463 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
13464 if (!rdev->wiphy.wowlan->tcp->seq)
13466 if (seq->len == 0 || seq->len > 4)
13468 if (seq->len + seq->offset > data_size)
13472 size = sizeof(*cfg);
13474 size += wake_size + wake_mask_size;
13475 size += tokens_size;
13477 cfg = kzalloc(size, GFP_KERNEL);
13480 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
13481 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
13482 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
13484 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
13485 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
13489 /* allocate a socket and port for it and use it */
13490 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
13491 IPPROTO_TCP, &cfg->sock, 1);
13496 if (inet_csk_get_port(cfg->sock->sk, port)) {
13497 sock_release(cfg->sock);
13499 return -EADDRINUSE;
13501 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
13507 cfg->src_port = port;
13510 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
13511 cfg->payload_len = data_size;
13512 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
13513 memcpy((void *)cfg->payload,
13514 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
13517 cfg->payload_seq = *seq;
13518 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
13519 cfg->wake_len = wake_size;
13520 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
13521 memcpy((void *)cfg->wake_data,
13522 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
13524 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
13525 data_size + wake_size;
13526 memcpy((void *)cfg->wake_mask,
13527 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
13530 cfg->tokens_size = tokens_size;
13531 cfg->payload_tok = *tok;
13532 memcpy(cfg->payload_tok.token_stream, tok->token_stream,
13541 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
13542 const struct wiphy_wowlan_support *wowlan,
13543 struct nlattr *attr,
13544 struct cfg80211_wowlan *trig)
13546 struct nlattr **tb;
13549 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
13553 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
13558 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
13559 nl80211_policy, NULL);
13563 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
13564 wowlan->max_nd_match_sets);
13565 err = PTR_ERR_OR_ZERO(trig->nd_config);
13567 trig->nd_config = NULL;
13574 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
13576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13577 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
13578 struct cfg80211_wowlan new_triggers = {};
13579 struct cfg80211_wowlan *ntrig;
13580 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
13582 bool prev_enabled = rdev->wiphy.wowlan_config;
13583 bool regular = false;
13586 return -EOPNOTSUPP;
13588 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
13589 cfg80211_rdev_free_wowlan(rdev);
13590 rdev->wiphy.wowlan_config = NULL;
13594 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
13595 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
13596 nl80211_wowlan_policy, info->extack);
13600 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
13601 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
13603 new_triggers.any = true;
13606 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
13607 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
13609 new_triggers.disconnect = true;
13613 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
13614 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
13616 new_triggers.magic_pkt = true;
13620 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
13623 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
13624 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
13626 new_triggers.gtk_rekey_failure = true;
13630 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
13631 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
13633 new_triggers.eap_identity_req = true;
13637 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
13638 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
13640 new_triggers.four_way_handshake = true;
13644 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
13645 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
13647 new_triggers.rfkill_release = true;
13651 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
13652 struct nlattr *pat;
13653 int n_patterns = 0;
13654 int rem, pat_len, mask_len, pkt_offset;
13655 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
13659 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
13662 if (n_patterns > wowlan->n_patterns)
13665 new_triggers.patterns = kcalloc(n_patterns,
13666 sizeof(new_triggers.patterns[0]),
13668 if (!new_triggers.patterns)
13671 new_triggers.n_patterns = n_patterns;
13674 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
13678 err = nla_parse_nested_deprecated(pat_tb,
13679 MAX_NL80211_PKTPAT,
13681 nl80211_packet_pattern_policy,
13687 if (!pat_tb[NL80211_PKTPAT_MASK] ||
13688 !pat_tb[NL80211_PKTPAT_PATTERN])
13690 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
13691 mask_len = DIV_ROUND_UP(pat_len, 8);
13692 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
13694 if (pat_len > wowlan->pattern_max_len ||
13695 pat_len < wowlan->pattern_min_len)
13698 if (!pat_tb[NL80211_PKTPAT_OFFSET])
13701 pkt_offset = nla_get_u32(
13702 pat_tb[NL80211_PKTPAT_OFFSET]);
13703 if (pkt_offset > wowlan->max_pkt_offset)
13705 new_triggers.patterns[i].pkt_offset = pkt_offset;
13707 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
13712 new_triggers.patterns[i].mask = mask_pat;
13713 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
13715 mask_pat += mask_len;
13716 new_triggers.patterns[i].pattern = mask_pat;
13717 new_triggers.patterns[i].pattern_len = pat_len;
13719 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
13725 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
13727 err = nl80211_parse_wowlan_tcp(
13728 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
13734 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
13736 err = nl80211_parse_wowlan_nd(
13737 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
13743 /* The 'any' trigger means the device continues operating more or less
13744 * as in its normal operation mode and wakes up the host on most of the
13745 * normal interrupts (like packet RX, ...)
13746 * It therefore makes little sense to combine with the more constrained
13747 * wakeup trigger modes.
13749 if (new_triggers.any && regular) {
13754 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
13759 cfg80211_rdev_free_wowlan(rdev);
13760 rdev->wiphy.wowlan_config = ntrig;
13763 if (rdev->ops->set_wakeup &&
13764 prev_enabled != !!rdev->wiphy.wowlan_config)
13765 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
13769 for (i = 0; i < new_triggers.n_patterns; i++)
13770 kfree(new_triggers.patterns[i].mask);
13771 kfree(new_triggers.patterns);
13772 if (new_triggers.tcp && new_triggers.tcp->sock)
13773 sock_release(new_triggers.tcp->sock);
13774 kfree(new_triggers.tcp);
13775 kfree(new_triggers.nd_config);
13780 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
13781 struct cfg80211_registered_device *rdev)
13783 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
13785 struct cfg80211_coalesce_rules *rule;
13787 if (!rdev->coalesce->n_rules)
13790 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
13794 for (i = 0; i < rdev->coalesce->n_rules; i++) {
13795 nl_rule = nla_nest_start_noflag(msg, i + 1);
13799 rule = &rdev->coalesce->rules[i];
13800 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
13804 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
13808 nl_pats = nla_nest_start_noflag(msg,
13809 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
13813 for (j = 0; j < rule->n_patterns; j++) {
13814 nl_pat = nla_nest_start_noflag(msg, j + 1);
13817 pat_len = rule->patterns[j].pattern_len;
13818 if (nla_put(msg, NL80211_PKTPAT_MASK,
13819 DIV_ROUND_UP(pat_len, 8),
13820 rule->patterns[j].mask) ||
13821 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
13822 rule->patterns[j].pattern) ||
13823 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
13824 rule->patterns[j].pkt_offset))
13826 nla_nest_end(msg, nl_pat);
13828 nla_nest_end(msg, nl_pats);
13829 nla_nest_end(msg, nl_rule);
13831 nla_nest_end(msg, nl_rules);
13836 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
13838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13839 struct sk_buff *msg;
13842 if (!rdev->wiphy.coalesce)
13843 return -EOPNOTSUPP;
13845 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13849 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13850 NL80211_CMD_GET_COALESCE);
13852 goto nla_put_failure;
13854 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
13855 goto nla_put_failure;
13857 genlmsg_end(msg, hdr);
13858 return genlmsg_reply(msg, info);
13865 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
13867 struct cfg80211_coalesce *coalesce = rdev->coalesce;
13869 struct cfg80211_coalesce_rules *rule;
13874 for (i = 0; i < coalesce->n_rules; i++) {
13875 rule = &coalesce->rules[i];
13876 for (j = 0; j < rule->n_patterns; j++)
13877 kfree(rule->patterns[j].mask);
13878 kfree(rule->patterns);
13880 kfree(coalesce->rules);
13882 rdev->coalesce = NULL;
13885 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
13886 struct nlattr *rule,
13887 struct cfg80211_coalesce_rules *new_rule)
13890 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
13891 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
13892 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
13893 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
13895 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
13896 rule, nl80211_coalesce_policy, NULL);
13900 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
13902 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
13903 if (new_rule->delay > coalesce->max_delay)
13906 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
13907 new_rule->condition =
13908 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
13910 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
13913 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
13916 if (n_patterns > coalesce->n_patterns)
13919 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
13921 if (!new_rule->patterns)
13924 new_rule->n_patterns = n_patterns;
13927 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
13931 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
13933 nl80211_packet_pattern_policy,
13938 if (!pat_tb[NL80211_PKTPAT_MASK] ||
13939 !pat_tb[NL80211_PKTPAT_PATTERN])
13941 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
13942 mask_len = DIV_ROUND_UP(pat_len, 8);
13943 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
13945 if (pat_len > coalesce->pattern_max_len ||
13946 pat_len < coalesce->pattern_min_len)
13949 if (!pat_tb[NL80211_PKTPAT_OFFSET])
13952 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
13953 if (pkt_offset > coalesce->max_pkt_offset)
13955 new_rule->patterns[i].pkt_offset = pkt_offset;
13957 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
13961 new_rule->patterns[i].mask = mask_pat;
13962 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
13965 mask_pat += mask_len;
13966 new_rule->patterns[i].pattern = mask_pat;
13967 new_rule->patterns[i].pattern_len = pat_len;
13968 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
13976 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
13978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13979 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
13980 struct cfg80211_coalesce new_coalesce = {};
13981 struct cfg80211_coalesce *n_coalesce;
13982 int err, rem_rule, n_rules = 0, i, j;
13983 struct nlattr *rule;
13984 struct cfg80211_coalesce_rules *tmp_rule;
13986 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
13987 return -EOPNOTSUPP;
13989 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
13990 cfg80211_rdev_free_coalesce(rdev);
13991 rdev_set_coalesce(rdev, NULL);
13995 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
13998 if (n_rules > coalesce->n_rules)
14001 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
14003 if (!new_coalesce.rules)
14006 new_coalesce.n_rules = n_rules;
14009 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
14011 err = nl80211_parse_coalesce_rule(rdev, rule,
14012 &new_coalesce.rules[i]);
14019 err = rdev_set_coalesce(rdev, &new_coalesce);
14023 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
14028 cfg80211_rdev_free_coalesce(rdev);
14029 rdev->coalesce = n_coalesce;
14033 for (i = 0; i < new_coalesce.n_rules; i++) {
14034 tmp_rule = &new_coalesce.rules[i];
14035 for (j = 0; j < tmp_rule->n_patterns; j++)
14036 kfree(tmp_rule->patterns[j].mask);
14037 kfree(tmp_rule->patterns);
14039 kfree(new_coalesce.rules);
14044 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
14046 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14047 struct net_device *dev = info->user_ptr[1];
14048 struct wireless_dev *wdev = dev->ieee80211_ptr;
14049 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
14050 struct cfg80211_gtk_rekey_data rekey_data = {};
14053 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
14056 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
14057 info->attrs[NL80211_ATTR_REKEY_DATA],
14058 nl80211_rekey_policy, info->extack);
14062 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
14063 !tb[NL80211_REKEY_DATA_KCK])
14065 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN &&
14066 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
14067 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN))
14069 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN &&
14070 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
14071 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN) &&
14072 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KCK_32 &&
14073 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN_32))
14076 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
14077 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
14078 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
14079 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
14080 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]);
14081 if (tb[NL80211_REKEY_DATA_AKM])
14082 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]);
14085 if (!wdev->connected) {
14090 if (!rdev->ops->set_rekey_data) {
14095 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
14101 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
14102 struct genl_info *info)
14104 struct net_device *dev = info->user_ptr[1];
14105 struct wireless_dev *wdev = dev->ieee80211_ptr;
14107 if (wdev->iftype != NL80211_IFTYPE_AP &&
14108 wdev->iftype != NL80211_IFTYPE_P2P_GO)
14111 if (wdev->ap_unexpected_nlportid)
14114 wdev->ap_unexpected_nlportid = info->snd_portid;
14118 static int nl80211_probe_client(struct sk_buff *skb,
14119 struct genl_info *info)
14121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14122 struct net_device *dev = info->user_ptr[1];
14123 struct wireless_dev *wdev = dev->ieee80211_ptr;
14124 struct sk_buff *msg;
14130 if (wdev->iftype != NL80211_IFTYPE_AP &&
14131 wdev->iftype != NL80211_IFTYPE_P2P_GO)
14132 return -EOPNOTSUPP;
14134 if (!info->attrs[NL80211_ATTR_MAC])
14137 if (!rdev->ops->probe_client)
14138 return -EOPNOTSUPP;
14140 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14144 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14145 NL80211_CMD_PROBE_CLIENT);
14151 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
14153 err = rdev_probe_client(rdev, dev, addr, &cookie);
14157 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14159 goto nla_put_failure;
14161 genlmsg_end(msg, hdr);
14163 return genlmsg_reply(msg, info);
14172 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
14174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14175 struct cfg80211_beacon_registration *reg, *nreg;
14178 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
14179 return -EOPNOTSUPP;
14181 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
14185 /* First, check if already registered. */
14186 spin_lock_bh(&rdev->beacon_registrations_lock);
14187 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14188 if (reg->nlportid == info->snd_portid) {
14193 /* Add it to the list */
14194 nreg->nlportid = info->snd_portid;
14195 list_add(&nreg->list, &rdev->beacon_registrations);
14197 spin_unlock_bh(&rdev->beacon_registrations_lock);
14201 spin_unlock_bh(&rdev->beacon_registrations_lock);
14206 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
14208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14209 struct wireless_dev *wdev = info->user_ptr[1];
14212 if (!rdev->ops->start_p2p_device)
14213 return -EOPNOTSUPP;
14215 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
14216 return -EOPNOTSUPP;
14218 if (wdev_running(wdev))
14221 if (rfkill_blocked(rdev->wiphy.rfkill))
14224 err = rdev_start_p2p_device(rdev, wdev);
14228 wdev->is_running = true;
14234 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
14236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14237 struct wireless_dev *wdev = info->user_ptr[1];
14239 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
14240 return -EOPNOTSUPP;
14242 if (!rdev->ops->stop_p2p_device)
14243 return -EOPNOTSUPP;
14245 cfg80211_stop_p2p_device(rdev, wdev);
14250 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
14252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14253 struct wireless_dev *wdev = info->user_ptr[1];
14254 struct cfg80211_nan_conf conf = {};
14257 if (wdev->iftype != NL80211_IFTYPE_NAN)
14258 return -EOPNOTSUPP;
14260 if (wdev_running(wdev))
14263 if (rfkill_blocked(rdev->wiphy.rfkill))
14266 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
14270 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
14272 if (info->attrs[NL80211_ATTR_BANDS]) {
14273 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
14275 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
14276 return -EOPNOTSUPP;
14278 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
14281 conf.bands = bands;
14284 err = rdev_start_nan(rdev, wdev, &conf);
14288 wdev->is_running = true;
14294 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
14296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14297 struct wireless_dev *wdev = info->user_ptr[1];
14299 if (wdev->iftype != NL80211_IFTYPE_NAN)
14300 return -EOPNOTSUPP;
14302 cfg80211_stop_nan(rdev, wdev);
14307 static int validate_nan_filter(struct nlattr *filter_attr)
14309 struct nlattr *attr;
14310 int len = 0, n_entries = 0, rem;
14312 nla_for_each_nested(attr, filter_attr, rem) {
14313 len += nla_len(attr);
14323 static int handle_nan_filter(struct nlattr *attr_filter,
14324 struct cfg80211_nan_func *func,
14327 struct nlattr *attr;
14328 int n_entries, rem, i;
14329 struct cfg80211_nan_func_filter *filter;
14331 n_entries = validate_nan_filter(attr_filter);
14335 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
14337 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
14342 nla_for_each_nested(attr, attr_filter, rem) {
14343 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
14344 if (!filter[i].filter)
14347 filter[i].len = nla_len(attr);
14351 func->num_tx_filters = n_entries;
14352 func->tx_filters = filter;
14354 func->num_rx_filters = n_entries;
14355 func->rx_filters = filter;
14362 nla_for_each_nested(attr, attr_filter, rem) {
14363 kfree(filter[i].filter);
14370 static int nl80211_nan_add_func(struct sk_buff *skb,
14371 struct genl_info *info)
14373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14374 struct wireless_dev *wdev = info->user_ptr[1];
14375 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
14376 struct cfg80211_nan_func *func;
14377 struct sk_buff *msg = NULL;
14381 if (wdev->iftype != NL80211_IFTYPE_NAN)
14382 return -EOPNOTSUPP;
14384 if (!wdev_running(wdev))
14387 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
14390 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
14391 info->attrs[NL80211_ATTR_NAN_FUNC],
14392 nl80211_nan_func_policy,
14397 func = kzalloc(sizeof(*func), GFP_KERNEL);
14401 func->cookie = cfg80211_assign_cookie(rdev);
14403 if (!tb[NL80211_NAN_FUNC_TYPE]) {
14409 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
14411 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
14416 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
14417 sizeof(func->service_id));
14419 func->close_range =
14420 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
14422 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
14423 func->serv_spec_info_len =
14424 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
14425 func->serv_spec_info =
14426 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
14427 func->serv_spec_info_len,
14429 if (!func->serv_spec_info) {
14435 if (tb[NL80211_NAN_FUNC_TTL])
14436 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
14438 switch (func->type) {
14439 case NL80211_NAN_FUNC_PUBLISH:
14440 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
14445 func->publish_type =
14446 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
14447 func->publish_bcast =
14448 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
14450 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
14451 func->publish_bcast) {
14456 case NL80211_NAN_FUNC_SUBSCRIBE:
14457 func->subscribe_active =
14458 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
14460 case NL80211_NAN_FUNC_FOLLOW_UP:
14461 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
14462 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
14463 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
14468 func->followup_id =
14469 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
14470 func->followup_reqid =
14471 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
14472 memcpy(func->followup_dest.addr,
14473 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
14474 sizeof(func->followup_dest.addr));
14485 if (tb[NL80211_NAN_FUNC_SRF]) {
14486 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
14488 err = nla_parse_nested_deprecated(srf_tb,
14489 NL80211_NAN_SRF_ATTR_MAX,
14490 tb[NL80211_NAN_FUNC_SRF],
14491 nl80211_nan_srf_policy,
14496 func->srf_include =
14497 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
14499 if (srf_tb[NL80211_NAN_SRF_BF]) {
14500 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
14501 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
14507 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
14509 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
14510 func->srf_bf_len, GFP_KERNEL);
14511 if (!func->srf_bf) {
14517 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
14519 struct nlattr *attr, *mac_attr =
14520 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
14521 int n_entries, rem, i = 0;
14528 n_entries = validate_acl_mac_addrs(mac_attr);
14529 if (n_entries <= 0) {
14534 func->srf_num_macs = n_entries;
14536 kcalloc(n_entries, sizeof(*func->srf_macs),
14538 if (!func->srf_macs) {
14543 nla_for_each_nested(attr, mac_attr, rem)
14544 memcpy(func->srf_macs[i++].addr, nla_data(attr),
14545 sizeof(*func->srf_macs));
14549 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
14550 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
14556 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
14557 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
14563 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14569 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14570 NL80211_CMD_ADD_NAN_FUNCTION);
14571 /* This can't really happen - we just allocated 4KB */
14572 if (WARN_ON(!hdr)) {
14577 err = rdev_add_nan_func(rdev, wdev, func);
14580 cfg80211_free_nan_func(func);
14585 /* propagate the instance id and cookie to userspace */
14586 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
14588 goto nla_put_failure;
14590 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
14592 goto nla_put_failure;
14594 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
14595 func->instance_id))
14596 goto nla_put_failure;
14598 nla_nest_end(msg, func_attr);
14600 genlmsg_end(msg, hdr);
14601 return genlmsg_reply(msg, info);
14608 static int nl80211_nan_del_func(struct sk_buff *skb,
14609 struct genl_info *info)
14611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14612 struct wireless_dev *wdev = info->user_ptr[1];
14615 if (wdev->iftype != NL80211_IFTYPE_NAN)
14616 return -EOPNOTSUPP;
14618 if (!wdev_running(wdev))
14621 if (!info->attrs[NL80211_ATTR_COOKIE])
14624 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
14626 rdev_del_nan_func(rdev, wdev, cookie);
14631 static int nl80211_nan_change_config(struct sk_buff *skb,
14632 struct genl_info *info)
14634 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14635 struct wireless_dev *wdev = info->user_ptr[1];
14636 struct cfg80211_nan_conf conf = {};
14639 if (wdev->iftype != NL80211_IFTYPE_NAN)
14640 return -EOPNOTSUPP;
14642 if (!wdev_running(wdev))
14645 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
14647 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
14648 if (conf.master_pref <= 1 || conf.master_pref == 255)
14651 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
14654 if (info->attrs[NL80211_ATTR_BANDS]) {
14655 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
14657 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
14658 return -EOPNOTSUPP;
14660 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
14663 conf.bands = bands;
14664 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
14670 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
14673 void cfg80211_nan_match(struct wireless_dev *wdev,
14674 struct cfg80211_nan_match_params *match, gfp_t gfp)
14676 struct wiphy *wiphy = wdev->wiphy;
14677 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14678 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
14679 struct sk_buff *msg;
14682 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
14685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14689 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
14695 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14696 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14697 wdev->netdev->ifindex)) ||
14698 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14700 goto nla_put_failure;
14702 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
14703 NL80211_ATTR_PAD) ||
14704 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
14705 goto nla_put_failure;
14707 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
14709 goto nla_put_failure;
14711 local_func_attr = nla_nest_start_noflag(msg,
14712 NL80211_NAN_MATCH_FUNC_LOCAL);
14713 if (!local_func_attr)
14714 goto nla_put_failure;
14716 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
14717 goto nla_put_failure;
14719 nla_nest_end(msg, local_func_attr);
14721 peer_func_attr = nla_nest_start_noflag(msg,
14722 NL80211_NAN_MATCH_FUNC_PEER);
14723 if (!peer_func_attr)
14724 goto nla_put_failure;
14726 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
14727 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
14728 goto nla_put_failure;
14730 if (match->info && match->info_len &&
14731 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
14733 goto nla_put_failure;
14735 nla_nest_end(msg, peer_func_attr);
14736 nla_nest_end(msg, match_attr);
14737 genlmsg_end(msg, hdr);
14739 if (!wdev->owner_nlportid)
14740 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
14741 msg, 0, NL80211_MCGRP_NAN, gfp);
14743 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
14744 wdev->owner_nlportid);
14751 EXPORT_SYMBOL(cfg80211_nan_match);
14753 void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
14755 enum nl80211_nan_func_term_reason reason,
14756 u64 cookie, gfp_t gfp)
14758 struct wiphy *wiphy = wdev->wiphy;
14759 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14760 struct sk_buff *msg;
14761 struct nlattr *func_attr;
14764 if (WARN_ON(!inst_id))
14767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14771 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
14777 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14778 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14779 wdev->netdev->ifindex)) ||
14780 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14782 goto nla_put_failure;
14784 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14786 goto nla_put_failure;
14788 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
14790 goto nla_put_failure;
14792 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
14793 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
14794 goto nla_put_failure;
14796 nla_nest_end(msg, func_attr);
14797 genlmsg_end(msg, hdr);
14799 if (!wdev->owner_nlportid)
14800 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
14801 msg, 0, NL80211_MCGRP_NAN, gfp);
14803 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
14804 wdev->owner_nlportid);
14811 EXPORT_SYMBOL(cfg80211_nan_func_terminated);
14813 static int nl80211_get_protocol_features(struct sk_buff *skb,
14814 struct genl_info *info)
14817 struct sk_buff *msg;
14819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14823 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14824 NL80211_CMD_GET_PROTOCOL_FEATURES);
14826 goto nla_put_failure;
14828 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
14829 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
14830 goto nla_put_failure;
14832 genlmsg_end(msg, hdr);
14833 return genlmsg_reply(msg, info);
14840 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
14842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14843 struct cfg80211_update_ft_ies_params ft_params;
14844 struct net_device *dev = info->user_ptr[1];
14846 if (!rdev->ops->update_ft_ies)
14847 return -EOPNOTSUPP;
14849 if (!info->attrs[NL80211_ATTR_MDID] ||
14850 !info->attrs[NL80211_ATTR_IE])
14853 memset(&ft_params, 0, sizeof(ft_params));
14854 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
14855 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
14856 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
14858 return rdev_update_ft_ies(rdev, dev, &ft_params);
14861 static int nl80211_crit_protocol_start(struct sk_buff *skb,
14862 struct genl_info *info)
14864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14865 struct wireless_dev *wdev = info->user_ptr[1];
14866 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
14870 if (!rdev->ops->crit_proto_start)
14871 return -EOPNOTSUPP;
14873 if (WARN_ON(!rdev->ops->crit_proto_stop))
14876 if (rdev->crit_proto_nlportid)
14879 /* determine protocol if provided */
14880 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
14881 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
14883 if (proto >= NUM_NL80211_CRIT_PROTO)
14886 /* timeout must be provided */
14887 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
14891 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
14893 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
14895 rdev->crit_proto_nlportid = info->snd_portid;
14900 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
14901 struct genl_info *info)
14903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14904 struct wireless_dev *wdev = info->user_ptr[1];
14906 if (!rdev->ops->crit_proto_stop)
14907 return -EOPNOTSUPP;
14909 if (rdev->crit_proto_nlportid) {
14910 rdev->crit_proto_nlportid = 0;
14911 rdev_crit_proto_stop(rdev, wdev);
14916 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
14917 struct nlattr *attr,
14918 struct netlink_ext_ack *extack)
14920 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
14921 if (attr->nla_type & NLA_F_NESTED) {
14922 NL_SET_ERR_MSG_ATTR(extack, attr,
14923 "unexpected nested data");
14930 if (!(attr->nla_type & NLA_F_NESTED)) {
14931 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
14935 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
14938 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
14940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14941 struct wireless_dev *wdev =
14942 __cfg80211_wdev_from_attrs(rdev, genl_info_net(info),
14947 if (!rdev->wiphy.vendor_commands)
14948 return -EOPNOTSUPP;
14950 if (IS_ERR(wdev)) {
14951 err = PTR_ERR(wdev);
14952 if (err != -EINVAL)
14955 } else if (wdev->wiphy != &rdev->wiphy) {
14959 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
14960 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
14963 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
14964 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
14965 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
14966 const struct wiphy_vendor_command *vcmd;
14970 vcmd = &rdev->wiphy.vendor_commands[i];
14972 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
14975 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
14976 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
14979 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
14983 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
14984 if (!wdev_running(wdev))
14992 return -EOPNOTSUPP;
14994 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
14995 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
14996 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
14998 err = nl80211_vendor_check_policy(vcmd,
14999 info->attrs[NL80211_ATTR_VENDOR_DATA],
15005 rdev->cur_cmd_info = info;
15006 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
15007 rdev->cur_cmd_info = NULL;
15011 return -EOPNOTSUPP;
15014 static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
15015 struct netlink_callback *cb,
15016 struct cfg80211_registered_device **rdev,
15017 struct wireless_dev **wdev)
15019 struct nlattr **attrbuf;
15025 unsigned int data_len = 0;
15028 /* subtract the 1 again here */
15029 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
15030 struct wireless_dev *tmp;
15034 *rdev = wiphy_to_rdev(wiphy);
15038 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
15039 if (tmp->identifier == cb->args[1] - 1) {
15046 /* keep rtnl locked in successful case */
15050 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
15054 err = nlmsg_parse_deprecated(cb->nlh,
15055 GENL_HDRLEN + nl80211_fam.hdrsize,
15056 attrbuf, nl80211_fam.maxattr,
15057 nl80211_policy, NULL);
15061 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
15062 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
15067 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf);
15071 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
15072 if (IS_ERR(*rdev)) {
15073 err = PTR_ERR(*rdev);
15077 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
15078 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
15080 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
15081 const struct wiphy_vendor_command *vcmd;
15083 vcmd = &(*rdev)->wiphy.vendor_commands[i];
15085 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
15088 if (!vcmd->dumpit) {
15097 if (vcmd_idx < 0) {
15102 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
15103 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
15104 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
15106 err = nl80211_vendor_check_policy(
15107 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
15108 attrbuf[NL80211_ATTR_VENDOR_DATA],
15114 /* 0 is the first index - add 1 to parse only once */
15115 cb->args[0] = (*rdev)->wiphy_idx + 1;
15116 /* add 1 to know if it was NULL */
15117 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
15118 cb->args[2] = vcmd_idx;
15119 cb->args[3] = (unsigned long)data;
15120 cb->args[4] = data_len;
15122 /* keep rtnl locked in successful case */
15129 static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
15130 struct netlink_callback *cb)
15132 struct cfg80211_registered_device *rdev;
15133 struct wireless_dev *wdev;
15134 unsigned int vcmd_idx;
15135 const struct wiphy_vendor_command *vcmd;
15139 struct nlattr *vendor_data;
15142 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
15146 vcmd_idx = cb->args[2];
15147 data = (void *)cb->args[3];
15148 data_len = cb->args[4];
15149 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
15151 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
15152 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
15157 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
15163 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
15164 if (!wdev_running(wdev)) {
15172 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
15173 cb->nlh->nlmsg_seq, NLM_F_MULTI,
15174 NL80211_CMD_VENDOR);
15178 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15179 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
15181 NL80211_ATTR_PAD))) {
15182 genlmsg_cancel(skb, hdr);
15186 vendor_data = nla_nest_start_noflag(skb,
15187 NL80211_ATTR_VENDOR_DATA);
15188 if (!vendor_data) {
15189 genlmsg_cancel(skb, hdr);
15193 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
15194 (unsigned long *)&cb->args[5]);
15195 nla_nest_end(skb, vendor_data);
15197 if (err == -ENOBUFS || err == -ENOENT) {
15198 genlmsg_cancel(skb, hdr);
15200 } else if (err <= 0) {
15201 genlmsg_cancel(skb, hdr);
15205 genlmsg_end(skb, hdr);
15214 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
15215 enum nl80211_commands cmd,
15216 enum nl80211_attrs attr,
15219 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15221 if (WARN_ON(!rdev->cur_cmd_info))
15224 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
15225 rdev->cur_cmd_info->snd_portid,
15226 rdev->cur_cmd_info->snd_seq,
15227 cmd, attr, NULL, GFP_KERNEL);
15229 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
15231 int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
15233 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
15234 void *hdr = ((void **)skb->cb)[1];
15235 struct nlattr *data = ((void **)skb->cb)[2];
15237 /* clear CB data for netlink core to own from now on */
15238 memset(skb->cb, 0, sizeof(skb->cb));
15240 if (WARN_ON(!rdev->cur_cmd_info)) {
15245 nla_nest_end(skb, data);
15246 genlmsg_end(skb, hdr);
15247 return genlmsg_reply(skb, rdev->cur_cmd_info);
15249 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
15251 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
15253 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15255 if (WARN_ON(!rdev->cur_cmd_info))
15258 return rdev->cur_cmd_info->snd_portid;
15260 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
15262 static int nl80211_set_qos_map(struct sk_buff *skb,
15263 struct genl_info *info)
15265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15266 struct cfg80211_qos_map *qos_map = NULL;
15267 struct net_device *dev = info->user_ptr[1];
15268 u8 *pos, len, num_des, des_len, des;
15271 if (!rdev->ops->set_qos_map)
15272 return -EOPNOTSUPP;
15274 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
15275 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
15276 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
15281 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
15285 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
15287 des_len = num_des *
15288 sizeof(struct cfg80211_dscp_exception);
15289 memcpy(qos_map->dscp_exception, pos, des_len);
15290 qos_map->num_des = num_des;
15291 for (des = 0; des < num_des; des++) {
15292 if (qos_map->dscp_exception[des].up > 7) {
15299 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
15302 wdev_lock(dev->ieee80211_ptr);
15303 ret = nl80211_key_allowed(dev->ieee80211_ptr);
15305 ret = rdev_set_qos_map(rdev, dev, qos_map);
15306 wdev_unlock(dev->ieee80211_ptr);
15312 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
15314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15315 struct net_device *dev = info->user_ptr[1];
15316 struct wireless_dev *wdev = dev->ieee80211_ptr;
15319 u16 admitted_time = 0;
15322 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
15323 return -EOPNOTSUPP;
15325 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
15326 !info->attrs[NL80211_ATTR_USER_PRIO])
15329 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
15330 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
15332 /* WMM uses TIDs 0-7 even for TSPEC */
15333 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
15334 /* TODO: handle 802.11 TSPEC/admission control
15335 * need more attributes for that (e.g. BA session requirement);
15336 * change the WMM adminssion test above to allow both then
15341 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15343 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
15345 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
15346 if (!admitted_time)
15351 switch (wdev->iftype) {
15352 case NL80211_IFTYPE_STATION:
15353 case NL80211_IFTYPE_P2P_CLIENT:
15354 if (wdev->connected)
15363 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
15370 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
15372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15373 struct net_device *dev = info->user_ptr[1];
15374 struct wireless_dev *wdev = dev->ieee80211_ptr;
15379 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
15382 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
15383 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15386 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
15392 static int nl80211_tdls_channel_switch(struct sk_buff *skb,
15393 struct genl_info *info)
15395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15396 struct net_device *dev = info->user_ptr[1];
15397 struct wireless_dev *wdev = dev->ieee80211_ptr;
15398 struct cfg80211_chan_def chandef = {};
15403 if (!rdev->ops->tdls_channel_switch ||
15404 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
15405 return -EOPNOTSUPP;
15407 switch (dev->ieee80211_ptr->iftype) {
15408 case NL80211_IFTYPE_STATION:
15409 case NL80211_IFTYPE_P2P_CLIENT:
15412 return -EOPNOTSUPP;
15415 if (!info->attrs[NL80211_ATTR_MAC] ||
15416 !info->attrs[NL80211_ATTR_OPER_CLASS])
15419 err = nl80211_parse_chandef(rdev, info, &chandef);
15424 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
15425 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
15426 * specification is not defined for them.
15428 if (chandef.chan->band == NL80211_BAND_2GHZ &&
15429 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
15430 chandef.width != NL80211_CHAN_WIDTH_20)
15433 /* we will be active on the TDLS link */
15434 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
15438 /* don't allow switching to DFS channels */
15439 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
15442 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
15443 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
15446 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
15452 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
15453 struct genl_info *info)
15455 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15456 struct net_device *dev = info->user_ptr[1];
15457 struct wireless_dev *wdev = dev->ieee80211_ptr;
15460 if (!rdev->ops->tdls_channel_switch ||
15461 !rdev->ops->tdls_cancel_channel_switch ||
15462 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
15463 return -EOPNOTSUPP;
15465 switch (dev->ieee80211_ptr->iftype) {
15466 case NL80211_IFTYPE_STATION:
15467 case NL80211_IFTYPE_P2P_CLIENT:
15470 return -EOPNOTSUPP;
15473 if (!info->attrs[NL80211_ATTR_MAC])
15476 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
15479 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
15485 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
15486 struct genl_info *info)
15488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15489 struct net_device *dev = info->user_ptr[1];
15490 struct wireless_dev *wdev = dev->ieee80211_ptr;
15491 const struct nlattr *nla;
15494 if (!rdev->ops->set_multicast_to_unicast)
15495 return -EOPNOTSUPP;
15497 if (wdev->iftype != NL80211_IFTYPE_AP &&
15498 wdev->iftype != NL80211_IFTYPE_P2P_GO)
15499 return -EOPNOTSUPP;
15501 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
15502 enabled = nla_get_flag(nla);
15504 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
15507 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
15509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15510 struct net_device *dev = info->user_ptr[1];
15511 struct wireless_dev *wdev = dev->ieee80211_ptr;
15512 struct cfg80211_pmk_conf pmk_conf = {};
15515 if (wdev->iftype != NL80211_IFTYPE_STATION &&
15516 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
15517 return -EOPNOTSUPP;
15519 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15520 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
15521 return -EOPNOTSUPP;
15523 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
15527 if (!wdev->connected) {
15532 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
15533 if (memcmp(pmk_conf.aa, wdev->u.client.connected_addr, ETH_ALEN)) {
15538 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
15539 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
15540 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
15541 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
15546 if (info->attrs[NL80211_ATTR_PMKR0_NAME])
15547 pmk_conf.pmk_r0_name =
15548 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
15550 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
15556 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
15558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15559 struct net_device *dev = info->user_ptr[1];
15560 struct wireless_dev *wdev = dev->ieee80211_ptr;
15564 if (wdev->iftype != NL80211_IFTYPE_STATION &&
15565 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
15566 return -EOPNOTSUPP;
15568 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15569 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
15570 return -EOPNOTSUPP;
15572 if (!info->attrs[NL80211_ATTR_MAC])
15576 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
15577 ret = rdev_del_pmk(rdev, dev, aa);
15583 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
15585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15586 struct net_device *dev = info->user_ptr[1];
15587 struct cfg80211_external_auth_params params;
15589 if (!rdev->ops->external_auth)
15590 return -EOPNOTSUPP;
15592 if (!info->attrs[NL80211_ATTR_SSID] &&
15593 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
15594 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
15597 if (!info->attrs[NL80211_ATTR_BSSID])
15600 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
15603 memset(¶ms, 0, sizeof(params));
15605 if (info->attrs[NL80211_ATTR_SSID]) {
15606 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
15607 if (params.ssid.ssid_len == 0)
15609 memcpy(params.ssid.ssid,
15610 nla_data(info->attrs[NL80211_ATTR_SSID]),
15611 params.ssid.ssid_len);
15614 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
15617 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
15619 if (info->attrs[NL80211_ATTR_PMKID])
15620 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
15622 return rdev_external_auth(rdev, dev, ¶ms);
15625 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
15627 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
15628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15629 struct net_device *dev = info->user_ptr[1];
15630 struct wireless_dev *wdev = dev->ieee80211_ptr;
15640 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15641 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
15642 return -EOPNOTSUPP;
15644 if (!rdev->ops->tx_control_port)
15645 return -EOPNOTSUPP;
15647 if (!info->attrs[NL80211_ATTR_FRAME] ||
15648 !info->attrs[NL80211_ATTR_MAC] ||
15649 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
15650 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
15656 switch (wdev->iftype) {
15657 case NL80211_IFTYPE_AP:
15658 case NL80211_IFTYPE_P2P_GO:
15659 case NL80211_IFTYPE_MESH_POINT:
15661 case NL80211_IFTYPE_ADHOC:
15662 if (wdev->u.ibss.current_bss)
15666 case NL80211_IFTYPE_STATION:
15667 case NL80211_IFTYPE_P2P_CLIENT:
15668 if (wdev->connected)
15679 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
15680 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
15681 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
15682 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
15684 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
15686 link_id = nl80211_link_id_or_invalid(info->attrs);
15688 err = rdev_tx_control_port(rdev, dev, buf, len,
15689 dest, cpu_to_be16(proto), noencrypt, link_id,
15690 dont_wait_for_ack ? NULL : &cookie);
15691 if (!err && !dont_wait_for_ack)
15692 nl_set_extack_cookie_u64(info->extack, cookie);
15699 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
15700 struct genl_info *info)
15702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15703 struct net_device *dev = info->user_ptr[1];
15704 struct wireless_dev *wdev = dev->ieee80211_ptr;
15705 struct cfg80211_ftm_responder_stats ftm_stats = {};
15706 unsigned int link_id = nl80211_link_id(info->attrs);
15707 struct sk_buff *msg;
15709 struct nlattr *ftm_stats_attr;
15712 if (wdev->iftype != NL80211_IFTYPE_AP ||
15713 !wdev->links[link_id].ap.beacon_interval)
15714 return -EOPNOTSUPP;
15716 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
15720 if (!ftm_stats.filled)
15723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15727 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
15728 NL80211_CMD_GET_FTM_RESPONDER_STATS);
15730 goto nla_put_failure;
15732 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15733 goto nla_put_failure;
15735 ftm_stats_attr = nla_nest_start_noflag(msg,
15736 NL80211_ATTR_FTM_RESPONDER_STATS);
15737 if (!ftm_stats_attr)
15738 goto nla_put_failure;
15740 #define SET_FTM(field, name, type) \
15741 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
15742 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
15743 ftm_stats.field)) \
15744 goto nla_put_failure; } while (0)
15745 #define SET_FTM_U64(field, name) \
15746 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
15747 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
15748 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
15749 goto nla_put_failure; } while (0)
15751 SET_FTM(success_num, SUCCESS_NUM, u32);
15752 SET_FTM(partial_num, PARTIAL_NUM, u32);
15753 SET_FTM(failed_num, FAILED_NUM, u32);
15754 SET_FTM(asap_num, ASAP_NUM, u32);
15755 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
15756 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
15757 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
15758 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
15759 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
15762 nla_nest_end(msg, ftm_stats_attr);
15764 genlmsg_end(msg, hdr);
15765 return genlmsg_reply(msg, info);
15772 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
15774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15775 struct cfg80211_update_owe_info owe_info;
15776 struct net_device *dev = info->user_ptr[1];
15778 if (!rdev->ops->update_owe_info)
15779 return -EOPNOTSUPP;
15781 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
15782 !info->attrs[NL80211_ATTR_MAC])
15785 memset(&owe_info, 0, sizeof(owe_info));
15786 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
15787 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
15789 if (info->attrs[NL80211_ATTR_IE]) {
15790 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
15791 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
15794 return rdev_update_owe_info(rdev, dev, &owe_info);
15797 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
15799 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15800 struct net_device *dev = info->user_ptr[1];
15801 struct wireless_dev *wdev = dev->ieee80211_ptr;
15802 struct station_info sinfo = {};
15808 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
15809 return -EOPNOTSUPP;
15811 if (!info->attrs[NL80211_ATTR_MAC] ||
15812 !info->attrs[NL80211_ATTR_FRAME]) {
15813 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
15817 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
15818 return -EOPNOTSUPP;
15820 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
15821 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
15822 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
15824 if (len < sizeof(struct ethhdr))
15827 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
15828 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
15831 err = rdev_get_station(rdev, dev, dest, &sinfo);
15835 cfg80211_sinfo_release_content(&sinfo);
15837 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
15840 static int parse_tid_conf(struct cfg80211_registered_device *rdev,
15841 struct nlattr *attrs[], struct net_device *dev,
15842 struct cfg80211_tid_cfg *tid_conf,
15843 struct genl_info *info, const u8 *peer,
15844 unsigned int link_id)
15846 struct netlink_ext_ack *extack = info->extack;
15850 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS])
15853 tid_conf->config_override =
15854 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]);
15855 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
15857 if (tid_conf->config_override) {
15858 if (rdev->ops->reset_tid_config) {
15859 err = rdev_reset_tid_config(rdev, dev, peer,
15868 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
15869 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
15871 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
15874 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) {
15875 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT);
15876 tid_conf->retry_short =
15877 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]);
15879 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count)
15883 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) {
15884 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
15885 tid_conf->retry_long =
15886 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]);
15888 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count)
15892 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) {
15893 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
15895 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]);
15898 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) {
15899 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
15901 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]);
15904 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) {
15905 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL);
15907 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]);
15910 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) {
15911 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr;
15913 tid_conf->txrate_type = nla_get_u8(attrs[idx]);
15915 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) {
15916 attr = NL80211_TID_CONFIG_ATTR_TX_RATE;
15917 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr,
15918 &tid_conf->txrate_mask, dev,
15923 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE);
15925 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
15929 mask = rdev->wiphy.tid_config_support.peer;
15931 mask = rdev->wiphy.tid_config_support.vif;
15933 if (tid_conf->mask & ~mask) {
15934 NL_SET_ERR_MSG(extack, "unsupported TID configuration");
15941 static int nl80211_set_tid_config(struct sk_buff *skb,
15942 struct genl_info *info)
15944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15945 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1];
15946 unsigned int link_id = nl80211_link_id(info->attrs);
15947 struct net_device *dev = info->user_ptr[1];
15948 struct cfg80211_tid_config *tid_config;
15949 struct nlattr *tid;
15950 int conf_idx = 0, rem_conf;
15954 if (!info->attrs[NL80211_ATTR_TID_CONFIG])
15957 if (!rdev->ops->set_tid_config)
15958 return -EOPNOTSUPP;
15960 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
15964 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf),
15969 tid_config->n_tid_conf = num_conf;
15971 if (info->attrs[NL80211_ATTR_MAC])
15972 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15974 wdev_lock(dev->ieee80211_ptr);
15976 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
15978 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX,
15984 ret = parse_tid_conf(rdev, attrs, dev,
15985 &tid_config->tid_conf[conf_idx],
15986 info, tid_config->peer, link_id);
15993 ret = rdev_set_tid_config(rdev, dev, tid_config);
15997 wdev_unlock(dev->ieee80211_ptr);
16001 static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)
16003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16004 struct cfg80211_color_change_settings params = {};
16005 struct net_device *dev = info->user_ptr[1];
16006 struct wireless_dev *wdev = dev->ieee80211_ptr;
16007 struct nlattr **tb;
16011 if (!rdev->ops->color_change)
16012 return -EOPNOTSUPP;
16014 if (!wiphy_ext_feature_isset(&rdev->wiphy,
16015 NL80211_EXT_FEATURE_BSS_COLOR))
16016 return -EOPNOTSUPP;
16018 if (wdev->iftype != NL80211_IFTYPE_AP)
16019 return -EOPNOTSUPP;
16021 if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] ||
16022 !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] ||
16023 !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS])
16026 params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]);
16027 params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]);
16029 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next,
16034 tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL);
16038 err = nla_parse_nested(tb, NL80211_ATTR_MAX,
16039 info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS],
16040 nl80211_policy, info->extack);
16044 err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change,
16049 if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) {
16054 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) {
16059 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
16060 if (offset >= params.beacon_color_change.tail_len) {
16065 if (params.beacon_color_change.tail[offset] != params.count) {
16070 params.counter_offset_beacon = offset;
16072 if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
16073 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) !=
16079 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
16080 if (offset >= params.beacon_color_change.probe_resp_len) {
16085 if (params.beacon_color_change.probe_resp[offset] !=
16091 params.counter_offset_presp = offset;
16095 err = rdev_color_change(rdev, dev, ¶ms);
16099 kfree(params.beacon_next.mbssid_ies);
16100 kfree(params.beacon_color_change.mbssid_ies);
16101 kfree(params.beacon_next.rnr_ies);
16102 kfree(params.beacon_color_change.rnr_ies);
16107 static int nl80211_set_fils_aad(struct sk_buff *skb,
16108 struct genl_info *info)
16110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16111 struct net_device *dev = info->user_ptr[1];
16112 struct cfg80211_fils_aad fils_aad = {};
16115 if (!info->attrs[NL80211_ATTR_MAC] ||
16116 !info->attrs[NL80211_ATTR_FILS_KEK] ||
16117 !info->attrs[NL80211_ATTR_FILS_NONCES])
16120 fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]);
16121 fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
16122 fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
16123 nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
16124 fils_aad.snonce = nonces;
16125 fils_aad.anonce = nonces + FILS_NONCE_LEN;
16127 return rdev_set_fils_aad(rdev, dev, &fils_aad);
16130 static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info)
16132 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16133 unsigned int link_id = nl80211_link_id(info->attrs);
16134 struct net_device *dev = info->user_ptr[1];
16135 struct wireless_dev *wdev = dev->ieee80211_ptr;
16138 if (!(wdev->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
16141 switch (wdev->iftype) {
16142 case NL80211_IFTYPE_AP:
16148 if (!info->attrs[NL80211_ATTR_MAC] ||
16149 !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC])))
16153 wdev->valid_links |= BIT(link_id);
16154 ether_addr_copy(wdev->links[link_id].addr,
16155 nla_data(info->attrs[NL80211_ATTR_MAC]));
16157 ret = rdev_add_intf_link(rdev, wdev, link_id);
16159 wdev->valid_links &= ~BIT(link_id);
16160 eth_zero_addr(wdev->links[link_id].addr);
16167 static int nl80211_remove_link(struct sk_buff *skb, struct genl_info *info)
16169 unsigned int link_id = nl80211_link_id(info->attrs);
16170 struct net_device *dev = info->user_ptr[1];
16171 struct wireless_dev *wdev = dev->ieee80211_ptr;
16173 /* cannot remove if there's no link */
16174 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID])
16177 switch (wdev->iftype) {
16178 case NL80211_IFTYPE_AP:
16185 cfg80211_remove_link(wdev, link_id);
16192 nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info,
16195 struct link_station_parameters params = {};
16196 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16197 struct net_device *dev = info->user_ptr[1];
16200 if ((add && !rdev->ops->add_link_station) ||
16201 (!add && !rdev->ops->mod_link_station))
16202 return -EOPNOTSUPP;
16204 if (add && !info->attrs[NL80211_ATTR_MAC])
16207 if (!info->attrs[NL80211_ATTR_MLD_ADDR])
16210 if (add && !info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
16213 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
16215 if (info->attrs[NL80211_ATTR_MAC]) {
16216 params.link_mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
16217 if (!is_valid_ether_addr(params.link_mac))
16221 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID])
16224 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]);
16226 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
16227 params.supported_rates =
16228 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
16229 params.supported_rates_len =
16230 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
16233 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
16235 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
16237 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
16239 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
16241 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
16243 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
16244 params.he_capa_len =
16245 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
16247 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
16249 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
16250 params.eht_capa_len =
16251 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
16253 if (!ieee80211_eht_capa_size_ok((const u8 *)params.he_capa,
16254 (const u8 *)params.eht_capa,
16255 params.eht_capa_len,
16261 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
16262 params.he_6ghz_capa =
16263 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
16265 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
16266 params.opmode_notif_used = true;
16267 params.opmode_notif =
16268 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
16271 err = nl80211_parse_sta_txpower_setting(info, ¶ms.txpwr,
16272 ¶ms.txpwr_set);
16276 wdev_lock(dev->ieee80211_ptr);
16278 err = rdev_add_link_station(rdev, dev, ¶ms);
16280 err = rdev_mod_link_station(rdev, dev, ¶ms);
16281 wdev_unlock(dev->ieee80211_ptr);
16287 nl80211_add_link_station(struct sk_buff *skb, struct genl_info *info)
16289 return nl80211_add_mod_link_station(skb, info, true);
16293 nl80211_modify_link_station(struct sk_buff *skb, struct genl_info *info)
16295 return nl80211_add_mod_link_station(skb, info, false);
16299 nl80211_remove_link_station(struct sk_buff *skb, struct genl_info *info)
16301 struct link_station_del_parameters params = {};
16302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16303 struct net_device *dev = info->user_ptr[1];
16306 if (!rdev->ops->del_link_station)
16307 return -EOPNOTSUPP;
16309 if (!info->attrs[NL80211_ATTR_MLD_ADDR] ||
16310 !info->attrs[NL80211_ATTR_MLO_LINK_ID])
16313 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
16314 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]);
16316 wdev_lock(dev->ieee80211_ptr);
16317 ret = rdev_del_link_station(rdev, dev, ¶ms);
16318 wdev_unlock(dev->ieee80211_ptr);
16323 static int nl80211_set_hw_timestamp(struct sk_buff *skb,
16324 struct genl_info *info)
16326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16327 struct net_device *dev = info->user_ptr[1];
16328 struct cfg80211_set_hw_timestamp hwts = {};
16330 if (!rdev->wiphy.hw_timestamp_max_peers)
16331 return -EOPNOTSUPP;
16333 if (!info->attrs[NL80211_ATTR_MAC] &&
16334 rdev->wiphy.hw_timestamp_max_peers != CFG80211_HW_TIMESTAMP_ALL_PEERS)
16335 return -EOPNOTSUPP;
16337 if (info->attrs[NL80211_ATTR_MAC])
16338 hwts.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]);
16341 nla_get_flag(info->attrs[NL80211_ATTR_HW_TIMESTAMP_ENABLED]);
16343 return rdev_set_hw_timestamp(rdev, dev, &hwts);
16346 #define NL80211_FLAG_NEED_WIPHY 0x01
16347 #define NL80211_FLAG_NEED_NETDEV 0x02
16348 #define NL80211_FLAG_NEED_RTNL 0x04
16349 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
16350 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
16351 NL80211_FLAG_CHECK_NETDEV_UP)
16352 #define NL80211_FLAG_NEED_WDEV 0x10
16353 /* If a netdev is associated, it must be UP, P2P must be started */
16354 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
16355 NL80211_FLAG_CHECK_NETDEV_UP)
16356 #define NL80211_FLAG_CLEAR_SKB 0x20
16357 #define NL80211_FLAG_NO_WIPHY_MTX 0x40
16358 #define NL80211_FLAG_MLO_VALID_LINK_ID 0x80
16359 #define NL80211_FLAG_MLO_UNSUPPORTED 0x100
16361 #define INTERNAL_FLAG_SELECTORS(__sel) \
16362 SELECTOR(__sel, NONE, 0) /* must be first */ \
16363 SELECTOR(__sel, WIPHY, \
16364 NL80211_FLAG_NEED_WIPHY) \
16365 SELECTOR(__sel, WDEV, \
16366 NL80211_FLAG_NEED_WDEV) \
16367 SELECTOR(__sel, NETDEV, \
16368 NL80211_FLAG_NEED_NETDEV) \
16369 SELECTOR(__sel, NETDEV_LINK, \
16370 NL80211_FLAG_NEED_NETDEV | \
16371 NL80211_FLAG_MLO_VALID_LINK_ID) \
16372 SELECTOR(__sel, NETDEV_NO_MLO, \
16373 NL80211_FLAG_NEED_NETDEV | \
16374 NL80211_FLAG_MLO_UNSUPPORTED) \
16375 SELECTOR(__sel, WIPHY_RTNL, \
16376 NL80211_FLAG_NEED_WIPHY | \
16377 NL80211_FLAG_NEED_RTNL) \
16378 SELECTOR(__sel, WIPHY_RTNL_NOMTX, \
16379 NL80211_FLAG_NEED_WIPHY | \
16380 NL80211_FLAG_NEED_RTNL | \
16381 NL80211_FLAG_NO_WIPHY_MTX) \
16382 SELECTOR(__sel, WDEV_RTNL, \
16383 NL80211_FLAG_NEED_WDEV | \
16384 NL80211_FLAG_NEED_RTNL) \
16385 SELECTOR(__sel, NETDEV_RTNL, \
16386 NL80211_FLAG_NEED_NETDEV | \
16387 NL80211_FLAG_NEED_RTNL) \
16388 SELECTOR(__sel, NETDEV_UP, \
16389 NL80211_FLAG_NEED_NETDEV_UP) \
16390 SELECTOR(__sel, NETDEV_UP_LINK, \
16391 NL80211_FLAG_NEED_NETDEV_UP | \
16392 NL80211_FLAG_MLO_VALID_LINK_ID) \
16393 SELECTOR(__sel, NETDEV_UP_NO_MLO, \
16394 NL80211_FLAG_NEED_NETDEV_UP | \
16395 NL80211_FLAG_MLO_UNSUPPORTED) \
16396 SELECTOR(__sel, NETDEV_UP_NO_MLO_CLEAR, \
16397 NL80211_FLAG_NEED_NETDEV_UP | \
16398 NL80211_FLAG_CLEAR_SKB | \
16399 NL80211_FLAG_MLO_UNSUPPORTED) \
16400 SELECTOR(__sel, NETDEV_UP_NOTMX, \
16401 NL80211_FLAG_NEED_NETDEV_UP | \
16402 NL80211_FLAG_NO_WIPHY_MTX) \
16403 SELECTOR(__sel, NETDEV_UP_NOTMX_NOMLO, \
16404 NL80211_FLAG_NEED_NETDEV_UP | \
16405 NL80211_FLAG_NO_WIPHY_MTX | \
16406 NL80211_FLAG_MLO_UNSUPPORTED) \
16407 SELECTOR(__sel, NETDEV_UP_CLEAR, \
16408 NL80211_FLAG_NEED_NETDEV_UP | \
16409 NL80211_FLAG_CLEAR_SKB) \
16410 SELECTOR(__sel, WDEV_UP, \
16411 NL80211_FLAG_NEED_WDEV_UP) \
16412 SELECTOR(__sel, WDEV_UP_LINK, \
16413 NL80211_FLAG_NEED_WDEV_UP | \
16414 NL80211_FLAG_MLO_VALID_LINK_ID) \
16415 SELECTOR(__sel, WDEV_UP_RTNL, \
16416 NL80211_FLAG_NEED_WDEV_UP | \
16417 NL80211_FLAG_NEED_RTNL) \
16418 SELECTOR(__sel, WIPHY_CLEAR, \
16419 NL80211_FLAG_NEED_WIPHY | \
16420 NL80211_FLAG_CLEAR_SKB)
16422 enum nl80211_internal_flags_selector {
16423 #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name,
16424 INTERNAL_FLAG_SELECTORS(_)
16428 static u32 nl80211_internal_flags[] = {
16429 #define SELECTOR(_, name, value) [NL80211_IFL_SEL_##name] = value,
16430 INTERNAL_FLAG_SELECTORS(_)
16434 static int nl80211_pre_doit(const struct genl_split_ops *ops,
16435 struct sk_buff *skb,
16436 struct genl_info *info)
16438 struct cfg80211_registered_device *rdev = NULL;
16439 struct wireless_dev *wdev = NULL;
16440 struct net_device *dev = NULL;
16441 u32 internal_flags;
16444 if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags)))
16447 internal_flags = nl80211_internal_flags[ops->internal_flags];
16450 if (internal_flags & NL80211_FLAG_NEED_WIPHY) {
16451 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
16452 if (IS_ERR(rdev)) {
16453 err = PTR_ERR(rdev);
16456 info->user_ptr[0] = rdev;
16457 } else if (internal_flags & NL80211_FLAG_NEED_NETDEV ||
16458 internal_flags & NL80211_FLAG_NEED_WDEV) {
16459 wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info),
16461 if (IS_ERR(wdev)) {
16462 err = PTR_ERR(wdev);
16466 dev = wdev->netdev;
16468 rdev = wiphy_to_rdev(wdev->wiphy);
16470 if (internal_flags & NL80211_FLAG_NEED_NETDEV) {
16476 info->user_ptr[1] = dev;
16478 info->user_ptr[1] = wdev;
16481 if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
16482 !wdev_running(wdev)) {
16487 info->user_ptr[0] = rdev;
16490 if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) {
16491 struct nlattr *link_id = info->attrs[NL80211_ATTR_MLO_LINK_ID];
16498 /* MLO -> require valid link ID */
16499 if (wdev->valid_links &&
16501 !(wdev->valid_links & BIT(nla_get_u8(link_id))))) {
16506 /* non-MLO -> no link ID attribute accepted */
16507 if (!wdev->valid_links && link_id) {
16513 if (internal_flags & NL80211_FLAG_MLO_UNSUPPORTED) {
16514 if (info->attrs[NL80211_ATTR_MLO_LINK_ID] ||
16515 (wdev && wdev->valid_links)) {
16521 if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) {
16522 wiphy_lock(&rdev->wiphy);
16523 /* we keep the mutex locked until post_doit */
16524 __release(&rdev->wiphy.mtx);
16526 if (!(internal_flags & NL80211_FLAG_NEED_RTNL))
16536 static void nl80211_post_doit(const struct genl_split_ops *ops,
16537 struct sk_buff *skb,
16538 struct genl_info *info)
16540 u32 internal_flags = nl80211_internal_flags[ops->internal_flags];
16542 if (info->user_ptr[1]) {
16543 if (internal_flags & NL80211_FLAG_NEED_WDEV) {
16544 struct wireless_dev *wdev = info->user_ptr[1];
16546 dev_put(wdev->netdev);
16548 dev_put(info->user_ptr[1]);
16552 if (info->user_ptr[0] &&
16553 !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) {
16554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16556 /* we kept the mutex locked since pre_doit */
16557 __acquire(&rdev->wiphy.mtx);
16558 wiphy_unlock(&rdev->wiphy);
16561 if (internal_flags & NL80211_FLAG_NEED_RTNL)
16564 /* If needed, clear the netlink message payload from the SKB
16565 * as it might contain key data that shouldn't stick around on
16566 * the heap after the SKB is freed. The netlink message header
16567 * is still needed for further processing, so leave it intact.
16569 if (internal_flags & NL80211_FLAG_CLEAR_SKB) {
16570 struct nlmsghdr *nlh = nlmsg_hdr(skb);
16572 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
16576 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev,
16577 struct cfg80211_sar_specs *sar_specs,
16578 struct nlattr *spec[], int index)
16580 u32 range_index, i;
16582 if (!sar_specs || !spec)
16585 if (!spec[NL80211_SAR_ATTR_SPECS_POWER] ||
16586 !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX])
16589 range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]);
16591 /* check if range_index exceeds num_freq_ranges */
16592 if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges)
16595 /* check if range_index duplicates */
16596 for (i = 0; i < index; i++) {
16597 if (sar_specs->sub_specs[i].freq_range_index == range_index)
16601 sar_specs->sub_specs[index].power =
16602 nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]);
16604 sar_specs->sub_specs[index].freq_range_index = range_index;
16609 static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info)
16611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16612 struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1];
16613 struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1];
16614 struct cfg80211_sar_specs *sar_spec;
16615 enum nl80211_sar_type type;
16616 struct nlattr *spec_list;
16620 if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs)
16621 return -EOPNOTSUPP;
16623 if (!info->attrs[NL80211_ATTR_SAR_SPEC])
16626 nla_parse_nested(tb, NL80211_SAR_ATTR_MAX,
16627 info->attrs[NL80211_ATTR_SAR_SPEC],
16630 if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS])
16633 type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]);
16634 if (type != rdev->wiphy.sar_capa->type)
16638 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem)
16641 if (specs > rdev->wiphy.sar_capa->num_freq_ranges)
16644 sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL);
16648 sar_spec->type = type;
16650 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) {
16651 nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX,
16652 spec_list, NULL, NULL);
16655 case NL80211_SAR_TYPE_POWER:
16656 if (nl80211_set_sar_sub_specs(rdev, sar_spec,
16669 sar_spec->num_sub_specs = specs;
16671 rdev->cur_cmd_info = info;
16672 err = rdev_set_sar_specs(rdev, sar_spec);
16673 rdev->cur_cmd_info = NULL;
16679 #define SELECTOR(__sel, name, value) \
16680 ((__sel) == (value)) ? NL80211_IFL_SEL_##name :
16681 int __missing_selector(void);
16682 #define IFLAGS(__val) INTERNAL_FLAG_SELECTORS(__val) __missing_selector()
16684 static const struct genl_ops nl80211_ops[] = {
16686 .cmd = NL80211_CMD_GET_WIPHY,
16687 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16688 .doit = nl80211_get_wiphy,
16689 .dumpit = nl80211_dump_wiphy,
16690 .done = nl80211_dump_wiphy_done,
16691 /* can be retrieved by unprivileged users */
16692 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16696 static const struct genl_small_ops nl80211_small_ops[] = {
16698 .cmd = NL80211_CMD_SET_WIPHY,
16699 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16700 .doit = nl80211_set_wiphy,
16701 .flags = GENL_UNS_ADMIN_PERM,
16704 .cmd = NL80211_CMD_GET_INTERFACE,
16705 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16706 .doit = nl80211_get_interface,
16707 .dumpit = nl80211_dump_interface,
16708 /* can be retrieved by unprivileged users */
16709 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV),
16712 .cmd = NL80211_CMD_SET_INTERFACE,
16713 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16714 .doit = nl80211_set_interface,
16715 .flags = GENL_UNS_ADMIN_PERM,
16716 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
16717 NL80211_FLAG_NEED_RTNL),
16720 .cmd = NL80211_CMD_NEW_INTERFACE,
16721 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16722 .doit = nl80211_new_interface,
16723 .flags = GENL_UNS_ADMIN_PERM,
16725 IFLAGS(NL80211_FLAG_NEED_WIPHY |
16726 NL80211_FLAG_NEED_RTNL |
16727 /* we take the wiphy mutex later ourselves */
16728 NL80211_FLAG_NO_WIPHY_MTX),
16731 .cmd = NL80211_CMD_DEL_INTERFACE,
16732 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16733 .doit = nl80211_del_interface,
16734 .flags = GENL_UNS_ADMIN_PERM,
16735 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
16736 NL80211_FLAG_NEED_RTNL),
16739 .cmd = NL80211_CMD_GET_KEY,
16740 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16741 .doit = nl80211_get_key,
16742 .flags = GENL_UNS_ADMIN_PERM,
16743 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16746 .cmd = NL80211_CMD_SET_KEY,
16747 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16748 .doit = nl80211_set_key,
16749 .flags = GENL_UNS_ADMIN_PERM,
16750 /* cannot use NL80211_FLAG_MLO_VALID_LINK_ID, depends on key */
16751 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16752 NL80211_FLAG_CLEAR_SKB),
16755 .cmd = NL80211_CMD_NEW_KEY,
16756 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16757 .doit = nl80211_new_key,
16758 .flags = GENL_UNS_ADMIN_PERM,
16759 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16760 NL80211_FLAG_CLEAR_SKB),
16763 .cmd = NL80211_CMD_DEL_KEY,
16764 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16765 .doit = nl80211_del_key,
16766 .flags = GENL_UNS_ADMIN_PERM,
16767 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16770 .cmd = NL80211_CMD_SET_BEACON,
16771 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16772 .flags = GENL_UNS_ADMIN_PERM,
16773 .doit = nl80211_set_beacon,
16774 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16775 NL80211_FLAG_MLO_VALID_LINK_ID),
16778 .cmd = NL80211_CMD_START_AP,
16779 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16780 .flags = GENL_UNS_ADMIN_PERM,
16781 .doit = nl80211_start_ap,
16782 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16783 NL80211_FLAG_MLO_VALID_LINK_ID),
16786 .cmd = NL80211_CMD_STOP_AP,
16787 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16788 .flags = GENL_UNS_ADMIN_PERM,
16789 .doit = nl80211_stop_ap,
16790 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16791 NL80211_FLAG_MLO_VALID_LINK_ID),
16794 .cmd = NL80211_CMD_GET_STATION,
16795 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16796 .doit = nl80211_get_station,
16797 .dumpit = nl80211_dump_station,
16798 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16801 .cmd = NL80211_CMD_SET_STATION,
16802 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16803 .doit = nl80211_set_station,
16804 .flags = GENL_UNS_ADMIN_PERM,
16805 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16808 .cmd = NL80211_CMD_NEW_STATION,
16809 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16810 .doit = nl80211_new_station,
16811 .flags = GENL_UNS_ADMIN_PERM,
16812 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16815 .cmd = NL80211_CMD_DEL_STATION,
16816 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16817 .doit = nl80211_del_station,
16818 .flags = GENL_UNS_ADMIN_PERM,
16819 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16822 .cmd = NL80211_CMD_GET_MPATH,
16823 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16824 .doit = nl80211_get_mpath,
16825 .dumpit = nl80211_dump_mpath,
16826 .flags = GENL_UNS_ADMIN_PERM,
16827 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16830 .cmd = NL80211_CMD_GET_MPP,
16831 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16832 .doit = nl80211_get_mpp,
16833 .dumpit = nl80211_dump_mpp,
16834 .flags = GENL_UNS_ADMIN_PERM,
16835 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16838 .cmd = NL80211_CMD_SET_MPATH,
16839 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16840 .doit = nl80211_set_mpath,
16841 .flags = GENL_UNS_ADMIN_PERM,
16842 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16845 .cmd = NL80211_CMD_NEW_MPATH,
16846 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16847 .doit = nl80211_new_mpath,
16848 .flags = GENL_UNS_ADMIN_PERM,
16849 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16852 .cmd = NL80211_CMD_DEL_MPATH,
16853 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16854 .doit = nl80211_del_mpath,
16855 .flags = GENL_UNS_ADMIN_PERM,
16856 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16859 .cmd = NL80211_CMD_SET_BSS,
16860 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16861 .doit = nl80211_set_bss,
16862 .flags = GENL_UNS_ADMIN_PERM,
16863 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16864 NL80211_FLAG_MLO_VALID_LINK_ID),
16867 .cmd = NL80211_CMD_GET_REG,
16868 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16869 .doit = nl80211_get_reg_do,
16870 .dumpit = nl80211_get_reg_dump,
16871 /* can be retrieved by unprivileged users */
16873 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
16875 .cmd = NL80211_CMD_SET_REG,
16876 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16877 .doit = nl80211_set_reg,
16878 .flags = GENL_ADMIN_PERM,
16882 .cmd = NL80211_CMD_REQ_SET_REG,
16883 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16884 .doit = nl80211_req_set_reg,
16885 .flags = GENL_ADMIN_PERM,
16888 .cmd = NL80211_CMD_RELOAD_REGDB,
16889 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16890 .doit = nl80211_reload_regdb,
16891 .flags = GENL_ADMIN_PERM,
16894 .cmd = NL80211_CMD_GET_MESH_CONFIG,
16895 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16896 .doit = nl80211_get_mesh_config,
16897 /* can be retrieved by unprivileged users */
16898 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16901 .cmd = NL80211_CMD_SET_MESH_CONFIG,
16902 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16903 .doit = nl80211_update_mesh_config,
16904 .flags = GENL_UNS_ADMIN_PERM,
16905 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16908 .cmd = NL80211_CMD_TRIGGER_SCAN,
16909 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16910 .doit = nl80211_trigger_scan,
16911 .flags = GENL_UNS_ADMIN_PERM,
16912 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16915 .cmd = NL80211_CMD_ABORT_SCAN,
16916 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16917 .doit = nl80211_abort_scan,
16918 .flags = GENL_UNS_ADMIN_PERM,
16919 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16922 .cmd = NL80211_CMD_GET_SCAN,
16923 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16924 .dumpit = nl80211_dump_scan,
16927 .cmd = NL80211_CMD_START_SCHED_SCAN,
16928 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16929 .doit = nl80211_start_sched_scan,
16930 .flags = GENL_UNS_ADMIN_PERM,
16931 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16934 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
16935 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16936 .doit = nl80211_stop_sched_scan,
16937 .flags = GENL_UNS_ADMIN_PERM,
16938 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16941 .cmd = NL80211_CMD_AUTHENTICATE,
16942 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16943 .doit = nl80211_authenticate,
16944 .flags = GENL_UNS_ADMIN_PERM,
16945 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16946 NL80211_FLAG_CLEAR_SKB),
16949 .cmd = NL80211_CMD_ASSOCIATE,
16950 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16951 .doit = nl80211_associate,
16952 .flags = GENL_UNS_ADMIN_PERM,
16953 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16954 NL80211_FLAG_CLEAR_SKB),
16957 .cmd = NL80211_CMD_DEAUTHENTICATE,
16958 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16959 .doit = nl80211_deauthenticate,
16960 .flags = GENL_UNS_ADMIN_PERM,
16961 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16964 .cmd = NL80211_CMD_DISASSOCIATE,
16965 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16966 .doit = nl80211_disassociate,
16967 .flags = GENL_UNS_ADMIN_PERM,
16968 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16971 .cmd = NL80211_CMD_JOIN_IBSS,
16972 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16973 .doit = nl80211_join_ibss,
16974 .flags = GENL_UNS_ADMIN_PERM,
16975 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16978 .cmd = NL80211_CMD_LEAVE_IBSS,
16979 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16980 .doit = nl80211_leave_ibss,
16981 .flags = GENL_UNS_ADMIN_PERM,
16982 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16984 #ifdef CONFIG_NL80211_TESTMODE
16986 .cmd = NL80211_CMD_TESTMODE,
16987 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16988 .doit = nl80211_testmode_do,
16989 .dumpit = nl80211_testmode_dump,
16990 .flags = GENL_UNS_ADMIN_PERM,
16991 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16995 .cmd = NL80211_CMD_CONNECT,
16996 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16997 .doit = nl80211_connect,
16998 .flags = GENL_UNS_ADMIN_PERM,
16999 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17000 NL80211_FLAG_CLEAR_SKB),
17003 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
17004 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17005 .doit = nl80211_update_connect_params,
17006 .flags = GENL_ADMIN_PERM,
17007 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17008 NL80211_FLAG_CLEAR_SKB),
17011 .cmd = NL80211_CMD_DISCONNECT,
17012 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17013 .doit = nl80211_disconnect,
17014 .flags = GENL_UNS_ADMIN_PERM,
17015 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17018 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
17019 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17020 .doit = nl80211_wiphy_netns,
17021 .flags = GENL_UNS_ADMIN_PERM,
17022 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
17023 NL80211_FLAG_NEED_RTNL |
17024 NL80211_FLAG_NO_WIPHY_MTX),
17027 .cmd = NL80211_CMD_GET_SURVEY,
17028 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17029 .dumpit = nl80211_dump_survey,
17032 .cmd = NL80211_CMD_SET_PMKSA,
17033 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17034 .doit = nl80211_setdel_pmksa,
17035 .flags = GENL_UNS_ADMIN_PERM,
17036 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17037 NL80211_FLAG_CLEAR_SKB),
17040 .cmd = NL80211_CMD_DEL_PMKSA,
17041 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17042 .doit = nl80211_setdel_pmksa,
17043 .flags = GENL_UNS_ADMIN_PERM,
17044 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17047 .cmd = NL80211_CMD_FLUSH_PMKSA,
17048 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17049 .doit = nl80211_flush_pmksa,
17050 .flags = GENL_UNS_ADMIN_PERM,
17051 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17054 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
17055 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17056 .doit = nl80211_remain_on_channel,
17057 .flags = GENL_UNS_ADMIN_PERM,
17058 /* FIXME: requiring a link ID here is probably not good */
17059 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
17060 NL80211_FLAG_MLO_VALID_LINK_ID),
17063 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
17064 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17065 .doit = nl80211_cancel_remain_on_channel,
17066 .flags = GENL_UNS_ADMIN_PERM,
17067 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17070 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
17071 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17072 .doit = nl80211_set_tx_bitrate_mask,
17073 .flags = GENL_UNS_ADMIN_PERM,
17074 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17075 NL80211_FLAG_MLO_VALID_LINK_ID),
17078 .cmd = NL80211_CMD_REGISTER_FRAME,
17079 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17080 .doit = nl80211_register_mgmt,
17081 .flags = GENL_UNS_ADMIN_PERM,
17082 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV),
17085 .cmd = NL80211_CMD_FRAME,
17086 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17087 .doit = nl80211_tx_mgmt,
17088 .flags = GENL_UNS_ADMIN_PERM,
17089 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17092 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
17093 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17094 .doit = nl80211_tx_mgmt_cancel_wait,
17095 .flags = GENL_UNS_ADMIN_PERM,
17096 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17099 .cmd = NL80211_CMD_SET_POWER_SAVE,
17100 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17101 .doit = nl80211_set_power_save,
17102 .flags = GENL_UNS_ADMIN_PERM,
17103 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17106 .cmd = NL80211_CMD_GET_POWER_SAVE,
17107 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17108 .doit = nl80211_get_power_save,
17109 /* can be retrieved by unprivileged users */
17110 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17113 .cmd = NL80211_CMD_SET_CQM,
17114 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17115 .doit = nl80211_set_cqm,
17116 .flags = GENL_UNS_ADMIN_PERM,
17117 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17120 .cmd = NL80211_CMD_SET_CHANNEL,
17121 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17122 .doit = nl80211_set_channel,
17123 .flags = GENL_UNS_ADMIN_PERM,
17124 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17125 NL80211_FLAG_MLO_VALID_LINK_ID),
17128 .cmd = NL80211_CMD_JOIN_MESH,
17129 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17130 .doit = nl80211_join_mesh,
17131 .flags = GENL_UNS_ADMIN_PERM,
17132 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17135 .cmd = NL80211_CMD_LEAVE_MESH,
17136 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17137 .doit = nl80211_leave_mesh,
17138 .flags = GENL_UNS_ADMIN_PERM,
17139 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17142 .cmd = NL80211_CMD_JOIN_OCB,
17143 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17144 .doit = nl80211_join_ocb,
17145 .flags = GENL_UNS_ADMIN_PERM,
17146 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17149 .cmd = NL80211_CMD_LEAVE_OCB,
17150 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17151 .doit = nl80211_leave_ocb,
17152 .flags = GENL_UNS_ADMIN_PERM,
17153 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17157 .cmd = NL80211_CMD_GET_WOWLAN,
17158 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17159 .doit = nl80211_get_wowlan,
17160 /* can be retrieved by unprivileged users */
17161 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17164 .cmd = NL80211_CMD_SET_WOWLAN,
17165 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17166 .doit = nl80211_set_wowlan,
17167 .flags = GENL_UNS_ADMIN_PERM,
17168 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17172 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
17173 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17174 .doit = nl80211_set_rekey_data,
17175 .flags = GENL_UNS_ADMIN_PERM,
17176 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17177 NL80211_FLAG_CLEAR_SKB),
17180 .cmd = NL80211_CMD_TDLS_MGMT,
17181 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17182 .doit = nl80211_tdls_mgmt,
17183 .flags = GENL_UNS_ADMIN_PERM,
17184 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17185 NL80211_FLAG_MLO_VALID_LINK_ID),
17188 .cmd = NL80211_CMD_TDLS_OPER,
17189 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17190 .doit = nl80211_tdls_oper,
17191 .flags = GENL_UNS_ADMIN_PERM,
17192 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17195 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
17196 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17197 .doit = nl80211_register_unexpected_frame,
17198 .flags = GENL_UNS_ADMIN_PERM,
17199 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17202 .cmd = NL80211_CMD_PROBE_CLIENT,
17203 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17204 .doit = nl80211_probe_client,
17205 .flags = GENL_UNS_ADMIN_PERM,
17206 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17209 .cmd = NL80211_CMD_REGISTER_BEACONS,
17210 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17211 .doit = nl80211_register_beacons,
17212 .flags = GENL_UNS_ADMIN_PERM,
17213 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17216 .cmd = NL80211_CMD_SET_NOACK_MAP,
17217 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17218 .doit = nl80211_set_noack_map,
17219 .flags = GENL_UNS_ADMIN_PERM,
17220 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17223 .cmd = NL80211_CMD_START_P2P_DEVICE,
17224 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17225 .doit = nl80211_start_p2p_device,
17226 .flags = GENL_UNS_ADMIN_PERM,
17227 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
17228 NL80211_FLAG_NEED_RTNL),
17231 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
17232 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17233 .doit = nl80211_stop_p2p_device,
17234 .flags = GENL_UNS_ADMIN_PERM,
17235 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
17236 NL80211_FLAG_NEED_RTNL),
17239 .cmd = NL80211_CMD_START_NAN,
17240 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17241 .doit = nl80211_start_nan,
17242 .flags = GENL_ADMIN_PERM,
17243 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
17244 NL80211_FLAG_NEED_RTNL),
17247 .cmd = NL80211_CMD_STOP_NAN,
17248 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17249 .doit = nl80211_stop_nan,
17250 .flags = GENL_ADMIN_PERM,
17251 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
17252 NL80211_FLAG_NEED_RTNL),
17255 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
17256 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17257 .doit = nl80211_nan_add_func,
17258 .flags = GENL_ADMIN_PERM,
17259 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17262 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
17263 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17264 .doit = nl80211_nan_del_func,
17265 .flags = GENL_ADMIN_PERM,
17266 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17269 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
17270 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17271 .doit = nl80211_nan_change_config,
17272 .flags = GENL_ADMIN_PERM,
17273 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17276 .cmd = NL80211_CMD_SET_MCAST_RATE,
17277 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17278 .doit = nl80211_set_mcast_rate,
17279 .flags = GENL_UNS_ADMIN_PERM,
17280 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17283 .cmd = NL80211_CMD_SET_MAC_ACL,
17284 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17285 .doit = nl80211_set_mac_acl,
17286 .flags = GENL_UNS_ADMIN_PERM,
17287 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17288 NL80211_FLAG_MLO_UNSUPPORTED),
17291 .cmd = NL80211_CMD_RADAR_DETECT,
17292 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17293 .doit = nl80211_start_radar_detection,
17294 .flags = GENL_UNS_ADMIN_PERM,
17295 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17296 NL80211_FLAG_NO_WIPHY_MTX |
17297 NL80211_FLAG_MLO_UNSUPPORTED),
17300 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
17301 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17302 .doit = nl80211_get_protocol_features,
17305 .cmd = NL80211_CMD_UPDATE_FT_IES,
17306 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17307 .doit = nl80211_update_ft_ies,
17308 .flags = GENL_UNS_ADMIN_PERM,
17309 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17312 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
17313 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17314 .doit = nl80211_crit_protocol_start,
17315 .flags = GENL_UNS_ADMIN_PERM,
17316 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17319 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
17320 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17321 .doit = nl80211_crit_protocol_stop,
17322 .flags = GENL_UNS_ADMIN_PERM,
17323 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17326 .cmd = NL80211_CMD_GET_COALESCE,
17327 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17328 .doit = nl80211_get_coalesce,
17329 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17332 .cmd = NL80211_CMD_SET_COALESCE,
17333 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17334 .doit = nl80211_set_coalesce,
17335 .flags = GENL_UNS_ADMIN_PERM,
17336 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17339 .cmd = NL80211_CMD_CHANNEL_SWITCH,
17340 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17341 .doit = nl80211_channel_switch,
17342 .flags = GENL_UNS_ADMIN_PERM,
17343 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17344 NL80211_FLAG_MLO_VALID_LINK_ID),
17347 .cmd = NL80211_CMD_VENDOR,
17348 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17349 .doit = nl80211_vendor_cmd,
17350 .dumpit = nl80211_vendor_cmd_dump,
17351 .flags = GENL_UNS_ADMIN_PERM,
17352 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
17353 NL80211_FLAG_CLEAR_SKB),
17356 .cmd = NL80211_CMD_SET_QOS_MAP,
17357 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17358 .doit = nl80211_set_qos_map,
17359 .flags = GENL_UNS_ADMIN_PERM,
17360 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17363 .cmd = NL80211_CMD_ADD_TX_TS,
17364 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17365 .doit = nl80211_add_tx_ts,
17366 .flags = GENL_UNS_ADMIN_PERM,
17367 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17368 NL80211_FLAG_MLO_UNSUPPORTED),
17371 .cmd = NL80211_CMD_DEL_TX_TS,
17372 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17373 .doit = nl80211_del_tx_ts,
17374 .flags = GENL_UNS_ADMIN_PERM,
17375 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17378 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
17379 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17380 .doit = nl80211_tdls_channel_switch,
17381 .flags = GENL_UNS_ADMIN_PERM,
17382 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17385 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
17386 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17387 .doit = nl80211_tdls_cancel_channel_switch,
17388 .flags = GENL_UNS_ADMIN_PERM,
17389 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17392 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
17393 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17394 .doit = nl80211_set_multicast_to_unicast,
17395 .flags = GENL_UNS_ADMIN_PERM,
17396 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17399 .cmd = NL80211_CMD_SET_PMK,
17400 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17401 .doit = nl80211_set_pmk,
17402 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17403 NL80211_FLAG_CLEAR_SKB),
17406 .cmd = NL80211_CMD_DEL_PMK,
17407 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17408 .doit = nl80211_del_pmk,
17409 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17412 .cmd = NL80211_CMD_EXTERNAL_AUTH,
17413 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17414 .doit = nl80211_external_auth,
17415 .flags = GENL_ADMIN_PERM,
17416 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17419 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
17420 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17421 .doit = nl80211_tx_control_port,
17422 .flags = GENL_UNS_ADMIN_PERM,
17423 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17426 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
17427 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17428 .doit = nl80211_get_ftm_responder_stats,
17429 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17430 NL80211_FLAG_MLO_VALID_LINK_ID),
17433 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
17434 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17435 .doit = nl80211_pmsr_start,
17436 .flags = GENL_UNS_ADMIN_PERM,
17437 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17440 .cmd = NL80211_CMD_NOTIFY_RADAR,
17441 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17442 .doit = nl80211_notify_radar_detection,
17443 .flags = GENL_UNS_ADMIN_PERM,
17444 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17447 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
17448 .doit = nl80211_update_owe_info,
17449 .flags = GENL_ADMIN_PERM,
17450 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17453 .cmd = NL80211_CMD_PROBE_MESH_LINK,
17454 .doit = nl80211_probe_mesh_link,
17455 .flags = GENL_UNS_ADMIN_PERM,
17456 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17459 .cmd = NL80211_CMD_SET_TID_CONFIG,
17460 .doit = nl80211_set_tid_config,
17461 .flags = GENL_UNS_ADMIN_PERM,
17462 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17463 NL80211_FLAG_MLO_VALID_LINK_ID),
17466 .cmd = NL80211_CMD_SET_SAR_SPECS,
17467 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17468 .doit = nl80211_set_sar_specs,
17469 .flags = GENL_UNS_ADMIN_PERM,
17470 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
17471 NL80211_FLAG_NEED_RTNL),
17474 .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST,
17475 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17476 .doit = nl80211_color_change,
17477 .flags = GENL_UNS_ADMIN_PERM,
17478 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17481 .cmd = NL80211_CMD_SET_FILS_AAD,
17482 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17483 .doit = nl80211_set_fils_aad,
17484 .flags = GENL_UNS_ADMIN_PERM,
17485 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17488 .cmd = NL80211_CMD_ADD_LINK,
17489 .doit = nl80211_add_link,
17490 .flags = GENL_UNS_ADMIN_PERM,
17491 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17494 .cmd = NL80211_CMD_REMOVE_LINK,
17495 .doit = nl80211_remove_link,
17496 .flags = GENL_UNS_ADMIN_PERM,
17497 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17498 NL80211_FLAG_MLO_VALID_LINK_ID),
17501 .cmd = NL80211_CMD_ADD_LINK_STA,
17502 .doit = nl80211_add_link_station,
17503 .flags = GENL_UNS_ADMIN_PERM,
17504 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17505 NL80211_FLAG_MLO_VALID_LINK_ID),
17508 .cmd = NL80211_CMD_MODIFY_LINK_STA,
17509 .doit = nl80211_modify_link_station,
17510 .flags = GENL_UNS_ADMIN_PERM,
17511 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17512 NL80211_FLAG_MLO_VALID_LINK_ID),
17515 .cmd = NL80211_CMD_REMOVE_LINK_STA,
17516 .doit = nl80211_remove_link_station,
17517 .flags = GENL_UNS_ADMIN_PERM,
17518 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17519 NL80211_FLAG_MLO_VALID_LINK_ID),
17522 .cmd = NL80211_CMD_SET_HW_TIMESTAMP,
17523 .doit = nl80211_set_hw_timestamp,
17524 .flags = GENL_UNS_ADMIN_PERM,
17525 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17529 static struct genl_family nl80211_fam __ro_after_init = {
17530 .name = NL80211_GENL_NAME, /* have users key off the name instead */
17531 .hdrsize = 0, /* no private header */
17532 .version = 1, /* no particular meaning now */
17533 .maxattr = NL80211_ATTR_MAX,
17534 .policy = nl80211_policy,
17536 .pre_doit = nl80211_pre_doit,
17537 .post_doit = nl80211_post_doit,
17538 .module = THIS_MODULE,
17539 .ops = nl80211_ops,
17540 .n_ops = ARRAY_SIZE(nl80211_ops),
17541 .small_ops = nl80211_small_ops,
17542 .n_small_ops = ARRAY_SIZE(nl80211_small_ops),
17543 .resv_start_op = NL80211_CMD_REMOVE_LINK_STA + 1,
17544 .mcgrps = nl80211_mcgrps,
17545 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
17546 .parallel_ops = true,
17549 /* notification functions */
17551 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
17552 enum nl80211_commands cmd)
17554 struct sk_buff *msg;
17555 struct nl80211_dump_wiphy_state state = {};
17557 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
17558 cmd != NL80211_CMD_DEL_WIPHY);
17560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17564 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
17569 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17570 NL80211_MCGRP_CONFIG, GFP_KERNEL);
17573 void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
17574 struct wireless_dev *wdev,
17575 enum nl80211_commands cmd)
17577 struct sk_buff *msg;
17579 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17583 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
17588 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17589 NL80211_MCGRP_CONFIG, GFP_KERNEL);
17592 static int nl80211_add_scan_req(struct sk_buff *msg,
17593 struct cfg80211_registered_device *rdev)
17595 struct cfg80211_scan_request *req = rdev->scan_req;
17596 struct nlattr *nest;
17598 struct cfg80211_scan_info *info;
17603 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
17605 goto nla_put_failure;
17606 for (i = 0; i < req->n_ssids; i++) {
17607 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
17608 goto nla_put_failure;
17610 nla_nest_end(msg, nest);
17612 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) {
17613 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ);
17615 goto nla_put_failure;
17616 for (i = 0; i < req->n_channels; i++) {
17617 if (nla_put_u32(msg, i,
17618 ieee80211_channel_to_khz(req->channels[i])))
17619 goto nla_put_failure;
17621 nla_nest_end(msg, nest);
17623 nest = nla_nest_start_noflag(msg,
17624 NL80211_ATTR_SCAN_FREQUENCIES);
17626 goto nla_put_failure;
17627 for (i = 0; i < req->n_channels; i++) {
17628 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
17629 goto nla_put_failure;
17631 nla_nest_end(msg, nest);
17635 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
17636 goto nla_put_failure;
17639 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
17640 goto nla_put_failure;
17642 info = rdev->int_scan_req ? &rdev->int_scan_req->info :
17643 &rdev->scan_req->info;
17644 if (info->scan_start_tsf &&
17645 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
17646 info->scan_start_tsf, NL80211_BSS_PAD) ||
17647 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
17649 goto nla_put_failure;
17656 static int nl80211_prep_scan_msg(struct sk_buff *msg,
17657 struct cfg80211_registered_device *rdev,
17658 struct wireless_dev *wdev,
17659 u32 portid, u32 seq, int flags,
17664 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
17668 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17669 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
17670 wdev->netdev->ifindex)) ||
17671 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17673 goto nla_put_failure;
17675 /* ignore errors and send incomplete event anyway */
17676 nl80211_add_scan_req(msg, rdev);
17678 genlmsg_end(msg, hdr);
17682 genlmsg_cancel(msg, hdr);
17687 nl80211_prep_sched_scan_msg(struct sk_buff *msg,
17688 struct cfg80211_sched_scan_request *req, u32 cmd)
17692 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17696 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
17697 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
17698 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
17699 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
17701 goto nla_put_failure;
17703 genlmsg_end(msg, hdr);
17707 genlmsg_cancel(msg, hdr);
17711 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
17712 struct wireless_dev *wdev)
17714 struct sk_buff *msg;
17716 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17720 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
17721 NL80211_CMD_TRIGGER_SCAN) < 0) {
17726 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17727 NL80211_MCGRP_SCAN, GFP_KERNEL);
17730 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
17731 struct wireless_dev *wdev, bool aborted)
17733 struct sk_buff *msg;
17735 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17739 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
17740 aborted ? NL80211_CMD_SCAN_ABORTED :
17741 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
17749 /* send message created by nl80211_build_scan_msg() */
17750 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
17751 struct sk_buff *msg)
17756 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17757 NL80211_MCGRP_SCAN, GFP_KERNEL);
17760 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
17762 struct sk_buff *msg;
17764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17768 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
17773 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
17774 NL80211_MCGRP_SCAN, GFP_KERNEL);
17777 static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
17778 struct regulatory_request *request)
17780 /* Userspace can always count this one always being set */
17781 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
17782 goto nla_put_failure;
17784 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
17785 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17786 NL80211_REGDOM_TYPE_WORLD))
17787 goto nla_put_failure;
17788 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
17789 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17790 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
17791 goto nla_put_failure;
17792 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
17793 request->intersect) {
17794 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17795 NL80211_REGDOM_TYPE_INTERSECTION))
17796 goto nla_put_failure;
17798 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17799 NL80211_REGDOM_TYPE_COUNTRY) ||
17800 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
17802 goto nla_put_failure;
17805 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
17806 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
17809 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
17810 goto nla_put_failure;
17813 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
17814 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
17815 goto nla_put_failure;
17825 * This can happen on global regulatory changes or device specific settings
17826 * based on custom regulatory domains.
17828 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
17829 struct regulatory_request *request)
17831 struct sk_buff *msg;
17834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17838 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
17840 goto nla_put_failure;
17842 if (!nl80211_reg_change_event_fill(msg, request))
17843 goto nla_put_failure;
17845 genlmsg_end(msg, hdr);
17848 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
17849 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
17858 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
17859 struct net_device *netdev,
17860 const u8 *buf, size_t len,
17861 enum nl80211_commands cmd, gfp_t gfp,
17862 int uapsd_queues, const u8 *req_ies,
17863 size_t req_ies_len, bool reconnect)
17865 struct sk_buff *msg;
17868 msg = nlmsg_new(100 + len + req_ies_len, gfp);
17872 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17878 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17879 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17880 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
17882 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
17883 goto nla_put_failure;
17885 if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED))
17886 goto nla_put_failure;
17888 if (uapsd_queues >= 0) {
17889 struct nlattr *nla_wmm =
17890 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
17892 goto nla_put_failure;
17894 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
17896 goto nla_put_failure;
17898 nla_nest_end(msg, nla_wmm);
17901 genlmsg_end(msg, hdr);
17903 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17904 NL80211_MCGRP_MLME, gfp);
17911 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
17912 struct net_device *netdev, const u8 *buf,
17913 size_t len, gfp_t gfp)
17915 nl80211_send_mlme_event(rdev, netdev, buf, len,
17916 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0,
17920 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
17921 struct net_device *netdev,
17922 struct cfg80211_rx_assoc_resp *data)
17924 nl80211_send_mlme_event(rdev, netdev, data->buf, data->len,
17925 NL80211_CMD_ASSOCIATE, GFP_KERNEL,
17926 data->uapsd_queues,
17927 data->req_ies, data->req_ies_len, false);
17930 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
17931 struct net_device *netdev, const u8 *buf,
17932 size_t len, bool reconnect, gfp_t gfp)
17934 nl80211_send_mlme_event(rdev, netdev, buf, len,
17935 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0,
17939 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
17940 struct net_device *netdev, const u8 *buf,
17941 size_t len, bool reconnect, gfp_t gfp)
17943 nl80211_send_mlme_event(rdev, netdev, buf, len,
17944 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0,
17948 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
17951 struct wireless_dev *wdev = dev->ieee80211_ptr;
17952 struct wiphy *wiphy = wdev->wiphy;
17953 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17954 const struct ieee80211_mgmt *mgmt = (void *)buf;
17957 if (WARN_ON(len < 2))
17960 if (ieee80211_is_deauth(mgmt->frame_control)) {
17961 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
17962 } else if (ieee80211_is_disassoc(mgmt->frame_control)) {
17963 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
17964 } else if (ieee80211_is_beacon(mgmt->frame_control)) {
17965 if (wdev->unprot_beacon_reported &&
17966 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000)
17968 cmd = NL80211_CMD_UNPROT_BEACON;
17969 wdev->unprot_beacon_reported = jiffies;
17974 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
17975 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
17978 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
17980 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
17981 struct net_device *netdev, int cmd,
17982 const u8 *addr, gfp_t gfp)
17984 struct sk_buff *msg;
17987 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17991 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17997 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17998 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17999 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
18000 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
18001 goto nla_put_failure;
18003 genlmsg_end(msg, hdr);
18005 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18006 NL80211_MCGRP_MLME, gfp);
18013 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
18014 struct net_device *netdev, const u8 *addr,
18017 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
18021 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
18022 struct net_device *netdev, const u8 *addr,
18025 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
18029 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
18030 struct net_device *netdev,
18031 struct cfg80211_connect_resp_params *cr,
18034 struct sk_buff *msg;
18037 size_t link_info_size = 0;
18038 const u8 *connected_addr = cr->valid_links ?
18039 cr->ap_mld_addr : cr->links[0].bssid;
18041 if (cr->valid_links) {
18042 for_each_valid_link(cr, link) {
18043 /* Nested attribute header */
18044 link_info_size += NLA_HDRLEN;
18046 link_info_size += nla_total_size(sizeof(u8));
18047 link_info_size += cr->links[link].addr ?
18048 nla_total_size(ETH_ALEN) : 0;
18049 link_info_size += (cr->links[link].bssid ||
18050 cr->links[link].bss) ?
18051 nla_total_size(ETH_ALEN) : 0;
18052 link_info_size += nla_total_size(sizeof(u16));
18056 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
18057 cr->fils.kek_len + cr->fils.pmk_len +
18058 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size,
18063 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
18069 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18070 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18072 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr)) ||
18073 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
18074 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
18077 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
18078 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
18079 cr->timeout_reason))) ||
18081 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
18083 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
18085 (cr->fils.update_erp_next_seq_num &&
18086 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
18087 cr->fils.erp_next_seq_num)) ||
18088 (cr->status == WLAN_STATUS_SUCCESS &&
18090 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
18093 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
18095 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
18096 goto nla_put_failure;
18098 if (cr->valid_links) {
18100 struct nlattr *nested;
18102 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
18104 goto nla_put_failure;
18106 for_each_valid_link(cr, link) {
18107 struct nlattr *nested_mlo_links;
18108 const u8 *bssid = cr->links[link].bss ?
18109 cr->links[link].bss->bssid :
18110 cr->links[link].bssid;
18112 nested_mlo_links = nla_nest_start(msg, i);
18113 if (!nested_mlo_links)
18114 goto nla_put_failure;
18116 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) ||
18118 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) ||
18119 (cr->links[link].addr &&
18120 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
18121 cr->links[link].addr)) ||
18122 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
18123 cr->links[link].status))
18124 goto nla_put_failure;
18126 nla_nest_end(msg, nested_mlo_links);
18129 nla_nest_end(msg, nested);
18132 genlmsg_end(msg, hdr);
18134 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18135 NL80211_MCGRP_MLME, gfp);
18142 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
18143 struct net_device *netdev,
18144 struct cfg80211_roam_info *info, gfp_t gfp)
18146 struct sk_buff *msg;
18148 size_t link_info_size = 0;
18150 const u8 *connected_addr = info->ap_mld_addr ?
18151 info->ap_mld_addr :
18152 (info->links[0].bss ?
18153 info->links[0].bss->bssid :
18154 info->links[0].bssid);
18156 if (info->valid_links) {
18157 for_each_valid_link(info, link) {
18158 /* Nested attribute header */
18159 link_info_size += NLA_HDRLEN;
18161 link_info_size += nla_total_size(sizeof(u8));
18162 link_info_size += info->links[link].addr ?
18163 nla_total_size(ETH_ALEN) : 0;
18164 link_info_size += (info->links[link].bssid ||
18165 info->links[link].bss) ?
18166 nla_total_size(ETH_ALEN) : 0;
18170 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
18171 info->fils.kek_len + info->fils.pmk_len +
18172 (info->fils.pmkid ? WLAN_PMKID_LEN : 0) +
18173 link_info_size, gfp);
18177 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
18183 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18184 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18185 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) ||
18187 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
18190 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
18192 (info->fils.update_erp_next_seq_num &&
18193 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
18194 info->fils.erp_next_seq_num)) ||
18196 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
18197 info->fils.kek)) ||
18199 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
18200 (info->fils.pmkid &&
18201 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
18202 goto nla_put_failure;
18204 if (info->valid_links) {
18206 struct nlattr *nested;
18208 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
18210 goto nla_put_failure;
18212 for_each_valid_link(info, link) {
18213 struct nlattr *nested_mlo_links;
18214 const u8 *bssid = info->links[link].bss ?
18215 info->links[link].bss->bssid :
18216 info->links[link].bssid;
18218 nested_mlo_links = nla_nest_start(msg, i);
18219 if (!nested_mlo_links)
18220 goto nla_put_failure;
18222 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) ||
18224 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) ||
18225 (info->links[link].addr &&
18226 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
18227 info->links[link].addr)))
18228 goto nla_put_failure;
18230 nla_nest_end(msg, nested_mlo_links);
18233 nla_nest_end(msg, nested);
18236 genlmsg_end(msg, hdr);
18238 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18239 NL80211_MCGRP_MLME, gfp);
18246 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
18247 struct net_device *netdev, const u8 *bssid,
18248 const u8 *td_bitmap, u8 td_bitmap_len)
18250 struct sk_buff *msg;
18253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
18257 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
18263 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18264 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18265 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
18266 goto nla_put_failure;
18268 if ((td_bitmap_len > 0) && td_bitmap)
18269 if (nla_put(msg, NL80211_ATTR_TD_BITMAP,
18270 td_bitmap_len, td_bitmap))
18271 goto nla_put_failure;
18273 genlmsg_end(msg, hdr);
18275 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18276 NL80211_MCGRP_MLME, GFP_KERNEL);
18283 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
18284 struct net_device *netdev, u16 reason,
18285 const u8 *ie, size_t ie_len, bool from_ap)
18287 struct sk_buff *msg;
18290 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
18294 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
18300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18301 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18303 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
18305 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
18306 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
18307 goto nla_put_failure;
18309 genlmsg_end(msg, hdr);
18311 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18312 NL80211_MCGRP_MLME, GFP_KERNEL);
18319 void cfg80211_links_removed(struct net_device *dev, u16 link_mask)
18321 struct wireless_dev *wdev = dev->ieee80211_ptr;
18322 struct wiphy *wiphy = wdev->wiphy;
18323 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18324 struct sk_buff *msg;
18325 struct nlattr *links;
18328 ASSERT_WDEV_LOCK(wdev);
18329 trace_cfg80211_links_removed(dev, link_mask);
18331 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
18332 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
18335 if (WARN_ON(!wdev->valid_links || !link_mask ||
18336 (wdev->valid_links & link_mask) != link_mask ||
18337 wdev->valid_links == link_mask))
18340 cfg80211_wdev_release_link_bsses(wdev, link_mask);
18341 wdev->valid_links &= ~link_mask;
18343 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
18347 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_LINKS_REMOVED);
18353 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18354 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
18355 goto nla_put_failure;
18357 links = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
18359 goto nla_put_failure;
18361 while (link_mask) {
18362 struct nlattr *link;
18363 int link_id = __ffs(link_mask);
18365 link = nla_nest_start(msg, link_id + 1);
18367 goto nla_put_failure;
18369 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
18370 goto nla_put_failure;
18372 nla_nest_end(msg, link);
18373 link_mask &= ~(1 << link_id);
18376 nla_nest_end(msg, links);
18378 genlmsg_end(msg, hdr);
18380 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18381 NL80211_MCGRP_MLME, GFP_KERNEL);
18387 EXPORT_SYMBOL(cfg80211_links_removed);
18389 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
18390 struct net_device *netdev, const u8 *bssid,
18393 struct sk_buff *msg;
18396 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18400 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
18406 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18407 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18408 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
18409 goto nla_put_failure;
18411 genlmsg_end(msg, hdr);
18413 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18414 NL80211_MCGRP_MLME, gfp);
18421 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
18422 const u8 *ie, u8 ie_len,
18423 int sig_dbm, gfp_t gfp)
18425 struct wireless_dev *wdev = dev->ieee80211_ptr;
18426 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18427 struct sk_buff *msg;
18430 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
18433 trace_cfg80211_notify_new_peer_candidate(dev, addr);
18435 msg = nlmsg_new(100 + ie_len, gfp);
18439 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
18445 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18446 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18447 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
18449 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
18451 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
18452 goto nla_put_failure;
18454 genlmsg_end(msg, hdr);
18456 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18457 NL80211_MCGRP_MLME, gfp);
18463 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
18465 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
18466 struct net_device *netdev, const u8 *addr,
18467 enum nl80211_key_type key_type, int key_id,
18468 const u8 *tsc, gfp_t gfp)
18470 struct sk_buff *msg;
18473 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18477 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
18483 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18485 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
18486 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
18488 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
18489 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
18490 goto nla_put_failure;
18492 genlmsg_end(msg, hdr);
18494 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18495 NL80211_MCGRP_MLME, gfp);
18502 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
18503 struct ieee80211_channel *channel_before,
18504 struct ieee80211_channel *channel_after)
18506 struct sk_buff *msg;
18508 struct nlattr *nl_freq;
18510 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
18514 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
18521 * Since we are applying the beacon hint to a wiphy we know its
18522 * wiphy_idx is valid
18524 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
18525 goto nla_put_failure;
18528 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
18530 goto nla_put_failure;
18532 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
18533 goto nla_put_failure;
18534 nla_nest_end(msg, nl_freq);
18537 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
18539 goto nla_put_failure;
18541 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
18542 goto nla_put_failure;
18543 nla_nest_end(msg, nl_freq);
18545 genlmsg_end(msg, hdr);
18548 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
18549 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
18558 static void nl80211_send_remain_on_chan_event(
18559 int cmd, struct cfg80211_registered_device *rdev,
18560 struct wireless_dev *wdev, u64 cookie,
18561 struct ieee80211_channel *chan,
18562 unsigned int duration, gfp_t gfp)
18564 struct sk_buff *msg;
18567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18571 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
18577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18578 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18579 wdev->netdev->ifindex)) ||
18580 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18581 NL80211_ATTR_PAD) ||
18582 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
18583 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
18584 NL80211_CHAN_NO_HT) ||
18585 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
18587 goto nla_put_failure;
18589 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
18590 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
18591 goto nla_put_failure;
18593 genlmsg_end(msg, hdr);
18595 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18596 NL80211_MCGRP_MLME, gfp);
18603 void cfg80211_assoc_comeback(struct net_device *netdev,
18604 const u8 *ap_addr, u32 timeout)
18606 struct wireless_dev *wdev = netdev->ieee80211_ptr;
18607 struct wiphy *wiphy = wdev->wiphy;
18608 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18609 struct sk_buff *msg;
18612 trace_cfg80211_assoc_comeback(wdev, ap_addr, timeout);
18614 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
18618 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ASSOC_COMEBACK);
18624 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18625 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18626 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ap_addr) ||
18627 nla_put_u32(msg, NL80211_ATTR_TIMEOUT, timeout))
18628 goto nla_put_failure;
18630 genlmsg_end(msg, hdr);
18632 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18633 NL80211_MCGRP_MLME, GFP_KERNEL);
18639 EXPORT_SYMBOL(cfg80211_assoc_comeback);
18641 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
18642 struct ieee80211_channel *chan,
18643 unsigned int duration, gfp_t gfp)
18645 struct wiphy *wiphy = wdev->wiphy;
18646 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18648 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
18649 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
18650 rdev, wdev, cookie, chan,
18653 EXPORT_SYMBOL(cfg80211_ready_on_channel);
18655 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
18656 struct ieee80211_channel *chan,
18659 struct wiphy *wiphy = wdev->wiphy;
18660 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18662 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
18663 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
18664 rdev, wdev, cookie, chan, 0, gfp);
18666 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
18668 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
18669 struct ieee80211_channel *chan,
18672 struct wiphy *wiphy = wdev->wiphy;
18673 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18675 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
18676 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
18677 rdev, wdev, cookie, chan, 0, gfp);
18679 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
18681 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
18682 struct station_info *sinfo, gfp_t gfp)
18684 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18685 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18686 struct sk_buff *msg;
18688 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
18690 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18694 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
18695 rdev, dev, mac_addr, sinfo) < 0) {
18700 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18701 NL80211_MCGRP_MLME, gfp);
18703 EXPORT_SYMBOL(cfg80211_new_sta);
18705 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
18706 struct station_info *sinfo, gfp_t gfp)
18708 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18709 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18710 struct sk_buff *msg;
18711 struct station_info empty_sinfo = {};
18714 sinfo = &empty_sinfo;
18716 trace_cfg80211_del_sta(dev, mac_addr);
18718 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18720 cfg80211_sinfo_release_content(sinfo);
18724 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
18725 rdev, dev, mac_addr, sinfo) < 0) {
18730 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18731 NL80211_MCGRP_MLME, gfp);
18733 EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
18735 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
18736 enum nl80211_connect_failed_reason reason,
18739 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18740 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18741 struct sk_buff *msg;
18744 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
18748 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
18754 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18755 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
18756 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
18757 goto nla_put_failure;
18759 genlmsg_end(msg, hdr);
18761 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18762 NL80211_MCGRP_MLME, gfp);
18768 EXPORT_SYMBOL(cfg80211_conn_failed);
18770 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
18771 const u8 *addr, gfp_t gfp)
18773 struct wireless_dev *wdev = dev->ieee80211_ptr;
18774 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18775 struct sk_buff *msg;
18777 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
18782 msg = nlmsg_new(100, gfp);
18786 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
18792 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18793 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18794 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
18795 goto nla_put_failure;
18797 genlmsg_end(msg, hdr);
18798 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
18806 bool cfg80211_rx_spurious_frame(struct net_device *dev,
18807 const u8 *addr, gfp_t gfp)
18809 struct wireless_dev *wdev = dev->ieee80211_ptr;
18812 trace_cfg80211_rx_spurious_frame(dev, addr);
18814 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
18815 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
18816 trace_cfg80211_return_bool(false);
18819 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
18821 trace_cfg80211_return_bool(ret);
18824 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
18826 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
18827 const u8 *addr, gfp_t gfp)
18829 struct wireless_dev *wdev = dev->ieee80211_ptr;
18832 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
18834 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
18835 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
18836 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
18837 trace_cfg80211_return_bool(false);
18840 ret = __nl80211_unexpected_frame(dev,
18841 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
18843 trace_cfg80211_return_bool(ret);
18846 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
18848 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
18849 struct wireless_dev *wdev, u32 nlportid,
18850 struct cfg80211_rx_info *info, gfp_t gfp)
18852 struct net_device *netdev = wdev->netdev;
18853 struct sk_buff *msg;
18856 msg = nlmsg_new(100 + info->len, gfp);
18860 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
18866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18867 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18868 netdev->ifindex)) ||
18869 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18870 NL80211_ATTR_PAD) ||
18871 (info->have_link_id &&
18872 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, info->link_id)) ||
18873 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(info->freq)) ||
18874 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, info->freq % 1000) ||
18876 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, info->sig_dbm)) ||
18877 nla_put(msg, NL80211_ATTR_FRAME, info->len, info->buf) ||
18879 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, info->flags)) ||
18880 (info->rx_tstamp && nla_put_u64_64bit(msg,
18881 NL80211_ATTR_RX_HW_TIMESTAMP,
18883 NL80211_ATTR_PAD)) ||
18884 (info->ack_tstamp && nla_put_u64_64bit(msg,
18885 NL80211_ATTR_TX_HW_TIMESTAMP,
18887 NL80211_ATTR_PAD)))
18888 goto nla_put_failure;
18890 genlmsg_end(msg, hdr);
18892 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
18899 static void nl80211_frame_tx_status(struct wireless_dev *wdev,
18900 struct cfg80211_tx_status *status,
18901 gfp_t gfp, enum nl80211_commands command)
18903 struct wiphy *wiphy = wdev->wiphy;
18904 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18905 struct net_device *netdev = wdev->netdev;
18906 struct sk_buff *msg;
18909 if (command == NL80211_CMD_FRAME_TX_STATUS)
18910 trace_cfg80211_mgmt_tx_status(wdev, status->cookie,
18913 trace_cfg80211_control_port_tx_status(wdev, status->cookie,
18916 msg = nlmsg_new(100 + status->len, gfp);
18920 hdr = nl80211hdr_put(msg, 0, 0, 0, command);
18926 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18927 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18928 netdev->ifindex)) ||
18929 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18930 NL80211_ATTR_PAD) ||
18931 nla_put(msg, NL80211_ATTR_FRAME, status->len, status->buf) ||
18932 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, status->cookie,
18933 NL80211_ATTR_PAD) ||
18934 (status->ack && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
18935 (status->tx_tstamp &&
18936 nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP,
18937 status->tx_tstamp, NL80211_ATTR_PAD)) ||
18938 (status->ack_tstamp &&
18939 nla_put_u64_64bit(msg, NL80211_ATTR_RX_HW_TIMESTAMP,
18940 status->ack_tstamp, NL80211_ATTR_PAD)))
18941 goto nla_put_failure;
18943 genlmsg_end(msg, hdr);
18945 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18946 NL80211_MCGRP_MLME, gfp);
18953 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie,
18954 const u8 *buf, size_t len, bool ack,
18957 struct cfg80211_tx_status status = {
18964 nl80211_frame_tx_status(wdev, &status, gfp,
18965 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS);
18967 EXPORT_SYMBOL(cfg80211_control_port_tx_status);
18969 void cfg80211_mgmt_tx_status_ext(struct wireless_dev *wdev,
18970 struct cfg80211_tx_status *status, gfp_t gfp)
18972 nl80211_frame_tx_status(wdev, status, gfp, NL80211_CMD_FRAME_TX_STATUS);
18974 EXPORT_SYMBOL(cfg80211_mgmt_tx_status_ext);
18976 static int __nl80211_rx_control_port(struct net_device *dev,
18977 struct sk_buff *skb,
18982 struct wireless_dev *wdev = dev->ieee80211_ptr;
18983 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18984 struct ethhdr *ehdr = eth_hdr(skb);
18985 const u8 *addr = ehdr->h_source;
18986 u16 proto = be16_to_cpu(skb->protocol);
18987 struct sk_buff *msg;
18989 struct nlattr *frame;
18991 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
18996 msg = nlmsg_new(100 + skb->len, gfp);
19000 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
19006 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19007 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19008 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19009 NL80211_ATTR_PAD) ||
19010 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
19011 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
19013 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) ||
19014 (unencrypted && nla_put_flag(msg,
19015 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
19016 goto nla_put_failure;
19018 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
19020 goto nla_put_failure;
19022 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
19023 genlmsg_end(msg, hdr);
19025 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
19032 bool cfg80211_rx_control_port(struct net_device *dev, struct sk_buff *skb,
19033 bool unencrypted, int link_id)
19037 trace_cfg80211_rx_control_port(dev, skb, unencrypted, link_id);
19038 ret = __nl80211_rx_control_port(dev, skb, unencrypted, link_id,
19040 trace_cfg80211_return_bool(ret == 0);
19043 EXPORT_SYMBOL(cfg80211_rx_control_port);
19045 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
19046 const char *mac, gfp_t gfp)
19048 struct wireless_dev *wdev = dev->ieee80211_ptr;
19049 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19050 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19056 cb = (void **)msg->cb;
19058 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
19064 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19065 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19066 goto nla_put_failure;
19068 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
19069 goto nla_put_failure;
19071 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
19073 goto nla_put_failure;
19083 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
19085 void **cb = (void **)msg->cb;
19086 struct cfg80211_registered_device *rdev = cb[2];
19088 nla_nest_end(msg, cb[1]);
19089 genlmsg_end(msg, cb[0]);
19091 memset(msg->cb, 0, sizeof(msg->cb));
19093 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19094 NL80211_MCGRP_MLME, gfp);
19097 void cfg80211_cqm_rssi_notify(struct net_device *dev,
19098 enum nl80211_cqm_rssi_threshold_event rssi_event,
19099 s32 rssi_level, gfp_t gfp)
19101 struct wireless_dev *wdev = dev->ieee80211_ptr;
19102 struct cfg80211_cqm_config *cqm_config;
19104 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
19106 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
19107 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
19111 cqm_config = rcu_dereference(wdev->cqm_config);
19113 cqm_config->last_rssi_event_value = rssi_level;
19114 cqm_config->last_rssi_event_type = rssi_event;
19115 wiphy_work_queue(wdev->wiphy, &wdev->cqm_rssi_work);
19119 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
19121 void cfg80211_cqm_rssi_notify_work(struct wiphy *wiphy, struct wiphy_work *work)
19123 struct wireless_dev *wdev = container_of(work, struct wireless_dev,
19125 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19126 enum nl80211_cqm_rssi_threshold_event rssi_event;
19127 struct cfg80211_cqm_config *cqm_config;
19128 struct sk_buff *msg;
19132 cqm_config = rcu_dereference_protected(wdev->cqm_config,
19133 lockdep_is_held(&wdev->mtx));
19134 if (!wdev->cqm_config)
19137 cfg80211_cqm_rssi_update(rdev, wdev->netdev, cqm_config);
19139 rssi_level = cqm_config->last_rssi_event_value;
19140 rssi_event = cqm_config->last_rssi_event_type;
19142 msg = cfg80211_prepare_cqm(wdev->netdev, NULL, GFP_KERNEL);
19146 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
19148 goto nla_put_failure;
19150 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
19152 goto nla_put_failure;
19154 cfg80211_send_cqm(msg, GFP_KERNEL);
19164 void cfg80211_cqm_txe_notify(struct net_device *dev,
19165 const u8 *peer, u32 num_packets,
19166 u32 rate, u32 intvl, gfp_t gfp)
19168 struct sk_buff *msg;
19170 msg = cfg80211_prepare_cqm(dev, peer, gfp);
19174 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
19175 goto nla_put_failure;
19177 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
19178 goto nla_put_failure;
19180 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
19181 goto nla_put_failure;
19183 cfg80211_send_cqm(msg, gfp);
19189 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
19191 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
19192 const u8 *peer, u32 num_packets, gfp_t gfp)
19194 struct sk_buff *msg;
19196 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
19198 msg = cfg80211_prepare_cqm(dev, peer, gfp);
19202 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
19203 goto nla_put_failure;
19205 cfg80211_send_cqm(msg, gfp);
19211 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
19213 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
19215 struct sk_buff *msg;
19217 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
19221 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
19222 goto nla_put_failure;
19224 cfg80211_send_cqm(msg, gfp);
19230 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
19232 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
19233 struct net_device *netdev, const u8 *bssid,
19234 const u8 *replay_ctr, gfp_t gfp)
19236 struct sk_buff *msg;
19237 struct nlattr *rekey_attr;
19240 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19244 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
19250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19251 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19252 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
19253 goto nla_put_failure;
19255 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
19257 goto nla_put_failure;
19259 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
19260 NL80211_REPLAY_CTR_LEN, replay_ctr))
19261 goto nla_put_failure;
19263 nla_nest_end(msg, rekey_attr);
19265 genlmsg_end(msg, hdr);
19267 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19268 NL80211_MCGRP_MLME, gfp);
19275 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
19276 const u8 *replay_ctr, gfp_t gfp)
19278 struct wireless_dev *wdev = dev->ieee80211_ptr;
19279 struct wiphy *wiphy = wdev->wiphy;
19280 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19282 trace_cfg80211_gtk_rekey_notify(dev, bssid);
19283 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
19285 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
19288 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
19289 struct net_device *netdev, int index,
19290 const u8 *bssid, bool preauth, gfp_t gfp)
19292 struct sk_buff *msg;
19293 struct nlattr *attr;
19296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19300 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
19306 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19307 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
19308 goto nla_put_failure;
19310 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
19312 goto nla_put_failure;
19314 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
19315 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
19317 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
19318 goto nla_put_failure;
19320 nla_nest_end(msg, attr);
19322 genlmsg_end(msg, hdr);
19324 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19325 NL80211_MCGRP_MLME, gfp);
19332 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
19333 const u8 *bssid, bool preauth, gfp_t gfp)
19335 struct wireless_dev *wdev = dev->ieee80211_ptr;
19336 struct wiphy *wiphy = wdev->wiphy;
19337 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19339 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
19340 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
19342 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
19344 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
19345 struct net_device *netdev,
19346 unsigned int link_id,
19347 struct cfg80211_chan_def *chandef,
19349 enum nl80211_commands notif,
19350 u8 count, bool quiet, u16 punct_bitmap)
19352 struct wireless_dev *wdev = netdev->ieee80211_ptr;
19353 struct sk_buff *msg;
19356 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19360 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
19366 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
19367 goto nla_put_failure;
19369 if (wdev->valid_links &&
19370 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
19371 goto nla_put_failure;
19373 if (nl80211_send_chandef(msg, chandef))
19374 goto nla_put_failure;
19376 if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) {
19377 if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))
19378 goto nla_put_failure;
19380 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))
19381 goto nla_put_failure;
19384 if (nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP, punct_bitmap))
19385 goto nla_put_failure;
19387 genlmsg_end(msg, hdr);
19389 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19390 NL80211_MCGRP_MLME, gfp);
19397 void cfg80211_ch_switch_notify(struct net_device *dev,
19398 struct cfg80211_chan_def *chandef,
19399 unsigned int link_id, u16 punct_bitmap)
19401 struct wireless_dev *wdev = dev->ieee80211_ptr;
19402 struct wiphy *wiphy = wdev->wiphy;
19403 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19405 ASSERT_WDEV_LOCK(wdev);
19406 WARN_INVALID_LINK_ID(wdev, link_id);
19408 trace_cfg80211_ch_switch_notify(dev, chandef, link_id, punct_bitmap);
19410 switch (wdev->iftype) {
19411 case NL80211_IFTYPE_STATION:
19412 case NL80211_IFTYPE_P2P_CLIENT:
19413 if (!WARN_ON(!wdev->links[link_id].client.current_bss))
19414 cfg80211_update_assoc_bss_entry(wdev, link_id,
19417 case NL80211_IFTYPE_MESH_POINT:
19418 wdev->u.mesh.chandef = *chandef;
19419 wdev->u.mesh.preset_chandef = *chandef;
19421 case NL80211_IFTYPE_AP:
19422 case NL80211_IFTYPE_P2P_GO:
19423 wdev->links[link_id].ap.chandef = *chandef;
19425 case NL80211_IFTYPE_ADHOC:
19426 wdev->u.ibss.chandef = *chandef;
19433 cfg80211_sched_dfs_chan_update(rdev);
19435 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL,
19436 NL80211_CMD_CH_SWITCH_NOTIFY, 0, false,
19439 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
19441 void cfg80211_ch_switch_started_notify(struct net_device *dev,
19442 struct cfg80211_chan_def *chandef,
19443 unsigned int link_id, u8 count,
19444 bool quiet, u16 punct_bitmap)
19446 struct wireless_dev *wdev = dev->ieee80211_ptr;
19447 struct wiphy *wiphy = wdev->wiphy;
19448 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19450 ASSERT_WDEV_LOCK(wdev);
19451 WARN_INVALID_LINK_ID(wdev, link_id);
19453 trace_cfg80211_ch_switch_started_notify(dev, chandef, link_id,
19457 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL,
19458 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY,
19459 count, quiet, punct_bitmap);
19461 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
19463 int cfg80211_bss_color_notify(struct net_device *dev,
19464 enum nl80211_commands cmd, u8 count,
19467 struct wireless_dev *wdev = dev->ieee80211_ptr;
19468 struct wiphy *wiphy = wdev->wiphy;
19469 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19470 struct sk_buff *msg;
19473 ASSERT_WDEV_LOCK(wdev);
19475 trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap);
19477 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
19481 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
19483 goto nla_put_failure;
19485 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19486 goto nla_put_failure;
19488 if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED &&
19489 nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count))
19490 goto nla_put_failure;
19492 if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION &&
19493 nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP,
19494 color_bitmap, NL80211_ATTR_PAD))
19495 goto nla_put_failure;
19497 genlmsg_end(msg, hdr);
19499 return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
19500 msg, 0, NL80211_MCGRP_MLME, GFP_KERNEL);
19506 EXPORT_SYMBOL(cfg80211_bss_color_notify);
19509 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
19510 const struct cfg80211_chan_def *chandef,
19511 enum nl80211_radar_event event,
19512 struct net_device *netdev, gfp_t gfp)
19514 struct sk_buff *msg;
19517 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19521 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
19527 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
19528 goto nla_put_failure;
19530 /* NOP and radar events don't need a netdev parameter */
19532 struct wireless_dev *wdev = netdev->ieee80211_ptr;
19534 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19535 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19537 goto nla_put_failure;
19540 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
19541 goto nla_put_failure;
19543 if (nl80211_send_chandef(msg, chandef))
19544 goto nla_put_failure;
19546 genlmsg_end(msg, hdr);
19548 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19549 NL80211_MCGRP_MLME, gfp);
19556 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
19557 struct sta_opmode_info *sta_opmode,
19560 struct sk_buff *msg;
19561 struct wireless_dev *wdev = dev->ieee80211_ptr;
19562 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19572 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
19578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
19579 goto nla_put_failure;
19581 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19582 goto nla_put_failure;
19584 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
19585 goto nla_put_failure;
19587 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
19588 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
19589 goto nla_put_failure;
19591 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
19592 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
19593 goto nla_put_failure;
19595 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
19596 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
19597 goto nla_put_failure;
19599 genlmsg_end(msg, hdr);
19601 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19602 NL80211_MCGRP_MLME, gfp);
19609 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
19611 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
19612 u64 cookie, bool acked, s32 ack_signal,
19613 bool is_valid_ack_signal, gfp_t gfp)
19615 struct wireless_dev *wdev = dev->ieee80211_ptr;
19616 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19617 struct sk_buff *msg;
19620 trace_cfg80211_probe_status(dev, addr, cookie, acked);
19622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19627 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
19633 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19634 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19635 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
19636 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
19637 NL80211_ATTR_PAD) ||
19638 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
19639 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
19641 goto nla_put_failure;
19643 genlmsg_end(msg, hdr);
19645 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19646 NL80211_MCGRP_MLME, gfp);
19652 EXPORT_SYMBOL(cfg80211_probe_status);
19654 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
19655 size_t len, int freq, int sig_dbm)
19657 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19658 struct sk_buff *msg;
19660 struct cfg80211_beacon_registration *reg;
19662 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
19664 spin_lock_bh(&rdev->beacon_registrations_lock);
19665 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
19666 msg = nlmsg_new(len + 100, GFP_ATOMIC);
19668 spin_unlock_bh(&rdev->beacon_registrations_lock);
19672 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
19674 goto nla_put_failure;
19676 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19678 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
19679 KHZ_TO_MHZ(freq)) ||
19680 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
19683 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
19684 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
19685 goto nla_put_failure;
19687 genlmsg_end(msg, hdr);
19689 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
19691 spin_unlock_bh(&rdev->beacon_registrations_lock);
19695 spin_unlock_bh(&rdev->beacon_registrations_lock);
19698 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
19701 static int cfg80211_net_detect_results(struct sk_buff *msg,
19702 struct cfg80211_wowlan_wakeup *wakeup)
19704 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
19705 struct nlattr *nl_results, *nl_match, *nl_freqs;
19708 nl_results = nla_nest_start_noflag(msg,
19709 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
19713 for (i = 0; i < nd->n_matches; i++) {
19714 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
19716 nl_match = nla_nest_start_noflag(msg, i);
19720 /* The SSID attribute is optional in nl80211, but for
19721 * simplicity reasons it's always present in the
19722 * cfg80211 structure. If a driver can't pass the
19723 * SSID, that needs to be changed. A zero length SSID
19724 * is still a valid SSID (wildcard), so it cannot be
19725 * used for this purpose.
19727 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
19728 match->ssid.ssid)) {
19729 nla_nest_cancel(msg, nl_match);
19733 if (match->n_channels) {
19734 nl_freqs = nla_nest_start_noflag(msg,
19735 NL80211_ATTR_SCAN_FREQUENCIES);
19737 nla_nest_cancel(msg, nl_match);
19741 for (j = 0; j < match->n_channels; j++) {
19742 if (nla_put_u32(msg, j, match->channels[j])) {
19743 nla_nest_cancel(msg, nl_freqs);
19744 nla_nest_cancel(msg, nl_match);
19749 nla_nest_end(msg, nl_freqs);
19752 nla_nest_end(msg, nl_match);
19756 nla_nest_end(msg, nl_results);
19760 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
19761 struct cfg80211_wowlan_wakeup *wakeup,
19764 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19765 struct sk_buff *msg;
19769 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
19772 size += wakeup->packet_present_len;
19774 msg = nlmsg_new(size, gfp);
19778 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
19782 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19783 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19787 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
19788 wdev->netdev->ifindex))
19792 struct nlattr *reasons;
19794 reasons = nla_nest_start_noflag(msg,
19795 NL80211_ATTR_WOWLAN_TRIGGERS);
19799 if (wakeup->disconnect &&
19800 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
19802 if (wakeup->magic_pkt &&
19803 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
19805 if (wakeup->gtk_rekey_failure &&
19806 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
19808 if (wakeup->eap_identity_req &&
19809 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
19811 if (wakeup->four_way_handshake &&
19812 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
19814 if (wakeup->rfkill_release &&
19815 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
19818 if (wakeup->pattern_idx >= 0 &&
19819 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
19820 wakeup->pattern_idx))
19823 if (wakeup->tcp_match &&
19824 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
19827 if (wakeup->tcp_connlost &&
19828 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
19831 if (wakeup->tcp_nomoretokens &&
19833 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
19836 if (wakeup->packet) {
19837 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
19838 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
19840 if (!wakeup->packet_80211) {
19842 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
19844 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
19847 if (wakeup->packet_len &&
19848 nla_put_u32(msg, len_attr, wakeup->packet_len))
19851 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
19856 if (wakeup->net_detect &&
19857 cfg80211_net_detect_results(msg, wakeup))
19860 nla_nest_end(msg, reasons);
19863 genlmsg_end(msg, hdr);
19865 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19866 NL80211_MCGRP_MLME, gfp);
19872 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
19875 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
19876 enum nl80211_tdls_operation oper,
19877 u16 reason_code, gfp_t gfp)
19879 struct wireless_dev *wdev = dev->ieee80211_ptr;
19880 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19881 struct sk_buff *msg;
19884 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
19887 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19891 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
19897 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19898 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19899 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
19900 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
19901 (reason_code > 0 &&
19902 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
19903 goto nla_put_failure;
19905 genlmsg_end(msg, hdr);
19907 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19908 NL80211_MCGRP_MLME, gfp);
19914 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
19916 static int nl80211_netlink_notify(struct notifier_block * nb,
19917 unsigned long state,
19920 struct netlink_notify *notify = _notify;
19921 struct cfg80211_registered_device *rdev;
19922 struct wireless_dev *wdev;
19923 struct cfg80211_beacon_registration *reg, *tmp;
19925 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
19926 return NOTIFY_DONE;
19930 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
19931 struct cfg80211_sched_scan_request *sched_scan_req;
19933 list_for_each_entry_rcu(sched_scan_req,
19934 &rdev->sched_scan_req_list,
19936 if (sched_scan_req->owner_nlportid == notify->portid) {
19937 sched_scan_req->nl_owner_dead = true;
19938 wiphy_work_queue(&rdev->wiphy,
19939 &rdev->sched_scan_stop_wk);
19943 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
19944 cfg80211_mlme_unregister_socket(wdev, notify->portid);
19946 if (wdev->owner_nlportid == notify->portid) {
19947 wdev->nl_owner_dead = true;
19948 schedule_work(&rdev->destroy_work);
19949 } else if (wdev->conn_owner_nlportid == notify->portid) {
19950 schedule_work(&wdev->disconnect_wk);
19953 cfg80211_release_pmsr(wdev, notify->portid);
19956 spin_lock_bh(&rdev->beacon_registrations_lock);
19957 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
19959 if (reg->nlportid == notify->portid) {
19960 list_del(®->list);
19965 spin_unlock_bh(&rdev->beacon_registrations_lock);
19971 * It is possible that the user space process that is controlling the
19972 * indoor setting disappeared, so notify the regulatory core.
19974 regulatory_netlink_notify(notify->portid);
19978 static struct notifier_block nl80211_netlink_notifier = {
19979 .notifier_call = nl80211_netlink_notify,
19982 void cfg80211_ft_event(struct net_device *netdev,
19983 struct cfg80211_ft_event_params *ft_event)
19985 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
19986 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19987 struct sk_buff *msg;
19990 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
19992 if (!ft_event->target_ap)
19995 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
20000 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
20004 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20005 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
20006 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
20009 if (ft_event->ies &&
20010 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
20012 if (ft_event->ric_ies &&
20013 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
20014 ft_event->ric_ies))
20017 genlmsg_end(msg, hdr);
20019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
20020 NL80211_MCGRP_MLME, GFP_KERNEL);
20025 EXPORT_SYMBOL(cfg80211_ft_event);
20027 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
20029 struct cfg80211_registered_device *rdev;
20030 struct sk_buff *msg;
20034 rdev = wiphy_to_rdev(wdev->wiphy);
20035 if (!rdev->crit_proto_nlportid)
20038 nlportid = rdev->crit_proto_nlportid;
20039 rdev->crit_proto_nlportid = 0;
20041 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
20045 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
20047 goto nla_put_failure;
20049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20050 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
20052 goto nla_put_failure;
20054 genlmsg_end(msg, hdr);
20056 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
20062 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
20064 void nl80211_send_ap_stopped(struct wireless_dev *wdev, unsigned int link_id)
20066 struct wiphy *wiphy = wdev->wiphy;
20067 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
20068 struct sk_buff *msg;
20071 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
20075 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
20079 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20080 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
20081 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
20082 NL80211_ATTR_PAD) ||
20083 (wdev->valid_links &&
20084 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)))
20087 genlmsg_end(msg, hdr);
20089 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
20090 NL80211_MCGRP_MLME, GFP_KERNEL);
20096 int cfg80211_external_auth_request(struct net_device *dev,
20097 struct cfg80211_external_auth_params *params,
20100 struct wireless_dev *wdev = dev->ieee80211_ptr;
20101 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
20102 struct sk_buff *msg;
20105 if (!wdev->conn_owner_nlportid)
20108 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
20112 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
20114 goto nla_put_failure;
20116 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20117 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
20118 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
20119 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
20121 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
20122 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
20123 params->ssid.ssid) ||
20124 (!is_zero_ether_addr(params->mld_addr) &&
20125 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, params->mld_addr)))
20126 goto nla_put_failure;
20128 genlmsg_end(msg, hdr);
20129 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
20130 wdev->conn_owner_nlportid);
20137 EXPORT_SYMBOL(cfg80211_external_auth_request);
20139 void cfg80211_update_owe_info_event(struct net_device *netdev,
20140 struct cfg80211_update_owe_info *owe_info,
20143 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
20144 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
20145 struct sk_buff *msg;
20148 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
20150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
20154 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
20156 goto nla_put_failure;
20158 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20159 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
20160 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
20161 goto nla_put_failure;
20163 if (!owe_info->ie_len ||
20164 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
20165 goto nla_put_failure;
20167 if (owe_info->assoc_link_id != -1) {
20168 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
20169 owe_info->assoc_link_id))
20170 goto nla_put_failure;
20172 if (!is_zero_ether_addr(owe_info->peer_mld_addr) &&
20173 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN,
20174 owe_info->peer_mld_addr))
20175 goto nla_put_failure;
20178 genlmsg_end(msg, hdr);
20180 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
20181 NL80211_MCGRP_MLME, gfp);
20185 genlmsg_cancel(msg, hdr);
20188 EXPORT_SYMBOL(cfg80211_update_owe_info_event);
20190 /* initialisation/exit functions */
20192 int __init nl80211_init(void)
20196 err = genl_register_family(&nl80211_fam);
20200 err = netlink_register_notifier(&nl80211_netlink_notifier);
20206 genl_unregister_family(&nl80211_fam);
20210 void nl80211_exit(void)
20212 netlink_unregister_notifier(&nl80211_netlink_notifier);
20213 genl_unregister_family(&nl80211_fam);