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-2020 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 net *netns, struct nlattr **attrs)
69 struct cfg80211_registered_device *rdev;
70 struct wireless_dev *result = NULL;
71 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
72 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
79 if (!have_ifidx && !have_wdev_id)
80 return ERR_PTR(-EINVAL);
83 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
85 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
86 wiphy_idx = wdev_id >> 32;
89 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
90 struct wireless_dev *wdev;
92 if (wiphy_net(&rdev->wiphy) != netns)
95 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
98 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
99 if (have_ifidx && wdev->netdev &&
100 wdev->netdev->ifindex == ifidx) {
104 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
116 return ERR_PTR(-ENODEV);
119 static struct cfg80211_registered_device *
120 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
122 struct cfg80211_registered_device *rdev = NULL, *tmp;
123 struct net_device *netdev;
127 if (!attrs[NL80211_ATTR_WIPHY] &&
128 !attrs[NL80211_ATTR_IFINDEX] &&
129 !attrs[NL80211_ATTR_WDEV])
130 return ERR_PTR(-EINVAL);
132 if (attrs[NL80211_ATTR_WIPHY])
133 rdev = cfg80211_rdev_by_wiphy_idx(
134 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
136 if (attrs[NL80211_ATTR_WDEV]) {
137 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
138 struct wireless_dev *wdev;
141 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
143 /* make sure wdev exists */
144 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
145 if (wdev->identifier != (u32)wdev_id)
154 if (rdev && tmp != rdev)
155 return ERR_PTR(-EINVAL);
160 if (attrs[NL80211_ATTR_IFINDEX]) {
161 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
163 netdev = __dev_get_by_index(netns, ifindex);
165 if (netdev->ieee80211_ptr)
167 netdev->ieee80211_ptr->wiphy);
171 /* not wireless device -- return error */
173 return ERR_PTR(-EINVAL);
175 /* mismatch -- return error */
176 if (rdev && tmp != rdev)
177 return ERR_PTR(-EINVAL);
184 return ERR_PTR(-ENODEV);
186 if (netns != wiphy_net(&rdev->wiphy))
187 return ERR_PTR(-ENODEV);
193 * This function returns a pointer to the driver
194 * that the genl_info item that is passed refers to.
196 * The result of this can be a PTR_ERR and hence must
197 * be checked with IS_ERR() for errors.
199 static struct cfg80211_registered_device *
200 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
202 return __cfg80211_rdev_from_attrs(netns, info->attrs);
205 static int validate_beacon_head(const struct nlattr *attr,
206 struct netlink_ext_ack *extack)
208 const u8 *data = nla_data(attr);
209 unsigned int len = nla_len(attr);
210 const struct element *elem;
211 const struct ieee80211_mgmt *mgmt = (void *)data;
212 bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
213 unsigned int fixedlen, hdrlen;
216 fixedlen = offsetof(struct ieee80211_ext,
217 u.s1g_beacon.variable);
218 hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon);
220 fixedlen = offsetof(struct ieee80211_mgmt,
222 hdrlen = offsetof(struct ieee80211_mgmt, u.beacon);
228 if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen)
234 for_each_element(elem, data, len) {
238 if (for_each_element_completed(elem, data, len))
242 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
246 static int validate_ie_attr(const struct nlattr *attr,
247 struct netlink_ext_ack *extack)
249 const u8 *data = nla_data(attr);
250 unsigned int len = nla_len(attr);
251 const struct element *elem;
253 for_each_element(elem, data, len) {
257 if (for_each_element_completed(elem, data, len))
260 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
264 /* policy for the attributes */
265 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR];
267 static const struct nla_policy
268 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = {
269 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, },
270 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY,
272 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY,
276 static const struct nla_policy
277 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
278 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG },
279 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 },
280 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] =
281 NLA_POLICY_MAX(NLA_U8, 15),
282 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 },
283 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] =
284 NLA_POLICY_MAX(NLA_U8, 15),
285 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] =
286 NLA_POLICY_MAX(NLA_U8, 31),
287 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 },
288 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG },
289 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG },
290 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG },
291 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG },
294 static const struct nla_policy
295 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
296 [NL80211_PMSR_TYPE_FTM] =
297 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
300 static const struct nla_policy
301 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
302 [NL80211_PMSR_REQ_ATTR_DATA] =
303 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
304 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
307 static const struct nla_policy
308 nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
309 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
310 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy),
311 [NL80211_PMSR_PEER_ATTR_REQ] =
312 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
313 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
316 static const struct nla_policy
317 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
318 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
319 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
320 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
321 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
322 [NL80211_PMSR_ATTR_PEERS] =
323 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy),
326 static const struct nla_policy
327 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = {
328 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] =
329 NLA_POLICY_RANGE(NLA_U8, 1, 20),
330 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] =
331 NLA_POLICY_RANGE(NLA_U8, 1, 20),
332 [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] =
333 NLA_POLICY_RANGE(NLA_U8, 1, 20),
334 [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] =
335 NLA_POLICY_EXACT_LEN(8),
336 [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] =
337 NLA_POLICY_EXACT_LEN(8),
338 [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 },
341 static const struct nla_policy
342 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = {
343 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63),
344 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG },
345 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG },
348 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
349 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
350 .len = NL80211_MAX_SUPP_RATES },
351 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
352 .len = NL80211_MAX_SUPP_HT_RATES },
353 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)),
354 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
355 [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)),
356 [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8,
357 NL80211_RATE_INFO_HE_GI_0_8,
358 NL80211_RATE_INFO_HE_GI_3_2),
359 [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8,
360 NL80211_RATE_INFO_HE_1XLTF,
361 NL80211_RATE_INFO_HE_4XLTF),
364 static const struct nla_policy
365 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = {
366 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 },
367 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 },
368 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG },
369 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff),
370 [NL80211_TID_CONFIG_ATTR_NOACK] =
371 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
372 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
373 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
374 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] =
375 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
376 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] =
377 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
378 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] =
379 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
380 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] =
381 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED),
382 [NL80211_TID_CONFIG_ATTR_TX_RATE] =
383 NLA_POLICY_NESTED(nl80211_txattr_policy),
386 static const struct nla_policy
387 nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = {
388 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000),
389 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000),
390 NLA_POLICY_RANGE(NLA_BINARY,
391 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN,
392 IEEE80211_MAX_DATA_LEN),
395 static const struct nla_policy
396 nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = {
397 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20),
398 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY,
399 .len = IEEE80211_MAX_DATA_LEN }
402 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
403 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
404 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
405 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
407 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
409 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
410 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
411 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
412 NL80211_EDMG_CHANNELS_MIN,
413 NL80211_EDMG_CHANNELS_MAX),
414 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
415 NL80211_EDMG_BW_CONFIG_MIN,
416 NL80211_EDMG_BW_CONFIG_MAX),
418 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
419 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
420 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
421 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
423 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
424 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
425 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
426 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
427 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
428 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
430 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
431 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
432 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
434 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
435 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
437 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
438 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
439 .len = WLAN_MAX_KEY_LEN },
440 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
441 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
442 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
443 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
444 [NL80211_ATTR_KEY_TYPE] =
445 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
447 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
448 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
449 [NL80211_ATTR_BEACON_HEAD] =
450 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
451 IEEE80211_MAX_DATA_LEN),
452 [NL80211_ATTR_BEACON_TAIL] =
453 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
454 IEEE80211_MAX_DATA_LEN),
455 [NL80211_ATTR_STA_AID] =
456 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
457 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
458 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
459 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
460 .len = NL80211_MAX_SUPP_RATES },
461 [NL80211_ATTR_STA_PLINK_ACTION] =
462 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
463 [NL80211_ATTR_STA_TX_POWER_SETTING] =
464 NLA_POLICY_RANGE(NLA_U8,
465 NL80211_TX_POWER_AUTOMATIC,
466 NL80211_TX_POWER_FIXED),
467 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
468 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
469 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
470 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
471 .len = IEEE80211_MAX_MESH_ID_LEN },
472 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
474 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
475 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
477 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
478 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
479 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
480 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
481 .len = NL80211_MAX_SUPP_RATES },
482 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
484 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
485 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
487 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN),
489 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
490 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
492 IEEE80211_MAX_DATA_LEN),
493 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
494 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
496 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
497 .len = IEEE80211_MAX_SSID_LEN },
498 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
499 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
500 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
501 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
502 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
504 NL80211_MFP_OPTIONAL),
505 [NL80211_ATTR_STA_FLAGS2] = {
506 .len = sizeof(struct nl80211_sta_flag_update),
508 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
509 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
510 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
511 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
512 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
513 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
514 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
515 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
516 [NL80211_ATTR_PID] = { .type = NLA_U32 },
517 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
518 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN),
519 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
520 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
521 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
522 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
523 .len = IEEE80211_MAX_DATA_LEN },
524 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
525 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
528 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
529 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
530 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
531 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
532 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
533 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
534 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
535 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
536 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
537 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
538 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
539 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
540 [NL80211_ATTR_STA_PLINK_STATE] =
541 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
542 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
543 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
544 [NL80211_ATTR_MESH_PEER_AID] =
545 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
546 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
547 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
548 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
549 [NL80211_ATTR_HIDDEN_SSID] =
550 NLA_POLICY_RANGE(NLA_U32,
551 NL80211_HIDDEN_SSID_NOT_IN_USE,
552 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
553 [NL80211_ATTR_IE_PROBE_RESP] =
554 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
555 IEEE80211_MAX_DATA_LEN),
556 [NL80211_ATTR_IE_ASSOC_RESP] =
557 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
558 IEEE80211_MAX_DATA_LEN),
559 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
560 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
561 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
562 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
563 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
564 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
565 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
566 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
567 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
568 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
569 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
570 .len = IEEE80211_MAX_DATA_LEN },
571 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
572 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
573 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
574 .len = NL80211_HT_CAPABILITY_LEN
576 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
577 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
578 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
579 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
580 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
582 /* need to include at least Auth Transaction and Status Code */
583 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4),
585 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN),
586 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
587 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
588 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
589 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
590 NLA_POLICY_RANGE(NLA_U32,
591 NL80211_MESH_POWER_UNKNOWN + 1,
592 NL80211_MESH_POWER_MAX),
593 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
594 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
595 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
596 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
597 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
598 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
599 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
600 .len = NL80211_VHT_CAPABILITY_LEN,
602 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
603 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
604 .len = IEEE80211_MAX_DATA_LEN },
605 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
606 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] =
607 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION),
608 [NL80211_ATTR_PEER_AID] =
609 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
610 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
611 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
612 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
613 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY },
614 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY },
615 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2),
617 * The value of the Length field of the Supported Operating
618 * Classes element is between 2 and 253.
620 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] =
621 NLA_POLICY_RANGE(NLA_BINARY, 2, 253),
622 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
623 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
624 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
625 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
626 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
627 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY,
628 IEEE80211_QOS_MAP_LEN_MIN,
629 IEEE80211_QOS_MAP_LEN_MAX),
630 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
631 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
632 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
633 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
634 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
635 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
636 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
637 [NL80211_ATTR_USER_PRIO] =
638 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
639 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
640 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
641 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
642 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
643 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
644 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
645 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
646 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
647 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
648 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
649 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
650 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
651 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
652 .len = VHT_MUMIMO_GROUPS_DATA_LEN
654 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
655 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
656 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
657 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
658 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
659 .len = FILS_MAX_KEK_LEN },
660 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN),
661 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
662 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
663 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
664 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
665 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
667 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
668 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
669 .len = FILS_ERP_MAX_USERNAME_LEN },
670 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
671 .len = FILS_ERP_MAX_REALM_LEN },
672 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
673 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
674 .len = FILS_ERP_MAX_RRK_LEN },
675 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2),
676 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
677 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN),
678 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
679 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
681 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
682 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
683 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
684 [NL80211_ATTR_HE_CAPABILITY] =
685 NLA_POLICY_RANGE(NLA_BINARY,
686 NL80211_HE_MIN_CAPABILITY_LEN,
687 NL80211_HE_MAX_CAPABILITY_LEN),
688 [NL80211_ATTR_FTM_RESPONDER] =
689 NLA_POLICY_NESTED(nl80211_ftm_responder_policy),
690 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
691 [NL80211_ATTR_PEER_MEASUREMENTS] =
692 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
693 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
694 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
695 .len = SAE_PASSWORD_MAX_LEN },
696 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
697 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
698 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
699 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
700 [NL80211_ATTR_TID_CONFIG] =
701 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
702 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG },
703 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1),
704 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100),
705 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG },
706 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
707 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED },
708 [NL80211_ATTR_HE_6GHZ_CAPABILITY] =
709 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)),
710 [NL80211_ATTR_FILS_DISCOVERY] =
711 NLA_POLICY_NESTED(nl80211_fils_discovery_policy),
712 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] =
713 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy),
714 [NL80211_ATTR_S1G_CAPABILITY] =
715 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
716 [NL80211_ATTR_S1G_CAPABILITY_MASK] =
717 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN),
720 /* policy for the key attributes */
721 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
722 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
723 [NL80211_KEY_IDX] = { .type = NLA_U8 },
724 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
725 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
726 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
727 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
728 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
729 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
730 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
733 /* policy for the key default flags */
734 static const struct nla_policy
735 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
736 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
737 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
741 /* policy for WoWLAN attributes */
742 static const struct nla_policy
743 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
744 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
745 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
746 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
747 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
748 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
749 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
750 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
751 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
752 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
753 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
756 static const struct nla_policy
757 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
758 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
759 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
760 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
761 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
762 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
763 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
764 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
765 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
767 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
768 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
770 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
771 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
772 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1),
774 #endif /* CONFIG_PM */
776 /* policy for coalesce rule attributes */
777 static const struct nla_policy
778 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
779 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
780 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
781 NLA_POLICY_RANGE(NLA_U32,
782 NL80211_COALESCE_CONDITION_MATCH,
783 NL80211_COALESCE_CONDITION_NO_MATCH),
784 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
787 /* policy for GTK rekey offload attributes */
788 static const struct nla_policy
789 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
790 [NL80211_REKEY_DATA_KEK] = {
792 .len = NL80211_KEK_EXT_LEN
794 [NL80211_REKEY_DATA_KCK] = {
796 .len = NL80211_KCK_EXT_LEN
798 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN),
799 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 },
802 static const struct nla_policy
803 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
804 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
805 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
806 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
807 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
810 static const struct nla_policy
811 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
812 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
813 .len = IEEE80211_MAX_SSID_LEN },
814 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
815 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
816 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
817 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
820 static const struct nla_policy
821 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
822 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
823 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
826 static const struct nla_policy
827 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
828 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
829 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
830 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
831 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
835 /* policy for NAN function attributes */
836 static const struct nla_policy
837 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
838 [NL80211_NAN_FUNC_TYPE] =
839 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE),
840 [NL80211_NAN_FUNC_SERVICE_ID] = {
841 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
842 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
843 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
844 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
845 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
846 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
847 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
848 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
849 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
850 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
851 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
852 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
853 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
854 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
855 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
856 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
859 /* policy for Service Response Filter attributes */
860 static const struct nla_policy
861 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
862 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
863 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
864 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
865 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
866 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
869 /* policy for packet pattern attributes */
870 static const struct nla_policy
871 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
872 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
873 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
874 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
877 int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
878 struct cfg80211_registered_device **rdev,
879 struct wireless_dev **wdev)
884 struct nlattr **attrbuf;
886 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
891 err = nlmsg_parse_deprecated(cb->nlh,
892 GENL_HDRLEN + nl80211_fam.hdrsize,
893 attrbuf, nl80211_fam.maxattr,
894 nl80211_policy, NULL);
900 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
904 return PTR_ERR(*wdev);
905 *rdev = wiphy_to_rdev((*wdev)->wiphy);
906 /* 0 is the first index - add 1 to parse only once */
907 cb->args[0] = (*rdev)->wiphy_idx + 1;
908 cb->args[1] = (*wdev)->identifier;
910 /* subtract the 1 again here */
911 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
912 struct wireless_dev *tmp;
916 *rdev = wiphy_to_rdev(wiphy);
919 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
920 if (tmp->identifier == cb->args[1]) {
933 /* message building helper */
934 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
937 /* since there is no private header just add the generic one */
938 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
941 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
942 const struct ieee80211_reg_rule *rule)
945 struct nlattr *nl_wmm_rules =
946 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
949 goto nla_put_failure;
951 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
952 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
955 goto nla_put_failure;
957 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
958 rule->wmm_rule.client[j].cw_min) ||
959 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
960 rule->wmm_rule.client[j].cw_max) ||
961 nla_put_u8(msg, NL80211_WMMR_AIFSN,
962 rule->wmm_rule.client[j].aifsn) ||
963 nla_put_u16(msg, NL80211_WMMR_TXOP,
964 rule->wmm_rule.client[j].cot))
965 goto nla_put_failure;
967 nla_nest_end(msg, nl_wmm_rule);
969 nla_nest_end(msg, nl_wmm_rules);
977 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
978 struct ieee80211_channel *chan,
981 /* Some channels must be completely excluded from the
982 * list to protect old user-space tools from breaking
984 if (!large && chan->flags &
985 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
987 if (!large && chan->freq_offset)
990 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
992 goto nla_put_failure;
994 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
995 goto nla_put_failure;
997 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
998 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
999 goto nla_put_failure;
1000 if (chan->flags & IEEE80211_CHAN_NO_IR) {
1001 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
1002 goto nla_put_failure;
1003 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
1004 goto nla_put_failure;
1006 if (chan->flags & IEEE80211_CHAN_RADAR) {
1007 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
1008 goto nla_put_failure;
1012 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
1014 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
1016 goto nla_put_failure;
1017 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
1019 goto nla_put_failure;
1020 if (nla_put_u32(msg,
1021 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
1023 goto nla_put_failure;
1028 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
1029 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
1030 goto nla_put_failure;
1031 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
1032 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
1033 goto nla_put_failure;
1034 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
1035 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
1036 goto nla_put_failure;
1037 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
1038 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
1039 goto nla_put_failure;
1040 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
1041 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
1042 goto nla_put_failure;
1043 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
1044 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
1045 goto nla_put_failure;
1046 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
1047 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
1048 goto nla_put_failure;
1049 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
1050 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
1051 goto nla_put_failure;
1052 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
1053 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
1054 goto nla_put_failure;
1055 if ((chan->flags & IEEE80211_CHAN_1MHZ) &&
1056 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ))
1057 goto nla_put_failure;
1058 if ((chan->flags & IEEE80211_CHAN_2MHZ) &&
1059 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ))
1060 goto nla_put_failure;
1061 if ((chan->flags & IEEE80211_CHAN_4MHZ) &&
1062 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ))
1063 goto nla_put_failure;
1064 if ((chan->flags & IEEE80211_CHAN_8MHZ) &&
1065 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ))
1066 goto nla_put_failure;
1067 if ((chan->flags & IEEE80211_CHAN_16MHZ) &&
1068 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ))
1069 goto nla_put_failure;
1072 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
1073 DBM_TO_MBM(chan->max_power)))
1074 goto nla_put_failure;
1077 const struct ieee80211_reg_rule *rule =
1078 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
1080 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
1081 if (nl80211_msg_put_wmm_rules(msg, rule))
1082 goto nla_put_failure;
1092 static bool nl80211_put_txq_stats(struct sk_buff *msg,
1093 struct cfg80211_txq_stats *txqstats,
1096 struct nlattr *txqattr;
1098 #define PUT_TXQVAL_U32(attr, memb) do { \
1099 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1100 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1104 txqattr = nla_nest_start_noflag(msg, attrtype);
1108 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1109 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1110 PUT_TXQVAL_U32(FLOWS, flows);
1111 PUT_TXQVAL_U32(DROPS, drops);
1112 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1113 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1114 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1115 PUT_TXQVAL_U32(COLLISIONS, collisions);
1116 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1117 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1118 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1119 nla_nest_end(msg, txqattr);
1121 #undef PUT_TXQVAL_U32
1125 /* netlink command implementations */
1128 struct key_params p;
1131 bool def, defmgmt, defbeacon;
1132 bool def_uni, def_multi;
1135 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1136 struct key_parse *k)
1138 struct nlattr *tb[NL80211_KEY_MAX + 1];
1139 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1145 k->def = !!tb[NL80211_KEY_DEFAULT];
1146 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1147 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
1151 k->def_multi = true;
1153 if (k->defmgmt || k->defbeacon)
1154 k->def_multi = true;
1156 if (tb[NL80211_KEY_IDX])
1157 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1159 if (tb[NL80211_KEY_DATA]) {
1160 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1161 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1164 if (tb[NL80211_KEY_SEQ]) {
1165 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1166 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1169 if (tb[NL80211_KEY_CIPHER])
1170 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1172 if (tb[NL80211_KEY_TYPE])
1173 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
1175 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1176 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1178 err = nla_parse_nested_deprecated(kdt,
1179 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1180 tb[NL80211_KEY_DEFAULT_TYPES],
1181 nl80211_key_default_policy,
1186 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1187 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1190 if (tb[NL80211_KEY_MODE])
1191 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1196 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1198 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1199 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1200 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1203 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1204 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1205 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1208 if (info->attrs[NL80211_ATTR_KEY_IDX])
1209 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1211 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1212 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1214 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1215 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1219 k->def_multi = true;
1222 k->def_multi = true;
1224 if (info->attrs[NL80211_ATTR_KEY_TYPE])
1225 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1227 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1228 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1229 int err = nla_parse_nested_deprecated(kdt,
1230 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1231 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1232 nl80211_key_default_policy,
1237 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1238 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1244 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1248 memset(k, 0, sizeof(*k));
1252 if (info->attrs[NL80211_ATTR_KEY])
1253 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
1255 err = nl80211_parse_key_old(info, k);
1260 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1261 (k->defbeacon ? 1 : 0) > 1) {
1262 GENL_SET_ERR_MSG(info,
1263 "key with multiple default flags is invalid");
1267 if (k->defmgmt || k->defbeacon) {
1268 if (k->def_uni || !k->def_multi) {
1269 GENL_SET_ERR_MSG(info,
1270 "defmgmt/defbeacon key must be mcast");
1277 if (k->idx < 4 || k->idx > 5) {
1278 GENL_SET_ERR_MSG(info,
1279 "defmgmt key idx not 4 or 5");
1282 } else if (k->defbeacon) {
1283 if (k->idx < 6 || k->idx > 7) {
1284 GENL_SET_ERR_MSG(info,
1285 "defbeacon key idx not 6 or 7");
1288 } else if (k->def) {
1289 if (k->idx < 0 || k->idx > 3) {
1290 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
1294 if (k->idx < 0 || k->idx > 7) {
1295 GENL_SET_ERR_MSG(info, "key idx not 0-7");
1304 static struct cfg80211_cached_keys *
1305 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
1306 struct genl_info *info, bool *no_ht)
1308 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
1309 struct key_parse parse;
1311 struct cfg80211_cached_keys *result;
1312 int rem, err, def = 0;
1313 bool have_key = false;
1315 nla_for_each_nested(key, keys, rem) {
1323 result = kzalloc(sizeof(*result), GFP_KERNEL);
1325 return ERR_PTR(-ENOMEM);
1329 nla_for_each_nested(key, keys, rem) {
1330 memset(&parse, 0, sizeof(parse));
1333 err = nl80211_parse_key_new(info, key, &parse);
1339 if (parse.idx < 0 || parse.idx > 3) {
1340 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
1345 GENL_SET_ERR_MSG(info,
1346 "only one key can be default");
1350 result->def = parse.idx;
1351 if (!parse.def_uni || !parse.def_multi)
1353 } else if (parse.defmgmt)
1355 err = cfg80211_validate_key_settings(rdev, &parse.p,
1356 parse.idx, false, NULL);
1359 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1360 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
1361 GENL_SET_ERR_MSG(info, "connect key must be WEP");
1365 result->params[parse.idx].cipher = parse.p.cipher;
1366 result->params[parse.idx].key_len = parse.p.key_len;
1367 result->params[parse.idx].key = result->data[parse.idx];
1368 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
1370 /* must be WEP key if we got here */
1375 if (result->def < 0) {
1377 GENL_SET_ERR_MSG(info, "need a default/TX key");
1384 return ERR_PTR(err);
1387 static int nl80211_key_allowed(struct wireless_dev *wdev)
1389 ASSERT_WDEV_LOCK(wdev);
1391 switch (wdev->iftype) {
1392 case NL80211_IFTYPE_AP:
1393 case NL80211_IFTYPE_AP_VLAN:
1394 case NL80211_IFTYPE_P2P_GO:
1395 case NL80211_IFTYPE_MESH_POINT:
1397 case NL80211_IFTYPE_ADHOC:
1398 case NL80211_IFTYPE_STATION:
1399 case NL80211_IFTYPE_P2P_CLIENT:
1400 if (!wdev->current_bss)
1403 case NL80211_IFTYPE_UNSPECIFIED:
1404 case NL80211_IFTYPE_OCB:
1405 case NL80211_IFTYPE_MONITOR:
1406 case NL80211_IFTYPE_NAN:
1407 case NL80211_IFTYPE_P2P_DEVICE:
1408 case NL80211_IFTYPE_WDS:
1409 case NUM_NL80211_IFTYPES:
1416 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1419 struct ieee80211_channel *chan;
1421 chan = ieee80211_get_channel_khz(wiphy, freq);
1422 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1427 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1429 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
1433 goto nla_put_failure;
1437 if ((ifmodes & 1) && nla_put_flag(msg, i))
1438 goto nla_put_failure;
1443 nla_nest_end(msg, nl_modes);
1450 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1451 struct sk_buff *msg,
1454 struct nlattr *nl_combis;
1457 nl_combis = nla_nest_start_noflag(msg,
1458 NL80211_ATTR_INTERFACE_COMBINATIONS);
1460 goto nla_put_failure;
1462 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1463 const struct ieee80211_iface_combination *c;
1464 struct nlattr *nl_combi, *nl_limits;
1466 c = &wiphy->iface_combinations[i];
1468 nl_combi = nla_nest_start_noflag(msg, i + 1);
1470 goto nla_put_failure;
1472 nl_limits = nla_nest_start_noflag(msg,
1473 NL80211_IFACE_COMB_LIMITS);
1475 goto nla_put_failure;
1477 for (j = 0; j < c->n_limits; j++) {
1478 struct nlattr *nl_limit;
1480 nl_limit = nla_nest_start_noflag(msg, j + 1);
1482 goto nla_put_failure;
1483 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1485 goto nla_put_failure;
1486 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1487 c->limits[j].types))
1488 goto nla_put_failure;
1489 nla_nest_end(msg, nl_limit);
1492 nla_nest_end(msg, nl_limits);
1494 if (c->beacon_int_infra_match &&
1495 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1496 goto nla_put_failure;
1497 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1498 c->num_different_channels) ||
1499 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1501 goto nla_put_failure;
1503 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1504 c->radar_detect_widths) ||
1505 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1506 c->radar_detect_regions)))
1507 goto nla_put_failure;
1508 if (c->beacon_int_min_gcd &&
1509 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1510 c->beacon_int_min_gcd))
1511 goto nla_put_failure;
1513 nla_nest_end(msg, nl_combi);
1516 nla_nest_end(msg, nl_combis);
1524 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1525 struct sk_buff *msg)
1527 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
1528 struct nlattr *nl_tcp;
1533 nl_tcp = nla_nest_start_noflag(msg,
1534 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1538 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1539 tcp->data_payload_max))
1542 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1543 tcp->data_payload_max))
1546 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1549 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1550 sizeof(*tcp->tok), tcp->tok))
1553 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1554 tcp->data_interval_max))
1557 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1558 tcp->wake_payload_max))
1561 nla_nest_end(msg, nl_tcp);
1565 static int nl80211_send_wowlan(struct sk_buff *msg,
1566 struct cfg80211_registered_device *rdev,
1569 struct nlattr *nl_wowlan;
1571 if (!rdev->wiphy.wowlan)
1574 nl_wowlan = nla_nest_start_noflag(msg,
1575 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1579 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
1580 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1581 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
1582 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1583 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1584 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1585 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1586 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1587 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1588 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1589 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1590 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1591 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1592 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1593 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1594 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1597 if (rdev->wiphy.wowlan->n_patterns) {
1598 struct nl80211_pattern_support pat = {
1599 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1600 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1601 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1602 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
1605 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1610 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1611 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1612 rdev->wiphy.wowlan->max_nd_match_sets))
1615 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
1618 nla_nest_end(msg, nl_wowlan);
1624 static int nl80211_send_coalesce(struct sk_buff *msg,
1625 struct cfg80211_registered_device *rdev)
1627 struct nl80211_coalesce_rule_support rule;
1629 if (!rdev->wiphy.coalesce)
1632 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1633 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1634 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1635 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1636 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1637 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
1639 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1646 nl80211_send_iftype_data(struct sk_buff *msg,
1647 const struct ieee80211_supported_band *sband,
1648 const struct ieee80211_sband_iftype_data *iftdata)
1650 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1652 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1653 iftdata->types_mask))
1656 if (he_cap->has_he) {
1657 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1658 sizeof(he_cap->he_cap_elem.mac_cap_info),
1659 he_cap->he_cap_elem.mac_cap_info) ||
1660 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1661 sizeof(he_cap->he_cap_elem.phy_cap_info),
1662 he_cap->he_cap_elem.phy_cap_info) ||
1663 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1664 sizeof(he_cap->he_mcs_nss_supp),
1665 &he_cap->he_mcs_nss_supp) ||
1666 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1667 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1671 if (sband->band == NL80211_BAND_6GHZ &&
1672 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA,
1673 sizeof(iftdata->he_6ghz_capa),
1674 &iftdata->he_6ghz_capa))
1680 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1681 struct ieee80211_supported_band *sband,
1684 struct nlattr *nl_rates, *nl_rate;
1685 struct ieee80211_rate *rate;
1689 if (sband->ht_cap.ht_supported &&
1690 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1691 sizeof(sband->ht_cap.mcs),
1692 &sband->ht_cap.mcs) ||
1693 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1694 sband->ht_cap.cap) ||
1695 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1696 sband->ht_cap.ampdu_factor) ||
1697 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1698 sband->ht_cap.ampdu_density)))
1702 if (sband->vht_cap.vht_supported &&
1703 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1704 sizeof(sband->vht_cap.vht_mcs),
1705 &sband->vht_cap.vht_mcs) ||
1706 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1707 sband->vht_cap.cap)))
1710 if (large && sband->n_iftype_data) {
1711 struct nlattr *nl_iftype_data =
1712 nla_nest_start_noflag(msg,
1713 NL80211_BAND_ATTR_IFTYPE_DATA);
1716 if (!nl_iftype_data)
1719 for (i = 0; i < sband->n_iftype_data; i++) {
1720 struct nlattr *iftdata;
1722 iftdata = nla_nest_start_noflag(msg, i + 1);
1726 err = nl80211_send_iftype_data(msg, sband,
1727 &sband->iftype_data[i]);
1731 nla_nest_end(msg, iftdata);
1734 nla_nest_end(msg, nl_iftype_data);
1738 if (large && sband->edmg_cap.channels &&
1739 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1740 sband->edmg_cap.channels) ||
1741 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1742 sband->edmg_cap.bw_config)))
1747 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
1751 for (i = 0; i < sband->n_bitrates; i++) {
1752 nl_rate = nla_nest_start_noflag(msg, i);
1756 rate = &sband->bitrates[i];
1757 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1760 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1762 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1765 nla_nest_end(msg, nl_rate);
1768 nla_nest_end(msg, nl_rates);
1774 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1775 const struct ieee80211_txrx_stypes *mgmt_stypes)
1778 struct nlattr *nl_ftypes, *nl_ifs;
1779 enum nl80211_iftype ift;
1785 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
1789 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1790 nl_ftypes = nla_nest_start_noflag(msg, ift);
1794 stypes = mgmt_stypes[ift].tx;
1797 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1798 (i << 4) | IEEE80211_FTYPE_MGMT))
1803 nla_nest_end(msg, nl_ftypes);
1806 nla_nest_end(msg, nl_ifs);
1808 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
1812 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1813 nl_ftypes = nla_nest_start_noflag(msg, ift);
1817 stypes = mgmt_stypes[ift].rx;
1820 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1821 (i << 4) | IEEE80211_FTYPE_MGMT))
1826 nla_nest_end(msg, nl_ftypes);
1828 nla_nest_end(msg, nl_ifs);
1833 #define CMD(op, n) \
1835 if (rdev->ops->op) { \
1837 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1838 goto nla_put_failure; \
1842 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1843 struct sk_buff *msg)
1848 * do *NOT* add anything into this function, new things need to be
1849 * advertised only to new versions of userspace that can deal with
1850 * the split (and they can't possibly care about new features...
1852 CMD(add_virtual_intf, NEW_INTERFACE);
1853 CMD(change_virtual_intf, SET_INTERFACE);
1854 CMD(add_key, NEW_KEY);
1855 CMD(start_ap, START_AP);
1856 CMD(add_station, NEW_STATION);
1857 CMD(add_mpath, NEW_MPATH);
1858 CMD(update_mesh_config, SET_MESH_CONFIG);
1859 CMD(change_bss, SET_BSS);
1860 CMD(auth, AUTHENTICATE);
1861 CMD(assoc, ASSOCIATE);
1862 CMD(deauth, DEAUTHENTICATE);
1863 CMD(disassoc, DISASSOCIATE);
1864 CMD(join_ibss, JOIN_IBSS);
1865 CMD(join_mesh, JOIN_MESH);
1866 CMD(set_pmksa, SET_PMKSA);
1867 CMD(del_pmksa, DEL_PMKSA);
1868 CMD(flush_pmksa, FLUSH_PMKSA);
1869 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1870 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1871 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1872 CMD(mgmt_tx, FRAME);
1873 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1874 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1876 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1877 goto nla_put_failure;
1879 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1880 rdev->ops->join_mesh) {
1882 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1883 goto nla_put_failure;
1885 CMD(set_wds_peer, SET_WDS_PEER);
1886 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1887 CMD(tdls_mgmt, TDLS_MGMT);
1888 CMD(tdls_oper, TDLS_OPER);
1890 if (rdev->wiphy.max_sched_scan_reqs)
1891 CMD(sched_scan_start, START_SCHED_SCAN);
1892 CMD(probe_client, PROBE_CLIENT);
1893 CMD(set_noack_map, SET_NOACK_MAP);
1894 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1896 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1897 goto nla_put_failure;
1899 CMD(start_p2p_device, START_P2P_DEVICE);
1900 CMD(set_mcast_rate, SET_MCAST_RATE);
1901 #ifdef CONFIG_NL80211_TESTMODE
1902 CMD(testmode_cmd, TESTMODE);
1905 if (rdev->ops->connect || rdev->ops->auth) {
1907 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1908 goto nla_put_failure;
1911 if (rdev->ops->disconnect || rdev->ops->deauth) {
1913 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1914 goto nla_put_failure;
1923 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1924 struct sk_buff *msg)
1928 if (!cap->ftm.supported)
1931 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
1935 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1937 if (cap->ftm.non_asap &&
1938 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1940 if (cap->ftm.request_lci &&
1941 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1943 if (cap->ftm.request_civicloc &&
1944 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1946 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1947 cap->ftm.preambles))
1949 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1950 cap->ftm.bandwidths))
1952 if (cap->ftm.max_bursts_exponent >= 0 &&
1953 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1954 cap->ftm.max_bursts_exponent))
1956 if (cap->ftm.max_ftms_per_burst &&
1957 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1958 cap->ftm.max_ftms_per_burst))
1960 if (cap->ftm.trigger_based &&
1961 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED))
1963 if (cap->ftm.non_trigger_based &&
1964 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED))
1967 nla_nest_end(msg, ftm);
1971 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1972 struct sk_buff *msg)
1974 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1975 struct nlattr *pmsr, *caps;
1981 * we don't need to clean up anything here since the caller
1982 * will genlmsg_cancel() if we fail
1985 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
1989 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1992 if (cap->report_ap_tsf &&
1993 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1996 if (cap->randomize_mac_addr &&
1997 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
2000 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
2004 if (nl80211_send_pmsr_ftm_capa(cap, msg))
2007 nla_nest_end(msg, caps);
2008 nla_nest_end(msg, pmsr);
2014 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev,
2015 struct sk_buff *msg)
2018 struct nlattr *nested, *nested_akms;
2019 const struct wiphy_iftype_akm_suites *iftype_akms;
2021 if (!rdev->wiphy.num_iftype_akm_suites ||
2022 !rdev->wiphy.iftype_akm_suites)
2025 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES);
2029 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) {
2030 nested_akms = nla_nest_start(msg, i + 1);
2034 iftype_akms = &rdev->wiphy.iftype_akm_suites[i];
2036 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES,
2037 iftype_akms->iftypes_mask))
2040 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES,
2041 sizeof(u32) * iftype_akms->n_akm_suites,
2042 iftype_akms->akm_suites)) {
2045 nla_nest_end(msg, nested_akms);
2048 nla_nest_end(msg, nested);
2054 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev,
2055 struct sk_buff *msg)
2057 struct nlattr *supp;
2059 if (!rdev->wiphy.tid_config_support.vif &&
2060 !rdev->wiphy.tid_config_support.peer)
2063 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG);
2067 if (rdev->wiphy.tid_config_support.vif &&
2068 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP,
2069 rdev->wiphy.tid_config_support.vif,
2070 NL80211_TID_CONFIG_ATTR_PAD))
2073 if (rdev->wiphy.tid_config_support.peer &&
2074 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP,
2075 rdev->wiphy.tid_config_support.peer,
2076 NL80211_TID_CONFIG_ATTR_PAD))
2079 /* for now we just use the same value ... makes more sense */
2080 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT,
2081 rdev->wiphy.tid_config_support.max_retry))
2083 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG,
2084 rdev->wiphy.tid_config_support.max_retry))
2087 nla_nest_end(msg, supp);
2091 nla_nest_cancel(msg, supp);
2095 struct nl80211_dump_wiphy_state {
2098 long split_start, band_start, chan_start, capa_start;
2102 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2103 enum nl80211_commands cmd,
2104 struct sk_buff *msg, u32 portid, u32 seq,
2105 int flags, struct nl80211_dump_wiphy_state *state)
2108 struct nlattr *nl_bands, *nl_band;
2109 struct nlattr *nl_freqs, *nl_freq;
2110 struct nlattr *nl_cmds;
2111 enum nl80211_band band;
2112 struct ieee80211_channel *chan;
2114 const struct ieee80211_txrx_stypes *mgmt_stypes =
2115 rdev->wiphy.mgmt_stypes;
2118 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
2122 if (WARN_ON(!state))
2125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2126 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
2127 wiphy_name(&rdev->wiphy)) ||
2128 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2129 cfg80211_rdev_list_generation))
2130 goto nla_put_failure;
2132 if (cmd != NL80211_CMD_NEW_WIPHY)
2135 switch (state->split_start) {
2137 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
2138 rdev->wiphy.retry_short) ||
2139 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
2140 rdev->wiphy.retry_long) ||
2141 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
2142 rdev->wiphy.frag_threshold) ||
2143 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
2144 rdev->wiphy.rts_threshold) ||
2145 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
2146 rdev->wiphy.coverage_class) ||
2147 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
2148 rdev->wiphy.max_scan_ssids) ||
2149 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
2150 rdev->wiphy.max_sched_scan_ssids) ||
2151 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
2152 rdev->wiphy.max_scan_ie_len) ||
2153 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
2154 rdev->wiphy.max_sched_scan_ie_len) ||
2155 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
2156 rdev->wiphy.max_match_sets))
2157 goto nla_put_failure;
2159 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
2160 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2161 goto nla_put_failure;
2162 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
2163 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2164 goto nla_put_failure;
2165 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2166 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2167 goto nla_put_failure;
2168 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
2169 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2170 goto nla_put_failure;
2171 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2172 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2173 goto nla_put_failure;
2174 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
2175 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
2176 goto nla_put_failure;
2177 state->split_start++;
2182 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
2183 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2184 rdev->wiphy.cipher_suites))
2185 goto nla_put_failure;
2187 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
2188 rdev->wiphy.max_num_pmkids))
2189 goto nla_put_failure;
2191 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
2192 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2193 goto nla_put_failure;
2195 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
2196 rdev->wiphy.available_antennas_tx) ||
2197 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
2198 rdev->wiphy.available_antennas_rx))
2199 goto nla_put_failure;
2201 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
2202 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
2203 rdev->wiphy.probe_resp_offload))
2204 goto nla_put_failure;
2206 if ((rdev->wiphy.available_antennas_tx ||
2207 rdev->wiphy.available_antennas_rx) &&
2208 rdev->ops->get_antenna) {
2209 u32 tx_ant = 0, rx_ant = 0;
2212 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
2214 if (nla_put_u32(msg,
2215 NL80211_ATTR_WIPHY_ANTENNA_TX,
2218 NL80211_ATTR_WIPHY_ANTENNA_RX,
2220 goto nla_put_failure;
2224 state->split_start++;
2229 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
2230 rdev->wiphy.interface_modes))
2231 goto nla_put_failure;
2232 state->split_start++;
2237 nl_bands = nla_nest_start_noflag(msg,
2238 NL80211_ATTR_WIPHY_BANDS);
2240 goto nla_put_failure;
2242 for (band = state->band_start;
2243 band < NUM_NL80211_BANDS; band++) {
2244 struct ieee80211_supported_band *sband;
2246 /* omit higher bands for ancient software */
2247 if (band > NL80211_BAND_5GHZ && !state->split)
2250 sband = rdev->wiphy.bands[band];
2255 nl_band = nla_nest_start_noflag(msg, band);
2257 goto nla_put_failure;
2259 switch (state->chan_start) {
2261 if (nl80211_send_band_rateinfo(msg, sband,
2263 goto nla_put_failure;
2264 state->chan_start++;
2269 /* add frequencies */
2270 nl_freqs = nla_nest_start_noflag(msg,
2271 NL80211_BAND_ATTR_FREQS);
2273 goto nla_put_failure;
2275 for (i = state->chan_start - 1;
2276 i < sband->n_channels;
2278 nl_freq = nla_nest_start_noflag(msg,
2281 goto nla_put_failure;
2283 chan = &sband->channels[i];
2285 if (nl80211_msg_put_channel(
2286 msg, &rdev->wiphy, chan,
2288 goto nla_put_failure;
2290 nla_nest_end(msg, nl_freq);
2294 if (i < sband->n_channels)
2295 state->chan_start = i + 2;
2297 state->chan_start = 0;
2298 nla_nest_end(msg, nl_freqs);
2301 nla_nest_end(msg, nl_band);
2304 /* start again here */
2305 if (state->chan_start)
2310 nla_nest_end(msg, nl_bands);
2312 if (band < NUM_NL80211_BANDS)
2313 state->band_start = band + 1;
2315 state->band_start = 0;
2317 /* if bands & channels are done, continue outside */
2318 if (state->band_start == 0 && state->chan_start == 0)
2319 state->split_start++;
2324 nl_cmds = nla_nest_start_noflag(msg,
2325 NL80211_ATTR_SUPPORTED_COMMANDS);
2327 goto nla_put_failure;
2329 i = nl80211_add_commands_unsplit(rdev, msg);
2331 goto nla_put_failure;
2333 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2334 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
2335 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
2336 CMD(channel_switch, CHANNEL_SWITCH);
2337 CMD(set_qos_map, SET_QOS_MAP);
2338 if (rdev->wiphy.features &
2339 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
2340 CMD(add_tx_ts, ADD_TX_TS);
2341 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
2342 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
2343 CMD(update_ft_ies, UPDATE_FT_IES);
2347 nla_nest_end(msg, nl_cmds);
2348 state->split_start++;
2353 if (rdev->ops->remain_on_channel &&
2354 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
2356 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
2357 rdev->wiphy.max_remain_on_channel_duration))
2358 goto nla_put_failure;
2360 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
2361 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2362 goto nla_put_failure;
2364 state->split_start++;
2370 if (nl80211_send_wowlan(msg, rdev, state->split))
2371 goto nla_put_failure;
2372 state->split_start++;
2376 state->split_start++;
2380 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
2381 rdev->wiphy.software_iftypes))
2382 goto nla_put_failure;
2384 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
2386 goto nla_put_failure;
2388 state->split_start++;
2393 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
2394 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
2395 rdev->wiphy.ap_sme_capa))
2396 goto nla_put_failure;
2398 features = rdev->wiphy.features;
2400 * We can only add the per-channel limit information if the
2401 * dump is split, otherwise it makes it too big. Therefore
2402 * only advertise it in that case.
2405 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2406 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
2407 goto nla_put_failure;
2409 if (rdev->wiphy.ht_capa_mod_mask &&
2410 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
2411 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2412 rdev->wiphy.ht_capa_mod_mask))
2413 goto nla_put_failure;
2415 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2416 rdev->wiphy.max_acl_mac_addrs &&
2417 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
2418 rdev->wiphy.max_acl_mac_addrs))
2419 goto nla_put_failure;
2422 * Any information below this point is only available to
2423 * applications that can deal with it being split. This
2424 * helps ensure that newly added capabilities don't break
2425 * older tools by overrunning their buffers.
2427 * We still increment split_start so that in the split
2428 * case we'll continue with more data in the next round,
2429 * but break unconditionally so unsplit data stops here.
2432 state->split_start++;
2434 state->split_start = 0;
2437 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2438 goto nla_put_failure;
2440 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
2441 rdev->wiphy.max_sched_scan_plans) ||
2442 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
2443 rdev->wiphy.max_sched_scan_plan_interval) ||
2444 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
2445 rdev->wiphy.max_sched_scan_plan_iterations))
2446 goto nla_put_failure;
2448 if (rdev->wiphy.extended_capabilities &&
2449 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
2450 rdev->wiphy.extended_capabilities_len,
2451 rdev->wiphy.extended_capabilities) ||
2452 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2453 rdev->wiphy.extended_capabilities_len,
2454 rdev->wiphy.extended_capabilities_mask)))
2455 goto nla_put_failure;
2457 if (rdev->wiphy.vht_capa_mod_mask &&
2458 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
2459 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2460 rdev->wiphy.vht_capa_mod_mask))
2461 goto nla_put_failure;
2463 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2464 rdev->wiphy.perm_addr))
2465 goto nla_put_failure;
2467 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2468 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2469 rdev->wiphy.addr_mask))
2470 goto nla_put_failure;
2472 if (rdev->wiphy.n_addresses > 1) {
2475 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2477 goto nla_put_failure;
2479 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2480 if (nla_put(msg, i + 1, ETH_ALEN,
2481 rdev->wiphy.addresses[i].addr))
2482 goto nla_put_failure;
2484 nla_nest_end(msg, attr);
2487 state->split_start++;
2490 if (nl80211_send_coalesce(msg, rdev))
2491 goto nla_put_failure;
2493 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
2494 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2495 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2496 goto nla_put_failure;
2498 if (rdev->wiphy.max_ap_assoc_sta &&
2499 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
2500 rdev->wiphy.max_ap_assoc_sta))
2501 goto nla_put_failure;
2503 state->split_start++;
2506 if (rdev->wiphy.n_vendor_commands) {
2507 const struct nl80211_vendor_cmd_info *info;
2508 struct nlattr *nested;
2510 nested = nla_nest_start_noflag(msg,
2511 NL80211_ATTR_VENDOR_DATA);
2513 goto nla_put_failure;
2515 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2516 info = &rdev->wiphy.vendor_commands[i].info;
2517 if (nla_put(msg, i + 1, sizeof(*info), info))
2518 goto nla_put_failure;
2520 nla_nest_end(msg, nested);
2523 if (rdev->wiphy.n_vendor_events) {
2524 const struct nl80211_vendor_cmd_info *info;
2525 struct nlattr *nested;
2527 nested = nla_nest_start_noflag(msg,
2528 NL80211_ATTR_VENDOR_EVENTS);
2530 goto nla_put_failure;
2532 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2533 info = &rdev->wiphy.vendor_events[i];
2534 if (nla_put(msg, i + 1, sizeof(*info), info))
2535 goto nla_put_failure;
2537 nla_nest_end(msg, nested);
2539 state->split_start++;
2542 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2543 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2544 rdev->wiphy.max_num_csa_counters))
2545 goto nla_put_failure;
2547 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2548 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2549 goto nla_put_failure;
2551 if (rdev->wiphy.max_sched_scan_reqs &&
2552 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2553 rdev->wiphy.max_sched_scan_reqs))
2554 goto nla_put_failure;
2556 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2557 sizeof(rdev->wiphy.ext_features),
2558 rdev->wiphy.ext_features))
2559 goto nla_put_failure;
2561 if (rdev->wiphy.bss_select_support) {
2562 struct nlattr *nested;
2563 u32 bss_select_support = rdev->wiphy.bss_select_support;
2565 nested = nla_nest_start_noflag(msg,
2566 NL80211_ATTR_BSS_SELECT);
2568 goto nla_put_failure;
2571 while (bss_select_support) {
2572 if ((bss_select_support & 1) &&
2573 nla_put_flag(msg, i))
2574 goto nla_put_failure;
2576 bss_select_support >>= 1;
2578 nla_nest_end(msg, nested);
2581 state->split_start++;
2584 if (rdev->wiphy.num_iftype_ext_capab &&
2585 rdev->wiphy.iftype_ext_capab) {
2586 struct nlattr *nested_ext_capab, *nested;
2588 nested = nla_nest_start_noflag(msg,
2589 NL80211_ATTR_IFTYPE_EXT_CAPA);
2591 goto nla_put_failure;
2593 for (i = state->capa_start;
2594 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2595 const struct wiphy_iftype_ext_capab *capab;
2597 capab = &rdev->wiphy.iftype_ext_capab[i];
2599 nested_ext_capab = nla_nest_start_noflag(msg,
2601 if (!nested_ext_capab ||
2602 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2604 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2605 capab->extended_capabilities_len,
2606 capab->extended_capabilities) ||
2607 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2608 capab->extended_capabilities_len,
2609 capab->extended_capabilities_mask))
2610 goto nla_put_failure;
2612 nla_nest_end(msg, nested_ext_capab);
2616 nla_nest_end(msg, nested);
2617 if (i < rdev->wiphy.num_iftype_ext_capab) {
2618 state->capa_start = i + 1;
2623 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2624 rdev->wiphy.nan_supported_bands))
2625 goto nla_put_failure;
2627 if (wiphy_ext_feature_isset(&rdev->wiphy,
2628 NL80211_EXT_FEATURE_TXQS)) {
2629 struct cfg80211_txq_stats txqstats = {};
2632 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2634 !nl80211_put_txq_stats(msg, &txqstats,
2635 NL80211_ATTR_TXQ_STATS))
2636 goto nla_put_failure;
2638 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2639 rdev->wiphy.txq_limit))
2640 goto nla_put_failure;
2641 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2642 rdev->wiphy.txq_memory_limit))
2643 goto nla_put_failure;
2644 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2645 rdev->wiphy.txq_quantum))
2646 goto nla_put_failure;
2649 state->split_start++;
2652 if (nl80211_send_pmsr_capa(rdev, msg))
2653 goto nla_put_failure;
2655 state->split_start++;
2658 if (rdev->wiphy.akm_suites &&
2659 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2660 sizeof(u32) * rdev->wiphy.n_akm_suites,
2661 rdev->wiphy.akm_suites))
2662 goto nla_put_failure;
2664 if (nl80211_put_iftype_akm_suites(rdev, msg))
2665 goto nla_put_failure;
2667 if (nl80211_put_tid_config_support(rdev, msg))
2668 goto nla_put_failure;
2671 state->split_start = 0;
2675 genlmsg_end(msg, hdr);
2679 genlmsg_cancel(msg, hdr);
2683 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2684 struct netlink_callback *cb,
2685 struct nl80211_dump_wiphy_state *state)
2687 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2693 ret = nlmsg_parse_deprecated(cb->nlh,
2694 GENL_HDRLEN + nl80211_fam.hdrsize,
2695 tb, nl80211_fam.maxattr,
2696 nl80211_policy, NULL);
2697 /* ignore parse errors for backward compatibility */
2703 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2704 if (tb[NL80211_ATTR_WIPHY])
2705 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2706 if (tb[NL80211_ATTR_WDEV])
2707 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2708 if (tb[NL80211_ATTR_IFINDEX]) {
2709 struct net_device *netdev;
2710 struct cfg80211_registered_device *rdev;
2711 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2713 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
2718 if (netdev->ieee80211_ptr) {
2719 rdev = wiphy_to_rdev(
2720 netdev->ieee80211_ptr->wiphy);
2721 state->filter_wiphy = rdev->wiphy_idx;
2731 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2734 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
2735 struct cfg80211_registered_device *rdev;
2739 state = kzalloc(sizeof(*state), GFP_KERNEL);
2744 state->filter_wiphy = -1;
2745 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2751 cb->args[0] = (long)state;
2754 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2755 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
2757 if (++idx <= state->start)
2759 if (state->filter_wiphy != -1 &&
2760 state->filter_wiphy != rdev->wiphy_idx)
2762 /* attempt to fit multiple wiphy data chunks into the skb */
2764 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2766 NETLINK_CB(cb->skb).portid,
2768 NLM_F_MULTI, state);
2771 * If sending the wiphy data didn't fit (ENOBUFS
2772 * or EMSGSIZE returned), this SKB is still
2773 * empty (so it's not too big because another
2774 * wiphy dataset is already in the skb) and
2775 * we've not tried to adjust the dump allocation
2776 * yet ... then adjust the alloc size to be
2777 * bigger, and return 1 but with the empty skb.
2778 * This results in an empty message being RX'ed
2779 * in userspace, but that is ignored.
2781 * We can then retry with the larger buffer.
2783 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
2784 !skb->len && !state->split &&
2785 cb->min_dump_alloc < 4096) {
2786 cb->min_dump_alloc = 4096;
2787 state->split_start = 0;
2794 } while (state->split_start > 0);
2804 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2806 kfree((void *)cb->args[0]);
2810 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2812 struct sk_buff *msg;
2813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2814 struct nl80211_dump_wiphy_state state = {};
2816 msg = nlmsg_new(4096, GFP_KERNEL);
2820 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2821 info->snd_portid, info->snd_seq, 0,
2827 return genlmsg_reply(msg, info);
2830 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2831 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2832 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2833 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2834 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2835 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2838 static int parse_txq_params(struct nlattr *tb[],
2839 struct ieee80211_txq_params *txq_params)
2843 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
2844 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2845 !tb[NL80211_TXQ_ATTR_AIFS])
2848 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
2849 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2850 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2851 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2852 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2854 if (ac >= NL80211_NUM_ACS)
2856 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
2860 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2863 * You can only set the channel explicitly for WDS interfaces,
2864 * all others have their channel managed via their respective
2865 * "establish a connection" command (connect, join, ...)
2867 * For AP/GO and mesh mode, the channel can be set with the
2868 * channel userspace API, but is only stored and passed to the
2869 * low-level driver when the AP starts or the mesh is joined.
2870 * This is for backward compatibility, userspace can also give
2871 * the channel in the start-ap or join-mesh commands instead.
2873 * Monitors are special as they are normally slaved to
2874 * whatever else is going on, so they have their own special
2875 * operation to set the monitor channel if possible.
2878 wdev->iftype == NL80211_IFTYPE_AP ||
2879 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
2880 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2881 wdev->iftype == NL80211_IFTYPE_P2P_GO;
2884 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2885 struct genl_info *info,
2886 struct cfg80211_chan_def *chandef)
2888 struct netlink_ext_ack *extack = info->extack;
2889 struct nlattr **attrs = info->attrs;
2892 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
2895 control_freq = MHZ_TO_KHZ(
2896 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2897 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
2899 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
2901 memset(chandef, 0, sizeof(*chandef));
2902 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq);
2903 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2904 chandef->center_freq1 = KHZ_TO_MHZ(control_freq);
2905 chandef->freq1_offset = control_freq % 1000;
2906 chandef->center_freq2 = 0;
2908 /* Primary channel not allowed */
2909 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2910 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2911 "Channel is disabled");
2915 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2916 enum nl80211_channel_type chantype;
2918 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2921 case NL80211_CHAN_NO_HT:
2922 case NL80211_CHAN_HT20:
2923 case NL80211_CHAN_HT40PLUS:
2924 case NL80211_CHAN_HT40MINUS:
2925 cfg80211_chandef_create(chandef, chandef->chan,
2927 /* user input for center_freq is incorrect */
2928 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2929 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2930 NL_SET_ERR_MSG_ATTR(extack,
2931 attrs[NL80211_ATTR_CENTER_FREQ1],
2932 "bad center frequency 1");
2935 /* center_freq2 must be zero */
2936 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2937 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2938 NL_SET_ERR_MSG_ATTR(extack,
2939 attrs[NL80211_ATTR_CENTER_FREQ2],
2940 "center frequency 2 can't be used");
2945 NL_SET_ERR_MSG_ATTR(extack,
2946 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2947 "invalid channel type");
2950 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2952 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2953 if (attrs[NL80211_ATTR_CENTER_FREQ1]) {
2954 chandef->center_freq1 =
2955 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2956 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET])
2957 chandef->freq1_offset = nla_get_u32(
2958 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]);
2960 chandef->freq1_offset = 0;
2962 if (attrs[NL80211_ATTR_CENTER_FREQ2])
2963 chandef->center_freq2 =
2964 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
2967 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
2968 chandef->edmg.channels =
2969 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
2971 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
2972 chandef->edmg.bw_config =
2973 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
2975 chandef->edmg.bw_config = 0;
2976 chandef->edmg.channels = 0;
2979 if (!cfg80211_chandef_valid(chandef)) {
2980 NL_SET_ERR_MSG(extack, "invalid channel definition");
2984 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2985 IEEE80211_CHAN_DISABLED)) {
2986 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
2990 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2991 chandef->width == NL80211_CHAN_WIDTH_10) &&
2992 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2993 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
3000 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
3001 struct net_device *dev,
3002 struct genl_info *info)
3004 struct cfg80211_chan_def chandef;
3006 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
3007 struct wireless_dev *wdev = NULL;
3010 wdev = dev->ieee80211_ptr;
3011 if (!nl80211_can_set_dev_channel(wdev))
3014 iftype = wdev->iftype;
3016 result = nl80211_parse_chandef(rdev, info, &chandef);
3021 case NL80211_IFTYPE_AP:
3022 case NL80211_IFTYPE_P2P_GO:
3023 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
3028 if (wdev->beacon_interval) {
3029 if (!dev || !rdev->ops->set_ap_chanwidth ||
3030 !(rdev->wiphy.features &
3031 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
3036 /* Only allow dynamic channel width changes */
3037 if (chandef.chan != wdev->preset_chandef.chan) {
3041 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
3045 wdev->preset_chandef = chandef;
3048 case NL80211_IFTYPE_MESH_POINT:
3049 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
3051 case NL80211_IFTYPE_MONITOR:
3052 result = cfg80211_set_monitor_channel(rdev, &chandef);
3061 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
3063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3064 struct net_device *netdev = info->user_ptr[1];
3066 return __nl80211_set_channel(rdev, netdev, info);
3069 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
3071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3072 struct net_device *dev = info->user_ptr[1];
3073 struct wireless_dev *wdev = dev->ieee80211_ptr;
3076 if (!info->attrs[NL80211_ATTR_MAC])
3079 if (netif_running(dev))
3082 if (!rdev->ops->set_wds_peer)
3085 if (wdev->iftype != NL80211_IFTYPE_WDS)
3088 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3089 return rdev_set_wds_peer(rdev, dev, bssid);
3092 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
3094 struct cfg80211_registered_device *rdev;
3095 struct net_device *netdev = NULL;
3096 struct wireless_dev *wdev;
3097 int result = 0, rem_txq_params = 0;
3098 struct nlattr *nl_txq_params;
3100 u8 retry_short = 0, retry_long = 0;
3101 u32 frag_threshold = 0, rts_threshold = 0;
3102 u8 coverage_class = 0;
3103 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
3108 * Try to find the wiphy and netdev. Normally this
3109 * function shouldn't need the netdev, but this is
3110 * done for backward compatibility -- previously
3111 * setting the channel was done per wiphy, but now
3112 * it is per netdev. Previous userland like hostapd
3113 * also passed a netdev to set_wiphy, so that it is
3114 * possible to let that go to the right netdev!
3117 if (info->attrs[NL80211_ATTR_IFINDEX]) {
3118 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
3120 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
3121 if (netdev && netdev->ieee80211_ptr)
3122 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
3128 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3131 return PTR_ERR(rdev);
3136 wdev = netdev->ieee80211_ptr;
3139 * end workaround code, by now the rdev is available
3140 * and locked, and wdev may or may not be NULL.
3143 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
3144 result = cfg80211_dev_rename(
3145 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
3150 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
3151 struct ieee80211_txq_params txq_params;
3152 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
3154 if (!rdev->ops->set_txq_params)
3160 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3161 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3164 if (!netif_running(netdev))
3167 nla_for_each_nested(nl_txq_params,
3168 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3170 result = nla_parse_nested_deprecated(tb,
3171 NL80211_TXQ_ATTR_MAX,
3177 result = parse_txq_params(tb, &txq_params);
3181 result = rdev_set_txq_params(rdev, netdev,
3188 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3189 result = __nl80211_set_channel(
3191 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3197 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
3198 struct wireless_dev *txp_wdev = wdev;
3199 enum nl80211_tx_power_setting type;
3202 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3205 if (!rdev->ops->set_tx_power)
3208 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
3209 type = nla_get_u32(info->attrs[idx]);
3211 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
3212 (type != NL80211_TX_POWER_AUTOMATIC))
3215 if (type != NL80211_TX_POWER_AUTOMATIC) {
3216 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
3217 mbm = nla_get_u32(info->attrs[idx]);
3220 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
3225 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3226 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3229 if ((!rdev->wiphy.available_antennas_tx &&
3230 !rdev->wiphy.available_antennas_rx) ||
3231 !rdev->ops->set_antenna)
3234 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3235 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3237 /* reject antenna configurations which don't match the
3238 * available antenna masks, except for the "all" mask */
3239 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
3240 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
3243 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3244 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
3246 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
3253 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3254 retry_short = nla_get_u8(
3255 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
3257 changed |= WIPHY_PARAM_RETRY_SHORT;
3260 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3261 retry_long = nla_get_u8(
3262 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
3264 changed |= WIPHY_PARAM_RETRY_LONG;
3267 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3268 frag_threshold = nla_get_u32(
3269 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
3270 if (frag_threshold < 256)
3273 if (frag_threshold != (u32) -1) {
3275 * Fragments (apart from the last one) are required to
3276 * have even length. Make the fragmentation code
3277 * simpler by stripping LSB should someone try to use
3278 * odd threshold value.
3280 frag_threshold &= ~0x1;
3282 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3285 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3286 rts_threshold = nla_get_u32(
3287 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3288 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3291 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
3292 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
3295 coverage_class = nla_get_u8(
3296 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3297 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3300 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3301 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
3304 changed |= WIPHY_PARAM_DYN_ACK;
3307 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3308 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3309 NL80211_EXT_FEATURE_TXQS))
3311 txq_limit = nla_get_u32(
3312 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3313 changed |= WIPHY_PARAM_TXQ_LIMIT;
3316 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3317 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3318 NL80211_EXT_FEATURE_TXQS))
3320 txq_memory_limit = nla_get_u32(
3321 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3322 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3325 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3326 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3327 NL80211_EXT_FEATURE_TXQS))
3329 txq_quantum = nla_get_u32(
3330 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3331 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3335 u8 old_retry_short, old_retry_long;
3336 u32 old_frag_threshold, old_rts_threshold;
3337 u8 old_coverage_class;
3338 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
3340 if (!rdev->ops->set_wiphy_params)
3343 old_retry_short = rdev->wiphy.retry_short;
3344 old_retry_long = rdev->wiphy.retry_long;
3345 old_frag_threshold = rdev->wiphy.frag_threshold;
3346 old_rts_threshold = rdev->wiphy.rts_threshold;
3347 old_coverage_class = rdev->wiphy.coverage_class;
3348 old_txq_limit = rdev->wiphy.txq_limit;
3349 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3350 old_txq_quantum = rdev->wiphy.txq_quantum;
3352 if (changed & WIPHY_PARAM_RETRY_SHORT)
3353 rdev->wiphy.retry_short = retry_short;
3354 if (changed & WIPHY_PARAM_RETRY_LONG)
3355 rdev->wiphy.retry_long = retry_long;
3356 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3357 rdev->wiphy.frag_threshold = frag_threshold;
3358 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3359 rdev->wiphy.rts_threshold = rts_threshold;
3360 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3361 rdev->wiphy.coverage_class = coverage_class;
3362 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3363 rdev->wiphy.txq_limit = txq_limit;
3364 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3365 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3366 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3367 rdev->wiphy.txq_quantum = txq_quantum;
3369 result = rdev_set_wiphy_params(rdev, changed);
3371 rdev->wiphy.retry_short = old_retry_short;
3372 rdev->wiphy.retry_long = old_retry_long;
3373 rdev->wiphy.frag_threshold = old_frag_threshold;
3374 rdev->wiphy.rts_threshold = old_rts_threshold;
3375 rdev->wiphy.coverage_class = old_coverage_class;
3376 rdev->wiphy.txq_limit = old_txq_limit;
3377 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3378 rdev->wiphy.txq_quantum = old_txq_quantum;
3385 static int nl80211_send_chandef(struct sk_buff *msg,
3386 const struct cfg80211_chan_def *chandef)
3388 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3391 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3392 chandef->chan->center_freq))
3394 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
3395 chandef->chan->freq_offset))
3397 switch (chandef->width) {
3398 case NL80211_CHAN_WIDTH_20_NOHT:
3399 case NL80211_CHAN_WIDTH_20:
3400 case NL80211_CHAN_WIDTH_40:
3401 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3402 cfg80211_get_chandef_type(chandef)))
3408 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3410 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3412 if (chandef->center_freq2 &&
3413 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
3418 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
3419 struct cfg80211_registered_device *rdev,
3420 struct wireless_dev *wdev,
3421 enum nl80211_commands cmd)
3423 struct net_device *dev = wdev->netdev;
3426 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3427 cmd != NL80211_CMD_DEL_INTERFACE &&
3428 cmd != NL80211_CMD_SET_INTERFACE);
3430 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
3435 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3436 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
3437 goto nla_put_failure;
3439 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3440 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
3441 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3442 NL80211_ATTR_PAD) ||
3443 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
3444 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3445 rdev->devlist_generation ^
3446 (cfg80211_rdev_list_generation << 2)) ||
3447 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
3448 goto nla_put_failure;
3450 if (rdev->ops->get_channel) {
3452 struct cfg80211_chan_def chandef = {};
3454 ret = rdev_get_channel(rdev, wdev, &chandef);
3456 if (nl80211_send_chandef(msg, &chandef))
3457 goto nla_put_failure;
3461 if (rdev->ops->get_tx_power) {
3464 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3466 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3468 goto nla_put_failure;
3472 switch (wdev->iftype) {
3473 case NL80211_IFTYPE_AP:
3474 if (wdev->ssid_len &&
3475 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
3476 goto nla_put_failure_locked;
3478 case NL80211_IFTYPE_STATION:
3479 case NL80211_IFTYPE_P2P_CLIENT:
3480 case NL80211_IFTYPE_ADHOC: {
3482 if (!wdev->current_bss)
3485 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3488 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3489 goto nla_put_failure_rcu_locked;
3499 if (rdev->ops->get_txq_stats) {
3500 struct cfg80211_txq_stats txqstats = {};
3501 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3504 !nl80211_put_txq_stats(msg, &txqstats,
3505 NL80211_ATTR_TXQ_STATS))
3506 goto nla_put_failure;
3509 genlmsg_end(msg, hdr);
3512 nla_put_failure_rcu_locked:
3514 nla_put_failure_locked:
3517 genlmsg_cancel(msg, hdr);
3521 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3525 int wp_start = cb->args[0];
3526 int if_start = cb->args[1];
3527 int filter_wiphy = -1;
3528 struct cfg80211_registered_device *rdev;
3529 struct wireless_dev *wdev;
3534 struct nl80211_dump_wiphy_state state = {
3538 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3542 filter_wiphy = state.filter_wiphy;
3545 * if filtering, set cb->args[2] to +1 since 0 is the default
3546 * value needed to determine that parsing is necessary.
3548 if (filter_wiphy >= 0)
3549 cb->args[2] = filter_wiphy + 1;
3552 } else if (cb->args[2] > 0) {
3553 filter_wiphy = cb->args[2] - 1;
3556 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3557 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3559 if (wp_idx < wp_start) {
3564 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3569 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
3570 if (if_idx < if_start) {
3574 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
3575 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3577 NL80211_CMD_NEW_INTERFACE) < 0) {
3586 cb->args[0] = wp_idx;
3587 cb->args[1] = if_idx;
3596 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3598 struct sk_buff *msg;
3599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3600 struct wireless_dev *wdev = info->user_ptr[1];
3602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3606 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3607 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
3612 return genlmsg_reply(msg, info);
3615 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3616 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3617 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3618 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3619 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3620 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
3621 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
3624 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3626 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3634 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
3637 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3639 *mntrflags |= (1<<flag);
3641 *mntrflags |= MONITOR_FLAG_CHANGED;
3646 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3647 enum nl80211_iftype type,
3648 struct genl_info *info,
3649 struct vif_params *params)
3651 bool change = false;
3654 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3655 if (type != NL80211_IFTYPE_MONITOR)
3658 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3666 if (params->flags & MONITOR_FLAG_ACTIVE &&
3667 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3670 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3671 const u8 *mumimo_groups;
3672 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3674 if (type != NL80211_IFTYPE_MONITOR)
3677 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3681 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3683 /* bits 0 and 63 are reserved and must be zero */
3684 if ((mumimo_groups[0] & BIT(0)) ||
3685 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
3688 params->vht_mumimo_groups = mumimo_groups;
3692 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3693 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3695 if (type != NL80211_IFTYPE_MONITOR)
3698 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3701 params->vht_mumimo_follow_addr =
3702 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3706 return change ? 1 : 0;
3709 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
3710 struct net_device *netdev, u8 use_4addr,
3711 enum nl80211_iftype iftype)
3714 if (netdev && netif_is_bridge_port(netdev))
3720 case NL80211_IFTYPE_AP_VLAN:
3721 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3724 case NL80211_IFTYPE_STATION:
3725 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3735 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3738 struct vif_params params;
3740 enum nl80211_iftype otype, ntype;
3741 struct net_device *dev = info->user_ptr[1];
3742 bool change = false;
3744 memset(¶ms, 0, sizeof(params));
3746 otype = ntype = dev->ieee80211_ptr->iftype;
3748 if (info->attrs[NL80211_ATTR_IFTYPE]) {
3749 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3754 if (info->attrs[NL80211_ATTR_MESH_ID]) {
3755 struct wireless_dev *wdev = dev->ieee80211_ptr;
3757 if (ntype != NL80211_IFTYPE_MESH_POINT)
3759 if (netif_running(dev))
3763 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3764 IEEE80211_MAX_MESH_ID_LEN);
3765 wdev->mesh_id_up_len =
3766 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3767 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3768 wdev->mesh_id_up_len);
3772 if (info->attrs[NL80211_ATTR_4ADDR]) {
3773 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3775 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
3779 params.use_4addr = -1;
3782 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms);
3789 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms);
3793 if (!err && params.use_4addr != -1)
3794 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3796 if (change && !err) {
3797 struct wireless_dev *wdev = dev->ieee80211_ptr;
3799 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3805 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3808 struct vif_params params;
3809 struct wireless_dev *wdev;
3810 struct sk_buff *msg;
3812 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3814 /* to avoid failing a new interface creation due to pending removal */
3815 cfg80211_destroy_ifaces(rdev);
3817 memset(¶ms, 0, sizeof(params));
3819 if (!info->attrs[NL80211_ATTR_IFNAME])
3822 if (info->attrs[NL80211_ATTR_IFTYPE])
3823 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3825 if (!rdev->ops->add_virtual_intf)
3828 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
3829 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3830 info->attrs[NL80211_ATTR_MAC]) {
3831 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3833 if (!is_valid_ether_addr(params.macaddr))
3834 return -EADDRNOTAVAIL;
3837 if (info->attrs[NL80211_ATTR_4ADDR]) {
3838 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3839 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
3844 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
3847 err = nl80211_parse_mon_options(rdev, type, info, ¶ms);
3851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3855 wdev = rdev_add_virtual_intf(rdev,
3856 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
3857 NET_NAME_USER, type, ¶ms);
3858 if (WARN_ON(!wdev)) {
3861 } else if (IS_ERR(wdev)) {
3863 return PTR_ERR(wdev);
3866 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
3867 wdev->owner_nlportid = info->snd_portid;
3870 case NL80211_IFTYPE_MESH_POINT:
3871 if (!info->attrs[NL80211_ATTR_MESH_ID])
3874 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3875 IEEE80211_MAX_MESH_ID_LEN);
3876 wdev->mesh_id_up_len =
3877 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3878 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3879 wdev->mesh_id_up_len);
3882 case NL80211_IFTYPE_NAN:
3883 case NL80211_IFTYPE_P2P_DEVICE:
3885 * P2P Device and NAN do not have a netdev, so don't go
3886 * through the netdev notifier and must be added here
3888 cfg80211_init_wdev(rdev, wdev);
3894 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3895 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
3900 return genlmsg_reply(msg, info);
3903 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3906 struct wireless_dev *wdev = info->user_ptr[1];
3908 if (!rdev->ops->del_virtual_intf)
3912 * If we remove a wireless device without a netdev then clear
3913 * user_ptr[1] so that nl80211_post_doit won't dereference it
3914 * to check if it needs to do dev_put(). Otherwise it crashes
3915 * since the wdev has been freed, unlike with a netdev where
3916 * we need the dev_put() for the netdev to really be freed.
3919 info->user_ptr[1] = NULL;
3921 return rdev_del_virtual_intf(rdev, wdev);
3924 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3927 struct net_device *dev = info->user_ptr[1];
3930 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3933 if (!rdev->ops->set_noack_map)
3936 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3938 return rdev_set_noack_map(rdev, dev, noack_map);
3941 struct get_key_cookie {
3942 struct sk_buff *msg;
3947 static void get_key_callback(void *c, struct key_params *params)
3950 struct get_key_cookie *cookie = c;
3953 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3954 params->key_len, params->key)) ||
3956 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3957 params->seq_len, params->seq)) ||
3959 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3961 goto nla_put_failure;
3963 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
3965 goto nla_put_failure;
3968 nla_put(cookie->msg, NL80211_KEY_DATA,
3969 params->key_len, params->key)) ||
3971 nla_put(cookie->msg, NL80211_KEY_SEQ,
3972 params->seq_len, params->seq)) ||
3974 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3976 goto nla_put_failure;
3978 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
3979 goto nla_put_failure;
3981 nla_nest_end(cookie->msg, key);
3988 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3992 struct net_device *dev = info->user_ptr[1];
3994 const u8 *mac_addr = NULL;
3996 struct get_key_cookie cookie = {
4000 struct sk_buff *msg;
4001 bool bigtk_support = false;
4003 if (wiphy_ext_feature_isset(&rdev->wiphy,
4004 NL80211_EXT_FEATURE_BEACON_PROTECTION))
4005 bigtk_support = true;
4007 if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION ||
4008 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
4009 wiphy_ext_feature_isset(&rdev->wiphy,
4010 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
4011 bigtk_support = true;
4013 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
4014 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
4016 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) {
4017 GENL_SET_ERR_MSG(info, "BIGTK not supported");
4022 if (info->attrs[NL80211_ATTR_MAC])
4023 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4025 pairwise = !!mac_addr;
4026 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
4027 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
4029 if (kt != NL80211_KEYTYPE_GROUP &&
4030 kt != NL80211_KEYTYPE_PAIRWISE)
4032 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
4035 if (!rdev->ops->get_key)
4038 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4041 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4045 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4046 NL80211_CMD_NEW_KEY);
4048 goto nla_put_failure;
4051 cookie.idx = key_idx;
4053 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4054 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
4055 goto nla_put_failure;
4057 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
4058 goto nla_put_failure;
4060 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
4067 goto nla_put_failure;
4069 genlmsg_end(msg, hdr);
4070 return genlmsg_reply(msg, info);
4079 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
4081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4082 struct key_parse key;
4084 struct net_device *dev = info->user_ptr[1];
4086 err = nl80211_parse_key(info, &key);
4093 /* Only support setting default key and
4094 * Extended Key ID action NL80211_KEY_SET_TX.
4096 if (!key.def && !key.defmgmt && !key.defbeacon &&
4097 !(key.p.mode == NL80211_KEY_SET_TX))
4100 wdev_lock(dev->ieee80211_ptr);
4103 if (!rdev->ops->set_default_key) {
4108 err = nl80211_key_allowed(dev->ieee80211_ptr);
4112 err = rdev_set_default_key(rdev, dev, key.idx,
4113 key.def_uni, key.def_multi);
4118 #ifdef CONFIG_CFG80211_WEXT
4119 dev->ieee80211_ptr->wext.default_key = key.idx;
4121 } else if (key.defmgmt) {
4122 if (key.def_uni || !key.def_multi) {
4127 if (!rdev->ops->set_default_mgmt_key) {
4132 err = nl80211_key_allowed(dev->ieee80211_ptr);
4136 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
4140 #ifdef CONFIG_CFG80211_WEXT
4141 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
4143 } else if (key.defbeacon) {
4144 if (key.def_uni || !key.def_multi) {
4149 if (!rdev->ops->set_default_beacon_key) {
4154 err = nl80211_key_allowed(dev->ieee80211_ptr);
4158 err = rdev_set_default_beacon_key(rdev, dev, key.idx);
4161 } else if (key.p.mode == NL80211_KEY_SET_TX &&
4162 wiphy_ext_feature_isset(&rdev->wiphy,
4163 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
4164 u8 *mac_addr = NULL;
4166 if (info->attrs[NL80211_ATTR_MAC])
4167 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4169 if (!mac_addr || key.idx < 0 || key.idx > 1) {
4174 err = rdev_add_key(rdev, dev, key.idx,
4175 NL80211_KEYTYPE_PAIRWISE,
4181 wdev_unlock(dev->ieee80211_ptr);
4186 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4190 struct net_device *dev = info->user_ptr[1];
4191 struct key_parse key;
4192 const u8 *mac_addr = NULL;
4194 err = nl80211_parse_key(info, &key);
4199 GENL_SET_ERR_MSG(info, "no key");
4203 if (info->attrs[NL80211_ATTR_MAC])
4204 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4206 if (key.type == -1) {
4208 key.type = NL80211_KEYTYPE_PAIRWISE;
4210 key.type = NL80211_KEYTYPE_GROUP;
4214 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4215 key.type != NL80211_KEYTYPE_GROUP) {
4216 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
4220 if (key.type == NL80211_KEYTYPE_GROUP &&
4221 info->attrs[NL80211_ATTR_VLAN_ID])
4222 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
4224 if (!rdev->ops->add_key)
4227 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4228 key.type == NL80211_KEYTYPE_PAIRWISE,
4230 GENL_SET_ERR_MSG(info, "key setting validation failed");
4234 wdev_lock(dev->ieee80211_ptr);
4235 err = nl80211_key_allowed(dev->ieee80211_ptr);
4237 GENL_SET_ERR_MSG(info, "key not allowed");
4239 err = rdev_add_key(rdev, dev, key.idx,
4240 key.type == NL80211_KEYTYPE_PAIRWISE,
4243 GENL_SET_ERR_MSG(info, "key addition failed");
4245 wdev_unlock(dev->ieee80211_ptr);
4250 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4254 struct net_device *dev = info->user_ptr[1];
4255 u8 *mac_addr = NULL;
4256 struct key_parse key;
4258 err = nl80211_parse_key(info, &key);
4265 if (info->attrs[NL80211_ATTR_MAC])
4266 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4268 if (key.type == -1) {
4270 key.type = NL80211_KEYTYPE_PAIRWISE;
4272 key.type = NL80211_KEYTYPE_GROUP;
4276 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4277 key.type != NL80211_KEYTYPE_GROUP)
4280 if (!rdev->ops->del_key)
4283 wdev_lock(dev->ieee80211_ptr);
4284 err = nl80211_key_allowed(dev->ieee80211_ptr);
4286 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
4287 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4291 err = rdev_del_key(rdev, dev, key.idx,
4292 key.type == NL80211_KEYTYPE_PAIRWISE,
4295 #ifdef CONFIG_CFG80211_WEXT
4297 if (key.idx == dev->ieee80211_ptr->wext.default_key)
4298 dev->ieee80211_ptr->wext.default_key = -1;
4299 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
4300 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
4303 wdev_unlock(dev->ieee80211_ptr);
4308 /* This function returns an error or the number of nested attributes */
4309 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4311 struct nlattr *attr;
4312 int n_entries = 0, tmp;
4314 nla_for_each_nested(attr, nl_attr, tmp) {
4315 if (nla_len(attr) != ETH_ALEN)
4325 * This function parses ACL information and allocates memory for ACL data.
4326 * On successful return, the calling function is responsible to free the
4327 * ACL buffer returned by this function.
4329 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4330 struct genl_info *info)
4332 enum nl80211_acl_policy acl_policy;
4333 struct nlattr *attr;
4334 struct cfg80211_acl_data *acl;
4335 int i = 0, n_entries, tmp;
4337 if (!wiphy->max_acl_mac_addrs)
4338 return ERR_PTR(-EOPNOTSUPP);
4340 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4341 return ERR_PTR(-EINVAL);
4343 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4344 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4345 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4346 return ERR_PTR(-EINVAL);
4348 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4349 return ERR_PTR(-EINVAL);
4351 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4353 return ERR_PTR(n_entries);
4355 if (n_entries > wiphy->max_acl_mac_addrs)
4356 return ERR_PTR(-ENOTSUPP);
4358 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
4360 return ERR_PTR(-ENOMEM);
4362 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4363 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4367 acl->n_acl_entries = n_entries;
4368 acl->acl_policy = acl_policy;
4373 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4376 struct net_device *dev = info->user_ptr[1];
4377 struct cfg80211_acl_data *acl;
4380 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4381 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4384 if (!dev->ieee80211_ptr->beacon_interval)
4387 acl = parse_acl_data(&rdev->wiphy, info);
4389 return PTR_ERR(acl);
4391 err = rdev_set_mac_acl(rdev, dev, acl);
4398 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4399 u8 *rates, u8 rates_len)
4404 for (i = 0; i < rates_len; i++) {
4405 int rate = (rates[i] & 0x7f) * 5;
4408 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4409 struct ieee80211_rate *srate =
4410 &sband->bitrates[ridx];
4411 if (rate == srate->bitrate) {
4416 if (ridx == sband->n_bitrates)
4417 return 0; /* rate not found */
4423 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4424 u8 *rates, u8 rates_len,
4425 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4429 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4431 for (i = 0; i < rates_len; i++) {
4434 ridx = rates[i] / 8;
4435 rbit = BIT(rates[i] % 8);
4437 /* check validity */
4438 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4441 /* check availability */
4442 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
4443 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4452 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4456 switch (vht_mcs_map) {
4457 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4459 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4462 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4465 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4475 static void vht_build_mcs_mask(u16 vht_mcs_map,
4476 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4480 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4481 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4486 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4487 struct nl80211_txrate_vht *txrate,
4488 u16 mcs[NL80211_VHT_NSS_MAX])
4490 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4491 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4494 if (!sband->vht_cap.vht_supported)
4497 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4499 /* Build vht_mcs_mask from VHT capabilities */
4500 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4502 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4503 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4504 mcs[i] = txrate->mcs[i];
4512 static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map)
4514 switch (he_mcs_map) {
4515 case IEEE80211_HE_MCS_NOT_SUPPORTED:
4517 case IEEE80211_HE_MCS_SUPPORT_0_7:
4519 case IEEE80211_HE_MCS_SUPPORT_0_9:
4521 case IEEE80211_HE_MCS_SUPPORT_0_11:
4529 static void he_build_mcs_mask(u16 he_mcs_map,
4530 u16 he_mcs_mask[NL80211_HE_NSS_MAX])
4534 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) {
4535 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03);
4540 static u16 he_get_txmcsmap(struct genl_info *info,
4541 const struct ieee80211_sta_he_cap *he_cap)
4543 struct net_device *dev = info->user_ptr[1];
4544 struct wireless_dev *wdev = dev->ieee80211_ptr;
4547 switch (wdev->chandef.width) {
4548 case NL80211_CHAN_WIDTH_80P80:
4549 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80;
4551 case NL80211_CHAN_WIDTH_160:
4552 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160;
4555 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80;
4558 return le16_to_cpu(tx_mcs);
4561 static bool he_set_mcs_mask(struct genl_info *info,
4562 struct wireless_dev *wdev,
4563 struct ieee80211_supported_band *sband,
4564 struct nl80211_txrate_he *txrate,
4565 u16 mcs[NL80211_HE_NSS_MAX])
4567 const struct ieee80211_sta_he_cap *he_cap;
4568 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {};
4572 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
4576 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX);
4578 tx_mcs_map = he_get_txmcsmap(info, he_cap);
4580 /* Build he_mcs_mask from HE capabilities */
4581 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4583 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
4584 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4585 mcs[i] = txrate->mcs[i];
4593 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4594 struct nlattr *attrs[],
4595 enum nl80211_attrs attr,
4596 struct cfg80211_bitrate_mask *mask,
4597 struct net_device *dev)
4599 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4601 struct wireless_dev *wdev = dev->ieee80211_ptr;
4603 struct nlattr *tx_rates;
4604 struct ieee80211_supported_band *sband;
4605 u16 vht_tx_mcs_map, he_tx_mcs_map;
4607 memset(mask, 0, sizeof(*mask));
4608 /* Default to all rates enabled */
4609 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4610 const struct ieee80211_sta_he_cap *he_cap;
4612 sband = rdev->wiphy.bands[i];
4617 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4618 memcpy(mask->control[i].ht_mcs,
4619 sband->ht_cap.mcs.rx_mask,
4620 sizeof(mask->control[i].ht_mcs));
4622 if (!sband->vht_cap.vht_supported)
4625 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4626 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4628 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
4632 he_tx_mcs_map = he_get_txmcsmap(info, he_cap);
4633 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs);
4635 mask->control[i].he_gi = 0xFF;
4636 mask->control[i].he_ltf = 0xFF;
4639 /* if no rates are given set it back to the defaults */
4643 /* The nested attribute uses enum nl80211_band as the index. This maps
4644 * directly to the enum nl80211_band values used in cfg80211.
4646 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4647 nla_for_each_nested(tx_rates, attrs[attr], rem) {
4648 enum nl80211_band band = nla_type(tx_rates);
4651 if (band < 0 || band >= NUM_NL80211_BANDS)
4653 sband = rdev->wiphy.bands[band];
4656 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4658 nl80211_txattr_policy,
4662 if (tb[NL80211_TXRATE_LEGACY]) {
4663 mask->control[band].legacy = rateset_to_mask(
4665 nla_data(tb[NL80211_TXRATE_LEGACY]),
4666 nla_len(tb[NL80211_TXRATE_LEGACY]));
4667 if ((mask->control[band].legacy == 0) &&
4668 nla_len(tb[NL80211_TXRATE_LEGACY]))
4671 if (tb[NL80211_TXRATE_HT]) {
4672 if (!ht_rateset_to_mask(
4674 nla_data(tb[NL80211_TXRATE_HT]),
4675 nla_len(tb[NL80211_TXRATE_HT]),
4676 mask->control[band].ht_mcs))
4679 if (tb[NL80211_TXRATE_VHT]) {
4680 if (!vht_set_mcs_mask(
4682 nla_data(tb[NL80211_TXRATE_VHT]),
4683 mask->control[band].vht_mcs))
4686 if (tb[NL80211_TXRATE_GI]) {
4687 mask->control[band].gi =
4688 nla_get_u8(tb[NL80211_TXRATE_GI]);
4689 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4692 if (tb[NL80211_TXRATE_HE] &&
4693 !he_set_mcs_mask(info, wdev, sband,
4694 nla_data(tb[NL80211_TXRATE_HE]),
4695 mask->control[band].he_mcs))
4697 if (tb[NL80211_TXRATE_HE_GI])
4698 mask->control[band].he_gi =
4699 nla_get_u8(tb[NL80211_TXRATE_HE_GI]);
4700 if (tb[NL80211_TXRATE_HE_LTF])
4701 mask->control[band].he_ltf =
4702 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]);
4704 if (mask->control[band].legacy == 0) {
4705 /* don't allow empty legacy rates if HT, VHT or HE
4706 * are not even supported.
4708 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4709 rdev->wiphy.bands[band]->vht_cap.vht_supported ||
4710 ieee80211_get_he_iftype_cap(sband, wdev->iftype)))
4713 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4714 if (mask->control[band].ht_mcs[i])
4717 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4718 if (mask->control[band].vht_mcs[i])
4721 for (i = 0; i < NL80211_HE_NSS_MAX; i++)
4722 if (mask->control[band].he_mcs[i])
4725 /* legacy and mcs rates may not be both empty */
4734 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4735 enum nl80211_band band,
4736 struct cfg80211_bitrate_mask *beacon_rate)
4738 u32 count_ht, count_vht, i;
4739 u32 rate = beacon_rate->control[band].legacy;
4741 /* Allow only one rate */
4742 if (hweight32(rate) > 1)
4746 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4747 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
4749 } else if (beacon_rate->control[band].ht_mcs[i]) {
4754 if (count_ht && rate)
4759 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4760 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
4762 } else if (beacon_rate->control[band].vht_mcs[i]) {
4767 if (count_vht && rate)
4771 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4775 !wiphy_ext_feature_isset(&rdev->wiphy,
4776 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4779 !wiphy_ext_feature_isset(&rdev->wiphy,
4780 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4783 !wiphy_ext_feature_isset(&rdev->wiphy,
4784 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4790 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4791 struct nlattr *attrs[],
4792 struct cfg80211_beacon_data *bcn)
4794 bool haveinfo = false;
4797 memset(bcn, 0, sizeof(*bcn));
4799 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4800 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4801 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
4807 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4808 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4809 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
4816 if (attrs[NL80211_ATTR_IE]) {
4817 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4818 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
4821 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
4822 bcn->proberesp_ies =
4823 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
4824 bcn->proberesp_ies_len =
4825 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
4828 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
4829 bcn->assocresp_ies =
4830 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
4831 bcn->assocresp_ies_len =
4832 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
4835 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4836 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4837 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
4840 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4841 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4843 err = nla_parse_nested_deprecated(tb,
4844 NL80211_FTM_RESP_ATTR_MAX,
4845 attrs[NL80211_ATTR_FTM_RESPONDER],
4850 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4851 wiphy_ext_feature_isset(&rdev->wiphy,
4852 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4853 bcn->ftm_responder = 1;
4857 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4858 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4859 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4862 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4863 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4864 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4867 bcn->ftm_responder = -1;
4873 static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
4874 struct ieee80211_he_obss_pd *he_obss_pd)
4876 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
4879 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
4880 he_obss_pd_policy, NULL);
4884 if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL])
4887 he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]);
4889 if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET])
4890 he_obss_pd->min_offset =
4891 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
4892 if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
4893 he_obss_pd->max_offset =
4894 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
4895 if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET])
4896 he_obss_pd->non_srg_max_offset =
4897 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]);
4899 if (he_obss_pd->min_offset > he_obss_pd->max_offset)
4902 if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP])
4903 memcpy(he_obss_pd->bss_color_bitmap,
4904 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]),
4905 sizeof(he_obss_pd->bss_color_bitmap));
4907 if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP])
4908 memcpy(he_obss_pd->partial_bssid_bitmap,
4909 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]),
4910 sizeof(he_obss_pd->partial_bssid_bitmap));
4912 he_obss_pd->enable = true;
4917 static int nl80211_parse_he_bss_color(struct nlattr *attrs,
4918 struct cfg80211_he_bss_color *he_bss_color)
4920 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1];
4923 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs,
4924 he_bss_color_policy, NULL);
4928 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR])
4931 he_bss_color->color =
4932 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]);
4933 he_bss_color->enabled =
4934 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]);
4935 he_bss_color->partial =
4936 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]);
4941 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev,
4942 struct nlattr *attrs,
4943 struct cfg80211_ap_settings *params)
4945 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1];
4947 struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery;
4949 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4950 NL80211_EXT_FEATURE_FILS_DISCOVERY))
4953 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs,
4958 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] ||
4959 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] ||
4960 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL])
4963 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
4964 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
4965 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]);
4966 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]);
4972 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev,
4973 struct nlattr *attrs,
4974 struct cfg80211_ap_settings *params)
4976 struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1];
4978 struct cfg80211_unsol_bcast_probe_resp *presp =
4979 ¶ms->unsol_bcast_probe_resp;
4981 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4982 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP))
4985 ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX,
4990 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] ||
4991 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL])
4994 presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]);
4995 presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]);
4996 presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]);
5000 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
5008 for (i = 0; i < rates[1]; i++) {
5009 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
5010 params->ht_required = true;
5011 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
5012 params->vht_required = true;
5013 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
5014 params->he_required = true;
5019 * Since the nl80211 API didn't include, from the beginning, attributes about
5020 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
5021 * benefit of drivers that rebuild IEs in the firmware.
5023 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
5025 const struct cfg80211_beacon_data *bcn = ¶ms->beacon;
5026 size_t ies_len = bcn->tail_len;
5027 const u8 *ies = bcn->tail;
5031 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
5032 nl80211_check_ap_rate_selectors(params, rates);
5034 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
5035 nl80211_check_ap_rate_selectors(params, rates);
5037 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
5038 if (cap && cap[1] >= sizeof(*params->ht_cap))
5039 params->ht_cap = (void *)(cap + 2);
5040 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
5041 if (cap && cap[1] >= sizeof(*params->vht_cap))
5042 params->vht_cap = (void *)(cap + 2);
5043 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
5044 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
5045 params->he_cap = (void *)(cap + 3);
5046 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len);
5047 if (cap && cap[1] >= sizeof(*params->he_oper) + 1)
5048 params->he_oper = (void *)(cap + 3);
5051 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
5052 struct cfg80211_ap_settings *params)
5054 struct wireless_dev *wdev;
5057 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
5058 if (wdev->iftype != NL80211_IFTYPE_AP &&
5059 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5062 if (!wdev->preset_chandef.chan)
5065 params->chandef = wdev->preset_chandef;
5073 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
5074 enum nl80211_auth_type auth_type,
5075 enum nl80211_commands cmd)
5077 if (auth_type > NL80211_AUTHTYPE_MAX)
5081 case NL80211_CMD_AUTHENTICATE:
5082 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
5083 auth_type == NL80211_AUTHTYPE_SAE)
5085 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5086 NL80211_EXT_FEATURE_FILS_STA) &&
5087 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5088 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5089 auth_type == NL80211_AUTHTYPE_FILS_PK))
5092 case NL80211_CMD_CONNECT:
5093 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
5094 !wiphy_ext_feature_isset(&rdev->wiphy,
5095 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
5096 auth_type == NL80211_AUTHTYPE_SAE)
5099 /* FILS with SK PFS or PK not supported yet */
5100 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5101 auth_type == NL80211_AUTHTYPE_FILS_PK)
5103 if (!wiphy_ext_feature_isset(
5105 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
5106 auth_type == NL80211_AUTHTYPE_FILS_SK)
5109 case NL80211_CMD_START_AP:
5110 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5111 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) &&
5112 auth_type == NL80211_AUTHTYPE_SAE)
5114 /* FILS not supported yet */
5115 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5116 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5117 auth_type == NL80211_AUTHTYPE_FILS_PK)
5125 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
5127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5128 struct net_device *dev = info->user_ptr[1];
5129 struct wireless_dev *wdev = dev->ieee80211_ptr;
5130 struct cfg80211_ap_settings params;
5133 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5134 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5137 if (!rdev->ops->start_ap)
5140 if (wdev->beacon_interval)
5143 memset(¶ms, 0, sizeof(params));
5145 /* these are required for START_AP */
5146 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
5147 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
5148 !info->attrs[NL80211_ATTR_BEACON_HEAD])
5151 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon);
5155 params.beacon_interval =
5156 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5157 params.dtim_period =
5158 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
5160 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
5161 params.beacon_interval);
5166 * In theory, some of these attributes should be required here
5167 * but since they were not used when the command was originally
5168 * added, keep them optional for old user space programs to let
5169 * them continue to work with drivers that do not need the
5170 * additional information -- drivers must check!
5172 if (info->attrs[NL80211_ATTR_SSID]) {
5173 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5175 nla_len(info->attrs[NL80211_ATTR_SSID]);
5176 if (params.ssid_len == 0)
5180 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
5181 params.hidden_ssid = nla_get_u32(
5182 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
5184 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5186 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5187 params.auth_type = nla_get_u32(
5188 info->attrs[NL80211_ATTR_AUTH_TYPE]);
5189 if (!nl80211_valid_auth_type(rdev, params.auth_type,
5190 NL80211_CMD_START_AP))
5193 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5195 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
5196 NL80211_MAX_NR_CIPHER_SUITES);
5200 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
5201 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
5203 params.inactivity_timeout = nla_get_u16(
5204 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
5207 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5208 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5210 params.p2p_ctwindow =
5211 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5212 if (params.p2p_ctwindow != 0 &&
5213 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5217 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5222 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5223 params.p2p_opp_ps = tmp;
5224 if (params.p2p_opp_ps != 0 &&
5225 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5229 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5230 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
5233 } else if (wdev->preset_chandef.chan) {
5234 params.chandef = wdev->preset_chandef;
5235 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
5238 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
5242 if (info->attrs[NL80211_ATTR_TX_RATES]) {
5243 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
5244 NL80211_ATTR_TX_RATES,
5245 ¶ms.beacon_rate,
5250 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
5251 ¶ms.beacon_rate);
5256 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
5258 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
5259 switch (params.smps_mode) {
5260 case NL80211_SMPS_OFF:
5262 case NL80211_SMPS_STATIC:
5263 if (!(rdev->wiphy.features &
5264 NL80211_FEATURE_STATIC_SMPS))
5267 case NL80211_SMPS_DYNAMIC:
5268 if (!(rdev->wiphy.features &
5269 NL80211_FEATURE_DYNAMIC_SMPS))
5276 params.smps_mode = NL80211_SMPS_OFF;
5279 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
5280 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
5283 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
5284 params.acl = parse_acl_data(&rdev->wiphy, info);
5285 if (IS_ERR(params.acl))
5286 return PTR_ERR(params.acl);
5289 params.twt_responder =
5290 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
5292 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
5293 err = nl80211_parse_he_obss_pd(
5294 info->attrs[NL80211_ATTR_HE_OBSS_PD],
5295 ¶ms.he_obss_pd);
5300 if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) {
5301 err = nl80211_parse_he_bss_color(
5302 info->attrs[NL80211_ATTR_HE_BSS_COLOR],
5303 ¶ms.he_bss_color);
5308 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) {
5309 err = nl80211_parse_fils_discovery(rdev,
5310 info->attrs[NL80211_ATTR_FILS_DISCOVERY],
5316 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) {
5317 err = nl80211_parse_unsol_bcast_probe_resp(
5318 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP],
5324 nl80211_calculate_ap_params(¶ms);
5326 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
5327 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
5330 err = rdev_start_ap(rdev, dev, ¶ms);
5332 wdev->preset_chandef = params.chandef;
5333 wdev->beacon_interval = params.beacon_interval;
5334 wdev->chandef = params.chandef;
5335 wdev->ssid_len = params.ssid_len;
5336 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
5338 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
5339 wdev->conn_owner_nlportid = info->snd_portid;
5349 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
5351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5352 struct net_device *dev = info->user_ptr[1];
5353 struct wireless_dev *wdev = dev->ieee80211_ptr;
5354 struct cfg80211_beacon_data params;
5357 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5358 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5361 if (!rdev->ops->change_beacon)
5364 if (!wdev->beacon_interval)
5367 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms);
5372 err = rdev_change_beacon(rdev, dev, ¶ms);
5378 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
5380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5381 struct net_device *dev = info->user_ptr[1];
5383 return cfg80211_stop_ap(rdev, dev, false);
5386 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
5387 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
5388 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
5389 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
5390 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
5391 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
5392 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
5395 static int parse_station_flags(struct genl_info *info,
5396 enum nl80211_iftype iftype,
5397 struct station_parameters *params)
5399 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
5404 * Try parsing the new attribute first so userspace
5405 * can specify both for older kernels.
5407 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
5409 struct nl80211_sta_flag_update *sta_flags;
5411 sta_flags = nla_data(nla);
5412 params->sta_flags_mask = sta_flags->mask;
5413 params->sta_flags_set = sta_flags->set;
5414 params->sta_flags_set &= params->sta_flags_mask;
5415 if ((params->sta_flags_mask |
5416 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
5421 /* if present, parse the old attribute */
5423 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
5427 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
5431 * Only allow certain flags for interface types so that
5432 * other attributes are silently ignored. Remember that
5433 * this is backward compatibility code with old userspace
5434 * and shouldn't be hit in other cases anyway.
5437 case NL80211_IFTYPE_AP:
5438 case NL80211_IFTYPE_AP_VLAN:
5439 case NL80211_IFTYPE_P2P_GO:
5440 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5441 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5442 BIT(NL80211_STA_FLAG_WME) |
5443 BIT(NL80211_STA_FLAG_MFP);
5445 case NL80211_IFTYPE_P2P_CLIENT:
5446 case NL80211_IFTYPE_STATION:
5447 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5448 BIT(NL80211_STA_FLAG_TDLS_PEER);
5450 case NL80211_IFTYPE_MESH_POINT:
5451 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5452 BIT(NL80211_STA_FLAG_MFP) |
5453 BIT(NL80211_STA_FLAG_AUTHORIZED);
5459 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
5461 params->sta_flags_set |= (1<<flag);
5463 /* no longer support new API additions in old API */
5464 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
5472 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
5474 struct nlattr *rate;
5477 enum nl80211_rate_info rate_flg;
5479 rate = nla_nest_start_noflag(msg, attr);
5483 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
5484 bitrate = cfg80211_calculate_bitrate(info);
5485 /* report 16-bit bitrate only if we can */
5486 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
5488 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
5490 if (bitrate_compat > 0 &&
5491 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
5495 case RATE_INFO_BW_5:
5496 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
5498 case RATE_INFO_BW_10:
5499 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
5504 case RATE_INFO_BW_20:
5507 case RATE_INFO_BW_40:
5508 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
5510 case RATE_INFO_BW_80:
5511 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
5513 case RATE_INFO_BW_160:
5514 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
5516 case RATE_INFO_BW_HE_RU:
5518 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
5521 if (rate_flg && nla_put_flag(msg, rate_flg))
5524 if (info->flags & RATE_INFO_FLAGS_MCS) {
5525 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
5527 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5528 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5530 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
5531 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
5533 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
5535 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5536 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5538 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
5539 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
5541 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
5543 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
5545 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
5547 if (info->bw == RATE_INFO_BW_HE_RU &&
5548 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
5553 nla_nest_end(msg, rate);
5557 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
5566 attr = nla_nest_start_noflag(msg, id);
5570 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
5571 if (!(mask & BIT(i)))
5574 if (nla_put_u8(msg, i, signal[i]))
5578 nla_nest_end(msg, attr);
5583 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
5585 struct cfg80211_registered_device *rdev,
5586 struct net_device *dev,
5587 const u8 *mac_addr, struct station_info *sinfo)
5590 struct nlattr *sinfoattr, *bss_param;
5592 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
5594 cfg80211_sinfo_release_content(sinfo);
5598 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5599 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
5600 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
5601 goto nla_put_failure;
5603 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
5605 goto nla_put_failure;
5607 #define PUT_SINFO(attr, memb, type) do { \
5608 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
5609 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5610 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5612 goto nla_put_failure; \
5614 #define PUT_SINFO_U64(attr, memb) do { \
5615 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5616 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5617 sinfo->memb, NL80211_STA_INFO_PAD)) \
5618 goto nla_put_failure; \
5621 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5622 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
5623 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
5625 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5626 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
5627 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
5628 (u32)sinfo->rx_bytes))
5629 goto nla_put_failure;
5631 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5632 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
5633 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5634 (u32)sinfo->tx_bytes))
5635 goto nla_put_failure;
5637 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5638 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
5639 PUT_SINFO(LLID, llid, u16);
5640 PUT_SINFO(PLID, plid, u16);
5641 PUT_SINFO(PLINK_STATE, plink_state, u8);
5642 PUT_SINFO_U64(RX_DURATION, rx_duration);
5643 PUT_SINFO_U64(TX_DURATION, tx_duration);
5645 if (wiphy_ext_feature_isset(&rdev->wiphy,
5646 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5647 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
5649 switch (rdev->wiphy.signal_type) {
5650 case CFG80211_SIGNAL_TYPE_MBM:
5651 PUT_SINFO(SIGNAL, signal, u8);
5652 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
5657 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
5658 if (!nl80211_put_signal(msg, sinfo->chains,
5659 sinfo->chain_signal,
5660 NL80211_STA_INFO_CHAIN_SIGNAL))
5661 goto nla_put_failure;
5663 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
5664 if (!nl80211_put_signal(msg, sinfo->chains,
5665 sinfo->chain_signal_avg,
5666 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
5667 goto nla_put_failure;
5669 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
5670 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5671 NL80211_STA_INFO_TX_BITRATE))
5672 goto nla_put_failure;
5674 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
5675 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5676 NL80211_STA_INFO_RX_BITRATE))
5677 goto nla_put_failure;
5680 PUT_SINFO(RX_PACKETS, rx_packets, u32);
5681 PUT_SINFO(TX_PACKETS, tx_packets, u32);
5682 PUT_SINFO(TX_RETRIES, tx_retries, u32);
5683 PUT_SINFO(TX_FAILED, tx_failed, u32);
5684 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
5685 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
5686 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
5687 PUT_SINFO(LOCAL_PM, local_pm, u32);
5688 PUT_SINFO(PEER_PM, peer_pm, u32);
5689 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
5690 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
5691 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8);
5693 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
5694 bss_param = nla_nest_start_noflag(msg,
5695 NL80211_STA_INFO_BSS_PARAM);
5697 goto nla_put_failure;
5699 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5700 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5701 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5702 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5703 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5704 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5705 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5706 sinfo->bss_param.dtim_period) ||
5707 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5708 sinfo->bss_param.beacon_interval))
5709 goto nla_put_failure;
5711 nla_nest_end(msg, bss_param);
5713 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
5714 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5715 sizeof(struct nl80211_sta_flag_update),
5717 goto nla_put_failure;
5719 PUT_SINFO_U64(T_OFFSET, t_offset);
5720 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5721 PUT_SINFO_U64(BEACON_RX, rx_beacon);
5722 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
5723 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5724 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
5725 if (wiphy_ext_feature_isset(&rdev->wiphy,
5726 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5727 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5728 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5732 #undef PUT_SINFO_U64
5734 if (sinfo->pertid) {
5735 struct nlattr *tidsattr;
5738 tidsattr = nla_nest_start_noflag(msg,
5739 NL80211_STA_INFO_TID_STATS);
5741 goto nla_put_failure;
5743 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5744 struct cfg80211_tid_stats *tidstats;
5745 struct nlattr *tidattr;
5747 tidstats = &sinfo->pertid[tid];
5749 if (!tidstats->filled)
5752 tidattr = nla_nest_start_noflag(msg, tid + 1);
5754 goto nla_put_failure;
5756 #define PUT_TIDVAL_U64(attr, memb) do { \
5757 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
5758 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5759 tidstats->memb, NL80211_TID_STATS_PAD)) \
5760 goto nla_put_failure; \
5763 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5764 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5765 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5766 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
5768 #undef PUT_TIDVAL_U64
5769 if ((tidstats->filled &
5770 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5771 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5772 NL80211_TID_STATS_TXQ_STATS))
5773 goto nla_put_failure;
5775 nla_nest_end(msg, tidattr);
5778 nla_nest_end(msg, tidsattr);
5781 nla_nest_end(msg, sinfoattr);
5783 if (sinfo->assoc_req_ies_len &&
5784 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5785 sinfo->assoc_req_ies))
5786 goto nla_put_failure;
5788 cfg80211_sinfo_release_content(sinfo);
5789 genlmsg_end(msg, hdr);
5793 cfg80211_sinfo_release_content(sinfo);
5794 genlmsg_cancel(msg, hdr);
5798 static int nl80211_dump_station(struct sk_buff *skb,
5799 struct netlink_callback *cb)
5801 struct station_info sinfo;
5802 struct cfg80211_registered_device *rdev;
5803 struct wireless_dev *wdev;
5804 u8 mac_addr[ETH_ALEN];
5805 int sta_idx = cb->args[2];
5809 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
5813 if (!wdev->netdev) {
5818 if (!rdev->ops->dump_station) {
5824 memset(&sinfo, 0, sizeof(sinfo));
5825 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
5832 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
5833 NETLINK_CB(cb->skb).portid,
5834 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5835 rdev, wdev->netdev, mac_addr,
5843 cb->args[2] = sta_idx;
5851 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5853 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5854 struct net_device *dev = info->user_ptr[1];
5855 struct station_info sinfo;
5856 struct sk_buff *msg;
5857 u8 *mac_addr = NULL;
5860 memset(&sinfo, 0, sizeof(sinfo));
5862 if (!info->attrs[NL80211_ATTR_MAC])
5865 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5867 if (!rdev->ops->get_station)
5870 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
5874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5876 cfg80211_sinfo_release_content(&sinfo);
5880 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5881 info->snd_portid, info->snd_seq, 0,
5882 rdev, dev, mac_addr, &sinfo) < 0) {
5887 return genlmsg_reply(msg, info);
5890 int cfg80211_check_station_change(struct wiphy *wiphy,
5891 struct station_parameters *params,
5892 enum cfg80211_station_type statype)
5894 if (params->listen_interval != -1 &&
5895 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5898 if (params->support_p2p_ps != -1 &&
5899 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5903 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5904 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5907 /* When you run into this, adjust the code below for the new flag */
5908 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5911 case CFG80211_STA_MESH_PEER_KERNEL:
5912 case CFG80211_STA_MESH_PEER_USER:
5914 * No ignoring the TDLS flag here -- the userspace mesh
5915 * code doesn't have the bug of including TDLS in the
5918 if (params->sta_flags_mask &
5919 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5920 BIT(NL80211_STA_FLAG_MFP) |
5921 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5924 case CFG80211_STA_TDLS_PEER_SETUP:
5925 case CFG80211_STA_TDLS_PEER_ACTIVE:
5926 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5928 /* ignore since it can't change */
5929 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5932 /* disallow mesh-specific things */
5933 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5935 if (params->local_pm)
5937 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5941 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5942 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5943 /* TDLS can't be set, ... */
5944 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5947 * ... but don't bother the driver with it. This works around
5948 * a hostapd/wpa_supplicant issue -- it always includes the
5949 * TLDS_PEER flag in the mask even for AP mode.
5951 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5954 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5955 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
5956 /* reject other things that can't change */
5957 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5959 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5961 if (params->supported_rates)
5963 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5968 if (statype != CFG80211_STA_AP_CLIENT &&
5969 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
5975 case CFG80211_STA_AP_MLME_CLIENT:
5976 /* Use this only for authorizing/unauthorizing a station */
5977 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5980 case CFG80211_STA_AP_CLIENT:
5981 case CFG80211_STA_AP_CLIENT_UNASSOC:
5982 /* accept only the listed bits */
5983 if (params->sta_flags_mask &
5984 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5985 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5986 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5987 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5988 BIT(NL80211_STA_FLAG_WME) |
5989 BIT(NL80211_STA_FLAG_MFP)))
5992 /* but authenticated/associated only if driver handles it */
5993 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5994 params->sta_flags_mask &
5995 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5996 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5999 case CFG80211_STA_IBSS:
6000 case CFG80211_STA_AP_STA:
6001 /* reject any changes other than AUTHORIZED */
6002 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
6005 case CFG80211_STA_TDLS_PEER_SETUP:
6006 /* reject any changes other than AUTHORIZED or WME */
6007 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
6008 BIT(NL80211_STA_FLAG_WME)))
6010 /* force (at least) rates when authorizing */
6011 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
6012 !params->supported_rates)
6015 case CFG80211_STA_TDLS_PEER_ACTIVE:
6016 /* reject any changes */
6018 case CFG80211_STA_MESH_PEER_KERNEL:
6019 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6022 case CFG80211_STA_MESH_PEER_USER:
6023 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
6024 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
6030 * Older kernel versions ignored this attribute entirely, so don't
6031 * reject attempts to update it but mark it as unused instead so the
6032 * driver won't look at the data.
6034 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
6035 statype != CFG80211_STA_TDLS_PEER_SETUP)
6036 params->opmode_notif_used = false;
6040 EXPORT_SYMBOL(cfg80211_check_station_change);
6043 * Get vlan interface making sure it is running and on the right wiphy.
6045 static struct net_device *get_vlan(struct genl_info *info,
6046 struct cfg80211_registered_device *rdev)
6048 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
6049 struct net_device *v;
6055 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
6057 return ERR_PTR(-ENODEV);
6059 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
6064 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6065 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6066 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
6071 if (!netif_running(v)) {
6079 return ERR_PTR(ret);
6082 static const struct nla_policy
6083 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
6084 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
6085 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
6088 static int nl80211_parse_sta_wme(struct genl_info *info,
6089 struct station_parameters *params)
6091 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
6095 /* parse WME attributes if present */
6096 if (!info->attrs[NL80211_ATTR_STA_WME])
6099 nla = info->attrs[NL80211_ATTR_STA_WME];
6100 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
6101 nl80211_sta_wme_policy,
6106 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
6107 params->uapsd_queues = nla_get_u8(
6108 tb[NL80211_STA_WME_UAPSD_QUEUES]);
6109 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
6112 if (tb[NL80211_STA_WME_MAX_SP])
6113 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
6115 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
6118 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
6123 static int nl80211_parse_sta_channel_info(struct genl_info *info,
6124 struct station_parameters *params)
6126 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
6127 params->supported_channels =
6128 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
6129 params->supported_channels_len =
6130 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
6132 * Need to include at least one (first channel, number of
6133 * channels) tuple for each subband (checked in policy),
6134 * and must have proper tuples for the rest of the data as well.
6136 if (params->supported_channels_len % 2)
6140 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
6141 params->supported_oper_classes =
6142 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
6143 params->supported_oper_classes_len =
6144 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
6149 static int nl80211_set_station_tdls(struct genl_info *info,
6150 struct station_parameters *params)
6153 /* Dummy STA entry gets updated once the peer capabilities are known */
6154 if (info->attrs[NL80211_ATTR_PEER_AID])
6155 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
6156 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6158 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6159 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6161 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6162 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
6164 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6165 params->he_capa_len =
6166 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6169 err = nl80211_parse_sta_channel_info(info, params);
6173 return nl80211_parse_sta_wme(info, params);
6176 static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
6177 struct station_parameters *params)
6179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6182 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
6183 if (!rdev->ops->set_tx_power ||
6184 !wiphy_ext_feature_isset(&rdev->wiphy,
6185 NL80211_EXT_FEATURE_STA_TX_PWR))
6188 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
6189 params->txpwr.type = nla_get_u8(info->attrs[idx]);
6191 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
6192 idx = NL80211_ATTR_STA_TX_POWER;
6194 if (info->attrs[idx])
6195 params->txpwr.power =
6196 nla_get_s16(info->attrs[idx]);
6200 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
6206 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
6208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6209 struct net_device *dev = info->user_ptr[1];
6210 struct station_parameters params;
6214 memset(¶ms, 0, sizeof(params));
6216 if (!rdev->ops->change_station)
6220 * AID and listen_interval properties can be set only for unassociated
6221 * station. Include these parameters here and will check them in
6222 * cfg80211_check_station_change().
6224 if (info->attrs[NL80211_ATTR_STA_AID])
6225 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
6227 if (info->attrs[NL80211_ATTR_VLAN_ID])
6228 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6230 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
6231 params.listen_interval =
6232 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
6234 params.listen_interval = -1;
6236 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
6237 params.support_p2p_ps =
6238 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
6240 params.support_p2p_ps = -1;
6242 if (!info->attrs[NL80211_ATTR_MAC])
6245 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6247 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
6248 params.supported_rates =
6249 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6250 params.supported_rates_len =
6251 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6254 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
6256 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
6257 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
6260 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
6262 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6263 params.ext_capab_len =
6264 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6267 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
6270 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
6271 params.plink_action =
6272 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
6274 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
6275 params.plink_state =
6276 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
6277 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
6278 params.peer_aid = nla_get_u16(
6279 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
6280 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
6283 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
6284 params.local_pm = nla_get_u32(
6285 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
6287 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
6288 params.opmode_notif_used = true;
6289 params.opmode_notif =
6290 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
6293 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
6294 params.he_6ghz_capa =
6295 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
6297 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
6298 params.airtime_weight =
6299 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
6301 if (params.airtime_weight &&
6302 !wiphy_ext_feature_isset(&rdev->wiphy,
6303 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6306 err = nl80211_parse_sta_txpower_setting(info, ¶ms);
6310 /* Include parameters for TDLS peer (will check later) */
6311 err = nl80211_set_station_tdls(info, ¶ms);
6315 params.vlan = get_vlan(info, rdev);
6316 if (IS_ERR(params.vlan))
6317 return PTR_ERR(params.vlan);
6319 switch (dev->ieee80211_ptr->iftype) {
6320 case NL80211_IFTYPE_AP:
6321 case NL80211_IFTYPE_AP_VLAN:
6322 case NL80211_IFTYPE_P2P_GO:
6323 case NL80211_IFTYPE_P2P_CLIENT:
6324 case NL80211_IFTYPE_STATION:
6325 case NL80211_IFTYPE_ADHOC:
6326 case NL80211_IFTYPE_MESH_POINT:
6333 /* driver will call cfg80211_check_station_change() */
6334 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
6338 dev_put(params.vlan);
6343 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
6345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6347 struct net_device *dev = info->user_ptr[1];
6348 struct station_parameters params;
6349 u8 *mac_addr = NULL;
6350 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6351 BIT(NL80211_STA_FLAG_ASSOCIATED);
6353 memset(¶ms, 0, sizeof(params));
6355 if (!rdev->ops->add_station)
6358 if (!info->attrs[NL80211_ATTR_MAC])
6361 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
6364 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
6367 if (!info->attrs[NL80211_ATTR_STA_AID] &&
6368 !info->attrs[NL80211_ATTR_PEER_AID])
6371 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6372 params.supported_rates =
6373 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6374 params.supported_rates_len =
6375 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6376 params.listen_interval =
6377 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
6379 if (info->attrs[NL80211_ATTR_VLAN_ID])
6380 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6382 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
6383 params.support_p2p_ps =
6384 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
6387 * if not specified, assume it's supported for P2P GO interface,
6388 * and is NOT supported for AP interface
6390 params.support_p2p_ps =
6391 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
6394 if (info->attrs[NL80211_ATTR_PEER_AID])
6395 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
6397 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
6399 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
6401 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
6402 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
6405 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
6407 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6408 params.ext_capab_len =
6409 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6412 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6414 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6416 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6418 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6420 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
6422 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6423 params.he_capa_len =
6424 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6427 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
6428 params.he_6ghz_capa =
6429 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
6431 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
6432 params.opmode_notif_used = true;
6433 params.opmode_notif =
6434 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
6437 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
6438 params.plink_action =
6439 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
6441 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
6442 params.airtime_weight =
6443 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
6445 if (params.airtime_weight &&
6446 !wiphy_ext_feature_isset(&rdev->wiphy,
6447 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6450 err = nl80211_parse_sta_txpower_setting(info, ¶ms);
6454 err = nl80211_parse_sta_channel_info(info, ¶ms);
6458 err = nl80211_parse_sta_wme(info, ¶ms);
6462 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
6465 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
6466 * as userspace might just pass through the capabilities from the IEs
6467 * directly, rather than enforcing this restriction and returning an
6468 * error in this case.
6470 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
6471 params.ht_capa = NULL;
6472 params.vht_capa = NULL;
6474 /* HE requires WME */
6475 if (params.he_capa_len || params.he_6ghz_capa)
6479 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
6480 if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa))
6483 /* When you run into this, adjust the code below for the new flag */
6484 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6486 switch (dev->ieee80211_ptr->iftype) {
6487 case NL80211_IFTYPE_AP:
6488 case NL80211_IFTYPE_AP_VLAN:
6489 case NL80211_IFTYPE_P2P_GO:
6490 /* ignore WME attributes if iface/sta is not capable */
6491 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
6492 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
6493 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6495 /* TDLS peers cannot be added */
6496 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6497 info->attrs[NL80211_ATTR_PEER_AID])
6499 /* but don't bother the driver with it */
6500 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6502 /* allow authenticated/associated only if driver handles it */
6503 if (!(rdev->wiphy.features &
6504 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
6505 params.sta_flags_mask & auth_assoc)
6508 /* Older userspace, or userspace wanting to be compatible with
6509 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
6510 * and assoc flags in the mask, but assumes the station will be
6511 * added as associated anyway since this was the required driver
6512 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
6514 * In order to not bother drivers with this quirk in the API
6515 * set the flags in both the mask and set for new stations in
6518 if (!(params.sta_flags_mask & auth_assoc)) {
6519 params.sta_flags_mask |= auth_assoc;
6520 params.sta_flags_set |= auth_assoc;
6523 /* must be last in here for error handling */
6524 params.vlan = get_vlan(info, rdev);
6525 if (IS_ERR(params.vlan))
6526 return PTR_ERR(params.vlan);
6528 case NL80211_IFTYPE_MESH_POINT:
6529 /* ignore uAPSD data */
6530 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6532 /* associated is disallowed */
6533 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
6535 /* TDLS peers cannot be added */
6536 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6537 info->attrs[NL80211_ATTR_PEER_AID])
6540 case NL80211_IFTYPE_STATION:
6541 case NL80211_IFTYPE_P2P_CLIENT:
6542 /* ignore uAPSD data */
6543 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6545 /* these are disallowed */
6546 if (params.sta_flags_mask &
6547 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
6548 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
6550 /* Only TDLS peers can be added */
6551 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6553 /* Can only add if TDLS ... */
6554 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
6556 /* ... with external setup is supported */
6557 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
6560 * Older wpa_supplicant versions always mark the TDLS peer
6561 * as authorized, but it shouldn't yet be.
6563 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
6569 /* be aware of params.vlan when changing code here */
6571 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
6574 dev_put(params.vlan);
6578 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
6580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6581 struct net_device *dev = info->user_ptr[1];
6582 struct station_del_parameters params;
6584 memset(¶ms, 0, sizeof(params));
6586 if (info->attrs[NL80211_ATTR_MAC])
6587 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
6589 switch (dev->ieee80211_ptr->iftype) {
6590 case NL80211_IFTYPE_AP:
6591 case NL80211_IFTYPE_AP_VLAN:
6592 case NL80211_IFTYPE_MESH_POINT:
6593 case NL80211_IFTYPE_P2P_GO:
6594 /* always accept these */
6596 case NL80211_IFTYPE_ADHOC:
6597 /* conditionally accept */
6598 if (wiphy_ext_feature_isset(&rdev->wiphy,
6599 NL80211_EXT_FEATURE_DEL_IBSS_STA))
6606 if (!rdev->ops->del_station)
6609 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
6611 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
6612 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
6613 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
6616 /* Default to Deauthentication frame */
6617 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
6620 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
6621 params.reason_code =
6622 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6623 if (params.reason_code == 0)
6624 return -EINVAL; /* 0 is reserved */
6626 /* Default to reason code 2 */
6627 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
6630 return rdev_del_station(rdev, dev, ¶ms);
6633 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
6634 int flags, struct net_device *dev,
6635 u8 *dst, u8 *next_hop,
6636 struct mpath_info *pinfo)
6639 struct nlattr *pinfoattr;
6641 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
6645 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6646 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
6647 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
6648 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
6649 goto nla_put_failure;
6651 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
6653 goto nla_put_failure;
6654 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
6655 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
6657 goto nla_put_failure;
6658 if (((pinfo->filled & MPATH_INFO_SN) &&
6659 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
6660 ((pinfo->filled & MPATH_INFO_METRIC) &&
6661 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
6663 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
6664 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
6666 ((pinfo->filled & MPATH_INFO_FLAGS) &&
6667 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
6669 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
6670 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
6671 pinfo->discovery_timeout)) ||
6672 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
6673 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
6674 pinfo->discovery_retries)) ||
6675 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6676 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
6677 pinfo->hop_count)) ||
6678 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
6679 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
6680 pinfo->path_change_count)))
6681 goto nla_put_failure;
6683 nla_nest_end(msg, pinfoattr);
6685 genlmsg_end(msg, hdr);
6689 genlmsg_cancel(msg, hdr);
6693 static int nl80211_dump_mpath(struct sk_buff *skb,
6694 struct netlink_callback *cb)
6696 struct mpath_info pinfo;
6697 struct cfg80211_registered_device *rdev;
6698 struct wireless_dev *wdev;
6700 u8 next_hop[ETH_ALEN];
6701 int path_idx = cb->args[2];
6705 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
6709 if (!rdev->ops->dump_mpath) {
6714 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6720 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
6727 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6728 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6729 wdev->netdev, dst, next_hop,
6737 cb->args[2] = path_idx;
6744 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6748 struct net_device *dev = info->user_ptr[1];
6749 struct mpath_info pinfo;
6750 struct sk_buff *msg;
6752 u8 next_hop[ETH_ALEN];
6754 memset(&pinfo, 0, sizeof(pinfo));
6756 if (!info->attrs[NL80211_ATTR_MAC])
6759 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6761 if (!rdev->ops->get_mpath)
6764 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6767 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
6771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6775 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6776 dev, dst, next_hop, &pinfo) < 0) {
6781 return genlmsg_reply(msg, info);
6784 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6786 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6787 struct net_device *dev = info->user_ptr[1];
6789 u8 *next_hop = NULL;
6791 if (!info->attrs[NL80211_ATTR_MAC])
6794 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6797 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6798 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6800 if (!rdev->ops->change_mpath)
6803 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6806 return rdev_change_mpath(rdev, dev, dst, next_hop);
6809 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6812 struct net_device *dev = info->user_ptr[1];
6814 u8 *next_hop = NULL;
6816 if (!info->attrs[NL80211_ATTR_MAC])
6819 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6822 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6823 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6825 if (!rdev->ops->add_mpath)
6828 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6831 return rdev_add_mpath(rdev, dev, dst, next_hop);
6834 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6837 struct net_device *dev = info->user_ptr[1];
6840 if (info->attrs[NL80211_ATTR_MAC])
6841 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6843 if (!rdev->ops->del_mpath)
6846 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6849 return rdev_del_mpath(rdev, dev, dst);
6852 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6856 struct net_device *dev = info->user_ptr[1];
6857 struct mpath_info pinfo;
6858 struct sk_buff *msg;
6862 memset(&pinfo, 0, sizeof(pinfo));
6864 if (!info->attrs[NL80211_ATTR_MAC])
6867 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6869 if (!rdev->ops->get_mpp)
6872 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6875 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6883 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6884 dev, dst, mpp, &pinfo) < 0) {
6889 return genlmsg_reply(msg, info);
6892 static int nl80211_dump_mpp(struct sk_buff *skb,
6893 struct netlink_callback *cb)
6895 struct mpath_info pinfo;
6896 struct cfg80211_registered_device *rdev;
6897 struct wireless_dev *wdev;
6900 int path_idx = cb->args[2];
6904 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
6908 if (!rdev->ops->dump_mpp) {
6913 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6919 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6926 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6927 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6928 wdev->netdev, dst, mpp,
6936 cb->args[2] = path_idx;
6943 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6946 struct net_device *dev = info->user_ptr[1];
6947 struct wireless_dev *wdev = dev->ieee80211_ptr;
6948 struct bss_parameters params;
6951 memset(¶ms, 0, sizeof(params));
6952 /* default to not changing parameters */
6953 params.use_cts_prot = -1;
6954 params.use_short_preamble = -1;
6955 params.use_short_slot_time = -1;
6956 params.ap_isolate = -1;
6957 params.ht_opmode = -1;
6958 params.p2p_ctwindow = -1;
6959 params.p2p_opp_ps = -1;
6961 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6962 params.use_cts_prot =
6963 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6964 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6965 params.use_short_preamble =
6966 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6967 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6968 params.use_short_slot_time =
6969 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
6970 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6971 params.basic_rates =
6972 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6973 params.basic_rates_len =
6974 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6976 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6977 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
6978 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6980 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
6982 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6983 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6985 params.p2p_ctwindow =
6986 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
6987 if (params.p2p_ctwindow != 0 &&
6988 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6992 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6995 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6997 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
6998 params.p2p_opp_ps = tmp;
6999 if (params.p2p_opp_ps &&
7000 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
7004 if (!rdev->ops->change_bss)
7007 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
7008 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
7012 err = rdev_change_bss(rdev, dev, ¶ms);
7018 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
7022 enum nl80211_user_reg_hint_type user_reg_hint_type;
7026 * You should only get this when cfg80211 hasn't yet initialized
7027 * completely when built-in to the kernel right between the time
7028 * window between nl80211_init() and regulatory_init(), if that is
7031 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
7032 return -EINPROGRESS;
7034 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
7035 user_reg_hint_type =
7036 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
7038 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
7040 switch (user_reg_hint_type) {
7041 case NL80211_USER_REG_HINT_USER:
7042 case NL80211_USER_REG_HINT_CELL_BASE:
7043 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7046 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7047 return regulatory_hint_user(data, user_reg_hint_type);
7048 case NL80211_USER_REG_HINT_INDOOR:
7049 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
7050 owner_nlportid = info->snd_portid;
7051 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
7057 return regulatory_hint_indoor(is_indoor, owner_nlportid);
7063 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
7065 return reg_reload_regdb();
7068 static int nl80211_get_mesh_config(struct sk_buff *skb,
7069 struct genl_info *info)
7071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7072 struct net_device *dev = info->user_ptr[1];
7073 struct wireless_dev *wdev = dev->ieee80211_ptr;
7074 struct mesh_config cur_params;
7077 struct nlattr *pinfoattr;
7078 struct sk_buff *msg;
7080 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7083 if (!rdev->ops->get_mesh_config)
7087 /* If not connected, get default parameters */
7088 if (!wdev->mesh_id_len)
7089 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
7091 err = rdev_get_mesh_config(rdev, dev, &cur_params);
7097 /* Draw up a netlink message to send back */
7098 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7101 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7102 NL80211_CMD_GET_MESH_CONFIG);
7105 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
7107 goto nla_put_failure;
7108 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7109 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
7110 cur_params.dot11MeshRetryTimeout) ||
7111 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
7112 cur_params.dot11MeshConfirmTimeout) ||
7113 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
7114 cur_params.dot11MeshHoldingTimeout) ||
7115 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
7116 cur_params.dot11MeshMaxPeerLinks) ||
7117 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
7118 cur_params.dot11MeshMaxRetries) ||
7119 nla_put_u8(msg, NL80211_MESHCONF_TTL,
7120 cur_params.dot11MeshTTL) ||
7121 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
7122 cur_params.element_ttl) ||
7123 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
7124 cur_params.auto_open_plinks) ||
7125 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
7126 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
7127 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
7128 cur_params.dot11MeshHWMPmaxPREQretries) ||
7129 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
7130 cur_params.path_refresh_time) ||
7131 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
7132 cur_params.min_discovery_timeout) ||
7133 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
7134 cur_params.dot11MeshHWMPactivePathTimeout) ||
7135 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
7136 cur_params.dot11MeshHWMPpreqMinInterval) ||
7137 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
7138 cur_params.dot11MeshHWMPperrMinInterval) ||
7139 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
7140 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
7141 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
7142 cur_params.dot11MeshHWMPRootMode) ||
7143 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
7144 cur_params.dot11MeshHWMPRannInterval) ||
7145 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
7146 cur_params.dot11MeshGateAnnouncementProtocol) ||
7147 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
7148 cur_params.dot11MeshForwarding) ||
7149 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
7150 cur_params.rssi_threshold) ||
7151 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
7152 cur_params.ht_opmode) ||
7153 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
7154 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
7155 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
7156 cur_params.dot11MeshHWMProotInterval) ||
7157 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
7158 cur_params.dot11MeshHWMPconfirmationInterval) ||
7159 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
7160 cur_params.power_mode) ||
7161 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
7162 cur_params.dot11MeshAwakeWindowDuration) ||
7163 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
7164 cur_params.plink_timeout) ||
7165 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
7166 cur_params.dot11MeshConnectedToMeshGate) ||
7167 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN,
7168 cur_params.dot11MeshNolearn) ||
7169 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS,
7170 cur_params.dot11MeshConnectedToAuthServer))
7171 goto nla_put_failure;
7172 nla_nest_end(msg, pinfoattr);
7173 genlmsg_end(msg, hdr);
7174 return genlmsg_reply(msg, info);
7182 static const struct nla_policy
7183 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
7184 [NL80211_MESHCONF_RETRY_TIMEOUT] =
7185 NLA_POLICY_RANGE(NLA_U16, 1, 255),
7186 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
7187 NLA_POLICY_RANGE(NLA_U16, 1, 255),
7188 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
7189 NLA_POLICY_RANGE(NLA_U16, 1, 255),
7190 [NL80211_MESHCONF_MAX_PEER_LINKS] =
7191 NLA_POLICY_RANGE(NLA_U16, 0, 255),
7192 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
7193 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
7194 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
7195 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
7196 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
7197 NLA_POLICY_RANGE(NLA_U32, 1, 255),
7198 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
7199 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
7200 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
7201 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
7202 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
7203 NLA_POLICY_MIN(NLA_U16, 1),
7204 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
7205 NLA_POLICY_MIN(NLA_U16, 1),
7206 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
7207 NLA_POLICY_MIN(NLA_U16, 1),
7208 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
7209 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
7210 NLA_POLICY_MIN(NLA_U16, 1),
7211 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
7212 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
7213 [NL80211_MESHCONF_RSSI_THRESHOLD] =
7214 NLA_POLICY_RANGE(NLA_S32, -255, 0),
7215 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
7216 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
7217 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
7218 NLA_POLICY_MIN(NLA_U16, 1),
7219 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
7220 NLA_POLICY_MIN(NLA_U16, 1),
7221 [NL80211_MESHCONF_POWER_MODE] =
7222 NLA_POLICY_RANGE(NLA_U32,
7223 NL80211_MESH_POWER_ACTIVE,
7224 NL80211_MESH_POWER_MAX),
7225 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
7226 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
7227 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
7228 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
7229 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
7232 static const struct nla_policy
7233 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
7234 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
7235 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
7236 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
7237 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
7238 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
7239 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
7240 [NL80211_MESH_SETUP_IE] =
7241 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
7242 IEEE80211_MAX_DATA_LEN),
7243 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
7246 static int nl80211_parse_mesh_config(struct genl_info *info,
7247 struct mesh_config *cfg,
7250 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
7254 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
7257 cfg->param = fn(tb[attr]); \
7258 mask |= BIT((attr) - 1); \
7262 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
7264 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
7267 /* This makes sure that there aren't more than 32 mesh config
7268 * parameters (otherwise our bitfield scheme would not work.) */
7269 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
7271 /* Fill in the params struct */
7272 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
7273 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
7274 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
7275 NL80211_MESHCONF_CONFIRM_TIMEOUT,
7277 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
7278 NL80211_MESHCONF_HOLDING_TIMEOUT,
7280 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
7281 NL80211_MESHCONF_MAX_PEER_LINKS,
7283 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
7284 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
7285 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
7286 NL80211_MESHCONF_TTL, nla_get_u8);
7287 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
7288 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
7289 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
7290 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
7292 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
7294 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
7296 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
7297 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
7299 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
7300 NL80211_MESHCONF_PATH_REFRESH_TIME,
7302 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
7303 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
7305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
7306 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
7308 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
7310 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
7312 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
7313 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
7314 cfg->dot11MeshHWMPactivePathTimeout > 65535))
7316 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
7317 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
7319 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
7320 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
7322 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
7323 dot11MeshHWMPnetDiameterTraversalTime, mask,
7324 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
7326 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
7327 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
7328 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
7329 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
7331 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
7332 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
7334 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
7335 NL80211_MESHCONF_FORWARDING, nla_get_u8);
7336 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
7337 NL80211_MESHCONF_RSSI_THRESHOLD,
7339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
7340 NL80211_MESHCONF_CONNECTED_TO_GATE,
7342 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask,
7343 NL80211_MESHCONF_CONNECTED_TO_AS,
7346 * Check HT operation mode based on
7347 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
7349 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
7350 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
7352 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
7353 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
7354 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
7357 /* NON_HT_STA bit is reserved, but some programs set it */
7358 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
7360 cfg->ht_opmode = ht_opmode;
7361 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
7363 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
7364 dot11MeshHWMPactivePathToRootTimeout, mask,
7365 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
7367 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
7368 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
7369 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
7371 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
7372 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
7374 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
7376 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
7378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
7379 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
7380 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
7381 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
7382 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
7383 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
7384 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask,
7385 NL80211_MESHCONF_NOLEARN, nla_get_u8);
7391 #undef FILL_IN_MESH_PARAM_IF_SET
7394 static int nl80211_parse_mesh_setup(struct genl_info *info,
7395 struct mesh_setup *setup)
7397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7398 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
7400 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
7402 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack))
7405 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
7406 setup->sync_method =
7407 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
7408 IEEE80211_SYNC_METHOD_VENDOR :
7409 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
7411 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
7412 setup->path_sel_proto =
7413 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
7414 IEEE80211_PATH_PROTOCOL_VENDOR :
7415 IEEE80211_PATH_PROTOCOL_HWMP;
7417 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
7418 setup->path_metric =
7419 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
7420 IEEE80211_PATH_METRIC_VENDOR :
7421 IEEE80211_PATH_METRIC_AIRTIME;
7423 if (tb[NL80211_MESH_SETUP_IE]) {
7424 struct nlattr *ieattr =
7425 tb[NL80211_MESH_SETUP_IE];
7426 setup->ie = nla_data(ieattr);
7427 setup->ie_len = nla_len(ieattr);
7429 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
7430 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
7432 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
7433 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
7434 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
7435 if (setup->is_secure)
7436 setup->user_mpm = true;
7438 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
7439 if (!setup->user_mpm)
7442 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
7448 static int nl80211_update_mesh_config(struct sk_buff *skb,
7449 struct genl_info *info)
7451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7452 struct net_device *dev = info->user_ptr[1];
7453 struct wireless_dev *wdev = dev->ieee80211_ptr;
7454 struct mesh_config cfg;
7458 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7461 if (!rdev->ops->update_mesh_config)
7464 err = nl80211_parse_mesh_config(info, &cfg, &mask);
7469 if (!wdev->mesh_id_len)
7473 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
7480 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
7481 struct sk_buff *msg)
7483 struct nlattr *nl_reg_rules;
7486 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
7487 (regdom->dfs_region &&
7488 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
7489 goto nla_put_failure;
7491 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
7493 goto nla_put_failure;
7495 for (i = 0; i < regdom->n_reg_rules; i++) {
7496 struct nlattr *nl_reg_rule;
7497 const struct ieee80211_reg_rule *reg_rule;
7498 const struct ieee80211_freq_range *freq_range;
7499 const struct ieee80211_power_rule *power_rule;
7500 unsigned int max_bandwidth_khz;
7502 reg_rule = ®dom->reg_rules[i];
7503 freq_range = ®_rule->freq_range;
7504 power_rule = ®_rule->power_rule;
7506 nl_reg_rule = nla_nest_start_noflag(msg, i);
7508 goto nla_put_failure;
7510 max_bandwidth_khz = freq_range->max_bandwidth_khz;
7511 if (!max_bandwidth_khz)
7512 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
7515 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
7517 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
7518 freq_range->start_freq_khz) ||
7519 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
7520 freq_range->end_freq_khz) ||
7521 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
7522 max_bandwidth_khz) ||
7523 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
7524 power_rule->max_antenna_gain) ||
7525 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
7526 power_rule->max_eirp) ||
7527 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
7528 reg_rule->dfs_cac_ms))
7529 goto nla_put_failure;
7531 nla_nest_end(msg, nl_reg_rule);
7534 nla_nest_end(msg, nl_reg_rules);
7541 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
7543 const struct ieee80211_regdomain *regdom = NULL;
7544 struct cfg80211_registered_device *rdev;
7545 struct wiphy *wiphy = NULL;
7546 struct sk_buff *msg;
7549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7553 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7554 NL80211_CMD_GET_REG);
7558 if (info->attrs[NL80211_ATTR_WIPHY]) {
7561 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7564 return PTR_ERR(rdev);
7567 wiphy = &rdev->wiphy;
7568 self_managed = wiphy->regulatory_flags &
7569 REGULATORY_WIPHY_SELF_MANAGED;
7570 regdom = get_wiphy_regdom(wiphy);
7572 /* a self-managed-reg device must have a private regdom */
7573 if (WARN_ON(!regdom && self_managed)) {
7579 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7580 goto nla_put_failure;
7583 if (!wiphy && reg_last_request_cell_base() &&
7584 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7585 NL80211_USER_REG_HINT_CELL_BASE))
7586 goto nla_put_failure;
7591 regdom = rcu_dereference(cfg80211_regdomain);
7593 if (nl80211_put_regdom(regdom, msg))
7594 goto nla_put_failure_rcu;
7598 genlmsg_end(msg, hdr);
7599 return genlmsg_reply(msg, info);
7601 nla_put_failure_rcu:
7609 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
7610 u32 seq, int flags, struct wiphy *wiphy,
7611 const struct ieee80211_regdomain *regdom)
7613 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
7614 NL80211_CMD_GET_REG);
7619 genl_dump_check_consistent(cb, hdr);
7621 if (nl80211_put_regdom(regdom, msg))
7622 goto nla_put_failure;
7624 if (!wiphy && reg_last_request_cell_base() &&
7625 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7626 NL80211_USER_REG_HINT_CELL_BASE))
7627 goto nla_put_failure;
7630 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7631 goto nla_put_failure;
7633 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
7634 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
7635 goto nla_put_failure;
7637 genlmsg_end(msg, hdr);
7641 genlmsg_cancel(msg, hdr);
7645 static int nl80211_get_reg_dump(struct sk_buff *skb,
7646 struct netlink_callback *cb)
7648 const struct ieee80211_regdomain *regdom = NULL;
7649 struct cfg80211_registered_device *rdev;
7650 int err, reg_idx, start = cb->args[2];
7654 if (cfg80211_regdomain && start == 0) {
7655 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7657 rtnl_dereference(cfg80211_regdomain));
7662 /* the global regdom is idx 0 */
7664 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7665 regdom = get_wiphy_regdom(&rdev->wiphy);
7669 if (++reg_idx <= start)
7672 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7673 NLM_F_MULTI, &rdev->wiphy, regdom);
7680 cb->args[2] = reg_idx;
7687 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
7688 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
7689 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
7690 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
7691 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
7692 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
7693 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
7694 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
7695 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
7698 static int parse_reg_rule(struct nlattr *tb[],
7699 struct ieee80211_reg_rule *reg_rule)
7701 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
7702 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
7704 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
7706 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
7708 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
7710 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
7712 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
7715 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
7717 freq_range->start_freq_khz =
7718 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
7719 freq_range->end_freq_khz =
7720 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7721 freq_range->max_bandwidth_khz =
7722 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7724 power_rule->max_eirp =
7725 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7727 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7728 power_rule->max_antenna_gain =
7729 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7731 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7732 reg_rule->dfs_cac_ms =
7733 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7738 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7740 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7741 struct nlattr *nl_reg_rule;
7743 int rem_reg_rules, r;
7744 u32 num_rules = 0, rule_idx = 0;
7745 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
7746 struct ieee80211_regdomain *rd;
7748 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7751 if (!info->attrs[NL80211_ATTR_REG_RULES])
7754 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7756 if (info->attrs[NL80211_ATTR_DFS_REGION])
7757 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7759 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
7762 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
7766 if (!reg_is_valid_request(alpha2))
7769 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
7773 rd->n_reg_rules = num_rules;
7774 rd->alpha2[0] = alpha2[0];
7775 rd->alpha2[1] = alpha2[1];
7778 * Disable DFS master mode if the DFS region was
7779 * not supported or known on this kernel.
7781 if (reg_supported_dfs_region(dfs_region))
7782 rd->dfs_region = dfs_region;
7784 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
7786 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7787 nl_reg_rule, reg_rule_policy,
7791 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7797 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7803 /* set_regdom takes ownership of rd */
7804 return set_regdom(rd, REGD_SOURCE_CRDA);
7809 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
7811 static int validate_scan_freqs(struct nlattr *freqs)
7813 struct nlattr *attr1, *attr2;
7814 int n_channels = 0, tmp1, tmp2;
7816 nla_for_each_nested(attr1, freqs, tmp1)
7817 if (nla_len(attr1) != sizeof(u32))
7820 nla_for_each_nested(attr1, freqs, tmp1) {
7823 * Some hardware has a limited channel list for
7824 * scanning, and it is pretty much nonsensical
7825 * to scan for a channel twice, so disallow that
7826 * and don't require drivers to check that the
7827 * channel list they get isn't longer than what
7828 * they can scan, as long as they can scan all
7829 * the channels they registered at once.
7831 nla_for_each_nested(attr2, freqs, tmp2)
7832 if (attr1 != attr2 &&
7833 nla_get_u32(attr1) == nla_get_u32(attr2))
7840 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
7842 return b < NUM_NL80211_BANDS && wiphy->bands[b];
7845 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7846 struct cfg80211_bss_selection *bss_select)
7848 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7849 struct nlattr *nest;
7854 /* only process one nested attribute */
7855 nest = nla_data(nla);
7856 if (!nla_ok(nest, nla_len(nest)))
7859 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7860 nest, nl80211_bss_select_policy,
7865 /* only one attribute may be given */
7866 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7874 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7876 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7877 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7879 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7880 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7881 bss_select->param.band_pref =
7882 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7883 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7887 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7888 struct nl80211_bss_select_rssi_adjust *adj_param;
7890 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7891 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7892 bss_select->param.adjust.band = adj_param->band;
7893 bss_select->param.adjust.delta = adj_param->delta;
7894 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7898 /* user-space did not provide behaviour attribute */
7899 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7902 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7908 int nl80211_parse_random_mac(struct nlattr **attrs,
7909 u8 *mac_addr, u8 *mac_addr_mask)
7913 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
7914 eth_zero_addr(mac_addr);
7915 eth_zero_addr(mac_addr_mask);
7917 mac_addr_mask[0] = 0x3;
7922 /* need both or none */
7923 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7926 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7927 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7929 /* don't allow or configure an mcast address */
7930 if (!is_multicast_ether_addr(mac_addr_mask) ||
7931 is_multicast_ether_addr(mac_addr))
7935 * allow users to pass a MAC address that has bits set outside
7936 * of the mask, but don't bother drivers with having to deal
7939 for (i = 0; i < ETH_ALEN; i++)
7940 mac_addr[i] &= mac_addr_mask[i];
7945 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7947 ASSERT_WDEV_LOCK(wdev);
7949 if (!cfg80211_beaconing_iface_active(wdev))
7952 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7955 return regulatory_pre_cac_allowed(wdev->wiphy);
7958 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7959 enum nl80211_ext_feature_index feat)
7961 if (!(flags & flag))
7963 if (wiphy_ext_feature_isset(wiphy, feat))
7969 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7970 void *request, struct nlattr **attrs,
7973 u8 *mac_addr, *mac_addr_mask;
7975 enum nl80211_feature_flags randomness_flag;
7977 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7980 if (is_sched_scan) {
7981 struct cfg80211_sched_scan_request *req = request;
7983 randomness_flag = wdev ?
7984 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7985 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7986 flags = &req->flags;
7987 mac_addr = req->mac_addr;
7988 mac_addr_mask = req->mac_addr_mask;
7990 struct cfg80211_scan_request *req = request;
7992 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7993 flags = &req->flags;
7994 mac_addr = req->mac_addr;
7995 mac_addr_mask = req->mac_addr_mask;
7998 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
8000 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
8001 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
8002 !nl80211_check_scan_feat(wiphy, *flags,
8003 NL80211_SCAN_FLAG_LOW_SPAN,
8004 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
8005 !nl80211_check_scan_feat(wiphy, *flags,
8006 NL80211_SCAN_FLAG_LOW_POWER,
8007 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
8008 !nl80211_check_scan_feat(wiphy, *flags,
8009 NL80211_SCAN_FLAG_HIGH_ACCURACY,
8010 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
8011 !nl80211_check_scan_feat(wiphy, *flags,
8012 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
8013 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
8014 !nl80211_check_scan_feat(wiphy, *flags,
8015 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
8016 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
8017 !nl80211_check_scan_feat(wiphy, *flags,
8018 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
8019 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
8020 !nl80211_check_scan_feat(wiphy, *flags,
8021 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
8022 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
8023 !nl80211_check_scan_feat(wiphy, *flags,
8024 NL80211_SCAN_FLAG_RANDOM_SN,
8025 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
8026 !nl80211_check_scan_feat(wiphy, *flags,
8027 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
8028 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
8031 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
8034 if (!(wiphy->features & randomness_flag) ||
8035 (wdev && wdev->current_bss))
8038 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
8046 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
8048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8049 struct wireless_dev *wdev = info->user_ptr[1];
8050 struct cfg80211_scan_request *request;
8051 struct nlattr *scan_freqs = NULL;
8052 bool scan_freqs_khz = false;
8053 struct nlattr *attr;
8054 struct wiphy *wiphy;
8055 int err, tmp, n_ssids = 0, n_channels, i;
8058 wiphy = &rdev->wiphy;
8060 if (wdev->iftype == NL80211_IFTYPE_NAN)
8063 if (!rdev->ops->scan)
8066 if (rdev->scan_req || rdev->scan_msg)
8069 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) {
8070 if (!wiphy_ext_feature_isset(wiphy,
8071 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ))
8073 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ];
8074 scan_freqs_khz = true;
8075 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES])
8076 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES];
8079 n_channels = validate_scan_freqs(scan_freqs);
8083 n_channels = ieee80211_get_num_supported_channels(wiphy);
8086 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
8087 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
8090 if (n_ssids > wiphy->max_scan_ssids)
8093 if (info->attrs[NL80211_ATTR_IE])
8094 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8098 if (ie_len > wiphy->max_scan_ie_len)
8101 request = kzalloc(sizeof(*request)
8102 + sizeof(*request->ssids) * n_ssids
8103 + sizeof(*request->channels) * n_channels
8104 + ie_len, GFP_KERNEL);
8109 request->ssids = (void *)&request->channels[n_channels];
8110 request->n_ssids = n_ssids;
8113 request->ie = (void *)(request->ssids + n_ssids);
8115 request->ie = (void *)(request->channels + n_channels);
8120 /* user specified, bail out if channel not found */
8121 nla_for_each_nested(attr, scan_freqs, tmp) {
8122 struct ieee80211_channel *chan;
8123 int freq = nla_get_u32(attr);
8125 if (!scan_freqs_khz)
8126 freq = MHZ_TO_KHZ(freq);
8128 chan = ieee80211_get_channel_khz(wiphy, freq);
8134 /* ignore disabled channels */
8135 if (chan->flags & IEEE80211_CHAN_DISABLED)
8138 request->channels[i] = chan;
8142 enum nl80211_band band;
8145 for (band = 0; band < NUM_NL80211_BANDS; band++) {
8148 if (!wiphy->bands[band])
8150 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8151 struct ieee80211_channel *chan;
8153 chan = &wiphy->bands[band]->channels[j];
8155 if (chan->flags & IEEE80211_CHAN_DISABLED)
8158 request->channels[i] = chan;
8169 request->n_channels = i;
8172 if (!cfg80211_off_channel_oper_allowed(wdev)) {
8173 struct ieee80211_channel *chan;
8175 if (request->n_channels != 1) {
8181 chan = request->channels[0];
8182 if (chan->center_freq != wdev->chandef.chan->center_freq) {
8192 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
8193 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
8197 request->ssids[i].ssid_len = nla_len(attr);
8198 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
8203 if (info->attrs[NL80211_ATTR_IE]) {
8204 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8205 memcpy((void *)request->ie,
8206 nla_data(info->attrs[NL80211_ATTR_IE]),
8210 for (i = 0; i < NUM_NL80211_BANDS; i++)
8211 if (wiphy->bands[i])
8213 (1 << wiphy->bands[i]->n_bitrates) - 1;
8215 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
8216 nla_for_each_nested(attr,
8217 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
8219 enum nl80211_band band = nla_type(attr);
8221 if (band < 0 || band >= NUM_NL80211_BANDS) {
8226 if (!wiphy->bands[band])
8229 err = ieee80211_get_ratemask(wiphy->bands[band],
8232 &request->rates[band]);
8238 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
8239 if (!wiphy_ext_feature_isset(wiphy,
8240 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
8246 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
8247 request->duration_mandatory =
8248 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
8251 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
8257 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
8259 /* Initial implementation used NL80211_ATTR_MAC to set the specific
8260 * BSSID to scan for. This was problematic because that same attribute
8261 * was already used for another purpose (local random MAC address). The
8262 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
8263 * compatibility with older userspace components, also use the
8264 * NL80211_ATTR_MAC value here if it can be determined to be used for
8265 * the specific BSSID use case instead of the random MAC address
8266 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
8268 if (info->attrs[NL80211_ATTR_BSSID])
8269 memcpy(request->bssid,
8270 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
8271 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
8272 info->attrs[NL80211_ATTR_MAC])
8273 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
8276 eth_broadcast_addr(request->bssid);
8278 request->wdev = wdev;
8279 request->wiphy = &rdev->wiphy;
8280 request->scan_start = jiffies;
8282 rdev->scan_req = request;
8283 err = cfg80211_scan(rdev);
8288 nl80211_send_scan_start(rdev, wdev);
8290 dev_hold(wdev->netdev);
8295 rdev->scan_req = NULL;
8301 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
8303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8304 struct wireless_dev *wdev = info->user_ptr[1];
8306 if (!rdev->ops->abort_scan)
8312 if (!rdev->scan_req)
8315 rdev_abort_scan(rdev, wdev);
8320 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
8321 struct cfg80211_sched_scan_request *request,
8322 struct nlattr **attrs)
8324 int tmp, err, i = 0;
8325 struct nlattr *attr;
8327 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
8331 * If scan plans are not specified,
8332 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
8333 * case one scan plan will be set with the specified scan
8334 * interval and infinite number of iterations.
8336 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
8340 request->scan_plans[0].interval =
8341 DIV_ROUND_UP(interval, MSEC_PER_SEC);
8342 if (!request->scan_plans[0].interval)
8345 if (request->scan_plans[0].interval >
8346 wiphy->max_sched_scan_plan_interval)
8347 request->scan_plans[0].interval =
8348 wiphy->max_sched_scan_plan_interval;
8353 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
8354 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
8356 if (WARN_ON(i >= n_plans))
8359 err = nla_parse_nested_deprecated(plan,
8360 NL80211_SCHED_SCAN_PLAN_MAX,
8361 attr, nl80211_plan_policy,
8366 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
8369 request->scan_plans[i].interval =
8370 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
8371 if (!request->scan_plans[i].interval ||
8372 request->scan_plans[i].interval >
8373 wiphy->max_sched_scan_plan_interval)
8376 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
8377 request->scan_plans[i].iterations =
8378 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
8379 if (!request->scan_plans[i].iterations ||
8380 (request->scan_plans[i].iterations >
8381 wiphy->max_sched_scan_plan_iterations))
8383 } else if (i < n_plans - 1) {
8385 * All scan plans but the last one must specify
8386 * a finite number of iterations
8395 * The last scan plan must not specify the number of
8396 * iterations, it is supposed to run infinitely
8398 if (request->scan_plans[n_plans - 1].iterations)
8405 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
8406 struct cfg80211_match_set *match_sets,
8407 struct nlattr *tb_band_rssi,
8410 struct nlattr *attr;
8411 int i, tmp, ret = 0;
8413 if (!wiphy_ext_feature_isset(wiphy,
8414 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
8418 for (i = 0; i < NUM_NL80211_BANDS; i++)
8419 match_sets->per_band_rssi_thold[i] =
8420 NL80211_SCAN_RSSI_THOLD_OFF;
8424 for (i = 0; i < NUM_NL80211_BANDS; i++)
8425 match_sets->per_band_rssi_thold[i] = rssi_thold;
8427 nla_for_each_nested(attr, tb_band_rssi, tmp) {
8428 enum nl80211_band band = nla_type(attr);
8430 if (band < 0 || band >= NUM_NL80211_BANDS)
8433 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
8439 static struct cfg80211_sched_scan_request *
8440 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
8441 struct nlattr **attrs, int max_match_sets)
8443 struct cfg80211_sched_scan_request *request;
8444 struct nlattr *attr;
8445 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
8446 enum nl80211_band band;
8448 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
8449 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
8451 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
8452 n_channels = validate_scan_freqs(
8453 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
8455 return ERR_PTR(-EINVAL);
8457 n_channels = ieee80211_get_num_supported_channels(wiphy);
8460 if (attrs[NL80211_ATTR_SCAN_SSIDS])
8461 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
8465 if (n_ssids > wiphy->max_sched_scan_ssids)
8466 return ERR_PTR(-EINVAL);
8469 * First, count the number of 'real' matchsets. Due to an issue with
8470 * the old implementation, matchsets containing only the RSSI attribute
8471 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
8472 * RSSI for all matchsets, rather than their own matchset for reporting
8473 * all APs with a strong RSSI. This is needed to be compatible with
8474 * older userspace that treated a matchset with only the RSSI as the
8475 * global RSSI for all other matchsets - if there are other matchsets.
8477 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
8478 nla_for_each_nested(attr,
8479 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
8481 struct nlattr *rssi;
8483 err = nla_parse_nested_deprecated(tb,
8484 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8486 nl80211_match_policy,
8489 return ERR_PTR(err);
8491 /* SSID and BSSID are mutually exclusive */
8492 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
8493 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
8494 return ERR_PTR(-EINVAL);
8496 /* add other standalone attributes here */
8497 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
8498 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
8502 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8504 default_match_rssi = nla_get_s32(rssi);
8508 /* However, if there's no other matchset, add the RSSI one */
8509 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
8512 if (n_match_sets > max_match_sets)
8513 return ERR_PTR(-EINVAL);
8515 if (attrs[NL80211_ATTR_IE])
8516 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
8520 if (ie_len > wiphy->max_sched_scan_ie_len)
8521 return ERR_PTR(-EINVAL);
8523 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
8525 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
8526 * each scan plan already specifies its own interval
8528 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8529 return ERR_PTR(-EINVAL);
8531 nla_for_each_nested(attr,
8532 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
8536 * The scan interval attribute is kept for backward
8537 * compatibility. If no scan plans are specified and sched scan
8538 * interval is specified, one scan plan will be set with this
8539 * scan interval and infinite number of iterations.
8541 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8542 return ERR_PTR(-EINVAL);
8547 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
8548 return ERR_PTR(-EINVAL);
8550 if (!wiphy_ext_feature_isset(
8551 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
8552 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
8553 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
8554 return ERR_PTR(-EINVAL);
8556 request = kzalloc(sizeof(*request)
8557 + sizeof(*request->ssids) * n_ssids
8558 + sizeof(*request->match_sets) * n_match_sets
8559 + sizeof(*request->scan_plans) * n_plans
8560 + sizeof(*request->channels) * n_channels
8561 + ie_len, GFP_KERNEL);
8563 return ERR_PTR(-ENOMEM);
8566 request->ssids = (void *)&request->channels[n_channels];
8567 request->n_ssids = n_ssids;
8570 request->ie = (void *)(request->ssids + n_ssids);
8572 request->ie = (void *)(request->channels + n_channels);
8577 request->match_sets = (void *)(request->ie + ie_len);
8579 request->match_sets =
8580 (void *)(request->ssids + n_ssids);
8582 request->match_sets =
8583 (void *)(request->channels + n_channels);
8585 request->n_match_sets = n_match_sets;
8588 request->scan_plans = (void *)(request->match_sets +
8590 else if (request->ie)
8591 request->scan_plans = (void *)(request->ie + ie_len);
8593 request->scan_plans = (void *)(request->ssids + n_ssids);
8595 request->scan_plans = (void *)(request->channels + n_channels);
8597 request->n_scan_plans = n_plans;
8600 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
8601 /* user specified, bail out if channel not found */
8602 nla_for_each_nested(attr,
8603 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
8605 struct ieee80211_channel *chan;
8607 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
8614 /* ignore disabled channels */
8615 if (chan->flags & IEEE80211_CHAN_DISABLED)
8618 request->channels[i] = chan;
8623 for (band = 0; band < NUM_NL80211_BANDS; band++) {
8626 if (!wiphy->bands[band])
8628 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8629 struct ieee80211_channel *chan;
8631 chan = &wiphy->bands[band]->channels[j];
8633 if (chan->flags & IEEE80211_CHAN_DISABLED)
8636 request->channels[i] = chan;
8647 request->n_channels = i;
8651 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
8653 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
8657 request->ssids[i].ssid_len = nla_len(attr);
8658 memcpy(request->ssids[i].ssid, nla_data(attr),
8665 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
8666 nla_for_each_nested(attr,
8667 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
8669 struct nlattr *ssid, *bssid, *rssi;
8671 err = nla_parse_nested_deprecated(tb,
8672 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8674 nl80211_match_policy,
8678 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
8679 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
8681 if (!ssid && !bssid) {
8686 if (WARN_ON(i >= n_match_sets)) {
8687 /* this indicates a programming error,
8688 * the loop above should have verified
8696 memcpy(request->match_sets[i].ssid.ssid,
8697 nla_data(ssid), nla_len(ssid));
8698 request->match_sets[i].ssid.ssid_len =
8702 memcpy(request->match_sets[i].bssid,
8703 nla_data(bssid), ETH_ALEN);
8705 /* special attribute - old implementation w/a */
8706 request->match_sets[i].rssi_thold = default_match_rssi;
8707 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8709 request->match_sets[i].rssi_thold =
8712 /* Parse per band RSSI attribute */
8713 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
8714 &request->match_sets[i],
8715 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
8716 request->match_sets[i].rssi_thold);
8723 /* there was no other matchset, so the RSSI one is alone */
8724 if (i == 0 && n_match_sets)
8725 request->match_sets[0].rssi_thold = default_match_rssi;
8727 request->min_rssi_thold = INT_MAX;
8728 for (i = 0; i < n_match_sets; i++)
8729 request->min_rssi_thold =
8730 min(request->match_sets[i].rssi_thold,
8731 request->min_rssi_thold);
8733 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
8737 request->ie_len = ie_len;
8738 memcpy((void *)request->ie,
8739 nla_data(attrs[NL80211_ATTR_IE]),
8743 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8747 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8749 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8751 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8752 request->relative_rssi = nla_get_s8(
8753 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8754 request->relative_rssi_set = true;
8757 if (request->relative_rssi_set &&
8758 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8759 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8761 rssi_adjust = nla_data(
8762 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8763 request->rssi_adjust.band = rssi_adjust->band;
8764 request->rssi_adjust.delta = rssi_adjust->delta;
8765 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8771 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8775 request->scan_start = jiffies;
8781 return ERR_PTR(err);
8784 static int nl80211_start_sched_scan(struct sk_buff *skb,
8785 struct genl_info *info)
8787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8788 struct net_device *dev = info->user_ptr[1];
8789 struct wireless_dev *wdev = dev->ieee80211_ptr;
8790 struct cfg80211_sched_scan_request *sched_scan_req;
8794 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
8797 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8798 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8802 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
8804 rdev->wiphy.max_match_sets);
8806 err = PTR_ERR_OR_ZERO(sched_scan_req);
8810 /* leave request id zero for legacy request
8811 * or if driver does not support multi-scheduled scan
8813 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
8814 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
8816 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
8820 sched_scan_req->dev = dev;
8821 sched_scan_req->wiphy = &rdev->wiphy;
8823 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8824 sched_scan_req->owner_nlportid = info->snd_portid;
8826 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
8828 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
8832 kfree(sched_scan_req);
8837 static int nl80211_stop_sched_scan(struct sk_buff *skb,
8838 struct genl_info *info)
8840 struct cfg80211_sched_scan_request *req;
8841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8844 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
8847 if (info->attrs[NL80211_ATTR_COOKIE]) {
8848 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8849 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8852 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8853 struct cfg80211_sched_scan_request,
8855 if (!req || req->reqid ||
8856 (req->owner_nlportid &&
8857 req->owner_nlportid != info->snd_portid))
8860 return cfg80211_stop_sched_scan_req(rdev, req, false);
8863 static int nl80211_start_radar_detection(struct sk_buff *skb,
8864 struct genl_info *info)
8866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8867 struct net_device *dev = info->user_ptr[1];
8868 struct wireless_dev *wdev = dev->ieee80211_ptr;
8869 struct wiphy *wiphy = wdev->wiphy;
8870 struct cfg80211_chan_def chandef;
8871 enum nl80211_dfs_regions dfs_region;
8872 unsigned int cac_time_ms;
8875 dfs_region = reg_get_dfs_region(wiphy);
8876 if (dfs_region == NL80211_DFS_UNSET)
8879 err = nl80211_parse_chandef(rdev, info, &chandef);
8883 if (netif_carrier_ok(dev))
8886 if (wdev->cac_started)
8889 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8896 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
8899 /* CAC start is offloaded to HW and can't be started manually */
8900 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8903 if (!rdev->ops->start_radar_detection)
8906 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8907 if (WARN_ON(!cac_time_ms))
8908 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8910 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
8912 wdev->chandef = chandef;
8913 wdev->cac_started = true;
8914 wdev->cac_start_time = jiffies;
8915 wdev->cac_time_ms = cac_time_ms;
8920 static int nl80211_notify_radar_detection(struct sk_buff *skb,
8921 struct genl_info *info)
8923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8924 struct net_device *dev = info->user_ptr[1];
8925 struct wireless_dev *wdev = dev->ieee80211_ptr;
8926 struct wiphy *wiphy = wdev->wiphy;
8927 struct cfg80211_chan_def chandef;
8928 enum nl80211_dfs_regions dfs_region;
8931 dfs_region = reg_get_dfs_region(wiphy);
8932 if (dfs_region == NL80211_DFS_UNSET) {
8933 GENL_SET_ERR_MSG(info,
8934 "DFS Region is not set. Unexpected Radar indication");
8938 err = nl80211_parse_chandef(rdev, info, &chandef);
8940 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8944 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8946 GENL_SET_ERR_MSG(info, "chandef is invalid");
8951 GENL_SET_ERR_MSG(info,
8952 "Unexpected Radar indication for chandef/iftype");
8956 /* Do not process this notification if radar is already detected
8957 * by kernel on this channel, and return success.
8959 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8962 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8964 cfg80211_sched_dfs_chan_update(rdev);
8966 rdev->radar_chandef = chandef;
8968 /* Propagate this notification to other radios as well */
8969 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8974 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8977 struct net_device *dev = info->user_ptr[1];
8978 struct wireless_dev *wdev = dev->ieee80211_ptr;
8979 struct cfg80211_csa_settings params;
8980 /* csa_attrs is defined static to avoid waste of stack size - this
8981 * function is called under RTNL lock, so this should not be a problem.
8983 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
8985 bool need_new_beacon = false;
8986 bool need_handle_dfs_flag = true;
8990 if (!rdev->ops->channel_switch ||
8991 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8994 switch (dev->ieee80211_ptr->iftype) {
8995 case NL80211_IFTYPE_AP:
8996 case NL80211_IFTYPE_P2P_GO:
8997 need_new_beacon = true;
8998 /* For all modes except AP the handle_dfs flag needs to be
8999 * supplied to tell the kernel that userspace will handle radar
9000 * events when they happen. Otherwise a switch to a channel
9001 * requiring DFS will be rejected.
9003 need_handle_dfs_flag = false;
9005 /* useless if AP is not running */
9006 if (!wdev->beacon_interval)
9009 case NL80211_IFTYPE_ADHOC:
9010 if (!wdev->ssid_len)
9013 case NL80211_IFTYPE_MESH_POINT:
9014 if (!wdev->mesh_id_len)
9021 memset(¶ms, 0, sizeof(params));
9022 params.beacon_csa.ftm_responder = -1;
9024 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9025 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
9028 /* only important for AP, IBSS and mesh create IEs internally */
9029 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
9032 /* Even though the attribute is u32, the specification says
9033 * u8, so let's make sure we don't overflow.
9035 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
9039 params.count = cs_count;
9041 if (!need_new_beacon)
9044 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after);
9048 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
9049 info->attrs[NL80211_ATTR_CSA_IES],
9050 nl80211_policy, info->extack);
9054 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa);
9058 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON])
9061 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
9062 if (!len || (len % sizeof(u16)))
9065 params.n_counter_offsets_beacon = len / sizeof(u16);
9066 if (rdev->wiphy.max_num_csa_counters &&
9067 (params.n_counter_offsets_beacon >
9068 rdev->wiphy.max_num_csa_counters))
9071 params.counter_offsets_beacon =
9072 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
9074 /* sanity checks - counters should fit and be the same */
9075 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
9076 u16 offset = params.counter_offsets_beacon[i];
9078 if (offset >= params.beacon_csa.tail_len)
9081 if (params.beacon_csa.tail[offset] != params.count)
9085 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
9086 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
9087 if (!len || (len % sizeof(u16)))
9090 params.n_counter_offsets_presp = len / sizeof(u16);
9091 if (rdev->wiphy.max_num_csa_counters &&
9092 (params.n_counter_offsets_presp >
9093 rdev->wiphy.max_num_csa_counters))
9096 params.counter_offsets_presp =
9097 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
9099 /* sanity checks - counters should fit and be the same */
9100 for (i = 0; i < params.n_counter_offsets_presp; i++) {
9101 u16 offset = params.counter_offsets_presp[i];
9103 if (offset >= params.beacon_csa.probe_resp_len)
9106 if (params.beacon_csa.probe_resp[offset] !=
9113 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
9117 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
9121 err = cfg80211_chandef_dfs_required(wdev->wiphy,
9128 params.radar_required = true;
9129 if (need_handle_dfs_flag &&
9130 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
9135 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
9136 params.block_tx = true;
9139 err = rdev_channel_switch(rdev, dev, ¶ms);
9145 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
9147 struct cfg80211_registered_device *rdev,
9148 struct wireless_dev *wdev,
9149 struct cfg80211_internal_bss *intbss)
9151 struct cfg80211_bss *res = &intbss->pub;
9152 const struct cfg80211_bss_ies *ies;
9156 ASSERT_WDEV_LOCK(wdev);
9158 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
9159 NL80211_CMD_NEW_SCAN_RESULTS);
9163 genl_dump_check_consistent(cb, hdr);
9165 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
9166 goto nla_put_failure;
9168 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
9169 goto nla_put_failure;
9170 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
9172 goto nla_put_failure;
9174 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
9176 goto nla_put_failure;
9177 if ((!is_zero_ether_addr(res->bssid) &&
9178 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
9179 goto nla_put_failure;
9182 /* indicate whether we have probe response data or not */
9183 if (rcu_access_pointer(res->proberesp_ies) &&
9184 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
9185 goto fail_unlock_rcu;
9187 /* this pointer prefers to be pointed to probe response data
9188 * but is always valid
9190 ies = rcu_dereference(res->ies);
9192 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
9194 goto fail_unlock_rcu;
9195 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
9196 ies->len, ies->data))
9197 goto fail_unlock_rcu;
9200 /* and this pointer is always (unless driver didn't know) beacon data */
9201 ies = rcu_dereference(res->beacon_ies);
9202 if (ies && ies->from_beacon) {
9203 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
9205 goto fail_unlock_rcu;
9206 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
9207 ies->len, ies->data))
9208 goto fail_unlock_rcu;
9212 if (res->beacon_interval &&
9213 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
9214 goto nla_put_failure;
9215 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
9216 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
9217 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET,
9218 res->channel->freq_offset) ||
9219 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
9220 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
9221 jiffies_to_msecs(jiffies - intbss->ts)))
9222 goto nla_put_failure;
9224 if (intbss->parent_tsf &&
9225 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
9226 intbss->parent_tsf, NL80211_BSS_PAD) ||
9227 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
9228 intbss->parent_bssid)))
9229 goto nla_put_failure;
9231 if (intbss->ts_boottime &&
9232 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
9233 intbss->ts_boottime, NL80211_BSS_PAD))
9234 goto nla_put_failure;
9236 if (!nl80211_put_signal(msg, intbss->pub.chains,
9237 intbss->pub.chain_signal,
9238 NL80211_BSS_CHAIN_SIGNAL))
9239 goto nla_put_failure;
9241 switch (rdev->wiphy.signal_type) {
9242 case CFG80211_SIGNAL_TYPE_MBM:
9243 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
9244 goto nla_put_failure;
9246 case CFG80211_SIGNAL_TYPE_UNSPEC:
9247 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
9248 goto nla_put_failure;
9254 switch (wdev->iftype) {
9255 case NL80211_IFTYPE_P2P_CLIENT:
9256 case NL80211_IFTYPE_STATION:
9257 if (intbss == wdev->current_bss &&
9258 nla_put_u32(msg, NL80211_BSS_STATUS,
9259 NL80211_BSS_STATUS_ASSOCIATED))
9260 goto nla_put_failure;
9262 case NL80211_IFTYPE_ADHOC:
9263 if (intbss == wdev->current_bss &&
9264 nla_put_u32(msg, NL80211_BSS_STATUS,
9265 NL80211_BSS_STATUS_IBSS_JOINED))
9266 goto nla_put_failure;
9272 nla_nest_end(msg, bss);
9274 genlmsg_end(msg, hdr);
9280 genlmsg_cancel(msg, hdr);
9284 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
9286 struct cfg80211_registered_device *rdev;
9287 struct cfg80211_internal_bss *scan;
9288 struct wireless_dev *wdev;
9289 int start = cb->args[2], idx = 0;
9293 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
9300 spin_lock_bh(&rdev->bss_lock);
9303 * dump_scan will be called multiple times to break up the scan results
9304 * into multiple messages. It is unlikely that any more bss-es will be
9305 * expired after the first call, so only call only call this on the
9306 * first dump_scan invocation.
9309 cfg80211_bss_expire(rdev);
9311 cb->seq = rdev->bss_generation;
9313 list_for_each_entry(scan, &rdev->bss_list, list) {
9316 if (nl80211_send_bss(skb, cb,
9317 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9318 rdev, wdev, scan) < 0) {
9324 spin_unlock_bh(&rdev->bss_lock);
9333 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
9334 int flags, struct net_device *dev,
9335 bool allow_radio_stats,
9336 struct survey_info *survey)
9339 struct nlattr *infoattr;
9341 /* skip radio stats if userspace didn't request them */
9342 if (!survey->channel && !allow_radio_stats)
9345 hdr = nl80211hdr_put(msg, portid, seq, flags,
9346 NL80211_CMD_NEW_SURVEY_RESULTS);
9350 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
9351 goto nla_put_failure;
9353 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
9355 goto nla_put_failure;
9357 if (survey->channel &&
9358 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
9359 survey->channel->center_freq))
9360 goto nla_put_failure;
9362 if (survey->channel && survey->channel->freq_offset &&
9363 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET,
9364 survey->channel->freq_offset))
9365 goto nla_put_failure;
9367 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
9368 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
9369 goto nla_put_failure;
9370 if ((survey->filled & SURVEY_INFO_IN_USE) &&
9371 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
9372 goto nla_put_failure;
9373 if ((survey->filled & SURVEY_INFO_TIME) &&
9374 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
9375 survey->time, NL80211_SURVEY_INFO_PAD))
9376 goto nla_put_failure;
9377 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
9378 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
9379 survey->time_busy, NL80211_SURVEY_INFO_PAD))
9380 goto nla_put_failure;
9381 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
9382 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
9383 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
9384 goto nla_put_failure;
9385 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
9386 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
9387 survey->time_rx, NL80211_SURVEY_INFO_PAD))
9388 goto nla_put_failure;
9389 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
9390 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
9391 survey->time_tx, NL80211_SURVEY_INFO_PAD))
9392 goto nla_put_failure;
9393 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
9394 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
9395 survey->time_scan, NL80211_SURVEY_INFO_PAD))
9396 goto nla_put_failure;
9397 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
9398 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
9399 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
9400 goto nla_put_failure;
9402 nla_nest_end(msg, infoattr);
9404 genlmsg_end(msg, hdr);
9408 genlmsg_cancel(msg, hdr);
9412 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
9414 struct nlattr **attrbuf;
9415 struct survey_info survey;
9416 struct cfg80211_registered_device *rdev;
9417 struct wireless_dev *wdev;
9418 int survey_idx = cb->args[2];
9422 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
9427 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
9431 /* prepare_wdev_dump parsed the attributes */
9432 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
9434 if (!wdev->netdev) {
9439 if (!rdev->ops->dump_survey) {
9445 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
9451 /* don't send disabled channels, but do send non-channel data */
9452 if (survey.channel &&
9453 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
9458 if (nl80211_send_survey(skb,
9459 NETLINK_CB(cb->skb).portid,
9460 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9461 wdev->netdev, radio_stats, &survey) < 0)
9467 cb->args[2] = survey_idx;
9475 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
9477 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
9478 NL80211_WPA_VERSION_2 |
9479 NL80211_WPA_VERSION_3));
9482 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
9484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9485 struct net_device *dev = info->user_ptr[1];
9486 struct ieee80211_channel *chan;
9487 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
9488 int err, ssid_len, ie_len = 0, auth_data_len = 0;
9489 enum nl80211_auth_type auth_type;
9490 struct key_parse key;
9491 bool local_state_change;
9494 if (!info->attrs[NL80211_ATTR_MAC])
9497 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
9500 if (!info->attrs[NL80211_ATTR_SSID])
9503 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9506 err = nl80211_parse_key(info, &key);
9511 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
9513 if (!key.p.key || !key.p.key_len)
9515 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
9516 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
9517 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
9518 key.p.key_len != WLAN_KEY_LEN_WEP104))
9531 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
9532 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
9541 if (!rdev->ops->auth)
9544 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9545 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9548 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9549 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
9550 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
9552 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
9554 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
9558 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9559 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9561 if (info->attrs[NL80211_ATTR_IE]) {
9562 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9563 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9566 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9567 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
9570 if ((auth_type == NL80211_AUTHTYPE_SAE ||
9571 auth_type == NL80211_AUTHTYPE_FILS_SK ||
9572 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
9573 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
9574 !info->attrs[NL80211_ATTR_AUTH_DATA])
9577 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
9578 if (auth_type != NL80211_AUTHTYPE_SAE &&
9579 auth_type != NL80211_AUTHTYPE_FILS_SK &&
9580 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
9581 auth_type != NL80211_AUTHTYPE_FILS_PK)
9583 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
9584 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
9587 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9590 * Since we no longer track auth state, ignore
9591 * requests to only change local state.
9593 if (local_state_change)
9596 wdev_lock(dev->ieee80211_ptr);
9597 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
9598 ssid, ssid_len, ie, ie_len,
9599 key.p.key, key.p.key_len, key.idx,
9600 auth_data, auth_data_len);
9601 wdev_unlock(dev->ieee80211_ptr);
9605 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
9606 struct genl_info *info)
9608 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9609 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
9613 if (!rdev->ops->tx_control_port ||
9614 !wiphy_ext_feature_isset(&rdev->wiphy,
9615 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
9621 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
9622 struct genl_info *info,
9623 struct cfg80211_crypto_settings *settings,
9626 memset(settings, 0, sizeof(*settings));
9628 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9630 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9633 proto = nla_get_u16(
9634 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
9635 settings->control_port_ethertype = cpu_to_be16(proto);
9636 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
9639 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
9640 settings->control_port_no_encrypt = true;
9642 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
9644 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9645 int r = validate_pae_over_nl80211(rdev, info);
9650 settings->control_port_over_nl80211 = true;
9652 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH])
9653 settings->control_port_no_preauth = true;
9656 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
9660 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9661 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9662 settings->n_ciphers_pairwise = len / sizeof(u32);
9664 if (len % sizeof(u32))
9667 if (settings->n_ciphers_pairwise > cipher_limit)
9670 memcpy(settings->ciphers_pairwise, data, len);
9672 for (i = 0; i < settings->n_ciphers_pairwise; i++)
9673 if (!cfg80211_supported_cipher_suite(
9675 settings->ciphers_pairwise[i]))
9679 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
9680 settings->cipher_group =
9681 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
9682 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9683 settings->cipher_group))
9687 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
9688 settings->wpa_versions =
9689 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
9690 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
9694 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
9698 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
9699 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
9700 settings->n_akm_suites = len / sizeof(u32);
9702 if (len % sizeof(u32))
9705 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9708 memcpy(settings->akm_suites, data, len);
9711 if (info->attrs[NL80211_ATTR_PMK]) {
9712 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
9714 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9715 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
9716 !wiphy_ext_feature_isset(&rdev->wiphy,
9717 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
9719 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9722 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9723 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9724 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
9725 !wiphy_ext_feature_isset(&rdev->wiphy,
9726 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
9729 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9730 settings->sae_pwd_len =
9731 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9737 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9740 struct net_device *dev = info->user_ptr[1];
9741 struct ieee80211_channel *chan;
9742 struct cfg80211_assoc_request req = {};
9743 const u8 *bssid, *ssid;
9744 int err, ssid_len = 0;
9747 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9748 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9751 if (!info->attrs[NL80211_ATTR_MAC] ||
9752 !info->attrs[NL80211_ATTR_SSID] ||
9753 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
9756 if (!rdev->ops->assoc)
9759 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9760 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9763 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9765 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
9766 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
9768 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
9769 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
9773 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9774 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9776 if (info->attrs[NL80211_ATTR_IE]) {
9777 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9778 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9781 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9782 enum nl80211_mfp mfp =
9783 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
9784 if (mfp == NL80211_MFP_REQUIRED)
9786 else if (mfp != NL80211_MFP_NO)
9790 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9791 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9793 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9794 req.flags |= ASSOC_REQ_DISABLE_HT;
9796 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9797 memcpy(&req.ht_capa_mask,
9798 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9799 sizeof(req.ht_capa_mask));
9801 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9802 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9804 memcpy(&req.ht_capa,
9805 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9806 sizeof(req.ht_capa));
9809 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9810 req.flags |= ASSOC_REQ_DISABLE_VHT;
9812 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9813 memcpy(&req.vht_capa_mask,
9814 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9815 sizeof(req.vht_capa_mask));
9817 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9818 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9820 memcpy(&req.vht_capa,
9821 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9822 sizeof(req.vht_capa));
9825 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
9826 if (!((rdev->wiphy.features &
9827 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9828 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9829 !wiphy_ext_feature_isset(&rdev->wiphy,
9830 NL80211_EXT_FEATURE_RRM))
9832 req.flags |= ASSOC_REQ_USE_RRM;
9835 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9836 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9837 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9838 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9841 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9844 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) {
9845 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY])
9847 memcpy(&req.s1g_capa_mask,
9848 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]),
9849 sizeof(req.s1g_capa_mask));
9852 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) {
9853 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK])
9855 memcpy(&req.s1g_capa,
9856 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]),
9857 sizeof(req.s1g_capa));
9860 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
9862 wdev_lock(dev->ieee80211_ptr);
9864 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9865 ssid, ssid_len, &req);
9867 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9868 dev->ieee80211_ptr->conn_owner_nlportid =
9870 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9874 wdev_unlock(dev->ieee80211_ptr);
9880 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9882 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9883 struct net_device *dev = info->user_ptr[1];
9884 const u8 *ie = NULL, *bssid;
9885 int ie_len = 0, err;
9887 bool local_state_change;
9889 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9890 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9893 if (!info->attrs[NL80211_ATTR_MAC])
9896 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9899 if (!rdev->ops->deauth)
9902 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9903 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9906 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9908 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9909 if (reason_code == 0) {
9910 /* Reason Code 0 is reserved */
9914 if (info->attrs[NL80211_ATTR_IE]) {
9915 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9916 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9919 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9921 wdev_lock(dev->ieee80211_ptr);
9922 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9923 local_state_change);
9924 wdev_unlock(dev->ieee80211_ptr);
9928 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9930 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9931 struct net_device *dev = info->user_ptr[1];
9932 const u8 *ie = NULL, *bssid;
9933 int ie_len = 0, err;
9935 bool local_state_change;
9937 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9938 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9941 if (!info->attrs[NL80211_ATTR_MAC])
9944 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9947 if (!rdev->ops->disassoc)
9950 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9951 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9954 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9956 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9957 if (reason_code == 0) {
9958 /* Reason Code 0 is reserved */
9962 if (info->attrs[NL80211_ATTR_IE]) {
9963 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9964 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9967 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9969 wdev_lock(dev->ieee80211_ptr);
9970 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9971 local_state_change);
9972 wdev_unlock(dev->ieee80211_ptr);
9977 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
9978 int mcast_rate[NUM_NL80211_BANDS],
9981 struct wiphy *wiphy = &rdev->wiphy;
9985 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9986 struct ieee80211_supported_band *sband;
9988 sband = wiphy->bands[band];
9992 for (i = 0; i < sband->n_bitrates; i++) {
9993 if (sband->bitrates[i].bitrate == rateval) {
9994 mcast_rate[band] = i + 1;
10004 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
10006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10007 struct net_device *dev = info->user_ptr[1];
10008 struct cfg80211_ibss_params ibss;
10009 struct wiphy *wiphy;
10010 struct cfg80211_cached_keys *connkeys = NULL;
10013 memset(&ibss, 0, sizeof(ibss));
10015 if (!info->attrs[NL80211_ATTR_SSID] ||
10016 !nla_len(info->attrs[NL80211_ATTR_SSID]))
10019 ibss.beacon_interval = 100;
10021 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
10022 ibss.beacon_interval =
10023 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
10025 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
10026 ibss.beacon_interval);
10030 if (!rdev->ops->join_ibss)
10031 return -EOPNOTSUPP;
10033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
10034 return -EOPNOTSUPP;
10036 wiphy = &rdev->wiphy;
10038 if (info->attrs[NL80211_ATTR_MAC]) {
10039 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10041 if (!is_valid_ether_addr(ibss.bssid))
10044 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10045 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10047 if (info->attrs[NL80211_ATTR_IE]) {
10048 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10049 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10052 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
10056 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
10057 NL80211_IFTYPE_ADHOC))
10060 switch (ibss.chandef.width) {
10061 case NL80211_CHAN_WIDTH_5:
10062 case NL80211_CHAN_WIDTH_10:
10063 case NL80211_CHAN_WIDTH_20_NOHT:
10065 case NL80211_CHAN_WIDTH_20:
10066 case NL80211_CHAN_WIDTH_40:
10067 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
10070 case NL80211_CHAN_WIDTH_80:
10071 case NL80211_CHAN_WIDTH_80P80:
10072 case NL80211_CHAN_WIDTH_160:
10073 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
10075 if (!wiphy_ext_feature_isset(&rdev->wiphy,
10076 NL80211_EXT_FEATURE_VHT_IBSS))
10083 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
10084 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
10086 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10088 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10090 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10091 struct ieee80211_supported_band *sband =
10092 wiphy->bands[ibss.chandef.chan->band];
10094 err = ieee80211_get_ratemask(sband, rates, n_rates,
10095 &ibss.basic_rates);
10100 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10101 memcpy(&ibss.ht_capa_mask,
10102 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
10103 sizeof(ibss.ht_capa_mask));
10105 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
10106 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10108 memcpy(&ibss.ht_capa,
10109 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10110 sizeof(ibss.ht_capa));
10113 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10114 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
10115 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10118 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
10119 bool no_ht = false;
10121 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
10122 if (IS_ERR(connkeys))
10123 return PTR_ERR(connkeys);
10125 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
10127 kfree_sensitive(connkeys);
10132 ibss.control_port =
10133 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
10135 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10136 int r = validate_pae_over_nl80211(rdev, info);
10139 kfree_sensitive(connkeys);
10143 ibss.control_port_over_nl80211 = true;
10146 ibss.userspace_handles_dfs =
10147 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10149 wdev_lock(dev->ieee80211_ptr);
10150 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
10152 kfree_sensitive(connkeys);
10153 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
10154 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10155 wdev_unlock(dev->ieee80211_ptr);
10160 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
10162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10163 struct net_device *dev = info->user_ptr[1];
10165 if (!rdev->ops->leave_ibss)
10166 return -EOPNOTSUPP;
10168 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
10169 return -EOPNOTSUPP;
10171 return cfg80211_leave_ibss(rdev, dev, false);
10174 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
10176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10177 struct net_device *dev = info->user_ptr[1];
10178 int mcast_rate[NUM_NL80211_BANDS];
10182 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
10183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
10184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
10185 return -EOPNOTSUPP;
10187 if (!rdev->ops->set_mcast_rate)
10188 return -EOPNOTSUPP;
10190 memset(mcast_rate, 0, sizeof(mcast_rate));
10192 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
10195 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
10196 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
10199 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
10204 static struct sk_buff *
10205 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
10206 struct wireless_dev *wdev, int approxlen,
10207 u32 portid, u32 seq, enum nl80211_commands cmd,
10208 enum nl80211_attrs attr,
10209 const struct nl80211_vendor_cmd_info *info,
10212 struct sk_buff *skb;
10214 struct nlattr *data;
10216 skb = nlmsg_new(approxlen + 100, gfp);
10220 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
10226 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10227 goto nla_put_failure;
10230 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
10232 goto nla_put_failure;
10233 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
10235 goto nla_put_failure;
10239 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10240 wdev_id(wdev), NL80211_ATTR_PAD))
10241 goto nla_put_failure;
10242 if (wdev->netdev &&
10243 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
10244 wdev->netdev->ifindex))
10245 goto nla_put_failure;
10248 data = nla_nest_start_noflag(skb, attr);
10250 goto nla_put_failure;
10252 ((void **)skb->cb)[0] = rdev;
10253 ((void **)skb->cb)[1] = hdr;
10254 ((void **)skb->cb)[2] = data;
10263 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
10264 struct wireless_dev *wdev,
10265 enum nl80211_commands cmd,
10266 enum nl80211_attrs attr,
10267 unsigned int portid,
10268 int vendor_event_idx,
10269 int approxlen, gfp_t gfp)
10271 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
10272 const struct nl80211_vendor_cmd_info *info;
10275 case NL80211_CMD_TESTMODE:
10276 if (WARN_ON(vendor_event_idx != -1))
10280 case NL80211_CMD_VENDOR:
10281 if (WARN_ON(vendor_event_idx < 0 ||
10282 vendor_event_idx >= wiphy->n_vendor_events))
10284 info = &wiphy->vendor_events[vendor_event_idx];
10291 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
10292 cmd, attr, info, gfp);
10294 EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
10296 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
10298 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10299 void *hdr = ((void **)skb->cb)[1];
10300 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
10301 struct nlattr *data = ((void **)skb->cb)[2];
10302 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
10304 /* clear CB data for netlink core to own from now on */
10305 memset(skb->cb, 0, sizeof(skb->cb));
10307 nla_nest_end(skb, data);
10308 genlmsg_end(skb, hdr);
10310 if (nlhdr->nlmsg_pid) {
10311 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
10314 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
10315 mcgrp = NL80211_MCGRP_VENDOR;
10317 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
10318 skb, 0, mcgrp, gfp);
10321 EXPORT_SYMBOL(__cfg80211_send_event_skb);
10323 #ifdef CONFIG_NL80211_TESTMODE
10324 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
10326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10327 struct wireless_dev *wdev =
10328 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10331 if (!rdev->ops->testmode_cmd)
10332 return -EOPNOTSUPP;
10334 if (IS_ERR(wdev)) {
10335 err = PTR_ERR(wdev);
10336 if (err != -EINVAL)
10339 } else if (wdev->wiphy != &rdev->wiphy) {
10343 if (!info->attrs[NL80211_ATTR_TESTDATA])
10346 rdev->cur_cmd_info = info;
10347 err = rdev_testmode_cmd(rdev, wdev,
10348 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
10349 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
10350 rdev->cur_cmd_info = NULL;
10355 static int nl80211_testmode_dump(struct sk_buff *skb,
10356 struct netlink_callback *cb)
10358 struct cfg80211_registered_device *rdev;
10359 struct nlattr **attrbuf = NULL;
10369 * 0 is a valid index, but not valid for args[0],
10370 * so we need to offset by 1.
10372 phy_idx = cb->args[0] - 1;
10374 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
10380 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
10387 err = nlmsg_parse_deprecated(cb->nlh,
10388 GENL_HDRLEN + nl80211_fam.hdrsize,
10389 attrbuf, nl80211_fam.maxattr,
10390 nl80211_policy, NULL);
10394 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
10395 if (IS_ERR(rdev)) {
10396 err = PTR_ERR(rdev);
10399 phy_idx = rdev->wiphy_idx;
10401 if (attrbuf[NL80211_ATTR_TESTDATA])
10402 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
10406 data = nla_data((void *)cb->args[1]);
10407 data_len = nla_len((void *)cb->args[1]);
10410 if (!rdev->ops->testmode_dump) {
10416 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10417 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10418 NL80211_CMD_TESTMODE);
10419 struct nlattr *tmdata;
10424 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
10425 genlmsg_cancel(skb, hdr);
10429 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
10431 genlmsg_cancel(skb, hdr);
10434 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
10435 nla_nest_end(skb, tmdata);
10437 if (err == -ENOBUFS || err == -ENOENT) {
10438 genlmsg_cancel(skb, hdr);
10441 genlmsg_cancel(skb, hdr);
10445 genlmsg_end(skb, hdr);
10450 cb->args[0] = phy_idx + 1;
10458 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
10460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10461 struct net_device *dev = info->user_ptr[1];
10462 struct cfg80211_connect_params connect;
10463 struct wiphy *wiphy;
10464 struct cfg80211_cached_keys *connkeys = NULL;
10468 memset(&connect, 0, sizeof(connect));
10470 if (!info->attrs[NL80211_ATTR_SSID] ||
10471 !nla_len(info->attrs[NL80211_ATTR_SSID]))
10474 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10475 connect.auth_type =
10476 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10477 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
10478 NL80211_CMD_CONNECT))
10481 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
10483 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
10485 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
10486 !wiphy_ext_feature_isset(&rdev->wiphy,
10487 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
10489 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
10491 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
10492 NL80211_MAX_NR_CIPHER_SUITES);
10496 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10497 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10498 return -EOPNOTSUPP;
10500 wiphy = &rdev->wiphy;
10502 connect.bg_scan_period = -1;
10503 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
10504 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
10505 connect.bg_scan_period =
10506 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
10509 if (info->attrs[NL80211_ATTR_MAC])
10510 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10511 else if (info->attrs[NL80211_ATTR_MAC_HINT])
10512 connect.bssid_hint =
10513 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
10514 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10515 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10517 if (info->attrs[NL80211_ATTR_IE]) {
10518 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10519 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10522 if (info->attrs[NL80211_ATTR_USE_MFP]) {
10523 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
10524 if (connect.mfp == NL80211_MFP_OPTIONAL &&
10525 !wiphy_ext_feature_isset(&rdev->wiphy,
10526 NL80211_EXT_FEATURE_MFP_OPTIONAL))
10527 return -EOPNOTSUPP;
10529 connect.mfp = NL80211_MFP_NO;
10532 if (info->attrs[NL80211_ATTR_PREV_BSSID])
10533 connect.prev_bssid =
10534 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
10536 if (info->attrs[NL80211_ATTR_WIPHY_FREQ])
10537 freq = MHZ_TO_KHZ(nla_get_u32(
10538 info->attrs[NL80211_ATTR_WIPHY_FREQ]));
10539 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10541 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10544 connect.channel = nl80211_get_valid_chan(wiphy, freq);
10545 if (!connect.channel)
10547 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
10548 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
10549 freq = MHZ_TO_KHZ(freq);
10550 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq);
10551 if (!connect.channel_hint)
10555 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
10556 connect.edmg.channels =
10557 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
10559 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
10560 connect.edmg.bw_config =
10561 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
10564 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
10565 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
10566 if (IS_ERR(connkeys))
10567 return PTR_ERR(connkeys);
10570 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
10571 connect.flags |= ASSOC_REQ_DISABLE_HT;
10573 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10574 memcpy(&connect.ht_capa_mask,
10575 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
10576 sizeof(connect.ht_capa_mask));
10578 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
10579 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
10580 kfree_sensitive(connkeys);
10583 memcpy(&connect.ht_capa,
10584 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10585 sizeof(connect.ht_capa));
10588 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
10589 connect.flags |= ASSOC_REQ_DISABLE_VHT;
10591 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
10592 memcpy(&connect.vht_capa_mask,
10593 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
10594 sizeof(connect.vht_capa_mask));
10596 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
10597 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
10598 kfree_sensitive(connkeys);
10601 memcpy(&connect.vht_capa,
10602 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
10603 sizeof(connect.vht_capa));
10606 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
10607 if (!((rdev->wiphy.features &
10608 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
10609 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
10610 !wiphy_ext_feature_isset(&rdev->wiphy,
10611 NL80211_EXT_FEATURE_RRM)) {
10612 kfree_sensitive(connkeys);
10615 connect.flags |= ASSOC_REQ_USE_RRM;
10618 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
10619 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
10620 kfree_sensitive(connkeys);
10621 return -EOPNOTSUPP;
10624 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
10625 /* bss selection makes no sense if bssid is set */
10626 if (connect.bssid) {
10627 kfree_sensitive(connkeys);
10631 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
10632 wiphy, &connect.bss_select);
10634 kfree_sensitive(connkeys);
10639 if (wiphy_ext_feature_isset(&rdev->wiphy,
10640 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10641 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10642 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10643 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10644 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10645 connect.fils_erp_username =
10646 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10647 connect.fils_erp_username_len =
10648 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10649 connect.fils_erp_realm =
10650 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10651 connect.fils_erp_realm_len =
10652 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10653 connect.fils_erp_next_seq_num =
10655 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10656 connect.fils_erp_rrk =
10657 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10658 connect.fils_erp_rrk_len =
10659 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10660 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10661 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10662 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10663 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10664 kfree_sensitive(connkeys);
10668 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10669 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10670 kfree_sensitive(connkeys);
10671 GENL_SET_ERR_MSG(info,
10672 "external auth requires connection ownership");
10675 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
10678 wdev_lock(dev->ieee80211_ptr);
10680 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10681 connect.prev_bssid);
10683 kfree_sensitive(connkeys);
10685 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10686 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10688 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10689 connect.bssid, ETH_ALEN);
10691 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid);
10694 wdev_unlock(dev->ieee80211_ptr);
10699 static int nl80211_update_connect_params(struct sk_buff *skb,
10700 struct genl_info *info)
10702 struct cfg80211_connect_params connect = {};
10703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10704 struct net_device *dev = info->user_ptr[1];
10705 struct wireless_dev *wdev = dev->ieee80211_ptr;
10706 bool fils_sk_offload;
10711 if (!rdev->ops->update_connect_params)
10712 return -EOPNOTSUPP;
10714 if (info->attrs[NL80211_ATTR_IE]) {
10715 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10716 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10717 changed |= UPDATE_ASSOC_IES;
10720 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
10721 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
10724 * when driver supports fils-sk offload all attributes must be
10725 * provided. So the else covers "fils-sk-not-all" and
10726 * "no-fils-sk-any".
10728 if (fils_sk_offload &&
10729 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10730 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10731 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10732 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10733 connect.fils_erp_username =
10734 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10735 connect.fils_erp_username_len =
10736 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10737 connect.fils_erp_realm =
10738 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10739 connect.fils_erp_realm_len =
10740 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10741 connect.fils_erp_next_seq_num =
10743 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10744 connect.fils_erp_rrk =
10745 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10746 connect.fils_erp_rrk_len =
10747 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10748 changed |= UPDATE_FILS_ERP_INFO;
10749 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10750 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10751 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10752 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10756 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10757 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10758 if (!nl80211_valid_auth_type(rdev, auth_type,
10759 NL80211_CMD_CONNECT))
10762 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
10763 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
10766 connect.auth_type = auth_type;
10767 changed |= UPDATE_AUTH_TYPE;
10770 wdev_lock(dev->ieee80211_ptr);
10771 if (!wdev->current_bss)
10774 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
10775 wdev_unlock(dev->ieee80211_ptr);
10780 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10783 struct net_device *dev = info->user_ptr[1];
10787 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10788 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10791 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10792 reason = WLAN_REASON_DEAUTH_LEAVING;
10794 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10799 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10800 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10801 return -EOPNOTSUPP;
10803 wdev_lock(dev->ieee80211_ptr);
10804 ret = cfg80211_disconnect(rdev, dev, reason, true);
10805 wdev_unlock(dev->ieee80211_ptr);
10809 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10815 if (info->attrs[NL80211_ATTR_PID]) {
10816 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10818 net = get_net_ns_by_pid(pid);
10819 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10820 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10822 net = get_net_ns_by_fd(fd);
10828 return PTR_ERR(net);
10832 /* check if anything to do */
10833 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10834 err = cfg80211_switch_netns(rdev, net);
10840 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10843 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10844 struct cfg80211_pmksa *pmksa) = NULL;
10845 struct net_device *dev = info->user_ptr[1];
10846 struct cfg80211_pmksa pmksa;
10848 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10850 if (!info->attrs[NL80211_ATTR_PMKID])
10853 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
10855 if (info->attrs[NL80211_ATTR_MAC]) {
10856 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10857 } else if (info->attrs[NL80211_ATTR_SSID] &&
10858 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10859 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10860 info->attrs[NL80211_ATTR_PMK])) {
10861 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10862 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10864 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10868 if (info->attrs[NL80211_ATTR_PMK]) {
10869 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10870 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10873 if (info->attrs[NL80211_ATTR_PMK_LIFETIME])
10874 pmksa.pmk_lifetime =
10875 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]);
10877 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD])
10878 pmksa.pmk_reauth_threshold =
10880 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]);
10882 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10883 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10884 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10885 wiphy_ext_feature_isset(&rdev->wiphy,
10886 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
10887 return -EOPNOTSUPP;
10889 switch (info->genlhdr->cmd) {
10890 case NL80211_CMD_SET_PMKSA:
10891 rdev_ops = rdev->ops->set_pmksa;
10893 case NL80211_CMD_DEL_PMKSA:
10894 rdev_ops = rdev->ops->del_pmksa;
10902 return -EOPNOTSUPP;
10904 return rdev_ops(&rdev->wiphy, dev, &pmksa);
10907 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10910 struct net_device *dev = info->user_ptr[1];
10912 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10913 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10914 return -EOPNOTSUPP;
10916 if (!rdev->ops->flush_pmksa)
10917 return -EOPNOTSUPP;
10919 return rdev_flush_pmksa(rdev, dev);
10922 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10925 struct net_device *dev = info->user_ptr[1];
10926 u8 action_code, dialog_token;
10927 u32 peer_capability = 0;
10932 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10933 !rdev->ops->tdls_mgmt)
10934 return -EOPNOTSUPP;
10936 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10937 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10938 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10939 !info->attrs[NL80211_ATTR_IE] ||
10940 !info->attrs[NL80211_ATTR_MAC])
10943 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10944 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10945 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10946 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
10947 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
10948 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10950 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
10952 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
10953 dialog_token, status_code, peer_capability,
10955 nla_data(info->attrs[NL80211_ATTR_IE]),
10956 nla_len(info->attrs[NL80211_ATTR_IE]));
10959 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10962 struct net_device *dev = info->user_ptr[1];
10963 enum nl80211_tdls_operation operation;
10966 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10967 !rdev->ops->tdls_oper)
10968 return -EOPNOTSUPP;
10970 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10971 !info->attrs[NL80211_ATTR_MAC])
10974 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10975 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10977 return rdev_tdls_oper(rdev, dev, peer, operation);
10980 static int nl80211_remain_on_channel(struct sk_buff *skb,
10981 struct genl_info *info)
10983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10984 struct wireless_dev *wdev = info->user_ptr[1];
10985 struct cfg80211_chan_def chandef;
10986 const struct cfg80211_chan_def *compat_chandef;
10987 struct sk_buff *msg;
10993 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10994 !info->attrs[NL80211_ATTR_DURATION])
10997 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10999 if (!rdev->ops->remain_on_channel ||
11000 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
11001 return -EOPNOTSUPP;
11004 * We should be on that channel for at least a minimum amount of
11005 * time (10ms) but no longer than the driver supports.
11007 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
11008 duration > rdev->wiphy.max_remain_on_channel_duration)
11011 err = nl80211_parse_chandef(rdev, info, &chandef);
11016 if (!cfg80211_off_channel_oper_allowed(wdev) &&
11017 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
11018 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
11020 if (compat_chandef != &chandef) {
11027 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11031 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11032 NL80211_CMD_REMAIN_ON_CHANNEL);
11038 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
11039 duration, &cookie);
11044 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11046 goto nla_put_failure;
11048 genlmsg_end(msg, hdr);
11050 return genlmsg_reply(msg, info);
11059 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
11060 struct genl_info *info)
11062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11063 struct wireless_dev *wdev = info->user_ptr[1];
11066 if (!info->attrs[NL80211_ATTR_COOKIE])
11069 if (!rdev->ops->cancel_remain_on_channel)
11070 return -EOPNOTSUPP;
11072 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11074 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
11077 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
11078 struct genl_info *info)
11080 struct cfg80211_bitrate_mask mask;
11081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11082 struct net_device *dev = info->user_ptr[1];
11085 if (!rdev->ops->set_bitrate_mask)
11086 return -EOPNOTSUPP;
11088 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
11089 NL80211_ATTR_TX_RATES, &mask,
11094 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
11097 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
11099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11100 struct wireless_dev *wdev = info->user_ptr[1];
11101 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
11103 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
11106 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
11107 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
11109 switch (wdev->iftype) {
11110 case NL80211_IFTYPE_STATION:
11111 case NL80211_IFTYPE_ADHOC:
11112 case NL80211_IFTYPE_P2P_CLIENT:
11113 case NL80211_IFTYPE_AP:
11114 case NL80211_IFTYPE_AP_VLAN:
11115 case NL80211_IFTYPE_MESH_POINT:
11116 case NL80211_IFTYPE_P2P_GO:
11117 case NL80211_IFTYPE_P2P_DEVICE:
11119 case NL80211_IFTYPE_NAN:
11121 return -EOPNOTSUPP;
11124 /* not much point in registering if we can't reply */
11125 if (!rdev->ops->mgmt_tx)
11126 return -EOPNOTSUPP;
11128 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] &&
11129 !wiphy_ext_feature_isset(&rdev->wiphy,
11130 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) {
11131 GENL_SET_ERR_MSG(info,
11132 "multicast RX registrations are not supported");
11133 return -EOPNOTSUPP;
11136 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
11137 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
11138 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
11139 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST],
11143 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
11145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11146 struct wireless_dev *wdev = info->user_ptr[1];
11147 struct cfg80211_chan_def chandef;
11151 struct sk_buff *msg = NULL;
11152 struct cfg80211_mgmt_tx_params params = {
11153 .dont_wait_for_ack =
11154 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
11157 if (!info->attrs[NL80211_ATTR_FRAME])
11160 if (!rdev->ops->mgmt_tx)
11161 return -EOPNOTSUPP;
11163 switch (wdev->iftype) {
11164 case NL80211_IFTYPE_P2P_DEVICE:
11165 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
11167 case NL80211_IFTYPE_STATION:
11168 case NL80211_IFTYPE_ADHOC:
11169 case NL80211_IFTYPE_P2P_CLIENT:
11170 case NL80211_IFTYPE_AP:
11171 case NL80211_IFTYPE_AP_VLAN:
11172 case NL80211_IFTYPE_MESH_POINT:
11173 case NL80211_IFTYPE_P2P_GO:
11175 case NL80211_IFTYPE_NAN:
11177 return -EOPNOTSUPP;
11180 if (info->attrs[NL80211_ATTR_DURATION]) {
11181 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
11183 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
11186 * We should wait on the channel for at least a minimum amount
11187 * of time (10ms) but no longer than the driver supports.
11189 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
11190 params.wait > rdev->wiphy.max_remain_on_channel_duration)
11194 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
11196 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
11199 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
11201 /* get the channel if any has been specified, otherwise pass NULL to
11202 * the driver. The latter will use the current one
11204 chandef.chan = NULL;
11205 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
11206 err = nl80211_parse_chandef(rdev, info, &chandef);
11211 if (!chandef.chan && params.offchan)
11215 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
11221 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
11222 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
11224 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
11225 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
11228 if (len % sizeof(u16))
11231 params.n_csa_offsets = len / sizeof(u16);
11232 params.csa_offsets =
11233 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
11235 /* check that all the offsets fit the frame */
11236 for (i = 0; i < params.n_csa_offsets; i++) {
11237 if (params.csa_offsets[i] >= params.len)
11242 if (!params.dont_wait_for_ack) {
11243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11247 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11248 NL80211_CMD_FRAME);
11255 params.chan = chandef.chan;
11256 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie);
11261 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11263 goto nla_put_failure;
11265 genlmsg_end(msg, hdr);
11266 return genlmsg_reply(msg, info);
11278 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
11280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11281 struct wireless_dev *wdev = info->user_ptr[1];
11284 if (!info->attrs[NL80211_ATTR_COOKIE])
11287 if (!rdev->ops->mgmt_tx_cancel_wait)
11288 return -EOPNOTSUPP;
11290 switch (wdev->iftype) {
11291 case NL80211_IFTYPE_STATION:
11292 case NL80211_IFTYPE_ADHOC:
11293 case NL80211_IFTYPE_P2P_CLIENT:
11294 case NL80211_IFTYPE_AP:
11295 case NL80211_IFTYPE_AP_VLAN:
11296 case NL80211_IFTYPE_P2P_GO:
11297 case NL80211_IFTYPE_P2P_DEVICE:
11299 case NL80211_IFTYPE_NAN:
11301 return -EOPNOTSUPP;
11304 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11306 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
11309 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
11311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11312 struct wireless_dev *wdev;
11313 struct net_device *dev = info->user_ptr[1];
11318 if (!info->attrs[NL80211_ATTR_PS_STATE])
11321 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
11323 wdev = dev->ieee80211_ptr;
11325 if (!rdev->ops->set_power_mgmt)
11326 return -EOPNOTSUPP;
11328 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
11330 if (state == wdev->ps)
11333 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
11339 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
11341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11342 enum nl80211_ps_state ps_state;
11343 struct wireless_dev *wdev;
11344 struct net_device *dev = info->user_ptr[1];
11345 struct sk_buff *msg;
11349 wdev = dev->ieee80211_ptr;
11351 if (!rdev->ops->set_power_mgmt)
11352 return -EOPNOTSUPP;
11354 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11358 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11359 NL80211_CMD_GET_POWER_SAVE);
11366 ps_state = NL80211_PS_ENABLED;
11368 ps_state = NL80211_PS_DISABLED;
11370 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
11371 goto nla_put_failure;
11373 genlmsg_end(msg, hdr);
11374 return genlmsg_reply(msg, info);
11383 static const struct nla_policy
11384 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
11385 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
11386 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
11387 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
11388 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
11389 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
11390 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
11391 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
11394 static int nl80211_set_cqm_txe(struct genl_info *info,
11395 u32 rate, u32 pkts, u32 intvl)
11397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11398 struct net_device *dev = info->user_ptr[1];
11399 struct wireless_dev *wdev = dev->ieee80211_ptr;
11401 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
11404 if (!rdev->ops->set_cqm_txe_config)
11405 return -EOPNOTSUPP;
11407 if (wdev->iftype != NL80211_IFTYPE_STATION &&
11408 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11409 return -EOPNOTSUPP;
11411 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
11414 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
11415 struct net_device *dev)
11417 struct wireless_dev *wdev = dev->ieee80211_ptr;
11418 s32 last, low, high;
11420 int i, n, low_index;
11423 /* RSSI reporting disabled? */
11424 if (!wdev->cqm_config)
11425 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
11428 * Obtain current RSSI value if possible, if not and no RSSI threshold
11429 * event has been received yet, we should receive an event after a
11430 * connection is established and enough beacons received to calculate
11433 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
11434 rdev->ops->get_station) {
11435 struct station_info sinfo = {};
11438 mac_addr = wdev->current_bss->pub.bssid;
11440 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
11444 cfg80211_sinfo_release_content(&sinfo);
11445 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
11446 wdev->cqm_config->last_rssi_event_value =
11447 (s8) sinfo.rx_beacon_signal_avg;
11450 last = wdev->cqm_config->last_rssi_event_value;
11451 hyst = wdev->cqm_config->rssi_hyst;
11452 n = wdev->cqm_config->n_rssi_thresholds;
11454 for (i = 0; i < n; i++) {
11455 i = array_index_nospec(i, n);
11456 if (last < wdev->cqm_config->rssi_thresholds[i])
11461 if (low_index >= 0) {
11462 low_index = array_index_nospec(low_index, n);
11463 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
11468 i = array_index_nospec(i, n);
11469 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
11474 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
11477 static int nl80211_set_cqm_rssi(struct genl_info *info,
11478 const s32 *thresholds, int n_thresholds,
11481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11482 struct net_device *dev = info->user_ptr[1];
11483 struct wireless_dev *wdev = dev->ieee80211_ptr;
11485 s32 prev = S32_MIN;
11487 /* Check all values negative and sorted */
11488 for (i = 0; i < n_thresholds; i++) {
11489 if (thresholds[i] > 0 || thresholds[i] <= prev)
11492 prev = thresholds[i];
11495 if (wdev->iftype != NL80211_IFTYPE_STATION &&
11496 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11497 return -EOPNOTSUPP;
11500 cfg80211_cqm_config_free(wdev);
11503 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
11504 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
11505 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
11507 return rdev_set_cqm_rssi_config(rdev, dev,
11508 thresholds[0], hysteresis);
11511 if (!wiphy_ext_feature_isset(&rdev->wiphy,
11512 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
11513 return -EOPNOTSUPP;
11515 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
11519 if (n_thresholds) {
11520 struct cfg80211_cqm_config *cqm_config;
11522 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
11523 n_thresholds * sizeof(s32), GFP_KERNEL);
11529 cqm_config->rssi_hyst = hysteresis;
11530 cqm_config->n_rssi_thresholds = n_thresholds;
11531 memcpy(cqm_config->rssi_thresholds, thresholds,
11532 n_thresholds * sizeof(s32));
11534 wdev->cqm_config = cqm_config;
11537 err = cfg80211_cqm_rssi_update(rdev, dev);
11545 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
11547 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
11548 struct nlattr *cqm;
11551 cqm = info->attrs[NL80211_ATTR_CQM];
11555 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
11556 nl80211_attr_cqm_policy,
11561 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
11562 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
11563 const s32 *thresholds =
11564 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
11565 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
11566 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
11571 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
11575 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
11576 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
11577 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
11578 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
11579 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
11580 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
11582 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
11588 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
11590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11591 struct net_device *dev = info->user_ptr[1];
11592 struct ocb_setup setup = {};
11595 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11599 return cfg80211_join_ocb(rdev, dev, &setup);
11602 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
11604 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11605 struct net_device *dev = info->user_ptr[1];
11607 return cfg80211_leave_ocb(rdev, dev);
11610 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
11612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11613 struct net_device *dev = info->user_ptr[1];
11614 struct mesh_config cfg;
11615 struct mesh_setup setup;
11618 /* start with default */
11619 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
11620 memcpy(&setup, &default_mesh_setup, sizeof(setup));
11622 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
11623 /* and parse parameters if given */
11624 err = nl80211_parse_mesh_config(info, &cfg, NULL);
11629 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
11630 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
11633 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
11634 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
11636 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11637 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
11638 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11641 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
11642 setup.beacon_interval =
11643 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
11645 err = cfg80211_validate_beacon_int(rdev,
11646 NL80211_IFTYPE_MESH_POINT,
11647 setup.beacon_interval);
11652 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
11653 setup.dtim_period =
11654 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
11655 if (setup.dtim_period < 1 || setup.dtim_period > 100)
11659 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
11660 /* parse additional setup parameters if given */
11661 err = nl80211_parse_mesh_setup(info, &setup);
11666 if (setup.user_mpm)
11667 cfg.auto_open_plinks = false;
11669 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
11670 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11674 /* __cfg80211_join_mesh() will sort it out */
11675 setup.chandef.chan = NULL;
11678 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11679 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11681 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11682 struct ieee80211_supported_band *sband;
11684 if (!setup.chandef.chan)
11687 sband = rdev->wiphy.bands[setup.chandef.chan->band];
11689 err = ieee80211_get_ratemask(sband, rates, n_rates,
11690 &setup.basic_rates);
11695 if (info->attrs[NL80211_ATTR_TX_RATES]) {
11696 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
11697 NL80211_ATTR_TX_RATES,
11698 &setup.beacon_rate,
11703 if (!setup.chandef.chan)
11706 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11707 &setup.beacon_rate);
11712 setup.userspace_handles_dfs =
11713 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11715 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11716 int r = validate_pae_over_nl80211(rdev, info);
11721 setup.control_port_over_nl80211 = true;
11724 wdev_lock(dev->ieee80211_ptr);
11725 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
11726 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
11727 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11728 wdev_unlock(dev->ieee80211_ptr);
11733 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
11735 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11736 struct net_device *dev = info->user_ptr[1];
11738 return cfg80211_leave_mesh(rdev, dev);
11742 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11743 struct cfg80211_registered_device *rdev)
11745 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
11746 struct nlattr *nl_pats, *nl_pat;
11749 if (!wowlan->n_patterns)
11752 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
11756 for (i = 0; i < wowlan->n_patterns; i++) {
11757 nl_pat = nla_nest_start_noflag(msg, i + 1);
11760 pat_len = wowlan->patterns[i].pattern_len;
11761 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
11762 wowlan->patterns[i].mask) ||
11763 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11764 wowlan->patterns[i].pattern) ||
11765 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11766 wowlan->patterns[i].pkt_offset))
11768 nla_nest_end(msg, nl_pat);
11770 nla_nest_end(msg, nl_pats);
11775 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
11776 struct cfg80211_wowlan_tcp *tcp)
11778 struct nlattr *nl_tcp;
11783 nl_tcp = nla_nest_start_noflag(msg,
11784 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
11788 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
11789 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
11790 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
11791 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
11792 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
11793 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
11794 tcp->payload_len, tcp->payload) ||
11795 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
11796 tcp->data_interval) ||
11797 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
11798 tcp->wake_len, tcp->wake_data) ||
11799 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
11800 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
11803 if (tcp->payload_seq.len &&
11804 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
11805 sizeof(tcp->payload_seq), &tcp->payload_seq))
11808 if (tcp->payload_tok.len &&
11809 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11810 sizeof(tcp->payload_tok) + tcp->tokens_size,
11811 &tcp->payload_tok))
11814 nla_nest_end(msg, nl_tcp);
11819 static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11820 struct cfg80211_sched_scan_request *req)
11822 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
11828 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
11832 if (req->n_scan_plans == 1 &&
11833 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11834 req->scan_plans[0].interval * 1000))
11837 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11840 if (req->relative_rssi_set) {
11841 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11843 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11844 req->relative_rssi))
11847 rssi_adjust.band = req->rssi_adjust.band;
11848 rssi_adjust.delta = req->rssi_adjust.delta;
11849 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11850 sizeof(rssi_adjust), &rssi_adjust))
11854 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11858 for (i = 0; i < req->n_channels; i++) {
11859 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11863 nla_nest_end(msg, freqs);
11865 if (req->n_match_sets) {
11866 matches = nla_nest_start_noflag(msg,
11867 NL80211_ATTR_SCHED_SCAN_MATCH);
11871 for (i = 0; i < req->n_match_sets; i++) {
11872 match = nla_nest_start_noflag(msg, i);
11876 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11877 req->match_sets[i].ssid.ssid_len,
11878 req->match_sets[i].ssid.ssid))
11880 nla_nest_end(msg, match);
11882 nla_nest_end(msg, matches);
11885 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
11889 for (i = 0; i < req->n_scan_plans; i++) {
11890 scan_plan = nla_nest_start_noflag(msg, i + 1);
11894 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
11895 req->scan_plans[i].interval) ||
11896 (req->scan_plans[i].iterations &&
11897 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11898 req->scan_plans[i].iterations)))
11900 nla_nest_end(msg, scan_plan);
11902 nla_nest_end(msg, scan_plans);
11904 nla_nest_end(msg, nd);
11909 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11912 struct sk_buff *msg;
11914 u32 size = NLMSG_DEFAULT_SIZE;
11916 if (!rdev->wiphy.wowlan)
11917 return -EOPNOTSUPP;
11919 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
11920 /* adjust size to have room for all the data */
11921 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11922 rdev->wiphy.wowlan_config->tcp->payload_len +
11923 rdev->wiphy.wowlan_config->tcp->wake_len +
11924 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
11927 msg = nlmsg_new(size, GFP_KERNEL);
11931 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11932 NL80211_CMD_GET_WOWLAN);
11934 goto nla_put_failure;
11936 if (rdev->wiphy.wowlan_config) {
11937 struct nlattr *nl_wowlan;
11939 nl_wowlan = nla_nest_start_noflag(msg,
11940 NL80211_ATTR_WOWLAN_TRIGGERS);
11942 goto nla_put_failure;
11944 if ((rdev->wiphy.wowlan_config->any &&
11945 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
11946 (rdev->wiphy.wowlan_config->disconnect &&
11947 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
11948 (rdev->wiphy.wowlan_config->magic_pkt &&
11949 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
11950 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
11951 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
11952 (rdev->wiphy.wowlan_config->eap_identity_req &&
11953 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
11954 (rdev->wiphy.wowlan_config->four_way_handshake &&
11955 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
11956 (rdev->wiphy.wowlan_config->rfkill_release &&
11957 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11958 goto nla_put_failure;
11960 if (nl80211_send_wowlan_patterns(msg, rdev))
11961 goto nla_put_failure;
11963 if (nl80211_send_wowlan_tcp(msg,
11964 rdev->wiphy.wowlan_config->tcp))
11965 goto nla_put_failure;
11967 if (nl80211_send_wowlan_nd(
11969 rdev->wiphy.wowlan_config->nd_config))
11970 goto nla_put_failure;
11972 nla_nest_end(msg, nl_wowlan);
11975 genlmsg_end(msg, hdr);
11976 return genlmsg_reply(msg, info);
11983 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11984 struct nlattr *attr,
11985 struct cfg80211_wowlan *trig)
11987 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11988 struct cfg80211_wowlan_tcp *cfg;
11989 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11990 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11992 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11995 if (!rdev->wiphy.wowlan->tcp)
11998 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11999 nl80211_wowlan_tcp_policy, NULL);
12003 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
12004 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
12005 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
12006 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
12007 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
12008 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
12009 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
12010 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
12013 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
12014 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
12017 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
12018 rdev->wiphy.wowlan->tcp->data_interval_max ||
12019 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
12022 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
12023 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
12026 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
12027 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
12030 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
12031 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
12033 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
12034 tokens_size = tokln - sizeof(*tok);
12036 if (!tok->len || tokens_size % tok->len)
12038 if (!rdev->wiphy.wowlan->tcp->tok)
12040 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
12042 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
12044 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
12046 if (tok->offset + tok->len > data_size)
12050 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
12051 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
12052 if (!rdev->wiphy.wowlan->tcp->seq)
12054 if (seq->len == 0 || seq->len > 4)
12056 if (seq->len + seq->offset > data_size)
12060 size = sizeof(*cfg);
12062 size += wake_size + wake_mask_size;
12063 size += tokens_size;
12065 cfg = kzalloc(size, GFP_KERNEL);
12068 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
12069 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
12070 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
12072 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
12073 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
12077 /* allocate a socket and port for it and use it */
12078 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
12079 IPPROTO_TCP, &cfg->sock, 1);
12084 if (inet_csk_get_port(cfg->sock->sk, port)) {
12085 sock_release(cfg->sock);
12087 return -EADDRINUSE;
12089 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
12095 cfg->src_port = port;
12098 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
12099 cfg->payload_len = data_size;
12100 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
12101 memcpy((void *)cfg->payload,
12102 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
12105 cfg->payload_seq = *seq;
12106 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
12107 cfg->wake_len = wake_size;
12108 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
12109 memcpy((void *)cfg->wake_data,
12110 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
12112 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
12113 data_size + wake_size;
12114 memcpy((void *)cfg->wake_mask,
12115 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
12118 cfg->tokens_size = tokens_size;
12119 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
12127 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
12128 const struct wiphy_wowlan_support *wowlan,
12129 struct nlattr *attr,
12130 struct cfg80211_wowlan *trig)
12132 struct nlattr **tb;
12135 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
12139 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
12144 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
12145 nl80211_policy, NULL);
12149 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
12150 wowlan->max_nd_match_sets);
12151 err = PTR_ERR_OR_ZERO(trig->nd_config);
12153 trig->nd_config = NULL;
12160 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
12162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12163 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
12164 struct cfg80211_wowlan new_triggers = {};
12165 struct cfg80211_wowlan *ntrig;
12166 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
12168 bool prev_enabled = rdev->wiphy.wowlan_config;
12169 bool regular = false;
12172 return -EOPNOTSUPP;
12174 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
12175 cfg80211_rdev_free_wowlan(rdev);
12176 rdev->wiphy.wowlan_config = NULL;
12180 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
12181 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
12182 nl80211_wowlan_policy, info->extack);
12186 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
12187 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
12189 new_triggers.any = true;
12192 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
12193 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
12195 new_triggers.disconnect = true;
12199 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
12200 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
12202 new_triggers.magic_pkt = true;
12206 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
12209 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
12210 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
12212 new_triggers.gtk_rekey_failure = true;
12216 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
12217 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
12219 new_triggers.eap_identity_req = true;
12223 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
12224 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
12226 new_triggers.four_way_handshake = true;
12230 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
12231 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
12233 new_triggers.rfkill_release = true;
12237 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
12238 struct nlattr *pat;
12239 int n_patterns = 0;
12240 int rem, pat_len, mask_len, pkt_offset;
12241 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
12245 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
12248 if (n_patterns > wowlan->n_patterns)
12251 new_triggers.patterns = kcalloc(n_patterns,
12252 sizeof(new_triggers.patterns[0]),
12254 if (!new_triggers.patterns)
12257 new_triggers.n_patterns = n_patterns;
12260 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
12264 err = nla_parse_nested_deprecated(pat_tb,
12265 MAX_NL80211_PKTPAT,
12267 nl80211_packet_pattern_policy,
12273 if (!pat_tb[NL80211_PKTPAT_MASK] ||
12274 !pat_tb[NL80211_PKTPAT_PATTERN])
12276 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
12277 mask_len = DIV_ROUND_UP(pat_len, 8);
12278 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
12280 if (pat_len > wowlan->pattern_max_len ||
12281 pat_len < wowlan->pattern_min_len)
12284 if (!pat_tb[NL80211_PKTPAT_OFFSET])
12287 pkt_offset = nla_get_u32(
12288 pat_tb[NL80211_PKTPAT_OFFSET]);
12289 if (pkt_offset > wowlan->max_pkt_offset)
12291 new_triggers.patterns[i].pkt_offset = pkt_offset;
12293 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12298 new_triggers.patterns[i].mask = mask_pat;
12299 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
12301 mask_pat += mask_len;
12302 new_triggers.patterns[i].pattern = mask_pat;
12303 new_triggers.patterns[i].pattern_len = pat_len;
12305 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
12311 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
12313 err = nl80211_parse_wowlan_tcp(
12314 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
12320 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
12322 err = nl80211_parse_wowlan_nd(
12323 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
12329 /* The 'any' trigger means the device continues operating more or less
12330 * as in its normal operation mode and wakes up the host on most of the
12331 * normal interrupts (like packet RX, ...)
12332 * It therefore makes little sense to combine with the more constrained
12333 * wakeup trigger modes.
12335 if (new_triggers.any && regular) {
12340 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
12345 cfg80211_rdev_free_wowlan(rdev);
12346 rdev->wiphy.wowlan_config = ntrig;
12349 if (rdev->ops->set_wakeup &&
12350 prev_enabled != !!rdev->wiphy.wowlan_config)
12351 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
12355 for (i = 0; i < new_triggers.n_patterns; i++)
12356 kfree(new_triggers.patterns[i].mask);
12357 kfree(new_triggers.patterns);
12358 if (new_triggers.tcp && new_triggers.tcp->sock)
12359 sock_release(new_triggers.tcp->sock);
12360 kfree(new_triggers.tcp);
12361 kfree(new_triggers.nd_config);
12366 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
12367 struct cfg80211_registered_device *rdev)
12369 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
12371 struct cfg80211_coalesce_rules *rule;
12373 if (!rdev->coalesce->n_rules)
12376 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
12380 for (i = 0; i < rdev->coalesce->n_rules; i++) {
12381 nl_rule = nla_nest_start_noflag(msg, i + 1);
12385 rule = &rdev->coalesce->rules[i];
12386 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
12390 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
12394 nl_pats = nla_nest_start_noflag(msg,
12395 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
12399 for (j = 0; j < rule->n_patterns; j++) {
12400 nl_pat = nla_nest_start_noflag(msg, j + 1);
12403 pat_len = rule->patterns[j].pattern_len;
12404 if (nla_put(msg, NL80211_PKTPAT_MASK,
12405 DIV_ROUND_UP(pat_len, 8),
12406 rule->patterns[j].mask) ||
12407 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
12408 rule->patterns[j].pattern) ||
12409 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
12410 rule->patterns[j].pkt_offset))
12412 nla_nest_end(msg, nl_pat);
12414 nla_nest_end(msg, nl_pats);
12415 nla_nest_end(msg, nl_rule);
12417 nla_nest_end(msg, nl_rules);
12422 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
12424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12425 struct sk_buff *msg;
12428 if (!rdev->wiphy.coalesce)
12429 return -EOPNOTSUPP;
12431 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12435 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12436 NL80211_CMD_GET_COALESCE);
12438 goto nla_put_failure;
12440 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
12441 goto nla_put_failure;
12443 genlmsg_end(msg, hdr);
12444 return genlmsg_reply(msg, info);
12451 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
12453 struct cfg80211_coalesce *coalesce = rdev->coalesce;
12455 struct cfg80211_coalesce_rules *rule;
12460 for (i = 0; i < coalesce->n_rules; i++) {
12461 rule = &coalesce->rules[i];
12462 for (j = 0; j < rule->n_patterns; j++)
12463 kfree(rule->patterns[j].mask);
12464 kfree(rule->patterns);
12466 kfree(coalesce->rules);
12468 rdev->coalesce = NULL;
12471 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
12472 struct nlattr *rule,
12473 struct cfg80211_coalesce_rules *new_rule)
12476 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12477 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
12478 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
12479 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
12481 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
12482 rule, nl80211_coalesce_policy, NULL);
12486 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
12488 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
12489 if (new_rule->delay > coalesce->max_delay)
12492 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
12493 new_rule->condition =
12494 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
12496 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
12499 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12502 if (n_patterns > coalesce->n_patterns)
12505 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
12507 if (!new_rule->patterns)
12510 new_rule->n_patterns = n_patterns;
12513 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12517 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
12519 nl80211_packet_pattern_policy,
12524 if (!pat_tb[NL80211_PKTPAT_MASK] ||
12525 !pat_tb[NL80211_PKTPAT_PATTERN])
12527 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
12528 mask_len = DIV_ROUND_UP(pat_len, 8);
12529 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
12531 if (pat_len > coalesce->pattern_max_len ||
12532 pat_len < coalesce->pattern_min_len)
12535 if (!pat_tb[NL80211_PKTPAT_OFFSET])
12538 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
12539 if (pkt_offset > coalesce->max_pkt_offset)
12541 new_rule->patterns[i].pkt_offset = pkt_offset;
12543 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12547 new_rule->patterns[i].mask = mask_pat;
12548 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
12551 mask_pat += mask_len;
12552 new_rule->patterns[i].pattern = mask_pat;
12553 new_rule->patterns[i].pattern_len = pat_len;
12554 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
12562 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
12564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12565 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12566 struct cfg80211_coalesce new_coalesce = {};
12567 struct cfg80211_coalesce *n_coalesce;
12568 int err, rem_rule, n_rules = 0, i, j;
12569 struct nlattr *rule;
12570 struct cfg80211_coalesce_rules *tmp_rule;
12572 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
12573 return -EOPNOTSUPP;
12575 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
12576 cfg80211_rdev_free_coalesce(rdev);
12577 rdev_set_coalesce(rdev, NULL);
12581 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12584 if (n_rules > coalesce->n_rules)
12587 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
12589 if (!new_coalesce.rules)
12592 new_coalesce.n_rules = n_rules;
12595 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12597 err = nl80211_parse_coalesce_rule(rdev, rule,
12598 &new_coalesce.rules[i]);
12605 err = rdev_set_coalesce(rdev, &new_coalesce);
12609 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
12614 cfg80211_rdev_free_coalesce(rdev);
12615 rdev->coalesce = n_coalesce;
12619 for (i = 0; i < new_coalesce.n_rules; i++) {
12620 tmp_rule = &new_coalesce.rules[i];
12621 for (j = 0; j < tmp_rule->n_patterns; j++)
12622 kfree(tmp_rule->patterns[j].mask);
12623 kfree(tmp_rule->patterns);
12625 kfree(new_coalesce.rules);
12630 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
12632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12633 struct net_device *dev = info->user_ptr[1];
12634 struct wireless_dev *wdev = dev->ieee80211_ptr;
12635 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
12636 struct cfg80211_gtk_rekey_data rekey_data;
12639 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
12642 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
12643 info->attrs[NL80211_ATTR_REKEY_DATA],
12644 nl80211_rekey_policy, info->extack);
12648 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
12649 !tb[NL80211_REKEY_DATA_KCK])
12651 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN &&
12652 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
12653 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN))
12655 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN &&
12656 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
12657 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN))
12660 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
12661 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
12662 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
12663 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
12664 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]);
12665 if (tb[NL80211_REKEY_DATA_AKM])
12666 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]);
12669 if (!wdev->current_bss) {
12674 if (!rdev->ops->set_rekey_data) {
12679 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
12685 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
12686 struct genl_info *info)
12688 struct net_device *dev = info->user_ptr[1];
12689 struct wireless_dev *wdev = dev->ieee80211_ptr;
12691 if (wdev->iftype != NL80211_IFTYPE_AP &&
12692 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12695 if (wdev->ap_unexpected_nlportid)
12698 wdev->ap_unexpected_nlportid = info->snd_portid;
12702 static int nl80211_probe_client(struct sk_buff *skb,
12703 struct genl_info *info)
12705 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12706 struct net_device *dev = info->user_ptr[1];
12707 struct wireless_dev *wdev = dev->ieee80211_ptr;
12708 struct sk_buff *msg;
12714 if (wdev->iftype != NL80211_IFTYPE_AP &&
12715 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12716 return -EOPNOTSUPP;
12718 if (!info->attrs[NL80211_ATTR_MAC])
12721 if (!rdev->ops->probe_client)
12722 return -EOPNOTSUPP;
12724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12728 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12729 NL80211_CMD_PROBE_CLIENT);
12735 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12737 err = rdev_probe_client(rdev, dev, addr, &cookie);
12741 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12743 goto nla_put_failure;
12745 genlmsg_end(msg, hdr);
12747 return genlmsg_reply(msg, info);
12756 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12759 struct cfg80211_beacon_registration *reg, *nreg;
12762 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12763 return -EOPNOTSUPP;
12765 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12769 /* First, check if already registered. */
12770 spin_lock_bh(&rdev->beacon_registrations_lock);
12771 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12772 if (reg->nlportid == info->snd_portid) {
12777 /* Add it to the list */
12778 nreg->nlportid = info->snd_portid;
12779 list_add(&nreg->list, &rdev->beacon_registrations);
12781 spin_unlock_bh(&rdev->beacon_registrations_lock);
12785 spin_unlock_bh(&rdev->beacon_registrations_lock);
12790 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
12792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12793 struct wireless_dev *wdev = info->user_ptr[1];
12796 if (!rdev->ops->start_p2p_device)
12797 return -EOPNOTSUPP;
12799 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12800 return -EOPNOTSUPP;
12802 if (wdev_running(wdev))
12805 if (rfkill_blocked(rdev->rfkill))
12808 err = rdev_start_p2p_device(rdev, wdev);
12812 wdev->is_running = true;
12818 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12821 struct wireless_dev *wdev = info->user_ptr[1];
12823 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12824 return -EOPNOTSUPP;
12826 if (!rdev->ops->stop_p2p_device)
12827 return -EOPNOTSUPP;
12829 cfg80211_stop_p2p_device(rdev, wdev);
12834 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12837 struct wireless_dev *wdev = info->user_ptr[1];
12838 struct cfg80211_nan_conf conf = {};
12841 if (wdev->iftype != NL80211_IFTYPE_NAN)
12842 return -EOPNOTSUPP;
12844 if (wdev_running(wdev))
12847 if (rfkill_blocked(rdev->rfkill))
12850 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12854 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12856 if (info->attrs[NL80211_ATTR_BANDS]) {
12857 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12859 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12860 return -EOPNOTSUPP;
12862 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12865 conf.bands = bands;
12868 err = rdev_start_nan(rdev, wdev, &conf);
12872 wdev->is_running = true;
12878 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12880 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12881 struct wireless_dev *wdev = info->user_ptr[1];
12883 if (wdev->iftype != NL80211_IFTYPE_NAN)
12884 return -EOPNOTSUPP;
12886 cfg80211_stop_nan(rdev, wdev);
12891 static int validate_nan_filter(struct nlattr *filter_attr)
12893 struct nlattr *attr;
12894 int len = 0, n_entries = 0, rem;
12896 nla_for_each_nested(attr, filter_attr, rem) {
12897 len += nla_len(attr);
12907 static int handle_nan_filter(struct nlattr *attr_filter,
12908 struct cfg80211_nan_func *func,
12911 struct nlattr *attr;
12912 int n_entries, rem, i;
12913 struct cfg80211_nan_func_filter *filter;
12915 n_entries = validate_nan_filter(attr_filter);
12919 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12921 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12926 nla_for_each_nested(attr, attr_filter, rem) {
12927 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
12928 filter[i].len = nla_len(attr);
12932 func->num_tx_filters = n_entries;
12933 func->tx_filters = filter;
12935 func->num_rx_filters = n_entries;
12936 func->rx_filters = filter;
12942 static int nl80211_nan_add_func(struct sk_buff *skb,
12943 struct genl_info *info)
12945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12946 struct wireless_dev *wdev = info->user_ptr[1];
12947 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12948 struct cfg80211_nan_func *func;
12949 struct sk_buff *msg = NULL;
12953 if (wdev->iftype != NL80211_IFTYPE_NAN)
12954 return -EOPNOTSUPP;
12956 if (!wdev_running(wdev))
12959 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12962 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12963 info->attrs[NL80211_ATTR_NAN_FUNC],
12964 nl80211_nan_func_policy,
12969 func = kzalloc(sizeof(*func), GFP_KERNEL);
12973 func->cookie = cfg80211_assign_cookie(rdev);
12975 if (!tb[NL80211_NAN_FUNC_TYPE]) {
12981 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12983 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12988 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12989 sizeof(func->service_id));
12991 func->close_range =
12992 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12994 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12995 func->serv_spec_info_len =
12996 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12997 func->serv_spec_info =
12998 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12999 func->serv_spec_info_len,
13001 if (!func->serv_spec_info) {
13007 if (tb[NL80211_NAN_FUNC_TTL])
13008 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
13010 switch (func->type) {
13011 case NL80211_NAN_FUNC_PUBLISH:
13012 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
13017 func->publish_type =
13018 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
13019 func->publish_bcast =
13020 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
13022 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
13023 func->publish_bcast) {
13028 case NL80211_NAN_FUNC_SUBSCRIBE:
13029 func->subscribe_active =
13030 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
13032 case NL80211_NAN_FUNC_FOLLOW_UP:
13033 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
13034 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
13035 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
13040 func->followup_id =
13041 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
13042 func->followup_reqid =
13043 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
13044 memcpy(func->followup_dest.addr,
13045 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
13046 sizeof(func->followup_dest.addr));
13057 if (tb[NL80211_NAN_FUNC_SRF]) {
13058 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
13060 err = nla_parse_nested_deprecated(srf_tb,
13061 NL80211_NAN_SRF_ATTR_MAX,
13062 tb[NL80211_NAN_FUNC_SRF],
13063 nl80211_nan_srf_policy,
13068 func->srf_include =
13069 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
13071 if (srf_tb[NL80211_NAN_SRF_BF]) {
13072 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
13073 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
13079 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
13081 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
13082 func->srf_bf_len, GFP_KERNEL);
13083 if (!func->srf_bf) {
13089 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
13091 struct nlattr *attr, *mac_attr =
13092 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
13093 int n_entries, rem, i = 0;
13100 n_entries = validate_acl_mac_addrs(mac_attr);
13101 if (n_entries <= 0) {
13106 func->srf_num_macs = n_entries;
13108 kcalloc(n_entries, sizeof(*func->srf_macs),
13110 if (!func->srf_macs) {
13115 nla_for_each_nested(attr, mac_attr, rem)
13116 memcpy(func->srf_macs[i++].addr, nla_data(attr),
13117 sizeof(*func->srf_macs));
13121 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
13122 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
13128 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
13129 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
13135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13141 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13142 NL80211_CMD_ADD_NAN_FUNCTION);
13143 /* This can't really happen - we just allocated 4KB */
13144 if (WARN_ON(!hdr)) {
13149 err = rdev_add_nan_func(rdev, wdev, func);
13152 cfg80211_free_nan_func(func);
13157 /* propagate the instance id and cookie to userspace */
13158 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
13160 goto nla_put_failure;
13162 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
13164 goto nla_put_failure;
13166 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
13167 func->instance_id))
13168 goto nla_put_failure;
13170 nla_nest_end(msg, func_attr);
13172 genlmsg_end(msg, hdr);
13173 return genlmsg_reply(msg, info);
13180 static int nl80211_nan_del_func(struct sk_buff *skb,
13181 struct genl_info *info)
13183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13184 struct wireless_dev *wdev = info->user_ptr[1];
13187 if (wdev->iftype != NL80211_IFTYPE_NAN)
13188 return -EOPNOTSUPP;
13190 if (!wdev_running(wdev))
13193 if (!info->attrs[NL80211_ATTR_COOKIE])
13196 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
13198 rdev_del_nan_func(rdev, wdev, cookie);
13203 static int nl80211_nan_change_config(struct sk_buff *skb,
13204 struct genl_info *info)
13206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13207 struct wireless_dev *wdev = info->user_ptr[1];
13208 struct cfg80211_nan_conf conf = {};
13211 if (wdev->iftype != NL80211_IFTYPE_NAN)
13212 return -EOPNOTSUPP;
13214 if (!wdev_running(wdev))
13217 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
13219 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
13220 if (conf.master_pref <= 1 || conf.master_pref == 255)
13223 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
13226 if (info->attrs[NL80211_ATTR_BANDS]) {
13227 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
13229 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
13230 return -EOPNOTSUPP;
13232 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
13235 conf.bands = bands;
13236 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
13242 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
13245 void cfg80211_nan_match(struct wireless_dev *wdev,
13246 struct cfg80211_nan_match_params *match, gfp_t gfp)
13248 struct wiphy *wiphy = wdev->wiphy;
13249 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13250 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
13251 struct sk_buff *msg;
13254 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
13257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13261 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
13267 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13268 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13269 wdev->netdev->ifindex)) ||
13270 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13272 goto nla_put_failure;
13274 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
13275 NL80211_ATTR_PAD) ||
13276 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
13277 goto nla_put_failure;
13279 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
13281 goto nla_put_failure;
13283 local_func_attr = nla_nest_start_noflag(msg,
13284 NL80211_NAN_MATCH_FUNC_LOCAL);
13285 if (!local_func_attr)
13286 goto nla_put_failure;
13288 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
13289 goto nla_put_failure;
13291 nla_nest_end(msg, local_func_attr);
13293 peer_func_attr = nla_nest_start_noflag(msg,
13294 NL80211_NAN_MATCH_FUNC_PEER);
13295 if (!peer_func_attr)
13296 goto nla_put_failure;
13298 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
13299 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
13300 goto nla_put_failure;
13302 if (match->info && match->info_len &&
13303 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
13305 goto nla_put_failure;
13307 nla_nest_end(msg, peer_func_attr);
13308 nla_nest_end(msg, match_attr);
13309 genlmsg_end(msg, hdr);
13311 if (!wdev->owner_nlportid)
13312 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
13313 msg, 0, NL80211_MCGRP_NAN, gfp);
13315 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
13316 wdev->owner_nlportid);
13323 EXPORT_SYMBOL(cfg80211_nan_match);
13325 void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
13327 enum nl80211_nan_func_term_reason reason,
13328 u64 cookie, gfp_t gfp)
13330 struct wiphy *wiphy = wdev->wiphy;
13331 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13332 struct sk_buff *msg;
13333 struct nlattr *func_attr;
13336 if (WARN_ON(!inst_id))
13339 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13343 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
13349 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13350 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13351 wdev->netdev->ifindex)) ||
13352 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13354 goto nla_put_failure;
13356 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13358 goto nla_put_failure;
13360 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
13362 goto nla_put_failure;
13364 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
13365 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
13366 goto nla_put_failure;
13368 nla_nest_end(msg, func_attr);
13369 genlmsg_end(msg, hdr);
13371 if (!wdev->owner_nlportid)
13372 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
13373 msg, 0, NL80211_MCGRP_NAN, gfp);
13375 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
13376 wdev->owner_nlportid);
13383 EXPORT_SYMBOL(cfg80211_nan_func_terminated);
13385 static int nl80211_get_protocol_features(struct sk_buff *skb,
13386 struct genl_info *info)
13389 struct sk_buff *msg;
13391 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13395 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13396 NL80211_CMD_GET_PROTOCOL_FEATURES);
13398 goto nla_put_failure;
13400 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
13401 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
13402 goto nla_put_failure;
13404 genlmsg_end(msg, hdr);
13405 return genlmsg_reply(msg, info);
13412 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
13414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13415 struct cfg80211_update_ft_ies_params ft_params;
13416 struct net_device *dev = info->user_ptr[1];
13418 if (!rdev->ops->update_ft_ies)
13419 return -EOPNOTSUPP;
13421 if (!info->attrs[NL80211_ATTR_MDID] ||
13422 !info->attrs[NL80211_ATTR_IE])
13425 memset(&ft_params, 0, sizeof(ft_params));
13426 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
13427 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13428 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13430 return rdev_update_ft_ies(rdev, dev, &ft_params);
13433 static int nl80211_crit_protocol_start(struct sk_buff *skb,
13434 struct genl_info *info)
13436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13437 struct wireless_dev *wdev = info->user_ptr[1];
13438 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
13442 if (!rdev->ops->crit_proto_start)
13443 return -EOPNOTSUPP;
13445 if (WARN_ON(!rdev->ops->crit_proto_stop))
13448 if (rdev->crit_proto_nlportid)
13451 /* determine protocol if provided */
13452 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
13453 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
13455 if (proto >= NUM_NL80211_CRIT_PROTO)
13458 /* timeout must be provided */
13459 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
13463 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
13465 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
13467 rdev->crit_proto_nlportid = info->snd_portid;
13472 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
13473 struct genl_info *info)
13475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13476 struct wireless_dev *wdev = info->user_ptr[1];
13478 if (!rdev->ops->crit_proto_stop)
13479 return -EOPNOTSUPP;
13481 if (rdev->crit_proto_nlportid) {
13482 rdev->crit_proto_nlportid = 0;
13483 rdev_crit_proto_stop(rdev, wdev);
13488 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
13489 struct nlattr *attr,
13490 struct netlink_ext_ack *extack)
13492 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
13493 if (attr->nla_type & NLA_F_NESTED) {
13494 NL_SET_ERR_MSG_ATTR(extack, attr,
13495 "unexpected nested data");
13502 if (!(attr->nla_type & NLA_F_NESTED)) {
13503 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
13507 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
13510 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
13512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13513 struct wireless_dev *wdev =
13514 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
13518 if (!rdev->wiphy.vendor_commands)
13519 return -EOPNOTSUPP;
13521 if (IS_ERR(wdev)) {
13522 err = PTR_ERR(wdev);
13523 if (err != -EINVAL)
13526 } else if (wdev->wiphy != &rdev->wiphy) {
13530 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
13531 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
13534 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
13535 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
13536 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
13537 const struct wiphy_vendor_command *vcmd;
13541 vcmd = &rdev->wiphy.vendor_commands[i];
13543 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13546 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13547 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
13550 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
13554 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
13555 if (!wdev_running(wdev))
13563 return -EOPNOTSUPP;
13565 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
13566 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
13567 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
13569 err = nl80211_vendor_check_policy(vcmd,
13570 info->attrs[NL80211_ATTR_VENDOR_DATA],
13576 rdev->cur_cmd_info = info;
13577 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
13578 rdev->cur_cmd_info = NULL;
13582 return -EOPNOTSUPP;
13585 static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
13586 struct netlink_callback *cb,
13587 struct cfg80211_registered_device **rdev,
13588 struct wireless_dev **wdev)
13590 struct nlattr **attrbuf;
13596 unsigned int data_len = 0;
13599 /* subtract the 1 again here */
13600 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
13601 struct wireless_dev *tmp;
13605 *rdev = wiphy_to_rdev(wiphy);
13609 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
13610 if (tmp->identifier == cb->args[1] - 1) {
13617 /* keep rtnl locked in successful case */
13621 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
13625 err = nlmsg_parse_deprecated(cb->nlh,
13626 GENL_HDRLEN + nl80211_fam.hdrsize,
13627 attrbuf, nl80211_fam.maxattr,
13628 nl80211_policy, NULL);
13632 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
13633 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
13638 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
13642 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
13643 if (IS_ERR(*rdev)) {
13644 err = PTR_ERR(*rdev);
13648 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
13649 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
13651 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
13652 const struct wiphy_vendor_command *vcmd;
13654 vcmd = &(*rdev)->wiphy.vendor_commands[i];
13656 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13659 if (!vcmd->dumpit) {
13668 if (vcmd_idx < 0) {
13673 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
13674 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13675 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13677 err = nl80211_vendor_check_policy(
13678 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
13679 attrbuf[NL80211_ATTR_VENDOR_DATA],
13685 /* 0 is the first index - add 1 to parse only once */
13686 cb->args[0] = (*rdev)->wiphy_idx + 1;
13687 /* add 1 to know if it was NULL */
13688 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
13689 cb->args[2] = vcmd_idx;
13690 cb->args[3] = (unsigned long)data;
13691 cb->args[4] = data_len;
13693 /* keep rtnl locked in successful case */
13700 static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
13701 struct netlink_callback *cb)
13703 struct cfg80211_registered_device *rdev;
13704 struct wireless_dev *wdev;
13705 unsigned int vcmd_idx;
13706 const struct wiphy_vendor_command *vcmd;
13710 struct nlattr *vendor_data;
13713 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13717 vcmd_idx = cb->args[2];
13718 data = (void *)cb->args[3];
13719 data_len = cb->args[4];
13720 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
13722 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13723 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
13728 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
13734 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
13735 if (!wdev_running(wdev)) {
13743 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
13744 cb->nlh->nlmsg_seq, NLM_F_MULTI,
13745 NL80211_CMD_VENDOR);
13749 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13750 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13752 NL80211_ATTR_PAD))) {
13753 genlmsg_cancel(skb, hdr);
13757 vendor_data = nla_nest_start_noflag(skb,
13758 NL80211_ATTR_VENDOR_DATA);
13759 if (!vendor_data) {
13760 genlmsg_cancel(skb, hdr);
13764 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
13765 (unsigned long *)&cb->args[5]);
13766 nla_nest_end(skb, vendor_data);
13768 if (err == -ENOBUFS || err == -ENOENT) {
13769 genlmsg_cancel(skb, hdr);
13771 } else if (err <= 0) {
13772 genlmsg_cancel(skb, hdr);
13776 genlmsg_end(skb, hdr);
13785 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13786 enum nl80211_commands cmd,
13787 enum nl80211_attrs attr,
13790 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13792 if (WARN_ON(!rdev->cur_cmd_info))
13795 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
13796 rdev->cur_cmd_info->snd_portid,
13797 rdev->cur_cmd_info->snd_seq,
13798 cmd, attr, NULL, GFP_KERNEL);
13800 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13802 int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
13804 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
13805 void *hdr = ((void **)skb->cb)[1];
13806 struct nlattr *data = ((void **)skb->cb)[2];
13808 /* clear CB data for netlink core to own from now on */
13809 memset(skb->cb, 0, sizeof(skb->cb));
13811 if (WARN_ON(!rdev->cur_cmd_info)) {
13816 nla_nest_end(skb, data);
13817 genlmsg_end(skb, hdr);
13818 return genlmsg_reply(skb, rdev->cur_cmd_info);
13820 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13822 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
13824 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13826 if (WARN_ON(!rdev->cur_cmd_info))
13829 return rdev->cur_cmd_info->snd_portid;
13831 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13833 static int nl80211_set_qos_map(struct sk_buff *skb,
13834 struct genl_info *info)
13836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13837 struct cfg80211_qos_map *qos_map = NULL;
13838 struct net_device *dev = info->user_ptr[1];
13839 u8 *pos, len, num_des, des_len, des;
13842 if (!rdev->ops->set_qos_map)
13843 return -EOPNOTSUPP;
13845 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13846 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13847 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13852 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13856 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13858 des_len = num_des *
13859 sizeof(struct cfg80211_dscp_exception);
13860 memcpy(qos_map->dscp_exception, pos, des_len);
13861 qos_map->num_des = num_des;
13862 for (des = 0; des < num_des; des++) {
13863 if (qos_map->dscp_exception[des].up > 7) {
13870 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13873 wdev_lock(dev->ieee80211_ptr);
13874 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13876 ret = rdev_set_qos_map(rdev, dev, qos_map);
13877 wdev_unlock(dev->ieee80211_ptr);
13883 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13886 struct net_device *dev = info->user_ptr[1];
13887 struct wireless_dev *wdev = dev->ieee80211_ptr;
13890 u16 admitted_time = 0;
13893 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
13894 return -EOPNOTSUPP;
13896 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13897 !info->attrs[NL80211_ATTR_USER_PRIO])
13900 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13901 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
13903 /* WMM uses TIDs 0-7 even for TSPEC */
13904 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
13905 /* TODO: handle 802.11 TSPEC/admission control
13906 * need more attributes for that (e.g. BA session requirement);
13907 * change the WMM adminssion test above to allow both then
13912 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13914 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13916 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13917 if (!admitted_time)
13922 switch (wdev->iftype) {
13923 case NL80211_IFTYPE_STATION:
13924 case NL80211_IFTYPE_P2P_CLIENT:
13925 if (wdev->current_bss)
13934 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13941 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13944 struct net_device *dev = info->user_ptr[1];
13945 struct wireless_dev *wdev = dev->ieee80211_ptr;
13950 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13953 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13954 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13957 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13963 static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13964 struct genl_info *info)
13966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13967 struct net_device *dev = info->user_ptr[1];
13968 struct wireless_dev *wdev = dev->ieee80211_ptr;
13969 struct cfg80211_chan_def chandef = {};
13974 if (!rdev->ops->tdls_channel_switch ||
13975 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13976 return -EOPNOTSUPP;
13978 switch (dev->ieee80211_ptr->iftype) {
13979 case NL80211_IFTYPE_STATION:
13980 case NL80211_IFTYPE_P2P_CLIENT:
13983 return -EOPNOTSUPP;
13986 if (!info->attrs[NL80211_ATTR_MAC] ||
13987 !info->attrs[NL80211_ATTR_OPER_CLASS])
13990 err = nl80211_parse_chandef(rdev, info, &chandef);
13995 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13996 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13997 * specification is not defined for them.
13999 if (chandef.chan->band == NL80211_BAND_2GHZ &&
14000 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
14001 chandef.width != NL80211_CHAN_WIDTH_20)
14004 /* we will be active on the TDLS link */
14005 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
14009 /* don't allow switching to DFS channels */
14010 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
14013 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
14014 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
14017 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
14023 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
14024 struct genl_info *info)
14026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14027 struct net_device *dev = info->user_ptr[1];
14028 struct wireless_dev *wdev = dev->ieee80211_ptr;
14031 if (!rdev->ops->tdls_channel_switch ||
14032 !rdev->ops->tdls_cancel_channel_switch ||
14033 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
14034 return -EOPNOTSUPP;
14036 switch (dev->ieee80211_ptr->iftype) {
14037 case NL80211_IFTYPE_STATION:
14038 case NL80211_IFTYPE_P2P_CLIENT:
14041 return -EOPNOTSUPP;
14044 if (!info->attrs[NL80211_ATTR_MAC])
14047 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
14050 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
14056 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
14057 struct genl_info *info)
14059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14060 struct net_device *dev = info->user_ptr[1];
14061 struct wireless_dev *wdev = dev->ieee80211_ptr;
14062 const struct nlattr *nla;
14065 if (!rdev->ops->set_multicast_to_unicast)
14066 return -EOPNOTSUPP;
14068 if (wdev->iftype != NL80211_IFTYPE_AP &&
14069 wdev->iftype != NL80211_IFTYPE_P2P_GO)
14070 return -EOPNOTSUPP;
14072 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
14073 enabled = nla_get_flag(nla);
14075 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
14078 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
14080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14081 struct net_device *dev = info->user_ptr[1];
14082 struct wireless_dev *wdev = dev->ieee80211_ptr;
14083 struct cfg80211_pmk_conf pmk_conf = {};
14086 if (wdev->iftype != NL80211_IFTYPE_STATION &&
14087 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
14088 return -EOPNOTSUPP;
14090 if (!wiphy_ext_feature_isset(&rdev->wiphy,
14091 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
14092 return -EOPNOTSUPP;
14094 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
14098 if (!wdev->current_bss) {
14103 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
14104 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
14109 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
14110 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
14111 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
14112 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
14117 if (info->attrs[NL80211_ATTR_PMKR0_NAME])
14118 pmk_conf.pmk_r0_name =
14119 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
14121 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
14127 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
14129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14130 struct net_device *dev = info->user_ptr[1];
14131 struct wireless_dev *wdev = dev->ieee80211_ptr;
14135 if (wdev->iftype != NL80211_IFTYPE_STATION &&
14136 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
14137 return -EOPNOTSUPP;
14139 if (!wiphy_ext_feature_isset(&rdev->wiphy,
14140 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
14141 return -EOPNOTSUPP;
14143 if (!info->attrs[NL80211_ATTR_MAC])
14147 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
14148 ret = rdev_del_pmk(rdev, dev, aa);
14154 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
14156 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14157 struct net_device *dev = info->user_ptr[1];
14158 struct cfg80211_external_auth_params params;
14160 if (!rdev->ops->external_auth)
14161 return -EOPNOTSUPP;
14163 if (!info->attrs[NL80211_ATTR_SSID] &&
14164 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
14165 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
14168 if (!info->attrs[NL80211_ATTR_BSSID])
14171 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
14174 memset(¶ms, 0, sizeof(params));
14176 if (info->attrs[NL80211_ATTR_SSID]) {
14177 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
14178 if (params.ssid.ssid_len == 0)
14180 memcpy(params.ssid.ssid,
14181 nla_data(info->attrs[NL80211_ATTR_SSID]),
14182 params.ssid.ssid_len);
14185 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
14188 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
14190 if (info->attrs[NL80211_ATTR_PMKID])
14191 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
14193 return rdev_external_auth(rdev, dev, ¶ms);
14196 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
14198 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
14199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14200 struct net_device *dev = info->user_ptr[1];
14201 struct wireless_dev *wdev = dev->ieee80211_ptr;
14210 if (!wiphy_ext_feature_isset(&rdev->wiphy,
14211 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
14212 return -EOPNOTSUPP;
14214 if (!rdev->ops->tx_control_port)
14215 return -EOPNOTSUPP;
14217 if (!info->attrs[NL80211_ATTR_FRAME] ||
14218 !info->attrs[NL80211_ATTR_MAC] ||
14219 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
14220 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
14226 switch (wdev->iftype) {
14227 case NL80211_IFTYPE_AP:
14228 case NL80211_IFTYPE_P2P_GO:
14229 case NL80211_IFTYPE_MESH_POINT:
14231 case NL80211_IFTYPE_ADHOC:
14232 case NL80211_IFTYPE_STATION:
14233 case NL80211_IFTYPE_P2P_CLIENT:
14234 if (wdev->current_bss)
14245 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
14246 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
14247 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
14248 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
14250 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
14252 err = rdev_tx_control_port(rdev, dev, buf, len,
14253 dest, cpu_to_be16(proto), noencrypt,
14254 dont_wait_for_ack ? NULL : &cookie);
14255 if (!err && !dont_wait_for_ack)
14256 nl_set_extack_cookie_u64(info->extack, cookie);
14263 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
14264 struct genl_info *info)
14266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14267 struct net_device *dev = info->user_ptr[1];
14268 struct wireless_dev *wdev = dev->ieee80211_ptr;
14269 struct cfg80211_ftm_responder_stats ftm_stats = {};
14270 struct sk_buff *msg;
14272 struct nlattr *ftm_stats_attr;
14275 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
14276 return -EOPNOTSUPP;
14278 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
14282 if (!ftm_stats.filled)
14285 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14289 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14290 NL80211_CMD_GET_FTM_RESPONDER_STATS);
14292 goto nla_put_failure;
14294 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
14295 goto nla_put_failure;
14297 ftm_stats_attr = nla_nest_start_noflag(msg,
14298 NL80211_ATTR_FTM_RESPONDER_STATS);
14299 if (!ftm_stats_attr)
14300 goto nla_put_failure;
14302 #define SET_FTM(field, name, type) \
14303 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14304 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
14305 ftm_stats.field)) \
14306 goto nla_put_failure; } while (0)
14307 #define SET_FTM_U64(field, name) \
14308 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14309 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
14310 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
14311 goto nla_put_failure; } while (0)
14313 SET_FTM(success_num, SUCCESS_NUM, u32);
14314 SET_FTM(partial_num, PARTIAL_NUM, u32);
14315 SET_FTM(failed_num, FAILED_NUM, u32);
14316 SET_FTM(asap_num, ASAP_NUM, u32);
14317 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
14318 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
14319 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
14320 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
14321 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
14324 nla_nest_end(msg, ftm_stats_attr);
14326 genlmsg_end(msg, hdr);
14327 return genlmsg_reply(msg, info);
14334 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
14336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14337 struct cfg80211_update_owe_info owe_info;
14338 struct net_device *dev = info->user_ptr[1];
14340 if (!rdev->ops->update_owe_info)
14341 return -EOPNOTSUPP;
14343 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
14344 !info->attrs[NL80211_ATTR_MAC])
14347 memset(&owe_info, 0, sizeof(owe_info));
14348 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
14349 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
14351 if (info->attrs[NL80211_ATTR_IE]) {
14352 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
14353 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
14356 return rdev_update_owe_info(rdev, dev, &owe_info);
14359 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
14361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14362 struct net_device *dev = info->user_ptr[1];
14363 struct wireless_dev *wdev = dev->ieee80211_ptr;
14364 struct station_info sinfo = {};
14370 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
14371 return -EOPNOTSUPP;
14373 if (!info->attrs[NL80211_ATTR_MAC] ||
14374 !info->attrs[NL80211_ATTR_FRAME]) {
14375 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
14379 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
14380 return -EOPNOTSUPP;
14382 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
14383 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
14384 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
14386 if (len < sizeof(struct ethhdr))
14389 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
14390 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
14393 err = rdev_get_station(rdev, dev, dest, &sinfo);
14397 cfg80211_sinfo_release_content(&sinfo);
14399 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
14402 static int parse_tid_conf(struct cfg80211_registered_device *rdev,
14403 struct nlattr *attrs[], struct net_device *dev,
14404 struct cfg80211_tid_cfg *tid_conf,
14405 struct genl_info *info, const u8 *peer)
14407 struct netlink_ext_ack *extack = info->extack;
14411 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS])
14414 tid_conf->config_override =
14415 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]);
14416 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
14418 if (tid_conf->config_override) {
14419 if (rdev->ops->reset_tid_config) {
14420 err = rdev_reset_tid_config(rdev, dev, peer,
14429 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
14430 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
14432 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
14435 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) {
14436 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT);
14437 tid_conf->retry_short =
14438 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]);
14440 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count)
14444 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) {
14445 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
14446 tid_conf->retry_long =
14447 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]);
14449 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count)
14453 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) {
14454 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
14456 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]);
14459 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) {
14460 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
14462 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]);
14465 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) {
14466 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL);
14468 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]);
14471 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) {
14472 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr;
14474 tid_conf->txrate_type = nla_get_u8(attrs[idx]);
14476 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) {
14477 attr = NL80211_TID_CONFIG_ATTR_TX_RATE;
14478 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr,
14479 &tid_conf->txrate_mask, dev);
14483 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE);
14485 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
14489 mask = rdev->wiphy.tid_config_support.peer;
14491 mask = rdev->wiphy.tid_config_support.vif;
14493 if (tid_conf->mask & ~mask) {
14494 NL_SET_ERR_MSG(extack, "unsupported TID configuration");
14501 static int nl80211_set_tid_config(struct sk_buff *skb,
14502 struct genl_info *info)
14504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14505 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1];
14506 struct net_device *dev = info->user_ptr[1];
14507 struct cfg80211_tid_config *tid_config;
14508 struct nlattr *tid;
14509 int conf_idx = 0, rem_conf;
14513 if (!info->attrs[NL80211_ATTR_TID_CONFIG])
14516 if (!rdev->ops->set_tid_config)
14517 return -EOPNOTSUPP;
14519 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14523 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf),
14528 tid_config->n_tid_conf = num_conf;
14530 if (info->attrs[NL80211_ATTR_MAC])
14531 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
14533 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14535 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX,
14541 ret = parse_tid_conf(rdev, attrs, dev,
14542 &tid_config->tid_conf[conf_idx],
14543 info, tid_config->peer);
14550 ret = rdev_set_tid_config(rdev, dev, tid_config);
14557 #define NL80211_FLAG_NEED_WIPHY 0x01
14558 #define NL80211_FLAG_NEED_NETDEV 0x02
14559 #define NL80211_FLAG_NEED_RTNL 0x04
14560 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
14561 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
14562 NL80211_FLAG_CHECK_NETDEV_UP)
14563 #define NL80211_FLAG_NEED_WDEV 0x10
14564 /* If a netdev is associated, it must be UP, P2P must be started */
14565 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
14566 NL80211_FLAG_CHECK_NETDEV_UP)
14567 #define NL80211_FLAG_CLEAR_SKB 0x20
14569 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
14570 struct genl_info *info)
14572 struct cfg80211_registered_device *rdev;
14573 struct wireless_dev *wdev;
14574 struct net_device *dev;
14575 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
14580 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
14581 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
14582 if (IS_ERR(rdev)) {
14585 return PTR_ERR(rdev);
14587 info->user_ptr[0] = rdev;
14588 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
14589 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
14592 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
14594 if (IS_ERR(wdev)) {
14597 return PTR_ERR(wdev);
14600 dev = wdev->netdev;
14601 rdev = wiphy_to_rdev(wdev->wiphy);
14603 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
14610 info->user_ptr[1] = dev;
14612 info->user_ptr[1] = wdev;
14615 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
14616 !wdev_running(wdev)) {
14625 info->user_ptr[0] = rdev;
14631 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
14632 struct genl_info *info)
14634 if (info->user_ptr[1]) {
14635 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
14636 struct wireless_dev *wdev = info->user_ptr[1];
14639 dev_put(wdev->netdev);
14641 dev_put(info->user_ptr[1]);
14645 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
14648 /* If needed, clear the netlink message payload from the SKB
14649 * as it might contain key data that shouldn't stick around on
14650 * the heap after the SKB is freed. The netlink message header
14651 * is still needed for further processing, so leave it intact.
14653 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
14654 struct nlmsghdr *nlh = nlmsg_hdr(skb);
14656 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
14660 static const struct genl_ops nl80211_ops[] = {
14662 .cmd = NL80211_CMD_GET_WIPHY,
14663 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14664 .doit = nl80211_get_wiphy,
14665 .dumpit = nl80211_dump_wiphy,
14666 .done = nl80211_dump_wiphy_done,
14667 /* can be retrieved by unprivileged users */
14668 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14669 NL80211_FLAG_NEED_RTNL,
14673 static const struct genl_small_ops nl80211_small_ops[] = {
14675 .cmd = NL80211_CMD_SET_WIPHY,
14676 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14677 .doit = nl80211_set_wiphy,
14678 .flags = GENL_UNS_ADMIN_PERM,
14679 .internal_flags = NL80211_FLAG_NEED_RTNL,
14682 .cmd = NL80211_CMD_GET_INTERFACE,
14683 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14684 .doit = nl80211_get_interface,
14685 .dumpit = nl80211_dump_interface,
14686 /* can be retrieved by unprivileged users */
14687 .internal_flags = NL80211_FLAG_NEED_WDEV |
14688 NL80211_FLAG_NEED_RTNL,
14691 .cmd = NL80211_CMD_SET_INTERFACE,
14692 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14693 .doit = nl80211_set_interface,
14694 .flags = GENL_UNS_ADMIN_PERM,
14695 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14696 NL80211_FLAG_NEED_RTNL,
14699 .cmd = NL80211_CMD_NEW_INTERFACE,
14700 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14701 .doit = nl80211_new_interface,
14702 .flags = GENL_UNS_ADMIN_PERM,
14703 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14704 NL80211_FLAG_NEED_RTNL,
14707 .cmd = NL80211_CMD_DEL_INTERFACE,
14708 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14709 .doit = nl80211_del_interface,
14710 .flags = GENL_UNS_ADMIN_PERM,
14711 .internal_flags = NL80211_FLAG_NEED_WDEV |
14712 NL80211_FLAG_NEED_RTNL,
14715 .cmd = NL80211_CMD_GET_KEY,
14716 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14717 .doit = nl80211_get_key,
14718 .flags = GENL_UNS_ADMIN_PERM,
14719 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14720 NL80211_FLAG_NEED_RTNL,
14723 .cmd = NL80211_CMD_SET_KEY,
14724 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14725 .doit = nl80211_set_key,
14726 .flags = GENL_UNS_ADMIN_PERM,
14727 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14728 NL80211_FLAG_NEED_RTNL |
14729 NL80211_FLAG_CLEAR_SKB,
14732 .cmd = NL80211_CMD_NEW_KEY,
14733 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14734 .doit = nl80211_new_key,
14735 .flags = GENL_UNS_ADMIN_PERM,
14736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14737 NL80211_FLAG_NEED_RTNL |
14738 NL80211_FLAG_CLEAR_SKB,
14741 .cmd = NL80211_CMD_DEL_KEY,
14742 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14743 .doit = nl80211_del_key,
14744 .flags = GENL_UNS_ADMIN_PERM,
14745 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14746 NL80211_FLAG_NEED_RTNL,
14749 .cmd = NL80211_CMD_SET_BEACON,
14750 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14751 .flags = GENL_UNS_ADMIN_PERM,
14752 .doit = nl80211_set_beacon,
14753 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14754 NL80211_FLAG_NEED_RTNL,
14757 .cmd = NL80211_CMD_START_AP,
14758 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14759 .flags = GENL_UNS_ADMIN_PERM,
14760 .doit = nl80211_start_ap,
14761 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14762 NL80211_FLAG_NEED_RTNL,
14765 .cmd = NL80211_CMD_STOP_AP,
14766 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14767 .flags = GENL_UNS_ADMIN_PERM,
14768 .doit = nl80211_stop_ap,
14769 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14770 NL80211_FLAG_NEED_RTNL,
14773 .cmd = NL80211_CMD_GET_STATION,
14774 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14775 .doit = nl80211_get_station,
14776 .dumpit = nl80211_dump_station,
14777 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14778 NL80211_FLAG_NEED_RTNL,
14781 .cmd = NL80211_CMD_SET_STATION,
14782 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14783 .doit = nl80211_set_station,
14784 .flags = GENL_UNS_ADMIN_PERM,
14785 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14786 NL80211_FLAG_NEED_RTNL,
14789 .cmd = NL80211_CMD_NEW_STATION,
14790 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14791 .doit = nl80211_new_station,
14792 .flags = GENL_UNS_ADMIN_PERM,
14793 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14794 NL80211_FLAG_NEED_RTNL,
14797 .cmd = NL80211_CMD_DEL_STATION,
14798 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14799 .doit = nl80211_del_station,
14800 .flags = GENL_UNS_ADMIN_PERM,
14801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14802 NL80211_FLAG_NEED_RTNL,
14805 .cmd = NL80211_CMD_GET_MPATH,
14806 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14807 .doit = nl80211_get_mpath,
14808 .dumpit = nl80211_dump_mpath,
14809 .flags = GENL_UNS_ADMIN_PERM,
14810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14811 NL80211_FLAG_NEED_RTNL,
14814 .cmd = NL80211_CMD_GET_MPP,
14815 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14816 .doit = nl80211_get_mpp,
14817 .dumpit = nl80211_dump_mpp,
14818 .flags = GENL_UNS_ADMIN_PERM,
14819 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14820 NL80211_FLAG_NEED_RTNL,
14823 .cmd = NL80211_CMD_SET_MPATH,
14824 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14825 .doit = nl80211_set_mpath,
14826 .flags = GENL_UNS_ADMIN_PERM,
14827 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14828 NL80211_FLAG_NEED_RTNL,
14831 .cmd = NL80211_CMD_NEW_MPATH,
14832 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14833 .doit = nl80211_new_mpath,
14834 .flags = GENL_UNS_ADMIN_PERM,
14835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14836 NL80211_FLAG_NEED_RTNL,
14839 .cmd = NL80211_CMD_DEL_MPATH,
14840 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14841 .doit = nl80211_del_mpath,
14842 .flags = GENL_UNS_ADMIN_PERM,
14843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14844 NL80211_FLAG_NEED_RTNL,
14847 .cmd = NL80211_CMD_SET_BSS,
14848 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14849 .doit = nl80211_set_bss,
14850 .flags = GENL_UNS_ADMIN_PERM,
14851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14852 NL80211_FLAG_NEED_RTNL,
14855 .cmd = NL80211_CMD_GET_REG,
14856 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14857 .doit = nl80211_get_reg_do,
14858 .dumpit = nl80211_get_reg_dump,
14859 .internal_flags = NL80211_FLAG_NEED_RTNL,
14860 /* can be retrieved by unprivileged users */
14862 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
14864 .cmd = NL80211_CMD_SET_REG,
14865 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14866 .doit = nl80211_set_reg,
14867 .flags = GENL_ADMIN_PERM,
14868 .internal_flags = NL80211_FLAG_NEED_RTNL,
14872 .cmd = NL80211_CMD_REQ_SET_REG,
14873 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14874 .doit = nl80211_req_set_reg,
14875 .flags = GENL_ADMIN_PERM,
14878 .cmd = NL80211_CMD_RELOAD_REGDB,
14879 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14880 .doit = nl80211_reload_regdb,
14881 .flags = GENL_ADMIN_PERM,
14884 .cmd = NL80211_CMD_GET_MESH_CONFIG,
14885 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14886 .doit = nl80211_get_mesh_config,
14887 /* can be retrieved by unprivileged users */
14888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14889 NL80211_FLAG_NEED_RTNL,
14892 .cmd = NL80211_CMD_SET_MESH_CONFIG,
14893 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14894 .doit = nl80211_update_mesh_config,
14895 .flags = GENL_UNS_ADMIN_PERM,
14896 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14897 NL80211_FLAG_NEED_RTNL,
14900 .cmd = NL80211_CMD_TRIGGER_SCAN,
14901 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14902 .doit = nl80211_trigger_scan,
14903 .flags = GENL_UNS_ADMIN_PERM,
14904 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14905 NL80211_FLAG_NEED_RTNL,
14908 .cmd = NL80211_CMD_ABORT_SCAN,
14909 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14910 .doit = nl80211_abort_scan,
14911 .flags = GENL_UNS_ADMIN_PERM,
14912 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14913 NL80211_FLAG_NEED_RTNL,
14916 .cmd = NL80211_CMD_GET_SCAN,
14917 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14918 .dumpit = nl80211_dump_scan,
14921 .cmd = NL80211_CMD_START_SCHED_SCAN,
14922 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14923 .doit = nl80211_start_sched_scan,
14924 .flags = GENL_UNS_ADMIN_PERM,
14925 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14926 NL80211_FLAG_NEED_RTNL,
14929 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
14930 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14931 .doit = nl80211_stop_sched_scan,
14932 .flags = GENL_UNS_ADMIN_PERM,
14933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14934 NL80211_FLAG_NEED_RTNL,
14937 .cmd = NL80211_CMD_AUTHENTICATE,
14938 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14939 .doit = nl80211_authenticate,
14940 .flags = GENL_UNS_ADMIN_PERM,
14941 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14942 NL80211_FLAG_NEED_RTNL |
14943 NL80211_FLAG_CLEAR_SKB,
14946 .cmd = NL80211_CMD_ASSOCIATE,
14947 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14948 .doit = nl80211_associate,
14949 .flags = GENL_UNS_ADMIN_PERM,
14950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14951 NL80211_FLAG_NEED_RTNL |
14952 NL80211_FLAG_CLEAR_SKB,
14955 .cmd = NL80211_CMD_DEAUTHENTICATE,
14956 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14957 .doit = nl80211_deauthenticate,
14958 .flags = GENL_UNS_ADMIN_PERM,
14959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14960 NL80211_FLAG_NEED_RTNL,
14963 .cmd = NL80211_CMD_DISASSOCIATE,
14964 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14965 .doit = nl80211_disassociate,
14966 .flags = GENL_UNS_ADMIN_PERM,
14967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14968 NL80211_FLAG_NEED_RTNL,
14971 .cmd = NL80211_CMD_JOIN_IBSS,
14972 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14973 .doit = nl80211_join_ibss,
14974 .flags = GENL_UNS_ADMIN_PERM,
14975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14976 NL80211_FLAG_NEED_RTNL,
14979 .cmd = NL80211_CMD_LEAVE_IBSS,
14980 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14981 .doit = nl80211_leave_ibss,
14982 .flags = GENL_UNS_ADMIN_PERM,
14983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14984 NL80211_FLAG_NEED_RTNL,
14986 #ifdef CONFIG_NL80211_TESTMODE
14988 .cmd = NL80211_CMD_TESTMODE,
14989 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14990 .doit = nl80211_testmode_do,
14991 .dumpit = nl80211_testmode_dump,
14992 .flags = GENL_UNS_ADMIN_PERM,
14993 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14994 NL80211_FLAG_NEED_RTNL,
14998 .cmd = NL80211_CMD_CONNECT,
14999 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15000 .doit = nl80211_connect,
15001 .flags = GENL_UNS_ADMIN_PERM,
15002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15003 NL80211_FLAG_NEED_RTNL |
15004 NL80211_FLAG_CLEAR_SKB,
15007 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
15008 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15009 .doit = nl80211_update_connect_params,
15010 .flags = GENL_ADMIN_PERM,
15011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15012 NL80211_FLAG_NEED_RTNL |
15013 NL80211_FLAG_CLEAR_SKB,
15016 .cmd = NL80211_CMD_DISCONNECT,
15017 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15018 .doit = nl80211_disconnect,
15019 .flags = GENL_UNS_ADMIN_PERM,
15020 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15021 NL80211_FLAG_NEED_RTNL,
15024 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
15025 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15026 .doit = nl80211_wiphy_netns,
15027 .flags = GENL_UNS_ADMIN_PERM,
15028 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15029 NL80211_FLAG_NEED_RTNL,
15032 .cmd = NL80211_CMD_GET_SURVEY,
15033 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15034 .dumpit = nl80211_dump_survey,
15037 .cmd = NL80211_CMD_SET_PMKSA,
15038 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15039 .doit = nl80211_setdel_pmksa,
15040 .flags = GENL_UNS_ADMIN_PERM,
15041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15042 NL80211_FLAG_NEED_RTNL |
15043 NL80211_FLAG_CLEAR_SKB,
15046 .cmd = NL80211_CMD_DEL_PMKSA,
15047 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15048 .doit = nl80211_setdel_pmksa,
15049 .flags = GENL_UNS_ADMIN_PERM,
15050 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15051 NL80211_FLAG_NEED_RTNL,
15054 .cmd = NL80211_CMD_FLUSH_PMKSA,
15055 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15056 .doit = nl80211_flush_pmksa,
15057 .flags = GENL_UNS_ADMIN_PERM,
15058 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15059 NL80211_FLAG_NEED_RTNL,
15062 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
15063 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15064 .doit = nl80211_remain_on_channel,
15065 .flags = GENL_UNS_ADMIN_PERM,
15066 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15067 NL80211_FLAG_NEED_RTNL,
15070 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
15071 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15072 .doit = nl80211_cancel_remain_on_channel,
15073 .flags = GENL_UNS_ADMIN_PERM,
15074 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15075 NL80211_FLAG_NEED_RTNL,
15078 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
15079 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15080 .doit = nl80211_set_tx_bitrate_mask,
15081 .flags = GENL_UNS_ADMIN_PERM,
15082 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15083 NL80211_FLAG_NEED_RTNL,
15086 .cmd = NL80211_CMD_REGISTER_FRAME,
15087 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15088 .doit = nl80211_register_mgmt,
15089 .flags = GENL_UNS_ADMIN_PERM,
15090 .internal_flags = NL80211_FLAG_NEED_WDEV |
15091 NL80211_FLAG_NEED_RTNL,
15094 .cmd = NL80211_CMD_FRAME,
15095 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15096 .doit = nl80211_tx_mgmt,
15097 .flags = GENL_UNS_ADMIN_PERM,
15098 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15099 NL80211_FLAG_NEED_RTNL,
15102 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
15103 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15104 .doit = nl80211_tx_mgmt_cancel_wait,
15105 .flags = GENL_UNS_ADMIN_PERM,
15106 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15107 NL80211_FLAG_NEED_RTNL,
15110 .cmd = NL80211_CMD_SET_POWER_SAVE,
15111 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15112 .doit = nl80211_set_power_save,
15113 .flags = GENL_UNS_ADMIN_PERM,
15114 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15115 NL80211_FLAG_NEED_RTNL,
15118 .cmd = NL80211_CMD_GET_POWER_SAVE,
15119 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15120 .doit = nl80211_get_power_save,
15121 /* can be retrieved by unprivileged users */
15122 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15123 NL80211_FLAG_NEED_RTNL,
15126 .cmd = NL80211_CMD_SET_CQM,
15127 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15128 .doit = nl80211_set_cqm,
15129 .flags = GENL_UNS_ADMIN_PERM,
15130 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15131 NL80211_FLAG_NEED_RTNL,
15134 .cmd = NL80211_CMD_SET_CHANNEL,
15135 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15136 .doit = nl80211_set_channel,
15137 .flags = GENL_UNS_ADMIN_PERM,
15138 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15139 NL80211_FLAG_NEED_RTNL,
15142 .cmd = NL80211_CMD_SET_WDS_PEER,
15143 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15144 .doit = nl80211_set_wds_peer,
15145 .flags = GENL_UNS_ADMIN_PERM,
15146 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15147 NL80211_FLAG_NEED_RTNL,
15150 .cmd = NL80211_CMD_JOIN_MESH,
15151 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15152 .doit = nl80211_join_mesh,
15153 .flags = GENL_UNS_ADMIN_PERM,
15154 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15155 NL80211_FLAG_NEED_RTNL,
15158 .cmd = NL80211_CMD_LEAVE_MESH,
15159 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15160 .doit = nl80211_leave_mesh,
15161 .flags = GENL_UNS_ADMIN_PERM,
15162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15163 NL80211_FLAG_NEED_RTNL,
15166 .cmd = NL80211_CMD_JOIN_OCB,
15167 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15168 .doit = nl80211_join_ocb,
15169 .flags = GENL_UNS_ADMIN_PERM,
15170 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15171 NL80211_FLAG_NEED_RTNL,
15174 .cmd = NL80211_CMD_LEAVE_OCB,
15175 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15176 .doit = nl80211_leave_ocb,
15177 .flags = GENL_UNS_ADMIN_PERM,
15178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15179 NL80211_FLAG_NEED_RTNL,
15183 .cmd = NL80211_CMD_GET_WOWLAN,
15184 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15185 .doit = nl80211_get_wowlan,
15186 /* can be retrieved by unprivileged users */
15187 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15188 NL80211_FLAG_NEED_RTNL,
15191 .cmd = NL80211_CMD_SET_WOWLAN,
15192 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15193 .doit = nl80211_set_wowlan,
15194 .flags = GENL_UNS_ADMIN_PERM,
15195 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15196 NL80211_FLAG_NEED_RTNL,
15200 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
15201 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15202 .doit = nl80211_set_rekey_data,
15203 .flags = GENL_UNS_ADMIN_PERM,
15204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15205 NL80211_FLAG_NEED_RTNL |
15206 NL80211_FLAG_CLEAR_SKB,
15209 .cmd = NL80211_CMD_TDLS_MGMT,
15210 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15211 .doit = nl80211_tdls_mgmt,
15212 .flags = GENL_UNS_ADMIN_PERM,
15213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15214 NL80211_FLAG_NEED_RTNL,
15217 .cmd = NL80211_CMD_TDLS_OPER,
15218 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15219 .doit = nl80211_tdls_oper,
15220 .flags = GENL_UNS_ADMIN_PERM,
15221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15222 NL80211_FLAG_NEED_RTNL,
15225 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
15226 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15227 .doit = nl80211_register_unexpected_frame,
15228 .flags = GENL_UNS_ADMIN_PERM,
15229 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15230 NL80211_FLAG_NEED_RTNL,
15233 .cmd = NL80211_CMD_PROBE_CLIENT,
15234 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15235 .doit = nl80211_probe_client,
15236 .flags = GENL_UNS_ADMIN_PERM,
15237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15238 NL80211_FLAG_NEED_RTNL,
15241 .cmd = NL80211_CMD_REGISTER_BEACONS,
15242 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15243 .doit = nl80211_register_beacons,
15244 .flags = GENL_UNS_ADMIN_PERM,
15245 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15246 NL80211_FLAG_NEED_RTNL,
15249 .cmd = NL80211_CMD_SET_NOACK_MAP,
15250 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15251 .doit = nl80211_set_noack_map,
15252 .flags = GENL_UNS_ADMIN_PERM,
15253 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15254 NL80211_FLAG_NEED_RTNL,
15257 .cmd = NL80211_CMD_START_P2P_DEVICE,
15258 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15259 .doit = nl80211_start_p2p_device,
15260 .flags = GENL_UNS_ADMIN_PERM,
15261 .internal_flags = NL80211_FLAG_NEED_WDEV |
15262 NL80211_FLAG_NEED_RTNL,
15265 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
15266 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15267 .doit = nl80211_stop_p2p_device,
15268 .flags = GENL_UNS_ADMIN_PERM,
15269 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15270 NL80211_FLAG_NEED_RTNL,
15273 .cmd = NL80211_CMD_START_NAN,
15274 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15275 .doit = nl80211_start_nan,
15276 .flags = GENL_ADMIN_PERM,
15277 .internal_flags = NL80211_FLAG_NEED_WDEV |
15278 NL80211_FLAG_NEED_RTNL,
15281 .cmd = NL80211_CMD_STOP_NAN,
15282 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15283 .doit = nl80211_stop_nan,
15284 .flags = GENL_ADMIN_PERM,
15285 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15286 NL80211_FLAG_NEED_RTNL,
15289 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
15290 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15291 .doit = nl80211_nan_add_func,
15292 .flags = GENL_ADMIN_PERM,
15293 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15294 NL80211_FLAG_NEED_RTNL,
15297 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
15298 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15299 .doit = nl80211_nan_del_func,
15300 .flags = GENL_ADMIN_PERM,
15301 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15302 NL80211_FLAG_NEED_RTNL,
15305 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
15306 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15307 .doit = nl80211_nan_change_config,
15308 .flags = GENL_ADMIN_PERM,
15309 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15310 NL80211_FLAG_NEED_RTNL,
15313 .cmd = NL80211_CMD_SET_MCAST_RATE,
15314 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15315 .doit = nl80211_set_mcast_rate,
15316 .flags = GENL_UNS_ADMIN_PERM,
15317 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15318 NL80211_FLAG_NEED_RTNL,
15321 .cmd = NL80211_CMD_SET_MAC_ACL,
15322 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15323 .doit = nl80211_set_mac_acl,
15324 .flags = GENL_UNS_ADMIN_PERM,
15325 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15326 NL80211_FLAG_NEED_RTNL,
15329 .cmd = NL80211_CMD_RADAR_DETECT,
15330 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15331 .doit = nl80211_start_radar_detection,
15332 .flags = GENL_UNS_ADMIN_PERM,
15333 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15334 NL80211_FLAG_NEED_RTNL,
15337 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
15338 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15339 .doit = nl80211_get_protocol_features,
15342 .cmd = NL80211_CMD_UPDATE_FT_IES,
15343 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15344 .doit = nl80211_update_ft_ies,
15345 .flags = GENL_UNS_ADMIN_PERM,
15346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15347 NL80211_FLAG_NEED_RTNL,
15350 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
15351 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15352 .doit = nl80211_crit_protocol_start,
15353 .flags = GENL_UNS_ADMIN_PERM,
15354 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15355 NL80211_FLAG_NEED_RTNL,
15358 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
15359 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15360 .doit = nl80211_crit_protocol_stop,
15361 .flags = GENL_UNS_ADMIN_PERM,
15362 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15363 NL80211_FLAG_NEED_RTNL,
15366 .cmd = NL80211_CMD_GET_COALESCE,
15367 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15368 .doit = nl80211_get_coalesce,
15369 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15370 NL80211_FLAG_NEED_RTNL,
15373 .cmd = NL80211_CMD_SET_COALESCE,
15374 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15375 .doit = nl80211_set_coalesce,
15376 .flags = GENL_UNS_ADMIN_PERM,
15377 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15378 NL80211_FLAG_NEED_RTNL,
15381 .cmd = NL80211_CMD_CHANNEL_SWITCH,
15382 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15383 .doit = nl80211_channel_switch,
15384 .flags = GENL_UNS_ADMIN_PERM,
15385 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15386 NL80211_FLAG_NEED_RTNL,
15389 .cmd = NL80211_CMD_VENDOR,
15390 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15391 .doit = nl80211_vendor_cmd,
15392 .dumpit = nl80211_vendor_cmd_dump,
15393 .flags = GENL_UNS_ADMIN_PERM,
15394 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15395 NL80211_FLAG_NEED_RTNL |
15396 NL80211_FLAG_CLEAR_SKB,
15399 .cmd = NL80211_CMD_SET_QOS_MAP,
15400 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15401 .doit = nl80211_set_qos_map,
15402 .flags = GENL_UNS_ADMIN_PERM,
15403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15404 NL80211_FLAG_NEED_RTNL,
15407 .cmd = NL80211_CMD_ADD_TX_TS,
15408 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15409 .doit = nl80211_add_tx_ts,
15410 .flags = GENL_UNS_ADMIN_PERM,
15411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15412 NL80211_FLAG_NEED_RTNL,
15415 .cmd = NL80211_CMD_DEL_TX_TS,
15416 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15417 .doit = nl80211_del_tx_ts,
15418 .flags = GENL_UNS_ADMIN_PERM,
15419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15420 NL80211_FLAG_NEED_RTNL,
15423 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
15424 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15425 .doit = nl80211_tdls_channel_switch,
15426 .flags = GENL_UNS_ADMIN_PERM,
15427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15428 NL80211_FLAG_NEED_RTNL,
15431 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
15432 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15433 .doit = nl80211_tdls_cancel_channel_switch,
15434 .flags = GENL_UNS_ADMIN_PERM,
15435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15436 NL80211_FLAG_NEED_RTNL,
15439 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
15440 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15441 .doit = nl80211_set_multicast_to_unicast,
15442 .flags = GENL_UNS_ADMIN_PERM,
15443 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15444 NL80211_FLAG_NEED_RTNL,
15447 .cmd = NL80211_CMD_SET_PMK,
15448 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15449 .doit = nl80211_set_pmk,
15450 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15451 NL80211_FLAG_NEED_RTNL |
15452 NL80211_FLAG_CLEAR_SKB,
15455 .cmd = NL80211_CMD_DEL_PMK,
15456 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15457 .doit = nl80211_del_pmk,
15458 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15459 NL80211_FLAG_NEED_RTNL,
15462 .cmd = NL80211_CMD_EXTERNAL_AUTH,
15463 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15464 .doit = nl80211_external_auth,
15465 .flags = GENL_ADMIN_PERM,
15466 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15467 NL80211_FLAG_NEED_RTNL,
15470 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
15471 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15472 .doit = nl80211_tx_control_port,
15473 .flags = GENL_UNS_ADMIN_PERM,
15474 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15475 NL80211_FLAG_NEED_RTNL,
15478 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
15479 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15480 .doit = nl80211_get_ftm_responder_stats,
15481 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15482 NL80211_FLAG_NEED_RTNL,
15485 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
15486 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15487 .doit = nl80211_pmsr_start,
15488 .flags = GENL_UNS_ADMIN_PERM,
15489 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15490 NL80211_FLAG_NEED_RTNL,
15493 .cmd = NL80211_CMD_NOTIFY_RADAR,
15494 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15495 .doit = nl80211_notify_radar_detection,
15496 .flags = GENL_UNS_ADMIN_PERM,
15497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15498 NL80211_FLAG_NEED_RTNL,
15501 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
15502 .doit = nl80211_update_owe_info,
15503 .flags = GENL_ADMIN_PERM,
15504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15505 NL80211_FLAG_NEED_RTNL,
15508 .cmd = NL80211_CMD_PROBE_MESH_LINK,
15509 .doit = nl80211_probe_mesh_link,
15510 .flags = GENL_UNS_ADMIN_PERM,
15511 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15512 NL80211_FLAG_NEED_RTNL,
15515 .cmd = NL80211_CMD_SET_TID_CONFIG,
15516 .doit = nl80211_set_tid_config,
15517 .flags = GENL_UNS_ADMIN_PERM,
15518 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15519 NL80211_FLAG_NEED_RTNL,
15523 static struct genl_family nl80211_fam __ro_after_init = {
15524 .name = NL80211_GENL_NAME, /* have users key off the name instead */
15525 .hdrsize = 0, /* no private header */
15526 .version = 1, /* no particular meaning now */
15527 .maxattr = NL80211_ATTR_MAX,
15528 .policy = nl80211_policy,
15530 .pre_doit = nl80211_pre_doit,
15531 .post_doit = nl80211_post_doit,
15532 .module = THIS_MODULE,
15533 .ops = nl80211_ops,
15534 .n_ops = ARRAY_SIZE(nl80211_ops),
15535 .small_ops = nl80211_small_ops,
15536 .n_small_ops = ARRAY_SIZE(nl80211_small_ops),
15537 .mcgrps = nl80211_mcgrps,
15538 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
15539 .parallel_ops = true,
15542 /* notification functions */
15544 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
15545 enum nl80211_commands cmd)
15547 struct sk_buff *msg;
15548 struct nl80211_dump_wiphy_state state = {};
15550 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
15551 cmd != NL80211_CMD_DEL_WIPHY);
15553 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15557 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
15562 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15563 NL80211_MCGRP_CONFIG, GFP_KERNEL);
15566 void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
15567 struct wireless_dev *wdev,
15568 enum nl80211_commands cmd)
15570 struct sk_buff *msg;
15572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15576 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
15581 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15582 NL80211_MCGRP_CONFIG, GFP_KERNEL);
15585 static int nl80211_add_scan_req(struct sk_buff *msg,
15586 struct cfg80211_registered_device *rdev)
15588 struct cfg80211_scan_request *req = rdev->scan_req;
15589 struct nlattr *nest;
15591 struct cfg80211_scan_info *info;
15596 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
15598 goto nla_put_failure;
15599 for (i = 0; i < req->n_ssids; i++) {
15600 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
15601 goto nla_put_failure;
15603 nla_nest_end(msg, nest);
15605 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) {
15606 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ);
15608 goto nla_put_failure;
15609 for (i = 0; i < req->n_channels; i++) {
15610 if (nla_put_u32(msg, i,
15611 ieee80211_channel_to_khz(req->channels[i])))
15612 goto nla_put_failure;
15614 nla_nest_end(msg, nest);
15616 nest = nla_nest_start_noflag(msg,
15617 NL80211_ATTR_SCAN_FREQUENCIES);
15619 goto nla_put_failure;
15620 for (i = 0; i < req->n_channels; i++) {
15621 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
15622 goto nla_put_failure;
15624 nla_nest_end(msg, nest);
15628 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
15629 goto nla_put_failure;
15632 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
15633 goto nla_put_failure;
15635 info = rdev->int_scan_req ? &rdev->int_scan_req->info :
15636 &rdev->scan_req->info;
15637 if (info->scan_start_tsf &&
15638 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
15639 info->scan_start_tsf, NL80211_BSS_PAD) ||
15640 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
15642 goto nla_put_failure;
15649 static int nl80211_prep_scan_msg(struct sk_buff *msg,
15650 struct cfg80211_registered_device *rdev,
15651 struct wireless_dev *wdev,
15652 u32 portid, u32 seq, int flags,
15657 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
15661 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15662 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15663 wdev->netdev->ifindex)) ||
15664 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15666 goto nla_put_failure;
15668 /* ignore errors and send incomplete event anyway */
15669 nl80211_add_scan_req(msg, rdev);
15671 genlmsg_end(msg, hdr);
15675 genlmsg_cancel(msg, hdr);
15680 nl80211_prep_sched_scan_msg(struct sk_buff *msg,
15681 struct cfg80211_sched_scan_request *req, u32 cmd)
15685 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15689 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
15690 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
15691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
15692 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
15694 goto nla_put_failure;
15696 genlmsg_end(msg, hdr);
15700 genlmsg_cancel(msg, hdr);
15704 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
15705 struct wireless_dev *wdev)
15707 struct sk_buff *msg;
15709 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15713 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
15714 NL80211_CMD_TRIGGER_SCAN) < 0) {
15719 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15720 NL80211_MCGRP_SCAN, GFP_KERNEL);
15723 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
15724 struct wireless_dev *wdev, bool aborted)
15726 struct sk_buff *msg;
15728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15732 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
15733 aborted ? NL80211_CMD_SCAN_ABORTED :
15734 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
15742 /* send message created by nl80211_build_scan_msg() */
15743 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
15744 struct sk_buff *msg)
15749 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15750 NL80211_MCGRP_SCAN, GFP_KERNEL);
15753 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
15755 struct sk_buff *msg;
15757 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15761 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
15766 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
15767 NL80211_MCGRP_SCAN, GFP_KERNEL);
15770 static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
15771 struct regulatory_request *request)
15773 /* Userspace can always count this one always being set */
15774 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
15775 goto nla_put_failure;
15777 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
15778 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15779 NL80211_REGDOM_TYPE_WORLD))
15780 goto nla_put_failure;
15781 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
15782 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15783 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
15784 goto nla_put_failure;
15785 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
15786 request->intersect) {
15787 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15788 NL80211_REGDOM_TYPE_INTERSECTION))
15789 goto nla_put_failure;
15791 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15792 NL80211_REGDOM_TYPE_COUNTRY) ||
15793 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
15795 goto nla_put_failure;
15798 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
15799 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
15802 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
15803 goto nla_put_failure;
15806 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
15807 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
15808 goto nla_put_failure;
15818 * This can happen on global regulatory changes or device specific settings
15819 * based on custom regulatory domains.
15821 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
15822 struct regulatory_request *request)
15824 struct sk_buff *msg;
15827 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15831 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
15833 goto nla_put_failure;
15835 if (!nl80211_reg_change_event_fill(msg, request))
15836 goto nla_put_failure;
15838 genlmsg_end(msg, hdr);
15841 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
15842 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
15851 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
15852 struct net_device *netdev,
15853 const u8 *buf, size_t len,
15854 enum nl80211_commands cmd, gfp_t gfp,
15855 int uapsd_queues, const u8 *req_ies,
15856 size_t req_ies_len)
15858 struct sk_buff *msg;
15861 msg = nlmsg_new(100 + len + req_ies_len, gfp);
15865 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15871 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15872 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15873 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15875 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
15876 goto nla_put_failure;
15878 if (uapsd_queues >= 0) {
15879 struct nlattr *nla_wmm =
15880 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
15882 goto nla_put_failure;
15884 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
15886 goto nla_put_failure;
15888 nla_nest_end(msg, nla_wmm);
15891 genlmsg_end(msg, hdr);
15893 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15894 NL80211_MCGRP_MLME, gfp);
15901 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
15902 struct net_device *netdev, const u8 *buf,
15903 size_t len, gfp_t gfp)
15905 nl80211_send_mlme_event(rdev, netdev, buf, len,
15906 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
15909 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15910 struct net_device *netdev, const u8 *buf,
15911 size_t len, gfp_t gfp, int uapsd_queues,
15912 const u8 *req_ies, size_t req_ies_len)
15914 nl80211_send_mlme_event(rdev, netdev, buf, len,
15915 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15916 req_ies, req_ies_len);
15919 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
15920 struct net_device *netdev, const u8 *buf,
15921 size_t len, gfp_t gfp)
15923 nl80211_send_mlme_event(rdev, netdev, buf, len,
15924 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
15927 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15928 struct net_device *netdev, const u8 *buf,
15929 size_t len, gfp_t gfp)
15931 nl80211_send_mlme_event(rdev, netdev, buf, len,
15932 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
15935 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15938 struct wireless_dev *wdev = dev->ieee80211_ptr;
15939 struct wiphy *wiphy = wdev->wiphy;
15940 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15941 const struct ieee80211_mgmt *mgmt = (void *)buf;
15944 if (WARN_ON(len < 2))
15947 if (ieee80211_is_deauth(mgmt->frame_control)) {
15948 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
15949 } else if (ieee80211_is_disassoc(mgmt->frame_control)) {
15950 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
15951 } else if (ieee80211_is_beacon(mgmt->frame_control)) {
15952 if (wdev->unprot_beacon_reported &&
15953 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000)
15955 cmd = NL80211_CMD_UNPROT_BEACON;
15956 wdev->unprot_beacon_reported = jiffies;
15961 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
15962 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15965 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
15967 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15968 struct net_device *netdev, int cmd,
15969 const u8 *addr, gfp_t gfp)
15971 struct sk_buff *msg;
15974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15978 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15984 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15985 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15986 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15987 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15988 goto nla_put_failure;
15990 genlmsg_end(msg, hdr);
15992 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15993 NL80211_MCGRP_MLME, gfp);
16000 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
16001 struct net_device *netdev, const u8 *addr,
16004 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
16008 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
16009 struct net_device *netdev, const u8 *addr,
16012 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
16016 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
16017 struct net_device *netdev,
16018 struct cfg80211_connect_resp_params *cr,
16021 struct sk_buff *msg;
16024 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
16025 cr->fils.kek_len + cr->fils.pmk_len +
16026 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
16030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
16036 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16037 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16039 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
16040 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
16041 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
16044 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
16045 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
16046 cr->timeout_reason))) ||
16048 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
16050 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
16052 (cr->fils.update_erp_next_seq_num &&
16053 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
16054 cr->fils.erp_next_seq_num)) ||
16055 (cr->status == WLAN_STATUS_SUCCESS &&
16057 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
16060 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
16062 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
16063 goto nla_put_failure;
16065 genlmsg_end(msg, hdr);
16067 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16068 NL80211_MCGRP_MLME, gfp);
16075 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
16076 struct net_device *netdev,
16077 struct cfg80211_roam_info *info, gfp_t gfp)
16079 struct sk_buff *msg;
16081 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
16083 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
16084 info->fils.kek_len + info->fils.pmk_len +
16085 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
16089 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
16095 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16096 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16097 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
16099 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
16102 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
16104 (info->fils.update_erp_next_seq_num &&
16105 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
16106 info->fils.erp_next_seq_num)) ||
16108 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
16109 info->fils.kek)) ||
16111 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
16112 (info->fils.pmkid &&
16113 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
16114 goto nla_put_failure;
16116 genlmsg_end(msg, hdr);
16118 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16119 NL80211_MCGRP_MLME, gfp);
16126 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
16127 struct net_device *netdev, const u8 *bssid)
16129 struct sk_buff *msg;
16132 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16136 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
16142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16143 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16144 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16145 goto nla_put_failure;
16147 genlmsg_end(msg, hdr);
16149 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16150 NL80211_MCGRP_MLME, GFP_KERNEL);
16157 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
16158 struct net_device *netdev, u16 reason,
16159 const u8 *ie, size_t ie_len, bool from_ap)
16161 struct sk_buff *msg;
16164 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
16168 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
16174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16177 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
16179 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
16180 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
16181 goto nla_put_failure;
16183 genlmsg_end(msg, hdr);
16185 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16186 NL80211_MCGRP_MLME, GFP_KERNEL);
16193 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
16194 struct net_device *netdev, const u8 *bssid,
16197 struct sk_buff *msg;
16200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16204 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
16210 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16211 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16212 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16213 goto nla_put_failure;
16215 genlmsg_end(msg, hdr);
16217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16218 NL80211_MCGRP_MLME, gfp);
16225 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
16226 const u8 *ie, u8 ie_len,
16227 int sig_dbm, gfp_t gfp)
16229 struct wireless_dev *wdev = dev->ieee80211_ptr;
16230 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16231 struct sk_buff *msg;
16234 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
16237 trace_cfg80211_notify_new_peer_candidate(dev, addr);
16239 msg = nlmsg_new(100 + ie_len, gfp);
16243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
16249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16251 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
16253 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
16255 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
16256 goto nla_put_failure;
16258 genlmsg_end(msg, hdr);
16260 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16261 NL80211_MCGRP_MLME, gfp);
16267 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
16269 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
16270 struct net_device *netdev, const u8 *addr,
16271 enum nl80211_key_type key_type, int key_id,
16272 const u8 *tsc, gfp_t gfp)
16274 struct sk_buff *msg;
16277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16281 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
16287 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16288 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16289 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
16290 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
16292 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
16293 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
16294 goto nla_put_failure;
16296 genlmsg_end(msg, hdr);
16298 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16299 NL80211_MCGRP_MLME, gfp);
16306 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
16307 struct ieee80211_channel *channel_before,
16308 struct ieee80211_channel *channel_after)
16310 struct sk_buff *msg;
16312 struct nlattr *nl_freq;
16314 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
16318 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
16325 * Since we are applying the beacon hint to a wiphy we know its
16326 * wiphy_idx is valid
16328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
16329 goto nla_put_failure;
16332 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
16334 goto nla_put_failure;
16336 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
16337 goto nla_put_failure;
16338 nla_nest_end(msg, nl_freq);
16341 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
16343 goto nla_put_failure;
16345 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
16346 goto nla_put_failure;
16347 nla_nest_end(msg, nl_freq);
16349 genlmsg_end(msg, hdr);
16352 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
16353 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
16362 static void nl80211_send_remain_on_chan_event(
16363 int cmd, struct cfg80211_registered_device *rdev,
16364 struct wireless_dev *wdev, u64 cookie,
16365 struct ieee80211_channel *chan,
16366 unsigned int duration, gfp_t gfp)
16368 struct sk_buff *msg;
16371 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16375 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
16381 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16382 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16383 wdev->netdev->ifindex)) ||
16384 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16385 NL80211_ATTR_PAD) ||
16386 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
16387 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
16388 NL80211_CHAN_NO_HT) ||
16389 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16391 goto nla_put_failure;
16393 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
16394 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
16395 goto nla_put_failure;
16397 genlmsg_end(msg, hdr);
16399 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16400 NL80211_MCGRP_MLME, gfp);
16407 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
16408 struct ieee80211_channel *chan,
16409 unsigned int duration, gfp_t gfp)
16411 struct wiphy *wiphy = wdev->wiphy;
16412 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16414 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
16415 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
16416 rdev, wdev, cookie, chan,
16419 EXPORT_SYMBOL(cfg80211_ready_on_channel);
16421 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
16422 struct ieee80211_channel *chan,
16425 struct wiphy *wiphy = wdev->wiphy;
16426 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16428 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
16429 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
16430 rdev, wdev, cookie, chan, 0, gfp);
16432 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
16434 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
16435 struct ieee80211_channel *chan,
16438 struct wiphy *wiphy = wdev->wiphy;
16439 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16441 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
16442 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
16443 rdev, wdev, cookie, chan, 0, gfp);
16445 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
16447 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
16448 struct station_info *sinfo, gfp_t gfp)
16450 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
16451 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16452 struct sk_buff *msg;
16454 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
16456 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16460 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
16461 rdev, dev, mac_addr, sinfo) < 0) {
16466 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16467 NL80211_MCGRP_MLME, gfp);
16469 EXPORT_SYMBOL(cfg80211_new_sta);
16471 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
16472 struct station_info *sinfo, gfp_t gfp)
16474 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
16475 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16476 struct sk_buff *msg;
16477 struct station_info empty_sinfo = {};
16480 sinfo = &empty_sinfo;
16482 trace_cfg80211_del_sta(dev, mac_addr);
16484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16486 cfg80211_sinfo_release_content(sinfo);
16490 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
16491 rdev, dev, mac_addr, sinfo) < 0) {
16496 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16497 NL80211_MCGRP_MLME, gfp);
16499 EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
16501 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
16502 enum nl80211_connect_failed_reason reason,
16505 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
16506 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16507 struct sk_buff *msg;
16510 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
16514 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
16520 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16521 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
16522 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
16523 goto nla_put_failure;
16525 genlmsg_end(msg, hdr);
16527 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16528 NL80211_MCGRP_MLME, gfp);
16534 EXPORT_SYMBOL(cfg80211_conn_failed);
16536 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
16537 const u8 *addr, gfp_t gfp)
16539 struct wireless_dev *wdev = dev->ieee80211_ptr;
16540 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16541 struct sk_buff *msg;
16543 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
16548 msg = nlmsg_new(100, gfp);
16552 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
16558 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16559 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16560 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
16561 goto nla_put_failure;
16563 genlmsg_end(msg, hdr);
16564 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16572 bool cfg80211_rx_spurious_frame(struct net_device *dev,
16573 const u8 *addr, gfp_t gfp)
16575 struct wireless_dev *wdev = dev->ieee80211_ptr;
16578 trace_cfg80211_rx_spurious_frame(dev, addr);
16580 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16581 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
16582 trace_cfg80211_return_bool(false);
16585 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
16587 trace_cfg80211_return_bool(ret);
16590 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
16592 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
16593 const u8 *addr, gfp_t gfp)
16595 struct wireless_dev *wdev = dev->ieee80211_ptr;
16598 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
16600 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16601 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
16602 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
16603 trace_cfg80211_return_bool(false);
16606 ret = __nl80211_unexpected_frame(dev,
16607 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
16609 trace_cfg80211_return_bool(ret);
16612 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
16614 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
16615 struct wireless_dev *wdev, u32 nlportid,
16616 int freq, int sig_dbm,
16617 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
16619 struct net_device *netdev = wdev->netdev;
16620 struct sk_buff *msg;
16623 msg = nlmsg_new(100 + len, gfp);
16627 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16633 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16634 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16635 netdev->ifindex)) ||
16636 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16637 NL80211_ATTR_PAD) ||
16638 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) ||
16639 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) ||
16641 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16642 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
16644 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
16645 goto nla_put_failure;
16647 genlmsg_end(msg, hdr);
16649 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16656 static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie,
16657 const u8 *buf, size_t len, bool ack,
16658 gfp_t gfp, enum nl80211_commands command)
16660 struct wiphy *wiphy = wdev->wiphy;
16661 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16662 struct net_device *netdev = wdev->netdev;
16663 struct sk_buff *msg;
16666 if (command == NL80211_CMD_FRAME_TX_STATUS)
16667 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
16669 trace_cfg80211_control_port_tx_status(wdev, cookie, ack);
16671 msg = nlmsg_new(100 + len, gfp);
16675 hdr = nl80211hdr_put(msg, 0, 0, 0, command);
16681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16682 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16683 netdev->ifindex)) ||
16684 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16685 NL80211_ATTR_PAD) ||
16686 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
16687 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16688 NL80211_ATTR_PAD) ||
16689 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
16690 goto nla_put_failure;
16692 genlmsg_end(msg, hdr);
16694 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16695 NL80211_MCGRP_MLME, gfp);
16702 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie,
16703 const u8 *buf, size_t len, bool ack,
16706 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp,
16707 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS);
16709 EXPORT_SYMBOL(cfg80211_control_port_tx_status);
16711 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
16712 const u8 *buf, size_t len, bool ack, gfp_t gfp)
16714 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp,
16715 NL80211_CMD_FRAME_TX_STATUS);
16717 EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
16719 static int __nl80211_rx_control_port(struct net_device *dev,
16720 struct sk_buff *skb,
16721 bool unencrypted, gfp_t gfp)
16723 struct wireless_dev *wdev = dev->ieee80211_ptr;
16724 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16725 struct ethhdr *ehdr = eth_hdr(skb);
16726 const u8 *addr = ehdr->h_source;
16727 u16 proto = be16_to_cpu(skb->protocol);
16728 struct sk_buff *msg;
16730 struct nlattr *frame;
16732 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
16737 msg = nlmsg_new(100 + skb->len, gfp);
16741 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
16747 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16748 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16749 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16750 NL80211_ATTR_PAD) ||
16751 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
16752 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
16753 (unencrypted && nla_put_flag(msg,
16754 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
16755 goto nla_put_failure;
16757 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
16759 goto nla_put_failure;
16761 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
16762 genlmsg_end(msg, hdr);
16764 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16771 bool cfg80211_rx_control_port(struct net_device *dev,
16772 struct sk_buff *skb, bool unencrypted)
16776 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
16777 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
16778 trace_cfg80211_return_bool(ret == 0);
16781 EXPORT_SYMBOL(cfg80211_rx_control_port);
16783 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
16784 const char *mac, gfp_t gfp)
16786 struct wireless_dev *wdev = dev->ieee80211_ptr;
16787 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16788 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16794 cb = (void **)msg->cb;
16796 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
16802 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16803 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16804 goto nla_put_failure;
16806 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16807 goto nla_put_failure;
16809 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
16811 goto nla_put_failure;
16821 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
16823 void **cb = (void **)msg->cb;
16824 struct cfg80211_registered_device *rdev = cb[2];
16826 nla_nest_end(msg, cb[1]);
16827 genlmsg_end(msg, cb[0]);
16829 memset(msg->cb, 0, sizeof(msg->cb));
16831 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16832 NL80211_MCGRP_MLME, gfp);
16835 void cfg80211_cqm_rssi_notify(struct net_device *dev,
16836 enum nl80211_cqm_rssi_threshold_event rssi_event,
16837 s32 rssi_level, gfp_t gfp)
16839 struct sk_buff *msg;
16840 struct wireless_dev *wdev = dev->ieee80211_ptr;
16841 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16843 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
16845 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
16846 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
16849 if (wdev->cqm_config) {
16850 wdev->cqm_config->last_rssi_event_value = rssi_level;
16852 cfg80211_cqm_rssi_update(rdev, dev);
16854 if (rssi_level == 0)
16855 rssi_level = wdev->cqm_config->last_rssi_event_value;
16858 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16862 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
16864 goto nla_put_failure;
16866 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
16868 goto nla_put_failure;
16870 cfg80211_send_cqm(msg, gfp);
16877 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
16879 void cfg80211_cqm_txe_notify(struct net_device *dev,
16880 const u8 *peer, u32 num_packets,
16881 u32 rate, u32 intvl, gfp_t gfp)
16883 struct sk_buff *msg;
16885 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16889 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
16890 goto nla_put_failure;
16892 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
16893 goto nla_put_failure;
16895 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
16896 goto nla_put_failure;
16898 cfg80211_send_cqm(msg, gfp);
16904 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16906 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
16907 const u8 *peer, u32 num_packets, gfp_t gfp)
16909 struct sk_buff *msg;
16911 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
16913 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16917 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
16918 goto nla_put_failure;
16920 cfg80211_send_cqm(msg, gfp);
16926 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16928 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
16930 struct sk_buff *msg;
16932 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16936 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
16937 goto nla_put_failure;
16939 cfg80211_send_cqm(msg, gfp);
16945 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16947 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
16948 struct net_device *netdev, const u8 *bssid,
16949 const u8 *replay_ctr, gfp_t gfp)
16951 struct sk_buff *msg;
16952 struct nlattr *rekey_attr;
16955 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16959 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
16965 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16966 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16967 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16968 goto nla_put_failure;
16970 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
16972 goto nla_put_failure;
16974 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16975 NL80211_REPLAY_CTR_LEN, replay_ctr))
16976 goto nla_put_failure;
16978 nla_nest_end(msg, rekey_attr);
16980 genlmsg_end(msg, hdr);
16982 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16983 NL80211_MCGRP_MLME, gfp);
16990 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
16991 const u8 *replay_ctr, gfp_t gfp)
16993 struct wireless_dev *wdev = dev->ieee80211_ptr;
16994 struct wiphy *wiphy = wdev->wiphy;
16995 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16997 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16998 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
17000 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
17003 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
17004 struct net_device *netdev, int index,
17005 const u8 *bssid, bool preauth, gfp_t gfp)
17007 struct sk_buff *msg;
17008 struct nlattr *attr;
17011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17015 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
17021 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17022 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
17023 goto nla_put_failure;
17025 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
17027 goto nla_put_failure;
17029 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
17030 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
17032 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
17033 goto nla_put_failure;
17035 nla_nest_end(msg, attr);
17037 genlmsg_end(msg, hdr);
17039 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17040 NL80211_MCGRP_MLME, gfp);
17047 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
17048 const u8 *bssid, bool preauth, gfp_t gfp)
17050 struct wireless_dev *wdev = dev->ieee80211_ptr;
17051 struct wiphy *wiphy = wdev->wiphy;
17052 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17054 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
17055 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
17057 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
17059 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
17060 struct net_device *netdev,
17061 struct cfg80211_chan_def *chandef,
17063 enum nl80211_commands notif,
17066 struct sk_buff *msg;
17069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17073 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
17079 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
17080 goto nla_put_failure;
17082 if (nl80211_send_chandef(msg, chandef))
17083 goto nla_put_failure;
17085 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
17086 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
17087 goto nla_put_failure;
17089 genlmsg_end(msg, hdr);
17091 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17092 NL80211_MCGRP_MLME, gfp);
17099 void cfg80211_ch_switch_notify(struct net_device *dev,
17100 struct cfg80211_chan_def *chandef)
17102 struct wireless_dev *wdev = dev->ieee80211_ptr;
17103 struct wiphy *wiphy = wdev->wiphy;
17104 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17106 ASSERT_WDEV_LOCK(wdev);
17108 trace_cfg80211_ch_switch_notify(dev, chandef);
17110 wdev->chandef = *chandef;
17111 wdev->preset_chandef = *chandef;
17113 if (wdev->iftype == NL80211_IFTYPE_STATION &&
17114 !WARN_ON(!wdev->current_bss))
17115 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
17117 cfg80211_sched_dfs_chan_update(rdev);
17119 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
17120 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
17122 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
17124 void cfg80211_ch_switch_started_notify(struct net_device *dev,
17125 struct cfg80211_chan_def *chandef,
17128 struct wireless_dev *wdev = dev->ieee80211_ptr;
17129 struct wiphy *wiphy = wdev->wiphy;
17130 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17132 trace_cfg80211_ch_switch_started_notify(dev, chandef);
17134 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
17135 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
17137 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
17140 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
17141 const struct cfg80211_chan_def *chandef,
17142 enum nl80211_radar_event event,
17143 struct net_device *netdev, gfp_t gfp)
17145 struct sk_buff *msg;
17148 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17152 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
17158 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
17159 goto nla_put_failure;
17161 /* NOP and radar events don't need a netdev parameter */
17163 struct wireless_dev *wdev = netdev->ieee80211_ptr;
17165 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17166 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17168 goto nla_put_failure;
17171 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
17172 goto nla_put_failure;
17174 if (nl80211_send_chandef(msg, chandef))
17175 goto nla_put_failure;
17177 genlmsg_end(msg, hdr);
17179 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17180 NL80211_MCGRP_MLME, gfp);
17187 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
17188 struct sta_opmode_info *sta_opmode,
17191 struct sk_buff *msg;
17192 struct wireless_dev *wdev = dev->ieee80211_ptr;
17193 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17199 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17203 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
17209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
17210 goto nla_put_failure;
17212 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
17213 goto nla_put_failure;
17215 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
17216 goto nla_put_failure;
17218 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
17219 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
17220 goto nla_put_failure;
17222 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
17223 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
17224 goto nla_put_failure;
17226 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
17227 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
17228 goto nla_put_failure;
17230 genlmsg_end(msg, hdr);
17232 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17233 NL80211_MCGRP_MLME, gfp);
17240 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
17242 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
17243 u64 cookie, bool acked, s32 ack_signal,
17244 bool is_valid_ack_signal, gfp_t gfp)
17246 struct wireless_dev *wdev = dev->ieee80211_ptr;
17247 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17248 struct sk_buff *msg;
17251 trace_cfg80211_probe_status(dev, addr, cookie, acked);
17253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17258 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
17264 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17265 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17266 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
17267 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
17268 NL80211_ATTR_PAD) ||
17269 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
17270 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
17272 goto nla_put_failure;
17274 genlmsg_end(msg, hdr);
17276 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17277 NL80211_MCGRP_MLME, gfp);
17283 EXPORT_SYMBOL(cfg80211_probe_status);
17285 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
17286 size_t len, int freq, int sig_dbm)
17288 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17289 struct sk_buff *msg;
17291 struct cfg80211_beacon_registration *reg;
17293 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
17295 spin_lock_bh(&rdev->beacon_registrations_lock);
17296 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
17297 msg = nlmsg_new(len + 100, GFP_ATOMIC);
17299 spin_unlock_bh(&rdev->beacon_registrations_lock);
17303 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
17305 goto nla_put_failure;
17307 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17309 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
17310 KHZ_TO_MHZ(freq)) ||
17311 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
17314 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
17315 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
17316 goto nla_put_failure;
17318 genlmsg_end(msg, hdr);
17320 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
17322 spin_unlock_bh(&rdev->beacon_registrations_lock);
17326 spin_unlock_bh(&rdev->beacon_registrations_lock);
17329 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
17332 static int cfg80211_net_detect_results(struct sk_buff *msg,
17333 struct cfg80211_wowlan_wakeup *wakeup)
17335 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
17336 struct nlattr *nl_results, *nl_match, *nl_freqs;
17339 nl_results = nla_nest_start_noflag(msg,
17340 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
17344 for (i = 0; i < nd->n_matches; i++) {
17345 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
17347 nl_match = nla_nest_start_noflag(msg, i);
17351 /* The SSID attribute is optional in nl80211, but for
17352 * simplicity reasons it's always present in the
17353 * cfg80211 structure. If a driver can't pass the
17354 * SSID, that needs to be changed. A zero length SSID
17355 * is still a valid SSID (wildcard), so it cannot be
17356 * used for this purpose.
17358 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
17359 match->ssid.ssid)) {
17360 nla_nest_cancel(msg, nl_match);
17364 if (match->n_channels) {
17365 nl_freqs = nla_nest_start_noflag(msg,
17366 NL80211_ATTR_SCAN_FREQUENCIES);
17368 nla_nest_cancel(msg, nl_match);
17372 for (j = 0; j < match->n_channels; j++) {
17373 if (nla_put_u32(msg, j, match->channels[j])) {
17374 nla_nest_cancel(msg, nl_freqs);
17375 nla_nest_cancel(msg, nl_match);
17380 nla_nest_end(msg, nl_freqs);
17383 nla_nest_end(msg, nl_match);
17387 nla_nest_end(msg, nl_results);
17391 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
17392 struct cfg80211_wowlan_wakeup *wakeup,
17395 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17396 struct sk_buff *msg;
17400 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
17403 size += wakeup->packet_present_len;
17405 msg = nlmsg_new(size, gfp);
17409 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
17413 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17414 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17418 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
17419 wdev->netdev->ifindex))
17423 struct nlattr *reasons;
17425 reasons = nla_nest_start_noflag(msg,
17426 NL80211_ATTR_WOWLAN_TRIGGERS);
17430 if (wakeup->disconnect &&
17431 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
17433 if (wakeup->magic_pkt &&
17434 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
17436 if (wakeup->gtk_rekey_failure &&
17437 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
17439 if (wakeup->eap_identity_req &&
17440 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
17442 if (wakeup->four_way_handshake &&
17443 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
17445 if (wakeup->rfkill_release &&
17446 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
17449 if (wakeup->pattern_idx >= 0 &&
17450 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
17451 wakeup->pattern_idx))
17454 if (wakeup->tcp_match &&
17455 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
17458 if (wakeup->tcp_connlost &&
17459 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
17462 if (wakeup->tcp_nomoretokens &&
17464 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
17467 if (wakeup->packet) {
17468 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
17469 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
17471 if (!wakeup->packet_80211) {
17473 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
17475 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
17478 if (wakeup->packet_len &&
17479 nla_put_u32(msg, len_attr, wakeup->packet_len))
17482 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
17487 if (wakeup->net_detect &&
17488 cfg80211_net_detect_results(msg, wakeup))
17491 nla_nest_end(msg, reasons);
17494 genlmsg_end(msg, hdr);
17496 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17497 NL80211_MCGRP_MLME, gfp);
17503 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
17506 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
17507 enum nl80211_tdls_operation oper,
17508 u16 reason_code, gfp_t gfp)
17510 struct wireless_dev *wdev = dev->ieee80211_ptr;
17511 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17512 struct sk_buff *msg;
17515 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
17518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17522 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
17528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17530 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
17531 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
17532 (reason_code > 0 &&
17533 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
17534 goto nla_put_failure;
17536 genlmsg_end(msg, hdr);
17538 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17539 NL80211_MCGRP_MLME, gfp);
17545 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
17547 static int nl80211_netlink_notify(struct notifier_block * nb,
17548 unsigned long state,
17551 struct netlink_notify *notify = _notify;
17552 struct cfg80211_registered_device *rdev;
17553 struct wireless_dev *wdev;
17554 struct cfg80211_beacon_registration *reg, *tmp;
17556 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
17557 return NOTIFY_DONE;
17561 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
17562 struct cfg80211_sched_scan_request *sched_scan_req;
17564 list_for_each_entry_rcu(sched_scan_req,
17565 &rdev->sched_scan_req_list,
17567 if (sched_scan_req->owner_nlportid == notify->portid) {
17568 sched_scan_req->nl_owner_dead = true;
17569 schedule_work(&rdev->sched_scan_stop_wk);
17573 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
17574 cfg80211_mlme_unregister_socket(wdev, notify->portid);
17576 if (wdev->owner_nlportid == notify->portid) {
17577 wdev->nl_owner_dead = true;
17578 schedule_work(&rdev->destroy_work);
17579 } else if (wdev->conn_owner_nlportid == notify->portid) {
17580 schedule_work(&wdev->disconnect_wk);
17583 cfg80211_release_pmsr(wdev, notify->portid);
17586 spin_lock_bh(&rdev->beacon_registrations_lock);
17587 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
17589 if (reg->nlportid == notify->portid) {
17590 list_del(®->list);
17595 spin_unlock_bh(&rdev->beacon_registrations_lock);
17601 * It is possible that the user space process that is controlling the
17602 * indoor setting disappeared, so notify the regulatory core.
17604 regulatory_netlink_notify(notify->portid);
17608 static struct notifier_block nl80211_netlink_notifier = {
17609 .notifier_call = nl80211_netlink_notify,
17612 void cfg80211_ft_event(struct net_device *netdev,
17613 struct cfg80211_ft_event_params *ft_event)
17615 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
17616 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17617 struct sk_buff *msg;
17620 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
17622 if (!ft_event->target_ap)
17625 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
17630 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
17634 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17635 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17636 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
17639 if (ft_event->ies &&
17640 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
17642 if (ft_event->ric_ies &&
17643 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
17644 ft_event->ric_ies))
17647 genlmsg_end(msg, hdr);
17649 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17650 NL80211_MCGRP_MLME, GFP_KERNEL);
17655 EXPORT_SYMBOL(cfg80211_ft_event);
17657 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
17659 struct cfg80211_registered_device *rdev;
17660 struct sk_buff *msg;
17664 rdev = wiphy_to_rdev(wdev->wiphy);
17665 if (!rdev->crit_proto_nlportid)
17668 nlportid = rdev->crit_proto_nlportid;
17669 rdev->crit_proto_nlportid = 0;
17671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17675 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
17677 goto nla_put_failure;
17679 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17680 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17682 goto nla_put_failure;
17684 genlmsg_end(msg, hdr);
17686 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
17692 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
17694 void nl80211_send_ap_stopped(struct wireless_dev *wdev)
17696 struct wiphy *wiphy = wdev->wiphy;
17697 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17698 struct sk_buff *msg;
17701 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17705 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
17709 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17710 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
17711 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17715 genlmsg_end(msg, hdr);
17717 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
17718 NL80211_MCGRP_MLME, GFP_KERNEL);
17724 int cfg80211_external_auth_request(struct net_device *dev,
17725 struct cfg80211_external_auth_params *params,
17728 struct wireless_dev *wdev = dev->ieee80211_ptr;
17729 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17730 struct sk_buff *msg;
17733 if (!wdev->conn_owner_nlportid)
17736 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17740 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
17742 goto nla_put_failure;
17744 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17745 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17746 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
17747 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
17749 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
17750 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
17751 params->ssid.ssid))
17752 goto nla_put_failure;
17754 genlmsg_end(msg, hdr);
17755 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
17756 wdev->conn_owner_nlportid);
17763 EXPORT_SYMBOL(cfg80211_external_auth_request);
17765 void cfg80211_update_owe_info_event(struct net_device *netdev,
17766 struct cfg80211_update_owe_info *owe_info,
17769 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
17770 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17771 struct sk_buff *msg;
17774 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
17776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17780 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
17782 goto nla_put_failure;
17784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17785 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17786 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
17787 goto nla_put_failure;
17789 if (!owe_info->ie_len ||
17790 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
17791 goto nla_put_failure;
17793 genlmsg_end(msg, hdr);
17795 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17796 NL80211_MCGRP_MLME, gfp);
17800 genlmsg_cancel(msg, hdr);
17803 EXPORT_SYMBOL(cfg80211_update_owe_info_event);
17805 /* initialisation/exit functions */
17807 int __init nl80211_init(void)
17811 err = genl_register_family(&nl80211_fam);
17815 err = netlink_register_notifier(&nl80211_netlink_notifier);
17821 genl_unregister_family(&nl80211_fam);
17825 void nl80211_exit(void)
17827 netlink_unregister_notifier(&nl80211_netlink_notifier);
17828 genl_unregister_family(&nl80211_fam);