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-2022 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 const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
466 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
467 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
468 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
470 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
472 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
473 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
474 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
475 NL80211_EDMG_CHANNELS_MIN,
476 NL80211_EDMG_CHANNELS_MAX),
477 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
478 NL80211_EDMG_BW_CONFIG_MIN,
479 NL80211_EDMG_BW_CONFIG_MAX),
481 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
482 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
483 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
484 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
486 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
487 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
488 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
489 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
490 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
491 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
493 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
494 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
495 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
497 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
498 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
500 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
501 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
502 .len = WLAN_MAX_KEY_LEN },
503 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
504 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
505 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
506 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
507 [NL80211_ATTR_KEY_TYPE] =
508 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
510 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
511 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
512 [NL80211_ATTR_BEACON_HEAD] =
513 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
514 IEEE80211_MAX_DATA_LEN),
515 [NL80211_ATTR_BEACON_TAIL] =
516 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
517 IEEE80211_MAX_DATA_LEN),
518 [NL80211_ATTR_STA_AID] =
519 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
520 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
521 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
522 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
523 .len = NL80211_MAX_SUPP_RATES },
524 [NL80211_ATTR_STA_PLINK_ACTION] =
525 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
526 [NL80211_ATTR_STA_TX_POWER_SETTING] =
527 NLA_POLICY_RANGE(NLA_U8,
528 NL80211_TX_POWER_AUTOMATIC,
529 NL80211_TX_POWER_FIXED),
530 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
531 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
532 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
533 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
534 .len = IEEE80211_MAX_MESH_ID_LEN },
535 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
537 /* allow 3 for NUL-termination, we used to declare this NLA_STRING */
538 [NL80211_ATTR_REG_ALPHA2] = NLA_POLICY_RANGE(NLA_BINARY, 2, 3),
539 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
541 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
542 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
543 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
544 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
545 .len = NL80211_MAX_SUPP_RATES },
546 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
548 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
549 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
551 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN),
553 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
554 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
556 IEEE80211_MAX_DATA_LEN),
557 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
558 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
560 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
561 .len = IEEE80211_MAX_SSID_LEN },
562 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
563 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
564 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
565 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
566 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
568 NL80211_MFP_OPTIONAL),
569 [NL80211_ATTR_STA_FLAGS2] =
570 NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_sta_flag_update)),
571 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
572 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
573 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
574 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
575 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
576 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
577 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
578 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
579 [NL80211_ATTR_PID] = { .type = NLA_U32 },
580 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
581 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN),
582 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
583 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
584 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
585 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
586 .len = IEEE80211_MAX_DATA_LEN },
587 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
588 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
591 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
592 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
593 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
594 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
595 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
596 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
597 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
598 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
599 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
600 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
601 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
602 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
603 [NL80211_ATTR_STA_PLINK_STATE] =
604 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
605 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
606 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
607 [NL80211_ATTR_MESH_PEER_AID] =
608 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
609 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
610 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
611 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
612 [NL80211_ATTR_HIDDEN_SSID] =
613 NLA_POLICY_RANGE(NLA_U32,
614 NL80211_HIDDEN_SSID_NOT_IN_USE,
615 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
616 [NL80211_ATTR_IE_PROBE_RESP] =
617 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
618 IEEE80211_MAX_DATA_LEN),
619 [NL80211_ATTR_IE_ASSOC_RESP] =
620 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
621 IEEE80211_MAX_DATA_LEN),
622 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
623 [NL80211_ATTR_STA_WME] = NLA_POLICY_NESTED(nl80211_sta_wme_policy),
624 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
625 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
626 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
627 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
628 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
629 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
630 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
631 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
632 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
633 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
634 .len = IEEE80211_MAX_DATA_LEN },
635 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
636 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
637 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
638 .len = NL80211_HT_CAPABILITY_LEN
640 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
641 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
642 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
643 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
644 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
646 /* need to include at least Auth Transaction and Status Code */
647 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4),
649 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN),
650 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
651 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
652 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
653 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
654 NLA_POLICY_RANGE(NLA_U32,
655 NL80211_MESH_POWER_UNKNOWN + 1,
656 NL80211_MESH_POWER_MAX),
657 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
658 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
659 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
660 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
661 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
662 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
663 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
664 .len = NL80211_VHT_CAPABILITY_LEN,
666 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
667 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
668 .len = IEEE80211_MAX_DATA_LEN },
669 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
670 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] =
671 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION),
672 [NL80211_ATTR_PEER_AID] =
673 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
674 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
675 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
676 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
677 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY },
678 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY },
679 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2),
681 * The value of the Length field of the Supported Operating
682 * Classes element is between 2 and 253.
684 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] =
685 NLA_POLICY_RANGE(NLA_BINARY, 2, 253),
686 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
687 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
688 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
689 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
690 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
691 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY,
692 IEEE80211_QOS_MAP_LEN_MIN,
693 IEEE80211_QOS_MAP_LEN_MAX),
694 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
695 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
696 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
697 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
698 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
699 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
700 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
701 [NL80211_ATTR_USER_PRIO] =
702 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
703 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
704 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
705 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
706 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
707 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
708 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
709 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
710 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
711 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
712 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
713 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
714 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
715 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
716 .len = VHT_MUMIMO_GROUPS_DATA_LEN
718 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
719 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
720 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
721 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
722 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
723 .len = FILS_MAX_KEK_LEN },
724 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN),
725 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
726 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
727 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
728 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
729 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
731 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
732 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
733 .len = FILS_ERP_MAX_USERNAME_LEN },
734 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
735 .len = FILS_ERP_MAX_REALM_LEN },
736 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
737 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
738 .len = FILS_ERP_MAX_RRK_LEN },
739 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2),
740 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
741 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN),
742 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
743 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
745 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
746 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
747 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
748 [NL80211_ATTR_HE_CAPABILITY] =
749 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_he_capa,
750 NL80211_HE_MAX_CAPABILITY_LEN),
751 [NL80211_ATTR_FTM_RESPONDER] =
752 NLA_POLICY_NESTED(nl80211_ftm_responder_policy),
753 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
754 [NL80211_ATTR_PEER_MEASUREMENTS] =
755 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
756 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
757 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
758 .len = SAE_PASSWORD_MAX_LEN },
759 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
760 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
761 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
762 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
763 [NL80211_ATTR_TID_CONFIG] =
764 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
765 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG },
766 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1),
767 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100),
768 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG },
769 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
770 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED },
771 [NL80211_ATTR_HE_6GHZ_CAPABILITY] =
772 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)),
773 [NL80211_ATTR_FILS_DISCOVERY] =
774 NLA_POLICY_NESTED(nl80211_fils_discovery_policy),
775 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] =
776 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy),
777 [NL80211_ATTR_S1G_CAPABILITY] =
778 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
779 [NL80211_ATTR_S1G_CAPABILITY_MASK] =
780 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
781 [NL80211_ATTR_SAE_PWE] =
782 NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK,
783 NL80211_SAE_PWE_BOTH),
784 [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT },
785 [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy),
786 [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG },
787 [NL80211_ATTR_OBSS_COLOR_BITMAP] = { .type = NLA_U64 },
788 [NL80211_ATTR_COLOR_CHANGE_COUNT] = { .type = NLA_U8 },
789 [NL80211_ATTR_COLOR_CHANGE_COLOR] = { .type = NLA_U8 },
790 [NL80211_ATTR_COLOR_CHANGE_ELEMS] = NLA_POLICY_NESTED(nl80211_policy),
791 [NL80211_ATTR_MBSSID_CONFIG] =
792 NLA_POLICY_NESTED(nl80211_mbssid_config_policy),
793 [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED },
794 [NL80211_ATTR_RADAR_BACKGROUND] = { .type = NLA_FLAG },
795 [NL80211_ATTR_AP_SETTINGS_FLAGS] = { .type = NLA_U32 },
796 [NL80211_ATTR_EHT_CAPABILITY] =
797 NLA_POLICY_RANGE(NLA_BINARY,
798 NL80211_EHT_MIN_CAPABILITY_LEN,
799 NL80211_EHT_MAX_CAPABILITY_LEN),
800 [NL80211_ATTR_DISABLE_EHT] = { .type = NLA_FLAG },
801 [NL80211_ATTR_MLO_LINKS] =
802 NLA_POLICY_NESTED_ARRAY(nl80211_policy),
803 [NL80211_ATTR_MLO_LINK_ID] =
804 NLA_POLICY_RANGE(NLA_U8, 0, IEEE80211_MLD_MAX_NUM_LINKS),
805 [NL80211_ATTR_MLD_ADDR] = NLA_POLICY_EXACT_LEN(ETH_ALEN),
806 [NL80211_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG },
807 [NL80211_ATTR_MAX_NUM_AKM_SUITES] = { .type = NLA_REJECT },
810 /* policy for the key attributes */
811 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
812 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
813 [NL80211_KEY_IDX] = { .type = NLA_U8 },
814 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
815 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
816 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
817 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
818 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
819 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
820 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
823 /* policy for the key default flags */
824 static const struct nla_policy
825 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
826 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
827 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
831 /* policy for WoWLAN attributes */
832 static const struct nla_policy
833 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
834 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
835 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
836 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
837 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
838 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
839 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
840 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
841 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
842 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
843 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
846 static const struct nla_policy
847 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
848 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
849 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
850 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
851 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
852 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
853 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
854 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
855 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
857 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
858 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
860 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
861 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
862 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1),
864 #endif /* CONFIG_PM */
866 /* policy for coalesce rule attributes */
867 static const struct nla_policy
868 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
869 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
870 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
871 NLA_POLICY_RANGE(NLA_U32,
872 NL80211_COALESCE_CONDITION_MATCH,
873 NL80211_COALESCE_CONDITION_NO_MATCH),
874 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
877 /* policy for GTK rekey offload attributes */
878 static const struct nla_policy
879 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
880 [NL80211_REKEY_DATA_KEK] = {
882 .len = NL80211_KEK_EXT_LEN
884 [NL80211_REKEY_DATA_KCK] = {
886 .len = NL80211_KCK_EXT_LEN
888 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN),
889 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 },
892 static const struct nla_policy
893 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
894 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
895 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
896 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
897 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
898 [NL80211_BAND_LC] = { .type = NLA_S32 },
901 static const struct nla_policy
902 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
903 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
904 .len = IEEE80211_MAX_SSID_LEN },
905 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
906 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
907 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
908 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
911 static const struct nla_policy
912 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
913 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
914 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
917 static const struct nla_policy
918 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
919 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
920 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
921 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
922 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
926 /* policy for NAN function attributes */
927 static const struct nla_policy
928 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
929 [NL80211_NAN_FUNC_TYPE] =
930 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE),
931 [NL80211_NAN_FUNC_SERVICE_ID] = {
932 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
933 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
934 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
935 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
936 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
937 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
938 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
939 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
940 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
941 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
942 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
943 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
944 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
945 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
946 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
947 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
950 /* policy for Service Response Filter attributes */
951 static const struct nla_policy
952 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
953 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
954 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
955 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
956 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
957 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
960 /* policy for packet pattern attributes */
961 static const struct nla_policy
962 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
963 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
964 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
965 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
968 static int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
969 struct cfg80211_registered_device **rdev,
970 struct wireless_dev **wdev,
971 struct nlattr **attrbuf)
976 struct nlattr **attrbuf_free = NULL;
979 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
983 attrbuf_free = attrbuf;
986 err = nlmsg_parse_deprecated(cb->nlh,
987 GENL_HDRLEN + nl80211_fam.hdrsize,
988 attrbuf, nl80211_fam.maxattr,
989 nl80211_policy, NULL);
996 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk),
1001 return PTR_ERR(*wdev);
1003 *rdev = wiphy_to_rdev((*wdev)->wiphy);
1004 mutex_lock(&(*rdev)->wiphy.mtx);
1006 /* 0 is the first index - add 1 to parse only once */
1007 cb->args[0] = (*rdev)->wiphy_idx + 1;
1008 cb->args[1] = (*wdev)->identifier;
1010 /* subtract the 1 again here */
1011 struct wiphy *wiphy;
1012 struct wireless_dev *tmp;
1015 wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
1020 *rdev = wiphy_to_rdev(wiphy);
1023 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
1024 if (tmp->identifier == cb->args[1]) {
1034 mutex_lock(&(*rdev)->wiphy.mtx);
1041 /* message building helper */
1042 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
1045 /* since there is no private header just add the generic one */
1046 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
1049 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
1050 const struct ieee80211_reg_rule *rule)
1053 struct nlattr *nl_wmm_rules =
1054 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
1057 goto nla_put_failure;
1059 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
1060 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
1063 goto nla_put_failure;
1065 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
1066 rule->wmm_rule.client[j].cw_min) ||
1067 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
1068 rule->wmm_rule.client[j].cw_max) ||
1069 nla_put_u8(msg, NL80211_WMMR_AIFSN,
1070 rule->wmm_rule.client[j].aifsn) ||
1071 nla_put_u16(msg, NL80211_WMMR_TXOP,
1072 rule->wmm_rule.client[j].cot))
1073 goto nla_put_failure;
1075 nla_nest_end(msg, nl_wmm_rule);
1077 nla_nest_end(msg, nl_wmm_rules);
1085 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
1086 struct ieee80211_channel *chan,
1089 /* Some channels must be completely excluded from the
1090 * list to protect old user-space tools from breaking
1092 if (!large && chan->flags &
1093 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
1095 if (!large && chan->freq_offset)
1098 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
1100 goto nla_put_failure;
1102 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
1103 goto nla_put_failure;
1105 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
1106 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
1107 goto nla_put_failure;
1108 if (chan->flags & IEEE80211_CHAN_NO_IR) {
1109 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
1110 goto nla_put_failure;
1111 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
1112 goto nla_put_failure;
1114 if (chan->flags & IEEE80211_CHAN_RADAR) {
1115 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
1116 goto nla_put_failure;
1120 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
1122 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
1124 goto nla_put_failure;
1125 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
1127 goto nla_put_failure;
1128 if (nla_put_u32(msg,
1129 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
1131 goto nla_put_failure;
1136 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
1137 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
1138 goto nla_put_failure;
1139 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
1140 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
1141 goto nla_put_failure;
1142 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
1143 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
1144 goto nla_put_failure;
1145 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
1146 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
1147 goto nla_put_failure;
1148 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
1149 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
1150 goto nla_put_failure;
1151 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
1152 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
1153 goto nla_put_failure;
1154 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
1155 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
1156 goto nla_put_failure;
1157 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
1158 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
1159 goto nla_put_failure;
1160 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
1161 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
1162 goto nla_put_failure;
1163 if ((chan->flags & IEEE80211_CHAN_1MHZ) &&
1164 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ))
1165 goto nla_put_failure;
1166 if ((chan->flags & IEEE80211_CHAN_2MHZ) &&
1167 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ))
1168 goto nla_put_failure;
1169 if ((chan->flags & IEEE80211_CHAN_4MHZ) &&
1170 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ))
1171 goto nla_put_failure;
1172 if ((chan->flags & IEEE80211_CHAN_8MHZ) &&
1173 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ))
1174 goto nla_put_failure;
1175 if ((chan->flags & IEEE80211_CHAN_16MHZ) &&
1176 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ))
1177 goto nla_put_failure;
1178 if ((chan->flags & IEEE80211_CHAN_NO_320MHZ) &&
1179 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_320MHZ))
1180 goto nla_put_failure;
1181 if ((chan->flags & IEEE80211_CHAN_NO_EHT) &&
1182 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_EHT))
1183 goto nla_put_failure;
1186 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
1187 DBM_TO_MBM(chan->max_power)))
1188 goto nla_put_failure;
1191 const struct ieee80211_reg_rule *rule =
1192 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
1194 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
1195 if (nl80211_msg_put_wmm_rules(msg, rule))
1196 goto nla_put_failure;
1206 static bool nl80211_put_txq_stats(struct sk_buff *msg,
1207 struct cfg80211_txq_stats *txqstats,
1210 struct nlattr *txqattr;
1212 #define PUT_TXQVAL_U32(attr, memb) do { \
1213 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1214 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1218 txqattr = nla_nest_start_noflag(msg, attrtype);
1222 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1223 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1224 PUT_TXQVAL_U32(FLOWS, flows);
1225 PUT_TXQVAL_U32(DROPS, drops);
1226 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1227 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1228 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1229 PUT_TXQVAL_U32(COLLISIONS, collisions);
1230 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1231 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1232 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1233 nla_nest_end(msg, txqattr);
1235 #undef PUT_TXQVAL_U32
1239 /* netlink command implementations */
1242 * nl80211_link_id - return link ID
1243 * @attrs: attributes to look at
1245 * Returns: the link ID or 0 if not given
1247 * Note this function doesn't do any validation of the link
1248 * ID validity wrt. links that were actually added, so it must
1249 * be called only from ops with %NL80211_FLAG_MLO_VALID_LINK_ID
1250 * or if additional validation is done.
1252 static unsigned int nl80211_link_id(struct nlattr **attrs)
1254 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID];
1259 return nla_get_u8(linkid);
1262 static int nl80211_link_id_or_invalid(struct nlattr **attrs)
1264 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID];
1269 return nla_get_u8(linkid);
1273 struct key_params p;
1276 bool def, defmgmt, defbeacon;
1277 bool def_uni, def_multi;
1280 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1281 struct key_parse *k)
1283 struct nlattr *tb[NL80211_KEY_MAX + 1];
1284 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1290 k->def = !!tb[NL80211_KEY_DEFAULT];
1291 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1292 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
1296 k->def_multi = true;
1298 if (k->defmgmt || k->defbeacon)
1299 k->def_multi = true;
1301 if (tb[NL80211_KEY_IDX])
1302 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1304 if (tb[NL80211_KEY_DATA]) {
1305 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1306 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1309 if (tb[NL80211_KEY_SEQ]) {
1310 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1311 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1314 if (tb[NL80211_KEY_CIPHER])
1315 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1317 if (tb[NL80211_KEY_TYPE])
1318 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
1320 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1321 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1323 err = nla_parse_nested_deprecated(kdt,
1324 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1325 tb[NL80211_KEY_DEFAULT_TYPES],
1326 nl80211_key_default_policy,
1331 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1332 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1335 if (tb[NL80211_KEY_MODE])
1336 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1341 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1343 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1344 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1345 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1348 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1349 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1350 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1353 if (info->attrs[NL80211_ATTR_KEY_IDX])
1354 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1356 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1357 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1359 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1360 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1364 k->def_multi = true;
1367 k->def_multi = true;
1369 if (info->attrs[NL80211_ATTR_KEY_TYPE])
1370 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1372 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1373 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1374 int err = nla_parse_nested_deprecated(kdt,
1375 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1376 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1377 nl80211_key_default_policy,
1382 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1383 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1389 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1393 memset(k, 0, sizeof(*k));
1397 if (info->attrs[NL80211_ATTR_KEY])
1398 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
1400 err = nl80211_parse_key_old(info, k);
1405 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1406 (k->defbeacon ? 1 : 0) > 1) {
1407 GENL_SET_ERR_MSG(info,
1408 "key with multiple default flags is invalid");
1412 if (k->defmgmt || k->defbeacon) {
1413 if (k->def_uni || !k->def_multi) {
1414 GENL_SET_ERR_MSG(info,
1415 "defmgmt/defbeacon key must be mcast");
1422 if (k->idx < 4 || k->idx > 5) {
1423 GENL_SET_ERR_MSG(info,
1424 "defmgmt key idx not 4 or 5");
1427 } else if (k->defbeacon) {
1428 if (k->idx < 6 || k->idx > 7) {
1429 GENL_SET_ERR_MSG(info,
1430 "defbeacon key idx not 6 or 7");
1433 } else if (k->def) {
1434 if (k->idx < 0 || k->idx > 3) {
1435 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
1439 if (k->idx < 0 || k->idx > 7) {
1440 GENL_SET_ERR_MSG(info, "key idx not 0-7");
1449 static struct cfg80211_cached_keys *
1450 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
1451 struct genl_info *info, bool *no_ht)
1453 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
1454 struct key_parse parse;
1456 struct cfg80211_cached_keys *result;
1457 int rem, err, def = 0;
1458 bool have_key = false;
1460 nla_for_each_nested(key, keys, rem) {
1468 result = kzalloc(sizeof(*result), GFP_KERNEL);
1470 return ERR_PTR(-ENOMEM);
1474 nla_for_each_nested(key, keys, rem) {
1475 memset(&parse, 0, sizeof(parse));
1478 err = nl80211_parse_key_new(info, key, &parse);
1484 if (parse.idx < 0 || parse.idx > 3) {
1485 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
1490 GENL_SET_ERR_MSG(info,
1491 "only one key can be default");
1495 result->def = parse.idx;
1496 if (!parse.def_uni || !parse.def_multi)
1498 } else if (parse.defmgmt)
1500 err = cfg80211_validate_key_settings(rdev, &parse.p,
1501 parse.idx, false, NULL);
1504 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1505 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
1506 GENL_SET_ERR_MSG(info, "connect key must be WEP");
1510 result->params[parse.idx].cipher = parse.p.cipher;
1511 result->params[parse.idx].key_len = parse.p.key_len;
1512 result->params[parse.idx].key = result->data[parse.idx];
1513 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
1515 /* must be WEP key if we got here */
1520 if (result->def < 0) {
1522 GENL_SET_ERR_MSG(info, "need a default/TX key");
1529 return ERR_PTR(err);
1532 static int nl80211_key_allowed(struct wireless_dev *wdev)
1534 ASSERT_WDEV_LOCK(wdev);
1536 switch (wdev->iftype) {
1537 case NL80211_IFTYPE_AP:
1538 case NL80211_IFTYPE_AP_VLAN:
1539 case NL80211_IFTYPE_P2P_GO:
1540 case NL80211_IFTYPE_MESH_POINT:
1542 case NL80211_IFTYPE_ADHOC:
1543 if (wdev->u.ibss.current_bss)
1546 case NL80211_IFTYPE_STATION:
1547 case NL80211_IFTYPE_P2P_CLIENT:
1548 if (wdev->connected)
1551 case NL80211_IFTYPE_UNSPECIFIED:
1552 case NL80211_IFTYPE_OCB:
1553 case NL80211_IFTYPE_MONITOR:
1554 case NL80211_IFTYPE_NAN:
1555 case NL80211_IFTYPE_P2P_DEVICE:
1556 case NL80211_IFTYPE_WDS:
1557 case NUM_NL80211_IFTYPES:
1564 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1567 struct ieee80211_channel *chan;
1569 chan = ieee80211_get_channel_khz(wiphy, freq);
1570 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1575 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1577 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
1581 goto nla_put_failure;
1585 if ((ifmodes & 1) && nla_put_flag(msg, i))
1586 goto nla_put_failure;
1591 nla_nest_end(msg, nl_modes);
1598 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1599 struct sk_buff *msg,
1602 struct nlattr *nl_combis;
1605 nl_combis = nla_nest_start_noflag(msg,
1606 NL80211_ATTR_INTERFACE_COMBINATIONS);
1608 goto nla_put_failure;
1610 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1611 const struct ieee80211_iface_combination *c;
1612 struct nlattr *nl_combi, *nl_limits;
1614 c = &wiphy->iface_combinations[i];
1616 nl_combi = nla_nest_start_noflag(msg, i + 1);
1618 goto nla_put_failure;
1620 nl_limits = nla_nest_start_noflag(msg,
1621 NL80211_IFACE_COMB_LIMITS);
1623 goto nla_put_failure;
1625 for (j = 0; j < c->n_limits; j++) {
1626 struct nlattr *nl_limit;
1628 nl_limit = nla_nest_start_noflag(msg, j + 1);
1630 goto nla_put_failure;
1631 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1633 goto nla_put_failure;
1634 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1635 c->limits[j].types))
1636 goto nla_put_failure;
1637 nla_nest_end(msg, nl_limit);
1640 nla_nest_end(msg, nl_limits);
1642 if (c->beacon_int_infra_match &&
1643 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1644 goto nla_put_failure;
1645 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1646 c->num_different_channels) ||
1647 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1649 goto nla_put_failure;
1651 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1652 c->radar_detect_widths) ||
1653 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1654 c->radar_detect_regions)))
1655 goto nla_put_failure;
1656 if (c->beacon_int_min_gcd &&
1657 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1658 c->beacon_int_min_gcd))
1659 goto nla_put_failure;
1661 nla_nest_end(msg, nl_combi);
1664 nla_nest_end(msg, nl_combis);
1672 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1673 struct sk_buff *msg)
1675 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
1676 struct nlattr *nl_tcp;
1681 nl_tcp = nla_nest_start_noflag(msg,
1682 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1686 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1687 tcp->data_payload_max))
1690 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1691 tcp->data_payload_max))
1694 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1697 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1698 sizeof(*tcp->tok), tcp->tok))
1701 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1702 tcp->data_interval_max))
1705 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1706 tcp->wake_payload_max))
1709 nla_nest_end(msg, nl_tcp);
1713 static int nl80211_send_wowlan(struct sk_buff *msg,
1714 struct cfg80211_registered_device *rdev,
1717 struct nlattr *nl_wowlan;
1719 if (!rdev->wiphy.wowlan)
1722 nl_wowlan = nla_nest_start_noflag(msg,
1723 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1727 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
1728 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1729 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
1730 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1731 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1732 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1733 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1734 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1735 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1736 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1737 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1738 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1739 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1740 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1741 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1742 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1745 if (rdev->wiphy.wowlan->n_patterns) {
1746 struct nl80211_pattern_support pat = {
1747 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1748 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1749 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1750 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
1753 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1758 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1759 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1760 rdev->wiphy.wowlan->max_nd_match_sets))
1763 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
1766 nla_nest_end(msg, nl_wowlan);
1772 static int nl80211_send_coalesce(struct sk_buff *msg,
1773 struct cfg80211_registered_device *rdev)
1775 struct nl80211_coalesce_rule_support rule;
1777 if (!rdev->wiphy.coalesce)
1780 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1781 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1782 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1783 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1784 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1785 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
1787 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1794 nl80211_send_iftype_data(struct sk_buff *msg,
1795 const struct ieee80211_supported_band *sband,
1796 const struct ieee80211_sband_iftype_data *iftdata)
1798 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1799 const struct ieee80211_sta_eht_cap *eht_cap = &iftdata->eht_cap;
1801 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1802 iftdata->types_mask))
1805 if (he_cap->has_he) {
1806 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1807 sizeof(he_cap->he_cap_elem.mac_cap_info),
1808 he_cap->he_cap_elem.mac_cap_info) ||
1809 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1810 sizeof(he_cap->he_cap_elem.phy_cap_info),
1811 he_cap->he_cap_elem.phy_cap_info) ||
1812 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1813 sizeof(he_cap->he_mcs_nss_supp),
1814 &he_cap->he_mcs_nss_supp) ||
1815 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1816 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1820 if (eht_cap->has_eht && he_cap->has_he) {
1821 u8 mcs_nss_size, ppe_thresh_size;
1825 is_ap = iftdata->types_mask & BIT(NL80211_IFTYPE_AP) ||
1826 iftdata->types_mask & BIT(NL80211_IFTYPE_P2P_GO);
1829 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
1830 &eht_cap->eht_cap_elem,
1833 ppe_thres_hdr = get_unaligned_le16(&eht_cap->eht_ppe_thres[0]);
1835 ieee80211_eht_ppe_size(ppe_thres_hdr,
1836 eht_cap->eht_cap_elem.phy_cap_info);
1838 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC,
1839 sizeof(eht_cap->eht_cap_elem.mac_cap_info),
1840 eht_cap->eht_cap_elem.mac_cap_info) ||
1841 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY,
1842 sizeof(eht_cap->eht_cap_elem.phy_cap_info),
1843 eht_cap->eht_cap_elem.phy_cap_info) ||
1844 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET,
1845 mcs_nss_size, &eht_cap->eht_mcs_nss_supp) ||
1846 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE,
1847 ppe_thresh_size, eht_cap->eht_ppe_thres))
1851 if (sband->band == NL80211_BAND_6GHZ &&
1852 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA,
1853 sizeof(iftdata->he_6ghz_capa),
1854 &iftdata->he_6ghz_capa))
1857 if (iftdata->vendor_elems.data && iftdata->vendor_elems.len &&
1858 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS,
1859 iftdata->vendor_elems.len, iftdata->vendor_elems.data))
1865 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1866 struct ieee80211_supported_band *sband,
1869 struct nlattr *nl_rates, *nl_rate;
1870 struct ieee80211_rate *rate;
1874 if (sband->ht_cap.ht_supported &&
1875 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1876 sizeof(sband->ht_cap.mcs),
1877 &sband->ht_cap.mcs) ||
1878 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1879 sband->ht_cap.cap) ||
1880 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1881 sband->ht_cap.ampdu_factor) ||
1882 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1883 sband->ht_cap.ampdu_density)))
1887 if (sband->vht_cap.vht_supported &&
1888 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1889 sizeof(sband->vht_cap.vht_mcs),
1890 &sband->vht_cap.vht_mcs) ||
1891 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1892 sband->vht_cap.cap)))
1895 if (large && sband->n_iftype_data) {
1896 struct nlattr *nl_iftype_data =
1897 nla_nest_start_noflag(msg,
1898 NL80211_BAND_ATTR_IFTYPE_DATA);
1901 if (!nl_iftype_data)
1904 for (i = 0; i < sband->n_iftype_data; i++) {
1905 struct nlattr *iftdata;
1907 iftdata = nla_nest_start_noflag(msg, i + 1);
1911 err = nl80211_send_iftype_data(msg, sband,
1912 &sband->iftype_data[i]);
1916 nla_nest_end(msg, iftdata);
1919 nla_nest_end(msg, nl_iftype_data);
1923 if (large && sband->edmg_cap.channels &&
1924 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1925 sband->edmg_cap.channels) ||
1926 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1927 sband->edmg_cap.bw_config)))
1932 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
1936 for (i = 0; i < sband->n_bitrates; i++) {
1937 nl_rate = nla_nest_start_noflag(msg, i);
1941 rate = &sband->bitrates[i];
1942 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1945 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1947 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1950 nla_nest_end(msg, nl_rate);
1953 nla_nest_end(msg, nl_rates);
1959 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1960 const struct ieee80211_txrx_stypes *mgmt_stypes)
1963 struct nlattr *nl_ftypes, *nl_ifs;
1964 enum nl80211_iftype ift;
1970 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
1974 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1975 nl_ftypes = nla_nest_start_noflag(msg, ift);
1979 stypes = mgmt_stypes[ift].tx;
1982 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1983 (i << 4) | IEEE80211_FTYPE_MGMT))
1988 nla_nest_end(msg, nl_ftypes);
1991 nla_nest_end(msg, nl_ifs);
1993 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
1997 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1998 nl_ftypes = nla_nest_start_noflag(msg, ift);
2002 stypes = mgmt_stypes[ift].rx;
2005 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
2006 (i << 4) | IEEE80211_FTYPE_MGMT))
2011 nla_nest_end(msg, nl_ftypes);
2013 nla_nest_end(msg, nl_ifs);
2018 #define CMD(op, n) \
2020 if (rdev->ops->op) { \
2022 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
2023 goto nla_put_failure; \
2027 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
2028 struct sk_buff *msg)
2033 * do *NOT* add anything into this function, new things need to be
2034 * advertised only to new versions of userspace that can deal with
2035 * the split (and they can't possibly care about new features...
2037 CMD(add_virtual_intf, NEW_INTERFACE);
2038 CMD(change_virtual_intf, SET_INTERFACE);
2039 CMD(add_key, NEW_KEY);
2040 CMD(start_ap, START_AP);
2041 CMD(add_station, NEW_STATION);
2042 CMD(add_mpath, NEW_MPATH);
2043 CMD(update_mesh_config, SET_MESH_CONFIG);
2044 CMD(change_bss, SET_BSS);
2045 CMD(auth, AUTHENTICATE);
2046 CMD(assoc, ASSOCIATE);
2047 CMD(deauth, DEAUTHENTICATE);
2048 CMD(disassoc, DISASSOCIATE);
2049 CMD(join_ibss, JOIN_IBSS);
2050 CMD(join_mesh, JOIN_MESH);
2051 CMD(set_pmksa, SET_PMKSA);
2052 CMD(del_pmksa, DEL_PMKSA);
2053 CMD(flush_pmksa, FLUSH_PMKSA);
2054 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
2055 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
2056 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
2057 CMD(mgmt_tx, FRAME);
2058 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
2059 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
2061 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
2062 goto nla_put_failure;
2064 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
2065 rdev->ops->join_mesh) {
2067 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
2068 goto nla_put_failure;
2070 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2071 CMD(tdls_mgmt, TDLS_MGMT);
2072 CMD(tdls_oper, TDLS_OPER);
2074 if (rdev->wiphy.max_sched_scan_reqs)
2075 CMD(sched_scan_start, START_SCHED_SCAN);
2076 CMD(probe_client, PROBE_CLIENT);
2077 CMD(set_noack_map, SET_NOACK_MAP);
2078 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
2080 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
2081 goto nla_put_failure;
2083 CMD(start_p2p_device, START_P2P_DEVICE);
2084 CMD(set_mcast_rate, SET_MCAST_RATE);
2085 #ifdef CONFIG_NL80211_TESTMODE
2086 CMD(testmode_cmd, TESTMODE);
2089 if (rdev->ops->connect || rdev->ops->auth) {
2091 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
2092 goto nla_put_failure;
2095 if (rdev->ops->disconnect || rdev->ops->deauth) {
2097 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
2098 goto nla_put_failure;
2107 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
2108 struct sk_buff *msg)
2112 if (!cap->ftm.supported)
2115 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
2119 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
2121 if (cap->ftm.non_asap &&
2122 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
2124 if (cap->ftm.request_lci &&
2125 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
2127 if (cap->ftm.request_civicloc &&
2128 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
2130 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
2131 cap->ftm.preambles))
2133 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
2134 cap->ftm.bandwidths))
2136 if (cap->ftm.max_bursts_exponent >= 0 &&
2137 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
2138 cap->ftm.max_bursts_exponent))
2140 if (cap->ftm.max_ftms_per_burst &&
2141 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
2142 cap->ftm.max_ftms_per_burst))
2144 if (cap->ftm.trigger_based &&
2145 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED))
2147 if (cap->ftm.non_trigger_based &&
2148 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED))
2151 nla_nest_end(msg, ftm);
2155 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
2156 struct sk_buff *msg)
2158 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
2159 struct nlattr *pmsr, *caps;
2165 * we don't need to clean up anything here since the caller
2166 * will genlmsg_cancel() if we fail
2169 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
2173 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
2176 if (cap->report_ap_tsf &&
2177 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
2180 if (cap->randomize_mac_addr &&
2181 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
2184 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
2188 if (nl80211_send_pmsr_ftm_capa(cap, msg))
2191 nla_nest_end(msg, caps);
2192 nla_nest_end(msg, pmsr);
2198 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev,
2199 struct sk_buff *msg)
2202 struct nlattr *nested, *nested_akms;
2203 const struct wiphy_iftype_akm_suites *iftype_akms;
2205 if (!rdev->wiphy.num_iftype_akm_suites ||
2206 !rdev->wiphy.iftype_akm_suites)
2209 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES);
2213 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) {
2214 nested_akms = nla_nest_start(msg, i + 1);
2218 iftype_akms = &rdev->wiphy.iftype_akm_suites[i];
2220 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES,
2221 iftype_akms->iftypes_mask))
2224 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES,
2225 sizeof(u32) * iftype_akms->n_akm_suites,
2226 iftype_akms->akm_suites)) {
2229 nla_nest_end(msg, nested_akms);
2232 nla_nest_end(msg, nested);
2238 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev,
2239 struct sk_buff *msg)
2241 struct nlattr *supp;
2243 if (!rdev->wiphy.tid_config_support.vif &&
2244 !rdev->wiphy.tid_config_support.peer)
2247 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG);
2251 if (rdev->wiphy.tid_config_support.vif &&
2252 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP,
2253 rdev->wiphy.tid_config_support.vif,
2254 NL80211_TID_CONFIG_ATTR_PAD))
2257 if (rdev->wiphy.tid_config_support.peer &&
2258 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP,
2259 rdev->wiphy.tid_config_support.peer,
2260 NL80211_TID_CONFIG_ATTR_PAD))
2263 /* for now we just use the same value ... makes more sense */
2264 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT,
2265 rdev->wiphy.tid_config_support.max_retry))
2267 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG,
2268 rdev->wiphy.tid_config_support.max_retry))
2271 nla_nest_end(msg, supp);
2275 nla_nest_cancel(msg, supp);
2280 nl80211_put_sar_specs(struct cfg80211_registered_device *rdev,
2281 struct sk_buff *msg)
2283 struct nlattr *sar_capa, *specs, *sub_freq_range;
2287 if (!rdev->wiphy.sar_capa)
2290 num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges;
2292 sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC);
2296 if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type))
2299 specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS);
2303 /* report supported freq_ranges */
2304 for (i = 0; i < num_freq_ranges; i++) {
2305 sub_freq_range = nla_nest_start(msg, i + 1);
2306 if (!sub_freq_range)
2309 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ,
2310 rdev->wiphy.sar_capa->freq_ranges[i].start_freq))
2313 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ,
2314 rdev->wiphy.sar_capa->freq_ranges[i].end_freq))
2317 nla_nest_end(msg, sub_freq_range);
2320 nla_nest_end(msg, specs);
2321 nla_nest_end(msg, sar_capa);
2325 nla_nest_cancel(msg, sar_capa);
2329 static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg)
2331 struct nlattr *config;
2333 if (!wiphy->mbssid_max_interfaces)
2336 config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG);
2340 if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES,
2341 wiphy->mbssid_max_interfaces))
2344 if (wiphy->ema_max_profile_periodicity &&
2346 NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY,
2347 wiphy->ema_max_profile_periodicity))
2350 nla_nest_end(msg, config);
2354 nla_nest_cancel(msg, config);
2358 struct nl80211_dump_wiphy_state {
2361 long split_start, band_start, chan_start, capa_start;
2365 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2366 enum nl80211_commands cmd,
2367 struct sk_buff *msg, u32 portid, u32 seq,
2368 int flags, struct nl80211_dump_wiphy_state *state)
2371 struct nlattr *nl_bands, *nl_band;
2372 struct nlattr *nl_freqs, *nl_freq;
2373 struct nlattr *nl_cmds;
2374 enum nl80211_band band;
2375 struct ieee80211_channel *chan;
2377 const struct ieee80211_txrx_stypes *mgmt_stypes =
2378 rdev->wiphy.mgmt_stypes;
2381 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
2385 if (WARN_ON(!state))
2388 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2389 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
2390 wiphy_name(&rdev->wiphy)) ||
2391 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2392 cfg80211_rdev_list_generation))
2393 goto nla_put_failure;
2395 if (cmd != NL80211_CMD_NEW_WIPHY)
2398 switch (state->split_start) {
2400 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
2401 rdev->wiphy.retry_short) ||
2402 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
2403 rdev->wiphy.retry_long) ||
2404 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
2405 rdev->wiphy.frag_threshold) ||
2406 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
2407 rdev->wiphy.rts_threshold) ||
2408 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
2409 rdev->wiphy.coverage_class) ||
2410 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
2411 rdev->wiphy.max_scan_ssids) ||
2412 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
2413 rdev->wiphy.max_sched_scan_ssids) ||
2414 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
2415 rdev->wiphy.max_scan_ie_len) ||
2416 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
2417 rdev->wiphy.max_sched_scan_ie_len) ||
2418 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
2419 rdev->wiphy.max_match_sets))
2420 goto nla_put_failure;
2422 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
2423 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2424 goto nla_put_failure;
2425 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
2426 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2427 goto nla_put_failure;
2428 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2429 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2430 goto nla_put_failure;
2431 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
2432 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2433 goto nla_put_failure;
2434 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2435 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2436 goto nla_put_failure;
2437 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
2438 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
2439 goto nla_put_failure;
2440 state->split_start++;
2445 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
2446 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2447 rdev->wiphy.cipher_suites))
2448 goto nla_put_failure;
2450 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
2451 rdev->wiphy.max_num_pmkids))
2452 goto nla_put_failure;
2454 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
2455 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2456 goto nla_put_failure;
2458 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
2459 rdev->wiphy.available_antennas_tx) ||
2460 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
2461 rdev->wiphy.available_antennas_rx))
2462 goto nla_put_failure;
2464 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
2465 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
2466 rdev->wiphy.probe_resp_offload))
2467 goto nla_put_failure;
2469 if ((rdev->wiphy.available_antennas_tx ||
2470 rdev->wiphy.available_antennas_rx) &&
2471 rdev->ops->get_antenna) {
2472 u32 tx_ant = 0, rx_ant = 0;
2475 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
2477 if (nla_put_u32(msg,
2478 NL80211_ATTR_WIPHY_ANTENNA_TX,
2481 NL80211_ATTR_WIPHY_ANTENNA_RX,
2483 goto nla_put_failure;
2487 state->split_start++;
2492 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
2493 rdev->wiphy.interface_modes))
2494 goto nla_put_failure;
2495 state->split_start++;
2500 nl_bands = nla_nest_start_noflag(msg,
2501 NL80211_ATTR_WIPHY_BANDS);
2503 goto nla_put_failure;
2505 for (band = state->band_start;
2506 band < (state->split ?
2508 NL80211_BAND_60GHZ + 1);
2510 struct ieee80211_supported_band *sband;
2512 /* omit higher bands for ancient software */
2513 if (band > NL80211_BAND_5GHZ && !state->split)
2516 sband = rdev->wiphy.bands[band];
2521 nl_band = nla_nest_start_noflag(msg, band);
2523 goto nla_put_failure;
2525 switch (state->chan_start) {
2527 if (nl80211_send_band_rateinfo(msg, sband,
2529 goto nla_put_failure;
2530 state->chan_start++;
2535 /* add frequencies */
2536 nl_freqs = nla_nest_start_noflag(msg,
2537 NL80211_BAND_ATTR_FREQS);
2539 goto nla_put_failure;
2541 for (i = state->chan_start - 1;
2542 i < sband->n_channels;
2544 nl_freq = nla_nest_start_noflag(msg,
2547 goto nla_put_failure;
2549 chan = &sband->channels[i];
2551 if (nl80211_msg_put_channel(
2552 msg, &rdev->wiphy, chan,
2554 goto nla_put_failure;
2556 nla_nest_end(msg, nl_freq);
2560 if (i < sband->n_channels)
2561 state->chan_start = i + 2;
2563 state->chan_start = 0;
2564 nla_nest_end(msg, nl_freqs);
2567 nla_nest_end(msg, nl_band);
2570 /* start again here */
2571 if (state->chan_start)
2576 nla_nest_end(msg, nl_bands);
2578 if (band < NUM_NL80211_BANDS)
2579 state->band_start = band + 1;
2581 state->band_start = 0;
2583 /* if bands & channels are done, continue outside */
2584 if (state->band_start == 0 && state->chan_start == 0)
2585 state->split_start++;
2590 nl_cmds = nla_nest_start_noflag(msg,
2591 NL80211_ATTR_SUPPORTED_COMMANDS);
2593 goto nla_put_failure;
2595 i = nl80211_add_commands_unsplit(rdev, msg);
2597 goto nla_put_failure;
2599 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2600 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
2601 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
2602 CMD(channel_switch, CHANNEL_SWITCH);
2603 CMD(set_qos_map, SET_QOS_MAP);
2604 if (rdev->wiphy.features &
2605 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
2606 CMD(add_tx_ts, ADD_TX_TS);
2607 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
2608 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
2609 CMD(update_ft_ies, UPDATE_FT_IES);
2610 if (rdev->wiphy.sar_capa)
2611 CMD(set_sar_specs, SET_SAR_SPECS);
2615 nla_nest_end(msg, nl_cmds);
2616 state->split_start++;
2621 if (rdev->ops->remain_on_channel &&
2622 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
2624 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
2625 rdev->wiphy.max_remain_on_channel_duration))
2626 goto nla_put_failure;
2628 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
2629 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2630 goto nla_put_failure;
2632 state->split_start++;
2638 if (nl80211_send_wowlan(msg, rdev, state->split))
2639 goto nla_put_failure;
2640 state->split_start++;
2644 state->split_start++;
2648 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
2649 rdev->wiphy.software_iftypes))
2650 goto nla_put_failure;
2652 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
2654 goto nla_put_failure;
2656 state->split_start++;
2661 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
2662 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
2663 rdev->wiphy.ap_sme_capa))
2664 goto nla_put_failure;
2666 features = rdev->wiphy.features;
2668 * We can only add the per-channel limit information if the
2669 * dump is split, otherwise it makes it too big. Therefore
2670 * only advertise it in that case.
2673 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2674 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
2675 goto nla_put_failure;
2677 if (rdev->wiphy.ht_capa_mod_mask &&
2678 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
2679 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2680 rdev->wiphy.ht_capa_mod_mask))
2681 goto nla_put_failure;
2683 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2684 rdev->wiphy.max_acl_mac_addrs &&
2685 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
2686 rdev->wiphy.max_acl_mac_addrs))
2687 goto nla_put_failure;
2690 * Any information below this point is only available to
2691 * applications that can deal with it being split. This
2692 * helps ensure that newly added capabilities don't break
2693 * older tools by overrunning their buffers.
2695 * We still increment split_start so that in the split
2696 * case we'll continue with more data in the next round,
2697 * but break unconditionally so unsplit data stops here.
2700 state->split_start++;
2702 state->split_start = 0;
2705 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2706 goto nla_put_failure;
2708 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
2709 rdev->wiphy.max_sched_scan_plans) ||
2710 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
2711 rdev->wiphy.max_sched_scan_plan_interval) ||
2712 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
2713 rdev->wiphy.max_sched_scan_plan_iterations))
2714 goto nla_put_failure;
2716 if (rdev->wiphy.extended_capabilities &&
2717 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
2718 rdev->wiphy.extended_capabilities_len,
2719 rdev->wiphy.extended_capabilities) ||
2720 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2721 rdev->wiphy.extended_capabilities_len,
2722 rdev->wiphy.extended_capabilities_mask)))
2723 goto nla_put_failure;
2725 if (rdev->wiphy.vht_capa_mod_mask &&
2726 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
2727 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2728 rdev->wiphy.vht_capa_mod_mask))
2729 goto nla_put_failure;
2731 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2732 rdev->wiphy.perm_addr))
2733 goto nla_put_failure;
2735 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2736 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2737 rdev->wiphy.addr_mask))
2738 goto nla_put_failure;
2740 if (rdev->wiphy.n_addresses > 1) {
2743 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2745 goto nla_put_failure;
2747 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2748 if (nla_put(msg, i + 1, ETH_ALEN,
2749 rdev->wiphy.addresses[i].addr))
2750 goto nla_put_failure;
2752 nla_nest_end(msg, attr);
2755 state->split_start++;
2758 if (nl80211_send_coalesce(msg, rdev))
2759 goto nla_put_failure;
2761 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
2762 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2763 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2764 goto nla_put_failure;
2766 if (rdev->wiphy.max_ap_assoc_sta &&
2767 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
2768 rdev->wiphy.max_ap_assoc_sta))
2769 goto nla_put_failure;
2771 state->split_start++;
2774 if (rdev->wiphy.n_vendor_commands) {
2775 const struct nl80211_vendor_cmd_info *info;
2776 struct nlattr *nested;
2778 nested = nla_nest_start_noflag(msg,
2779 NL80211_ATTR_VENDOR_DATA);
2781 goto nla_put_failure;
2783 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2784 info = &rdev->wiphy.vendor_commands[i].info;
2785 if (nla_put(msg, i + 1, sizeof(*info), info))
2786 goto nla_put_failure;
2788 nla_nest_end(msg, nested);
2791 if (rdev->wiphy.n_vendor_events) {
2792 const struct nl80211_vendor_cmd_info *info;
2793 struct nlattr *nested;
2795 nested = nla_nest_start_noflag(msg,
2796 NL80211_ATTR_VENDOR_EVENTS);
2798 goto nla_put_failure;
2800 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2801 info = &rdev->wiphy.vendor_events[i];
2802 if (nla_put(msg, i + 1, sizeof(*info), info))
2803 goto nla_put_failure;
2805 nla_nest_end(msg, nested);
2807 state->split_start++;
2810 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2811 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2812 rdev->wiphy.max_num_csa_counters))
2813 goto nla_put_failure;
2815 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2816 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2817 goto nla_put_failure;
2819 if (rdev->wiphy.max_sched_scan_reqs &&
2820 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2821 rdev->wiphy.max_sched_scan_reqs))
2822 goto nla_put_failure;
2824 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2825 sizeof(rdev->wiphy.ext_features),
2826 rdev->wiphy.ext_features))
2827 goto nla_put_failure;
2829 if (rdev->wiphy.bss_select_support) {
2830 struct nlattr *nested;
2831 u32 bss_select_support = rdev->wiphy.bss_select_support;
2833 nested = nla_nest_start_noflag(msg,
2834 NL80211_ATTR_BSS_SELECT);
2836 goto nla_put_failure;
2839 while (bss_select_support) {
2840 if ((bss_select_support & 1) &&
2841 nla_put_flag(msg, i))
2842 goto nla_put_failure;
2844 bss_select_support >>= 1;
2846 nla_nest_end(msg, nested);
2849 state->split_start++;
2852 if (rdev->wiphy.num_iftype_ext_capab &&
2853 rdev->wiphy.iftype_ext_capab) {
2854 struct nlattr *nested_ext_capab, *nested;
2856 nested = nla_nest_start_noflag(msg,
2857 NL80211_ATTR_IFTYPE_EXT_CAPA);
2859 goto nla_put_failure;
2861 for (i = state->capa_start;
2862 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2863 const struct wiphy_iftype_ext_capab *capab;
2865 capab = &rdev->wiphy.iftype_ext_capab[i];
2867 nested_ext_capab = nla_nest_start_noflag(msg,
2869 if (!nested_ext_capab ||
2870 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2872 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2873 capab->extended_capabilities_len,
2874 capab->extended_capabilities) ||
2875 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2876 capab->extended_capabilities_len,
2877 capab->extended_capabilities_mask))
2878 goto nla_put_failure;
2880 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO &&
2882 NL80211_ATTR_EML_CAPABILITY,
2883 capab->eml_capabilities) ||
2885 NL80211_ATTR_MLD_CAPA_AND_OPS,
2886 capab->mld_capa_and_ops)))
2887 goto nla_put_failure;
2889 nla_nest_end(msg, nested_ext_capab);
2893 nla_nest_end(msg, nested);
2894 if (i < rdev->wiphy.num_iftype_ext_capab) {
2895 state->capa_start = i + 1;
2900 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2901 rdev->wiphy.nan_supported_bands))
2902 goto nla_put_failure;
2904 if (wiphy_ext_feature_isset(&rdev->wiphy,
2905 NL80211_EXT_FEATURE_TXQS)) {
2906 struct cfg80211_txq_stats txqstats = {};
2909 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2911 !nl80211_put_txq_stats(msg, &txqstats,
2912 NL80211_ATTR_TXQ_STATS))
2913 goto nla_put_failure;
2915 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2916 rdev->wiphy.txq_limit))
2917 goto nla_put_failure;
2918 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2919 rdev->wiphy.txq_memory_limit))
2920 goto nla_put_failure;
2921 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2922 rdev->wiphy.txq_quantum))
2923 goto nla_put_failure;
2926 state->split_start++;
2929 if (nl80211_send_pmsr_capa(rdev, msg))
2930 goto nla_put_failure;
2932 state->split_start++;
2935 if (rdev->wiphy.akm_suites &&
2936 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2937 sizeof(u32) * rdev->wiphy.n_akm_suites,
2938 rdev->wiphy.akm_suites))
2939 goto nla_put_failure;
2941 if (nl80211_put_iftype_akm_suites(rdev, msg))
2942 goto nla_put_failure;
2944 if (nl80211_put_tid_config_support(rdev, msg))
2945 goto nla_put_failure;
2946 state->split_start++;
2949 if (nl80211_put_sar_specs(rdev, msg))
2950 goto nla_put_failure;
2952 if (nl80211_put_mbssid_support(&rdev->wiphy, msg))
2953 goto nla_put_failure;
2955 if (nla_put_u16(msg, NL80211_ATTR_MAX_NUM_AKM_SUITES,
2956 rdev->wiphy.max_num_akm_suites))
2957 goto nla_put_failure;
2959 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)
2960 nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT);
2963 state->split_start = 0;
2967 genlmsg_end(msg, hdr);
2971 genlmsg_cancel(msg, hdr);
2975 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2976 struct netlink_callback *cb,
2977 struct nl80211_dump_wiphy_state *state)
2979 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2985 ret = nlmsg_parse_deprecated(cb->nlh,
2986 GENL_HDRLEN + nl80211_fam.hdrsize,
2987 tb, nl80211_fam.maxattr,
2988 nl80211_policy, NULL);
2989 /* ignore parse errors for backward compatibility */
2995 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2996 if (tb[NL80211_ATTR_WIPHY])
2997 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2998 if (tb[NL80211_ATTR_WDEV])
2999 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
3000 if (tb[NL80211_ATTR_IFINDEX]) {
3001 struct net_device *netdev;
3002 struct cfg80211_registered_device *rdev;
3003 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
3005 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
3010 if (netdev->ieee80211_ptr) {
3011 rdev = wiphy_to_rdev(
3012 netdev->ieee80211_ptr->wiphy);
3013 state->filter_wiphy = rdev->wiphy_idx;
3023 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
3026 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
3027 struct cfg80211_registered_device *rdev;
3031 state = kzalloc(sizeof(*state), GFP_KERNEL);
3036 state->filter_wiphy = -1;
3037 ret = nl80211_dump_wiphy_parse(skb, cb, state);
3043 cb->args[0] = (long)state;
3046 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3047 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3049 if (++idx <= state->start)
3051 if (state->filter_wiphy != -1 &&
3052 state->filter_wiphy != rdev->wiphy_idx)
3054 /* attempt to fit multiple wiphy data chunks into the skb */
3056 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
3058 NETLINK_CB(cb->skb).portid,
3060 NLM_F_MULTI, state);
3063 * If sending the wiphy data didn't fit (ENOBUFS
3064 * or EMSGSIZE returned), this SKB is still
3065 * empty (so it's not too big because another
3066 * wiphy dataset is already in the skb) and
3067 * we've not tried to adjust the dump allocation
3068 * yet ... then adjust the alloc size to be
3069 * bigger, and return 1 but with the empty skb.
3070 * This results in an empty message being RX'ed
3071 * in userspace, but that is ignored.
3073 * We can then retry with the larger buffer.
3075 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
3076 !skb->len && !state->split &&
3077 cb->min_dump_alloc < 4096) {
3078 cb->min_dump_alloc = 4096;
3079 state->split_start = 0;
3086 } while (state->split_start > 0);
3096 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
3098 kfree((void *)cb->args[0]);
3102 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
3104 struct sk_buff *msg;
3105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3106 struct nl80211_dump_wiphy_state state = {};
3108 msg = nlmsg_new(4096, GFP_KERNEL);
3112 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
3113 info->snd_portid, info->snd_seq, 0,
3119 return genlmsg_reply(msg, info);
3122 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
3123 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
3124 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
3125 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
3126 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
3127 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
3130 static int parse_txq_params(struct nlattr *tb[],
3131 struct ieee80211_txq_params *txq_params)
3135 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
3136 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
3137 !tb[NL80211_TXQ_ATTR_AIFS])
3140 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
3141 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
3142 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
3143 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
3144 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
3146 if (ac >= NL80211_NUM_ACS)
3148 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
3152 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
3155 * You can only set the channel explicitly for some interfaces,
3156 * most have their channel managed via their respective
3157 * "establish a connection" command (connect, join, ...)
3159 * For AP/GO and mesh mode, the channel can be set with the
3160 * channel userspace API, but is only stored and passed to the
3161 * low-level driver when the AP starts or the mesh is joined.
3162 * This is for backward compatibility, userspace can also give
3163 * the channel in the start-ap or join-mesh commands instead.
3165 * Monitors are special as they are normally slaved to
3166 * whatever else is going on, so they have their own special
3167 * operation to set the monitor channel if possible.
3170 wdev->iftype == NL80211_IFTYPE_AP ||
3171 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
3172 wdev->iftype == NL80211_IFTYPE_MONITOR ||
3173 wdev->iftype == NL80211_IFTYPE_P2P_GO;
3176 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
3177 struct genl_info *info,
3178 struct cfg80211_chan_def *chandef)
3180 struct netlink_ext_ack *extack = info->extack;
3181 struct nlattr **attrs = info->attrs;
3184 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
3187 control_freq = MHZ_TO_KHZ(
3188 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3189 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
3191 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
3193 memset(chandef, 0, sizeof(*chandef));
3194 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq);
3195 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
3196 chandef->center_freq1 = KHZ_TO_MHZ(control_freq);
3197 chandef->freq1_offset = control_freq % 1000;
3198 chandef->center_freq2 = 0;
3200 /* Primary channel not allowed */
3201 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
3202 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
3203 "Channel is disabled");
3207 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
3208 enum nl80211_channel_type chantype;
3210 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
3213 case NL80211_CHAN_NO_HT:
3214 case NL80211_CHAN_HT20:
3215 case NL80211_CHAN_HT40PLUS:
3216 case NL80211_CHAN_HT40MINUS:
3217 cfg80211_chandef_create(chandef, chandef->chan,
3219 /* user input for center_freq is incorrect */
3220 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
3221 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
3222 NL_SET_ERR_MSG_ATTR(extack,
3223 attrs[NL80211_ATTR_CENTER_FREQ1],
3224 "bad center frequency 1");
3227 /* center_freq2 must be zero */
3228 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
3229 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
3230 NL_SET_ERR_MSG_ATTR(extack,
3231 attrs[NL80211_ATTR_CENTER_FREQ2],
3232 "center frequency 2 can't be used");
3237 NL_SET_ERR_MSG_ATTR(extack,
3238 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
3239 "invalid channel type");
3242 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
3244 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
3245 if (chandef->chan->band == NL80211_BAND_S1GHZ) {
3246 /* User input error for channel width doesn't match channel */
3247 if (chandef->width != ieee80211_s1g_channel_width(chandef->chan)) {
3248 NL_SET_ERR_MSG_ATTR(extack,
3249 attrs[NL80211_ATTR_CHANNEL_WIDTH],
3250 "bad channel width");
3254 if (attrs[NL80211_ATTR_CENTER_FREQ1]) {
3255 chandef->center_freq1 =
3256 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
3257 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET])
3258 chandef->freq1_offset = nla_get_u32(
3259 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]);
3261 chandef->freq1_offset = 0;
3263 if (attrs[NL80211_ATTR_CENTER_FREQ2])
3264 chandef->center_freq2 =
3265 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
3268 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
3269 chandef->edmg.channels =
3270 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
3272 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
3273 chandef->edmg.bw_config =
3274 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
3276 chandef->edmg.bw_config = 0;
3277 chandef->edmg.channels = 0;
3280 if (!cfg80211_chandef_valid(chandef)) {
3281 NL_SET_ERR_MSG(extack, "invalid channel definition");
3285 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
3286 IEEE80211_CHAN_DISABLED)) {
3287 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
3291 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
3292 chandef->width == NL80211_CHAN_WIDTH_10) &&
3293 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
3294 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
3301 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
3302 struct net_device *dev,
3303 struct genl_info *info,
3306 struct cfg80211_chan_def chandef;
3308 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
3309 struct wireless_dev *wdev = NULL;
3310 int link_id = _link_id;
3313 wdev = dev->ieee80211_ptr;
3314 if (!nl80211_can_set_dev_channel(wdev))
3317 iftype = wdev->iftype;
3320 if (wdev && wdev->valid_links)
3325 result = nl80211_parse_chandef(rdev, info, &chandef);
3330 case NL80211_IFTYPE_AP:
3331 case NL80211_IFTYPE_P2P_GO:
3332 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
3335 if (wdev->links[link_id].ap.beacon_interval) {
3336 struct ieee80211_channel *cur_chan;
3338 if (!dev || !rdev->ops->set_ap_chanwidth ||
3339 !(rdev->wiphy.features &
3340 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE))
3343 /* Only allow dynamic channel width changes */
3344 cur_chan = wdev->links[link_id].ap.chandef.chan;
3345 if (chandef.chan != cur_chan)
3348 result = rdev_set_ap_chanwidth(rdev, dev, link_id,
3352 wdev->links[link_id].ap.chandef = chandef;
3354 wdev->u.ap.preset_chandef = chandef;
3357 case NL80211_IFTYPE_MESH_POINT:
3358 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
3359 case NL80211_IFTYPE_MONITOR:
3360 return cfg80211_set_monitor_channel(rdev, &chandef);
3368 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
3370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3371 int link_id = nl80211_link_id_or_invalid(info->attrs);
3372 struct net_device *netdev = info->user_ptr[1];
3375 wdev_lock(netdev->ieee80211_ptr);
3376 ret = __nl80211_set_channel(rdev, netdev, info, link_id);
3377 wdev_unlock(netdev->ieee80211_ptr);
3382 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
3384 struct cfg80211_registered_device *rdev = NULL;
3385 struct net_device *netdev = NULL;
3386 struct wireless_dev *wdev;
3387 int result = 0, rem_txq_params = 0;
3388 struct nlattr *nl_txq_params;
3390 u8 retry_short = 0, retry_long = 0;
3391 u32 frag_threshold = 0, rts_threshold = 0;
3392 u8 coverage_class = 0;
3393 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
3397 * Try to find the wiphy and netdev. Normally this
3398 * function shouldn't need the netdev, but this is
3399 * done for backward compatibility -- previously
3400 * setting the channel was done per wiphy, but now
3401 * it is per netdev. Previous userland like hostapd
3402 * also passed a netdev to set_wiphy, so that it is
3403 * possible to let that go to the right netdev!
3406 if (info->attrs[NL80211_ATTR_IFINDEX]) {
3407 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
3409 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
3410 if (netdev && netdev->ieee80211_ptr)
3411 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
3417 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3421 return PTR_ERR(rdev);
3427 wdev = netdev->ieee80211_ptr;
3429 wiphy_lock(&rdev->wiphy);
3432 * end workaround code, by now the rdev is available
3433 * and locked, and wdev may or may not be NULL.
3436 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
3437 result = cfg80211_dev_rename(
3438 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
3444 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
3445 struct ieee80211_txq_params txq_params;
3446 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
3448 if (!rdev->ops->set_txq_params) {
3449 result = -EOPNOTSUPP;
3458 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3459 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3464 if (!netif_running(netdev)) {
3469 nla_for_each_nested(nl_txq_params,
3470 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3472 result = nla_parse_nested_deprecated(tb,
3473 NL80211_TXQ_ATTR_MAX,
3479 result = parse_txq_params(tb, &txq_params);
3483 txq_params.link_id =
3484 nl80211_link_id_or_invalid(info->attrs);
3486 wdev_lock(netdev->ieee80211_ptr);
3487 if (txq_params.link_id >= 0 &&
3488 !(netdev->ieee80211_ptr->valid_links &
3489 BIT(txq_params.link_id)))
3491 else if (txq_params.link_id >= 0 &&
3492 !netdev->ieee80211_ptr->valid_links)
3495 result = rdev_set_txq_params(rdev, netdev,
3497 wdev_unlock(netdev->ieee80211_ptr);
3503 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3504 int link_id = nl80211_link_id_or_invalid(info->attrs);
3508 result = __nl80211_set_channel(
3510 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3514 result = __nl80211_set_channel(rdev, netdev, info, link_id);
3521 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
3522 struct wireless_dev *txp_wdev = wdev;
3523 enum nl80211_tx_power_setting type;
3526 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3529 if (!rdev->ops->set_tx_power) {
3530 result = -EOPNOTSUPP;
3534 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
3535 type = nla_get_u32(info->attrs[idx]);
3537 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
3538 (type != NL80211_TX_POWER_AUTOMATIC)) {
3543 if (type != NL80211_TX_POWER_AUTOMATIC) {
3544 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
3545 mbm = nla_get_u32(info->attrs[idx]);
3548 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
3553 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3554 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3557 if ((!rdev->wiphy.available_antennas_tx &&
3558 !rdev->wiphy.available_antennas_rx) ||
3559 !rdev->ops->set_antenna) {
3560 result = -EOPNOTSUPP;
3564 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3565 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3567 /* reject antenna configurations which don't match the
3568 * available antenna masks, except for the "all" mask */
3569 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
3570 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
3575 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3576 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
3578 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
3585 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3586 retry_short = nla_get_u8(
3587 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
3589 changed |= WIPHY_PARAM_RETRY_SHORT;
3592 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3593 retry_long = nla_get_u8(
3594 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
3596 changed |= WIPHY_PARAM_RETRY_LONG;
3599 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3600 frag_threshold = nla_get_u32(
3601 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
3602 if (frag_threshold < 256) {
3607 if (frag_threshold != (u32) -1) {
3609 * Fragments (apart from the last one) are required to
3610 * have even length. Make the fragmentation code
3611 * simpler by stripping LSB should someone try to use
3612 * odd threshold value.
3614 frag_threshold &= ~0x1;
3616 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3619 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3620 rts_threshold = nla_get_u32(
3621 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3622 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3625 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
3626 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3631 coverage_class = nla_get_u8(
3632 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3633 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3636 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3637 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) {
3638 result = -EOPNOTSUPP;
3642 changed |= WIPHY_PARAM_DYN_ACK;
3645 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3646 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3647 NL80211_EXT_FEATURE_TXQS)) {
3648 result = -EOPNOTSUPP;
3651 txq_limit = nla_get_u32(
3652 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3653 changed |= WIPHY_PARAM_TXQ_LIMIT;
3656 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3657 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3658 NL80211_EXT_FEATURE_TXQS)) {
3659 result = -EOPNOTSUPP;
3662 txq_memory_limit = nla_get_u32(
3663 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3664 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3667 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3668 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3669 NL80211_EXT_FEATURE_TXQS)) {
3670 result = -EOPNOTSUPP;
3673 txq_quantum = nla_get_u32(
3674 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3675 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3679 u8 old_retry_short, old_retry_long;
3680 u32 old_frag_threshold, old_rts_threshold;
3681 u8 old_coverage_class;
3682 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
3684 if (!rdev->ops->set_wiphy_params) {
3685 result = -EOPNOTSUPP;
3689 old_retry_short = rdev->wiphy.retry_short;
3690 old_retry_long = rdev->wiphy.retry_long;
3691 old_frag_threshold = rdev->wiphy.frag_threshold;
3692 old_rts_threshold = rdev->wiphy.rts_threshold;
3693 old_coverage_class = rdev->wiphy.coverage_class;
3694 old_txq_limit = rdev->wiphy.txq_limit;
3695 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3696 old_txq_quantum = rdev->wiphy.txq_quantum;
3698 if (changed & WIPHY_PARAM_RETRY_SHORT)
3699 rdev->wiphy.retry_short = retry_short;
3700 if (changed & WIPHY_PARAM_RETRY_LONG)
3701 rdev->wiphy.retry_long = retry_long;
3702 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3703 rdev->wiphy.frag_threshold = frag_threshold;
3704 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3705 rdev->wiphy.rts_threshold = rts_threshold;
3706 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3707 rdev->wiphy.coverage_class = coverage_class;
3708 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3709 rdev->wiphy.txq_limit = txq_limit;
3710 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3711 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3712 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3713 rdev->wiphy.txq_quantum = txq_quantum;
3715 result = rdev_set_wiphy_params(rdev, changed);
3717 rdev->wiphy.retry_short = old_retry_short;
3718 rdev->wiphy.retry_long = old_retry_long;
3719 rdev->wiphy.frag_threshold = old_frag_threshold;
3720 rdev->wiphy.rts_threshold = old_rts_threshold;
3721 rdev->wiphy.coverage_class = old_coverage_class;
3722 rdev->wiphy.txq_limit = old_txq_limit;
3723 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3724 rdev->wiphy.txq_quantum = old_txq_quantum;
3732 wiphy_unlock(&rdev->wiphy);
3736 static int nl80211_send_chandef(struct sk_buff *msg,
3737 const struct cfg80211_chan_def *chandef)
3739 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3743 chandef->chan->center_freq))
3745 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
3746 chandef->chan->freq_offset))
3748 switch (chandef->width) {
3749 case NL80211_CHAN_WIDTH_20_NOHT:
3750 case NL80211_CHAN_WIDTH_20:
3751 case NL80211_CHAN_WIDTH_40:
3752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3753 cfg80211_get_chandef_type(chandef)))
3759 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3761 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3763 if (chandef->center_freq2 &&
3764 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
3769 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
3770 struct cfg80211_registered_device *rdev,
3771 struct wireless_dev *wdev,
3772 enum nl80211_commands cmd)
3774 struct net_device *dev = wdev->netdev;
3777 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3778 cmd != NL80211_CMD_DEL_INTERFACE &&
3779 cmd != NL80211_CMD_SET_INTERFACE);
3781 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
3786 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3787 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
3788 goto nla_put_failure;
3790 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3791 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
3792 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3793 NL80211_ATTR_PAD) ||
3794 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
3795 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3796 rdev->devlist_generation ^
3797 (cfg80211_rdev_list_generation << 2)) ||
3798 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
3799 goto nla_put_failure;
3801 if (rdev->ops->get_channel && !wdev->valid_links) {
3802 struct cfg80211_chan_def chandef = {};
3805 ret = rdev_get_channel(rdev, wdev, 0, &chandef);
3806 if (ret == 0 && nl80211_send_chandef(msg, &chandef))
3807 goto nla_put_failure;
3810 if (rdev->ops->get_tx_power) {
3813 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3815 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3817 goto nla_put_failure;
3821 switch (wdev->iftype) {
3822 case NL80211_IFTYPE_AP:
3823 case NL80211_IFTYPE_P2P_GO:
3824 if (wdev->u.ap.ssid_len &&
3825 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len,
3827 goto nla_put_failure_locked;
3829 case NL80211_IFTYPE_STATION:
3830 case NL80211_IFTYPE_P2P_CLIENT:
3831 if (wdev->u.client.ssid_len &&
3832 nla_put(msg, NL80211_ATTR_SSID, wdev->u.client.ssid_len,
3833 wdev->u.client.ssid))
3834 goto nla_put_failure_locked;
3836 case NL80211_IFTYPE_ADHOC:
3837 if (wdev->u.ibss.ssid_len &&
3838 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ibss.ssid_len,
3840 goto nla_put_failure_locked;
3848 if (rdev->ops->get_txq_stats) {
3849 struct cfg80211_txq_stats txqstats = {};
3850 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3853 !nl80211_put_txq_stats(msg, &txqstats,
3854 NL80211_ATTR_TXQ_STATS))
3855 goto nla_put_failure;
3858 if (wdev->valid_links) {
3859 unsigned int link_id;
3860 struct nlattr *links = nla_nest_start(msg,
3861 NL80211_ATTR_MLO_LINKS);
3864 goto nla_put_failure;
3866 for_each_valid_link(wdev, link_id) {
3867 struct nlattr *link = nla_nest_start(msg, link_id + 1);
3868 struct cfg80211_chan_def chandef = {};
3872 goto nla_put_failure;
3874 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
3875 goto nla_put_failure;
3876 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
3877 wdev->links[link_id].addr))
3878 goto nla_put_failure;
3880 ret = rdev_get_channel(rdev, wdev, link_id, &chandef);
3881 if (ret == 0 && nl80211_send_chandef(msg, &chandef))
3882 goto nla_put_failure;
3884 nla_nest_end(msg, link);
3887 nla_nest_end(msg, links);
3890 genlmsg_end(msg, hdr);
3893 nla_put_failure_locked:
3896 genlmsg_cancel(msg, hdr);
3900 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3904 int wp_start = cb->args[0];
3905 int if_start = cb->args[1];
3906 int filter_wiphy = -1;
3907 struct cfg80211_registered_device *rdev;
3908 struct wireless_dev *wdev;
3913 struct nl80211_dump_wiphy_state state = {
3917 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3921 filter_wiphy = state.filter_wiphy;
3924 * if filtering, set cb->args[2] to +1 since 0 is the default
3925 * value needed to determine that parsing is necessary.
3927 if (filter_wiphy >= 0)
3928 cb->args[2] = filter_wiphy + 1;
3931 } else if (cb->args[2] > 0) {
3932 filter_wiphy = cb->args[2] - 1;
3935 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3936 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3938 if (wp_idx < wp_start) {
3943 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3948 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
3949 if (if_idx < if_start) {
3953 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
3954 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3956 NL80211_CMD_NEW_INTERFACE) < 0) {
3965 cb->args[0] = wp_idx;
3966 cb->args[1] = if_idx;
3975 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3977 struct sk_buff *msg;
3978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3979 struct wireless_dev *wdev = info->user_ptr[1];
3981 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3985 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3986 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
3991 return genlmsg_reply(msg, info);
3994 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3995 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3996 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3997 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3998 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3999 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
4000 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
4003 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
4005 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
4013 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
4016 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
4018 *mntrflags |= (1<<flag);
4020 *mntrflags |= MONITOR_FLAG_CHANGED;
4025 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
4026 enum nl80211_iftype type,
4027 struct genl_info *info,
4028 struct vif_params *params)
4030 bool change = false;
4033 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
4034 if (type != NL80211_IFTYPE_MONITOR)
4037 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
4045 if (params->flags & MONITOR_FLAG_ACTIVE &&
4046 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
4049 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
4050 const u8 *mumimo_groups;
4051 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
4053 if (type != NL80211_IFTYPE_MONITOR)
4056 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
4060 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
4062 /* bits 0 and 63 are reserved and must be zero */
4063 if ((mumimo_groups[0] & BIT(0)) ||
4064 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
4067 params->vht_mumimo_groups = mumimo_groups;
4071 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
4072 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
4074 if (type != NL80211_IFTYPE_MONITOR)
4077 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
4080 params->vht_mumimo_follow_addr =
4081 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
4085 return change ? 1 : 0;
4088 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
4089 struct net_device *netdev, u8 use_4addr,
4090 enum nl80211_iftype iftype)
4093 if (netdev && netif_is_bridge_port(netdev))
4099 case NL80211_IFTYPE_AP_VLAN:
4100 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
4103 case NL80211_IFTYPE_STATION:
4104 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
4114 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
4116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4117 struct vif_params params;
4119 enum nl80211_iftype otype, ntype;
4120 struct net_device *dev = info->user_ptr[1];
4121 bool change = false;
4123 memset(¶ms, 0, sizeof(params));
4125 otype = ntype = dev->ieee80211_ptr->iftype;
4127 if (info->attrs[NL80211_ATTR_IFTYPE]) {
4128 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
4133 if (info->attrs[NL80211_ATTR_MESH_ID]) {
4134 struct wireless_dev *wdev = dev->ieee80211_ptr;
4136 if (ntype != NL80211_IFTYPE_MESH_POINT)
4138 if (netif_running(dev))
4142 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
4143 IEEE80211_MAX_MESH_ID_LEN);
4144 wdev->u.mesh.id_up_len =
4145 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
4146 memcpy(wdev->u.mesh.id,
4147 nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
4148 wdev->u.mesh.id_up_len);
4152 if (info->attrs[NL80211_ATTR_4ADDR]) {
4153 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
4155 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
4159 params.use_4addr = -1;
4162 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms);
4169 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms);
4173 if (!err && params.use_4addr != -1)
4174 dev->ieee80211_ptr->use_4addr = params.use_4addr;
4176 if (change && !err) {
4177 struct wireless_dev *wdev = dev->ieee80211_ptr;
4179 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
4185 static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
4187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4188 struct vif_params params;
4189 struct wireless_dev *wdev;
4190 struct sk_buff *msg;
4192 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
4194 memset(¶ms, 0, sizeof(params));
4196 if (!info->attrs[NL80211_ATTR_IFNAME])
4199 if (info->attrs[NL80211_ATTR_IFTYPE])
4200 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
4202 if (!rdev->ops->add_virtual_intf)
4205 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
4206 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
4207 info->attrs[NL80211_ATTR_MAC]) {
4208 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
4210 if (!is_valid_ether_addr(params.macaddr))
4211 return -EADDRNOTAVAIL;
4214 if (info->attrs[NL80211_ATTR_4ADDR]) {
4215 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
4216 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
4221 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
4224 err = nl80211_parse_mon_options(rdev, type, info, ¶ms);
4228 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4232 wdev = rdev_add_virtual_intf(rdev,
4233 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
4234 NET_NAME_USER, type, ¶ms);
4235 if (WARN_ON(!wdev)) {
4238 } else if (IS_ERR(wdev)) {
4240 return PTR_ERR(wdev);
4243 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
4244 wdev->owner_nlportid = info->snd_portid;
4247 case NL80211_IFTYPE_MESH_POINT:
4248 if (!info->attrs[NL80211_ATTR_MESH_ID])
4251 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
4252 IEEE80211_MAX_MESH_ID_LEN);
4253 wdev->u.mesh.id_up_len =
4254 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
4255 memcpy(wdev->u.mesh.id,
4256 nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
4257 wdev->u.mesh.id_up_len);
4260 case NL80211_IFTYPE_NAN:
4261 case NL80211_IFTYPE_P2P_DEVICE:
4263 * P2P Device and NAN do not have a netdev, so don't go
4264 * through the netdev notifier and must be added here
4266 cfg80211_init_wdev(wdev);
4267 cfg80211_register_wdev(rdev, wdev);
4273 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
4274 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
4279 return genlmsg_reply(msg, info);
4282 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
4284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4287 /* to avoid failing a new interface creation due to pending removal */
4288 cfg80211_destroy_ifaces(rdev);
4290 wiphy_lock(&rdev->wiphy);
4291 ret = _nl80211_new_interface(skb, info);
4292 wiphy_unlock(&rdev->wiphy);
4297 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
4299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4300 struct wireless_dev *wdev = info->user_ptr[1];
4302 if (!rdev->ops->del_virtual_intf)
4306 * We hold RTNL, so this is safe, without RTNL opencount cannot
4307 * reach 0, and thus the rdev cannot be deleted.
4309 * We need to do it for the dev_close(), since that will call
4310 * the netdev notifiers, and we need to acquire the mutex there
4311 * but don't know if we get there from here or from some other
4312 * place (e.g. "ip link set ... down").
4314 mutex_unlock(&rdev->wiphy.mtx);
4317 * If we remove a wireless device without a netdev then clear
4318 * user_ptr[1] so that nl80211_post_doit won't dereference it
4319 * to check if it needs to do dev_put(). Otherwise it crashes
4320 * since the wdev has been freed, unlike with a netdev where
4321 * we need the dev_put() for the netdev to really be freed.
4324 info->user_ptr[1] = NULL;
4326 dev_close(wdev->netdev);
4328 mutex_lock(&rdev->wiphy.mtx);
4330 return cfg80211_remove_virtual_intf(rdev, wdev);
4333 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
4335 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4336 struct net_device *dev = info->user_ptr[1];
4339 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
4342 if (!rdev->ops->set_noack_map)
4345 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
4347 return rdev_set_noack_map(rdev, dev, noack_map);
4350 static int nl80211_validate_key_link_id(struct genl_info *info,
4351 struct wireless_dev *wdev,
4352 int link_id, bool pairwise)
4355 if (link_id != -1) {
4356 GENL_SET_ERR_MSG(info,
4357 "link ID not allowed for pairwise key");
4364 if (wdev->valid_links) {
4365 if (link_id == -1) {
4366 GENL_SET_ERR_MSG(info,
4367 "link ID must for MLO group key");
4370 if (!(wdev->valid_links & BIT(link_id))) {
4371 GENL_SET_ERR_MSG(info, "invalid link ID for MLO group key");
4374 } else if (link_id != -1) {
4375 GENL_SET_ERR_MSG(info, "link ID not allowed for non-MLO group key");
4382 struct get_key_cookie {
4383 struct sk_buff *msg;
4388 static void get_key_callback(void *c, struct key_params *params)
4391 struct get_key_cookie *cookie = c;
4394 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
4395 params->key_len, params->key)) ||
4397 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
4398 params->seq_len, params->seq)) ||
4400 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
4402 goto nla_put_failure;
4404 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
4406 goto nla_put_failure;
4409 nla_put(cookie->msg, NL80211_KEY_DATA,
4410 params->key_len, params->key)) ||
4412 nla_put(cookie->msg, NL80211_KEY_SEQ,
4413 params->seq_len, params->seq)) ||
4415 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
4417 goto nla_put_failure;
4419 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
4420 goto nla_put_failure;
4422 nla_nest_end(cookie->msg, key);
4429 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
4431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4433 struct net_device *dev = info->user_ptr[1];
4435 const u8 *mac_addr = NULL;
4437 struct get_key_cookie cookie = {
4441 struct sk_buff *msg;
4442 bool bigtk_support = false;
4443 int link_id = nl80211_link_id_or_invalid(info->attrs);
4444 struct wireless_dev *wdev = dev->ieee80211_ptr;
4446 if (wiphy_ext_feature_isset(&rdev->wiphy,
4447 NL80211_EXT_FEATURE_BEACON_PROTECTION))
4448 bigtk_support = true;
4450 if ((wdev->iftype == NL80211_IFTYPE_STATION ||
4451 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
4452 wiphy_ext_feature_isset(&rdev->wiphy,
4453 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
4454 bigtk_support = true;
4456 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
4457 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
4459 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) {
4460 GENL_SET_ERR_MSG(info, "BIGTK not supported");
4465 if (info->attrs[NL80211_ATTR_MAC])
4466 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4468 pairwise = !!mac_addr;
4469 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
4470 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
4472 if (kt != NL80211_KEYTYPE_GROUP &&
4473 kt != NL80211_KEYTYPE_PAIRWISE)
4475 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
4478 if (!rdev->ops->get_key)
4481 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4488 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4489 NL80211_CMD_NEW_KEY);
4491 goto nla_put_failure;
4494 cookie.idx = key_idx;
4496 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4497 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
4498 goto nla_put_failure;
4500 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
4501 goto nla_put_failure;
4503 err = nl80211_validate_key_link_id(info, wdev, link_id, pairwise);
4507 err = rdev_get_key(rdev, dev, link_id, key_idx, pairwise, mac_addr,
4508 &cookie, get_key_callback);
4514 goto nla_put_failure;
4516 genlmsg_end(msg, hdr);
4517 return genlmsg_reply(msg, info);
4526 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
4528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4529 struct key_parse key;
4531 struct net_device *dev = info->user_ptr[1];
4532 int link_id = nl80211_link_id_or_invalid(info->attrs);
4533 struct wireless_dev *wdev = dev->ieee80211_ptr;
4535 err = nl80211_parse_key(info, &key);
4542 /* Only support setting default key and
4543 * Extended Key ID action NL80211_KEY_SET_TX.
4545 if (!key.def && !key.defmgmt && !key.defbeacon &&
4546 !(key.p.mode == NL80211_KEY_SET_TX))
4552 if (!rdev->ops->set_default_key) {
4557 err = nl80211_key_allowed(wdev);
4561 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4565 err = rdev_set_default_key(rdev, dev, link_id, key.idx,
4566 key.def_uni, key.def_multi);
4571 #ifdef CONFIG_CFG80211_WEXT
4572 wdev->wext.default_key = key.idx;
4574 } else if (key.defmgmt) {
4575 if (key.def_uni || !key.def_multi) {
4580 if (!rdev->ops->set_default_mgmt_key) {
4585 err = nl80211_key_allowed(wdev);
4589 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4593 err = rdev_set_default_mgmt_key(rdev, dev, link_id, key.idx);
4597 #ifdef CONFIG_CFG80211_WEXT
4598 wdev->wext.default_mgmt_key = key.idx;
4600 } else if (key.defbeacon) {
4601 if (key.def_uni || !key.def_multi) {
4606 if (!rdev->ops->set_default_beacon_key) {
4611 err = nl80211_key_allowed(wdev);
4615 err = nl80211_validate_key_link_id(info, wdev, link_id, false);
4619 err = rdev_set_default_beacon_key(rdev, dev, link_id, key.idx);
4622 } else if (key.p.mode == NL80211_KEY_SET_TX &&
4623 wiphy_ext_feature_isset(&rdev->wiphy,
4624 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
4625 u8 *mac_addr = NULL;
4627 if (info->attrs[NL80211_ATTR_MAC])
4628 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4630 if (!mac_addr || key.idx < 0 || key.idx > 1) {
4635 err = nl80211_validate_key_link_id(info, wdev, link_id, true);
4639 err = rdev_add_key(rdev, dev, link_id, key.idx,
4640 NL80211_KEYTYPE_PAIRWISE,
4651 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4655 struct net_device *dev = info->user_ptr[1];
4656 struct key_parse key;
4657 const u8 *mac_addr = NULL;
4658 int link_id = nl80211_link_id_or_invalid(info->attrs);
4659 struct wireless_dev *wdev = dev->ieee80211_ptr;
4661 err = nl80211_parse_key(info, &key);
4666 GENL_SET_ERR_MSG(info, "no key");
4670 if (info->attrs[NL80211_ATTR_MAC])
4671 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4673 if (key.type == -1) {
4675 key.type = NL80211_KEYTYPE_PAIRWISE;
4677 key.type = NL80211_KEYTYPE_GROUP;
4681 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4682 key.type != NL80211_KEYTYPE_GROUP) {
4683 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
4687 if (key.type == NL80211_KEYTYPE_GROUP &&
4688 info->attrs[NL80211_ATTR_VLAN_ID])
4689 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
4691 if (!rdev->ops->add_key)
4694 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4695 key.type == NL80211_KEYTYPE_PAIRWISE,
4697 GENL_SET_ERR_MSG(info, "key setting validation failed");
4702 err = nl80211_key_allowed(wdev);
4704 GENL_SET_ERR_MSG(info, "key not allowed");
4707 err = nl80211_validate_key_link_id(info, wdev, link_id,
4708 key.type == NL80211_KEYTYPE_PAIRWISE);
4711 err = rdev_add_key(rdev, dev, link_id, key.idx,
4712 key.type == NL80211_KEYTYPE_PAIRWISE,
4715 GENL_SET_ERR_MSG(info, "key addition failed");
4722 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4726 struct net_device *dev = info->user_ptr[1];
4727 u8 *mac_addr = NULL;
4728 struct key_parse key;
4729 int link_id = nl80211_link_id_or_invalid(info->attrs);
4730 struct wireless_dev *wdev = dev->ieee80211_ptr;
4732 err = nl80211_parse_key(info, &key);
4736 if (info->attrs[NL80211_ATTR_MAC])
4737 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4739 if (key.type == -1) {
4741 key.type = NL80211_KEYTYPE_PAIRWISE;
4743 key.type = NL80211_KEYTYPE_GROUP;
4747 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4748 key.type != NL80211_KEYTYPE_GROUP)
4751 if (!cfg80211_valid_key_idx(rdev, key.idx,
4752 key.type == NL80211_KEYTYPE_PAIRWISE))
4755 if (!rdev->ops->del_key)
4759 err = nl80211_key_allowed(wdev);
4761 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
4762 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4766 err = nl80211_validate_key_link_id(info, wdev, link_id,
4767 key.type == NL80211_KEYTYPE_PAIRWISE);
4770 err = rdev_del_key(rdev, dev, link_id, key.idx,
4771 key.type == NL80211_KEYTYPE_PAIRWISE,
4774 #ifdef CONFIG_CFG80211_WEXT
4776 if (key.idx == wdev->wext.default_key)
4777 wdev->wext.default_key = -1;
4778 else if (key.idx == wdev->wext.default_mgmt_key)
4779 wdev->wext.default_mgmt_key = -1;
4787 /* This function returns an error or the number of nested attributes */
4788 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4790 struct nlattr *attr;
4791 int n_entries = 0, tmp;
4793 nla_for_each_nested(attr, nl_attr, tmp) {
4794 if (nla_len(attr) != ETH_ALEN)
4804 * This function parses ACL information and allocates memory for ACL data.
4805 * On successful return, the calling function is responsible to free the
4806 * ACL buffer returned by this function.
4808 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4809 struct genl_info *info)
4811 enum nl80211_acl_policy acl_policy;
4812 struct nlattr *attr;
4813 struct cfg80211_acl_data *acl;
4814 int i = 0, n_entries, tmp;
4816 if (!wiphy->max_acl_mac_addrs)
4817 return ERR_PTR(-EOPNOTSUPP);
4819 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4820 return ERR_PTR(-EINVAL);
4822 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4823 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4824 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4825 return ERR_PTR(-EINVAL);
4827 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4828 return ERR_PTR(-EINVAL);
4830 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4832 return ERR_PTR(n_entries);
4834 if (n_entries > wiphy->max_acl_mac_addrs)
4835 return ERR_PTR(-ENOTSUPP);
4837 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
4839 return ERR_PTR(-ENOMEM);
4841 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4842 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4846 acl->n_acl_entries = n_entries;
4847 acl->acl_policy = acl_policy;
4852 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4855 struct net_device *dev = info->user_ptr[1];
4856 struct cfg80211_acl_data *acl;
4859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4860 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4863 if (!dev->ieee80211_ptr->links[0].ap.beacon_interval)
4866 acl = parse_acl_data(&rdev->wiphy, info);
4868 return PTR_ERR(acl);
4870 err = rdev_set_mac_acl(rdev, dev, acl);
4877 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4878 u8 *rates, u8 rates_len)
4883 for (i = 0; i < rates_len; i++) {
4884 int rate = (rates[i] & 0x7f) * 5;
4887 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4888 struct ieee80211_rate *srate =
4889 &sband->bitrates[ridx];
4890 if (rate == srate->bitrate) {
4895 if (ridx == sband->n_bitrates)
4896 return 0; /* rate not found */
4902 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4903 u8 *rates, u8 rates_len,
4904 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4908 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4910 for (i = 0; i < rates_len; i++) {
4913 ridx = rates[i] / 8;
4914 rbit = BIT(rates[i] % 8);
4916 /* check validity */
4917 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4920 /* check availability */
4921 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
4922 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4931 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4935 switch (vht_mcs_map) {
4936 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4938 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4941 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4944 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4954 static void vht_build_mcs_mask(u16 vht_mcs_map,
4955 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4959 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4960 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4965 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4966 struct nl80211_txrate_vht *txrate,
4967 u16 mcs[NL80211_VHT_NSS_MAX])
4969 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4970 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4973 if (!sband->vht_cap.vht_supported)
4976 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4978 /* Build vht_mcs_mask from VHT capabilities */
4979 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4981 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4982 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4983 mcs[i] = txrate->mcs[i];
4991 static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map)
4993 switch (he_mcs_map) {
4994 case IEEE80211_HE_MCS_NOT_SUPPORTED:
4996 case IEEE80211_HE_MCS_SUPPORT_0_7:
4998 case IEEE80211_HE_MCS_SUPPORT_0_9:
5000 case IEEE80211_HE_MCS_SUPPORT_0_11:
5008 static void he_build_mcs_mask(u16 he_mcs_map,
5009 u16 he_mcs_mask[NL80211_HE_NSS_MAX])
5013 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) {
5014 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03);
5019 static u16 he_get_txmcsmap(struct genl_info *info, unsigned int link_id,
5020 const struct ieee80211_sta_he_cap *he_cap)
5022 struct net_device *dev = info->user_ptr[1];
5023 struct wireless_dev *wdev = dev->ieee80211_ptr;
5024 struct cfg80211_chan_def *chandef;
5027 chandef = wdev_chandef(wdev, link_id);
5030 * This is probably broken, but we never maintained
5031 * a chandef in these cases, so it always was.
5033 return le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
5036 switch (chandef->width) {
5037 case NL80211_CHAN_WIDTH_80P80:
5038 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80;
5040 case NL80211_CHAN_WIDTH_160:
5041 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160;
5044 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80;
5048 return le16_to_cpu(tx_mcs);
5051 static bool he_set_mcs_mask(struct genl_info *info,
5052 struct wireless_dev *wdev,
5053 struct ieee80211_supported_band *sband,
5054 struct nl80211_txrate_he *txrate,
5055 u16 mcs[NL80211_HE_NSS_MAX],
5056 unsigned int link_id)
5058 const struct ieee80211_sta_he_cap *he_cap;
5059 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {};
5063 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
5067 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX);
5069 tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap);
5071 /* Build he_mcs_mask from HE capabilities */
5072 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
5074 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
5075 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
5076 mcs[i] = txrate->mcs[i];
5084 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
5085 struct nlattr *attrs[],
5086 enum nl80211_attrs attr,
5087 struct cfg80211_bitrate_mask *mask,
5088 struct net_device *dev,
5089 bool default_all_enabled,
5090 unsigned int link_id)
5092 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
5093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5094 struct wireless_dev *wdev = dev->ieee80211_ptr;
5096 struct nlattr *tx_rates;
5097 struct ieee80211_supported_band *sband;
5098 u16 vht_tx_mcs_map, he_tx_mcs_map;
5100 memset(mask, 0, sizeof(*mask));
5101 /* Default to all rates enabled */
5102 for (i = 0; i < NUM_NL80211_BANDS; i++) {
5103 const struct ieee80211_sta_he_cap *he_cap;
5105 if (!default_all_enabled)
5108 sband = rdev->wiphy.bands[i];
5113 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
5114 memcpy(mask->control[i].ht_mcs,
5115 sband->ht_cap.mcs.rx_mask,
5116 sizeof(mask->control[i].ht_mcs));
5118 if (sband->vht_cap.vht_supported) {
5119 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5120 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
5123 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
5127 he_tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap);
5128 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs);
5130 mask->control[i].he_gi = 0xFF;
5131 mask->control[i].he_ltf = 0xFF;
5134 /* if no rates are given set it back to the defaults */
5138 /* The nested attribute uses enum nl80211_band as the index. This maps
5139 * directly to the enum nl80211_band values used in cfg80211.
5141 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
5142 nla_for_each_nested(tx_rates, attrs[attr], rem) {
5143 enum nl80211_band band = nla_type(tx_rates);
5146 if (band < 0 || band >= NUM_NL80211_BANDS)
5148 sband = rdev->wiphy.bands[band];
5151 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
5153 nl80211_txattr_policy,
5157 if (tb[NL80211_TXRATE_LEGACY]) {
5158 mask->control[band].legacy = rateset_to_mask(
5160 nla_data(tb[NL80211_TXRATE_LEGACY]),
5161 nla_len(tb[NL80211_TXRATE_LEGACY]));
5162 if ((mask->control[band].legacy == 0) &&
5163 nla_len(tb[NL80211_TXRATE_LEGACY]))
5166 if (tb[NL80211_TXRATE_HT]) {
5167 if (!ht_rateset_to_mask(
5169 nla_data(tb[NL80211_TXRATE_HT]),
5170 nla_len(tb[NL80211_TXRATE_HT]),
5171 mask->control[band].ht_mcs))
5175 if (tb[NL80211_TXRATE_VHT]) {
5176 if (!vht_set_mcs_mask(
5178 nla_data(tb[NL80211_TXRATE_VHT]),
5179 mask->control[band].vht_mcs))
5183 if (tb[NL80211_TXRATE_GI]) {
5184 mask->control[band].gi =
5185 nla_get_u8(tb[NL80211_TXRATE_GI]);
5186 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
5189 if (tb[NL80211_TXRATE_HE] &&
5190 !he_set_mcs_mask(info, wdev, sband,
5191 nla_data(tb[NL80211_TXRATE_HE]),
5192 mask->control[band].he_mcs,
5196 if (tb[NL80211_TXRATE_HE_GI])
5197 mask->control[band].he_gi =
5198 nla_get_u8(tb[NL80211_TXRATE_HE_GI]);
5199 if (tb[NL80211_TXRATE_HE_LTF])
5200 mask->control[band].he_ltf =
5201 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]);
5203 if (mask->control[band].legacy == 0) {
5204 /* don't allow empty legacy rates if HT, VHT or HE
5205 * are not even supported.
5207 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
5208 rdev->wiphy.bands[band]->vht_cap.vht_supported ||
5209 ieee80211_get_he_iftype_cap(sband, wdev->iftype)))
5212 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5213 if (mask->control[band].ht_mcs[i])
5216 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5217 if (mask->control[band].vht_mcs[i])
5220 for (i = 0; i < NL80211_HE_NSS_MAX; i++)
5221 if (mask->control[band].he_mcs[i])
5224 /* legacy and mcs rates may not be both empty */
5233 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
5234 enum nl80211_band band,
5235 struct cfg80211_bitrate_mask *beacon_rate)
5237 u32 count_ht, count_vht, count_he, i;
5238 u32 rate = beacon_rate->control[band].legacy;
5240 /* Allow only one rate */
5241 if (hweight32(rate) > 1)
5245 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5246 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
5248 } else if (beacon_rate->control[band].ht_mcs[i]) {
5253 if (count_ht && rate)
5258 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5259 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
5261 } else if (beacon_rate->control[band].vht_mcs[i]) {
5266 if (count_vht && rate)
5271 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
5272 if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) {
5274 } else if (beacon_rate->control[band].he_mcs[i]) {
5279 if (count_he && rate)
5283 if ((count_ht && count_vht && count_he) ||
5284 (!rate && !count_ht && !count_vht && !count_he))
5288 !wiphy_ext_feature_isset(&rdev->wiphy,
5289 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
5292 !wiphy_ext_feature_isset(&rdev->wiphy,
5293 NL80211_EXT_FEATURE_BEACON_RATE_HT))
5296 !wiphy_ext_feature_isset(&rdev->wiphy,
5297 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
5300 !wiphy_ext_feature_isset(&rdev->wiphy,
5301 NL80211_EXT_FEATURE_BEACON_RATE_HE))
5307 static int nl80211_parse_mbssid_config(struct wiphy *wiphy,
5308 struct net_device *dev,
5309 struct nlattr *attrs,
5310 struct cfg80211_mbssid_config *config,
5313 struct nlattr *tb[NL80211_MBSSID_CONFIG_ATTR_MAX + 1];
5315 if (!wiphy->mbssid_max_interfaces)
5318 if (nla_parse_nested(tb, NL80211_MBSSID_CONFIG_ATTR_MAX, attrs, NULL,
5320 !tb[NL80211_MBSSID_CONFIG_ATTR_INDEX])
5323 config->ema = nla_get_flag(tb[NL80211_MBSSID_CONFIG_ATTR_EMA]);
5325 if (!wiphy->ema_max_profile_periodicity)
5328 if (num_elems > wiphy->ema_max_profile_periodicity)
5332 config->index = nla_get_u8(tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]);
5333 if (config->index >= wiphy->mbssid_max_interfaces ||
5334 (!config->index && !num_elems))
5337 if (tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]) {
5339 nla_get_u32(tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]);
5341 if ((!config->index && tx_ifindex != dev->ifindex) ||
5342 (config->index && tx_ifindex == dev->ifindex))
5345 if (tx_ifindex != dev->ifindex) {
5346 struct net_device *tx_netdev =
5347 dev_get_by_index(wiphy_net(wiphy), tx_ifindex);
5349 if (!tx_netdev || !tx_netdev->ieee80211_ptr ||
5350 tx_netdev->ieee80211_ptr->wiphy != wiphy ||
5351 tx_netdev->ieee80211_ptr->iftype !=
5352 NL80211_IFTYPE_AP) {
5357 config->tx_wdev = tx_netdev->ieee80211_ptr;
5359 config->tx_wdev = dev->ieee80211_ptr;
5361 } else if (!config->index) {
5362 config->tx_wdev = dev->ieee80211_ptr;
5370 static struct cfg80211_mbssid_elems *
5371 nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs)
5373 struct nlattr *nl_elems;
5374 struct cfg80211_mbssid_elems *elems;
5376 u8 i = 0, num_elems = 0;
5378 if (!wiphy->mbssid_max_interfaces)
5379 return ERR_PTR(-EINVAL);
5381 nla_for_each_nested(nl_elems, attrs, rem_elems)
5384 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
5386 return ERR_PTR(-ENOMEM);
5388 nla_for_each_nested(nl_elems, attrs, rem_elems) {
5389 elems->elem[i].data = nla_data(nl_elems);
5390 elems->elem[i].len = nla_len(nl_elems);
5393 elems->cnt = num_elems;
5397 static int nl80211_parse_he_bss_color(struct nlattr *attrs,
5398 struct cfg80211_he_bss_color *he_bss_color)
5400 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1];
5403 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs,
5404 he_bss_color_policy, NULL);
5408 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR])
5411 he_bss_color->color =
5412 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]);
5413 he_bss_color->enabled =
5414 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]);
5415 he_bss_color->partial =
5416 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]);
5421 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
5422 struct nlattr *attrs[],
5423 struct cfg80211_beacon_data *bcn)
5425 bool haveinfo = false;
5428 memset(bcn, 0, sizeof(*bcn));
5430 bcn->link_id = nl80211_link_id(attrs);
5432 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
5433 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
5434 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
5440 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
5441 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
5442 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
5449 if (attrs[NL80211_ATTR_IE]) {
5450 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
5451 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
5454 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
5455 bcn->proberesp_ies =
5456 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
5457 bcn->proberesp_ies_len =
5458 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
5461 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
5462 bcn->assocresp_ies =
5463 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
5464 bcn->assocresp_ies_len =
5465 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
5468 if (attrs[NL80211_ATTR_PROBE_RESP]) {
5469 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
5470 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
5473 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
5474 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
5476 err = nla_parse_nested_deprecated(tb,
5477 NL80211_FTM_RESP_ATTR_MAX,
5478 attrs[NL80211_ATTR_FTM_RESPONDER],
5483 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
5484 wiphy_ext_feature_isset(&rdev->wiphy,
5485 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
5486 bcn->ftm_responder = 1;
5490 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
5491 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
5492 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
5495 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
5496 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
5497 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
5500 bcn->ftm_responder = -1;
5503 if (attrs[NL80211_ATTR_HE_BSS_COLOR]) {
5504 err = nl80211_parse_he_bss_color(attrs[NL80211_ATTR_HE_BSS_COLOR],
5505 &bcn->he_bss_color);
5508 bcn->he_bss_color_valid = true;
5511 if (attrs[NL80211_ATTR_MBSSID_ELEMS]) {
5512 struct cfg80211_mbssid_elems *mbssid =
5513 nl80211_parse_mbssid_elems(&rdev->wiphy,
5514 attrs[NL80211_ATTR_MBSSID_ELEMS]);
5517 return PTR_ERR(mbssid);
5519 bcn->mbssid_ies = mbssid;
5525 static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
5526 struct ieee80211_he_obss_pd *he_obss_pd)
5528 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
5531 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
5532 he_obss_pd_policy, NULL);
5536 if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL])
5539 he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]);
5541 if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET])
5542 he_obss_pd->min_offset =
5543 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
5544 if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
5545 he_obss_pd->max_offset =
5546 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
5547 if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET])
5548 he_obss_pd->non_srg_max_offset =
5549 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]);
5551 if (he_obss_pd->min_offset > he_obss_pd->max_offset)
5554 if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP])
5555 memcpy(he_obss_pd->bss_color_bitmap,
5556 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]),
5557 sizeof(he_obss_pd->bss_color_bitmap));
5559 if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP])
5560 memcpy(he_obss_pd->partial_bssid_bitmap,
5561 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]),
5562 sizeof(he_obss_pd->partial_bssid_bitmap));
5564 he_obss_pd->enable = true;
5569 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev,
5570 struct nlattr *attrs,
5571 struct cfg80211_ap_settings *params)
5573 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1];
5575 struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery;
5577 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5578 NL80211_EXT_FEATURE_FILS_DISCOVERY))
5581 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs,
5586 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] ||
5587 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] ||
5588 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL])
5591 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
5592 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
5593 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]);
5594 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]);
5600 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev,
5601 struct nlattr *attrs,
5602 struct cfg80211_ap_settings *params)
5604 struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1];
5606 struct cfg80211_unsol_bcast_probe_resp *presp =
5607 ¶ms->unsol_bcast_probe_resp;
5609 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5610 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP))
5613 ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX,
5618 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] ||
5619 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL])
5622 presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]);
5623 presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]);
5624 presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]);
5628 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
5629 const struct element *rates)
5636 for (i = 0; i < rates->datalen; i++) {
5637 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
5638 params->ht_required = true;
5639 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
5640 params->vht_required = true;
5641 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
5642 params->he_required = true;
5643 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E)
5644 params->sae_h2e_required = true;
5649 * Since the nl80211 API didn't include, from the beginning, attributes about
5650 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
5651 * benefit of drivers that rebuild IEs in the firmware.
5653 static int nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
5655 const struct cfg80211_beacon_data *bcn = ¶ms->beacon;
5656 size_t ies_len = bcn->tail_len;
5657 const u8 *ies = bcn->tail;
5658 const struct element *rates;
5659 const struct element *cap;
5661 rates = cfg80211_find_elem(WLAN_EID_SUPP_RATES, ies, ies_len);
5662 nl80211_check_ap_rate_selectors(params, rates);
5664 rates = cfg80211_find_elem(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
5665 nl80211_check_ap_rate_selectors(params, rates);
5667 cap = cfg80211_find_elem(WLAN_EID_HT_CAPABILITY, ies, ies_len);
5668 if (cap && cap->datalen >= sizeof(*params->ht_cap))
5669 params->ht_cap = (void *)cap->data;
5670 cap = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
5671 if (cap && cap->datalen >= sizeof(*params->vht_cap))
5672 params->vht_cap = (void *)cap->data;
5673 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
5674 if (cap && cap->datalen >= sizeof(*params->he_cap) + 1)
5675 params->he_cap = (void *)(cap->data + 1);
5676 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ies, ies_len);
5677 if (cap && cap->datalen >= sizeof(*params->he_oper) + 1)
5678 params->he_oper = (void *)(cap->data + 1);
5679 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_CAPABILITY, ies, ies_len);
5683 params->eht_cap = (void *)(cap->data + 1);
5684 if (!ieee80211_eht_capa_size_ok((const u8 *)params->he_cap,
5685 (const u8 *)params->eht_cap,
5686 cap->datalen - 1, true))
5689 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION, ies, ies_len);
5693 params->eht_oper = (void *)(cap->data + 1);
5694 if (!ieee80211_eht_oper_size_ok((const u8 *)params->eht_oper,
5701 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
5702 struct cfg80211_ap_settings *params)
5704 struct wireless_dev *wdev;
5706 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
5707 if (wdev->iftype != NL80211_IFTYPE_AP &&
5708 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5711 if (!wdev->u.ap.preset_chandef.chan)
5714 params->chandef = wdev->u.ap.preset_chandef;
5721 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
5722 enum nl80211_auth_type auth_type,
5723 enum nl80211_commands cmd)
5725 if (auth_type > NL80211_AUTHTYPE_MAX)
5729 case NL80211_CMD_AUTHENTICATE:
5730 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
5731 auth_type == NL80211_AUTHTYPE_SAE)
5733 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5734 NL80211_EXT_FEATURE_FILS_STA) &&
5735 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5736 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5737 auth_type == NL80211_AUTHTYPE_FILS_PK))
5740 case NL80211_CMD_CONNECT:
5741 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
5742 !wiphy_ext_feature_isset(&rdev->wiphy,
5743 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
5744 auth_type == NL80211_AUTHTYPE_SAE)
5747 /* FILS with SK PFS or PK not supported yet */
5748 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5749 auth_type == NL80211_AUTHTYPE_FILS_PK)
5751 if (!wiphy_ext_feature_isset(
5753 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
5754 auth_type == NL80211_AUTHTYPE_FILS_SK)
5757 case NL80211_CMD_START_AP:
5758 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5759 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) &&
5760 auth_type == NL80211_AUTHTYPE_SAE)
5762 /* FILS not supported yet */
5763 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5764 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5765 auth_type == NL80211_AUTHTYPE_FILS_PK)
5773 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
5775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5776 unsigned int link_id = nl80211_link_id(info->attrs);
5777 struct net_device *dev = info->user_ptr[1];
5778 struct wireless_dev *wdev = dev->ieee80211_ptr;
5779 struct cfg80211_ap_settings *params;
5782 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5783 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5786 if (!rdev->ops->start_ap)
5789 if (wdev->links[link_id].ap.beacon_interval)
5792 /* these are required for START_AP */
5793 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
5794 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
5795 !info->attrs[NL80211_ATTR_BEACON_HEAD])
5798 params = kzalloc(sizeof(*params), GFP_KERNEL);
5802 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon);
5806 params->beacon_interval =
5807 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5808 params->dtim_period =
5809 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
5811 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
5812 params->beacon_interval);
5817 * In theory, some of these attributes should be required here
5818 * but since they were not used when the command was originally
5819 * added, keep them optional for old user space programs to let
5820 * them continue to work with drivers that do not need the
5821 * additional information -- drivers must check!
5823 if (info->attrs[NL80211_ATTR_SSID]) {
5824 params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5826 nla_len(info->attrs[NL80211_ATTR_SSID]);
5827 if (params->ssid_len == 0) {
5832 if (wdev->u.ap.ssid_len &&
5833 (wdev->u.ap.ssid_len != params->ssid_len ||
5834 memcmp(wdev->u.ap.ssid, params->ssid, params->ssid_len))) {
5835 /* require identical SSID for MLO */
5839 } else if (wdev->valid_links) {
5840 /* require SSID for MLO */
5845 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
5846 params->hidden_ssid = nla_get_u32(
5847 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
5849 params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5851 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5852 params->auth_type = nla_get_u32(
5853 info->attrs[NL80211_ATTR_AUTH_TYPE]);
5854 if (!nl80211_valid_auth_type(rdev, params->auth_type,
5855 NL80211_CMD_START_AP)) {
5860 params->auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5862 err = nl80211_crypto_settings(rdev, info, ¶ms->crypto,
5863 NL80211_MAX_NR_CIPHER_SUITES);
5867 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
5868 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) {
5872 params->inactivity_timeout = nla_get_u16(
5873 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
5876 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5877 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5881 params->p2p_ctwindow =
5882 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5883 if (params->p2p_ctwindow != 0 &&
5884 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) {
5890 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5893 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5897 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5898 params->p2p_opp_ps = tmp;
5899 if (params->p2p_opp_ps != 0 &&
5900 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) {
5906 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5907 err = nl80211_parse_chandef(rdev, info, ¶ms->chandef);
5910 } else if (wdev->valid_links) {
5911 /* with MLD need to specify the channel configuration */
5914 } else if (wdev->u.ap.preset_chandef.chan) {
5915 params->chandef = wdev->u.ap.preset_chandef;
5916 } else if (!nl80211_get_ap_channel(rdev, params)) {
5921 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef,
5929 if (info->attrs[NL80211_ATTR_TX_RATES]) {
5930 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
5931 NL80211_ATTR_TX_RATES,
5932 ¶ms->beacon_rate,
5933 dev, false, link_id);
5937 err = validate_beacon_tx_rate(rdev, params->chandef.chan->band,
5938 ¶ms->beacon_rate);
5943 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
5945 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
5946 switch (params->smps_mode) {
5947 case NL80211_SMPS_OFF:
5949 case NL80211_SMPS_STATIC:
5950 if (!(rdev->wiphy.features &
5951 NL80211_FEATURE_STATIC_SMPS)) {
5956 case NL80211_SMPS_DYNAMIC:
5957 if (!(rdev->wiphy.features &
5958 NL80211_FEATURE_DYNAMIC_SMPS)) {
5968 params->smps_mode = NL80211_SMPS_OFF;
5971 params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
5972 if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
5977 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
5978 params->acl = parse_acl_data(&rdev->wiphy, info);
5979 if (IS_ERR(params->acl)) {
5980 err = PTR_ERR(params->acl);
5986 params->twt_responder =
5987 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
5989 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
5990 err = nl80211_parse_he_obss_pd(
5991 info->attrs[NL80211_ATTR_HE_OBSS_PD],
5992 ¶ms->he_obss_pd);
5997 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) {
5998 err = nl80211_parse_fils_discovery(rdev,
5999 info->attrs[NL80211_ATTR_FILS_DISCOVERY],
6005 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) {
6006 err = nl80211_parse_unsol_bcast_probe_resp(
6007 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP],
6013 if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) {
6014 err = nl80211_parse_mbssid_config(&rdev->wiphy, dev,
6015 info->attrs[NL80211_ATTR_MBSSID_CONFIG],
6016 ¶ms->mbssid_config,
6017 params->beacon.mbssid_ies ?
6018 params->beacon.mbssid_ies->cnt :
6024 err = nl80211_calculate_ap_params(params);
6028 if (info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS])
6029 params->flags = nla_get_u32(
6030 info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]);
6031 else if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
6032 params->flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
6034 if (wdev->conn_owner_nlportid &&
6035 info->attrs[NL80211_ATTR_SOCKET_OWNER] &&
6036 wdev->conn_owner_nlportid != info->snd_portid) {
6041 /* FIXME: validate MLO/link-id against driver capabilities */
6043 err = rdev_start_ap(rdev, dev, params);
6045 wdev->links[link_id].ap.beacon_interval = params->beacon_interval;
6046 wdev->links[link_id].ap.chandef = params->chandef;
6047 wdev->u.ap.ssid_len = params->ssid_len;
6048 memcpy(wdev->u.ap.ssid, params->ssid,
6051 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6052 wdev->conn_owner_nlportid = info->snd_portid;
6058 kfree(params->beacon.mbssid_ies);
6059 if (params->mbssid_config.tx_wdev &&
6060 params->mbssid_config.tx_wdev->netdev &&
6061 params->mbssid_config.tx_wdev->netdev != dev)
6062 dev_put(params->mbssid_config.tx_wdev->netdev);
6068 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
6070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6071 unsigned int link_id = nl80211_link_id(info->attrs);
6072 struct net_device *dev = info->user_ptr[1];
6073 struct wireless_dev *wdev = dev->ieee80211_ptr;
6074 struct cfg80211_beacon_data params;
6077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6078 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6081 if (!rdev->ops->change_beacon)
6084 if (!wdev->links[link_id].ap.beacon_interval)
6087 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms);
6092 err = rdev_change_beacon(rdev, dev, ¶ms);
6096 kfree(params.mbssid_ies);
6100 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
6102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6103 unsigned int link_id = nl80211_link_id(info->attrs);
6104 struct net_device *dev = info->user_ptr[1];
6106 return cfg80211_stop_ap(rdev, dev, link_id, false);
6109 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
6110 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
6111 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
6112 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
6113 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
6114 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
6115 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
6118 static int parse_station_flags(struct genl_info *info,
6119 enum nl80211_iftype iftype,
6120 struct station_parameters *params)
6122 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
6127 * Try parsing the new attribute first so userspace
6128 * can specify both for older kernels.
6130 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
6132 struct nl80211_sta_flag_update *sta_flags;
6134 sta_flags = nla_data(nla);
6135 params->sta_flags_mask = sta_flags->mask;
6136 params->sta_flags_set = sta_flags->set;
6137 params->sta_flags_set &= params->sta_flags_mask;
6138 if ((params->sta_flags_mask |
6139 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
6144 /* if present, parse the old attribute */
6146 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
6150 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
6154 * Only allow certain flags for interface types so that
6155 * other attributes are silently ignored. Remember that
6156 * this is backward compatibility code with old userspace
6157 * and shouldn't be hit in other cases anyway.
6160 case NL80211_IFTYPE_AP:
6161 case NL80211_IFTYPE_AP_VLAN:
6162 case NL80211_IFTYPE_P2P_GO:
6163 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
6164 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
6165 BIT(NL80211_STA_FLAG_WME) |
6166 BIT(NL80211_STA_FLAG_MFP);
6168 case NL80211_IFTYPE_P2P_CLIENT:
6169 case NL80211_IFTYPE_STATION:
6170 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
6171 BIT(NL80211_STA_FLAG_TDLS_PEER);
6173 case NL80211_IFTYPE_MESH_POINT:
6174 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6175 BIT(NL80211_STA_FLAG_MFP) |
6176 BIT(NL80211_STA_FLAG_AUTHORIZED);
6182 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
6184 params->sta_flags_set |= (1<<flag);
6186 /* no longer support new API additions in old API */
6187 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
6195 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
6197 struct nlattr *rate;
6200 enum nl80211_rate_info rate_flg;
6202 rate = nla_nest_start_noflag(msg, attr);
6206 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
6207 bitrate = cfg80211_calculate_bitrate(info);
6208 /* report 16-bit bitrate only if we can */
6209 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
6211 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
6213 if (bitrate_compat > 0 &&
6214 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
6218 case RATE_INFO_BW_5:
6219 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
6221 case RATE_INFO_BW_10:
6222 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
6227 case RATE_INFO_BW_20:
6230 case RATE_INFO_BW_40:
6231 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
6233 case RATE_INFO_BW_80:
6234 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
6236 case RATE_INFO_BW_160:
6237 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
6239 case RATE_INFO_BW_HE_RU:
6241 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
6243 case RATE_INFO_BW_320:
6244 rate_flg = NL80211_RATE_INFO_320_MHZ_WIDTH;
6246 case RATE_INFO_BW_EHT_RU:
6248 WARN_ON(!(info->flags & RATE_INFO_FLAGS_EHT_MCS));
6252 if (rate_flg && nla_put_flag(msg, rate_flg))
6255 if (info->flags & RATE_INFO_FLAGS_MCS) {
6256 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
6258 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6259 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6261 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
6262 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
6264 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
6266 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
6267 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
6269 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
6270 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
6272 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
6274 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
6276 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
6278 if (info->bw == RATE_INFO_BW_HE_RU &&
6279 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
6282 } else if (info->flags & RATE_INFO_FLAGS_EHT_MCS) {
6283 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_MCS, info->mcs))
6285 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_NSS, info->nss))
6287 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_GI, info->eht_gi))
6289 if (info->bw == RATE_INFO_BW_EHT_RU &&
6290 nla_put_u8(msg, NL80211_RATE_INFO_EHT_RU_ALLOC,
6291 info->eht_ru_alloc))
6295 nla_nest_end(msg, rate);
6299 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
6308 attr = nla_nest_start_noflag(msg, id);
6312 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
6313 if (!(mask & BIT(i)))
6316 if (nla_put_u8(msg, i, signal[i]))
6320 nla_nest_end(msg, attr);
6325 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
6327 struct cfg80211_registered_device *rdev,
6328 struct net_device *dev,
6329 const u8 *mac_addr, struct station_info *sinfo)
6332 struct nlattr *sinfoattr, *bss_param;
6334 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
6336 cfg80211_sinfo_release_content(sinfo);
6340 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6341 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
6342 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
6343 goto nla_put_failure;
6345 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
6347 goto nla_put_failure;
6349 #define PUT_SINFO(attr, memb, type) do { \
6350 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
6351 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
6352 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
6354 goto nla_put_failure; \
6356 #define PUT_SINFO_U64(attr, memb) do { \
6357 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
6358 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
6359 sinfo->memb, NL80211_STA_INFO_PAD)) \
6360 goto nla_put_failure; \
6363 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
6364 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
6365 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
6367 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
6368 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
6369 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
6370 (u32)sinfo->rx_bytes))
6371 goto nla_put_failure;
6373 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
6374 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
6375 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
6376 (u32)sinfo->tx_bytes))
6377 goto nla_put_failure;
6379 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
6380 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
6381 PUT_SINFO(LLID, llid, u16);
6382 PUT_SINFO(PLID, plid, u16);
6383 PUT_SINFO(PLINK_STATE, plink_state, u8);
6384 PUT_SINFO_U64(RX_DURATION, rx_duration);
6385 PUT_SINFO_U64(TX_DURATION, tx_duration);
6387 if (wiphy_ext_feature_isset(&rdev->wiphy,
6388 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6389 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
6391 switch (rdev->wiphy.signal_type) {
6392 case CFG80211_SIGNAL_TYPE_MBM:
6393 PUT_SINFO(SIGNAL, signal, u8);
6394 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
6399 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
6400 if (!nl80211_put_signal(msg, sinfo->chains,
6401 sinfo->chain_signal,
6402 NL80211_STA_INFO_CHAIN_SIGNAL))
6403 goto nla_put_failure;
6405 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
6406 if (!nl80211_put_signal(msg, sinfo->chains,
6407 sinfo->chain_signal_avg,
6408 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
6409 goto nla_put_failure;
6411 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
6412 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
6413 NL80211_STA_INFO_TX_BITRATE))
6414 goto nla_put_failure;
6416 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
6417 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
6418 NL80211_STA_INFO_RX_BITRATE))
6419 goto nla_put_failure;
6422 PUT_SINFO(RX_PACKETS, rx_packets, u32);
6423 PUT_SINFO(TX_PACKETS, tx_packets, u32);
6424 PUT_SINFO(TX_RETRIES, tx_retries, u32);
6425 PUT_SINFO(TX_FAILED, tx_failed, u32);
6426 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
6427 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
6428 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
6429 PUT_SINFO(LOCAL_PM, local_pm, u32);
6430 PUT_SINFO(PEER_PM, peer_pm, u32);
6431 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
6432 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
6433 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8);
6435 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
6436 bss_param = nla_nest_start_noflag(msg,
6437 NL80211_STA_INFO_BSS_PARAM);
6439 goto nla_put_failure;
6441 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
6442 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
6443 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
6444 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
6445 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
6446 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
6447 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
6448 sinfo->bss_param.dtim_period) ||
6449 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
6450 sinfo->bss_param.beacon_interval))
6451 goto nla_put_failure;
6453 nla_nest_end(msg, bss_param);
6455 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
6456 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
6457 sizeof(struct nl80211_sta_flag_update),
6459 goto nla_put_failure;
6461 PUT_SINFO_U64(T_OFFSET, t_offset);
6462 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
6463 PUT_SINFO_U64(BEACON_RX, rx_beacon);
6464 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
6465 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
6466 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
6467 if (wiphy_ext_feature_isset(&rdev->wiphy,
6468 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
6469 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
6470 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
6474 #undef PUT_SINFO_U64
6476 if (sinfo->pertid) {
6477 struct nlattr *tidsattr;
6480 tidsattr = nla_nest_start_noflag(msg,
6481 NL80211_STA_INFO_TID_STATS);
6483 goto nla_put_failure;
6485 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
6486 struct cfg80211_tid_stats *tidstats;
6487 struct nlattr *tidattr;
6489 tidstats = &sinfo->pertid[tid];
6491 if (!tidstats->filled)
6494 tidattr = nla_nest_start_noflag(msg, tid + 1);
6496 goto nla_put_failure;
6498 #define PUT_TIDVAL_U64(attr, memb) do { \
6499 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
6500 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
6501 tidstats->memb, NL80211_TID_STATS_PAD)) \
6502 goto nla_put_failure; \
6505 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
6506 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
6507 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
6508 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
6510 #undef PUT_TIDVAL_U64
6511 if ((tidstats->filled &
6512 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
6513 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
6514 NL80211_TID_STATS_TXQ_STATS))
6515 goto nla_put_failure;
6517 nla_nest_end(msg, tidattr);
6520 nla_nest_end(msg, tidsattr);
6523 nla_nest_end(msg, sinfoattr);
6525 if (sinfo->assoc_req_ies_len &&
6526 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
6527 sinfo->assoc_req_ies))
6528 goto nla_put_failure;
6530 cfg80211_sinfo_release_content(sinfo);
6531 genlmsg_end(msg, hdr);
6535 cfg80211_sinfo_release_content(sinfo);
6536 genlmsg_cancel(msg, hdr);
6540 static int nl80211_dump_station(struct sk_buff *skb,
6541 struct netlink_callback *cb)
6543 struct station_info sinfo;
6544 struct cfg80211_registered_device *rdev;
6545 struct wireless_dev *wdev;
6546 u8 mac_addr[ETH_ALEN];
6547 int sta_idx = cb->args[2];
6550 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
6553 /* nl80211_prepare_wdev_dump acquired it in the successful case */
6554 __acquire(&rdev->wiphy.mtx);
6556 if (!wdev->netdev) {
6561 if (!rdev->ops->dump_station) {
6567 memset(&sinfo, 0, sizeof(sinfo));
6568 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
6575 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
6576 NETLINK_CB(cb->skb).portid,
6577 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6578 rdev, wdev->netdev, mac_addr,
6586 cb->args[2] = sta_idx;
6589 wiphy_unlock(&rdev->wiphy);
6594 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
6596 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6597 struct net_device *dev = info->user_ptr[1];
6598 struct station_info sinfo;
6599 struct sk_buff *msg;
6600 u8 *mac_addr = NULL;
6603 memset(&sinfo, 0, sizeof(sinfo));
6605 if (!info->attrs[NL80211_ATTR_MAC])
6608 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6610 if (!rdev->ops->get_station)
6613 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
6617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6619 cfg80211_sinfo_release_content(&sinfo);
6623 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
6624 info->snd_portid, info->snd_seq, 0,
6625 rdev, dev, mac_addr, &sinfo) < 0) {
6630 return genlmsg_reply(msg, info);
6633 int cfg80211_check_station_change(struct wiphy *wiphy,
6634 struct station_parameters *params,
6635 enum cfg80211_station_type statype)
6637 if (params->listen_interval != -1 &&
6638 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6641 if (params->support_p2p_ps != -1 &&
6642 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6646 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
6647 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
6650 /* When you run into this, adjust the code below for the new flag */
6651 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6654 case CFG80211_STA_MESH_PEER_KERNEL:
6655 case CFG80211_STA_MESH_PEER_USER:
6657 * No ignoring the TDLS flag here -- the userspace mesh
6658 * code doesn't have the bug of including TDLS in the
6661 if (params->sta_flags_mask &
6662 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6663 BIT(NL80211_STA_FLAG_MFP) |
6664 BIT(NL80211_STA_FLAG_AUTHORIZED)))
6667 case CFG80211_STA_TDLS_PEER_SETUP:
6668 case CFG80211_STA_TDLS_PEER_ACTIVE:
6669 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6671 /* ignore since it can't change */
6672 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6675 /* disallow mesh-specific things */
6676 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
6678 if (params->local_pm)
6680 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6684 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
6685 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
6686 /* TDLS can't be set, ... */
6687 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
6690 * ... but don't bother the driver with it. This works around
6691 * a hostapd/wpa_supplicant issue -- it always includes the
6692 * TLDS_PEER flag in the mask even for AP mode.
6694 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6697 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
6698 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
6699 /* reject other things that can't change */
6700 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
6702 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
6704 if (params->link_sta_params.supported_rates)
6706 if (params->ext_capab || params->link_sta_params.ht_capa ||
6707 params->link_sta_params.vht_capa ||
6708 params->link_sta_params.he_capa ||
6709 params->link_sta_params.eht_capa)
6713 if (statype != CFG80211_STA_AP_CLIENT &&
6714 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
6720 case CFG80211_STA_AP_MLME_CLIENT:
6721 /* Use this only for authorizing/unauthorizing a station */
6722 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
6725 case CFG80211_STA_AP_CLIENT:
6726 case CFG80211_STA_AP_CLIENT_UNASSOC:
6727 /* accept only the listed bits */
6728 if (params->sta_flags_mask &
6729 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
6730 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6731 BIT(NL80211_STA_FLAG_ASSOCIATED) |
6732 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
6733 BIT(NL80211_STA_FLAG_WME) |
6734 BIT(NL80211_STA_FLAG_MFP)))
6737 /* but authenticated/associated only if driver handles it */
6738 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
6739 params->sta_flags_mask &
6740 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6741 BIT(NL80211_STA_FLAG_ASSOCIATED)))
6744 case CFG80211_STA_IBSS:
6745 case CFG80211_STA_AP_STA:
6746 /* reject any changes other than AUTHORIZED */
6747 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
6750 case CFG80211_STA_TDLS_PEER_SETUP:
6751 /* reject any changes other than AUTHORIZED or WME */
6752 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
6753 BIT(NL80211_STA_FLAG_WME)))
6755 /* force (at least) rates when authorizing */
6756 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
6757 !params->link_sta_params.supported_rates)
6760 case CFG80211_STA_TDLS_PEER_ACTIVE:
6761 /* reject any changes */
6763 case CFG80211_STA_MESH_PEER_KERNEL:
6764 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6767 case CFG80211_STA_MESH_PEER_USER:
6768 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
6769 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
6775 * Older kernel versions ignored this attribute entirely, so don't
6776 * reject attempts to update it but mark it as unused instead so the
6777 * driver won't look at the data.
6779 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
6780 statype != CFG80211_STA_TDLS_PEER_SETUP)
6781 params->link_sta_params.opmode_notif_used = false;
6785 EXPORT_SYMBOL(cfg80211_check_station_change);
6788 * Get vlan interface making sure it is running and on the right wiphy.
6790 static struct net_device *get_vlan(struct genl_info *info,
6791 struct cfg80211_registered_device *rdev)
6793 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
6794 struct net_device *v;
6800 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
6802 return ERR_PTR(-ENODEV);
6804 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
6809 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6810 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6811 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
6816 if (!netif_running(v)) {
6824 return ERR_PTR(ret);
6827 static int nl80211_parse_sta_wme(struct genl_info *info,
6828 struct station_parameters *params)
6830 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
6834 /* parse WME attributes if present */
6835 if (!info->attrs[NL80211_ATTR_STA_WME])
6838 nla = info->attrs[NL80211_ATTR_STA_WME];
6839 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
6840 nl80211_sta_wme_policy,
6845 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
6846 params->uapsd_queues = nla_get_u8(
6847 tb[NL80211_STA_WME_UAPSD_QUEUES]);
6848 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
6851 if (tb[NL80211_STA_WME_MAX_SP])
6852 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
6854 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
6857 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
6862 static int nl80211_parse_sta_channel_info(struct genl_info *info,
6863 struct station_parameters *params)
6865 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
6866 params->supported_channels =
6867 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
6868 params->supported_channels_len =
6869 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
6871 * Need to include at least one (first channel, number of
6872 * channels) tuple for each subband (checked in policy),
6873 * and must have proper tuples for the rest of the data as well.
6875 if (params->supported_channels_len % 2)
6879 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
6880 params->supported_oper_classes =
6881 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
6882 params->supported_oper_classes_len =
6883 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
6888 static int nl80211_set_station_tdls(struct genl_info *info,
6889 struct station_parameters *params)
6892 /* Dummy STA entry gets updated once the peer capabilities are known */
6893 if (info->attrs[NL80211_ATTR_PEER_AID])
6894 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
6895 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6896 params->link_sta_params.ht_capa =
6897 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6898 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6899 params->link_sta_params.vht_capa =
6900 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6901 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
6902 params->link_sta_params.he_capa =
6903 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6904 params->link_sta_params.he_capa_len =
6905 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6907 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
6908 params->link_sta_params.eht_capa =
6909 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
6910 params->link_sta_params.eht_capa_len =
6911 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
6913 if (!ieee80211_eht_capa_size_ok((const u8 *)params->link_sta_params.he_capa,
6914 (const u8 *)params->link_sta_params.eht_capa,
6915 params->link_sta_params.eht_capa_len,
6921 err = nl80211_parse_sta_channel_info(info, params);
6925 return nl80211_parse_sta_wme(info, params);
6928 static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
6929 struct sta_txpwr *txpwr,
6932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6935 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
6936 if (!rdev->ops->set_tx_power ||
6937 !wiphy_ext_feature_isset(&rdev->wiphy,
6938 NL80211_EXT_FEATURE_STA_TX_PWR))
6941 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
6942 txpwr->type = nla_get_u8(info->attrs[idx]);
6944 if (txpwr->type == NL80211_TX_POWER_LIMITED) {
6945 idx = NL80211_ATTR_STA_TX_POWER;
6947 if (info->attrs[idx])
6948 txpwr->power = nla_get_s16(info->attrs[idx]);
6961 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
6963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6964 struct net_device *dev = info->user_ptr[1];
6965 struct station_parameters params;
6969 memset(¶ms, 0, sizeof(params));
6971 if (!rdev->ops->change_station)
6975 * AID and listen_interval properties can be set only for unassociated
6976 * station. Include these parameters here and will check them in
6977 * cfg80211_check_station_change().
6979 if (info->attrs[NL80211_ATTR_STA_AID])
6980 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
6982 if (info->attrs[NL80211_ATTR_VLAN_ID])
6983 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6985 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
6986 params.listen_interval =
6987 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
6989 params.listen_interval = -1;
6991 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
6992 params.support_p2p_ps =
6993 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
6995 params.support_p2p_ps = -1;
6997 if (!info->attrs[NL80211_ATTR_MAC])
7000 params.link_sta_params.link_id =
7001 nl80211_link_id_or_invalid(info->attrs);
7003 if (info->attrs[NL80211_ATTR_MLD_ADDR]) {
7004 /* If MLD_ADDR attribute is set then this is an MLD station
7005 * and the MLD_ADDR attribute holds the MLD address and the
7006 * MAC attribute holds for the LINK address.
7007 * In that case, the link_id is also expected to be valid.
7009 if (params.link_sta_params.link_id < 0)
7012 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
7013 params.link_sta_params.mld_mac = mac_addr;
7014 params.link_sta_params.link_mac =
7015 nla_data(info->attrs[NL80211_ATTR_MAC]);
7016 if (!is_valid_ether_addr(params.link_sta_params.link_mac))
7019 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7023 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
7024 params.link_sta_params.supported_rates =
7025 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7026 params.link_sta_params.supported_rates_len =
7027 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7030 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
7032 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
7033 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
7036 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
7038 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7039 params.ext_capab_len =
7040 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7043 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
7046 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
7047 params.plink_action =
7048 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
7050 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
7051 params.plink_state =
7052 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
7053 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
7054 params.peer_aid = nla_get_u16(
7055 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
7056 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
7059 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
7060 params.local_pm = nla_get_u32(
7061 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
7063 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
7064 params.link_sta_params.opmode_notif_used = true;
7065 params.link_sta_params.opmode_notif =
7066 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
7069 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
7070 params.link_sta_params.he_6ghz_capa =
7071 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
7073 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
7074 params.airtime_weight =
7075 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
7077 if (params.airtime_weight &&
7078 !wiphy_ext_feature_isset(&rdev->wiphy,
7079 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
7082 err = nl80211_parse_sta_txpower_setting(info,
7083 ¶ms.link_sta_params.txpwr,
7084 ¶ms.link_sta_params.txpwr_set);
7088 /* Include parameters for TDLS peer (will check later) */
7089 err = nl80211_set_station_tdls(info, ¶ms);
7093 params.vlan = get_vlan(info, rdev);
7094 if (IS_ERR(params.vlan))
7095 return PTR_ERR(params.vlan);
7097 switch (dev->ieee80211_ptr->iftype) {
7098 case NL80211_IFTYPE_AP:
7099 case NL80211_IFTYPE_AP_VLAN:
7100 case NL80211_IFTYPE_P2P_GO:
7101 case NL80211_IFTYPE_P2P_CLIENT:
7102 case NL80211_IFTYPE_STATION:
7103 case NL80211_IFTYPE_ADHOC:
7104 case NL80211_IFTYPE_MESH_POINT:
7111 /* driver will call cfg80211_check_station_change() */
7112 wdev_lock(dev->ieee80211_ptr);
7113 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
7114 wdev_unlock(dev->ieee80211_ptr);
7117 dev_put(params.vlan);
7122 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
7124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7126 struct net_device *dev = info->user_ptr[1];
7127 struct wireless_dev *wdev = dev->ieee80211_ptr;
7128 struct station_parameters params;
7129 u8 *mac_addr = NULL;
7130 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
7131 BIT(NL80211_STA_FLAG_ASSOCIATED);
7133 memset(¶ms, 0, sizeof(params));
7135 if (!rdev->ops->add_station)
7138 if (!info->attrs[NL80211_ATTR_MAC])
7141 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
7144 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
7147 if (!info->attrs[NL80211_ATTR_STA_AID] &&
7148 !info->attrs[NL80211_ATTR_PEER_AID])
7151 params.link_sta_params.link_id =
7152 nl80211_link_id_or_invalid(info->attrs);
7154 if (info->attrs[NL80211_ATTR_MLD_ADDR]) {
7155 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
7156 params.link_sta_params.mld_mac = mac_addr;
7157 params.link_sta_params.link_mac =
7158 nla_data(info->attrs[NL80211_ATTR_MAC]);
7159 if (!is_valid_ether_addr(params.link_sta_params.link_mac))
7162 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7165 params.link_sta_params.supported_rates =
7166 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7167 params.link_sta_params.supported_rates_len =
7168 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
7169 params.listen_interval =
7170 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
7172 if (info->attrs[NL80211_ATTR_VLAN_ID])
7173 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
7175 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
7176 params.support_p2p_ps =
7177 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
7180 * if not specified, assume it's supported for P2P GO interface,
7181 * and is NOT supported for AP interface
7183 params.support_p2p_ps =
7184 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
7187 if (info->attrs[NL80211_ATTR_PEER_AID])
7188 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
7190 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
7192 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
7194 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
7195 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
7198 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
7200 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7201 params.ext_capab_len =
7202 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
7205 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
7206 params.link_sta_params.ht_capa =
7207 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
7209 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
7210 params.link_sta_params.vht_capa =
7211 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
7213 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
7214 params.link_sta_params.he_capa =
7215 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7216 params.link_sta_params.he_capa_len =
7217 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
7219 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
7220 params.link_sta_params.eht_capa =
7221 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7222 params.link_sta_params.eht_capa_len =
7223 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
7225 if (!ieee80211_eht_capa_size_ok((const u8 *)params.link_sta_params.he_capa,
7226 (const u8 *)params.link_sta_params.eht_capa,
7227 params.link_sta_params.eht_capa_len,
7233 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
7234 params.link_sta_params.he_6ghz_capa =
7235 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
7237 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
7238 params.link_sta_params.opmode_notif_used = true;
7239 params.link_sta_params.opmode_notif =
7240 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
7243 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
7244 params.plink_action =
7245 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
7247 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
7248 params.airtime_weight =
7249 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
7251 if (params.airtime_weight &&
7252 !wiphy_ext_feature_isset(&rdev->wiphy,
7253 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
7256 err = nl80211_parse_sta_txpower_setting(info,
7257 ¶ms.link_sta_params.txpwr,
7258 ¶ms.link_sta_params.txpwr_set);
7262 err = nl80211_parse_sta_channel_info(info, ¶ms);
7266 err = nl80211_parse_sta_wme(info, ¶ms);
7270 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
7273 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
7274 * as userspace might just pass through the capabilities from the IEs
7275 * directly, rather than enforcing this restriction and returning an
7276 * error in this case.
7278 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
7279 params.link_sta_params.ht_capa = NULL;
7280 params.link_sta_params.vht_capa = NULL;
7282 /* HE and EHT require WME */
7283 if (params.link_sta_params.he_capa_len ||
7284 params.link_sta_params.he_6ghz_capa ||
7285 params.link_sta_params.eht_capa_len)
7289 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
7290 if (params.link_sta_params.he_6ghz_capa &&
7291 (params.link_sta_params.ht_capa || params.link_sta_params.vht_capa))
7294 /* When you run into this, adjust the code below for the new flag */
7295 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
7297 switch (dev->ieee80211_ptr->iftype) {
7298 case NL80211_IFTYPE_AP:
7299 case NL80211_IFTYPE_AP_VLAN:
7300 case NL80211_IFTYPE_P2P_GO:
7301 /* ignore WME attributes if iface/sta is not capable */
7302 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
7303 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
7304 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7306 /* TDLS peers cannot be added */
7307 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
7308 info->attrs[NL80211_ATTR_PEER_AID])
7310 /* but don't bother the driver with it */
7311 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
7313 /* allow authenticated/associated only if driver handles it */
7314 if (!(rdev->wiphy.features &
7315 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
7316 params.sta_flags_mask & auth_assoc)
7319 /* Older userspace, or userspace wanting to be compatible with
7320 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
7321 * and assoc flags in the mask, but assumes the station will be
7322 * added as associated anyway since this was the required driver
7323 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
7325 * In order to not bother drivers with this quirk in the API
7326 * set the flags in both the mask and set for new stations in
7329 if (!(params.sta_flags_mask & auth_assoc)) {
7330 params.sta_flags_mask |= auth_assoc;
7331 params.sta_flags_set |= auth_assoc;
7334 /* must be last in here for error handling */
7335 params.vlan = get_vlan(info, rdev);
7336 if (IS_ERR(params.vlan))
7337 return PTR_ERR(params.vlan);
7339 case NL80211_IFTYPE_MESH_POINT:
7340 /* ignore uAPSD data */
7341 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7343 /* associated is disallowed */
7344 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
7346 /* TDLS peers cannot be added */
7347 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
7348 info->attrs[NL80211_ATTR_PEER_AID])
7351 case NL80211_IFTYPE_STATION:
7352 case NL80211_IFTYPE_P2P_CLIENT:
7353 /* ignore uAPSD data */
7354 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
7356 /* these are disallowed */
7357 if (params.sta_flags_mask &
7358 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
7359 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
7361 /* Only TDLS peers can be added */
7362 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
7364 /* Can only add if TDLS ... */
7365 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
7367 /* ... with external setup is supported */
7368 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
7371 * Older wpa_supplicant versions always mark the TDLS peer
7372 * as authorized, but it shouldn't yet be.
7374 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
7380 /* be aware of params.vlan when changing code here */
7382 wdev_lock(dev->ieee80211_ptr);
7383 if (wdev->valid_links) {
7384 if (params.link_sta_params.link_id < 0) {
7388 if (!(wdev->valid_links & BIT(params.link_sta_params.link_id))) {
7393 if (params.link_sta_params.link_id >= 0) {
7398 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
7400 wdev_unlock(dev->ieee80211_ptr);
7401 dev_put(params.vlan);
7405 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
7407 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7408 struct net_device *dev = info->user_ptr[1];
7409 struct station_del_parameters params;
7412 memset(¶ms, 0, sizeof(params));
7414 if (info->attrs[NL80211_ATTR_MAC])
7415 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
7417 switch (dev->ieee80211_ptr->iftype) {
7418 case NL80211_IFTYPE_AP:
7419 case NL80211_IFTYPE_AP_VLAN:
7420 case NL80211_IFTYPE_MESH_POINT:
7421 case NL80211_IFTYPE_P2P_GO:
7422 /* always accept these */
7424 case NL80211_IFTYPE_ADHOC:
7425 /* conditionally accept */
7426 if (wiphy_ext_feature_isset(&rdev->wiphy,
7427 NL80211_EXT_FEATURE_DEL_IBSS_STA))
7434 if (!rdev->ops->del_station)
7437 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
7439 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
7440 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
7441 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
7444 /* Default to Deauthentication frame */
7445 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
7448 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
7449 params.reason_code =
7450 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7451 if (params.reason_code == 0)
7452 return -EINVAL; /* 0 is reserved */
7454 /* Default to reason code 2 */
7455 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
7458 wdev_lock(dev->ieee80211_ptr);
7459 ret = rdev_del_station(rdev, dev, ¶ms);
7460 wdev_unlock(dev->ieee80211_ptr);
7465 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
7466 int flags, struct net_device *dev,
7467 u8 *dst, u8 *next_hop,
7468 struct mpath_info *pinfo)
7471 struct nlattr *pinfoattr;
7473 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
7477 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7478 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7479 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
7480 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
7481 goto nla_put_failure;
7483 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
7485 goto nla_put_failure;
7486 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
7487 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
7489 goto nla_put_failure;
7490 if (((pinfo->filled & MPATH_INFO_SN) &&
7491 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
7492 ((pinfo->filled & MPATH_INFO_METRIC) &&
7493 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
7495 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
7496 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
7498 ((pinfo->filled & MPATH_INFO_FLAGS) &&
7499 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
7501 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
7502 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
7503 pinfo->discovery_timeout)) ||
7504 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
7505 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
7506 pinfo->discovery_retries)) ||
7507 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
7508 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
7509 pinfo->hop_count)) ||
7510 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
7511 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
7512 pinfo->path_change_count)))
7513 goto nla_put_failure;
7515 nla_nest_end(msg, pinfoattr);
7517 genlmsg_end(msg, hdr);
7521 genlmsg_cancel(msg, hdr);
7525 static int nl80211_dump_mpath(struct sk_buff *skb,
7526 struct netlink_callback *cb)
7528 struct mpath_info pinfo;
7529 struct cfg80211_registered_device *rdev;
7530 struct wireless_dev *wdev;
7532 u8 next_hop[ETH_ALEN];
7533 int path_idx = cb->args[2];
7536 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
7539 /* nl80211_prepare_wdev_dump acquired it in the successful case */
7540 __acquire(&rdev->wiphy.mtx);
7542 if (!rdev->ops->dump_mpath) {
7547 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
7553 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
7560 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
7561 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7562 wdev->netdev, dst, next_hop,
7570 cb->args[2] = path_idx;
7573 wiphy_unlock(&rdev->wiphy);
7577 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
7579 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7581 struct net_device *dev = info->user_ptr[1];
7582 struct mpath_info pinfo;
7583 struct sk_buff *msg;
7585 u8 next_hop[ETH_ALEN];
7587 memset(&pinfo, 0, sizeof(pinfo));
7589 if (!info->attrs[NL80211_ATTR_MAC])
7592 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7594 if (!rdev->ops->get_mpath)
7597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7600 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
7604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7608 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
7609 dev, dst, next_hop, &pinfo) < 0) {
7614 return genlmsg_reply(msg, info);
7617 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
7619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7620 struct net_device *dev = info->user_ptr[1];
7622 u8 *next_hop = NULL;
7624 if (!info->attrs[NL80211_ATTR_MAC])
7627 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
7630 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7631 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
7633 if (!rdev->ops->change_mpath)
7636 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7639 return rdev_change_mpath(rdev, dev, dst, next_hop);
7642 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
7644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7645 struct net_device *dev = info->user_ptr[1];
7647 u8 *next_hop = NULL;
7649 if (!info->attrs[NL80211_ATTR_MAC])
7652 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
7655 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7656 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
7658 if (!rdev->ops->add_mpath)
7661 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7664 return rdev_add_mpath(rdev, dev, dst, next_hop);
7667 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
7669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7670 struct net_device *dev = info->user_ptr[1];
7673 if (info->attrs[NL80211_ATTR_MAC])
7674 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7676 if (!rdev->ops->del_mpath)
7679 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7682 return rdev_del_mpath(rdev, dev, dst);
7685 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
7687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7689 struct net_device *dev = info->user_ptr[1];
7690 struct mpath_info pinfo;
7691 struct sk_buff *msg;
7695 memset(&pinfo, 0, sizeof(pinfo));
7697 if (!info->attrs[NL80211_ATTR_MAC])
7700 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
7702 if (!rdev->ops->get_mpp)
7705 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7708 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
7712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7716 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
7717 dev, dst, mpp, &pinfo) < 0) {
7722 return genlmsg_reply(msg, info);
7725 static int nl80211_dump_mpp(struct sk_buff *skb,
7726 struct netlink_callback *cb)
7728 struct mpath_info pinfo;
7729 struct cfg80211_registered_device *rdev;
7730 struct wireless_dev *wdev;
7733 int path_idx = cb->args[2];
7736 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
7739 /* nl80211_prepare_wdev_dump acquired it in the successful case */
7740 __acquire(&rdev->wiphy.mtx);
7742 if (!rdev->ops->dump_mpp) {
7747 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
7753 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
7760 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
7761 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7762 wdev->netdev, dst, mpp,
7770 cb->args[2] = path_idx;
7773 wiphy_unlock(&rdev->wiphy);
7777 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
7779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7780 struct net_device *dev = info->user_ptr[1];
7781 struct wireless_dev *wdev = dev->ieee80211_ptr;
7782 struct bss_parameters params;
7785 memset(¶ms, 0, sizeof(params));
7786 /* default to not changing parameters */
7787 params.use_cts_prot = -1;
7788 params.use_short_preamble = -1;
7789 params.use_short_slot_time = -1;
7790 params.ap_isolate = -1;
7791 params.ht_opmode = -1;
7792 params.p2p_ctwindow = -1;
7793 params.p2p_opp_ps = -1;
7795 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
7796 params.use_cts_prot =
7797 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
7798 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
7799 params.use_short_preamble =
7800 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
7801 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
7802 params.use_short_slot_time =
7803 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
7804 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7805 params.basic_rates =
7806 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7807 params.basic_rates_len =
7808 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7810 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
7811 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
7812 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
7814 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
7816 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
7817 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
7819 params.p2p_ctwindow =
7820 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
7821 if (params.p2p_ctwindow != 0 &&
7822 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
7826 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
7829 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
7831 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
7832 params.p2p_opp_ps = tmp;
7833 if (params.p2p_opp_ps &&
7834 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
7838 if (!rdev->ops->change_bss)
7841 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
7842 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
7846 err = rdev_change_bss(rdev, dev, ¶ms);
7852 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
7856 enum nl80211_user_reg_hint_type user_reg_hint_type;
7860 * You should only get this when cfg80211 hasn't yet initialized
7861 * completely when built-in to the kernel right between the time
7862 * window between nl80211_init() and regulatory_init(), if that is
7865 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
7866 return -EINPROGRESS;
7868 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
7869 user_reg_hint_type =
7870 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
7872 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
7874 switch (user_reg_hint_type) {
7875 case NL80211_USER_REG_HINT_USER:
7876 case NL80211_USER_REG_HINT_CELL_BASE:
7877 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7880 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7881 return regulatory_hint_user(data, user_reg_hint_type);
7882 case NL80211_USER_REG_HINT_INDOOR:
7883 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
7884 owner_nlportid = info->snd_portid;
7885 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
7891 return regulatory_hint_indoor(is_indoor, owner_nlportid);
7897 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
7899 return reg_reload_regdb();
7902 static int nl80211_get_mesh_config(struct sk_buff *skb,
7903 struct genl_info *info)
7905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7906 struct net_device *dev = info->user_ptr[1];
7907 struct wireless_dev *wdev = dev->ieee80211_ptr;
7908 struct mesh_config cur_params;
7911 struct nlattr *pinfoattr;
7912 struct sk_buff *msg;
7914 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7917 if (!rdev->ops->get_mesh_config)
7921 /* If not connected, get default parameters */
7922 if (!wdev->u.mesh.id_len)
7923 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
7925 err = rdev_get_mesh_config(rdev, dev, &cur_params);
7931 /* Draw up a netlink message to send back */
7932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7935 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7936 NL80211_CMD_GET_MESH_CONFIG);
7939 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
7941 goto nla_put_failure;
7942 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7943 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
7944 cur_params.dot11MeshRetryTimeout) ||
7945 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
7946 cur_params.dot11MeshConfirmTimeout) ||
7947 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
7948 cur_params.dot11MeshHoldingTimeout) ||
7949 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
7950 cur_params.dot11MeshMaxPeerLinks) ||
7951 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
7952 cur_params.dot11MeshMaxRetries) ||
7953 nla_put_u8(msg, NL80211_MESHCONF_TTL,
7954 cur_params.dot11MeshTTL) ||
7955 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
7956 cur_params.element_ttl) ||
7957 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
7958 cur_params.auto_open_plinks) ||
7959 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
7960 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
7961 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
7962 cur_params.dot11MeshHWMPmaxPREQretries) ||
7963 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
7964 cur_params.path_refresh_time) ||
7965 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
7966 cur_params.min_discovery_timeout) ||
7967 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
7968 cur_params.dot11MeshHWMPactivePathTimeout) ||
7969 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
7970 cur_params.dot11MeshHWMPpreqMinInterval) ||
7971 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
7972 cur_params.dot11MeshHWMPperrMinInterval) ||
7973 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
7974 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
7975 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
7976 cur_params.dot11MeshHWMPRootMode) ||
7977 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
7978 cur_params.dot11MeshHWMPRannInterval) ||
7979 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
7980 cur_params.dot11MeshGateAnnouncementProtocol) ||
7981 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
7982 cur_params.dot11MeshForwarding) ||
7983 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
7984 cur_params.rssi_threshold) ||
7985 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
7986 cur_params.ht_opmode) ||
7987 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
7988 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
7989 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
7990 cur_params.dot11MeshHWMProotInterval) ||
7991 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
7992 cur_params.dot11MeshHWMPconfirmationInterval) ||
7993 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
7994 cur_params.power_mode) ||
7995 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
7996 cur_params.dot11MeshAwakeWindowDuration) ||
7997 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
7998 cur_params.plink_timeout) ||
7999 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
8000 cur_params.dot11MeshConnectedToMeshGate) ||
8001 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN,
8002 cur_params.dot11MeshNolearn) ||
8003 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS,
8004 cur_params.dot11MeshConnectedToAuthServer))
8005 goto nla_put_failure;
8006 nla_nest_end(msg, pinfoattr);
8007 genlmsg_end(msg, hdr);
8008 return genlmsg_reply(msg, info);
8016 static const struct nla_policy
8017 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
8018 [NL80211_MESHCONF_RETRY_TIMEOUT] =
8019 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8020 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
8021 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8022 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
8023 NLA_POLICY_RANGE(NLA_U16, 1, 255),
8024 [NL80211_MESHCONF_MAX_PEER_LINKS] =
8025 NLA_POLICY_RANGE(NLA_U16, 0, 255),
8026 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
8027 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
8028 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
8029 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
8030 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
8031 NLA_POLICY_RANGE(NLA_U32, 1, 255),
8032 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
8033 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
8034 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
8035 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
8036 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
8037 NLA_POLICY_MIN(NLA_U16, 1),
8038 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
8039 NLA_POLICY_MIN(NLA_U16, 1),
8040 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
8041 NLA_POLICY_MIN(NLA_U16, 1),
8042 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
8043 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
8044 NLA_POLICY_MIN(NLA_U16, 1),
8045 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
8046 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
8047 [NL80211_MESHCONF_RSSI_THRESHOLD] =
8048 NLA_POLICY_RANGE(NLA_S32, -255, 0),
8049 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
8050 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
8051 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
8052 NLA_POLICY_MIN(NLA_U16, 1),
8053 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
8054 NLA_POLICY_MIN(NLA_U16, 1),
8055 [NL80211_MESHCONF_POWER_MODE] =
8056 NLA_POLICY_RANGE(NLA_U32,
8057 NL80211_MESH_POWER_ACTIVE,
8058 NL80211_MESH_POWER_MAX),
8059 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
8060 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
8061 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8062 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8063 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
8066 static const struct nla_policy
8067 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
8068 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
8069 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
8070 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
8071 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
8072 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
8073 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
8074 [NL80211_MESH_SETUP_IE] =
8075 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
8076 IEEE80211_MAX_DATA_LEN),
8077 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
8080 static int nl80211_parse_mesh_config(struct genl_info *info,
8081 struct mesh_config *cfg,
8084 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
8088 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
8091 cfg->param = fn(tb[attr]); \
8092 mask |= BIT((attr) - 1); \
8096 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
8098 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
8101 /* This makes sure that there aren't more than 32 mesh config
8102 * parameters (otherwise our bitfield scheme would not work.) */
8103 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
8105 /* Fill in the params struct */
8106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
8107 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
8108 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
8109 NL80211_MESHCONF_CONFIRM_TIMEOUT,
8111 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
8112 NL80211_MESHCONF_HOLDING_TIMEOUT,
8114 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
8115 NL80211_MESHCONF_MAX_PEER_LINKS,
8117 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
8118 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
8119 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
8120 NL80211_MESHCONF_TTL, nla_get_u8);
8121 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
8122 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
8123 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
8124 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
8126 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
8128 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
8130 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
8131 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
8133 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
8134 NL80211_MESHCONF_PATH_REFRESH_TIME,
8136 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
8137 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
8139 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
8140 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
8142 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
8144 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
8146 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
8147 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
8148 cfg->dot11MeshHWMPactivePathTimeout > 65535))
8150 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
8151 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
8153 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
8154 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
8156 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
8157 dot11MeshHWMPnetDiameterTraversalTime, mask,
8158 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
8160 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
8161 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
8162 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
8163 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
8165 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
8166 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
8168 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
8169 NL80211_MESHCONF_FORWARDING, nla_get_u8);
8170 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
8171 NL80211_MESHCONF_RSSI_THRESHOLD,
8173 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
8174 NL80211_MESHCONF_CONNECTED_TO_GATE,
8176 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask,
8177 NL80211_MESHCONF_CONNECTED_TO_AS,
8180 * Check HT operation mode based on
8181 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
8183 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
8184 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
8186 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
8187 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
8188 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
8191 /* NON_HT_STA bit is reserved, but some programs set it */
8192 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
8194 cfg->ht_opmode = ht_opmode;
8195 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
8197 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
8198 dot11MeshHWMPactivePathToRootTimeout, mask,
8199 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
8201 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
8202 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
8203 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
8205 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
8206 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
8208 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
8210 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
8212 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
8213 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
8214 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
8215 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
8216 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
8217 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
8218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask,
8219 NL80211_MESHCONF_NOLEARN, nla_get_u8);
8225 #undef FILL_IN_MESH_PARAM_IF_SET
8228 static int nl80211_parse_mesh_setup(struct genl_info *info,
8229 struct mesh_setup *setup)
8231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8232 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
8234 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
8236 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack))
8239 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
8240 setup->sync_method =
8241 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
8242 IEEE80211_SYNC_METHOD_VENDOR :
8243 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
8245 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
8246 setup->path_sel_proto =
8247 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
8248 IEEE80211_PATH_PROTOCOL_VENDOR :
8249 IEEE80211_PATH_PROTOCOL_HWMP;
8251 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
8252 setup->path_metric =
8253 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
8254 IEEE80211_PATH_METRIC_VENDOR :
8255 IEEE80211_PATH_METRIC_AIRTIME;
8257 if (tb[NL80211_MESH_SETUP_IE]) {
8258 struct nlattr *ieattr =
8259 tb[NL80211_MESH_SETUP_IE];
8260 setup->ie = nla_data(ieattr);
8261 setup->ie_len = nla_len(ieattr);
8263 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
8264 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
8266 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
8267 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
8268 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
8269 if (setup->is_secure)
8270 setup->user_mpm = true;
8272 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
8273 if (!setup->user_mpm)
8276 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
8282 static int nl80211_update_mesh_config(struct sk_buff *skb,
8283 struct genl_info *info)
8285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8286 struct net_device *dev = info->user_ptr[1];
8287 struct wireless_dev *wdev = dev->ieee80211_ptr;
8288 struct mesh_config cfg;
8292 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
8295 if (!rdev->ops->update_mesh_config)
8298 err = nl80211_parse_mesh_config(info, &cfg, &mask);
8303 if (!wdev->u.mesh.id_len)
8307 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
8314 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
8315 struct sk_buff *msg)
8317 struct nlattr *nl_reg_rules;
8320 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
8321 (regdom->dfs_region &&
8322 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
8323 goto nla_put_failure;
8325 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
8327 goto nla_put_failure;
8329 for (i = 0; i < regdom->n_reg_rules; i++) {
8330 struct nlattr *nl_reg_rule;
8331 const struct ieee80211_reg_rule *reg_rule;
8332 const struct ieee80211_freq_range *freq_range;
8333 const struct ieee80211_power_rule *power_rule;
8334 unsigned int max_bandwidth_khz;
8336 reg_rule = ®dom->reg_rules[i];
8337 freq_range = ®_rule->freq_range;
8338 power_rule = ®_rule->power_rule;
8340 nl_reg_rule = nla_nest_start_noflag(msg, i);
8342 goto nla_put_failure;
8344 max_bandwidth_khz = freq_range->max_bandwidth_khz;
8345 if (!max_bandwidth_khz)
8346 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
8349 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
8351 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
8352 freq_range->start_freq_khz) ||
8353 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
8354 freq_range->end_freq_khz) ||
8355 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
8356 max_bandwidth_khz) ||
8357 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
8358 power_rule->max_antenna_gain) ||
8359 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
8360 power_rule->max_eirp) ||
8361 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
8362 reg_rule->dfs_cac_ms))
8363 goto nla_put_failure;
8365 nla_nest_end(msg, nl_reg_rule);
8368 nla_nest_end(msg, nl_reg_rules);
8375 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
8377 const struct ieee80211_regdomain *regdom = NULL;
8378 struct cfg80211_registered_device *rdev;
8379 struct wiphy *wiphy = NULL;
8380 struct sk_buff *msg;
8381 int err = -EMSGSIZE;
8384 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8388 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8389 NL80211_CMD_GET_REG);
8395 if (info->attrs[NL80211_ATTR_WIPHY]) {
8398 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
8400 err = PTR_ERR(rdev);
8401 goto nla_put_failure;
8404 wiphy = &rdev->wiphy;
8405 self_managed = wiphy->regulatory_flags &
8406 REGULATORY_WIPHY_SELF_MANAGED;
8410 regdom = get_wiphy_regdom(wiphy);
8412 /* a self-managed-reg device must have a private regdom */
8413 if (WARN_ON(!regdom && self_managed)) {
8415 goto nla_put_failure_rcu;
8419 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8420 goto nla_put_failure_rcu;
8425 if (!wiphy && reg_last_request_cell_base() &&
8426 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
8427 NL80211_USER_REG_HINT_CELL_BASE))
8428 goto nla_put_failure_rcu;
8431 regdom = rcu_dereference(cfg80211_regdomain);
8433 if (nl80211_put_regdom(regdom, msg))
8434 goto nla_put_failure_rcu;
8438 genlmsg_end(msg, hdr);
8440 return genlmsg_reply(msg, info);
8442 nla_put_failure_rcu:
8451 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
8452 u32 seq, int flags, struct wiphy *wiphy,
8453 const struct ieee80211_regdomain *regdom)
8455 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
8456 NL80211_CMD_GET_REG);
8461 genl_dump_check_consistent(cb, hdr);
8463 if (nl80211_put_regdom(regdom, msg))
8464 goto nla_put_failure;
8466 if (!wiphy && reg_last_request_cell_base() &&
8467 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
8468 NL80211_USER_REG_HINT_CELL_BASE))
8469 goto nla_put_failure;
8472 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8473 goto nla_put_failure;
8475 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
8476 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
8477 goto nla_put_failure;
8479 genlmsg_end(msg, hdr);
8483 genlmsg_cancel(msg, hdr);
8487 static int nl80211_get_reg_dump(struct sk_buff *skb,
8488 struct netlink_callback *cb)
8490 const struct ieee80211_regdomain *regdom = NULL;
8491 struct cfg80211_registered_device *rdev;
8492 int err, reg_idx, start = cb->args[2];
8496 if (cfg80211_regdomain && start == 0) {
8497 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
8499 rcu_dereference(cfg80211_regdomain));
8504 /* the global regdom is idx 0 */
8506 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
8507 regdom = get_wiphy_regdom(&rdev->wiphy);
8511 if (++reg_idx <= start)
8514 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
8515 NLM_F_MULTI, &rdev->wiphy, regdom);
8522 cb->args[2] = reg_idx;
8529 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
8530 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
8531 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
8532 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
8533 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
8534 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
8535 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
8536 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
8537 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
8540 static int parse_reg_rule(struct nlattr *tb[],
8541 struct ieee80211_reg_rule *reg_rule)
8543 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
8544 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
8546 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
8548 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
8550 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
8552 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
8554 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
8557 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
8559 freq_range->start_freq_khz =
8560 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
8561 freq_range->end_freq_khz =
8562 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
8563 freq_range->max_bandwidth_khz =
8564 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
8566 power_rule->max_eirp =
8567 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
8569 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
8570 power_rule->max_antenna_gain =
8571 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
8573 if (tb[NL80211_ATTR_DFS_CAC_TIME])
8574 reg_rule->dfs_cac_ms =
8575 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
8580 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
8582 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
8583 struct nlattr *nl_reg_rule;
8585 int rem_reg_rules, r;
8586 u32 num_rules = 0, rule_idx = 0;
8587 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
8588 struct ieee80211_regdomain *rd;
8590 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
8593 if (!info->attrs[NL80211_ATTR_REG_RULES])
8596 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
8598 if (info->attrs[NL80211_ATTR_DFS_REGION])
8599 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
8601 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
8604 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
8609 if (!reg_is_valid_request(alpha2)) {
8614 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
8620 rd->n_reg_rules = num_rules;
8621 rd->alpha2[0] = alpha2[0];
8622 rd->alpha2[1] = alpha2[1];
8625 * Disable DFS master mode if the DFS region was
8626 * not supported or known on this kernel.
8628 if (reg_supported_dfs_region(dfs_region))
8629 rd->dfs_region = dfs_region;
8631 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
8633 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
8634 nl_reg_rule, reg_rule_policy,
8638 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
8644 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
8650 r = set_regdom(rd, REGD_SOURCE_CRDA);
8651 /* set_regdom takes ownership of rd */
8659 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
8661 static int validate_scan_freqs(struct nlattr *freqs)
8663 struct nlattr *attr1, *attr2;
8664 int n_channels = 0, tmp1, tmp2;
8666 nla_for_each_nested(attr1, freqs, tmp1)
8667 if (nla_len(attr1) != sizeof(u32))
8670 nla_for_each_nested(attr1, freqs, tmp1) {
8673 * Some hardware has a limited channel list for
8674 * scanning, and it is pretty much nonsensical
8675 * to scan for a channel twice, so disallow that
8676 * and don't require drivers to check that the
8677 * channel list they get isn't longer than what
8678 * they can scan, as long as they can scan all
8679 * the channels they registered at once.
8681 nla_for_each_nested(attr2, freqs, tmp2)
8682 if (attr1 != attr2 &&
8683 nla_get_u32(attr1) == nla_get_u32(attr2))
8690 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
8692 return b < NUM_NL80211_BANDS && wiphy->bands[b];
8695 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
8696 struct cfg80211_bss_selection *bss_select)
8698 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
8699 struct nlattr *nest;
8704 /* only process one nested attribute */
8705 nest = nla_data(nla);
8706 if (!nla_ok(nest, nla_len(nest)))
8709 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
8710 nest, nl80211_bss_select_policy,
8715 /* only one attribute may be given */
8716 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
8724 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
8726 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
8727 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
8729 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
8730 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
8731 bss_select->param.band_pref =
8732 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
8733 if (!is_band_valid(wiphy, bss_select->param.band_pref))
8737 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
8738 struct nl80211_bss_select_rssi_adjust *adj_param;
8740 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
8741 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
8742 bss_select->param.adjust.band = adj_param->band;
8743 bss_select->param.adjust.delta = adj_param->delta;
8744 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
8748 /* user-space did not provide behaviour attribute */
8749 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
8752 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
8758 int nl80211_parse_random_mac(struct nlattr **attrs,
8759 u8 *mac_addr, u8 *mac_addr_mask)
8763 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
8764 eth_zero_addr(mac_addr);
8765 eth_zero_addr(mac_addr_mask);
8767 mac_addr_mask[0] = 0x3;
8772 /* need both or none */
8773 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
8776 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
8777 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
8779 /* don't allow or configure an mcast address */
8780 if (!is_multicast_ether_addr(mac_addr_mask) ||
8781 is_multicast_ether_addr(mac_addr))
8785 * allow users to pass a MAC address that has bits set outside
8786 * of the mask, but don't bother drivers with having to deal
8789 for (i = 0; i < ETH_ALEN; i++)
8790 mac_addr[i] &= mac_addr_mask[i];
8795 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev,
8796 struct ieee80211_channel *chan)
8798 unsigned int link_id;
8801 ASSERT_WDEV_LOCK(wdev);
8803 if (!cfg80211_beaconing_iface_active(wdev))
8807 * FIXME: check if we have a free HW resource/link for chan
8809 * This, as well as the FIXME below, requires knowing the link
8810 * capabilities of the hardware.
8813 /* we cannot leave radar channels */
8814 for_each_valid_link(wdev, link_id) {
8815 struct cfg80211_chan_def *chandef;
8817 chandef = wdev_chandef(wdev, link_id);
8818 if (!chandef || !chandef->chan)
8822 * FIXME: don't require all_ok, but rather check only the
8823 * correct HW resource/link onto which 'chan' falls,
8824 * as only that link leaves the channel for doing
8825 * the off-channel operation.
8828 if (chandef->chan->flags & IEEE80211_CHAN_RADAR)
8835 return regulatory_pre_cac_allowed(wdev->wiphy);
8838 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
8839 enum nl80211_ext_feature_index feat)
8841 if (!(flags & flag))
8843 if (wiphy_ext_feature_isset(wiphy, feat))
8849 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
8850 void *request, struct nlattr **attrs,
8853 u8 *mac_addr, *mac_addr_mask;
8855 enum nl80211_feature_flags randomness_flag;
8857 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
8860 if (is_sched_scan) {
8861 struct cfg80211_sched_scan_request *req = request;
8863 randomness_flag = wdev ?
8864 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
8865 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
8866 flags = &req->flags;
8867 mac_addr = req->mac_addr;
8868 mac_addr_mask = req->mac_addr_mask;
8870 struct cfg80211_scan_request *req = request;
8872 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8873 flags = &req->flags;
8874 mac_addr = req->mac_addr;
8875 mac_addr_mask = req->mac_addr_mask;
8878 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
8880 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
8881 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
8882 !nl80211_check_scan_feat(wiphy, *flags,
8883 NL80211_SCAN_FLAG_LOW_SPAN,
8884 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
8885 !nl80211_check_scan_feat(wiphy, *flags,
8886 NL80211_SCAN_FLAG_LOW_POWER,
8887 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
8888 !nl80211_check_scan_feat(wiphy, *flags,
8889 NL80211_SCAN_FLAG_HIGH_ACCURACY,
8890 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
8891 !nl80211_check_scan_feat(wiphy, *flags,
8892 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
8893 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
8894 !nl80211_check_scan_feat(wiphy, *flags,
8895 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
8896 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
8897 !nl80211_check_scan_feat(wiphy, *flags,
8898 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
8899 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
8900 !nl80211_check_scan_feat(wiphy, *flags,
8901 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
8902 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
8903 !nl80211_check_scan_feat(wiphy, *flags,
8904 NL80211_SCAN_FLAG_RANDOM_SN,
8905 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
8906 !nl80211_check_scan_feat(wiphy, *flags,
8907 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
8908 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
8911 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
8914 if (!(wiphy->features & randomness_flag) ||
8915 (wdev && wdev->connected))
8918 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
8926 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
8928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8929 struct wireless_dev *wdev = info->user_ptr[1];
8930 struct cfg80211_scan_request *request;
8931 struct nlattr *scan_freqs = NULL;
8932 bool scan_freqs_khz = false;
8933 struct nlattr *attr;
8934 struct wiphy *wiphy;
8935 int err, tmp, n_ssids = 0, n_channels, i;
8938 wiphy = &rdev->wiphy;
8940 if (wdev->iftype == NL80211_IFTYPE_NAN)
8943 if (!rdev->ops->scan)
8946 if (rdev->scan_req || rdev->scan_msg)
8949 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) {
8950 if (!wiphy_ext_feature_isset(wiphy,
8951 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ))
8953 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ];
8954 scan_freqs_khz = true;
8955 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES])
8956 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES];
8959 n_channels = validate_scan_freqs(scan_freqs);
8963 n_channels = ieee80211_get_num_supported_channels(wiphy);
8966 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
8967 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
8970 if (n_ssids > wiphy->max_scan_ssids)
8973 if (info->attrs[NL80211_ATTR_IE])
8974 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8978 if (ie_len > wiphy->max_scan_ie_len)
8981 request = kzalloc(sizeof(*request)
8982 + sizeof(*request->ssids) * n_ssids
8983 + sizeof(*request->channels) * n_channels
8984 + ie_len, GFP_KERNEL);
8989 request->ssids = (void *)&request->channels[n_channels];
8990 request->n_ssids = n_ssids;
8993 request->ie = (void *)(request->ssids + n_ssids);
8995 request->ie = (void *)(request->channels + n_channels);
9000 /* user specified, bail out if channel not found */
9001 nla_for_each_nested(attr, scan_freqs, tmp) {
9002 struct ieee80211_channel *chan;
9003 int freq = nla_get_u32(attr);
9005 if (!scan_freqs_khz)
9006 freq = MHZ_TO_KHZ(freq);
9008 chan = ieee80211_get_channel_khz(wiphy, freq);
9014 /* ignore disabled channels */
9015 if (chan->flags & IEEE80211_CHAN_DISABLED)
9018 request->channels[i] = chan;
9022 enum nl80211_band band;
9025 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9028 if (!wiphy->bands[band])
9030 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
9031 struct ieee80211_channel *chan;
9033 chan = &wiphy->bands[band]->channels[j];
9035 if (chan->flags & IEEE80211_CHAN_DISABLED)
9038 request->channels[i] = chan;
9049 request->n_channels = i;
9052 for (i = 0; i < request->n_channels; i++) {
9053 struct ieee80211_channel *chan = request->channels[i];
9055 /* if we can go off-channel to the target channel we're good */
9056 if (cfg80211_off_channel_oper_allowed(wdev, chan))
9059 if (!cfg80211_wdev_on_sub_chan(wdev, chan, true)) {
9069 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
9070 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
9074 request->ssids[i].ssid_len = nla_len(attr);
9075 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
9080 if (info->attrs[NL80211_ATTR_IE]) {
9081 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9082 memcpy((void *)request->ie,
9083 nla_data(info->attrs[NL80211_ATTR_IE]),
9087 for (i = 0; i < NUM_NL80211_BANDS; i++)
9088 if (wiphy->bands[i])
9090 (1 << wiphy->bands[i]->n_bitrates) - 1;
9092 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
9093 nla_for_each_nested(attr,
9094 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
9096 enum nl80211_band band = nla_type(attr);
9098 if (band < 0 || band >= NUM_NL80211_BANDS) {
9103 if (!wiphy->bands[band])
9106 err = ieee80211_get_ratemask(wiphy->bands[band],
9109 &request->rates[band]);
9115 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
9117 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
9118 request->duration_mandatory =
9119 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
9122 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
9128 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
9130 /* Initial implementation used NL80211_ATTR_MAC to set the specific
9131 * BSSID to scan for. This was problematic because that same attribute
9132 * was already used for another purpose (local random MAC address). The
9133 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
9134 * compatibility with older userspace components, also use the
9135 * NL80211_ATTR_MAC value here if it can be determined to be used for
9136 * the specific BSSID use case instead of the random MAC address
9137 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
9139 if (info->attrs[NL80211_ATTR_BSSID])
9140 memcpy(request->bssid,
9141 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
9142 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
9143 info->attrs[NL80211_ATTR_MAC])
9144 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
9147 eth_broadcast_addr(request->bssid);
9149 request->wdev = wdev;
9150 request->wiphy = &rdev->wiphy;
9151 request->scan_start = jiffies;
9153 rdev->scan_req = request;
9154 err = cfg80211_scan(rdev);
9159 nl80211_send_scan_start(rdev, wdev);
9160 dev_hold(wdev->netdev);
9165 rdev->scan_req = NULL;
9171 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
9173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9174 struct wireless_dev *wdev = info->user_ptr[1];
9176 if (!rdev->ops->abort_scan)
9182 if (!rdev->scan_req)
9185 rdev_abort_scan(rdev, wdev);
9190 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
9191 struct cfg80211_sched_scan_request *request,
9192 struct nlattr **attrs)
9194 int tmp, err, i = 0;
9195 struct nlattr *attr;
9197 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
9201 * If scan plans are not specified,
9202 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
9203 * case one scan plan will be set with the specified scan
9204 * interval and infinite number of iterations.
9206 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
9210 request->scan_plans[0].interval =
9211 DIV_ROUND_UP(interval, MSEC_PER_SEC);
9212 if (!request->scan_plans[0].interval)
9215 if (request->scan_plans[0].interval >
9216 wiphy->max_sched_scan_plan_interval)
9217 request->scan_plans[0].interval =
9218 wiphy->max_sched_scan_plan_interval;
9223 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
9224 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
9226 if (WARN_ON(i >= n_plans))
9229 err = nla_parse_nested_deprecated(plan,
9230 NL80211_SCHED_SCAN_PLAN_MAX,
9231 attr, nl80211_plan_policy,
9236 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
9239 request->scan_plans[i].interval =
9240 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
9241 if (!request->scan_plans[i].interval ||
9242 request->scan_plans[i].interval >
9243 wiphy->max_sched_scan_plan_interval)
9246 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
9247 request->scan_plans[i].iterations =
9248 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
9249 if (!request->scan_plans[i].iterations ||
9250 (request->scan_plans[i].iterations >
9251 wiphy->max_sched_scan_plan_iterations))
9253 } else if (i < n_plans - 1) {
9255 * All scan plans but the last one must specify
9256 * a finite number of iterations
9265 * The last scan plan must not specify the number of
9266 * iterations, it is supposed to run infinitely
9268 if (request->scan_plans[n_plans - 1].iterations)
9275 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
9276 struct cfg80211_match_set *match_sets,
9277 struct nlattr *tb_band_rssi,
9280 struct nlattr *attr;
9281 int i, tmp, ret = 0;
9283 if (!wiphy_ext_feature_isset(wiphy,
9284 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
9288 for (i = 0; i < NUM_NL80211_BANDS; i++)
9289 match_sets->per_band_rssi_thold[i] =
9290 NL80211_SCAN_RSSI_THOLD_OFF;
9294 for (i = 0; i < NUM_NL80211_BANDS; i++)
9295 match_sets->per_band_rssi_thold[i] = rssi_thold;
9297 nla_for_each_nested(attr, tb_band_rssi, tmp) {
9298 enum nl80211_band band = nla_type(attr);
9300 if (band < 0 || band >= NUM_NL80211_BANDS)
9303 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
9309 static struct cfg80211_sched_scan_request *
9310 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
9311 struct nlattr **attrs, int max_match_sets)
9313 struct cfg80211_sched_scan_request *request;
9314 struct nlattr *attr;
9315 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
9316 enum nl80211_band band;
9318 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
9319 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
9321 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
9322 n_channels = validate_scan_freqs(
9323 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
9325 return ERR_PTR(-EINVAL);
9327 n_channels = ieee80211_get_num_supported_channels(wiphy);
9330 if (attrs[NL80211_ATTR_SCAN_SSIDS])
9331 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
9335 if (n_ssids > wiphy->max_sched_scan_ssids)
9336 return ERR_PTR(-EINVAL);
9339 * First, count the number of 'real' matchsets. Due to an issue with
9340 * the old implementation, matchsets containing only the RSSI attribute
9341 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
9342 * RSSI for all matchsets, rather than their own matchset for reporting
9343 * all APs with a strong RSSI. This is needed to be compatible with
9344 * older userspace that treated a matchset with only the RSSI as the
9345 * global RSSI for all other matchsets - if there are other matchsets.
9347 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
9348 nla_for_each_nested(attr,
9349 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
9351 struct nlattr *rssi;
9353 err = nla_parse_nested_deprecated(tb,
9354 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
9356 nl80211_match_policy,
9359 return ERR_PTR(err);
9361 /* SSID and BSSID are mutually exclusive */
9362 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
9363 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
9364 return ERR_PTR(-EINVAL);
9366 /* add other standalone attributes here */
9367 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
9368 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
9372 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
9374 default_match_rssi = nla_get_s32(rssi);
9378 /* However, if there's no other matchset, add the RSSI one */
9379 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
9382 if (n_match_sets > max_match_sets)
9383 return ERR_PTR(-EINVAL);
9385 if (attrs[NL80211_ATTR_IE])
9386 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
9390 if (ie_len > wiphy->max_sched_scan_ie_len)
9391 return ERR_PTR(-EINVAL);
9393 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
9395 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
9396 * each scan plan already specifies its own interval
9398 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
9399 return ERR_PTR(-EINVAL);
9401 nla_for_each_nested(attr,
9402 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
9406 * The scan interval attribute is kept for backward
9407 * compatibility. If no scan plans are specified and sched scan
9408 * interval is specified, one scan plan will be set with this
9409 * scan interval and infinite number of iterations.
9411 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
9412 return ERR_PTR(-EINVAL);
9417 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
9418 return ERR_PTR(-EINVAL);
9420 if (!wiphy_ext_feature_isset(
9421 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
9422 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
9423 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
9424 return ERR_PTR(-EINVAL);
9426 request = kzalloc(sizeof(*request)
9427 + sizeof(*request->ssids) * n_ssids
9428 + sizeof(*request->match_sets) * n_match_sets
9429 + sizeof(*request->scan_plans) * n_plans
9430 + sizeof(*request->channels) * n_channels
9431 + ie_len, GFP_KERNEL);
9433 return ERR_PTR(-ENOMEM);
9436 request->ssids = (void *)&request->channels[n_channels];
9437 request->n_ssids = n_ssids;
9440 request->ie = (void *)(request->ssids + n_ssids);
9442 request->ie = (void *)(request->channels + n_channels);
9447 request->match_sets = (void *)(request->ie + ie_len);
9449 request->match_sets =
9450 (void *)(request->ssids + n_ssids);
9452 request->match_sets =
9453 (void *)(request->channels + n_channels);
9455 request->n_match_sets = n_match_sets;
9458 request->scan_plans = (void *)(request->match_sets +
9460 else if (request->ie)
9461 request->scan_plans = (void *)(request->ie + ie_len);
9463 request->scan_plans = (void *)(request->ssids + n_ssids);
9465 request->scan_plans = (void *)(request->channels + n_channels);
9467 request->n_scan_plans = n_plans;
9470 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
9471 /* user specified, bail out if channel not found */
9472 nla_for_each_nested(attr,
9473 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
9475 struct ieee80211_channel *chan;
9477 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
9484 /* ignore disabled channels */
9485 if (chan->flags & IEEE80211_CHAN_DISABLED)
9488 request->channels[i] = chan;
9493 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9496 if (!wiphy->bands[band])
9498 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
9499 struct ieee80211_channel *chan;
9501 chan = &wiphy->bands[band]->channels[j];
9503 if (chan->flags & IEEE80211_CHAN_DISABLED)
9506 request->channels[i] = chan;
9517 request->n_channels = i;
9521 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
9523 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
9527 request->ssids[i].ssid_len = nla_len(attr);
9528 memcpy(request->ssids[i].ssid, nla_data(attr),
9535 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
9536 nla_for_each_nested(attr,
9537 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
9539 struct nlattr *ssid, *bssid, *rssi;
9541 err = nla_parse_nested_deprecated(tb,
9542 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
9544 nl80211_match_policy,
9548 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
9549 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
9551 if (!ssid && !bssid) {
9556 if (WARN_ON(i >= n_match_sets)) {
9557 /* this indicates a programming error,
9558 * the loop above should have verified
9566 memcpy(request->match_sets[i].ssid.ssid,
9567 nla_data(ssid), nla_len(ssid));
9568 request->match_sets[i].ssid.ssid_len =
9572 memcpy(request->match_sets[i].bssid,
9573 nla_data(bssid), ETH_ALEN);
9575 /* special attribute - old implementation w/a */
9576 request->match_sets[i].rssi_thold = default_match_rssi;
9577 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
9579 request->match_sets[i].rssi_thold =
9582 /* Parse per band RSSI attribute */
9583 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
9584 &request->match_sets[i],
9585 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
9586 request->match_sets[i].rssi_thold);
9593 /* there was no other matchset, so the RSSI one is alone */
9594 if (i == 0 && n_match_sets)
9595 request->match_sets[0].rssi_thold = default_match_rssi;
9597 request->min_rssi_thold = INT_MAX;
9598 for (i = 0; i < n_match_sets; i++)
9599 request->min_rssi_thold =
9600 min(request->match_sets[i].rssi_thold,
9601 request->min_rssi_thold);
9603 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
9607 request->ie_len = ie_len;
9608 memcpy((void *)request->ie,
9609 nla_data(attrs[NL80211_ATTR_IE]),
9613 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
9617 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
9619 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
9621 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
9622 request->relative_rssi = nla_get_s8(
9623 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
9624 request->relative_rssi_set = true;
9627 if (request->relative_rssi_set &&
9628 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
9629 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
9631 rssi_adjust = nla_data(
9632 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
9633 request->rssi_adjust.band = rssi_adjust->band;
9634 request->rssi_adjust.delta = rssi_adjust->delta;
9635 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
9641 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
9645 request->scan_start = jiffies;
9651 return ERR_PTR(err);
9654 static int nl80211_start_sched_scan(struct sk_buff *skb,
9655 struct genl_info *info)
9657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9658 struct net_device *dev = info->user_ptr[1];
9659 struct wireless_dev *wdev = dev->ieee80211_ptr;
9660 struct cfg80211_sched_scan_request *sched_scan_req;
9664 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
9667 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
9668 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
9672 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
9674 rdev->wiphy.max_match_sets);
9676 err = PTR_ERR_OR_ZERO(sched_scan_req);
9680 /* leave request id zero for legacy request
9681 * or if driver does not support multi-scheduled scan
9683 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
9684 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
9686 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
9690 sched_scan_req->dev = dev;
9691 sched_scan_req->wiphy = &rdev->wiphy;
9693 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9694 sched_scan_req->owner_nlportid = info->snd_portid;
9696 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
9698 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
9702 kfree(sched_scan_req);
9707 static int nl80211_stop_sched_scan(struct sk_buff *skb,
9708 struct genl_info *info)
9710 struct cfg80211_sched_scan_request *req;
9711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9714 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
9717 if (info->attrs[NL80211_ATTR_COOKIE]) {
9718 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9719 return __cfg80211_stop_sched_scan(rdev, cookie, false);
9722 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
9723 struct cfg80211_sched_scan_request,
9725 if (!req || req->reqid ||
9726 (req->owner_nlportid &&
9727 req->owner_nlportid != info->snd_portid))
9730 return cfg80211_stop_sched_scan_req(rdev, req, false);
9733 static int nl80211_start_radar_detection(struct sk_buff *skb,
9734 struct genl_info *info)
9736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9737 struct net_device *dev = info->user_ptr[1];
9738 struct wireless_dev *wdev = dev->ieee80211_ptr;
9739 struct wiphy *wiphy = wdev->wiphy;
9740 struct cfg80211_chan_def chandef;
9741 enum nl80211_dfs_regions dfs_region;
9742 unsigned int cac_time_ms;
9745 flush_delayed_work(&rdev->dfs_update_channels_wk);
9749 dfs_region = reg_get_dfs_region(wiphy);
9750 if (dfs_region == NL80211_DFS_UNSET)
9753 err = nl80211_parse_chandef(rdev, info, &chandef);
9757 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
9766 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) {
9771 if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) {
9772 err = cfg80211_start_background_radar_detection(rdev, wdev,
9777 if (netif_carrier_ok(dev)) {
9782 if (wdev->cac_started) {
9787 /* CAC start is offloaded to HW and can't be started manually */
9788 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) {
9793 if (!rdev->ops->start_radar_detection) {
9798 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
9799 if (WARN_ON(!cac_time_ms))
9800 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
9802 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
9804 wdev->links[0].ap.chandef = chandef;
9805 wdev->cac_started = true;
9806 wdev->cac_start_time = jiffies;
9807 wdev->cac_time_ms = cac_time_ms;
9810 wiphy_unlock(wiphy);
9815 static int nl80211_notify_radar_detection(struct sk_buff *skb,
9816 struct genl_info *info)
9818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9819 struct net_device *dev = info->user_ptr[1];
9820 struct wireless_dev *wdev = dev->ieee80211_ptr;
9821 struct wiphy *wiphy = wdev->wiphy;
9822 struct cfg80211_chan_def chandef;
9823 enum nl80211_dfs_regions dfs_region;
9826 dfs_region = reg_get_dfs_region(wiphy);
9827 if (dfs_region == NL80211_DFS_UNSET) {
9828 GENL_SET_ERR_MSG(info,
9829 "DFS Region is not set. Unexpected Radar indication");
9833 err = nl80211_parse_chandef(rdev, info, &chandef);
9835 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
9839 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
9841 GENL_SET_ERR_MSG(info, "chandef is invalid");
9846 GENL_SET_ERR_MSG(info,
9847 "Unexpected Radar indication for chandef/iftype");
9851 /* Do not process this notification if radar is already detected
9852 * by kernel on this channel, and return success.
9854 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
9857 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
9859 cfg80211_sched_dfs_chan_update(rdev);
9861 rdev->radar_chandef = chandef;
9863 /* Propagate this notification to other radios as well */
9864 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
9869 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
9871 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9872 unsigned int link_id = nl80211_link_id(info->attrs);
9873 struct net_device *dev = info->user_ptr[1];
9874 struct wireless_dev *wdev = dev->ieee80211_ptr;
9875 struct cfg80211_csa_settings params;
9876 struct nlattr **csa_attrs = NULL;
9878 bool need_new_beacon = false;
9879 bool need_handle_dfs_flag = true;
9883 if (!rdev->ops->channel_switch ||
9884 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
9887 switch (dev->ieee80211_ptr->iftype) {
9888 case NL80211_IFTYPE_AP:
9889 case NL80211_IFTYPE_P2P_GO:
9890 need_new_beacon = true;
9891 /* For all modes except AP the handle_dfs flag needs to be
9892 * supplied to tell the kernel that userspace will handle radar
9893 * events when they happen. Otherwise a switch to a channel
9894 * requiring DFS will be rejected.
9896 need_handle_dfs_flag = false;
9898 /* useless if AP is not running */
9899 if (!wdev->links[link_id].ap.beacon_interval)
9902 case NL80211_IFTYPE_ADHOC:
9903 if (!wdev->u.ibss.ssid_len)
9906 case NL80211_IFTYPE_MESH_POINT:
9907 if (!wdev->u.mesh.id_len)
9914 memset(¶ms, 0, sizeof(params));
9915 params.beacon_csa.ftm_responder = -1;
9917 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9918 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
9921 /* only important for AP, IBSS and mesh create IEs internally */
9922 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
9925 /* Even though the attribute is u32, the specification says
9926 * u8, so let's make sure we don't overflow.
9928 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
9932 params.count = cs_count;
9934 if (!need_new_beacon)
9937 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after);
9941 csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs),
9948 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
9949 info->attrs[NL80211_ATTR_CSA_IES],
9950 nl80211_policy, info->extack);
9954 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa);
9958 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) {
9963 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
9964 if (!len || (len % sizeof(u16))) {
9969 params.n_counter_offsets_beacon = len / sizeof(u16);
9970 if (rdev->wiphy.max_num_csa_counters &&
9971 (params.n_counter_offsets_beacon >
9972 rdev->wiphy.max_num_csa_counters)) {
9977 params.counter_offsets_beacon =
9978 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
9980 /* sanity checks - counters should fit and be the same */
9981 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
9982 u16 offset = params.counter_offsets_beacon[i];
9984 if (offset >= params.beacon_csa.tail_len) {
9989 if (params.beacon_csa.tail[offset] != params.count) {
9995 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
9996 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
9997 if (!len || (len % sizeof(u16))) {
10002 params.n_counter_offsets_presp = len / sizeof(u16);
10003 if (rdev->wiphy.max_num_csa_counters &&
10004 (params.n_counter_offsets_presp >
10005 rdev->wiphy.max_num_csa_counters)) {
10010 params.counter_offsets_presp =
10011 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
10013 /* sanity checks - counters should fit and be the same */
10014 for (i = 0; i < params.n_counter_offsets_presp; i++) {
10015 u16 offset = params.counter_offsets_presp[i];
10017 if (offset >= params.beacon_csa.probe_resp_len) {
10022 if (params.beacon_csa.probe_resp[offset] !=
10031 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
10035 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
10041 err = cfg80211_chandef_dfs_required(wdev->wiphy,
10048 params.radar_required = true;
10049 if (need_handle_dfs_flag &&
10050 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
10056 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
10057 params.block_tx = true;
10060 err = rdev_channel_switch(rdev, dev, ¶ms);
10064 kfree(params.beacon_after.mbssid_ies);
10065 kfree(params.beacon_csa.mbssid_ies);
10070 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
10071 u32 seq, int flags,
10072 struct cfg80211_registered_device *rdev,
10073 struct wireless_dev *wdev,
10074 struct cfg80211_internal_bss *intbss)
10076 struct cfg80211_bss *res = &intbss->pub;
10077 const struct cfg80211_bss_ies *ies;
10078 unsigned int link_id;
10080 struct nlattr *bss;
10082 ASSERT_WDEV_LOCK(wdev);
10084 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
10085 NL80211_CMD_NEW_SCAN_RESULTS);
10089 genl_dump_check_consistent(cb, hdr);
10091 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
10092 goto nla_put_failure;
10093 if (wdev->netdev &&
10094 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
10095 goto nla_put_failure;
10096 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
10098 goto nla_put_failure;
10100 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
10102 goto nla_put_failure;
10103 if ((!is_zero_ether_addr(res->bssid) &&
10104 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
10105 goto nla_put_failure;
10108 /* indicate whether we have probe response data or not */
10109 if (rcu_access_pointer(res->proberesp_ies) &&
10110 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
10111 goto fail_unlock_rcu;
10113 /* this pointer prefers to be pointed to probe response data
10114 * but is always valid
10116 ies = rcu_dereference(res->ies);
10118 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
10120 goto fail_unlock_rcu;
10121 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
10122 ies->len, ies->data))
10123 goto fail_unlock_rcu;
10126 /* and this pointer is always (unless driver didn't know) beacon data */
10127 ies = rcu_dereference(res->beacon_ies);
10128 if (ies && ies->from_beacon) {
10129 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
10131 goto fail_unlock_rcu;
10132 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
10133 ies->len, ies->data))
10134 goto fail_unlock_rcu;
10138 if (res->beacon_interval &&
10139 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
10140 goto nla_put_failure;
10141 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
10142 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
10143 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET,
10144 res->channel->freq_offset) ||
10145 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
10146 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
10147 jiffies_to_msecs(jiffies - intbss->ts)))
10148 goto nla_put_failure;
10150 if (intbss->parent_tsf &&
10151 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
10152 intbss->parent_tsf, NL80211_BSS_PAD) ||
10153 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
10154 intbss->parent_bssid)))
10155 goto nla_put_failure;
10157 if (intbss->ts_boottime &&
10158 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
10159 intbss->ts_boottime, NL80211_BSS_PAD))
10160 goto nla_put_failure;
10162 if (!nl80211_put_signal(msg, intbss->pub.chains,
10163 intbss->pub.chain_signal,
10164 NL80211_BSS_CHAIN_SIGNAL))
10165 goto nla_put_failure;
10167 switch (rdev->wiphy.signal_type) {
10168 case CFG80211_SIGNAL_TYPE_MBM:
10169 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
10170 goto nla_put_failure;
10172 case CFG80211_SIGNAL_TYPE_UNSPEC:
10173 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
10174 goto nla_put_failure;
10180 switch (wdev->iftype) {
10181 case NL80211_IFTYPE_P2P_CLIENT:
10182 case NL80211_IFTYPE_STATION:
10183 for_each_valid_link(wdev, link_id) {
10184 if (intbss == wdev->links[link_id].client.current_bss &&
10185 (nla_put_u32(msg, NL80211_BSS_STATUS,
10186 NL80211_BSS_STATUS_ASSOCIATED) ||
10187 (wdev->valid_links &&
10188 (nla_put_u8(msg, NL80211_BSS_MLO_LINK_ID,
10190 nla_put(msg, NL80211_BSS_MLD_ADDR, ETH_ALEN,
10191 wdev->u.client.connected_addr)))))
10192 goto nla_put_failure;
10195 case NL80211_IFTYPE_ADHOC:
10196 if (intbss == wdev->u.ibss.current_bss &&
10197 nla_put_u32(msg, NL80211_BSS_STATUS,
10198 NL80211_BSS_STATUS_IBSS_JOINED))
10199 goto nla_put_failure;
10205 nla_nest_end(msg, bss);
10207 genlmsg_end(msg, hdr);
10213 genlmsg_cancel(msg, hdr);
10217 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
10219 struct cfg80211_registered_device *rdev;
10220 struct cfg80211_internal_bss *scan;
10221 struct wireless_dev *wdev;
10222 int start = cb->args[2], idx = 0;
10225 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
10228 /* nl80211_prepare_wdev_dump acquired it in the successful case */
10229 __acquire(&rdev->wiphy.mtx);
10232 spin_lock_bh(&rdev->bss_lock);
10235 * dump_scan will be called multiple times to break up the scan results
10236 * into multiple messages. It is unlikely that any more bss-es will be
10237 * expired after the first call, so only call only call this on the
10238 * first dump_scan invocation.
10241 cfg80211_bss_expire(rdev);
10243 cb->seq = rdev->bss_generation;
10245 list_for_each_entry(scan, &rdev->bss_list, list) {
10246 if (++idx <= start)
10248 if (nl80211_send_bss(skb, cb,
10249 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10250 rdev, wdev, scan) < 0) {
10256 spin_unlock_bh(&rdev->bss_lock);
10260 wiphy_unlock(&rdev->wiphy);
10265 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
10266 int flags, struct net_device *dev,
10267 bool allow_radio_stats,
10268 struct survey_info *survey)
10271 struct nlattr *infoattr;
10273 /* skip radio stats if userspace didn't request them */
10274 if (!survey->channel && !allow_radio_stats)
10277 hdr = nl80211hdr_put(msg, portid, seq, flags,
10278 NL80211_CMD_NEW_SURVEY_RESULTS);
10282 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
10283 goto nla_put_failure;
10285 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
10287 goto nla_put_failure;
10289 if (survey->channel &&
10290 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
10291 survey->channel->center_freq))
10292 goto nla_put_failure;
10294 if (survey->channel && survey->channel->freq_offset &&
10295 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET,
10296 survey->channel->freq_offset))
10297 goto nla_put_failure;
10299 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
10300 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
10301 goto nla_put_failure;
10302 if ((survey->filled & SURVEY_INFO_IN_USE) &&
10303 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
10304 goto nla_put_failure;
10305 if ((survey->filled & SURVEY_INFO_TIME) &&
10306 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
10307 survey->time, NL80211_SURVEY_INFO_PAD))
10308 goto nla_put_failure;
10309 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
10310 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
10311 survey->time_busy, NL80211_SURVEY_INFO_PAD))
10312 goto nla_put_failure;
10313 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
10314 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
10315 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
10316 goto nla_put_failure;
10317 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
10318 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
10319 survey->time_rx, NL80211_SURVEY_INFO_PAD))
10320 goto nla_put_failure;
10321 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
10322 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
10323 survey->time_tx, NL80211_SURVEY_INFO_PAD))
10324 goto nla_put_failure;
10325 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
10326 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
10327 survey->time_scan, NL80211_SURVEY_INFO_PAD))
10328 goto nla_put_failure;
10329 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
10330 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
10331 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
10332 goto nla_put_failure;
10334 nla_nest_end(msg, infoattr);
10336 genlmsg_end(msg, hdr);
10340 genlmsg_cancel(msg, hdr);
10344 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
10346 struct nlattr **attrbuf;
10347 struct survey_info survey;
10348 struct cfg80211_registered_device *rdev;
10349 struct wireless_dev *wdev;
10350 int survey_idx = cb->args[2];
10354 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
10358 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf);
10363 /* nl80211_prepare_wdev_dump acquired it in the successful case */
10364 __acquire(&rdev->wiphy.mtx);
10366 /* prepare_wdev_dump parsed the attributes */
10367 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
10369 if (!wdev->netdev) {
10374 if (!rdev->ops->dump_survey) {
10381 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
10383 if (res == -ENOENT)
10388 /* don't send disabled channels, but do send non-channel data */
10389 if (survey.channel &&
10390 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
10395 if (nl80211_send_survey(skb,
10396 NETLINK_CB(cb->skb).portid,
10397 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10398 wdev->netdev, radio_stats, &survey) < 0)
10404 cb->args[2] = survey_idx;
10408 wiphy_unlock(&rdev->wiphy);
10412 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
10414 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
10415 NL80211_WPA_VERSION_2 |
10416 NL80211_WPA_VERSION_3));
10419 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
10421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10422 struct net_device *dev = info->user_ptr[1];
10423 struct ieee80211_channel *chan;
10424 const u8 *bssid, *ssid;
10426 enum nl80211_auth_type auth_type;
10427 struct key_parse key;
10428 bool local_state_change;
10429 struct cfg80211_auth_request req = {};
10432 if (!info->attrs[NL80211_ATTR_MAC])
10435 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
10438 if (!info->attrs[NL80211_ATTR_SSID])
10441 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10444 err = nl80211_parse_key(info, &key);
10448 if (key.idx >= 0) {
10449 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
10451 if (!key.p.key || !key.p.key_len)
10453 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
10454 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
10455 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
10456 key.p.key_len != WLAN_KEY_LEN_WEP104))
10465 if (key.idx >= 0) {
10469 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
10470 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
10479 if (!rdev->ops->auth)
10480 return -EOPNOTSUPP;
10482 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10483 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10484 return -EOPNOTSUPP;
10486 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10487 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
10488 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10490 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10492 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
10496 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10497 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10499 if (info->attrs[NL80211_ATTR_IE]) {
10500 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10501 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10504 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10505 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
10508 if ((auth_type == NL80211_AUTHTYPE_SAE ||
10509 auth_type == NL80211_AUTHTYPE_FILS_SK ||
10510 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
10511 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
10512 !info->attrs[NL80211_ATTR_AUTH_DATA])
10515 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
10516 if (auth_type != NL80211_AUTHTYPE_SAE &&
10517 auth_type != NL80211_AUTHTYPE_FILS_SK &&
10518 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
10519 auth_type != NL80211_AUTHTYPE_FILS_PK)
10521 req.auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
10522 req.auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
10525 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
10528 * Since we no longer track auth state, ignore
10529 * requests to only change local state.
10531 if (local_state_change)
10534 req.auth_type = auth_type;
10535 req.key = key.p.key;
10536 req.key_len = key.p.key_len;
10537 req.key_idx = key.idx;
10538 req.link_id = nl80211_link_id_or_invalid(info->attrs);
10539 if (req.link_id >= 0) {
10540 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO))
10542 if (!info->attrs[NL80211_ATTR_MLD_ADDR])
10544 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
10545 if (!is_valid_ether_addr(req.ap_mld_addr))
10549 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
10550 IEEE80211_BSS_TYPE_ESS,
10551 IEEE80211_PRIVACY_ANY);
10555 wdev_lock(dev->ieee80211_ptr);
10556 err = cfg80211_mlme_auth(rdev, dev, &req);
10557 wdev_unlock(dev->ieee80211_ptr);
10559 cfg80211_put_bss(&rdev->wiphy, req.bss);
10564 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
10565 struct genl_info *info)
10567 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10568 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
10572 if (!rdev->ops->tx_control_port ||
10573 !wiphy_ext_feature_isset(&rdev->wiphy,
10574 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
10575 return -EOPNOTSUPP;
10580 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
10581 struct genl_info *info,
10582 struct cfg80211_crypto_settings *settings,
10585 memset(settings, 0, sizeof(*settings));
10587 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
10589 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
10592 proto = nla_get_u16(
10593 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
10594 settings->control_port_ethertype = cpu_to_be16(proto);
10595 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
10596 proto != ETH_P_PAE)
10598 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
10599 settings->control_port_no_encrypt = true;
10601 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
10603 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10604 int r = validate_pae_over_nl80211(rdev, info);
10609 settings->control_port_over_nl80211 = true;
10611 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH])
10612 settings->control_port_no_preauth = true;
10615 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
10619 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
10620 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
10621 settings->n_ciphers_pairwise = len / sizeof(u32);
10623 if (len % sizeof(u32))
10626 if (settings->n_ciphers_pairwise > cipher_limit)
10629 memcpy(settings->ciphers_pairwise, data, len);
10631 for (i = 0; i < settings->n_ciphers_pairwise; i++)
10632 if (!cfg80211_supported_cipher_suite(
10634 settings->ciphers_pairwise[i]))
10638 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
10639 settings->cipher_group =
10640 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
10641 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
10642 settings->cipher_group))
10646 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
10647 settings->wpa_versions =
10648 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
10649 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
10653 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
10657 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
10658 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
10659 settings->n_akm_suites = len / sizeof(u32);
10661 if (len % sizeof(u32))
10664 if (settings->n_akm_suites > rdev->wiphy.max_num_akm_suites)
10667 memcpy(settings->akm_suites, data, len);
10670 if (info->attrs[NL80211_ATTR_PMK]) {
10671 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
10673 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10674 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
10675 !wiphy_ext_feature_isset(&rdev->wiphy,
10676 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
10678 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10681 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
10682 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10683 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
10684 !wiphy_ext_feature_isset(&rdev->wiphy,
10685 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
10687 settings->sae_pwd =
10688 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
10689 settings->sae_pwd_len =
10690 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
10693 if (info->attrs[NL80211_ATTR_SAE_PWE])
10694 settings->sae_pwe =
10695 nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]);
10697 settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED;
10702 static struct cfg80211_bss *nl80211_assoc_bss(struct cfg80211_registered_device *rdev,
10703 const u8 *ssid, int ssid_len,
10704 struct nlattr **attrs)
10706 struct ieee80211_channel *chan;
10707 struct cfg80211_bss *bss;
10711 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_WIPHY_FREQ])
10712 return ERR_PTR(-EINVAL);
10714 bssid = nla_data(attrs[NL80211_ATTR_MAC]);
10716 freq = MHZ_TO_KHZ(nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]));
10717 if (attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10718 freq += nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10720 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
10722 return ERR_PTR(-EINVAL);
10724 bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid,
10726 IEEE80211_BSS_TYPE_ESS,
10727 IEEE80211_PRIVACY_ANY);
10729 return ERR_PTR(-ENOENT);
10734 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
10736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10737 struct net_device *dev = info->user_ptr[1];
10738 struct cfg80211_assoc_request req = {};
10739 struct nlattr **attrs = NULL;
10740 const u8 *ap_addr, *ssid;
10741 unsigned int link_id;
10744 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10745 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10748 if (!info->attrs[NL80211_ATTR_SSID])
10751 if (!rdev->ops->assoc)
10752 return -EOPNOTSUPP;
10754 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10755 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10756 return -EOPNOTSUPP;
10758 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10759 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10761 if (info->attrs[NL80211_ATTR_IE]) {
10762 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10763 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10765 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
10766 req.ie, req.ie_len)) {
10767 GENL_SET_ERR_MSG(info,
10768 "non-inheritance makes no sense");
10773 if (info->attrs[NL80211_ATTR_USE_MFP]) {
10774 enum nl80211_mfp mfp =
10775 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
10776 if (mfp == NL80211_MFP_REQUIRED)
10777 req.use_mfp = true;
10778 else if (mfp != NL80211_MFP_NO)
10782 if (info->attrs[NL80211_ATTR_PREV_BSSID])
10783 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
10785 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
10786 req.flags |= ASSOC_REQ_DISABLE_HT;
10788 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10789 memcpy(&req.ht_capa_mask,
10790 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
10791 sizeof(req.ht_capa_mask));
10793 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
10794 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10796 memcpy(&req.ht_capa,
10797 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10798 sizeof(req.ht_capa));
10801 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
10802 req.flags |= ASSOC_REQ_DISABLE_VHT;
10804 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE]))
10805 req.flags |= ASSOC_REQ_DISABLE_HE;
10807 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT]))
10808 req.flags |= ASSOC_REQ_DISABLE_EHT;
10810 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
10811 memcpy(&req.vht_capa_mask,
10812 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
10813 sizeof(req.vht_capa_mask));
10815 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
10816 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
10818 memcpy(&req.vht_capa,
10819 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
10820 sizeof(req.vht_capa));
10823 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
10824 if (!((rdev->wiphy.features &
10825 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
10826 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
10827 !wiphy_ext_feature_isset(&rdev->wiphy,
10828 NL80211_EXT_FEATURE_RRM))
10830 req.flags |= ASSOC_REQ_USE_RRM;
10833 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
10834 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
10835 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
10836 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
10839 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
10842 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) {
10843 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY])
10845 memcpy(&req.s1g_capa_mask,
10846 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]),
10847 sizeof(req.s1g_capa_mask));
10850 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) {
10851 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK])
10853 memcpy(&req.s1g_capa,
10854 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]),
10855 sizeof(req.s1g_capa));
10858 req.link_id = nl80211_link_id_or_invalid(info->attrs);
10860 if (info->attrs[NL80211_ATTR_MLO_LINKS]) {
10861 unsigned int attrsize = NUM_NL80211_ATTR * sizeof(*attrs);
10862 struct nlattr *link;
10865 if (req.link_id < 0)
10868 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO))
10871 if (info->attrs[NL80211_ATTR_MAC] ||
10872 info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10873 !info->attrs[NL80211_ATTR_MLD_ADDR])
10876 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
10877 ap_addr = req.ap_mld_addr;
10879 attrs = kzalloc(attrsize, GFP_KERNEL);
10883 nla_for_each_nested(link,
10884 info->attrs[NL80211_ATTR_MLO_LINKS],
10886 memset(attrs, 0, attrsize);
10888 nla_parse_nested(attrs, NL80211_ATTR_MAX,
10891 if (!attrs[NL80211_ATTR_MLO_LINK_ID]) {
10896 link_id = nla_get_u8(attrs[NL80211_ATTR_MLO_LINK_ID]);
10897 /* cannot use the same link ID again */
10898 if (req.links[link_id].bss) {
10902 req.links[link_id].bss =
10903 nl80211_assoc_bss(rdev, ssid, ssid_len, attrs);
10904 if (IS_ERR(req.links[link_id].bss)) {
10905 err = PTR_ERR(req.links[link_id].bss);
10906 req.links[link_id].bss = NULL;
10910 if (attrs[NL80211_ATTR_IE]) {
10911 req.links[link_id].elems =
10912 nla_data(attrs[NL80211_ATTR_IE]);
10913 req.links[link_id].elems_len =
10914 nla_len(attrs[NL80211_ATTR_IE]);
10916 if (cfg80211_find_elem(WLAN_EID_FRAGMENT,
10917 req.links[link_id].elems,
10918 req.links[link_id].elems_len)) {
10919 GENL_SET_ERR_MSG(info,
10920 "cannot deal with fragmentation");
10925 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
10926 req.links[link_id].elems,
10927 req.links[link_id].elems_len)) {
10928 GENL_SET_ERR_MSG(info,
10929 "cannot deal with non-inheritance");
10936 if (!req.links[req.link_id].bss) {
10941 if (req.links[req.link_id].elems_len) {
10942 GENL_SET_ERR_MSG(info,
10943 "cannot have per-link elems on assoc link");
10951 if (req.link_id >= 0)
10954 req.bss = nl80211_assoc_bss(rdev, ssid, ssid_len, info->attrs);
10955 if (IS_ERR(req.bss))
10956 return PTR_ERR(req.bss);
10957 ap_addr = req.bss->bssid;
10960 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
10962 wdev_lock(dev->ieee80211_ptr);
10964 err = cfg80211_mlme_assoc(rdev, dev, &req);
10966 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10967 dev->ieee80211_ptr->conn_owner_nlportid =
10969 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10970 ap_addr, ETH_ALEN);
10973 wdev_unlock(dev->ieee80211_ptr);
10977 for (link_id = 0; link_id < ARRAY_SIZE(req.links); link_id++)
10978 cfg80211_put_bss(&rdev->wiphy, req.links[link_id].bss);
10979 cfg80211_put_bss(&rdev->wiphy, req.bss);
10985 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
10987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10988 struct net_device *dev = info->user_ptr[1];
10989 const u8 *ie = NULL, *bssid;
10990 int ie_len = 0, err;
10992 bool local_state_change;
10994 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10995 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10998 if (!info->attrs[NL80211_ATTR_MAC])
11001 if (!info->attrs[NL80211_ATTR_REASON_CODE])
11004 if (!rdev->ops->deauth)
11005 return -EOPNOTSUPP;
11007 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11008 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11009 return -EOPNOTSUPP;
11011 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11013 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
11014 if (reason_code == 0) {
11015 /* Reason Code 0 is reserved */
11019 if (info->attrs[NL80211_ATTR_IE]) {
11020 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11021 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11024 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
11026 wdev_lock(dev->ieee80211_ptr);
11027 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
11028 local_state_change);
11029 wdev_unlock(dev->ieee80211_ptr);
11033 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
11035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11036 struct net_device *dev = info->user_ptr[1];
11037 const u8 *ie = NULL, *bssid;
11038 int ie_len = 0, err;
11040 bool local_state_change;
11042 if (dev->ieee80211_ptr->conn_owner_nlportid &&
11043 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
11046 if (!info->attrs[NL80211_ATTR_MAC])
11049 if (!info->attrs[NL80211_ATTR_REASON_CODE])
11052 if (!rdev->ops->disassoc)
11053 return -EOPNOTSUPP;
11055 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11056 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11057 return -EOPNOTSUPP;
11059 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11061 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
11062 if (reason_code == 0) {
11063 /* Reason Code 0 is reserved */
11067 if (info->attrs[NL80211_ATTR_IE]) {
11068 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11069 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11072 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
11074 wdev_lock(dev->ieee80211_ptr);
11075 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
11076 local_state_change);
11077 wdev_unlock(dev->ieee80211_ptr);
11082 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
11083 int mcast_rate[NUM_NL80211_BANDS],
11086 struct wiphy *wiphy = &rdev->wiphy;
11087 bool found = false;
11090 for (band = 0; band < NUM_NL80211_BANDS; band++) {
11091 struct ieee80211_supported_band *sband;
11093 sband = wiphy->bands[band];
11097 for (i = 0; i < sband->n_bitrates; i++) {
11098 if (sband->bitrates[i].bitrate == rateval) {
11099 mcast_rate[band] = i + 1;
11109 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
11111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11112 struct net_device *dev = info->user_ptr[1];
11113 struct cfg80211_ibss_params ibss;
11114 struct wiphy *wiphy;
11115 struct cfg80211_cached_keys *connkeys = NULL;
11118 memset(&ibss, 0, sizeof(ibss));
11120 if (!info->attrs[NL80211_ATTR_SSID] ||
11121 !nla_len(info->attrs[NL80211_ATTR_SSID]))
11124 ibss.beacon_interval = 100;
11126 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
11127 ibss.beacon_interval =
11128 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
11130 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
11131 ibss.beacon_interval);
11135 if (!rdev->ops->join_ibss)
11136 return -EOPNOTSUPP;
11138 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
11139 return -EOPNOTSUPP;
11141 wiphy = &rdev->wiphy;
11143 if (info->attrs[NL80211_ATTR_MAC]) {
11144 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11146 if (!is_valid_ether_addr(ibss.bssid))
11149 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
11150 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
11152 if (info->attrs[NL80211_ATTR_IE]) {
11153 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11154 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11157 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
11161 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
11162 NL80211_IFTYPE_ADHOC))
11165 switch (ibss.chandef.width) {
11166 case NL80211_CHAN_WIDTH_5:
11167 case NL80211_CHAN_WIDTH_10:
11168 case NL80211_CHAN_WIDTH_20_NOHT:
11170 case NL80211_CHAN_WIDTH_20:
11171 case NL80211_CHAN_WIDTH_40:
11172 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
11175 case NL80211_CHAN_WIDTH_80:
11176 case NL80211_CHAN_WIDTH_80P80:
11177 case NL80211_CHAN_WIDTH_160:
11178 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
11180 if (!wiphy_ext_feature_isset(&rdev->wiphy,
11181 NL80211_EXT_FEATURE_VHT_IBSS))
11184 case NL80211_CHAN_WIDTH_320:
11190 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
11191 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
11193 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11195 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11197 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11198 struct ieee80211_supported_band *sband =
11199 wiphy->bands[ibss.chandef.chan->band];
11201 err = ieee80211_get_ratemask(sband, rates, n_rates,
11202 &ibss.basic_rates);
11207 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11208 memcpy(&ibss.ht_capa_mask,
11209 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11210 sizeof(ibss.ht_capa_mask));
11212 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11213 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11215 memcpy(&ibss.ht_capa,
11216 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11217 sizeof(ibss.ht_capa));
11220 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11221 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
11222 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11225 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
11226 bool no_ht = false;
11228 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
11229 if (IS_ERR(connkeys))
11230 return PTR_ERR(connkeys);
11232 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
11234 kfree_sensitive(connkeys);
11239 ibss.control_port =
11240 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
11242 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11243 int r = validate_pae_over_nl80211(rdev, info);
11246 kfree_sensitive(connkeys);
11250 ibss.control_port_over_nl80211 = true;
11253 ibss.userspace_handles_dfs =
11254 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11256 wdev_lock(dev->ieee80211_ptr);
11257 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
11259 kfree_sensitive(connkeys);
11260 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
11261 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11262 wdev_unlock(dev->ieee80211_ptr);
11267 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
11269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11270 struct net_device *dev = info->user_ptr[1];
11272 if (!rdev->ops->leave_ibss)
11273 return -EOPNOTSUPP;
11275 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
11276 return -EOPNOTSUPP;
11278 return cfg80211_leave_ibss(rdev, dev, false);
11281 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
11283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11284 struct net_device *dev = info->user_ptr[1];
11285 int mcast_rate[NUM_NL80211_BANDS];
11288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
11289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
11290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
11291 return -EOPNOTSUPP;
11293 if (!rdev->ops->set_mcast_rate)
11294 return -EOPNOTSUPP;
11296 memset(mcast_rate, 0, sizeof(mcast_rate));
11298 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
11301 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
11302 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
11305 return rdev_set_mcast_rate(rdev, dev, mcast_rate);
11308 static struct sk_buff *
11309 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
11310 struct wireless_dev *wdev, int approxlen,
11311 u32 portid, u32 seq, enum nl80211_commands cmd,
11312 enum nl80211_attrs attr,
11313 const struct nl80211_vendor_cmd_info *info,
11316 struct sk_buff *skb;
11318 struct nlattr *data;
11320 skb = nlmsg_new(approxlen + 100, gfp);
11324 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
11330 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11331 goto nla_put_failure;
11334 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
11336 goto nla_put_failure;
11337 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
11339 goto nla_put_failure;
11343 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11344 wdev_id(wdev), NL80211_ATTR_PAD))
11345 goto nla_put_failure;
11346 if (wdev->netdev &&
11347 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
11348 wdev->netdev->ifindex))
11349 goto nla_put_failure;
11352 data = nla_nest_start_noflag(skb, attr);
11354 goto nla_put_failure;
11356 ((void **)skb->cb)[0] = rdev;
11357 ((void **)skb->cb)[1] = hdr;
11358 ((void **)skb->cb)[2] = data;
11367 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
11368 struct wireless_dev *wdev,
11369 enum nl80211_commands cmd,
11370 enum nl80211_attrs attr,
11371 unsigned int portid,
11372 int vendor_event_idx,
11373 int approxlen, gfp_t gfp)
11375 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11376 const struct nl80211_vendor_cmd_info *info;
11379 case NL80211_CMD_TESTMODE:
11380 if (WARN_ON(vendor_event_idx != -1))
11384 case NL80211_CMD_VENDOR:
11385 if (WARN_ON(vendor_event_idx < 0 ||
11386 vendor_event_idx >= wiphy->n_vendor_events))
11388 info = &wiphy->vendor_events[vendor_event_idx];
11395 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
11396 cmd, attr, info, gfp);
11398 EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
11400 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
11402 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11403 void *hdr = ((void **)skb->cb)[1];
11404 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
11405 struct nlattr *data = ((void **)skb->cb)[2];
11406 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
11408 /* clear CB data for netlink core to own from now on */
11409 memset(skb->cb, 0, sizeof(skb->cb));
11411 nla_nest_end(skb, data);
11412 genlmsg_end(skb, hdr);
11414 if (nlhdr->nlmsg_pid) {
11415 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
11418 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
11419 mcgrp = NL80211_MCGRP_VENDOR;
11421 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11422 skb, 0, mcgrp, gfp);
11425 EXPORT_SYMBOL(__cfg80211_send_event_skb);
11427 #ifdef CONFIG_NL80211_TESTMODE
11428 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
11430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11431 struct wireless_dev *wdev;
11434 lockdep_assert_held(&rdev->wiphy.mtx);
11436 wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info),
11439 if (!rdev->ops->testmode_cmd)
11440 return -EOPNOTSUPP;
11442 if (IS_ERR(wdev)) {
11443 err = PTR_ERR(wdev);
11444 if (err != -EINVAL)
11447 } else if (wdev->wiphy != &rdev->wiphy) {
11451 if (!info->attrs[NL80211_ATTR_TESTDATA])
11454 rdev->cur_cmd_info = info;
11455 err = rdev_testmode_cmd(rdev, wdev,
11456 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
11457 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
11458 rdev->cur_cmd_info = NULL;
11463 static int nl80211_testmode_dump(struct sk_buff *skb,
11464 struct netlink_callback *cb)
11466 struct cfg80211_registered_device *rdev;
11467 struct nlattr **attrbuf = NULL;
11477 * 0 is a valid index, but not valid for args[0],
11478 * so we need to offset by 1.
11480 phy_idx = cb->args[0] - 1;
11482 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
11488 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
11495 err = nlmsg_parse_deprecated(cb->nlh,
11496 GENL_HDRLEN + nl80211_fam.hdrsize,
11497 attrbuf, nl80211_fam.maxattr,
11498 nl80211_policy, NULL);
11502 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
11503 if (IS_ERR(rdev)) {
11504 err = PTR_ERR(rdev);
11507 phy_idx = rdev->wiphy_idx;
11509 if (attrbuf[NL80211_ATTR_TESTDATA])
11510 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
11514 data = nla_data((void *)cb->args[1]);
11515 data_len = nla_len((void *)cb->args[1]);
11518 if (!rdev->ops->testmode_dump) {
11524 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11525 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11526 NL80211_CMD_TESTMODE);
11527 struct nlattr *tmdata;
11532 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
11533 genlmsg_cancel(skb, hdr);
11537 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
11539 genlmsg_cancel(skb, hdr);
11542 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
11543 nla_nest_end(skb, tmdata);
11545 if (err == -ENOBUFS || err == -ENOENT) {
11546 genlmsg_cancel(skb, hdr);
11549 genlmsg_cancel(skb, hdr);
11553 genlmsg_end(skb, hdr);
11558 cb->args[0] = phy_idx + 1;
11566 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
11568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11569 struct net_device *dev = info->user_ptr[1];
11570 struct cfg80211_connect_params connect;
11571 struct wiphy *wiphy;
11572 struct cfg80211_cached_keys *connkeys = NULL;
11576 memset(&connect, 0, sizeof(connect));
11578 if (!info->attrs[NL80211_ATTR_SSID] ||
11579 !nla_len(info->attrs[NL80211_ATTR_SSID]))
11582 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
11583 connect.auth_type =
11584 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
11585 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
11586 NL80211_CMD_CONNECT))
11589 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
11591 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
11593 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
11594 !wiphy_ext_feature_isset(&rdev->wiphy,
11595 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
11597 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
11599 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
11600 NL80211_MAX_NR_CIPHER_SUITES);
11604 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11605 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11606 return -EOPNOTSUPP;
11608 wiphy = &rdev->wiphy;
11610 connect.bg_scan_period = -1;
11611 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
11612 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
11613 connect.bg_scan_period =
11614 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
11617 if (info->attrs[NL80211_ATTR_MAC])
11618 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11619 else if (info->attrs[NL80211_ATTR_MAC_HINT])
11620 connect.bssid_hint =
11621 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
11622 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
11623 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
11625 if (info->attrs[NL80211_ATTR_IE]) {
11626 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11627 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11630 if (info->attrs[NL80211_ATTR_USE_MFP]) {
11631 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
11632 if (connect.mfp == NL80211_MFP_OPTIONAL &&
11633 !wiphy_ext_feature_isset(&rdev->wiphy,
11634 NL80211_EXT_FEATURE_MFP_OPTIONAL))
11635 return -EOPNOTSUPP;
11637 connect.mfp = NL80211_MFP_NO;
11640 if (info->attrs[NL80211_ATTR_PREV_BSSID])
11641 connect.prev_bssid =
11642 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
11644 if (info->attrs[NL80211_ATTR_WIPHY_FREQ])
11645 freq = MHZ_TO_KHZ(nla_get_u32(
11646 info->attrs[NL80211_ATTR_WIPHY_FREQ]));
11647 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
11649 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
11652 connect.channel = nl80211_get_valid_chan(wiphy, freq);
11653 if (!connect.channel)
11655 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
11656 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
11657 freq = MHZ_TO_KHZ(freq);
11658 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq);
11659 if (!connect.channel_hint)
11663 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
11664 connect.edmg.channels =
11665 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
11667 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
11668 connect.edmg.bw_config =
11669 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
11672 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
11673 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
11674 if (IS_ERR(connkeys))
11675 return PTR_ERR(connkeys);
11678 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
11679 connect.flags |= ASSOC_REQ_DISABLE_HT;
11681 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
11682 memcpy(&connect.ht_capa_mask,
11683 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
11684 sizeof(connect.ht_capa_mask));
11686 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
11687 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
11688 kfree_sensitive(connkeys);
11691 memcpy(&connect.ht_capa,
11692 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
11693 sizeof(connect.ht_capa));
11696 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
11697 connect.flags |= ASSOC_REQ_DISABLE_VHT;
11699 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE]))
11700 connect.flags |= ASSOC_REQ_DISABLE_HE;
11702 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT]))
11703 connect.flags |= ASSOC_REQ_DISABLE_EHT;
11705 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
11706 memcpy(&connect.vht_capa_mask,
11707 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
11708 sizeof(connect.vht_capa_mask));
11710 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
11711 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
11712 kfree_sensitive(connkeys);
11715 memcpy(&connect.vht_capa,
11716 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
11717 sizeof(connect.vht_capa));
11720 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
11721 if (!((rdev->wiphy.features &
11722 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
11723 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
11724 !wiphy_ext_feature_isset(&rdev->wiphy,
11725 NL80211_EXT_FEATURE_RRM)) {
11726 kfree_sensitive(connkeys);
11729 connect.flags |= ASSOC_REQ_USE_RRM;
11732 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
11733 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
11734 kfree_sensitive(connkeys);
11735 return -EOPNOTSUPP;
11738 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
11739 /* bss selection makes no sense if bssid is set */
11740 if (connect.bssid) {
11741 kfree_sensitive(connkeys);
11745 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
11746 wiphy, &connect.bss_select);
11748 kfree_sensitive(connkeys);
11753 if (wiphy_ext_feature_isset(&rdev->wiphy,
11754 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
11755 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
11756 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
11757 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
11758 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
11759 connect.fils_erp_username =
11760 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
11761 connect.fils_erp_username_len =
11762 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
11763 connect.fils_erp_realm =
11764 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
11765 connect.fils_erp_realm_len =
11766 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
11767 connect.fils_erp_next_seq_num =
11769 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
11770 connect.fils_erp_rrk =
11771 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
11772 connect.fils_erp_rrk_len =
11773 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
11774 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
11775 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
11776 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
11777 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
11778 kfree_sensitive(connkeys);
11782 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
11783 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
11784 kfree_sensitive(connkeys);
11785 GENL_SET_ERR_MSG(info,
11786 "external auth requires connection ownership");
11789 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
11792 if (nla_get_flag(info->attrs[NL80211_ATTR_MLO_SUPPORT]))
11793 connect.flags |= CONNECT_REQ_MLO_SUPPORT;
11795 wdev_lock(dev->ieee80211_ptr);
11797 err = cfg80211_connect(rdev, dev, &connect, connkeys,
11798 connect.prev_bssid);
11800 kfree_sensitive(connkeys);
11802 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
11803 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11805 memcpy(dev->ieee80211_ptr->disconnect_bssid,
11806 connect.bssid, ETH_ALEN);
11808 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid);
11811 wdev_unlock(dev->ieee80211_ptr);
11816 static int nl80211_update_connect_params(struct sk_buff *skb,
11817 struct genl_info *info)
11819 struct cfg80211_connect_params connect = {};
11820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11821 struct net_device *dev = info->user_ptr[1];
11822 struct wireless_dev *wdev = dev->ieee80211_ptr;
11823 bool fils_sk_offload;
11828 if (!rdev->ops->update_connect_params)
11829 return -EOPNOTSUPP;
11831 if (info->attrs[NL80211_ATTR_IE]) {
11832 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11833 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11834 changed |= UPDATE_ASSOC_IES;
11837 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
11838 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
11841 * when driver supports fils-sk offload all attributes must be
11842 * provided. So the else covers "fils-sk-not-all" and
11843 * "no-fils-sk-any".
11845 if (fils_sk_offload &&
11846 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
11847 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
11848 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
11849 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
11850 connect.fils_erp_username =
11851 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
11852 connect.fils_erp_username_len =
11853 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
11854 connect.fils_erp_realm =
11855 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
11856 connect.fils_erp_realm_len =
11857 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
11858 connect.fils_erp_next_seq_num =
11860 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
11861 connect.fils_erp_rrk =
11862 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
11863 connect.fils_erp_rrk_len =
11864 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
11865 changed |= UPDATE_FILS_ERP_INFO;
11866 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
11867 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
11868 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
11869 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
11873 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
11874 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
11875 if (!nl80211_valid_auth_type(rdev, auth_type,
11876 NL80211_CMD_CONNECT))
11879 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
11880 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
11883 connect.auth_type = auth_type;
11884 changed |= UPDATE_AUTH_TYPE;
11887 wdev_lock(dev->ieee80211_ptr);
11888 if (!wdev->connected)
11891 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
11892 wdev_unlock(dev->ieee80211_ptr);
11897 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
11899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11900 struct net_device *dev = info->user_ptr[1];
11904 if (dev->ieee80211_ptr->conn_owner_nlportid &&
11905 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
11908 if (!info->attrs[NL80211_ATTR_REASON_CODE])
11909 reason = WLAN_REASON_DEAUTH_LEAVING;
11911 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
11916 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
11917 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
11918 return -EOPNOTSUPP;
11920 wdev_lock(dev->ieee80211_ptr);
11921 ret = cfg80211_disconnect(rdev, dev, reason, true);
11922 wdev_unlock(dev->ieee80211_ptr);
11926 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
11928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11932 if (info->attrs[NL80211_ATTR_PID]) {
11933 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
11935 net = get_net_ns_by_pid(pid);
11936 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
11937 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
11939 net = get_net_ns_by_fd(fd);
11945 return PTR_ERR(net);
11949 /* check if anything to do */
11950 if (!net_eq(wiphy_net(&rdev->wiphy), net))
11951 err = cfg80211_switch_netns(rdev, net);
11957 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
11959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11960 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
11961 struct cfg80211_pmksa *pmksa) = NULL;
11962 struct net_device *dev = info->user_ptr[1];
11963 struct cfg80211_pmksa pmksa;
11965 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
11967 if (!info->attrs[NL80211_ATTR_PMKID])
11970 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
11972 if (info->attrs[NL80211_ATTR_MAC]) {
11973 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
11974 } else if (info->attrs[NL80211_ATTR_SSID] &&
11975 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
11976 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
11977 info->attrs[NL80211_ATTR_PMK])) {
11978 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
11979 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
11981 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
11985 if (info->attrs[NL80211_ATTR_PMK]) {
11986 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
11987 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
11990 if (info->attrs[NL80211_ATTR_PMK_LIFETIME])
11991 pmksa.pmk_lifetime =
11992 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]);
11994 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD])
11995 pmksa.pmk_reauth_threshold =
11997 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]);
11999 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12000 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
12001 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
12002 wiphy_ext_feature_isset(&rdev->wiphy,
12003 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
12004 return -EOPNOTSUPP;
12006 switch (info->genlhdr->cmd) {
12007 case NL80211_CMD_SET_PMKSA:
12008 rdev_ops = rdev->ops->set_pmksa;
12010 case NL80211_CMD_DEL_PMKSA:
12011 rdev_ops = rdev->ops->del_pmksa;
12019 return -EOPNOTSUPP;
12021 return rdev_ops(&rdev->wiphy, dev, &pmksa);
12024 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
12026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12027 struct net_device *dev = info->user_ptr[1];
12029 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
12030 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
12031 return -EOPNOTSUPP;
12033 if (!rdev->ops->flush_pmksa)
12034 return -EOPNOTSUPP;
12036 return rdev_flush_pmksa(rdev, dev);
12039 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
12041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12042 struct net_device *dev = info->user_ptr[1];
12043 u8 action_code, dialog_token;
12044 u32 peer_capability = 0;
12049 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
12050 !rdev->ops->tdls_mgmt)
12051 return -EOPNOTSUPP;
12053 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
12054 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
12055 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
12056 !info->attrs[NL80211_ATTR_IE] ||
12057 !info->attrs[NL80211_ATTR_MAC])
12060 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12061 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
12062 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12063 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
12064 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
12065 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
12067 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
12069 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
12070 dialog_token, status_code, peer_capability,
12072 nla_data(info->attrs[NL80211_ATTR_IE]),
12073 nla_len(info->attrs[NL80211_ATTR_IE]));
12076 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
12078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12079 struct net_device *dev = info->user_ptr[1];
12080 enum nl80211_tdls_operation operation;
12083 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
12084 !rdev->ops->tdls_oper)
12085 return -EOPNOTSUPP;
12087 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
12088 !info->attrs[NL80211_ATTR_MAC])
12091 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
12092 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12094 return rdev_tdls_oper(rdev, dev, peer, operation);
12097 static int nl80211_remain_on_channel(struct sk_buff *skb,
12098 struct genl_info *info)
12100 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12101 unsigned int link_id = nl80211_link_id(info->attrs);
12102 struct wireless_dev *wdev = info->user_ptr[1];
12103 struct cfg80211_chan_def chandef;
12104 struct sk_buff *msg;
12110 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
12111 !info->attrs[NL80211_ATTR_DURATION])
12114 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
12116 if (!rdev->ops->remain_on_channel ||
12117 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
12118 return -EOPNOTSUPP;
12121 * We should be on that channel for at least a minimum amount of
12122 * time (10ms) but no longer than the driver supports.
12124 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
12125 duration > rdev->wiphy.max_remain_on_channel_duration)
12128 err = nl80211_parse_chandef(rdev, info, &chandef);
12133 if (!cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) {
12134 const struct cfg80211_chan_def *oper_chandef, *compat_chandef;
12136 oper_chandef = wdev_chandef(wdev, link_id);
12138 if (WARN_ON(!oper_chandef)) {
12139 /* cannot happen since we must beacon to get here */
12145 /* note: returns first one if identical chandefs */
12146 compat_chandef = cfg80211_chandef_compatible(&chandef,
12149 if (compat_chandef != &chandef) {
12156 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12160 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12161 NL80211_CMD_REMAIN_ON_CHANNEL);
12167 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
12168 duration, &cookie);
12173 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12175 goto nla_put_failure;
12177 genlmsg_end(msg, hdr);
12179 return genlmsg_reply(msg, info);
12188 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
12189 struct genl_info *info)
12191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12192 struct wireless_dev *wdev = info->user_ptr[1];
12195 if (!info->attrs[NL80211_ATTR_COOKIE])
12198 if (!rdev->ops->cancel_remain_on_channel)
12199 return -EOPNOTSUPP;
12201 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12203 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
12206 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
12207 struct genl_info *info)
12209 struct cfg80211_bitrate_mask mask;
12210 unsigned int link_id = nl80211_link_id(info->attrs);
12211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12212 struct net_device *dev = info->user_ptr[1];
12213 struct wireless_dev *wdev = dev->ieee80211_ptr;
12216 if (!rdev->ops->set_bitrate_mask)
12217 return -EOPNOTSUPP;
12220 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
12221 NL80211_ATTR_TX_RATES, &mask,
12222 dev, true, link_id);
12226 err = rdev_set_bitrate_mask(rdev, dev, link_id, NULL, &mask);
12232 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
12234 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12235 struct wireless_dev *wdev = info->user_ptr[1];
12236 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
12238 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
12241 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
12242 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
12244 switch (wdev->iftype) {
12245 case NL80211_IFTYPE_STATION:
12246 case NL80211_IFTYPE_ADHOC:
12247 case NL80211_IFTYPE_P2P_CLIENT:
12248 case NL80211_IFTYPE_AP:
12249 case NL80211_IFTYPE_AP_VLAN:
12250 case NL80211_IFTYPE_MESH_POINT:
12251 case NL80211_IFTYPE_P2P_GO:
12252 case NL80211_IFTYPE_P2P_DEVICE:
12254 case NL80211_IFTYPE_NAN:
12256 return -EOPNOTSUPP;
12259 /* not much point in registering if we can't reply */
12260 if (!rdev->ops->mgmt_tx)
12261 return -EOPNOTSUPP;
12263 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] &&
12264 !wiphy_ext_feature_isset(&rdev->wiphy,
12265 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) {
12266 GENL_SET_ERR_MSG(info,
12267 "multicast RX registrations are not supported");
12268 return -EOPNOTSUPP;
12271 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
12272 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
12273 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
12274 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST],
12278 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
12280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12281 struct wireless_dev *wdev = info->user_ptr[1];
12282 struct cfg80211_chan_def chandef;
12286 struct sk_buff *msg = NULL;
12287 struct cfg80211_mgmt_tx_params params = {
12288 .dont_wait_for_ack =
12289 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
12292 if (!info->attrs[NL80211_ATTR_FRAME])
12295 if (!rdev->ops->mgmt_tx)
12296 return -EOPNOTSUPP;
12298 switch (wdev->iftype) {
12299 case NL80211_IFTYPE_P2P_DEVICE:
12300 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
12303 case NL80211_IFTYPE_STATION:
12304 case NL80211_IFTYPE_ADHOC:
12305 case NL80211_IFTYPE_P2P_CLIENT:
12306 case NL80211_IFTYPE_AP:
12307 case NL80211_IFTYPE_AP_VLAN:
12308 case NL80211_IFTYPE_MESH_POINT:
12309 case NL80211_IFTYPE_P2P_GO:
12311 case NL80211_IFTYPE_NAN:
12313 return -EOPNOTSUPP;
12316 if (info->attrs[NL80211_ATTR_DURATION]) {
12317 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
12319 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
12322 * We should wait on the channel for at least a minimum amount
12323 * of time (10ms) but no longer than the driver supports.
12325 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
12326 params.wait > rdev->wiphy.max_remain_on_channel_duration)
12330 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
12332 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
12335 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
12337 /* get the channel if any has been specified, otherwise pass NULL to
12338 * the driver. The latter will use the current one
12340 chandef.chan = NULL;
12341 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
12342 err = nl80211_parse_chandef(rdev, info, &chandef);
12347 if (!chandef.chan && params.offchan)
12351 if (params.offchan &&
12352 !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) {
12357 params.link_id = nl80211_link_id_or_invalid(info->attrs);
12359 * This now races due to the unlock, but we cannot check
12360 * the valid links for the _station_ anyway, so that's up
12363 if (params.link_id >= 0 &&
12364 !(wdev->valid_links & BIT(params.link_id))) {
12370 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
12371 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
12373 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
12374 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
12377 if (len % sizeof(u16))
12380 params.n_csa_offsets = len / sizeof(u16);
12381 params.csa_offsets =
12382 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
12384 /* check that all the offsets fit the frame */
12385 for (i = 0; i < params.n_csa_offsets; i++) {
12386 if (params.csa_offsets[i] >= params.len)
12391 if (!params.dont_wait_for_ack) {
12392 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12396 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12397 NL80211_CMD_FRAME);
12404 params.chan = chandef.chan;
12405 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie);
12410 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12412 goto nla_put_failure;
12414 genlmsg_end(msg, hdr);
12415 return genlmsg_reply(msg, info);
12427 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
12429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12430 struct wireless_dev *wdev = info->user_ptr[1];
12433 if (!info->attrs[NL80211_ATTR_COOKIE])
12436 if (!rdev->ops->mgmt_tx_cancel_wait)
12437 return -EOPNOTSUPP;
12439 switch (wdev->iftype) {
12440 case NL80211_IFTYPE_STATION:
12441 case NL80211_IFTYPE_ADHOC:
12442 case NL80211_IFTYPE_P2P_CLIENT:
12443 case NL80211_IFTYPE_AP:
12444 case NL80211_IFTYPE_AP_VLAN:
12445 case NL80211_IFTYPE_P2P_GO:
12446 case NL80211_IFTYPE_P2P_DEVICE:
12448 case NL80211_IFTYPE_NAN:
12450 return -EOPNOTSUPP;
12453 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12455 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
12458 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
12460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12461 struct wireless_dev *wdev;
12462 struct net_device *dev = info->user_ptr[1];
12467 if (!info->attrs[NL80211_ATTR_PS_STATE])
12470 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
12472 wdev = dev->ieee80211_ptr;
12474 if (!rdev->ops->set_power_mgmt)
12475 return -EOPNOTSUPP;
12477 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
12479 if (state == wdev->ps)
12482 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
12488 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
12490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12491 enum nl80211_ps_state ps_state;
12492 struct wireless_dev *wdev;
12493 struct net_device *dev = info->user_ptr[1];
12494 struct sk_buff *msg;
12498 wdev = dev->ieee80211_ptr;
12500 if (!rdev->ops->set_power_mgmt)
12501 return -EOPNOTSUPP;
12503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12507 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12508 NL80211_CMD_GET_POWER_SAVE);
12515 ps_state = NL80211_PS_ENABLED;
12517 ps_state = NL80211_PS_DISABLED;
12519 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
12520 goto nla_put_failure;
12522 genlmsg_end(msg, hdr);
12523 return genlmsg_reply(msg, info);
12532 static const struct nla_policy
12533 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
12534 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
12535 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
12536 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
12537 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
12538 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
12539 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
12540 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
12543 static int nl80211_set_cqm_txe(struct genl_info *info,
12544 u32 rate, u32 pkts, u32 intvl)
12546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12547 struct net_device *dev = info->user_ptr[1];
12548 struct wireless_dev *wdev = dev->ieee80211_ptr;
12550 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
12553 if (!rdev->ops->set_cqm_txe_config)
12554 return -EOPNOTSUPP;
12556 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12557 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12558 return -EOPNOTSUPP;
12560 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
12563 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
12564 struct net_device *dev)
12566 struct wireless_dev *wdev = dev->ieee80211_ptr;
12567 s32 last, low, high;
12569 int i, n, low_index;
12572 /* RSSI reporting disabled? */
12573 if (!wdev->cqm_config)
12574 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
12577 * Obtain current RSSI value if possible, if not and no RSSI threshold
12578 * event has been received yet, we should receive an event after a
12579 * connection is established and enough beacons received to calculate
12582 if (!wdev->cqm_config->last_rssi_event_value &&
12583 wdev->links[0].client.current_bss &&
12584 rdev->ops->get_station) {
12585 struct station_info sinfo = {};
12588 mac_addr = wdev->links[0].client.current_bss->pub.bssid;
12590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
12594 cfg80211_sinfo_release_content(&sinfo);
12595 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
12596 wdev->cqm_config->last_rssi_event_value =
12597 (s8) sinfo.rx_beacon_signal_avg;
12600 last = wdev->cqm_config->last_rssi_event_value;
12601 hyst = wdev->cqm_config->rssi_hyst;
12602 n = wdev->cqm_config->n_rssi_thresholds;
12604 for (i = 0; i < n; i++) {
12605 i = array_index_nospec(i, n);
12606 if (last < wdev->cqm_config->rssi_thresholds[i])
12611 if (low_index >= 0) {
12612 low_index = array_index_nospec(low_index, n);
12613 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
12618 i = array_index_nospec(i, n);
12619 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
12624 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
12627 static int nl80211_set_cqm_rssi(struct genl_info *info,
12628 const s32 *thresholds, int n_thresholds,
12631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12632 struct net_device *dev = info->user_ptr[1];
12633 struct wireless_dev *wdev = dev->ieee80211_ptr;
12635 s32 prev = S32_MIN;
12637 /* Check all values negative and sorted */
12638 for (i = 0; i < n_thresholds; i++) {
12639 if (thresholds[i] > 0 || thresholds[i] <= prev)
12642 prev = thresholds[i];
12645 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12646 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12647 return -EOPNOTSUPP;
12650 cfg80211_cqm_config_free(wdev);
12653 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
12654 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
12655 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
12657 return rdev_set_cqm_rssi_config(rdev, dev,
12658 thresholds[0], hysteresis);
12661 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12662 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
12663 return -EOPNOTSUPP;
12665 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
12669 if (n_thresholds) {
12670 struct cfg80211_cqm_config *cqm_config;
12672 cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds,
12680 cqm_config->rssi_hyst = hysteresis;
12681 cqm_config->n_rssi_thresholds = n_thresholds;
12682 memcpy(cqm_config->rssi_thresholds, thresholds,
12683 flex_array_size(cqm_config, rssi_thresholds,
12686 wdev->cqm_config = cqm_config;
12689 err = cfg80211_cqm_rssi_update(rdev, dev);
12697 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
12699 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
12700 struct nlattr *cqm;
12703 cqm = info->attrs[NL80211_ATTR_CQM];
12707 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
12708 nl80211_attr_cqm_policy,
12713 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
12714 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
12715 const s32 *thresholds =
12716 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
12717 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
12718 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
12723 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
12727 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
12728 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
12729 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
12730 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
12731 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
12732 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
12734 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
12740 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
12742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12743 struct net_device *dev = info->user_ptr[1];
12744 struct ocb_setup setup = {};
12747 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
12751 return cfg80211_join_ocb(rdev, dev, &setup);
12754 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
12756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12757 struct net_device *dev = info->user_ptr[1];
12759 return cfg80211_leave_ocb(rdev, dev);
12762 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
12764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12765 struct net_device *dev = info->user_ptr[1];
12766 struct mesh_config cfg;
12767 struct mesh_setup setup;
12770 /* start with default */
12771 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
12772 memcpy(&setup, &default_mesh_setup, sizeof(setup));
12774 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
12775 /* and parse parameters if given */
12776 err = nl80211_parse_mesh_config(info, &cfg, NULL);
12781 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
12782 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
12785 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
12786 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
12788 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
12789 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
12790 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
12793 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
12794 setup.beacon_interval =
12795 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
12797 err = cfg80211_validate_beacon_int(rdev,
12798 NL80211_IFTYPE_MESH_POINT,
12799 setup.beacon_interval);
12804 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
12805 setup.dtim_period =
12806 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
12807 if (setup.dtim_period < 1 || setup.dtim_period > 100)
12811 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
12812 /* parse additional setup parameters if given */
12813 err = nl80211_parse_mesh_setup(info, &setup);
12818 if (setup.user_mpm)
12819 cfg.auto_open_plinks = false;
12821 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
12822 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
12826 /* __cfg80211_join_mesh() will sort it out */
12827 setup.chandef.chan = NULL;
12830 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
12831 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
12833 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
12834 struct ieee80211_supported_band *sband;
12836 if (!setup.chandef.chan)
12839 sband = rdev->wiphy.bands[setup.chandef.chan->band];
12841 err = ieee80211_get_ratemask(sband, rates, n_rates,
12842 &setup.basic_rates);
12847 if (info->attrs[NL80211_ATTR_TX_RATES]) {
12848 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
12849 NL80211_ATTR_TX_RATES,
12850 &setup.beacon_rate,
12855 if (!setup.chandef.chan)
12858 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
12859 &setup.beacon_rate);
12864 setup.userspace_handles_dfs =
12865 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
12867 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
12868 int r = validate_pae_over_nl80211(rdev, info);
12873 setup.control_port_over_nl80211 = true;
12876 wdev_lock(dev->ieee80211_ptr);
12877 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
12878 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
12879 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
12880 wdev_unlock(dev->ieee80211_ptr);
12885 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
12887 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12888 struct net_device *dev = info->user_ptr[1];
12890 return cfg80211_leave_mesh(rdev, dev);
12894 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
12895 struct cfg80211_registered_device *rdev)
12897 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
12898 struct nlattr *nl_pats, *nl_pat;
12901 if (!wowlan->n_patterns)
12904 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
12908 for (i = 0; i < wowlan->n_patterns; i++) {
12909 nl_pat = nla_nest_start_noflag(msg, i + 1);
12912 pat_len = wowlan->patterns[i].pattern_len;
12913 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
12914 wowlan->patterns[i].mask) ||
12915 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
12916 wowlan->patterns[i].pattern) ||
12917 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
12918 wowlan->patterns[i].pkt_offset))
12920 nla_nest_end(msg, nl_pat);
12922 nla_nest_end(msg, nl_pats);
12927 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
12928 struct cfg80211_wowlan_tcp *tcp)
12930 struct nlattr *nl_tcp;
12935 nl_tcp = nla_nest_start_noflag(msg,
12936 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
12940 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
12941 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
12942 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
12943 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
12944 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
12945 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
12946 tcp->payload_len, tcp->payload) ||
12947 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
12948 tcp->data_interval) ||
12949 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
12950 tcp->wake_len, tcp->wake_data) ||
12951 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
12952 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
12955 if (tcp->payload_seq.len &&
12956 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
12957 sizeof(tcp->payload_seq), &tcp->payload_seq))
12960 if (tcp->payload_tok.len &&
12961 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
12962 sizeof(tcp->payload_tok) + tcp->tokens_size,
12963 &tcp->payload_tok))
12966 nla_nest_end(msg, nl_tcp);
12971 static int nl80211_send_wowlan_nd(struct sk_buff *msg,
12972 struct cfg80211_sched_scan_request *req)
12974 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
12980 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
12984 if (req->n_scan_plans == 1 &&
12985 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
12986 req->scan_plans[0].interval * 1000))
12989 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
12992 if (req->relative_rssi_set) {
12993 struct nl80211_bss_select_rssi_adjust rssi_adjust;
12995 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
12996 req->relative_rssi))
12999 rssi_adjust.band = req->rssi_adjust.band;
13000 rssi_adjust.delta = req->rssi_adjust.delta;
13001 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
13002 sizeof(rssi_adjust), &rssi_adjust))
13006 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13010 for (i = 0; i < req->n_channels; i++) {
13011 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13015 nla_nest_end(msg, freqs);
13017 if (req->n_match_sets) {
13018 matches = nla_nest_start_noflag(msg,
13019 NL80211_ATTR_SCHED_SCAN_MATCH);
13023 for (i = 0; i < req->n_match_sets; i++) {
13024 match = nla_nest_start_noflag(msg, i);
13028 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
13029 req->match_sets[i].ssid.ssid_len,
13030 req->match_sets[i].ssid.ssid))
13032 nla_nest_end(msg, match);
13034 nla_nest_end(msg, matches);
13037 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
13041 for (i = 0; i < req->n_scan_plans; i++) {
13042 scan_plan = nla_nest_start_noflag(msg, i + 1);
13046 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
13047 req->scan_plans[i].interval) ||
13048 (req->scan_plans[i].iterations &&
13049 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
13050 req->scan_plans[i].iterations)))
13052 nla_nest_end(msg, scan_plan);
13054 nla_nest_end(msg, scan_plans);
13056 nla_nest_end(msg, nd);
13061 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
13063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13064 struct sk_buff *msg;
13066 u32 size = NLMSG_DEFAULT_SIZE;
13068 if (!rdev->wiphy.wowlan)
13069 return -EOPNOTSUPP;
13071 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
13072 /* adjust size to have room for all the data */
13073 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
13074 rdev->wiphy.wowlan_config->tcp->payload_len +
13075 rdev->wiphy.wowlan_config->tcp->wake_len +
13076 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
13079 msg = nlmsg_new(size, GFP_KERNEL);
13083 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13084 NL80211_CMD_GET_WOWLAN);
13086 goto nla_put_failure;
13088 if (rdev->wiphy.wowlan_config) {
13089 struct nlattr *nl_wowlan;
13091 nl_wowlan = nla_nest_start_noflag(msg,
13092 NL80211_ATTR_WOWLAN_TRIGGERS);
13094 goto nla_put_failure;
13096 if ((rdev->wiphy.wowlan_config->any &&
13097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
13098 (rdev->wiphy.wowlan_config->disconnect &&
13099 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
13100 (rdev->wiphy.wowlan_config->magic_pkt &&
13101 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
13102 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
13103 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
13104 (rdev->wiphy.wowlan_config->eap_identity_req &&
13105 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
13106 (rdev->wiphy.wowlan_config->four_way_handshake &&
13107 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
13108 (rdev->wiphy.wowlan_config->rfkill_release &&
13109 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
13110 goto nla_put_failure;
13112 if (nl80211_send_wowlan_patterns(msg, rdev))
13113 goto nla_put_failure;
13115 if (nl80211_send_wowlan_tcp(msg,
13116 rdev->wiphy.wowlan_config->tcp))
13117 goto nla_put_failure;
13119 if (nl80211_send_wowlan_nd(
13121 rdev->wiphy.wowlan_config->nd_config))
13122 goto nla_put_failure;
13124 nla_nest_end(msg, nl_wowlan);
13127 genlmsg_end(msg, hdr);
13128 return genlmsg_reply(msg, info);
13135 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
13136 struct nlattr *attr,
13137 struct cfg80211_wowlan *trig)
13139 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
13140 struct cfg80211_wowlan_tcp *cfg;
13141 struct nl80211_wowlan_tcp_data_token *tok = NULL;
13142 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
13144 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
13147 if (!rdev->wiphy.wowlan->tcp)
13150 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
13151 nl80211_wowlan_tcp_policy, NULL);
13155 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
13156 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
13157 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
13158 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
13159 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
13160 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
13161 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
13162 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
13165 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
13166 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
13169 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
13170 rdev->wiphy.wowlan->tcp->data_interval_max ||
13171 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
13174 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
13175 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
13178 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
13179 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
13182 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
13183 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
13185 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
13186 tokens_size = tokln - sizeof(*tok);
13188 if (!tok->len || tokens_size % tok->len)
13190 if (!rdev->wiphy.wowlan->tcp->tok)
13192 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
13194 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
13196 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
13198 if (tok->offset + tok->len > data_size)
13202 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
13203 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
13204 if (!rdev->wiphy.wowlan->tcp->seq)
13206 if (seq->len == 0 || seq->len > 4)
13208 if (seq->len + seq->offset > data_size)
13212 size = sizeof(*cfg);
13214 size += wake_size + wake_mask_size;
13215 size += tokens_size;
13217 cfg = kzalloc(size, GFP_KERNEL);
13220 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
13221 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
13222 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
13224 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
13225 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
13229 /* allocate a socket and port for it and use it */
13230 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
13231 IPPROTO_TCP, &cfg->sock, 1);
13236 if (inet_csk_get_port(cfg->sock->sk, port)) {
13237 sock_release(cfg->sock);
13239 return -EADDRINUSE;
13241 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
13247 cfg->src_port = port;
13250 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
13251 cfg->payload_len = data_size;
13252 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
13253 memcpy((void *)cfg->payload,
13254 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
13257 cfg->payload_seq = *seq;
13258 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
13259 cfg->wake_len = wake_size;
13260 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
13261 memcpy((void *)cfg->wake_data,
13262 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
13264 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
13265 data_size + wake_size;
13266 memcpy((void *)cfg->wake_mask,
13267 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
13270 cfg->tokens_size = tokens_size;
13271 cfg->payload_tok = *tok;
13272 memcpy(cfg->payload_tok.token_stream, tok->token_stream,
13281 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
13282 const struct wiphy_wowlan_support *wowlan,
13283 struct nlattr *attr,
13284 struct cfg80211_wowlan *trig)
13286 struct nlattr **tb;
13289 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
13293 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
13298 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
13299 nl80211_policy, NULL);
13303 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
13304 wowlan->max_nd_match_sets);
13305 err = PTR_ERR_OR_ZERO(trig->nd_config);
13307 trig->nd_config = NULL;
13314 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
13316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13317 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
13318 struct cfg80211_wowlan new_triggers = {};
13319 struct cfg80211_wowlan *ntrig;
13320 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
13322 bool prev_enabled = rdev->wiphy.wowlan_config;
13323 bool regular = false;
13326 return -EOPNOTSUPP;
13328 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
13329 cfg80211_rdev_free_wowlan(rdev);
13330 rdev->wiphy.wowlan_config = NULL;
13334 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
13335 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
13336 nl80211_wowlan_policy, info->extack);
13340 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
13341 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
13343 new_triggers.any = true;
13346 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
13347 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
13349 new_triggers.disconnect = true;
13353 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
13354 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
13356 new_triggers.magic_pkt = true;
13360 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
13363 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
13364 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
13366 new_triggers.gtk_rekey_failure = true;
13370 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
13371 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
13373 new_triggers.eap_identity_req = true;
13377 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
13378 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
13380 new_triggers.four_way_handshake = true;
13384 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
13385 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
13387 new_triggers.rfkill_release = true;
13391 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
13392 struct nlattr *pat;
13393 int n_patterns = 0;
13394 int rem, pat_len, mask_len, pkt_offset;
13395 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
13399 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
13402 if (n_patterns > wowlan->n_patterns)
13405 new_triggers.patterns = kcalloc(n_patterns,
13406 sizeof(new_triggers.patterns[0]),
13408 if (!new_triggers.patterns)
13411 new_triggers.n_patterns = n_patterns;
13414 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
13418 err = nla_parse_nested_deprecated(pat_tb,
13419 MAX_NL80211_PKTPAT,
13421 nl80211_packet_pattern_policy,
13427 if (!pat_tb[NL80211_PKTPAT_MASK] ||
13428 !pat_tb[NL80211_PKTPAT_PATTERN])
13430 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
13431 mask_len = DIV_ROUND_UP(pat_len, 8);
13432 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
13434 if (pat_len > wowlan->pattern_max_len ||
13435 pat_len < wowlan->pattern_min_len)
13438 if (!pat_tb[NL80211_PKTPAT_OFFSET])
13441 pkt_offset = nla_get_u32(
13442 pat_tb[NL80211_PKTPAT_OFFSET]);
13443 if (pkt_offset > wowlan->max_pkt_offset)
13445 new_triggers.patterns[i].pkt_offset = pkt_offset;
13447 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
13452 new_triggers.patterns[i].mask = mask_pat;
13453 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
13455 mask_pat += mask_len;
13456 new_triggers.patterns[i].pattern = mask_pat;
13457 new_triggers.patterns[i].pattern_len = pat_len;
13459 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
13465 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
13467 err = nl80211_parse_wowlan_tcp(
13468 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
13474 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
13476 err = nl80211_parse_wowlan_nd(
13477 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
13483 /* The 'any' trigger means the device continues operating more or less
13484 * as in its normal operation mode and wakes up the host on most of the
13485 * normal interrupts (like packet RX, ...)
13486 * It therefore makes little sense to combine with the more constrained
13487 * wakeup trigger modes.
13489 if (new_triggers.any && regular) {
13494 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
13499 cfg80211_rdev_free_wowlan(rdev);
13500 rdev->wiphy.wowlan_config = ntrig;
13503 if (rdev->ops->set_wakeup &&
13504 prev_enabled != !!rdev->wiphy.wowlan_config)
13505 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
13509 for (i = 0; i < new_triggers.n_patterns; i++)
13510 kfree(new_triggers.patterns[i].mask);
13511 kfree(new_triggers.patterns);
13512 if (new_triggers.tcp && new_triggers.tcp->sock)
13513 sock_release(new_triggers.tcp->sock);
13514 kfree(new_triggers.tcp);
13515 kfree(new_triggers.nd_config);
13520 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
13521 struct cfg80211_registered_device *rdev)
13523 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
13525 struct cfg80211_coalesce_rules *rule;
13527 if (!rdev->coalesce->n_rules)
13530 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
13534 for (i = 0; i < rdev->coalesce->n_rules; i++) {
13535 nl_rule = nla_nest_start_noflag(msg, i + 1);
13539 rule = &rdev->coalesce->rules[i];
13540 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
13544 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
13548 nl_pats = nla_nest_start_noflag(msg,
13549 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
13553 for (j = 0; j < rule->n_patterns; j++) {
13554 nl_pat = nla_nest_start_noflag(msg, j + 1);
13557 pat_len = rule->patterns[j].pattern_len;
13558 if (nla_put(msg, NL80211_PKTPAT_MASK,
13559 DIV_ROUND_UP(pat_len, 8),
13560 rule->patterns[j].mask) ||
13561 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
13562 rule->patterns[j].pattern) ||
13563 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
13564 rule->patterns[j].pkt_offset))
13566 nla_nest_end(msg, nl_pat);
13568 nla_nest_end(msg, nl_pats);
13569 nla_nest_end(msg, nl_rule);
13571 nla_nest_end(msg, nl_rules);
13576 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
13578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13579 struct sk_buff *msg;
13582 if (!rdev->wiphy.coalesce)
13583 return -EOPNOTSUPP;
13585 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13589 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13590 NL80211_CMD_GET_COALESCE);
13592 goto nla_put_failure;
13594 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
13595 goto nla_put_failure;
13597 genlmsg_end(msg, hdr);
13598 return genlmsg_reply(msg, info);
13605 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
13607 struct cfg80211_coalesce *coalesce = rdev->coalesce;
13609 struct cfg80211_coalesce_rules *rule;
13614 for (i = 0; i < coalesce->n_rules; i++) {
13615 rule = &coalesce->rules[i];
13616 for (j = 0; j < rule->n_patterns; j++)
13617 kfree(rule->patterns[j].mask);
13618 kfree(rule->patterns);
13620 kfree(coalesce->rules);
13622 rdev->coalesce = NULL;
13625 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
13626 struct nlattr *rule,
13627 struct cfg80211_coalesce_rules *new_rule)
13630 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
13631 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
13632 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
13633 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
13635 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
13636 rule, nl80211_coalesce_policy, NULL);
13640 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
13642 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
13643 if (new_rule->delay > coalesce->max_delay)
13646 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
13647 new_rule->condition =
13648 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
13650 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
13653 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
13656 if (n_patterns > coalesce->n_patterns)
13659 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
13661 if (!new_rule->patterns)
13664 new_rule->n_patterns = n_patterns;
13667 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
13671 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
13673 nl80211_packet_pattern_policy,
13678 if (!pat_tb[NL80211_PKTPAT_MASK] ||
13679 !pat_tb[NL80211_PKTPAT_PATTERN])
13681 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
13682 mask_len = DIV_ROUND_UP(pat_len, 8);
13683 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
13685 if (pat_len > coalesce->pattern_max_len ||
13686 pat_len < coalesce->pattern_min_len)
13689 if (!pat_tb[NL80211_PKTPAT_OFFSET])
13692 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
13693 if (pkt_offset > coalesce->max_pkt_offset)
13695 new_rule->patterns[i].pkt_offset = pkt_offset;
13697 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
13701 new_rule->patterns[i].mask = mask_pat;
13702 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
13705 mask_pat += mask_len;
13706 new_rule->patterns[i].pattern = mask_pat;
13707 new_rule->patterns[i].pattern_len = pat_len;
13708 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
13716 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
13718 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13719 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
13720 struct cfg80211_coalesce new_coalesce = {};
13721 struct cfg80211_coalesce *n_coalesce;
13722 int err, rem_rule, n_rules = 0, i, j;
13723 struct nlattr *rule;
13724 struct cfg80211_coalesce_rules *tmp_rule;
13726 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
13727 return -EOPNOTSUPP;
13729 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
13730 cfg80211_rdev_free_coalesce(rdev);
13731 rdev_set_coalesce(rdev, NULL);
13735 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
13738 if (n_rules > coalesce->n_rules)
13741 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
13743 if (!new_coalesce.rules)
13746 new_coalesce.n_rules = n_rules;
13749 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
13751 err = nl80211_parse_coalesce_rule(rdev, rule,
13752 &new_coalesce.rules[i]);
13759 err = rdev_set_coalesce(rdev, &new_coalesce);
13763 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
13768 cfg80211_rdev_free_coalesce(rdev);
13769 rdev->coalesce = n_coalesce;
13773 for (i = 0; i < new_coalesce.n_rules; i++) {
13774 tmp_rule = &new_coalesce.rules[i];
13775 for (j = 0; j < tmp_rule->n_patterns; j++)
13776 kfree(tmp_rule->patterns[j].mask);
13777 kfree(tmp_rule->patterns);
13779 kfree(new_coalesce.rules);
13784 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
13786 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13787 struct net_device *dev = info->user_ptr[1];
13788 struct wireless_dev *wdev = dev->ieee80211_ptr;
13789 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
13790 struct cfg80211_gtk_rekey_data rekey_data = {};
13793 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
13796 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
13797 info->attrs[NL80211_ATTR_REKEY_DATA],
13798 nl80211_rekey_policy, info->extack);
13802 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
13803 !tb[NL80211_REKEY_DATA_KCK])
13805 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN &&
13806 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
13807 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN))
13809 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN &&
13810 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
13811 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN))
13814 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
13815 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
13816 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
13817 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
13818 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]);
13819 if (tb[NL80211_REKEY_DATA_AKM])
13820 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]);
13823 if (!wdev->connected) {
13828 if (!rdev->ops->set_rekey_data) {
13833 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
13839 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
13840 struct genl_info *info)
13842 struct net_device *dev = info->user_ptr[1];
13843 struct wireless_dev *wdev = dev->ieee80211_ptr;
13845 if (wdev->iftype != NL80211_IFTYPE_AP &&
13846 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13849 if (wdev->ap_unexpected_nlportid)
13852 wdev->ap_unexpected_nlportid = info->snd_portid;
13856 static int nl80211_probe_client(struct sk_buff *skb,
13857 struct genl_info *info)
13859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13860 struct net_device *dev = info->user_ptr[1];
13861 struct wireless_dev *wdev = dev->ieee80211_ptr;
13862 struct sk_buff *msg;
13868 if (wdev->iftype != NL80211_IFTYPE_AP &&
13869 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13870 return -EOPNOTSUPP;
13872 if (!info->attrs[NL80211_ATTR_MAC])
13875 if (!rdev->ops->probe_client)
13876 return -EOPNOTSUPP;
13878 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13882 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13883 NL80211_CMD_PROBE_CLIENT);
13889 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13891 err = rdev_probe_client(rdev, dev, addr, &cookie);
13895 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13897 goto nla_put_failure;
13899 genlmsg_end(msg, hdr);
13901 return genlmsg_reply(msg, info);
13910 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
13912 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13913 struct cfg80211_beacon_registration *reg, *nreg;
13916 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
13917 return -EOPNOTSUPP;
13919 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
13923 /* First, check if already registered. */
13924 spin_lock_bh(&rdev->beacon_registrations_lock);
13925 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13926 if (reg->nlportid == info->snd_portid) {
13931 /* Add it to the list */
13932 nreg->nlportid = info->snd_portid;
13933 list_add(&nreg->list, &rdev->beacon_registrations);
13935 spin_unlock_bh(&rdev->beacon_registrations_lock);
13939 spin_unlock_bh(&rdev->beacon_registrations_lock);
13944 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
13946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13947 struct wireless_dev *wdev = info->user_ptr[1];
13950 if (!rdev->ops->start_p2p_device)
13951 return -EOPNOTSUPP;
13953 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
13954 return -EOPNOTSUPP;
13956 if (wdev_running(wdev))
13959 if (rfkill_blocked(rdev->wiphy.rfkill))
13962 err = rdev_start_p2p_device(rdev, wdev);
13966 wdev->is_running = true;
13972 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
13974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13975 struct wireless_dev *wdev = info->user_ptr[1];
13977 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
13978 return -EOPNOTSUPP;
13980 if (!rdev->ops->stop_p2p_device)
13981 return -EOPNOTSUPP;
13983 cfg80211_stop_p2p_device(rdev, wdev);
13988 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
13990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13991 struct wireless_dev *wdev = info->user_ptr[1];
13992 struct cfg80211_nan_conf conf = {};
13995 if (wdev->iftype != NL80211_IFTYPE_NAN)
13996 return -EOPNOTSUPP;
13998 if (wdev_running(wdev))
14001 if (rfkill_blocked(rdev->wiphy.rfkill))
14004 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
14008 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
14010 if (info->attrs[NL80211_ATTR_BANDS]) {
14011 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
14013 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
14014 return -EOPNOTSUPP;
14016 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
14019 conf.bands = bands;
14022 err = rdev_start_nan(rdev, wdev, &conf);
14026 wdev->is_running = true;
14032 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
14034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14035 struct wireless_dev *wdev = info->user_ptr[1];
14037 if (wdev->iftype != NL80211_IFTYPE_NAN)
14038 return -EOPNOTSUPP;
14040 cfg80211_stop_nan(rdev, wdev);
14045 static int validate_nan_filter(struct nlattr *filter_attr)
14047 struct nlattr *attr;
14048 int len = 0, n_entries = 0, rem;
14050 nla_for_each_nested(attr, filter_attr, rem) {
14051 len += nla_len(attr);
14061 static int handle_nan_filter(struct nlattr *attr_filter,
14062 struct cfg80211_nan_func *func,
14065 struct nlattr *attr;
14066 int n_entries, rem, i;
14067 struct cfg80211_nan_func_filter *filter;
14069 n_entries = validate_nan_filter(attr_filter);
14073 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
14075 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
14080 nla_for_each_nested(attr, attr_filter, rem) {
14081 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
14082 if (!filter[i].filter)
14085 filter[i].len = nla_len(attr);
14089 func->num_tx_filters = n_entries;
14090 func->tx_filters = filter;
14092 func->num_rx_filters = n_entries;
14093 func->rx_filters = filter;
14100 nla_for_each_nested(attr, attr_filter, rem) {
14101 kfree(filter[i].filter);
14108 static int nl80211_nan_add_func(struct sk_buff *skb,
14109 struct genl_info *info)
14111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14112 struct wireless_dev *wdev = info->user_ptr[1];
14113 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
14114 struct cfg80211_nan_func *func;
14115 struct sk_buff *msg = NULL;
14119 if (wdev->iftype != NL80211_IFTYPE_NAN)
14120 return -EOPNOTSUPP;
14122 if (!wdev_running(wdev))
14125 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
14128 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
14129 info->attrs[NL80211_ATTR_NAN_FUNC],
14130 nl80211_nan_func_policy,
14135 func = kzalloc(sizeof(*func), GFP_KERNEL);
14139 func->cookie = cfg80211_assign_cookie(rdev);
14141 if (!tb[NL80211_NAN_FUNC_TYPE]) {
14147 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
14149 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
14154 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
14155 sizeof(func->service_id));
14157 func->close_range =
14158 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
14160 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
14161 func->serv_spec_info_len =
14162 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
14163 func->serv_spec_info =
14164 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
14165 func->serv_spec_info_len,
14167 if (!func->serv_spec_info) {
14173 if (tb[NL80211_NAN_FUNC_TTL])
14174 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
14176 switch (func->type) {
14177 case NL80211_NAN_FUNC_PUBLISH:
14178 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
14183 func->publish_type =
14184 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
14185 func->publish_bcast =
14186 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
14188 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
14189 func->publish_bcast) {
14194 case NL80211_NAN_FUNC_SUBSCRIBE:
14195 func->subscribe_active =
14196 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
14198 case NL80211_NAN_FUNC_FOLLOW_UP:
14199 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
14200 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
14201 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
14206 func->followup_id =
14207 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
14208 func->followup_reqid =
14209 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
14210 memcpy(func->followup_dest.addr,
14211 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
14212 sizeof(func->followup_dest.addr));
14223 if (tb[NL80211_NAN_FUNC_SRF]) {
14224 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
14226 err = nla_parse_nested_deprecated(srf_tb,
14227 NL80211_NAN_SRF_ATTR_MAX,
14228 tb[NL80211_NAN_FUNC_SRF],
14229 nl80211_nan_srf_policy,
14234 func->srf_include =
14235 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
14237 if (srf_tb[NL80211_NAN_SRF_BF]) {
14238 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
14239 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
14245 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
14247 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
14248 func->srf_bf_len, GFP_KERNEL);
14249 if (!func->srf_bf) {
14255 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
14257 struct nlattr *attr, *mac_attr =
14258 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
14259 int n_entries, rem, i = 0;
14266 n_entries = validate_acl_mac_addrs(mac_attr);
14267 if (n_entries <= 0) {
14272 func->srf_num_macs = n_entries;
14274 kcalloc(n_entries, sizeof(*func->srf_macs),
14276 if (!func->srf_macs) {
14281 nla_for_each_nested(attr, mac_attr, rem)
14282 memcpy(func->srf_macs[i++].addr, nla_data(attr),
14283 sizeof(*func->srf_macs));
14287 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
14288 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
14294 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
14295 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
14301 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14307 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14308 NL80211_CMD_ADD_NAN_FUNCTION);
14309 /* This can't really happen - we just allocated 4KB */
14310 if (WARN_ON(!hdr)) {
14315 err = rdev_add_nan_func(rdev, wdev, func);
14318 cfg80211_free_nan_func(func);
14323 /* propagate the instance id and cookie to userspace */
14324 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
14326 goto nla_put_failure;
14328 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
14330 goto nla_put_failure;
14332 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
14333 func->instance_id))
14334 goto nla_put_failure;
14336 nla_nest_end(msg, func_attr);
14338 genlmsg_end(msg, hdr);
14339 return genlmsg_reply(msg, info);
14346 static int nl80211_nan_del_func(struct sk_buff *skb,
14347 struct genl_info *info)
14349 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14350 struct wireless_dev *wdev = info->user_ptr[1];
14353 if (wdev->iftype != NL80211_IFTYPE_NAN)
14354 return -EOPNOTSUPP;
14356 if (!wdev_running(wdev))
14359 if (!info->attrs[NL80211_ATTR_COOKIE])
14362 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
14364 rdev_del_nan_func(rdev, wdev, cookie);
14369 static int nl80211_nan_change_config(struct sk_buff *skb,
14370 struct genl_info *info)
14372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14373 struct wireless_dev *wdev = info->user_ptr[1];
14374 struct cfg80211_nan_conf conf = {};
14377 if (wdev->iftype != NL80211_IFTYPE_NAN)
14378 return -EOPNOTSUPP;
14380 if (!wdev_running(wdev))
14383 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
14385 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
14386 if (conf.master_pref <= 1 || conf.master_pref == 255)
14389 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
14392 if (info->attrs[NL80211_ATTR_BANDS]) {
14393 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
14395 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
14396 return -EOPNOTSUPP;
14398 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
14401 conf.bands = bands;
14402 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
14408 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
14411 void cfg80211_nan_match(struct wireless_dev *wdev,
14412 struct cfg80211_nan_match_params *match, gfp_t gfp)
14414 struct wiphy *wiphy = wdev->wiphy;
14415 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14416 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
14417 struct sk_buff *msg;
14420 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
14423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14427 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
14433 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14434 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14435 wdev->netdev->ifindex)) ||
14436 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14438 goto nla_put_failure;
14440 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
14441 NL80211_ATTR_PAD) ||
14442 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
14443 goto nla_put_failure;
14445 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
14447 goto nla_put_failure;
14449 local_func_attr = nla_nest_start_noflag(msg,
14450 NL80211_NAN_MATCH_FUNC_LOCAL);
14451 if (!local_func_attr)
14452 goto nla_put_failure;
14454 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
14455 goto nla_put_failure;
14457 nla_nest_end(msg, local_func_attr);
14459 peer_func_attr = nla_nest_start_noflag(msg,
14460 NL80211_NAN_MATCH_FUNC_PEER);
14461 if (!peer_func_attr)
14462 goto nla_put_failure;
14464 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
14465 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
14466 goto nla_put_failure;
14468 if (match->info && match->info_len &&
14469 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
14471 goto nla_put_failure;
14473 nla_nest_end(msg, peer_func_attr);
14474 nla_nest_end(msg, match_attr);
14475 genlmsg_end(msg, hdr);
14477 if (!wdev->owner_nlportid)
14478 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
14479 msg, 0, NL80211_MCGRP_NAN, gfp);
14481 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
14482 wdev->owner_nlportid);
14489 EXPORT_SYMBOL(cfg80211_nan_match);
14491 void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
14493 enum nl80211_nan_func_term_reason reason,
14494 u64 cookie, gfp_t gfp)
14496 struct wiphy *wiphy = wdev->wiphy;
14497 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14498 struct sk_buff *msg;
14499 struct nlattr *func_attr;
14502 if (WARN_ON(!inst_id))
14505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
14515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14516 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14517 wdev->netdev->ifindex)) ||
14518 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14520 goto nla_put_failure;
14522 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14524 goto nla_put_failure;
14526 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
14528 goto nla_put_failure;
14530 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
14531 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
14532 goto nla_put_failure;
14534 nla_nest_end(msg, func_attr);
14535 genlmsg_end(msg, hdr);
14537 if (!wdev->owner_nlportid)
14538 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
14539 msg, 0, NL80211_MCGRP_NAN, gfp);
14541 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
14542 wdev->owner_nlportid);
14549 EXPORT_SYMBOL(cfg80211_nan_func_terminated);
14551 static int nl80211_get_protocol_features(struct sk_buff *skb,
14552 struct genl_info *info)
14555 struct sk_buff *msg;
14557 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14561 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14562 NL80211_CMD_GET_PROTOCOL_FEATURES);
14564 goto nla_put_failure;
14566 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
14567 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
14568 goto nla_put_failure;
14570 genlmsg_end(msg, hdr);
14571 return genlmsg_reply(msg, info);
14578 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
14580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14581 struct cfg80211_update_ft_ies_params ft_params;
14582 struct net_device *dev = info->user_ptr[1];
14584 if (!rdev->ops->update_ft_ies)
14585 return -EOPNOTSUPP;
14587 if (!info->attrs[NL80211_ATTR_MDID] ||
14588 !info->attrs[NL80211_ATTR_IE])
14591 memset(&ft_params, 0, sizeof(ft_params));
14592 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
14593 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
14594 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
14596 return rdev_update_ft_ies(rdev, dev, &ft_params);
14599 static int nl80211_crit_protocol_start(struct sk_buff *skb,
14600 struct genl_info *info)
14602 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14603 struct wireless_dev *wdev = info->user_ptr[1];
14604 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
14608 if (!rdev->ops->crit_proto_start)
14609 return -EOPNOTSUPP;
14611 if (WARN_ON(!rdev->ops->crit_proto_stop))
14614 if (rdev->crit_proto_nlportid)
14617 /* determine protocol if provided */
14618 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
14619 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
14621 if (proto >= NUM_NL80211_CRIT_PROTO)
14624 /* timeout must be provided */
14625 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
14629 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
14631 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
14633 rdev->crit_proto_nlportid = info->snd_portid;
14638 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
14639 struct genl_info *info)
14641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14642 struct wireless_dev *wdev = info->user_ptr[1];
14644 if (!rdev->ops->crit_proto_stop)
14645 return -EOPNOTSUPP;
14647 if (rdev->crit_proto_nlportid) {
14648 rdev->crit_proto_nlportid = 0;
14649 rdev_crit_proto_stop(rdev, wdev);
14654 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
14655 struct nlattr *attr,
14656 struct netlink_ext_ack *extack)
14658 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
14659 if (attr->nla_type & NLA_F_NESTED) {
14660 NL_SET_ERR_MSG_ATTR(extack, attr,
14661 "unexpected nested data");
14668 if (!(attr->nla_type & NLA_F_NESTED)) {
14669 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
14673 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
14676 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
14678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14679 struct wireless_dev *wdev =
14680 __cfg80211_wdev_from_attrs(rdev, genl_info_net(info),
14685 if (!rdev->wiphy.vendor_commands)
14686 return -EOPNOTSUPP;
14688 if (IS_ERR(wdev)) {
14689 err = PTR_ERR(wdev);
14690 if (err != -EINVAL)
14693 } else if (wdev->wiphy != &rdev->wiphy) {
14697 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
14698 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
14701 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
14702 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
14703 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
14704 const struct wiphy_vendor_command *vcmd;
14708 vcmd = &rdev->wiphy.vendor_commands[i];
14710 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
14713 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
14714 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
14717 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
14721 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
14722 if (!wdev_running(wdev))
14730 return -EOPNOTSUPP;
14732 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
14733 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
14734 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
14736 err = nl80211_vendor_check_policy(vcmd,
14737 info->attrs[NL80211_ATTR_VENDOR_DATA],
14743 rdev->cur_cmd_info = info;
14744 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
14745 rdev->cur_cmd_info = NULL;
14749 return -EOPNOTSUPP;
14752 static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
14753 struct netlink_callback *cb,
14754 struct cfg80211_registered_device **rdev,
14755 struct wireless_dev **wdev)
14757 struct nlattr **attrbuf;
14763 unsigned int data_len = 0;
14766 /* subtract the 1 again here */
14767 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
14768 struct wireless_dev *tmp;
14772 *rdev = wiphy_to_rdev(wiphy);
14776 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
14777 if (tmp->identifier == cb->args[1] - 1) {
14784 /* keep rtnl locked in successful case */
14788 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
14792 err = nlmsg_parse_deprecated(cb->nlh,
14793 GENL_HDRLEN + nl80211_fam.hdrsize,
14794 attrbuf, nl80211_fam.maxattr,
14795 nl80211_policy, NULL);
14799 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
14800 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
14805 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf);
14809 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
14810 if (IS_ERR(*rdev)) {
14811 err = PTR_ERR(*rdev);
14815 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
14816 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
14818 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
14819 const struct wiphy_vendor_command *vcmd;
14821 vcmd = &(*rdev)->wiphy.vendor_commands[i];
14823 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
14826 if (!vcmd->dumpit) {
14835 if (vcmd_idx < 0) {
14840 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
14841 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
14842 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
14844 err = nl80211_vendor_check_policy(
14845 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
14846 attrbuf[NL80211_ATTR_VENDOR_DATA],
14852 /* 0 is the first index - add 1 to parse only once */
14853 cb->args[0] = (*rdev)->wiphy_idx + 1;
14854 /* add 1 to know if it was NULL */
14855 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
14856 cb->args[2] = vcmd_idx;
14857 cb->args[3] = (unsigned long)data;
14858 cb->args[4] = data_len;
14860 /* keep rtnl locked in successful case */
14867 static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
14868 struct netlink_callback *cb)
14870 struct cfg80211_registered_device *rdev;
14871 struct wireless_dev *wdev;
14872 unsigned int vcmd_idx;
14873 const struct wiphy_vendor_command *vcmd;
14877 struct nlattr *vendor_data;
14880 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
14884 vcmd_idx = cb->args[2];
14885 data = (void *)cb->args[3];
14886 data_len = cb->args[4];
14887 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
14889 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
14890 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
14895 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
14901 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
14902 if (!wdev_running(wdev)) {
14910 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
14911 cb->nlh->nlmsg_seq, NLM_F_MULTI,
14912 NL80211_CMD_VENDOR);
14916 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14917 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
14919 NL80211_ATTR_PAD))) {
14920 genlmsg_cancel(skb, hdr);
14924 vendor_data = nla_nest_start_noflag(skb,
14925 NL80211_ATTR_VENDOR_DATA);
14926 if (!vendor_data) {
14927 genlmsg_cancel(skb, hdr);
14931 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
14932 (unsigned long *)&cb->args[5]);
14933 nla_nest_end(skb, vendor_data);
14935 if (err == -ENOBUFS || err == -ENOENT) {
14936 genlmsg_cancel(skb, hdr);
14938 } else if (err <= 0) {
14939 genlmsg_cancel(skb, hdr);
14943 genlmsg_end(skb, hdr);
14952 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
14953 enum nl80211_commands cmd,
14954 enum nl80211_attrs attr,
14957 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14959 if (WARN_ON(!rdev->cur_cmd_info))
14962 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
14963 rdev->cur_cmd_info->snd_portid,
14964 rdev->cur_cmd_info->snd_seq,
14965 cmd, attr, NULL, GFP_KERNEL);
14967 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
14969 int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
14971 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
14972 void *hdr = ((void **)skb->cb)[1];
14973 struct nlattr *data = ((void **)skb->cb)[2];
14975 /* clear CB data for netlink core to own from now on */
14976 memset(skb->cb, 0, sizeof(skb->cb));
14978 if (WARN_ON(!rdev->cur_cmd_info)) {
14983 nla_nest_end(skb, data);
14984 genlmsg_end(skb, hdr);
14985 return genlmsg_reply(skb, rdev->cur_cmd_info);
14987 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
14989 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
14991 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14993 if (WARN_ON(!rdev->cur_cmd_info))
14996 return rdev->cur_cmd_info->snd_portid;
14998 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
15000 static int nl80211_set_qos_map(struct sk_buff *skb,
15001 struct genl_info *info)
15003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15004 struct cfg80211_qos_map *qos_map = NULL;
15005 struct net_device *dev = info->user_ptr[1];
15006 u8 *pos, len, num_des, des_len, des;
15009 if (!rdev->ops->set_qos_map)
15010 return -EOPNOTSUPP;
15012 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
15013 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
15014 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
15019 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
15023 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
15025 des_len = num_des *
15026 sizeof(struct cfg80211_dscp_exception);
15027 memcpy(qos_map->dscp_exception, pos, des_len);
15028 qos_map->num_des = num_des;
15029 for (des = 0; des < num_des; des++) {
15030 if (qos_map->dscp_exception[des].up > 7) {
15037 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
15040 wdev_lock(dev->ieee80211_ptr);
15041 ret = nl80211_key_allowed(dev->ieee80211_ptr);
15043 ret = rdev_set_qos_map(rdev, dev, qos_map);
15044 wdev_unlock(dev->ieee80211_ptr);
15050 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
15052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15053 struct net_device *dev = info->user_ptr[1];
15054 struct wireless_dev *wdev = dev->ieee80211_ptr;
15057 u16 admitted_time = 0;
15060 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
15061 return -EOPNOTSUPP;
15063 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
15064 !info->attrs[NL80211_ATTR_USER_PRIO])
15067 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
15068 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
15070 /* WMM uses TIDs 0-7 even for TSPEC */
15071 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
15072 /* TODO: handle 802.11 TSPEC/admission control
15073 * need more attributes for that (e.g. BA session requirement);
15074 * change the WMM adminssion test above to allow both then
15079 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15081 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
15083 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
15084 if (!admitted_time)
15089 switch (wdev->iftype) {
15090 case NL80211_IFTYPE_STATION:
15091 case NL80211_IFTYPE_P2P_CLIENT:
15092 if (wdev->connected)
15101 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
15108 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
15110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15111 struct net_device *dev = info->user_ptr[1];
15112 struct wireless_dev *wdev = dev->ieee80211_ptr;
15117 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
15120 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
15121 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15124 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
15130 static int nl80211_tdls_channel_switch(struct sk_buff *skb,
15131 struct genl_info *info)
15133 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15134 struct net_device *dev = info->user_ptr[1];
15135 struct wireless_dev *wdev = dev->ieee80211_ptr;
15136 struct cfg80211_chan_def chandef = {};
15141 if (!rdev->ops->tdls_channel_switch ||
15142 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
15143 return -EOPNOTSUPP;
15145 switch (dev->ieee80211_ptr->iftype) {
15146 case NL80211_IFTYPE_STATION:
15147 case NL80211_IFTYPE_P2P_CLIENT:
15150 return -EOPNOTSUPP;
15153 if (!info->attrs[NL80211_ATTR_MAC] ||
15154 !info->attrs[NL80211_ATTR_OPER_CLASS])
15157 err = nl80211_parse_chandef(rdev, info, &chandef);
15162 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
15163 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
15164 * specification is not defined for them.
15166 if (chandef.chan->band == NL80211_BAND_2GHZ &&
15167 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
15168 chandef.width != NL80211_CHAN_WIDTH_20)
15171 /* we will be active on the TDLS link */
15172 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
15176 /* don't allow switching to DFS channels */
15177 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
15180 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
15181 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
15184 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
15190 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
15191 struct genl_info *info)
15193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15194 struct net_device *dev = info->user_ptr[1];
15195 struct wireless_dev *wdev = dev->ieee80211_ptr;
15198 if (!rdev->ops->tdls_channel_switch ||
15199 !rdev->ops->tdls_cancel_channel_switch ||
15200 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
15201 return -EOPNOTSUPP;
15203 switch (dev->ieee80211_ptr->iftype) {
15204 case NL80211_IFTYPE_STATION:
15205 case NL80211_IFTYPE_P2P_CLIENT:
15208 return -EOPNOTSUPP;
15211 if (!info->attrs[NL80211_ATTR_MAC])
15214 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
15217 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
15223 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
15224 struct genl_info *info)
15226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15227 struct net_device *dev = info->user_ptr[1];
15228 struct wireless_dev *wdev = dev->ieee80211_ptr;
15229 const struct nlattr *nla;
15232 if (!rdev->ops->set_multicast_to_unicast)
15233 return -EOPNOTSUPP;
15235 if (wdev->iftype != NL80211_IFTYPE_AP &&
15236 wdev->iftype != NL80211_IFTYPE_P2P_GO)
15237 return -EOPNOTSUPP;
15239 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
15240 enabled = nla_get_flag(nla);
15242 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
15245 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
15247 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15248 struct net_device *dev = info->user_ptr[1];
15249 struct wireless_dev *wdev = dev->ieee80211_ptr;
15250 struct cfg80211_pmk_conf pmk_conf = {};
15253 if (wdev->iftype != NL80211_IFTYPE_STATION &&
15254 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
15255 return -EOPNOTSUPP;
15257 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15258 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
15259 return -EOPNOTSUPP;
15261 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
15265 if (!wdev->connected) {
15270 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
15271 if (memcmp(pmk_conf.aa, wdev->u.client.connected_addr, ETH_ALEN)) {
15276 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
15277 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
15278 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
15279 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
15284 if (info->attrs[NL80211_ATTR_PMKR0_NAME])
15285 pmk_conf.pmk_r0_name =
15286 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
15288 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
15294 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
15296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15297 struct net_device *dev = info->user_ptr[1];
15298 struct wireless_dev *wdev = dev->ieee80211_ptr;
15302 if (wdev->iftype != NL80211_IFTYPE_STATION &&
15303 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
15304 return -EOPNOTSUPP;
15306 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15307 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
15308 return -EOPNOTSUPP;
15310 if (!info->attrs[NL80211_ATTR_MAC])
15314 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
15315 ret = rdev_del_pmk(rdev, dev, aa);
15321 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
15323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15324 struct net_device *dev = info->user_ptr[1];
15325 struct cfg80211_external_auth_params params;
15327 if (!rdev->ops->external_auth)
15328 return -EOPNOTSUPP;
15330 if (!info->attrs[NL80211_ATTR_SSID] &&
15331 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
15332 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
15335 if (!info->attrs[NL80211_ATTR_BSSID])
15338 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
15341 memset(¶ms, 0, sizeof(params));
15343 if (info->attrs[NL80211_ATTR_SSID]) {
15344 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
15345 if (params.ssid.ssid_len == 0)
15347 memcpy(params.ssid.ssid,
15348 nla_data(info->attrs[NL80211_ATTR_SSID]),
15349 params.ssid.ssid_len);
15352 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
15355 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
15357 if (info->attrs[NL80211_ATTR_PMKID])
15358 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
15360 return rdev_external_auth(rdev, dev, ¶ms);
15363 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
15365 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
15366 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15367 struct net_device *dev = info->user_ptr[1];
15368 struct wireless_dev *wdev = dev->ieee80211_ptr;
15378 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15379 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
15380 return -EOPNOTSUPP;
15382 if (!rdev->ops->tx_control_port)
15383 return -EOPNOTSUPP;
15385 if (!info->attrs[NL80211_ATTR_FRAME] ||
15386 !info->attrs[NL80211_ATTR_MAC] ||
15387 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
15388 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
15394 switch (wdev->iftype) {
15395 case NL80211_IFTYPE_AP:
15396 case NL80211_IFTYPE_P2P_GO:
15397 case NL80211_IFTYPE_MESH_POINT:
15399 case NL80211_IFTYPE_ADHOC:
15400 if (wdev->u.ibss.current_bss)
15404 case NL80211_IFTYPE_STATION:
15405 case NL80211_IFTYPE_P2P_CLIENT:
15406 if (wdev->connected)
15417 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
15418 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
15419 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
15420 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
15422 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
15424 link_id = nl80211_link_id_or_invalid(info->attrs);
15426 err = rdev_tx_control_port(rdev, dev, buf, len,
15427 dest, cpu_to_be16(proto), noencrypt, link_id,
15428 dont_wait_for_ack ? NULL : &cookie);
15429 if (!err && !dont_wait_for_ack)
15430 nl_set_extack_cookie_u64(info->extack, cookie);
15437 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
15438 struct genl_info *info)
15440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15441 struct net_device *dev = info->user_ptr[1];
15442 struct wireless_dev *wdev = dev->ieee80211_ptr;
15443 struct cfg80211_ftm_responder_stats ftm_stats = {};
15444 unsigned int link_id = nl80211_link_id(info->attrs);
15445 struct sk_buff *msg;
15447 struct nlattr *ftm_stats_attr;
15450 if (wdev->iftype != NL80211_IFTYPE_AP ||
15451 !wdev->links[link_id].ap.beacon_interval)
15452 return -EOPNOTSUPP;
15454 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
15458 if (!ftm_stats.filled)
15461 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15465 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
15466 NL80211_CMD_GET_FTM_RESPONDER_STATS);
15468 goto nla_put_failure;
15470 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
15471 goto nla_put_failure;
15473 ftm_stats_attr = nla_nest_start_noflag(msg,
15474 NL80211_ATTR_FTM_RESPONDER_STATS);
15475 if (!ftm_stats_attr)
15476 goto nla_put_failure;
15478 #define SET_FTM(field, name, type) \
15479 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
15480 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
15481 ftm_stats.field)) \
15482 goto nla_put_failure; } while (0)
15483 #define SET_FTM_U64(field, name) \
15484 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
15485 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
15486 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
15487 goto nla_put_failure; } while (0)
15489 SET_FTM(success_num, SUCCESS_NUM, u32);
15490 SET_FTM(partial_num, PARTIAL_NUM, u32);
15491 SET_FTM(failed_num, FAILED_NUM, u32);
15492 SET_FTM(asap_num, ASAP_NUM, u32);
15493 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
15494 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
15495 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
15496 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
15497 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
15500 nla_nest_end(msg, ftm_stats_attr);
15502 genlmsg_end(msg, hdr);
15503 return genlmsg_reply(msg, info);
15510 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
15512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15513 struct cfg80211_update_owe_info owe_info;
15514 struct net_device *dev = info->user_ptr[1];
15516 if (!rdev->ops->update_owe_info)
15517 return -EOPNOTSUPP;
15519 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
15520 !info->attrs[NL80211_ATTR_MAC])
15523 memset(&owe_info, 0, sizeof(owe_info));
15524 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
15525 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
15527 if (info->attrs[NL80211_ATTR_IE]) {
15528 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
15529 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
15532 return rdev_update_owe_info(rdev, dev, &owe_info);
15535 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
15537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15538 struct net_device *dev = info->user_ptr[1];
15539 struct wireless_dev *wdev = dev->ieee80211_ptr;
15540 struct station_info sinfo = {};
15546 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
15547 return -EOPNOTSUPP;
15549 if (!info->attrs[NL80211_ATTR_MAC] ||
15550 !info->attrs[NL80211_ATTR_FRAME]) {
15551 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
15555 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
15556 return -EOPNOTSUPP;
15558 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
15559 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
15560 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
15562 if (len < sizeof(struct ethhdr))
15565 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
15566 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
15569 err = rdev_get_station(rdev, dev, dest, &sinfo);
15573 cfg80211_sinfo_release_content(&sinfo);
15575 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
15578 static int parse_tid_conf(struct cfg80211_registered_device *rdev,
15579 struct nlattr *attrs[], struct net_device *dev,
15580 struct cfg80211_tid_cfg *tid_conf,
15581 struct genl_info *info, const u8 *peer,
15582 unsigned int link_id)
15584 struct netlink_ext_ack *extack = info->extack;
15588 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS])
15591 tid_conf->config_override =
15592 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]);
15593 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
15595 if (tid_conf->config_override) {
15596 if (rdev->ops->reset_tid_config) {
15597 err = rdev_reset_tid_config(rdev, dev, peer,
15606 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
15607 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
15609 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
15612 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) {
15613 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT);
15614 tid_conf->retry_short =
15615 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]);
15617 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count)
15621 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) {
15622 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
15623 tid_conf->retry_long =
15624 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]);
15626 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count)
15630 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) {
15631 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
15633 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]);
15636 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) {
15637 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
15639 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]);
15642 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) {
15643 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL);
15645 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]);
15648 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) {
15649 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr;
15651 tid_conf->txrate_type = nla_get_u8(attrs[idx]);
15653 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) {
15654 attr = NL80211_TID_CONFIG_ATTR_TX_RATE;
15655 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr,
15656 &tid_conf->txrate_mask, dev,
15661 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE);
15663 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
15667 mask = rdev->wiphy.tid_config_support.peer;
15669 mask = rdev->wiphy.tid_config_support.vif;
15671 if (tid_conf->mask & ~mask) {
15672 NL_SET_ERR_MSG(extack, "unsupported TID configuration");
15679 static int nl80211_set_tid_config(struct sk_buff *skb,
15680 struct genl_info *info)
15682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15683 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1];
15684 unsigned int link_id = nl80211_link_id(info->attrs);
15685 struct net_device *dev = info->user_ptr[1];
15686 struct cfg80211_tid_config *tid_config;
15687 struct nlattr *tid;
15688 int conf_idx = 0, rem_conf;
15692 if (!info->attrs[NL80211_ATTR_TID_CONFIG])
15695 if (!rdev->ops->set_tid_config)
15696 return -EOPNOTSUPP;
15698 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
15702 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf),
15707 tid_config->n_tid_conf = num_conf;
15709 if (info->attrs[NL80211_ATTR_MAC])
15710 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
15712 wdev_lock(dev->ieee80211_ptr);
15714 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
15716 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX,
15722 ret = parse_tid_conf(rdev, attrs, dev,
15723 &tid_config->tid_conf[conf_idx],
15724 info, tid_config->peer, link_id);
15731 ret = rdev_set_tid_config(rdev, dev, tid_config);
15735 wdev_unlock(dev->ieee80211_ptr);
15739 static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info)
15741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15742 struct cfg80211_color_change_settings params = {};
15743 struct net_device *dev = info->user_ptr[1];
15744 struct wireless_dev *wdev = dev->ieee80211_ptr;
15745 struct nlattr **tb;
15749 if (!rdev->ops->color_change)
15750 return -EOPNOTSUPP;
15752 if (!wiphy_ext_feature_isset(&rdev->wiphy,
15753 NL80211_EXT_FEATURE_BSS_COLOR))
15754 return -EOPNOTSUPP;
15756 if (wdev->iftype != NL80211_IFTYPE_AP)
15757 return -EOPNOTSUPP;
15759 if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] ||
15760 !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] ||
15761 !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS])
15764 params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]);
15765 params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]);
15767 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next);
15771 tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL);
15775 err = nla_parse_nested(tb, NL80211_ATTR_MAX,
15776 info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS],
15777 nl80211_policy, info->extack);
15781 err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change);
15785 if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) {
15790 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) {
15795 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
15796 if (offset >= params.beacon_color_change.tail_len) {
15801 if (params.beacon_color_change.tail[offset] != params.count) {
15806 params.counter_offset_beacon = offset;
15808 if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
15809 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) !=
15815 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
15816 if (offset >= params.beacon_color_change.probe_resp_len) {
15821 if (params.beacon_color_change.probe_resp[offset] !=
15827 params.counter_offset_presp = offset;
15831 err = rdev_color_change(rdev, dev, ¶ms);
15835 kfree(params.beacon_next.mbssid_ies);
15836 kfree(params.beacon_color_change.mbssid_ies);
15841 static int nl80211_set_fils_aad(struct sk_buff *skb,
15842 struct genl_info *info)
15844 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15845 struct net_device *dev = info->user_ptr[1];
15846 struct cfg80211_fils_aad fils_aad = {};
15849 if (!info->attrs[NL80211_ATTR_MAC] ||
15850 !info->attrs[NL80211_ATTR_FILS_KEK] ||
15851 !info->attrs[NL80211_ATTR_FILS_NONCES])
15854 fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]);
15855 fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
15856 fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
15857 nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
15858 fils_aad.snonce = nonces;
15859 fils_aad.anonce = nonces + FILS_NONCE_LEN;
15861 return rdev_set_fils_aad(rdev, dev, &fils_aad);
15864 static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info)
15866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15867 unsigned int link_id = nl80211_link_id(info->attrs);
15868 struct net_device *dev = info->user_ptr[1];
15869 struct wireless_dev *wdev = dev->ieee80211_ptr;
15872 if (!(wdev->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
15875 switch (wdev->iftype) {
15876 case NL80211_IFTYPE_AP:
15882 if (!info->attrs[NL80211_ATTR_MAC] ||
15883 !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC])))
15887 wdev->valid_links |= BIT(link_id);
15888 ether_addr_copy(wdev->links[link_id].addr,
15889 nla_data(info->attrs[NL80211_ATTR_MAC]));
15891 ret = rdev_add_intf_link(rdev, wdev, link_id);
15893 wdev->valid_links &= ~BIT(link_id);
15894 eth_zero_addr(wdev->links[link_id].addr);
15901 static int nl80211_remove_link(struct sk_buff *skb, struct genl_info *info)
15903 unsigned int link_id = nl80211_link_id(info->attrs);
15904 struct net_device *dev = info->user_ptr[1];
15905 struct wireless_dev *wdev = dev->ieee80211_ptr;
15907 /* cannot remove if there's no link */
15908 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID])
15911 switch (wdev->iftype) {
15912 case NL80211_IFTYPE_AP:
15919 cfg80211_remove_link(wdev, link_id);
15926 nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info,
15929 struct link_station_parameters params = {};
15930 struct cfg80211_registered_device *rdev = info->user_ptr[0];
15931 struct net_device *dev = info->user_ptr[1];
15934 if ((add && !rdev->ops->add_link_station) ||
15935 (!add && !rdev->ops->mod_link_station))
15936 return -EOPNOTSUPP;
15938 if (add && !info->attrs[NL80211_ATTR_MAC])
15941 if (!info->attrs[NL80211_ATTR_MLD_ADDR])
15944 if (add && !info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
15947 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
15949 if (info->attrs[NL80211_ATTR_MAC]) {
15950 params.link_mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
15951 if (!is_valid_ether_addr(params.link_mac))
15955 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID])
15958 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]);
15960 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
15961 params.supported_rates =
15962 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
15963 params.supported_rates_len =
15964 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
15967 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
15969 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
15971 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
15973 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
15975 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
15977 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
15978 params.he_capa_len =
15979 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
15981 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) {
15983 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
15984 params.eht_capa_len =
15985 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]);
15987 if (!ieee80211_eht_capa_size_ok((const u8 *)params.he_capa,
15988 (const u8 *)params.eht_capa,
15989 params.eht_capa_len,
15995 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
15996 params.he_6ghz_capa =
15997 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
15999 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
16000 params.opmode_notif_used = true;
16001 params.opmode_notif =
16002 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
16005 err = nl80211_parse_sta_txpower_setting(info, ¶ms.txpwr,
16006 ¶ms.txpwr_set);
16010 wdev_lock(dev->ieee80211_ptr);
16012 err = rdev_add_link_station(rdev, dev, ¶ms);
16014 err = rdev_mod_link_station(rdev, dev, ¶ms);
16015 wdev_unlock(dev->ieee80211_ptr);
16021 nl80211_add_link_station(struct sk_buff *skb, struct genl_info *info)
16023 return nl80211_add_mod_link_station(skb, info, true);
16027 nl80211_modify_link_station(struct sk_buff *skb, struct genl_info *info)
16029 return nl80211_add_mod_link_station(skb, info, false);
16033 nl80211_remove_link_station(struct sk_buff *skb, struct genl_info *info)
16035 struct link_station_del_parameters params = {};
16036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16037 struct net_device *dev = info->user_ptr[1];
16040 if (!rdev->ops->del_link_station)
16041 return -EOPNOTSUPP;
16043 if (!info->attrs[NL80211_ATTR_MLD_ADDR] ||
16044 !info->attrs[NL80211_ATTR_MLO_LINK_ID])
16047 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]);
16048 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]);
16050 wdev_lock(dev->ieee80211_ptr);
16051 ret = rdev_del_link_station(rdev, dev, ¶ms);
16052 wdev_unlock(dev->ieee80211_ptr);
16057 #define NL80211_FLAG_NEED_WIPHY 0x01
16058 #define NL80211_FLAG_NEED_NETDEV 0x02
16059 #define NL80211_FLAG_NEED_RTNL 0x04
16060 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
16061 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
16062 NL80211_FLAG_CHECK_NETDEV_UP)
16063 #define NL80211_FLAG_NEED_WDEV 0x10
16064 /* If a netdev is associated, it must be UP, P2P must be started */
16065 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
16066 NL80211_FLAG_CHECK_NETDEV_UP)
16067 #define NL80211_FLAG_CLEAR_SKB 0x20
16068 #define NL80211_FLAG_NO_WIPHY_MTX 0x40
16069 #define NL80211_FLAG_MLO_VALID_LINK_ID 0x80
16070 #define NL80211_FLAG_MLO_UNSUPPORTED 0x100
16072 #define INTERNAL_FLAG_SELECTORS(__sel) \
16073 SELECTOR(__sel, NONE, 0) /* must be first */ \
16074 SELECTOR(__sel, WIPHY, \
16075 NL80211_FLAG_NEED_WIPHY) \
16076 SELECTOR(__sel, WDEV, \
16077 NL80211_FLAG_NEED_WDEV) \
16078 SELECTOR(__sel, NETDEV, \
16079 NL80211_FLAG_NEED_NETDEV) \
16080 SELECTOR(__sel, NETDEV_LINK, \
16081 NL80211_FLAG_NEED_NETDEV | \
16082 NL80211_FLAG_MLO_VALID_LINK_ID) \
16083 SELECTOR(__sel, NETDEV_NO_MLO, \
16084 NL80211_FLAG_NEED_NETDEV | \
16085 NL80211_FLAG_MLO_UNSUPPORTED) \
16086 SELECTOR(__sel, WIPHY_RTNL, \
16087 NL80211_FLAG_NEED_WIPHY | \
16088 NL80211_FLAG_NEED_RTNL) \
16089 SELECTOR(__sel, WIPHY_RTNL_NOMTX, \
16090 NL80211_FLAG_NEED_WIPHY | \
16091 NL80211_FLAG_NEED_RTNL | \
16092 NL80211_FLAG_NO_WIPHY_MTX) \
16093 SELECTOR(__sel, WDEV_RTNL, \
16094 NL80211_FLAG_NEED_WDEV | \
16095 NL80211_FLAG_NEED_RTNL) \
16096 SELECTOR(__sel, NETDEV_RTNL, \
16097 NL80211_FLAG_NEED_NETDEV | \
16098 NL80211_FLAG_NEED_RTNL) \
16099 SELECTOR(__sel, NETDEV_UP, \
16100 NL80211_FLAG_NEED_NETDEV_UP) \
16101 SELECTOR(__sel, NETDEV_UP_LINK, \
16102 NL80211_FLAG_NEED_NETDEV_UP | \
16103 NL80211_FLAG_MLO_VALID_LINK_ID) \
16104 SELECTOR(__sel, NETDEV_UP_NO_MLO, \
16105 NL80211_FLAG_NEED_NETDEV_UP | \
16106 NL80211_FLAG_MLO_UNSUPPORTED) \
16107 SELECTOR(__sel, NETDEV_UP_NO_MLO_CLEAR, \
16108 NL80211_FLAG_NEED_NETDEV_UP | \
16109 NL80211_FLAG_CLEAR_SKB | \
16110 NL80211_FLAG_MLO_UNSUPPORTED) \
16111 SELECTOR(__sel, NETDEV_UP_NOTMX, \
16112 NL80211_FLAG_NEED_NETDEV_UP | \
16113 NL80211_FLAG_NO_WIPHY_MTX) \
16114 SELECTOR(__sel, NETDEV_UP_NOTMX_NOMLO, \
16115 NL80211_FLAG_NEED_NETDEV_UP | \
16116 NL80211_FLAG_NO_WIPHY_MTX | \
16117 NL80211_FLAG_MLO_UNSUPPORTED) \
16118 SELECTOR(__sel, NETDEV_UP_CLEAR, \
16119 NL80211_FLAG_NEED_NETDEV_UP | \
16120 NL80211_FLAG_CLEAR_SKB) \
16121 SELECTOR(__sel, WDEV_UP, \
16122 NL80211_FLAG_NEED_WDEV_UP) \
16123 SELECTOR(__sel, WDEV_UP_LINK, \
16124 NL80211_FLAG_NEED_WDEV_UP | \
16125 NL80211_FLAG_MLO_VALID_LINK_ID) \
16126 SELECTOR(__sel, WDEV_UP_RTNL, \
16127 NL80211_FLAG_NEED_WDEV_UP | \
16128 NL80211_FLAG_NEED_RTNL) \
16129 SELECTOR(__sel, WIPHY_CLEAR, \
16130 NL80211_FLAG_NEED_WIPHY | \
16131 NL80211_FLAG_CLEAR_SKB)
16133 enum nl80211_internal_flags_selector {
16134 #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name,
16135 INTERNAL_FLAG_SELECTORS(_)
16139 static u32 nl80211_internal_flags[] = {
16140 #define SELECTOR(_, name, value) [NL80211_IFL_SEL_##name] = value,
16141 INTERNAL_FLAG_SELECTORS(_)
16145 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
16146 struct genl_info *info)
16148 struct cfg80211_registered_device *rdev = NULL;
16149 struct wireless_dev *wdev = NULL;
16150 struct net_device *dev = NULL;
16151 u32 internal_flags;
16154 if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags)))
16157 internal_flags = nl80211_internal_flags[ops->internal_flags];
16160 if (internal_flags & NL80211_FLAG_NEED_WIPHY) {
16161 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
16162 if (IS_ERR(rdev)) {
16163 err = PTR_ERR(rdev);
16166 info->user_ptr[0] = rdev;
16167 } else if (internal_flags & NL80211_FLAG_NEED_NETDEV ||
16168 internal_flags & NL80211_FLAG_NEED_WDEV) {
16169 wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info),
16171 if (IS_ERR(wdev)) {
16172 err = PTR_ERR(wdev);
16176 dev = wdev->netdev;
16178 rdev = wiphy_to_rdev(wdev->wiphy);
16180 if (internal_flags & NL80211_FLAG_NEED_NETDEV) {
16186 info->user_ptr[1] = dev;
16188 info->user_ptr[1] = wdev;
16191 if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
16192 !wdev_running(wdev)) {
16197 info->user_ptr[0] = rdev;
16200 if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) {
16201 struct nlattr *link_id = info->attrs[NL80211_ATTR_MLO_LINK_ID];
16208 /* MLO -> require valid link ID */
16209 if (wdev->valid_links &&
16211 !(wdev->valid_links & BIT(nla_get_u8(link_id))))) {
16216 /* non-MLO -> no link ID attribute accepted */
16217 if (!wdev->valid_links && link_id) {
16223 if (internal_flags & NL80211_FLAG_MLO_UNSUPPORTED) {
16224 if (info->attrs[NL80211_ATTR_MLO_LINK_ID] ||
16225 (wdev && wdev->valid_links)) {
16231 if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) {
16232 wiphy_lock(&rdev->wiphy);
16233 /* we keep the mutex locked until post_doit */
16234 __release(&rdev->wiphy.mtx);
16236 if (!(internal_flags & NL80211_FLAG_NEED_RTNL))
16246 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
16247 struct genl_info *info)
16249 u32 internal_flags = nl80211_internal_flags[ops->internal_flags];
16251 if (info->user_ptr[1]) {
16252 if (internal_flags & NL80211_FLAG_NEED_WDEV) {
16253 struct wireless_dev *wdev = info->user_ptr[1];
16255 dev_put(wdev->netdev);
16257 dev_put(info->user_ptr[1]);
16261 if (info->user_ptr[0] &&
16262 !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) {
16263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16265 /* we kept the mutex locked since pre_doit */
16266 __acquire(&rdev->wiphy.mtx);
16267 wiphy_unlock(&rdev->wiphy);
16270 if (internal_flags & NL80211_FLAG_NEED_RTNL)
16273 /* If needed, clear the netlink message payload from the SKB
16274 * as it might contain key data that shouldn't stick around on
16275 * the heap after the SKB is freed. The netlink message header
16276 * is still needed for further processing, so leave it intact.
16278 if (internal_flags & NL80211_FLAG_CLEAR_SKB) {
16279 struct nlmsghdr *nlh = nlmsg_hdr(skb);
16281 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
16285 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev,
16286 struct cfg80211_sar_specs *sar_specs,
16287 struct nlattr *spec[], int index)
16289 u32 range_index, i;
16291 if (!sar_specs || !spec)
16294 if (!spec[NL80211_SAR_ATTR_SPECS_POWER] ||
16295 !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX])
16298 range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]);
16300 /* check if range_index exceeds num_freq_ranges */
16301 if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges)
16304 /* check if range_index duplicates */
16305 for (i = 0; i < index; i++) {
16306 if (sar_specs->sub_specs[i].freq_range_index == range_index)
16310 sar_specs->sub_specs[index].power =
16311 nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]);
16313 sar_specs->sub_specs[index].freq_range_index = range_index;
16318 static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info)
16320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
16321 struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1];
16322 struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1];
16323 struct cfg80211_sar_specs *sar_spec;
16324 enum nl80211_sar_type type;
16325 struct nlattr *spec_list;
16329 if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs)
16330 return -EOPNOTSUPP;
16332 if (!info->attrs[NL80211_ATTR_SAR_SPEC])
16335 nla_parse_nested(tb, NL80211_SAR_ATTR_MAX,
16336 info->attrs[NL80211_ATTR_SAR_SPEC],
16339 if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS])
16342 type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]);
16343 if (type != rdev->wiphy.sar_capa->type)
16347 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem)
16350 if (specs > rdev->wiphy.sar_capa->num_freq_ranges)
16353 sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL);
16357 sar_spec->type = type;
16359 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) {
16360 nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX,
16361 spec_list, NULL, NULL);
16364 case NL80211_SAR_TYPE_POWER:
16365 if (nl80211_set_sar_sub_specs(rdev, sar_spec,
16378 sar_spec->num_sub_specs = specs;
16380 rdev->cur_cmd_info = info;
16381 err = rdev_set_sar_specs(rdev, sar_spec);
16382 rdev->cur_cmd_info = NULL;
16388 #define SELECTOR(__sel, name, value) \
16389 ((__sel) == (value)) ? NL80211_IFL_SEL_##name :
16390 int __missing_selector(void);
16391 #define IFLAGS(__val) INTERNAL_FLAG_SELECTORS(__val) __missing_selector()
16393 static const struct genl_ops nl80211_ops[] = {
16395 .cmd = NL80211_CMD_GET_WIPHY,
16396 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16397 .doit = nl80211_get_wiphy,
16398 .dumpit = nl80211_dump_wiphy,
16399 .done = nl80211_dump_wiphy_done,
16400 /* can be retrieved by unprivileged users */
16401 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16405 static const struct genl_small_ops nl80211_small_ops[] = {
16407 .cmd = NL80211_CMD_SET_WIPHY,
16408 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16409 .doit = nl80211_set_wiphy,
16410 .flags = GENL_UNS_ADMIN_PERM,
16413 .cmd = NL80211_CMD_GET_INTERFACE,
16414 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16415 .doit = nl80211_get_interface,
16416 .dumpit = nl80211_dump_interface,
16417 /* can be retrieved by unprivileged users */
16418 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV),
16421 .cmd = NL80211_CMD_SET_INTERFACE,
16422 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16423 .doit = nl80211_set_interface,
16424 .flags = GENL_UNS_ADMIN_PERM,
16425 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
16426 NL80211_FLAG_NEED_RTNL),
16429 .cmd = NL80211_CMD_NEW_INTERFACE,
16430 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16431 .doit = nl80211_new_interface,
16432 .flags = GENL_UNS_ADMIN_PERM,
16434 IFLAGS(NL80211_FLAG_NEED_WIPHY |
16435 NL80211_FLAG_NEED_RTNL |
16436 /* we take the wiphy mutex later ourselves */
16437 NL80211_FLAG_NO_WIPHY_MTX),
16440 .cmd = NL80211_CMD_DEL_INTERFACE,
16441 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16442 .doit = nl80211_del_interface,
16443 .flags = GENL_UNS_ADMIN_PERM,
16444 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
16445 NL80211_FLAG_NEED_RTNL),
16448 .cmd = NL80211_CMD_GET_KEY,
16449 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16450 .doit = nl80211_get_key,
16451 .flags = GENL_UNS_ADMIN_PERM,
16452 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16455 .cmd = NL80211_CMD_SET_KEY,
16456 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16457 .doit = nl80211_set_key,
16458 .flags = GENL_UNS_ADMIN_PERM,
16459 /* cannot use NL80211_FLAG_MLO_VALID_LINK_ID, depends on key */
16460 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16461 NL80211_FLAG_CLEAR_SKB),
16464 .cmd = NL80211_CMD_NEW_KEY,
16465 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16466 .doit = nl80211_new_key,
16467 .flags = GENL_UNS_ADMIN_PERM,
16468 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16469 NL80211_FLAG_CLEAR_SKB),
16472 .cmd = NL80211_CMD_DEL_KEY,
16473 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16474 .doit = nl80211_del_key,
16475 .flags = GENL_UNS_ADMIN_PERM,
16476 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16479 .cmd = NL80211_CMD_SET_BEACON,
16480 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16481 .flags = GENL_UNS_ADMIN_PERM,
16482 .doit = nl80211_set_beacon,
16483 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16484 NL80211_FLAG_MLO_VALID_LINK_ID),
16487 .cmd = NL80211_CMD_START_AP,
16488 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16489 .flags = GENL_UNS_ADMIN_PERM,
16490 .doit = nl80211_start_ap,
16491 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16492 NL80211_FLAG_MLO_VALID_LINK_ID),
16495 .cmd = NL80211_CMD_STOP_AP,
16496 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16497 .flags = GENL_UNS_ADMIN_PERM,
16498 .doit = nl80211_stop_ap,
16499 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16500 NL80211_FLAG_MLO_VALID_LINK_ID),
16503 .cmd = NL80211_CMD_GET_STATION,
16504 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16505 .doit = nl80211_get_station,
16506 .dumpit = nl80211_dump_station,
16507 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16510 .cmd = NL80211_CMD_SET_STATION,
16511 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16512 .doit = nl80211_set_station,
16513 .flags = GENL_UNS_ADMIN_PERM,
16514 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16517 .cmd = NL80211_CMD_NEW_STATION,
16518 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16519 .doit = nl80211_new_station,
16520 .flags = GENL_UNS_ADMIN_PERM,
16521 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16524 .cmd = NL80211_CMD_DEL_STATION,
16525 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16526 .doit = nl80211_del_station,
16527 .flags = GENL_UNS_ADMIN_PERM,
16528 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16531 .cmd = NL80211_CMD_GET_MPATH,
16532 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16533 .doit = nl80211_get_mpath,
16534 .dumpit = nl80211_dump_mpath,
16535 .flags = GENL_UNS_ADMIN_PERM,
16536 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16539 .cmd = NL80211_CMD_GET_MPP,
16540 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16541 .doit = nl80211_get_mpp,
16542 .dumpit = nl80211_dump_mpp,
16543 .flags = GENL_UNS_ADMIN_PERM,
16544 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16547 .cmd = NL80211_CMD_SET_MPATH,
16548 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16549 .doit = nl80211_set_mpath,
16550 .flags = GENL_UNS_ADMIN_PERM,
16551 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16554 .cmd = NL80211_CMD_NEW_MPATH,
16555 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16556 .doit = nl80211_new_mpath,
16557 .flags = GENL_UNS_ADMIN_PERM,
16558 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16561 .cmd = NL80211_CMD_DEL_MPATH,
16562 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16563 .doit = nl80211_del_mpath,
16564 .flags = GENL_UNS_ADMIN_PERM,
16565 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16568 .cmd = NL80211_CMD_SET_BSS,
16569 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16570 .doit = nl80211_set_bss,
16571 .flags = GENL_UNS_ADMIN_PERM,
16572 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16575 .cmd = NL80211_CMD_GET_REG,
16576 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16577 .doit = nl80211_get_reg_do,
16578 .dumpit = nl80211_get_reg_dump,
16579 /* can be retrieved by unprivileged users */
16581 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
16583 .cmd = NL80211_CMD_SET_REG,
16584 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16585 .doit = nl80211_set_reg,
16586 .flags = GENL_ADMIN_PERM,
16590 .cmd = NL80211_CMD_REQ_SET_REG,
16591 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16592 .doit = nl80211_req_set_reg,
16593 .flags = GENL_ADMIN_PERM,
16596 .cmd = NL80211_CMD_RELOAD_REGDB,
16597 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16598 .doit = nl80211_reload_regdb,
16599 .flags = GENL_ADMIN_PERM,
16602 .cmd = NL80211_CMD_GET_MESH_CONFIG,
16603 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16604 .doit = nl80211_get_mesh_config,
16605 /* can be retrieved by unprivileged users */
16606 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16609 .cmd = NL80211_CMD_SET_MESH_CONFIG,
16610 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16611 .doit = nl80211_update_mesh_config,
16612 .flags = GENL_UNS_ADMIN_PERM,
16613 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16616 .cmd = NL80211_CMD_TRIGGER_SCAN,
16617 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16618 .doit = nl80211_trigger_scan,
16619 .flags = GENL_UNS_ADMIN_PERM,
16620 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16623 .cmd = NL80211_CMD_ABORT_SCAN,
16624 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16625 .doit = nl80211_abort_scan,
16626 .flags = GENL_UNS_ADMIN_PERM,
16627 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16630 .cmd = NL80211_CMD_GET_SCAN,
16631 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16632 .dumpit = nl80211_dump_scan,
16635 .cmd = NL80211_CMD_START_SCHED_SCAN,
16636 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16637 .doit = nl80211_start_sched_scan,
16638 .flags = GENL_UNS_ADMIN_PERM,
16639 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16642 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
16643 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16644 .doit = nl80211_stop_sched_scan,
16645 .flags = GENL_UNS_ADMIN_PERM,
16646 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16649 .cmd = NL80211_CMD_AUTHENTICATE,
16650 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16651 .doit = nl80211_authenticate,
16652 .flags = GENL_UNS_ADMIN_PERM,
16653 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16654 NL80211_FLAG_CLEAR_SKB),
16657 .cmd = NL80211_CMD_ASSOCIATE,
16658 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16659 .doit = nl80211_associate,
16660 .flags = GENL_UNS_ADMIN_PERM,
16661 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16662 NL80211_FLAG_CLEAR_SKB),
16665 .cmd = NL80211_CMD_DEAUTHENTICATE,
16666 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16667 .doit = nl80211_deauthenticate,
16668 .flags = GENL_UNS_ADMIN_PERM,
16669 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16672 .cmd = NL80211_CMD_DISASSOCIATE,
16673 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16674 .doit = nl80211_disassociate,
16675 .flags = GENL_UNS_ADMIN_PERM,
16676 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16679 .cmd = NL80211_CMD_JOIN_IBSS,
16680 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16681 .doit = nl80211_join_ibss,
16682 .flags = GENL_UNS_ADMIN_PERM,
16683 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16686 .cmd = NL80211_CMD_LEAVE_IBSS,
16687 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16688 .doit = nl80211_leave_ibss,
16689 .flags = GENL_UNS_ADMIN_PERM,
16690 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16692 #ifdef CONFIG_NL80211_TESTMODE
16694 .cmd = NL80211_CMD_TESTMODE,
16695 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16696 .doit = nl80211_testmode_do,
16697 .dumpit = nl80211_testmode_dump,
16698 .flags = GENL_UNS_ADMIN_PERM,
16699 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16703 .cmd = NL80211_CMD_CONNECT,
16704 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16705 .doit = nl80211_connect,
16706 .flags = GENL_UNS_ADMIN_PERM,
16707 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16708 NL80211_FLAG_CLEAR_SKB),
16711 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
16712 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16713 .doit = nl80211_update_connect_params,
16714 .flags = GENL_ADMIN_PERM,
16715 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16716 NL80211_FLAG_CLEAR_SKB),
16719 .cmd = NL80211_CMD_DISCONNECT,
16720 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16721 .doit = nl80211_disconnect,
16722 .flags = GENL_UNS_ADMIN_PERM,
16723 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16726 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
16727 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16728 .doit = nl80211_wiphy_netns,
16729 .flags = GENL_UNS_ADMIN_PERM,
16730 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
16731 NL80211_FLAG_NEED_RTNL |
16732 NL80211_FLAG_NO_WIPHY_MTX),
16735 .cmd = NL80211_CMD_GET_SURVEY,
16736 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16737 .dumpit = nl80211_dump_survey,
16740 .cmd = NL80211_CMD_SET_PMKSA,
16741 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16742 .doit = nl80211_setdel_pmksa,
16743 .flags = GENL_UNS_ADMIN_PERM,
16744 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16745 NL80211_FLAG_CLEAR_SKB),
16748 .cmd = NL80211_CMD_DEL_PMKSA,
16749 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16750 .doit = nl80211_setdel_pmksa,
16751 .flags = GENL_UNS_ADMIN_PERM,
16752 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16755 .cmd = NL80211_CMD_FLUSH_PMKSA,
16756 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16757 .doit = nl80211_flush_pmksa,
16758 .flags = GENL_UNS_ADMIN_PERM,
16759 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16762 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
16763 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16764 .doit = nl80211_remain_on_channel,
16765 .flags = GENL_UNS_ADMIN_PERM,
16766 /* FIXME: requiring a link ID here is probably not good */
16767 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
16768 NL80211_FLAG_MLO_VALID_LINK_ID),
16771 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
16772 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16773 .doit = nl80211_cancel_remain_on_channel,
16774 .flags = GENL_UNS_ADMIN_PERM,
16775 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16778 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
16779 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16780 .doit = nl80211_set_tx_bitrate_mask,
16781 .flags = GENL_UNS_ADMIN_PERM,
16782 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
16783 NL80211_FLAG_MLO_VALID_LINK_ID),
16786 .cmd = NL80211_CMD_REGISTER_FRAME,
16787 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16788 .doit = nl80211_register_mgmt,
16789 .flags = GENL_UNS_ADMIN_PERM,
16790 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV),
16793 .cmd = NL80211_CMD_FRAME,
16794 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16795 .doit = nl80211_tx_mgmt,
16796 .flags = GENL_UNS_ADMIN_PERM,
16797 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16800 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
16801 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16802 .doit = nl80211_tx_mgmt_cancel_wait,
16803 .flags = GENL_UNS_ADMIN_PERM,
16804 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16807 .cmd = NL80211_CMD_SET_POWER_SAVE,
16808 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16809 .doit = nl80211_set_power_save,
16810 .flags = GENL_UNS_ADMIN_PERM,
16811 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16814 .cmd = NL80211_CMD_GET_POWER_SAVE,
16815 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16816 .doit = nl80211_get_power_save,
16817 /* can be retrieved by unprivileged users */
16818 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16821 .cmd = NL80211_CMD_SET_CQM,
16822 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16823 .doit = nl80211_set_cqm,
16824 .flags = GENL_UNS_ADMIN_PERM,
16825 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16828 .cmd = NL80211_CMD_SET_CHANNEL,
16829 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16830 .doit = nl80211_set_channel,
16831 .flags = GENL_UNS_ADMIN_PERM,
16832 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
16833 NL80211_FLAG_MLO_VALID_LINK_ID),
16836 .cmd = NL80211_CMD_JOIN_MESH,
16837 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16838 .doit = nl80211_join_mesh,
16839 .flags = GENL_UNS_ADMIN_PERM,
16840 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16843 .cmd = NL80211_CMD_LEAVE_MESH,
16844 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16845 .doit = nl80211_leave_mesh,
16846 .flags = GENL_UNS_ADMIN_PERM,
16847 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16850 .cmd = NL80211_CMD_JOIN_OCB,
16851 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16852 .doit = nl80211_join_ocb,
16853 .flags = GENL_UNS_ADMIN_PERM,
16854 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16857 .cmd = NL80211_CMD_LEAVE_OCB,
16858 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16859 .doit = nl80211_leave_ocb,
16860 .flags = GENL_UNS_ADMIN_PERM,
16861 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16865 .cmd = NL80211_CMD_GET_WOWLAN,
16866 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16867 .doit = nl80211_get_wowlan,
16868 /* can be retrieved by unprivileged users */
16869 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16872 .cmd = NL80211_CMD_SET_WOWLAN,
16873 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16874 .doit = nl80211_set_wowlan,
16875 .flags = GENL_UNS_ADMIN_PERM,
16876 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16880 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
16881 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16882 .doit = nl80211_set_rekey_data,
16883 .flags = GENL_UNS_ADMIN_PERM,
16884 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
16885 NL80211_FLAG_CLEAR_SKB),
16888 .cmd = NL80211_CMD_TDLS_MGMT,
16889 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16890 .doit = nl80211_tdls_mgmt,
16891 .flags = GENL_UNS_ADMIN_PERM,
16892 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16895 .cmd = NL80211_CMD_TDLS_OPER,
16896 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16897 .doit = nl80211_tdls_oper,
16898 .flags = GENL_UNS_ADMIN_PERM,
16899 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16902 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
16903 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16904 .doit = nl80211_register_unexpected_frame,
16905 .flags = GENL_UNS_ADMIN_PERM,
16906 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16909 .cmd = NL80211_CMD_PROBE_CLIENT,
16910 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16911 .doit = nl80211_probe_client,
16912 .flags = GENL_UNS_ADMIN_PERM,
16913 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
16916 .cmd = NL80211_CMD_REGISTER_BEACONS,
16917 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16918 .doit = nl80211_register_beacons,
16919 .flags = GENL_UNS_ADMIN_PERM,
16920 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
16923 .cmd = NL80211_CMD_SET_NOACK_MAP,
16924 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16925 .doit = nl80211_set_noack_map,
16926 .flags = GENL_UNS_ADMIN_PERM,
16927 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16930 .cmd = NL80211_CMD_START_P2P_DEVICE,
16931 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16932 .doit = nl80211_start_p2p_device,
16933 .flags = GENL_UNS_ADMIN_PERM,
16934 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
16935 NL80211_FLAG_NEED_RTNL),
16938 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
16939 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16940 .doit = nl80211_stop_p2p_device,
16941 .flags = GENL_UNS_ADMIN_PERM,
16942 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
16943 NL80211_FLAG_NEED_RTNL),
16946 .cmd = NL80211_CMD_START_NAN,
16947 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16948 .doit = nl80211_start_nan,
16949 .flags = GENL_ADMIN_PERM,
16950 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
16951 NL80211_FLAG_NEED_RTNL),
16954 .cmd = NL80211_CMD_STOP_NAN,
16955 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16956 .doit = nl80211_stop_nan,
16957 .flags = GENL_ADMIN_PERM,
16958 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
16959 NL80211_FLAG_NEED_RTNL),
16962 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
16963 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16964 .doit = nl80211_nan_add_func,
16965 .flags = GENL_ADMIN_PERM,
16966 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16969 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
16970 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16971 .doit = nl80211_nan_del_func,
16972 .flags = GENL_ADMIN_PERM,
16973 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16976 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
16977 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16978 .doit = nl80211_nan_change_config,
16979 .flags = GENL_ADMIN_PERM,
16980 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
16983 .cmd = NL80211_CMD_SET_MCAST_RATE,
16984 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16985 .doit = nl80211_set_mcast_rate,
16986 .flags = GENL_UNS_ADMIN_PERM,
16987 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
16990 .cmd = NL80211_CMD_SET_MAC_ACL,
16991 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16992 .doit = nl80211_set_mac_acl,
16993 .flags = GENL_UNS_ADMIN_PERM,
16994 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
16995 NL80211_FLAG_MLO_UNSUPPORTED),
16998 .cmd = NL80211_CMD_RADAR_DETECT,
16999 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17000 .doit = nl80211_start_radar_detection,
17001 .flags = GENL_UNS_ADMIN_PERM,
17002 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17003 NL80211_FLAG_NO_WIPHY_MTX |
17004 NL80211_FLAG_MLO_UNSUPPORTED),
17007 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
17008 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17009 .doit = nl80211_get_protocol_features,
17012 .cmd = NL80211_CMD_UPDATE_FT_IES,
17013 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17014 .doit = nl80211_update_ft_ies,
17015 .flags = GENL_UNS_ADMIN_PERM,
17016 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17019 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
17020 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17021 .doit = nl80211_crit_protocol_start,
17022 .flags = GENL_UNS_ADMIN_PERM,
17023 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17026 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
17027 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17028 .doit = nl80211_crit_protocol_stop,
17029 .flags = GENL_UNS_ADMIN_PERM,
17030 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17033 .cmd = NL80211_CMD_GET_COALESCE,
17034 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17035 .doit = nl80211_get_coalesce,
17036 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17039 .cmd = NL80211_CMD_SET_COALESCE,
17040 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17041 .doit = nl80211_set_coalesce,
17042 .flags = GENL_UNS_ADMIN_PERM,
17043 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY),
17046 .cmd = NL80211_CMD_CHANNEL_SWITCH,
17047 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17048 .doit = nl80211_channel_switch,
17049 .flags = GENL_UNS_ADMIN_PERM,
17050 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17051 NL80211_FLAG_MLO_VALID_LINK_ID),
17054 .cmd = NL80211_CMD_VENDOR,
17055 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17056 .doit = nl80211_vendor_cmd,
17057 .dumpit = nl80211_vendor_cmd_dump,
17058 .flags = GENL_UNS_ADMIN_PERM,
17059 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
17060 NL80211_FLAG_CLEAR_SKB),
17063 .cmd = NL80211_CMD_SET_QOS_MAP,
17064 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17065 .doit = nl80211_set_qos_map,
17066 .flags = GENL_UNS_ADMIN_PERM,
17067 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17070 .cmd = NL80211_CMD_ADD_TX_TS,
17071 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17072 .doit = nl80211_add_tx_ts,
17073 .flags = GENL_UNS_ADMIN_PERM,
17074 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17075 NL80211_FLAG_MLO_UNSUPPORTED),
17078 .cmd = NL80211_CMD_DEL_TX_TS,
17079 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17080 .doit = nl80211_del_tx_ts,
17081 .flags = GENL_UNS_ADMIN_PERM,
17082 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17085 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
17086 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17087 .doit = nl80211_tdls_channel_switch,
17088 .flags = GENL_UNS_ADMIN_PERM,
17089 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17092 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
17093 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17094 .doit = nl80211_tdls_cancel_channel_switch,
17095 .flags = GENL_UNS_ADMIN_PERM,
17096 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17099 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
17100 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17101 .doit = nl80211_set_multicast_to_unicast,
17102 .flags = GENL_UNS_ADMIN_PERM,
17103 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV),
17106 .cmd = NL80211_CMD_SET_PMK,
17107 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17108 .doit = nl80211_set_pmk,
17109 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17110 NL80211_FLAG_CLEAR_SKB),
17113 .cmd = NL80211_CMD_DEL_PMK,
17114 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17115 .doit = nl80211_del_pmk,
17116 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17119 .cmd = NL80211_CMD_EXTERNAL_AUTH,
17120 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17121 .doit = nl80211_external_auth,
17122 .flags = GENL_ADMIN_PERM,
17123 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17126 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
17127 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17128 .doit = nl80211_tx_control_port,
17129 .flags = GENL_UNS_ADMIN_PERM,
17130 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17133 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
17134 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17135 .doit = nl80211_get_ftm_responder_stats,
17136 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17137 NL80211_FLAG_MLO_VALID_LINK_ID),
17140 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
17141 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17142 .doit = nl80211_pmsr_start,
17143 .flags = GENL_UNS_ADMIN_PERM,
17144 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
17147 .cmd = NL80211_CMD_NOTIFY_RADAR,
17148 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17149 .doit = nl80211_notify_radar_detection,
17150 .flags = GENL_UNS_ADMIN_PERM,
17151 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17154 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
17155 .doit = nl80211_update_owe_info,
17156 .flags = GENL_ADMIN_PERM,
17157 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17160 .cmd = NL80211_CMD_PROBE_MESH_LINK,
17161 .doit = nl80211_probe_mesh_link,
17162 .flags = GENL_UNS_ADMIN_PERM,
17163 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17166 .cmd = NL80211_CMD_SET_TID_CONFIG,
17167 .doit = nl80211_set_tid_config,
17168 .flags = GENL_UNS_ADMIN_PERM,
17169 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV |
17170 NL80211_FLAG_MLO_VALID_LINK_ID),
17173 .cmd = NL80211_CMD_SET_SAR_SPECS,
17174 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17175 .doit = nl80211_set_sar_specs,
17176 .flags = GENL_UNS_ADMIN_PERM,
17177 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY |
17178 NL80211_FLAG_NEED_RTNL),
17181 .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST,
17182 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17183 .doit = nl80211_color_change,
17184 .flags = GENL_UNS_ADMIN_PERM,
17185 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17188 .cmd = NL80211_CMD_SET_FILS_AAD,
17189 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
17190 .doit = nl80211_set_fils_aad,
17191 .flags = GENL_UNS_ADMIN_PERM,
17192 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17195 .cmd = NL80211_CMD_ADD_LINK,
17196 .doit = nl80211_add_link,
17197 .flags = GENL_UNS_ADMIN_PERM,
17198 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP),
17201 .cmd = NL80211_CMD_REMOVE_LINK,
17202 .doit = nl80211_remove_link,
17203 .flags = GENL_UNS_ADMIN_PERM,
17204 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17205 NL80211_FLAG_MLO_VALID_LINK_ID),
17208 .cmd = NL80211_CMD_ADD_LINK_STA,
17209 .doit = nl80211_add_link_station,
17210 .flags = GENL_UNS_ADMIN_PERM,
17211 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17212 NL80211_FLAG_MLO_VALID_LINK_ID),
17215 .cmd = NL80211_CMD_MODIFY_LINK_STA,
17216 .doit = nl80211_modify_link_station,
17217 .flags = GENL_UNS_ADMIN_PERM,
17218 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17219 NL80211_FLAG_MLO_VALID_LINK_ID),
17222 .cmd = NL80211_CMD_REMOVE_LINK_STA,
17223 .doit = nl80211_remove_link_station,
17224 .flags = GENL_UNS_ADMIN_PERM,
17225 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP |
17226 NL80211_FLAG_MLO_VALID_LINK_ID),
17230 static struct genl_family nl80211_fam __ro_after_init = {
17231 .name = NL80211_GENL_NAME, /* have users key off the name instead */
17232 .hdrsize = 0, /* no private header */
17233 .version = 1, /* no particular meaning now */
17234 .maxattr = NL80211_ATTR_MAX,
17235 .policy = nl80211_policy,
17237 .pre_doit = nl80211_pre_doit,
17238 .post_doit = nl80211_post_doit,
17239 .module = THIS_MODULE,
17240 .ops = nl80211_ops,
17241 .n_ops = ARRAY_SIZE(nl80211_ops),
17242 .small_ops = nl80211_small_ops,
17243 .n_small_ops = ARRAY_SIZE(nl80211_small_ops),
17244 .resv_start_op = NL80211_CMD_REMOVE_LINK_STA + 1,
17245 .mcgrps = nl80211_mcgrps,
17246 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
17247 .parallel_ops = true,
17250 /* notification functions */
17252 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
17253 enum nl80211_commands cmd)
17255 struct sk_buff *msg;
17256 struct nl80211_dump_wiphy_state state = {};
17258 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
17259 cmd != NL80211_CMD_DEL_WIPHY);
17261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17265 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
17270 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17271 NL80211_MCGRP_CONFIG, GFP_KERNEL);
17274 void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
17275 struct wireless_dev *wdev,
17276 enum nl80211_commands cmd)
17278 struct sk_buff *msg;
17280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17284 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
17289 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17290 NL80211_MCGRP_CONFIG, GFP_KERNEL);
17293 static int nl80211_add_scan_req(struct sk_buff *msg,
17294 struct cfg80211_registered_device *rdev)
17296 struct cfg80211_scan_request *req = rdev->scan_req;
17297 struct nlattr *nest;
17299 struct cfg80211_scan_info *info;
17304 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
17306 goto nla_put_failure;
17307 for (i = 0; i < req->n_ssids; i++) {
17308 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
17309 goto nla_put_failure;
17311 nla_nest_end(msg, nest);
17313 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) {
17314 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ);
17316 goto nla_put_failure;
17317 for (i = 0; i < req->n_channels; i++) {
17318 if (nla_put_u32(msg, i,
17319 ieee80211_channel_to_khz(req->channels[i])))
17320 goto nla_put_failure;
17322 nla_nest_end(msg, nest);
17324 nest = nla_nest_start_noflag(msg,
17325 NL80211_ATTR_SCAN_FREQUENCIES);
17327 goto nla_put_failure;
17328 for (i = 0; i < req->n_channels; i++) {
17329 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
17330 goto nla_put_failure;
17332 nla_nest_end(msg, nest);
17336 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
17337 goto nla_put_failure;
17340 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
17341 goto nla_put_failure;
17343 info = rdev->int_scan_req ? &rdev->int_scan_req->info :
17344 &rdev->scan_req->info;
17345 if (info->scan_start_tsf &&
17346 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
17347 info->scan_start_tsf, NL80211_BSS_PAD) ||
17348 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
17350 goto nla_put_failure;
17357 static int nl80211_prep_scan_msg(struct sk_buff *msg,
17358 struct cfg80211_registered_device *rdev,
17359 struct wireless_dev *wdev,
17360 u32 portid, u32 seq, int flags,
17365 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
17369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17370 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
17371 wdev->netdev->ifindex)) ||
17372 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17374 goto nla_put_failure;
17376 /* ignore errors and send incomplete event anyway */
17377 nl80211_add_scan_req(msg, rdev);
17379 genlmsg_end(msg, hdr);
17383 genlmsg_cancel(msg, hdr);
17388 nl80211_prep_sched_scan_msg(struct sk_buff *msg,
17389 struct cfg80211_sched_scan_request *req, u32 cmd)
17393 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17397 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
17398 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
17399 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
17400 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
17402 goto nla_put_failure;
17404 genlmsg_end(msg, hdr);
17408 genlmsg_cancel(msg, hdr);
17412 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
17413 struct wireless_dev *wdev)
17415 struct sk_buff *msg;
17417 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17421 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
17422 NL80211_CMD_TRIGGER_SCAN) < 0) {
17427 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17428 NL80211_MCGRP_SCAN, GFP_KERNEL);
17431 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
17432 struct wireless_dev *wdev, bool aborted)
17434 struct sk_buff *msg;
17436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17440 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
17441 aborted ? NL80211_CMD_SCAN_ABORTED :
17442 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
17450 /* send message created by nl80211_build_scan_msg() */
17451 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
17452 struct sk_buff *msg)
17457 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17458 NL80211_MCGRP_SCAN, GFP_KERNEL);
17461 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
17463 struct sk_buff *msg;
17465 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17469 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
17474 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
17475 NL80211_MCGRP_SCAN, GFP_KERNEL);
17478 static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
17479 struct regulatory_request *request)
17481 /* Userspace can always count this one always being set */
17482 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
17483 goto nla_put_failure;
17485 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
17486 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17487 NL80211_REGDOM_TYPE_WORLD))
17488 goto nla_put_failure;
17489 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
17490 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17491 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
17492 goto nla_put_failure;
17493 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
17494 request->intersect) {
17495 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17496 NL80211_REGDOM_TYPE_INTERSECTION))
17497 goto nla_put_failure;
17499 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
17500 NL80211_REGDOM_TYPE_COUNTRY) ||
17501 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
17503 goto nla_put_failure;
17506 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
17507 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
17510 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
17511 goto nla_put_failure;
17514 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
17515 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
17516 goto nla_put_failure;
17526 * This can happen on global regulatory changes or device specific settings
17527 * based on custom regulatory domains.
17529 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
17530 struct regulatory_request *request)
17532 struct sk_buff *msg;
17535 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17539 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
17541 goto nla_put_failure;
17543 if (!nl80211_reg_change_event_fill(msg, request))
17544 goto nla_put_failure;
17546 genlmsg_end(msg, hdr);
17549 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
17550 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
17559 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
17560 struct net_device *netdev,
17561 const u8 *buf, size_t len,
17562 enum nl80211_commands cmd, gfp_t gfp,
17563 int uapsd_queues, const u8 *req_ies,
17564 size_t req_ies_len, bool reconnect)
17566 struct sk_buff *msg;
17569 msg = nlmsg_new(100 + len + req_ies_len, gfp);
17573 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17579 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17580 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17581 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
17583 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
17584 goto nla_put_failure;
17586 if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED))
17587 goto nla_put_failure;
17589 if (uapsd_queues >= 0) {
17590 struct nlattr *nla_wmm =
17591 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
17593 goto nla_put_failure;
17595 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
17597 goto nla_put_failure;
17599 nla_nest_end(msg, nla_wmm);
17602 genlmsg_end(msg, hdr);
17604 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17605 NL80211_MCGRP_MLME, gfp);
17612 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
17613 struct net_device *netdev, const u8 *buf,
17614 size_t len, gfp_t gfp)
17616 nl80211_send_mlme_event(rdev, netdev, buf, len,
17617 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0,
17621 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
17622 struct net_device *netdev,
17623 struct cfg80211_rx_assoc_resp *data)
17625 nl80211_send_mlme_event(rdev, netdev, data->buf, data->len,
17626 NL80211_CMD_ASSOCIATE, GFP_KERNEL,
17627 data->uapsd_queues,
17628 data->req_ies, data->req_ies_len, false);
17631 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
17632 struct net_device *netdev, const u8 *buf,
17633 size_t len, bool reconnect, gfp_t gfp)
17635 nl80211_send_mlme_event(rdev, netdev, buf, len,
17636 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0,
17640 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
17641 struct net_device *netdev, const u8 *buf,
17642 size_t len, bool reconnect, gfp_t gfp)
17644 nl80211_send_mlme_event(rdev, netdev, buf, len,
17645 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0,
17649 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
17652 struct wireless_dev *wdev = dev->ieee80211_ptr;
17653 struct wiphy *wiphy = wdev->wiphy;
17654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17655 const struct ieee80211_mgmt *mgmt = (void *)buf;
17658 if (WARN_ON(len < 2))
17661 if (ieee80211_is_deauth(mgmt->frame_control)) {
17662 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
17663 } else if (ieee80211_is_disassoc(mgmt->frame_control)) {
17664 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
17665 } else if (ieee80211_is_beacon(mgmt->frame_control)) {
17666 if (wdev->unprot_beacon_reported &&
17667 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000)
17669 cmd = NL80211_CMD_UNPROT_BEACON;
17670 wdev->unprot_beacon_reported = jiffies;
17675 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
17676 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
17679 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
17681 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
17682 struct net_device *netdev, int cmd,
17683 const u8 *addr, gfp_t gfp)
17685 struct sk_buff *msg;
17688 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17692 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
17698 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17699 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17700 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
17701 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
17702 goto nla_put_failure;
17704 genlmsg_end(msg, hdr);
17706 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17707 NL80211_MCGRP_MLME, gfp);
17714 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
17715 struct net_device *netdev, const u8 *addr,
17718 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
17722 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
17723 struct net_device *netdev, const u8 *addr,
17726 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
17730 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
17731 struct net_device *netdev,
17732 struct cfg80211_connect_resp_params *cr,
17735 struct sk_buff *msg;
17738 size_t link_info_size = 0;
17739 const u8 *connected_addr = cr->valid_links ?
17740 cr->ap_mld_addr : cr->links[0].bssid;
17742 if (cr->valid_links) {
17743 for_each_valid_link(cr, link) {
17744 /* Nested attribute header */
17745 link_info_size += NLA_HDRLEN;
17747 link_info_size += nla_total_size(sizeof(u8));
17748 link_info_size += cr->links[link].addr ?
17749 nla_total_size(ETH_ALEN) : 0;
17750 link_info_size += (cr->links[link].bssid ||
17751 cr->links[link].bss) ?
17752 nla_total_size(ETH_ALEN) : 0;
17756 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
17757 cr->fils.kek_len + cr->fils.pmk_len +
17758 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size,
17763 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
17769 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17770 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17772 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr)) ||
17773 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
17774 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
17777 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
17778 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
17779 cr->timeout_reason))) ||
17781 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
17783 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
17785 (cr->fils.update_erp_next_seq_num &&
17786 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
17787 cr->fils.erp_next_seq_num)) ||
17788 (cr->status == WLAN_STATUS_SUCCESS &&
17790 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
17793 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
17795 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
17796 goto nla_put_failure;
17798 if (cr->valid_links) {
17800 struct nlattr *nested;
17802 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
17804 goto nla_put_failure;
17806 for_each_valid_link(cr, link) {
17807 struct nlattr *nested_mlo_links;
17808 const u8 *bssid = cr->links[link].bss ?
17809 cr->links[link].bss->bssid :
17810 cr->links[link].bssid;
17812 nested_mlo_links = nla_nest_start(msg, i);
17813 if (!nested_mlo_links)
17814 goto nla_put_failure;
17816 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) ||
17818 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) ||
17819 (cr->links[link].addr &&
17820 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
17821 cr->links[link].addr)))
17822 goto nla_put_failure;
17824 nla_nest_end(msg, nested_mlo_links);
17827 nla_nest_end(msg, nested);
17830 genlmsg_end(msg, hdr);
17832 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17833 NL80211_MCGRP_MLME, gfp);
17840 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
17841 struct net_device *netdev,
17842 struct cfg80211_roam_info *info, gfp_t gfp)
17844 struct sk_buff *msg;
17846 size_t link_info_size = 0;
17848 const u8 *connected_addr = info->ap_mld_addr ?
17849 info->ap_mld_addr :
17850 (info->links[0].bss ?
17851 info->links[0].bss->bssid :
17852 info->links[0].bssid);
17854 if (info->valid_links) {
17855 for_each_valid_link(info, link) {
17856 /* Nested attribute header */
17857 link_info_size += NLA_HDRLEN;
17859 link_info_size += nla_total_size(sizeof(u8));
17860 link_info_size += info->links[link].addr ?
17861 nla_total_size(ETH_ALEN) : 0;
17862 link_info_size += (info->links[link].bssid ||
17863 info->links[link].bss) ?
17864 nla_total_size(ETH_ALEN) : 0;
17868 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
17869 info->fils.kek_len + info->fils.pmk_len +
17870 (info->fils.pmkid ? WLAN_PMKID_LEN : 0) +
17871 link_info_size, gfp);
17875 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
17881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17882 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17883 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) ||
17885 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
17888 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
17890 (info->fils.update_erp_next_seq_num &&
17891 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
17892 info->fils.erp_next_seq_num)) ||
17894 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
17895 info->fils.kek)) ||
17897 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
17898 (info->fils.pmkid &&
17899 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
17900 goto nla_put_failure;
17902 if (info->valid_links) {
17904 struct nlattr *nested;
17906 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
17908 goto nla_put_failure;
17910 for_each_valid_link(info, link) {
17911 struct nlattr *nested_mlo_links;
17912 const u8 *bssid = info->links[link].bss ?
17913 info->links[link].bss->bssid :
17914 info->links[link].bssid;
17916 nested_mlo_links = nla_nest_start(msg, i);
17917 if (!nested_mlo_links)
17918 goto nla_put_failure;
17920 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) ||
17922 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) ||
17923 (info->links[link].addr &&
17924 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
17925 info->links[link].addr)))
17926 goto nla_put_failure;
17928 nla_nest_end(msg, nested_mlo_links);
17931 nla_nest_end(msg, nested);
17934 genlmsg_end(msg, hdr);
17936 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17937 NL80211_MCGRP_MLME, gfp);
17944 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
17945 struct net_device *netdev, const u8 *bssid)
17947 struct sk_buff *msg;
17950 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17954 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
17960 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17961 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17962 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
17963 goto nla_put_failure;
17965 genlmsg_end(msg, hdr);
17967 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17968 NL80211_MCGRP_MLME, GFP_KERNEL);
17975 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
17976 struct net_device *netdev, u16 reason,
17977 const u8 *ie, size_t ie_len, bool from_ap)
17979 struct sk_buff *msg;
17982 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
17986 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
17992 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17993 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17995 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
17997 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
17998 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
17999 goto nla_put_failure;
18001 genlmsg_end(msg, hdr);
18003 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18004 NL80211_MCGRP_MLME, GFP_KERNEL);
18011 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
18012 struct net_device *netdev, const u8 *bssid,
18015 struct sk_buff *msg;
18018 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18022 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
18028 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18029 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18030 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
18031 goto nla_put_failure;
18033 genlmsg_end(msg, hdr);
18035 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18036 NL80211_MCGRP_MLME, gfp);
18043 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
18044 const u8 *ie, u8 ie_len,
18045 int sig_dbm, gfp_t gfp)
18047 struct wireless_dev *wdev = dev->ieee80211_ptr;
18048 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18049 struct sk_buff *msg;
18052 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
18055 trace_cfg80211_notify_new_peer_candidate(dev, addr);
18057 msg = nlmsg_new(100 + ie_len, gfp);
18061 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
18067 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18068 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18069 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
18071 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
18073 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
18074 goto nla_put_failure;
18076 genlmsg_end(msg, hdr);
18078 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18079 NL80211_MCGRP_MLME, gfp);
18085 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
18087 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
18088 struct net_device *netdev, const u8 *addr,
18089 enum nl80211_key_type key_type, int key_id,
18090 const u8 *tsc, gfp_t gfp)
18092 struct sk_buff *msg;
18095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18099 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
18105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18106 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18107 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
18108 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
18110 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
18111 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
18112 goto nla_put_failure;
18114 genlmsg_end(msg, hdr);
18116 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18117 NL80211_MCGRP_MLME, gfp);
18124 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
18125 struct ieee80211_channel *channel_before,
18126 struct ieee80211_channel *channel_after)
18128 struct sk_buff *msg;
18130 struct nlattr *nl_freq;
18132 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
18136 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
18143 * Since we are applying the beacon hint to a wiphy we know its
18144 * wiphy_idx is valid
18146 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
18147 goto nla_put_failure;
18150 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
18152 goto nla_put_failure;
18154 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
18155 goto nla_put_failure;
18156 nla_nest_end(msg, nl_freq);
18159 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
18161 goto nla_put_failure;
18163 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
18164 goto nla_put_failure;
18165 nla_nest_end(msg, nl_freq);
18167 genlmsg_end(msg, hdr);
18170 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
18171 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
18180 static void nl80211_send_remain_on_chan_event(
18181 int cmd, struct cfg80211_registered_device *rdev,
18182 struct wireless_dev *wdev, u64 cookie,
18183 struct ieee80211_channel *chan,
18184 unsigned int duration, gfp_t gfp)
18186 struct sk_buff *msg;
18189 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18193 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
18199 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18200 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18201 wdev->netdev->ifindex)) ||
18202 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18203 NL80211_ATTR_PAD) ||
18204 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
18205 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
18206 NL80211_CHAN_NO_HT) ||
18207 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
18209 goto nla_put_failure;
18211 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
18212 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
18213 goto nla_put_failure;
18215 genlmsg_end(msg, hdr);
18217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18218 NL80211_MCGRP_MLME, gfp);
18225 void cfg80211_assoc_comeback(struct net_device *netdev,
18226 const u8 *ap_addr, u32 timeout)
18228 struct wireless_dev *wdev = netdev->ieee80211_ptr;
18229 struct wiphy *wiphy = wdev->wiphy;
18230 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18231 struct sk_buff *msg;
18234 trace_cfg80211_assoc_comeback(wdev, ap_addr, timeout);
18236 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
18240 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ASSOC_COMEBACK);
18246 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18247 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18248 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ap_addr) ||
18249 nla_put_u32(msg, NL80211_ATTR_TIMEOUT, timeout))
18250 goto nla_put_failure;
18252 genlmsg_end(msg, hdr);
18254 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18255 NL80211_MCGRP_MLME, GFP_KERNEL);
18261 EXPORT_SYMBOL(cfg80211_assoc_comeback);
18263 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
18264 struct ieee80211_channel *chan,
18265 unsigned int duration, gfp_t gfp)
18267 struct wiphy *wiphy = wdev->wiphy;
18268 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18270 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
18271 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
18272 rdev, wdev, cookie, chan,
18275 EXPORT_SYMBOL(cfg80211_ready_on_channel);
18277 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
18278 struct ieee80211_channel *chan,
18281 struct wiphy *wiphy = wdev->wiphy;
18282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18284 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
18285 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
18286 rdev, wdev, cookie, chan, 0, gfp);
18288 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
18290 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
18291 struct ieee80211_channel *chan,
18294 struct wiphy *wiphy = wdev->wiphy;
18295 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18297 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
18298 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
18299 rdev, wdev, cookie, chan, 0, gfp);
18301 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
18303 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
18304 struct station_info *sinfo, gfp_t gfp)
18306 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18307 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18308 struct sk_buff *msg;
18310 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
18312 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18316 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
18317 rdev, dev, mac_addr, sinfo) < 0) {
18322 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18323 NL80211_MCGRP_MLME, gfp);
18325 EXPORT_SYMBOL(cfg80211_new_sta);
18327 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
18328 struct station_info *sinfo, gfp_t gfp)
18330 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18331 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18332 struct sk_buff *msg;
18333 struct station_info empty_sinfo = {};
18336 sinfo = &empty_sinfo;
18338 trace_cfg80211_del_sta(dev, mac_addr);
18340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18342 cfg80211_sinfo_release_content(sinfo);
18346 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
18347 rdev, dev, mac_addr, sinfo) < 0) {
18352 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18353 NL80211_MCGRP_MLME, gfp);
18355 EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
18357 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
18358 enum nl80211_connect_failed_reason reason,
18361 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18362 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18363 struct sk_buff *msg;
18366 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
18370 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
18376 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18377 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
18378 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
18379 goto nla_put_failure;
18381 genlmsg_end(msg, hdr);
18383 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18384 NL80211_MCGRP_MLME, gfp);
18390 EXPORT_SYMBOL(cfg80211_conn_failed);
18392 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
18393 const u8 *addr, gfp_t gfp)
18395 struct wireless_dev *wdev = dev->ieee80211_ptr;
18396 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18397 struct sk_buff *msg;
18399 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
18404 msg = nlmsg_new(100, gfp);
18408 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
18414 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18415 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18416 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
18417 goto nla_put_failure;
18419 genlmsg_end(msg, hdr);
18420 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
18428 bool cfg80211_rx_spurious_frame(struct net_device *dev,
18429 const u8 *addr, gfp_t gfp)
18431 struct wireless_dev *wdev = dev->ieee80211_ptr;
18434 trace_cfg80211_rx_spurious_frame(dev, addr);
18436 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
18437 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
18438 trace_cfg80211_return_bool(false);
18441 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
18443 trace_cfg80211_return_bool(ret);
18446 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
18448 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
18449 const u8 *addr, gfp_t gfp)
18451 struct wireless_dev *wdev = dev->ieee80211_ptr;
18454 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
18456 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
18457 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
18458 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
18459 trace_cfg80211_return_bool(false);
18462 ret = __nl80211_unexpected_frame(dev,
18463 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
18465 trace_cfg80211_return_bool(ret);
18468 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
18470 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
18471 struct wireless_dev *wdev, u32 nlportid,
18472 struct cfg80211_rx_info *info, gfp_t gfp)
18474 struct net_device *netdev = wdev->netdev;
18475 struct sk_buff *msg;
18478 msg = nlmsg_new(100 + info->len, gfp);
18482 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
18488 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18489 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18490 netdev->ifindex)) ||
18491 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18492 NL80211_ATTR_PAD) ||
18493 (info->have_link_id &&
18494 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, info->link_id)) ||
18495 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(info->freq)) ||
18496 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, info->freq % 1000) ||
18498 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, info->sig_dbm)) ||
18499 nla_put(msg, NL80211_ATTR_FRAME, info->len, info->buf) ||
18501 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, info->flags)) ||
18502 (info->rx_tstamp && nla_put_u64_64bit(msg,
18503 NL80211_ATTR_RX_HW_TIMESTAMP,
18505 NL80211_ATTR_PAD)) ||
18506 (info->ack_tstamp && nla_put_u64_64bit(msg,
18507 NL80211_ATTR_TX_HW_TIMESTAMP,
18509 NL80211_ATTR_PAD)))
18510 goto nla_put_failure;
18512 genlmsg_end(msg, hdr);
18514 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
18521 static void nl80211_frame_tx_status(struct wireless_dev *wdev,
18522 struct cfg80211_tx_status *status,
18523 gfp_t gfp, enum nl80211_commands command)
18525 struct wiphy *wiphy = wdev->wiphy;
18526 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18527 struct net_device *netdev = wdev->netdev;
18528 struct sk_buff *msg;
18531 if (command == NL80211_CMD_FRAME_TX_STATUS)
18532 trace_cfg80211_mgmt_tx_status(wdev, status->cookie,
18535 trace_cfg80211_control_port_tx_status(wdev, status->cookie,
18538 msg = nlmsg_new(100 + status->len, gfp);
18542 hdr = nl80211hdr_put(msg, 0, 0, 0, command);
18548 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18549 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
18550 netdev->ifindex)) ||
18551 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18552 NL80211_ATTR_PAD) ||
18553 nla_put(msg, NL80211_ATTR_FRAME, status->len, status->buf) ||
18554 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, status->cookie,
18555 NL80211_ATTR_PAD) ||
18556 (status->ack && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
18557 (status->tx_tstamp &&
18558 nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP,
18559 status->tx_tstamp, NL80211_ATTR_PAD)) ||
18560 (status->ack_tstamp &&
18561 nla_put_u64_64bit(msg, NL80211_ATTR_RX_HW_TIMESTAMP,
18562 status->ack_tstamp, NL80211_ATTR_PAD)))
18563 goto nla_put_failure;
18565 genlmsg_end(msg, hdr);
18567 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18568 NL80211_MCGRP_MLME, gfp);
18575 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie,
18576 const u8 *buf, size_t len, bool ack,
18579 struct cfg80211_tx_status status = {
18586 nl80211_frame_tx_status(wdev, &status, gfp,
18587 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS);
18589 EXPORT_SYMBOL(cfg80211_control_port_tx_status);
18591 void cfg80211_mgmt_tx_status_ext(struct wireless_dev *wdev,
18592 struct cfg80211_tx_status *status, gfp_t gfp)
18594 nl80211_frame_tx_status(wdev, status, gfp, NL80211_CMD_FRAME_TX_STATUS);
18596 EXPORT_SYMBOL(cfg80211_mgmt_tx_status_ext);
18598 static int __nl80211_rx_control_port(struct net_device *dev,
18599 struct sk_buff *skb,
18600 bool unencrypted, gfp_t gfp)
18602 struct wireless_dev *wdev = dev->ieee80211_ptr;
18603 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18604 struct ethhdr *ehdr = eth_hdr(skb);
18605 const u8 *addr = ehdr->h_source;
18606 u16 proto = be16_to_cpu(skb->protocol);
18607 struct sk_buff *msg;
18609 struct nlattr *frame;
18611 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
18616 msg = nlmsg_new(100 + skb->len, gfp);
18620 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
18626 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
18628 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
18629 NL80211_ATTR_PAD) ||
18630 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
18631 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
18632 (unencrypted && nla_put_flag(msg,
18633 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
18634 goto nla_put_failure;
18636 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
18638 goto nla_put_failure;
18640 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
18641 genlmsg_end(msg, hdr);
18643 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
18650 bool cfg80211_rx_control_port(struct net_device *dev,
18651 struct sk_buff *skb, bool unencrypted)
18655 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
18656 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
18657 trace_cfg80211_return_bool(ret == 0);
18660 EXPORT_SYMBOL(cfg80211_rx_control_port);
18662 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
18663 const char *mac, gfp_t gfp)
18665 struct wireless_dev *wdev = dev->ieee80211_ptr;
18666 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18667 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18673 cb = (void **)msg->cb;
18675 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
18681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18682 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
18683 goto nla_put_failure;
18685 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
18686 goto nla_put_failure;
18688 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
18690 goto nla_put_failure;
18700 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
18702 void **cb = (void **)msg->cb;
18703 struct cfg80211_registered_device *rdev = cb[2];
18705 nla_nest_end(msg, cb[1]);
18706 genlmsg_end(msg, cb[0]);
18708 memset(msg->cb, 0, sizeof(msg->cb));
18710 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18711 NL80211_MCGRP_MLME, gfp);
18714 void cfg80211_cqm_rssi_notify(struct net_device *dev,
18715 enum nl80211_cqm_rssi_threshold_event rssi_event,
18716 s32 rssi_level, gfp_t gfp)
18718 struct sk_buff *msg;
18719 struct wireless_dev *wdev = dev->ieee80211_ptr;
18720 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
18722 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
18724 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
18725 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
18728 if (wdev->cqm_config) {
18729 wdev->cqm_config->last_rssi_event_value = rssi_level;
18731 cfg80211_cqm_rssi_update(rdev, dev);
18733 if (rssi_level == 0)
18734 rssi_level = wdev->cqm_config->last_rssi_event_value;
18737 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
18741 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
18743 goto nla_put_failure;
18745 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
18747 goto nla_put_failure;
18749 cfg80211_send_cqm(msg, gfp);
18756 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
18758 void cfg80211_cqm_txe_notify(struct net_device *dev,
18759 const u8 *peer, u32 num_packets,
18760 u32 rate, u32 intvl, gfp_t gfp)
18762 struct sk_buff *msg;
18764 msg = cfg80211_prepare_cqm(dev, peer, gfp);
18768 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
18769 goto nla_put_failure;
18771 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
18772 goto nla_put_failure;
18774 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
18775 goto nla_put_failure;
18777 cfg80211_send_cqm(msg, gfp);
18783 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
18785 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
18786 const u8 *peer, u32 num_packets, gfp_t gfp)
18788 struct sk_buff *msg;
18790 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
18792 msg = cfg80211_prepare_cqm(dev, peer, gfp);
18796 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
18797 goto nla_put_failure;
18799 cfg80211_send_cqm(msg, gfp);
18805 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
18807 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
18809 struct sk_buff *msg;
18811 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
18815 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
18816 goto nla_put_failure;
18818 cfg80211_send_cqm(msg, gfp);
18824 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
18826 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
18827 struct net_device *netdev, const u8 *bssid,
18828 const u8 *replay_ctr, gfp_t gfp)
18830 struct sk_buff *msg;
18831 struct nlattr *rekey_attr;
18834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18838 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
18844 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18845 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
18846 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
18847 goto nla_put_failure;
18849 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
18851 goto nla_put_failure;
18853 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
18854 NL80211_REPLAY_CTR_LEN, replay_ctr))
18855 goto nla_put_failure;
18857 nla_nest_end(msg, rekey_attr);
18859 genlmsg_end(msg, hdr);
18861 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18862 NL80211_MCGRP_MLME, gfp);
18869 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
18870 const u8 *replay_ctr, gfp_t gfp)
18872 struct wireless_dev *wdev = dev->ieee80211_ptr;
18873 struct wiphy *wiphy = wdev->wiphy;
18874 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18876 trace_cfg80211_gtk_rekey_notify(dev, bssid);
18877 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
18879 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
18882 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
18883 struct net_device *netdev, int index,
18884 const u8 *bssid, bool preauth, gfp_t gfp)
18886 struct sk_buff *msg;
18887 struct nlattr *attr;
18890 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18894 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
18900 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
18901 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
18902 goto nla_put_failure;
18904 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
18906 goto nla_put_failure;
18908 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
18909 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
18911 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
18912 goto nla_put_failure;
18914 nla_nest_end(msg, attr);
18916 genlmsg_end(msg, hdr);
18918 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18919 NL80211_MCGRP_MLME, gfp);
18926 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
18927 const u8 *bssid, bool preauth, gfp_t gfp)
18929 struct wireless_dev *wdev = dev->ieee80211_ptr;
18930 struct wiphy *wiphy = wdev->wiphy;
18931 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18933 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
18934 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
18936 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
18938 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
18939 struct net_device *netdev,
18940 unsigned int link_id,
18941 struct cfg80211_chan_def *chandef,
18943 enum nl80211_commands notif,
18944 u8 count, bool quiet)
18946 struct wireless_dev *wdev = netdev->ieee80211_ptr;
18947 struct sk_buff *msg;
18950 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
18954 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
18960 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
18961 goto nla_put_failure;
18963 if (wdev->valid_links &&
18964 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
18965 goto nla_put_failure;
18967 if (nl80211_send_chandef(msg, chandef))
18968 goto nla_put_failure;
18970 if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) {
18971 if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))
18972 goto nla_put_failure;
18974 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))
18975 goto nla_put_failure;
18978 genlmsg_end(msg, hdr);
18980 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
18981 NL80211_MCGRP_MLME, gfp);
18988 void cfg80211_ch_switch_notify(struct net_device *dev,
18989 struct cfg80211_chan_def *chandef,
18990 unsigned int link_id)
18992 struct wireless_dev *wdev = dev->ieee80211_ptr;
18993 struct wiphy *wiphy = wdev->wiphy;
18994 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
18996 ASSERT_WDEV_LOCK(wdev);
18997 WARN_INVALID_LINK_ID(wdev, link_id);
18999 trace_cfg80211_ch_switch_notify(dev, chandef, link_id);
19001 switch (wdev->iftype) {
19002 case NL80211_IFTYPE_STATION:
19003 case NL80211_IFTYPE_P2P_CLIENT:
19004 if (!WARN_ON(!wdev->links[link_id].client.current_bss))
19005 cfg80211_update_assoc_bss_entry(wdev, link_id,
19008 case NL80211_IFTYPE_MESH_POINT:
19009 wdev->u.mesh.chandef = *chandef;
19010 wdev->u.mesh.preset_chandef = *chandef;
19012 case NL80211_IFTYPE_AP:
19013 case NL80211_IFTYPE_P2P_GO:
19014 wdev->links[link_id].ap.chandef = *chandef;
19016 case NL80211_IFTYPE_ADHOC:
19017 wdev->u.ibss.chandef = *chandef;
19024 cfg80211_sched_dfs_chan_update(rdev);
19026 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL,
19027 NL80211_CMD_CH_SWITCH_NOTIFY, 0, false);
19029 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
19031 void cfg80211_ch_switch_started_notify(struct net_device *dev,
19032 struct cfg80211_chan_def *chandef,
19033 unsigned int link_id, u8 count,
19036 struct wireless_dev *wdev = dev->ieee80211_ptr;
19037 struct wiphy *wiphy = wdev->wiphy;
19038 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19040 ASSERT_WDEV_LOCK(wdev);
19041 WARN_INVALID_LINK_ID(wdev, link_id);
19043 trace_cfg80211_ch_switch_started_notify(dev, chandef, link_id);
19045 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL,
19046 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY,
19049 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
19051 int cfg80211_bss_color_notify(struct net_device *dev, gfp_t gfp,
19052 enum nl80211_commands cmd, u8 count,
19055 struct wireless_dev *wdev = dev->ieee80211_ptr;
19056 struct wiphy *wiphy = wdev->wiphy;
19057 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19058 struct sk_buff *msg;
19061 ASSERT_WDEV_LOCK(wdev);
19063 trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap);
19065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19069 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
19071 goto nla_put_failure;
19073 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19074 goto nla_put_failure;
19076 if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED &&
19077 nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count))
19078 goto nla_put_failure;
19080 if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION &&
19081 nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP,
19082 color_bitmap, NL80211_ATTR_PAD))
19083 goto nla_put_failure;
19085 genlmsg_end(msg, hdr);
19087 return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
19088 msg, 0, NL80211_MCGRP_MLME, gfp);
19094 EXPORT_SYMBOL(cfg80211_bss_color_notify);
19097 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
19098 const struct cfg80211_chan_def *chandef,
19099 enum nl80211_radar_event event,
19100 struct net_device *netdev, gfp_t gfp)
19102 struct sk_buff *msg;
19105 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19109 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
19115 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
19116 goto nla_put_failure;
19118 /* NOP and radar events don't need a netdev parameter */
19120 struct wireless_dev *wdev = netdev->ieee80211_ptr;
19122 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19123 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19125 goto nla_put_failure;
19128 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
19129 goto nla_put_failure;
19131 if (nl80211_send_chandef(msg, chandef))
19132 goto nla_put_failure;
19134 genlmsg_end(msg, hdr);
19136 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19137 NL80211_MCGRP_MLME, gfp);
19144 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
19145 struct sta_opmode_info *sta_opmode,
19148 struct sk_buff *msg;
19149 struct wireless_dev *wdev = dev->ieee80211_ptr;
19150 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19156 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19160 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
19166 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
19167 goto nla_put_failure;
19169 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
19170 goto nla_put_failure;
19172 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
19173 goto nla_put_failure;
19175 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
19176 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
19177 goto nla_put_failure;
19179 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
19180 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
19181 goto nla_put_failure;
19183 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
19184 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
19185 goto nla_put_failure;
19187 genlmsg_end(msg, hdr);
19189 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19190 NL80211_MCGRP_MLME, gfp);
19197 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
19199 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
19200 u64 cookie, bool acked, s32 ack_signal,
19201 bool is_valid_ack_signal, gfp_t gfp)
19203 struct wireless_dev *wdev = dev->ieee80211_ptr;
19204 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19205 struct sk_buff *msg;
19208 trace_cfg80211_probe_status(dev, addr, cookie, acked);
19210 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19215 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
19221 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19222 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19223 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
19224 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
19225 NL80211_ATTR_PAD) ||
19226 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
19227 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
19229 goto nla_put_failure;
19231 genlmsg_end(msg, hdr);
19233 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19234 NL80211_MCGRP_MLME, gfp);
19240 EXPORT_SYMBOL(cfg80211_probe_status);
19242 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
19243 size_t len, int freq, int sig_dbm)
19245 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19246 struct sk_buff *msg;
19248 struct cfg80211_beacon_registration *reg;
19250 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
19252 spin_lock_bh(&rdev->beacon_registrations_lock);
19253 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
19254 msg = nlmsg_new(len + 100, GFP_ATOMIC);
19256 spin_unlock_bh(&rdev->beacon_registrations_lock);
19260 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
19262 goto nla_put_failure;
19264 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19266 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
19267 KHZ_TO_MHZ(freq)) ||
19268 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
19271 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
19272 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
19273 goto nla_put_failure;
19275 genlmsg_end(msg, hdr);
19277 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
19279 spin_unlock_bh(&rdev->beacon_registrations_lock);
19283 spin_unlock_bh(&rdev->beacon_registrations_lock);
19286 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
19289 static int cfg80211_net_detect_results(struct sk_buff *msg,
19290 struct cfg80211_wowlan_wakeup *wakeup)
19292 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
19293 struct nlattr *nl_results, *nl_match, *nl_freqs;
19296 nl_results = nla_nest_start_noflag(msg,
19297 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
19301 for (i = 0; i < nd->n_matches; i++) {
19302 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
19304 nl_match = nla_nest_start_noflag(msg, i);
19308 /* The SSID attribute is optional in nl80211, but for
19309 * simplicity reasons it's always present in the
19310 * cfg80211 structure. If a driver can't pass the
19311 * SSID, that needs to be changed. A zero length SSID
19312 * is still a valid SSID (wildcard), so it cannot be
19313 * used for this purpose.
19315 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
19316 match->ssid.ssid)) {
19317 nla_nest_cancel(msg, nl_match);
19321 if (match->n_channels) {
19322 nl_freqs = nla_nest_start_noflag(msg,
19323 NL80211_ATTR_SCAN_FREQUENCIES);
19325 nla_nest_cancel(msg, nl_match);
19329 for (j = 0; j < match->n_channels; j++) {
19330 if (nla_put_u32(msg, j, match->channels[j])) {
19331 nla_nest_cancel(msg, nl_freqs);
19332 nla_nest_cancel(msg, nl_match);
19337 nla_nest_end(msg, nl_freqs);
19340 nla_nest_end(msg, nl_match);
19344 nla_nest_end(msg, nl_results);
19348 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
19349 struct cfg80211_wowlan_wakeup *wakeup,
19352 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19353 struct sk_buff *msg;
19357 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
19360 size += wakeup->packet_present_len;
19362 msg = nlmsg_new(size, gfp);
19366 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
19370 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19371 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19375 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
19376 wdev->netdev->ifindex))
19380 struct nlattr *reasons;
19382 reasons = nla_nest_start_noflag(msg,
19383 NL80211_ATTR_WOWLAN_TRIGGERS);
19387 if (wakeup->disconnect &&
19388 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
19390 if (wakeup->magic_pkt &&
19391 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
19393 if (wakeup->gtk_rekey_failure &&
19394 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
19396 if (wakeup->eap_identity_req &&
19397 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
19399 if (wakeup->four_way_handshake &&
19400 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
19402 if (wakeup->rfkill_release &&
19403 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
19406 if (wakeup->pattern_idx >= 0 &&
19407 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
19408 wakeup->pattern_idx))
19411 if (wakeup->tcp_match &&
19412 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
19415 if (wakeup->tcp_connlost &&
19416 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
19419 if (wakeup->tcp_nomoretokens &&
19421 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
19424 if (wakeup->packet) {
19425 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
19426 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
19428 if (!wakeup->packet_80211) {
19430 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
19432 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
19435 if (wakeup->packet_len &&
19436 nla_put_u32(msg, len_attr, wakeup->packet_len))
19439 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
19444 if (wakeup->net_detect &&
19445 cfg80211_net_detect_results(msg, wakeup))
19448 nla_nest_end(msg, reasons);
19451 genlmsg_end(msg, hdr);
19453 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19454 NL80211_MCGRP_MLME, gfp);
19460 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
19463 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
19464 enum nl80211_tdls_operation oper,
19465 u16 reason_code, gfp_t gfp)
19467 struct wireless_dev *wdev = dev->ieee80211_ptr;
19468 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19469 struct sk_buff *msg;
19472 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
19475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19479 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
19485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19486 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19487 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
19488 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
19489 (reason_code > 0 &&
19490 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
19491 goto nla_put_failure;
19493 genlmsg_end(msg, hdr);
19495 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19496 NL80211_MCGRP_MLME, gfp);
19502 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
19504 static int nl80211_netlink_notify(struct notifier_block * nb,
19505 unsigned long state,
19508 struct netlink_notify *notify = _notify;
19509 struct cfg80211_registered_device *rdev;
19510 struct wireless_dev *wdev;
19511 struct cfg80211_beacon_registration *reg, *tmp;
19513 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
19514 return NOTIFY_DONE;
19518 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
19519 struct cfg80211_sched_scan_request *sched_scan_req;
19521 list_for_each_entry_rcu(sched_scan_req,
19522 &rdev->sched_scan_req_list,
19524 if (sched_scan_req->owner_nlportid == notify->portid) {
19525 sched_scan_req->nl_owner_dead = true;
19526 schedule_work(&rdev->sched_scan_stop_wk);
19530 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
19531 cfg80211_mlme_unregister_socket(wdev, notify->portid);
19533 if (wdev->owner_nlportid == notify->portid) {
19534 wdev->nl_owner_dead = true;
19535 schedule_work(&rdev->destroy_work);
19536 } else if (wdev->conn_owner_nlportid == notify->portid) {
19537 schedule_work(&wdev->disconnect_wk);
19540 cfg80211_release_pmsr(wdev, notify->portid);
19543 spin_lock_bh(&rdev->beacon_registrations_lock);
19544 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
19546 if (reg->nlportid == notify->portid) {
19547 list_del(®->list);
19552 spin_unlock_bh(&rdev->beacon_registrations_lock);
19558 * It is possible that the user space process that is controlling the
19559 * indoor setting disappeared, so notify the regulatory core.
19561 regulatory_netlink_notify(notify->portid);
19565 static struct notifier_block nl80211_netlink_notifier = {
19566 .notifier_call = nl80211_netlink_notify,
19569 void cfg80211_ft_event(struct net_device *netdev,
19570 struct cfg80211_ft_event_params *ft_event)
19572 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
19573 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19574 struct sk_buff *msg;
19577 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
19579 if (!ft_event->target_ap)
19582 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
19587 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
19591 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19592 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19593 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
19596 if (ft_event->ies &&
19597 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
19599 if (ft_event->ric_ies &&
19600 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
19601 ft_event->ric_ies))
19604 genlmsg_end(msg, hdr);
19606 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19607 NL80211_MCGRP_MLME, GFP_KERNEL);
19612 EXPORT_SYMBOL(cfg80211_ft_event);
19614 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
19616 struct cfg80211_registered_device *rdev;
19617 struct sk_buff *msg;
19621 rdev = wiphy_to_rdev(wdev->wiphy);
19622 if (!rdev->crit_proto_nlportid)
19625 nlportid = rdev->crit_proto_nlportid;
19626 rdev->crit_proto_nlportid = 0;
19628 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19632 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
19634 goto nla_put_failure;
19636 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19637 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19639 goto nla_put_failure;
19641 genlmsg_end(msg, hdr);
19643 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
19649 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
19651 void nl80211_send_ap_stopped(struct wireless_dev *wdev)
19653 struct wiphy *wiphy = wdev->wiphy;
19654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19655 struct sk_buff *msg;
19658 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
19662 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
19666 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19667 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
19668 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
19672 genlmsg_end(msg, hdr);
19674 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
19675 NL80211_MCGRP_MLME, GFP_KERNEL);
19681 int cfg80211_external_auth_request(struct net_device *dev,
19682 struct cfg80211_external_auth_params *params,
19685 struct wireless_dev *wdev = dev->ieee80211_ptr;
19686 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
19687 struct sk_buff *msg;
19690 if (!wdev->conn_owner_nlportid)
19693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19697 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
19699 goto nla_put_failure;
19701 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19702 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
19703 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
19704 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
19706 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
19707 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
19708 params->ssid.ssid))
19709 goto nla_put_failure;
19711 genlmsg_end(msg, hdr);
19712 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
19713 wdev->conn_owner_nlportid);
19720 EXPORT_SYMBOL(cfg80211_external_auth_request);
19722 void cfg80211_update_owe_info_event(struct net_device *netdev,
19723 struct cfg80211_update_owe_info *owe_info,
19726 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
19727 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
19728 struct sk_buff *msg;
19731 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
19733 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
19737 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
19739 goto nla_put_failure;
19741 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
19742 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
19743 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
19744 goto nla_put_failure;
19746 if (!owe_info->ie_len ||
19747 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
19748 goto nla_put_failure;
19750 genlmsg_end(msg, hdr);
19752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
19753 NL80211_MCGRP_MLME, gfp);
19757 genlmsg_cancel(msg, hdr);
19760 EXPORT_SYMBOL(cfg80211_update_owe_info_event);
19762 /* initialisation/exit functions */
19764 int __init nl80211_init(void)
19768 err = genl_register_family(&nl80211_fam);
19772 err = netlink_register_notifier(&nl80211_netlink_notifier);
19778 genl_unregister_family(&nl80211_fam);
19782 void nl80211_exit(void)
19784 netlink_unregister_notifier(&nl80211_netlink_notifier);
19785 genl_unregister_family(&nl80211_fam);