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 },
328 static const struct nla_policy
329 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
330 [NL80211_PMSR_TYPE_FTM] =
331 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
334 static const struct nla_policy
335 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
336 [NL80211_PMSR_REQ_ATTR_DATA] =
337 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
338 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
341 static const struct nla_policy
342 nl80211_pmsr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
343 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
344 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy),
345 [NL80211_PMSR_PEER_ATTR_REQ] =
346 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
347 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
350 static const struct nla_policy
351 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
352 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
353 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
354 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
355 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
356 [NL80211_PMSR_ATTR_PEERS] =
357 NLA_POLICY_NESTED_ARRAY(nl80211_pmsr_peer_attr_policy),
360 static const struct nla_policy
361 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = {
362 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] =
363 NLA_POLICY_RANGE(NLA_U8, 1, 20),
364 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] =
365 NLA_POLICY_RANGE(NLA_U8, 1, 20),
366 [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] =
367 NLA_POLICY_RANGE(NLA_U8, 1, 20),
368 [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] =
369 NLA_POLICY_EXACT_LEN(8),
370 [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] =
371 NLA_POLICY_EXACT_LEN(8),
372 [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 },
375 static const struct nla_policy
376 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = {
377 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63),
378 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG },
379 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG },
382 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
383 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
384 .len = NL80211_MAX_SUPP_RATES },
385 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
386 .len = NL80211_MAX_SUPP_HT_RATES },
387 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)),
388 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
389 [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)),
390 [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8,
391 NL80211_RATE_INFO_HE_GI_0_8,
392 NL80211_RATE_INFO_HE_GI_3_2),
393 [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8,
394 NL80211_RATE_INFO_HE_1XLTF,
395 NL80211_RATE_INFO_HE_4XLTF),
398 static const struct nla_policy
399 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = {
400 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 },
401 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 },
402 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG },
403 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff),
404 [NL80211_TID_CONFIG_ATTR_NOACK] =
405 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
406 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
407 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
408 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] =
409 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
410 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] =
411 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
412 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] =
413 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
414 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] =
415 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED),
416 [NL80211_TID_CONFIG_ATTR_TX_RATE] =
417 NLA_POLICY_NESTED(nl80211_txattr_policy),
420 static const struct nla_policy
421 nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = {
422 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000),
423 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000),
424 [NL80211_FILS_DISCOVERY_ATTR_TMPL] =
425 NLA_POLICY_RANGE(NLA_BINARY,
426 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN,
427 IEEE80211_MAX_DATA_LEN),
430 static const struct nla_policy
431 nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = {
432 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20),
433 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY,
434 .len = IEEE80211_MAX_DATA_LEN }
437 static const struct nla_policy
438 sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = {
439 [NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_S32 },
440 [NL80211_SAR_ATTR_SPECS_RANGE_INDEX] = {.type = NLA_U32 },
443 static const struct nla_policy
444 sar_policy[NL80211_SAR_ATTR_MAX + 1] = {
445 [NL80211_SAR_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_SAR_TYPE),
446 [NL80211_SAR_ATTR_SPECS] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy),
449 static const struct nla_policy
450 nl80211_mbssid_config_policy[NL80211_MBSSID_CONFIG_ATTR_MAX + 1] = {
451 [NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES] = NLA_POLICY_MIN(NLA_U8, 2),
452 [NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY] =
453 NLA_POLICY_MIN(NLA_U8, 1),
454 [NL80211_MBSSID_CONFIG_ATTR_INDEX] = { .type = NLA_U8 },
455 [NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX] = { .type = NLA_U32 },
456 [NL80211_MBSSID_CONFIG_ATTR_EMA] = { .type = NLA_FLAG },
459 static const struct nla_policy
460 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
461 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
462 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
465 static struct netlink_range_validation nl80211_punct_bitmap_range = {
470 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
471 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
472 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
473 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
475 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
477 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
478 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
479 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
480 NL80211_EDMG_CHANNELS_MIN,
481 NL80211_EDMG_CHANNELS_MAX),
482 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
483 NL80211_EDMG_BW_CONFIG_MIN,
484 NL80211_EDMG_BW_CONFIG_MAX),
486 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
487 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
488 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
489 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
491 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
492 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
493 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
494 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
495 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
496 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
498 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
499 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
500 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
502 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
503 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
505 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
506 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
507 .len = WLAN_MAX_KEY_LEN },
508 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
509 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
510 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
511 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
512 [NL80211_ATTR_KEY_TYPE] =
513 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
515 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
516 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
517 [NL80211_ATTR_BEACON_HEAD] =
518 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
519 IEEE80211_MAX_DATA_LEN),
520 [NL80211_ATTR_BEACON_TAIL] =
521 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
522 IEEE80211_MAX_DATA_LEN),
523 [NL80211_ATTR_STA_AID] =
524 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
525 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
526 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
527 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
528 .len = NL80211_MAX_SUPP_RATES },
529 [NL80211_ATTR_STA_PLINK_ACTION] =
530 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
531 [NL80211_ATTR_STA_TX_POWER_SETTING] =
532 NLA_POLICY_RANGE(NLA_U8,
533 NL80211_TX_POWER_AUTOMATIC,
534 NL80211_TX_POWER_FIXED),
535 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
536 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
537 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
538 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
539 .len = IEEE80211_MAX_MESH_ID_LEN },
540 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
542 /* allow 3 for NUL-termination, we used to declare this NLA_STRING */
543 [NL80211_ATTR_REG_ALPHA2] = NLA_POLICY_RANGE(NLA_BINARY, 2, 3),
544 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
546 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
547 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
548 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
549 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
550 .len = NL80211_MAX_SUPP_RATES },
551 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
553 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
554 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
556 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN),
558 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
559 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
561 IEEE80211_MAX_DATA_LEN),
562 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
563 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
565 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
566 .len = IEEE80211_MAX_SSID_LEN },
567 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
568 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
569 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
570 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
571 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
573 NL80211_MFP_OPTIONAL),
574 [NL80211_ATTR_STA_FLAGS2] =
575 NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_sta_flag_update)),
576 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
577 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
578 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
579 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
580 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
581 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
582 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
583 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
584 [NL80211_ATTR_PID] = { .type = NLA_U32 },
585 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
586 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN),
587 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
588 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
589 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
590 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
591 .len = IEEE80211_MAX_DATA_LEN },
592 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
593 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
596 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
597 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
598 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
599 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
600 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
601 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
602 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
603 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
604 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
605 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
606 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
607 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
608 [NL80211_ATTR_STA_PLINK_STATE] =
609 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
610 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
611 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
612 [NL80211_ATTR_MESH_PEER_AID] =
613 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
614 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
615 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
616 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
617 [NL80211_ATTR_HIDDEN_SSID] =
618 NLA_POLICY_RANGE(NLA_U32,
619 NL80211_HIDDEN_SSID_NOT_IN_USE,
620 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
621 [NL80211_ATTR_IE_PROBE_RESP] =
622 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
623 IEEE80211_MAX_DATA_LEN),
624 [NL80211_ATTR_IE_ASSOC_RESP] =
625 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
626 IEEE80211_MAX_DATA_LEN),
627 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
628 [NL80211_ATTR_STA_WME] = NLA_POLICY_NESTED(nl80211_sta_wme_policy),
629 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
630 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
631 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
632 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
633 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
634 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
635 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
636 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
637 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
638 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
639 .len = IEEE80211_MAX_DATA_LEN },
640 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
641 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
642 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
643 .len = NL80211_HT_CAPABILITY_LEN
645 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
646 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
647 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
648 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
649 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
651 /* need to include at least Auth Transaction and Status Code */
652 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4),
654 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN),
655 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
656 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
657 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
658 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
659 NLA_POLICY_RANGE(NLA_U32,
660 NL80211_MESH_POWER_UNKNOWN + 1,
661 NL80211_MESH_POWER_MAX),
662 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
663 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
664 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
665 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
666 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
667 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
668 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
669 .len = NL80211_VHT_CAPABILITY_LEN,
671 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
672 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
673 .len = IEEE80211_MAX_DATA_LEN },
674 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
675 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] =
676 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION),
677 [NL80211_ATTR_PEER_AID] =
678 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
679 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
680 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
681 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
682 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY },
683 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY },
684 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2),
686 * The value of the Length field of the Supported Operating
687 * Classes element is between 2 and 253.
689 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] =
690 NLA_POLICY_RANGE(NLA_BINARY, 2, 253),
691 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
692 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
693 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
694 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
695 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
696 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY,
697 IEEE80211_QOS_MAP_LEN_MIN,
698 IEEE80211_QOS_MAP_LEN_MAX),
699 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
700 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
701 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
702 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
703 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
704 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
705 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
706 [NL80211_ATTR_USER_PRIO] =
707 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
708 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
709 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
710 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
711 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
712 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
713 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
714 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
715 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
716 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
717 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
718 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
719 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
720 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
721 .len = VHT_MUMIMO_GROUPS_DATA_LEN
723 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
724 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
725 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
726 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
727 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
728 .len = FILS_MAX_KEK_LEN },
729 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN),
730 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
731 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
732 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
733 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
734 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
736 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
737 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
738 .len = FILS_ERP_MAX_USERNAME_LEN },
739 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
740 .len = FILS_ERP_MAX_REALM_LEN },
741 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
742 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
743 .len = FILS_ERP_MAX_RRK_LEN },
744 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2),
745 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
746 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN),
747 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
748 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
750 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
751 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
752 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
753 [NL80211_ATTR_HE_CAPABILITY] =
754 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_he_capa,
755 NL80211_HE_MAX_CAPABILITY_LEN),
756 [NL80211_ATTR_FTM_RESPONDER] =
757 NLA_POLICY_NESTED(nl80211_ftm_responder_policy),
758 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
759 [NL80211_ATTR_PEER_MEASUREMENTS] =
760 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
761 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
762 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
763 .len = SAE_PASSWORD_MAX_LEN },
764 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
765 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
766 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
767 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
768 [NL80211_ATTR_TID_CONFIG] =
769 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
770 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG },
771 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1),
772 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100),
773 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG },
774 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
775 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED },
776 [NL80211_ATTR_HE_6GHZ_CAPABILITY] =
777 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)),
778 [NL80211_ATTR_FILS_DISCOVERY] =
779 NLA_POLICY_NESTED(nl80211_fils_discovery_policy),
780 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] =
781 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy),
782 [NL80211_ATTR_S1G_CAPABILITY] =
783 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
784 [NL80211_ATTR_S1G_CAPABILITY_MASK] =
785 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
786 [NL80211_ATTR_SAE_PWE] =
787 NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK,
788 NL80211_SAE_PWE_BOTH),
789 [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT },
790 [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy),
791 [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG },
792 [NL80211_ATTR_OBSS_COLOR_BITMAP] = { .type = NLA_U64 },
793 [NL80211_ATTR_COLOR_CHANGE_COUNT] = { .type = NLA_U8 },
794 [NL80211_ATTR_COLOR_CHANGE_COLOR] = { .type = NLA_U8 },
795 [NL80211_ATTR_COLOR_CHANGE_ELEMS] = NLA_POLICY_NESTED(nl80211_policy),
796 [NL80211_ATTR_MBSSID_CONFIG] =
797 NLA_POLICY_NESTED(nl80211_mbssid_config_policy),
798 [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED },
799 [NL80211_ATTR_RADAR_BACKGROUND] = { .type = NLA_FLAG },
800 [NL80211_ATTR_AP_SETTINGS_FLAGS] = { .type = NLA_U32 },
801 [NL80211_ATTR_EHT_CAPABILITY] =
802 NLA_POLICY_RANGE(NLA_BINARY,
803 NL80211_EHT_MIN_CAPABILITY_LEN,
804 NL80211_EHT_MAX_CAPABILITY_LEN),
805 [NL80211_ATTR_DISABLE_EHT] = { .type = NLA_FLAG },
806 [NL80211_ATTR_MLO_LINKS] =
807 NLA_POLICY_NESTED_ARRAY(nl80211_policy),
808 [NL80211_ATTR_MLO_LINK_ID] =
809 NLA_POLICY_RANGE(NLA_U8, 0, IEEE80211_MLD_MAX_NUM_LINKS),
810 [NL80211_ATTR_MLD_ADDR] = NLA_POLICY_EXACT_LEN(ETH_ALEN),
811 [NL80211_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG },
812 [NL80211_ATTR_MAX_NUM_AKM_SUITES] = { .type = NLA_REJECT },
813 [NL80211_ATTR_PUNCT_BITMAP] =
814 NLA_POLICY_FULL_RANGE(NLA_U32, &nl80211_punct_bitmap_range),
816 [NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS] = { .type = NLA_U16 },
817 [NL80211_ATTR_HW_TIMESTAMP_ENABLED] = { .type = NLA_FLAG },
818 [NL80211_ATTR_EMA_RNR_ELEMS] = { .type = NLA_NESTED },
819 [NL80211_ATTR_MLO_LINK_DISABLED] = { .type = NLA_FLAG },
822 /* policy for the key attributes */
823 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
824 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
825 [NL80211_KEY_IDX] = { .type = NLA_U8 },
826 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
827 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
828 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
829 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
830 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
831 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
832 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
835 /* policy for the key default flags */
836 static const struct nla_policy
837 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
838 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
839 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
843 /* policy for WoWLAN attributes */
844 static const struct nla_policy
845 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
846 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
847 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
848 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
849 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
850 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
851 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
852 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
853 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
854 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
855 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
858 static const struct nla_policy
859 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
860 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
861 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
862 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
863 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
864 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
865 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
866 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
867 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
869 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
870 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
872 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
873 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
874 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1),
876 #endif /* CONFIG_PM */
878 /* policy for coalesce rule attributes */
879 static const struct nla_policy
880 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
881 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
882 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
883 NLA_POLICY_RANGE(NLA_U32,
884 NL80211_COALESCE_CONDITION_MATCH,
885 NL80211_COALESCE_CONDITION_NO_MATCH),
886 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
889 /* policy for GTK rekey offload attributes */
890 static const struct nla_policy
891 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
892 [NL80211_REKEY_DATA_KEK] = {
894 .len = NL80211_KEK_EXT_LEN
896 [NL80211_REKEY_DATA_KCK] = {
898 .len = NL80211_KCK_EXT_LEN_32
900 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN),
901 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 },
904 static const struct nla_policy
905 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
906 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
907 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
908 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
909 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
910 [NL80211_BAND_LC] = { .type = NLA_S32 },
913 static const struct nla_policy
914 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
915 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
916 .len = IEEE80211_MAX_SSID_LEN },
917 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
918 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
919 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
920 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
923 static const struct nla_policy
924 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
925 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
926 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
929 static const struct nla_policy
930 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
931 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
932 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
933 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
934 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
938 /* policy for NAN function attributes */
939 static const struct nla_policy
940 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
941 [NL80211_NAN_FUNC_TYPE] =
942 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE),
943 [NL80211_NAN_FUNC_SERVICE_ID] = {
944 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
945 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
946 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
947 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
948 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
949 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
950 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
951 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
952 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
953 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
954 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
955 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
956 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
957 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
958 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
959 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
962 /* policy for Service Response Filter attributes */
963 static const struct nla_policy
964 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
965 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
966 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
967 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
968 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
969 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
972 /* policy for packet pattern attributes */
973 static const struct nla_policy
974 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
975 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
976 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
977 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
980 static int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
981 struct cfg80211_registered_device **rdev,
982 struct wireless_dev **wdev,
983 struct nlattr **attrbuf)
988 struct nlattr **attrbuf_free = NULL;
991 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
995 attrbuf_free = attrbuf;
998 err = nlmsg_parse_deprecated(cb->nlh,
999 GENL_HDRLEN + nl80211_fam.hdrsize,
1000 attrbuf, nl80211_fam.maxattr,
1001 nl80211_policy, NULL);
1003 kfree(attrbuf_free);
1008 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk),
1010 kfree(attrbuf_free);
1011 if (IS_ERR(*wdev)) {
1013 return PTR_ERR(*wdev);
1015 *rdev = wiphy_to_rdev((*wdev)->wiphy);
1016 mutex_lock(&(*rdev)->wiphy.mtx);
1018 /* 0 is the first index - add 1 to parse only once */
1019 cb->args[0] = (*rdev)->wiphy_idx + 1;
1020 cb->args[1] = (*wdev)->identifier;
1022 /* subtract the 1 again here */
1023 struct wiphy *wiphy;
1024 struct wireless_dev *tmp;
1027 wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
1032 *rdev = wiphy_to_rdev(wiphy);
1035 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
1036 if (tmp->identifier == cb->args[1]) {
1046 mutex_lock(&(*rdev)->wiphy.mtx);
1053 /* message building helper */
1054 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
1057 /* since there is no private header just add the generic one */
1058 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
1061 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
1062 const struct ieee80211_reg_rule *rule)
1065 struct nlattr *nl_wmm_rules =
1066 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
1069 goto nla_put_failure;
1071 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
1072 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
1075 goto nla_put_failure;
1077 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
1078 rule->wmm_rule.client[j].cw_min) ||
1079 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
1080 rule->wmm_rule.client[j].cw_max) ||
1081 nla_put_u8(msg, NL80211_WMMR_AIFSN,
1082 rule->wmm_rule.client[j].aifsn) ||
1083 nla_put_u16(msg, NL80211_WMMR_TXOP,
1084 rule->wmm_rule.client[j].cot))
1085 goto nla_put_failure;
1087 nla_nest_end(msg, nl_wmm_rule);
1089 nla_nest_end(msg, nl_wmm_rules);
1097 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
1098 struct ieee80211_channel *chan,
1101 /* Some channels must be completely excluded from the
1102 * list to protect old user-space tools from breaking
1104 if (!large && chan->flags &
1105 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
1107 if (!large && chan->freq_offset)
1110 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
1112 goto nla_put_failure;
1114 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
1115 goto nla_put_failure;
1117 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
1118 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
1119 goto nla_put_failure;
1120 if (chan->flags & IEEE80211_CHAN_NO_IR) {
1121 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
1122 goto nla_put_failure;
1123 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
1124 goto nla_put_failure;
1126 if (chan->flags & IEEE80211_CHAN_RADAR) {
1127 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
1128 goto nla_put_failure;
1132 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
1134 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
1136 goto nla_put_failure;
1137 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
1139 goto nla_put_failure;
1140 if (nla_put_u32(msg,
1141 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
1143 goto nla_put_failure;
1148 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
1149 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
1150 goto nla_put_failure;
1151 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
1152 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
1153 goto nla_put_failure;
1154 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
1155 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
1156 goto nla_put_failure;
1157 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
1158 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
1159 goto nla_put_failure;
1160 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
1161 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
1162 goto nla_put_failure;
1163 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
1164 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
1165 goto nla_put_failure;
1166 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
1167 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
1168 goto nla_put_failure;
1169 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
1170 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
1171 goto nla_put_failure;
1172 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
1173 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
1174 goto nla_put_failure;
1175 if ((chan->flags & IEEE80211_CHAN_1MHZ) &&
1176 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ))
1177 goto nla_put_failure;
1178 if ((chan->flags & IEEE80211_CHAN_2MHZ) &&
1179 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ))
1180 goto nla_put_failure;
1181 if ((chan->flags & IEEE80211_CHAN_4MHZ) &&
1182 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ))
1183 goto nla_put_failure;
1184 if ((chan->flags & IEEE80211_CHAN_8MHZ) &&
1185 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ))
1186 goto nla_put_failure;
1187 if ((chan->flags & IEEE80211_CHAN_16MHZ) &&
1188 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ))
1189 goto nla_put_failure;
1190 if ((chan->flags & IEEE80211_CHAN_NO_320MHZ) &&
1191 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_320MHZ))
1192 goto nla_put_failure;
1193 if ((chan->flags & IEEE80211_CHAN_NO_EHT) &&
1194 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_EHT))
1195 goto nla_put_failure;
1198 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
1199 DBM_TO_MBM(chan->max_power)))
1200 goto nla_put_failure;
1203 const struct ieee80211_reg_rule *rule =
1204 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
1206 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
1207 if (nl80211_msg_put_wmm_rules(msg, rule))
1208 goto nla_put_failure;
1218 static bool nl80211_put_txq_stats(struct sk_buff *msg,
1219 struct cfg80211_txq_stats *txqstats,
1222 struct nlattr *txqattr;
1224 #define PUT_TXQVAL_U32(attr, memb) do { \
1225 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1226 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1230 txqattr = nla_nest_start_noflag(msg, attrtype);
1234 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1235 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1236 PUT_TXQVAL_U32(FLOWS, flows);
1237 PUT_TXQVAL_U32(DROPS, drops);
1238 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1239 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1240 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1241 PUT_TXQVAL_U32(COLLISIONS, collisions);
1242 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1243 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1244 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1245 nla_nest_end(msg, txqattr);
1247 #undef PUT_TXQVAL_U32
1251 /* netlink command implementations */
1254 * nl80211_link_id - return link ID
1255 * @attrs: attributes to look at
1257 * Returns: the link ID or 0 if not given
1259 * Note this function doesn't do any validation of the link
1260 * ID validity wrt. links that were actually added, so it must
1261 * be called only from ops with %NL80211_FLAG_MLO_VALID_LINK_ID
1262 * or if additional validation is done.
1264 static unsigned int nl80211_link_id(struct nlattr **attrs)
1266 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID];
1271 return nla_get_u8(linkid);
1274 static int nl80211_link_id_or_invalid(struct nlattr **attrs)
1276 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID];
1281 return nla_get_u8(linkid);
1285 struct key_params p;
1288 bool def, defmgmt, defbeacon;
1289 bool def_uni, def_multi;
1292 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1293 struct key_parse *k)
1295 struct nlattr *tb[NL80211_KEY_MAX + 1];
1296 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1302 k->def = !!tb[NL80211_KEY_DEFAULT];
1303 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1304 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
1308 k->def_multi = true;
1310 if (k->defmgmt || k->defbeacon)
1311 k->def_multi = true;
1313 if (tb[NL80211_KEY_IDX])
1314 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1316 if (tb[NL80211_KEY_DATA]) {
1317 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1318 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1321 if (tb[NL80211_KEY_SEQ]) {
1322 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1323 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1326 if (tb[NL80211_KEY_CIPHER])
1327 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1329 if (tb[NL80211_KEY_TYPE])
1330 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
1332 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1333 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1335 err = nla_parse_nested_deprecated(kdt,
1336 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1337 tb[NL80211_KEY_DEFAULT_TYPES],
1338 nl80211_key_default_policy,
1343 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1344 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1347 if (tb[NL80211_KEY_MODE])
1348 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1353 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1355 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1356 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1357 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1360 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1361 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1362 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1365 if (info->attrs[NL80211_ATTR_KEY_IDX])
1366 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1368 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1369 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1371 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1372 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1376 k->def_multi = true;
1379 k->def_multi = true;
1381 if (info->attrs[NL80211_ATTR_KEY_TYPE])
1382 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1384 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1385 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1386 int err = nla_parse_nested_deprecated(kdt,
1387 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1388 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1389 nl80211_key_default_policy,
1394 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1395 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1401 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1405 memset(k, 0, sizeof(*k));
1409 if (info->attrs[NL80211_ATTR_KEY])
1410 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
1412 err = nl80211_parse_key_old(info, k);
1417 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1418 (k->defbeacon ? 1 : 0) > 1) {
1419 GENL_SET_ERR_MSG(info,
1420 "key with multiple default flags is invalid");
1424 if (k->defmgmt || k->defbeacon) {
1425 if (k->def_uni || !k->def_multi) {
1426 GENL_SET_ERR_MSG(info,
1427 "defmgmt/defbeacon key must be mcast");
1434 if (k->idx < 4 || k->idx > 5) {
1435 GENL_SET_ERR_MSG(info,
1436 "defmgmt key idx not 4 or 5");
1439 } else if (k->defbeacon) {
1440 if (k->idx < 6 || k->idx > 7) {
1441 GENL_SET_ERR_MSG(info,
1442 "defbeacon key idx not 6 or 7");
1445 } else if (k->def) {
1446 if (k->idx < 0 || k->idx > 3) {
1447 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
1451 if (k->idx < 0 || k->idx > 7) {
1452 GENL_SET_ERR_MSG(info, "key idx not 0-7");
1461 static struct cfg80211_cached_keys *
1462 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
1463 struct genl_info *info, bool *no_ht)
1465 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
1466 struct key_parse parse;
1468 struct cfg80211_cached_keys *result;
1469 int rem, err, def = 0;
1470 bool have_key = false;
1472 nla_for_each_nested(key, keys, rem) {
1480 result = kzalloc(sizeof(*result), GFP_KERNEL);
1482 return ERR_PTR(-ENOMEM);
1486 nla_for_each_nested(key, keys, rem) {
1487 memset(&parse, 0, sizeof(parse));
1490 err = nl80211_parse_key_new(info, key, &parse);
1496 if (parse.idx < 0 || parse.idx > 3) {
1497 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
1502 GENL_SET_ERR_MSG(info,
1503 "only one key can be default");
1507 result->def = parse.idx;
1508 if (!parse.def_uni || !parse.def_multi)
1510 } else if (parse.defmgmt)
1512 err = cfg80211_validate_key_settings(rdev, &parse.p,
1513 parse.idx, false, NULL);
1516 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1517 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
1518 GENL_SET_ERR_MSG(info, "connect key must be WEP");
1522 result->params[parse.idx].cipher = parse.p.cipher;
1523 result->params[parse.idx].key_len = parse.p.key_len;
1524 result->params[parse.idx].key = result->data[parse.idx];
1525 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
1527 /* must be WEP key if we got here */
1532 if (result->def < 0) {
1534 GENL_SET_ERR_MSG(info, "need a default/TX key");
1541 return ERR_PTR(err);
1544 static int nl80211_key_allowed(struct wireless_dev *wdev)
1546 ASSERT_WDEV_LOCK(wdev);
1548 switch (wdev->iftype) {
1549 case NL80211_IFTYPE_AP:
1550 case NL80211_IFTYPE_AP_VLAN:
1551 case NL80211_IFTYPE_P2P_GO:
1552 case NL80211_IFTYPE_MESH_POINT:
1554 case NL80211_IFTYPE_ADHOC:
1555 if (wdev->u.ibss.current_bss)
1558 case NL80211_IFTYPE_STATION:
1559 case NL80211_IFTYPE_P2P_CLIENT:
1560 if (wdev->connected)
1563 case NL80211_IFTYPE_NAN:
1564 if (wiphy_ext_feature_isset(wdev->wiphy,
1565 NL80211_EXT_FEATURE_SECURE_NAN))
1568 case NL80211_IFTYPE_UNSPECIFIED:
1569 case NL80211_IFTYPE_OCB:
1570 case NL80211_IFTYPE_MONITOR:
1571 case NL80211_IFTYPE_P2P_DEVICE:
1572 case NL80211_IFTYPE_WDS:
1573 case NUM_NL80211_IFTYPES:
1580 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1583 struct ieee80211_channel *chan;
1585 chan = ieee80211_get_channel_khz(wiphy, freq);
1586 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1591 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1593 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
1597 goto nla_put_failure;
1601 if ((ifmodes & 1) && nla_put_flag(msg, i))
1602 goto nla_put_failure;
1607 nla_nest_end(msg, nl_modes);
1614 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1615 struct sk_buff *msg,
1618 struct nlattr *nl_combis;
1621 nl_combis = nla_nest_start_noflag(msg,
1622 NL80211_ATTR_INTERFACE_COMBINATIONS);
1624 goto nla_put_failure;
1626 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1627 const struct ieee80211_iface_combination *c;
1628 struct nlattr *nl_combi, *nl_limits;
1630 c = &wiphy->iface_combinations[i];
1632 nl_combi = nla_nest_start_noflag(msg, i + 1);
1634 goto nla_put_failure;
1636 nl_limits = nla_nest_start_noflag(msg,
1637 NL80211_IFACE_COMB_LIMITS);
1639 goto nla_put_failure;
1641 for (j = 0; j < c->n_limits; j++) {
1642 struct nlattr *nl_limit;
1644 nl_limit = nla_nest_start_noflag(msg, j + 1);
1646 goto nla_put_failure;
1647 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1649 goto nla_put_failure;
1650 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1651 c->limits[j].types))
1652 goto nla_put_failure;
1653 nla_nest_end(msg, nl_limit);
1656 nla_nest_end(msg, nl_limits);
1658 if (c->beacon_int_infra_match &&
1659 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1660 goto nla_put_failure;
1661 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1662 c->num_different_channels) ||
1663 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1665 goto nla_put_failure;
1667 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1668 c->radar_detect_widths) ||
1669 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1670 c->radar_detect_regions)))
1671 goto nla_put_failure;
1672 if (c->beacon_int_min_gcd &&
1673 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1674 c->beacon_int_min_gcd))
1675 goto nla_put_failure;
1677 nla_nest_end(msg, nl_combi);
1680 nla_nest_end(msg, nl_combis);
1688 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1689 struct sk_buff *msg)
1691 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
1692 struct nlattr *nl_tcp;
1697 nl_tcp = nla_nest_start_noflag(msg,
1698 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1702 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1703 tcp->data_payload_max))
1706 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1707 tcp->data_payload_max))
1710 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1713 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1714 sizeof(*tcp->tok), tcp->tok))
1717 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1718 tcp->data_interval_max))
1721 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1722 tcp->wake_payload_max))
1725 nla_nest_end(msg, nl_tcp);
1729 static int nl80211_send_wowlan(struct sk_buff *msg,
1730 struct cfg80211_registered_device *rdev,
1733 struct nlattr *nl_wowlan;
1735 if (!rdev->wiphy.wowlan)
1738 nl_wowlan = nla_nest_start_noflag(msg,
1739 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1743 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
1744 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1745 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
1746 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1747 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1748 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1749 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1750 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1751 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1752 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1753 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1754 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1755 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1756 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1757 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1758 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1761 if (rdev->wiphy.wowlan->n_patterns) {
1762 struct nl80211_pattern_support pat = {
1763 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1764 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1765 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1766 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
1769 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1774 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1775 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1776 rdev->wiphy.wowlan->max_nd_match_sets))
1779 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
1782 nla_nest_end(msg, nl_wowlan);
1788 static int nl80211_send_coalesce(struct sk_buff *msg,
1789 struct cfg80211_registered_device *rdev)
1791 struct nl80211_coalesce_rule_support rule;
1793 if (!rdev->wiphy.coalesce)
1796 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1797 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1798 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1799 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1800 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1801 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
1803 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1810 nl80211_send_iftype_data(struct sk_buff *msg,
1811 const struct ieee80211_supported_band *sband,
1812 const struct ieee80211_sband_iftype_data *iftdata)
1814 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1815 const struct ieee80211_sta_eht_cap *eht_cap = &iftdata->eht_cap;
1817 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1818 iftdata->types_mask))
1821 if (he_cap->has_he) {
1822 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1823 sizeof(he_cap->he_cap_elem.mac_cap_info),
1824 he_cap->he_cap_elem.mac_cap_info) ||
1825 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1826 sizeof(he_cap->he_cap_elem.phy_cap_info),
1827 he_cap->he_cap_elem.phy_cap_info) ||
1828 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1829 sizeof(he_cap->he_mcs_nss_supp),
1830 &he_cap->he_mcs_nss_supp) ||
1831 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1832 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1836 if (eht_cap->has_eht && he_cap->has_he) {
1837 u8 mcs_nss_size, ppe_thresh_size;
1841 is_ap = iftdata->types_mask & BIT(NL80211_IFTYPE_AP) ||
1842 iftdata->types_mask & BIT(NL80211_IFTYPE_P2P_GO);
1845 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
1846 &eht_cap->eht_cap_elem,
1849 ppe_thres_hdr = get_unaligned_le16(&eht_cap->eht_ppe_thres[0]);
1851 ieee80211_eht_ppe_size(ppe_thres_hdr,
1852 eht_cap->eht_cap_elem.phy_cap_info);
1854 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC,
1855 sizeof(eht_cap->eht_cap_elem.mac_cap_info),
1856 eht_cap->eht_cap_elem.mac_cap_info) ||
1857 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY,
1858 sizeof(eht_cap->eht_cap_elem.phy_cap_info),
1859 eht_cap->eht_cap_elem.phy_cap_info) ||
1860 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET,
1861 mcs_nss_size, &eht_cap->eht_mcs_nss_supp) ||
1862 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE,
1863 ppe_thresh_size, eht_cap->eht_ppe_thres))
1867 if (sband->band == NL80211_BAND_6GHZ &&
1868 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA,
1869 sizeof(iftdata->he_6ghz_capa),
1870 &iftdata->he_6ghz_capa))
1873 if (iftdata->vendor_elems.data && iftdata->vendor_elems.len &&
1874 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS,
1875 iftdata->vendor_elems.len, iftdata->vendor_elems.data))
1881 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1882 struct ieee80211_supported_band *sband,
1885 struct nlattr *nl_rates, *nl_rate;
1886 struct ieee80211_rate *rate;
1890 if (sband->ht_cap.ht_supported &&
1891 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1892 sizeof(sband->ht_cap.mcs),
1893 &sband->ht_cap.mcs) ||
1894 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1895 sband->ht_cap.cap) ||
1896 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1897 sband->ht_cap.ampdu_factor) ||
1898 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1899 sband->ht_cap.ampdu_density)))
1903 if (sband->vht_cap.vht_supported &&
1904 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1905 sizeof(sband->vht_cap.vht_mcs),
1906 &sband->vht_cap.vht_mcs) ||
1907 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1908 sband->vht_cap.cap)))
1911 if (large && sband->n_iftype_data) {
1912 struct nlattr *nl_iftype_data =
1913 nla_nest_start_noflag(msg,
1914 NL80211_BAND_ATTR_IFTYPE_DATA);
1917 if (!nl_iftype_data)
1920 for (i = 0; i < sband->n_iftype_data; i++) {
1921 struct nlattr *iftdata;
1923 iftdata = nla_nest_start_noflag(msg, i + 1);
1927 err = nl80211_send_iftype_data(msg, sband,
1928 &sband->iftype_data[i]);
1932 nla_nest_end(msg, iftdata);
1935 nla_nest_end(msg, nl_iftype_data);
1939 if (large && sband->edmg_cap.channels &&
1940 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1941 sband->edmg_cap.channels) ||
1942 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1943 sband->edmg_cap.bw_config)))
1948 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
1952 for (i = 0; i < sband->n_bitrates; i++) {
1953 nl_rate = nla_nest_start_noflag(msg, i);
1957 rate = &sband->bitrates[i];
1958 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1961 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1963 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1966 nla_nest_end(msg, nl_rate);
1969 nla_nest_end(msg, nl_rates);
1971 /* S1G capabilities */
1972 if (sband->band == NL80211_BAND_S1GHZ && sband->s1g_cap.s1g &&
1973 (nla_put(msg, NL80211_BAND_ATTR_S1G_CAPA,
1974 sizeof(sband->s1g_cap.cap),
1975 sband->s1g_cap.cap) ||
1976 nla_put(msg, NL80211_BAND_ATTR_S1G_MCS_NSS_SET,
1977 sizeof(sband->s1g_cap.nss_mcs),
1978 sband->s1g_cap.nss_mcs)))
1985 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1986 const struct ieee80211_txrx_stypes *mgmt_stypes)
1989 struct nlattr *nl_ftypes, *nl_ifs;
1990 enum nl80211_iftype ift;
1996 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
2000 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
2001 nl_ftypes = nla_nest_start_noflag(msg, ift);
2005 stypes = mgmt_stypes[ift].tx;
2008 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
2009 (i << 4) | IEEE80211_FTYPE_MGMT))
2014 nla_nest_end(msg, nl_ftypes);
2017 nla_nest_end(msg, nl_ifs);
2019 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
2023 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
2024 nl_ftypes = nla_nest_start_noflag(msg, ift);
2028 stypes = mgmt_stypes[ift].rx;
2031 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
2032 (i << 4) | IEEE80211_FTYPE_MGMT))
2037 nla_nest_end(msg, nl_ftypes);
2039 nla_nest_end(msg, nl_ifs);
2044 #define CMD(op, n) \
2046 if (rdev->ops->op) { \
2048 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
2049 goto nla_put_failure; \
2053 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
2054 struct sk_buff *msg)
2059 * do *NOT* add anything into this function, new things need to be
2060 * advertised only to new versions of userspace that can deal with
2061 * the split (and they can't possibly care about new features...
2063 CMD(add_virtual_intf, NEW_INTERFACE);
2064 CMD(change_virtual_intf, SET_INTERFACE);
2065 CMD(add_key, NEW_KEY);
2066 CMD(start_ap, START_AP);
2067 CMD(add_station, NEW_STATION);
2068 CMD(add_mpath, NEW_MPATH);
2069 CMD(update_mesh_config, SET_MESH_CONFIG);
2070 CMD(change_bss, SET_BSS);
2071 CMD(auth, AUTHENTICATE);
2072 CMD(assoc, ASSOCIATE);
2073 CMD(deauth, DEAUTHENTICATE);
2074 CMD(disassoc, DISASSOCIATE);
2075 CMD(join_ibss, JOIN_IBSS);
2076 CMD(join_mesh, JOIN_MESH);
2077 CMD(set_pmksa, SET_PMKSA);
2078 CMD(del_pmksa, DEL_PMKSA);
2079 CMD(flush_pmksa, FLUSH_PMKSA);
2080 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
2081 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
2082 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
2083 CMD(mgmt_tx, FRAME);
2084 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
2085 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
2087 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
2088 goto nla_put_failure;
2090 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
2091 rdev->ops->join_mesh) {
2093 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
2094 goto nla_put_failure;
2096 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2097 CMD(tdls_mgmt, TDLS_MGMT);
2098 CMD(tdls_oper, TDLS_OPER);
2100 if (rdev->wiphy.max_sched_scan_reqs)
2101 CMD(sched_scan_start, START_SCHED_SCAN);
2102 CMD(probe_client, PROBE_CLIENT);
2103 CMD(set_noack_map, SET_NOACK_MAP);
2104 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
2106 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
2107 goto nla_put_failure;
2109 CMD(start_p2p_device, START_P2P_DEVICE);
2110 CMD(set_mcast_rate, SET_MCAST_RATE);
2111 #ifdef CONFIG_NL80211_TESTMODE
2112 CMD(testmode_cmd, TESTMODE);
2115 if (rdev->ops->connect || rdev->ops->auth) {
2117 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
2118 goto nla_put_failure;
2121 if (rdev->ops->disconnect || rdev->ops->deauth) {
2123 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
2124 goto nla_put_failure;
2133 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
2134 struct sk_buff *msg)
2138 if (!cap->ftm.supported)
2141 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
2145 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
2147 if (cap->ftm.non_asap &&
2148 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
2150 if (cap->ftm.request_lci &&
2151 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
2153 if (cap->ftm.request_civicloc &&
2154 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
2156 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
2157 cap->ftm.preambles))
2159 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
2160 cap->ftm.bandwidths))
2162 if (cap->ftm.max_bursts_exponent >= 0 &&
2163 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
2164 cap->ftm.max_bursts_exponent))
2166 if (cap->ftm.max_ftms_per_burst &&
2167 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
2168 cap->ftm.max_ftms_per_burst))
2170 if (cap->ftm.trigger_based &&
2171 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED))
2173 if (cap->ftm.non_trigger_based &&
2174 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED))
2177 nla_nest_end(msg, ftm);
2181 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
2182 struct sk_buff *msg)
2184 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
2185 struct nlattr *pmsr, *caps;
2191 * we don't need to clean up anything here since the caller
2192 * will genlmsg_cancel() if we fail
2195 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
2199 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
2202 if (cap->report_ap_tsf &&
2203 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
2206 if (cap->randomize_mac_addr &&
2207 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
2210 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
2214 if (nl80211_send_pmsr_ftm_capa(cap, msg))
2217 nla_nest_end(msg, caps);
2218 nla_nest_end(msg, pmsr);
2224 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev,
2225 struct sk_buff *msg)
2228 struct nlattr *nested, *nested_akms;
2229 const struct wiphy_iftype_akm_suites *iftype_akms;
2231 if (!rdev->wiphy.num_iftype_akm_suites ||
2232 !rdev->wiphy.iftype_akm_suites)
2235 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES);
2239 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) {
2240 nested_akms = nla_nest_start(msg, i + 1);
2244 iftype_akms = &rdev->wiphy.iftype_akm_suites[i];
2246 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES,
2247 iftype_akms->iftypes_mask))
2250 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES,
2251 sizeof(u32) * iftype_akms->n_akm_suites,
2252 iftype_akms->akm_suites)) {
2255 nla_nest_end(msg, nested_akms);
2258 nla_nest_end(msg, nested);
2264 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev,
2265 struct sk_buff *msg)
2267 struct nlattr *supp;
2269 if (!rdev->wiphy.tid_config_support.vif &&
2270 !rdev->wiphy.tid_config_support.peer)
2273 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG);
2277 if (rdev->wiphy.tid_config_support.vif &&
2278 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP,
2279 rdev->wiphy.tid_config_support.vif,
2280 NL80211_TID_CONFIG_ATTR_PAD))
2283 if (rdev->wiphy.tid_config_support.peer &&
2284 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP,
2285 rdev->wiphy.tid_config_support.peer,
2286 NL80211_TID_CONFIG_ATTR_PAD))
2289 /* for now we just use the same value ... makes more sense */
2290 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT,
2291 rdev->wiphy.tid_config_support.max_retry))
2293 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG,
2294 rdev->wiphy.tid_config_support.max_retry))
2297 nla_nest_end(msg, supp);
2301 nla_nest_cancel(msg, supp);
2306 nl80211_put_sar_specs(struct cfg80211_registered_device *rdev,
2307 struct sk_buff *msg)
2309 struct nlattr *sar_capa, *specs, *sub_freq_range;
2313 if (!rdev->wiphy.sar_capa)
2316 num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges;
2318 sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC);
2322 if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type))
2325 specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS);
2329 /* report supported freq_ranges */
2330 for (i = 0; i < num_freq_ranges; i++) {
2331 sub_freq_range = nla_nest_start(msg, i + 1);
2332 if (!sub_freq_range)
2335 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ,
2336 rdev->wiphy.sar_capa->freq_ranges[i].start_freq))
2339 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ,
2340 rdev->wiphy.sar_capa->freq_ranges[i].end_freq))
2343 nla_nest_end(msg, sub_freq_range);
2346 nla_nest_end(msg, specs);
2347 nla_nest_end(msg, sar_capa);
2351 nla_nest_cancel(msg, sar_capa);
2355 static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg)
2357 struct nlattr *config;
2359 if (!wiphy->mbssid_max_interfaces)
2362 config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG);
2366 if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES,
2367 wiphy->mbssid_max_interfaces))
2370 if (wiphy->ema_max_profile_periodicity &&
2372 NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY,
2373 wiphy->ema_max_profile_periodicity))
2376 nla_nest_end(msg, config);
2380 nla_nest_cancel(msg, config);
2384 struct nl80211_dump_wiphy_state {
2387 long split_start, band_start, chan_start, capa_start;
2391 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2392 enum nl80211_commands cmd,
2393 struct sk_buff *msg, u32 portid, u32 seq,
2394 int flags, struct nl80211_dump_wiphy_state *state)
2397 struct nlattr *nl_bands, *nl_band;
2398 struct nlattr *nl_freqs, *nl_freq;
2399 struct nlattr *nl_cmds;
2400 enum nl80211_band band;
2401 struct ieee80211_channel *chan;
2403 const struct ieee80211_txrx_stypes *mgmt_stypes =
2404 rdev->wiphy.mgmt_stypes;
2407 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
2411 if (WARN_ON(!state))
2414 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2415 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
2416 wiphy_name(&rdev->wiphy)) ||
2417 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2418 cfg80211_rdev_list_generation))
2419 goto nla_put_failure;
2421 if (cmd != NL80211_CMD_NEW_WIPHY)
2424 switch (state->split_start) {
2426 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
2427 rdev->wiphy.retry_short) ||
2428 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
2429 rdev->wiphy.retry_long) ||
2430 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
2431 rdev->wiphy.frag_threshold) ||
2432 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
2433 rdev->wiphy.rts_threshold) ||
2434 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
2435 rdev->wiphy.coverage_class) ||
2436 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
2437 rdev->wiphy.max_scan_ssids) ||
2438 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
2439 rdev->wiphy.max_sched_scan_ssids) ||
2440 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
2441 rdev->wiphy.max_scan_ie_len) ||
2442 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
2443 rdev->wiphy.max_sched_scan_ie_len) ||
2444 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
2445 rdev->wiphy.max_match_sets))
2446 goto nla_put_failure;
2448 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
2449 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2450 goto nla_put_failure;
2451 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
2452 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2453 goto nla_put_failure;
2454 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2455 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2456 goto nla_put_failure;
2457 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
2458 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2459 goto nla_put_failure;
2460 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2461 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2462 goto nla_put_failure;
2463 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
2464 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
2465 goto nla_put_failure;
2466 state->split_start++;
2471 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
2472 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2473 rdev->wiphy.cipher_suites))
2474 goto nla_put_failure;
2476 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
2477 rdev->wiphy.max_num_pmkids))
2478 goto nla_put_failure;
2480 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
2481 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2482 goto nla_put_failure;
2484 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
2485 rdev->wiphy.available_antennas_tx) ||
2486 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
2487 rdev->wiphy.available_antennas_rx))
2488 goto nla_put_failure;
2490 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
2491 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
2492 rdev->wiphy.probe_resp_offload))
2493 goto nla_put_failure;
2495 if ((rdev->wiphy.available_antennas_tx ||
2496 rdev->wiphy.available_antennas_rx) &&
2497 rdev->ops->get_antenna) {
2498 u32 tx_ant = 0, rx_ant = 0;
2501 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
2503 if (nla_put_u32(msg,
2504 NL80211_ATTR_WIPHY_ANTENNA_TX,
2507 NL80211_ATTR_WIPHY_ANTENNA_RX,
2509 goto nla_put_failure;
2513 state->split_start++;
2518 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
2519 rdev->wiphy.interface_modes))
2520 goto nla_put_failure;
2521 state->split_start++;
2526 nl_bands = nla_nest_start_noflag(msg,
2527 NL80211_ATTR_WIPHY_BANDS);
2529 goto nla_put_failure;
2531 for (band = state->band_start;
2532 band < (state->split ?
2534 NL80211_BAND_60GHZ + 1);
2536 struct ieee80211_supported_band *sband;
2538 /* omit higher bands for ancient software */
2539 if (band > NL80211_BAND_5GHZ && !state->split)
2542 sband = rdev->wiphy.bands[band];
2547 nl_band = nla_nest_start_noflag(msg, band);
2549 goto nla_put_failure;
2551 switch (state->chan_start) {
2553 if (nl80211_send_band_rateinfo(msg, sband,
2555 goto nla_put_failure;
2556 state->chan_start++;
2561 /* add frequencies */
2562 nl_freqs = nla_nest_start_noflag(msg,
2563 NL80211_BAND_ATTR_FREQS);
2565 goto nla_put_failure;
2567 for (i = state->chan_start - 1;
2568 i < sband->n_channels;
2570 nl_freq = nla_nest_start_noflag(msg,
2573 goto nla_put_failure;
2575 chan = &sband->channels[i];
2577 if (nl80211_msg_put_channel(
2578 msg, &rdev->wiphy, chan,
2580 goto nla_put_failure;
2582 nla_nest_end(msg, nl_freq);
2586 if (i < sband->n_channels)
2587 state->chan_start = i + 2;
2589 state->chan_start = 0;
2590 nla_nest_end(msg, nl_freqs);
2593 nla_nest_end(msg, nl_band);
2596 /* start again here */
2597 if (state->chan_start)
2602 nla_nest_end(msg, nl_bands);
2604 if (band < NUM_NL80211_BANDS)
2605 state->band_start = band + 1;
2607 state->band_start = 0;
2609 /* if bands & channels are done, continue outside */
2610 if (state->band_start == 0 && state->chan_start == 0)
2611 state->split_start++;
2616 nl_cmds = nla_nest_start_noflag(msg,
2617 NL80211_ATTR_SUPPORTED_COMMANDS);
2619 goto nla_put_failure;
2621 i = nl80211_add_commands_unsplit(rdev, msg);
2623 goto nla_put_failure;
2625 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2626 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
2627 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
2628 CMD(channel_switch, CHANNEL_SWITCH);
2629 CMD(set_qos_map, SET_QOS_MAP);
2630 if (rdev->wiphy.features &
2631 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
2632 CMD(add_tx_ts, ADD_TX_TS);
2633 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
2634 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
2635 CMD(update_ft_ies, UPDATE_FT_IES);
2636 if (rdev->wiphy.sar_capa)
2637 CMD(set_sar_specs, SET_SAR_SPECS);
2641 nla_nest_end(msg, nl_cmds);
2642 state->split_start++;
2647 if (rdev->ops->remain_on_channel &&
2648 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
2650 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
2651 rdev->wiphy.max_remain_on_channel_duration))
2652 goto nla_put_failure;
2654 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
2655 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2656 goto nla_put_failure;
2658 state->split_start++;
2664 if (nl80211_send_wowlan(msg, rdev, state->split))
2665 goto nla_put_failure;
2666 state->split_start++;
2670 state->split_start++;
2674 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
2675 rdev->wiphy.software_iftypes))
2676 goto nla_put_failure;
2678 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
2680 goto nla_put_failure;
2682 state->split_start++;
2687 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
2688 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
2689 rdev->wiphy.ap_sme_capa))
2690 goto nla_put_failure;
2692 features = rdev->wiphy.features;
2694 * We can only add the per-channel limit information if the
2695 * dump is split, otherwise it makes it too big. Therefore
2696 * only advertise it in that case.
2699 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2700 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
2701 goto nla_put_failure;
2703 if (rdev->wiphy.ht_capa_mod_mask &&
2704 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
2705 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2706 rdev->wiphy.ht_capa_mod_mask))
2707 goto nla_put_failure;
2709 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2710 rdev->wiphy.max_acl_mac_addrs &&
2711 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
2712 rdev->wiphy.max_acl_mac_addrs))
2713 goto nla_put_failure;
2716 * Any information below this point is only available to
2717 * applications that can deal with it being split. This
2718 * helps ensure that newly added capabilities don't break
2719 * older tools by overrunning their buffers.
2721 * We still increment split_start so that in the split
2722 * case we'll continue with more data in the next round,
2723 * but break unconditionally so unsplit data stops here.
2726 state->split_start++;
2728 state->split_start = 0;
2731 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2732 goto nla_put_failure;
2734 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
2735 rdev->wiphy.max_sched_scan_plans) ||
2736 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
2737 rdev->wiphy.max_sched_scan_plan_interval) ||
2738 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
2739 rdev->wiphy.max_sched_scan_plan_iterations))
2740 goto nla_put_failure;
2742 if (rdev->wiphy.extended_capabilities &&
2743 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
2744 rdev->wiphy.extended_capabilities_len,
2745 rdev->wiphy.extended_capabilities) ||
2746 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2747 rdev->wiphy.extended_capabilities_len,
2748 rdev->wiphy.extended_capabilities_mask)))
2749 goto nla_put_failure;
2751 if (rdev->wiphy.vht_capa_mod_mask &&
2752 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
2753 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2754 rdev->wiphy.vht_capa_mod_mask))
2755 goto nla_put_failure;
2757 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2758 rdev->wiphy.perm_addr))
2759 goto nla_put_failure;
2761 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2762 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2763 rdev->wiphy.addr_mask))
2764 goto nla_put_failure;
2766 if (rdev->wiphy.n_addresses > 1) {
2769 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2771 goto nla_put_failure;
2773 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2774 if (nla_put(msg, i + 1, ETH_ALEN,
2775 rdev->wiphy.addresses[i].addr))
2776 goto nla_put_failure;
2778 nla_nest_end(msg, attr);
2781 state->split_start++;
2784 if (nl80211_send_coalesce(msg, rdev))
2785 goto nla_put_failure;
2787 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
2788 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2789 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2790 goto nla_put_failure;
2792 if (rdev->wiphy.max_ap_assoc_sta &&
2793 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
2794 rdev->wiphy.max_ap_assoc_sta))
2795 goto nla_put_failure;
2797 state->split_start++;
2800 if (rdev->wiphy.n_vendor_commands) {
2801 const struct nl80211_vendor_cmd_info *info;
2802 struct nlattr *nested;
2804 nested = nla_nest_start_noflag(msg,
2805 NL80211_ATTR_VENDOR_DATA);
2807 goto nla_put_failure;
2809 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2810 info = &rdev->wiphy.vendor_commands[i].info;
2811 if (nla_put(msg, i + 1, sizeof(*info), info))
2812 goto nla_put_failure;
2814 nla_nest_end(msg, nested);
2817 if (rdev->wiphy.n_vendor_events) {
2818 const struct nl80211_vendor_cmd_info *info;
2819 struct nlattr *nested;
2821 nested = nla_nest_start_noflag(msg,
2822 NL80211_ATTR_VENDOR_EVENTS);
2824 goto nla_put_failure;
2826 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2827 info = &rdev->wiphy.vendor_events[i];
2828 if (nla_put(msg, i + 1, sizeof(*info), info))
2829 goto nla_put_failure;
2831 nla_nest_end(msg, nested);
2833 state->split_start++;
2836 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2837 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2838 rdev->wiphy.max_num_csa_counters))
2839 goto nla_put_failure;
2841 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2842 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2843 goto nla_put_failure;
2845 if (rdev->wiphy.max_sched_scan_reqs &&
2846 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2847 rdev->wiphy.max_sched_scan_reqs))
2848 goto nla_put_failure;
2850 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2851 sizeof(rdev->wiphy.ext_features),
2852 rdev->wiphy.ext_features))
2853 goto nla_put_failure;
2855 if (rdev->wiphy.bss_select_support) {
2856 struct nlattr *nested;
2857 u32 bss_select_support = rdev->wiphy.bss_select_support;
2859 nested = nla_nest_start_noflag(msg,
2860 NL80211_ATTR_BSS_SELECT);
2862 goto nla_put_failure;
2865 while (bss_select_support) {
2866 if ((bss_select_support & 1) &&
2867 nla_put_flag(msg, i))
2868 goto nla_put_failure;
2870 bss_select_support >>= 1;
2872 nla_nest_end(msg, nested);
2875 state->split_start++;
2878 if (rdev->wiphy.num_iftype_ext_capab &&
2879 rdev->wiphy.iftype_ext_capab) {
2880 struct nlattr *nested_ext_capab, *nested;
2882 nested = nla_nest_start_noflag(msg,
2883 NL80211_ATTR_IFTYPE_EXT_CAPA);
2885 goto nla_put_failure;
2887 for (i = state->capa_start;
2888 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2889 const struct wiphy_iftype_ext_capab *capab;
2891 capab = &rdev->wiphy.iftype_ext_capab[i];
2893 nested_ext_capab = nla_nest_start_noflag(msg,
2895 if (!nested_ext_capab ||
2896 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2898 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2899 capab->extended_capabilities_len,
2900 capab->extended_capabilities) ||
2901 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2902 capab->extended_capabilities_len,
2903 capab->extended_capabilities_mask))
2904 goto nla_put_failure;
2906 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO &&
2908 NL80211_ATTR_EML_CAPABILITY,
2909 capab->eml_capabilities) ||
2911 NL80211_ATTR_MLD_CAPA_AND_OPS,
2912 capab->mld_capa_and_ops)))
2913 goto nla_put_failure;
2915 nla_nest_end(msg, nested_ext_capab);
2919 nla_nest_end(msg, nested);
2920 if (i < rdev->wiphy.num_iftype_ext_capab) {
2921 state->capa_start = i + 1;
2926 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2927 rdev->wiphy.nan_supported_bands))
2928 goto nla_put_failure;
2930 if (wiphy_ext_feature_isset(&rdev->wiphy,
2931 NL80211_EXT_FEATURE_TXQS)) {
2932 struct cfg80211_txq_stats txqstats = {};
2935 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2937 !nl80211_put_txq_stats(msg, &txqstats,
2938 NL80211_ATTR_TXQ_STATS))
2939 goto nla_put_failure;
2941 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2942 rdev->wiphy.txq_limit))
2943 goto nla_put_failure;
2944 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2945 rdev->wiphy.txq_memory_limit))
2946 goto nla_put_failure;
2947 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2948 rdev->wiphy.txq_quantum))
2949 goto nla_put_failure;
2952 state->split_start++;
2955 if (nl80211_send_pmsr_capa(rdev, msg))
2956 goto nla_put_failure;
2958 state->split_start++;
2961 if (rdev->wiphy.akm_suites &&
2962 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2963 sizeof(u32) * rdev->wiphy.n_akm_suites,
2964 rdev->wiphy.akm_suites))
2965 goto nla_put_failure;
2967 if (nl80211_put_iftype_akm_suites(rdev, msg))
2968 goto nla_put_failure;
2970 if (nl80211_put_tid_config_support(rdev, msg))
2971 goto nla_put_failure;
2972 state->split_start++;
2975 if (nl80211_put_sar_specs(rdev, msg))
2976 goto nla_put_failure;
2978 if (nl80211_put_mbssid_support(&rdev->wiphy, msg))
2979 goto nla_put_failure;
2981 if (nla_put_u16(msg, NL80211_ATTR_MAX_NUM_AKM_SUITES,
2982 rdev->wiphy.max_num_akm_suites))
2983 goto nla_put_failure;
2985 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)
2986 nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT);
2988 if (rdev->wiphy.hw_timestamp_max_peers &&
2989 nla_put_u16(msg, NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS,
2990 rdev->wiphy.hw_timestamp_max_peers))
2991 goto nla_put_failure;
2994 state->split_start = 0;
2998 genlmsg_end(msg, hdr);
3002 genlmsg_cancel(msg, hdr);
3006 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
3007 struct netlink_callback *cb,
3008 struct nl80211_dump_wiphy_state *state)
3010 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
3016 ret = nlmsg_parse_deprecated(cb->nlh,
3017 GENL_HDRLEN + nl80211_fam.hdrsize,
3018 tb, nl80211_fam.maxattr,
3019 nl80211_policy, NULL);
3020 /* ignore parse errors for backward compatibility */
3026 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
3027 if (tb[NL80211_ATTR_WIPHY])
3028 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
3029 if (tb[NL80211_ATTR_WDEV])
3030 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
3031 if (tb[NL80211_ATTR_IFINDEX]) {
3032 struct net_device *netdev;
3033 struct cfg80211_registered_device *rdev;
3034 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
3036 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
3041 if (netdev->ieee80211_ptr) {
3042 rdev = wiphy_to_rdev(
3043 netdev->ieee80211_ptr->wiphy);
3044 state->filter_wiphy = rdev->wiphy_idx;
3054 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
3057 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
3058 struct cfg80211_registered_device *rdev;
3062 state = kzalloc(sizeof(*state), GFP_KERNEL);
3067 state->filter_wiphy = -1;
3068 ret = nl80211_dump_wiphy_parse(skb, cb, state);
3074 cb->args[0] = (long)state;
3077 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3078 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3080 if (++idx <= state->start)
3082 if (state->filter_wiphy != -1 &&
3083 state->filter_wiphy != rdev->wiphy_idx)
3085 wiphy_lock(&rdev->wiphy);
3086 /* attempt to fit multiple wiphy data chunks into the skb */
3088 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
3090 NETLINK_CB(cb->skb).portid,
3092 NLM_F_MULTI, state);
3095 * If sending the wiphy data didn't fit (ENOBUFS
3096 * or EMSGSIZE returned), this SKB is still
3097 * empty (so it's not too big because another
3098 * wiphy dataset is already in the skb) and
3099 * we've not tried to adjust the dump allocation
3100 * yet ... then adjust the alloc size to be
3101 * bigger, and return 1 but with the empty skb.
3102 * This results in an empty message being RX'ed
3103 * in userspace, but that is ignored.
3105 * We can then retry with the larger buffer.
3107 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
3108 !skb->len && !state->split &&
3109 cb->min_dump_alloc < 4096) {
3110 cb->min_dump_alloc = 4096;
3111 state->split_start = 0;
3112 wiphy_unlock(&rdev->wiphy);
3119 } while (state->split_start > 0);
3120 wiphy_unlock(&rdev->wiphy);
3130 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
3132 kfree((void *)cb->args[0]);
3136 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
3138 struct sk_buff *msg;
3139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3140 struct nl80211_dump_wiphy_state state = {};
3142 msg = nlmsg_new(4096, GFP_KERNEL);
3146 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
3147 info->snd_portid, info->snd_seq, 0,
3153 return genlmsg_reply(msg, info);
3156 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
3157 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
3158 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
3159 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
3160 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
3161 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
3164 static int parse_txq_params(struct nlattr *tb[],
3165 struct ieee80211_txq_params *txq_params)
3169 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
3170 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
3171 !tb[NL80211_TXQ_ATTR_AIFS])
3174 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
3175 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
3176 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
3177 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
3178 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
3180 if (ac >= NL80211_NUM_ACS)
3182 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
3186 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
3189 * You can only set the channel explicitly for some interfaces,
3190 * most have their channel managed via their respective
3191 * "establish a connection" command (connect, join, ...)
3193 * For AP/GO and mesh mode, the channel can be set with the
3194 * channel userspace API, but is only stored and passed to the
3195 * low-level driver when the AP starts or the mesh is joined.
3196 * This is for backward compatibility, userspace can also give
3197 * the channel in the start-ap or join-mesh commands instead.
3199 * Monitors are special as they are normally slaved to
3200 * whatever else is going on, so they have their own special
3201 * operation to set the monitor channel if possible.
3204 wdev->iftype == NL80211_IFTYPE_AP ||
3205 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
3206 wdev->iftype == NL80211_IFTYPE_MONITOR ||
3207 wdev->iftype == NL80211_IFTYPE_P2P_GO;
3210 static int nl80211_parse_punct_bitmap(struct cfg80211_registered_device *rdev,
3211 struct genl_info *info,
3212 const struct cfg80211_chan_def *chandef,
3215 if (!wiphy_ext_feature_isset(&rdev->wiphy, NL80211_EXT_FEATURE_PUNCT))
3218 *punct_bitmap = nla_get_u32(info->attrs[NL80211_ATTR_PUNCT_BITMAP]);
3219 if (!cfg80211_valid_disable_subchannel_bitmap(punct_bitmap, chandef))
3225 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
3226 struct genl_info *info,
3227 struct cfg80211_chan_def *chandef)
3229 struct netlink_ext_ack *extack = info->extack;
3230 struct nlattr **attrs = info->attrs;
3233 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) {
3234 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
3235 "Frequency is missing");
3239 control_freq = MHZ_TO_KHZ(
3240 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3241 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
3243 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
3245 memset(chandef, 0, sizeof(*chandef));
3246 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq);
3247 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
3248 chandef->center_freq1 = KHZ_TO_MHZ(control_freq);
3249 chandef->freq1_offset = control_freq % 1000;
3250 chandef->center_freq2 = 0;
3252 /* Primary channel not allowed */
3253 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
3254 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
3255 "Channel is disabled");
3259 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
3260 enum nl80211_channel_type chantype;
3262 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
3265 case NL80211_CHAN_NO_HT:
3266 case NL80211_CHAN_HT20:
3267 case NL80211_CHAN_HT40PLUS:
3268 case NL80211_CHAN_HT40MINUS:
3269 cfg80211_chandef_create(chandef, chandef->chan,
3271 /* user input for center_freq is incorrect */
3272 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
3273 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
3274 NL_SET_ERR_MSG_ATTR(extack,
3275 attrs[NL80211_ATTR_CENTER_FREQ1],
3276 "bad center frequency 1");
3279 /* center_freq2 must be zero */
3280 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
3281 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
3282 NL_SET_ERR_MSG_ATTR(extack,
3283 attrs[NL80211_ATTR_CENTER_FREQ2],
3284 "center frequency 2 can't be used");
3289 NL_SET_ERR_MSG_ATTR(extack,
3290 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
3291 "invalid channel type");
3294 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
3296 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
3297 if (chandef->chan->band == NL80211_BAND_S1GHZ) {
3298 /* User input error for channel width doesn't match channel */
3299 if (chandef->width != ieee80211_s1g_channel_width(chandef->chan)) {
3300 NL_SET_ERR_MSG_ATTR(extack,
3301 attrs[NL80211_ATTR_CHANNEL_WIDTH],
3302 "bad channel width");
3306 if (attrs[NL80211_ATTR_CENTER_FREQ1]) {
3307 chandef->center_freq1 =
3308 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
3309 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET])
3310 chandef->freq1_offset = nla_get_u32(
3311 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]);
3313 chandef->freq1_offset = 0;
3315 if (attrs[NL80211_ATTR_CENTER_FREQ2])
3316 chandef->center_freq2 =
3317 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
3320 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
3321 chandef->edmg.channels =
3322 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
3324 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
3325 chandef->edmg.bw_config =
3326 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
3328 chandef->edmg.bw_config = 0;
3329 chandef->edmg.channels = 0;
3332 if (!cfg80211_chandef_valid(chandef)) {
3333 NL_SET_ERR_MSG(extack, "invalid channel definition");
3337 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
3338 IEEE80211_CHAN_DISABLED)) {
3339 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
3343 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
3344 chandef->width == NL80211_CHAN_WIDTH_10) &&
3345 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
3346 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
3353 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
3354 struct net_device *dev,
3355 struct genl_info *info,
3358 struct cfg80211_chan_def chandef;
3360 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
3361 struct wireless_dev *wdev = NULL;
3362 int link_id = _link_id;
3365 wdev = dev->ieee80211_ptr;
3366 if (!nl80211_can_set_dev_channel(wdev))
3369 iftype = wdev->iftype;
3372 if (wdev && wdev->valid_links)
3377 result = nl80211_parse_chandef(rdev, info, &chandef);
3382 case NL80211_IFTYPE_AP:
3383 case NL80211_IFTYPE_P2P_GO:
3384 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
3387 if (wdev->links[link_id].ap.beacon_interval) {
3388 struct ieee80211_channel *cur_chan;
3390 if (!dev || !rdev->ops->set_ap_chanwidth ||
3391 !(rdev->wiphy.features &
3392 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE))
3395 /* Only allow dynamic channel width changes */
3396 cur_chan = wdev->links[link_id].ap.chandef.chan;
3397 if (chandef.chan != cur_chan)
3400 result = rdev_set_ap_chanwidth(rdev, dev, link_id,
3404 wdev->links[link_id].ap.chandef = chandef;
3406 wdev->u.ap.preset_chandef = chandef;
3409 case NL80211_IFTYPE_MESH_POINT:
3410 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
3411 case NL80211_IFTYPE_MONITOR:
3412 return cfg80211_set_monitor_channel(rdev, &chandef);
3420 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
3422 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3423 int link_id = nl80211_link_id_or_invalid(info->attrs);
3424 struct net_device *netdev = info->user_ptr[1];
3427 wdev_lock(netdev->ieee80211_ptr);
3428 ret = __nl80211_set_channel(rdev, netdev, info, link_id);
3429 wdev_unlock(netdev->ieee80211_ptr);
3434 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
3436 struct cfg80211_registered_device *rdev = NULL;
3437 struct net_device *netdev = NULL;
3438 struct wireless_dev *wdev;
3439 int result = 0, rem_txq_params = 0;
3440 struct nlattr *nl_txq_params;
3442 u8 retry_short = 0, retry_long = 0;
3443 u32 frag_threshold = 0, rts_threshold = 0;
3444 u8 coverage_class = 0;
3445 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
3449 * Try to find the wiphy and netdev. Normally this
3450 * function shouldn't need the netdev, but this is
3451 * done for backward compatibility -- previously
3452 * setting the channel was done per wiphy, but now
3453 * it is per netdev. Previous userland like hostapd
3454 * also passed a netdev to set_wiphy, so that it is
3455 * possible to let that go to the right netdev!
3458 if (info->attrs[NL80211_ATTR_IFINDEX]) {
3459 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
3461 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
3462 if (netdev && netdev->ieee80211_ptr)
3463 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
3469 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3473 return PTR_ERR(rdev);
3479 wdev = netdev->ieee80211_ptr;
3481 wiphy_lock(&rdev->wiphy);
3484 * end workaround code, by now the rdev is available
3485 * and locked, and wdev may or may not be NULL.
3488 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
3489 result = cfg80211_dev_rename(
3490 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
3496 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
3497 struct ieee80211_txq_params txq_params;
3498 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
3500 if (!rdev->ops->set_txq_params) {
3501 result = -EOPNOTSUPP;
3510 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3511 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3516 if (!netif_running(netdev)) {
3521 nla_for_each_nested(nl_txq_params,
3522 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3524 result = nla_parse_nested_deprecated(tb,
3525 NL80211_TXQ_ATTR_MAX,
3531 result = parse_txq_params(tb, &txq_params);
3535 txq_params.link_id =
3536 nl80211_link_id_or_invalid(info->attrs);
3538 wdev_lock(netdev->ieee80211_ptr);
3539 if (txq_params.link_id >= 0 &&
3540 !(netdev->ieee80211_ptr->valid_links &
3541 BIT(txq_params.link_id)))
3543 else if (txq_params.link_id >= 0 &&
3544 !netdev->ieee80211_ptr->valid_links)
3547 result = rdev_set_txq_params(rdev, netdev,
3549 wdev_unlock(netdev->ieee80211_ptr);
3555 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3556 int link_id = nl80211_link_id_or_invalid(info->attrs);
3560 result = __nl80211_set_channel(
3562 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3566 result = __nl80211_set_channel(rdev, netdev, info, link_id);
3573 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
3574 struct wireless_dev *txp_wdev = wdev;
3575 enum nl80211_tx_power_setting type;
3578 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3581 if (!rdev->ops->set_tx_power) {
3582 result = -EOPNOTSUPP;
3586 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
3587 type = nla_get_u32(info->attrs[idx]);
3589 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
3590 (type != NL80211_TX_POWER_AUTOMATIC)) {
3595 if (type != NL80211_TX_POWER_AUTOMATIC) {
3596 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
3597 mbm = nla_get_u32(info->attrs[idx]);
3600 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
3605 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3606 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3609 if ((!rdev->wiphy.available_antennas_tx &&
3610 !rdev->wiphy.available_antennas_rx) ||
3611 !rdev->ops->set_antenna) {
3612 result = -EOPNOTSUPP;
3616 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3617 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3619 /* reject antenna configurations which don't match the
3620 * available antenna masks, except for the "all" mask */
3621 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
3622 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
3627 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3628 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
3630 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
3637 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3638 retry_short = nla_get_u8(
3639 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
3641 changed |= WIPHY_PARAM_RETRY_SHORT;
3644 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3645 retry_long = nla_get_u8(
3646 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
3648 changed |= WIPHY_PARAM_RETRY_LONG;
3651 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3652 frag_threshold = nla_get_u32(
3653 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
3654 if (frag_threshold < 256) {
3659 if (frag_threshold != (u32) -1) {
3661 * Fragments (apart from the last one) are required to
3662 * have even length. Make the fragmentation code
3663 * simpler by stripping LSB should someone try to use
3664 * odd threshold value.
3666 frag_threshold &= ~0x1;
3668 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3671 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3672 rts_threshold = nla_get_u32(
3673 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3674 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3677 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
3678 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3683 coverage_class = nla_get_u8(
3684 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3685 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3688 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3689 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) {
3690 result = -EOPNOTSUPP;
3694 changed |= WIPHY_PARAM_DYN_ACK;
3697 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3698 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3699 NL80211_EXT_FEATURE_TXQS)) {
3700 result = -EOPNOTSUPP;
3703 txq_limit = nla_get_u32(
3704 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3705 changed |= WIPHY_PARAM_TXQ_LIMIT;
3708 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3709 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3710 NL80211_EXT_FEATURE_TXQS)) {
3711 result = -EOPNOTSUPP;
3714 txq_memory_limit = nla_get_u32(
3715 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3716 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3719 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3720 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3721 NL80211_EXT_FEATURE_TXQS)) {
3722 result = -EOPNOTSUPP;
3725 txq_quantum = nla_get_u32(
3726 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3727 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3731 u8 old_retry_short, old_retry_long;
3732 u32 old_frag_threshold, old_rts_threshold;
3733 u8 old_coverage_class;
3734 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
3736 if (!rdev->ops->set_wiphy_params) {
3737 result = -EOPNOTSUPP;
3741 old_retry_short = rdev->wiphy.retry_short;
3742 old_retry_long = rdev->wiphy.retry_long;
3743 old_frag_threshold = rdev->wiphy.frag_threshold;
3744 old_rts_threshold = rdev->wiphy.rts_threshold;
3745 old_coverage_class = rdev->wiphy.coverage_class;
3746 old_txq_limit = rdev->wiphy.txq_limit;
3747 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3748 old_txq_quantum = rdev->wiphy.txq_quantum;
3750 if (changed & WIPHY_PARAM_RETRY_SHORT)
3751 rdev->wiphy.retry_short = retry_short;
3752 if (changed & WIPHY_PARAM_RETRY_LONG)
3753 rdev->wiphy.retry_long = retry_long;
3754 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3755 rdev->wiphy.frag_threshold = frag_threshold;
3756 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3757 rdev->wiphy.rts_threshold = rts_threshold;
3758 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3759 rdev->wiphy.coverage_class = coverage_class;
3760 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3761 rdev->wiphy.txq_limit = txq_limit;
3762 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3763 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3764 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3765 rdev->wiphy.txq_quantum = txq_quantum;
3767 result = rdev_set_wiphy_params(rdev, changed);
3769 rdev->wiphy.retry_short = old_retry_short;
3770 rdev->wiphy.retry_long = old_retry_long;
3771 rdev->wiphy.frag_threshold = old_frag_threshold;
3772 rdev->wiphy.rts_threshold = old_rts_threshold;
3773 rdev->wiphy.coverage_class = old_coverage_class;
3774 rdev->wiphy.txq_limit = old_txq_limit;
3775 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3776 rdev->wiphy.txq_quantum = old_txq_quantum;
3784 wiphy_unlock(&rdev->wiphy);
3788 int nl80211_send_chandef(struct sk_buff *msg, const struct cfg80211_chan_def *chandef)
3790 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3793 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3794 chandef->chan->center_freq))
3796 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
3797 chandef->chan->freq_offset))
3799 switch (chandef->width) {
3800 case NL80211_CHAN_WIDTH_20_NOHT:
3801 case NL80211_CHAN_WIDTH_20:
3802 case NL80211_CHAN_WIDTH_40:
3803 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3804 cfg80211_get_chandef_type(chandef)))
3810 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3812 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3814 if (chandef->center_freq2 &&
3815 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
3819 EXPORT_SYMBOL(nl80211_send_chandef);
3821 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
3822 struct cfg80211_registered_device *rdev,
3823 struct wireless_dev *wdev,
3824 enum nl80211_commands cmd)
3826 struct net_device *dev = wdev->netdev;
3829 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3830 cmd != NL80211_CMD_DEL_INTERFACE &&
3831 cmd != NL80211_CMD_SET_INTERFACE);
3833 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
3838 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3839 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
3840 goto nla_put_failure;
3842 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3843 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
3844 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3845 NL80211_ATTR_PAD) ||
3846 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
3847 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3848 rdev->devlist_generation ^
3849 (cfg80211_rdev_list_generation << 2)) ||
3850 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
3851 goto nla_put_failure;
3853 if (rdev->ops->get_channel && !wdev->valid_links) {
3854 struct cfg80211_chan_def chandef = {};
3857 ret = rdev_get_channel(rdev, wdev, 0, &chandef);
3858 if (ret == 0 && nl80211_send_chandef(msg, &chandef))
3859 goto nla_put_failure;
3862 if (rdev->ops->get_tx_power) {
3865 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3867 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3869 goto nla_put_failure;
3873 switch (wdev->iftype) {
3874 case NL80211_IFTYPE_AP:
3875 case NL80211_IFTYPE_P2P_GO:
3876 if (wdev->u.ap.ssid_len &&
3877 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len,
3879 goto nla_put_failure_locked;
3881 case NL80211_IFTYPE_STATION:
3882 case NL80211_IFTYPE_P2P_CLIENT:
3883 if (wdev->u.client.ssid_len &&
3884 nla_put(msg, NL80211_ATTR_SSID, wdev->u.client.ssid_len,
3885 wdev->u.client.ssid))
3886 goto nla_put_failure_locked;
3888 case NL80211_IFTYPE_ADHOC:
3889 if (wdev->u.ibss.ssid_len &&
3890 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ibss.ssid_len,
3892 goto nla_put_failure_locked;
3900 if (rdev->ops->get_txq_stats) {
3901 struct cfg80211_txq_stats txqstats = {};
3902 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3905 !nl80211_put_txq_stats(msg, &txqstats,
3906 NL80211_ATTR_TXQ_STATS))
3907 goto nla_put_failure;
3910 if (wdev->valid_links) {
3911 unsigned int link_id;
3912 struct nlattr *links = nla_nest_start(msg,
3913 NL80211_ATTR_MLO_LINKS);
3916 goto nla_put_failure;
3918 for_each_valid_link(wdev, link_id) {
3919 struct nlattr *link = nla_nest_start(msg, link_id + 1);
3920 struct cfg80211_chan_def chandef = {};
3924 goto nla_put_failure;
3926 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
3927 goto nla_put_failure;
3928 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
3929 wdev->links[link_id].addr))
3930 goto nla_put_failure;
3932 ret = rdev_get_channel(rdev, wdev, link_id, &chandef);
3933 if (ret == 0 && nl80211_send_chandef(msg, &chandef))
3934 goto nla_put_failure;
3936 nla_nest_end(msg, link);
3939 nla_nest_end(msg, links);
3942 genlmsg_end(msg, hdr);
3945 nla_put_failure_locked:
3948 genlmsg_cancel(msg, hdr);
3952 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3956 int wp_start = cb->args[0];
3957 int if_start = cb->args[1];
3958 int filter_wiphy = -1;
3959 struct cfg80211_registered_device *rdev;
3960 struct wireless_dev *wdev;
3965 struct nl80211_dump_wiphy_state state = {
3969 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3973 filter_wiphy = state.filter_wiphy;
3976 * if filtering, set cb->args[2] to +1 since 0 is the default
3977 * value needed to determine that parsing is necessary.
3979 if (filter_wiphy >= 0)
3980 cb->args[2] = filter_wiphy + 1;
3983 } else if (cb->args[2] > 0) {
3984 filter_wiphy = cb->args[2] - 1;
3987 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3988 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3990 if (wp_idx < wp_start) {
3995 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
4000 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
4001 if (if_idx < if_start) {
4005 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
4006 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4008 NL80211_CMD_NEW_INTERFACE) < 0) {
4017 cb->args[0] = wp_idx;
4018 cb->args[1] = if_idx;
4027 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
4029 struct sk_buff *msg;
4030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4031 struct wireless_dev *wdev = info->user_ptr[1];
4033 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4037 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
4038 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
4043 return genlmsg_reply(msg, info);
4046 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
4047 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
4048 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
4049 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
4050 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
4051 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
4052 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
4055 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
4057 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
4065 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
4068 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
4070 *mntrflags |= (1<<flag);
4072 *mntrflags |= MONITOR_FLAG_CHANGED;
4077 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
4078 enum nl80211_iftype type,
4079 struct genl_info *info,
4080 struct vif_params *params)
4082 bool change = false;
4085 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
4086 if (type != NL80211_IFTYPE_MONITOR)
4089 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
4097 if (params->flags & MONITOR_FLAG_ACTIVE &&
4098 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
4101 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
4102 const u8 *mumimo_groups;
4103 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
4105 if (type != NL80211_IFTYPE_MONITOR)
4108 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
4112 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
4114 /* bits 0 and 63 are reserved and must be zero */
4115 if ((mumimo_groups[0] & BIT(0)) ||
4116 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
4119 params->vht_mumimo_groups = mumimo_groups;
4123 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
4124 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
4126 if (type != NL80211_IFTYPE_MONITOR)
4129 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
4132 params->vht_mumimo_follow_addr =
4133 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
4137 return change ? 1 : 0;
4140 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
4141 struct net_device *netdev, u8 use_4addr,
4142 enum nl80211_iftype iftype)
4145 if (netdev && netif_is_bridge_port(netdev))
4151 case NL80211_IFTYPE_AP_VLAN:
4152 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
4155 case NL80211_IFTYPE_STATION:
4156 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
4166 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
4168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4169 struct vif_params params;
4171 enum nl80211_iftype otype, ntype;
4172 struct net_device *dev = info->user_ptr[1];
4173 bool change = false;
4175 memset(¶ms, 0, sizeof(params));
4177 otype = ntype = dev->ieee80211_ptr->iftype;
4179 if (info->attrs[NL80211_ATTR_IFTYPE]) {
4180 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
4185 if (info->attrs[NL80211_ATTR_MESH_ID]) {
4186 struct wireless_dev *wdev = dev->ieee80211_ptr;
4188 if (ntype != NL80211_IFTYPE_MESH_POINT)
4190 if (netif_running(dev))
4194 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
4195 IEEE80211_MAX_MESH_ID_LEN);
4196 wdev->u.mesh.id_up_len =
4197 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
4198 memcpy(wdev->u.mesh.id,
4199 nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
4200 wdev->u.mesh.id_up_len);
4204 if (info->attrs[NL80211_ATTR_4ADDR]) {
4205 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
4207 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
4211 params.use_4addr = -1;
4214 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms);
4221 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms);
4225 if (!err && params.use_4addr != -1)
4226 dev->ieee80211_ptr->use_4addr = params.use_4addr;
4228 if (change && !err) {
4229 struct wireless_dev *wdev = dev->ieee80211_ptr;
4231 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
4237 static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
4239 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4240 struct vif_params params;
4241 struct wireless_dev *wdev;
4242 struct sk_buff *msg;
4244 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
4246 memset(¶ms, 0, sizeof(params));
4248 if (!info->attrs[NL80211_ATTR_IFNAME])
4251 if (info->attrs[NL80211_ATTR_IFTYPE])
4252 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
4254 if (!rdev->ops->add_virtual_intf)
4257 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
4258 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
4259 info->attrs[NL80211_ATTR_MAC]) {
4260 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
4262 if (!is_valid_ether_addr(params.macaddr))
4263 return -EADDRNOTAVAIL;
4266 if (info->attrs[NL80211_ATTR_4ADDR]) {
4267 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
4268 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
4273 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
4276 err = nl80211_parse_mon_options(rdev, type, info, ¶ms);
4280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4284 wdev = rdev_add_virtual_intf(rdev,
4285 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
4286 NET_NAME_USER, type, ¶ms);
4287 if (WARN_ON(!wdev)) {
4290 } else if (IS_ERR(wdev)) {
4292 return PTR_ERR(wdev);
4295 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4296 wdev->owner_nlportid = info->snd_portid;
4299 case NL80211_IFTYPE_MESH_POINT:
4300 if (!info->attrs[NL80211_ATTR_MESH_ID])
4303 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
4304 IEEE80211_MAX_MESH_ID_LEN);
4305 wdev->u.mesh.id_up_len =
4306 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
4307 memcpy(wdev->u.mesh.id,
4308 nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
4309 wdev->u.mesh.id_up_len);
4312 case NL80211_IFTYPE_NAN:
4313 case NL80211_IFTYPE_P2P_DEVICE:
4315 * P2P Device and NAN do not have a netdev, so don't go
4316 * through the netdev notifier and must be added here
4318 cfg80211_init_wdev(wdev);
4319 cfg80211_register_wdev(rdev, wdev);
4325 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
4326 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
4331 return genlmsg_reply(msg, info);
4334 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
4336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4339 /* to avoid failing a new interface creation due to pending removal */
4340 cfg80211_destroy_ifaces(rdev);
4342 wiphy_lock(&rdev->wiphy);
4343 ret = _nl80211_new_interface(skb, info);
4344 wiphy_unlock(&rdev->wiphy);
4349 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
4351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4352 struct wireless_dev *wdev = info->user_ptr[1];
4354 if (!rdev->ops->del_virtual_intf)
4358 * We hold RTNL, so this is safe, without RTNL opencount cannot
4359 * reach 0, and thus the rdev cannot be deleted.
4361 * We need to do it for the dev_close(), since that will call
4362 * the netdev notifiers, and we need to acquire the mutex there
4363 * but don't know if we get there from here or from some other
4364 * place (e.g. "ip link set ... down").
4366 mutex_unlock(&rdev->wiphy.mtx);
4369 * If we remove a wireless device without a netdev then clear
4370 * user_ptr[1] so that nl80211_post_doit won't dereference it
4371 * to check if it needs to do dev_put(). Otherwise it crashes
4372 * since the wdev has been freed, unlike with a netdev where
4373 * we need the dev_put() for the netdev to really be freed.
4376 info->user_ptr[1] = NULL;
4378 dev_close(wdev->netdev);
4380 mutex_lock(&rdev->wiphy.mtx);
4382 return cfg80211_remove_virtual_intf(rdev, wdev);
4385 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
4387 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4388 struct net_device *dev = info->user_ptr[1];
4391 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
4394 if (!rdev->ops->set_noack_map)
4397 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
4399 return rdev_set_noack_map(rdev, dev, noack_map);
4402 static int nl80211_validate_key_link_id(struct genl_info *info,
4403 struct wireless_dev *wdev,
4404 int link_id, bool pairwise)
4407 if (link_id != -1) {
4408 GENL_SET_ERR_MSG(info,
4409 "link ID not allowed for pairwise key");
4416 if (wdev->valid_links) {
4417 if (link_id == -1) {
4418 GENL_SET_ERR_MSG(info,
4419 "link ID must for MLO group key");
4422 if (!(wdev->valid_links & BIT(link_id))) {
4423 GENL_SET_ERR_MSG(info, "invalid link ID for MLO group key");
4426 } else if (link_id != -1) {
4427 GENL_SET_ERR_MSG(info, "link ID not allowed for non-MLO group key");
4434 struct get_key_cookie {
4435 struct sk_buff *msg;
4440 static void get_key_callback(void *c, struct key_params *params)
4443 struct get_key_cookie *cookie = c;
4446 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
4447 params->key_len, params->key)) ||
4449 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
4450 params->seq_len, params->seq)) ||
4452 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
4454 goto nla_put_failure;
4456 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
4458 goto nla_put_failure;
4461 nla_put(cookie->msg, NL80211_KEY_DATA,
4462 params->key_len, params->key)) ||
4464 nla_put(cookie->msg, NL80211_KEY_SEQ,
4465 params->seq_len, params->seq)) ||
4467 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
4469 goto nla_put_failure;
4471 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
4472 goto nla_put_failure;
4474 nla_nest_end(cookie->msg, key);
4481 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
4483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4485 struct net_device *dev = info->user_ptr[1];
4487 const u8 *mac_addr = NULL;
4489 struct get_key_cookie cookie = {
4493 struct sk_buff *msg;
4494 bool bigtk_support = false;
4495 int link_id = nl80211_link_id_or_invalid(info->attrs);
4496 struct wireless_dev *wdev = dev->ieee80211_ptr;
4498 if (wiphy_ext_feature_isset(&rdev->wiphy,
4499 NL80211_EXT_FEATURE_BEACON_PROTECTION))
4500 bigtk_support = true;
4502 if ((wdev->iftype == NL80211_IFTYPE_STATION ||
4503 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
4504 wiphy_ext_feature_isset(&rdev->wiphy,
4505 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
4506 bigtk_support = true;
4508 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
4509 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
4511 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) {
4512 GENL_SET_ERR_MSG(info, "BIGTK not supported");
4517 if (info->attrs[NL80211_ATTR_MAC])
4518 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4520 pairwise = !!mac_addr;
4521 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
4522 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
4524 if (kt != NL80211_KEYTYPE_GROUP &&
4525 kt != NL80211_KEYTYPE_PAIRWISE)
4527 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
4530 if (!rdev->ops->get_key)
4533 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4536 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4540 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4541 NL80211_CMD_NEW_KEY);
4543 goto nla_put_failure;
4546 cookie.idx = key_idx;
4548 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4549 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
4550 goto nla_put_failure;
4552 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
4553 goto nla_put_failure;
4555 err = nl80211_validate_key_link_id(info, wdev, link_id, pairwise);
4559 err = rdev_get_key(rdev, dev, link_id, key_idx, pairwise, mac_addr,
4560 &cookie, get_key_callback);
4566 goto nla_put_failure;
4568 genlmsg_end(msg, hdr);
4569 return genlmsg_reply(msg, info);
4578 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
4580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4581 struct key_parse key;
4583 struct net_device *dev = info->user_ptr[1];
4584 int link_id = nl80211_link_id_or_invalid(info->attrs);
4585 struct wireless_dev *wdev = dev->ieee80211_ptr;
4587 err = nl80211_parse_key(info, &key);
4594 /* Only support setting default key and
4595 * Extended Key ID action NL80211_KEY_SET_TX.
4597 if (!key.def && !key.defmgmt && !key.defbeacon &&
4598 !(key.p.mode == NL80211_KEY_SET_TX))
4604 if (!rdev->ops->set_default_key) {
4609 err = nl80211_key_allowed(wdev);
4613 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4617 err = rdev_set_default_key(rdev, dev, link_id, key.idx,
4618 key.def_uni, key.def_multi);
4623 #ifdef CONFIG_CFG80211_WEXT
4624 wdev->wext.default_key = key.idx;
4626 } else if (key.defmgmt) {
4627 if (key.def_uni || !key.def_multi) {
4632 if (!rdev->ops->set_default_mgmt_key) {
4637 err = nl80211_key_allowed(wdev);
4641 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4645 err = rdev_set_default_mgmt_key(rdev, dev, link_id, key.idx);
4649 #ifdef CONFIG_CFG80211_WEXT
4650 wdev->wext.default_mgmt_key = key.idx;
4652 } else if (key.defbeacon) {
4653 if (key.def_uni || !key.def_multi) {
4658 if (!rdev->ops->set_default_beacon_key) {
4663 err = nl80211_key_allowed(wdev);
4667 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4671 err = rdev_set_default_beacon_key(rdev, dev, link_id, key.idx);
4674 } else if (key.p.mode == NL80211_KEY_SET_TX &&
4675 wiphy_ext_feature_isset(&rdev->wiphy,
4676 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
4677 u8 *mac_addr = NULL;
4679 if (info->attrs[NL80211_ATTR_MAC])
4680 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4682 if (!mac_addr || key.idx < 0 || key.idx > 1) {
4687 err = nl80211_validate_key_link_id(info, wdev, link_id, true);
4691 err = rdev_add_key(rdev, dev, link_id, key.idx,
4692 NL80211_KEYTYPE_PAIRWISE,
4703 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4705 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4707 struct net_device *dev = info->user_ptr[1];
4708 struct key_parse key;
4709 const u8 *mac_addr = NULL;
4710 int link_id = nl80211_link_id_or_invalid(info->attrs);
4711 struct wireless_dev *wdev = dev->ieee80211_ptr;
4713 err = nl80211_parse_key(info, &key);
4718 GENL_SET_ERR_MSG(info, "no key");
4722 if (info->attrs[NL80211_ATTR_MAC])
4723 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4725 if (key.type == -1) {
4727 key.type = NL80211_KEYTYPE_PAIRWISE;
4729 key.type = NL80211_KEYTYPE_GROUP;
4733 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4734 key.type != NL80211_KEYTYPE_GROUP) {
4735 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
4739 if (key.type == NL80211_KEYTYPE_GROUP &&
4740 info->attrs[NL80211_ATTR_VLAN_ID])
4741 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
4743 if (!rdev->ops->add_key)
4746 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4747 key.type == NL80211_KEYTYPE_PAIRWISE,
4749 GENL_SET_ERR_MSG(info, "key setting validation failed");
4754 err = nl80211_key_allowed(wdev);
4756 GENL_SET_ERR_MSG(info, "key not allowed");
4759 err = nl80211_validate_key_link_id(info, wdev, link_id,
4760 key.type == NL80211_KEYTYPE_PAIRWISE);
4763 err = rdev_add_key(rdev, dev, link_id, key.idx,
4764 key.type == NL80211_KEYTYPE_PAIRWISE,
4767 GENL_SET_ERR_MSG(info, "key addition failed");
4774 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4778 struct net_device *dev = info->user_ptr[1];
4779 u8 *mac_addr = NULL;
4780 struct key_parse key;
4781 int link_id = nl80211_link_id_or_invalid(info->attrs);
4782 struct wireless_dev *wdev = dev->ieee80211_ptr;
4784 err = nl80211_parse_key(info, &key);
4788 if (info->attrs[NL80211_ATTR_MAC])
4789 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4791 if (key.type == -1) {
4793 key.type = NL80211_KEYTYPE_PAIRWISE;
4795 key.type = NL80211_KEYTYPE_GROUP;
4799 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4800 key.type != NL80211_KEYTYPE_GROUP)
4803 if (!cfg80211_valid_key_idx(rdev, key.idx,
4804 key.type == NL80211_KEYTYPE_PAIRWISE))
4807 if (!rdev->ops->del_key)
4811 err = nl80211_key_allowed(wdev);
4813 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
4814 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4818 err = nl80211_validate_key_link_id(info, wdev, link_id,
4819 key.type == NL80211_KEYTYPE_PAIRWISE);
4822 err = rdev_del_key(rdev, dev, link_id, key.idx,
4823 key.type == NL80211_KEYTYPE_PAIRWISE,
4826 #ifdef CONFIG_CFG80211_WEXT
4828 if (key.idx == wdev->wext.default_key)
4829 wdev->wext.default_key = -1;
4830 else if (key.idx == wdev->wext.default_mgmt_key)
4831 wdev->wext.default_mgmt_key = -1;
4839 /* This function returns an error or the number of nested attributes */
4840 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4842 struct nlattr *attr;
4843 int n_entries = 0, tmp;
4845 nla_for_each_nested(attr, nl_attr, tmp) {
4846 if (nla_len(attr) != ETH_ALEN)
4856 * This function parses ACL information and allocates memory for ACL data.
4857 * On successful return, the calling function is responsible to free the
4858 * ACL buffer returned by this function.
4860 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4861 struct genl_info *info)
4863 enum nl80211_acl_policy acl_policy;
4864 struct nlattr *attr;
4865 struct cfg80211_acl_data *acl;
4866 int i = 0, n_entries, tmp;
4868 if (!wiphy->max_acl_mac_addrs)
4869 return ERR_PTR(-EOPNOTSUPP);
4871 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4872 return ERR_PTR(-EINVAL);
4874 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4875 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4876 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4877 return ERR_PTR(-EINVAL);
4879 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4880 return ERR_PTR(-EINVAL);
4882 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4884 return ERR_PTR(n_entries);
4886 if (n_entries > wiphy->max_acl_mac_addrs)
4887 return ERR_PTR(-ENOTSUPP);
4889 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
4891 return ERR_PTR(-ENOMEM);
4893 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4894 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4898 acl->n_acl_entries = n_entries;
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);
5443 nla_for_each_nested(nl_elems, attrs, rem_elems) {
5444 elems->elem[i].data = nla_data(nl_elems);
5445 elems->elem[i].len = nla_len(nl_elems);
5448 elems->cnt = num_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);
5475 nla_for_each_nested(nl_elems, attrs, rem_elems) {
5476 elems->elem[i].data = nla_data(nl_elems);
5477 elems->elem[i].len = nla_len(nl_elems);
5480 elems->cnt = num_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_start_ap(struct sk_buff *skb, struct genl_info *info)
5914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5915 unsigned int link_id = nl80211_link_id(info->attrs);
5916 struct net_device *dev = info->user_ptr[1];
5917 struct wireless_dev *wdev = dev->ieee80211_ptr;
5918 struct cfg80211_ap_settings *params;
5921 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5922 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5925 if (!rdev->ops->start_ap)
5928 if (wdev->links[link_id].ap.beacon_interval)
5931 /* these are required for START_AP */
5932 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
5933 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
5934 !info->attrs[NL80211_ATTR_BEACON_HEAD])
5937 params = kzalloc(sizeof(*params), GFP_KERNEL);
5941 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon,
5946 params->beacon_interval =
5947 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5948 params->dtim_period =
5949 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
5951 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
5952 params->beacon_interval);
5957 * In theory, some of these attributes should be required here
5958 * but since they were not used when the command was originally
5959 * added, keep them optional for old user space programs to let
5960 * them continue to work with drivers that do not need the
5961 * additional information -- drivers must check!
5963 if (info->attrs[NL80211_ATTR_SSID]) {
5964 params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5966 nla_len(info->attrs[NL80211_ATTR_SSID]);
5967 if (params->ssid_len == 0) {
5972 if (wdev->u.ap.ssid_len &&
5973 (wdev->u.ap.ssid_len != params->ssid_len ||
5974 memcmp(wdev->u.ap.ssid, params->ssid, params->ssid_len))) {
5975 /* require identical SSID for MLO */
5979 } else if (wdev->valid_links) {
5980 /* require SSID for MLO */
5985 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
5986 params->hidden_ssid = nla_get_u32(
5987 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
5989 params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5991 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5992 params->auth_type = nla_get_u32(
5993 info->attrs[NL80211_ATTR_AUTH_TYPE]);
5994 if (!nl80211_valid_auth_type(rdev, params->auth_type,
5995 NL80211_CMD_START_AP)) {
6000 params->auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6002 err = nl80211_crypto_settings(rdev, info, ¶ms->crypto,
6003 NL80211_MAX_NR_CIPHER_SUITES);
6007 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
6008 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) {
6012 params->inactivity_timeout = nla_get_u16(
6013 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
6016 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6017 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
6021 params->p2p_ctwindow =
6022 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
6023 if (params->p2p_ctwindow != 0 &&
6024 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) {
6030 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
6037 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
6038 params->p2p_opp_ps = tmp;
6039 if (params->p2p_opp_ps != 0 &&
6040 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) {
6046 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6047 err = nl80211_parse_chandef(rdev, info, ¶ms->chandef);
6050 } else if (wdev->valid_links) {
6051 /* with MLD need to specify the channel configuration */
6054 } else if (wdev->u.ap.preset_chandef.chan) {
6055 params->chandef = wdev->u.ap.preset_chandef;
6056 } else if (!nl80211_get_ap_channel(rdev, params)) {
6061 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) {
6062 err = nl80211_parse_punct_bitmap(rdev, info,
6064 ¶ms->punct_bitmap);
6069 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef,
6077 if (info->attrs[NL80211_ATTR_TX_RATES]) {
6078 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
6079 NL80211_ATTR_TX_RATES,
6080 ¶ms->beacon_rate,
6081 dev, false, link_id);
6085 err = validate_beacon_tx_rate(rdev, params->chandef.chan->band,
6086 ¶ms->beacon_rate);
6091 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
6093 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
6094 switch (params->smps_mode) {
6095 case NL80211_SMPS_OFF:
6097 case NL80211_SMPS_STATIC:
6098 if (!(rdev->wiphy.features &
6099 NL80211_FEATURE_STATIC_SMPS)) {
6104 case NL80211_SMPS_DYNAMIC:
6105 if (!(rdev->wiphy.features &
6106 NL80211_FEATURE_DYNAMIC_SMPS)) {
6116 params->smps_mode = NL80211_SMPS_OFF;
6119 params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
6120 if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
6125 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
6126 params->acl = parse_acl_data(&rdev->wiphy, info);
6127 if (IS_ERR(params->acl)) {
6128 err = PTR_ERR(params->acl);
6134 params->twt_responder =
6135 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
6137 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
6138 err = nl80211_parse_he_obss_pd(
6139 info->attrs[NL80211_ATTR_HE_OBSS_PD],
6140 ¶ms->he_obss_pd);
6145 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) {
6146 err = nl80211_parse_fils_discovery(rdev,
6147 info->attrs[NL80211_ATTR_FILS_DISCOVERY],
6153 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) {
6154 err = nl80211_parse_unsol_bcast_probe_resp(
6155 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP],
6161 if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) {
6162 err = nl80211_parse_mbssid_config(&rdev->wiphy, dev,
6163 info->attrs[NL80211_ATTR_MBSSID_CONFIG],
6164 ¶ms->mbssid_config,
6165 params->beacon.mbssid_ies ?
6166 params->beacon.mbssid_ies->cnt :
6172 if (!params->mbssid_config.ema && params->beacon.rnr_ies) {
6177 err = nl80211_calculate_ap_params(params);
6181 if (info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS])
6182 params->flags = nla_get_u32(
6183 info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]);
6184 else if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
6185 params->flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
6187 if (wdev->conn_owner_nlportid &&
6188 info->attrs[NL80211_ATTR_SOCKET_OWNER] &&
6189 wdev->conn_owner_nlportid != info->snd_portid) {
6194 /* FIXME: validate MLO/link-id against driver capabilities */
6196 err = rdev_start_ap(rdev, dev, params);
6198 wdev->links[link_id].ap.beacon_interval = params->beacon_interval;
6199 wdev->links[link_id].ap.chandef = params->chandef;
6200 wdev->u.ap.ssid_len = params->ssid_len;
6201 memcpy(wdev->u.ap.ssid, params->ssid,
6204 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6205 wdev->conn_owner_nlportid = info->snd_portid;
6207 nl80211_send_ap_started(wdev, link_id);
6213 kfree(params->beacon.mbssid_ies);
6214 if (params->mbssid_config.tx_wdev &&
6215 params->mbssid_config.tx_wdev->netdev &&
6216 params->mbssid_config.tx_wdev->netdev != dev)
6217 dev_put(params->mbssid_config.tx_wdev->netdev);
6218 kfree(params->beacon.rnr_ies);
6224 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
6226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6227 unsigned int link_id = nl80211_link_id(info->attrs);
6228 struct net_device *dev = info->user_ptr[1];
6229 struct wireless_dev *wdev = dev->ieee80211_ptr;
6230 struct cfg80211_beacon_data params;
6233 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6234 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6237 if (!rdev->ops->change_beacon)
6240 if (!wdev->links[link_id].ap.beacon_interval)
6243 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms, info->extack);
6248 err = rdev_change_beacon(rdev, dev, ¶ms);
6252 kfree(params.mbssid_ies);
6253 kfree(params.rnr_ies);
6257 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
6259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6260 unsigned int link_id = nl80211_link_id(info->attrs);
6261 struct net_device *dev = info->user_ptr[1];
6263 return cfg80211_stop_ap(rdev, dev, link_id, false);
6266 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
6267 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
6268 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
6269 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
6270 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
6271 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
6272 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
6275 static int parse_station_flags(struct genl_info *info,
6276 enum nl80211_iftype iftype,
6277 struct station_parameters *params)
6279 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
6284 * Try parsing the new attribute first so userspace
6285 * can specify both for older kernels.
6287 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
6289 struct nl80211_sta_flag_update *sta_flags;
6291 sta_flags = nla_data(nla);
6292 params->sta_flags_mask = sta_flags->mask;
6293 params->sta_flags_set = sta_flags->set;
6294 params->sta_flags_set &= params->sta_flags_mask;
6295 if ((params->sta_flags_mask |
6296 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
6301 /* if present, parse the old attribute */
6303 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
6307 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
6311 * Only allow certain flags for interface types so that
6312 * other attributes are silently ignored. Remember that
6313 * this is backward compatibility code with old userspace
6314 * and shouldn't be hit in other cases anyway.
6317 case NL80211_IFTYPE_AP:
6318 case NL80211_IFTYPE_AP_VLAN:
6319 case NL80211_IFTYPE_P2P_GO:
6320 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
6321 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
6322 BIT(NL80211_STA_FLAG_WME) |
6323 BIT(NL80211_STA_FLAG_MFP);
6325 case NL80211_IFTYPE_P2P_CLIENT:
6326 case NL80211_IFTYPE_STATION:
6327 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
6328 BIT(NL80211_STA_FLAG_TDLS_PEER);
6330 case NL80211_IFTYPE_MESH_POINT:
6331 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6332 BIT(NL80211_STA_FLAG_MFP) |
6333 BIT(NL80211_STA_FLAG_AUTHORIZED);
6339 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
6341 params->sta_flags_set |= (1<<flag);
6343 /* no longer support new API additions in old API */
6344 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
6352 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
6354 struct nlattr *rate;
6357 enum nl80211_rate_info rate_flg;
6359 rate = nla_nest_start_noflag(msg, attr);
6363 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
6364 bitrate = cfg80211_calculate_bitrate(info);
6365 /* report 16-bit bitrate only if we can */
6366 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
6368 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
6370 if (bitrate_compat > 0 &&
6371 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
6375 case RATE_INFO_BW_1:
6376 rate_flg = NL80211_RATE_INFO_1_MHZ_WIDTH;
6378 case RATE_INFO_BW_2:
6379 rate_flg = NL80211_RATE_INFO_2_MHZ_WIDTH;
6381 case RATE_INFO_BW_4:
6382 rate_flg = NL80211_RATE_INFO_4_MHZ_WIDTH;
6384 case RATE_INFO_BW_5:
6385 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
6387 case RATE_INFO_BW_8:
6388 rate_flg = NL80211_RATE_INFO_8_MHZ_WIDTH;
6390 case RATE_INFO_BW_10:
6391 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
6393 case RATE_INFO_BW_16:
6394 rate_flg = NL80211_RATE_INFO_16_MHZ_WIDTH;
6399 case RATE_INFO_BW_20:
6402 case RATE_INFO_BW_40:
6403 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
6405 case RATE_INFO_BW_80:
6406 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
6408 case RATE_INFO_BW_160:
6409 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
6411 case RATE_INFO_BW_HE_RU:
6413 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
6415 case RATE_INFO_BW_320:
6416 rate_flg = NL80211_RATE_INFO_320_MHZ_WIDTH;
6418 case RATE_INFO_BW_EHT_RU:
6420 WARN_ON(!(info->flags & RATE_INFO_FLAGS_EHT_MCS));
6424 if (rate_flg && nla_put_flag(msg, rate_flg))
6427 if (info->flags & RATE_INFO_FLAGS_MCS) {
6428 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
6430 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6431 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6433 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
6434 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
6436 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
6438 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6439 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6441 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
6442 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
6444 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
6446 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
6448 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
6450 if (info->bw == RATE_INFO_BW_HE_RU &&
6451 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
6454 } else if (info->flags & RATE_INFO_FLAGS_S1G_MCS) {
6455 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_MCS, info->mcs))
6457 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_NSS, info->nss))
6459 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6460 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6462 } else if (info->flags & RATE_INFO_FLAGS_EHT_MCS) {
6463 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_MCS, info->mcs))
6465 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_NSS, info->nss))
6467 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_GI, info->eht_gi))
6469 if (info->bw == RATE_INFO_BW_EHT_RU &&
6470 nla_put_u8(msg, NL80211_RATE_INFO_EHT_RU_ALLOC,
6471 info->eht_ru_alloc))
6475 nla_nest_end(msg, rate);
6479 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
6488 attr = nla_nest_start_noflag(msg, id);
6492 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
6493 if (!(mask & BIT(i)))
6496 if (nla_put_u8(msg, i, signal[i]))
6500 nla_nest_end(msg, attr);
6505 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
6507 struct cfg80211_registered_device *rdev,
6508 struct net_device *dev,
6509 const u8 *mac_addr, struct station_info *sinfo)
6512 struct nlattr *sinfoattr, *bss_param;
6514 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
6516 cfg80211_sinfo_release_content(sinfo);
6520 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6521 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
6522 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
6523 goto nla_put_failure;
6525 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
6527 goto nla_put_failure;
6529 #define PUT_SINFO(attr, memb, type) do { \
6530 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
6531 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
6532 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
6534 goto nla_put_failure; \
6536 #define PUT_SINFO_U64(attr, memb) do { \
6537 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
6538 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
6539 sinfo->memb, NL80211_STA_INFO_PAD)) \
6540 goto nla_put_failure; \
6543 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
6544 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
6545 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
6547 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
6548 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
6549 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
6550 (u32)sinfo->rx_bytes))
6551 goto nla_put_failure;
6553 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
6554 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
6555 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
6556 (u32)sinfo->tx_bytes))
6557 goto nla_put_failure;
6559 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
6560 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
6561 PUT_SINFO(LLID, llid, u16);
6562 PUT_SINFO(PLID, plid, u16);
6563 PUT_SINFO(PLINK_STATE, plink_state, u8);
6564 PUT_SINFO_U64(RX_DURATION, rx_duration);
6565 PUT_SINFO_U64(TX_DURATION, tx_duration);
6567 if (wiphy_ext_feature_isset(&rdev->wiphy,
6568 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6569 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
6571 switch (rdev->wiphy.signal_type) {
6572 case CFG80211_SIGNAL_TYPE_MBM:
6573 PUT_SINFO(SIGNAL, signal, u8);
6574 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
6579 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
6580 if (!nl80211_put_signal(msg, sinfo->chains,
6581 sinfo->chain_signal,
6582 NL80211_STA_INFO_CHAIN_SIGNAL))
6583 goto nla_put_failure;
6585 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
6586 if (!nl80211_put_signal(msg, sinfo->chains,
6587 sinfo->chain_signal_avg,
6588 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
6589 goto nla_put_failure;
6591 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
6592 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
6593 NL80211_STA_INFO_TX_BITRATE))
6594 goto nla_put_failure;
6596 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
6597 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
6598 NL80211_STA_INFO_RX_BITRATE))
6599 goto nla_put_failure;
6602 PUT_SINFO(RX_PACKETS, rx_packets, u32);
6603 PUT_SINFO(TX_PACKETS, tx_packets, u32);
6604 PUT_SINFO(TX_RETRIES, tx_retries, u32);
6605 PUT_SINFO(TX_FAILED, tx_failed, u32);
6606 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
6607 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
6608 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
6609 PUT_SINFO(LOCAL_PM, local_pm, u32);
6610 PUT_SINFO(PEER_PM, peer_pm, u32);
6611 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
6612 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
6613 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8);
6615 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
6616 bss_param = nla_nest_start_noflag(msg,
6617 NL80211_STA_INFO_BSS_PARAM);
6619 goto nla_put_failure;
6621 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
6622 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
6623 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
6624 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
6625 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
6626 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
6627 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
6628 sinfo->bss_param.dtim_period) ||
6629 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
6630 sinfo->bss_param.beacon_interval))
6631 goto nla_put_failure;
6633 nla_nest_end(msg, bss_param);
6635 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
6636 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
6637 sizeof(struct nl80211_sta_flag_update),
6639 goto nla_put_failure;
6641 PUT_SINFO_U64(T_OFFSET, t_offset);
6642 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
6643 PUT_SINFO_U64(BEACON_RX, rx_beacon);
6644 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
6645 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
6646 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
6647 if (wiphy_ext_feature_isset(&rdev->wiphy,
6648 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
6649 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
6650 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
6654 #undef PUT_SINFO_U64
6656 if (sinfo->pertid) {
6657 struct nlattr *tidsattr;
6660 tidsattr = nla_nest_start_noflag(msg,
6661 NL80211_STA_INFO_TID_STATS);
6663 goto nla_put_failure;
6665 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
6666 struct cfg80211_tid_stats *tidstats;
6667 struct nlattr *tidattr;
6669 tidstats = &sinfo->pertid[tid];
6671 if (!tidstats->filled)
6674 tidattr = nla_nest_start_noflag(msg, tid + 1);
6676 goto nla_put_failure;
6678 #define PUT_TIDVAL_U64(attr, memb) do { \
6679 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
6680 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
6681 tidstats->memb, NL80211_TID_STATS_PAD)) \
6682 goto nla_put_failure; \
6685 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
6686 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
6687 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
6688 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
6690 #undef PUT_TIDVAL_U64
6691 if ((tidstats->filled &
6692 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
6693 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
6694 NL80211_TID_STATS_TXQ_STATS))
6695 goto nla_put_failure;
6697 nla_nest_end(msg, tidattr);
6700 nla_nest_end(msg, tidsattr);
6703 nla_nest_end(msg, sinfoattr);
6705 if (sinfo->assoc_req_ies_len &&
6706 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
6707 sinfo->assoc_req_ies))
6708 goto nla_put_failure;
6710 if (sinfo->assoc_resp_ies_len &&
6711 nla_put(msg, NL80211_ATTR_RESP_IE, sinfo->assoc_resp_ies_len,
6712 sinfo->assoc_resp_ies))
6713 goto nla_put_failure;
6715 if (sinfo->mlo_params_valid) {
6716 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
6717 sinfo->assoc_link_id))
6718 goto nla_put_failure;
6720 if (!is_zero_ether_addr(sinfo->mld_addr) &&
6721 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN,
6723 goto nla_put_failure;
6726 cfg80211_sinfo_release_content(sinfo);
6727 genlmsg_end(msg, hdr);
6731 cfg80211_sinfo_release_content(sinfo);
6732 genlmsg_cancel(msg, hdr);
6736 static int nl80211_dump_station(struct sk_buff *skb,
6737 struct netlink_callback *cb)
6739 struct station_info sinfo;
6740 struct cfg80211_registered_device *rdev;
6741 struct wireless_dev *wdev;
6742 u8 mac_addr[ETH_ALEN];
6743 int sta_idx = cb->args[2];
6746 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
6749 /* nl80211_prepare_wdev_dump acquired it in the successful case */
6750 __acquire(&rdev->wiphy.mtx);
6752 if (!wdev->netdev) {
6757 if (!rdev->ops->dump_station) {
6763 memset(&sinfo, 0, sizeof(sinfo));
6764 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
6771 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
6772 NETLINK_CB(cb->skb).portid,
6773 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6774 rdev, wdev->netdev, mac_addr,
6782 cb->args[2] = sta_idx;
6785 wiphy_unlock(&rdev->wiphy);
6790 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
6792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6793 struct net_device *dev = info->user_ptr[1];
6794 struct station_info sinfo;
6795 struct sk_buff *msg;
6796 u8 *mac_addr = NULL;
6799 memset(&sinfo, 0, sizeof(sinfo));
6801 if (!info->attrs[NL80211_ATTR_MAC])
6804 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6806 if (!rdev->ops->get_station)
6809 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
6813 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6815 cfg80211_sinfo_release_content(&sinfo);
6819 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
6820 info->snd_portid, info->snd_seq, 0,
6821 rdev, dev, mac_addr, &sinfo) < 0) {
6826 return genlmsg_reply(msg, info);
6829 int cfg80211_check_station_change(struct wiphy *wiphy,
6830 struct station_parameters *params,
6831 enum cfg80211_station_type statype)
6833 if (params->listen_interval != -1 &&
6834 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6837 if (params->support_p2p_ps != -1 &&
6838 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6842 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
6843 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6846 /* When you run into this, adjust the code below for the new flag */
6847 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6850 case CFG80211_STA_MESH_PEER_KERNEL:
6851 case CFG80211_STA_MESH_PEER_USER:
6853 * No ignoring the TDLS flag here -- the userspace mesh
6854 * code doesn't have the bug of including TDLS in the
6857 if (params->sta_flags_mask &
6858 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6859 BIT(NL80211_STA_FLAG_MFP) |
6860 BIT(NL80211_STA_FLAG_AUTHORIZED)))
6863 case CFG80211_STA_TDLS_PEER_SETUP:
6864 case CFG80211_STA_TDLS_PEER_ACTIVE:
6865 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6867 /* ignore since it can't change */
6868 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6871 /* disallow mesh-specific things */
6872 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
6874 if (params->local_pm)
6876 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6880 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
6881 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
6882 /* TDLS can't be set, ... */
6883 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
6886 * ... but don't bother the driver with it. This works around
6887 * a hostapd/wpa_supplicant issue -- it always includes the
6888 * TLDS_PEER flag in the mask even for AP mode.
6890 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6893 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
6894 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
6895 /* reject other things that can't change */
6896 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
6898 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
6900 if (params->link_sta_params.supported_rates)
6902 if (params->ext_capab || params->link_sta_params.ht_capa ||
6903 params->link_sta_params.vht_capa ||
6904 params->link_sta_params.he_capa ||
6905 params->link_sta_params.eht_capa)
6909 if (statype != CFG80211_STA_AP_CLIENT &&
6910 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
6916 case CFG80211_STA_AP_MLME_CLIENT:
6917 /* Use this only for authorizing/unauthorizing a station */
6918 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
6921 case CFG80211_STA_AP_CLIENT:
6922 case CFG80211_STA_AP_CLIENT_UNASSOC:
6923 /* accept only the listed bits */
6924 if (params->sta_flags_mask &
6925 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
6926 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6927 BIT(NL80211_STA_FLAG_ASSOCIATED) |
6928 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
6929 BIT(NL80211_STA_FLAG_WME) |
6930 BIT(NL80211_STA_FLAG_MFP)))
6933 /* but authenticated/associated only if driver handles it */
6934 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
6935 params->sta_flags_mask &
6936 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6937 BIT(NL80211_STA_FLAG_ASSOCIATED)))
6940 case CFG80211_STA_IBSS:
6941 case CFG80211_STA_AP_STA:
6942 /* reject any changes other than AUTHORIZED */
6943 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
6946 case CFG80211_STA_TDLS_PEER_SETUP:
6947 /* reject any changes other than AUTHORIZED or WME */
6948 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
6949 BIT(NL80211_STA_FLAG_WME)))
6951 /* force (at least) rates when authorizing */
6952 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
6953 !params->link_sta_params.supported_rates)
6956 case CFG80211_STA_TDLS_PEER_ACTIVE:
6957 /* reject any changes */
6959 case CFG80211_STA_MESH_PEER_KERNEL:
6960 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6963 case CFG80211_STA_MESH_PEER_USER:
6964 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
6965 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
6971 * Older kernel versions ignored this attribute entirely, so don't
6972 * reject attempts to update it but mark it as unused instead so the
6973 * driver won't look at the data.
6975 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
6976 statype != CFG80211_STA_TDLS_PEER_SETUP)
6977 params->link_sta_params.opmode_notif_used = false;
6981 EXPORT_SYMBOL(cfg80211_check_station_change);
6984 * Get vlan interface making sure it is running and on the right wiphy.
6986 static struct net_device *get_vlan(struct genl_info *info,
6987 struct cfg80211_registered_device *rdev)
6989 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
6990 struct net_device *v;
6996 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
6998 return ERR_PTR(-ENODEV);
7000 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
7005 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
7006 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
7007 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
7012 if (!netif_running(v)) {
7020 return ERR_PTR(ret);
7023 static int nl80211_parse_sta_wme(struct genl_info *info,
7024 struct station_parameters *params)
7026 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
7030 /* parse WME attributes if present */
7031 if (!info->attrs[NL80211_ATTR_STA_WME])
7034 nla = info->attrs[NL80211_ATTR_STA_WME];
7035 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
7036 nl80211_sta_wme_policy,
7041 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
7042 params->uapsd_queues = nla_get_u8(
7043 tb[NL80211_STA_WME_UAPSD_QUEUES]);
7044 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
7047 if (tb[NL80211_STA_WME_MAX_SP])
7048 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
7050 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
7053 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
7058 static int nl80211_parse_sta_channel_info(struct genl_info *info,
7059 struct station_parameters *params)
7061 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
7062 params->supported_channels =
7063 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
7064 params->supported_channels_len =
7065 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
7067 * Need to include at least one (first channel, number of
7068 * channels) tuple for each subband (checked in policy),
7069 * and must have proper tuples for the rest of the data as well.
7071 if (params->supported_channels_len % 2)
7075 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
7076 params->supported_oper_classes =
7077 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
7078 params->supported_oper_classes_len =
7079 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
7084 static int nl80211_set_station_tdls(struct genl_info *info,
7085 struct station_parameters *params)
7088 /* Dummy STA entry gets updated once the peer capabilities are known */
7089 if (info->attrs[NL80211_ATTR_PEER_AID])
7090 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
7091 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
7092 params->link_sta_params.ht_capa =
7093 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
7094 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
7095 params->link_sta_params.vht_capa =
7096 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
7097 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
7098 params->link_sta_params.he_capa =
7099 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7100 params->link_sta_params.he_capa_len =
7101 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7103 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
7104 params->link_sta_params.eht_capa =
7105 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7106 params->link_sta_params.eht_capa_len =
7107 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7109 if (!ieee80211_eht_capa_size_ok((const u8 *)params->link_sta_params.he_capa,
7110 (const u8 *)params->link_sta_params.eht_capa,
7111 params->link_sta_params.eht_capa_len,
7117 err = nl80211_parse_sta_channel_info(info, params);
7121 return nl80211_parse_sta_wme(info, params);
7124 static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
7125 struct sta_txpwr *txpwr,
7128 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7131 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
7132 if (!rdev->ops->set_tx_power ||
7133 !wiphy_ext_feature_isset(&rdev->wiphy,
7134 NL80211_EXT_FEATURE_STA_TX_PWR))
7137 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
7138 txpwr->type = nla_get_u8(info->attrs[idx]);
7140 if (txpwr->type == NL80211_TX_POWER_LIMITED) {
7141 idx = NL80211_ATTR_STA_TX_POWER;
7143 if (info->attrs[idx])
7144 txpwr->power = nla_get_s16(info->attrs[idx]);
7157 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
7159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7160 struct net_device *dev = info->user_ptr[1];
7161 struct station_parameters params;
7165 memset(¶ms, 0, sizeof(params));
7167 if (!rdev->ops->change_station)
7171 * AID and listen_interval properties can be set only for unassociated
7172 * station. Include these parameters here and will check them in
7173 * cfg80211_check_station_change().
7175 if (info->attrs[NL80211_ATTR_STA_AID])
7176 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
7178 if (info->attrs[NL80211_ATTR_VLAN_ID])
7179 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
7181 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
7182 params.listen_interval =
7183 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
7185 params.listen_interval = -1;
7187 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
7188 params.support_p2p_ps =
7189 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
7191 params.support_p2p_ps = -1;
7193 if (!info->attrs[NL80211_ATTR_MAC])
7196 params.link_sta_params.link_id =
7197 nl80211_link_id_or_invalid(info->attrs);
7199 if (info->attrs[NL80211_ATTR_MLD_ADDR]) {
7200 /* If MLD_ADDR attribute is set then this is an MLD station
7201 * and the MLD_ADDR attribute holds the MLD address and the
7202 * MAC attribute holds for the LINK address.
7203 * In that case, the link_id is also expected to be valid.
7205 if (params.link_sta_params.link_id < 0)
7208 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
7209 params.link_sta_params.mld_mac = mac_addr;
7210 params.link_sta_params.link_mac =
7211 nla_data(info->attrs[NL80211_ATTR_MAC]);
7212 if (!is_valid_ether_addr(params.link_sta_params.link_mac))
7215 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7219 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
7220 params.link_sta_params.supported_rates =
7221 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7222 params.link_sta_params.supported_rates_len =
7223 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7226 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
7228 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
7229 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
7232 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
7234 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7235 params.ext_capab_len =
7236 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7239 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
7242 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
7243 params.plink_action =
7244 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
7246 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
7247 params.plink_state =
7248 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
7249 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
7250 params.peer_aid = nla_get_u16(
7251 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
7252 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
7255 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
7256 params.local_pm = nla_get_u32(
7257 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
7259 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
7260 params.link_sta_params.opmode_notif_used = true;
7261 params.link_sta_params.opmode_notif =
7262 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
7265 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
7266 params.link_sta_params.he_6ghz_capa =
7267 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
7269 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
7270 params.airtime_weight =
7271 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
7273 if (params.airtime_weight &&
7274 !wiphy_ext_feature_isset(&rdev->wiphy,
7275 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
7278 err = nl80211_parse_sta_txpower_setting(info,
7279 ¶ms.link_sta_params.txpwr,
7280 ¶ms.link_sta_params.txpwr_set);
7284 /* Include parameters for TDLS peer (will check later) */
7285 err = nl80211_set_station_tdls(info, ¶ms);
7289 params.vlan = get_vlan(info, rdev);
7290 if (IS_ERR(params.vlan))
7291 return PTR_ERR(params.vlan);
7293 switch (dev->ieee80211_ptr->iftype) {
7294 case NL80211_IFTYPE_AP:
7295 case NL80211_IFTYPE_AP_VLAN:
7296 case NL80211_IFTYPE_P2P_GO:
7297 case NL80211_IFTYPE_P2P_CLIENT:
7298 case NL80211_IFTYPE_STATION:
7299 case NL80211_IFTYPE_ADHOC:
7300 case NL80211_IFTYPE_MESH_POINT:
7307 /* driver will call cfg80211_check_station_change() */
7308 wdev_lock(dev->ieee80211_ptr);
7309 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
7310 wdev_unlock(dev->ieee80211_ptr);
7313 dev_put(params.vlan);
7318 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
7320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7322 struct net_device *dev = info->user_ptr[1];
7323 struct wireless_dev *wdev = dev->ieee80211_ptr;
7324 struct station_parameters params;
7325 u8 *mac_addr = NULL;
7326 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
7327 BIT(NL80211_STA_FLAG_ASSOCIATED);
7329 memset(¶ms, 0, sizeof(params));
7331 if (!rdev->ops->add_station)
7334 if (!info->attrs[NL80211_ATTR_MAC])
7337 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
7340 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
7343 if (!info->attrs[NL80211_ATTR_STA_AID] &&
7344 !info->attrs[NL80211_ATTR_PEER_AID])
7347 params.link_sta_params.link_id =
7348 nl80211_link_id_or_invalid(info->attrs);
7350 if (info->attrs[NL80211_ATTR_MLD_ADDR]) {
7351 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
7352 params.link_sta_params.mld_mac = mac_addr;
7353 params.link_sta_params.link_mac =
7354 nla_data(info->attrs[NL80211_ATTR_MAC]);
7355 if (!is_valid_ether_addr(params.link_sta_params.link_mac))
7358 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7361 params.link_sta_params.supported_rates =
7362 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7363 params.link_sta_params.supported_rates_len =
7364 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7365 params.listen_interval =
7366 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
7368 if (info->attrs[NL80211_ATTR_VLAN_ID])
7369 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
7371 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
7372 params.support_p2p_ps =
7373 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
7376 * if not specified, assume it's supported for P2P GO interface,
7377 * and is NOT supported for AP interface
7379 params.support_p2p_ps =
7380 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
7383 if (info->attrs[NL80211_ATTR_PEER_AID])
7384 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
7386 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
7388 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
7390 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
7391 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
7394 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
7396 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7397 params.ext_capab_len =
7398 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7401 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
7402 params.link_sta_params.ht_capa =
7403 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
7405 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
7406 params.link_sta_params.vht_capa =
7407 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
7409 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
7410 params.link_sta_params.he_capa =
7411 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7412 params.link_sta_params.he_capa_len =
7413 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7415 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
7416 params.link_sta_params.eht_capa =
7417 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7418 params.link_sta_params.eht_capa_len =
7419 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7421 if (!ieee80211_eht_capa_size_ok((const u8 *)params.link_sta_params.he_capa,
7422 (const u8 *)params.link_sta_params.eht_capa,
7423 params.link_sta_params.eht_capa_len,
7429 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
7430 params.link_sta_params.he_6ghz_capa =
7431 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
7433 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
7434 params.link_sta_params.opmode_notif_used = true;
7435 params.link_sta_params.opmode_notif =
7436 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
7439 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
7440 params.plink_action =
7441 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
7443 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
7444 params.airtime_weight =
7445 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
7447 if (params.airtime_weight &&
7448 !wiphy_ext_feature_isset(&rdev->wiphy,
7449 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
7452 err = nl80211_parse_sta_txpower_setting(info,
7453 ¶ms.link_sta_params.txpwr,
7454 ¶ms.link_sta_params.txpwr_set);
7458 err = nl80211_parse_sta_channel_info(info, ¶ms);
7462 err = nl80211_parse_sta_wme(info, ¶ms);
7466 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
7469 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
7470 * as userspace might just pass through the capabilities from the IEs
7471 * directly, rather than enforcing this restriction and returning an
7472 * error in this case.
7474 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
7475 params.link_sta_params.ht_capa = NULL;
7476 params.link_sta_params.vht_capa = NULL;
7478 /* HE and EHT require WME */
7479 if (params.link_sta_params.he_capa_len ||
7480 params.link_sta_params.he_6ghz_capa ||
7481 params.link_sta_params.eht_capa_len)
7485 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
7486 if (params.link_sta_params.he_6ghz_capa &&
7487 (params.link_sta_params.ht_capa || params.link_sta_params.vht_capa))
7490 /* When you run into this, adjust the code below for the new flag */
7491 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
7493 switch (dev->ieee80211_ptr->iftype) {
7494 case NL80211_IFTYPE_AP:
7495 case NL80211_IFTYPE_AP_VLAN:
7496 case NL80211_IFTYPE_P2P_GO:
7497 /* ignore WME attributes if iface/sta is not capable */
7498 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
7499 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
7500 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7502 /* TDLS peers cannot be added */
7503 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
7504 info->attrs[NL80211_ATTR_PEER_AID])
7506 /* but don't bother the driver with it */
7507 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
7509 /* allow authenticated/associated only if driver handles it */
7510 if (!(rdev->wiphy.features &
7511 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
7512 params.sta_flags_mask & auth_assoc)
7515 /* Older userspace, or userspace wanting to be compatible with
7516 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
7517 * and assoc flags in the mask, but assumes the station will be
7518 * added as associated anyway since this was the required driver
7519 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
7521 * In order to not bother drivers with this quirk in the API
7522 * set the flags in both the mask and set for new stations in
7525 if (!(params.sta_flags_mask & auth_assoc)) {
7526 params.sta_flags_mask |= auth_assoc;
7527 params.sta_flags_set |= auth_assoc;
7530 /* must be last in here for error handling */
7531 params.vlan = get_vlan(info, rdev);
7532 if (IS_ERR(params.vlan))
7533 return PTR_ERR(params.vlan);
7535 case NL80211_IFTYPE_MESH_POINT:
7536 /* ignore uAPSD data */
7537 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7539 /* associated is disallowed */
7540 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
7542 /* TDLS peers cannot be added */
7543 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
7544 info->attrs[NL80211_ATTR_PEER_AID])
7547 case NL80211_IFTYPE_STATION:
7548 case NL80211_IFTYPE_P2P_CLIENT:
7549 /* ignore uAPSD data */
7550 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7552 /* these are disallowed */
7553 if (params.sta_flags_mask &
7554 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
7555 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
7557 /* Only TDLS peers can be added */
7558 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
7560 /* Can only add if TDLS ... */
7561 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
7563 /* ... with external setup is supported */
7564 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
7567 * Older wpa_supplicant versions always mark the TDLS peer
7568 * as authorized, but it shouldn't yet be.
7570 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
7576 /* be aware of params.vlan when changing code here */
7578 wdev_lock(dev->ieee80211_ptr);
7579 if (wdev->valid_links) {
7580 if (params.link_sta_params.link_id < 0) {
7584 if (!(wdev->valid_links & BIT(params.link_sta_params.link_id))) {
7589 if (params.link_sta_params.link_id >= 0) {
7594 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
7596 wdev_unlock(dev->ieee80211_ptr);
7597 dev_put(params.vlan);
7601 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
7603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7604 struct net_device *dev = info->user_ptr[1];
7605 struct station_del_parameters params;
7608 memset(¶ms, 0, sizeof(params));
7610 if (info->attrs[NL80211_ATTR_MAC])
7611 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
7613 switch (dev->ieee80211_ptr->iftype) {
7614 case NL80211_IFTYPE_AP:
7615 case NL80211_IFTYPE_AP_VLAN:
7616 case NL80211_IFTYPE_MESH_POINT:
7617 case NL80211_IFTYPE_P2P_GO:
7618 /* always accept these */
7620 case NL80211_IFTYPE_ADHOC:
7621 /* conditionally accept */
7622 if (wiphy_ext_feature_isset(&rdev->wiphy,
7623 NL80211_EXT_FEATURE_DEL_IBSS_STA))
7630 if (!rdev->ops->del_station)
7633 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
7635 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
7636 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
7637 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
7640 /* Default to Deauthentication frame */
7641 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
7644 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
7645 params.reason_code =
7646 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7647 if (params.reason_code == 0)
7648 return -EINVAL; /* 0 is reserved */
7650 /* Default to reason code 2 */
7651 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
7654 wdev_lock(dev->ieee80211_ptr);
7655 ret = rdev_del_station(rdev, dev, ¶ms);
7656 wdev_unlock(dev->ieee80211_ptr);
7661 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
7662 int flags, struct net_device *dev,
7663 u8 *dst, u8 *next_hop,
7664 struct mpath_info *pinfo)
7667 struct nlattr *pinfoattr;
7669 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
7673 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7674 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7675 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
7676 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
7677 goto nla_put_failure;
7679 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
7681 goto nla_put_failure;
7682 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
7683 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
7685 goto nla_put_failure;
7686 if (((pinfo->filled & MPATH_INFO_SN) &&
7687 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
7688 ((pinfo->filled & MPATH_INFO_METRIC) &&
7689 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
7691 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
7692 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
7694 ((pinfo->filled & MPATH_INFO_FLAGS) &&
7695 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
7697 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
7698 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
7699 pinfo->discovery_timeout)) ||
7700 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
7701 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
7702 pinfo->discovery_retries)) ||
7703 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
7704 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
7705 pinfo->hop_count)) ||
7706 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
7707 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
7708 pinfo->path_change_count)))
7709 goto nla_put_failure;
7711 nla_nest_end(msg, pinfoattr);
7713 genlmsg_end(msg, hdr);
7717 genlmsg_cancel(msg, hdr);
7721 static int nl80211_dump_mpath(struct sk_buff *skb,
7722 struct netlink_callback *cb)
7724 struct mpath_info pinfo;
7725 struct cfg80211_registered_device *rdev;
7726 struct wireless_dev *wdev;
7728 u8 next_hop[ETH_ALEN];
7729 int path_idx = cb->args[2];
7732 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
7735 /* nl80211_prepare_wdev_dump acquired it in the successful case */
7736 __acquire(&rdev->wiphy.mtx);
7738 if (!rdev->ops->dump_mpath) {
7743 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
7749 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
7756 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
7757 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7758 wdev->netdev, dst, next_hop,
7766 cb->args[2] = path_idx;
7769 wiphy_unlock(&rdev->wiphy);
7773 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
7775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7777 struct net_device *dev = info->user_ptr[1];
7778 struct mpath_info pinfo;
7779 struct sk_buff *msg;
7781 u8 next_hop[ETH_ALEN];
7783 memset(&pinfo, 0, sizeof(pinfo));
7785 if (!info->attrs[NL80211_ATTR_MAC])
7788 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7790 if (!rdev->ops->get_mpath)
7793 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7796 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
7800 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7804 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
7805 dev, dst, next_hop, &pinfo) < 0) {
7810 return genlmsg_reply(msg, info);
7813 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
7815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7816 struct net_device *dev = info->user_ptr[1];
7818 u8 *next_hop = NULL;
7820 if (!info->attrs[NL80211_ATTR_MAC])
7823 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
7826 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7827 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
7829 if (!rdev->ops->change_mpath)
7832 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7835 return rdev_change_mpath(rdev, dev, dst, next_hop);
7838 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
7840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7841 struct net_device *dev = info->user_ptr[1];
7843 u8 *next_hop = NULL;
7845 if (!info->attrs[NL80211_ATTR_MAC])
7848 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
7851 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7852 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
7854 if (!rdev->ops->add_mpath)
7857 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7860 return rdev_add_mpath(rdev, dev, dst, next_hop);
7863 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
7865 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7866 struct net_device *dev = info->user_ptr[1];
7869 if (info->attrs[NL80211_ATTR_MAC])
7870 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7872 if (!rdev->ops->del_mpath)
7875 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7878 return rdev_del_mpath(rdev, dev, dst);
7881 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
7883 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7885 struct net_device *dev = info->user_ptr[1];
7886 struct mpath_info pinfo;
7887 struct sk_buff *msg;
7891 memset(&pinfo, 0, sizeof(pinfo));
7893 if (!info->attrs[NL80211_ATTR_MAC])
7896 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7898 if (!rdev->ops->get_mpp)
7901 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7904 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
7908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7912 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
7913 dev, dst, mpp, &pinfo) < 0) {
7918 return genlmsg_reply(msg, info);
7921 static int nl80211_dump_mpp(struct sk_buff *skb,
7922 struct netlink_callback *cb)
7924 struct mpath_info pinfo;
7925 struct cfg80211_registered_device *rdev;
7926 struct wireless_dev *wdev;
7929 int path_idx = cb->args[2];
7932 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
7935 /* nl80211_prepare_wdev_dump acquired it in the successful case */
7936 __acquire(&rdev->wiphy.mtx);
7938 if (!rdev->ops->dump_mpp) {
7943 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
7949 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
7956 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
7957 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7958 wdev->netdev, dst, mpp,
7966 cb->args[2] = path_idx;
7969 wiphy_unlock(&rdev->wiphy);
7973 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
7975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7976 struct net_device *dev = info->user_ptr[1];
7977 struct wireless_dev *wdev = dev->ieee80211_ptr;
7978 struct bss_parameters params;
7981 memset(¶ms, 0, sizeof(params));
7982 params.link_id = nl80211_link_id_or_invalid(info->attrs);
7983 /* default to not changing parameters */
7984 params.use_cts_prot = -1;
7985 params.use_short_preamble = -1;
7986 params.use_short_slot_time = -1;
7987 params.ap_isolate = -1;
7988 params.ht_opmode = -1;
7989 params.p2p_ctwindow = -1;
7990 params.p2p_opp_ps = -1;
7992 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
7993 params.use_cts_prot =
7994 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
7995 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
7996 params.use_short_preamble =
7997 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
7998 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
7999 params.use_short_slot_time =
8000 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
8001 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8002 params.basic_rates =
8003 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8004 params.basic_rates_len =
8005 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8007 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
8008 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
8009 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
8011 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
8013 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
8014 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
8016 params.p2p_ctwindow =
8017 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
8018 if (params.p2p_ctwindow != 0 &&
8019 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
8023 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
8026 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
8028 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
8029 params.p2p_opp_ps = tmp;
8030 if (params.p2p_opp_ps &&
8031 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
8035 if (!rdev->ops->change_bss)
8038 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
8039 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
8043 err = rdev_change_bss(rdev, dev, ¶ms);
8049 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
8053 enum nl80211_user_reg_hint_type user_reg_hint_type;
8057 * You should only get this when cfg80211 hasn't yet initialized
8058 * completely when built-in to the kernel right between the time
8059 * window between nl80211_init() and regulatory_init(), if that is
8062 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
8063 return -EINPROGRESS;
8065 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
8066 user_reg_hint_type =
8067 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
8069 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
8071 switch (user_reg_hint_type) {
8072 case NL80211_USER_REG_HINT_USER:
8073 case NL80211_USER_REG_HINT_CELL_BASE:
8074 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
8077 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
8078 return regulatory_hint_user(data, user_reg_hint_type);
8079 case NL80211_USER_REG_HINT_INDOOR:
8080 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8081 owner_nlportid = info->snd_portid;
8082 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
8088 return regulatory_hint_indoor(is_indoor, owner_nlportid);
8094 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
8096 return reg_reload_regdb();
8099 static int nl80211_get_mesh_config(struct sk_buff *skb,
8100 struct genl_info *info)
8102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8103 struct net_device *dev = info->user_ptr[1];
8104 struct wireless_dev *wdev = dev->ieee80211_ptr;
8105 struct mesh_config cur_params;
8108 struct nlattr *pinfoattr;
8109 struct sk_buff *msg;
8111 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
8114 if (!rdev->ops->get_mesh_config)
8118 /* If not connected, get default parameters */
8119 if (!wdev->u.mesh.id_len)
8120 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
8122 err = rdev_get_mesh_config(rdev, dev, &cur_params);
8128 /* Draw up a netlink message to send back */
8129 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8132 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8133 NL80211_CMD_GET_MESH_CONFIG);
8136 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
8138 goto nla_put_failure;
8139 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8140 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
8141 cur_params.dot11MeshRetryTimeout) ||
8142 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
8143 cur_params.dot11MeshConfirmTimeout) ||
8144 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
8145 cur_params.dot11MeshHoldingTimeout) ||
8146 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
8147 cur_params.dot11MeshMaxPeerLinks) ||
8148 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
8149 cur_params.dot11MeshMaxRetries) ||
8150 nla_put_u8(msg, NL80211_MESHCONF_TTL,
8151 cur_params.dot11MeshTTL) ||
8152 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
8153 cur_params.element_ttl) ||
8154 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
8155 cur_params.auto_open_plinks) ||
8156 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
8157 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
8158 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
8159 cur_params.dot11MeshHWMPmaxPREQretries) ||
8160 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
8161 cur_params.path_refresh_time) ||
8162 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
8163 cur_params.min_discovery_timeout) ||
8164 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
8165 cur_params.dot11MeshHWMPactivePathTimeout) ||
8166 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
8167 cur_params.dot11MeshHWMPpreqMinInterval) ||
8168 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
8169 cur_params.dot11MeshHWMPperrMinInterval) ||
8170 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
8171 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
8172 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
8173 cur_params.dot11MeshHWMPRootMode) ||
8174 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
8175 cur_params.dot11MeshHWMPRannInterval) ||
8176 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
8177 cur_params.dot11MeshGateAnnouncementProtocol) ||
8178 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
8179 cur_params.dot11MeshForwarding) ||
8180 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
8181 cur_params.rssi_threshold) ||
8182 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
8183 cur_params.ht_opmode) ||
8184 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
8185 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
8186 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
8187 cur_params.dot11MeshHWMProotInterval) ||
8188 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
8189 cur_params.dot11MeshHWMPconfirmationInterval) ||
8190 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
8191 cur_params.power_mode) ||
8192 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
8193 cur_params.dot11MeshAwakeWindowDuration) ||
8194 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
8195 cur_params.plink_timeout) ||
8196 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
8197 cur_params.dot11MeshConnectedToMeshGate) ||
8198 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN,
8199 cur_params.dot11MeshNolearn) ||
8200 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS,
8201 cur_params.dot11MeshConnectedToAuthServer))
8202 goto nla_put_failure;
8203 nla_nest_end(msg, pinfoattr);
8204 genlmsg_end(msg, hdr);
8205 return genlmsg_reply(msg, info);
8213 static const struct nla_policy
8214 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
8215 [NL80211_MESHCONF_RETRY_TIMEOUT] =
8216 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8217 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
8218 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8219 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
8220 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8221 [NL80211_MESHCONF_MAX_PEER_LINKS] =
8222 NLA_POLICY_RANGE(NLA_U16, 0, 255),
8223 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
8224 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
8225 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
8226 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
8227 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
8228 NLA_POLICY_RANGE(NLA_U32, 1, 255),
8229 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
8230 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
8231 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
8232 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
8233 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
8234 NLA_POLICY_MIN(NLA_U16, 1),
8235 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
8236 NLA_POLICY_MIN(NLA_U16, 1),
8237 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
8238 NLA_POLICY_MIN(NLA_U16, 1),
8239 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
8240 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
8241 NLA_POLICY_MIN(NLA_U16, 1),
8242 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
8243 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
8244 [NL80211_MESHCONF_RSSI_THRESHOLD] =
8245 NLA_POLICY_RANGE(NLA_S32, -255, 0),
8246 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
8247 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
8248 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
8249 NLA_POLICY_MIN(NLA_U16, 1),
8250 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
8251 NLA_POLICY_MIN(NLA_U16, 1),
8252 [NL80211_MESHCONF_POWER_MODE] =
8253 NLA_POLICY_RANGE(NLA_U32,
8254 NL80211_MESH_POWER_ACTIVE,
8255 NL80211_MESH_POWER_MAX),
8256 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
8257 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
8258 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8259 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8260 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8263 static const struct nla_policy
8264 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
8265 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
8266 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
8267 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
8268 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
8269 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
8270 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
8271 [NL80211_MESH_SETUP_IE] =
8272 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
8273 IEEE80211_MAX_DATA_LEN),
8274 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
8277 static int nl80211_parse_mesh_config(struct genl_info *info,
8278 struct mesh_config *cfg,
8281 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
8285 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
8288 cfg->param = fn(tb[attr]); \
8289 mask |= BIT((attr) - 1); \
8293 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
8295 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
8298 /* This makes sure that there aren't more than 32 mesh config
8299 * parameters (otherwise our bitfield scheme would not work.) */
8300 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
8302 /* Fill in the params struct */
8303 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
8304 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
8305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
8306 NL80211_MESHCONF_CONFIRM_TIMEOUT,
8308 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
8309 NL80211_MESHCONF_HOLDING_TIMEOUT,
8311 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
8312 NL80211_MESHCONF_MAX_PEER_LINKS,
8314 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
8315 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
8316 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
8317 NL80211_MESHCONF_TTL, nla_get_u8);
8318 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
8319 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
8320 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
8321 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
8323 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
8325 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
8327 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
8328 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
8330 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
8331 NL80211_MESHCONF_PATH_REFRESH_TIME,
8333 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
8334 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
8336 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
8337 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
8339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
8341 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
8343 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
8344 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
8345 cfg->dot11MeshHWMPactivePathTimeout > 65535))
8347 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
8348 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
8350 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
8351 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
8353 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
8354 dot11MeshHWMPnetDiameterTraversalTime, mask,
8355 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
8357 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
8358 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
8359 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
8360 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
8362 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
8363 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
8365 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
8366 NL80211_MESHCONF_FORWARDING, nla_get_u8);
8367 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
8368 NL80211_MESHCONF_RSSI_THRESHOLD,
8370 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
8371 NL80211_MESHCONF_CONNECTED_TO_GATE,
8373 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask,
8374 NL80211_MESHCONF_CONNECTED_TO_AS,
8377 * Check HT operation mode based on
8378 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
8380 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
8381 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
8383 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
8384 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
8385 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
8388 /* NON_HT_STA bit is reserved, but some programs set it */
8389 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
8391 cfg->ht_opmode = ht_opmode;
8392 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
8394 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
8395 dot11MeshHWMPactivePathToRootTimeout, mask,
8396 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
8398 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
8399 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
8400 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
8402 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
8403 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
8405 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
8407 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
8409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
8410 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
8411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
8412 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
8413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
8414 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
8415 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask,
8416 NL80211_MESHCONF_NOLEARN, nla_get_u8);
8422 #undef FILL_IN_MESH_PARAM_IF_SET
8425 static int nl80211_parse_mesh_setup(struct genl_info *info,
8426 struct mesh_setup *setup)
8428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8429 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
8431 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
8433 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack))
8436 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
8437 setup->sync_method =
8438 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
8439 IEEE80211_SYNC_METHOD_VENDOR :
8440 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
8442 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
8443 setup->path_sel_proto =
8444 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
8445 IEEE80211_PATH_PROTOCOL_VENDOR :
8446 IEEE80211_PATH_PROTOCOL_HWMP;
8448 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
8449 setup->path_metric =
8450 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
8451 IEEE80211_PATH_METRIC_VENDOR :
8452 IEEE80211_PATH_METRIC_AIRTIME;
8454 if (tb[NL80211_MESH_SETUP_IE]) {
8455 struct nlattr *ieattr =
8456 tb[NL80211_MESH_SETUP_IE];
8457 setup->ie = nla_data(ieattr);
8458 setup->ie_len = nla_len(ieattr);
8460 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
8461 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
8463 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
8464 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
8465 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
8466 if (setup->is_secure)
8467 setup->user_mpm = true;
8469 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
8470 if (!setup->user_mpm)
8473 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
8479 static int nl80211_update_mesh_config(struct sk_buff *skb,
8480 struct genl_info *info)
8482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8483 struct net_device *dev = info->user_ptr[1];
8484 struct wireless_dev *wdev = dev->ieee80211_ptr;
8485 struct mesh_config cfg;
8489 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
8492 if (!rdev->ops->update_mesh_config)
8495 err = nl80211_parse_mesh_config(info, &cfg, &mask);
8500 if (!wdev->u.mesh.id_len)
8504 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
8511 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
8512 struct sk_buff *msg)
8514 struct nlattr *nl_reg_rules;
8517 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
8518 (regdom->dfs_region &&
8519 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
8520 goto nla_put_failure;
8522 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
8524 goto nla_put_failure;
8526 for (i = 0; i < regdom->n_reg_rules; i++) {
8527 struct nlattr *nl_reg_rule;
8528 const struct ieee80211_reg_rule *reg_rule;
8529 const struct ieee80211_freq_range *freq_range;
8530 const struct ieee80211_power_rule *power_rule;
8531 unsigned int max_bandwidth_khz;
8533 reg_rule = ®dom->reg_rules[i];
8534 freq_range = ®_rule->freq_range;
8535 power_rule = ®_rule->power_rule;
8537 nl_reg_rule = nla_nest_start_noflag(msg, i);
8539 goto nla_put_failure;
8541 max_bandwidth_khz = freq_range->max_bandwidth_khz;
8542 if (!max_bandwidth_khz)
8543 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
8546 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
8548 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
8549 freq_range->start_freq_khz) ||
8550 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
8551 freq_range->end_freq_khz) ||
8552 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
8553 max_bandwidth_khz) ||
8554 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
8555 power_rule->max_antenna_gain) ||
8556 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
8557 power_rule->max_eirp) ||
8558 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
8559 reg_rule->dfs_cac_ms))
8560 goto nla_put_failure;
8562 nla_nest_end(msg, nl_reg_rule);
8565 nla_nest_end(msg, nl_reg_rules);
8572 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
8574 const struct ieee80211_regdomain *regdom = NULL;
8575 struct cfg80211_registered_device *rdev;
8576 struct wiphy *wiphy = NULL;
8577 struct sk_buff *msg;
8578 int err = -EMSGSIZE;
8581 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8585 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8586 NL80211_CMD_GET_REG);
8592 if (info->attrs[NL80211_ATTR_WIPHY]) {
8595 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
8597 err = PTR_ERR(rdev);
8598 goto nla_put_failure;
8601 wiphy = &rdev->wiphy;
8602 self_managed = wiphy->regulatory_flags &
8603 REGULATORY_WIPHY_SELF_MANAGED;
8607 regdom = get_wiphy_regdom(wiphy);
8609 /* a self-managed-reg device must have a private regdom */
8610 if (WARN_ON(!regdom && self_managed)) {
8612 goto nla_put_failure_rcu;
8616 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8617 goto nla_put_failure_rcu;
8622 if (!wiphy && reg_last_request_cell_base() &&
8623 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
8624 NL80211_USER_REG_HINT_CELL_BASE))
8625 goto nla_put_failure_rcu;
8628 regdom = rcu_dereference(cfg80211_regdomain);
8630 if (nl80211_put_regdom(regdom, msg))
8631 goto nla_put_failure_rcu;
8635 genlmsg_end(msg, hdr);
8637 return genlmsg_reply(msg, info);
8639 nla_put_failure_rcu:
8648 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
8649 u32 seq, int flags, struct wiphy *wiphy,
8650 const struct ieee80211_regdomain *regdom)
8652 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
8653 NL80211_CMD_GET_REG);
8658 genl_dump_check_consistent(cb, hdr);
8660 if (nl80211_put_regdom(regdom, msg))
8661 goto nla_put_failure;
8663 if (!wiphy && reg_last_request_cell_base() &&
8664 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
8665 NL80211_USER_REG_HINT_CELL_BASE))
8666 goto nla_put_failure;
8669 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8670 goto nla_put_failure;
8672 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
8673 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
8674 goto nla_put_failure;
8676 genlmsg_end(msg, hdr);
8680 genlmsg_cancel(msg, hdr);
8684 static int nl80211_get_reg_dump(struct sk_buff *skb,
8685 struct netlink_callback *cb)
8687 const struct ieee80211_regdomain *regdom = NULL;
8688 struct cfg80211_registered_device *rdev;
8689 int err, reg_idx, start = cb->args[2];
8693 if (cfg80211_regdomain && start == 0) {
8694 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
8696 rcu_dereference(cfg80211_regdomain));
8701 /* the global regdom is idx 0 */
8703 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
8704 regdom = get_wiphy_regdom(&rdev->wiphy);
8708 if (++reg_idx <= start)
8711 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
8712 NLM_F_MULTI, &rdev->wiphy, regdom);
8719 cb->args[2] = reg_idx;
8726 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
8727 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
8728 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
8729 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
8730 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
8731 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
8732 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
8733 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
8734 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
8737 static int parse_reg_rule(struct nlattr *tb[],
8738 struct ieee80211_reg_rule *reg_rule)
8740 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
8741 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
8743 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
8745 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
8747 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
8749 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
8751 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
8754 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
8756 freq_range->start_freq_khz =
8757 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
8758 freq_range->end_freq_khz =
8759 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
8760 freq_range->max_bandwidth_khz =
8761 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
8763 power_rule->max_eirp =
8764 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
8766 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
8767 power_rule->max_antenna_gain =
8768 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
8770 if (tb[NL80211_ATTR_DFS_CAC_TIME])
8771 reg_rule->dfs_cac_ms =
8772 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
8777 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
8779 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
8780 struct nlattr *nl_reg_rule;
8782 int rem_reg_rules, r;
8783 u32 num_rules = 0, rule_idx = 0;
8784 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
8785 struct ieee80211_regdomain *rd;
8787 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
8790 if (!info->attrs[NL80211_ATTR_REG_RULES])
8793 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
8795 if (info->attrs[NL80211_ATTR_DFS_REGION])
8796 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
8798 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
8801 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
8806 if (!reg_is_valid_request(alpha2)) {
8811 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
8817 rd->n_reg_rules = num_rules;
8818 rd->alpha2[0] = alpha2[0];
8819 rd->alpha2[1] = alpha2[1];
8822 * Disable DFS master mode if the DFS region was
8823 * not supported or known on this kernel.
8825 if (reg_supported_dfs_region(dfs_region))
8826 rd->dfs_region = dfs_region;
8828 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
8830 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
8831 nl_reg_rule, reg_rule_policy,
8835 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
8841 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
8847 r = set_regdom(rd, REGD_SOURCE_CRDA);
8848 /* set_regdom takes ownership of rd */
8856 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
8858 static int validate_scan_freqs(struct nlattr *freqs)
8860 struct nlattr *attr1, *attr2;
8861 int n_channels = 0, tmp1, tmp2;
8863 nla_for_each_nested(attr1, freqs, tmp1)
8864 if (nla_len(attr1) != sizeof(u32))
8867 nla_for_each_nested(attr1, freqs, tmp1) {
8870 * Some hardware has a limited channel list for
8871 * scanning, and it is pretty much nonsensical
8872 * to scan for a channel twice, so disallow that
8873 * and don't require drivers to check that the
8874 * channel list they get isn't longer than what
8875 * they can scan, as long as they can scan all
8876 * the channels they registered at once.
8878 nla_for_each_nested(attr2, freqs, tmp2)
8879 if (attr1 != attr2 &&
8880 nla_get_u32(attr1) == nla_get_u32(attr2))
8887 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
8889 return b < NUM_NL80211_BANDS && wiphy->bands[b];
8892 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
8893 struct cfg80211_bss_selection *bss_select)
8895 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
8896 struct nlattr *nest;
8901 /* only process one nested attribute */
8902 nest = nla_data(nla);
8903 if (!nla_ok(nest, nla_len(nest)))
8906 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
8907 nest, nl80211_bss_select_policy,
8912 /* only one attribute may be given */
8913 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
8921 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
8923 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
8924 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
8926 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
8927 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
8928 bss_select->param.band_pref =
8929 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
8930 if (!is_band_valid(wiphy, bss_select->param.band_pref))
8934 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
8935 struct nl80211_bss_select_rssi_adjust *adj_param;
8937 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
8938 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
8939 bss_select->param.adjust.band = adj_param->band;
8940 bss_select->param.adjust.delta = adj_param->delta;
8941 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
8945 /* user-space did not provide behaviour attribute */
8946 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
8949 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
8955 int nl80211_parse_random_mac(struct nlattr **attrs,
8956 u8 *mac_addr, u8 *mac_addr_mask)
8960 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
8961 eth_zero_addr(mac_addr);
8962 eth_zero_addr(mac_addr_mask);
8964 mac_addr_mask[0] = 0x3;
8969 /* need both or none */
8970 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
8973 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
8974 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
8976 /* don't allow or configure an mcast address */
8977 if (!is_multicast_ether_addr(mac_addr_mask) ||
8978 is_multicast_ether_addr(mac_addr))
8982 * allow users to pass a MAC address that has bits set outside
8983 * of the mask, but don't bother drivers with having to deal
8986 for (i = 0; i < ETH_ALEN; i++)
8987 mac_addr[i] &= mac_addr_mask[i];
8992 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev,
8993 struct ieee80211_channel *chan)
8995 unsigned int link_id;
8998 ASSERT_WDEV_LOCK(wdev);
9000 if (!cfg80211_beaconing_iface_active(wdev))
9004 * FIXME: check if we have a free HW resource/link for chan
9006 * This, as well as the FIXME below, requires knowing the link
9007 * capabilities of the hardware.
9010 /* we cannot leave radar channels */
9011 for_each_valid_link(wdev, link_id) {
9012 struct cfg80211_chan_def *chandef;
9014 chandef = wdev_chandef(wdev, link_id);
9015 if (!chandef || !chandef->chan)
9019 * FIXME: don't require all_ok, but rather check only the
9020 * correct HW resource/link onto which 'chan' falls,
9021 * as only that link leaves the channel for doing
9022 * the off-channel operation.
9025 if (chandef->chan->flags & IEEE80211_CHAN_RADAR)
9032 return regulatory_pre_cac_allowed(wdev->wiphy);
9035 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
9036 enum nl80211_ext_feature_index feat)
9038 if (!(flags & flag))
9040 if (wiphy_ext_feature_isset(wiphy, feat))
9046 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
9047 void *request, struct nlattr **attrs,
9050 u8 *mac_addr, *mac_addr_mask;
9052 enum nl80211_feature_flags randomness_flag;
9054 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
9057 if (is_sched_scan) {
9058 struct cfg80211_sched_scan_request *req = request;
9060 randomness_flag = wdev ?
9061 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
9062 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
9063 flags = &req->flags;
9064 mac_addr = req->mac_addr;
9065 mac_addr_mask = req->mac_addr_mask;
9067 struct cfg80211_scan_request *req = request;
9069 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
9070 flags = &req->flags;
9071 mac_addr = req->mac_addr;
9072 mac_addr_mask = req->mac_addr_mask;
9075 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
9077 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
9078 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
9079 !nl80211_check_scan_feat(wiphy, *flags,
9080 NL80211_SCAN_FLAG_LOW_SPAN,
9081 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
9082 !nl80211_check_scan_feat(wiphy, *flags,
9083 NL80211_SCAN_FLAG_LOW_POWER,
9084 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
9085 !nl80211_check_scan_feat(wiphy, *flags,
9086 NL80211_SCAN_FLAG_HIGH_ACCURACY,
9087 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
9088 !nl80211_check_scan_feat(wiphy, *flags,
9089 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
9090 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
9091 !nl80211_check_scan_feat(wiphy, *flags,
9092 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
9093 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
9094 !nl80211_check_scan_feat(wiphy, *flags,
9095 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
9096 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
9097 !nl80211_check_scan_feat(wiphy, *flags,
9098 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
9099 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
9100 !nl80211_check_scan_feat(wiphy, *flags,
9101 NL80211_SCAN_FLAG_RANDOM_SN,
9102 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
9103 !nl80211_check_scan_feat(wiphy, *flags,
9104 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
9105 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
9108 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
9111 if (!(wiphy->features & randomness_flag) ||
9112 (wdev && wdev->connected))
9115 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
9123 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
9125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9126 struct wireless_dev *wdev = info->user_ptr[1];
9127 struct cfg80211_scan_request *request;
9128 struct nlattr *scan_freqs = NULL;
9129 bool scan_freqs_khz = false;
9130 struct nlattr *attr;
9131 struct wiphy *wiphy;
9132 int err, tmp, n_ssids = 0, n_channels, i;
9133 size_t ie_len, size;
9135 wiphy = &rdev->wiphy;
9137 if (wdev->iftype == NL80211_IFTYPE_NAN)
9140 if (!rdev->ops->scan)
9143 if (rdev->scan_req || rdev->scan_msg)
9146 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) {
9147 if (!wiphy_ext_feature_isset(wiphy,
9148 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ))
9150 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ];
9151 scan_freqs_khz = true;
9152 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES])
9153 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES];
9156 n_channels = validate_scan_freqs(scan_freqs);
9160 n_channels = ieee80211_get_num_supported_channels(wiphy);
9163 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
9164 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
9167 if (n_ssids > wiphy->max_scan_ssids)
9170 if (info->attrs[NL80211_ATTR_IE])
9171 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9175 if (ie_len > wiphy->max_scan_ie_len)
9178 size = struct_size(request, channels, n_channels);
9179 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids));
9180 size = size_add(size, ie_len);
9181 request = kzalloc(size, GFP_KERNEL);
9186 request->ssids = (void *)&request->channels[n_channels];
9187 request->n_ssids = n_ssids;
9190 request->ie = (void *)(request->ssids + n_ssids);
9192 request->ie = (void *)(request->channels + n_channels);
9197 /* user specified, bail out if channel not found */
9198 nla_for_each_nested(attr, scan_freqs, tmp) {
9199 struct ieee80211_channel *chan;
9200 int freq = nla_get_u32(attr);
9202 if (!scan_freqs_khz)
9203 freq = MHZ_TO_KHZ(freq);
9205 chan = ieee80211_get_channel_khz(wiphy, freq);
9211 /* ignore disabled channels */
9212 if (chan->flags & IEEE80211_CHAN_DISABLED)
9215 request->channels[i] = chan;
9219 enum nl80211_band band;
9222 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9225 if (!wiphy->bands[band])
9227 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
9228 struct ieee80211_channel *chan;
9230 chan = &wiphy->bands[band]->channels[j];
9232 if (chan->flags & IEEE80211_CHAN_DISABLED)
9235 request->channels[i] = chan;
9246 request->n_channels = i;
9249 for (i = 0; i < request->n_channels; i++) {
9250 struct ieee80211_channel *chan = request->channels[i];
9252 /* if we can go off-channel to the target channel we're good */
9253 if (cfg80211_off_channel_oper_allowed(wdev, chan))
9256 if (!cfg80211_wdev_on_sub_chan(wdev, chan, true)) {
9266 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
9267 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
9271 request->ssids[i].ssid_len = nla_len(attr);
9272 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
9277 if (info->attrs[NL80211_ATTR_IE]) {
9278 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9279 memcpy((void *)request->ie,
9280 nla_data(info->attrs[NL80211_ATTR_IE]),
9284 for (i = 0; i < NUM_NL80211_BANDS; i++)
9285 if (wiphy->bands[i])
9287 (1 << wiphy->bands[i]->n_bitrates) - 1;
9289 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
9290 nla_for_each_nested(attr,
9291 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
9293 enum nl80211_band band = nla_type(attr);
9295 if (band < 0 || band >= NUM_NL80211_BANDS) {
9300 if (!wiphy->bands[band])
9303 err = ieee80211_get_ratemask(wiphy->bands[band],
9306 &request->rates[band]);
9312 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
9314 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
9315 request->duration_mandatory =
9316 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
9319 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
9325 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
9327 /* Initial implementation used NL80211_ATTR_MAC to set the specific
9328 * BSSID to scan for. This was problematic because that same attribute
9329 * was already used for another purpose (local random MAC address). The
9330 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
9331 * compatibility with older userspace components, also use the
9332 * NL80211_ATTR_MAC value here if it can be determined to be used for
9333 * the specific BSSID use case instead of the random MAC address
9334 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
9336 if (info->attrs[NL80211_ATTR_BSSID])
9337 memcpy(request->bssid,
9338 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
9339 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
9340 info->attrs[NL80211_ATTR_MAC])
9341 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
9344 eth_broadcast_addr(request->bssid);
9346 request->wdev = wdev;
9347 request->wiphy = &rdev->wiphy;
9348 request->scan_start = jiffies;
9350 rdev->scan_req = request;
9351 err = cfg80211_scan(rdev);
9356 nl80211_send_scan_start(rdev, wdev);
9357 dev_hold(wdev->netdev);
9362 rdev->scan_req = NULL;
9368 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
9370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9371 struct wireless_dev *wdev = info->user_ptr[1];
9373 if (!rdev->ops->abort_scan)
9379 if (!rdev->scan_req)
9382 rdev_abort_scan(rdev, wdev);
9387 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
9388 struct cfg80211_sched_scan_request *request,
9389 struct nlattr **attrs)
9391 int tmp, err, i = 0;
9392 struct nlattr *attr;
9394 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
9398 * If scan plans are not specified,
9399 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
9400 * case one scan plan will be set with the specified scan
9401 * interval and infinite number of iterations.
9403 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
9407 request->scan_plans[0].interval =
9408 DIV_ROUND_UP(interval, MSEC_PER_SEC);
9409 if (!request->scan_plans[0].interval)
9412 if (request->scan_plans[0].interval >
9413 wiphy->max_sched_scan_plan_interval)
9414 request->scan_plans[0].interval =
9415 wiphy->max_sched_scan_plan_interval;
9420 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
9421 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
9423 if (WARN_ON(i >= n_plans))
9426 err = nla_parse_nested_deprecated(plan,
9427 NL80211_SCHED_SCAN_PLAN_MAX,
9428 attr, nl80211_plan_policy,
9433 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
9436 request->scan_plans[i].interval =
9437 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
9438 if (!request->scan_plans[i].interval ||
9439 request->scan_plans[i].interval >
9440 wiphy->max_sched_scan_plan_interval)
9443 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
9444 request->scan_plans[i].iterations =
9445 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
9446 if (!request->scan_plans[i].iterations ||
9447 (request->scan_plans[i].iterations >
9448 wiphy->max_sched_scan_plan_iterations))
9450 } else if (i < n_plans - 1) {
9452 * All scan plans but the last one must specify
9453 * a finite number of iterations
9462 * The last scan plan must not specify the number of
9463 * iterations, it is supposed to run infinitely
9465 if (request->scan_plans[n_plans - 1].iterations)
9472 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
9473 struct cfg80211_match_set *match_sets,
9474 struct nlattr *tb_band_rssi,
9477 struct nlattr *attr;
9478 int i, tmp, ret = 0;
9480 if (!wiphy_ext_feature_isset(wiphy,
9481 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
9485 for (i = 0; i < NUM_NL80211_BANDS; i++)
9486 match_sets->per_band_rssi_thold[i] =
9487 NL80211_SCAN_RSSI_THOLD_OFF;
9491 for (i = 0; i < NUM_NL80211_BANDS; i++)
9492 match_sets->per_band_rssi_thold[i] = rssi_thold;
9494 nla_for_each_nested(attr, tb_band_rssi, tmp) {
9495 enum nl80211_band band = nla_type(attr);
9497 if (band < 0 || band >= NUM_NL80211_BANDS)
9500 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
9506 static struct cfg80211_sched_scan_request *
9507 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
9508 struct nlattr **attrs, int max_match_sets)
9510 struct cfg80211_sched_scan_request *request;
9511 struct nlattr *attr;
9512 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
9513 enum nl80211_band band;
9514 size_t ie_len, size;
9515 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
9516 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
9518 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
9519 n_channels = validate_scan_freqs(
9520 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
9522 return ERR_PTR(-EINVAL);
9524 n_channels = ieee80211_get_num_supported_channels(wiphy);
9527 if (attrs[NL80211_ATTR_SCAN_SSIDS])
9528 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
9532 if (n_ssids > wiphy->max_sched_scan_ssids)
9533 return ERR_PTR(-EINVAL);
9536 * First, count the number of 'real' matchsets. Due to an issue with
9537 * the old implementation, matchsets containing only the RSSI attribute
9538 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
9539 * RSSI for all matchsets, rather than their own matchset for reporting
9540 * all APs with a strong RSSI. This is needed to be compatible with
9541 * older userspace that treated a matchset with only the RSSI as the
9542 * global RSSI for all other matchsets - if there are other matchsets.
9544 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
9545 nla_for_each_nested(attr,
9546 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
9548 struct nlattr *rssi;
9550 err = nla_parse_nested_deprecated(tb,
9551 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
9553 nl80211_match_policy,
9556 return ERR_PTR(err);
9558 /* SSID and BSSID are mutually exclusive */
9559 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
9560 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
9561 return ERR_PTR(-EINVAL);
9563 /* add other standalone attributes here */
9564 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
9565 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
9569 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
9571 default_match_rssi = nla_get_s32(rssi);
9575 /* However, if there's no other matchset, add the RSSI one */
9576 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
9579 if (n_match_sets > max_match_sets)
9580 return ERR_PTR(-EINVAL);
9582 if (attrs[NL80211_ATTR_IE])
9583 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
9587 if (ie_len > wiphy->max_sched_scan_ie_len)
9588 return ERR_PTR(-EINVAL);
9590 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
9592 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
9593 * each scan plan already specifies its own interval
9595 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
9596 return ERR_PTR(-EINVAL);
9598 nla_for_each_nested(attr,
9599 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
9603 * The scan interval attribute is kept for backward
9604 * compatibility. If no scan plans are specified and sched scan
9605 * interval is specified, one scan plan will be set with this
9606 * scan interval and infinite number of iterations.
9608 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
9609 return ERR_PTR(-EINVAL);
9614 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
9615 return ERR_PTR(-EINVAL);
9617 if (!wiphy_ext_feature_isset(
9618 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
9619 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
9620 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
9621 return ERR_PTR(-EINVAL);
9623 size = struct_size(request, channels, n_channels);
9624 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids));
9625 size = size_add(size, array_size(sizeof(*request->match_sets),
9627 size = size_add(size, array_size(sizeof(*request->scan_plans),
9629 size = size_add(size, ie_len);
9630 request = kzalloc(size, GFP_KERNEL);
9632 return ERR_PTR(-ENOMEM);
9635 request->ssids = (void *)&request->channels[n_channels];
9636 request->n_ssids = n_ssids;
9639 request->ie = (void *)(request->ssids + n_ssids);
9641 request->ie = (void *)(request->channels + n_channels);
9646 request->match_sets = (void *)(request->ie + ie_len);
9648 request->match_sets =
9649 (void *)(request->ssids + n_ssids);
9651 request->match_sets =
9652 (void *)(request->channels + n_channels);
9654 request->n_match_sets = n_match_sets;
9657 request->scan_plans = (void *)(request->match_sets +
9659 else if (request->ie)
9660 request->scan_plans = (void *)(request->ie + ie_len);
9662 request->scan_plans = (void *)(request->ssids + n_ssids);
9664 request->scan_plans = (void *)(request->channels + n_channels);
9666 request->n_scan_plans = n_plans;
9669 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
9670 /* user specified, bail out if channel not found */
9671 nla_for_each_nested(attr,
9672 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
9674 struct ieee80211_channel *chan;
9676 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
9683 /* ignore disabled channels */
9684 if (chan->flags & IEEE80211_CHAN_DISABLED)
9687 request->channels[i] = chan;
9692 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9695 if (!wiphy->bands[band])
9697 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
9698 struct ieee80211_channel *chan;
9700 chan = &wiphy->bands[band]->channels[j];
9702 if (chan->flags & IEEE80211_CHAN_DISABLED)
9705 request->channels[i] = chan;
9716 request->n_channels = i;
9720 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
9722 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
9726 request->ssids[i].ssid_len = nla_len(attr);
9727 memcpy(request->ssids[i].ssid, nla_data(attr),
9734 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
9735 nla_for_each_nested(attr,
9736 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
9738 struct nlattr *ssid, *bssid, *rssi;
9740 err = nla_parse_nested_deprecated(tb,
9741 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
9743 nl80211_match_policy,
9747 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
9748 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
9750 if (!ssid && !bssid) {
9755 if (WARN_ON(i >= n_match_sets)) {
9756 /* this indicates a programming error,
9757 * the loop above should have verified
9765 memcpy(request->match_sets[i].ssid.ssid,
9766 nla_data(ssid), nla_len(ssid));
9767 request->match_sets[i].ssid.ssid_len =
9771 memcpy(request->match_sets[i].bssid,
9772 nla_data(bssid), ETH_ALEN);
9774 /* special attribute - old implementation w/a */
9775 request->match_sets[i].rssi_thold = default_match_rssi;
9776 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
9778 request->match_sets[i].rssi_thold =
9781 /* Parse per band RSSI attribute */
9782 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
9783 &request->match_sets[i],
9784 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
9785 request->match_sets[i].rssi_thold);
9792 /* there was no other matchset, so the RSSI one is alone */
9793 if (i == 0 && n_match_sets)
9794 request->match_sets[0].rssi_thold = default_match_rssi;
9796 request->min_rssi_thold = INT_MAX;
9797 for (i = 0; i < n_match_sets; i++)
9798 request->min_rssi_thold =
9799 min(request->match_sets[i].rssi_thold,
9800 request->min_rssi_thold);
9802 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
9806 request->ie_len = ie_len;
9807 memcpy((void *)request->ie,
9808 nla_data(attrs[NL80211_ATTR_IE]),
9812 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
9816 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
9818 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
9820 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
9821 request->relative_rssi = nla_get_s8(
9822 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
9823 request->relative_rssi_set = true;
9826 if (request->relative_rssi_set &&
9827 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
9828 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
9830 rssi_adjust = nla_data(
9831 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
9832 request->rssi_adjust.band = rssi_adjust->band;
9833 request->rssi_adjust.delta = rssi_adjust->delta;
9834 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
9840 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
9844 request->scan_start = jiffies;
9850 return ERR_PTR(err);
9853 static int nl80211_start_sched_scan(struct sk_buff *skb,
9854 struct genl_info *info)
9856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9857 struct net_device *dev = info->user_ptr[1];
9858 struct wireless_dev *wdev = dev->ieee80211_ptr;
9859 struct cfg80211_sched_scan_request *sched_scan_req;
9863 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
9866 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
9867 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
9871 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
9873 rdev->wiphy.max_match_sets);
9875 err = PTR_ERR_OR_ZERO(sched_scan_req);
9879 /* leave request id zero for legacy request
9880 * or if driver does not support multi-scheduled scan
9882 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
9883 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
9885 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
9889 sched_scan_req->dev = dev;
9890 sched_scan_req->wiphy = &rdev->wiphy;
9892 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9893 sched_scan_req->owner_nlportid = info->snd_portid;
9895 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
9897 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
9901 kfree(sched_scan_req);
9906 static int nl80211_stop_sched_scan(struct sk_buff *skb,
9907 struct genl_info *info)
9909 struct cfg80211_sched_scan_request *req;
9910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9913 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
9916 if (info->attrs[NL80211_ATTR_COOKIE]) {
9917 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9918 return __cfg80211_stop_sched_scan(rdev, cookie, false);
9921 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
9922 struct cfg80211_sched_scan_request,
9924 if (!req || req->reqid ||
9925 (req->owner_nlportid &&
9926 req->owner_nlportid != info->snd_portid))
9929 return cfg80211_stop_sched_scan_req(rdev, req, false);
9932 static int nl80211_start_radar_detection(struct sk_buff *skb,
9933 struct genl_info *info)
9935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9936 struct net_device *dev = info->user_ptr[1];
9937 struct wireless_dev *wdev = dev->ieee80211_ptr;
9938 struct wiphy *wiphy = wdev->wiphy;
9939 struct cfg80211_chan_def chandef;
9940 enum nl80211_dfs_regions dfs_region;
9941 unsigned int cac_time_ms;
9944 flush_delayed_work(&rdev->dfs_update_channels_wk);
9948 dfs_region = reg_get_dfs_region(wiphy);
9949 if (dfs_region == NL80211_DFS_UNSET)
9952 err = nl80211_parse_chandef(rdev, info, &chandef);
9956 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
9965 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) {
9970 if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) {
9971 err = cfg80211_start_background_radar_detection(rdev, wdev,
9976 if (netif_carrier_ok(dev)) {
9981 if (wdev->cac_started) {
9986 /* CAC start is offloaded to HW and can't be started manually */
9987 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) {
9992 if (!rdev->ops->start_radar_detection) {
9997 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
9998 if (WARN_ON(!cac_time_ms))
9999 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
10001 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
10003 wdev->links[0].ap.chandef = chandef;
10004 wdev->cac_started = true;
10005 wdev->cac_start_time = jiffies;
10006 wdev->cac_time_ms = cac_time_ms;
10009 wiphy_unlock(wiphy);
10014 static int nl80211_notify_radar_detection(struct sk_buff *skb,
10015 struct genl_info *info)
10017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10018 struct net_device *dev = info->user_ptr[1];
10019 struct wireless_dev *wdev = dev->ieee80211_ptr;
10020 struct wiphy *wiphy = wdev->wiphy;
10021 struct cfg80211_chan_def chandef;
10022 enum nl80211_dfs_regions dfs_region;
10025 dfs_region = reg_get_dfs_region(wiphy);
10026 if (dfs_region == NL80211_DFS_UNSET) {
10027 GENL_SET_ERR_MSG(info,
10028 "DFS Region is not set. Unexpected Radar indication");
10032 err = nl80211_parse_chandef(rdev, info, &chandef);
10034 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
10038 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
10040 GENL_SET_ERR_MSG(info, "chandef is invalid");
10045 GENL_SET_ERR_MSG(info,
10046 "Unexpected Radar indication for chandef/iftype");
10050 /* Do not process this notification if radar is already detected
10051 * by kernel on this channel, and return success.
10053 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
10056 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
10058 cfg80211_sched_dfs_chan_update(rdev);
10060 rdev->radar_chandef = chandef;
10062 /* Propagate this notification to other radios as well */
10063 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
10068 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
10070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10071 unsigned int link_id = nl80211_link_id(info->attrs);
10072 struct net_device *dev = info->user_ptr[1];
10073 struct wireless_dev *wdev = dev->ieee80211_ptr;
10074 struct cfg80211_csa_settings params;
10075 struct nlattr **csa_attrs = NULL;
10077 bool need_new_beacon = false;
10078 bool need_handle_dfs_flag = true;
10082 if (!rdev->ops->channel_switch ||
10083 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
10084 return -EOPNOTSUPP;
10086 switch (dev->ieee80211_ptr->iftype) {
10087 case NL80211_IFTYPE_AP:
10088 case NL80211_IFTYPE_P2P_GO:
10089 need_new_beacon = true;
10090 /* For all modes except AP the handle_dfs flag needs to be
10091 * supplied to tell the kernel that userspace will handle radar
10092 * events when they happen. Otherwise a switch to a channel
10093 * requiring DFS will be rejected.
10095 need_handle_dfs_flag = false;
10097 /* useless if AP is not running */
10098 if (!wdev->links[link_id].ap.beacon_interval)
10101 case NL80211_IFTYPE_ADHOC:
10102 if (!wdev->u.ibss.ssid_len)
10105 case NL80211_IFTYPE_MESH_POINT:
10106 if (!wdev->u.mesh.id_len)
10110 return -EOPNOTSUPP;
10113 memset(¶ms, 0, sizeof(params));
10114 params.beacon_csa.ftm_responder = -1;
10116 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10117 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
10120 /* only important for AP, IBSS and mesh create IEs internally */
10121 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
10124 /* Even though the attribute is u32, the specification says
10125 * u8, so let's make sure we don't overflow.
10127 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
10128 if (cs_count > 255)
10131 params.count = cs_count;
10133 if (!need_new_beacon)
10136 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after,
10141 csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs),
10148 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
10149 info->attrs[NL80211_ATTR_CSA_IES],
10150 nl80211_policy, info->extack);
10154 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa,
10159 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) {
10164 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
10165 if (!len || (len % sizeof(u16))) {
10170 params.n_counter_offsets_beacon = len / sizeof(u16);
10171 if (rdev->wiphy.max_num_csa_counters &&
10172 (params.n_counter_offsets_beacon >
10173 rdev->wiphy.max_num_csa_counters)) {
10178 params.counter_offsets_beacon =
10179 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
10181 /* sanity checks - counters should fit and be the same */
10182 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
10183 u16 offset = params.counter_offsets_beacon[i];
10185 if (offset >= params.beacon_csa.tail_len) {
10190 if (params.beacon_csa.tail[offset] != params.count) {
10196 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
10197 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
10198 if (!len || (len % sizeof(u16))) {
10203 params.n_counter_offsets_presp = len / sizeof(u16);
10204 if (rdev->wiphy.max_num_csa_counters &&
10205 (params.n_counter_offsets_presp >
10206 rdev->wiphy.max_num_csa_counters)) {
10211 params.counter_offsets_presp =
10212 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
10214 /* sanity checks - counters should fit and be the same */
10215 for (i = 0; i < params.n_counter_offsets_presp; i++) {
10216 u16 offset = params.counter_offsets_presp[i];
10218 if (offset >= params.beacon_csa.probe_resp_len) {
10223 if (params.beacon_csa.probe_resp[offset] !=
10232 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
10236 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
10242 err = cfg80211_chandef_dfs_required(wdev->wiphy,
10249 params.radar_required = true;
10250 if (need_handle_dfs_flag &&
10251 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
10257 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
10258 params.block_tx = true;
10260 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) {
10261 err = nl80211_parse_punct_bitmap(rdev, info,
10263 ¶ms.punct_bitmap);
10269 err = rdev_channel_switch(rdev, dev, ¶ms);
10273 kfree(params.beacon_after.mbssid_ies);
10274 kfree(params.beacon_csa.mbssid_ies);
10275 kfree(params.beacon_after.rnr_ies);
10276 kfree(params.beacon_csa.rnr_ies);
10281 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
10282 u32 seq, int flags,
10283 struct cfg80211_registered_device *rdev,
10284 struct wireless_dev *wdev,
10285 struct cfg80211_internal_bss *intbss)
10287 struct cfg80211_bss *res = &intbss->pub;
10288 const struct cfg80211_bss_ies *ies;
10289 unsigned int link_id;
10291 struct nlattr *bss;
10293 ASSERT_WDEV_LOCK(wdev);
10295 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
10296 NL80211_CMD_NEW_SCAN_RESULTS);
10300 genl_dump_check_consistent(cb, hdr);
10302 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
10303 goto nla_put_failure;
10304 if (wdev->netdev &&
10305 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
10306 goto nla_put_failure;
10307 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
10309 goto nla_put_failure;
10311 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
10313 goto nla_put_failure;
10314 if ((!is_zero_ether_addr(res->bssid) &&
10315 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
10316 goto nla_put_failure;
10319 /* indicate whether we have probe response data or not */
10320 if (rcu_access_pointer(res->proberesp_ies) &&
10321 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
10322 goto fail_unlock_rcu;
10324 /* this pointer prefers to be pointed to probe response data
10325 * but is always valid
10327 ies = rcu_dereference(res->ies);
10329 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
10331 goto fail_unlock_rcu;
10332 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
10333 ies->len, ies->data))
10334 goto fail_unlock_rcu;
10337 /* and this pointer is always (unless driver didn't know) beacon data */
10338 ies = rcu_dereference(res->beacon_ies);
10339 if (ies && ies->from_beacon) {
10340 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
10342 goto fail_unlock_rcu;
10343 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
10344 ies->len, ies->data))
10345 goto fail_unlock_rcu;
10349 if (res->beacon_interval &&
10350 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
10351 goto nla_put_failure;
10352 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
10353 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
10354 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET,
10355 res->channel->freq_offset) ||
10356 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
10357 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
10358 jiffies_to_msecs(jiffies - intbss->ts)))
10359 goto nla_put_failure;
10361 if (intbss->parent_tsf &&
10362 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
10363 intbss->parent_tsf, NL80211_BSS_PAD) ||
10364 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
10365 intbss->parent_bssid)))
10366 goto nla_put_failure;
10368 if (intbss->ts_boottime &&
10369 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
10370 intbss->ts_boottime, NL80211_BSS_PAD))
10371 goto nla_put_failure;
10373 if (!nl80211_put_signal(msg, intbss->pub.chains,
10374 intbss->pub.chain_signal,
10375 NL80211_BSS_CHAIN_SIGNAL))
10376 goto nla_put_failure;
10378 switch (rdev->wiphy.signal_type) {
10379 case CFG80211_SIGNAL_TYPE_MBM:
10380 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
10381 goto nla_put_failure;
10383 case CFG80211_SIGNAL_TYPE_UNSPEC:
10384 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
10385 goto nla_put_failure;
10391 switch (wdev->iftype) {
10392 case NL80211_IFTYPE_P2P_CLIENT:
10393 case NL80211_IFTYPE_STATION:
10394 for_each_valid_link(wdev, link_id) {
10395 if (intbss == wdev->links[link_id].client.current_bss &&
10396 (nla_put_u32(msg, NL80211_BSS_STATUS,
10397 NL80211_BSS_STATUS_ASSOCIATED) ||
10398 (wdev->valid_links &&
10399 (nla_put_u8(msg, NL80211_BSS_MLO_LINK_ID,
10401 nla_put(msg, NL80211_BSS_MLD_ADDR, ETH_ALEN,
10402 wdev->u.client.connected_addr)))))
10403 goto nla_put_failure;
10406 case NL80211_IFTYPE_ADHOC:
10407 if (intbss == wdev->u.ibss.current_bss &&
10408 nla_put_u32(msg, NL80211_BSS_STATUS,
10409 NL80211_BSS_STATUS_IBSS_JOINED))
10410 goto nla_put_failure;
10416 nla_nest_end(msg, bss);
10418 genlmsg_end(msg, hdr);
10424 genlmsg_cancel(msg, hdr);
10428 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
10430 struct cfg80211_registered_device *rdev;
10431 struct cfg80211_internal_bss *scan;
10432 struct wireless_dev *wdev;
10433 int start = cb->args[2], idx = 0;
10436 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
10439 /* nl80211_prepare_wdev_dump acquired it in the successful case */
10440 __acquire(&rdev->wiphy.mtx);
10443 spin_lock_bh(&rdev->bss_lock);
10446 * dump_scan will be called multiple times to break up the scan results
10447 * into multiple messages. It is unlikely that any more bss-es will be
10448 * expired after the first call, so only call only call this on the
10449 * first dump_scan invocation.
10452 cfg80211_bss_expire(rdev);
10454 cb->seq = rdev->bss_generation;
10456 list_for_each_entry(scan, &rdev->bss_list, list) {
10457 if (++idx <= start)
10459 if (nl80211_send_bss(skb, cb,
10460 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10461 rdev, wdev, scan) < 0) {
10467 spin_unlock_bh(&rdev->bss_lock);
10471 wiphy_unlock(&rdev->wiphy);
10476 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
10477 int flags, struct net_device *dev,
10478 bool allow_radio_stats,
10479 struct survey_info *survey)
10482 struct nlattr *infoattr;
10484 /* skip radio stats if userspace didn't request them */
10485 if (!survey->channel && !allow_radio_stats)
10488 hdr = nl80211hdr_put(msg, portid, seq, flags,
10489 NL80211_CMD_NEW_SURVEY_RESULTS);
10493 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
10494 goto nla_put_failure;
10496 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
10498 goto nla_put_failure;
10500 if (survey->channel &&
10501 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
10502 survey->channel->center_freq))
10503 goto nla_put_failure;
10505 if (survey->channel && survey->channel->freq_offset &&
10506 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET,
10507 survey->channel->freq_offset))
10508 goto nla_put_failure;
10510 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
10511 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
10512 goto nla_put_failure;
10513 if ((survey->filled & SURVEY_INFO_IN_USE) &&
10514 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
10515 goto nla_put_failure;
10516 if ((survey->filled & SURVEY_INFO_TIME) &&
10517 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
10518 survey->time, NL80211_SURVEY_INFO_PAD))
10519 goto nla_put_failure;
10520 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
10521 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
10522 survey->time_busy, NL80211_SURVEY_INFO_PAD))
10523 goto nla_put_failure;
10524 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
10525 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
10526 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
10527 goto nla_put_failure;
10528 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
10529 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
10530 survey->time_rx, NL80211_SURVEY_INFO_PAD))
10531 goto nla_put_failure;
10532 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
10533 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
10534 survey->time_tx, NL80211_SURVEY_INFO_PAD))
10535 goto nla_put_failure;
10536 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
10537 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
10538 survey->time_scan, NL80211_SURVEY_INFO_PAD))
10539 goto nla_put_failure;
10540 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
10541 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
10542 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
10543 goto nla_put_failure;
10545 nla_nest_end(msg, infoattr);
10547 genlmsg_end(msg, hdr);
10551 genlmsg_cancel(msg, hdr);
10555 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
10557 struct nlattr **attrbuf;
10558 struct survey_info survey;
10559 struct cfg80211_registered_device *rdev;
10560 struct wireless_dev *wdev;
10561 int survey_idx = cb->args[2];
10565 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
10569 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf);
10574 /* nl80211_prepare_wdev_dump acquired it in the successful case */
10575 __acquire(&rdev->wiphy.mtx);
10577 /* prepare_wdev_dump parsed the attributes */
10578 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
10580 if (!wdev->netdev) {
10585 if (!rdev->ops->dump_survey) {
10592 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
10594 if (res == -ENOENT)
10599 /* don't send disabled channels, but do send non-channel data */
10600 if (survey.channel &&
10601 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
10606 if (nl80211_send_survey(skb,
10607 NETLINK_CB(cb->skb).portid,
10608 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10609 wdev->netdev, radio_stats, &survey) < 0)
10615 cb->args[2] = survey_idx;
10619 wiphy_unlock(&rdev->wiphy);
10623 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
10625 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
10626 NL80211_WPA_VERSION_2 |
10627 NL80211_WPA_VERSION_3));
10630 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
10632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10633 struct net_device *dev = info->user_ptr[1];
10634 struct ieee80211_channel *chan;
10635 const u8 *bssid, *ssid;
10637 enum nl80211_auth_type auth_type;
10638 struct key_parse key;
10639 bool local_state_change;
10640 struct cfg80211_auth_request req = {};
10643 if (!info->attrs[NL80211_ATTR_MAC])
10646 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
10649 if (!info->attrs[NL80211_ATTR_SSID])
10652 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10655 err = nl80211_parse_key(info, &key);
10659 if (key.idx >= 0) {
10660 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
10662 if (!key.p.key || !key.p.key_len)
10664 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
10665 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
10666 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
10667 key.p.key_len != WLAN_KEY_LEN_WEP104))
10676 if (key.idx >= 0) {
10680 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
10681 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
10690 if (!rdev->ops->auth)
10691 return -EOPNOTSUPP;
10693 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10694 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10695 return -EOPNOTSUPP;
10697 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10698 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
10699 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10701 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10703 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
10707 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10708 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10710 if (info->attrs[NL80211_ATTR_IE]) {
10711 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10712 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10715 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10716 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
10719 if ((auth_type == NL80211_AUTHTYPE_SAE ||
10720 auth_type == NL80211_AUTHTYPE_FILS_SK ||
10721 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
10722 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
10723 !info->attrs[NL80211_ATTR_AUTH_DATA])
10726 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
10727 if (auth_type != NL80211_AUTHTYPE_SAE &&
10728 auth_type != NL80211_AUTHTYPE_FILS_SK &&
10729 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
10730 auth_type != NL80211_AUTHTYPE_FILS_PK)
10732 req.auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
10733 req.auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
10736 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
10739 * Since we no longer track auth state, ignore
10740 * requests to only change local state.
10742 if (local_state_change)
10745 req.auth_type = auth_type;
10746 req.key = key.p.key;
10747 req.key_len = key.p.key_len;
10748 req.key_idx = key.idx;
10749 req.link_id = nl80211_link_id_or_invalid(info->attrs);
10750 if (req.link_id >= 0) {
10751 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO))
10753 if (!info->attrs[NL80211_ATTR_MLD_ADDR])
10755 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
10756 if (!is_valid_ether_addr(req.ap_mld_addr))
10760 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
10761 IEEE80211_BSS_TYPE_ESS,
10762 IEEE80211_PRIVACY_ANY);
10766 wdev_lock(dev->ieee80211_ptr);
10767 err = cfg80211_mlme_auth(rdev, dev, &req);
10768 wdev_unlock(dev->ieee80211_ptr);
10770 cfg80211_put_bss(&rdev->wiphy, req.bss);
10775 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
10776 struct genl_info *info)
10778 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10779 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
10783 if (!rdev->ops->tx_control_port ||
10784 !wiphy_ext_feature_isset(&rdev->wiphy,
10785 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
10786 return -EOPNOTSUPP;
10791 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
10792 struct genl_info *info,
10793 struct cfg80211_crypto_settings *settings,
10796 memset(settings, 0, sizeof(*settings));
10798 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
10800 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
10803 proto = nla_get_u16(
10804 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
10805 settings->control_port_ethertype = cpu_to_be16(proto);
10806 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
10807 proto != ETH_P_PAE)
10809 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
10810 settings->control_port_no_encrypt = true;
10812 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
10814 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10815 int r = validate_pae_over_nl80211(rdev, info);
10820 settings->control_port_over_nl80211 = true;
10822 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH])
10823 settings->control_port_no_preauth = true;
10826 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
10830 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
10831 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
10832 settings->n_ciphers_pairwise = len / sizeof(u32);
10834 if (len % sizeof(u32))
10837 if (settings->n_ciphers_pairwise > cipher_limit)
10840 memcpy(settings->ciphers_pairwise, data, len);
10842 for (i = 0; i < settings->n_ciphers_pairwise; i++)
10843 if (!cfg80211_supported_cipher_suite(
10845 settings->ciphers_pairwise[i]))
10849 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
10850 settings->cipher_group =
10851 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
10852 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
10853 settings->cipher_group))
10857 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
10858 settings->wpa_versions =
10859 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
10860 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
10864 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
10868 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
10869 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
10870 settings->n_akm_suites = len / sizeof(u32);
10872 if (len % sizeof(u32))
10875 if (settings->n_akm_suites > rdev->wiphy.max_num_akm_suites)
10878 memcpy(settings->akm_suites, data, len);
10881 if (info->attrs[NL80211_ATTR_PMK]) {
10882 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
10884 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10885 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
10886 !wiphy_ext_feature_isset(&rdev->wiphy,
10887 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
10889 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10892 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
10893 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10894 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
10895 !wiphy_ext_feature_isset(&rdev->wiphy,
10896 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
10898 settings->sae_pwd =
10899 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
10900 settings->sae_pwd_len =
10901 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
10904 if (info->attrs[NL80211_ATTR_SAE_PWE])
10905 settings->sae_pwe =
10906 nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]);
10908 settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED;
10913 static struct cfg80211_bss *nl80211_assoc_bss(struct cfg80211_registered_device *rdev,
10914 const u8 *ssid, int ssid_len,
10915 struct nlattr **attrs)
10917 struct ieee80211_channel *chan;
10918 struct cfg80211_bss *bss;
10922 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_WIPHY_FREQ])
10923 return ERR_PTR(-EINVAL);
10925 bssid = nla_data(attrs[NL80211_ATTR_MAC]);
10927 freq = MHZ_TO_KHZ(nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]));
10928 if (attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10929 freq += nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10931 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
10933 return ERR_PTR(-EINVAL);
10935 bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid,
10937 IEEE80211_BSS_TYPE_ESS,
10938 IEEE80211_PRIVACY_ANY);
10940 return ERR_PTR(-ENOENT);
10945 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
10947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10948 struct net_device *dev = info->user_ptr[1];
10949 struct cfg80211_assoc_request req = {};
10950 struct nlattr **attrs = NULL;
10951 const u8 *ap_addr, *ssid;
10952 unsigned int link_id;
10955 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10956 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10959 if (!info->attrs[NL80211_ATTR_SSID])
10962 if (!rdev->ops->assoc)
10963 return -EOPNOTSUPP;
10965 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10966 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10967 return -EOPNOTSUPP;
10969 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10970 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10972 if (info->attrs[NL80211_ATTR_IE]) {
10973 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10974 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10976 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
10977 req.ie, req.ie_len)) {
10978 GENL_SET_ERR_MSG(info,
10979 "non-inheritance makes no sense");
10984 if (info->attrs[NL80211_ATTR_USE_MFP]) {
10985 enum nl80211_mfp mfp =
10986 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
10987 if (mfp == NL80211_MFP_REQUIRED)
10988 req.use_mfp = true;
10989 else if (mfp != NL80211_MFP_NO)
10993 if (info->attrs[NL80211_ATTR_PREV_BSSID])
10994 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
10996 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
10997 req.flags |= ASSOC_REQ_DISABLE_HT;
10999 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11000 memcpy(&req.ht_capa_mask,
11001 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11002 sizeof(req.ht_capa_mask));
11004 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11005 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11007 memcpy(&req.ht_capa,
11008 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11009 sizeof(req.ht_capa));
11012 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
11013 req.flags |= ASSOC_REQ_DISABLE_VHT;
11015 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE]))
11016 req.flags |= ASSOC_REQ_DISABLE_HE;
11018 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT]))
11019 req.flags |= ASSOC_REQ_DISABLE_EHT;
11021 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
11022 memcpy(&req.vht_capa_mask,
11023 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
11024 sizeof(req.vht_capa_mask));
11026 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
11027 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
11029 memcpy(&req.vht_capa,
11030 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
11031 sizeof(req.vht_capa));
11034 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
11035 if (!((rdev->wiphy.features &
11036 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
11037 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
11038 !wiphy_ext_feature_isset(&rdev->wiphy,
11039 NL80211_EXT_FEATURE_RRM))
11041 req.flags |= ASSOC_REQ_USE_RRM;
11044 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
11045 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
11046 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
11047 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
11050 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
11053 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) {
11054 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY])
11056 memcpy(&req.s1g_capa_mask,
11057 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]),
11058 sizeof(req.s1g_capa_mask));
11061 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) {
11062 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK])
11064 memcpy(&req.s1g_capa,
11065 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]),
11066 sizeof(req.s1g_capa));
11069 req.link_id = nl80211_link_id_or_invalid(info->attrs);
11071 if (info->attrs[NL80211_ATTR_MLO_LINKS]) {
11072 unsigned int attrsize = NUM_NL80211_ATTR * sizeof(*attrs);
11073 struct nlattr *link;
11076 if (req.link_id < 0)
11079 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO))
11082 if (info->attrs[NL80211_ATTR_MAC] ||
11083 info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
11084 !info->attrs[NL80211_ATTR_MLD_ADDR])
11087 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
11088 ap_addr = req.ap_mld_addr;
11090 attrs = kzalloc(attrsize, GFP_KERNEL);
11094 nla_for_each_nested(link,
11095 info->attrs[NL80211_ATTR_MLO_LINKS],
11097 memset(attrs, 0, attrsize);
11099 nla_parse_nested(attrs, NL80211_ATTR_MAX,
11102 if (!attrs[NL80211_ATTR_MLO_LINK_ID]) {
11107 link_id = nla_get_u8(attrs[NL80211_ATTR_MLO_LINK_ID]);
11108 /* cannot use the same link ID again */
11109 if (req.links[link_id].bss) {
11113 req.links[link_id].bss =
11114 nl80211_assoc_bss(rdev, ssid, ssid_len, attrs);
11115 if (IS_ERR(req.links[link_id].bss)) {
11116 err = PTR_ERR(req.links[link_id].bss);
11117 req.links[link_id].bss = NULL;
11121 if (attrs[NL80211_ATTR_IE]) {
11122 req.links[link_id].elems =
11123 nla_data(attrs[NL80211_ATTR_IE]);
11124 req.links[link_id].elems_len =
11125 nla_len(attrs[NL80211_ATTR_IE]);
11127 if (cfg80211_find_elem(WLAN_EID_FRAGMENT,
11128 req.links[link_id].elems,
11129 req.links[link_id].elems_len)) {
11130 GENL_SET_ERR_MSG(info,
11131 "cannot deal with fragmentation");
11136 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
11137 req.links[link_id].elems,
11138 req.links[link_id].elems_len)) {
11139 GENL_SET_ERR_MSG(info,
11140 "cannot deal with non-inheritance");
11146 req.links[link_id].disabled =
11147 nla_get_flag(attrs[NL80211_ATTR_MLO_LINK_DISABLED]);
11150 if (!req.links[req.link_id].bss) {
11155 if (req.links[req.link_id].elems_len) {
11156 GENL_SET_ERR_MSG(info,
11157 "cannot have per-link elems on assoc link");
11162 if (req.links[req.link_id].disabled) {
11163 GENL_SET_ERR_MSG(info,
11164 "cannot have assoc link disabled");
11172 if (req.link_id >= 0)
11175 req.bss = nl80211_assoc_bss(rdev, ssid, ssid_len, info->attrs);
11176 if (IS_ERR(req.bss))
11177 return PTR_ERR(req.bss);
11178 ap_addr = req.bss->bssid;
11181 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
11183 wdev_lock(dev->ieee80211_ptr);
11185 err = cfg80211_mlme_assoc(rdev, dev, &req);
11187 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
11188 dev->ieee80211_ptr->conn_owner_nlportid =
11190 memcpy(dev->ieee80211_ptr->disconnect_bssid,
11191 ap_addr, ETH_ALEN);
11194 wdev_unlock(dev->ieee80211_ptr);
11198 for (link_id = 0; link_id < ARRAY_SIZE(req.links); link_id++)
11199 cfg80211_put_bss(&rdev->wiphy, req.links[link_id].bss);
11200 cfg80211_put_bss(&rdev->wiphy, req.bss);
11206 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
11208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11209 struct net_device *dev = info->user_ptr[1];
11210 const u8 *ie = NULL, *bssid;
11211 int ie_len = 0, err;
11213 bool local_state_change;
11215 if (dev->ieee80211_ptr->conn_owner_nlportid &&
11216 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
11219 if (!info->attrs[NL80211_ATTR_MAC])
11222 if (!info->attrs[NL80211_ATTR_REASON_CODE])
11225 if (!rdev->ops->deauth)
11226 return -EOPNOTSUPP;
11228 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11229 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11230 return -EOPNOTSUPP;
11232 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11234 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
11235 if (reason_code == 0) {
11236 /* Reason Code 0 is reserved */
11240 if (info->attrs[NL80211_ATTR_IE]) {
11241 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11242 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11245 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
11247 wdev_lock(dev->ieee80211_ptr);
11248 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
11249 local_state_change);
11250 wdev_unlock(dev->ieee80211_ptr);
11254 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
11256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11257 struct net_device *dev = info->user_ptr[1];
11258 const u8 *ie = NULL, *bssid;
11259 int ie_len = 0, err;
11261 bool local_state_change;
11263 if (dev->ieee80211_ptr->conn_owner_nlportid &&
11264 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
11267 if (!info->attrs[NL80211_ATTR_MAC])
11270 if (!info->attrs[NL80211_ATTR_REASON_CODE])
11273 if (!rdev->ops->disassoc)
11274 return -EOPNOTSUPP;
11276 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11277 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11278 return -EOPNOTSUPP;
11280 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11282 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
11283 if (reason_code == 0) {
11284 /* Reason Code 0 is reserved */
11288 if (info->attrs[NL80211_ATTR_IE]) {
11289 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11290 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11293 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
11295 wdev_lock(dev->ieee80211_ptr);
11296 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
11297 local_state_change);
11298 wdev_unlock(dev->ieee80211_ptr);
11303 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
11304 int mcast_rate[NUM_NL80211_BANDS],
11307 struct wiphy *wiphy = &rdev->wiphy;
11308 bool found = false;
11311 for (band = 0; band < NUM_NL80211_BANDS; band++) {
11312 struct ieee80211_supported_band *sband;
11314 sband = wiphy->bands[band];
11318 for (i = 0; i < sband->n_bitrates; i++) {
11319 if (sband->bitrates[i].bitrate == rateval) {
11320 mcast_rate[band] = i + 1;
11330 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
11332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11333 struct net_device *dev = info->user_ptr[1];
11334 struct cfg80211_ibss_params ibss;
11335 struct wiphy *wiphy;
11336 struct cfg80211_cached_keys *connkeys = NULL;
11339 memset(&ibss, 0, sizeof(ibss));
11341 if (!info->attrs[NL80211_ATTR_SSID] ||
11342 !nla_len(info->attrs[NL80211_ATTR_SSID]))
11345 ibss.beacon_interval = 100;
11347 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
11348 ibss.beacon_interval =
11349 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
11351 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
11352 ibss.beacon_interval);
11356 if (!rdev->ops->join_ibss)
11357 return -EOPNOTSUPP;
11359 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
11360 return -EOPNOTSUPP;
11362 wiphy = &rdev->wiphy;
11364 if (info->attrs[NL80211_ATTR_MAC]) {
11365 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11367 if (!is_valid_ether_addr(ibss.bssid))
11370 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
11371 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
11373 if (info->attrs[NL80211_ATTR_IE]) {
11374 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11375 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11378 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
11382 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
11383 NL80211_IFTYPE_ADHOC))
11386 switch (ibss.chandef.width) {
11387 case NL80211_CHAN_WIDTH_5:
11388 case NL80211_CHAN_WIDTH_10:
11389 case NL80211_CHAN_WIDTH_20_NOHT:
11391 case NL80211_CHAN_WIDTH_20:
11392 case NL80211_CHAN_WIDTH_40:
11393 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
11396 case NL80211_CHAN_WIDTH_80:
11397 case NL80211_CHAN_WIDTH_80P80:
11398 case NL80211_CHAN_WIDTH_160:
11399 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
11401 if (!wiphy_ext_feature_isset(&rdev->wiphy,
11402 NL80211_EXT_FEATURE_VHT_IBSS))
11405 case NL80211_CHAN_WIDTH_320:
11411 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
11412 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
11414 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11416 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11418 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11419 struct ieee80211_supported_band *sband =
11420 wiphy->bands[ibss.chandef.chan->band];
11422 err = ieee80211_get_ratemask(sband, rates, n_rates,
11423 &ibss.basic_rates);
11428 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11429 memcpy(&ibss.ht_capa_mask,
11430 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11431 sizeof(ibss.ht_capa_mask));
11433 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11434 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11436 memcpy(&ibss.ht_capa,
11437 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11438 sizeof(ibss.ht_capa));
11441 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11442 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
11443 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11446 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
11447 bool no_ht = false;
11449 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
11450 if (IS_ERR(connkeys))
11451 return PTR_ERR(connkeys);
11453 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
11455 kfree_sensitive(connkeys);
11460 ibss.control_port =
11461 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
11463 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11464 int r = validate_pae_over_nl80211(rdev, info);
11467 kfree_sensitive(connkeys);
11471 ibss.control_port_over_nl80211 = true;
11474 ibss.userspace_handles_dfs =
11475 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11477 wdev_lock(dev->ieee80211_ptr);
11478 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
11480 kfree_sensitive(connkeys);
11481 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
11482 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11483 wdev_unlock(dev->ieee80211_ptr);
11488 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
11490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11491 struct net_device *dev = info->user_ptr[1];
11493 if (!rdev->ops->leave_ibss)
11494 return -EOPNOTSUPP;
11496 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
11497 return -EOPNOTSUPP;
11499 return cfg80211_leave_ibss(rdev, dev, false);
11502 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
11504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11505 struct net_device *dev = info->user_ptr[1];
11506 int mcast_rate[NUM_NL80211_BANDS];
11509 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
11510 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
11511 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
11512 return -EOPNOTSUPP;
11514 if (!rdev->ops->set_mcast_rate)
11515 return -EOPNOTSUPP;
11517 memset(mcast_rate, 0, sizeof(mcast_rate));
11519 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
11522 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
11523 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
11526 return rdev_set_mcast_rate(rdev, dev, mcast_rate);
11529 static struct sk_buff *
11530 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
11531 struct wireless_dev *wdev, int approxlen,
11532 u32 portid, u32 seq, enum nl80211_commands cmd,
11533 enum nl80211_attrs attr,
11534 const struct nl80211_vendor_cmd_info *info,
11537 struct sk_buff *skb;
11539 struct nlattr *data;
11541 skb = nlmsg_new(approxlen + 100, gfp);
11545 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
11551 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11552 goto nla_put_failure;
11555 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
11557 goto nla_put_failure;
11558 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
11560 goto nla_put_failure;
11564 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11565 wdev_id(wdev), NL80211_ATTR_PAD))
11566 goto nla_put_failure;
11567 if (wdev->netdev &&
11568 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
11569 wdev->netdev->ifindex))
11570 goto nla_put_failure;
11573 data = nla_nest_start_noflag(skb, attr);
11575 goto nla_put_failure;
11577 ((void **)skb->cb)[0] = rdev;
11578 ((void **)skb->cb)[1] = hdr;
11579 ((void **)skb->cb)[2] = data;
11588 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
11589 struct wireless_dev *wdev,
11590 enum nl80211_commands cmd,
11591 enum nl80211_attrs attr,
11592 unsigned int portid,
11593 int vendor_event_idx,
11594 int approxlen, gfp_t gfp)
11596 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11597 const struct nl80211_vendor_cmd_info *info;
11600 case NL80211_CMD_TESTMODE:
11601 if (WARN_ON(vendor_event_idx != -1))
11605 case NL80211_CMD_VENDOR:
11606 if (WARN_ON(vendor_event_idx < 0 ||
11607 vendor_event_idx >= wiphy->n_vendor_events))
11609 info = &wiphy->vendor_events[vendor_event_idx];
11616 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
11617 cmd, attr, info, gfp);
11619 EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
11621 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
11623 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11624 void *hdr = ((void **)skb->cb)[1];
11625 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
11626 struct nlattr *data = ((void **)skb->cb)[2];
11627 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
11629 /* clear CB data for netlink core to own from now on */
11630 memset(skb->cb, 0, sizeof(skb->cb));
11632 nla_nest_end(skb, data);
11633 genlmsg_end(skb, hdr);
11635 if (nlhdr->nlmsg_pid) {
11636 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
11639 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
11640 mcgrp = NL80211_MCGRP_VENDOR;
11642 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11643 skb, 0, mcgrp, gfp);
11646 EXPORT_SYMBOL(__cfg80211_send_event_skb);
11648 #ifdef CONFIG_NL80211_TESTMODE
11649 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
11651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11652 struct wireless_dev *wdev;
11655 lockdep_assert_held(&rdev->wiphy.mtx);
11657 wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info),
11660 if (!rdev->ops->testmode_cmd)
11661 return -EOPNOTSUPP;
11663 if (IS_ERR(wdev)) {
11664 err = PTR_ERR(wdev);
11665 if (err != -EINVAL)
11668 } else if (wdev->wiphy != &rdev->wiphy) {
11672 if (!info->attrs[NL80211_ATTR_TESTDATA])
11675 rdev->cur_cmd_info = info;
11676 err = rdev_testmode_cmd(rdev, wdev,
11677 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
11678 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
11679 rdev->cur_cmd_info = NULL;
11684 static int nl80211_testmode_dump(struct sk_buff *skb,
11685 struct netlink_callback *cb)
11687 struct cfg80211_registered_device *rdev;
11688 struct nlattr **attrbuf = NULL;
11698 * 0 is a valid index, but not valid for args[0],
11699 * so we need to offset by 1.
11701 phy_idx = cb->args[0] - 1;
11703 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
11709 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
11716 err = nlmsg_parse_deprecated(cb->nlh,
11717 GENL_HDRLEN + nl80211_fam.hdrsize,
11718 attrbuf, nl80211_fam.maxattr,
11719 nl80211_policy, NULL);
11723 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
11724 if (IS_ERR(rdev)) {
11725 err = PTR_ERR(rdev);
11728 phy_idx = rdev->wiphy_idx;
11730 if (attrbuf[NL80211_ATTR_TESTDATA])
11731 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
11735 data = nla_data((void *)cb->args[1]);
11736 data_len = nla_len((void *)cb->args[1]);
11739 if (!rdev->ops->testmode_dump) {
11745 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11746 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11747 NL80211_CMD_TESTMODE);
11748 struct nlattr *tmdata;
11753 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
11754 genlmsg_cancel(skb, hdr);
11758 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
11760 genlmsg_cancel(skb, hdr);
11763 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
11764 nla_nest_end(skb, tmdata);
11766 if (err == -ENOBUFS || err == -ENOENT) {
11767 genlmsg_cancel(skb, hdr);
11770 genlmsg_cancel(skb, hdr);
11774 genlmsg_end(skb, hdr);
11779 cb->args[0] = phy_idx + 1;
11787 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
11789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11790 struct net_device *dev = info->user_ptr[1];
11791 struct cfg80211_connect_params connect;
11792 struct wiphy *wiphy;
11793 struct cfg80211_cached_keys *connkeys = NULL;
11797 memset(&connect, 0, sizeof(connect));
11799 if (!info->attrs[NL80211_ATTR_SSID] ||
11800 !nla_len(info->attrs[NL80211_ATTR_SSID]))
11803 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
11804 connect.auth_type =
11805 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
11806 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
11807 NL80211_CMD_CONNECT))
11810 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
11812 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
11814 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
11815 !wiphy_ext_feature_isset(&rdev->wiphy,
11816 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
11818 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
11820 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
11821 NL80211_MAX_NR_CIPHER_SUITES);
11825 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11826 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11827 return -EOPNOTSUPP;
11829 wiphy = &rdev->wiphy;
11831 connect.bg_scan_period = -1;
11832 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
11833 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
11834 connect.bg_scan_period =
11835 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
11838 if (info->attrs[NL80211_ATTR_MAC])
11839 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11840 else if (info->attrs[NL80211_ATTR_MAC_HINT])
11841 connect.bssid_hint =
11842 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
11843 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
11844 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
11846 if (info->attrs[NL80211_ATTR_IE]) {
11847 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11848 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11851 if (info->attrs[NL80211_ATTR_USE_MFP]) {
11852 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
11853 if (connect.mfp == NL80211_MFP_OPTIONAL &&
11854 !wiphy_ext_feature_isset(&rdev->wiphy,
11855 NL80211_EXT_FEATURE_MFP_OPTIONAL))
11856 return -EOPNOTSUPP;
11858 connect.mfp = NL80211_MFP_NO;
11861 if (info->attrs[NL80211_ATTR_PREV_BSSID])
11862 connect.prev_bssid =
11863 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
11865 if (info->attrs[NL80211_ATTR_WIPHY_FREQ])
11866 freq = MHZ_TO_KHZ(nla_get_u32(
11867 info->attrs[NL80211_ATTR_WIPHY_FREQ]));
11868 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
11870 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
11873 connect.channel = nl80211_get_valid_chan(wiphy, freq);
11874 if (!connect.channel)
11876 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
11877 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
11878 freq = MHZ_TO_KHZ(freq);
11879 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq);
11880 if (!connect.channel_hint)
11884 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
11885 connect.edmg.channels =
11886 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
11888 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
11889 connect.edmg.bw_config =
11890 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
11893 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
11894 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
11895 if (IS_ERR(connkeys))
11896 return PTR_ERR(connkeys);
11899 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
11900 connect.flags |= ASSOC_REQ_DISABLE_HT;
11902 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11903 memcpy(&connect.ht_capa_mask,
11904 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11905 sizeof(connect.ht_capa_mask));
11907 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11908 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
11909 kfree_sensitive(connkeys);
11912 memcpy(&connect.ht_capa,
11913 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11914 sizeof(connect.ht_capa));
11917 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
11918 connect.flags |= ASSOC_REQ_DISABLE_VHT;
11920 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE]))
11921 connect.flags |= ASSOC_REQ_DISABLE_HE;
11923 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT]))
11924 connect.flags |= ASSOC_REQ_DISABLE_EHT;
11926 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
11927 memcpy(&connect.vht_capa_mask,
11928 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
11929 sizeof(connect.vht_capa_mask));
11931 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
11932 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
11933 kfree_sensitive(connkeys);
11936 memcpy(&connect.vht_capa,
11937 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
11938 sizeof(connect.vht_capa));
11941 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
11942 if (!((rdev->wiphy.features &
11943 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
11944 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
11945 !wiphy_ext_feature_isset(&rdev->wiphy,
11946 NL80211_EXT_FEATURE_RRM)) {
11947 kfree_sensitive(connkeys);
11950 connect.flags |= ASSOC_REQ_USE_RRM;
11953 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
11954 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
11955 kfree_sensitive(connkeys);
11956 return -EOPNOTSUPP;
11959 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
11960 /* bss selection makes no sense if bssid is set */
11961 if (connect.bssid) {
11962 kfree_sensitive(connkeys);
11966 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
11967 wiphy, &connect.bss_select);
11969 kfree_sensitive(connkeys);
11974 if (wiphy_ext_feature_isset(&rdev->wiphy,
11975 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
11976 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
11977 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
11978 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
11979 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
11980 connect.fils_erp_username =
11981 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
11982 connect.fils_erp_username_len =
11983 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
11984 connect.fils_erp_realm =
11985 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
11986 connect.fils_erp_realm_len =
11987 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
11988 connect.fils_erp_next_seq_num =
11990 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
11991 connect.fils_erp_rrk =
11992 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
11993 connect.fils_erp_rrk_len =
11994 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
11995 } else if (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 kfree_sensitive(connkeys);
12003 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
12004 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
12005 kfree_sensitive(connkeys);
12006 GENL_SET_ERR_MSG(info,
12007 "external auth requires connection ownership");
12010 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
12013 if (nla_get_flag(info->attrs[NL80211_ATTR_MLO_SUPPORT]))
12014 connect.flags |= CONNECT_REQ_MLO_SUPPORT;
12016 wdev_lock(dev->ieee80211_ptr);
12018 err = cfg80211_connect(rdev, dev, &connect, connkeys,
12019 connect.prev_bssid);
12021 kfree_sensitive(connkeys);
12023 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
12024 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
12026 memcpy(dev->ieee80211_ptr->disconnect_bssid,
12027 connect.bssid, ETH_ALEN);
12029 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid);
12032 wdev_unlock(dev->ieee80211_ptr);
12037 static int nl80211_update_connect_params(struct sk_buff *skb,
12038 struct genl_info *info)
12040 struct cfg80211_connect_params connect = {};
12041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12042 struct net_device *dev = info->user_ptr[1];
12043 struct wireless_dev *wdev = dev->ieee80211_ptr;
12044 bool fils_sk_offload;
12049 if (!rdev->ops->update_connect_params)
12050 return -EOPNOTSUPP;
12052 if (info->attrs[NL80211_ATTR_IE]) {
12053 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
12054 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
12055 changed |= UPDATE_ASSOC_IES;
12058 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
12059 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
12062 * when driver supports fils-sk offload all attributes must be
12063 * provided. So the else covers "fils-sk-not-all" and
12064 * "no-fils-sk-any".
12066 if (fils_sk_offload &&
12067 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
12068 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
12069 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
12070 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
12071 connect.fils_erp_username =
12072 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
12073 connect.fils_erp_username_len =
12074 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
12075 connect.fils_erp_realm =
12076 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
12077 connect.fils_erp_realm_len =
12078 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
12079 connect.fils_erp_next_seq_num =
12081 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
12082 connect.fils_erp_rrk =
12083 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
12084 connect.fils_erp_rrk_len =
12085 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
12086 changed |= UPDATE_FILS_ERP_INFO;
12087 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
12088 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
12089 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
12090 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
12094 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
12095 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
12096 if (!nl80211_valid_auth_type(rdev, auth_type,
12097 NL80211_CMD_CONNECT))
12100 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
12101 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
12104 connect.auth_type = auth_type;
12105 changed |= UPDATE_AUTH_TYPE;
12108 wdev_lock(dev->ieee80211_ptr);
12109 if (!wdev->connected)
12112 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
12113 wdev_unlock(dev->ieee80211_ptr);
12118 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
12120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12121 struct net_device *dev = info->user_ptr[1];
12125 if (dev->ieee80211_ptr->conn_owner_nlportid &&
12126 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
12129 if (!info->attrs[NL80211_ATTR_REASON_CODE])
12130 reason = WLAN_REASON_DEAUTH_LEAVING;
12132 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
12137 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12138 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
12139 return -EOPNOTSUPP;
12141 wdev_lock(dev->ieee80211_ptr);
12142 ret = cfg80211_disconnect(rdev, dev, reason, true);
12143 wdev_unlock(dev->ieee80211_ptr);
12147 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
12149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12153 if (info->attrs[NL80211_ATTR_PID]) {
12154 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
12156 net = get_net_ns_by_pid(pid);
12157 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
12158 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
12160 net = get_net_ns_by_fd(fd);
12166 return PTR_ERR(net);
12170 /* check if anything to do */
12171 if (!net_eq(wiphy_net(&rdev->wiphy), net))
12172 err = cfg80211_switch_netns(rdev, net);
12178 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
12180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12181 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
12182 struct cfg80211_pmksa *pmksa) = NULL;
12183 struct net_device *dev = info->user_ptr[1];
12184 struct cfg80211_pmksa pmksa;
12186 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
12188 if (!info->attrs[NL80211_ATTR_PMKID])
12191 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
12193 if (info->attrs[NL80211_ATTR_MAC]) {
12194 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
12195 } else if (info->attrs[NL80211_ATTR_SSID] &&
12196 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
12197 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
12198 info->attrs[NL80211_ATTR_PMK])) {
12199 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
12200 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
12202 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
12206 if (info->attrs[NL80211_ATTR_PMK]) {
12207 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12208 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12211 if (info->attrs[NL80211_ATTR_PMK_LIFETIME])
12212 pmksa.pmk_lifetime =
12213 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]);
12215 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD])
12216 pmksa.pmk_reauth_threshold =
12218 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]);
12220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
12222 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
12223 wiphy_ext_feature_isset(&rdev->wiphy,
12224 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
12225 return -EOPNOTSUPP;
12227 switch (info->genlhdr->cmd) {
12228 case NL80211_CMD_SET_PMKSA:
12229 rdev_ops = rdev->ops->set_pmksa;
12231 case NL80211_CMD_DEL_PMKSA:
12232 rdev_ops = rdev->ops->del_pmksa;
12240 return -EOPNOTSUPP;
12242 return rdev_ops(&rdev->wiphy, dev, &pmksa);
12245 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
12247 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12248 struct net_device *dev = info->user_ptr[1];
12250 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12251 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
12252 return -EOPNOTSUPP;
12254 if (!rdev->ops->flush_pmksa)
12255 return -EOPNOTSUPP;
12257 return rdev_flush_pmksa(rdev, dev);
12260 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
12262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12263 struct net_device *dev = info->user_ptr[1];
12264 u8 action_code, dialog_token;
12265 u32 peer_capability = 0;
12271 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
12272 !rdev->ops->tdls_mgmt)
12273 return -EOPNOTSUPP;
12275 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
12276 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
12277 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
12278 !info->attrs[NL80211_ATTR_IE] ||
12279 !info->attrs[NL80211_ATTR_MAC])
12282 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12283 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
12284 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12285 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
12286 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
12287 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
12289 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
12290 link_id = nl80211_link_id_or_invalid(info->attrs);
12292 return rdev_tdls_mgmt(rdev, dev, peer, link_id, action_code,
12293 dialog_token, status_code, peer_capability,
12295 nla_data(info->attrs[NL80211_ATTR_IE]),
12296 nla_len(info->attrs[NL80211_ATTR_IE]));
12299 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
12301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12302 struct net_device *dev = info->user_ptr[1];
12303 enum nl80211_tdls_operation operation;
12306 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
12307 !rdev->ops->tdls_oper)
12308 return -EOPNOTSUPP;
12310 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
12311 !info->attrs[NL80211_ATTR_MAC])
12314 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
12315 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12317 return rdev_tdls_oper(rdev, dev, peer, operation);
12320 static int nl80211_remain_on_channel(struct sk_buff *skb,
12321 struct genl_info *info)
12323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12324 unsigned int link_id = nl80211_link_id(info->attrs);
12325 struct wireless_dev *wdev = info->user_ptr[1];
12326 struct cfg80211_chan_def chandef;
12327 struct sk_buff *msg;
12333 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
12334 !info->attrs[NL80211_ATTR_DURATION])
12337 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
12339 if (!rdev->ops->remain_on_channel ||
12340 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
12341 return -EOPNOTSUPP;
12344 * We should be on that channel for at least a minimum amount of
12345 * time (10ms) but no longer than the driver supports.
12347 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
12348 duration > rdev->wiphy.max_remain_on_channel_duration)
12351 err = nl80211_parse_chandef(rdev, info, &chandef);
12356 if (!cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) {
12357 const struct cfg80211_chan_def *oper_chandef, *compat_chandef;
12359 oper_chandef = wdev_chandef(wdev, link_id);
12361 if (WARN_ON(!oper_chandef)) {
12362 /* cannot happen since we must beacon to get here */
12368 /* note: returns first one if identical chandefs */
12369 compat_chandef = cfg80211_chandef_compatible(&chandef,
12372 if (compat_chandef != &chandef) {
12379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12383 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12384 NL80211_CMD_REMAIN_ON_CHANNEL);
12390 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
12391 duration, &cookie);
12396 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12398 goto nla_put_failure;
12400 genlmsg_end(msg, hdr);
12402 return genlmsg_reply(msg, info);
12411 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
12412 struct genl_info *info)
12414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12415 struct wireless_dev *wdev = info->user_ptr[1];
12418 if (!info->attrs[NL80211_ATTR_COOKIE])
12421 if (!rdev->ops->cancel_remain_on_channel)
12422 return -EOPNOTSUPP;
12424 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12426 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
12429 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
12430 struct genl_info *info)
12432 struct cfg80211_bitrate_mask mask;
12433 unsigned int link_id = nl80211_link_id(info->attrs);
12434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12435 struct net_device *dev = info->user_ptr[1];
12436 struct wireless_dev *wdev = dev->ieee80211_ptr;
12439 if (!rdev->ops->set_bitrate_mask)
12440 return -EOPNOTSUPP;
12443 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
12444 NL80211_ATTR_TX_RATES, &mask,
12445 dev, true, link_id);
12449 err = rdev_set_bitrate_mask(rdev, dev, link_id, NULL, &mask);
12455 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
12457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12458 struct wireless_dev *wdev = info->user_ptr[1];
12459 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
12461 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
12464 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
12465 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
12467 switch (wdev->iftype) {
12468 case NL80211_IFTYPE_STATION:
12469 case NL80211_IFTYPE_ADHOC:
12470 case NL80211_IFTYPE_P2P_CLIENT:
12471 case NL80211_IFTYPE_AP:
12472 case NL80211_IFTYPE_AP_VLAN:
12473 case NL80211_IFTYPE_MESH_POINT:
12474 case NL80211_IFTYPE_P2P_GO:
12475 case NL80211_IFTYPE_P2P_DEVICE:
12477 case NL80211_IFTYPE_NAN:
12478 if (!wiphy_ext_feature_isset(wdev->wiphy,
12479 NL80211_EXT_FEATURE_SECURE_NAN))
12480 return -EOPNOTSUPP;
12483 return -EOPNOTSUPP;
12486 /* not much point in registering if we can't reply */
12487 if (!rdev->ops->mgmt_tx)
12488 return -EOPNOTSUPP;
12490 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] &&
12491 !wiphy_ext_feature_isset(&rdev->wiphy,
12492 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) {
12493 GENL_SET_ERR_MSG(info,
12494 "multicast RX registrations are not supported");
12495 return -EOPNOTSUPP;
12498 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
12499 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
12500 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
12501 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST],
12505 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
12507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12508 struct wireless_dev *wdev = info->user_ptr[1];
12509 struct cfg80211_chan_def chandef;
12513 struct sk_buff *msg = NULL;
12514 struct cfg80211_mgmt_tx_params params = {
12515 .dont_wait_for_ack =
12516 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
12519 if (!info->attrs[NL80211_ATTR_FRAME])
12522 if (!rdev->ops->mgmt_tx)
12523 return -EOPNOTSUPP;
12525 switch (wdev->iftype) {
12526 case NL80211_IFTYPE_P2P_DEVICE:
12527 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
12530 case NL80211_IFTYPE_STATION:
12531 case NL80211_IFTYPE_ADHOC:
12532 case NL80211_IFTYPE_P2P_CLIENT:
12533 case NL80211_IFTYPE_AP:
12534 case NL80211_IFTYPE_AP_VLAN:
12535 case NL80211_IFTYPE_MESH_POINT:
12536 case NL80211_IFTYPE_P2P_GO:
12538 case NL80211_IFTYPE_NAN:
12539 if (!wiphy_ext_feature_isset(wdev->wiphy,
12540 NL80211_EXT_FEATURE_SECURE_NAN))
12541 return -EOPNOTSUPP;
12544 return -EOPNOTSUPP;
12547 if (info->attrs[NL80211_ATTR_DURATION]) {
12548 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
12550 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
12553 * We should wait on the channel for at least a minimum amount
12554 * of time (10ms) but no longer than the driver supports.
12556 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
12557 params.wait > rdev->wiphy.max_remain_on_channel_duration)
12561 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
12563 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
12566 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
12568 /* get the channel if any has been specified, otherwise pass NULL to
12569 * the driver. The latter will use the current one
12571 chandef.chan = NULL;
12572 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
12573 err = nl80211_parse_chandef(rdev, info, &chandef);
12578 if (!chandef.chan && params.offchan)
12582 if (params.offchan &&
12583 !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) {
12588 params.link_id = nl80211_link_id_or_invalid(info->attrs);
12590 * This now races due to the unlock, but we cannot check
12591 * the valid links for the _station_ anyway, so that's up
12594 if (params.link_id >= 0 &&
12595 !(wdev->valid_links & BIT(params.link_id))) {
12601 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
12602 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
12604 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
12605 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
12608 if (len % sizeof(u16))
12611 params.n_csa_offsets = len / sizeof(u16);
12612 params.csa_offsets =
12613 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
12615 /* check that all the offsets fit the frame */
12616 for (i = 0; i < params.n_csa_offsets; i++) {
12617 if (params.csa_offsets[i] >= params.len)
12622 if (!params.dont_wait_for_ack) {
12623 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12627 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12628 NL80211_CMD_FRAME);
12635 params.chan = chandef.chan;
12636 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie);
12641 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12643 goto nla_put_failure;
12645 genlmsg_end(msg, hdr);
12646 return genlmsg_reply(msg, info);
12658 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
12660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12661 struct wireless_dev *wdev = info->user_ptr[1];
12664 if (!info->attrs[NL80211_ATTR_COOKIE])
12667 if (!rdev->ops->mgmt_tx_cancel_wait)
12668 return -EOPNOTSUPP;
12670 switch (wdev->iftype) {
12671 case NL80211_IFTYPE_STATION:
12672 case NL80211_IFTYPE_ADHOC:
12673 case NL80211_IFTYPE_P2P_CLIENT:
12674 case NL80211_IFTYPE_AP:
12675 case NL80211_IFTYPE_AP_VLAN:
12676 case NL80211_IFTYPE_P2P_GO:
12677 case NL80211_IFTYPE_P2P_DEVICE:
12679 case NL80211_IFTYPE_NAN:
12680 if (!wiphy_ext_feature_isset(wdev->wiphy,
12681 NL80211_EXT_FEATURE_SECURE_NAN))
12682 return -EOPNOTSUPP;
12685 return -EOPNOTSUPP;
12688 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12690 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
12693 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
12695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12696 struct wireless_dev *wdev;
12697 struct net_device *dev = info->user_ptr[1];
12702 if (!info->attrs[NL80211_ATTR_PS_STATE])
12705 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
12707 wdev = dev->ieee80211_ptr;
12709 if (!rdev->ops->set_power_mgmt)
12710 return -EOPNOTSUPP;
12712 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
12714 if (state == wdev->ps)
12717 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
12723 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
12725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12726 enum nl80211_ps_state ps_state;
12727 struct wireless_dev *wdev;
12728 struct net_device *dev = info->user_ptr[1];
12729 struct sk_buff *msg;
12733 wdev = dev->ieee80211_ptr;
12735 if (!rdev->ops->set_power_mgmt)
12736 return -EOPNOTSUPP;
12738 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12742 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12743 NL80211_CMD_GET_POWER_SAVE);
12750 ps_state = NL80211_PS_ENABLED;
12752 ps_state = NL80211_PS_DISABLED;
12754 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
12755 goto nla_put_failure;
12757 genlmsg_end(msg, hdr);
12758 return genlmsg_reply(msg, info);
12767 static const struct nla_policy
12768 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
12769 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
12770 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
12771 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
12772 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
12773 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
12774 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
12775 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
12778 static int nl80211_set_cqm_txe(struct genl_info *info,
12779 u32 rate, u32 pkts, u32 intvl)
12781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12782 struct net_device *dev = info->user_ptr[1];
12783 struct wireless_dev *wdev = dev->ieee80211_ptr;
12785 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
12788 if (!rdev->ops->set_cqm_txe_config)
12789 return -EOPNOTSUPP;
12791 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12792 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12793 return -EOPNOTSUPP;
12795 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
12798 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
12799 struct net_device *dev)
12801 struct wireless_dev *wdev = dev->ieee80211_ptr;
12802 s32 last, low, high;
12804 int i, n, low_index;
12807 /* RSSI reporting disabled? */
12808 if (!wdev->cqm_config)
12809 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
12812 * Obtain current RSSI value if possible, if not and no RSSI threshold
12813 * event has been received yet, we should receive an event after a
12814 * connection is established and enough beacons received to calculate
12817 if (!wdev->cqm_config->last_rssi_event_value &&
12818 wdev->links[0].client.current_bss &&
12819 rdev->ops->get_station) {
12820 struct station_info sinfo = {};
12823 mac_addr = wdev->links[0].client.current_bss->pub.bssid;
12825 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
12829 cfg80211_sinfo_release_content(&sinfo);
12830 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
12831 wdev->cqm_config->last_rssi_event_value =
12832 (s8) sinfo.rx_beacon_signal_avg;
12835 last = wdev->cqm_config->last_rssi_event_value;
12836 hyst = wdev->cqm_config->rssi_hyst;
12837 n = wdev->cqm_config->n_rssi_thresholds;
12839 for (i = 0; i < n; i++) {
12840 i = array_index_nospec(i, n);
12841 if (last < wdev->cqm_config->rssi_thresholds[i])
12846 if (low_index >= 0) {
12847 low_index = array_index_nospec(low_index, n);
12848 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
12853 i = array_index_nospec(i, n);
12854 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
12859 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
12862 static int nl80211_set_cqm_rssi(struct genl_info *info,
12863 const s32 *thresholds, int n_thresholds,
12866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12867 struct net_device *dev = info->user_ptr[1];
12868 struct wireless_dev *wdev = dev->ieee80211_ptr;
12870 s32 prev = S32_MIN;
12872 /* Check all values negative and sorted */
12873 for (i = 0; i < n_thresholds; i++) {
12874 if (thresholds[i] > 0 || thresholds[i] <= prev)
12877 prev = thresholds[i];
12880 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12881 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12882 return -EOPNOTSUPP;
12885 cfg80211_cqm_config_free(wdev);
12888 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
12889 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
12890 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
12892 return rdev_set_cqm_rssi_config(rdev, dev,
12893 thresholds[0], hysteresis);
12896 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12897 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
12898 return -EOPNOTSUPP;
12900 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
12904 if (n_thresholds) {
12905 struct cfg80211_cqm_config *cqm_config;
12907 cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds,
12915 cqm_config->rssi_hyst = hysteresis;
12916 cqm_config->n_rssi_thresholds = n_thresholds;
12917 memcpy(cqm_config->rssi_thresholds, thresholds,
12918 flex_array_size(cqm_config, rssi_thresholds,
12921 wdev->cqm_config = cqm_config;
12924 err = cfg80211_cqm_rssi_update(rdev, dev);
12932 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
12934 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
12935 struct nlattr *cqm;
12938 cqm = info->attrs[NL80211_ATTR_CQM];
12942 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
12943 nl80211_attr_cqm_policy,
12948 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
12949 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
12950 const s32 *thresholds =
12951 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
12952 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
12953 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
12958 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
12962 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
12963 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
12964 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
12965 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
12966 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
12967 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
12969 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
12975 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
12977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12978 struct net_device *dev = info->user_ptr[1];
12979 struct ocb_setup setup = {};
12982 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
12986 return cfg80211_join_ocb(rdev, dev, &setup);
12989 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
12991 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12992 struct net_device *dev = info->user_ptr[1];
12994 return cfg80211_leave_ocb(rdev, dev);
12997 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
12999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13000 struct net_device *dev = info->user_ptr[1];
13001 struct mesh_config cfg;
13002 struct mesh_setup setup;
13005 /* start with default */
13006 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
13007 memcpy(&setup, &default_mesh_setup, sizeof(setup));
13009 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
13010 /* and parse parameters if given */
13011 err = nl80211_parse_mesh_config(info, &cfg, NULL);
13016 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
13017 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
13020 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
13021 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
13023 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
13024 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
13025 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
13028 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
13029 setup.beacon_interval =
13030 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
13032 err = cfg80211_validate_beacon_int(rdev,
13033 NL80211_IFTYPE_MESH_POINT,
13034 setup.beacon_interval);
13039 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
13040 setup.dtim_period =
13041 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
13042 if (setup.dtim_period < 1 || setup.dtim_period > 100)
13046 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
13047 /* parse additional setup parameters if given */
13048 err = nl80211_parse_mesh_setup(info, &setup);
13053 if (setup.user_mpm)
13054 cfg.auto_open_plinks = false;
13056 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
13057 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
13061 /* __cfg80211_join_mesh() will sort it out */
13062 setup.chandef.chan = NULL;
13065 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
13066 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
13068 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
13069 struct ieee80211_supported_band *sband;
13071 if (!setup.chandef.chan)
13074 sband = rdev->wiphy.bands[setup.chandef.chan->band];
13076 err = ieee80211_get_ratemask(sband, rates, n_rates,
13077 &setup.basic_rates);
13082 if (info->attrs[NL80211_ATTR_TX_RATES]) {
13083 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
13084 NL80211_ATTR_TX_RATES,
13085 &setup.beacon_rate,
13090 if (!setup.chandef.chan)
13093 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
13094 &setup.beacon_rate);
13099 setup.userspace_handles_dfs =
13100 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
13102 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
13103 int r = validate_pae_over_nl80211(rdev, info);
13108 setup.control_port_over_nl80211 = true;
13111 wdev_lock(dev->ieee80211_ptr);
13112 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
13113 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
13114 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
13115 wdev_unlock(dev->ieee80211_ptr);
13120 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
13122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13123 struct net_device *dev = info->user_ptr[1];
13125 return cfg80211_leave_mesh(rdev, dev);
13129 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
13130 struct cfg80211_registered_device *rdev)
13132 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
13133 struct nlattr *nl_pats, *nl_pat;
13136 if (!wowlan->n_patterns)
13139 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
13143 for (i = 0; i < wowlan->n_patterns; i++) {
13144 nl_pat = nla_nest_start_noflag(msg, i + 1);
13147 pat_len = wowlan->patterns[i].pattern_len;
13148 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
13149 wowlan->patterns[i].mask) ||
13150 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
13151 wowlan->patterns[i].pattern) ||
13152 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
13153 wowlan->patterns[i].pkt_offset))
13155 nla_nest_end(msg, nl_pat);
13157 nla_nest_end(msg, nl_pats);
13162 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
13163 struct cfg80211_wowlan_tcp *tcp)
13165 struct nlattr *nl_tcp;
13170 nl_tcp = nla_nest_start_noflag(msg,
13171 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
13175 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
13176 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
13177 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
13178 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
13179 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
13180 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
13181 tcp->payload_len, tcp->payload) ||
13182 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
13183 tcp->data_interval) ||
13184 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
13185 tcp->wake_len, tcp->wake_data) ||
13186 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
13187 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
13190 if (tcp->payload_seq.len &&
13191 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
13192 sizeof(tcp->payload_seq), &tcp->payload_seq))
13195 if (tcp->payload_tok.len &&
13196 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
13197 sizeof(tcp->payload_tok) + tcp->tokens_size,
13198 &tcp->payload_tok))
13201 nla_nest_end(msg, nl_tcp);
13206 static int nl80211_send_wowlan_nd(struct sk_buff *msg,
13207 struct cfg80211_sched_scan_request *req)
13209 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
13215 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
13219 if (req->n_scan_plans == 1 &&
13220 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
13221 req->scan_plans[0].interval * 1000))
13224 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
13227 if (req->relative_rssi_set) {
13228 struct nl80211_bss_select_rssi_adjust rssi_adjust;
13230 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
13231 req->relative_rssi))
13234 rssi_adjust.band = req->rssi_adjust.band;
13235 rssi_adjust.delta = req->rssi_adjust.delta;
13236 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
13237 sizeof(rssi_adjust), &rssi_adjust))
13241 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13245 for (i = 0; i < req->n_channels; i++) {
13246 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13250 nla_nest_end(msg, freqs);
13252 if (req->n_match_sets) {
13253 matches = nla_nest_start_noflag(msg,
13254 NL80211_ATTR_SCHED_SCAN_MATCH);
13258 for (i = 0; i < req->n_match_sets; i++) {
13259 match = nla_nest_start_noflag(msg, i);
13263 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
13264 req->match_sets[i].ssid.ssid_len,
13265 req->match_sets[i].ssid.ssid))
13267 nla_nest_end(msg, match);
13269 nla_nest_end(msg, matches);
13272 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
13276 for (i = 0; i < req->n_scan_plans; i++) {
13277 scan_plan = nla_nest_start_noflag(msg, i + 1);
13281 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
13282 req->scan_plans[i].interval) ||
13283 (req->scan_plans[i].iterations &&
13284 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
13285 req->scan_plans[i].iterations)))
13287 nla_nest_end(msg, scan_plan);
13289 nla_nest_end(msg, scan_plans);
13291 nla_nest_end(msg, nd);
13296 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
13298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13299 struct sk_buff *msg;
13301 u32 size = NLMSG_DEFAULT_SIZE;
13303 if (!rdev->wiphy.wowlan)
13304 return -EOPNOTSUPP;
13306 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
13307 /* adjust size to have room for all the data */
13308 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
13309 rdev->wiphy.wowlan_config->tcp->payload_len +
13310 rdev->wiphy.wowlan_config->tcp->wake_len +
13311 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
13314 msg = nlmsg_new(size, GFP_KERNEL);
13318 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13319 NL80211_CMD_GET_WOWLAN);
13321 goto nla_put_failure;
13323 if (rdev->wiphy.wowlan_config) {
13324 struct nlattr *nl_wowlan;
13326 nl_wowlan = nla_nest_start_noflag(msg,
13327 NL80211_ATTR_WOWLAN_TRIGGERS);
13329 goto nla_put_failure;
13331 if ((rdev->wiphy.wowlan_config->any &&
13332 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
13333 (rdev->wiphy.wowlan_config->disconnect &&
13334 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
13335 (rdev->wiphy.wowlan_config->magic_pkt &&
13336 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
13337 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
13338 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
13339 (rdev->wiphy.wowlan_config->eap_identity_req &&
13340 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
13341 (rdev->wiphy.wowlan_config->four_way_handshake &&
13342 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
13343 (rdev->wiphy.wowlan_config->rfkill_release &&
13344 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
13345 goto nla_put_failure;
13347 if (nl80211_send_wowlan_patterns(msg, rdev))
13348 goto nla_put_failure;
13350 if (nl80211_send_wowlan_tcp(msg,
13351 rdev->wiphy.wowlan_config->tcp))
13352 goto nla_put_failure;
13354 if (nl80211_send_wowlan_nd(
13356 rdev->wiphy.wowlan_config->nd_config))
13357 goto nla_put_failure;
13359 nla_nest_end(msg, nl_wowlan);
13362 genlmsg_end(msg, hdr);
13363 return genlmsg_reply(msg, info);
13370 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
13371 struct nlattr *attr,
13372 struct cfg80211_wowlan *trig)
13374 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
13375 struct cfg80211_wowlan_tcp *cfg;
13376 struct nl80211_wowlan_tcp_data_token *tok = NULL;
13377 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
13379 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
13382 if (!rdev->wiphy.wowlan->tcp)
13385 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
13386 nl80211_wowlan_tcp_policy, NULL);
13390 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
13391 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
13392 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
13393 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
13394 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
13395 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
13396 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
13397 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
13400 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
13401 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
13404 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
13405 rdev->wiphy.wowlan->tcp->data_interval_max ||
13406 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
13409 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
13410 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
13413 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
13414 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
13417 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
13418 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
13420 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
13421 tokens_size = tokln - sizeof(*tok);
13423 if (!tok->len || tokens_size % tok->len)
13425 if (!rdev->wiphy.wowlan->tcp->tok)
13427 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
13429 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
13431 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
13433 if (tok->offset + tok->len > data_size)
13437 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
13438 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
13439 if (!rdev->wiphy.wowlan->tcp->seq)
13441 if (seq->len == 0 || seq->len > 4)
13443 if (seq->len + seq->offset > data_size)
13447 size = sizeof(*cfg);
13449 size += wake_size + wake_mask_size;
13450 size += tokens_size;
13452 cfg = kzalloc(size, GFP_KERNEL);
13455 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
13456 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
13457 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
13459 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
13460 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
13464 /* allocate a socket and port for it and use it */
13465 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
13466 IPPROTO_TCP, &cfg->sock, 1);
13471 if (inet_csk_get_port(cfg->sock->sk, port)) {
13472 sock_release(cfg->sock);
13474 return -EADDRINUSE;
13476 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
13482 cfg->src_port = port;
13485 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
13486 cfg->payload_len = data_size;
13487 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
13488 memcpy((void *)cfg->payload,
13489 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
13492 cfg->payload_seq = *seq;
13493 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
13494 cfg->wake_len = wake_size;
13495 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
13496 memcpy((void *)cfg->wake_data,
13497 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
13499 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
13500 data_size + wake_size;
13501 memcpy((void *)cfg->wake_mask,
13502 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
13505 cfg->tokens_size = tokens_size;
13506 cfg->payload_tok = *tok;
13507 memcpy(cfg->payload_tok.token_stream, tok->token_stream,
13516 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
13517 const struct wiphy_wowlan_support *wowlan,
13518 struct nlattr *attr,
13519 struct cfg80211_wowlan *trig)
13521 struct nlattr **tb;
13524 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
13528 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
13533 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
13534 nl80211_policy, NULL);
13538 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
13539 wowlan->max_nd_match_sets);
13540 err = PTR_ERR_OR_ZERO(trig->nd_config);
13542 trig->nd_config = NULL;
13549 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
13551 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13552 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
13553 struct cfg80211_wowlan new_triggers = {};
13554 struct cfg80211_wowlan *ntrig;
13555 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
13557 bool prev_enabled = rdev->wiphy.wowlan_config;
13558 bool regular = false;
13561 return -EOPNOTSUPP;
13563 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
13564 cfg80211_rdev_free_wowlan(rdev);
13565 rdev->wiphy.wowlan_config = NULL;
13569 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
13570 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
13571 nl80211_wowlan_policy, info->extack);
13575 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
13576 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
13578 new_triggers.any = true;
13581 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
13582 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
13584 new_triggers.disconnect = true;
13588 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
13589 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
13591 new_triggers.magic_pkt = true;
13595 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
13598 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
13599 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
13601 new_triggers.gtk_rekey_failure = true;
13605 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
13606 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
13608 new_triggers.eap_identity_req = true;
13612 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
13613 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
13615 new_triggers.four_way_handshake = true;
13619 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
13620 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
13622 new_triggers.rfkill_release = true;
13626 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
13627 struct nlattr *pat;
13628 int n_patterns = 0;
13629 int rem, pat_len, mask_len, pkt_offset;
13630 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
13634 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
13637 if (n_patterns > wowlan->n_patterns)
13640 new_triggers.patterns = kcalloc(n_patterns,
13641 sizeof(new_triggers.patterns[0]),
13643 if (!new_triggers.patterns)
13646 new_triggers.n_patterns = n_patterns;
13649 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
13653 err = nla_parse_nested_deprecated(pat_tb,
13654 MAX_NL80211_PKTPAT,
13656 nl80211_packet_pattern_policy,
13662 if (!pat_tb[NL80211_PKTPAT_MASK] ||
13663 !pat_tb[NL80211_PKTPAT_PATTERN])
13665 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
13666 mask_len = DIV_ROUND_UP(pat_len, 8);
13667 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
13669 if (pat_len > wowlan->pattern_max_len ||
13670 pat_len < wowlan->pattern_min_len)
13673 if (!pat_tb[NL80211_PKTPAT_OFFSET])
13676 pkt_offset = nla_get_u32(
13677 pat_tb[NL80211_PKTPAT_OFFSET]);
13678 if (pkt_offset > wowlan->max_pkt_offset)
13680 new_triggers.patterns[i].pkt_offset = pkt_offset;
13682 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
13687 new_triggers.patterns[i].mask = mask_pat;
13688 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
13690 mask_pat += mask_len;
13691 new_triggers.patterns[i].pattern = mask_pat;
13692 new_triggers.patterns[i].pattern_len = pat_len;
13694 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
13700 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
13702 err = nl80211_parse_wowlan_tcp(
13703 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
13709 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
13711 err = nl80211_parse_wowlan_nd(
13712 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
13718 /* The 'any' trigger means the device continues operating more or less
13719 * as in its normal operation mode and wakes up the host on most of the
13720 * normal interrupts (like packet RX, ...)
13721 * It therefore makes little sense to combine with the more constrained
13722 * wakeup trigger modes.
13724 if (new_triggers.any && regular) {
13729 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
13734 cfg80211_rdev_free_wowlan(rdev);
13735 rdev->wiphy.wowlan_config = ntrig;
13738 if (rdev->ops->set_wakeup &&
13739 prev_enabled != !!rdev->wiphy.wowlan_config)
13740 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
13744 for (i = 0; i < new_triggers.n_patterns; i++)
13745 kfree(new_triggers.patterns[i].mask);
13746 kfree(new_triggers.patterns);
13747 if (new_triggers.tcp && new_triggers.tcp->sock)
13748 sock_release(new_triggers.tcp->sock);
13749 kfree(new_triggers.tcp);
13750 kfree(new_triggers.nd_config);
13755 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
13756 struct cfg80211_registered_device *rdev)
13758 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
13760 struct cfg80211_coalesce_rules *rule;
13762 if (!rdev->coalesce->n_rules)
13765 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
13769 for (i = 0; i < rdev->coalesce->n_rules; i++) {
13770 nl_rule = nla_nest_start_noflag(msg, i + 1);
13774 rule = &rdev->coalesce->rules[i];
13775 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
13779 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
13783 nl_pats = nla_nest_start_noflag(msg,
13784 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
13788 for (j = 0; j < rule->n_patterns; j++) {
13789 nl_pat = nla_nest_start_noflag(msg, j + 1);
13792 pat_len = rule->patterns[j].pattern_len;
13793 if (nla_put(msg, NL80211_PKTPAT_MASK,
13794 DIV_ROUND_UP(pat_len, 8),
13795 rule->patterns[j].mask) ||
13796 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
13797 rule->patterns[j].pattern) ||
13798 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
13799 rule->patterns[j].pkt_offset))
13801 nla_nest_end(msg, nl_pat);
13803 nla_nest_end(msg, nl_pats);
13804 nla_nest_end(msg, nl_rule);
13806 nla_nest_end(msg, nl_rules);
13811 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
13813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13814 struct sk_buff *msg;
13817 if (!rdev->wiphy.coalesce)
13818 return -EOPNOTSUPP;
13820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13824 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13825 NL80211_CMD_GET_COALESCE);
13827 goto nla_put_failure;
13829 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
13830 goto nla_put_failure;
13832 genlmsg_end(msg, hdr);
13833 return genlmsg_reply(msg, info);
13840 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
13842 struct cfg80211_coalesce *coalesce = rdev->coalesce;
13844 struct cfg80211_coalesce_rules *rule;
13849 for (i = 0; i < coalesce->n_rules; i++) {
13850 rule = &coalesce->rules[i];
13851 for (j = 0; j < rule->n_patterns; j++)
13852 kfree(rule->patterns[j].mask);
13853 kfree(rule->patterns);
13855 kfree(coalesce->rules);
13857 rdev->coalesce = NULL;
13860 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
13861 struct nlattr *rule,
13862 struct cfg80211_coalesce_rules *new_rule)
13865 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
13866 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
13867 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
13868 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
13870 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
13871 rule, nl80211_coalesce_policy, NULL);
13875 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
13877 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
13878 if (new_rule->delay > coalesce->max_delay)
13881 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
13882 new_rule->condition =
13883 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
13885 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
13888 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
13891 if (n_patterns > coalesce->n_patterns)
13894 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
13896 if (!new_rule->patterns)
13899 new_rule->n_patterns = n_patterns;
13902 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
13906 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
13908 nl80211_packet_pattern_policy,
13913 if (!pat_tb[NL80211_PKTPAT_MASK] ||
13914 !pat_tb[NL80211_PKTPAT_PATTERN])
13916 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
13917 mask_len = DIV_ROUND_UP(pat_len, 8);
13918 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
13920 if (pat_len > coalesce->pattern_max_len ||
13921 pat_len < coalesce->pattern_min_len)
13924 if (!pat_tb[NL80211_PKTPAT_OFFSET])
13927 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
13928 if (pkt_offset > coalesce->max_pkt_offset)
13930 new_rule->patterns[i].pkt_offset = pkt_offset;
13932 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
13936 new_rule->patterns[i].mask = mask_pat;
13937 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
13940 mask_pat += mask_len;
13941 new_rule->patterns[i].pattern = mask_pat;
13942 new_rule->patterns[i].pattern_len = pat_len;
13943 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
13951 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
13953 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13954 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
13955 struct cfg80211_coalesce new_coalesce = {};
13956 struct cfg80211_coalesce *n_coalesce;
13957 int err, rem_rule, n_rules = 0, i, j;
13958 struct nlattr *rule;
13959 struct cfg80211_coalesce_rules *tmp_rule;
13961 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
13962 return -EOPNOTSUPP;
13964 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
13965 cfg80211_rdev_free_coalesce(rdev);
13966 rdev_set_coalesce(rdev, NULL);
13970 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
13973 if (n_rules > coalesce->n_rules)
13976 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
13978 if (!new_coalesce.rules)
13981 new_coalesce.n_rules = n_rules;
13984 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
13986 err = nl80211_parse_coalesce_rule(rdev, rule,
13987 &new_coalesce.rules[i]);
13994 err = rdev_set_coalesce(rdev, &new_coalesce);
13998 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
14003 cfg80211_rdev_free_coalesce(rdev);
14004 rdev->coalesce = n_coalesce;
14008 for (i = 0; i < new_coalesce.n_rules; i++) {
14009 tmp_rule = &new_coalesce.rules[i];
14010 for (j = 0; j < tmp_rule->n_patterns; j++)
14011 kfree(tmp_rule->patterns[j].mask);
14012 kfree(tmp_rule->patterns);
14014 kfree(new_coalesce.rules);
14019 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
14021 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14022 struct net_device *dev = info->user_ptr[1];
14023 struct wireless_dev *wdev = dev->ieee80211_ptr;
14024 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
14025 struct cfg80211_gtk_rekey_data rekey_data = {};
14028 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
14031 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
14032 info->attrs[NL80211_ATTR_REKEY_DATA],
14033 nl80211_rekey_policy, info->extack);
14037 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
14038 !tb[NL80211_REKEY_DATA_KCK])
14040 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN &&
14041 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
14042 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN))
14044 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN &&
14045 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
14046 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN) &&
14047 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KCK_32 &&
14048 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN_32))
14051 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
14052 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
14053 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
14054 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
14055 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]);
14056 if (tb[NL80211_REKEY_DATA_AKM])
14057 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]);
14060 if (!wdev->connected) {
14065 if (!rdev->ops->set_rekey_data) {
14070 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
14076 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
14077 struct genl_info *info)
14079 struct net_device *dev = info->user_ptr[1];
14080 struct wireless_dev *wdev = dev->ieee80211_ptr;
14082 if (wdev->iftype != NL80211_IFTYPE_AP &&
14083 wdev->iftype != NL80211_IFTYPE_P2P_GO)
14086 if (wdev->ap_unexpected_nlportid)
14089 wdev->ap_unexpected_nlportid = info->snd_portid;
14093 static int nl80211_probe_client(struct sk_buff *skb,
14094 struct genl_info *info)
14096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14097 struct net_device *dev = info->user_ptr[1];
14098 struct wireless_dev *wdev = dev->ieee80211_ptr;
14099 struct sk_buff *msg;
14105 if (wdev->iftype != NL80211_IFTYPE_AP &&
14106 wdev->iftype != NL80211_IFTYPE_P2P_GO)
14107 return -EOPNOTSUPP;
14109 if (!info->attrs[NL80211_ATTR_MAC])
14112 if (!rdev->ops->probe_client)
14113 return -EOPNOTSUPP;
14115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14119 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14120 NL80211_CMD_PROBE_CLIENT);
14126 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
14128 err = rdev_probe_client(rdev, dev, addr, &cookie);
14132 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14134 goto nla_put_failure;
14136 genlmsg_end(msg, hdr);
14138 return genlmsg_reply(msg, info);
14147 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
14149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14150 struct cfg80211_beacon_registration *reg, *nreg;
14153 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
14154 return -EOPNOTSUPP;
14156 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
14160 /* First, check if already registered. */
14161 spin_lock_bh(&rdev->beacon_registrations_lock);
14162 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14163 if (reg->nlportid == info->snd_portid) {
14168 /* Add it to the list */
14169 nreg->nlportid = info->snd_portid;
14170 list_add(&nreg->list, &rdev->beacon_registrations);
14172 spin_unlock_bh(&rdev->beacon_registrations_lock);
14176 spin_unlock_bh(&rdev->beacon_registrations_lock);
14181 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
14183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14184 struct wireless_dev *wdev = info->user_ptr[1];
14187 if (!rdev->ops->start_p2p_device)
14188 return -EOPNOTSUPP;
14190 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
14191 return -EOPNOTSUPP;
14193 if (wdev_running(wdev))
14196 if (rfkill_blocked(rdev->wiphy.rfkill))
14199 err = rdev_start_p2p_device(rdev, wdev);
14203 wdev->is_running = true;
14209 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
14211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14212 struct wireless_dev *wdev = info->user_ptr[1];
14214 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
14215 return -EOPNOTSUPP;
14217 if (!rdev->ops->stop_p2p_device)
14218 return -EOPNOTSUPP;
14220 cfg80211_stop_p2p_device(rdev, wdev);
14225 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
14227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14228 struct wireless_dev *wdev = info->user_ptr[1];
14229 struct cfg80211_nan_conf conf = {};
14232 if (wdev->iftype != NL80211_IFTYPE_NAN)
14233 return -EOPNOTSUPP;
14235 if (wdev_running(wdev))
14238 if (rfkill_blocked(rdev->wiphy.rfkill))
14241 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
14245 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
14247 if (info->attrs[NL80211_ATTR_BANDS]) {
14248 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
14250 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
14251 return -EOPNOTSUPP;
14253 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
14256 conf.bands = bands;
14259 err = rdev_start_nan(rdev, wdev, &conf);
14263 wdev->is_running = true;
14269 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
14271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14272 struct wireless_dev *wdev = info->user_ptr[1];
14274 if (wdev->iftype != NL80211_IFTYPE_NAN)
14275 return -EOPNOTSUPP;
14277 cfg80211_stop_nan(rdev, wdev);
14282 static int validate_nan_filter(struct nlattr *filter_attr)
14284 struct nlattr *attr;
14285 int len = 0, n_entries = 0, rem;
14287 nla_for_each_nested(attr, filter_attr, rem) {
14288 len += nla_len(attr);
14298 static int handle_nan_filter(struct nlattr *attr_filter,
14299 struct cfg80211_nan_func *func,
14302 struct nlattr *attr;
14303 int n_entries, rem, i;
14304 struct cfg80211_nan_func_filter *filter;
14306 n_entries = validate_nan_filter(attr_filter);
14310 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
14312 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
14317 nla_for_each_nested(attr, attr_filter, rem) {
14318 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
14319 if (!filter[i].filter)
14322 filter[i].len = nla_len(attr);
14326 func->num_tx_filters = n_entries;
14327 func->tx_filters = filter;
14329 func->num_rx_filters = n_entries;
14330 func->rx_filters = filter;
14337 nla_for_each_nested(attr, attr_filter, rem) {
14338 kfree(filter[i].filter);
14345 static int nl80211_nan_add_func(struct sk_buff *skb,
14346 struct genl_info *info)
14348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14349 struct wireless_dev *wdev = info->user_ptr[1];
14350 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
14351 struct cfg80211_nan_func *func;
14352 struct sk_buff *msg = NULL;
14356 if (wdev->iftype != NL80211_IFTYPE_NAN)
14357 return -EOPNOTSUPP;
14359 if (!wdev_running(wdev))
14362 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
14365 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
14366 info->attrs[NL80211_ATTR_NAN_FUNC],
14367 nl80211_nan_func_policy,
14372 func = kzalloc(sizeof(*func), GFP_KERNEL);
14376 func->cookie = cfg80211_assign_cookie(rdev);
14378 if (!tb[NL80211_NAN_FUNC_TYPE]) {
14384 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
14386 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
14391 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
14392 sizeof(func->service_id));
14394 func->close_range =
14395 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
14397 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
14398 func->serv_spec_info_len =
14399 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
14400 func->serv_spec_info =
14401 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
14402 func->serv_spec_info_len,
14404 if (!func->serv_spec_info) {
14410 if (tb[NL80211_NAN_FUNC_TTL])
14411 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
14413 switch (func->type) {
14414 case NL80211_NAN_FUNC_PUBLISH:
14415 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
14420 func->publish_type =
14421 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
14422 func->publish_bcast =
14423 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
14425 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
14426 func->publish_bcast) {
14431 case NL80211_NAN_FUNC_SUBSCRIBE:
14432 func->subscribe_active =
14433 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
14435 case NL80211_NAN_FUNC_FOLLOW_UP:
14436 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
14437 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
14438 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
14443 func->followup_id =
14444 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
14445 func->followup_reqid =
14446 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
14447 memcpy(func->followup_dest.addr,
14448 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
14449 sizeof(func->followup_dest.addr));
14460 if (tb[NL80211_NAN_FUNC_SRF]) {
14461 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
14463 err = nla_parse_nested_deprecated(srf_tb,
14464 NL80211_NAN_SRF_ATTR_MAX,
14465 tb[NL80211_NAN_FUNC_SRF],
14466 nl80211_nan_srf_policy,
14471 func->srf_include =
14472 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
14474 if (srf_tb[NL80211_NAN_SRF_BF]) {
14475 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
14476 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
14482 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
14484 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
14485 func->srf_bf_len, GFP_KERNEL);
14486 if (!func->srf_bf) {
14492 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
14494 struct nlattr *attr, *mac_attr =
14495 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
14496 int n_entries, rem, i = 0;
14503 n_entries = validate_acl_mac_addrs(mac_attr);
14504 if (n_entries <= 0) {
14509 func->srf_num_macs = n_entries;
14511 kcalloc(n_entries, sizeof(*func->srf_macs),
14513 if (!func->srf_macs) {
14518 nla_for_each_nested(attr, mac_attr, rem)
14519 memcpy(func->srf_macs[i++].addr, nla_data(attr),
14520 sizeof(*func->srf_macs));
14524 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
14525 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
14531 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
14532 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
14538 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14544 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14545 NL80211_CMD_ADD_NAN_FUNCTION);
14546 /* This can't really happen - we just allocated 4KB */
14547 if (WARN_ON(!hdr)) {
14552 err = rdev_add_nan_func(rdev, wdev, func);
14555 cfg80211_free_nan_func(func);
14560 /* propagate the instance id and cookie to userspace */
14561 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
14563 goto nla_put_failure;
14565 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
14567 goto nla_put_failure;
14569 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
14570 func->instance_id))
14571 goto nla_put_failure;
14573 nla_nest_end(msg, func_attr);
14575 genlmsg_end(msg, hdr);
14576 return genlmsg_reply(msg, info);
14583 static int nl80211_nan_del_func(struct sk_buff *skb,
14584 struct genl_info *info)
14586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14587 struct wireless_dev *wdev = info->user_ptr[1];
14590 if (wdev->iftype != NL80211_IFTYPE_NAN)
14591 return -EOPNOTSUPP;
14593 if (!wdev_running(wdev))
14596 if (!info->attrs[NL80211_ATTR_COOKIE])
14599 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
14601 rdev_del_nan_func(rdev, wdev, cookie);
14606 static int nl80211_nan_change_config(struct sk_buff *skb,
14607 struct genl_info *info)
14609 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14610 struct wireless_dev *wdev = info->user_ptr[1];
14611 struct cfg80211_nan_conf conf = {};
14614 if (wdev->iftype != NL80211_IFTYPE_NAN)
14615 return -EOPNOTSUPP;
14617 if (!wdev_running(wdev))
14620 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
14622 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
14623 if (conf.master_pref <= 1 || conf.master_pref == 255)
14626 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
14629 if (info->attrs[NL80211_ATTR_BANDS]) {
14630 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
14632 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
14633 return -EOPNOTSUPP;
14635 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
14638 conf.bands = bands;
14639 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
14645 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
14648 void cfg80211_nan_match(struct wireless_dev *wdev,
14649 struct cfg80211_nan_match_params *match, gfp_t gfp)
14651 struct wiphy *wiphy = wdev->wiphy;
14652 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14653 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
14654 struct sk_buff *msg;
14657 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
14660 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14664 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
14670 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14671 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14672 wdev->netdev->ifindex)) ||
14673 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14675 goto nla_put_failure;
14677 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
14678 NL80211_ATTR_PAD) ||
14679 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
14680 goto nla_put_failure;
14682 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
14684 goto nla_put_failure;
14686 local_func_attr = nla_nest_start_noflag(msg,
14687 NL80211_NAN_MATCH_FUNC_LOCAL);
14688 if (!local_func_attr)
14689 goto nla_put_failure;
14691 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
14692 goto nla_put_failure;
14694 nla_nest_end(msg, local_func_attr);
14696 peer_func_attr = nla_nest_start_noflag(msg,
14697 NL80211_NAN_MATCH_FUNC_PEER);
14698 if (!peer_func_attr)
14699 goto nla_put_failure;
14701 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
14702 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
14703 goto nla_put_failure;
14705 if (match->info && match->info_len &&
14706 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
14708 goto nla_put_failure;
14710 nla_nest_end(msg, peer_func_attr);
14711 nla_nest_end(msg, match_attr);
14712 genlmsg_end(msg, hdr);
14714 if (!wdev->owner_nlportid)
14715 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
14716 msg, 0, NL80211_MCGRP_NAN, gfp);
14718 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
14719 wdev->owner_nlportid);
14726 EXPORT_SYMBOL(cfg80211_nan_match);
14728 void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
14730 enum nl80211_nan_func_term_reason reason,
14731 u64 cookie, gfp_t gfp)
14733 struct wiphy *wiphy = wdev->wiphy;
14734 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14735 struct sk_buff *msg;
14736 struct nlattr *func_attr;
14739 if (WARN_ON(!inst_id))
14742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14746 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
14752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14753 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14754 wdev->netdev->ifindex)) ||
14755 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14757 goto nla_put_failure;
14759 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14761 goto nla_put_failure;
14763 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
14765 goto nla_put_failure;
14767 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
14768 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
14769 goto nla_put_failure;
14771 nla_nest_end(msg, func_attr);
14772 genlmsg_end(msg, hdr);
14774 if (!wdev->owner_nlportid)
14775 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
14776 msg, 0, NL80211_MCGRP_NAN, gfp);
14778 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
14779 wdev->owner_nlportid);
14786 EXPORT_SYMBOL(cfg80211_nan_func_terminated);
14788 static int nl80211_get_protocol_features(struct sk_buff *skb,
14789 struct genl_info *info)
14792 struct sk_buff *msg;
14794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14798 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14799 NL80211_CMD_GET_PROTOCOL_FEATURES);
14801 goto nla_put_failure;
14803 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
14804 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
14805 goto nla_put_failure;
14807 genlmsg_end(msg, hdr);
14808 return genlmsg_reply(msg, info);
14815 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
14817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14818 struct cfg80211_update_ft_ies_params ft_params;
14819 struct net_device *dev = info->user_ptr[1];
14821 if (!rdev->ops->update_ft_ies)
14822 return -EOPNOTSUPP;
14824 if (!info->attrs[NL80211_ATTR_MDID] ||
14825 !info->attrs[NL80211_ATTR_IE])
14828 memset(&ft_params, 0, sizeof(ft_params));
14829 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
14830 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
14831 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
14833 return rdev_update_ft_ies(rdev, dev, &ft_params);
14836 static int nl80211_crit_protocol_start(struct sk_buff *skb,
14837 struct genl_info *info)
14839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14840 struct wireless_dev *wdev = info->user_ptr[1];
14841 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
14845 if (!rdev->ops->crit_proto_start)
14846 return -EOPNOTSUPP;
14848 if (WARN_ON(!rdev->ops->crit_proto_stop))
14851 if (rdev->crit_proto_nlportid)
14854 /* determine protocol if provided */
14855 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
14856 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
14858 if (proto >= NUM_NL80211_CRIT_PROTO)
14861 /* timeout must be provided */
14862 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
14866 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
14868 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
14870 rdev->crit_proto_nlportid = info->snd_portid;
14875 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
14876 struct genl_info *info)
14878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14879 struct wireless_dev *wdev = info->user_ptr[1];
14881 if (!rdev->ops->crit_proto_stop)
14882 return -EOPNOTSUPP;
14884 if (rdev->crit_proto_nlportid) {
14885 rdev->crit_proto_nlportid = 0;
14886 rdev_crit_proto_stop(rdev, wdev);
14891 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
14892 struct nlattr *attr,
14893 struct netlink_ext_ack *extack)
14895 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
14896 if (attr->nla_type & NLA_F_NESTED) {
14897 NL_SET_ERR_MSG_ATTR(extack, attr,
14898 "unexpected nested data");
14905 if (!(attr->nla_type & NLA_F_NESTED)) {
14906 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
14910 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
14913 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
14915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14916 struct wireless_dev *wdev =
14917 __cfg80211_wdev_from_attrs(rdev, genl_info_net(info),
14922 if (!rdev->wiphy.vendor_commands)
14923 return -EOPNOTSUPP;
14925 if (IS_ERR(wdev)) {
14926 err = PTR_ERR(wdev);
14927 if (err != -EINVAL)
14930 } else if (wdev->wiphy != &rdev->wiphy) {
14934 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
14935 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
14938 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
14939 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
14940 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
14941 const struct wiphy_vendor_command *vcmd;
14945 vcmd = &rdev->wiphy.vendor_commands[i];
14947 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
14950 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
14951 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
14954 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
14958 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
14959 if (!wdev_running(wdev))
14967 return -EOPNOTSUPP;
14969 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
14970 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
14971 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
14973 err = nl80211_vendor_check_policy(vcmd,
14974 info->attrs[NL80211_ATTR_VENDOR_DATA],
14980 rdev->cur_cmd_info = info;
14981 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
14982 rdev->cur_cmd_info = NULL;
14986 return -EOPNOTSUPP;
14989 static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
14990 struct netlink_callback *cb,
14991 struct cfg80211_registered_device **rdev,
14992 struct wireless_dev **wdev)
14994 struct nlattr **attrbuf;
15000 unsigned int data_len = 0;
15003 /* subtract the 1 again here */
15004 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
15005 struct wireless_dev *tmp;
15009 *rdev = wiphy_to_rdev(wiphy);
15013 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
15014 if (tmp->identifier == cb->args[1] - 1) {
15021 /* keep rtnl locked in successful case */
15025 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
15029 err = nlmsg_parse_deprecated(cb->nlh,
15030 GENL_HDRLEN + nl80211_fam.hdrsize,
15031 attrbuf, nl80211_fam.maxattr,
15032 nl80211_policy, NULL);
15036 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
15037 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
15042 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf);
15046 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
15047 if (IS_ERR(*rdev)) {
15048 err = PTR_ERR(*rdev);
15052 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
15053 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
15055 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
15056 const struct wiphy_vendor_command *vcmd;
15058 vcmd = &(*rdev)->wiphy.vendor_commands[i];
15060 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
15063 if (!vcmd->dumpit) {
15072 if (vcmd_idx < 0) {
15077 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
15078 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
15079 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
15081 err = nl80211_vendor_check_policy(
15082 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
15083 attrbuf[NL80211_ATTR_VENDOR_DATA],
15089 /* 0 is the first index - add 1 to parse only once */
15090 cb->args[0] = (*rdev)->wiphy_idx + 1;
15091 /* add 1 to know if it was NULL */
15092 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
15093 cb->args[2] = vcmd_idx;
15094 cb->args[3] = (unsigned long)data;
15095 cb->args[4] = data_len;
15097 /* keep rtnl locked in successful case */
15104 static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
15105 struct netlink_callback *cb)
15107 struct cfg80211_registered_device *rdev;
15108 struct wireless_dev *wdev;
15109 unsigned int vcmd_idx;
15110 const struct wiphy_vendor_command *vcmd;
15114 struct nlattr *vendor_data;
15117 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
15121 vcmd_idx = cb->args[2];
15122 data = (void *)cb->args[3];
15123 data_len = cb->args[4];
15124 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
15126 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
15127 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
15132 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
15138 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
15139 if (!wdev_running(wdev)) {
15147 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
15148 cb->nlh->nlmsg_seq, NLM_F_MULTI,
15149 NL80211_CMD_VENDOR);
15153 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15154 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
15156 NL80211_ATTR_PAD))) {
15157 genlmsg_cancel(skb, hdr);
15161 vendor_data = nla_nest_start_noflag(skb,
15162 NL80211_ATTR_VENDOR_DATA);
15163 if (!vendor_data) {
15164 genlmsg_cancel(skb, hdr);
15168 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
15169 (unsigned long *)&cb->args[5]);
15170 nla_nest_end(skb, vendor_data);
15172 if (err == -ENOBUFS || err == -ENOENT) {
15173 genlmsg_cancel(skb, hdr);
15175 } else if (err <= 0) {
15176 genlmsg_cancel(skb, hdr);
15180 genlmsg_end(skb, hdr);
15189 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
15190 enum nl80211_commands cmd,
15191 enum nl80211_attrs attr,
15194 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15196 if (WARN_ON(!rdev->cur_cmd_info))
15199 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
15200 rdev->cur_cmd_info->snd_portid,
15201 rdev->cur_cmd_info->snd_seq,
15202 cmd, attr, NULL, GFP_KERNEL);
15204 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
15206 int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
15208 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
15209 void *hdr = ((void **)skb->cb)[1];
15210 struct nlattr *data = ((void **)skb->cb)[2];
15212 /* clear CB data for netlink core to own from now on */
15213 memset(skb->cb, 0, sizeof(skb->cb));
15215 if (WARN_ON(!rdev->cur_cmd_info)) {
15220 nla_nest_end(skb, data);
15221 genlmsg_end(skb, hdr);
15222 return genlmsg_reply(skb, rdev->cur_cmd_info);
15224 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
15226 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
15228 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15230 if (WARN_ON(!rdev->cur_cmd_info))
15233 return rdev->cur_cmd_info->snd_portid;
15235 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
15237 static int nl80211_set_qos_map(struct sk_buff *skb,
15238 struct genl_info *info)
15240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15241 struct cfg80211_qos_map *qos_map = NULL;
15242 struct net_device *dev = info->user_ptr[1];
15243 u8 *pos, len, num_des, des_len, des;
15246 if (!rdev->ops->set_qos_map)
15247 return -EOPNOTSUPP;
15249 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
15250 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
15251 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
15256 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
15260 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
15262 des_len = num_des *
15263 sizeof(struct cfg80211_dscp_exception);
15264 memcpy(qos_map->dscp_exception, pos, des_len);
15265 qos_map->num_des = num_des;
15266 for (des = 0; des < num_des; des++) {
15267 if (qos_map->dscp_exception[des].up > 7) {
15274 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
15277 wdev_lock(dev->ieee80211_ptr);
15278 ret = nl80211_key_allowed(dev->ieee80211_ptr);
15280 ret = rdev_set_qos_map(rdev, dev, qos_map);
15281 wdev_unlock(dev->ieee80211_ptr);
15287 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
15289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15290 struct net_device *dev = info->user_ptr[1];
15291 struct wireless_dev *wdev = dev->ieee80211_ptr;
15294 u16 admitted_time = 0;
15297 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
15298 return -EOPNOTSUPP;
15300 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
15301 !info->attrs[NL80211_ATTR_USER_PRIO])
15304 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
15305 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
15307 /* WMM uses TIDs 0-7 even for TSPEC */
15308 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
15309 /* TODO: handle 802.11 TSPEC/admission control
15310 * need more attributes for that (e.g. BA session requirement);
15311 * change the WMM adminssion test above to allow both then
15316 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15318 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
15320 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
15321 if (!admitted_time)
15326 switch (wdev->iftype) {
15327 case NL80211_IFTYPE_STATION:
15328 case NL80211_IFTYPE_P2P_CLIENT:
15329 if (wdev->connected)
15338 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
15345 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
15347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15348 struct net_device *dev = info->user_ptr[1];
15349 struct wireless_dev *wdev = dev->ieee80211_ptr;
15354 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
15357 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
15358 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15361 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
15367 static int nl80211_tdls_channel_switch(struct sk_buff *skb,
15368 struct genl_info *info)
15370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15371 struct net_device *dev = info->user_ptr[1];
15372 struct wireless_dev *wdev = dev->ieee80211_ptr;
15373 struct cfg80211_chan_def chandef = {};
15378 if (!rdev->ops->tdls_channel_switch ||
15379 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
15380 return -EOPNOTSUPP;
15382 switch (dev->ieee80211_ptr->iftype) {
15383 case NL80211_IFTYPE_STATION:
15384 case NL80211_IFTYPE_P2P_CLIENT:
15387 return -EOPNOTSUPP;
15390 if (!info->attrs[NL80211_ATTR_MAC] ||
15391 !info->attrs[NL80211_ATTR_OPER_CLASS])
15394 err = nl80211_parse_chandef(rdev, info, &chandef);
15399 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
15400 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
15401 * specification is not defined for them.
15403 if (chandef.chan->band == NL80211_BAND_2GHZ &&
15404 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
15405 chandef.width != NL80211_CHAN_WIDTH_20)
15408 /* we will be active on the TDLS link */
15409 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
15413 /* don't allow switching to DFS channels */
15414 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
15417 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
15418 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
15421 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
15427 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
15428 struct genl_info *info)
15430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15431 struct net_device *dev = info->user_ptr[1];
15432 struct wireless_dev *wdev = dev->ieee80211_ptr;
15435 if (!rdev->ops->tdls_channel_switch ||
15436 !rdev->ops->tdls_cancel_channel_switch ||
15437 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
15438 return -EOPNOTSUPP;
15440 switch (dev->ieee80211_ptr->iftype) {
15441 case NL80211_IFTYPE_STATION:
15442 case NL80211_IFTYPE_P2P_CLIENT:
15445 return -EOPNOTSUPP;
15448 if (!info->attrs[NL80211_ATTR_MAC])
15451 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
15454 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
15460 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
15461 struct genl_info *info)
15463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15464 struct net_device *dev = info->user_ptr[1];
15465 struct wireless_dev *wdev = dev->ieee80211_ptr;
15466 const struct nlattr *nla;
15469 if (!rdev->ops->set_multicast_to_unicast)
15470 return -EOPNOTSUPP;
15472 if (wdev->iftype != NL80211_IFTYPE_AP &&
15473 wdev->iftype != NL80211_IFTYPE_P2P_GO)
15474 return -EOPNOTSUPP;
15476 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
15477 enabled = nla_get_flag(nla);
15479 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
15482 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
15484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15485 struct net_device *dev = info->user_ptr[1];
15486 struct wireless_dev *wdev = dev->ieee80211_ptr;
15487 struct cfg80211_pmk_conf pmk_conf = {};
15490 if (wdev->iftype != NL80211_IFTYPE_STATION &&
15491 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
15492 return -EOPNOTSUPP;
15494 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15495 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
15496 return -EOPNOTSUPP;
15498 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
15502 if (!wdev->connected) {
15507 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
15508 if (memcmp(pmk_conf.aa, wdev->u.client.connected_addr, ETH_ALEN)) {
15513 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
15514 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
15515 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
15516 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
15521 if (info->attrs[NL80211_ATTR_PMKR0_NAME])
15522 pmk_conf.pmk_r0_name =
15523 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
15525 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
15531 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
15533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15534 struct net_device *dev = info->user_ptr[1];
15535 struct wireless_dev *wdev = dev->ieee80211_ptr;
15539 if (wdev->iftype != NL80211_IFTYPE_STATION &&
15540 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
15541 return -EOPNOTSUPP;
15543 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15544 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
15545 return -EOPNOTSUPP;
15547 if (!info->attrs[NL80211_ATTR_MAC])
15551 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
15552 ret = rdev_del_pmk(rdev, dev, aa);
15558 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
15560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15561 struct net_device *dev = info->user_ptr[1];
15562 struct cfg80211_external_auth_params params;
15564 if (!rdev->ops->external_auth)
15565 return -EOPNOTSUPP;
15567 if (!info->attrs[NL80211_ATTR_SSID] &&
15568 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
15569 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
15572 if (!info->attrs[NL80211_ATTR_BSSID])
15575 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
15578 memset(¶ms, 0, sizeof(params));
15580 if (info->attrs[NL80211_ATTR_SSID]) {
15581 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
15582 if (params.ssid.ssid_len == 0)
15584 memcpy(params.ssid.ssid,
15585 nla_data(info->attrs[NL80211_ATTR_SSID]),
15586 params.ssid.ssid_len);
15589 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
15592 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
15594 if (info->attrs[NL80211_ATTR_PMKID])
15595 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
15597 return rdev_external_auth(rdev, dev, ¶ms);
15600 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
15602 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
15603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15604 struct net_device *dev = info->user_ptr[1];
15605 struct wireless_dev *wdev = dev->ieee80211_ptr;
15615 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15616 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
15617 return -EOPNOTSUPP;
15619 if (!rdev->ops->tx_control_port)
15620 return -EOPNOTSUPP;
15622 if (!info->attrs[NL80211_ATTR_FRAME] ||
15623 !info->attrs[NL80211_ATTR_MAC] ||
15624 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
15625 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
15631 switch (wdev->iftype) {
15632 case NL80211_IFTYPE_AP:
15633 case NL80211_IFTYPE_P2P_GO:
15634 case NL80211_IFTYPE_MESH_POINT:
15636 case NL80211_IFTYPE_ADHOC:
15637 if (wdev->u.ibss.current_bss)
15641 case NL80211_IFTYPE_STATION:
15642 case NL80211_IFTYPE_P2P_CLIENT:
15643 if (wdev->connected)
15654 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
15655 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
15656 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
15657 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
15659 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
15661 link_id = nl80211_link_id_or_invalid(info->attrs);
15663 err = rdev_tx_control_port(rdev, dev, buf, len,
15664 dest, cpu_to_be16(proto), noencrypt, link_id,
15665 dont_wait_for_ack ? NULL : &cookie);
15666 if (!err && !dont_wait_for_ack)
15667 nl_set_extack_cookie_u64(info->extack, cookie);
15674 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
15675 struct genl_info *info)
15677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15678 struct net_device *dev = info->user_ptr[1];
15679 struct wireless_dev *wdev = dev->ieee80211_ptr;
15680 struct cfg80211_ftm_responder_stats ftm_stats = {};
15681 unsigned int link_id = nl80211_link_id(info->attrs);
15682 struct sk_buff *msg;
15684 struct nlattr *ftm_stats_attr;
15687 if (wdev->iftype != NL80211_IFTYPE_AP ||
15688 !wdev->links[link_id].ap.beacon_interval)
15689 return -EOPNOTSUPP;
15691 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
15695 if (!ftm_stats.filled)
15698 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15702 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
15703 NL80211_CMD_GET_FTM_RESPONDER_STATS);
15705 goto nla_put_failure;
15707 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15708 goto nla_put_failure;
15710 ftm_stats_attr = nla_nest_start_noflag(msg,
15711 NL80211_ATTR_FTM_RESPONDER_STATS);
15712 if (!ftm_stats_attr)
15713 goto nla_put_failure;
15715 #define SET_FTM(field, name, type) \
15716 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
15717 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
15718 ftm_stats.field)) \
15719 goto nla_put_failure; } while (0)
15720 #define SET_FTM_U64(field, name) \
15721 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
15722 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
15723 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
15724 goto nla_put_failure; } while (0)
15726 SET_FTM(success_num, SUCCESS_NUM, u32);
15727 SET_FTM(partial_num, PARTIAL_NUM, u32);
15728 SET_FTM(failed_num, FAILED_NUM, u32);
15729 SET_FTM(asap_num, ASAP_NUM, u32);
15730 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
15731 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
15732 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
15733 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
15734 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
15737 nla_nest_end(msg, ftm_stats_attr);
15739 genlmsg_end(msg, hdr);
15740 return genlmsg_reply(msg, info);
15747 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
15749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15750 struct cfg80211_update_owe_info owe_info;
15751 struct net_device *dev = info->user_ptr[1];
15753 if (!rdev->ops->update_owe_info)
15754 return -EOPNOTSUPP;
15756 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
15757 !info->attrs[NL80211_ATTR_MAC])
15760 memset(&owe_info, 0, sizeof(owe_info));
15761 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
15762 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
15764 if (info->attrs[NL80211_ATTR_IE]) {
15765 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
15766 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
15769 return rdev_update_owe_info(rdev, dev, &owe_info);
15772 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
15774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15775 struct net_device *dev = info->user_ptr[1];
15776 struct wireless_dev *wdev = dev->ieee80211_ptr;
15777 struct station_info sinfo = {};
15783 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
15784 return -EOPNOTSUPP;
15786 if (!info->attrs[NL80211_ATTR_MAC] ||
15787 !info->attrs[NL80211_ATTR_FRAME]) {
15788 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
15792 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
15793 return -EOPNOTSUPP;
15795 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
15796 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
15797 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
15799 if (len < sizeof(struct ethhdr))
15802 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
15803 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
15806 err = rdev_get_station(rdev, dev, dest, &sinfo);
15810 cfg80211_sinfo_release_content(&sinfo);
15812 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
15815 static int parse_tid_conf(struct cfg80211_registered_device *rdev,
15816 struct nlattr *attrs[], struct net_device *dev,
15817 struct cfg80211_tid_cfg *tid_conf,
15818 struct genl_info *info, const u8 *peer,
15819 unsigned int link_id)
15821 struct netlink_ext_ack *extack = info->extack;
15825 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS])
15828 tid_conf->config_override =
15829 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]);
15830 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
15832 if (tid_conf->config_override) {
15833 if (rdev->ops->reset_tid_config) {
15834 err = rdev_reset_tid_config(rdev, dev, peer,
15843 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
15844 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
15846 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
15849 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) {
15850 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT);
15851 tid_conf->retry_short =
15852 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]);
15854 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count)
15858 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) {
15859 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
15860 tid_conf->retry_long =
15861 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]);
15863 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count)
15867 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) {
15868 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
15870 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]);
15873 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) {
15874 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
15876 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]);
15879 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) {
15880 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL);
15882 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]);
15885 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) {
15886 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr;
15888 tid_conf->txrate_type = nla_get_u8(attrs[idx]);
15890 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) {
15891 attr = NL80211_TID_CONFIG_ATTR_TX_RATE;
15892 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr,
15893 &tid_conf->txrate_mask, dev,
15898 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE);
15900 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
15904 mask = rdev->wiphy.tid_config_support.peer;
15906 mask = rdev->wiphy.tid_config_support.vif;
15908 if (tid_conf->mask & ~mask) {
15909 NL_SET_ERR_MSG(extack, "unsupported TID configuration");
15916 static int nl80211_set_tid_config(struct sk_buff *skb,
15917 struct genl_info *info)
15919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15920 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1];
15921 unsigned int link_id = nl80211_link_id(info->attrs);
15922 struct net_device *dev = info->user_ptr[1];
15923 struct cfg80211_tid_config *tid_config;
15924 struct nlattr *tid;
15925 int conf_idx = 0, rem_conf;
15929 if (!info->attrs[NL80211_ATTR_TID_CONFIG])
15932 if (!rdev->ops->set_tid_config)
15933 return -EOPNOTSUPP;
15935 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
15939 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf),
15944 tid_config->n_tid_conf = num_conf;
15946 if (info->attrs[NL80211_ATTR_MAC])
15947 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15949 wdev_lock(dev->ieee80211_ptr);
15951 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
15953 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX,
15959 ret = parse_tid_conf(rdev, attrs, dev,
15960 &tid_config->tid_conf[conf_idx],
15961 info, tid_config->peer, link_id);
15968 ret = rdev_set_tid_config(rdev, dev, tid_config);
15972 wdev_unlock(dev->ieee80211_ptr);
15976 static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)
15978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15979 struct cfg80211_color_change_settings params = {};
15980 struct net_device *dev = info->user_ptr[1];
15981 struct wireless_dev *wdev = dev->ieee80211_ptr;
15982 struct nlattr **tb;
15986 if (!rdev->ops->color_change)
15987 return -EOPNOTSUPP;
15989 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15990 NL80211_EXT_FEATURE_BSS_COLOR))
15991 return -EOPNOTSUPP;
15993 if (wdev->iftype != NL80211_IFTYPE_AP)
15994 return -EOPNOTSUPP;
15996 if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] ||
15997 !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] ||
15998 !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS])
16001 params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]);
16002 params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]);
16004 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next,
16009 tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL);
16013 err = nla_parse_nested(tb, NL80211_ATTR_MAX,
16014 info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS],
16015 nl80211_policy, info->extack);
16019 err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change,
16024 if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) {
16029 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) {
16034 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
16035 if (offset >= params.beacon_color_change.tail_len) {
16040 if (params.beacon_color_change.tail[offset] != params.count) {
16045 params.counter_offset_beacon = offset;
16047 if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
16048 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) !=
16054 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
16055 if (offset >= params.beacon_color_change.probe_resp_len) {
16060 if (params.beacon_color_change.probe_resp[offset] !=
16066 params.counter_offset_presp = offset;
16070 err = rdev_color_change(rdev, dev, ¶ms);
16074 kfree(params.beacon_next.mbssid_ies);
16075 kfree(params.beacon_color_change.mbssid_ies);
16076 kfree(params.beacon_next.rnr_ies);
16077 kfree(params.beacon_color_change.rnr_ies);
16082 static int nl80211_set_fils_aad(struct sk_buff *skb,
16083 struct genl_info *info)
16085 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16086 struct net_device *dev = info->user_ptr[1];
16087 struct cfg80211_fils_aad fils_aad = {};
16090 if (!info->attrs[NL80211_ATTR_MAC] ||
16091 !info->attrs[NL80211_ATTR_FILS_KEK] ||
16092 !info->attrs[NL80211_ATTR_FILS_NONCES])
16095 fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]);
16096 fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
16097 fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
16098 nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
16099 fils_aad.snonce = nonces;
16100 fils_aad.anonce = nonces + FILS_NONCE_LEN;
16102 return rdev_set_fils_aad(rdev, dev, &fils_aad);
16105 static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info)
16107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16108 unsigned int link_id = nl80211_link_id(info->attrs);
16109 struct net_device *dev = info->user_ptr[1];
16110 struct wireless_dev *wdev = dev->ieee80211_ptr;
16113 if (!(wdev->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
16116 switch (wdev->iftype) {
16117 case NL80211_IFTYPE_AP:
16123 if (!info->attrs[NL80211_ATTR_MAC] ||
16124 !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC])))
16128 wdev->valid_links |= BIT(link_id);
16129 ether_addr_copy(wdev->links[link_id].addr,
16130 nla_data(info->attrs[NL80211_ATTR_MAC]));
16132 ret = rdev_add_intf_link(rdev, wdev, link_id);
16134 wdev->valid_links &= ~BIT(link_id);
16135 eth_zero_addr(wdev->links[link_id].addr);
16142 static int nl80211_remove_link(struct sk_buff *skb, struct genl_info *info)
16144 unsigned int link_id = nl80211_link_id(info->attrs);
16145 struct net_device *dev = info->user_ptr[1];
16146 struct wireless_dev *wdev = dev->ieee80211_ptr;
16148 /* cannot remove if there's no link */
16149 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID])
16152 switch (wdev->iftype) {
16153 case NL80211_IFTYPE_AP:
16160 cfg80211_remove_link(wdev, link_id);
16167 nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info,
16170 struct link_station_parameters params = {};
16171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16172 struct net_device *dev = info->user_ptr[1];
16175 if ((add && !rdev->ops->add_link_station) ||
16176 (!add && !rdev->ops->mod_link_station))
16177 return -EOPNOTSUPP;
16179 if (add && !info->attrs[NL80211_ATTR_MAC])
16182 if (!info->attrs[NL80211_ATTR_MLD_ADDR])
16185 if (add && !info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
16188 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
16190 if (info->attrs[NL80211_ATTR_MAC]) {
16191 params.link_mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
16192 if (!is_valid_ether_addr(params.link_mac))
16196 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID])
16199 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]);
16201 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
16202 params.supported_rates =
16203 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
16204 params.supported_rates_len =
16205 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
16208 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
16210 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
16212 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
16214 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
16216 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
16218 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
16219 params.he_capa_len =
16220 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
16222 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
16224 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
16225 params.eht_capa_len =
16226 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
16228 if (!ieee80211_eht_capa_size_ok((const u8 *)params.he_capa,
16229 (const u8 *)params.eht_capa,
16230 params.eht_capa_len,
16236 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
16237 params.he_6ghz_capa =
16238 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
16240 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
16241 params.opmode_notif_used = true;
16242 params.opmode_notif =
16243 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
16246 err = nl80211_parse_sta_txpower_setting(info, ¶ms.txpwr,
16247 ¶ms.txpwr_set);
16251 wdev_lock(dev->ieee80211_ptr);
16253 err = rdev_add_link_station(rdev, dev, ¶ms);
16255 err = rdev_mod_link_station(rdev, dev, ¶ms);
16256 wdev_unlock(dev->ieee80211_ptr);
16262 nl80211_add_link_station(struct sk_buff *skb, struct genl_info *info)
16264 return nl80211_add_mod_link_station(skb, info, true);
16268 nl80211_modify_link_station(struct sk_buff *skb, struct genl_info *info)
16270 return nl80211_add_mod_link_station(skb, info, false);
16274 nl80211_remove_link_station(struct sk_buff *skb, struct genl_info *info)
16276 struct link_station_del_parameters params = {};
16277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16278 struct net_device *dev = info->user_ptr[1];
16281 if (!rdev->ops->del_link_station)
16282 return -EOPNOTSUPP;
16284 if (!info->attrs[NL80211_ATTR_MLD_ADDR] ||
16285 !info->attrs[NL80211_ATTR_MLO_LINK_ID])
16288 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
16289 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]);
16291 wdev_lock(dev->ieee80211_ptr);
16292 ret = rdev_del_link_station(rdev, dev, ¶ms);
16293 wdev_unlock(dev->ieee80211_ptr);
16298 static int nl80211_set_hw_timestamp(struct sk_buff *skb,
16299 struct genl_info *info)
16301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16302 struct net_device *dev = info->user_ptr[1];
16303 struct cfg80211_set_hw_timestamp hwts = {};
16305 if (!rdev->wiphy.hw_timestamp_max_peers)
16306 return -EOPNOTSUPP;
16308 if (!info->attrs[NL80211_ATTR_MAC] &&
16309 rdev->wiphy.hw_timestamp_max_peers != CFG80211_HW_TIMESTAMP_ALL_PEERS)
16310 return -EOPNOTSUPP;
16312 if (info->attrs[NL80211_ATTR_MAC])
16313 hwts.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]);
16316 nla_get_flag(info->attrs[NL80211_ATTR_HW_TIMESTAMP_ENABLED]);
16318 return rdev_set_hw_timestamp(rdev, dev, &hwts);
16321 #define NL80211_FLAG_NEED_WIPHY 0x01
16322 #define NL80211_FLAG_NEED_NETDEV 0x02
16323 #define NL80211_FLAG_NEED_RTNL 0x04
16324 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
16325 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
16326 NL80211_FLAG_CHECK_NETDEV_UP)
16327 #define NL80211_FLAG_NEED_WDEV 0x10
16328 /* If a netdev is associated, it must be UP, P2P must be started */
16329 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
16330 NL80211_FLAG_CHECK_NETDEV_UP)
16331 #define NL80211_FLAG_CLEAR_SKB 0x20
16332 #define NL80211_FLAG_NO_WIPHY_MTX 0x40
16333 #define NL80211_FLAG_MLO_VALID_LINK_ID 0x80
16334 #define NL80211_FLAG_MLO_UNSUPPORTED 0x100
16336 #define INTERNAL_FLAG_SELECTORS(__sel) \
16337 SELECTOR(__sel, NONE, 0) /* must be first */ \
16338 SELECTOR(__sel, WIPHY, \
16339 NL80211_FLAG_NEED_WIPHY) \
16340 SELECTOR(__sel, WDEV, \
16341 NL80211_FLAG_NEED_WDEV) \
16342 SELECTOR(__sel, NETDEV, \
16343 NL80211_FLAG_NEED_NETDEV) \
16344 SELECTOR(__sel, NETDEV_LINK, \
16345 NL80211_FLAG_NEED_NETDEV | \
16346 NL80211_FLAG_MLO_VALID_LINK_ID) \
16347 SELECTOR(__sel, NETDEV_NO_MLO, \
16348 NL80211_FLAG_NEED_NETDEV | \
16349 NL80211_FLAG_MLO_UNSUPPORTED) \
16350 SELECTOR(__sel, WIPHY_RTNL, \
16351 NL80211_FLAG_NEED_WIPHY | \
16352 NL80211_FLAG_NEED_RTNL) \
16353 SELECTOR(__sel, WIPHY_RTNL_NOMTX, \
16354 NL80211_FLAG_NEED_WIPHY | \
16355 NL80211_FLAG_NEED_RTNL | \
16356 NL80211_FLAG_NO_WIPHY_MTX) \
16357 SELECTOR(__sel, WDEV_RTNL, \
16358 NL80211_FLAG_NEED_WDEV | \
16359 NL80211_FLAG_NEED_RTNL) \
16360 SELECTOR(__sel, NETDEV_RTNL, \
16361 NL80211_FLAG_NEED_NETDEV | \
16362 NL80211_FLAG_NEED_RTNL) \
16363 SELECTOR(__sel, NETDEV_UP, \
16364 NL80211_FLAG_NEED_NETDEV_UP) \
16365 SELECTOR(__sel, NETDEV_UP_LINK, \
16366 NL80211_FLAG_NEED_NETDEV_UP | \
16367 NL80211_FLAG_MLO_VALID_LINK_ID) \
16368 SELECTOR(__sel, NETDEV_UP_NO_MLO, \
16369 NL80211_FLAG_NEED_NETDEV_UP | \
16370 NL80211_FLAG_MLO_UNSUPPORTED) \
16371 SELECTOR(__sel, NETDEV_UP_NO_MLO_CLEAR, \
16372 NL80211_FLAG_NEED_NETDEV_UP | \
16373 NL80211_FLAG_CLEAR_SKB | \
16374 NL80211_FLAG_MLO_UNSUPPORTED) \
16375 SELECTOR(__sel, NETDEV_UP_NOTMX, \
16376 NL80211_FLAG_NEED_NETDEV_UP | \
16377 NL80211_FLAG_NO_WIPHY_MTX) \
16378 SELECTOR(__sel, NETDEV_UP_NOTMX_NOMLO, \
16379 NL80211_FLAG_NEED_NETDEV_UP | \
16380 NL80211_FLAG_NO_WIPHY_MTX | \
16381 NL80211_FLAG_MLO_UNSUPPORTED) \
16382 SELECTOR(__sel, NETDEV_UP_CLEAR, \
16383 NL80211_FLAG_NEED_NETDEV_UP | \
16384 NL80211_FLAG_CLEAR_SKB) \
16385 SELECTOR(__sel, WDEV_UP, \
16386 NL80211_FLAG_NEED_WDEV_UP) \
16387 SELECTOR(__sel, WDEV_UP_LINK, \
16388 NL80211_FLAG_NEED_WDEV_UP | \
16389 NL80211_FLAG_MLO_VALID_LINK_ID) \
16390 SELECTOR(__sel, WDEV_UP_RTNL, \
16391 NL80211_FLAG_NEED_WDEV_UP | \
16392 NL80211_FLAG_NEED_RTNL) \
16393 SELECTOR(__sel, WIPHY_CLEAR, \
16394 NL80211_FLAG_NEED_WIPHY | \
16395 NL80211_FLAG_CLEAR_SKB)
16397 enum nl80211_internal_flags_selector {
16398 #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name,
16399 INTERNAL_FLAG_SELECTORS(_)
16403 static u32 nl80211_internal_flags[] = {
16404 #define SELECTOR(_, name, value) [NL80211_IFL_SEL_##name] = value,
16405 INTERNAL_FLAG_SELECTORS(_)
16409 static int nl80211_pre_doit(const struct genl_split_ops *ops,
16410 struct sk_buff *skb,
16411 struct genl_info *info)
16413 struct cfg80211_registered_device *rdev = NULL;
16414 struct wireless_dev *wdev = NULL;
16415 struct net_device *dev = NULL;
16416 u32 internal_flags;
16419 if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags)))
16422 internal_flags = nl80211_internal_flags[ops->internal_flags];
16425 if (internal_flags & NL80211_FLAG_NEED_WIPHY) {
16426 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
16427 if (IS_ERR(rdev)) {
16428 err = PTR_ERR(rdev);
16431 info->user_ptr[0] = rdev;
16432 } else if (internal_flags & NL80211_FLAG_NEED_NETDEV ||
16433 internal_flags & NL80211_FLAG_NEED_WDEV) {
16434 wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info),
16436 if (IS_ERR(wdev)) {
16437 err = PTR_ERR(wdev);
16441 dev = wdev->netdev;
16443 rdev = wiphy_to_rdev(wdev->wiphy);
16445 if (internal_flags & NL80211_FLAG_NEED_NETDEV) {
16451 info->user_ptr[1] = dev;
16453 info->user_ptr[1] = wdev;
16456 if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
16457 !wdev_running(wdev)) {
16462 info->user_ptr[0] = rdev;
16465 if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) {
16466 struct nlattr *link_id = info->attrs[NL80211_ATTR_MLO_LINK_ID];
16473 /* MLO -> require valid link ID */
16474 if (wdev->valid_links &&
16476 !(wdev->valid_links & BIT(nla_get_u8(link_id))))) {
16481 /* non-MLO -> no link ID attribute accepted */
16482 if (!wdev->valid_links && link_id) {
16488 if (internal_flags & NL80211_FLAG_MLO_UNSUPPORTED) {
16489 if (info->attrs[NL80211_ATTR_MLO_LINK_ID] ||
16490 (wdev && wdev->valid_links)) {
16496 if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) {
16497 wiphy_lock(&rdev->wiphy);
16498 /* we keep the mutex locked until post_doit */
16499 __release(&rdev->wiphy.mtx);
16501 if (!(internal_flags & NL80211_FLAG_NEED_RTNL))
16511 static void nl80211_post_doit(const struct genl_split_ops *ops,
16512 struct sk_buff *skb,
16513 struct genl_info *info)
16515 u32 internal_flags = nl80211_internal_flags[ops->internal_flags];
16517 if (info->user_ptr[1]) {
16518 if (internal_flags & NL80211_FLAG_NEED_WDEV) {
16519 struct wireless_dev *wdev = info->user_ptr[1];
16521 dev_put(wdev->netdev);
16523 dev_put(info->user_ptr[1]);
16527 if (info->user_ptr[0] &&
16528 !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) {
16529 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16531 /* we kept the mutex locked since pre_doit */
16532 __acquire(&rdev->wiphy.mtx);
16533 wiphy_unlock(&rdev->wiphy);
16536 if (internal_flags & NL80211_FLAG_NEED_RTNL)
16539 /* If needed, clear the netlink message payload from the SKB
16540 * as it might contain key data that shouldn't stick around on
16541 * the heap after the SKB is freed. The netlink message header
16542 * is still needed for further processing, so leave it intact.
16544 if (internal_flags & NL80211_FLAG_CLEAR_SKB) {
16545 struct nlmsghdr *nlh = nlmsg_hdr(skb);
16547 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
16551 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev,
16552 struct cfg80211_sar_specs *sar_specs,
16553 struct nlattr *spec[], int index)
16555 u32 range_index, i;
16557 if (!sar_specs || !spec)
16560 if (!spec[NL80211_SAR_ATTR_SPECS_POWER] ||
16561 !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX])
16564 range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]);
16566 /* check if range_index exceeds num_freq_ranges */
16567 if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges)
16570 /* check if range_index duplicates */
16571 for (i = 0; i < index; i++) {
16572 if (sar_specs->sub_specs[i].freq_range_index == range_index)
16576 sar_specs->sub_specs[index].power =
16577 nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]);
16579 sar_specs->sub_specs[index].freq_range_index = range_index;
16584 static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info)
16586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16587 struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1];
16588 struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1];
16589 struct cfg80211_sar_specs *sar_spec;
16590 enum nl80211_sar_type type;
16591 struct nlattr *spec_list;
16595 if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs)
16596 return -EOPNOTSUPP;
16598 if (!info->attrs[NL80211_ATTR_SAR_SPEC])
16601 nla_parse_nested(tb, NL80211_SAR_ATTR_MAX,
16602 info->attrs[NL80211_ATTR_SAR_SPEC],
16605 if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS])
16608 type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]);
16609 if (type != rdev->wiphy.sar_capa->type)
16613 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem)
16616 if (specs > rdev->wiphy.sar_capa->num_freq_ranges)
16619 sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL);
16623 sar_spec->type = type;
16625 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) {
16626 nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX,
16627 spec_list, NULL, NULL);
16630 case NL80211_SAR_TYPE_POWER:
16631 if (nl80211_set_sar_sub_specs(rdev, sar_spec,
16644 sar_spec->num_sub_specs = specs;
16646 rdev->cur_cmd_info = info;
16647 err = rdev_set_sar_specs(rdev, sar_spec);
16648 rdev->cur_cmd_info = NULL;
16654 #define SELECTOR(__sel, name, value) \
16655 ((__sel) == (value)) ? NL80211_IFL_SEL_##name :
16656 int __missing_selector(void);
16657 #define IFLAGS(__val) INTERNAL_FLAG_SELECTORS(__val) __missing_selector()
16659 static const struct genl_ops nl80211_ops[] = {
16661 .cmd = NL80211_CMD_GET_WIPHY,
16662 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16663 .doit = nl80211_get_wiphy,
16664 .dumpit = nl80211_dump_wiphy,
16665 .done = nl80211_dump_wiphy_done,
16666 /* can be retrieved by unprivileged users */
16667 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16671 static const struct genl_small_ops nl80211_small_ops[] = {
16673 .cmd = NL80211_CMD_SET_WIPHY,
16674 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16675 .doit = nl80211_set_wiphy,
16676 .flags = GENL_UNS_ADMIN_PERM,
16679 .cmd = NL80211_CMD_GET_INTERFACE,
16680 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16681 .doit = nl80211_get_interface,
16682 .dumpit = nl80211_dump_interface,
16683 /* can be retrieved by unprivileged users */
16684 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV),
16687 .cmd = NL80211_CMD_SET_INTERFACE,
16688 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16689 .doit = nl80211_set_interface,
16690 .flags = GENL_UNS_ADMIN_PERM,
16691 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
16692 NL80211_FLAG_NEED_RTNL),
16695 .cmd = NL80211_CMD_NEW_INTERFACE,
16696 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16697 .doit = nl80211_new_interface,
16698 .flags = GENL_UNS_ADMIN_PERM,
16700 IFLAGS(NL80211_FLAG_NEED_WIPHY |
16701 NL80211_FLAG_NEED_RTNL |
16702 /* we take the wiphy mutex later ourselves */
16703 NL80211_FLAG_NO_WIPHY_MTX),
16706 .cmd = NL80211_CMD_DEL_INTERFACE,
16707 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16708 .doit = nl80211_del_interface,
16709 .flags = GENL_UNS_ADMIN_PERM,
16710 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
16711 NL80211_FLAG_NEED_RTNL),
16714 .cmd = NL80211_CMD_GET_KEY,
16715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16716 .doit = nl80211_get_key,
16717 .flags = GENL_UNS_ADMIN_PERM,
16718 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16721 .cmd = NL80211_CMD_SET_KEY,
16722 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16723 .doit = nl80211_set_key,
16724 .flags = GENL_UNS_ADMIN_PERM,
16725 /* cannot use NL80211_FLAG_MLO_VALID_LINK_ID, depends on key */
16726 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16727 NL80211_FLAG_CLEAR_SKB),
16730 .cmd = NL80211_CMD_NEW_KEY,
16731 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16732 .doit = nl80211_new_key,
16733 .flags = GENL_UNS_ADMIN_PERM,
16734 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16735 NL80211_FLAG_CLEAR_SKB),
16738 .cmd = NL80211_CMD_DEL_KEY,
16739 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16740 .doit = nl80211_del_key,
16741 .flags = GENL_UNS_ADMIN_PERM,
16742 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16745 .cmd = NL80211_CMD_SET_BEACON,
16746 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16747 .flags = GENL_UNS_ADMIN_PERM,
16748 .doit = nl80211_set_beacon,
16749 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16750 NL80211_FLAG_MLO_VALID_LINK_ID),
16753 .cmd = NL80211_CMD_START_AP,
16754 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16755 .flags = GENL_UNS_ADMIN_PERM,
16756 .doit = nl80211_start_ap,
16757 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16758 NL80211_FLAG_MLO_VALID_LINK_ID),
16761 .cmd = NL80211_CMD_STOP_AP,
16762 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16763 .flags = GENL_UNS_ADMIN_PERM,
16764 .doit = nl80211_stop_ap,
16765 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16766 NL80211_FLAG_MLO_VALID_LINK_ID),
16769 .cmd = NL80211_CMD_GET_STATION,
16770 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16771 .doit = nl80211_get_station,
16772 .dumpit = nl80211_dump_station,
16773 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16776 .cmd = NL80211_CMD_SET_STATION,
16777 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16778 .doit = nl80211_set_station,
16779 .flags = GENL_UNS_ADMIN_PERM,
16780 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16783 .cmd = NL80211_CMD_NEW_STATION,
16784 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16785 .doit = nl80211_new_station,
16786 .flags = GENL_UNS_ADMIN_PERM,
16787 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16790 .cmd = NL80211_CMD_DEL_STATION,
16791 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16792 .doit = nl80211_del_station,
16793 .flags = GENL_UNS_ADMIN_PERM,
16794 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16797 .cmd = NL80211_CMD_GET_MPATH,
16798 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16799 .doit = nl80211_get_mpath,
16800 .dumpit = nl80211_dump_mpath,
16801 .flags = GENL_UNS_ADMIN_PERM,
16802 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16805 .cmd = NL80211_CMD_GET_MPP,
16806 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16807 .doit = nl80211_get_mpp,
16808 .dumpit = nl80211_dump_mpp,
16809 .flags = GENL_UNS_ADMIN_PERM,
16810 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16813 .cmd = NL80211_CMD_SET_MPATH,
16814 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16815 .doit = nl80211_set_mpath,
16816 .flags = GENL_UNS_ADMIN_PERM,
16817 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16820 .cmd = NL80211_CMD_NEW_MPATH,
16821 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16822 .doit = nl80211_new_mpath,
16823 .flags = GENL_UNS_ADMIN_PERM,
16824 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16827 .cmd = NL80211_CMD_DEL_MPATH,
16828 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16829 .doit = nl80211_del_mpath,
16830 .flags = GENL_UNS_ADMIN_PERM,
16831 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16834 .cmd = NL80211_CMD_SET_BSS,
16835 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16836 .doit = nl80211_set_bss,
16837 .flags = GENL_UNS_ADMIN_PERM,
16838 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16839 NL80211_FLAG_MLO_VALID_LINK_ID),
16842 .cmd = NL80211_CMD_GET_REG,
16843 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16844 .doit = nl80211_get_reg_do,
16845 .dumpit = nl80211_get_reg_dump,
16846 /* can be retrieved by unprivileged users */
16848 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
16850 .cmd = NL80211_CMD_SET_REG,
16851 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16852 .doit = nl80211_set_reg,
16853 .flags = GENL_ADMIN_PERM,
16857 .cmd = NL80211_CMD_REQ_SET_REG,
16858 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16859 .doit = nl80211_req_set_reg,
16860 .flags = GENL_ADMIN_PERM,
16863 .cmd = NL80211_CMD_RELOAD_REGDB,
16864 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16865 .doit = nl80211_reload_regdb,
16866 .flags = GENL_ADMIN_PERM,
16869 .cmd = NL80211_CMD_GET_MESH_CONFIG,
16870 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16871 .doit = nl80211_get_mesh_config,
16872 /* can be retrieved by unprivileged users */
16873 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16876 .cmd = NL80211_CMD_SET_MESH_CONFIG,
16877 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16878 .doit = nl80211_update_mesh_config,
16879 .flags = GENL_UNS_ADMIN_PERM,
16880 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16883 .cmd = NL80211_CMD_TRIGGER_SCAN,
16884 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16885 .doit = nl80211_trigger_scan,
16886 .flags = GENL_UNS_ADMIN_PERM,
16887 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16890 .cmd = NL80211_CMD_ABORT_SCAN,
16891 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16892 .doit = nl80211_abort_scan,
16893 .flags = GENL_UNS_ADMIN_PERM,
16894 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16897 .cmd = NL80211_CMD_GET_SCAN,
16898 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16899 .dumpit = nl80211_dump_scan,
16902 .cmd = NL80211_CMD_START_SCHED_SCAN,
16903 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16904 .doit = nl80211_start_sched_scan,
16905 .flags = GENL_UNS_ADMIN_PERM,
16906 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16909 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
16910 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16911 .doit = nl80211_stop_sched_scan,
16912 .flags = GENL_UNS_ADMIN_PERM,
16913 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16916 .cmd = NL80211_CMD_AUTHENTICATE,
16917 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16918 .doit = nl80211_authenticate,
16919 .flags = GENL_UNS_ADMIN_PERM,
16920 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16921 NL80211_FLAG_CLEAR_SKB),
16924 .cmd = NL80211_CMD_ASSOCIATE,
16925 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16926 .doit = nl80211_associate,
16927 .flags = GENL_UNS_ADMIN_PERM,
16928 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16929 NL80211_FLAG_CLEAR_SKB),
16932 .cmd = NL80211_CMD_DEAUTHENTICATE,
16933 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16934 .doit = nl80211_deauthenticate,
16935 .flags = GENL_UNS_ADMIN_PERM,
16936 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16939 .cmd = NL80211_CMD_DISASSOCIATE,
16940 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16941 .doit = nl80211_disassociate,
16942 .flags = GENL_UNS_ADMIN_PERM,
16943 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16946 .cmd = NL80211_CMD_JOIN_IBSS,
16947 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16948 .doit = nl80211_join_ibss,
16949 .flags = GENL_UNS_ADMIN_PERM,
16950 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16953 .cmd = NL80211_CMD_LEAVE_IBSS,
16954 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16955 .doit = nl80211_leave_ibss,
16956 .flags = GENL_UNS_ADMIN_PERM,
16957 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16959 #ifdef CONFIG_NL80211_TESTMODE
16961 .cmd = NL80211_CMD_TESTMODE,
16962 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16963 .doit = nl80211_testmode_do,
16964 .dumpit = nl80211_testmode_dump,
16965 .flags = GENL_UNS_ADMIN_PERM,
16966 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16970 .cmd = NL80211_CMD_CONNECT,
16971 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16972 .doit = nl80211_connect,
16973 .flags = GENL_UNS_ADMIN_PERM,
16974 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16975 NL80211_FLAG_CLEAR_SKB),
16978 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
16979 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16980 .doit = nl80211_update_connect_params,
16981 .flags = GENL_ADMIN_PERM,
16982 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16983 NL80211_FLAG_CLEAR_SKB),
16986 .cmd = NL80211_CMD_DISCONNECT,
16987 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16988 .doit = nl80211_disconnect,
16989 .flags = GENL_UNS_ADMIN_PERM,
16990 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16993 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
16994 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16995 .doit = nl80211_wiphy_netns,
16996 .flags = GENL_UNS_ADMIN_PERM,
16997 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
16998 NL80211_FLAG_NEED_RTNL |
16999 NL80211_FLAG_NO_WIPHY_MTX),
17002 .cmd = NL80211_CMD_GET_SURVEY,
17003 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17004 .dumpit = nl80211_dump_survey,
17007 .cmd = NL80211_CMD_SET_PMKSA,
17008 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17009 .doit = nl80211_setdel_pmksa,
17010 .flags = GENL_UNS_ADMIN_PERM,
17011 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17012 NL80211_FLAG_CLEAR_SKB),
17015 .cmd = NL80211_CMD_DEL_PMKSA,
17016 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17017 .doit = nl80211_setdel_pmksa,
17018 .flags = GENL_UNS_ADMIN_PERM,
17019 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17022 .cmd = NL80211_CMD_FLUSH_PMKSA,
17023 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17024 .doit = nl80211_flush_pmksa,
17025 .flags = GENL_UNS_ADMIN_PERM,
17026 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17029 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
17030 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17031 .doit = nl80211_remain_on_channel,
17032 .flags = GENL_UNS_ADMIN_PERM,
17033 /* FIXME: requiring a link ID here is probably not good */
17034 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
17035 NL80211_FLAG_MLO_VALID_LINK_ID),
17038 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
17039 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17040 .doit = nl80211_cancel_remain_on_channel,
17041 .flags = GENL_UNS_ADMIN_PERM,
17042 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17045 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
17046 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17047 .doit = nl80211_set_tx_bitrate_mask,
17048 .flags = GENL_UNS_ADMIN_PERM,
17049 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17050 NL80211_FLAG_MLO_VALID_LINK_ID),
17053 .cmd = NL80211_CMD_REGISTER_FRAME,
17054 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17055 .doit = nl80211_register_mgmt,
17056 .flags = GENL_UNS_ADMIN_PERM,
17057 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV),
17060 .cmd = NL80211_CMD_FRAME,
17061 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17062 .doit = nl80211_tx_mgmt,
17063 .flags = GENL_UNS_ADMIN_PERM,
17064 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17067 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
17068 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17069 .doit = nl80211_tx_mgmt_cancel_wait,
17070 .flags = GENL_UNS_ADMIN_PERM,
17071 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17074 .cmd = NL80211_CMD_SET_POWER_SAVE,
17075 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17076 .doit = nl80211_set_power_save,
17077 .flags = GENL_UNS_ADMIN_PERM,
17078 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17081 .cmd = NL80211_CMD_GET_POWER_SAVE,
17082 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17083 .doit = nl80211_get_power_save,
17084 /* can be retrieved by unprivileged users */
17085 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17088 .cmd = NL80211_CMD_SET_CQM,
17089 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17090 .doit = nl80211_set_cqm,
17091 .flags = GENL_UNS_ADMIN_PERM,
17092 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17095 .cmd = NL80211_CMD_SET_CHANNEL,
17096 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17097 .doit = nl80211_set_channel,
17098 .flags = GENL_UNS_ADMIN_PERM,
17099 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17100 NL80211_FLAG_MLO_VALID_LINK_ID),
17103 .cmd = NL80211_CMD_JOIN_MESH,
17104 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17105 .doit = nl80211_join_mesh,
17106 .flags = GENL_UNS_ADMIN_PERM,
17107 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17110 .cmd = NL80211_CMD_LEAVE_MESH,
17111 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17112 .doit = nl80211_leave_mesh,
17113 .flags = GENL_UNS_ADMIN_PERM,
17114 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17117 .cmd = NL80211_CMD_JOIN_OCB,
17118 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17119 .doit = nl80211_join_ocb,
17120 .flags = GENL_UNS_ADMIN_PERM,
17121 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17124 .cmd = NL80211_CMD_LEAVE_OCB,
17125 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17126 .doit = nl80211_leave_ocb,
17127 .flags = GENL_UNS_ADMIN_PERM,
17128 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17132 .cmd = NL80211_CMD_GET_WOWLAN,
17133 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17134 .doit = nl80211_get_wowlan,
17135 /* can be retrieved by unprivileged users */
17136 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17139 .cmd = NL80211_CMD_SET_WOWLAN,
17140 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17141 .doit = nl80211_set_wowlan,
17142 .flags = GENL_UNS_ADMIN_PERM,
17143 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17147 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
17148 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17149 .doit = nl80211_set_rekey_data,
17150 .flags = GENL_UNS_ADMIN_PERM,
17151 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17152 NL80211_FLAG_CLEAR_SKB),
17155 .cmd = NL80211_CMD_TDLS_MGMT,
17156 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17157 .doit = nl80211_tdls_mgmt,
17158 .flags = GENL_UNS_ADMIN_PERM,
17159 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17160 NL80211_FLAG_MLO_VALID_LINK_ID),
17163 .cmd = NL80211_CMD_TDLS_OPER,
17164 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17165 .doit = nl80211_tdls_oper,
17166 .flags = GENL_UNS_ADMIN_PERM,
17167 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17170 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
17171 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17172 .doit = nl80211_register_unexpected_frame,
17173 .flags = GENL_UNS_ADMIN_PERM,
17174 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17177 .cmd = NL80211_CMD_PROBE_CLIENT,
17178 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17179 .doit = nl80211_probe_client,
17180 .flags = GENL_UNS_ADMIN_PERM,
17181 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17184 .cmd = NL80211_CMD_REGISTER_BEACONS,
17185 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17186 .doit = nl80211_register_beacons,
17187 .flags = GENL_UNS_ADMIN_PERM,
17188 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17191 .cmd = NL80211_CMD_SET_NOACK_MAP,
17192 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17193 .doit = nl80211_set_noack_map,
17194 .flags = GENL_UNS_ADMIN_PERM,
17195 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17198 .cmd = NL80211_CMD_START_P2P_DEVICE,
17199 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17200 .doit = nl80211_start_p2p_device,
17201 .flags = GENL_UNS_ADMIN_PERM,
17202 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
17203 NL80211_FLAG_NEED_RTNL),
17206 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
17207 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17208 .doit = nl80211_stop_p2p_device,
17209 .flags = GENL_UNS_ADMIN_PERM,
17210 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
17211 NL80211_FLAG_NEED_RTNL),
17214 .cmd = NL80211_CMD_START_NAN,
17215 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17216 .doit = nl80211_start_nan,
17217 .flags = GENL_ADMIN_PERM,
17218 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
17219 NL80211_FLAG_NEED_RTNL),
17222 .cmd = NL80211_CMD_STOP_NAN,
17223 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17224 .doit = nl80211_stop_nan,
17225 .flags = GENL_ADMIN_PERM,
17226 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
17227 NL80211_FLAG_NEED_RTNL),
17230 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
17231 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17232 .doit = nl80211_nan_add_func,
17233 .flags = GENL_ADMIN_PERM,
17234 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17237 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
17238 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17239 .doit = nl80211_nan_del_func,
17240 .flags = GENL_ADMIN_PERM,
17241 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17244 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
17245 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17246 .doit = nl80211_nan_change_config,
17247 .flags = GENL_ADMIN_PERM,
17248 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17251 .cmd = NL80211_CMD_SET_MCAST_RATE,
17252 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17253 .doit = nl80211_set_mcast_rate,
17254 .flags = GENL_UNS_ADMIN_PERM,
17255 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17258 .cmd = NL80211_CMD_SET_MAC_ACL,
17259 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17260 .doit = nl80211_set_mac_acl,
17261 .flags = GENL_UNS_ADMIN_PERM,
17262 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17263 NL80211_FLAG_MLO_UNSUPPORTED),
17266 .cmd = NL80211_CMD_RADAR_DETECT,
17267 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17268 .doit = nl80211_start_radar_detection,
17269 .flags = GENL_UNS_ADMIN_PERM,
17270 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17271 NL80211_FLAG_NO_WIPHY_MTX |
17272 NL80211_FLAG_MLO_UNSUPPORTED),
17275 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
17276 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17277 .doit = nl80211_get_protocol_features,
17280 .cmd = NL80211_CMD_UPDATE_FT_IES,
17281 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17282 .doit = nl80211_update_ft_ies,
17283 .flags = GENL_UNS_ADMIN_PERM,
17284 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17287 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
17288 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17289 .doit = nl80211_crit_protocol_start,
17290 .flags = GENL_UNS_ADMIN_PERM,
17291 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17294 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
17295 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17296 .doit = nl80211_crit_protocol_stop,
17297 .flags = GENL_UNS_ADMIN_PERM,
17298 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17301 .cmd = NL80211_CMD_GET_COALESCE,
17302 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17303 .doit = nl80211_get_coalesce,
17304 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17307 .cmd = NL80211_CMD_SET_COALESCE,
17308 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17309 .doit = nl80211_set_coalesce,
17310 .flags = GENL_UNS_ADMIN_PERM,
17311 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17314 .cmd = NL80211_CMD_CHANNEL_SWITCH,
17315 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17316 .doit = nl80211_channel_switch,
17317 .flags = GENL_UNS_ADMIN_PERM,
17318 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17319 NL80211_FLAG_MLO_VALID_LINK_ID),
17322 .cmd = NL80211_CMD_VENDOR,
17323 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17324 .doit = nl80211_vendor_cmd,
17325 .dumpit = nl80211_vendor_cmd_dump,
17326 .flags = GENL_UNS_ADMIN_PERM,
17327 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
17328 NL80211_FLAG_CLEAR_SKB),
17331 .cmd = NL80211_CMD_SET_QOS_MAP,
17332 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17333 .doit = nl80211_set_qos_map,
17334 .flags = GENL_UNS_ADMIN_PERM,
17335 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17338 .cmd = NL80211_CMD_ADD_TX_TS,
17339 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17340 .doit = nl80211_add_tx_ts,
17341 .flags = GENL_UNS_ADMIN_PERM,
17342 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17343 NL80211_FLAG_MLO_UNSUPPORTED),
17346 .cmd = NL80211_CMD_DEL_TX_TS,
17347 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17348 .doit = nl80211_del_tx_ts,
17349 .flags = GENL_UNS_ADMIN_PERM,
17350 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17353 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
17354 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17355 .doit = nl80211_tdls_channel_switch,
17356 .flags = GENL_UNS_ADMIN_PERM,
17357 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17360 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
17361 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17362 .doit = nl80211_tdls_cancel_channel_switch,
17363 .flags = GENL_UNS_ADMIN_PERM,
17364 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17367 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
17368 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17369 .doit = nl80211_set_multicast_to_unicast,
17370 .flags = GENL_UNS_ADMIN_PERM,
17371 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17374 .cmd = NL80211_CMD_SET_PMK,
17375 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17376 .doit = nl80211_set_pmk,
17377 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17378 NL80211_FLAG_CLEAR_SKB),
17381 .cmd = NL80211_CMD_DEL_PMK,
17382 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17383 .doit = nl80211_del_pmk,
17384 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17387 .cmd = NL80211_CMD_EXTERNAL_AUTH,
17388 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17389 .doit = nl80211_external_auth,
17390 .flags = GENL_ADMIN_PERM,
17391 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17394 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
17395 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17396 .doit = nl80211_tx_control_port,
17397 .flags = GENL_UNS_ADMIN_PERM,
17398 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17401 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
17402 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17403 .doit = nl80211_get_ftm_responder_stats,
17404 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17405 NL80211_FLAG_MLO_VALID_LINK_ID),
17408 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
17409 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17410 .doit = nl80211_pmsr_start,
17411 .flags = GENL_UNS_ADMIN_PERM,
17412 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17415 .cmd = NL80211_CMD_NOTIFY_RADAR,
17416 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17417 .doit = nl80211_notify_radar_detection,
17418 .flags = GENL_UNS_ADMIN_PERM,
17419 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17422 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
17423 .doit = nl80211_update_owe_info,
17424 .flags = GENL_ADMIN_PERM,
17425 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17428 .cmd = NL80211_CMD_PROBE_MESH_LINK,
17429 .doit = nl80211_probe_mesh_link,
17430 .flags = GENL_UNS_ADMIN_PERM,
17431 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17434 .cmd = NL80211_CMD_SET_TID_CONFIG,
17435 .doit = nl80211_set_tid_config,
17436 .flags = GENL_UNS_ADMIN_PERM,
17437 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17438 NL80211_FLAG_MLO_VALID_LINK_ID),
17441 .cmd = NL80211_CMD_SET_SAR_SPECS,
17442 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17443 .doit = nl80211_set_sar_specs,
17444 .flags = GENL_UNS_ADMIN_PERM,
17445 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
17446 NL80211_FLAG_NEED_RTNL),
17449 .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST,
17450 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17451 .doit = nl80211_color_change,
17452 .flags = GENL_UNS_ADMIN_PERM,
17453 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17456 .cmd = NL80211_CMD_SET_FILS_AAD,
17457 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17458 .doit = nl80211_set_fils_aad,
17459 .flags = GENL_UNS_ADMIN_PERM,
17460 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17463 .cmd = NL80211_CMD_ADD_LINK,
17464 .doit = nl80211_add_link,
17465 .flags = GENL_UNS_ADMIN_PERM,
17466 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17469 .cmd = NL80211_CMD_REMOVE_LINK,
17470 .doit = nl80211_remove_link,
17471 .flags = GENL_UNS_ADMIN_PERM,
17472 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17473 NL80211_FLAG_MLO_VALID_LINK_ID),
17476 .cmd = NL80211_CMD_ADD_LINK_STA,
17477 .doit = nl80211_add_link_station,
17478 .flags = GENL_UNS_ADMIN_PERM,
17479 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17480 NL80211_FLAG_MLO_VALID_LINK_ID),
17483 .cmd = NL80211_CMD_MODIFY_LINK_STA,
17484 .doit = nl80211_modify_link_station,
17485 .flags = GENL_UNS_ADMIN_PERM,
17486 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17487 NL80211_FLAG_MLO_VALID_LINK_ID),
17490 .cmd = NL80211_CMD_REMOVE_LINK_STA,
17491 .doit = nl80211_remove_link_station,
17492 .flags = GENL_UNS_ADMIN_PERM,
17493 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17494 NL80211_FLAG_MLO_VALID_LINK_ID),
17497 .cmd = NL80211_CMD_SET_HW_TIMESTAMP,
17498 .doit = nl80211_set_hw_timestamp,
17499 .flags = GENL_UNS_ADMIN_PERM,
17500 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17504 static struct genl_family nl80211_fam __ro_after_init = {
17505 .name = NL80211_GENL_NAME, /* have users key off the name instead */
17506 .hdrsize = 0, /* no private header */
17507 .version = 1, /* no particular meaning now */
17508 .maxattr = NL80211_ATTR_MAX,
17509 .policy = nl80211_policy,
17511 .pre_doit = nl80211_pre_doit,
17512 .post_doit = nl80211_post_doit,
17513 .module = THIS_MODULE,
17514 .ops = nl80211_ops,
17515 .n_ops = ARRAY_SIZE(nl80211_ops),
17516 .small_ops = nl80211_small_ops,
17517 .n_small_ops = ARRAY_SIZE(nl80211_small_ops),
17518 .resv_start_op = NL80211_CMD_REMOVE_LINK_STA + 1,
17519 .mcgrps = nl80211_mcgrps,
17520 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
17521 .parallel_ops = true,
17524 /* notification functions */
17526 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
17527 enum nl80211_commands cmd)
17529 struct sk_buff *msg;
17530 struct nl80211_dump_wiphy_state state = {};
17532 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
17533 cmd != NL80211_CMD_DEL_WIPHY);
17535 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17539 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
17544 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17545 NL80211_MCGRP_CONFIG, GFP_KERNEL);
17548 void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
17549 struct wireless_dev *wdev,
17550 enum nl80211_commands cmd)
17552 struct sk_buff *msg;
17554 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17558 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
17563 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17564 NL80211_MCGRP_CONFIG, GFP_KERNEL);
17567 static int nl80211_add_scan_req(struct sk_buff *msg,
17568 struct cfg80211_registered_device *rdev)
17570 struct cfg80211_scan_request *req = rdev->scan_req;
17571 struct nlattr *nest;
17573 struct cfg80211_scan_info *info;
17578 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
17580 goto nla_put_failure;
17581 for (i = 0; i < req->n_ssids; i++) {
17582 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
17583 goto nla_put_failure;
17585 nla_nest_end(msg, nest);
17587 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) {
17588 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ);
17590 goto nla_put_failure;
17591 for (i = 0; i < req->n_channels; i++) {
17592 if (nla_put_u32(msg, i,
17593 ieee80211_channel_to_khz(req->channels[i])))
17594 goto nla_put_failure;
17596 nla_nest_end(msg, nest);
17598 nest = nla_nest_start_noflag(msg,
17599 NL80211_ATTR_SCAN_FREQUENCIES);
17601 goto nla_put_failure;
17602 for (i = 0; i < req->n_channels; i++) {
17603 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
17604 goto nla_put_failure;
17606 nla_nest_end(msg, nest);
17610 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
17611 goto nla_put_failure;
17614 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
17615 goto nla_put_failure;
17617 info = rdev->int_scan_req ? &rdev->int_scan_req->info :
17618 &rdev->scan_req->info;
17619 if (info->scan_start_tsf &&
17620 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
17621 info->scan_start_tsf, NL80211_BSS_PAD) ||
17622 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
17624 goto nla_put_failure;
17631 static int nl80211_prep_scan_msg(struct sk_buff *msg,
17632 struct cfg80211_registered_device *rdev,
17633 struct wireless_dev *wdev,
17634 u32 portid, u32 seq, int flags,
17639 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
17643 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17644 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
17645 wdev->netdev->ifindex)) ||
17646 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17648 goto nla_put_failure;
17650 /* ignore errors and send incomplete event anyway */
17651 nl80211_add_scan_req(msg, rdev);
17653 genlmsg_end(msg, hdr);
17657 genlmsg_cancel(msg, hdr);
17662 nl80211_prep_sched_scan_msg(struct sk_buff *msg,
17663 struct cfg80211_sched_scan_request *req, u32 cmd)
17667 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17671 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
17672 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
17673 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
17674 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
17676 goto nla_put_failure;
17678 genlmsg_end(msg, hdr);
17682 genlmsg_cancel(msg, hdr);
17686 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
17687 struct wireless_dev *wdev)
17689 struct sk_buff *msg;
17691 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17695 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
17696 NL80211_CMD_TRIGGER_SCAN) < 0) {
17701 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17702 NL80211_MCGRP_SCAN, GFP_KERNEL);
17705 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
17706 struct wireless_dev *wdev, bool aborted)
17708 struct sk_buff *msg;
17710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17714 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
17715 aborted ? NL80211_CMD_SCAN_ABORTED :
17716 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
17724 /* send message created by nl80211_build_scan_msg() */
17725 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
17726 struct sk_buff *msg)
17731 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17732 NL80211_MCGRP_SCAN, GFP_KERNEL);
17735 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
17737 struct sk_buff *msg;
17739 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17743 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
17748 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
17749 NL80211_MCGRP_SCAN, GFP_KERNEL);
17752 static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
17753 struct regulatory_request *request)
17755 /* Userspace can always count this one always being set */
17756 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
17757 goto nla_put_failure;
17759 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
17760 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17761 NL80211_REGDOM_TYPE_WORLD))
17762 goto nla_put_failure;
17763 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
17764 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17765 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
17766 goto nla_put_failure;
17767 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
17768 request->intersect) {
17769 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17770 NL80211_REGDOM_TYPE_INTERSECTION))
17771 goto nla_put_failure;
17773 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17774 NL80211_REGDOM_TYPE_COUNTRY) ||
17775 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
17777 goto nla_put_failure;
17780 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
17781 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
17784 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
17785 goto nla_put_failure;
17788 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
17789 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
17790 goto nla_put_failure;
17800 * This can happen on global regulatory changes or device specific settings
17801 * based on custom regulatory domains.
17803 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
17804 struct regulatory_request *request)
17806 struct sk_buff *msg;
17809 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17813 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
17815 goto nla_put_failure;
17817 if (!nl80211_reg_change_event_fill(msg, request))
17818 goto nla_put_failure;
17820 genlmsg_end(msg, hdr);
17823 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
17824 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
17833 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
17834 struct net_device *netdev,
17835 const u8 *buf, size_t len,
17836 enum nl80211_commands cmd, gfp_t gfp,
17837 int uapsd_queues, const u8 *req_ies,
17838 size_t req_ies_len, bool reconnect)
17840 struct sk_buff *msg;
17843 msg = nlmsg_new(100 + len + req_ies_len, gfp);
17847 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17853 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17854 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17855 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
17857 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
17858 goto nla_put_failure;
17860 if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED))
17861 goto nla_put_failure;
17863 if (uapsd_queues >= 0) {
17864 struct nlattr *nla_wmm =
17865 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
17867 goto nla_put_failure;
17869 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
17871 goto nla_put_failure;
17873 nla_nest_end(msg, nla_wmm);
17876 genlmsg_end(msg, hdr);
17878 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17879 NL80211_MCGRP_MLME, gfp);
17886 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
17887 struct net_device *netdev, const u8 *buf,
17888 size_t len, gfp_t gfp)
17890 nl80211_send_mlme_event(rdev, netdev, buf, len,
17891 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0,
17895 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
17896 struct net_device *netdev,
17897 struct cfg80211_rx_assoc_resp *data)
17899 nl80211_send_mlme_event(rdev, netdev, data->buf, data->len,
17900 NL80211_CMD_ASSOCIATE, GFP_KERNEL,
17901 data->uapsd_queues,
17902 data->req_ies, data->req_ies_len, false);
17905 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
17906 struct net_device *netdev, const u8 *buf,
17907 size_t len, bool reconnect, gfp_t gfp)
17909 nl80211_send_mlme_event(rdev, netdev, buf, len,
17910 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0,
17914 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
17915 struct net_device *netdev, const u8 *buf,
17916 size_t len, bool reconnect, gfp_t gfp)
17918 nl80211_send_mlme_event(rdev, netdev, buf, len,
17919 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0,
17923 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
17926 struct wireless_dev *wdev = dev->ieee80211_ptr;
17927 struct wiphy *wiphy = wdev->wiphy;
17928 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17929 const struct ieee80211_mgmt *mgmt = (void *)buf;
17932 if (WARN_ON(len < 2))
17935 if (ieee80211_is_deauth(mgmt->frame_control)) {
17936 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
17937 } else if (ieee80211_is_disassoc(mgmt->frame_control)) {
17938 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
17939 } else if (ieee80211_is_beacon(mgmt->frame_control)) {
17940 if (wdev->unprot_beacon_reported &&
17941 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000)
17943 cmd = NL80211_CMD_UNPROT_BEACON;
17944 wdev->unprot_beacon_reported = jiffies;
17949 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
17950 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
17953 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
17955 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
17956 struct net_device *netdev, int cmd,
17957 const u8 *addr, gfp_t gfp)
17959 struct sk_buff *msg;
17962 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17966 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17972 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17973 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17974 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
17975 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
17976 goto nla_put_failure;
17978 genlmsg_end(msg, hdr);
17980 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17981 NL80211_MCGRP_MLME, gfp);
17988 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
17989 struct net_device *netdev, const u8 *addr,
17992 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
17996 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
17997 struct net_device *netdev, const u8 *addr,
18000 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
18004 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
18005 struct net_device *netdev,
18006 struct cfg80211_connect_resp_params *cr,
18009 struct sk_buff *msg;
18012 size_t link_info_size = 0;
18013 const u8 *connected_addr = cr->valid_links ?
18014 cr->ap_mld_addr : cr->links[0].bssid;
18016 if (cr->valid_links) {
18017 for_each_valid_link(cr, link) {
18018 /* Nested attribute header */
18019 link_info_size += NLA_HDRLEN;
18021 link_info_size += nla_total_size(sizeof(u8));
18022 link_info_size += cr->links[link].addr ?
18023 nla_total_size(ETH_ALEN) : 0;
18024 link_info_size += (cr->links[link].bssid ||
18025 cr->links[link].bss) ?
18026 nla_total_size(ETH_ALEN) : 0;
18027 link_info_size += nla_total_size(sizeof(u16));
18031 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
18032 cr->fils.kek_len + cr->fils.pmk_len +
18033 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size,
18038 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
18044 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18045 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18047 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr)) ||
18048 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
18049 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
18052 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
18053 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
18054 cr->timeout_reason))) ||
18056 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
18058 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
18060 (cr->fils.update_erp_next_seq_num &&
18061 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
18062 cr->fils.erp_next_seq_num)) ||
18063 (cr->status == WLAN_STATUS_SUCCESS &&
18065 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
18068 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
18070 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
18071 goto nla_put_failure;
18073 if (cr->valid_links) {
18075 struct nlattr *nested;
18077 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
18079 goto nla_put_failure;
18081 for_each_valid_link(cr, link) {
18082 struct nlattr *nested_mlo_links;
18083 const u8 *bssid = cr->links[link].bss ?
18084 cr->links[link].bss->bssid :
18085 cr->links[link].bssid;
18087 nested_mlo_links = nla_nest_start(msg, i);
18088 if (!nested_mlo_links)
18089 goto nla_put_failure;
18091 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) ||
18093 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) ||
18094 (cr->links[link].addr &&
18095 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
18096 cr->links[link].addr)) ||
18097 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
18098 cr->links[link].status))
18099 goto nla_put_failure;
18101 nla_nest_end(msg, nested_mlo_links);
18104 nla_nest_end(msg, nested);
18107 genlmsg_end(msg, hdr);
18109 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18110 NL80211_MCGRP_MLME, gfp);
18117 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
18118 struct net_device *netdev,
18119 struct cfg80211_roam_info *info, gfp_t gfp)
18121 struct sk_buff *msg;
18123 size_t link_info_size = 0;
18125 const u8 *connected_addr = info->ap_mld_addr ?
18126 info->ap_mld_addr :
18127 (info->links[0].bss ?
18128 info->links[0].bss->bssid :
18129 info->links[0].bssid);
18131 if (info->valid_links) {
18132 for_each_valid_link(info, link) {
18133 /* Nested attribute header */
18134 link_info_size += NLA_HDRLEN;
18136 link_info_size += nla_total_size(sizeof(u8));
18137 link_info_size += info->links[link].addr ?
18138 nla_total_size(ETH_ALEN) : 0;
18139 link_info_size += (info->links[link].bssid ||
18140 info->links[link].bss) ?
18141 nla_total_size(ETH_ALEN) : 0;
18145 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
18146 info->fils.kek_len + info->fils.pmk_len +
18147 (info->fils.pmkid ? WLAN_PMKID_LEN : 0) +
18148 link_info_size, gfp);
18152 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
18158 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18159 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18160 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) ||
18162 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
18165 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
18167 (info->fils.update_erp_next_seq_num &&
18168 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
18169 info->fils.erp_next_seq_num)) ||
18171 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
18172 info->fils.kek)) ||
18174 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
18175 (info->fils.pmkid &&
18176 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
18177 goto nla_put_failure;
18179 if (info->valid_links) {
18181 struct nlattr *nested;
18183 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
18185 goto nla_put_failure;
18187 for_each_valid_link(info, link) {
18188 struct nlattr *nested_mlo_links;
18189 const u8 *bssid = info->links[link].bss ?
18190 info->links[link].bss->bssid :
18191 info->links[link].bssid;
18193 nested_mlo_links = nla_nest_start(msg, i);
18194 if (!nested_mlo_links)
18195 goto nla_put_failure;
18197 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) ||
18199 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) ||
18200 (info->links[link].addr &&
18201 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
18202 info->links[link].addr)))
18203 goto nla_put_failure;
18205 nla_nest_end(msg, nested_mlo_links);
18208 nla_nest_end(msg, nested);
18211 genlmsg_end(msg, hdr);
18213 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18214 NL80211_MCGRP_MLME, gfp);
18221 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
18222 struct net_device *netdev, const u8 *bssid,
18223 const u8 *td_bitmap, u8 td_bitmap_len)
18225 struct sk_buff *msg;
18228 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
18232 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
18238 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18239 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18240 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
18241 goto nla_put_failure;
18243 if ((td_bitmap_len > 0) && td_bitmap)
18244 if (nla_put(msg, NL80211_ATTR_TD_BITMAP,
18245 td_bitmap_len, td_bitmap))
18246 goto nla_put_failure;
18248 genlmsg_end(msg, hdr);
18250 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18251 NL80211_MCGRP_MLME, GFP_KERNEL);
18258 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
18259 struct net_device *netdev, u16 reason,
18260 const u8 *ie, size_t ie_len, bool from_ap)
18262 struct sk_buff *msg;
18265 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
18269 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
18275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18276 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18278 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
18280 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
18281 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
18282 goto nla_put_failure;
18284 genlmsg_end(msg, hdr);
18286 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18287 NL80211_MCGRP_MLME, GFP_KERNEL);
18294 void cfg80211_links_removed(struct net_device *dev, u16 link_mask)
18296 struct wireless_dev *wdev = dev->ieee80211_ptr;
18297 struct wiphy *wiphy = wdev->wiphy;
18298 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18299 struct sk_buff *msg;
18300 struct nlattr *links;
18303 ASSERT_WDEV_LOCK(wdev);
18304 trace_cfg80211_links_removed(dev, link_mask);
18306 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
18307 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
18310 if (WARN_ON(!wdev->valid_links || !link_mask ||
18311 (wdev->valid_links & link_mask) != link_mask ||
18312 wdev->valid_links == link_mask))
18315 cfg80211_wdev_release_link_bsses(wdev, link_mask);
18316 wdev->valid_links &= ~link_mask;
18318 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
18322 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_LINKS_REMOVED);
18328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18329 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
18330 goto nla_put_failure;
18332 links = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
18334 goto nla_put_failure;
18336 while (link_mask) {
18337 struct nlattr *link;
18338 int link_id = __ffs(link_mask);
18340 link = nla_nest_start(msg, link_id + 1);
18342 goto nla_put_failure;
18344 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
18345 goto nla_put_failure;
18347 nla_nest_end(msg, link);
18348 link_mask &= ~(1 << link_id);
18351 nla_nest_end(msg, links);
18353 genlmsg_end(msg, hdr);
18355 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18356 NL80211_MCGRP_MLME, GFP_KERNEL);
18362 EXPORT_SYMBOL(cfg80211_links_removed);
18364 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
18365 struct net_device *netdev, const u8 *bssid,
18368 struct sk_buff *msg;
18371 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18375 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
18381 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18382 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18383 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
18384 goto nla_put_failure;
18386 genlmsg_end(msg, hdr);
18388 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18389 NL80211_MCGRP_MLME, gfp);
18396 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
18397 const u8 *ie, u8 ie_len,
18398 int sig_dbm, gfp_t gfp)
18400 struct wireless_dev *wdev = dev->ieee80211_ptr;
18401 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18402 struct sk_buff *msg;
18405 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
18408 trace_cfg80211_notify_new_peer_candidate(dev, addr);
18410 msg = nlmsg_new(100 + ie_len, gfp);
18414 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
18420 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18421 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18422 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
18424 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
18426 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
18427 goto nla_put_failure;
18429 genlmsg_end(msg, hdr);
18431 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18432 NL80211_MCGRP_MLME, gfp);
18438 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
18440 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
18441 struct net_device *netdev, const u8 *addr,
18442 enum nl80211_key_type key_type, int key_id,
18443 const u8 *tsc, gfp_t gfp)
18445 struct sk_buff *msg;
18448 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18452 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
18458 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18459 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18460 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
18461 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
18463 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
18464 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
18465 goto nla_put_failure;
18467 genlmsg_end(msg, hdr);
18469 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18470 NL80211_MCGRP_MLME, gfp);
18477 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
18478 struct ieee80211_channel *channel_before,
18479 struct ieee80211_channel *channel_after)
18481 struct sk_buff *msg;
18483 struct nlattr *nl_freq;
18485 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
18489 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
18496 * Since we are applying the beacon hint to a wiphy we know its
18497 * wiphy_idx is valid
18499 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
18500 goto nla_put_failure;
18503 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
18505 goto nla_put_failure;
18507 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
18508 goto nla_put_failure;
18509 nla_nest_end(msg, nl_freq);
18512 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
18514 goto nla_put_failure;
18516 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
18517 goto nla_put_failure;
18518 nla_nest_end(msg, nl_freq);
18520 genlmsg_end(msg, hdr);
18523 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
18524 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
18533 static void nl80211_send_remain_on_chan_event(
18534 int cmd, struct cfg80211_registered_device *rdev,
18535 struct wireless_dev *wdev, u64 cookie,
18536 struct ieee80211_channel *chan,
18537 unsigned int duration, gfp_t gfp)
18539 struct sk_buff *msg;
18542 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18546 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
18552 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18553 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18554 wdev->netdev->ifindex)) ||
18555 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18556 NL80211_ATTR_PAD) ||
18557 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
18558 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
18559 NL80211_CHAN_NO_HT) ||
18560 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
18562 goto nla_put_failure;
18564 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
18565 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
18566 goto nla_put_failure;
18568 genlmsg_end(msg, hdr);
18570 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18571 NL80211_MCGRP_MLME, gfp);
18578 void cfg80211_assoc_comeback(struct net_device *netdev,
18579 const u8 *ap_addr, u32 timeout)
18581 struct wireless_dev *wdev = netdev->ieee80211_ptr;
18582 struct wiphy *wiphy = wdev->wiphy;
18583 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18584 struct sk_buff *msg;
18587 trace_cfg80211_assoc_comeback(wdev, ap_addr, timeout);
18589 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
18593 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ASSOC_COMEBACK);
18599 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18600 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18601 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ap_addr) ||
18602 nla_put_u32(msg, NL80211_ATTR_TIMEOUT, timeout))
18603 goto nla_put_failure;
18605 genlmsg_end(msg, hdr);
18607 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18608 NL80211_MCGRP_MLME, GFP_KERNEL);
18614 EXPORT_SYMBOL(cfg80211_assoc_comeback);
18616 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
18617 struct ieee80211_channel *chan,
18618 unsigned int duration, gfp_t gfp)
18620 struct wiphy *wiphy = wdev->wiphy;
18621 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18623 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
18624 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
18625 rdev, wdev, cookie, chan,
18628 EXPORT_SYMBOL(cfg80211_ready_on_channel);
18630 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
18631 struct ieee80211_channel *chan,
18634 struct wiphy *wiphy = wdev->wiphy;
18635 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18637 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
18638 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
18639 rdev, wdev, cookie, chan, 0, gfp);
18641 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
18643 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
18644 struct ieee80211_channel *chan,
18647 struct wiphy *wiphy = wdev->wiphy;
18648 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18650 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
18651 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
18652 rdev, wdev, cookie, chan, 0, gfp);
18654 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
18656 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
18657 struct station_info *sinfo, gfp_t gfp)
18659 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18660 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18661 struct sk_buff *msg;
18663 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
18665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18669 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
18670 rdev, dev, mac_addr, sinfo) < 0) {
18675 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18676 NL80211_MCGRP_MLME, gfp);
18678 EXPORT_SYMBOL(cfg80211_new_sta);
18680 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
18681 struct station_info *sinfo, gfp_t gfp)
18683 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18684 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18685 struct sk_buff *msg;
18686 struct station_info empty_sinfo = {};
18689 sinfo = &empty_sinfo;
18691 trace_cfg80211_del_sta(dev, mac_addr);
18693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18695 cfg80211_sinfo_release_content(sinfo);
18699 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
18700 rdev, dev, mac_addr, sinfo) < 0) {
18705 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18706 NL80211_MCGRP_MLME, gfp);
18708 EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
18710 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
18711 enum nl80211_connect_failed_reason reason,
18714 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18715 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18716 struct sk_buff *msg;
18719 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
18723 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
18729 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18730 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
18731 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
18732 goto nla_put_failure;
18734 genlmsg_end(msg, hdr);
18736 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18737 NL80211_MCGRP_MLME, gfp);
18743 EXPORT_SYMBOL(cfg80211_conn_failed);
18745 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
18746 const u8 *addr, gfp_t gfp)
18748 struct wireless_dev *wdev = dev->ieee80211_ptr;
18749 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18750 struct sk_buff *msg;
18752 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
18757 msg = nlmsg_new(100, gfp);
18761 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
18767 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18768 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18769 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
18770 goto nla_put_failure;
18772 genlmsg_end(msg, hdr);
18773 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
18781 bool cfg80211_rx_spurious_frame(struct net_device *dev,
18782 const u8 *addr, gfp_t gfp)
18784 struct wireless_dev *wdev = dev->ieee80211_ptr;
18787 trace_cfg80211_rx_spurious_frame(dev, addr);
18789 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
18790 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
18791 trace_cfg80211_return_bool(false);
18794 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
18796 trace_cfg80211_return_bool(ret);
18799 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
18801 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
18802 const u8 *addr, gfp_t gfp)
18804 struct wireless_dev *wdev = dev->ieee80211_ptr;
18807 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
18809 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
18810 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
18811 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
18812 trace_cfg80211_return_bool(false);
18815 ret = __nl80211_unexpected_frame(dev,
18816 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
18818 trace_cfg80211_return_bool(ret);
18821 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
18823 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
18824 struct wireless_dev *wdev, u32 nlportid,
18825 struct cfg80211_rx_info *info, gfp_t gfp)
18827 struct net_device *netdev = wdev->netdev;
18828 struct sk_buff *msg;
18831 msg = nlmsg_new(100 + info->len, gfp);
18835 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
18841 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18842 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18843 netdev->ifindex)) ||
18844 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18845 NL80211_ATTR_PAD) ||
18846 (info->have_link_id &&
18847 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, info->link_id)) ||
18848 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(info->freq)) ||
18849 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, info->freq % 1000) ||
18851 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, info->sig_dbm)) ||
18852 nla_put(msg, NL80211_ATTR_FRAME, info->len, info->buf) ||
18854 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, info->flags)) ||
18855 (info->rx_tstamp && nla_put_u64_64bit(msg,
18856 NL80211_ATTR_RX_HW_TIMESTAMP,
18858 NL80211_ATTR_PAD)) ||
18859 (info->ack_tstamp && nla_put_u64_64bit(msg,
18860 NL80211_ATTR_TX_HW_TIMESTAMP,
18862 NL80211_ATTR_PAD)))
18863 goto nla_put_failure;
18865 genlmsg_end(msg, hdr);
18867 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
18874 static void nl80211_frame_tx_status(struct wireless_dev *wdev,
18875 struct cfg80211_tx_status *status,
18876 gfp_t gfp, enum nl80211_commands command)
18878 struct wiphy *wiphy = wdev->wiphy;
18879 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18880 struct net_device *netdev = wdev->netdev;
18881 struct sk_buff *msg;
18884 if (command == NL80211_CMD_FRAME_TX_STATUS)
18885 trace_cfg80211_mgmt_tx_status(wdev, status->cookie,
18888 trace_cfg80211_control_port_tx_status(wdev, status->cookie,
18891 msg = nlmsg_new(100 + status->len, gfp);
18895 hdr = nl80211hdr_put(msg, 0, 0, 0, command);
18901 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18902 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18903 netdev->ifindex)) ||
18904 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18905 NL80211_ATTR_PAD) ||
18906 nla_put(msg, NL80211_ATTR_FRAME, status->len, status->buf) ||
18907 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, status->cookie,
18908 NL80211_ATTR_PAD) ||
18909 (status->ack && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
18910 (status->tx_tstamp &&
18911 nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP,
18912 status->tx_tstamp, NL80211_ATTR_PAD)) ||
18913 (status->ack_tstamp &&
18914 nla_put_u64_64bit(msg, NL80211_ATTR_RX_HW_TIMESTAMP,
18915 status->ack_tstamp, NL80211_ATTR_PAD)))
18916 goto nla_put_failure;
18918 genlmsg_end(msg, hdr);
18920 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18921 NL80211_MCGRP_MLME, gfp);
18928 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie,
18929 const u8 *buf, size_t len, bool ack,
18932 struct cfg80211_tx_status status = {
18939 nl80211_frame_tx_status(wdev, &status, gfp,
18940 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS);
18942 EXPORT_SYMBOL(cfg80211_control_port_tx_status);
18944 void cfg80211_mgmt_tx_status_ext(struct wireless_dev *wdev,
18945 struct cfg80211_tx_status *status, gfp_t gfp)
18947 nl80211_frame_tx_status(wdev, status, gfp, NL80211_CMD_FRAME_TX_STATUS);
18949 EXPORT_SYMBOL(cfg80211_mgmt_tx_status_ext);
18951 static int __nl80211_rx_control_port(struct net_device *dev,
18952 struct sk_buff *skb,
18957 struct wireless_dev *wdev = dev->ieee80211_ptr;
18958 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18959 struct ethhdr *ehdr = eth_hdr(skb);
18960 const u8 *addr = ehdr->h_source;
18961 u16 proto = be16_to_cpu(skb->protocol);
18962 struct sk_buff *msg;
18964 struct nlattr *frame;
18966 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
18971 msg = nlmsg_new(100 + skb->len, gfp);
18975 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
18981 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18982 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18983 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18984 NL80211_ATTR_PAD) ||
18985 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
18986 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
18988 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) ||
18989 (unencrypted && nla_put_flag(msg,
18990 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
18991 goto nla_put_failure;
18993 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
18995 goto nla_put_failure;
18997 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
18998 genlmsg_end(msg, hdr);
19000 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
19007 bool cfg80211_rx_control_port(struct net_device *dev, struct sk_buff *skb,
19008 bool unencrypted, int link_id)
19012 trace_cfg80211_rx_control_port(dev, skb, unencrypted, link_id);
19013 ret = __nl80211_rx_control_port(dev, skb, unencrypted, link_id,
19015 trace_cfg80211_return_bool(ret == 0);
19018 EXPORT_SYMBOL(cfg80211_rx_control_port);
19020 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
19021 const char *mac, gfp_t gfp)
19023 struct wireless_dev *wdev = dev->ieee80211_ptr;
19024 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19025 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19031 cb = (void **)msg->cb;
19033 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
19039 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19040 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19041 goto nla_put_failure;
19043 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
19044 goto nla_put_failure;
19046 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
19048 goto nla_put_failure;
19058 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
19060 void **cb = (void **)msg->cb;
19061 struct cfg80211_registered_device *rdev = cb[2];
19063 nla_nest_end(msg, cb[1]);
19064 genlmsg_end(msg, cb[0]);
19066 memset(msg->cb, 0, sizeof(msg->cb));
19068 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19069 NL80211_MCGRP_MLME, gfp);
19072 void cfg80211_cqm_rssi_notify(struct net_device *dev,
19073 enum nl80211_cqm_rssi_threshold_event rssi_event,
19074 s32 rssi_level, gfp_t gfp)
19076 struct sk_buff *msg;
19077 struct wireless_dev *wdev = dev->ieee80211_ptr;
19078 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19080 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
19082 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
19083 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
19086 if (wdev->cqm_config) {
19087 wdev->cqm_config->last_rssi_event_value = rssi_level;
19089 cfg80211_cqm_rssi_update(rdev, dev);
19091 if (rssi_level == 0)
19092 rssi_level = wdev->cqm_config->last_rssi_event_value;
19095 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
19099 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
19101 goto nla_put_failure;
19103 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
19105 goto nla_put_failure;
19107 cfg80211_send_cqm(msg, gfp);
19114 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
19116 void cfg80211_cqm_txe_notify(struct net_device *dev,
19117 const u8 *peer, u32 num_packets,
19118 u32 rate, u32 intvl, gfp_t gfp)
19120 struct sk_buff *msg;
19122 msg = cfg80211_prepare_cqm(dev, peer, gfp);
19126 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
19127 goto nla_put_failure;
19129 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
19130 goto nla_put_failure;
19132 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
19133 goto nla_put_failure;
19135 cfg80211_send_cqm(msg, gfp);
19141 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
19143 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
19144 const u8 *peer, u32 num_packets, gfp_t gfp)
19146 struct sk_buff *msg;
19148 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
19150 msg = cfg80211_prepare_cqm(dev, peer, gfp);
19154 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
19155 goto nla_put_failure;
19157 cfg80211_send_cqm(msg, gfp);
19163 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
19165 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
19167 struct sk_buff *msg;
19169 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
19173 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
19174 goto nla_put_failure;
19176 cfg80211_send_cqm(msg, gfp);
19182 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
19184 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
19185 struct net_device *netdev, const u8 *bssid,
19186 const u8 *replay_ctr, gfp_t gfp)
19188 struct sk_buff *msg;
19189 struct nlattr *rekey_attr;
19192 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19196 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
19202 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19203 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19204 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
19205 goto nla_put_failure;
19207 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
19209 goto nla_put_failure;
19211 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
19212 NL80211_REPLAY_CTR_LEN, replay_ctr))
19213 goto nla_put_failure;
19215 nla_nest_end(msg, rekey_attr);
19217 genlmsg_end(msg, hdr);
19219 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19220 NL80211_MCGRP_MLME, gfp);
19227 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
19228 const u8 *replay_ctr, gfp_t gfp)
19230 struct wireless_dev *wdev = dev->ieee80211_ptr;
19231 struct wiphy *wiphy = wdev->wiphy;
19232 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19234 trace_cfg80211_gtk_rekey_notify(dev, bssid);
19235 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
19237 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
19240 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
19241 struct net_device *netdev, int index,
19242 const u8 *bssid, bool preauth, gfp_t gfp)
19244 struct sk_buff *msg;
19245 struct nlattr *attr;
19248 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19252 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
19258 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19259 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
19260 goto nla_put_failure;
19262 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
19264 goto nla_put_failure;
19266 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
19267 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
19269 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
19270 goto nla_put_failure;
19272 nla_nest_end(msg, attr);
19274 genlmsg_end(msg, hdr);
19276 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19277 NL80211_MCGRP_MLME, gfp);
19284 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
19285 const u8 *bssid, bool preauth, gfp_t gfp)
19287 struct wireless_dev *wdev = dev->ieee80211_ptr;
19288 struct wiphy *wiphy = wdev->wiphy;
19289 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19291 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
19292 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
19294 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
19296 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
19297 struct net_device *netdev,
19298 unsigned int link_id,
19299 struct cfg80211_chan_def *chandef,
19301 enum nl80211_commands notif,
19302 u8 count, bool quiet, u16 punct_bitmap)
19304 struct wireless_dev *wdev = netdev->ieee80211_ptr;
19305 struct sk_buff *msg;
19308 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19312 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
19318 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
19319 goto nla_put_failure;
19321 if (wdev->valid_links &&
19322 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
19323 goto nla_put_failure;
19325 if (nl80211_send_chandef(msg, chandef))
19326 goto nla_put_failure;
19328 if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) {
19329 if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))
19330 goto nla_put_failure;
19332 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))
19333 goto nla_put_failure;
19336 if (nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP, punct_bitmap))
19337 goto nla_put_failure;
19339 genlmsg_end(msg, hdr);
19341 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19342 NL80211_MCGRP_MLME, gfp);
19349 void cfg80211_ch_switch_notify(struct net_device *dev,
19350 struct cfg80211_chan_def *chandef,
19351 unsigned int link_id, u16 punct_bitmap)
19353 struct wireless_dev *wdev = dev->ieee80211_ptr;
19354 struct wiphy *wiphy = wdev->wiphy;
19355 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19357 ASSERT_WDEV_LOCK(wdev);
19358 WARN_INVALID_LINK_ID(wdev, link_id);
19360 trace_cfg80211_ch_switch_notify(dev, chandef, link_id, punct_bitmap);
19362 switch (wdev->iftype) {
19363 case NL80211_IFTYPE_STATION:
19364 case NL80211_IFTYPE_P2P_CLIENT:
19365 if (!WARN_ON(!wdev->links[link_id].client.current_bss))
19366 cfg80211_update_assoc_bss_entry(wdev, link_id,
19369 case NL80211_IFTYPE_MESH_POINT:
19370 wdev->u.mesh.chandef = *chandef;
19371 wdev->u.mesh.preset_chandef = *chandef;
19373 case NL80211_IFTYPE_AP:
19374 case NL80211_IFTYPE_P2P_GO:
19375 wdev->links[link_id].ap.chandef = *chandef;
19377 case NL80211_IFTYPE_ADHOC:
19378 wdev->u.ibss.chandef = *chandef;
19385 cfg80211_sched_dfs_chan_update(rdev);
19387 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL,
19388 NL80211_CMD_CH_SWITCH_NOTIFY, 0, false,
19391 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
19393 void cfg80211_ch_switch_started_notify(struct net_device *dev,
19394 struct cfg80211_chan_def *chandef,
19395 unsigned int link_id, u8 count,
19396 bool quiet, u16 punct_bitmap)
19398 struct wireless_dev *wdev = dev->ieee80211_ptr;
19399 struct wiphy *wiphy = wdev->wiphy;
19400 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19402 ASSERT_WDEV_LOCK(wdev);
19403 WARN_INVALID_LINK_ID(wdev, link_id);
19405 trace_cfg80211_ch_switch_started_notify(dev, chandef, link_id,
19409 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL,
19410 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY,
19411 count, quiet, punct_bitmap);
19413 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
19415 int cfg80211_bss_color_notify(struct net_device *dev,
19416 enum nl80211_commands cmd, u8 count,
19419 struct wireless_dev *wdev = dev->ieee80211_ptr;
19420 struct wiphy *wiphy = wdev->wiphy;
19421 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19422 struct sk_buff *msg;
19425 ASSERT_WDEV_LOCK(wdev);
19427 trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap);
19429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
19433 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
19435 goto nla_put_failure;
19437 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19438 goto nla_put_failure;
19440 if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED &&
19441 nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count))
19442 goto nla_put_failure;
19444 if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION &&
19445 nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP,
19446 color_bitmap, NL80211_ATTR_PAD))
19447 goto nla_put_failure;
19449 genlmsg_end(msg, hdr);
19451 return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
19452 msg, 0, NL80211_MCGRP_MLME, GFP_KERNEL);
19458 EXPORT_SYMBOL(cfg80211_bss_color_notify);
19461 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
19462 const struct cfg80211_chan_def *chandef,
19463 enum nl80211_radar_event event,
19464 struct net_device *netdev, gfp_t gfp)
19466 struct sk_buff *msg;
19469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19473 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
19479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
19480 goto nla_put_failure;
19482 /* NOP and radar events don't need a netdev parameter */
19484 struct wireless_dev *wdev = netdev->ieee80211_ptr;
19486 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19487 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19489 goto nla_put_failure;
19492 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
19493 goto nla_put_failure;
19495 if (nl80211_send_chandef(msg, chandef))
19496 goto nla_put_failure;
19498 genlmsg_end(msg, hdr);
19500 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19501 NL80211_MCGRP_MLME, gfp);
19508 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
19509 struct sta_opmode_info *sta_opmode,
19512 struct sk_buff *msg;
19513 struct wireless_dev *wdev = dev->ieee80211_ptr;
19514 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19524 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
19530 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
19531 goto nla_put_failure;
19533 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19534 goto nla_put_failure;
19536 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
19537 goto nla_put_failure;
19539 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
19540 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
19541 goto nla_put_failure;
19543 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
19544 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
19545 goto nla_put_failure;
19547 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
19548 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
19549 goto nla_put_failure;
19551 genlmsg_end(msg, hdr);
19553 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19554 NL80211_MCGRP_MLME, gfp);
19561 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
19563 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
19564 u64 cookie, bool acked, s32 ack_signal,
19565 bool is_valid_ack_signal, gfp_t gfp)
19567 struct wireless_dev *wdev = dev->ieee80211_ptr;
19568 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19569 struct sk_buff *msg;
19572 trace_cfg80211_probe_status(dev, addr, cookie, acked);
19574 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19579 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
19585 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19586 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19587 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
19588 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
19589 NL80211_ATTR_PAD) ||
19590 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
19591 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
19593 goto nla_put_failure;
19595 genlmsg_end(msg, hdr);
19597 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19598 NL80211_MCGRP_MLME, gfp);
19604 EXPORT_SYMBOL(cfg80211_probe_status);
19606 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
19607 size_t len, int freq, int sig_dbm)
19609 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19610 struct sk_buff *msg;
19612 struct cfg80211_beacon_registration *reg;
19614 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
19616 spin_lock_bh(&rdev->beacon_registrations_lock);
19617 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
19618 msg = nlmsg_new(len + 100, GFP_ATOMIC);
19620 spin_unlock_bh(&rdev->beacon_registrations_lock);
19624 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
19626 goto nla_put_failure;
19628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19630 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
19631 KHZ_TO_MHZ(freq)) ||
19632 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
19635 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
19636 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
19637 goto nla_put_failure;
19639 genlmsg_end(msg, hdr);
19641 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
19643 spin_unlock_bh(&rdev->beacon_registrations_lock);
19647 spin_unlock_bh(&rdev->beacon_registrations_lock);
19650 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
19653 static int cfg80211_net_detect_results(struct sk_buff *msg,
19654 struct cfg80211_wowlan_wakeup *wakeup)
19656 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
19657 struct nlattr *nl_results, *nl_match, *nl_freqs;
19660 nl_results = nla_nest_start_noflag(msg,
19661 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
19665 for (i = 0; i < nd->n_matches; i++) {
19666 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
19668 nl_match = nla_nest_start_noflag(msg, i);
19672 /* The SSID attribute is optional in nl80211, but for
19673 * simplicity reasons it's always present in the
19674 * cfg80211 structure. If a driver can't pass the
19675 * SSID, that needs to be changed. A zero length SSID
19676 * is still a valid SSID (wildcard), so it cannot be
19677 * used for this purpose.
19679 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
19680 match->ssid.ssid)) {
19681 nla_nest_cancel(msg, nl_match);
19685 if (match->n_channels) {
19686 nl_freqs = nla_nest_start_noflag(msg,
19687 NL80211_ATTR_SCAN_FREQUENCIES);
19689 nla_nest_cancel(msg, nl_match);
19693 for (j = 0; j < match->n_channels; j++) {
19694 if (nla_put_u32(msg, j, match->channels[j])) {
19695 nla_nest_cancel(msg, nl_freqs);
19696 nla_nest_cancel(msg, nl_match);
19701 nla_nest_end(msg, nl_freqs);
19704 nla_nest_end(msg, nl_match);
19708 nla_nest_end(msg, nl_results);
19712 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
19713 struct cfg80211_wowlan_wakeup *wakeup,
19716 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19717 struct sk_buff *msg;
19721 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
19724 size += wakeup->packet_present_len;
19726 msg = nlmsg_new(size, gfp);
19730 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
19734 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19735 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19739 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
19740 wdev->netdev->ifindex))
19744 struct nlattr *reasons;
19746 reasons = nla_nest_start_noflag(msg,
19747 NL80211_ATTR_WOWLAN_TRIGGERS);
19751 if (wakeup->disconnect &&
19752 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
19754 if (wakeup->magic_pkt &&
19755 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
19757 if (wakeup->gtk_rekey_failure &&
19758 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
19760 if (wakeup->eap_identity_req &&
19761 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
19763 if (wakeup->four_way_handshake &&
19764 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
19766 if (wakeup->rfkill_release &&
19767 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
19770 if (wakeup->pattern_idx >= 0 &&
19771 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
19772 wakeup->pattern_idx))
19775 if (wakeup->tcp_match &&
19776 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
19779 if (wakeup->tcp_connlost &&
19780 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
19783 if (wakeup->tcp_nomoretokens &&
19785 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
19788 if (wakeup->packet) {
19789 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
19790 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
19792 if (!wakeup->packet_80211) {
19794 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
19796 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
19799 if (wakeup->packet_len &&
19800 nla_put_u32(msg, len_attr, wakeup->packet_len))
19803 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
19808 if (wakeup->net_detect &&
19809 cfg80211_net_detect_results(msg, wakeup))
19812 nla_nest_end(msg, reasons);
19815 genlmsg_end(msg, hdr);
19817 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19818 NL80211_MCGRP_MLME, gfp);
19824 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
19827 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
19828 enum nl80211_tdls_operation oper,
19829 u16 reason_code, gfp_t gfp)
19831 struct wireless_dev *wdev = dev->ieee80211_ptr;
19832 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19833 struct sk_buff *msg;
19836 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
19839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19843 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
19849 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19850 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19851 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
19852 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
19853 (reason_code > 0 &&
19854 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
19855 goto nla_put_failure;
19857 genlmsg_end(msg, hdr);
19859 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19860 NL80211_MCGRP_MLME, gfp);
19866 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
19868 static int nl80211_netlink_notify(struct notifier_block * nb,
19869 unsigned long state,
19872 struct netlink_notify *notify = _notify;
19873 struct cfg80211_registered_device *rdev;
19874 struct wireless_dev *wdev;
19875 struct cfg80211_beacon_registration *reg, *tmp;
19877 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
19878 return NOTIFY_DONE;
19882 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
19883 struct cfg80211_sched_scan_request *sched_scan_req;
19885 list_for_each_entry_rcu(sched_scan_req,
19886 &rdev->sched_scan_req_list,
19888 if (sched_scan_req->owner_nlportid == notify->portid) {
19889 sched_scan_req->nl_owner_dead = true;
19890 wiphy_work_queue(&rdev->wiphy,
19891 &rdev->sched_scan_stop_wk);
19895 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
19896 cfg80211_mlme_unregister_socket(wdev, notify->portid);
19898 if (wdev->owner_nlportid == notify->portid) {
19899 wdev->nl_owner_dead = true;
19900 schedule_work(&rdev->destroy_work);
19901 } else if (wdev->conn_owner_nlportid == notify->portid) {
19902 schedule_work(&wdev->disconnect_wk);
19905 cfg80211_release_pmsr(wdev, notify->portid);
19908 spin_lock_bh(&rdev->beacon_registrations_lock);
19909 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
19911 if (reg->nlportid == notify->portid) {
19912 list_del(®->list);
19917 spin_unlock_bh(&rdev->beacon_registrations_lock);
19923 * It is possible that the user space process that is controlling the
19924 * indoor setting disappeared, so notify the regulatory core.
19926 regulatory_netlink_notify(notify->portid);
19930 static struct notifier_block nl80211_netlink_notifier = {
19931 .notifier_call = nl80211_netlink_notify,
19934 void cfg80211_ft_event(struct net_device *netdev,
19935 struct cfg80211_ft_event_params *ft_event)
19937 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
19938 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19939 struct sk_buff *msg;
19942 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
19944 if (!ft_event->target_ap)
19947 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
19952 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
19956 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19957 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19958 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
19961 if (ft_event->ies &&
19962 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
19964 if (ft_event->ric_ies &&
19965 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
19966 ft_event->ric_ies))
19969 genlmsg_end(msg, hdr);
19971 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19972 NL80211_MCGRP_MLME, GFP_KERNEL);
19977 EXPORT_SYMBOL(cfg80211_ft_event);
19979 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
19981 struct cfg80211_registered_device *rdev;
19982 struct sk_buff *msg;
19986 rdev = wiphy_to_rdev(wdev->wiphy);
19987 if (!rdev->crit_proto_nlportid)
19990 nlportid = rdev->crit_proto_nlportid;
19991 rdev->crit_proto_nlportid = 0;
19993 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19997 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
19999 goto nla_put_failure;
20001 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20002 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
20004 goto nla_put_failure;
20006 genlmsg_end(msg, hdr);
20008 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
20014 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
20016 void nl80211_send_ap_stopped(struct wireless_dev *wdev, unsigned int link_id)
20018 struct wiphy *wiphy = wdev->wiphy;
20019 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
20020 struct sk_buff *msg;
20023 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
20027 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
20031 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20032 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
20033 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
20034 NL80211_ATTR_PAD) ||
20035 (wdev->valid_links &&
20036 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)))
20039 genlmsg_end(msg, hdr);
20041 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
20042 NL80211_MCGRP_MLME, GFP_KERNEL);
20048 int cfg80211_external_auth_request(struct net_device *dev,
20049 struct cfg80211_external_auth_params *params,
20052 struct wireless_dev *wdev = dev->ieee80211_ptr;
20053 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
20054 struct sk_buff *msg;
20057 if (!wdev->conn_owner_nlportid)
20060 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
20064 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
20066 goto nla_put_failure;
20068 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20069 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
20070 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
20071 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
20073 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
20074 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
20075 params->ssid.ssid) ||
20076 (!is_zero_ether_addr(params->mld_addr) &&
20077 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, params->mld_addr)))
20078 goto nla_put_failure;
20080 genlmsg_end(msg, hdr);
20081 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
20082 wdev->conn_owner_nlportid);
20089 EXPORT_SYMBOL(cfg80211_external_auth_request);
20091 void cfg80211_update_owe_info_event(struct net_device *netdev,
20092 struct cfg80211_update_owe_info *owe_info,
20095 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
20096 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
20097 struct sk_buff *msg;
20100 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
20102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
20106 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
20108 goto nla_put_failure;
20110 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
20111 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
20112 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
20113 goto nla_put_failure;
20115 if (!owe_info->ie_len ||
20116 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
20117 goto nla_put_failure;
20119 if (owe_info->assoc_link_id != -1) {
20120 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID,
20121 owe_info->assoc_link_id))
20122 goto nla_put_failure;
20124 if (!is_zero_ether_addr(owe_info->peer_mld_addr) &&
20125 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN,
20126 owe_info->peer_mld_addr))
20127 goto nla_put_failure;
20130 genlmsg_end(msg, hdr);
20132 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
20133 NL80211_MCGRP_MLME, gfp);
20137 genlmsg_cancel(msg, hdr);
20140 EXPORT_SYMBOL(cfg80211_update_owe_info_event);
20142 /* initialisation/exit functions */
20144 int __init nl80211_init(void)
20148 err = genl_register_family(&nl80211_fam);
20152 err = netlink_register_notifier(&nl80211_netlink_notifier);
20158 genl_unregister_family(&nl80211_fam);
20162 void nl80211_exit(void)
20164 netlink_unregister_notifier(&nl80211_netlink_notifier);
20165 genl_unregister_family(&nl80211_fam);