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 unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
218 if (ieee80211_hdrlen(mgmt->frame_control) !=
219 offsetof(struct ieee80211_mgmt, u.beacon))
225 for_each_element(elem, data, len) {
229 if (for_each_element_completed(elem, data, len))
233 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
237 static int validate_ie_attr(const struct nlattr *attr,
238 struct netlink_ext_ack *extack)
240 const u8 *data = nla_data(attr);
241 unsigned int len = nla_len(attr);
242 const struct element *elem;
244 for_each_element(elem, data, len) {
248 if (for_each_element_completed(elem, data, len))
251 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
255 /* policy for the attributes */
256 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR];
258 static const struct nla_policy
259 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = {
260 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, },
261 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY,
263 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY,
267 static const struct nla_policy
268 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
269 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG },
270 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 },
271 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] =
272 NLA_POLICY_MAX(NLA_U8, 15),
273 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 },
274 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] =
275 NLA_POLICY_MAX(NLA_U8, 15),
276 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] =
277 NLA_POLICY_MAX(NLA_U8, 31),
278 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 },
279 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG },
280 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG },
281 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG },
282 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG },
285 static const struct nla_policy
286 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
287 [NL80211_PMSR_TYPE_FTM] =
288 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
291 static const struct nla_policy
292 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
293 [NL80211_PMSR_REQ_ATTR_DATA] =
294 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
295 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
298 static const struct nla_policy
299 nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
300 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
301 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy),
302 [NL80211_PMSR_PEER_ATTR_REQ] =
303 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
304 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
307 static const struct nla_policy
308 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
309 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
310 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
311 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
312 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
313 [NL80211_PMSR_ATTR_PEERS] =
314 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy),
317 static const struct nla_policy
318 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = {
319 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] =
320 NLA_POLICY_RANGE(NLA_U8, 1, 20),
321 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] =
322 NLA_POLICY_RANGE(NLA_U8, 1, 20),
325 static const struct nla_policy
326 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = {
327 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63),
328 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG },
329 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG },
332 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
333 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
334 .len = NL80211_MAX_SUPP_RATES },
335 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
336 .len = NL80211_MAX_SUPP_HT_RATES },
337 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)),
338 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
341 static const struct nla_policy
342 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = {
343 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 },
344 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 },
345 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG },
346 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff),
347 [NL80211_TID_CONFIG_ATTR_NOACK] =
348 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
349 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
350 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
351 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] =
352 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
353 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] =
354 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
355 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] =
356 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
357 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] =
358 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED),
359 [NL80211_TID_CONFIG_ATTR_TX_RATE] =
360 NLA_POLICY_NESTED(nl80211_txattr_policy),
363 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
364 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
365 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
366 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
368 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
370 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
371 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
372 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
373 NL80211_EDMG_CHANNELS_MIN,
374 NL80211_EDMG_CHANNELS_MAX),
375 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
376 NL80211_EDMG_BW_CONFIG_MIN,
377 NL80211_EDMG_BW_CONFIG_MAX),
379 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
380 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
381 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
382 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
384 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
385 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
386 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
387 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
388 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
389 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
391 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
392 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
393 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
395 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
396 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
398 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
399 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
400 .len = WLAN_MAX_KEY_LEN },
401 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
402 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
403 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
404 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
405 [NL80211_ATTR_KEY_TYPE] =
406 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
408 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
409 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
410 [NL80211_ATTR_BEACON_HEAD] =
411 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
412 IEEE80211_MAX_DATA_LEN),
413 [NL80211_ATTR_BEACON_TAIL] =
414 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
415 IEEE80211_MAX_DATA_LEN),
416 [NL80211_ATTR_STA_AID] =
417 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
418 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
419 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
420 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
421 .len = NL80211_MAX_SUPP_RATES },
422 [NL80211_ATTR_STA_PLINK_ACTION] =
423 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
424 [NL80211_ATTR_STA_TX_POWER_SETTING] =
425 NLA_POLICY_RANGE(NLA_U8,
426 NL80211_TX_POWER_AUTOMATIC,
427 NL80211_TX_POWER_FIXED),
428 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
429 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
430 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
431 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
432 .len = IEEE80211_MAX_MESH_ID_LEN },
433 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
435 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
436 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
438 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
439 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
440 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
441 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
442 .len = NL80211_MAX_SUPP_RATES },
443 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
445 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
446 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
448 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN),
450 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
451 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
453 IEEE80211_MAX_DATA_LEN),
454 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
455 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
457 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
458 .len = IEEE80211_MAX_SSID_LEN },
459 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
460 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
461 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
462 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
463 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
465 NL80211_MFP_OPTIONAL),
466 [NL80211_ATTR_STA_FLAGS2] = {
467 .len = sizeof(struct nl80211_sta_flag_update),
469 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
470 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
471 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
472 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
473 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
474 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
475 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
476 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
477 [NL80211_ATTR_PID] = { .type = NLA_U32 },
478 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
479 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN),
480 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
481 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
482 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
483 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
484 .len = IEEE80211_MAX_DATA_LEN },
485 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
486 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
489 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
490 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
491 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
492 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
493 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
494 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
495 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
496 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
497 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
498 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
499 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
500 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
501 [NL80211_ATTR_STA_PLINK_STATE] =
502 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
503 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
504 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
505 [NL80211_ATTR_MESH_PEER_AID] =
506 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
507 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
508 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
509 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
510 [NL80211_ATTR_HIDDEN_SSID] =
511 NLA_POLICY_RANGE(NLA_U32,
512 NL80211_HIDDEN_SSID_NOT_IN_USE,
513 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
514 [NL80211_ATTR_IE_PROBE_RESP] =
515 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
516 IEEE80211_MAX_DATA_LEN),
517 [NL80211_ATTR_IE_ASSOC_RESP] =
518 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
519 IEEE80211_MAX_DATA_LEN),
520 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
521 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
522 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
523 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
524 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
525 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
526 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
527 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
528 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
529 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
530 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
531 .len = IEEE80211_MAX_DATA_LEN },
532 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
533 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
534 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
535 .len = NL80211_HT_CAPABILITY_LEN
537 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
538 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
539 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
540 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
541 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
542 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
543 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN),
544 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
545 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
546 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
547 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
548 NLA_POLICY_RANGE(NLA_U32,
549 NL80211_MESH_POWER_UNKNOWN + 1,
550 NL80211_MESH_POWER_MAX),
551 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
552 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
553 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
554 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
555 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
556 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
557 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
558 .len = NL80211_VHT_CAPABILITY_LEN,
560 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
561 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
562 .len = IEEE80211_MAX_DATA_LEN },
563 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
564 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = { .type = NLA_U16 },
565 [NL80211_ATTR_PEER_AID] =
566 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
567 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
568 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
569 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
570 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
571 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
572 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
573 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
574 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
575 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
576 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
577 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
578 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
579 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
580 .len = IEEE80211_QOS_MAP_LEN_MAX },
581 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
582 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
583 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
584 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
585 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
586 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
587 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
588 [NL80211_ATTR_USER_PRIO] =
589 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
590 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
591 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
592 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
593 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
594 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
595 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
596 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
597 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
598 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
599 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
600 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
601 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
602 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
603 .len = VHT_MUMIMO_GROUPS_DATA_LEN
605 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
606 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
607 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
608 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
609 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
610 .len = FILS_MAX_KEK_LEN },
611 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN),
612 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
613 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
614 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
615 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
616 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
618 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
619 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
620 .len = FILS_ERP_MAX_USERNAME_LEN },
621 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
622 .len = FILS_ERP_MAX_REALM_LEN },
623 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
624 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
625 .len = FILS_ERP_MAX_RRK_LEN },
626 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2),
627 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
628 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
629 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
631 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
632 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
633 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
634 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
635 .len = NL80211_HE_MAX_CAPABILITY_LEN },
637 [NL80211_ATTR_FTM_RESPONDER] =
638 NLA_POLICY_NESTED(nl80211_ftm_responder_policy),
639 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
640 [NL80211_ATTR_PEER_MEASUREMENTS] =
641 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
642 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
643 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
644 .len = SAE_PASSWORD_MAX_LEN },
645 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
646 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
647 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
648 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
649 [NL80211_ATTR_TID_CONFIG] =
650 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
651 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG },
652 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1),
653 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100),
654 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG },
655 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
656 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED },
657 [NL80211_ATTR_HE_6GHZ_CAPABILITY] = {
658 .type = NLA_EXACT_LEN,
659 .len = sizeof(struct ieee80211_he_6ghz_capa),
663 /* policy for the key attributes */
664 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
665 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
666 [NL80211_KEY_IDX] = { .type = NLA_U8 },
667 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
668 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
669 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
670 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
671 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
672 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
673 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
676 /* policy for the key default flags */
677 static const struct nla_policy
678 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
679 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
680 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
684 /* policy for WoWLAN attributes */
685 static const struct nla_policy
686 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
687 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
688 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
689 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
690 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
691 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
692 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
693 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
694 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
695 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
696 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
699 static const struct nla_policy
700 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
701 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
702 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
703 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
704 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
705 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
706 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
707 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
708 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
710 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
711 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
713 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
714 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
715 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 },
717 #endif /* CONFIG_PM */
719 /* policy for coalesce rule attributes */
720 static const struct nla_policy
721 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
722 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
723 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
724 NLA_POLICY_RANGE(NLA_U32,
725 NL80211_COALESCE_CONDITION_MATCH,
726 NL80211_COALESCE_CONDITION_NO_MATCH),
727 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
730 /* policy for GTK rekey offload attributes */
731 static const struct nla_policy
732 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
733 [NL80211_REKEY_DATA_KEK] = {
735 .len = NL80211_KEK_EXT_LEN
737 [NL80211_REKEY_DATA_KCK] = {
739 .len = NL80211_KCK_EXT_LEN
741 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN_WARN(NL80211_REPLAY_CTR_LEN),
742 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 },
745 static const struct nla_policy
746 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
747 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
748 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
749 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
750 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
753 static const struct nla_policy
754 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
755 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
756 .len = IEEE80211_MAX_SSID_LEN },
757 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
758 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
759 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
760 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
763 static const struct nla_policy
764 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
765 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
766 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
769 static const struct nla_policy
770 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
771 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
772 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
773 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
774 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
778 /* policy for NAN function attributes */
779 static const struct nla_policy
780 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
781 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
782 [NL80211_NAN_FUNC_SERVICE_ID] = {
783 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
784 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
785 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
786 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
787 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
788 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
789 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
790 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
791 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
792 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
793 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
794 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
795 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
796 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
797 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
798 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
801 /* policy for Service Response Filter attributes */
802 static const struct nla_policy
803 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
804 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
805 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
806 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
807 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
808 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
811 /* policy for packet pattern attributes */
812 static const struct nla_policy
813 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
814 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
815 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
816 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
819 int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
820 struct cfg80211_registered_device **rdev,
821 struct wireless_dev **wdev)
826 struct nlattr **attrbuf;
828 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
833 err = nlmsg_parse_deprecated(cb->nlh,
834 GENL_HDRLEN + nl80211_fam.hdrsize,
835 attrbuf, nl80211_fam.maxattr,
836 nl80211_policy, NULL);
842 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
846 return PTR_ERR(*wdev);
847 *rdev = wiphy_to_rdev((*wdev)->wiphy);
848 /* 0 is the first index - add 1 to parse only once */
849 cb->args[0] = (*rdev)->wiphy_idx + 1;
850 cb->args[1] = (*wdev)->identifier;
852 /* subtract the 1 again here */
853 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
854 struct wireless_dev *tmp;
858 *rdev = wiphy_to_rdev(wiphy);
861 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
862 if (tmp->identifier == cb->args[1]) {
875 /* message building helper */
876 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
879 /* since there is no private header just add the generic one */
880 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
883 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
884 const struct ieee80211_reg_rule *rule)
887 struct nlattr *nl_wmm_rules =
888 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
891 goto nla_put_failure;
893 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
894 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
897 goto nla_put_failure;
899 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
900 rule->wmm_rule.client[j].cw_min) ||
901 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
902 rule->wmm_rule.client[j].cw_max) ||
903 nla_put_u8(msg, NL80211_WMMR_AIFSN,
904 rule->wmm_rule.client[j].aifsn) ||
905 nla_put_u16(msg, NL80211_WMMR_TXOP,
906 rule->wmm_rule.client[j].cot))
907 goto nla_put_failure;
909 nla_nest_end(msg, nl_wmm_rule);
911 nla_nest_end(msg, nl_wmm_rules);
919 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
920 struct ieee80211_channel *chan,
923 /* Some channels must be completely excluded from the
924 * list to protect old user-space tools from breaking
926 if (!large && chan->flags &
927 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
930 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
932 goto nla_put_failure;
934 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
935 goto nla_put_failure;
937 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
938 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
939 goto nla_put_failure;
940 if (chan->flags & IEEE80211_CHAN_NO_IR) {
941 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
942 goto nla_put_failure;
943 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
944 goto nla_put_failure;
946 if (chan->flags & IEEE80211_CHAN_RADAR) {
947 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
948 goto nla_put_failure;
952 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
954 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
956 goto nla_put_failure;
957 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
959 goto nla_put_failure;
961 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
963 goto nla_put_failure;
968 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
969 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
970 goto nla_put_failure;
971 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
972 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
973 goto nla_put_failure;
974 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
975 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
976 goto nla_put_failure;
977 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
978 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
979 goto nla_put_failure;
980 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
981 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
982 goto nla_put_failure;
983 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
984 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
985 goto nla_put_failure;
986 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
987 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
988 goto nla_put_failure;
989 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
990 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
991 goto nla_put_failure;
992 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
993 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
994 goto nla_put_failure;
997 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
998 DBM_TO_MBM(chan->max_power)))
999 goto nla_put_failure;
1002 const struct ieee80211_reg_rule *rule =
1003 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
1005 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
1006 if (nl80211_msg_put_wmm_rules(msg, rule))
1007 goto nla_put_failure;
1017 static bool nl80211_put_txq_stats(struct sk_buff *msg,
1018 struct cfg80211_txq_stats *txqstats,
1021 struct nlattr *txqattr;
1023 #define PUT_TXQVAL_U32(attr, memb) do { \
1024 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1025 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1029 txqattr = nla_nest_start_noflag(msg, attrtype);
1033 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1034 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1035 PUT_TXQVAL_U32(FLOWS, flows);
1036 PUT_TXQVAL_U32(DROPS, drops);
1037 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1038 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1039 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1040 PUT_TXQVAL_U32(COLLISIONS, collisions);
1041 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1042 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1043 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1044 nla_nest_end(msg, txqattr);
1046 #undef PUT_TXQVAL_U32
1050 /* netlink command implementations */
1053 struct key_params p;
1056 bool def, defmgmt, defbeacon;
1057 bool def_uni, def_multi;
1060 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1061 struct key_parse *k)
1063 struct nlattr *tb[NL80211_KEY_MAX + 1];
1064 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1070 k->def = !!tb[NL80211_KEY_DEFAULT];
1071 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1072 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
1076 k->def_multi = true;
1078 if (k->defmgmt || k->defbeacon)
1079 k->def_multi = true;
1081 if (tb[NL80211_KEY_IDX])
1082 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1084 if (tb[NL80211_KEY_DATA]) {
1085 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1086 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1089 if (tb[NL80211_KEY_SEQ]) {
1090 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1091 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1094 if (tb[NL80211_KEY_CIPHER])
1095 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1097 if (tb[NL80211_KEY_TYPE])
1098 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
1100 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1101 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1103 err = nla_parse_nested_deprecated(kdt,
1104 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1105 tb[NL80211_KEY_DEFAULT_TYPES],
1106 nl80211_key_default_policy,
1111 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1112 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1115 if (tb[NL80211_KEY_MODE])
1116 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1121 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1123 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1124 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1125 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1128 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1129 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1130 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1133 if (info->attrs[NL80211_ATTR_KEY_IDX])
1134 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1136 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1137 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1139 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1140 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1144 k->def_multi = true;
1147 k->def_multi = true;
1149 if (info->attrs[NL80211_ATTR_KEY_TYPE])
1150 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1152 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1153 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
1154 int err = nla_parse_nested_deprecated(kdt,
1155 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1156 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1157 nl80211_key_default_policy,
1162 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1163 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1169 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1173 memset(k, 0, sizeof(*k));
1177 if (info->attrs[NL80211_ATTR_KEY])
1178 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
1180 err = nl80211_parse_key_old(info, k);
1185 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1186 (k->defbeacon ? 1 : 0) > 1) {
1187 GENL_SET_ERR_MSG(info,
1188 "key with multiple default flags is invalid");
1192 if (k->defmgmt || k->defbeacon) {
1193 if (k->def_uni || !k->def_multi) {
1194 GENL_SET_ERR_MSG(info,
1195 "defmgmt/defbeacon key must be mcast");
1202 if (k->idx < 4 || k->idx > 5) {
1203 GENL_SET_ERR_MSG(info,
1204 "defmgmt key idx not 4 or 5");
1207 } else if (k->defbeacon) {
1208 if (k->idx < 6 || k->idx > 7) {
1209 GENL_SET_ERR_MSG(info,
1210 "defbeacon key idx not 6 or 7");
1213 } else if (k->def) {
1214 if (k->idx < 0 || k->idx > 3) {
1215 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
1219 if (k->idx < 0 || k->idx > 7) {
1220 GENL_SET_ERR_MSG(info, "key idx not 0-7");
1229 static struct cfg80211_cached_keys *
1230 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
1231 struct genl_info *info, bool *no_ht)
1233 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
1234 struct key_parse parse;
1236 struct cfg80211_cached_keys *result;
1237 int rem, err, def = 0;
1238 bool have_key = false;
1240 nla_for_each_nested(key, keys, rem) {
1248 result = kzalloc(sizeof(*result), GFP_KERNEL);
1250 return ERR_PTR(-ENOMEM);
1254 nla_for_each_nested(key, keys, rem) {
1255 memset(&parse, 0, sizeof(parse));
1258 err = nl80211_parse_key_new(info, key, &parse);
1264 if (parse.idx < 0 || parse.idx > 3) {
1265 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
1270 GENL_SET_ERR_MSG(info,
1271 "only one key can be default");
1275 result->def = parse.idx;
1276 if (!parse.def_uni || !parse.def_multi)
1278 } else if (parse.defmgmt)
1280 err = cfg80211_validate_key_settings(rdev, &parse.p,
1281 parse.idx, false, NULL);
1284 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1285 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
1286 GENL_SET_ERR_MSG(info, "connect key must be WEP");
1290 result->params[parse.idx].cipher = parse.p.cipher;
1291 result->params[parse.idx].key_len = parse.p.key_len;
1292 result->params[parse.idx].key = result->data[parse.idx];
1293 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
1295 /* must be WEP key if we got here */
1300 if (result->def < 0) {
1302 GENL_SET_ERR_MSG(info, "need a default/TX key");
1309 return ERR_PTR(err);
1312 static int nl80211_key_allowed(struct wireless_dev *wdev)
1314 ASSERT_WDEV_LOCK(wdev);
1316 switch (wdev->iftype) {
1317 case NL80211_IFTYPE_AP:
1318 case NL80211_IFTYPE_AP_VLAN:
1319 case NL80211_IFTYPE_P2P_GO:
1320 case NL80211_IFTYPE_MESH_POINT:
1322 case NL80211_IFTYPE_ADHOC:
1323 case NL80211_IFTYPE_STATION:
1324 case NL80211_IFTYPE_P2P_CLIENT:
1325 if (!wdev->current_bss)
1328 case NL80211_IFTYPE_UNSPECIFIED:
1329 case NL80211_IFTYPE_OCB:
1330 case NL80211_IFTYPE_MONITOR:
1331 case NL80211_IFTYPE_NAN:
1332 case NL80211_IFTYPE_P2P_DEVICE:
1333 case NL80211_IFTYPE_WDS:
1334 case NUM_NL80211_IFTYPES:
1341 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1344 struct ieee80211_channel *chan;
1346 chan = ieee80211_get_channel_khz(wiphy, freq);
1347 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1352 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1354 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
1358 goto nla_put_failure;
1362 if ((ifmodes & 1) && nla_put_flag(msg, i))
1363 goto nla_put_failure;
1368 nla_nest_end(msg, nl_modes);
1375 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1376 struct sk_buff *msg,
1379 struct nlattr *nl_combis;
1382 nl_combis = nla_nest_start_noflag(msg,
1383 NL80211_ATTR_INTERFACE_COMBINATIONS);
1385 goto nla_put_failure;
1387 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1388 const struct ieee80211_iface_combination *c;
1389 struct nlattr *nl_combi, *nl_limits;
1391 c = &wiphy->iface_combinations[i];
1393 nl_combi = nla_nest_start_noflag(msg, i + 1);
1395 goto nla_put_failure;
1397 nl_limits = nla_nest_start_noflag(msg,
1398 NL80211_IFACE_COMB_LIMITS);
1400 goto nla_put_failure;
1402 for (j = 0; j < c->n_limits; j++) {
1403 struct nlattr *nl_limit;
1405 nl_limit = nla_nest_start_noflag(msg, j + 1);
1407 goto nla_put_failure;
1408 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1410 goto nla_put_failure;
1411 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1412 c->limits[j].types))
1413 goto nla_put_failure;
1414 nla_nest_end(msg, nl_limit);
1417 nla_nest_end(msg, nl_limits);
1419 if (c->beacon_int_infra_match &&
1420 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1421 goto nla_put_failure;
1422 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1423 c->num_different_channels) ||
1424 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1426 goto nla_put_failure;
1428 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1429 c->radar_detect_widths) ||
1430 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1431 c->radar_detect_regions)))
1432 goto nla_put_failure;
1433 if (c->beacon_int_min_gcd &&
1434 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1435 c->beacon_int_min_gcd))
1436 goto nla_put_failure;
1438 nla_nest_end(msg, nl_combi);
1441 nla_nest_end(msg, nl_combis);
1449 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1450 struct sk_buff *msg)
1452 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
1453 struct nlattr *nl_tcp;
1458 nl_tcp = nla_nest_start_noflag(msg,
1459 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1463 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1464 tcp->data_payload_max))
1467 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1468 tcp->data_payload_max))
1471 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1474 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1475 sizeof(*tcp->tok), tcp->tok))
1478 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1479 tcp->data_interval_max))
1482 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1483 tcp->wake_payload_max))
1486 nla_nest_end(msg, nl_tcp);
1490 static int nl80211_send_wowlan(struct sk_buff *msg,
1491 struct cfg80211_registered_device *rdev,
1494 struct nlattr *nl_wowlan;
1496 if (!rdev->wiphy.wowlan)
1499 nl_wowlan = nla_nest_start_noflag(msg,
1500 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1504 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
1505 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1506 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
1507 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1508 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1509 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1510 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1511 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1512 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1513 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1514 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1515 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1516 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1517 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1518 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1519 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1522 if (rdev->wiphy.wowlan->n_patterns) {
1523 struct nl80211_pattern_support pat = {
1524 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1525 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1526 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1527 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
1530 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1535 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1536 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1537 rdev->wiphy.wowlan->max_nd_match_sets))
1540 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
1543 nla_nest_end(msg, nl_wowlan);
1549 static int nl80211_send_coalesce(struct sk_buff *msg,
1550 struct cfg80211_registered_device *rdev)
1552 struct nl80211_coalesce_rule_support rule;
1554 if (!rdev->wiphy.coalesce)
1557 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1558 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1559 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1560 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1561 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1562 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
1564 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1571 nl80211_send_iftype_data(struct sk_buff *msg,
1572 const struct ieee80211_supported_band *sband,
1573 const struct ieee80211_sband_iftype_data *iftdata)
1575 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1577 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1578 iftdata->types_mask))
1581 if (he_cap->has_he) {
1582 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1583 sizeof(he_cap->he_cap_elem.mac_cap_info),
1584 he_cap->he_cap_elem.mac_cap_info) ||
1585 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1586 sizeof(he_cap->he_cap_elem.phy_cap_info),
1587 he_cap->he_cap_elem.phy_cap_info) ||
1588 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1589 sizeof(he_cap->he_mcs_nss_supp),
1590 &he_cap->he_mcs_nss_supp) ||
1591 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1592 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1596 if (sband->band == NL80211_BAND_6GHZ &&
1597 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA,
1598 sizeof(iftdata->he_6ghz_capa),
1599 &iftdata->he_6ghz_capa))
1605 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1606 struct ieee80211_supported_band *sband)
1608 struct nlattr *nl_rates, *nl_rate;
1609 struct ieee80211_rate *rate;
1613 if (sband->ht_cap.ht_supported &&
1614 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1615 sizeof(sband->ht_cap.mcs),
1616 &sband->ht_cap.mcs) ||
1617 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1618 sband->ht_cap.cap) ||
1619 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1620 sband->ht_cap.ampdu_factor) ||
1621 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1622 sband->ht_cap.ampdu_density)))
1626 if (sband->vht_cap.vht_supported &&
1627 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1628 sizeof(sband->vht_cap.vht_mcs),
1629 &sband->vht_cap.vht_mcs) ||
1630 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1631 sband->vht_cap.cap)))
1634 if (sband->n_iftype_data) {
1635 struct nlattr *nl_iftype_data =
1636 nla_nest_start_noflag(msg,
1637 NL80211_BAND_ATTR_IFTYPE_DATA);
1640 if (!nl_iftype_data)
1643 for (i = 0; i < sband->n_iftype_data; i++) {
1644 struct nlattr *iftdata;
1646 iftdata = nla_nest_start_noflag(msg, i + 1);
1650 err = nl80211_send_iftype_data(msg, sband,
1651 &sband->iftype_data[i]);
1655 nla_nest_end(msg, iftdata);
1658 nla_nest_end(msg, nl_iftype_data);
1662 if (sband->edmg_cap.channels &&
1663 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1664 sband->edmg_cap.channels) ||
1665 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1666 sband->edmg_cap.bw_config)))
1671 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
1675 for (i = 0; i < sband->n_bitrates; i++) {
1676 nl_rate = nla_nest_start_noflag(msg, i);
1680 rate = &sband->bitrates[i];
1681 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1684 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1686 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1689 nla_nest_end(msg, nl_rate);
1692 nla_nest_end(msg, nl_rates);
1698 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1699 const struct ieee80211_txrx_stypes *mgmt_stypes)
1702 struct nlattr *nl_ftypes, *nl_ifs;
1703 enum nl80211_iftype ift;
1709 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
1713 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1714 nl_ftypes = nla_nest_start_noflag(msg, ift);
1718 stypes = mgmt_stypes[ift].tx;
1721 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1722 (i << 4) | IEEE80211_FTYPE_MGMT))
1727 nla_nest_end(msg, nl_ftypes);
1730 nla_nest_end(msg, nl_ifs);
1732 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
1736 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1737 nl_ftypes = nla_nest_start_noflag(msg, ift);
1741 stypes = mgmt_stypes[ift].rx;
1744 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1745 (i << 4) | IEEE80211_FTYPE_MGMT))
1750 nla_nest_end(msg, nl_ftypes);
1752 nla_nest_end(msg, nl_ifs);
1757 #define CMD(op, n) \
1759 if (rdev->ops->op) { \
1761 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1762 goto nla_put_failure; \
1766 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1767 struct sk_buff *msg)
1772 * do *NOT* add anything into this function, new things need to be
1773 * advertised only to new versions of userspace that can deal with
1774 * the split (and they can't possibly care about new features...
1776 CMD(add_virtual_intf, NEW_INTERFACE);
1777 CMD(change_virtual_intf, SET_INTERFACE);
1778 CMD(add_key, NEW_KEY);
1779 CMD(start_ap, START_AP);
1780 CMD(add_station, NEW_STATION);
1781 CMD(add_mpath, NEW_MPATH);
1782 CMD(update_mesh_config, SET_MESH_CONFIG);
1783 CMD(change_bss, SET_BSS);
1784 CMD(auth, AUTHENTICATE);
1785 CMD(assoc, ASSOCIATE);
1786 CMD(deauth, DEAUTHENTICATE);
1787 CMD(disassoc, DISASSOCIATE);
1788 CMD(join_ibss, JOIN_IBSS);
1789 CMD(join_mesh, JOIN_MESH);
1790 CMD(set_pmksa, SET_PMKSA);
1791 CMD(del_pmksa, DEL_PMKSA);
1792 CMD(flush_pmksa, FLUSH_PMKSA);
1793 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1794 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1795 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1796 CMD(mgmt_tx, FRAME);
1797 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1798 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1800 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1801 goto nla_put_failure;
1803 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1804 rdev->ops->join_mesh) {
1806 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1807 goto nla_put_failure;
1809 CMD(set_wds_peer, SET_WDS_PEER);
1810 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1811 CMD(tdls_mgmt, TDLS_MGMT);
1812 CMD(tdls_oper, TDLS_OPER);
1814 if (rdev->wiphy.max_sched_scan_reqs)
1815 CMD(sched_scan_start, START_SCHED_SCAN);
1816 CMD(probe_client, PROBE_CLIENT);
1817 CMD(set_noack_map, SET_NOACK_MAP);
1818 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1820 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1821 goto nla_put_failure;
1823 CMD(start_p2p_device, START_P2P_DEVICE);
1824 CMD(set_mcast_rate, SET_MCAST_RATE);
1825 #ifdef CONFIG_NL80211_TESTMODE
1826 CMD(testmode_cmd, TESTMODE);
1829 if (rdev->ops->connect || rdev->ops->auth) {
1831 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1832 goto nla_put_failure;
1835 if (rdev->ops->disconnect || rdev->ops->deauth) {
1837 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1838 goto nla_put_failure;
1847 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1848 struct sk_buff *msg)
1852 if (!cap->ftm.supported)
1855 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
1859 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1861 if (cap->ftm.non_asap &&
1862 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1864 if (cap->ftm.request_lci &&
1865 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1867 if (cap->ftm.request_civicloc &&
1868 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1870 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1871 cap->ftm.preambles))
1873 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1874 cap->ftm.bandwidths))
1876 if (cap->ftm.max_bursts_exponent >= 0 &&
1877 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1878 cap->ftm.max_bursts_exponent))
1880 if (cap->ftm.max_ftms_per_burst &&
1881 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1882 cap->ftm.max_ftms_per_burst))
1884 if (cap->ftm.trigger_based &&
1885 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED))
1887 if (cap->ftm.non_trigger_based &&
1888 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED))
1891 nla_nest_end(msg, ftm);
1895 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1896 struct sk_buff *msg)
1898 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1899 struct nlattr *pmsr, *caps;
1905 * we don't need to clean up anything here since the caller
1906 * will genlmsg_cancel() if we fail
1909 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
1913 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1916 if (cap->report_ap_tsf &&
1917 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1920 if (cap->randomize_mac_addr &&
1921 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1924 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
1928 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1931 nla_nest_end(msg, caps);
1932 nla_nest_end(msg, pmsr);
1938 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev,
1939 struct sk_buff *msg)
1942 struct nlattr *nested, *nested_akms;
1943 const struct wiphy_iftype_akm_suites *iftype_akms;
1945 if (!rdev->wiphy.num_iftype_akm_suites ||
1946 !rdev->wiphy.iftype_akm_suites)
1949 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES);
1953 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) {
1954 nested_akms = nla_nest_start(msg, i + 1);
1958 iftype_akms = &rdev->wiphy.iftype_akm_suites[i];
1960 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES,
1961 iftype_akms->iftypes_mask))
1964 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES,
1965 sizeof(u32) * iftype_akms->n_akm_suites,
1966 iftype_akms->akm_suites)) {
1969 nla_nest_end(msg, nested_akms);
1972 nla_nest_end(msg, nested);
1978 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev,
1979 struct sk_buff *msg)
1981 struct nlattr *supp;
1983 if (!rdev->wiphy.tid_config_support.vif &&
1984 !rdev->wiphy.tid_config_support.peer)
1987 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG);
1991 if (rdev->wiphy.tid_config_support.vif &&
1992 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP,
1993 rdev->wiphy.tid_config_support.vif,
1994 NL80211_TID_CONFIG_ATTR_PAD))
1997 if (rdev->wiphy.tid_config_support.peer &&
1998 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP,
1999 rdev->wiphy.tid_config_support.peer,
2000 NL80211_TID_CONFIG_ATTR_PAD))
2003 /* for now we just use the same value ... makes more sense */
2004 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT,
2005 rdev->wiphy.tid_config_support.max_retry))
2007 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG,
2008 rdev->wiphy.tid_config_support.max_retry))
2011 nla_nest_end(msg, supp);
2015 nla_nest_cancel(msg, supp);
2019 struct nl80211_dump_wiphy_state {
2022 long split_start, band_start, chan_start, capa_start;
2026 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2027 enum nl80211_commands cmd,
2028 struct sk_buff *msg, u32 portid, u32 seq,
2029 int flags, struct nl80211_dump_wiphy_state *state)
2032 struct nlattr *nl_bands, *nl_band;
2033 struct nlattr *nl_freqs, *nl_freq;
2034 struct nlattr *nl_cmds;
2035 enum nl80211_band band;
2036 struct ieee80211_channel *chan;
2038 const struct ieee80211_txrx_stypes *mgmt_stypes =
2039 rdev->wiphy.mgmt_stypes;
2042 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
2046 if (WARN_ON(!state))
2049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2050 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
2051 wiphy_name(&rdev->wiphy)) ||
2052 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2053 cfg80211_rdev_list_generation))
2054 goto nla_put_failure;
2056 if (cmd != NL80211_CMD_NEW_WIPHY)
2059 switch (state->split_start) {
2061 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
2062 rdev->wiphy.retry_short) ||
2063 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
2064 rdev->wiphy.retry_long) ||
2065 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
2066 rdev->wiphy.frag_threshold) ||
2067 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
2068 rdev->wiphy.rts_threshold) ||
2069 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
2070 rdev->wiphy.coverage_class) ||
2071 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
2072 rdev->wiphy.max_scan_ssids) ||
2073 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
2074 rdev->wiphy.max_sched_scan_ssids) ||
2075 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
2076 rdev->wiphy.max_scan_ie_len) ||
2077 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
2078 rdev->wiphy.max_sched_scan_ie_len) ||
2079 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
2080 rdev->wiphy.max_match_sets) ||
2081 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
2082 rdev->wiphy.max_sched_scan_plans) ||
2083 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
2084 rdev->wiphy.max_sched_scan_plan_interval) ||
2085 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
2086 rdev->wiphy.max_sched_scan_plan_iterations))
2087 goto nla_put_failure;
2089 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
2090 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2091 goto nla_put_failure;
2092 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
2093 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2094 goto nla_put_failure;
2095 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2096 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2097 goto nla_put_failure;
2098 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
2099 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2100 goto nla_put_failure;
2101 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2102 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2103 goto nla_put_failure;
2104 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
2105 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
2106 goto nla_put_failure;
2107 state->split_start++;
2112 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
2113 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2114 rdev->wiphy.cipher_suites))
2115 goto nla_put_failure;
2117 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
2118 rdev->wiphy.max_num_pmkids))
2119 goto nla_put_failure;
2121 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
2122 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2123 goto nla_put_failure;
2125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
2126 rdev->wiphy.available_antennas_tx) ||
2127 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
2128 rdev->wiphy.available_antennas_rx))
2129 goto nla_put_failure;
2131 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
2132 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
2133 rdev->wiphy.probe_resp_offload))
2134 goto nla_put_failure;
2136 if ((rdev->wiphy.available_antennas_tx ||
2137 rdev->wiphy.available_antennas_rx) &&
2138 rdev->ops->get_antenna) {
2139 u32 tx_ant = 0, rx_ant = 0;
2142 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
2144 if (nla_put_u32(msg,
2145 NL80211_ATTR_WIPHY_ANTENNA_TX,
2148 NL80211_ATTR_WIPHY_ANTENNA_RX,
2150 goto nla_put_failure;
2154 state->split_start++;
2159 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
2160 rdev->wiphy.interface_modes))
2161 goto nla_put_failure;
2162 state->split_start++;
2167 nl_bands = nla_nest_start_noflag(msg,
2168 NL80211_ATTR_WIPHY_BANDS);
2170 goto nla_put_failure;
2172 for (band = state->band_start;
2173 band < NUM_NL80211_BANDS; band++) {
2174 struct ieee80211_supported_band *sband;
2176 sband = rdev->wiphy.bands[band];
2181 nl_band = nla_nest_start_noflag(msg, band);
2183 goto nla_put_failure;
2185 switch (state->chan_start) {
2187 if (nl80211_send_band_rateinfo(msg, sband))
2188 goto nla_put_failure;
2189 state->chan_start++;
2194 /* add frequencies */
2195 nl_freqs = nla_nest_start_noflag(msg,
2196 NL80211_BAND_ATTR_FREQS);
2198 goto nla_put_failure;
2200 for (i = state->chan_start - 1;
2201 i < sband->n_channels;
2203 nl_freq = nla_nest_start_noflag(msg,
2206 goto nla_put_failure;
2208 chan = &sband->channels[i];
2210 if (nl80211_msg_put_channel(
2211 msg, &rdev->wiphy, chan,
2213 goto nla_put_failure;
2215 nla_nest_end(msg, nl_freq);
2219 if (i < sband->n_channels)
2220 state->chan_start = i + 2;
2222 state->chan_start = 0;
2223 nla_nest_end(msg, nl_freqs);
2226 nla_nest_end(msg, nl_band);
2229 /* start again here */
2230 if (state->chan_start)
2235 nla_nest_end(msg, nl_bands);
2237 if (band < NUM_NL80211_BANDS)
2238 state->band_start = band + 1;
2240 state->band_start = 0;
2242 /* if bands & channels are done, continue outside */
2243 if (state->band_start == 0 && state->chan_start == 0)
2244 state->split_start++;
2249 nl_cmds = nla_nest_start_noflag(msg,
2250 NL80211_ATTR_SUPPORTED_COMMANDS);
2252 goto nla_put_failure;
2254 i = nl80211_add_commands_unsplit(rdev, msg);
2256 goto nla_put_failure;
2258 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2259 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
2260 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
2261 CMD(channel_switch, CHANNEL_SWITCH);
2262 CMD(set_qos_map, SET_QOS_MAP);
2263 if (rdev->wiphy.features &
2264 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
2265 CMD(add_tx_ts, ADD_TX_TS);
2266 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
2267 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
2268 CMD(update_ft_ies, UPDATE_FT_IES);
2272 nla_nest_end(msg, nl_cmds);
2273 state->split_start++;
2278 if (rdev->ops->remain_on_channel &&
2279 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
2281 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
2282 rdev->wiphy.max_remain_on_channel_duration))
2283 goto nla_put_failure;
2285 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
2286 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2287 goto nla_put_failure;
2289 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2290 goto nla_put_failure;
2291 state->split_start++;
2297 if (nl80211_send_wowlan(msg, rdev, state->split))
2298 goto nla_put_failure;
2299 state->split_start++;
2303 state->split_start++;
2307 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
2308 rdev->wiphy.software_iftypes))
2309 goto nla_put_failure;
2311 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
2313 goto nla_put_failure;
2315 state->split_start++;
2320 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
2321 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
2322 rdev->wiphy.ap_sme_capa))
2323 goto nla_put_failure;
2325 features = rdev->wiphy.features;
2327 * We can only add the per-channel limit information if the
2328 * dump is split, otherwise it makes it too big. Therefore
2329 * only advertise it in that case.
2332 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2333 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
2334 goto nla_put_failure;
2336 if (rdev->wiphy.ht_capa_mod_mask &&
2337 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
2338 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2339 rdev->wiphy.ht_capa_mod_mask))
2340 goto nla_put_failure;
2342 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2343 rdev->wiphy.max_acl_mac_addrs &&
2344 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
2345 rdev->wiphy.max_acl_mac_addrs))
2346 goto nla_put_failure;
2349 * Any information below this point is only available to
2350 * applications that can deal with it being split. This
2351 * helps ensure that newly added capabilities don't break
2352 * older tools by overrunning their buffers.
2354 * We still increment split_start so that in the split
2355 * case we'll continue with more data in the next round,
2356 * but break unconditionally so unsplit data stops here.
2358 state->split_start++;
2361 if (rdev->wiphy.extended_capabilities &&
2362 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
2363 rdev->wiphy.extended_capabilities_len,
2364 rdev->wiphy.extended_capabilities) ||
2365 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2366 rdev->wiphy.extended_capabilities_len,
2367 rdev->wiphy.extended_capabilities_mask)))
2368 goto nla_put_failure;
2370 if (rdev->wiphy.vht_capa_mod_mask &&
2371 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
2372 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2373 rdev->wiphy.vht_capa_mod_mask))
2374 goto nla_put_failure;
2376 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2377 rdev->wiphy.perm_addr))
2378 goto nla_put_failure;
2380 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2381 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2382 rdev->wiphy.addr_mask))
2383 goto nla_put_failure;
2385 if (rdev->wiphy.n_addresses > 1) {
2388 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2390 goto nla_put_failure;
2392 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2393 if (nla_put(msg, i + 1, ETH_ALEN,
2394 rdev->wiphy.addresses[i].addr))
2395 goto nla_put_failure;
2397 nla_nest_end(msg, attr);
2400 state->split_start++;
2403 if (nl80211_send_coalesce(msg, rdev))
2404 goto nla_put_failure;
2406 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
2407 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2408 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2409 goto nla_put_failure;
2411 if (rdev->wiphy.max_ap_assoc_sta &&
2412 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
2413 rdev->wiphy.max_ap_assoc_sta))
2414 goto nla_put_failure;
2416 state->split_start++;
2419 if (rdev->wiphy.n_vendor_commands) {
2420 const struct nl80211_vendor_cmd_info *info;
2421 struct nlattr *nested;
2423 nested = nla_nest_start_noflag(msg,
2424 NL80211_ATTR_VENDOR_DATA);
2426 goto nla_put_failure;
2428 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2429 info = &rdev->wiphy.vendor_commands[i].info;
2430 if (nla_put(msg, i + 1, sizeof(*info), info))
2431 goto nla_put_failure;
2433 nla_nest_end(msg, nested);
2436 if (rdev->wiphy.n_vendor_events) {
2437 const struct nl80211_vendor_cmd_info *info;
2438 struct nlattr *nested;
2440 nested = nla_nest_start_noflag(msg,
2441 NL80211_ATTR_VENDOR_EVENTS);
2443 goto nla_put_failure;
2445 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2446 info = &rdev->wiphy.vendor_events[i];
2447 if (nla_put(msg, i + 1, sizeof(*info), info))
2448 goto nla_put_failure;
2450 nla_nest_end(msg, nested);
2452 state->split_start++;
2455 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2456 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2457 rdev->wiphy.max_num_csa_counters))
2458 goto nla_put_failure;
2460 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2461 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2462 goto nla_put_failure;
2464 if (rdev->wiphy.max_sched_scan_reqs &&
2465 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2466 rdev->wiphy.max_sched_scan_reqs))
2467 goto nla_put_failure;
2469 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2470 sizeof(rdev->wiphy.ext_features),
2471 rdev->wiphy.ext_features))
2472 goto nla_put_failure;
2474 if (rdev->wiphy.bss_select_support) {
2475 struct nlattr *nested;
2476 u32 bss_select_support = rdev->wiphy.bss_select_support;
2478 nested = nla_nest_start_noflag(msg,
2479 NL80211_ATTR_BSS_SELECT);
2481 goto nla_put_failure;
2484 while (bss_select_support) {
2485 if ((bss_select_support & 1) &&
2486 nla_put_flag(msg, i))
2487 goto nla_put_failure;
2489 bss_select_support >>= 1;
2491 nla_nest_end(msg, nested);
2494 state->split_start++;
2497 if (rdev->wiphy.num_iftype_ext_capab &&
2498 rdev->wiphy.iftype_ext_capab) {
2499 struct nlattr *nested_ext_capab, *nested;
2501 nested = nla_nest_start_noflag(msg,
2502 NL80211_ATTR_IFTYPE_EXT_CAPA);
2504 goto nla_put_failure;
2506 for (i = state->capa_start;
2507 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2508 const struct wiphy_iftype_ext_capab *capab;
2510 capab = &rdev->wiphy.iftype_ext_capab[i];
2512 nested_ext_capab = nla_nest_start_noflag(msg,
2514 if (!nested_ext_capab ||
2515 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2517 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2518 capab->extended_capabilities_len,
2519 capab->extended_capabilities) ||
2520 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2521 capab->extended_capabilities_len,
2522 capab->extended_capabilities_mask))
2523 goto nla_put_failure;
2525 nla_nest_end(msg, nested_ext_capab);
2529 nla_nest_end(msg, nested);
2530 if (i < rdev->wiphy.num_iftype_ext_capab) {
2531 state->capa_start = i + 1;
2536 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2537 rdev->wiphy.nan_supported_bands))
2538 goto nla_put_failure;
2540 if (wiphy_ext_feature_isset(&rdev->wiphy,
2541 NL80211_EXT_FEATURE_TXQS)) {
2542 struct cfg80211_txq_stats txqstats = {};
2545 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2547 !nl80211_put_txq_stats(msg, &txqstats,
2548 NL80211_ATTR_TXQ_STATS))
2549 goto nla_put_failure;
2551 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2552 rdev->wiphy.txq_limit))
2553 goto nla_put_failure;
2554 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2555 rdev->wiphy.txq_memory_limit))
2556 goto nla_put_failure;
2557 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2558 rdev->wiphy.txq_quantum))
2559 goto nla_put_failure;
2562 state->split_start++;
2565 if (nl80211_send_pmsr_capa(rdev, msg))
2566 goto nla_put_failure;
2568 state->split_start++;
2571 if (rdev->wiphy.akm_suites &&
2572 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2573 sizeof(u32) * rdev->wiphy.n_akm_suites,
2574 rdev->wiphy.akm_suites))
2575 goto nla_put_failure;
2577 if (nl80211_put_iftype_akm_suites(rdev, msg))
2578 goto nla_put_failure;
2580 if (nl80211_put_tid_config_support(rdev, msg))
2581 goto nla_put_failure;
2584 state->split_start = 0;
2588 genlmsg_end(msg, hdr);
2592 genlmsg_cancel(msg, hdr);
2596 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2597 struct netlink_callback *cb,
2598 struct nl80211_dump_wiphy_state *state)
2600 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2606 ret = nlmsg_parse_deprecated(cb->nlh,
2607 GENL_HDRLEN + nl80211_fam.hdrsize,
2608 tb, nl80211_fam.maxattr,
2609 nl80211_policy, NULL);
2610 /* ignore parse errors for backward compatibility */
2616 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2617 if (tb[NL80211_ATTR_WIPHY])
2618 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2619 if (tb[NL80211_ATTR_WDEV])
2620 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2621 if (tb[NL80211_ATTR_IFINDEX]) {
2622 struct net_device *netdev;
2623 struct cfg80211_registered_device *rdev;
2624 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2626 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
2631 if (netdev->ieee80211_ptr) {
2632 rdev = wiphy_to_rdev(
2633 netdev->ieee80211_ptr->wiphy);
2634 state->filter_wiphy = rdev->wiphy_idx;
2644 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2647 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
2648 struct cfg80211_registered_device *rdev;
2652 state = kzalloc(sizeof(*state), GFP_KERNEL);
2657 state->filter_wiphy = -1;
2658 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2664 cb->args[0] = (long)state;
2667 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2668 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
2670 if (++idx <= state->start)
2672 if (state->filter_wiphy != -1 &&
2673 state->filter_wiphy != rdev->wiphy_idx)
2675 /* attempt to fit multiple wiphy data chunks into the skb */
2677 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2679 NETLINK_CB(cb->skb).portid,
2681 NLM_F_MULTI, state);
2684 * If sending the wiphy data didn't fit (ENOBUFS
2685 * or EMSGSIZE returned), this SKB is still
2686 * empty (so it's not too big because another
2687 * wiphy dataset is already in the skb) and
2688 * we've not tried to adjust the dump allocation
2689 * yet ... then adjust the alloc size to be
2690 * bigger, and return 1 but with the empty skb.
2691 * This results in an empty message being RX'ed
2692 * in userspace, but that is ignored.
2694 * We can then retry with the larger buffer.
2696 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
2697 !skb->len && !state->split &&
2698 cb->min_dump_alloc < 4096) {
2699 cb->min_dump_alloc = 4096;
2700 state->split_start = 0;
2707 } while (state->split_start > 0);
2717 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2719 kfree((void *)cb->args[0]);
2723 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2725 struct sk_buff *msg;
2726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2727 struct nl80211_dump_wiphy_state state = {};
2729 msg = nlmsg_new(4096, GFP_KERNEL);
2733 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2734 info->snd_portid, info->snd_seq, 0,
2740 return genlmsg_reply(msg, info);
2743 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2744 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2745 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2746 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2747 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2748 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2751 static int parse_txq_params(struct nlattr *tb[],
2752 struct ieee80211_txq_params *txq_params)
2756 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
2757 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2758 !tb[NL80211_TXQ_ATTR_AIFS])
2761 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
2762 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2763 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2764 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2765 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2767 if (ac >= NL80211_NUM_ACS)
2769 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
2773 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2776 * You can only set the channel explicitly for WDS interfaces,
2777 * all others have their channel managed via their respective
2778 * "establish a connection" command (connect, join, ...)
2780 * For AP/GO and mesh mode, the channel can be set with the
2781 * channel userspace API, but is only stored and passed to the
2782 * low-level driver when the AP starts or the mesh is joined.
2783 * This is for backward compatibility, userspace can also give
2784 * the channel in the start-ap or join-mesh commands instead.
2786 * Monitors are special as they are normally slaved to
2787 * whatever else is going on, so they have their own special
2788 * operation to set the monitor channel if possible.
2791 wdev->iftype == NL80211_IFTYPE_AP ||
2792 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
2793 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2794 wdev->iftype == NL80211_IFTYPE_P2P_GO;
2797 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2798 struct genl_info *info,
2799 struct cfg80211_chan_def *chandef)
2801 struct netlink_ext_ack *extack = info->extack;
2802 struct nlattr **attrs = info->attrs;
2805 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
2808 control_freq = MHZ_TO_KHZ(
2809 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2810 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
2812 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
2814 memset(chandef, 0, sizeof(*chandef));
2815 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq);
2816 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2817 chandef->center_freq1 = KHZ_TO_MHZ(control_freq);
2818 chandef->freq1_offset = control_freq % 1000;
2819 chandef->center_freq2 = 0;
2821 /* Primary channel not allowed */
2822 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2823 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2824 "Channel is disabled");
2828 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2829 enum nl80211_channel_type chantype;
2831 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2834 case NL80211_CHAN_NO_HT:
2835 case NL80211_CHAN_HT20:
2836 case NL80211_CHAN_HT40PLUS:
2837 case NL80211_CHAN_HT40MINUS:
2838 cfg80211_chandef_create(chandef, chandef->chan,
2840 /* user input for center_freq is incorrect */
2841 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2842 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2843 NL_SET_ERR_MSG_ATTR(extack,
2844 attrs[NL80211_ATTR_CENTER_FREQ1],
2845 "bad center frequency 1");
2848 /* center_freq2 must be zero */
2849 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2850 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2851 NL_SET_ERR_MSG_ATTR(extack,
2852 attrs[NL80211_ATTR_CENTER_FREQ2],
2853 "center frequency 2 can't be used");
2858 NL_SET_ERR_MSG_ATTR(extack,
2859 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2860 "invalid channel type");
2863 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2865 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2866 if (attrs[NL80211_ATTR_CENTER_FREQ1]) {
2867 chandef->center_freq1 =
2868 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2869 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET])
2870 chandef->freq1_offset = nla_get_u32(
2871 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]);
2873 chandef->freq1_offset = 0;
2875 if (attrs[NL80211_ATTR_CENTER_FREQ2])
2876 chandef->center_freq2 =
2877 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
2880 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
2881 chandef->edmg.channels =
2882 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
2884 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
2885 chandef->edmg.bw_config =
2886 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
2888 chandef->edmg.bw_config = 0;
2889 chandef->edmg.channels = 0;
2892 if (!cfg80211_chandef_valid(chandef)) {
2893 NL_SET_ERR_MSG(extack, "invalid channel definition");
2897 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2898 IEEE80211_CHAN_DISABLED)) {
2899 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
2903 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2904 chandef->width == NL80211_CHAN_WIDTH_10) &&
2905 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2906 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
2913 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
2914 struct net_device *dev,
2915 struct genl_info *info)
2917 struct cfg80211_chan_def chandef;
2919 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
2920 struct wireless_dev *wdev = NULL;
2923 wdev = dev->ieee80211_ptr;
2924 if (!nl80211_can_set_dev_channel(wdev))
2927 iftype = wdev->iftype;
2929 result = nl80211_parse_chandef(rdev, info, &chandef);
2934 case NL80211_IFTYPE_AP:
2935 case NL80211_IFTYPE_P2P_GO:
2936 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2941 if (wdev->beacon_interval) {
2942 if (!dev || !rdev->ops->set_ap_chanwidth ||
2943 !(rdev->wiphy.features &
2944 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2949 /* Only allow dynamic channel width changes */
2950 if (chandef.chan != wdev->preset_chandef.chan) {
2954 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2958 wdev->preset_chandef = chandef;
2961 case NL80211_IFTYPE_MESH_POINT:
2962 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
2964 case NL80211_IFTYPE_MONITOR:
2965 result = cfg80211_set_monitor_channel(rdev, &chandef);
2974 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2977 struct net_device *netdev = info->user_ptr[1];
2979 return __nl80211_set_channel(rdev, netdev, info);
2982 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2984 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2985 struct net_device *dev = info->user_ptr[1];
2986 struct wireless_dev *wdev = dev->ieee80211_ptr;
2989 if (!info->attrs[NL80211_ATTR_MAC])
2992 if (netif_running(dev))
2995 if (!rdev->ops->set_wds_peer)
2998 if (wdev->iftype != NL80211_IFTYPE_WDS)
3001 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3002 return rdev_set_wds_peer(rdev, dev, bssid);
3005 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
3007 struct cfg80211_registered_device *rdev;
3008 struct net_device *netdev = NULL;
3009 struct wireless_dev *wdev;
3010 int result = 0, rem_txq_params = 0;
3011 struct nlattr *nl_txq_params;
3013 u8 retry_short = 0, retry_long = 0;
3014 u32 frag_threshold = 0, rts_threshold = 0;
3015 u8 coverage_class = 0;
3016 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
3021 * Try to find the wiphy and netdev. Normally this
3022 * function shouldn't need the netdev, but this is
3023 * done for backward compatibility -- previously
3024 * setting the channel was done per wiphy, but now
3025 * it is per netdev. Previous userland like hostapd
3026 * also passed a netdev to set_wiphy, so that it is
3027 * possible to let that go to the right netdev!
3030 if (info->attrs[NL80211_ATTR_IFINDEX]) {
3031 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
3033 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
3034 if (netdev && netdev->ieee80211_ptr)
3035 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
3041 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3044 return PTR_ERR(rdev);
3049 wdev = netdev->ieee80211_ptr;
3052 * end workaround code, by now the rdev is available
3053 * and locked, and wdev may or may not be NULL.
3056 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
3057 result = cfg80211_dev_rename(
3058 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
3063 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
3064 struct ieee80211_txq_params txq_params;
3065 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
3067 if (!rdev->ops->set_txq_params)
3073 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3074 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3077 if (!netif_running(netdev))
3080 nla_for_each_nested(nl_txq_params,
3081 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3083 result = nla_parse_nested_deprecated(tb,
3084 NL80211_TXQ_ATTR_MAX,
3090 result = parse_txq_params(tb, &txq_params);
3094 result = rdev_set_txq_params(rdev, netdev,
3101 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3102 result = __nl80211_set_channel(
3104 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3110 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
3111 struct wireless_dev *txp_wdev = wdev;
3112 enum nl80211_tx_power_setting type;
3115 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3118 if (!rdev->ops->set_tx_power)
3121 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
3122 type = nla_get_u32(info->attrs[idx]);
3124 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
3125 (type != NL80211_TX_POWER_AUTOMATIC))
3128 if (type != NL80211_TX_POWER_AUTOMATIC) {
3129 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
3130 mbm = nla_get_u32(info->attrs[idx]);
3133 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
3138 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3139 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3142 if ((!rdev->wiphy.available_antennas_tx &&
3143 !rdev->wiphy.available_antennas_rx) ||
3144 !rdev->ops->set_antenna)
3147 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3148 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3150 /* reject antenna configurations which don't match the
3151 * available antenna masks, except for the "all" mask */
3152 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
3153 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
3156 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3157 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
3159 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
3166 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3167 retry_short = nla_get_u8(
3168 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
3170 changed |= WIPHY_PARAM_RETRY_SHORT;
3173 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3174 retry_long = nla_get_u8(
3175 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
3177 changed |= WIPHY_PARAM_RETRY_LONG;
3180 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3181 frag_threshold = nla_get_u32(
3182 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
3183 if (frag_threshold < 256)
3186 if (frag_threshold != (u32) -1) {
3188 * Fragments (apart from the last one) are required to
3189 * have even length. Make the fragmentation code
3190 * simpler by stripping LSB should someone try to use
3191 * odd threshold value.
3193 frag_threshold &= ~0x1;
3195 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3198 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3199 rts_threshold = nla_get_u32(
3200 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3201 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3204 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
3205 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
3208 coverage_class = nla_get_u8(
3209 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3210 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3213 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3214 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
3217 changed |= WIPHY_PARAM_DYN_ACK;
3220 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3221 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3222 NL80211_EXT_FEATURE_TXQS))
3224 txq_limit = nla_get_u32(
3225 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3226 changed |= WIPHY_PARAM_TXQ_LIMIT;
3229 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3230 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3231 NL80211_EXT_FEATURE_TXQS))
3233 txq_memory_limit = nla_get_u32(
3234 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3235 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3238 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3239 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3240 NL80211_EXT_FEATURE_TXQS))
3242 txq_quantum = nla_get_u32(
3243 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3244 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3248 u8 old_retry_short, old_retry_long;
3249 u32 old_frag_threshold, old_rts_threshold;
3250 u8 old_coverage_class;
3251 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
3253 if (!rdev->ops->set_wiphy_params)
3256 old_retry_short = rdev->wiphy.retry_short;
3257 old_retry_long = rdev->wiphy.retry_long;
3258 old_frag_threshold = rdev->wiphy.frag_threshold;
3259 old_rts_threshold = rdev->wiphy.rts_threshold;
3260 old_coverage_class = rdev->wiphy.coverage_class;
3261 old_txq_limit = rdev->wiphy.txq_limit;
3262 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3263 old_txq_quantum = rdev->wiphy.txq_quantum;
3265 if (changed & WIPHY_PARAM_RETRY_SHORT)
3266 rdev->wiphy.retry_short = retry_short;
3267 if (changed & WIPHY_PARAM_RETRY_LONG)
3268 rdev->wiphy.retry_long = retry_long;
3269 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3270 rdev->wiphy.frag_threshold = frag_threshold;
3271 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3272 rdev->wiphy.rts_threshold = rts_threshold;
3273 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3274 rdev->wiphy.coverage_class = coverage_class;
3275 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3276 rdev->wiphy.txq_limit = txq_limit;
3277 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3278 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3279 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3280 rdev->wiphy.txq_quantum = txq_quantum;
3282 result = rdev_set_wiphy_params(rdev, changed);
3284 rdev->wiphy.retry_short = old_retry_short;
3285 rdev->wiphy.retry_long = old_retry_long;
3286 rdev->wiphy.frag_threshold = old_frag_threshold;
3287 rdev->wiphy.rts_threshold = old_rts_threshold;
3288 rdev->wiphy.coverage_class = old_coverage_class;
3289 rdev->wiphy.txq_limit = old_txq_limit;
3290 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3291 rdev->wiphy.txq_quantum = old_txq_quantum;
3298 static int nl80211_send_chandef(struct sk_buff *msg,
3299 const struct cfg80211_chan_def *chandef)
3301 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3304 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3305 chandef->chan->center_freq))
3307 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
3308 chandef->chan->freq_offset))
3310 switch (chandef->width) {
3311 case NL80211_CHAN_WIDTH_20_NOHT:
3312 case NL80211_CHAN_WIDTH_20:
3313 case NL80211_CHAN_WIDTH_40:
3314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3315 cfg80211_get_chandef_type(chandef)))
3321 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3323 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3325 if (chandef->center_freq2 &&
3326 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
3331 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
3332 struct cfg80211_registered_device *rdev,
3333 struct wireless_dev *wdev,
3334 enum nl80211_commands cmd)
3336 struct net_device *dev = wdev->netdev;
3339 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3340 cmd != NL80211_CMD_DEL_INTERFACE &&
3341 cmd != NL80211_CMD_SET_INTERFACE);
3343 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
3348 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3349 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
3350 goto nla_put_failure;
3352 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3353 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
3354 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3355 NL80211_ATTR_PAD) ||
3356 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
3357 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3358 rdev->devlist_generation ^
3359 (cfg80211_rdev_list_generation << 2)) ||
3360 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
3361 goto nla_put_failure;
3363 if (rdev->ops->get_channel) {
3365 struct cfg80211_chan_def chandef = {};
3367 ret = rdev_get_channel(rdev, wdev, &chandef);
3369 if (nl80211_send_chandef(msg, &chandef))
3370 goto nla_put_failure;
3374 if (rdev->ops->get_tx_power) {
3377 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3379 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3381 goto nla_put_failure;
3385 switch (wdev->iftype) {
3386 case NL80211_IFTYPE_AP:
3387 if (wdev->ssid_len &&
3388 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
3389 goto nla_put_failure_locked;
3391 case NL80211_IFTYPE_STATION:
3392 case NL80211_IFTYPE_P2P_CLIENT:
3393 case NL80211_IFTYPE_ADHOC: {
3395 if (!wdev->current_bss)
3398 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3401 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3402 goto nla_put_failure_rcu_locked;
3412 if (rdev->ops->get_txq_stats) {
3413 struct cfg80211_txq_stats txqstats = {};
3414 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3417 !nl80211_put_txq_stats(msg, &txqstats,
3418 NL80211_ATTR_TXQ_STATS))
3419 goto nla_put_failure;
3422 genlmsg_end(msg, hdr);
3425 nla_put_failure_rcu_locked:
3427 nla_put_failure_locked:
3430 genlmsg_cancel(msg, hdr);
3434 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3438 int wp_start = cb->args[0];
3439 int if_start = cb->args[1];
3440 int filter_wiphy = -1;
3441 struct cfg80211_registered_device *rdev;
3442 struct wireless_dev *wdev;
3447 struct nl80211_dump_wiphy_state state = {
3451 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3455 filter_wiphy = state.filter_wiphy;
3458 * if filtering, set cb->args[2] to +1 since 0 is the default
3459 * value needed to determine that parsing is necessary.
3461 if (filter_wiphy >= 0)
3462 cb->args[2] = filter_wiphy + 1;
3465 } else if (cb->args[2] > 0) {
3466 filter_wiphy = cb->args[2] - 1;
3469 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3470 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
3472 if (wp_idx < wp_start) {
3477 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3482 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
3483 if (if_idx < if_start) {
3487 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
3488 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3490 NL80211_CMD_NEW_INTERFACE) < 0) {
3499 cb->args[0] = wp_idx;
3500 cb->args[1] = if_idx;
3509 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3511 struct sk_buff *msg;
3512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3513 struct wireless_dev *wdev = info->user_ptr[1];
3515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3519 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3520 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
3525 return genlmsg_reply(msg, info);
3528 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3529 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3530 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3531 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3532 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3533 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
3534 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
3537 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3539 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3547 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
3550 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3552 *mntrflags |= (1<<flag);
3554 *mntrflags |= MONITOR_FLAG_CHANGED;
3559 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3560 enum nl80211_iftype type,
3561 struct genl_info *info,
3562 struct vif_params *params)
3564 bool change = false;
3567 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3568 if (type != NL80211_IFTYPE_MONITOR)
3571 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3579 if (params->flags & MONITOR_FLAG_ACTIVE &&
3580 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3583 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3584 const u8 *mumimo_groups;
3585 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3587 if (type != NL80211_IFTYPE_MONITOR)
3590 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3594 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3596 /* bits 0 and 63 are reserved and must be zero */
3597 if ((mumimo_groups[0] & BIT(0)) ||
3598 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
3601 params->vht_mumimo_groups = mumimo_groups;
3605 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3606 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3608 if (type != NL80211_IFTYPE_MONITOR)
3611 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3614 params->vht_mumimo_follow_addr =
3615 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3619 return change ? 1 : 0;
3622 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
3623 struct net_device *netdev, u8 use_4addr,
3624 enum nl80211_iftype iftype)
3627 if (netdev && netif_is_bridge_port(netdev))
3633 case NL80211_IFTYPE_AP_VLAN:
3634 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3637 case NL80211_IFTYPE_STATION:
3638 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3648 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3650 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3651 struct vif_params params;
3653 enum nl80211_iftype otype, ntype;
3654 struct net_device *dev = info->user_ptr[1];
3655 bool change = false;
3657 memset(¶ms, 0, sizeof(params));
3659 otype = ntype = dev->ieee80211_ptr->iftype;
3661 if (info->attrs[NL80211_ATTR_IFTYPE]) {
3662 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3667 if (info->attrs[NL80211_ATTR_MESH_ID]) {
3668 struct wireless_dev *wdev = dev->ieee80211_ptr;
3670 if (ntype != NL80211_IFTYPE_MESH_POINT)
3672 if (netif_running(dev))
3676 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3677 IEEE80211_MAX_MESH_ID_LEN);
3678 wdev->mesh_id_up_len =
3679 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3680 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3681 wdev->mesh_id_up_len);
3685 if (info->attrs[NL80211_ATTR_4ADDR]) {
3686 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3688 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
3692 params.use_4addr = -1;
3695 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms);
3702 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms);
3706 if (!err && params.use_4addr != -1)
3707 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3709 if (change && !err) {
3710 struct wireless_dev *wdev = dev->ieee80211_ptr;
3712 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3718 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3721 struct vif_params params;
3722 struct wireless_dev *wdev;
3723 struct sk_buff *msg;
3725 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3727 /* to avoid failing a new interface creation due to pending removal */
3728 cfg80211_destroy_ifaces(rdev);
3730 memset(¶ms, 0, sizeof(params));
3732 if (!info->attrs[NL80211_ATTR_IFNAME])
3735 if (info->attrs[NL80211_ATTR_IFTYPE])
3736 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
3738 if (!rdev->ops->add_virtual_intf)
3741 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
3742 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3743 info->attrs[NL80211_ATTR_MAC]) {
3744 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3746 if (!is_valid_ether_addr(params.macaddr))
3747 return -EADDRNOTAVAIL;
3750 if (info->attrs[NL80211_ATTR_4ADDR]) {
3751 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3752 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
3757 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
3760 err = nl80211_parse_mon_options(rdev, type, info, ¶ms);
3764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3768 wdev = rdev_add_virtual_intf(rdev,
3769 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
3770 NET_NAME_USER, type, ¶ms);
3771 if (WARN_ON(!wdev)) {
3774 } else if (IS_ERR(wdev)) {
3776 return PTR_ERR(wdev);
3779 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
3780 wdev->owner_nlportid = info->snd_portid;
3783 case NL80211_IFTYPE_MESH_POINT:
3784 if (!info->attrs[NL80211_ATTR_MESH_ID])
3787 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3788 IEEE80211_MAX_MESH_ID_LEN);
3789 wdev->mesh_id_up_len =
3790 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3791 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3792 wdev->mesh_id_up_len);
3795 case NL80211_IFTYPE_NAN:
3796 case NL80211_IFTYPE_P2P_DEVICE:
3798 * P2P Device and NAN do not have a netdev, so don't go
3799 * through the netdev notifier and must be added here
3801 cfg80211_init_wdev(rdev, wdev);
3807 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3808 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
3813 return genlmsg_reply(msg, info);
3816 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3819 struct wireless_dev *wdev = info->user_ptr[1];
3821 if (!rdev->ops->del_virtual_intf)
3825 * If we remove a wireless device without a netdev then clear
3826 * user_ptr[1] so that nl80211_post_doit won't dereference it
3827 * to check if it needs to do dev_put(). Otherwise it crashes
3828 * since the wdev has been freed, unlike with a netdev where
3829 * we need the dev_put() for the netdev to really be freed.
3832 info->user_ptr[1] = NULL;
3834 return rdev_del_virtual_intf(rdev, wdev);
3837 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3840 struct net_device *dev = info->user_ptr[1];
3843 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3846 if (!rdev->ops->set_noack_map)
3849 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3851 return rdev_set_noack_map(rdev, dev, noack_map);
3854 struct get_key_cookie {
3855 struct sk_buff *msg;
3860 static void get_key_callback(void *c, struct key_params *params)
3863 struct get_key_cookie *cookie = c;
3866 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3867 params->key_len, params->key)) ||
3869 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3870 params->seq_len, params->seq)) ||
3872 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3874 goto nla_put_failure;
3876 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
3878 goto nla_put_failure;
3881 nla_put(cookie->msg, NL80211_KEY_DATA,
3882 params->key_len, params->key)) ||
3884 nla_put(cookie->msg, NL80211_KEY_SEQ,
3885 params->seq_len, params->seq)) ||
3887 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3889 goto nla_put_failure;
3891 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
3892 goto nla_put_failure;
3894 nla_nest_end(cookie->msg, key);
3901 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3905 struct net_device *dev = info->user_ptr[1];
3907 const u8 *mac_addr = NULL;
3909 struct get_key_cookie cookie = {
3913 struct sk_buff *msg;
3914 bool bigtk_support = false;
3916 if (wiphy_ext_feature_isset(&rdev->wiphy,
3917 NL80211_EXT_FEATURE_BEACON_PROTECTION))
3918 bigtk_support = true;
3920 if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION ||
3921 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
3922 wiphy_ext_feature_isset(&rdev->wiphy,
3923 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
3924 bigtk_support = true;
3926 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
3927 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3929 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) {
3930 GENL_SET_ERR_MSG(info, "BIGTK not supported");
3935 if (info->attrs[NL80211_ATTR_MAC])
3936 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3938 pairwise = !!mac_addr;
3939 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3940 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
3942 if (kt != NL80211_KEYTYPE_GROUP &&
3943 kt != NL80211_KEYTYPE_PAIRWISE)
3945 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3948 if (!rdev->ops->get_key)
3951 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3954 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3958 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
3959 NL80211_CMD_NEW_KEY);
3961 goto nla_put_failure;
3964 cookie.idx = key_idx;
3966 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3967 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3968 goto nla_put_failure;
3970 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3971 goto nla_put_failure;
3973 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3980 goto nla_put_failure;
3982 genlmsg_end(msg, hdr);
3983 return genlmsg_reply(msg, info);
3992 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3995 struct key_parse key;
3997 struct net_device *dev = info->user_ptr[1];
3999 err = nl80211_parse_key(info, &key);
4006 /* Only support setting default key and
4007 * Extended Key ID action NL80211_KEY_SET_TX.
4009 if (!key.def && !key.defmgmt && !key.defbeacon &&
4010 !(key.p.mode == NL80211_KEY_SET_TX))
4013 wdev_lock(dev->ieee80211_ptr);
4016 if (!rdev->ops->set_default_key) {
4021 err = nl80211_key_allowed(dev->ieee80211_ptr);
4025 err = rdev_set_default_key(rdev, dev, key.idx,
4026 key.def_uni, key.def_multi);
4031 #ifdef CONFIG_CFG80211_WEXT
4032 dev->ieee80211_ptr->wext.default_key = key.idx;
4034 } else if (key.defmgmt) {
4035 if (key.def_uni || !key.def_multi) {
4040 if (!rdev->ops->set_default_mgmt_key) {
4045 err = nl80211_key_allowed(dev->ieee80211_ptr);
4049 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
4053 #ifdef CONFIG_CFG80211_WEXT
4054 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
4056 } else if (key.defbeacon) {
4057 if (key.def_uni || !key.def_multi) {
4062 if (!rdev->ops->set_default_beacon_key) {
4067 err = nl80211_key_allowed(dev->ieee80211_ptr);
4071 err = rdev_set_default_beacon_key(rdev, dev, key.idx);
4074 } else if (key.p.mode == NL80211_KEY_SET_TX &&
4075 wiphy_ext_feature_isset(&rdev->wiphy,
4076 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
4077 u8 *mac_addr = NULL;
4079 if (info->attrs[NL80211_ATTR_MAC])
4080 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4082 if (!mac_addr || key.idx < 0 || key.idx > 1) {
4087 err = rdev_add_key(rdev, dev, key.idx,
4088 NL80211_KEYTYPE_PAIRWISE,
4094 wdev_unlock(dev->ieee80211_ptr);
4099 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4103 struct net_device *dev = info->user_ptr[1];
4104 struct key_parse key;
4105 const u8 *mac_addr = NULL;
4107 err = nl80211_parse_key(info, &key);
4112 GENL_SET_ERR_MSG(info, "no key");
4116 if (info->attrs[NL80211_ATTR_MAC])
4117 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4119 if (key.type == -1) {
4121 key.type = NL80211_KEYTYPE_PAIRWISE;
4123 key.type = NL80211_KEYTYPE_GROUP;
4127 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4128 key.type != NL80211_KEYTYPE_GROUP) {
4129 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
4133 if (key.type == NL80211_KEYTYPE_GROUP &&
4134 info->attrs[NL80211_ATTR_VLAN_ID])
4135 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
4137 if (!rdev->ops->add_key)
4140 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4141 key.type == NL80211_KEYTYPE_PAIRWISE,
4143 GENL_SET_ERR_MSG(info, "key setting validation failed");
4147 wdev_lock(dev->ieee80211_ptr);
4148 err = nl80211_key_allowed(dev->ieee80211_ptr);
4150 GENL_SET_ERR_MSG(info, "key not allowed");
4152 err = rdev_add_key(rdev, dev, key.idx,
4153 key.type == NL80211_KEYTYPE_PAIRWISE,
4156 GENL_SET_ERR_MSG(info, "key addition failed");
4158 wdev_unlock(dev->ieee80211_ptr);
4163 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4167 struct net_device *dev = info->user_ptr[1];
4168 u8 *mac_addr = NULL;
4169 struct key_parse key;
4171 err = nl80211_parse_key(info, &key);
4178 if (info->attrs[NL80211_ATTR_MAC])
4179 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4181 if (key.type == -1) {
4183 key.type = NL80211_KEYTYPE_PAIRWISE;
4185 key.type = NL80211_KEYTYPE_GROUP;
4189 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4190 key.type != NL80211_KEYTYPE_GROUP)
4193 if (!rdev->ops->del_key)
4196 wdev_lock(dev->ieee80211_ptr);
4197 err = nl80211_key_allowed(dev->ieee80211_ptr);
4199 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
4200 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4204 err = rdev_del_key(rdev, dev, key.idx,
4205 key.type == NL80211_KEYTYPE_PAIRWISE,
4208 #ifdef CONFIG_CFG80211_WEXT
4210 if (key.idx == dev->ieee80211_ptr->wext.default_key)
4211 dev->ieee80211_ptr->wext.default_key = -1;
4212 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
4213 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
4216 wdev_unlock(dev->ieee80211_ptr);
4221 /* This function returns an error or the number of nested attributes */
4222 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4224 struct nlattr *attr;
4225 int n_entries = 0, tmp;
4227 nla_for_each_nested(attr, nl_attr, tmp) {
4228 if (nla_len(attr) != ETH_ALEN)
4238 * This function parses ACL information and allocates memory for ACL data.
4239 * On successful return, the calling function is responsible to free the
4240 * ACL buffer returned by this function.
4242 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4243 struct genl_info *info)
4245 enum nl80211_acl_policy acl_policy;
4246 struct nlattr *attr;
4247 struct cfg80211_acl_data *acl;
4248 int i = 0, n_entries, tmp;
4250 if (!wiphy->max_acl_mac_addrs)
4251 return ERR_PTR(-EOPNOTSUPP);
4253 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4254 return ERR_PTR(-EINVAL);
4256 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4257 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4258 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4259 return ERR_PTR(-EINVAL);
4261 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4262 return ERR_PTR(-EINVAL);
4264 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4266 return ERR_PTR(n_entries);
4268 if (n_entries > wiphy->max_acl_mac_addrs)
4269 return ERR_PTR(-ENOTSUPP);
4271 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
4273 return ERR_PTR(-ENOMEM);
4275 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4276 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4280 acl->n_acl_entries = n_entries;
4281 acl->acl_policy = acl_policy;
4286 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4288 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4289 struct net_device *dev = info->user_ptr[1];
4290 struct cfg80211_acl_data *acl;
4293 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4294 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4297 if (!dev->ieee80211_ptr->beacon_interval)
4300 acl = parse_acl_data(&rdev->wiphy, info);
4302 return PTR_ERR(acl);
4304 err = rdev_set_mac_acl(rdev, dev, acl);
4311 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4312 u8 *rates, u8 rates_len)
4317 for (i = 0; i < rates_len; i++) {
4318 int rate = (rates[i] & 0x7f) * 5;
4321 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4322 struct ieee80211_rate *srate =
4323 &sband->bitrates[ridx];
4324 if (rate == srate->bitrate) {
4329 if (ridx == sband->n_bitrates)
4330 return 0; /* rate not found */
4336 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4337 u8 *rates, u8 rates_len,
4338 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4342 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4344 for (i = 0; i < rates_len; i++) {
4347 ridx = rates[i] / 8;
4348 rbit = BIT(rates[i] % 8);
4350 /* check validity */
4351 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4354 /* check availability */
4355 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
4356 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4365 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4369 switch (vht_mcs_map) {
4370 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4372 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4375 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4378 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4388 static void vht_build_mcs_mask(u16 vht_mcs_map,
4389 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4393 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4394 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4399 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4400 struct nl80211_txrate_vht *txrate,
4401 u16 mcs[NL80211_VHT_NSS_MAX])
4403 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4404 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4407 if (!sband->vht_cap.vht_supported)
4410 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4412 /* Build vht_mcs_mask from VHT capabilities */
4413 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4415 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4416 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4417 mcs[i] = txrate->mcs[i];
4425 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4426 struct nlattr *attrs[],
4427 enum nl80211_attrs attr,
4428 struct cfg80211_bitrate_mask *mask)
4430 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4433 struct nlattr *tx_rates;
4434 struct ieee80211_supported_band *sband;
4437 memset(mask, 0, sizeof(*mask));
4438 /* Default to all rates enabled */
4439 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4440 sband = rdev->wiphy.bands[i];
4445 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4446 memcpy(mask->control[i].ht_mcs,
4447 sband->ht_cap.mcs.rx_mask,
4448 sizeof(mask->control[i].ht_mcs));
4450 if (!sband->vht_cap.vht_supported)
4453 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4454 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4457 /* if no rates are given set it back to the defaults */
4461 /* The nested attribute uses enum nl80211_band as the index. This maps
4462 * directly to the enum nl80211_band values used in cfg80211.
4464 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4465 nla_for_each_nested(tx_rates, attrs[attr], rem) {
4466 enum nl80211_band band = nla_type(tx_rates);
4469 if (band < 0 || band >= NUM_NL80211_BANDS)
4471 sband = rdev->wiphy.bands[band];
4474 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4476 nl80211_txattr_policy,
4480 if (tb[NL80211_TXRATE_LEGACY]) {
4481 mask->control[band].legacy = rateset_to_mask(
4483 nla_data(tb[NL80211_TXRATE_LEGACY]),
4484 nla_len(tb[NL80211_TXRATE_LEGACY]));
4485 if ((mask->control[band].legacy == 0) &&
4486 nla_len(tb[NL80211_TXRATE_LEGACY]))
4489 if (tb[NL80211_TXRATE_HT]) {
4490 if (!ht_rateset_to_mask(
4492 nla_data(tb[NL80211_TXRATE_HT]),
4493 nla_len(tb[NL80211_TXRATE_HT]),
4494 mask->control[band].ht_mcs))
4497 if (tb[NL80211_TXRATE_VHT]) {
4498 if (!vht_set_mcs_mask(
4500 nla_data(tb[NL80211_TXRATE_VHT]),
4501 mask->control[band].vht_mcs))
4504 if (tb[NL80211_TXRATE_GI]) {
4505 mask->control[band].gi =
4506 nla_get_u8(tb[NL80211_TXRATE_GI]);
4507 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4511 if (mask->control[band].legacy == 0) {
4512 /* don't allow empty legacy rates if HT or VHT
4513 * are not even supported.
4515 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4516 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4519 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4520 if (mask->control[band].ht_mcs[i])
4523 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4524 if (mask->control[band].vht_mcs[i])
4527 /* legacy and mcs rates may not be both empty */
4536 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4537 enum nl80211_band band,
4538 struct cfg80211_bitrate_mask *beacon_rate)
4540 u32 count_ht, count_vht, i;
4541 u32 rate = beacon_rate->control[band].legacy;
4543 /* Allow only one rate */
4544 if (hweight32(rate) > 1)
4548 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4549 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
4551 } else if (beacon_rate->control[band].ht_mcs[i]) {
4556 if (count_ht && rate)
4561 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4562 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
4564 } else if (beacon_rate->control[band].vht_mcs[i]) {
4569 if (count_vht && rate)
4573 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4577 !wiphy_ext_feature_isset(&rdev->wiphy,
4578 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4581 !wiphy_ext_feature_isset(&rdev->wiphy,
4582 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4585 !wiphy_ext_feature_isset(&rdev->wiphy,
4586 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4592 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4593 struct nlattr *attrs[],
4594 struct cfg80211_beacon_data *bcn)
4596 bool haveinfo = false;
4599 memset(bcn, 0, sizeof(*bcn));
4601 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4602 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4603 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
4609 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4610 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4611 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
4618 if (attrs[NL80211_ATTR_IE]) {
4619 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4620 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
4623 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
4624 bcn->proberesp_ies =
4625 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
4626 bcn->proberesp_ies_len =
4627 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
4630 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
4631 bcn->assocresp_ies =
4632 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
4633 bcn->assocresp_ies_len =
4634 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
4637 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4638 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4639 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
4642 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4643 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4645 err = nla_parse_nested_deprecated(tb,
4646 NL80211_FTM_RESP_ATTR_MAX,
4647 attrs[NL80211_ATTR_FTM_RESPONDER],
4652 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4653 wiphy_ext_feature_isset(&rdev->wiphy,
4654 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4655 bcn->ftm_responder = 1;
4659 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4660 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4661 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4664 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4665 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4666 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4669 bcn->ftm_responder = -1;
4675 static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
4676 struct ieee80211_he_obss_pd *he_obss_pd)
4678 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
4681 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
4682 he_obss_pd_policy, NULL);
4686 if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] ||
4687 !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
4690 he_obss_pd->min_offset =
4691 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
4692 he_obss_pd->max_offset =
4693 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
4695 if (he_obss_pd->min_offset >= he_obss_pd->max_offset)
4698 he_obss_pd->enable = true;
4703 static int nl80211_parse_he_bss_color(struct nlattr *attrs,
4704 struct cfg80211_he_bss_color *he_bss_color)
4706 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1];
4709 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs,
4710 he_bss_color_policy, NULL);
4714 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR])
4717 he_bss_color->color =
4718 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]);
4719 he_bss_color->enabled =
4720 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]);
4721 he_bss_color->partial =
4722 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]);
4727 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4735 for (i = 0; i < rates[1]; i++) {
4736 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4737 params->ht_required = true;
4738 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4739 params->vht_required = true;
4740 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
4741 params->he_required = true;
4746 * Since the nl80211 API didn't include, from the beginning, attributes about
4747 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4748 * benefit of drivers that rebuild IEs in the firmware.
4750 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4752 const struct cfg80211_beacon_data *bcn = ¶ms->beacon;
4753 size_t ies_len = bcn->tail_len;
4754 const u8 *ies = bcn->tail;
4758 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4759 nl80211_check_ap_rate_selectors(params, rates);
4761 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4762 nl80211_check_ap_rate_selectors(params, rates);
4764 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4765 if (cap && cap[1] >= sizeof(*params->ht_cap))
4766 params->ht_cap = (void *)(cap + 2);
4767 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4768 if (cap && cap[1] >= sizeof(*params->vht_cap))
4769 params->vht_cap = (void *)(cap + 2);
4770 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4771 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4772 params->he_cap = (void *)(cap + 3);
4773 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len);
4774 if (cap && cap[1] >= sizeof(*params->he_oper) + 1)
4775 params->he_oper = (void *)(cap + 3);
4778 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4779 struct cfg80211_ap_settings *params)
4781 struct wireless_dev *wdev;
4784 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
4785 if (wdev->iftype != NL80211_IFTYPE_AP &&
4786 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4789 if (!wdev->preset_chandef.chan)
4792 params->chandef = wdev->preset_chandef;
4800 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4801 enum nl80211_auth_type auth_type,
4802 enum nl80211_commands cmd)
4804 if (auth_type > NL80211_AUTHTYPE_MAX)
4808 case NL80211_CMD_AUTHENTICATE:
4809 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4810 auth_type == NL80211_AUTHTYPE_SAE)
4812 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4813 NL80211_EXT_FEATURE_FILS_STA) &&
4814 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4815 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4816 auth_type == NL80211_AUTHTYPE_FILS_PK))
4819 case NL80211_CMD_CONNECT:
4820 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4821 !wiphy_ext_feature_isset(&rdev->wiphy,
4822 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
4823 auth_type == NL80211_AUTHTYPE_SAE)
4826 /* FILS with SK PFS or PK not supported yet */
4827 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4828 auth_type == NL80211_AUTHTYPE_FILS_PK)
4830 if (!wiphy_ext_feature_isset(
4832 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4833 auth_type == NL80211_AUTHTYPE_FILS_SK)
4836 case NL80211_CMD_START_AP:
4837 /* SAE not supported yet */
4838 if (auth_type == NL80211_AUTHTYPE_SAE)
4840 /* FILS not supported yet */
4841 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4842 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4843 auth_type == NL80211_AUTHTYPE_FILS_PK)
4851 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4853 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4854 struct net_device *dev = info->user_ptr[1];
4855 struct wireless_dev *wdev = dev->ieee80211_ptr;
4856 struct cfg80211_ap_settings params;
4859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4860 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4863 if (!rdev->ops->start_ap)
4866 if (wdev->beacon_interval)
4869 memset(¶ms, 0, sizeof(params));
4871 /* these are required for START_AP */
4872 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4873 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4874 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4877 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon);
4881 params.beacon_interval =
4882 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4883 params.dtim_period =
4884 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4886 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4887 params.beacon_interval);
4892 * In theory, some of these attributes should be required here
4893 * but since they were not used when the command was originally
4894 * added, keep them optional for old user space programs to let
4895 * them continue to work with drivers that do not need the
4896 * additional information -- drivers must check!
4898 if (info->attrs[NL80211_ATTR_SSID]) {
4899 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4901 nla_len(info->attrs[NL80211_ATTR_SSID]);
4902 if (params.ssid_len == 0 ||
4903 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4907 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
4908 params.hidden_ssid = nla_get_u32(
4909 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
4911 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4913 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4914 params.auth_type = nla_get_u32(
4915 info->attrs[NL80211_ATTR_AUTH_TYPE]);
4916 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4917 NL80211_CMD_START_AP))
4920 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4922 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
4923 NL80211_MAX_NR_CIPHER_SUITES);
4927 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4928 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4930 params.inactivity_timeout = nla_get_u16(
4931 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4934 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4935 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4937 params.p2p_ctwindow =
4938 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4939 if (params.p2p_ctwindow != 0 &&
4940 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4944 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4947 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4949 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4950 params.p2p_opp_ps = tmp;
4951 if (params.p2p_opp_ps != 0 &&
4952 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4956 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4957 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
4960 } else if (wdev->preset_chandef.chan) {
4961 params.chandef = wdev->preset_chandef;
4962 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
4965 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
4969 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4970 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
4971 NL80211_ATTR_TX_RATES,
4972 ¶ms.beacon_rate);
4976 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4977 ¶ms.beacon_rate);
4982 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4984 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4985 switch (params.smps_mode) {
4986 case NL80211_SMPS_OFF:
4988 case NL80211_SMPS_STATIC:
4989 if (!(rdev->wiphy.features &
4990 NL80211_FEATURE_STATIC_SMPS))
4993 case NL80211_SMPS_DYNAMIC:
4994 if (!(rdev->wiphy.features &
4995 NL80211_FEATURE_DYNAMIC_SMPS))
5002 params.smps_mode = NL80211_SMPS_OFF;
5005 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
5006 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
5009 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
5010 params.acl = parse_acl_data(&rdev->wiphy, info);
5011 if (IS_ERR(params.acl))
5012 return PTR_ERR(params.acl);
5015 params.twt_responder =
5016 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
5018 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
5019 err = nl80211_parse_he_obss_pd(
5020 info->attrs[NL80211_ATTR_HE_OBSS_PD],
5021 ¶ms.he_obss_pd);
5026 if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) {
5027 err = nl80211_parse_he_bss_color(
5028 info->attrs[NL80211_ATTR_HE_BSS_COLOR],
5029 ¶ms.he_bss_color);
5034 nl80211_calculate_ap_params(¶ms);
5036 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
5037 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
5040 err = rdev_start_ap(rdev, dev, ¶ms);
5042 wdev->preset_chandef = params.chandef;
5043 wdev->beacon_interval = params.beacon_interval;
5044 wdev->chandef = params.chandef;
5045 wdev->ssid_len = params.ssid_len;
5046 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
5048 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
5049 wdev->conn_owner_nlportid = info->snd_portid;
5059 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
5061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5062 struct net_device *dev = info->user_ptr[1];
5063 struct wireless_dev *wdev = dev->ieee80211_ptr;
5064 struct cfg80211_beacon_data params;
5067 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5068 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5071 if (!rdev->ops->change_beacon)
5074 if (!wdev->beacon_interval)
5077 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms);
5082 err = rdev_change_beacon(rdev, dev, ¶ms);
5088 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
5090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5091 struct net_device *dev = info->user_ptr[1];
5093 return cfg80211_stop_ap(rdev, dev, false);
5096 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
5097 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
5098 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
5099 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
5100 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
5101 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
5102 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
5105 static int parse_station_flags(struct genl_info *info,
5106 enum nl80211_iftype iftype,
5107 struct station_parameters *params)
5109 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
5114 * Try parsing the new attribute first so userspace
5115 * can specify both for older kernels.
5117 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
5119 struct nl80211_sta_flag_update *sta_flags;
5121 sta_flags = nla_data(nla);
5122 params->sta_flags_mask = sta_flags->mask;
5123 params->sta_flags_set = sta_flags->set;
5124 params->sta_flags_set &= params->sta_flags_mask;
5125 if ((params->sta_flags_mask |
5126 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
5131 /* if present, parse the old attribute */
5133 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
5137 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
5141 * Only allow certain flags for interface types so that
5142 * other attributes are silently ignored. Remember that
5143 * this is backward compatibility code with old userspace
5144 * and shouldn't be hit in other cases anyway.
5147 case NL80211_IFTYPE_AP:
5148 case NL80211_IFTYPE_AP_VLAN:
5149 case NL80211_IFTYPE_P2P_GO:
5150 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5151 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5152 BIT(NL80211_STA_FLAG_WME) |
5153 BIT(NL80211_STA_FLAG_MFP);
5155 case NL80211_IFTYPE_P2P_CLIENT:
5156 case NL80211_IFTYPE_STATION:
5157 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5158 BIT(NL80211_STA_FLAG_TDLS_PEER);
5160 case NL80211_IFTYPE_MESH_POINT:
5161 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5162 BIT(NL80211_STA_FLAG_MFP) |
5163 BIT(NL80211_STA_FLAG_AUTHORIZED);
5169 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
5171 params->sta_flags_set |= (1<<flag);
5173 /* no longer support new API additions in old API */
5174 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
5182 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
5184 struct nlattr *rate;
5187 enum nl80211_rate_info rate_flg;
5189 rate = nla_nest_start_noflag(msg, attr);
5193 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
5194 bitrate = cfg80211_calculate_bitrate(info);
5195 /* report 16-bit bitrate only if we can */
5196 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
5198 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
5200 if (bitrate_compat > 0 &&
5201 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
5205 case RATE_INFO_BW_5:
5206 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
5208 case RATE_INFO_BW_10:
5209 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
5214 case RATE_INFO_BW_20:
5217 case RATE_INFO_BW_40:
5218 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
5220 case RATE_INFO_BW_80:
5221 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
5223 case RATE_INFO_BW_160:
5224 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
5226 case RATE_INFO_BW_HE_RU:
5228 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
5231 if (rate_flg && nla_put_flag(msg, rate_flg))
5234 if (info->flags & RATE_INFO_FLAGS_MCS) {
5235 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
5237 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5238 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5240 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
5241 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
5243 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
5245 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5246 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5248 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
5249 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
5251 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
5253 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
5255 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
5257 if (info->bw == RATE_INFO_BW_HE_RU &&
5258 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
5263 nla_nest_end(msg, rate);
5267 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
5276 attr = nla_nest_start_noflag(msg, id);
5280 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
5281 if (!(mask & BIT(i)))
5284 if (nla_put_u8(msg, i, signal[i]))
5288 nla_nest_end(msg, attr);
5293 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
5295 struct cfg80211_registered_device *rdev,
5296 struct net_device *dev,
5297 const u8 *mac_addr, struct station_info *sinfo)
5300 struct nlattr *sinfoattr, *bss_param;
5302 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
5304 cfg80211_sinfo_release_content(sinfo);
5308 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5309 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
5310 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
5311 goto nla_put_failure;
5313 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
5315 goto nla_put_failure;
5317 #define PUT_SINFO(attr, memb, type) do { \
5318 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
5319 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5320 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5322 goto nla_put_failure; \
5324 #define PUT_SINFO_U64(attr, memb) do { \
5325 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5326 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5327 sinfo->memb, NL80211_STA_INFO_PAD)) \
5328 goto nla_put_failure; \
5331 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5332 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
5333 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
5335 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5336 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
5337 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
5338 (u32)sinfo->rx_bytes))
5339 goto nla_put_failure;
5341 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5342 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
5343 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5344 (u32)sinfo->tx_bytes))
5345 goto nla_put_failure;
5347 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5348 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
5349 PUT_SINFO(LLID, llid, u16);
5350 PUT_SINFO(PLID, plid, u16);
5351 PUT_SINFO(PLINK_STATE, plink_state, u8);
5352 PUT_SINFO_U64(RX_DURATION, rx_duration);
5353 PUT_SINFO_U64(TX_DURATION, tx_duration);
5355 if (wiphy_ext_feature_isset(&rdev->wiphy,
5356 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5357 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
5359 switch (rdev->wiphy.signal_type) {
5360 case CFG80211_SIGNAL_TYPE_MBM:
5361 PUT_SINFO(SIGNAL, signal, u8);
5362 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
5367 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
5368 if (!nl80211_put_signal(msg, sinfo->chains,
5369 sinfo->chain_signal,
5370 NL80211_STA_INFO_CHAIN_SIGNAL))
5371 goto nla_put_failure;
5373 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
5374 if (!nl80211_put_signal(msg, sinfo->chains,
5375 sinfo->chain_signal_avg,
5376 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
5377 goto nla_put_failure;
5379 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
5380 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5381 NL80211_STA_INFO_TX_BITRATE))
5382 goto nla_put_failure;
5384 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
5385 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5386 NL80211_STA_INFO_RX_BITRATE))
5387 goto nla_put_failure;
5390 PUT_SINFO(RX_PACKETS, rx_packets, u32);
5391 PUT_SINFO(TX_PACKETS, tx_packets, u32);
5392 PUT_SINFO(TX_RETRIES, tx_retries, u32);
5393 PUT_SINFO(TX_FAILED, tx_failed, u32);
5394 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
5395 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
5396 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
5397 PUT_SINFO(LOCAL_PM, local_pm, u32);
5398 PUT_SINFO(PEER_PM, peer_pm, u32);
5399 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
5400 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
5401 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8);
5403 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
5404 bss_param = nla_nest_start_noflag(msg,
5405 NL80211_STA_INFO_BSS_PARAM);
5407 goto nla_put_failure;
5409 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5410 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5411 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5412 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5413 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5414 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5415 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5416 sinfo->bss_param.dtim_period) ||
5417 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5418 sinfo->bss_param.beacon_interval))
5419 goto nla_put_failure;
5421 nla_nest_end(msg, bss_param);
5423 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
5424 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5425 sizeof(struct nl80211_sta_flag_update),
5427 goto nla_put_failure;
5429 PUT_SINFO_U64(T_OFFSET, t_offset);
5430 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5431 PUT_SINFO_U64(BEACON_RX, rx_beacon);
5432 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
5433 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5434 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
5435 if (wiphy_ext_feature_isset(&rdev->wiphy,
5436 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5437 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5438 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5442 #undef PUT_SINFO_U64
5444 if (sinfo->pertid) {
5445 struct nlattr *tidsattr;
5448 tidsattr = nla_nest_start_noflag(msg,
5449 NL80211_STA_INFO_TID_STATS);
5451 goto nla_put_failure;
5453 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5454 struct cfg80211_tid_stats *tidstats;
5455 struct nlattr *tidattr;
5457 tidstats = &sinfo->pertid[tid];
5459 if (!tidstats->filled)
5462 tidattr = nla_nest_start_noflag(msg, tid + 1);
5464 goto nla_put_failure;
5466 #define PUT_TIDVAL_U64(attr, memb) do { \
5467 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
5468 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5469 tidstats->memb, NL80211_TID_STATS_PAD)) \
5470 goto nla_put_failure; \
5473 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5474 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5475 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5476 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
5478 #undef PUT_TIDVAL_U64
5479 if ((tidstats->filled &
5480 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5481 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5482 NL80211_TID_STATS_TXQ_STATS))
5483 goto nla_put_failure;
5485 nla_nest_end(msg, tidattr);
5488 nla_nest_end(msg, tidsattr);
5491 nla_nest_end(msg, sinfoattr);
5493 if (sinfo->assoc_req_ies_len &&
5494 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5495 sinfo->assoc_req_ies))
5496 goto nla_put_failure;
5498 cfg80211_sinfo_release_content(sinfo);
5499 genlmsg_end(msg, hdr);
5503 cfg80211_sinfo_release_content(sinfo);
5504 genlmsg_cancel(msg, hdr);
5508 static int nl80211_dump_station(struct sk_buff *skb,
5509 struct netlink_callback *cb)
5511 struct station_info sinfo;
5512 struct cfg80211_registered_device *rdev;
5513 struct wireless_dev *wdev;
5514 u8 mac_addr[ETH_ALEN];
5515 int sta_idx = cb->args[2];
5519 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
5523 if (!wdev->netdev) {
5528 if (!rdev->ops->dump_station) {
5534 memset(&sinfo, 0, sizeof(sinfo));
5535 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
5542 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
5543 NETLINK_CB(cb->skb).portid,
5544 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5545 rdev, wdev->netdev, mac_addr,
5553 cb->args[2] = sta_idx;
5561 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5564 struct net_device *dev = info->user_ptr[1];
5565 struct station_info sinfo;
5566 struct sk_buff *msg;
5567 u8 *mac_addr = NULL;
5570 memset(&sinfo, 0, sizeof(sinfo));
5572 if (!info->attrs[NL80211_ATTR_MAC])
5575 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5577 if (!rdev->ops->get_station)
5580 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
5584 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5586 cfg80211_sinfo_release_content(&sinfo);
5590 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5591 info->snd_portid, info->snd_seq, 0,
5592 rdev, dev, mac_addr, &sinfo) < 0) {
5597 return genlmsg_reply(msg, info);
5600 int cfg80211_check_station_change(struct wiphy *wiphy,
5601 struct station_parameters *params,
5602 enum cfg80211_station_type statype)
5604 if (params->listen_interval != -1 &&
5605 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5608 if (params->support_p2p_ps != -1 &&
5609 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5613 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5614 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5617 /* When you run into this, adjust the code below for the new flag */
5618 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5621 case CFG80211_STA_MESH_PEER_KERNEL:
5622 case CFG80211_STA_MESH_PEER_USER:
5624 * No ignoring the TDLS flag here -- the userspace mesh
5625 * code doesn't have the bug of including TDLS in the
5628 if (params->sta_flags_mask &
5629 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5630 BIT(NL80211_STA_FLAG_MFP) |
5631 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5634 case CFG80211_STA_TDLS_PEER_SETUP:
5635 case CFG80211_STA_TDLS_PEER_ACTIVE:
5636 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5638 /* ignore since it can't change */
5639 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5642 /* disallow mesh-specific things */
5643 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5645 if (params->local_pm)
5647 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5651 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5652 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5653 /* TDLS can't be set, ... */
5654 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5657 * ... but don't bother the driver with it. This works around
5658 * a hostapd/wpa_supplicant issue -- it always includes the
5659 * TLDS_PEER flag in the mask even for AP mode.
5661 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5664 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5665 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
5666 /* reject other things that can't change */
5667 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5669 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5671 if (params->supported_rates)
5673 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5678 if (statype != CFG80211_STA_AP_CLIENT &&
5679 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
5685 case CFG80211_STA_AP_MLME_CLIENT:
5686 /* Use this only for authorizing/unauthorizing a station */
5687 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5690 case CFG80211_STA_AP_CLIENT:
5691 case CFG80211_STA_AP_CLIENT_UNASSOC:
5692 /* accept only the listed bits */
5693 if (params->sta_flags_mask &
5694 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5695 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5696 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5697 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5698 BIT(NL80211_STA_FLAG_WME) |
5699 BIT(NL80211_STA_FLAG_MFP)))
5702 /* but authenticated/associated only if driver handles it */
5703 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5704 params->sta_flags_mask &
5705 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5706 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5709 case CFG80211_STA_IBSS:
5710 case CFG80211_STA_AP_STA:
5711 /* reject any changes other than AUTHORIZED */
5712 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5715 case CFG80211_STA_TDLS_PEER_SETUP:
5716 /* reject any changes other than AUTHORIZED or WME */
5717 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5718 BIT(NL80211_STA_FLAG_WME)))
5720 /* force (at least) rates when authorizing */
5721 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5722 !params->supported_rates)
5725 case CFG80211_STA_TDLS_PEER_ACTIVE:
5726 /* reject any changes */
5728 case CFG80211_STA_MESH_PEER_KERNEL:
5729 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5732 case CFG80211_STA_MESH_PEER_USER:
5733 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5734 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
5740 * Older kernel versions ignored this attribute entirely, so don't
5741 * reject attempts to update it but mark it as unused instead so the
5742 * driver won't look at the data.
5744 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5745 statype != CFG80211_STA_TDLS_PEER_SETUP)
5746 params->opmode_notif_used = false;
5750 EXPORT_SYMBOL(cfg80211_check_station_change);
5753 * Get vlan interface making sure it is running and on the right wiphy.
5755 static struct net_device *get_vlan(struct genl_info *info,
5756 struct cfg80211_registered_device *rdev)
5758 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
5759 struct net_device *v;
5765 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5767 return ERR_PTR(-ENODEV);
5769 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5774 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5775 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5776 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5781 if (!netif_running(v)) {
5789 return ERR_PTR(ret);
5792 static const struct nla_policy
5793 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
5794 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5795 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5798 static int nl80211_parse_sta_wme(struct genl_info *info,
5799 struct station_parameters *params)
5801 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5805 /* parse WME attributes if present */
5806 if (!info->attrs[NL80211_ATTR_STA_WME])
5809 nla = info->attrs[NL80211_ATTR_STA_WME];
5810 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5811 nl80211_sta_wme_policy,
5816 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5817 params->uapsd_queues = nla_get_u8(
5818 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5819 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5822 if (tb[NL80211_STA_WME_MAX_SP])
5823 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5825 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5828 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5833 static int nl80211_parse_sta_channel_info(struct genl_info *info,
5834 struct station_parameters *params)
5836 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5837 params->supported_channels =
5838 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5839 params->supported_channels_len =
5840 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5842 * Need to include at least one (first channel, number of
5843 * channels) tuple for each subband, and must have proper
5844 * tuples for the rest of the data as well.
5846 if (params->supported_channels_len < 2)
5848 if (params->supported_channels_len % 2)
5852 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5853 params->supported_oper_classes =
5854 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5855 params->supported_oper_classes_len =
5856 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5858 * The value of the Length field of the Supported Operating
5859 * Classes element is between 2 and 253.
5861 if (params->supported_oper_classes_len < 2 ||
5862 params->supported_oper_classes_len > 253)
5868 static int nl80211_set_station_tdls(struct genl_info *info,
5869 struct station_parameters *params)
5872 /* Dummy STA entry gets updated once the peer capabilities are known */
5873 if (info->attrs[NL80211_ATTR_PEER_AID])
5874 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
5875 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5877 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5878 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5880 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5881 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5883 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5884 params->he_capa_len =
5885 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5887 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5891 err = nl80211_parse_sta_channel_info(info, params);
5895 return nl80211_parse_sta_wme(info, params);
5898 static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5899 struct station_parameters *params)
5901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5904 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5905 if (!rdev->ops->set_tx_power ||
5906 !wiphy_ext_feature_isset(&rdev->wiphy,
5907 NL80211_EXT_FEATURE_STA_TX_PWR))
5910 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5911 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5913 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5914 idx = NL80211_ATTR_STA_TX_POWER;
5916 if (info->attrs[idx])
5917 params->txpwr.power =
5918 nla_get_s16(info->attrs[idx]);
5922 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5928 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5930 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5931 struct net_device *dev = info->user_ptr[1];
5932 struct station_parameters params;
5936 memset(¶ms, 0, sizeof(params));
5938 if (!rdev->ops->change_station)
5942 * AID and listen_interval properties can be set only for unassociated
5943 * station. Include these parameters here and will check them in
5944 * cfg80211_check_station_change().
5946 if (info->attrs[NL80211_ATTR_STA_AID])
5947 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
5949 if (info->attrs[NL80211_ATTR_VLAN_ID])
5950 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
5952 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5953 params.listen_interval =
5954 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5956 params.listen_interval = -1;
5958 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5959 params.support_p2p_ps =
5960 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5962 params.support_p2p_ps = -1;
5964 if (!info->attrs[NL80211_ATTR_MAC])
5967 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5969 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5970 params.supported_rates =
5971 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5972 params.supported_rates_len =
5973 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5976 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5978 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5979 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5982 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5984 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5985 params.ext_capab_len =
5986 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5989 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
5992 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
5993 params.plink_action =
5994 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5996 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
5997 params.plink_state =
5998 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
5999 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
6000 params.peer_aid = nla_get_u16(
6001 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
6002 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
6005 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
6006 params.local_pm = nla_get_u32(
6007 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
6009 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
6010 params.opmode_notif_used = true;
6011 params.opmode_notif =
6012 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
6015 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
6016 params.he_6ghz_capa =
6017 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
6019 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
6020 params.airtime_weight =
6021 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
6023 if (params.airtime_weight &&
6024 !wiphy_ext_feature_isset(&rdev->wiphy,
6025 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6028 err = nl80211_parse_sta_txpower_setting(info, ¶ms);
6032 /* Include parameters for TDLS peer (will check later) */
6033 err = nl80211_set_station_tdls(info, ¶ms);
6037 params.vlan = get_vlan(info, rdev);
6038 if (IS_ERR(params.vlan))
6039 return PTR_ERR(params.vlan);
6041 switch (dev->ieee80211_ptr->iftype) {
6042 case NL80211_IFTYPE_AP:
6043 case NL80211_IFTYPE_AP_VLAN:
6044 case NL80211_IFTYPE_P2P_GO:
6045 case NL80211_IFTYPE_P2P_CLIENT:
6046 case NL80211_IFTYPE_STATION:
6047 case NL80211_IFTYPE_ADHOC:
6048 case NL80211_IFTYPE_MESH_POINT:
6055 /* driver will call cfg80211_check_station_change() */
6056 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
6060 dev_put(params.vlan);
6065 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
6067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6069 struct net_device *dev = info->user_ptr[1];
6070 struct station_parameters params;
6071 u8 *mac_addr = NULL;
6072 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6073 BIT(NL80211_STA_FLAG_ASSOCIATED);
6075 memset(¶ms, 0, sizeof(params));
6077 if (!rdev->ops->add_station)
6080 if (!info->attrs[NL80211_ATTR_MAC])
6083 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
6086 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
6089 if (!info->attrs[NL80211_ATTR_STA_AID] &&
6090 !info->attrs[NL80211_ATTR_PEER_AID])
6093 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6094 params.supported_rates =
6095 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6096 params.supported_rates_len =
6097 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6098 params.listen_interval =
6099 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
6101 if (info->attrs[NL80211_ATTR_VLAN_ID])
6102 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6104 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
6105 params.support_p2p_ps =
6106 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
6109 * if not specified, assume it's supported for P2P GO interface,
6110 * and is NOT supported for AP interface
6112 params.support_p2p_ps =
6113 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
6116 if (info->attrs[NL80211_ATTR_PEER_AID])
6117 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
6119 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
6121 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
6123 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
6124 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
6127 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
6129 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6130 params.ext_capab_len =
6131 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6134 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6136 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6138 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6140 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6142 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
6144 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6145 params.he_capa_len =
6146 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6148 /* max len is validated in nla policy */
6149 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
6153 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
6154 params.he_6ghz_capa =
6155 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
6157 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
6158 params.opmode_notif_used = true;
6159 params.opmode_notif =
6160 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
6163 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
6164 params.plink_action =
6165 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
6167 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
6168 params.airtime_weight =
6169 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
6171 if (params.airtime_weight &&
6172 !wiphy_ext_feature_isset(&rdev->wiphy,
6173 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6176 err = nl80211_parse_sta_txpower_setting(info, ¶ms);
6180 err = nl80211_parse_sta_channel_info(info, ¶ms);
6184 err = nl80211_parse_sta_wme(info, ¶ms);
6188 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
6191 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
6192 * as userspace might just pass through the capabilities from the IEs
6193 * directly, rather than enforcing this restriction and returning an
6194 * error in this case.
6196 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
6197 params.ht_capa = NULL;
6198 params.vht_capa = NULL;
6200 /* HE requires WME */
6201 if (params.he_capa_len || params.he_6ghz_capa)
6205 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
6206 if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa))
6209 /* When you run into this, adjust the code below for the new flag */
6210 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6212 switch (dev->ieee80211_ptr->iftype) {
6213 case NL80211_IFTYPE_AP:
6214 case NL80211_IFTYPE_AP_VLAN:
6215 case NL80211_IFTYPE_P2P_GO:
6216 /* ignore WME attributes if iface/sta is not capable */
6217 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
6218 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
6219 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6221 /* TDLS peers cannot be added */
6222 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6223 info->attrs[NL80211_ATTR_PEER_AID])
6225 /* but don't bother the driver with it */
6226 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
6228 /* allow authenticated/associated only if driver handles it */
6229 if (!(rdev->wiphy.features &
6230 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
6231 params.sta_flags_mask & auth_assoc)
6234 /* Older userspace, or userspace wanting to be compatible with
6235 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
6236 * and assoc flags in the mask, but assumes the station will be
6237 * added as associated anyway since this was the required driver
6238 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
6240 * In order to not bother drivers with this quirk in the API
6241 * set the flags in both the mask and set for new stations in
6244 if (!(params.sta_flags_mask & auth_assoc)) {
6245 params.sta_flags_mask |= auth_assoc;
6246 params.sta_flags_set |= auth_assoc;
6249 /* must be last in here for error handling */
6250 params.vlan = get_vlan(info, rdev);
6251 if (IS_ERR(params.vlan))
6252 return PTR_ERR(params.vlan);
6254 case NL80211_IFTYPE_MESH_POINT:
6255 /* ignore uAPSD data */
6256 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6258 /* associated is disallowed */
6259 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
6261 /* TDLS peers cannot be added */
6262 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6263 info->attrs[NL80211_ATTR_PEER_AID])
6266 case NL80211_IFTYPE_STATION:
6267 case NL80211_IFTYPE_P2P_CLIENT:
6268 /* ignore uAPSD data */
6269 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6271 /* these are disallowed */
6272 if (params.sta_flags_mask &
6273 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
6274 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
6276 /* Only TDLS peers can be added */
6277 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6279 /* Can only add if TDLS ... */
6280 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
6282 /* ... with external setup is supported */
6283 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
6286 * Older wpa_supplicant versions always mark the TDLS peer
6287 * as authorized, but it shouldn't yet be.
6289 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
6295 /* be aware of params.vlan when changing code here */
6297 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
6300 dev_put(params.vlan);
6304 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
6306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6307 struct net_device *dev = info->user_ptr[1];
6308 struct station_del_parameters params;
6310 memset(¶ms, 0, sizeof(params));
6312 if (info->attrs[NL80211_ATTR_MAC])
6313 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
6315 switch (dev->ieee80211_ptr->iftype) {
6316 case NL80211_IFTYPE_AP:
6317 case NL80211_IFTYPE_AP_VLAN:
6318 case NL80211_IFTYPE_MESH_POINT:
6319 case NL80211_IFTYPE_P2P_GO:
6320 /* always accept these */
6322 case NL80211_IFTYPE_ADHOC:
6323 /* conditionally accept */
6324 if (wiphy_ext_feature_isset(&rdev->wiphy,
6325 NL80211_EXT_FEATURE_DEL_IBSS_STA))
6332 if (!rdev->ops->del_station)
6335 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
6337 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
6338 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
6339 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
6342 /* Default to Deauthentication frame */
6343 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
6346 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
6347 params.reason_code =
6348 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6349 if (params.reason_code == 0)
6350 return -EINVAL; /* 0 is reserved */
6352 /* Default to reason code 2 */
6353 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
6356 return rdev_del_station(rdev, dev, ¶ms);
6359 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
6360 int flags, struct net_device *dev,
6361 u8 *dst, u8 *next_hop,
6362 struct mpath_info *pinfo)
6365 struct nlattr *pinfoattr;
6367 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
6371 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6372 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
6373 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
6374 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
6375 goto nla_put_failure;
6377 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
6379 goto nla_put_failure;
6380 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
6381 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
6383 goto nla_put_failure;
6384 if (((pinfo->filled & MPATH_INFO_SN) &&
6385 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
6386 ((pinfo->filled & MPATH_INFO_METRIC) &&
6387 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
6389 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
6390 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
6392 ((pinfo->filled & MPATH_INFO_FLAGS) &&
6393 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
6395 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
6396 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
6397 pinfo->discovery_timeout)) ||
6398 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
6399 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
6400 pinfo->discovery_retries)) ||
6401 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6402 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
6403 pinfo->hop_count)) ||
6404 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
6405 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
6406 pinfo->path_change_count)))
6407 goto nla_put_failure;
6409 nla_nest_end(msg, pinfoattr);
6411 genlmsg_end(msg, hdr);
6415 genlmsg_cancel(msg, hdr);
6419 static int nl80211_dump_mpath(struct sk_buff *skb,
6420 struct netlink_callback *cb)
6422 struct mpath_info pinfo;
6423 struct cfg80211_registered_device *rdev;
6424 struct wireless_dev *wdev;
6426 u8 next_hop[ETH_ALEN];
6427 int path_idx = cb->args[2];
6431 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
6435 if (!rdev->ops->dump_mpath) {
6440 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6446 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
6453 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6454 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6455 wdev->netdev, dst, next_hop,
6463 cb->args[2] = path_idx;
6470 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6474 struct net_device *dev = info->user_ptr[1];
6475 struct mpath_info pinfo;
6476 struct sk_buff *msg;
6478 u8 next_hop[ETH_ALEN];
6480 memset(&pinfo, 0, sizeof(pinfo));
6482 if (!info->attrs[NL80211_ATTR_MAC])
6485 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6487 if (!rdev->ops->get_mpath)
6490 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6493 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
6497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6501 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6502 dev, dst, next_hop, &pinfo) < 0) {
6507 return genlmsg_reply(msg, info);
6510 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6513 struct net_device *dev = info->user_ptr[1];
6515 u8 *next_hop = NULL;
6517 if (!info->attrs[NL80211_ATTR_MAC])
6520 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6523 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6524 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6526 if (!rdev->ops->change_mpath)
6529 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6532 return rdev_change_mpath(rdev, dev, dst, next_hop);
6535 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6538 struct net_device *dev = info->user_ptr[1];
6540 u8 *next_hop = NULL;
6542 if (!info->attrs[NL80211_ATTR_MAC])
6545 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6548 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6549 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6551 if (!rdev->ops->add_mpath)
6554 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6557 return rdev_add_mpath(rdev, dev, dst, next_hop);
6560 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6563 struct net_device *dev = info->user_ptr[1];
6566 if (info->attrs[NL80211_ATTR_MAC])
6567 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6569 if (!rdev->ops->del_mpath)
6572 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6575 return rdev_del_mpath(rdev, dev, dst);
6578 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6582 struct net_device *dev = info->user_ptr[1];
6583 struct mpath_info pinfo;
6584 struct sk_buff *msg;
6588 memset(&pinfo, 0, sizeof(pinfo));
6590 if (!info->attrs[NL80211_ATTR_MAC])
6593 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6595 if (!rdev->ops->get_mpp)
6598 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6601 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6605 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6609 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6610 dev, dst, mpp, &pinfo) < 0) {
6615 return genlmsg_reply(msg, info);
6618 static int nl80211_dump_mpp(struct sk_buff *skb,
6619 struct netlink_callback *cb)
6621 struct mpath_info pinfo;
6622 struct cfg80211_registered_device *rdev;
6623 struct wireless_dev *wdev;
6626 int path_idx = cb->args[2];
6630 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
6634 if (!rdev->ops->dump_mpp) {
6639 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6645 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6652 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6653 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6654 wdev->netdev, dst, mpp,
6662 cb->args[2] = path_idx;
6669 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6672 struct net_device *dev = info->user_ptr[1];
6673 struct wireless_dev *wdev = dev->ieee80211_ptr;
6674 struct bss_parameters params;
6677 memset(¶ms, 0, sizeof(params));
6678 /* default to not changing parameters */
6679 params.use_cts_prot = -1;
6680 params.use_short_preamble = -1;
6681 params.use_short_slot_time = -1;
6682 params.ap_isolate = -1;
6683 params.ht_opmode = -1;
6684 params.p2p_ctwindow = -1;
6685 params.p2p_opp_ps = -1;
6687 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6688 params.use_cts_prot =
6689 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6690 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6691 params.use_short_preamble =
6692 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6693 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6694 params.use_short_slot_time =
6695 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
6696 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6697 params.basic_rates =
6698 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6699 params.basic_rates_len =
6700 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6702 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6703 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
6704 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6706 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
6708 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6709 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6711 params.p2p_ctwindow =
6712 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
6713 if (params.p2p_ctwindow != 0 &&
6714 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6718 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6721 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6723 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
6724 params.p2p_opp_ps = tmp;
6725 if (params.p2p_opp_ps &&
6726 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6730 if (!rdev->ops->change_bss)
6733 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6734 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6738 err = rdev_change_bss(rdev, dev, ¶ms);
6744 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6748 enum nl80211_user_reg_hint_type user_reg_hint_type;
6752 * You should only get this when cfg80211 hasn't yet initialized
6753 * completely when built-in to the kernel right between the time
6754 * window between nl80211_init() and regulatory_init(), if that is
6757 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
6758 return -EINPROGRESS;
6760 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6761 user_reg_hint_type =
6762 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6764 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6766 switch (user_reg_hint_type) {
6767 case NL80211_USER_REG_HINT_USER:
6768 case NL80211_USER_REG_HINT_CELL_BASE:
6769 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6772 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6773 return regulatory_hint_user(data, user_reg_hint_type);
6774 case NL80211_USER_REG_HINT_INDOOR:
6775 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6776 owner_nlportid = info->snd_portid;
6777 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6783 return regulatory_hint_indoor(is_indoor, owner_nlportid);
6789 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6791 return reg_reload_regdb();
6794 static int nl80211_get_mesh_config(struct sk_buff *skb,
6795 struct genl_info *info)
6797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6798 struct net_device *dev = info->user_ptr[1];
6799 struct wireless_dev *wdev = dev->ieee80211_ptr;
6800 struct mesh_config cur_params;
6803 struct nlattr *pinfoattr;
6804 struct sk_buff *msg;
6806 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6809 if (!rdev->ops->get_mesh_config)
6813 /* If not connected, get default parameters */
6814 if (!wdev->mesh_id_len)
6815 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6817 err = rdev_get_mesh_config(rdev, dev, &cur_params);
6823 /* Draw up a netlink message to send back */
6824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6827 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6828 NL80211_CMD_GET_MESH_CONFIG);
6831 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
6833 goto nla_put_failure;
6834 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6835 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6836 cur_params.dot11MeshRetryTimeout) ||
6837 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6838 cur_params.dot11MeshConfirmTimeout) ||
6839 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6840 cur_params.dot11MeshHoldingTimeout) ||
6841 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6842 cur_params.dot11MeshMaxPeerLinks) ||
6843 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6844 cur_params.dot11MeshMaxRetries) ||
6845 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6846 cur_params.dot11MeshTTL) ||
6847 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6848 cur_params.element_ttl) ||
6849 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6850 cur_params.auto_open_plinks) ||
6851 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6852 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
6853 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6854 cur_params.dot11MeshHWMPmaxPREQretries) ||
6855 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6856 cur_params.path_refresh_time) ||
6857 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6858 cur_params.min_discovery_timeout) ||
6859 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6860 cur_params.dot11MeshHWMPactivePathTimeout) ||
6861 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6862 cur_params.dot11MeshHWMPpreqMinInterval) ||
6863 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6864 cur_params.dot11MeshHWMPperrMinInterval) ||
6865 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6866 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6867 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6868 cur_params.dot11MeshHWMPRootMode) ||
6869 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6870 cur_params.dot11MeshHWMPRannInterval) ||
6871 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6872 cur_params.dot11MeshGateAnnouncementProtocol) ||
6873 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6874 cur_params.dot11MeshForwarding) ||
6875 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
6876 cur_params.rssi_threshold) ||
6877 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
6878 cur_params.ht_opmode) ||
6879 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6880 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6881 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6882 cur_params.dot11MeshHWMProotInterval) ||
6883 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
6884 cur_params.dot11MeshHWMPconfirmationInterval) ||
6885 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6886 cur_params.power_mode) ||
6887 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
6888 cur_params.dot11MeshAwakeWindowDuration) ||
6889 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
6890 cur_params.plink_timeout) ||
6891 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6892 cur_params.dot11MeshConnectedToMeshGate) ||
6893 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN,
6894 cur_params.dot11MeshNolearn) ||
6895 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS,
6896 cur_params.dot11MeshConnectedToAuthServer))
6897 goto nla_put_failure;
6898 nla_nest_end(msg, pinfoattr);
6899 genlmsg_end(msg, hdr);
6900 return genlmsg_reply(msg, info);
6908 static const struct nla_policy
6909 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6910 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6911 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6912 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6913 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6914 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6915 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6916 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6917 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6918 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6919 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6920 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6921 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6922 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6923 NLA_POLICY_RANGE(NLA_U32, 1, 255),
6924 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6925 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
6926 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
6927 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
6928 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6929 NLA_POLICY_MIN(NLA_U16, 1),
6930 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6931 NLA_POLICY_MIN(NLA_U16, 1),
6932 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6933 NLA_POLICY_MIN(NLA_U16, 1),
6934 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6935 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6936 NLA_POLICY_MIN(NLA_U16, 1),
6937 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6938 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6939 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6940 NLA_POLICY_RANGE(NLA_S32, -255, 0),
6941 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
6942 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
6943 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6944 NLA_POLICY_MIN(NLA_U16, 1),
6945 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6946 NLA_POLICY_MIN(NLA_U16, 1),
6947 [NL80211_MESHCONF_POWER_MODE] =
6948 NLA_POLICY_RANGE(NLA_U32,
6949 NL80211_MESH_POWER_ACTIVE,
6950 NL80211_MESH_POWER_MAX),
6951 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
6952 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
6953 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
6954 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
6955 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
6958 static const struct nla_policy
6959 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
6960 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
6961 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6962 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
6963 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
6964 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
6965 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
6966 [NL80211_MESH_SETUP_IE] =
6967 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6968 IEEE80211_MAX_DATA_LEN),
6969 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
6972 static int nl80211_parse_mesh_config(struct genl_info *info,
6973 struct mesh_config *cfg,
6976 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
6980 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6983 cfg->param = fn(tb[attr]); \
6984 mask |= BIT((attr) - 1); \
6988 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
6990 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
6993 /* This makes sure that there aren't more than 32 mesh config
6994 * parameters (otherwise our bitfield scheme would not work.) */
6995 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6997 /* Fill in the params struct */
6998 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6999 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
7000 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
7001 NL80211_MESHCONF_CONFIRM_TIMEOUT,
7003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
7004 NL80211_MESHCONF_HOLDING_TIMEOUT,
7006 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
7007 NL80211_MESHCONF_MAX_PEER_LINKS,
7009 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
7010 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
7011 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
7012 NL80211_MESHCONF_TTL, nla_get_u8);
7013 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
7014 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
7015 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
7016 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
7018 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
7020 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
7022 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
7023 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
7025 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
7026 NL80211_MESHCONF_PATH_REFRESH_TIME,
7028 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
7029 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
7031 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
7032 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
7034 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
7036 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
7038 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
7039 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
7040 cfg->dot11MeshHWMPactivePathTimeout > 65535))
7042 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
7043 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
7045 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
7046 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
7048 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
7049 dot11MeshHWMPnetDiameterTraversalTime, mask,
7050 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
7052 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
7053 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
7054 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
7055 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
7057 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
7058 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
7060 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
7061 NL80211_MESHCONF_FORWARDING, nla_get_u8);
7062 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
7063 NL80211_MESHCONF_RSSI_THRESHOLD,
7065 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
7066 NL80211_MESHCONF_CONNECTED_TO_GATE,
7068 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask,
7069 NL80211_MESHCONF_CONNECTED_TO_AS,
7072 * Check HT operation mode based on
7073 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
7075 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
7076 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
7078 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
7079 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
7080 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
7083 /* NON_HT_STA bit is reserved, but some programs set it */
7084 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
7086 cfg->ht_opmode = ht_opmode;
7087 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
7089 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
7090 dot11MeshHWMPactivePathToRootTimeout, mask,
7091 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
7093 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
7094 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
7095 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
7097 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
7098 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
7100 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
7102 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
7104 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
7105 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
7106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
7107 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
7108 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
7109 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
7110 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask,
7111 NL80211_MESHCONF_NOLEARN, nla_get_u8);
7117 #undef FILL_IN_MESH_PARAM_IF_SET
7120 static int nl80211_parse_mesh_setup(struct genl_info *info,
7121 struct mesh_setup *setup)
7123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7124 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
7126 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
7128 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack))
7131 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
7132 setup->sync_method =
7133 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
7134 IEEE80211_SYNC_METHOD_VENDOR :
7135 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
7137 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
7138 setup->path_sel_proto =
7139 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
7140 IEEE80211_PATH_PROTOCOL_VENDOR :
7141 IEEE80211_PATH_PROTOCOL_HWMP;
7143 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
7144 setup->path_metric =
7145 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
7146 IEEE80211_PATH_METRIC_VENDOR :
7147 IEEE80211_PATH_METRIC_AIRTIME;
7149 if (tb[NL80211_MESH_SETUP_IE]) {
7150 struct nlattr *ieattr =
7151 tb[NL80211_MESH_SETUP_IE];
7152 setup->ie = nla_data(ieattr);
7153 setup->ie_len = nla_len(ieattr);
7155 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
7156 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
7158 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
7159 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
7160 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
7161 if (setup->is_secure)
7162 setup->user_mpm = true;
7164 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
7165 if (!setup->user_mpm)
7168 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
7174 static int nl80211_update_mesh_config(struct sk_buff *skb,
7175 struct genl_info *info)
7177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7178 struct net_device *dev = info->user_ptr[1];
7179 struct wireless_dev *wdev = dev->ieee80211_ptr;
7180 struct mesh_config cfg;
7184 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7187 if (!rdev->ops->update_mesh_config)
7190 err = nl80211_parse_mesh_config(info, &cfg, &mask);
7195 if (!wdev->mesh_id_len)
7199 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
7206 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
7207 struct sk_buff *msg)
7209 struct nlattr *nl_reg_rules;
7212 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
7213 (regdom->dfs_region &&
7214 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
7215 goto nla_put_failure;
7217 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
7219 goto nla_put_failure;
7221 for (i = 0; i < regdom->n_reg_rules; i++) {
7222 struct nlattr *nl_reg_rule;
7223 const struct ieee80211_reg_rule *reg_rule;
7224 const struct ieee80211_freq_range *freq_range;
7225 const struct ieee80211_power_rule *power_rule;
7226 unsigned int max_bandwidth_khz;
7228 reg_rule = ®dom->reg_rules[i];
7229 freq_range = ®_rule->freq_range;
7230 power_rule = ®_rule->power_rule;
7232 nl_reg_rule = nla_nest_start_noflag(msg, i);
7234 goto nla_put_failure;
7236 max_bandwidth_khz = freq_range->max_bandwidth_khz;
7237 if (!max_bandwidth_khz)
7238 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
7241 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
7243 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
7244 freq_range->start_freq_khz) ||
7245 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
7246 freq_range->end_freq_khz) ||
7247 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
7248 max_bandwidth_khz) ||
7249 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
7250 power_rule->max_antenna_gain) ||
7251 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
7252 power_rule->max_eirp) ||
7253 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
7254 reg_rule->dfs_cac_ms))
7255 goto nla_put_failure;
7257 nla_nest_end(msg, nl_reg_rule);
7260 nla_nest_end(msg, nl_reg_rules);
7267 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
7269 const struct ieee80211_regdomain *regdom = NULL;
7270 struct cfg80211_registered_device *rdev;
7271 struct wiphy *wiphy = NULL;
7272 struct sk_buff *msg;
7275 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7279 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7280 NL80211_CMD_GET_REG);
7284 if (info->attrs[NL80211_ATTR_WIPHY]) {
7287 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7290 return PTR_ERR(rdev);
7293 wiphy = &rdev->wiphy;
7294 self_managed = wiphy->regulatory_flags &
7295 REGULATORY_WIPHY_SELF_MANAGED;
7296 regdom = get_wiphy_regdom(wiphy);
7298 /* a self-managed-reg device must have a private regdom */
7299 if (WARN_ON(!regdom && self_managed)) {
7305 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7306 goto nla_put_failure;
7309 if (!wiphy && reg_last_request_cell_base() &&
7310 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7311 NL80211_USER_REG_HINT_CELL_BASE))
7312 goto nla_put_failure;
7317 regdom = rcu_dereference(cfg80211_regdomain);
7319 if (nl80211_put_regdom(regdom, msg))
7320 goto nla_put_failure_rcu;
7324 genlmsg_end(msg, hdr);
7325 return genlmsg_reply(msg, info);
7327 nla_put_failure_rcu:
7335 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
7336 u32 seq, int flags, struct wiphy *wiphy,
7337 const struct ieee80211_regdomain *regdom)
7339 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
7340 NL80211_CMD_GET_REG);
7345 genl_dump_check_consistent(cb, hdr);
7347 if (nl80211_put_regdom(regdom, msg))
7348 goto nla_put_failure;
7350 if (!wiphy && reg_last_request_cell_base() &&
7351 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7352 NL80211_USER_REG_HINT_CELL_BASE))
7353 goto nla_put_failure;
7356 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7357 goto nla_put_failure;
7359 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
7360 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
7361 goto nla_put_failure;
7363 genlmsg_end(msg, hdr);
7367 genlmsg_cancel(msg, hdr);
7371 static int nl80211_get_reg_dump(struct sk_buff *skb,
7372 struct netlink_callback *cb)
7374 const struct ieee80211_regdomain *regdom = NULL;
7375 struct cfg80211_registered_device *rdev;
7376 int err, reg_idx, start = cb->args[2];
7380 if (cfg80211_regdomain && start == 0) {
7381 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7383 rtnl_dereference(cfg80211_regdomain));
7388 /* the global regdom is idx 0 */
7390 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7391 regdom = get_wiphy_regdom(&rdev->wiphy);
7395 if (++reg_idx <= start)
7398 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7399 NLM_F_MULTI, &rdev->wiphy, regdom);
7406 cb->args[2] = reg_idx;
7413 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
7414 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
7415 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
7416 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
7417 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
7418 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
7419 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
7420 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
7421 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
7424 static int parse_reg_rule(struct nlattr *tb[],
7425 struct ieee80211_reg_rule *reg_rule)
7427 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
7428 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
7430 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
7432 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
7434 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
7436 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
7438 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
7441 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
7443 freq_range->start_freq_khz =
7444 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
7445 freq_range->end_freq_khz =
7446 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7447 freq_range->max_bandwidth_khz =
7448 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7450 power_rule->max_eirp =
7451 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7453 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7454 power_rule->max_antenna_gain =
7455 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7457 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7458 reg_rule->dfs_cac_ms =
7459 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7464 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7466 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7467 struct nlattr *nl_reg_rule;
7469 int rem_reg_rules, r;
7470 u32 num_rules = 0, rule_idx = 0;
7471 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
7472 struct ieee80211_regdomain *rd;
7474 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7477 if (!info->attrs[NL80211_ATTR_REG_RULES])
7480 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7482 if (info->attrs[NL80211_ATTR_DFS_REGION])
7483 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7485 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
7488 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
7492 if (!reg_is_valid_request(alpha2))
7495 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
7499 rd->n_reg_rules = num_rules;
7500 rd->alpha2[0] = alpha2[0];
7501 rd->alpha2[1] = alpha2[1];
7504 * Disable DFS master mode if the DFS region was
7505 * not supported or known on this kernel.
7507 if (reg_supported_dfs_region(dfs_region))
7508 rd->dfs_region = dfs_region;
7510 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
7512 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7513 nl_reg_rule, reg_rule_policy,
7517 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7523 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7529 /* set_regdom takes ownership of rd */
7530 return set_regdom(rd, REGD_SOURCE_CRDA);
7535 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
7537 static int validate_scan_freqs(struct nlattr *freqs)
7539 struct nlattr *attr1, *attr2;
7540 int n_channels = 0, tmp1, tmp2;
7542 nla_for_each_nested(attr1, freqs, tmp1)
7543 if (nla_len(attr1) != sizeof(u32))
7546 nla_for_each_nested(attr1, freqs, tmp1) {
7549 * Some hardware has a limited channel list for
7550 * scanning, and it is pretty much nonsensical
7551 * to scan for a channel twice, so disallow that
7552 * and don't require drivers to check that the
7553 * channel list they get isn't longer than what
7554 * they can scan, as long as they can scan all
7555 * the channels they registered at once.
7557 nla_for_each_nested(attr2, freqs, tmp2)
7558 if (attr1 != attr2 &&
7559 nla_get_u32(attr1) == nla_get_u32(attr2))
7566 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
7568 return b < NUM_NL80211_BANDS && wiphy->bands[b];
7571 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7572 struct cfg80211_bss_selection *bss_select)
7574 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7575 struct nlattr *nest;
7580 /* only process one nested attribute */
7581 nest = nla_data(nla);
7582 if (!nla_ok(nest, nla_len(nest)))
7585 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7586 nest, nl80211_bss_select_policy,
7591 /* only one attribute may be given */
7592 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7600 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7602 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7603 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7605 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7606 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7607 bss_select->param.band_pref =
7608 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7609 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7613 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7614 struct nl80211_bss_select_rssi_adjust *adj_param;
7616 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7617 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7618 bss_select->param.adjust.band = adj_param->band;
7619 bss_select->param.adjust.delta = adj_param->delta;
7620 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7624 /* user-space did not provide behaviour attribute */
7625 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7628 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7634 int nl80211_parse_random_mac(struct nlattr **attrs,
7635 u8 *mac_addr, u8 *mac_addr_mask)
7639 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
7640 eth_zero_addr(mac_addr);
7641 eth_zero_addr(mac_addr_mask);
7643 mac_addr_mask[0] = 0x3;
7648 /* need both or none */
7649 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7652 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7653 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7655 /* don't allow or configure an mcast address */
7656 if (!is_multicast_ether_addr(mac_addr_mask) ||
7657 is_multicast_ether_addr(mac_addr))
7661 * allow users to pass a MAC address that has bits set outside
7662 * of the mask, but don't bother drivers with having to deal
7665 for (i = 0; i < ETH_ALEN; i++)
7666 mac_addr[i] &= mac_addr_mask[i];
7671 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7673 ASSERT_WDEV_LOCK(wdev);
7675 if (!cfg80211_beaconing_iface_active(wdev))
7678 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7681 return regulatory_pre_cac_allowed(wdev->wiphy);
7684 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7685 enum nl80211_ext_feature_index feat)
7687 if (!(flags & flag))
7689 if (wiphy_ext_feature_isset(wiphy, feat))
7695 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7696 void *request, struct nlattr **attrs,
7699 u8 *mac_addr, *mac_addr_mask;
7701 enum nl80211_feature_flags randomness_flag;
7703 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7706 if (is_sched_scan) {
7707 struct cfg80211_sched_scan_request *req = request;
7709 randomness_flag = wdev ?
7710 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7711 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7712 flags = &req->flags;
7713 mac_addr = req->mac_addr;
7714 mac_addr_mask = req->mac_addr_mask;
7716 struct cfg80211_scan_request *req = request;
7718 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7719 flags = &req->flags;
7720 mac_addr = req->mac_addr;
7721 mac_addr_mask = req->mac_addr_mask;
7724 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7726 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7727 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
7728 !nl80211_check_scan_feat(wiphy, *flags,
7729 NL80211_SCAN_FLAG_LOW_SPAN,
7730 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7731 !nl80211_check_scan_feat(wiphy, *flags,
7732 NL80211_SCAN_FLAG_LOW_POWER,
7733 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7734 !nl80211_check_scan_feat(wiphy, *flags,
7735 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7736 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7737 !nl80211_check_scan_feat(wiphy, *flags,
7738 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7739 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7740 !nl80211_check_scan_feat(wiphy, *flags,
7741 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7742 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7743 !nl80211_check_scan_feat(wiphy, *flags,
7744 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7745 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7746 !nl80211_check_scan_feat(wiphy, *flags,
7747 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
7748 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7749 !nl80211_check_scan_feat(wiphy, *flags,
7750 NL80211_SCAN_FLAG_RANDOM_SN,
7751 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7752 !nl80211_check_scan_feat(wiphy, *flags,
7753 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7754 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
7757 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7760 if (!(wiphy->features & randomness_flag) ||
7761 (wdev && wdev->current_bss))
7764 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7772 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7775 struct wireless_dev *wdev = info->user_ptr[1];
7776 struct cfg80211_scan_request *request;
7777 struct nlattr *scan_freqs = NULL;
7778 bool scan_freqs_khz = false;
7779 struct nlattr *attr;
7780 struct wiphy *wiphy;
7781 int err, tmp, n_ssids = 0, n_channels, i;
7784 wiphy = &rdev->wiphy;
7786 if (wdev->iftype == NL80211_IFTYPE_NAN)
7789 if (!rdev->ops->scan)
7792 if (rdev->scan_req || rdev->scan_msg)
7795 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) {
7796 if (!wiphy_ext_feature_isset(wiphy,
7797 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ))
7799 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ];
7800 scan_freqs_khz = true;
7801 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES])
7802 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES];
7805 n_channels = validate_scan_freqs(scan_freqs);
7809 n_channels = ieee80211_get_num_supported_channels(wiphy);
7812 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7813 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7816 if (n_ssids > wiphy->max_scan_ssids)
7819 if (info->attrs[NL80211_ATTR_IE])
7820 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7824 if (ie_len > wiphy->max_scan_ie_len)
7827 request = kzalloc(sizeof(*request)
7828 + sizeof(*request->ssids) * n_ssids
7829 + sizeof(*request->channels) * n_channels
7830 + ie_len, GFP_KERNEL);
7835 request->ssids = (void *)&request->channels[n_channels];
7836 request->n_ssids = n_ssids;
7839 request->ie = (void *)(request->ssids + n_ssids);
7841 request->ie = (void *)(request->channels + n_channels);
7846 /* user specified, bail out if channel not found */
7847 nla_for_each_nested(attr, scan_freqs, tmp) {
7848 struct ieee80211_channel *chan;
7849 int freq = nla_get_u32(attr);
7851 if (!scan_freqs_khz)
7852 freq = MHZ_TO_KHZ(freq);
7854 chan = ieee80211_get_channel_khz(wiphy, freq);
7860 /* ignore disabled channels */
7861 if (chan->flags & IEEE80211_CHAN_DISABLED)
7864 request->channels[i] = chan;
7868 enum nl80211_band band;
7871 for (band = 0; band < NUM_NL80211_BANDS; band++) {
7874 if (!wiphy->bands[band])
7876 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7877 struct ieee80211_channel *chan;
7879 chan = &wiphy->bands[band]->channels[j];
7881 if (chan->flags & IEEE80211_CHAN_DISABLED)
7884 request->channels[i] = chan;
7895 request->n_channels = i;
7898 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7899 struct ieee80211_channel *chan;
7901 if (request->n_channels != 1) {
7907 chan = request->channels[0];
7908 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7918 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
7919 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
7923 request->ssids[i].ssid_len = nla_len(attr);
7924 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
7929 if (info->attrs[NL80211_ATTR_IE]) {
7930 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7931 memcpy((void *)request->ie,
7932 nla_data(info->attrs[NL80211_ATTR_IE]),
7936 for (i = 0; i < NUM_NL80211_BANDS; i++)
7937 if (wiphy->bands[i])
7939 (1 << wiphy->bands[i]->n_bitrates) - 1;
7941 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7942 nla_for_each_nested(attr,
7943 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7945 enum nl80211_band band = nla_type(attr);
7947 if (band < 0 || band >= NUM_NL80211_BANDS) {
7952 if (!wiphy->bands[band])
7955 err = ieee80211_get_ratemask(wiphy->bands[band],
7958 &request->rates[band]);
7964 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7965 if (!wiphy_ext_feature_isset(wiphy,
7966 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7972 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7973 request->duration_mandatory =
7974 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7977 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7983 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7985 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7986 * BSSID to scan for. This was problematic because that same attribute
7987 * was already used for another purpose (local random MAC address). The
7988 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7989 * compatibility with older userspace components, also use the
7990 * NL80211_ATTR_MAC value here if it can be determined to be used for
7991 * the specific BSSID use case instead of the random MAC address
7992 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7994 if (info->attrs[NL80211_ATTR_BSSID])
7995 memcpy(request->bssid,
7996 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7997 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7998 info->attrs[NL80211_ATTR_MAC])
7999 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
8002 eth_broadcast_addr(request->bssid);
8004 request->wdev = wdev;
8005 request->wiphy = &rdev->wiphy;
8006 request->scan_start = jiffies;
8008 rdev->scan_req = request;
8009 err = rdev_scan(rdev, request);
8014 nl80211_send_scan_start(rdev, wdev);
8016 dev_hold(wdev->netdev);
8021 rdev->scan_req = NULL;
8027 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
8029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8030 struct wireless_dev *wdev = info->user_ptr[1];
8032 if (!rdev->ops->abort_scan)
8038 if (!rdev->scan_req)
8041 rdev_abort_scan(rdev, wdev);
8046 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
8047 struct cfg80211_sched_scan_request *request,
8048 struct nlattr **attrs)
8050 int tmp, err, i = 0;
8051 struct nlattr *attr;
8053 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
8057 * If scan plans are not specified,
8058 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
8059 * case one scan plan will be set with the specified scan
8060 * interval and infinite number of iterations.
8062 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
8066 request->scan_plans[0].interval =
8067 DIV_ROUND_UP(interval, MSEC_PER_SEC);
8068 if (!request->scan_plans[0].interval)
8071 if (request->scan_plans[0].interval >
8072 wiphy->max_sched_scan_plan_interval)
8073 request->scan_plans[0].interval =
8074 wiphy->max_sched_scan_plan_interval;
8079 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
8080 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
8082 if (WARN_ON(i >= n_plans))
8085 err = nla_parse_nested_deprecated(plan,
8086 NL80211_SCHED_SCAN_PLAN_MAX,
8087 attr, nl80211_plan_policy,
8092 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
8095 request->scan_plans[i].interval =
8096 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
8097 if (!request->scan_plans[i].interval ||
8098 request->scan_plans[i].interval >
8099 wiphy->max_sched_scan_plan_interval)
8102 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
8103 request->scan_plans[i].iterations =
8104 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
8105 if (!request->scan_plans[i].iterations ||
8106 (request->scan_plans[i].iterations >
8107 wiphy->max_sched_scan_plan_iterations))
8109 } else if (i < n_plans - 1) {
8111 * All scan plans but the last one must specify
8112 * a finite number of iterations
8121 * The last scan plan must not specify the number of
8122 * iterations, it is supposed to run infinitely
8124 if (request->scan_plans[n_plans - 1].iterations)
8131 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
8132 struct cfg80211_match_set *match_sets,
8133 struct nlattr *tb_band_rssi,
8136 struct nlattr *attr;
8137 int i, tmp, ret = 0;
8139 if (!wiphy_ext_feature_isset(wiphy,
8140 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
8144 for (i = 0; i < NUM_NL80211_BANDS; i++)
8145 match_sets->per_band_rssi_thold[i] =
8146 NL80211_SCAN_RSSI_THOLD_OFF;
8150 for (i = 0; i < NUM_NL80211_BANDS; i++)
8151 match_sets->per_band_rssi_thold[i] = rssi_thold;
8153 nla_for_each_nested(attr, tb_band_rssi, tmp) {
8154 enum nl80211_band band = nla_type(attr);
8156 if (band < 0 || band >= NUM_NL80211_BANDS)
8159 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
8165 static struct cfg80211_sched_scan_request *
8166 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
8167 struct nlattr **attrs, int max_match_sets)
8169 struct cfg80211_sched_scan_request *request;
8170 struct nlattr *attr;
8171 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
8172 enum nl80211_band band;
8174 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
8175 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
8177 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
8178 n_channels = validate_scan_freqs(
8179 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
8181 return ERR_PTR(-EINVAL);
8183 n_channels = ieee80211_get_num_supported_channels(wiphy);
8186 if (attrs[NL80211_ATTR_SCAN_SSIDS])
8187 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
8191 if (n_ssids > wiphy->max_sched_scan_ssids)
8192 return ERR_PTR(-EINVAL);
8195 * First, count the number of 'real' matchsets. Due to an issue with
8196 * the old implementation, matchsets containing only the RSSI attribute
8197 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
8198 * RSSI for all matchsets, rather than their own matchset for reporting
8199 * all APs with a strong RSSI. This is needed to be compatible with
8200 * older userspace that treated a matchset with only the RSSI as the
8201 * global RSSI for all other matchsets - if there are other matchsets.
8203 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
8204 nla_for_each_nested(attr,
8205 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
8207 struct nlattr *rssi;
8209 err = nla_parse_nested_deprecated(tb,
8210 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8212 nl80211_match_policy,
8215 return ERR_PTR(err);
8217 /* SSID and BSSID are mutually exclusive */
8218 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
8219 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
8220 return ERR_PTR(-EINVAL);
8222 /* add other standalone attributes here */
8223 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
8224 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
8228 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8230 default_match_rssi = nla_get_s32(rssi);
8234 /* However, if there's no other matchset, add the RSSI one */
8235 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
8238 if (n_match_sets > max_match_sets)
8239 return ERR_PTR(-EINVAL);
8241 if (attrs[NL80211_ATTR_IE])
8242 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
8246 if (ie_len > wiphy->max_sched_scan_ie_len)
8247 return ERR_PTR(-EINVAL);
8249 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
8251 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
8252 * each scan plan already specifies its own interval
8254 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8255 return ERR_PTR(-EINVAL);
8257 nla_for_each_nested(attr,
8258 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
8262 * The scan interval attribute is kept for backward
8263 * compatibility. If no scan plans are specified and sched scan
8264 * interval is specified, one scan plan will be set with this
8265 * scan interval and infinite number of iterations.
8267 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8268 return ERR_PTR(-EINVAL);
8273 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
8274 return ERR_PTR(-EINVAL);
8276 if (!wiphy_ext_feature_isset(
8277 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
8278 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
8279 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
8280 return ERR_PTR(-EINVAL);
8282 request = kzalloc(sizeof(*request)
8283 + sizeof(*request->ssids) * n_ssids
8284 + sizeof(*request->match_sets) * n_match_sets
8285 + sizeof(*request->scan_plans) * n_plans
8286 + sizeof(*request->channels) * n_channels
8287 + ie_len, GFP_KERNEL);
8289 return ERR_PTR(-ENOMEM);
8292 request->ssids = (void *)&request->channels[n_channels];
8293 request->n_ssids = n_ssids;
8296 request->ie = (void *)(request->ssids + n_ssids);
8298 request->ie = (void *)(request->channels + n_channels);
8303 request->match_sets = (void *)(request->ie + ie_len);
8305 request->match_sets =
8306 (void *)(request->ssids + n_ssids);
8308 request->match_sets =
8309 (void *)(request->channels + n_channels);
8311 request->n_match_sets = n_match_sets;
8314 request->scan_plans = (void *)(request->match_sets +
8316 else if (request->ie)
8317 request->scan_plans = (void *)(request->ie + ie_len);
8319 request->scan_plans = (void *)(request->ssids + n_ssids);
8321 request->scan_plans = (void *)(request->channels + n_channels);
8323 request->n_scan_plans = n_plans;
8326 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
8327 /* user specified, bail out if channel not found */
8328 nla_for_each_nested(attr,
8329 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
8331 struct ieee80211_channel *chan;
8333 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
8340 /* ignore disabled channels */
8341 if (chan->flags & IEEE80211_CHAN_DISABLED)
8344 request->channels[i] = chan;
8349 for (band = 0; band < NUM_NL80211_BANDS; band++) {
8352 if (!wiphy->bands[band])
8354 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8355 struct ieee80211_channel *chan;
8357 chan = &wiphy->bands[band]->channels[j];
8359 if (chan->flags & IEEE80211_CHAN_DISABLED)
8362 request->channels[i] = chan;
8373 request->n_channels = i;
8377 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
8379 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
8383 request->ssids[i].ssid_len = nla_len(attr);
8384 memcpy(request->ssids[i].ssid, nla_data(attr),
8391 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
8392 nla_for_each_nested(attr,
8393 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
8395 struct nlattr *ssid, *bssid, *rssi;
8397 err = nla_parse_nested_deprecated(tb,
8398 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8400 nl80211_match_policy,
8404 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
8405 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
8407 if (!ssid && !bssid) {
8412 if (WARN_ON(i >= n_match_sets)) {
8413 /* this indicates a programming error,
8414 * the loop above should have verified
8422 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
8426 memcpy(request->match_sets[i].ssid.ssid,
8427 nla_data(ssid), nla_len(ssid));
8428 request->match_sets[i].ssid.ssid_len =
8432 if (nla_len(bssid) != ETH_ALEN) {
8436 memcpy(request->match_sets[i].bssid,
8437 nla_data(bssid), ETH_ALEN);
8440 /* special attribute - old implementation w/a */
8441 request->match_sets[i].rssi_thold = default_match_rssi;
8442 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8444 request->match_sets[i].rssi_thold =
8447 /* Parse per band RSSI attribute */
8448 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
8449 &request->match_sets[i],
8450 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
8451 request->match_sets[i].rssi_thold);
8458 /* there was no other matchset, so the RSSI one is alone */
8459 if (i == 0 && n_match_sets)
8460 request->match_sets[0].rssi_thold = default_match_rssi;
8462 request->min_rssi_thold = INT_MAX;
8463 for (i = 0; i < n_match_sets; i++)
8464 request->min_rssi_thold =
8465 min(request->match_sets[i].rssi_thold,
8466 request->min_rssi_thold);
8468 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
8472 request->ie_len = ie_len;
8473 memcpy((void *)request->ie,
8474 nla_data(attrs[NL80211_ATTR_IE]),
8478 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8482 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8484 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8486 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8487 request->relative_rssi = nla_get_s8(
8488 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8489 request->relative_rssi_set = true;
8492 if (request->relative_rssi_set &&
8493 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8494 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8496 rssi_adjust = nla_data(
8497 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8498 request->rssi_adjust.band = rssi_adjust->band;
8499 request->rssi_adjust.delta = rssi_adjust->delta;
8500 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8506 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8510 request->scan_start = jiffies;
8516 return ERR_PTR(err);
8519 static int nl80211_start_sched_scan(struct sk_buff *skb,
8520 struct genl_info *info)
8522 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8523 struct net_device *dev = info->user_ptr[1];
8524 struct wireless_dev *wdev = dev->ieee80211_ptr;
8525 struct cfg80211_sched_scan_request *sched_scan_req;
8529 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
8532 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8533 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8537 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
8539 rdev->wiphy.max_match_sets);
8541 err = PTR_ERR_OR_ZERO(sched_scan_req);
8545 /* leave request id zero for legacy request
8546 * or if driver does not support multi-scheduled scan
8548 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
8549 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
8551 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
8555 sched_scan_req->dev = dev;
8556 sched_scan_req->wiphy = &rdev->wiphy;
8558 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8559 sched_scan_req->owner_nlportid = info->snd_portid;
8561 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
8563 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
8567 kfree(sched_scan_req);
8572 static int nl80211_stop_sched_scan(struct sk_buff *skb,
8573 struct genl_info *info)
8575 struct cfg80211_sched_scan_request *req;
8576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8579 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
8582 if (info->attrs[NL80211_ATTR_COOKIE]) {
8583 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8584 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8587 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8588 struct cfg80211_sched_scan_request,
8590 if (!req || req->reqid ||
8591 (req->owner_nlportid &&
8592 req->owner_nlportid != info->snd_portid))
8595 return cfg80211_stop_sched_scan_req(rdev, req, false);
8598 static int nl80211_start_radar_detection(struct sk_buff *skb,
8599 struct genl_info *info)
8601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8602 struct net_device *dev = info->user_ptr[1];
8603 struct wireless_dev *wdev = dev->ieee80211_ptr;
8604 struct wiphy *wiphy = wdev->wiphy;
8605 struct cfg80211_chan_def chandef;
8606 enum nl80211_dfs_regions dfs_region;
8607 unsigned int cac_time_ms;
8610 dfs_region = reg_get_dfs_region(wiphy);
8611 if (dfs_region == NL80211_DFS_UNSET)
8614 err = nl80211_parse_chandef(rdev, info, &chandef);
8618 if (netif_carrier_ok(dev))
8621 if (wdev->cac_started)
8624 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8631 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
8634 /* CAC start is offloaded to HW and can't be started manually */
8635 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8638 if (!rdev->ops->start_radar_detection)
8641 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8642 if (WARN_ON(!cac_time_ms))
8643 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8645 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
8647 wdev->chandef = chandef;
8648 wdev->cac_started = true;
8649 wdev->cac_start_time = jiffies;
8650 wdev->cac_time_ms = cac_time_ms;
8655 static int nl80211_notify_radar_detection(struct sk_buff *skb,
8656 struct genl_info *info)
8658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8659 struct net_device *dev = info->user_ptr[1];
8660 struct wireless_dev *wdev = dev->ieee80211_ptr;
8661 struct wiphy *wiphy = wdev->wiphy;
8662 struct cfg80211_chan_def chandef;
8663 enum nl80211_dfs_regions dfs_region;
8666 dfs_region = reg_get_dfs_region(wiphy);
8667 if (dfs_region == NL80211_DFS_UNSET) {
8668 GENL_SET_ERR_MSG(info,
8669 "DFS Region is not set. Unexpected Radar indication");
8673 err = nl80211_parse_chandef(rdev, info, &chandef);
8675 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8679 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8681 GENL_SET_ERR_MSG(info, "chandef is invalid");
8686 GENL_SET_ERR_MSG(info,
8687 "Unexpected Radar indication for chandef/iftype");
8691 /* Do not process this notification if radar is already detected
8692 * by kernel on this channel, and return success.
8694 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8697 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8699 cfg80211_sched_dfs_chan_update(rdev);
8701 rdev->radar_chandef = chandef;
8703 /* Propagate this notification to other radios as well */
8704 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8709 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8712 struct net_device *dev = info->user_ptr[1];
8713 struct wireless_dev *wdev = dev->ieee80211_ptr;
8714 struct cfg80211_csa_settings params;
8715 /* csa_attrs is defined static to avoid waste of stack size - this
8716 * function is called under RTNL lock, so this should not be a problem.
8718 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
8720 bool need_new_beacon = false;
8721 bool need_handle_dfs_flag = true;
8725 if (!rdev->ops->channel_switch ||
8726 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8729 switch (dev->ieee80211_ptr->iftype) {
8730 case NL80211_IFTYPE_AP:
8731 case NL80211_IFTYPE_P2P_GO:
8732 need_new_beacon = true;
8733 /* For all modes except AP the handle_dfs flag needs to be
8734 * supplied to tell the kernel that userspace will handle radar
8735 * events when they happen. Otherwise a switch to a channel
8736 * requiring DFS will be rejected.
8738 need_handle_dfs_flag = false;
8740 /* useless if AP is not running */
8741 if (!wdev->beacon_interval)
8744 case NL80211_IFTYPE_ADHOC:
8745 if (!wdev->ssid_len)
8748 case NL80211_IFTYPE_MESH_POINT:
8749 if (!wdev->mesh_id_len)
8756 memset(¶ms, 0, sizeof(params));
8757 params.beacon_csa.ftm_responder = -1;
8759 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8760 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8763 /* only important for AP, IBSS and mesh create IEs internally */
8764 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
8767 /* Even though the attribute is u32, the specification says
8768 * u8, so let's make sure we don't overflow.
8770 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8774 params.count = cs_count;
8776 if (!need_new_beacon)
8779 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after);
8783 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8784 info->attrs[NL80211_ATTR_CSA_IES],
8785 nl80211_policy, info->extack);
8789 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa);
8793 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8796 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8797 if (!len || (len % sizeof(u16)))
8800 params.n_counter_offsets_beacon = len / sizeof(u16);
8801 if (rdev->wiphy.max_num_csa_counters &&
8802 (params.n_counter_offsets_beacon >
8803 rdev->wiphy.max_num_csa_counters))
8806 params.counter_offsets_beacon =
8807 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8809 /* sanity checks - counters should fit and be the same */
8810 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8811 u16 offset = params.counter_offsets_beacon[i];
8813 if (offset >= params.beacon_csa.tail_len)
8816 if (params.beacon_csa.tail[offset] != params.count)
8820 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
8821 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8822 if (!len || (len % sizeof(u16)))
8825 params.n_counter_offsets_presp = len / sizeof(u16);
8826 if (rdev->wiphy.max_num_csa_counters &&
8827 (params.n_counter_offsets_presp >
8828 rdev->wiphy.max_num_csa_counters))
8831 params.counter_offsets_presp =
8832 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8834 /* sanity checks - counters should fit and be the same */
8835 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8836 u16 offset = params.counter_offsets_presp[i];
8838 if (offset >= params.beacon_csa.probe_resp_len)
8841 if (params.beacon_csa.probe_resp[offset] !=
8848 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
8852 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
8856 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8863 params.radar_required = true;
8864 if (need_handle_dfs_flag &&
8865 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8870 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8871 params.block_tx = true;
8874 err = rdev_channel_switch(rdev, dev, ¶ms);
8880 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8882 struct cfg80211_registered_device *rdev,
8883 struct wireless_dev *wdev,
8884 struct cfg80211_internal_bss *intbss)
8886 struct cfg80211_bss *res = &intbss->pub;
8887 const struct cfg80211_bss_ies *ies;
8891 ASSERT_WDEV_LOCK(wdev);
8893 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
8894 NL80211_CMD_NEW_SCAN_RESULTS);
8898 genl_dump_check_consistent(cb, hdr);
8900 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8901 goto nla_put_failure;
8903 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8904 goto nla_put_failure;
8905 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8907 goto nla_put_failure;
8909 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
8911 goto nla_put_failure;
8912 if ((!is_zero_ether_addr(res->bssid) &&
8913 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
8914 goto nla_put_failure;
8917 /* indicate whether we have probe response data or not */
8918 if (rcu_access_pointer(res->proberesp_ies) &&
8919 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8920 goto fail_unlock_rcu;
8922 /* this pointer prefers to be pointed to probe response data
8923 * but is always valid
8925 ies = rcu_dereference(res->ies);
8927 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8929 goto fail_unlock_rcu;
8930 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8931 ies->len, ies->data))
8932 goto fail_unlock_rcu;
8935 /* and this pointer is always (unless driver didn't know) beacon data */
8936 ies = rcu_dereference(res->beacon_ies);
8937 if (ies && ies->from_beacon) {
8938 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8940 goto fail_unlock_rcu;
8941 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8942 ies->len, ies->data))
8943 goto fail_unlock_rcu;
8947 if (res->beacon_interval &&
8948 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8949 goto nla_put_failure;
8950 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8951 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
8952 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET,
8953 res->channel->freq_offset) ||
8954 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
8955 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8956 jiffies_to_msecs(jiffies - intbss->ts)))
8957 goto nla_put_failure;
8959 if (intbss->parent_tsf &&
8960 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8961 intbss->parent_tsf, NL80211_BSS_PAD) ||
8962 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8963 intbss->parent_bssid)))
8964 goto nla_put_failure;
8966 if (intbss->ts_boottime &&
8967 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8968 intbss->ts_boottime, NL80211_BSS_PAD))
8969 goto nla_put_failure;
8971 if (!nl80211_put_signal(msg, intbss->pub.chains,
8972 intbss->pub.chain_signal,
8973 NL80211_BSS_CHAIN_SIGNAL))
8974 goto nla_put_failure;
8976 switch (rdev->wiphy.signal_type) {
8977 case CFG80211_SIGNAL_TYPE_MBM:
8978 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8979 goto nla_put_failure;
8981 case CFG80211_SIGNAL_TYPE_UNSPEC:
8982 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8983 goto nla_put_failure;
8989 switch (wdev->iftype) {
8990 case NL80211_IFTYPE_P2P_CLIENT:
8991 case NL80211_IFTYPE_STATION:
8992 if (intbss == wdev->current_bss &&
8993 nla_put_u32(msg, NL80211_BSS_STATUS,
8994 NL80211_BSS_STATUS_ASSOCIATED))
8995 goto nla_put_failure;
8997 case NL80211_IFTYPE_ADHOC:
8998 if (intbss == wdev->current_bss &&
8999 nla_put_u32(msg, NL80211_BSS_STATUS,
9000 NL80211_BSS_STATUS_IBSS_JOINED))
9001 goto nla_put_failure;
9007 nla_nest_end(msg, bss);
9009 genlmsg_end(msg, hdr);
9015 genlmsg_cancel(msg, hdr);
9019 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
9021 struct cfg80211_registered_device *rdev;
9022 struct cfg80211_internal_bss *scan;
9023 struct wireless_dev *wdev;
9024 int start = cb->args[2], idx = 0;
9028 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
9035 spin_lock_bh(&rdev->bss_lock);
9038 * dump_scan will be called multiple times to break up the scan results
9039 * into multiple messages. It is unlikely that any more bss-es will be
9040 * expired after the first call, so only call only call this on the
9041 * first dump_scan invocation.
9044 cfg80211_bss_expire(rdev);
9046 cb->seq = rdev->bss_generation;
9048 list_for_each_entry(scan, &rdev->bss_list, list) {
9051 if (nl80211_send_bss(skb, cb,
9052 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9053 rdev, wdev, scan) < 0) {
9059 spin_unlock_bh(&rdev->bss_lock);
9068 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
9069 int flags, struct net_device *dev,
9070 bool allow_radio_stats,
9071 struct survey_info *survey)
9074 struct nlattr *infoattr;
9076 /* skip radio stats if userspace didn't request them */
9077 if (!survey->channel && !allow_radio_stats)
9080 hdr = nl80211hdr_put(msg, portid, seq, flags,
9081 NL80211_CMD_NEW_SURVEY_RESULTS);
9085 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
9086 goto nla_put_failure;
9088 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
9090 goto nla_put_failure;
9092 if (survey->channel &&
9093 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
9094 survey->channel->center_freq))
9095 goto nla_put_failure;
9097 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
9098 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
9099 goto nla_put_failure;
9100 if ((survey->filled & SURVEY_INFO_IN_USE) &&
9101 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
9102 goto nla_put_failure;
9103 if ((survey->filled & SURVEY_INFO_TIME) &&
9104 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
9105 survey->time, NL80211_SURVEY_INFO_PAD))
9106 goto nla_put_failure;
9107 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
9108 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
9109 survey->time_busy, NL80211_SURVEY_INFO_PAD))
9110 goto nla_put_failure;
9111 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
9112 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
9113 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
9114 goto nla_put_failure;
9115 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
9116 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
9117 survey->time_rx, NL80211_SURVEY_INFO_PAD))
9118 goto nla_put_failure;
9119 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
9120 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
9121 survey->time_tx, NL80211_SURVEY_INFO_PAD))
9122 goto nla_put_failure;
9123 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
9124 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
9125 survey->time_scan, NL80211_SURVEY_INFO_PAD))
9126 goto nla_put_failure;
9127 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
9128 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
9129 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
9130 goto nla_put_failure;
9132 nla_nest_end(msg, infoattr);
9134 genlmsg_end(msg, hdr);
9138 genlmsg_cancel(msg, hdr);
9142 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
9144 struct nlattr **attrbuf;
9145 struct survey_info survey;
9146 struct cfg80211_registered_device *rdev;
9147 struct wireless_dev *wdev;
9148 int survey_idx = cb->args[2];
9152 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
9157 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
9161 /* prepare_wdev_dump parsed the attributes */
9162 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
9164 if (!wdev->netdev) {
9169 if (!rdev->ops->dump_survey) {
9175 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
9181 /* don't send disabled channels, but do send non-channel data */
9182 if (survey.channel &&
9183 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
9188 if (nl80211_send_survey(skb,
9189 NETLINK_CB(cb->skb).portid,
9190 cb->nlh->nlmsg_seq, NLM_F_MULTI,
9191 wdev->netdev, radio_stats, &survey) < 0)
9197 cb->args[2] = survey_idx;
9205 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
9207 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
9208 NL80211_WPA_VERSION_2 |
9209 NL80211_WPA_VERSION_3));
9212 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
9214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9215 struct net_device *dev = info->user_ptr[1];
9216 struct ieee80211_channel *chan;
9217 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
9218 int err, ssid_len, ie_len = 0, auth_data_len = 0;
9219 enum nl80211_auth_type auth_type;
9220 struct key_parse key;
9221 bool local_state_change;
9224 if (!info->attrs[NL80211_ATTR_MAC])
9227 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
9230 if (!info->attrs[NL80211_ATTR_SSID])
9233 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9236 err = nl80211_parse_key(info, &key);
9241 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
9243 if (!key.p.key || !key.p.key_len)
9245 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
9246 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
9247 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
9248 key.p.key_len != WLAN_KEY_LEN_WEP104))
9261 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
9262 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
9271 if (!rdev->ops->auth)
9274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9275 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9278 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9279 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
9280 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
9282 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
9284 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
9288 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9289 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9291 if (info->attrs[NL80211_ATTR_IE]) {
9292 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9293 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9296 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
9297 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
9300 if ((auth_type == NL80211_AUTHTYPE_SAE ||
9301 auth_type == NL80211_AUTHTYPE_FILS_SK ||
9302 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
9303 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
9304 !info->attrs[NL80211_ATTR_AUTH_DATA])
9307 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
9308 if (auth_type != NL80211_AUTHTYPE_SAE &&
9309 auth_type != NL80211_AUTHTYPE_FILS_SK &&
9310 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
9311 auth_type != NL80211_AUTHTYPE_FILS_PK)
9313 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
9314 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
9315 /* need to include at least Auth Transaction and Status Code */
9316 if (auth_data_len < 4)
9320 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9323 * Since we no longer track auth state, ignore
9324 * requests to only change local state.
9326 if (local_state_change)
9329 wdev_lock(dev->ieee80211_ptr);
9330 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
9331 ssid, ssid_len, ie, ie_len,
9332 key.p.key, key.p.key_len, key.idx,
9333 auth_data, auth_data_len);
9334 wdev_unlock(dev->ieee80211_ptr);
9338 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
9339 struct genl_info *info)
9341 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9342 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
9346 if (!rdev->ops->tx_control_port ||
9347 !wiphy_ext_feature_isset(&rdev->wiphy,
9348 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
9354 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
9355 struct genl_info *info,
9356 struct cfg80211_crypto_settings *settings,
9359 memset(settings, 0, sizeof(*settings));
9361 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9363 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9366 proto = nla_get_u16(
9367 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
9368 settings->control_port_ethertype = cpu_to_be16(proto);
9369 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
9372 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
9373 settings->control_port_no_encrypt = true;
9375 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
9377 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9378 int r = validate_pae_over_nl80211(rdev, info);
9383 settings->control_port_over_nl80211 = true;
9385 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH])
9386 settings->control_port_no_preauth = true;
9389 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
9393 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9394 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9395 settings->n_ciphers_pairwise = len / sizeof(u32);
9397 if (len % sizeof(u32))
9400 if (settings->n_ciphers_pairwise > cipher_limit)
9403 memcpy(settings->ciphers_pairwise, data, len);
9405 for (i = 0; i < settings->n_ciphers_pairwise; i++)
9406 if (!cfg80211_supported_cipher_suite(
9408 settings->ciphers_pairwise[i]))
9412 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
9413 settings->cipher_group =
9414 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
9415 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9416 settings->cipher_group))
9420 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
9421 settings->wpa_versions =
9422 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
9423 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
9427 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
9431 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
9432 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
9433 settings->n_akm_suites = len / sizeof(u32);
9435 if (len % sizeof(u32))
9438 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9441 memcpy(settings->akm_suites, data, len);
9444 if (info->attrs[NL80211_ATTR_PMK]) {
9445 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
9447 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9448 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
9449 !wiphy_ext_feature_isset(&rdev->wiphy,
9450 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
9452 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9455 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9456 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9457 NL80211_EXT_FEATURE_SAE_OFFLOAD))
9460 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9461 settings->sae_pwd_len =
9462 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9468 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9471 struct net_device *dev = info->user_ptr[1];
9472 struct ieee80211_channel *chan;
9473 struct cfg80211_assoc_request req = {};
9474 const u8 *bssid, *ssid;
9475 int err, ssid_len = 0;
9478 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9479 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9482 if (!info->attrs[NL80211_ATTR_MAC] ||
9483 !info->attrs[NL80211_ATTR_SSID] ||
9484 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
9487 if (!rdev->ops->assoc)
9490 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9491 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9494 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9496 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
9497 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
9499 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
9500 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
9504 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9505 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9507 if (info->attrs[NL80211_ATTR_IE]) {
9508 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9509 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9512 if (info->attrs[NL80211_ATTR_USE_MFP]) {
9513 enum nl80211_mfp mfp =
9514 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
9515 if (mfp == NL80211_MFP_REQUIRED)
9517 else if (mfp != NL80211_MFP_NO)
9521 if (info->attrs[NL80211_ATTR_PREV_BSSID])
9522 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
9524 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9525 req.flags |= ASSOC_REQ_DISABLE_HT;
9527 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9528 memcpy(&req.ht_capa_mask,
9529 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9530 sizeof(req.ht_capa_mask));
9532 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9533 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9535 memcpy(&req.ht_capa,
9536 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9537 sizeof(req.ht_capa));
9540 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9541 req.flags |= ASSOC_REQ_DISABLE_VHT;
9543 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9544 memcpy(&req.vht_capa_mask,
9545 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9546 sizeof(req.vht_capa_mask));
9548 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9549 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9551 memcpy(&req.vht_capa,
9552 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9553 sizeof(req.vht_capa));
9556 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
9557 if (!((rdev->wiphy.features &
9558 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9559 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9560 !wiphy_ext_feature_isset(&rdev->wiphy,
9561 NL80211_EXT_FEATURE_RRM))
9563 req.flags |= ASSOC_REQ_USE_RRM;
9566 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9567 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9568 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9569 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9572 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9575 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
9577 wdev_lock(dev->ieee80211_ptr);
9579 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9580 ssid, ssid_len, &req);
9582 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9583 dev->ieee80211_ptr->conn_owner_nlportid =
9585 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9589 wdev_unlock(dev->ieee80211_ptr);
9595 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9598 struct net_device *dev = info->user_ptr[1];
9599 const u8 *ie = NULL, *bssid;
9600 int ie_len = 0, err;
9602 bool local_state_change;
9604 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9605 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9608 if (!info->attrs[NL80211_ATTR_MAC])
9611 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9614 if (!rdev->ops->deauth)
9617 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9618 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9621 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9623 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9624 if (reason_code == 0) {
9625 /* Reason Code 0 is reserved */
9629 if (info->attrs[NL80211_ATTR_IE]) {
9630 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9631 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9634 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9636 wdev_lock(dev->ieee80211_ptr);
9637 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9638 local_state_change);
9639 wdev_unlock(dev->ieee80211_ptr);
9643 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9645 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9646 struct net_device *dev = info->user_ptr[1];
9647 const u8 *ie = NULL, *bssid;
9648 int ie_len = 0, err;
9650 bool local_state_change;
9652 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9653 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9656 if (!info->attrs[NL80211_ATTR_MAC])
9659 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9662 if (!rdev->ops->disassoc)
9665 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9666 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9669 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9671 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9672 if (reason_code == 0) {
9673 /* Reason Code 0 is reserved */
9677 if (info->attrs[NL80211_ATTR_IE]) {
9678 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9679 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9682 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9684 wdev_lock(dev->ieee80211_ptr);
9685 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9686 local_state_change);
9687 wdev_unlock(dev->ieee80211_ptr);
9692 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
9693 int mcast_rate[NUM_NL80211_BANDS],
9696 struct wiphy *wiphy = &rdev->wiphy;
9700 for (band = 0; band < NUM_NL80211_BANDS; band++) {
9701 struct ieee80211_supported_band *sband;
9703 sband = wiphy->bands[band];
9707 for (i = 0; i < sband->n_bitrates; i++) {
9708 if (sband->bitrates[i].bitrate == rateval) {
9709 mcast_rate[band] = i + 1;
9719 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9722 struct net_device *dev = info->user_ptr[1];
9723 struct cfg80211_ibss_params ibss;
9724 struct wiphy *wiphy;
9725 struct cfg80211_cached_keys *connkeys = NULL;
9728 memset(&ibss, 0, sizeof(ibss));
9730 if (!info->attrs[NL80211_ATTR_SSID] ||
9731 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9734 ibss.beacon_interval = 100;
9736 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
9737 ibss.beacon_interval =
9738 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9740 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9741 ibss.beacon_interval);
9745 if (!rdev->ops->join_ibss)
9748 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9751 wiphy = &rdev->wiphy;
9753 if (info->attrs[NL80211_ATTR_MAC]) {
9754 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9756 if (!is_valid_ether_addr(ibss.bssid))
9759 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9760 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9762 if (info->attrs[NL80211_ATTR_IE]) {
9763 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9764 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9767 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9771 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9772 NL80211_IFTYPE_ADHOC))
9775 switch (ibss.chandef.width) {
9776 case NL80211_CHAN_WIDTH_5:
9777 case NL80211_CHAN_WIDTH_10:
9778 case NL80211_CHAN_WIDTH_20_NOHT:
9780 case NL80211_CHAN_WIDTH_20:
9781 case NL80211_CHAN_WIDTH_40:
9782 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9785 case NL80211_CHAN_WIDTH_80:
9786 case NL80211_CHAN_WIDTH_80P80:
9787 case NL80211_CHAN_WIDTH_160:
9788 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9790 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9791 NL80211_EXT_FEATURE_VHT_IBSS))
9798 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
9799 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
9801 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9803 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9805 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9806 struct ieee80211_supported_band *sband =
9807 wiphy->bands[ibss.chandef.chan->band];
9809 err = ieee80211_get_ratemask(sband, rates, n_rates,
9815 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9816 memcpy(&ibss.ht_capa_mask,
9817 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9818 sizeof(ibss.ht_capa_mask));
9820 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9821 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9823 memcpy(&ibss.ht_capa,
9824 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9825 sizeof(ibss.ht_capa));
9828 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9829 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9830 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9833 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
9836 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
9837 if (IS_ERR(connkeys))
9838 return PTR_ERR(connkeys);
9840 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9842 kfree_sensitive(connkeys);
9848 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9850 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9851 int r = validate_pae_over_nl80211(rdev, info);
9854 kfree_sensitive(connkeys);
9858 ibss.control_port_over_nl80211 = true;
9861 ibss.userspace_handles_dfs =
9862 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9864 wdev_lock(dev->ieee80211_ptr);
9865 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
9867 kfree_sensitive(connkeys);
9868 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9869 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9870 wdev_unlock(dev->ieee80211_ptr);
9875 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9878 struct net_device *dev = info->user_ptr[1];
9880 if (!rdev->ops->leave_ibss)
9883 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9886 return cfg80211_leave_ibss(rdev, dev, false);
9889 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9891 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9892 struct net_device *dev = info->user_ptr[1];
9893 int mcast_rate[NUM_NL80211_BANDS];
9897 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
9898 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9899 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
9902 if (!rdev->ops->set_mcast_rate)
9905 memset(mcast_rate, 0, sizeof(mcast_rate));
9907 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9910 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9911 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9914 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
9919 static struct sk_buff *
9920 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
9921 struct wireless_dev *wdev, int approxlen,
9922 u32 portid, u32 seq, enum nl80211_commands cmd,
9923 enum nl80211_attrs attr,
9924 const struct nl80211_vendor_cmd_info *info,
9927 struct sk_buff *skb;
9929 struct nlattr *data;
9931 skb = nlmsg_new(approxlen + 100, gfp);
9935 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9941 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9942 goto nla_put_failure;
9945 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9947 goto nla_put_failure;
9948 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9950 goto nla_put_failure;
9954 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9955 wdev_id(wdev), NL80211_ATTR_PAD))
9956 goto nla_put_failure;
9958 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9959 wdev->netdev->ifindex))
9960 goto nla_put_failure;
9963 data = nla_nest_start_noflag(skb, attr);
9965 goto nla_put_failure;
9967 ((void **)skb->cb)[0] = rdev;
9968 ((void **)skb->cb)[1] = hdr;
9969 ((void **)skb->cb)[2] = data;
9978 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
9979 struct wireless_dev *wdev,
9980 enum nl80211_commands cmd,
9981 enum nl80211_attrs attr,
9982 unsigned int portid,
9983 int vendor_event_idx,
9984 int approxlen, gfp_t gfp)
9986 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
9987 const struct nl80211_vendor_cmd_info *info;
9990 case NL80211_CMD_TESTMODE:
9991 if (WARN_ON(vendor_event_idx != -1))
9995 case NL80211_CMD_VENDOR:
9996 if (WARN_ON(vendor_event_idx < 0 ||
9997 vendor_event_idx >= wiphy->n_vendor_events))
9999 info = &wiphy->vendor_events[vendor_event_idx];
10006 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
10007 cmd, attr, info, gfp);
10009 EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
10011 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
10013 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10014 void *hdr = ((void **)skb->cb)[1];
10015 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
10016 struct nlattr *data = ((void **)skb->cb)[2];
10017 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
10019 /* clear CB data for netlink core to own from now on */
10020 memset(skb->cb, 0, sizeof(skb->cb));
10022 nla_nest_end(skb, data);
10023 genlmsg_end(skb, hdr);
10025 if (nlhdr->nlmsg_pid) {
10026 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
10029 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
10030 mcgrp = NL80211_MCGRP_VENDOR;
10032 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
10033 skb, 0, mcgrp, gfp);
10036 EXPORT_SYMBOL(__cfg80211_send_event_skb);
10038 #ifdef CONFIG_NL80211_TESTMODE
10039 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
10041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10042 struct wireless_dev *wdev =
10043 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10046 if (!rdev->ops->testmode_cmd)
10047 return -EOPNOTSUPP;
10049 if (IS_ERR(wdev)) {
10050 err = PTR_ERR(wdev);
10051 if (err != -EINVAL)
10054 } else if (wdev->wiphy != &rdev->wiphy) {
10058 if (!info->attrs[NL80211_ATTR_TESTDATA])
10061 rdev->cur_cmd_info = info;
10062 err = rdev_testmode_cmd(rdev, wdev,
10063 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
10064 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
10065 rdev->cur_cmd_info = NULL;
10070 static int nl80211_testmode_dump(struct sk_buff *skb,
10071 struct netlink_callback *cb)
10073 struct cfg80211_registered_device *rdev;
10074 struct nlattr **attrbuf = NULL;
10084 * 0 is a valid index, but not valid for args[0],
10085 * so we need to offset by 1.
10087 phy_idx = cb->args[0] - 1;
10089 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
10095 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
10102 err = nlmsg_parse_deprecated(cb->nlh,
10103 GENL_HDRLEN + nl80211_fam.hdrsize,
10104 attrbuf, nl80211_fam.maxattr,
10105 nl80211_policy, NULL);
10109 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
10110 if (IS_ERR(rdev)) {
10111 err = PTR_ERR(rdev);
10114 phy_idx = rdev->wiphy_idx;
10116 if (attrbuf[NL80211_ATTR_TESTDATA])
10117 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
10121 data = nla_data((void *)cb->args[1]);
10122 data_len = nla_len((void *)cb->args[1]);
10125 if (!rdev->ops->testmode_dump) {
10131 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10132 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10133 NL80211_CMD_TESTMODE);
10134 struct nlattr *tmdata;
10139 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
10140 genlmsg_cancel(skb, hdr);
10144 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
10146 genlmsg_cancel(skb, hdr);
10149 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
10150 nla_nest_end(skb, tmdata);
10152 if (err == -ENOBUFS || err == -ENOENT) {
10153 genlmsg_cancel(skb, hdr);
10156 genlmsg_cancel(skb, hdr);
10160 genlmsg_end(skb, hdr);
10165 cb->args[0] = phy_idx + 1;
10173 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
10175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10176 struct net_device *dev = info->user_ptr[1];
10177 struct cfg80211_connect_params connect;
10178 struct wiphy *wiphy;
10179 struct cfg80211_cached_keys *connkeys = NULL;
10183 memset(&connect, 0, sizeof(connect));
10185 if (!info->attrs[NL80211_ATTR_SSID] ||
10186 !nla_len(info->attrs[NL80211_ATTR_SSID]))
10189 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10190 connect.auth_type =
10191 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10192 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
10193 NL80211_CMD_CONNECT))
10196 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
10198 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
10200 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
10201 !wiphy_ext_feature_isset(&rdev->wiphy,
10202 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
10204 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
10206 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
10207 NL80211_MAX_NR_CIPHER_SUITES);
10211 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10212 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10213 return -EOPNOTSUPP;
10215 wiphy = &rdev->wiphy;
10217 connect.bg_scan_period = -1;
10218 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
10219 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
10220 connect.bg_scan_period =
10221 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
10224 if (info->attrs[NL80211_ATTR_MAC])
10225 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10226 else if (info->attrs[NL80211_ATTR_MAC_HINT])
10227 connect.bssid_hint =
10228 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
10229 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10230 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10232 if (info->attrs[NL80211_ATTR_IE]) {
10233 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10234 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10237 if (info->attrs[NL80211_ATTR_USE_MFP]) {
10238 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
10239 if (connect.mfp == NL80211_MFP_OPTIONAL &&
10240 !wiphy_ext_feature_isset(&rdev->wiphy,
10241 NL80211_EXT_FEATURE_MFP_OPTIONAL))
10242 return -EOPNOTSUPP;
10244 connect.mfp = NL80211_MFP_NO;
10247 if (info->attrs[NL80211_ATTR_PREV_BSSID])
10248 connect.prev_bssid =
10249 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
10251 if (info->attrs[NL80211_ATTR_WIPHY_FREQ])
10252 freq = MHZ_TO_KHZ(nla_get_u32(
10253 info->attrs[NL80211_ATTR_WIPHY_FREQ]));
10254 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10256 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10259 connect.channel = nl80211_get_valid_chan(wiphy, freq);
10260 if (!connect.channel)
10262 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
10263 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
10264 freq = MHZ_TO_KHZ(freq);
10265 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq);
10266 if (!connect.channel_hint)
10270 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
10271 connect.edmg.channels =
10272 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
10274 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
10275 connect.edmg.bw_config =
10276 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
10279 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
10280 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
10281 if (IS_ERR(connkeys))
10282 return PTR_ERR(connkeys);
10285 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
10286 connect.flags |= ASSOC_REQ_DISABLE_HT;
10288 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10289 memcpy(&connect.ht_capa_mask,
10290 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
10291 sizeof(connect.ht_capa_mask));
10293 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
10294 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
10295 kfree_sensitive(connkeys);
10298 memcpy(&connect.ht_capa,
10299 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10300 sizeof(connect.ht_capa));
10303 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
10304 connect.flags |= ASSOC_REQ_DISABLE_VHT;
10306 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
10307 memcpy(&connect.vht_capa_mask,
10308 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
10309 sizeof(connect.vht_capa_mask));
10311 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
10312 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
10313 kfree_sensitive(connkeys);
10316 memcpy(&connect.vht_capa,
10317 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
10318 sizeof(connect.vht_capa));
10321 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
10322 if (!((rdev->wiphy.features &
10323 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
10324 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
10325 !wiphy_ext_feature_isset(&rdev->wiphy,
10326 NL80211_EXT_FEATURE_RRM)) {
10327 kfree_sensitive(connkeys);
10330 connect.flags |= ASSOC_REQ_USE_RRM;
10333 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
10334 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
10335 kfree_sensitive(connkeys);
10336 return -EOPNOTSUPP;
10339 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
10340 /* bss selection makes no sense if bssid is set */
10341 if (connect.bssid) {
10342 kfree_sensitive(connkeys);
10346 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
10347 wiphy, &connect.bss_select);
10349 kfree_sensitive(connkeys);
10354 if (wiphy_ext_feature_isset(&rdev->wiphy,
10355 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10356 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10357 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10358 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10359 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10360 connect.fils_erp_username =
10361 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10362 connect.fils_erp_username_len =
10363 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10364 connect.fils_erp_realm =
10365 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10366 connect.fils_erp_realm_len =
10367 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10368 connect.fils_erp_next_seq_num =
10370 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10371 connect.fils_erp_rrk =
10372 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10373 connect.fils_erp_rrk_len =
10374 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10375 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10376 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10377 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10378 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10379 kfree_sensitive(connkeys);
10383 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10384 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10385 kfree_sensitive(connkeys);
10386 GENL_SET_ERR_MSG(info,
10387 "external auth requires connection ownership");
10390 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
10393 wdev_lock(dev->ieee80211_ptr);
10395 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10396 connect.prev_bssid);
10398 kfree_sensitive(connkeys);
10400 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10401 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10403 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10404 connect.bssid, ETH_ALEN);
10406 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid);
10409 wdev_unlock(dev->ieee80211_ptr);
10414 static int nl80211_update_connect_params(struct sk_buff *skb,
10415 struct genl_info *info)
10417 struct cfg80211_connect_params connect = {};
10418 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10419 struct net_device *dev = info->user_ptr[1];
10420 struct wireless_dev *wdev = dev->ieee80211_ptr;
10421 bool fils_sk_offload;
10426 if (!rdev->ops->update_connect_params)
10427 return -EOPNOTSUPP;
10429 if (info->attrs[NL80211_ATTR_IE]) {
10430 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10431 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10432 changed |= UPDATE_ASSOC_IES;
10435 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
10436 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
10439 * when driver supports fils-sk offload all attributes must be
10440 * provided. So the else covers "fils-sk-not-all" and
10441 * "no-fils-sk-any".
10443 if (fils_sk_offload &&
10444 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10445 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10446 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10447 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10448 connect.fils_erp_username =
10449 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10450 connect.fils_erp_username_len =
10451 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10452 connect.fils_erp_realm =
10453 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10454 connect.fils_erp_realm_len =
10455 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10456 connect.fils_erp_next_seq_num =
10458 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10459 connect.fils_erp_rrk =
10460 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10461 connect.fils_erp_rrk_len =
10462 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10463 changed |= UPDATE_FILS_ERP_INFO;
10464 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10465 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10466 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10467 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10471 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10472 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10473 if (!nl80211_valid_auth_type(rdev, auth_type,
10474 NL80211_CMD_CONNECT))
10477 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
10478 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
10481 connect.auth_type = auth_type;
10482 changed |= UPDATE_AUTH_TYPE;
10485 wdev_lock(dev->ieee80211_ptr);
10486 if (!wdev->current_bss)
10489 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
10490 wdev_unlock(dev->ieee80211_ptr);
10495 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10498 struct net_device *dev = info->user_ptr[1];
10502 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10503 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10506 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10507 reason = WLAN_REASON_DEAUTH_LEAVING;
10509 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10514 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10515 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10516 return -EOPNOTSUPP;
10518 wdev_lock(dev->ieee80211_ptr);
10519 ret = cfg80211_disconnect(rdev, dev, reason, true);
10520 wdev_unlock(dev->ieee80211_ptr);
10524 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10530 if (info->attrs[NL80211_ATTR_PID]) {
10531 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10533 net = get_net_ns_by_pid(pid);
10534 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10535 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10537 net = get_net_ns_by_fd(fd);
10543 return PTR_ERR(net);
10547 /* check if anything to do */
10548 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10549 err = cfg80211_switch_netns(rdev, net);
10555 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10557 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10558 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10559 struct cfg80211_pmksa *pmksa) = NULL;
10560 struct net_device *dev = info->user_ptr[1];
10561 struct cfg80211_pmksa pmksa;
10563 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10565 if (!info->attrs[NL80211_ATTR_PMKID])
10568 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
10570 if (info->attrs[NL80211_ATTR_MAC]) {
10571 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10572 } else if (info->attrs[NL80211_ATTR_SSID] &&
10573 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10574 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10575 info->attrs[NL80211_ATTR_PMK])) {
10576 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10577 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10579 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10583 if (info->attrs[NL80211_ATTR_PMK]) {
10584 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10585 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10588 if (info->attrs[NL80211_ATTR_PMK_LIFETIME])
10589 pmksa.pmk_lifetime =
10590 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]);
10592 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD])
10593 pmksa.pmk_reauth_threshold =
10595 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]);
10597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10598 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10599 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10600 wiphy_ext_feature_isset(&rdev->wiphy,
10601 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
10602 return -EOPNOTSUPP;
10604 switch (info->genlhdr->cmd) {
10605 case NL80211_CMD_SET_PMKSA:
10606 rdev_ops = rdev->ops->set_pmksa;
10608 case NL80211_CMD_DEL_PMKSA:
10609 rdev_ops = rdev->ops->del_pmksa;
10617 return -EOPNOTSUPP;
10619 return rdev_ops(&rdev->wiphy, dev, &pmksa);
10622 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10625 struct net_device *dev = info->user_ptr[1];
10627 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
10628 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10629 return -EOPNOTSUPP;
10631 if (!rdev->ops->flush_pmksa)
10632 return -EOPNOTSUPP;
10634 return rdev_flush_pmksa(rdev, dev);
10637 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10640 struct net_device *dev = info->user_ptr[1];
10641 u8 action_code, dialog_token;
10642 u32 peer_capability = 0;
10647 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10648 !rdev->ops->tdls_mgmt)
10649 return -EOPNOTSUPP;
10651 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10652 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10653 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10654 !info->attrs[NL80211_ATTR_IE] ||
10655 !info->attrs[NL80211_ATTR_MAC])
10658 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10659 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10660 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10661 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
10662 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
10663 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10665 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
10667 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
10668 dialog_token, status_code, peer_capability,
10670 nla_data(info->attrs[NL80211_ATTR_IE]),
10671 nla_len(info->attrs[NL80211_ATTR_IE]));
10674 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10677 struct net_device *dev = info->user_ptr[1];
10678 enum nl80211_tdls_operation operation;
10681 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10682 !rdev->ops->tdls_oper)
10683 return -EOPNOTSUPP;
10685 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10686 !info->attrs[NL80211_ATTR_MAC])
10689 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10690 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10692 return rdev_tdls_oper(rdev, dev, peer, operation);
10695 static int nl80211_remain_on_channel(struct sk_buff *skb,
10696 struct genl_info *info)
10698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10699 struct wireless_dev *wdev = info->user_ptr[1];
10700 struct cfg80211_chan_def chandef;
10701 const struct cfg80211_chan_def *compat_chandef;
10702 struct sk_buff *msg;
10708 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10709 !info->attrs[NL80211_ATTR_DURATION])
10712 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10714 if (!rdev->ops->remain_on_channel ||
10715 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
10716 return -EOPNOTSUPP;
10719 * We should be on that channel for at least a minimum amount of
10720 * time (10ms) but no longer than the driver supports.
10722 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10723 duration > rdev->wiphy.max_remain_on_channel_duration)
10726 err = nl80211_parse_chandef(rdev, info, &chandef);
10731 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10732 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10733 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10735 if (compat_chandef != &chandef) {
10742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10746 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10747 NL80211_CMD_REMAIN_ON_CHANNEL);
10753 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10754 duration, &cookie);
10759 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10761 goto nla_put_failure;
10763 genlmsg_end(msg, hdr);
10765 return genlmsg_reply(msg, info);
10774 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10775 struct genl_info *info)
10777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10778 struct wireless_dev *wdev = info->user_ptr[1];
10781 if (!info->attrs[NL80211_ATTR_COOKIE])
10784 if (!rdev->ops->cancel_remain_on_channel)
10785 return -EOPNOTSUPP;
10787 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10789 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
10792 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10793 struct genl_info *info)
10795 struct cfg80211_bitrate_mask mask;
10796 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10797 struct net_device *dev = info->user_ptr[1];
10800 if (!rdev->ops->set_bitrate_mask)
10801 return -EOPNOTSUPP;
10803 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
10804 NL80211_ATTR_TX_RATES, &mask);
10808 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
10811 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
10813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10814 struct wireless_dev *wdev = info->user_ptr[1];
10815 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
10817 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10820 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10821 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
10823 switch (wdev->iftype) {
10824 case NL80211_IFTYPE_STATION:
10825 case NL80211_IFTYPE_ADHOC:
10826 case NL80211_IFTYPE_P2P_CLIENT:
10827 case NL80211_IFTYPE_AP:
10828 case NL80211_IFTYPE_AP_VLAN:
10829 case NL80211_IFTYPE_MESH_POINT:
10830 case NL80211_IFTYPE_P2P_GO:
10831 case NL80211_IFTYPE_P2P_DEVICE:
10833 case NL80211_IFTYPE_NAN:
10835 return -EOPNOTSUPP;
10838 /* not much point in registering if we can't reply */
10839 if (!rdev->ops->mgmt_tx)
10840 return -EOPNOTSUPP;
10842 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] &&
10843 !wiphy_ext_feature_isset(&rdev->wiphy,
10844 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) {
10845 GENL_SET_ERR_MSG(info,
10846 "multicast RX registrations are not supported");
10847 return -EOPNOTSUPP;
10850 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
10851 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10852 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10853 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST],
10857 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
10859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10860 struct wireless_dev *wdev = info->user_ptr[1];
10861 struct cfg80211_chan_def chandef;
10865 struct sk_buff *msg = NULL;
10866 struct cfg80211_mgmt_tx_params params = {
10867 .dont_wait_for_ack =
10868 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10871 if (!info->attrs[NL80211_ATTR_FRAME])
10874 if (!rdev->ops->mgmt_tx)
10875 return -EOPNOTSUPP;
10877 switch (wdev->iftype) {
10878 case NL80211_IFTYPE_P2P_DEVICE:
10879 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10881 case NL80211_IFTYPE_STATION:
10882 case NL80211_IFTYPE_ADHOC:
10883 case NL80211_IFTYPE_P2P_CLIENT:
10884 case NL80211_IFTYPE_AP:
10885 case NL80211_IFTYPE_AP_VLAN:
10886 case NL80211_IFTYPE_MESH_POINT:
10887 case NL80211_IFTYPE_P2P_GO:
10889 case NL80211_IFTYPE_NAN:
10891 return -EOPNOTSUPP;
10894 if (info->attrs[NL80211_ATTR_DURATION]) {
10895 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
10897 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10900 * We should wait on the channel for at least a minimum amount
10901 * of time (10ms) but no longer than the driver supports.
10903 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10904 params.wait > rdev->wiphy.max_remain_on_channel_duration)
10908 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
10910 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
10913 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
10915 /* get the channel if any has been specified, otherwise pass NULL to
10916 * the driver. The latter will use the current one
10918 chandef.chan = NULL;
10919 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10920 err = nl80211_parse_chandef(rdev, info, &chandef);
10925 if (!chandef.chan && params.offchan)
10929 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10935 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10936 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10938 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10939 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10942 if (len % sizeof(u16))
10945 params.n_csa_offsets = len / sizeof(u16);
10946 params.csa_offsets =
10947 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10949 /* check that all the offsets fit the frame */
10950 for (i = 0; i < params.n_csa_offsets; i++) {
10951 if (params.csa_offsets[i] >= params.len)
10956 if (!params.dont_wait_for_ack) {
10957 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10961 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10962 NL80211_CMD_FRAME);
10969 params.chan = chandef.chan;
10970 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie);
10975 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10977 goto nla_put_failure;
10979 genlmsg_end(msg, hdr);
10980 return genlmsg_reply(msg, info);
10992 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10995 struct wireless_dev *wdev = info->user_ptr[1];
10998 if (!info->attrs[NL80211_ATTR_COOKIE])
11001 if (!rdev->ops->mgmt_tx_cancel_wait)
11002 return -EOPNOTSUPP;
11004 switch (wdev->iftype) {
11005 case NL80211_IFTYPE_STATION:
11006 case NL80211_IFTYPE_ADHOC:
11007 case NL80211_IFTYPE_P2P_CLIENT:
11008 case NL80211_IFTYPE_AP:
11009 case NL80211_IFTYPE_AP_VLAN:
11010 case NL80211_IFTYPE_P2P_GO:
11011 case NL80211_IFTYPE_P2P_DEVICE:
11013 case NL80211_IFTYPE_NAN:
11015 return -EOPNOTSUPP;
11018 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11020 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
11023 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
11025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11026 struct wireless_dev *wdev;
11027 struct net_device *dev = info->user_ptr[1];
11032 if (!info->attrs[NL80211_ATTR_PS_STATE])
11035 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
11037 wdev = dev->ieee80211_ptr;
11039 if (!rdev->ops->set_power_mgmt)
11040 return -EOPNOTSUPP;
11042 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
11044 if (state == wdev->ps)
11047 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
11053 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
11055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11056 enum nl80211_ps_state ps_state;
11057 struct wireless_dev *wdev;
11058 struct net_device *dev = info->user_ptr[1];
11059 struct sk_buff *msg;
11063 wdev = dev->ieee80211_ptr;
11065 if (!rdev->ops->set_power_mgmt)
11066 return -EOPNOTSUPP;
11068 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11072 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11073 NL80211_CMD_GET_POWER_SAVE);
11080 ps_state = NL80211_PS_ENABLED;
11082 ps_state = NL80211_PS_DISABLED;
11084 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
11085 goto nla_put_failure;
11087 genlmsg_end(msg, hdr);
11088 return genlmsg_reply(msg, info);
11097 static const struct nla_policy
11098 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
11099 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
11100 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
11101 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
11102 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
11103 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
11104 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
11105 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
11108 static int nl80211_set_cqm_txe(struct genl_info *info,
11109 u32 rate, u32 pkts, u32 intvl)
11111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11112 struct net_device *dev = info->user_ptr[1];
11113 struct wireless_dev *wdev = dev->ieee80211_ptr;
11115 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
11118 if (!rdev->ops->set_cqm_txe_config)
11119 return -EOPNOTSUPP;
11121 if (wdev->iftype != NL80211_IFTYPE_STATION &&
11122 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11123 return -EOPNOTSUPP;
11125 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
11128 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
11129 struct net_device *dev)
11131 struct wireless_dev *wdev = dev->ieee80211_ptr;
11132 s32 last, low, high;
11134 int i, n, low_index;
11137 /* RSSI reporting disabled? */
11138 if (!wdev->cqm_config)
11139 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
11142 * Obtain current RSSI value if possible, if not and no RSSI threshold
11143 * event has been received yet, we should receive an event after a
11144 * connection is established and enough beacons received to calculate
11147 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
11148 rdev->ops->get_station) {
11149 struct station_info sinfo = {};
11152 mac_addr = wdev->current_bss->pub.bssid;
11154 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
11158 cfg80211_sinfo_release_content(&sinfo);
11159 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
11160 wdev->cqm_config->last_rssi_event_value =
11161 (s8) sinfo.rx_beacon_signal_avg;
11164 last = wdev->cqm_config->last_rssi_event_value;
11165 hyst = wdev->cqm_config->rssi_hyst;
11166 n = wdev->cqm_config->n_rssi_thresholds;
11168 for (i = 0; i < n; i++) {
11169 i = array_index_nospec(i, n);
11170 if (last < wdev->cqm_config->rssi_thresholds[i])
11175 if (low_index >= 0) {
11176 low_index = array_index_nospec(low_index, n);
11177 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
11182 i = array_index_nospec(i, n);
11183 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
11188 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
11191 static int nl80211_set_cqm_rssi(struct genl_info *info,
11192 const s32 *thresholds, int n_thresholds,
11195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11196 struct net_device *dev = info->user_ptr[1];
11197 struct wireless_dev *wdev = dev->ieee80211_ptr;
11199 s32 prev = S32_MIN;
11201 /* Check all values negative and sorted */
11202 for (i = 0; i < n_thresholds; i++) {
11203 if (thresholds[i] > 0 || thresholds[i] <= prev)
11206 prev = thresholds[i];
11209 if (wdev->iftype != NL80211_IFTYPE_STATION &&
11210 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11211 return -EOPNOTSUPP;
11214 cfg80211_cqm_config_free(wdev);
11217 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
11218 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
11219 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
11221 return rdev_set_cqm_rssi_config(rdev, dev,
11222 thresholds[0], hysteresis);
11225 if (!wiphy_ext_feature_isset(&rdev->wiphy,
11226 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
11227 return -EOPNOTSUPP;
11229 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
11233 if (n_thresholds) {
11234 struct cfg80211_cqm_config *cqm_config;
11236 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
11237 n_thresholds * sizeof(s32), GFP_KERNEL);
11243 cqm_config->rssi_hyst = hysteresis;
11244 cqm_config->n_rssi_thresholds = n_thresholds;
11245 memcpy(cqm_config->rssi_thresholds, thresholds,
11246 n_thresholds * sizeof(s32));
11248 wdev->cqm_config = cqm_config;
11251 err = cfg80211_cqm_rssi_update(rdev, dev);
11259 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
11261 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
11262 struct nlattr *cqm;
11265 cqm = info->attrs[NL80211_ATTR_CQM];
11269 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
11270 nl80211_attr_cqm_policy,
11275 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
11276 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
11277 const s32 *thresholds =
11278 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
11279 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
11280 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
11285 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
11289 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
11290 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
11291 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
11292 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
11293 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
11294 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
11296 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
11302 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
11304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11305 struct net_device *dev = info->user_ptr[1];
11306 struct ocb_setup setup = {};
11309 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11313 return cfg80211_join_ocb(rdev, dev, &setup);
11316 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
11318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11319 struct net_device *dev = info->user_ptr[1];
11321 return cfg80211_leave_ocb(rdev, dev);
11324 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
11326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11327 struct net_device *dev = info->user_ptr[1];
11328 struct mesh_config cfg;
11329 struct mesh_setup setup;
11332 /* start with default */
11333 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
11334 memcpy(&setup, &default_mesh_setup, sizeof(setup));
11336 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
11337 /* and parse parameters if given */
11338 err = nl80211_parse_mesh_config(info, &cfg, NULL);
11343 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
11344 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
11347 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
11348 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
11350 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11351 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
11352 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11355 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
11356 setup.beacon_interval =
11357 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
11359 err = cfg80211_validate_beacon_int(rdev,
11360 NL80211_IFTYPE_MESH_POINT,
11361 setup.beacon_interval);
11366 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
11367 setup.dtim_period =
11368 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
11369 if (setup.dtim_period < 1 || setup.dtim_period > 100)
11373 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
11374 /* parse additional setup parameters if given */
11375 err = nl80211_parse_mesh_setup(info, &setup);
11380 if (setup.user_mpm)
11381 cfg.auto_open_plinks = false;
11383 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
11384 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11388 /* __cfg80211_join_mesh() will sort it out */
11389 setup.chandef.chan = NULL;
11392 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11393 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11395 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11396 struct ieee80211_supported_band *sband;
11398 if (!setup.chandef.chan)
11401 sband = rdev->wiphy.bands[setup.chandef.chan->band];
11403 err = ieee80211_get_ratemask(sband, rates, n_rates,
11404 &setup.basic_rates);
11409 if (info->attrs[NL80211_ATTR_TX_RATES]) {
11410 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
11411 NL80211_ATTR_TX_RATES,
11412 &setup.beacon_rate);
11416 if (!setup.chandef.chan)
11419 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11420 &setup.beacon_rate);
11425 setup.userspace_handles_dfs =
11426 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11428 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11429 int r = validate_pae_over_nl80211(rdev, info);
11434 setup.control_port_over_nl80211 = true;
11437 wdev_lock(dev->ieee80211_ptr);
11438 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
11439 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
11440 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11441 wdev_unlock(dev->ieee80211_ptr);
11446 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
11448 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11449 struct net_device *dev = info->user_ptr[1];
11451 return cfg80211_leave_mesh(rdev, dev);
11455 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11456 struct cfg80211_registered_device *rdev)
11458 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
11459 struct nlattr *nl_pats, *nl_pat;
11462 if (!wowlan->n_patterns)
11465 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
11469 for (i = 0; i < wowlan->n_patterns; i++) {
11470 nl_pat = nla_nest_start_noflag(msg, i + 1);
11473 pat_len = wowlan->patterns[i].pattern_len;
11474 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
11475 wowlan->patterns[i].mask) ||
11476 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11477 wowlan->patterns[i].pattern) ||
11478 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11479 wowlan->patterns[i].pkt_offset))
11481 nla_nest_end(msg, nl_pat);
11483 nla_nest_end(msg, nl_pats);
11488 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
11489 struct cfg80211_wowlan_tcp *tcp)
11491 struct nlattr *nl_tcp;
11496 nl_tcp = nla_nest_start_noflag(msg,
11497 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
11501 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
11502 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
11503 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
11504 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
11505 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
11506 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
11507 tcp->payload_len, tcp->payload) ||
11508 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
11509 tcp->data_interval) ||
11510 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
11511 tcp->wake_len, tcp->wake_data) ||
11512 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
11513 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
11516 if (tcp->payload_seq.len &&
11517 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
11518 sizeof(tcp->payload_seq), &tcp->payload_seq))
11521 if (tcp->payload_tok.len &&
11522 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11523 sizeof(tcp->payload_tok) + tcp->tokens_size,
11524 &tcp->payload_tok))
11527 nla_nest_end(msg, nl_tcp);
11532 static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11533 struct cfg80211_sched_scan_request *req)
11535 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
11541 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
11545 if (req->n_scan_plans == 1 &&
11546 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11547 req->scan_plans[0].interval * 1000))
11550 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11553 if (req->relative_rssi_set) {
11554 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11556 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11557 req->relative_rssi))
11560 rssi_adjust.band = req->rssi_adjust.band;
11561 rssi_adjust.delta = req->rssi_adjust.delta;
11562 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11563 sizeof(rssi_adjust), &rssi_adjust))
11567 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11571 for (i = 0; i < req->n_channels; i++) {
11572 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11576 nla_nest_end(msg, freqs);
11578 if (req->n_match_sets) {
11579 matches = nla_nest_start_noflag(msg,
11580 NL80211_ATTR_SCHED_SCAN_MATCH);
11584 for (i = 0; i < req->n_match_sets; i++) {
11585 match = nla_nest_start_noflag(msg, i);
11589 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11590 req->match_sets[i].ssid.ssid_len,
11591 req->match_sets[i].ssid.ssid))
11593 nla_nest_end(msg, match);
11595 nla_nest_end(msg, matches);
11598 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
11602 for (i = 0; i < req->n_scan_plans; i++) {
11603 scan_plan = nla_nest_start_noflag(msg, i + 1);
11607 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
11608 req->scan_plans[i].interval) ||
11609 (req->scan_plans[i].iterations &&
11610 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11611 req->scan_plans[i].iterations)))
11613 nla_nest_end(msg, scan_plan);
11615 nla_nest_end(msg, scan_plans);
11617 nla_nest_end(msg, nd);
11622 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11625 struct sk_buff *msg;
11627 u32 size = NLMSG_DEFAULT_SIZE;
11629 if (!rdev->wiphy.wowlan)
11630 return -EOPNOTSUPP;
11632 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
11633 /* adjust size to have room for all the data */
11634 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11635 rdev->wiphy.wowlan_config->tcp->payload_len +
11636 rdev->wiphy.wowlan_config->tcp->wake_len +
11637 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
11640 msg = nlmsg_new(size, GFP_KERNEL);
11644 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11645 NL80211_CMD_GET_WOWLAN);
11647 goto nla_put_failure;
11649 if (rdev->wiphy.wowlan_config) {
11650 struct nlattr *nl_wowlan;
11652 nl_wowlan = nla_nest_start_noflag(msg,
11653 NL80211_ATTR_WOWLAN_TRIGGERS);
11655 goto nla_put_failure;
11657 if ((rdev->wiphy.wowlan_config->any &&
11658 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
11659 (rdev->wiphy.wowlan_config->disconnect &&
11660 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
11661 (rdev->wiphy.wowlan_config->magic_pkt &&
11662 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
11663 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
11664 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
11665 (rdev->wiphy.wowlan_config->eap_identity_req &&
11666 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
11667 (rdev->wiphy.wowlan_config->four_way_handshake &&
11668 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
11669 (rdev->wiphy.wowlan_config->rfkill_release &&
11670 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11671 goto nla_put_failure;
11673 if (nl80211_send_wowlan_patterns(msg, rdev))
11674 goto nla_put_failure;
11676 if (nl80211_send_wowlan_tcp(msg,
11677 rdev->wiphy.wowlan_config->tcp))
11678 goto nla_put_failure;
11680 if (nl80211_send_wowlan_nd(
11682 rdev->wiphy.wowlan_config->nd_config))
11683 goto nla_put_failure;
11685 nla_nest_end(msg, nl_wowlan);
11688 genlmsg_end(msg, hdr);
11689 return genlmsg_reply(msg, info);
11696 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11697 struct nlattr *attr,
11698 struct cfg80211_wowlan *trig)
11700 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11701 struct cfg80211_wowlan_tcp *cfg;
11702 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11703 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11705 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11708 if (!rdev->wiphy.wowlan->tcp)
11711 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11712 nl80211_wowlan_tcp_policy, NULL);
11716 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11717 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11718 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11719 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11720 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11721 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11722 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11723 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11726 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
11727 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
11730 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
11731 rdev->wiphy.wowlan->tcp->data_interval_max ||
11732 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
11735 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
11736 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
11739 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11740 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11743 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11744 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11746 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11747 tokens_size = tokln - sizeof(*tok);
11749 if (!tok->len || tokens_size % tok->len)
11751 if (!rdev->wiphy.wowlan->tcp->tok)
11753 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
11755 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
11757 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
11759 if (tok->offset + tok->len > data_size)
11763 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11764 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
11765 if (!rdev->wiphy.wowlan->tcp->seq)
11767 if (seq->len == 0 || seq->len > 4)
11769 if (seq->len + seq->offset > data_size)
11773 size = sizeof(*cfg);
11775 size += wake_size + wake_mask_size;
11776 size += tokens_size;
11778 cfg = kzalloc(size, GFP_KERNEL);
11781 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11782 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
11783 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11785 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11786 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11790 /* allocate a socket and port for it and use it */
11791 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11792 IPPROTO_TCP, &cfg->sock, 1);
11797 if (inet_csk_get_port(cfg->sock->sk, port)) {
11798 sock_release(cfg->sock);
11800 return -EADDRINUSE;
11802 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11808 cfg->src_port = port;
11811 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11812 cfg->payload_len = data_size;
11813 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11814 memcpy((void *)cfg->payload,
11815 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11818 cfg->payload_seq = *seq;
11819 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11820 cfg->wake_len = wake_size;
11821 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11822 memcpy((void *)cfg->wake_data,
11823 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11825 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11826 data_size + wake_size;
11827 memcpy((void *)cfg->wake_mask,
11828 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11831 cfg->tokens_size = tokens_size;
11832 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11840 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11841 const struct wiphy_wowlan_support *wowlan,
11842 struct nlattr *attr,
11843 struct cfg80211_wowlan *trig)
11845 struct nlattr **tb;
11848 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
11852 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11857 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11858 nl80211_policy, NULL);
11862 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11863 wowlan->max_nd_match_sets);
11864 err = PTR_ERR_OR_ZERO(trig->nd_config);
11866 trig->nd_config = NULL;
11873 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11876 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
11877 struct cfg80211_wowlan new_triggers = {};
11878 struct cfg80211_wowlan *ntrig;
11879 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
11881 bool prev_enabled = rdev->wiphy.wowlan_config;
11882 bool regular = false;
11885 return -EOPNOTSUPP;
11887 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11888 cfg80211_rdev_free_wowlan(rdev);
11889 rdev->wiphy.wowlan_config = NULL;
11893 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11894 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11895 nl80211_wowlan_policy, info->extack);
11899 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11900 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11902 new_triggers.any = true;
11905 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11906 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11908 new_triggers.disconnect = true;
11912 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11913 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11915 new_triggers.magic_pkt = true;
11919 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11922 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11923 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11925 new_triggers.gtk_rekey_failure = true;
11929 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11930 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11932 new_triggers.eap_identity_req = true;
11936 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11937 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11939 new_triggers.four_way_handshake = true;
11943 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11944 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11946 new_triggers.rfkill_release = true;
11950 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11951 struct nlattr *pat;
11952 int n_patterns = 0;
11953 int rem, pat_len, mask_len, pkt_offset;
11954 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11958 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11961 if (n_patterns > wowlan->n_patterns)
11964 new_triggers.patterns = kcalloc(n_patterns,
11965 sizeof(new_triggers.patterns[0]),
11967 if (!new_triggers.patterns)
11970 new_triggers.n_patterns = n_patterns;
11973 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11977 err = nla_parse_nested_deprecated(pat_tb,
11978 MAX_NL80211_PKTPAT,
11980 nl80211_packet_pattern_policy,
11986 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11987 !pat_tb[NL80211_PKTPAT_PATTERN])
11989 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
11990 mask_len = DIV_ROUND_UP(pat_len, 8);
11991 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
11993 if (pat_len > wowlan->pattern_max_len ||
11994 pat_len < wowlan->pattern_min_len)
11997 if (!pat_tb[NL80211_PKTPAT_OFFSET])
12000 pkt_offset = nla_get_u32(
12001 pat_tb[NL80211_PKTPAT_OFFSET]);
12002 if (pkt_offset > wowlan->max_pkt_offset)
12004 new_triggers.patterns[i].pkt_offset = pkt_offset;
12006 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12011 new_triggers.patterns[i].mask = mask_pat;
12012 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
12014 mask_pat += mask_len;
12015 new_triggers.patterns[i].pattern = mask_pat;
12016 new_triggers.patterns[i].pattern_len = pat_len;
12018 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
12024 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
12026 err = nl80211_parse_wowlan_tcp(
12027 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
12033 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
12035 err = nl80211_parse_wowlan_nd(
12036 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
12042 /* The 'any' trigger means the device continues operating more or less
12043 * as in its normal operation mode and wakes up the host on most of the
12044 * normal interrupts (like packet RX, ...)
12045 * It therefore makes little sense to combine with the more constrained
12046 * wakeup trigger modes.
12048 if (new_triggers.any && regular) {
12053 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
12058 cfg80211_rdev_free_wowlan(rdev);
12059 rdev->wiphy.wowlan_config = ntrig;
12062 if (rdev->ops->set_wakeup &&
12063 prev_enabled != !!rdev->wiphy.wowlan_config)
12064 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
12068 for (i = 0; i < new_triggers.n_patterns; i++)
12069 kfree(new_triggers.patterns[i].mask);
12070 kfree(new_triggers.patterns);
12071 if (new_triggers.tcp && new_triggers.tcp->sock)
12072 sock_release(new_triggers.tcp->sock);
12073 kfree(new_triggers.tcp);
12074 kfree(new_triggers.nd_config);
12079 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
12080 struct cfg80211_registered_device *rdev)
12082 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
12084 struct cfg80211_coalesce_rules *rule;
12086 if (!rdev->coalesce->n_rules)
12089 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
12093 for (i = 0; i < rdev->coalesce->n_rules; i++) {
12094 nl_rule = nla_nest_start_noflag(msg, i + 1);
12098 rule = &rdev->coalesce->rules[i];
12099 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
12103 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
12107 nl_pats = nla_nest_start_noflag(msg,
12108 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
12112 for (j = 0; j < rule->n_patterns; j++) {
12113 nl_pat = nla_nest_start_noflag(msg, j + 1);
12116 pat_len = rule->patterns[j].pattern_len;
12117 if (nla_put(msg, NL80211_PKTPAT_MASK,
12118 DIV_ROUND_UP(pat_len, 8),
12119 rule->patterns[j].mask) ||
12120 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
12121 rule->patterns[j].pattern) ||
12122 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
12123 rule->patterns[j].pkt_offset))
12125 nla_nest_end(msg, nl_pat);
12127 nla_nest_end(msg, nl_pats);
12128 nla_nest_end(msg, nl_rule);
12130 nla_nest_end(msg, nl_rules);
12135 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
12137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12138 struct sk_buff *msg;
12141 if (!rdev->wiphy.coalesce)
12142 return -EOPNOTSUPP;
12144 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12148 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12149 NL80211_CMD_GET_COALESCE);
12151 goto nla_put_failure;
12153 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
12154 goto nla_put_failure;
12156 genlmsg_end(msg, hdr);
12157 return genlmsg_reply(msg, info);
12164 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
12166 struct cfg80211_coalesce *coalesce = rdev->coalesce;
12168 struct cfg80211_coalesce_rules *rule;
12173 for (i = 0; i < coalesce->n_rules; i++) {
12174 rule = &coalesce->rules[i];
12175 for (j = 0; j < rule->n_patterns; j++)
12176 kfree(rule->patterns[j].mask);
12177 kfree(rule->patterns);
12179 kfree(coalesce->rules);
12181 rdev->coalesce = NULL;
12184 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
12185 struct nlattr *rule,
12186 struct cfg80211_coalesce_rules *new_rule)
12189 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12190 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
12191 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
12192 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
12194 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
12195 rule, nl80211_coalesce_policy, NULL);
12199 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
12201 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
12202 if (new_rule->delay > coalesce->max_delay)
12205 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
12206 new_rule->condition =
12207 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
12209 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
12212 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12215 if (n_patterns > coalesce->n_patterns)
12218 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
12220 if (!new_rule->patterns)
12223 new_rule->n_patterns = n_patterns;
12226 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12230 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
12232 nl80211_packet_pattern_policy,
12237 if (!pat_tb[NL80211_PKTPAT_MASK] ||
12238 !pat_tb[NL80211_PKTPAT_PATTERN])
12240 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
12241 mask_len = DIV_ROUND_UP(pat_len, 8);
12242 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
12244 if (pat_len > coalesce->pattern_max_len ||
12245 pat_len < coalesce->pattern_min_len)
12248 if (!pat_tb[NL80211_PKTPAT_OFFSET])
12251 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
12252 if (pkt_offset > coalesce->max_pkt_offset)
12254 new_rule->patterns[i].pkt_offset = pkt_offset;
12256 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12260 new_rule->patterns[i].mask = mask_pat;
12261 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
12264 mask_pat += mask_len;
12265 new_rule->patterns[i].pattern = mask_pat;
12266 new_rule->patterns[i].pattern_len = pat_len;
12267 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
12275 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
12277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12278 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12279 struct cfg80211_coalesce new_coalesce = {};
12280 struct cfg80211_coalesce *n_coalesce;
12281 int err, rem_rule, n_rules = 0, i, j;
12282 struct nlattr *rule;
12283 struct cfg80211_coalesce_rules *tmp_rule;
12285 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
12286 return -EOPNOTSUPP;
12288 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
12289 cfg80211_rdev_free_coalesce(rdev);
12290 rdev_set_coalesce(rdev, NULL);
12294 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12297 if (n_rules > coalesce->n_rules)
12300 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
12302 if (!new_coalesce.rules)
12305 new_coalesce.n_rules = n_rules;
12308 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12310 err = nl80211_parse_coalesce_rule(rdev, rule,
12311 &new_coalesce.rules[i]);
12318 err = rdev_set_coalesce(rdev, &new_coalesce);
12322 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
12327 cfg80211_rdev_free_coalesce(rdev);
12328 rdev->coalesce = n_coalesce;
12332 for (i = 0; i < new_coalesce.n_rules; i++) {
12333 tmp_rule = &new_coalesce.rules[i];
12334 for (j = 0; j < tmp_rule->n_patterns; j++)
12335 kfree(tmp_rule->patterns[j].mask);
12336 kfree(tmp_rule->patterns);
12338 kfree(new_coalesce.rules);
12343 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
12345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12346 struct net_device *dev = info->user_ptr[1];
12347 struct wireless_dev *wdev = dev->ieee80211_ptr;
12348 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
12349 struct cfg80211_gtk_rekey_data rekey_data;
12352 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
12355 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
12356 info->attrs[NL80211_ATTR_REKEY_DATA],
12357 nl80211_rekey_policy, info->extack);
12361 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
12362 !tb[NL80211_REKEY_DATA_KCK])
12364 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
12366 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN &&
12367 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
12368 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN))
12370 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN &&
12371 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
12372 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN))
12375 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
12376 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
12377 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
12378 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
12379 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]);
12380 if (tb[NL80211_REKEY_DATA_AKM])
12381 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]);
12384 if (!wdev->current_bss) {
12389 if (!rdev->ops->set_rekey_data) {
12394 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
12400 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
12401 struct genl_info *info)
12403 struct net_device *dev = info->user_ptr[1];
12404 struct wireless_dev *wdev = dev->ieee80211_ptr;
12406 if (wdev->iftype != NL80211_IFTYPE_AP &&
12407 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12410 if (wdev->ap_unexpected_nlportid)
12413 wdev->ap_unexpected_nlportid = info->snd_portid;
12417 static int nl80211_probe_client(struct sk_buff *skb,
12418 struct genl_info *info)
12420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12421 struct net_device *dev = info->user_ptr[1];
12422 struct wireless_dev *wdev = dev->ieee80211_ptr;
12423 struct sk_buff *msg;
12429 if (wdev->iftype != NL80211_IFTYPE_AP &&
12430 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12431 return -EOPNOTSUPP;
12433 if (!info->attrs[NL80211_ATTR_MAC])
12436 if (!rdev->ops->probe_client)
12437 return -EOPNOTSUPP;
12439 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12443 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12444 NL80211_CMD_PROBE_CLIENT);
12450 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12452 err = rdev_probe_client(rdev, dev, addr, &cookie);
12456 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12458 goto nla_put_failure;
12460 genlmsg_end(msg, hdr);
12462 return genlmsg_reply(msg, info);
12471 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12474 struct cfg80211_beacon_registration *reg, *nreg;
12477 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12478 return -EOPNOTSUPP;
12480 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12484 /* First, check if already registered. */
12485 spin_lock_bh(&rdev->beacon_registrations_lock);
12486 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12487 if (reg->nlportid == info->snd_portid) {
12492 /* Add it to the list */
12493 nreg->nlportid = info->snd_portid;
12494 list_add(&nreg->list, &rdev->beacon_registrations);
12496 spin_unlock_bh(&rdev->beacon_registrations_lock);
12500 spin_unlock_bh(&rdev->beacon_registrations_lock);
12505 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
12507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12508 struct wireless_dev *wdev = info->user_ptr[1];
12511 if (!rdev->ops->start_p2p_device)
12512 return -EOPNOTSUPP;
12514 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12515 return -EOPNOTSUPP;
12517 if (wdev_running(wdev))
12520 if (rfkill_blocked(rdev->rfkill))
12523 err = rdev_start_p2p_device(rdev, wdev);
12527 wdev->is_running = true;
12533 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12535 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12536 struct wireless_dev *wdev = info->user_ptr[1];
12538 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12539 return -EOPNOTSUPP;
12541 if (!rdev->ops->stop_p2p_device)
12542 return -EOPNOTSUPP;
12544 cfg80211_stop_p2p_device(rdev, wdev);
12549 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12551 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12552 struct wireless_dev *wdev = info->user_ptr[1];
12553 struct cfg80211_nan_conf conf = {};
12556 if (wdev->iftype != NL80211_IFTYPE_NAN)
12557 return -EOPNOTSUPP;
12559 if (wdev_running(wdev))
12562 if (rfkill_blocked(rdev->rfkill))
12565 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12569 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12571 if (info->attrs[NL80211_ATTR_BANDS]) {
12572 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12574 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12575 return -EOPNOTSUPP;
12577 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12580 conf.bands = bands;
12583 err = rdev_start_nan(rdev, wdev, &conf);
12587 wdev->is_running = true;
12593 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12596 struct wireless_dev *wdev = info->user_ptr[1];
12598 if (wdev->iftype != NL80211_IFTYPE_NAN)
12599 return -EOPNOTSUPP;
12601 cfg80211_stop_nan(rdev, wdev);
12606 static int validate_nan_filter(struct nlattr *filter_attr)
12608 struct nlattr *attr;
12609 int len = 0, n_entries = 0, rem;
12611 nla_for_each_nested(attr, filter_attr, rem) {
12612 len += nla_len(attr);
12622 static int handle_nan_filter(struct nlattr *attr_filter,
12623 struct cfg80211_nan_func *func,
12626 struct nlattr *attr;
12627 int n_entries, rem, i;
12628 struct cfg80211_nan_func_filter *filter;
12630 n_entries = validate_nan_filter(attr_filter);
12634 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12636 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12641 nla_for_each_nested(attr, attr_filter, rem) {
12642 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
12643 filter[i].len = nla_len(attr);
12647 func->num_tx_filters = n_entries;
12648 func->tx_filters = filter;
12650 func->num_rx_filters = n_entries;
12651 func->rx_filters = filter;
12657 static int nl80211_nan_add_func(struct sk_buff *skb,
12658 struct genl_info *info)
12660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12661 struct wireless_dev *wdev = info->user_ptr[1];
12662 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12663 struct cfg80211_nan_func *func;
12664 struct sk_buff *msg = NULL;
12668 if (wdev->iftype != NL80211_IFTYPE_NAN)
12669 return -EOPNOTSUPP;
12671 if (!wdev_running(wdev))
12674 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12677 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12678 info->attrs[NL80211_ATTR_NAN_FUNC],
12679 nl80211_nan_func_policy,
12684 func = kzalloc(sizeof(*func), GFP_KERNEL);
12688 func->cookie = cfg80211_assign_cookie(rdev);
12690 if (!tb[NL80211_NAN_FUNC_TYPE] ||
12691 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
12697 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12699 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12704 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12705 sizeof(func->service_id));
12707 func->close_range =
12708 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12710 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12711 func->serv_spec_info_len =
12712 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12713 func->serv_spec_info =
12714 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12715 func->serv_spec_info_len,
12717 if (!func->serv_spec_info) {
12723 if (tb[NL80211_NAN_FUNC_TTL])
12724 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12726 switch (func->type) {
12727 case NL80211_NAN_FUNC_PUBLISH:
12728 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12733 func->publish_type =
12734 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12735 func->publish_bcast =
12736 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12738 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12739 func->publish_bcast) {
12744 case NL80211_NAN_FUNC_SUBSCRIBE:
12745 func->subscribe_active =
12746 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12748 case NL80211_NAN_FUNC_FOLLOW_UP:
12749 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
12750 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12751 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
12756 func->followup_id =
12757 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12758 func->followup_reqid =
12759 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12760 memcpy(func->followup_dest.addr,
12761 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12762 sizeof(func->followup_dest.addr));
12773 if (tb[NL80211_NAN_FUNC_SRF]) {
12774 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12776 err = nla_parse_nested_deprecated(srf_tb,
12777 NL80211_NAN_SRF_ATTR_MAX,
12778 tb[NL80211_NAN_FUNC_SRF],
12779 nl80211_nan_srf_policy,
12784 func->srf_include =
12785 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12787 if (srf_tb[NL80211_NAN_SRF_BF]) {
12788 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12789 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12795 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12797 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12798 func->srf_bf_len, GFP_KERNEL);
12799 if (!func->srf_bf) {
12805 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12807 struct nlattr *attr, *mac_attr =
12808 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12809 int n_entries, rem, i = 0;
12816 n_entries = validate_acl_mac_addrs(mac_attr);
12817 if (n_entries <= 0) {
12822 func->srf_num_macs = n_entries;
12824 kcalloc(n_entries, sizeof(*func->srf_macs),
12826 if (!func->srf_macs) {
12831 nla_for_each_nested(attr, mac_attr, rem)
12832 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12833 sizeof(*func->srf_macs));
12837 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12838 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12844 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12845 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12857 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12858 NL80211_CMD_ADD_NAN_FUNCTION);
12859 /* This can't really happen - we just allocated 4KB */
12860 if (WARN_ON(!hdr)) {
12865 err = rdev_add_nan_func(rdev, wdev, func);
12868 cfg80211_free_nan_func(func);
12873 /* propagate the instance id and cookie to userspace */
12874 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12876 goto nla_put_failure;
12878 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
12880 goto nla_put_failure;
12882 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12883 func->instance_id))
12884 goto nla_put_failure;
12886 nla_nest_end(msg, func_attr);
12888 genlmsg_end(msg, hdr);
12889 return genlmsg_reply(msg, info);
12896 static int nl80211_nan_del_func(struct sk_buff *skb,
12897 struct genl_info *info)
12899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12900 struct wireless_dev *wdev = info->user_ptr[1];
12903 if (wdev->iftype != NL80211_IFTYPE_NAN)
12904 return -EOPNOTSUPP;
12906 if (!wdev_running(wdev))
12909 if (!info->attrs[NL80211_ATTR_COOKIE])
12912 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12914 rdev_del_nan_func(rdev, wdev, cookie);
12919 static int nl80211_nan_change_config(struct sk_buff *skb,
12920 struct genl_info *info)
12922 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12923 struct wireless_dev *wdev = info->user_ptr[1];
12924 struct cfg80211_nan_conf conf = {};
12927 if (wdev->iftype != NL80211_IFTYPE_NAN)
12928 return -EOPNOTSUPP;
12930 if (!wdev_running(wdev))
12933 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12935 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12936 if (conf.master_pref <= 1 || conf.master_pref == 255)
12939 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12942 if (info->attrs[NL80211_ATTR_BANDS]) {
12943 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12945 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12946 return -EOPNOTSUPP;
12948 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12951 conf.bands = bands;
12952 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
12958 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12961 void cfg80211_nan_match(struct wireless_dev *wdev,
12962 struct cfg80211_nan_match_params *match, gfp_t gfp)
12964 struct wiphy *wiphy = wdev->wiphy;
12965 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12966 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12967 struct sk_buff *msg;
12970 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12977 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12983 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12984 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12985 wdev->netdev->ifindex)) ||
12986 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12988 goto nla_put_failure;
12990 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12991 NL80211_ATTR_PAD) ||
12992 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12993 goto nla_put_failure;
12995 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
12997 goto nla_put_failure;
12999 local_func_attr = nla_nest_start_noflag(msg,
13000 NL80211_NAN_MATCH_FUNC_LOCAL);
13001 if (!local_func_attr)
13002 goto nla_put_failure;
13004 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
13005 goto nla_put_failure;
13007 nla_nest_end(msg, local_func_attr);
13009 peer_func_attr = nla_nest_start_noflag(msg,
13010 NL80211_NAN_MATCH_FUNC_PEER);
13011 if (!peer_func_attr)
13012 goto nla_put_failure;
13014 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
13015 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
13016 goto nla_put_failure;
13018 if (match->info && match->info_len &&
13019 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
13021 goto nla_put_failure;
13023 nla_nest_end(msg, peer_func_attr);
13024 nla_nest_end(msg, match_attr);
13025 genlmsg_end(msg, hdr);
13027 if (!wdev->owner_nlportid)
13028 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
13029 msg, 0, NL80211_MCGRP_NAN, gfp);
13031 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
13032 wdev->owner_nlportid);
13039 EXPORT_SYMBOL(cfg80211_nan_match);
13041 void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
13043 enum nl80211_nan_func_term_reason reason,
13044 u64 cookie, gfp_t gfp)
13046 struct wiphy *wiphy = wdev->wiphy;
13047 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13048 struct sk_buff *msg;
13049 struct nlattr *func_attr;
13052 if (WARN_ON(!inst_id))
13055 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13059 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
13065 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13066 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13067 wdev->netdev->ifindex)) ||
13068 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13070 goto nla_put_failure;
13072 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13074 goto nla_put_failure;
13076 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
13078 goto nla_put_failure;
13080 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
13081 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
13082 goto nla_put_failure;
13084 nla_nest_end(msg, func_attr);
13085 genlmsg_end(msg, hdr);
13087 if (!wdev->owner_nlportid)
13088 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
13089 msg, 0, NL80211_MCGRP_NAN, gfp);
13091 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
13092 wdev->owner_nlportid);
13099 EXPORT_SYMBOL(cfg80211_nan_func_terminated);
13101 static int nl80211_get_protocol_features(struct sk_buff *skb,
13102 struct genl_info *info)
13105 struct sk_buff *msg;
13107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13111 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13112 NL80211_CMD_GET_PROTOCOL_FEATURES);
13114 goto nla_put_failure;
13116 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
13117 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
13118 goto nla_put_failure;
13120 genlmsg_end(msg, hdr);
13121 return genlmsg_reply(msg, info);
13128 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
13130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13131 struct cfg80211_update_ft_ies_params ft_params;
13132 struct net_device *dev = info->user_ptr[1];
13134 if (!rdev->ops->update_ft_ies)
13135 return -EOPNOTSUPP;
13137 if (!info->attrs[NL80211_ATTR_MDID] ||
13138 !info->attrs[NL80211_ATTR_IE])
13141 memset(&ft_params, 0, sizeof(ft_params));
13142 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
13143 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13144 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13146 return rdev_update_ft_ies(rdev, dev, &ft_params);
13149 static int nl80211_crit_protocol_start(struct sk_buff *skb,
13150 struct genl_info *info)
13152 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13153 struct wireless_dev *wdev = info->user_ptr[1];
13154 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
13158 if (!rdev->ops->crit_proto_start)
13159 return -EOPNOTSUPP;
13161 if (WARN_ON(!rdev->ops->crit_proto_stop))
13164 if (rdev->crit_proto_nlportid)
13167 /* determine protocol if provided */
13168 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
13169 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
13171 if (proto >= NUM_NL80211_CRIT_PROTO)
13174 /* timeout must be provided */
13175 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
13179 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
13181 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
13184 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
13186 rdev->crit_proto_nlportid = info->snd_portid;
13191 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
13192 struct genl_info *info)
13194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13195 struct wireless_dev *wdev = info->user_ptr[1];
13197 if (!rdev->ops->crit_proto_stop)
13198 return -EOPNOTSUPP;
13200 if (rdev->crit_proto_nlportid) {
13201 rdev->crit_proto_nlportid = 0;
13202 rdev_crit_proto_stop(rdev, wdev);
13207 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
13208 struct nlattr *attr,
13209 struct netlink_ext_ack *extack)
13211 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
13212 if (attr->nla_type & NLA_F_NESTED) {
13213 NL_SET_ERR_MSG_ATTR(extack, attr,
13214 "unexpected nested data");
13221 if (!(attr->nla_type & NLA_F_NESTED)) {
13222 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
13226 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
13229 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
13231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13232 struct wireless_dev *wdev =
13233 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
13237 if (!rdev->wiphy.vendor_commands)
13238 return -EOPNOTSUPP;
13240 if (IS_ERR(wdev)) {
13241 err = PTR_ERR(wdev);
13242 if (err != -EINVAL)
13245 } else if (wdev->wiphy != &rdev->wiphy) {
13249 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
13250 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
13253 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
13254 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
13255 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
13256 const struct wiphy_vendor_command *vcmd;
13260 vcmd = &rdev->wiphy.vendor_commands[i];
13262 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13265 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13266 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
13269 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
13273 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
13274 if (!wdev_running(wdev))
13282 return -EOPNOTSUPP;
13284 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
13285 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
13286 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
13288 err = nl80211_vendor_check_policy(vcmd,
13289 info->attrs[NL80211_ATTR_VENDOR_DATA],
13295 rdev->cur_cmd_info = info;
13296 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
13297 rdev->cur_cmd_info = NULL;
13301 return -EOPNOTSUPP;
13304 static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
13305 struct netlink_callback *cb,
13306 struct cfg80211_registered_device **rdev,
13307 struct wireless_dev **wdev)
13309 struct nlattr **attrbuf;
13315 unsigned int data_len = 0;
13318 /* subtract the 1 again here */
13319 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
13320 struct wireless_dev *tmp;
13324 *rdev = wiphy_to_rdev(wiphy);
13328 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
13329 if (tmp->identifier == cb->args[1] - 1) {
13336 /* keep rtnl locked in successful case */
13340 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
13344 err = nlmsg_parse_deprecated(cb->nlh,
13345 GENL_HDRLEN + nl80211_fam.hdrsize,
13346 attrbuf, nl80211_fam.maxattr,
13347 nl80211_policy, NULL);
13351 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
13352 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
13357 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
13361 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
13362 if (IS_ERR(*rdev)) {
13363 err = PTR_ERR(*rdev);
13367 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
13368 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
13370 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
13371 const struct wiphy_vendor_command *vcmd;
13373 vcmd = &(*rdev)->wiphy.vendor_commands[i];
13375 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13378 if (!vcmd->dumpit) {
13387 if (vcmd_idx < 0) {
13392 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
13393 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13394 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13396 err = nl80211_vendor_check_policy(
13397 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
13398 attrbuf[NL80211_ATTR_VENDOR_DATA],
13404 /* 0 is the first index - add 1 to parse only once */
13405 cb->args[0] = (*rdev)->wiphy_idx + 1;
13406 /* add 1 to know if it was NULL */
13407 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
13408 cb->args[2] = vcmd_idx;
13409 cb->args[3] = (unsigned long)data;
13410 cb->args[4] = data_len;
13412 /* keep rtnl locked in successful case */
13419 static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
13420 struct netlink_callback *cb)
13422 struct cfg80211_registered_device *rdev;
13423 struct wireless_dev *wdev;
13424 unsigned int vcmd_idx;
13425 const struct wiphy_vendor_command *vcmd;
13429 struct nlattr *vendor_data;
13432 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13436 vcmd_idx = cb->args[2];
13437 data = (void *)cb->args[3];
13438 data_len = cb->args[4];
13439 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
13441 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13442 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
13447 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
13453 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
13454 if (!wdev_running(wdev)) {
13462 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
13463 cb->nlh->nlmsg_seq, NLM_F_MULTI,
13464 NL80211_CMD_VENDOR);
13468 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13469 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13471 NL80211_ATTR_PAD))) {
13472 genlmsg_cancel(skb, hdr);
13476 vendor_data = nla_nest_start_noflag(skb,
13477 NL80211_ATTR_VENDOR_DATA);
13478 if (!vendor_data) {
13479 genlmsg_cancel(skb, hdr);
13483 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
13484 (unsigned long *)&cb->args[5]);
13485 nla_nest_end(skb, vendor_data);
13487 if (err == -ENOBUFS || err == -ENOENT) {
13488 genlmsg_cancel(skb, hdr);
13490 } else if (err <= 0) {
13491 genlmsg_cancel(skb, hdr);
13495 genlmsg_end(skb, hdr);
13504 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13505 enum nl80211_commands cmd,
13506 enum nl80211_attrs attr,
13509 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13511 if (WARN_ON(!rdev->cur_cmd_info))
13514 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
13515 rdev->cur_cmd_info->snd_portid,
13516 rdev->cur_cmd_info->snd_seq,
13517 cmd, attr, NULL, GFP_KERNEL);
13519 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13521 int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
13523 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
13524 void *hdr = ((void **)skb->cb)[1];
13525 struct nlattr *data = ((void **)skb->cb)[2];
13527 /* clear CB data for netlink core to own from now on */
13528 memset(skb->cb, 0, sizeof(skb->cb));
13530 if (WARN_ON(!rdev->cur_cmd_info)) {
13535 nla_nest_end(skb, data);
13536 genlmsg_end(skb, hdr);
13537 return genlmsg_reply(skb, rdev->cur_cmd_info);
13539 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13541 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
13543 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13545 if (WARN_ON(!rdev->cur_cmd_info))
13548 return rdev->cur_cmd_info->snd_portid;
13550 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13552 static int nl80211_set_qos_map(struct sk_buff *skb,
13553 struct genl_info *info)
13555 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13556 struct cfg80211_qos_map *qos_map = NULL;
13557 struct net_device *dev = info->user_ptr[1];
13558 u8 *pos, len, num_des, des_len, des;
13561 if (!rdev->ops->set_qos_map)
13562 return -EOPNOTSUPP;
13564 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13565 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13566 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13568 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
13569 len > IEEE80211_QOS_MAP_LEN_MAX)
13572 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13576 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13578 des_len = num_des *
13579 sizeof(struct cfg80211_dscp_exception);
13580 memcpy(qos_map->dscp_exception, pos, des_len);
13581 qos_map->num_des = num_des;
13582 for (des = 0; des < num_des; des++) {
13583 if (qos_map->dscp_exception[des].up > 7) {
13590 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13593 wdev_lock(dev->ieee80211_ptr);
13594 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13596 ret = rdev_set_qos_map(rdev, dev, qos_map);
13597 wdev_unlock(dev->ieee80211_ptr);
13603 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13605 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13606 struct net_device *dev = info->user_ptr[1];
13607 struct wireless_dev *wdev = dev->ieee80211_ptr;
13610 u16 admitted_time = 0;
13613 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
13614 return -EOPNOTSUPP;
13616 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13617 !info->attrs[NL80211_ATTR_USER_PRIO])
13620 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13621 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
13623 /* WMM uses TIDs 0-7 even for TSPEC */
13624 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
13625 /* TODO: handle 802.11 TSPEC/admission control
13626 * need more attributes for that (e.g. BA session requirement);
13627 * change the WMM adminssion test above to allow both then
13632 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13634 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13636 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13637 if (!admitted_time)
13642 switch (wdev->iftype) {
13643 case NL80211_IFTYPE_STATION:
13644 case NL80211_IFTYPE_P2P_CLIENT:
13645 if (wdev->current_bss)
13654 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13661 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13663 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13664 struct net_device *dev = info->user_ptr[1];
13665 struct wireless_dev *wdev = dev->ieee80211_ptr;
13670 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13673 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13674 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13677 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13683 static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13684 struct genl_info *info)
13686 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13687 struct net_device *dev = info->user_ptr[1];
13688 struct wireless_dev *wdev = dev->ieee80211_ptr;
13689 struct cfg80211_chan_def chandef = {};
13694 if (!rdev->ops->tdls_channel_switch ||
13695 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13696 return -EOPNOTSUPP;
13698 switch (dev->ieee80211_ptr->iftype) {
13699 case NL80211_IFTYPE_STATION:
13700 case NL80211_IFTYPE_P2P_CLIENT:
13703 return -EOPNOTSUPP;
13706 if (!info->attrs[NL80211_ATTR_MAC] ||
13707 !info->attrs[NL80211_ATTR_OPER_CLASS])
13710 err = nl80211_parse_chandef(rdev, info, &chandef);
13715 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13716 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13717 * specification is not defined for them.
13719 if (chandef.chan->band == NL80211_BAND_2GHZ &&
13720 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13721 chandef.width != NL80211_CHAN_WIDTH_20)
13724 /* we will be active on the TDLS link */
13725 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13729 /* don't allow switching to DFS channels */
13730 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13733 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13734 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13737 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13743 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13744 struct genl_info *info)
13746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13747 struct net_device *dev = info->user_ptr[1];
13748 struct wireless_dev *wdev = dev->ieee80211_ptr;
13751 if (!rdev->ops->tdls_channel_switch ||
13752 !rdev->ops->tdls_cancel_channel_switch ||
13753 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13754 return -EOPNOTSUPP;
13756 switch (dev->ieee80211_ptr->iftype) {
13757 case NL80211_IFTYPE_STATION:
13758 case NL80211_IFTYPE_P2P_CLIENT:
13761 return -EOPNOTSUPP;
13764 if (!info->attrs[NL80211_ATTR_MAC])
13767 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13770 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13776 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13777 struct genl_info *info)
13779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13780 struct net_device *dev = info->user_ptr[1];
13781 struct wireless_dev *wdev = dev->ieee80211_ptr;
13782 const struct nlattr *nla;
13785 if (!rdev->ops->set_multicast_to_unicast)
13786 return -EOPNOTSUPP;
13788 if (wdev->iftype != NL80211_IFTYPE_AP &&
13789 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13790 return -EOPNOTSUPP;
13792 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13793 enabled = nla_get_flag(nla);
13795 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13798 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13801 struct net_device *dev = info->user_ptr[1];
13802 struct wireless_dev *wdev = dev->ieee80211_ptr;
13803 struct cfg80211_pmk_conf pmk_conf = {};
13806 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13807 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13808 return -EOPNOTSUPP;
13810 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13811 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13812 return -EOPNOTSUPP;
13814 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13818 if (!wdev->current_bss) {
13823 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13824 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13829 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13830 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13831 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13832 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13837 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13838 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13840 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13845 pmk_conf.pmk_r0_name =
13846 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13849 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13855 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13858 struct net_device *dev = info->user_ptr[1];
13859 struct wireless_dev *wdev = dev->ieee80211_ptr;
13863 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13864 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13865 return -EOPNOTSUPP;
13867 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13868 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13869 return -EOPNOTSUPP;
13871 if (!info->attrs[NL80211_ATTR_MAC])
13875 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13876 ret = rdev_del_pmk(rdev, dev, aa);
13882 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13885 struct net_device *dev = info->user_ptr[1];
13886 struct cfg80211_external_auth_params params;
13888 if (!rdev->ops->external_auth)
13889 return -EOPNOTSUPP;
13891 if (!info->attrs[NL80211_ATTR_SSID] &&
13892 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13893 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
13896 if (!info->attrs[NL80211_ATTR_BSSID])
13899 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13902 memset(¶ms, 0, sizeof(params));
13904 if (info->attrs[NL80211_ATTR_SSID]) {
13905 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13906 if (params.ssid.ssid_len == 0 ||
13907 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13909 memcpy(params.ssid.ssid,
13910 nla_data(info->attrs[NL80211_ATTR_SSID]),
13911 params.ssid.ssid_len);
13914 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13917 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13919 if (info->attrs[NL80211_ATTR_PMKID])
13920 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13922 return rdev_external_auth(rdev, dev, ¶ms);
13925 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13927 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
13928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13929 struct net_device *dev = info->user_ptr[1];
13930 struct wireless_dev *wdev = dev->ieee80211_ptr;
13939 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13940 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13941 return -EOPNOTSUPP;
13943 if (!rdev->ops->tx_control_port)
13944 return -EOPNOTSUPP;
13946 if (!info->attrs[NL80211_ATTR_FRAME] ||
13947 !info->attrs[NL80211_ATTR_MAC] ||
13948 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13949 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13955 switch (wdev->iftype) {
13956 case NL80211_IFTYPE_AP:
13957 case NL80211_IFTYPE_P2P_GO:
13958 case NL80211_IFTYPE_MESH_POINT:
13960 case NL80211_IFTYPE_ADHOC:
13961 case NL80211_IFTYPE_STATION:
13962 case NL80211_IFTYPE_P2P_CLIENT:
13963 if (wdev->current_bss)
13974 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13975 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13976 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13977 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13979 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13981 err = rdev_tx_control_port(rdev, dev, buf, len,
13982 dest, cpu_to_be16(proto), noencrypt,
13983 dont_wait_for_ack ? NULL : &cookie);
13984 if (!err && !dont_wait_for_ack)
13985 nl_set_extack_cookie_u64(info->extack, cookie);
13992 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13993 struct genl_info *info)
13995 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13996 struct net_device *dev = info->user_ptr[1];
13997 struct wireless_dev *wdev = dev->ieee80211_ptr;
13998 struct cfg80211_ftm_responder_stats ftm_stats = {};
13999 struct sk_buff *msg;
14001 struct nlattr *ftm_stats_attr;
14004 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
14005 return -EOPNOTSUPP;
14007 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
14011 if (!ftm_stats.filled)
14014 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14018 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14019 NL80211_CMD_GET_FTM_RESPONDER_STATS);
14021 goto nla_put_failure;
14023 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
14024 goto nla_put_failure;
14026 ftm_stats_attr = nla_nest_start_noflag(msg,
14027 NL80211_ATTR_FTM_RESPONDER_STATS);
14028 if (!ftm_stats_attr)
14029 goto nla_put_failure;
14031 #define SET_FTM(field, name, type) \
14032 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14033 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
14034 ftm_stats.field)) \
14035 goto nla_put_failure; } while (0)
14036 #define SET_FTM_U64(field, name) \
14037 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14038 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
14039 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
14040 goto nla_put_failure; } while (0)
14042 SET_FTM(success_num, SUCCESS_NUM, u32);
14043 SET_FTM(partial_num, PARTIAL_NUM, u32);
14044 SET_FTM(failed_num, FAILED_NUM, u32);
14045 SET_FTM(asap_num, ASAP_NUM, u32);
14046 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
14047 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
14048 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
14049 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
14050 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
14053 nla_nest_end(msg, ftm_stats_attr);
14055 genlmsg_end(msg, hdr);
14056 return genlmsg_reply(msg, info);
14063 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
14065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14066 struct cfg80211_update_owe_info owe_info;
14067 struct net_device *dev = info->user_ptr[1];
14069 if (!rdev->ops->update_owe_info)
14070 return -EOPNOTSUPP;
14072 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
14073 !info->attrs[NL80211_ATTR_MAC])
14076 memset(&owe_info, 0, sizeof(owe_info));
14077 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
14078 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
14080 if (info->attrs[NL80211_ATTR_IE]) {
14081 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
14082 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
14085 return rdev_update_owe_info(rdev, dev, &owe_info);
14088 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
14090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14091 struct net_device *dev = info->user_ptr[1];
14092 struct wireless_dev *wdev = dev->ieee80211_ptr;
14093 struct station_info sinfo = {};
14099 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
14100 return -EOPNOTSUPP;
14102 if (!info->attrs[NL80211_ATTR_MAC] ||
14103 !info->attrs[NL80211_ATTR_FRAME]) {
14104 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
14108 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
14109 return -EOPNOTSUPP;
14111 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
14112 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
14113 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
14115 if (len < sizeof(struct ethhdr))
14118 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
14119 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
14122 err = rdev_get_station(rdev, dev, dest, &sinfo);
14126 cfg80211_sinfo_release_content(&sinfo);
14128 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
14131 static int parse_tid_conf(struct cfg80211_registered_device *rdev,
14132 struct nlattr *attrs[], struct net_device *dev,
14133 struct cfg80211_tid_cfg *tid_conf,
14134 struct genl_info *info, const u8 *peer)
14136 struct netlink_ext_ack *extack = info->extack;
14140 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS])
14143 tid_conf->config_override =
14144 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]);
14145 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
14147 if (tid_conf->config_override) {
14148 if (rdev->ops->reset_tid_config) {
14149 err = rdev_reset_tid_config(rdev, dev, peer,
14158 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
14159 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
14161 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
14164 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) {
14165 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT);
14166 tid_conf->retry_short =
14167 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]);
14169 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count)
14173 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) {
14174 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
14175 tid_conf->retry_long =
14176 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]);
14178 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count)
14182 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) {
14183 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
14185 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]);
14188 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) {
14189 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
14191 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]);
14194 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) {
14195 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL);
14197 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]);
14200 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) {
14201 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr;
14203 tid_conf->txrate_type = nla_get_u8(attrs[idx]);
14205 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) {
14206 attr = NL80211_TID_CONFIG_ATTR_TX_RATE;
14207 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr,
14208 &tid_conf->txrate_mask);
14212 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE);
14214 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
14218 mask = rdev->wiphy.tid_config_support.peer;
14220 mask = rdev->wiphy.tid_config_support.vif;
14222 if (tid_conf->mask & ~mask) {
14223 NL_SET_ERR_MSG(extack, "unsupported TID configuration");
14230 static int nl80211_set_tid_config(struct sk_buff *skb,
14231 struct genl_info *info)
14233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14234 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1];
14235 struct net_device *dev = info->user_ptr[1];
14236 struct cfg80211_tid_config *tid_config;
14237 struct nlattr *tid;
14238 int conf_idx = 0, rem_conf;
14242 if (!info->attrs[NL80211_ATTR_TID_CONFIG])
14245 if (!rdev->ops->set_tid_config)
14246 return -EOPNOTSUPP;
14248 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14252 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf),
14257 tid_config->n_tid_conf = num_conf;
14259 if (info->attrs[NL80211_ATTR_MAC])
14260 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
14262 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14264 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX,
14270 ret = parse_tid_conf(rdev, attrs, dev,
14271 &tid_config->tid_conf[conf_idx],
14272 info, tid_config->peer);
14279 ret = rdev_set_tid_config(rdev, dev, tid_config);
14286 #define NL80211_FLAG_NEED_WIPHY 0x01
14287 #define NL80211_FLAG_NEED_NETDEV 0x02
14288 #define NL80211_FLAG_NEED_RTNL 0x04
14289 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
14290 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
14291 NL80211_FLAG_CHECK_NETDEV_UP)
14292 #define NL80211_FLAG_NEED_WDEV 0x10
14293 /* If a netdev is associated, it must be UP, P2P must be started */
14294 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
14295 NL80211_FLAG_CHECK_NETDEV_UP)
14296 #define NL80211_FLAG_CLEAR_SKB 0x20
14298 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
14299 struct genl_info *info)
14301 struct cfg80211_registered_device *rdev;
14302 struct wireless_dev *wdev;
14303 struct net_device *dev;
14304 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
14309 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
14310 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
14311 if (IS_ERR(rdev)) {
14314 return PTR_ERR(rdev);
14316 info->user_ptr[0] = rdev;
14317 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
14318 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
14321 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
14323 if (IS_ERR(wdev)) {
14326 return PTR_ERR(wdev);
14329 dev = wdev->netdev;
14330 rdev = wiphy_to_rdev(wdev->wiphy);
14332 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
14339 info->user_ptr[1] = dev;
14341 info->user_ptr[1] = wdev;
14344 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
14345 !wdev_running(wdev)) {
14354 info->user_ptr[0] = rdev;
14360 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
14361 struct genl_info *info)
14363 if (info->user_ptr[1]) {
14364 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
14365 struct wireless_dev *wdev = info->user_ptr[1];
14368 dev_put(wdev->netdev);
14370 dev_put(info->user_ptr[1]);
14374 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
14377 /* If needed, clear the netlink message payload from the SKB
14378 * as it might contain key data that shouldn't stick around on
14379 * the heap after the SKB is freed. The netlink message header
14380 * is still needed for further processing, so leave it intact.
14382 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
14383 struct nlmsghdr *nlh = nlmsg_hdr(skb);
14385 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
14389 static const struct genl_ops nl80211_ops[] = {
14391 .cmd = NL80211_CMD_GET_WIPHY,
14392 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14393 .doit = nl80211_get_wiphy,
14394 .dumpit = nl80211_dump_wiphy,
14395 .done = nl80211_dump_wiphy_done,
14396 /* can be retrieved by unprivileged users */
14397 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14398 NL80211_FLAG_NEED_RTNL,
14401 .cmd = NL80211_CMD_SET_WIPHY,
14402 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14403 .doit = nl80211_set_wiphy,
14404 .flags = GENL_UNS_ADMIN_PERM,
14405 .internal_flags = NL80211_FLAG_NEED_RTNL,
14408 .cmd = NL80211_CMD_GET_INTERFACE,
14409 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14410 .doit = nl80211_get_interface,
14411 .dumpit = nl80211_dump_interface,
14412 /* can be retrieved by unprivileged users */
14413 .internal_flags = NL80211_FLAG_NEED_WDEV |
14414 NL80211_FLAG_NEED_RTNL,
14417 .cmd = NL80211_CMD_SET_INTERFACE,
14418 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14419 .doit = nl80211_set_interface,
14420 .flags = GENL_UNS_ADMIN_PERM,
14421 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14422 NL80211_FLAG_NEED_RTNL,
14425 .cmd = NL80211_CMD_NEW_INTERFACE,
14426 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14427 .doit = nl80211_new_interface,
14428 .flags = GENL_UNS_ADMIN_PERM,
14429 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14430 NL80211_FLAG_NEED_RTNL,
14433 .cmd = NL80211_CMD_DEL_INTERFACE,
14434 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14435 .doit = nl80211_del_interface,
14436 .flags = GENL_UNS_ADMIN_PERM,
14437 .internal_flags = NL80211_FLAG_NEED_WDEV |
14438 NL80211_FLAG_NEED_RTNL,
14441 .cmd = NL80211_CMD_GET_KEY,
14442 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14443 .doit = nl80211_get_key,
14444 .flags = GENL_UNS_ADMIN_PERM,
14445 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14446 NL80211_FLAG_NEED_RTNL,
14449 .cmd = NL80211_CMD_SET_KEY,
14450 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14451 .doit = nl80211_set_key,
14452 .flags = GENL_UNS_ADMIN_PERM,
14453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14454 NL80211_FLAG_NEED_RTNL |
14455 NL80211_FLAG_CLEAR_SKB,
14458 .cmd = NL80211_CMD_NEW_KEY,
14459 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14460 .doit = nl80211_new_key,
14461 .flags = GENL_UNS_ADMIN_PERM,
14462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14463 NL80211_FLAG_NEED_RTNL |
14464 NL80211_FLAG_CLEAR_SKB,
14467 .cmd = NL80211_CMD_DEL_KEY,
14468 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14469 .doit = nl80211_del_key,
14470 .flags = GENL_UNS_ADMIN_PERM,
14471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14472 NL80211_FLAG_NEED_RTNL,
14475 .cmd = NL80211_CMD_SET_BEACON,
14476 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14477 .flags = GENL_UNS_ADMIN_PERM,
14478 .doit = nl80211_set_beacon,
14479 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14480 NL80211_FLAG_NEED_RTNL,
14483 .cmd = NL80211_CMD_START_AP,
14484 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14485 .flags = GENL_UNS_ADMIN_PERM,
14486 .doit = nl80211_start_ap,
14487 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14488 NL80211_FLAG_NEED_RTNL,
14491 .cmd = NL80211_CMD_STOP_AP,
14492 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14493 .flags = GENL_UNS_ADMIN_PERM,
14494 .doit = nl80211_stop_ap,
14495 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14496 NL80211_FLAG_NEED_RTNL,
14499 .cmd = NL80211_CMD_GET_STATION,
14500 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14501 .doit = nl80211_get_station,
14502 .dumpit = nl80211_dump_station,
14503 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14504 NL80211_FLAG_NEED_RTNL,
14507 .cmd = NL80211_CMD_SET_STATION,
14508 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14509 .doit = nl80211_set_station,
14510 .flags = GENL_UNS_ADMIN_PERM,
14511 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14512 NL80211_FLAG_NEED_RTNL,
14515 .cmd = NL80211_CMD_NEW_STATION,
14516 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14517 .doit = nl80211_new_station,
14518 .flags = GENL_UNS_ADMIN_PERM,
14519 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14520 NL80211_FLAG_NEED_RTNL,
14523 .cmd = NL80211_CMD_DEL_STATION,
14524 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14525 .doit = nl80211_del_station,
14526 .flags = GENL_UNS_ADMIN_PERM,
14527 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14528 NL80211_FLAG_NEED_RTNL,
14531 .cmd = NL80211_CMD_GET_MPATH,
14532 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14533 .doit = nl80211_get_mpath,
14534 .dumpit = nl80211_dump_mpath,
14535 .flags = GENL_UNS_ADMIN_PERM,
14536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14537 NL80211_FLAG_NEED_RTNL,
14540 .cmd = NL80211_CMD_GET_MPP,
14541 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14542 .doit = nl80211_get_mpp,
14543 .dumpit = nl80211_dump_mpp,
14544 .flags = GENL_UNS_ADMIN_PERM,
14545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14546 NL80211_FLAG_NEED_RTNL,
14549 .cmd = NL80211_CMD_SET_MPATH,
14550 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14551 .doit = nl80211_set_mpath,
14552 .flags = GENL_UNS_ADMIN_PERM,
14553 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14554 NL80211_FLAG_NEED_RTNL,
14557 .cmd = NL80211_CMD_NEW_MPATH,
14558 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14559 .doit = nl80211_new_mpath,
14560 .flags = GENL_UNS_ADMIN_PERM,
14561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14562 NL80211_FLAG_NEED_RTNL,
14565 .cmd = NL80211_CMD_DEL_MPATH,
14566 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14567 .doit = nl80211_del_mpath,
14568 .flags = GENL_UNS_ADMIN_PERM,
14569 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14570 NL80211_FLAG_NEED_RTNL,
14573 .cmd = NL80211_CMD_SET_BSS,
14574 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14575 .doit = nl80211_set_bss,
14576 .flags = GENL_UNS_ADMIN_PERM,
14577 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14578 NL80211_FLAG_NEED_RTNL,
14581 .cmd = NL80211_CMD_GET_REG,
14582 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14583 .doit = nl80211_get_reg_do,
14584 .dumpit = nl80211_get_reg_dump,
14585 .internal_flags = NL80211_FLAG_NEED_RTNL,
14586 /* can be retrieved by unprivileged users */
14588 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
14590 .cmd = NL80211_CMD_SET_REG,
14591 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14592 .doit = nl80211_set_reg,
14593 .flags = GENL_ADMIN_PERM,
14594 .internal_flags = NL80211_FLAG_NEED_RTNL,
14598 .cmd = NL80211_CMD_REQ_SET_REG,
14599 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14600 .doit = nl80211_req_set_reg,
14601 .flags = GENL_ADMIN_PERM,
14604 .cmd = NL80211_CMD_RELOAD_REGDB,
14605 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14606 .doit = nl80211_reload_regdb,
14607 .flags = GENL_ADMIN_PERM,
14610 .cmd = NL80211_CMD_GET_MESH_CONFIG,
14611 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14612 .doit = nl80211_get_mesh_config,
14613 /* can be retrieved by unprivileged users */
14614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14615 NL80211_FLAG_NEED_RTNL,
14618 .cmd = NL80211_CMD_SET_MESH_CONFIG,
14619 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14620 .doit = nl80211_update_mesh_config,
14621 .flags = GENL_UNS_ADMIN_PERM,
14622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14623 NL80211_FLAG_NEED_RTNL,
14626 .cmd = NL80211_CMD_TRIGGER_SCAN,
14627 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14628 .doit = nl80211_trigger_scan,
14629 .flags = GENL_UNS_ADMIN_PERM,
14630 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14631 NL80211_FLAG_NEED_RTNL,
14634 .cmd = NL80211_CMD_ABORT_SCAN,
14635 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14636 .doit = nl80211_abort_scan,
14637 .flags = GENL_UNS_ADMIN_PERM,
14638 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14639 NL80211_FLAG_NEED_RTNL,
14642 .cmd = NL80211_CMD_GET_SCAN,
14643 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14644 .dumpit = nl80211_dump_scan,
14647 .cmd = NL80211_CMD_START_SCHED_SCAN,
14648 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14649 .doit = nl80211_start_sched_scan,
14650 .flags = GENL_UNS_ADMIN_PERM,
14651 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14652 NL80211_FLAG_NEED_RTNL,
14655 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
14656 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14657 .doit = nl80211_stop_sched_scan,
14658 .flags = GENL_UNS_ADMIN_PERM,
14659 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14660 NL80211_FLAG_NEED_RTNL,
14663 .cmd = NL80211_CMD_AUTHENTICATE,
14664 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14665 .doit = nl80211_authenticate,
14666 .flags = GENL_UNS_ADMIN_PERM,
14667 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14668 NL80211_FLAG_NEED_RTNL |
14669 NL80211_FLAG_CLEAR_SKB,
14672 .cmd = NL80211_CMD_ASSOCIATE,
14673 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14674 .doit = nl80211_associate,
14675 .flags = GENL_UNS_ADMIN_PERM,
14676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14677 NL80211_FLAG_NEED_RTNL |
14678 NL80211_FLAG_CLEAR_SKB,
14681 .cmd = NL80211_CMD_DEAUTHENTICATE,
14682 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14683 .doit = nl80211_deauthenticate,
14684 .flags = GENL_UNS_ADMIN_PERM,
14685 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14686 NL80211_FLAG_NEED_RTNL,
14689 .cmd = NL80211_CMD_DISASSOCIATE,
14690 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14691 .doit = nl80211_disassociate,
14692 .flags = GENL_UNS_ADMIN_PERM,
14693 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14694 NL80211_FLAG_NEED_RTNL,
14697 .cmd = NL80211_CMD_JOIN_IBSS,
14698 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14699 .doit = nl80211_join_ibss,
14700 .flags = GENL_UNS_ADMIN_PERM,
14701 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14702 NL80211_FLAG_NEED_RTNL,
14705 .cmd = NL80211_CMD_LEAVE_IBSS,
14706 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14707 .doit = nl80211_leave_ibss,
14708 .flags = GENL_UNS_ADMIN_PERM,
14709 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14710 NL80211_FLAG_NEED_RTNL,
14712 #ifdef CONFIG_NL80211_TESTMODE
14714 .cmd = NL80211_CMD_TESTMODE,
14715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14716 .doit = nl80211_testmode_do,
14717 .dumpit = nl80211_testmode_dump,
14718 .flags = GENL_UNS_ADMIN_PERM,
14719 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14720 NL80211_FLAG_NEED_RTNL,
14724 .cmd = NL80211_CMD_CONNECT,
14725 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14726 .doit = nl80211_connect,
14727 .flags = GENL_UNS_ADMIN_PERM,
14728 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14729 NL80211_FLAG_NEED_RTNL |
14730 NL80211_FLAG_CLEAR_SKB,
14733 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
14734 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14735 .doit = nl80211_update_connect_params,
14736 .flags = GENL_ADMIN_PERM,
14737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14738 NL80211_FLAG_NEED_RTNL |
14739 NL80211_FLAG_CLEAR_SKB,
14742 .cmd = NL80211_CMD_DISCONNECT,
14743 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14744 .doit = nl80211_disconnect,
14745 .flags = GENL_UNS_ADMIN_PERM,
14746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14747 NL80211_FLAG_NEED_RTNL,
14750 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
14751 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14752 .doit = nl80211_wiphy_netns,
14753 .flags = GENL_UNS_ADMIN_PERM,
14754 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14755 NL80211_FLAG_NEED_RTNL,
14758 .cmd = NL80211_CMD_GET_SURVEY,
14759 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14760 .dumpit = nl80211_dump_survey,
14763 .cmd = NL80211_CMD_SET_PMKSA,
14764 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14765 .doit = nl80211_setdel_pmksa,
14766 .flags = GENL_UNS_ADMIN_PERM,
14767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14768 NL80211_FLAG_NEED_RTNL |
14769 NL80211_FLAG_CLEAR_SKB,
14772 .cmd = NL80211_CMD_DEL_PMKSA,
14773 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14774 .doit = nl80211_setdel_pmksa,
14775 .flags = GENL_UNS_ADMIN_PERM,
14776 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14777 NL80211_FLAG_NEED_RTNL,
14780 .cmd = NL80211_CMD_FLUSH_PMKSA,
14781 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14782 .doit = nl80211_flush_pmksa,
14783 .flags = GENL_UNS_ADMIN_PERM,
14784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14785 NL80211_FLAG_NEED_RTNL,
14788 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
14789 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14790 .doit = nl80211_remain_on_channel,
14791 .flags = GENL_UNS_ADMIN_PERM,
14792 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14793 NL80211_FLAG_NEED_RTNL,
14796 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
14797 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14798 .doit = nl80211_cancel_remain_on_channel,
14799 .flags = GENL_UNS_ADMIN_PERM,
14800 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14801 NL80211_FLAG_NEED_RTNL,
14804 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
14805 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14806 .doit = nl80211_set_tx_bitrate_mask,
14807 .flags = GENL_UNS_ADMIN_PERM,
14808 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14809 NL80211_FLAG_NEED_RTNL,
14812 .cmd = NL80211_CMD_REGISTER_FRAME,
14813 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14814 .doit = nl80211_register_mgmt,
14815 .flags = GENL_UNS_ADMIN_PERM,
14816 .internal_flags = NL80211_FLAG_NEED_WDEV |
14817 NL80211_FLAG_NEED_RTNL,
14820 .cmd = NL80211_CMD_FRAME,
14821 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14822 .doit = nl80211_tx_mgmt,
14823 .flags = GENL_UNS_ADMIN_PERM,
14824 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14825 NL80211_FLAG_NEED_RTNL,
14828 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
14829 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14830 .doit = nl80211_tx_mgmt_cancel_wait,
14831 .flags = GENL_UNS_ADMIN_PERM,
14832 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14833 NL80211_FLAG_NEED_RTNL,
14836 .cmd = NL80211_CMD_SET_POWER_SAVE,
14837 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14838 .doit = nl80211_set_power_save,
14839 .flags = GENL_UNS_ADMIN_PERM,
14840 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14841 NL80211_FLAG_NEED_RTNL,
14844 .cmd = NL80211_CMD_GET_POWER_SAVE,
14845 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14846 .doit = nl80211_get_power_save,
14847 /* can be retrieved by unprivileged users */
14848 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14849 NL80211_FLAG_NEED_RTNL,
14852 .cmd = NL80211_CMD_SET_CQM,
14853 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14854 .doit = nl80211_set_cqm,
14855 .flags = GENL_UNS_ADMIN_PERM,
14856 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14857 NL80211_FLAG_NEED_RTNL,
14860 .cmd = NL80211_CMD_SET_CHANNEL,
14861 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14862 .doit = nl80211_set_channel,
14863 .flags = GENL_UNS_ADMIN_PERM,
14864 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14865 NL80211_FLAG_NEED_RTNL,
14868 .cmd = NL80211_CMD_SET_WDS_PEER,
14869 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14870 .doit = nl80211_set_wds_peer,
14871 .flags = GENL_UNS_ADMIN_PERM,
14872 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14873 NL80211_FLAG_NEED_RTNL,
14876 .cmd = NL80211_CMD_JOIN_MESH,
14877 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14878 .doit = nl80211_join_mesh,
14879 .flags = GENL_UNS_ADMIN_PERM,
14880 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14881 NL80211_FLAG_NEED_RTNL,
14884 .cmd = NL80211_CMD_LEAVE_MESH,
14885 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14886 .doit = nl80211_leave_mesh,
14887 .flags = GENL_UNS_ADMIN_PERM,
14888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14889 NL80211_FLAG_NEED_RTNL,
14892 .cmd = NL80211_CMD_JOIN_OCB,
14893 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14894 .doit = nl80211_join_ocb,
14895 .flags = GENL_UNS_ADMIN_PERM,
14896 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14897 NL80211_FLAG_NEED_RTNL,
14900 .cmd = NL80211_CMD_LEAVE_OCB,
14901 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14902 .doit = nl80211_leave_ocb,
14903 .flags = GENL_UNS_ADMIN_PERM,
14904 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14905 NL80211_FLAG_NEED_RTNL,
14909 .cmd = NL80211_CMD_GET_WOWLAN,
14910 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14911 .doit = nl80211_get_wowlan,
14912 /* can be retrieved by unprivileged users */
14913 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14914 NL80211_FLAG_NEED_RTNL,
14917 .cmd = NL80211_CMD_SET_WOWLAN,
14918 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14919 .doit = nl80211_set_wowlan,
14920 .flags = GENL_UNS_ADMIN_PERM,
14921 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14922 NL80211_FLAG_NEED_RTNL,
14926 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
14927 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14928 .doit = nl80211_set_rekey_data,
14929 .flags = GENL_UNS_ADMIN_PERM,
14930 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14931 NL80211_FLAG_NEED_RTNL |
14932 NL80211_FLAG_CLEAR_SKB,
14935 .cmd = NL80211_CMD_TDLS_MGMT,
14936 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14937 .doit = nl80211_tdls_mgmt,
14938 .flags = GENL_UNS_ADMIN_PERM,
14939 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14940 NL80211_FLAG_NEED_RTNL,
14943 .cmd = NL80211_CMD_TDLS_OPER,
14944 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14945 .doit = nl80211_tdls_oper,
14946 .flags = GENL_UNS_ADMIN_PERM,
14947 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14948 NL80211_FLAG_NEED_RTNL,
14951 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
14952 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14953 .doit = nl80211_register_unexpected_frame,
14954 .flags = GENL_UNS_ADMIN_PERM,
14955 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14956 NL80211_FLAG_NEED_RTNL,
14959 .cmd = NL80211_CMD_PROBE_CLIENT,
14960 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14961 .doit = nl80211_probe_client,
14962 .flags = GENL_UNS_ADMIN_PERM,
14963 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14964 NL80211_FLAG_NEED_RTNL,
14967 .cmd = NL80211_CMD_REGISTER_BEACONS,
14968 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14969 .doit = nl80211_register_beacons,
14970 .flags = GENL_UNS_ADMIN_PERM,
14971 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14972 NL80211_FLAG_NEED_RTNL,
14975 .cmd = NL80211_CMD_SET_NOACK_MAP,
14976 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14977 .doit = nl80211_set_noack_map,
14978 .flags = GENL_UNS_ADMIN_PERM,
14979 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14980 NL80211_FLAG_NEED_RTNL,
14983 .cmd = NL80211_CMD_START_P2P_DEVICE,
14984 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14985 .doit = nl80211_start_p2p_device,
14986 .flags = GENL_UNS_ADMIN_PERM,
14987 .internal_flags = NL80211_FLAG_NEED_WDEV |
14988 NL80211_FLAG_NEED_RTNL,
14991 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
14992 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14993 .doit = nl80211_stop_p2p_device,
14994 .flags = GENL_UNS_ADMIN_PERM,
14995 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14996 NL80211_FLAG_NEED_RTNL,
14999 .cmd = NL80211_CMD_START_NAN,
15000 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15001 .doit = nl80211_start_nan,
15002 .flags = GENL_ADMIN_PERM,
15003 .internal_flags = NL80211_FLAG_NEED_WDEV |
15004 NL80211_FLAG_NEED_RTNL,
15007 .cmd = NL80211_CMD_STOP_NAN,
15008 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15009 .doit = nl80211_stop_nan,
15010 .flags = GENL_ADMIN_PERM,
15011 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15012 NL80211_FLAG_NEED_RTNL,
15015 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
15016 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15017 .doit = nl80211_nan_add_func,
15018 .flags = GENL_ADMIN_PERM,
15019 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15020 NL80211_FLAG_NEED_RTNL,
15023 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
15024 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15025 .doit = nl80211_nan_del_func,
15026 .flags = GENL_ADMIN_PERM,
15027 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15028 NL80211_FLAG_NEED_RTNL,
15031 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
15032 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15033 .doit = nl80211_nan_change_config,
15034 .flags = GENL_ADMIN_PERM,
15035 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15036 NL80211_FLAG_NEED_RTNL,
15039 .cmd = NL80211_CMD_SET_MCAST_RATE,
15040 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15041 .doit = nl80211_set_mcast_rate,
15042 .flags = GENL_UNS_ADMIN_PERM,
15043 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15044 NL80211_FLAG_NEED_RTNL,
15047 .cmd = NL80211_CMD_SET_MAC_ACL,
15048 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15049 .doit = nl80211_set_mac_acl,
15050 .flags = GENL_UNS_ADMIN_PERM,
15051 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15052 NL80211_FLAG_NEED_RTNL,
15055 .cmd = NL80211_CMD_RADAR_DETECT,
15056 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15057 .doit = nl80211_start_radar_detection,
15058 .flags = GENL_UNS_ADMIN_PERM,
15059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15060 NL80211_FLAG_NEED_RTNL,
15063 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
15064 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15065 .doit = nl80211_get_protocol_features,
15068 .cmd = NL80211_CMD_UPDATE_FT_IES,
15069 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15070 .doit = nl80211_update_ft_ies,
15071 .flags = GENL_UNS_ADMIN_PERM,
15072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15073 NL80211_FLAG_NEED_RTNL,
15076 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
15077 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15078 .doit = nl80211_crit_protocol_start,
15079 .flags = GENL_UNS_ADMIN_PERM,
15080 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15081 NL80211_FLAG_NEED_RTNL,
15084 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
15085 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15086 .doit = nl80211_crit_protocol_stop,
15087 .flags = GENL_UNS_ADMIN_PERM,
15088 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15089 NL80211_FLAG_NEED_RTNL,
15092 .cmd = NL80211_CMD_GET_COALESCE,
15093 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15094 .doit = nl80211_get_coalesce,
15095 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15096 NL80211_FLAG_NEED_RTNL,
15099 .cmd = NL80211_CMD_SET_COALESCE,
15100 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15101 .doit = nl80211_set_coalesce,
15102 .flags = GENL_UNS_ADMIN_PERM,
15103 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15104 NL80211_FLAG_NEED_RTNL,
15107 .cmd = NL80211_CMD_CHANNEL_SWITCH,
15108 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15109 .doit = nl80211_channel_switch,
15110 .flags = GENL_UNS_ADMIN_PERM,
15111 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15112 NL80211_FLAG_NEED_RTNL,
15115 .cmd = NL80211_CMD_VENDOR,
15116 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15117 .doit = nl80211_vendor_cmd,
15118 .dumpit = nl80211_vendor_cmd_dump,
15119 .flags = GENL_UNS_ADMIN_PERM,
15120 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15121 NL80211_FLAG_NEED_RTNL |
15122 NL80211_FLAG_CLEAR_SKB,
15125 .cmd = NL80211_CMD_SET_QOS_MAP,
15126 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15127 .doit = nl80211_set_qos_map,
15128 .flags = GENL_UNS_ADMIN_PERM,
15129 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15130 NL80211_FLAG_NEED_RTNL,
15133 .cmd = NL80211_CMD_ADD_TX_TS,
15134 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15135 .doit = nl80211_add_tx_ts,
15136 .flags = GENL_UNS_ADMIN_PERM,
15137 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15138 NL80211_FLAG_NEED_RTNL,
15141 .cmd = NL80211_CMD_DEL_TX_TS,
15142 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15143 .doit = nl80211_del_tx_ts,
15144 .flags = GENL_UNS_ADMIN_PERM,
15145 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15146 NL80211_FLAG_NEED_RTNL,
15149 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
15150 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15151 .doit = nl80211_tdls_channel_switch,
15152 .flags = GENL_UNS_ADMIN_PERM,
15153 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15154 NL80211_FLAG_NEED_RTNL,
15157 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
15158 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15159 .doit = nl80211_tdls_cancel_channel_switch,
15160 .flags = GENL_UNS_ADMIN_PERM,
15161 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15162 NL80211_FLAG_NEED_RTNL,
15165 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
15166 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15167 .doit = nl80211_set_multicast_to_unicast,
15168 .flags = GENL_UNS_ADMIN_PERM,
15169 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15170 NL80211_FLAG_NEED_RTNL,
15173 .cmd = NL80211_CMD_SET_PMK,
15174 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15175 .doit = nl80211_set_pmk,
15176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15177 NL80211_FLAG_NEED_RTNL |
15178 NL80211_FLAG_CLEAR_SKB,
15181 .cmd = NL80211_CMD_DEL_PMK,
15182 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15183 .doit = nl80211_del_pmk,
15184 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15185 NL80211_FLAG_NEED_RTNL,
15188 .cmd = NL80211_CMD_EXTERNAL_AUTH,
15189 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15190 .doit = nl80211_external_auth,
15191 .flags = GENL_ADMIN_PERM,
15192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15193 NL80211_FLAG_NEED_RTNL,
15196 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
15197 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15198 .doit = nl80211_tx_control_port,
15199 .flags = GENL_UNS_ADMIN_PERM,
15200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15201 NL80211_FLAG_NEED_RTNL,
15204 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
15205 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15206 .doit = nl80211_get_ftm_responder_stats,
15207 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15208 NL80211_FLAG_NEED_RTNL,
15211 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
15212 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15213 .doit = nl80211_pmsr_start,
15214 .flags = GENL_UNS_ADMIN_PERM,
15215 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15216 NL80211_FLAG_NEED_RTNL,
15219 .cmd = NL80211_CMD_NOTIFY_RADAR,
15220 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
15221 .doit = nl80211_notify_radar_detection,
15222 .flags = GENL_UNS_ADMIN_PERM,
15223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15224 NL80211_FLAG_NEED_RTNL,
15227 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
15228 .doit = nl80211_update_owe_info,
15229 .flags = GENL_ADMIN_PERM,
15230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15231 NL80211_FLAG_NEED_RTNL,
15234 .cmd = NL80211_CMD_PROBE_MESH_LINK,
15235 .doit = nl80211_probe_mesh_link,
15236 .flags = GENL_UNS_ADMIN_PERM,
15237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15238 NL80211_FLAG_NEED_RTNL,
15241 .cmd = NL80211_CMD_SET_TID_CONFIG,
15242 .doit = nl80211_set_tid_config,
15243 .flags = GENL_UNS_ADMIN_PERM,
15244 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15245 NL80211_FLAG_NEED_RTNL,
15249 static struct genl_family nl80211_fam __ro_after_init = {
15250 .name = NL80211_GENL_NAME, /* have users key off the name instead */
15251 .hdrsize = 0, /* no private header */
15252 .version = 1, /* no particular meaning now */
15253 .maxattr = NL80211_ATTR_MAX,
15254 .policy = nl80211_policy,
15256 .pre_doit = nl80211_pre_doit,
15257 .post_doit = nl80211_post_doit,
15258 .module = THIS_MODULE,
15259 .ops = nl80211_ops,
15260 .n_ops = ARRAY_SIZE(nl80211_ops),
15261 .mcgrps = nl80211_mcgrps,
15262 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
15263 .parallel_ops = true,
15266 /* notification functions */
15268 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
15269 enum nl80211_commands cmd)
15271 struct sk_buff *msg;
15272 struct nl80211_dump_wiphy_state state = {};
15274 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
15275 cmd != NL80211_CMD_DEL_WIPHY);
15277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15281 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
15286 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15287 NL80211_MCGRP_CONFIG, GFP_KERNEL);
15290 void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
15291 struct wireless_dev *wdev,
15292 enum nl80211_commands cmd)
15294 struct sk_buff *msg;
15296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15300 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
15305 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15306 NL80211_MCGRP_CONFIG, GFP_KERNEL);
15309 static int nl80211_add_scan_req(struct sk_buff *msg,
15310 struct cfg80211_registered_device *rdev)
15312 struct cfg80211_scan_request *req = rdev->scan_req;
15313 struct nlattr *nest;
15319 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
15321 goto nla_put_failure;
15322 for (i = 0; i < req->n_ssids; i++) {
15323 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
15324 goto nla_put_failure;
15326 nla_nest_end(msg, nest);
15328 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) {
15329 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ);
15331 goto nla_put_failure;
15332 for (i = 0; i < req->n_channels; i++) {
15333 if (nla_put_u32(msg, i,
15334 ieee80211_channel_to_khz(req->channels[i])))
15335 goto nla_put_failure;
15337 nla_nest_end(msg, nest);
15339 nest = nla_nest_start_noflag(msg,
15340 NL80211_ATTR_SCAN_FREQUENCIES);
15342 goto nla_put_failure;
15343 for (i = 0; i < req->n_channels; i++) {
15344 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
15345 goto nla_put_failure;
15347 nla_nest_end(msg, nest);
15351 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
15352 goto nla_put_failure;
15355 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
15356 goto nla_put_failure;
15358 if (req->info.scan_start_tsf &&
15359 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
15360 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
15361 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
15362 req->info.tsf_bssid)))
15363 goto nla_put_failure;
15370 static int nl80211_prep_scan_msg(struct sk_buff *msg,
15371 struct cfg80211_registered_device *rdev,
15372 struct wireless_dev *wdev,
15373 u32 portid, u32 seq, int flags,
15378 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
15382 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15383 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15384 wdev->netdev->ifindex)) ||
15385 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15387 goto nla_put_failure;
15389 /* ignore errors and send incomplete event anyway */
15390 nl80211_add_scan_req(msg, rdev);
15392 genlmsg_end(msg, hdr);
15396 genlmsg_cancel(msg, hdr);
15401 nl80211_prep_sched_scan_msg(struct sk_buff *msg,
15402 struct cfg80211_sched_scan_request *req, u32 cmd)
15406 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
15411 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
15412 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
15413 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
15415 goto nla_put_failure;
15417 genlmsg_end(msg, hdr);
15421 genlmsg_cancel(msg, hdr);
15425 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
15426 struct wireless_dev *wdev)
15428 struct sk_buff *msg;
15430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15434 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
15435 NL80211_CMD_TRIGGER_SCAN) < 0) {
15440 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15441 NL80211_MCGRP_SCAN, GFP_KERNEL);
15444 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
15445 struct wireless_dev *wdev, bool aborted)
15447 struct sk_buff *msg;
15449 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15453 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
15454 aborted ? NL80211_CMD_SCAN_ABORTED :
15455 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
15463 /* send message created by nl80211_build_scan_msg() */
15464 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
15465 struct sk_buff *msg)
15470 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15471 NL80211_MCGRP_SCAN, GFP_KERNEL);
15474 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
15476 struct sk_buff *msg;
15478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15482 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
15487 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
15488 NL80211_MCGRP_SCAN, GFP_KERNEL);
15491 static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
15492 struct regulatory_request *request)
15494 /* Userspace can always count this one always being set */
15495 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
15496 goto nla_put_failure;
15498 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
15499 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15500 NL80211_REGDOM_TYPE_WORLD))
15501 goto nla_put_failure;
15502 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
15503 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15504 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
15505 goto nla_put_failure;
15506 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
15507 request->intersect) {
15508 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15509 NL80211_REGDOM_TYPE_INTERSECTION))
15510 goto nla_put_failure;
15512 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15513 NL80211_REGDOM_TYPE_COUNTRY) ||
15514 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
15516 goto nla_put_failure;
15519 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
15520 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
15523 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
15524 goto nla_put_failure;
15527 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
15528 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
15529 goto nla_put_failure;
15539 * This can happen on global regulatory changes or device specific settings
15540 * based on custom regulatory domains.
15542 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
15543 struct regulatory_request *request)
15545 struct sk_buff *msg;
15548 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15552 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
15554 goto nla_put_failure;
15556 if (!nl80211_reg_change_event_fill(msg, request))
15557 goto nla_put_failure;
15559 genlmsg_end(msg, hdr);
15562 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
15563 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
15572 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
15573 struct net_device *netdev,
15574 const u8 *buf, size_t len,
15575 enum nl80211_commands cmd, gfp_t gfp,
15576 int uapsd_queues, const u8 *req_ies,
15577 size_t req_ies_len)
15579 struct sk_buff *msg;
15582 msg = nlmsg_new(100 + len + req_ies_len, gfp);
15586 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15592 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15593 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15594 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15596 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
15597 goto nla_put_failure;
15599 if (uapsd_queues >= 0) {
15600 struct nlattr *nla_wmm =
15601 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
15603 goto nla_put_failure;
15605 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
15607 goto nla_put_failure;
15609 nla_nest_end(msg, nla_wmm);
15612 genlmsg_end(msg, hdr);
15614 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15615 NL80211_MCGRP_MLME, gfp);
15622 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
15623 struct net_device *netdev, const u8 *buf,
15624 size_t len, gfp_t gfp)
15626 nl80211_send_mlme_event(rdev, netdev, buf, len,
15627 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
15630 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15631 struct net_device *netdev, const u8 *buf,
15632 size_t len, gfp_t gfp, int uapsd_queues,
15633 const u8 *req_ies, size_t req_ies_len)
15635 nl80211_send_mlme_event(rdev, netdev, buf, len,
15636 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15637 req_ies, req_ies_len);
15640 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
15641 struct net_device *netdev, const u8 *buf,
15642 size_t len, gfp_t gfp)
15644 nl80211_send_mlme_event(rdev, netdev, buf, len,
15645 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
15648 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15649 struct net_device *netdev, const u8 *buf,
15650 size_t len, gfp_t gfp)
15652 nl80211_send_mlme_event(rdev, netdev, buf, len,
15653 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
15656 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15659 struct wireless_dev *wdev = dev->ieee80211_ptr;
15660 struct wiphy *wiphy = wdev->wiphy;
15661 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15662 const struct ieee80211_mgmt *mgmt = (void *)buf;
15665 if (WARN_ON(len < 2))
15668 if (ieee80211_is_deauth(mgmt->frame_control)) {
15669 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
15670 } else if (ieee80211_is_disassoc(mgmt->frame_control)) {
15671 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
15672 } else if (ieee80211_is_beacon(mgmt->frame_control)) {
15673 if (wdev->unprot_beacon_reported &&
15674 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000)
15676 cmd = NL80211_CMD_UNPROT_BEACON;
15677 wdev->unprot_beacon_reported = jiffies;
15682 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
15683 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15686 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
15688 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15689 struct net_device *netdev, int cmd,
15690 const u8 *addr, gfp_t gfp)
15692 struct sk_buff *msg;
15695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15699 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15705 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15707 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15708 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15709 goto nla_put_failure;
15711 genlmsg_end(msg, hdr);
15713 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15714 NL80211_MCGRP_MLME, gfp);
15721 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
15722 struct net_device *netdev, const u8 *addr,
15725 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
15729 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
15730 struct net_device *netdev, const u8 *addr,
15733 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
15737 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
15738 struct net_device *netdev,
15739 struct cfg80211_connect_resp_params *cr,
15742 struct sk_buff *msg;
15745 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
15746 cr->fils.kek_len + cr->fils.pmk_len +
15747 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
15751 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
15757 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15758 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15760 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
15761 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
15762 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
15765 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15766 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
15767 cr->timeout_reason))) ||
15769 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
15771 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
15773 (cr->fils.update_erp_next_seq_num &&
15774 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15775 cr->fils.erp_next_seq_num)) ||
15776 (cr->status == WLAN_STATUS_SUCCESS &&
15778 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
15781 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
15783 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
15784 goto nla_put_failure;
15786 genlmsg_end(msg, hdr);
15788 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15789 NL80211_MCGRP_MLME, gfp);
15796 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
15797 struct net_device *netdev,
15798 struct cfg80211_roam_info *info, gfp_t gfp)
15800 struct sk_buff *msg;
15802 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
15804 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15805 info->fils.kek_len + info->fils.pmk_len +
15806 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
15810 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15816 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15817 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15818 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
15820 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15823 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
15825 (info->fils.update_erp_next_seq_num &&
15826 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15827 info->fils.erp_next_seq_num)) ||
15829 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15830 info->fils.kek)) ||
15832 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15833 (info->fils.pmkid &&
15834 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
15835 goto nla_put_failure;
15837 genlmsg_end(msg, hdr);
15839 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15840 NL80211_MCGRP_MLME, gfp);
15847 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
15848 struct net_device *netdev, const u8 *bssid)
15850 struct sk_buff *msg;
15853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
15863 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15864 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15865 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15866 goto nla_put_failure;
15868 genlmsg_end(msg, hdr);
15870 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15871 NL80211_MCGRP_MLME, GFP_KERNEL);
15878 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
15879 struct net_device *netdev, u16 reason,
15880 const u8 *ie, size_t ie_len, bool from_ap)
15882 struct sk_buff *msg;
15885 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
15889 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
15895 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15896 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15898 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
15900 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
15901 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
15902 goto nla_put_failure;
15904 genlmsg_end(msg, hdr);
15906 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15907 NL80211_MCGRP_MLME, GFP_KERNEL);
15914 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
15915 struct net_device *netdev, const u8 *bssid,
15918 struct sk_buff *msg;
15921 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15925 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
15931 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15932 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15933 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15934 goto nla_put_failure;
15936 genlmsg_end(msg, hdr);
15938 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15939 NL80211_MCGRP_MLME, gfp);
15946 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
15947 const u8 *ie, u8 ie_len,
15948 int sig_dbm, gfp_t gfp)
15950 struct wireless_dev *wdev = dev->ieee80211_ptr;
15951 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15952 struct sk_buff *msg;
15955 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
15958 trace_cfg80211_notify_new_peer_candidate(dev, addr);
15960 msg = nlmsg_new(100 + ie_len, gfp);
15964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
15970 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15971 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15972 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
15974 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
15976 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
15977 goto nla_put_failure;
15979 genlmsg_end(msg, hdr);
15981 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15982 NL80211_MCGRP_MLME, gfp);
15988 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
15990 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
15991 struct net_device *netdev, const u8 *addr,
15992 enum nl80211_key_type key_type, int key_id,
15993 const u8 *tsc, gfp_t gfp)
15995 struct sk_buff *msg;
15998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16002 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
16008 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16009 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16010 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
16011 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
16013 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
16014 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
16015 goto nla_put_failure;
16017 genlmsg_end(msg, hdr);
16019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16020 NL80211_MCGRP_MLME, gfp);
16027 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
16028 struct ieee80211_channel *channel_before,
16029 struct ieee80211_channel *channel_after)
16031 struct sk_buff *msg;
16033 struct nlattr *nl_freq;
16035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
16039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
16046 * Since we are applying the beacon hint to a wiphy we know its
16047 * wiphy_idx is valid
16049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
16050 goto nla_put_failure;
16053 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
16055 goto nla_put_failure;
16057 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
16058 goto nla_put_failure;
16059 nla_nest_end(msg, nl_freq);
16062 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
16064 goto nla_put_failure;
16066 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
16067 goto nla_put_failure;
16068 nla_nest_end(msg, nl_freq);
16070 genlmsg_end(msg, hdr);
16073 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
16074 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
16083 static void nl80211_send_remain_on_chan_event(
16084 int cmd, struct cfg80211_registered_device *rdev,
16085 struct wireless_dev *wdev, u64 cookie,
16086 struct ieee80211_channel *chan,
16087 unsigned int duration, gfp_t gfp)
16089 struct sk_buff *msg;
16092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16096 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
16102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16103 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16104 wdev->netdev->ifindex)) ||
16105 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16106 NL80211_ATTR_PAD) ||
16107 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
16108 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
16109 NL80211_CHAN_NO_HT) ||
16110 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16112 goto nla_put_failure;
16114 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
16115 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
16116 goto nla_put_failure;
16118 genlmsg_end(msg, hdr);
16120 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16121 NL80211_MCGRP_MLME, gfp);
16128 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
16129 struct ieee80211_channel *chan,
16130 unsigned int duration, gfp_t gfp)
16132 struct wiphy *wiphy = wdev->wiphy;
16133 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16135 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
16136 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
16137 rdev, wdev, cookie, chan,
16140 EXPORT_SYMBOL(cfg80211_ready_on_channel);
16142 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
16143 struct ieee80211_channel *chan,
16146 struct wiphy *wiphy = wdev->wiphy;
16147 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16149 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
16150 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
16151 rdev, wdev, cookie, chan, 0, gfp);
16153 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
16155 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
16156 struct ieee80211_channel *chan,
16159 struct wiphy *wiphy = wdev->wiphy;
16160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16162 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
16163 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
16164 rdev, wdev, cookie, chan, 0, gfp);
16166 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
16168 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
16169 struct station_info *sinfo, gfp_t gfp)
16171 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
16172 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16173 struct sk_buff *msg;
16175 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
16177 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16181 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
16182 rdev, dev, mac_addr, sinfo) < 0) {
16187 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16188 NL80211_MCGRP_MLME, gfp);
16190 EXPORT_SYMBOL(cfg80211_new_sta);
16192 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
16193 struct station_info *sinfo, gfp_t gfp)
16195 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
16196 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16197 struct sk_buff *msg;
16198 struct station_info empty_sinfo = {};
16201 sinfo = &empty_sinfo;
16203 trace_cfg80211_del_sta(dev, mac_addr);
16205 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16207 cfg80211_sinfo_release_content(sinfo);
16211 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
16212 rdev, dev, mac_addr, sinfo) < 0) {
16217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16218 NL80211_MCGRP_MLME, gfp);
16220 EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
16222 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
16223 enum nl80211_connect_failed_reason reason,
16226 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
16227 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16228 struct sk_buff *msg;
16231 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
16235 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
16241 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16242 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
16243 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
16244 goto nla_put_failure;
16246 genlmsg_end(msg, hdr);
16248 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16249 NL80211_MCGRP_MLME, gfp);
16255 EXPORT_SYMBOL(cfg80211_conn_failed);
16257 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
16258 const u8 *addr, gfp_t gfp)
16260 struct wireless_dev *wdev = dev->ieee80211_ptr;
16261 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16262 struct sk_buff *msg;
16264 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
16269 msg = nlmsg_new(100, gfp);
16273 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
16279 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16280 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16281 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
16282 goto nla_put_failure;
16284 genlmsg_end(msg, hdr);
16285 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16293 bool cfg80211_rx_spurious_frame(struct net_device *dev,
16294 const u8 *addr, gfp_t gfp)
16296 struct wireless_dev *wdev = dev->ieee80211_ptr;
16299 trace_cfg80211_rx_spurious_frame(dev, addr);
16301 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16302 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
16303 trace_cfg80211_return_bool(false);
16306 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
16308 trace_cfg80211_return_bool(ret);
16311 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
16313 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
16314 const u8 *addr, gfp_t gfp)
16316 struct wireless_dev *wdev = dev->ieee80211_ptr;
16319 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
16321 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16322 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
16323 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
16324 trace_cfg80211_return_bool(false);
16327 ret = __nl80211_unexpected_frame(dev,
16328 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
16330 trace_cfg80211_return_bool(ret);
16333 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
16335 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
16336 struct wireless_dev *wdev, u32 nlportid,
16337 int freq, int sig_dbm,
16338 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
16340 struct net_device *netdev = wdev->netdev;
16341 struct sk_buff *msg;
16344 msg = nlmsg_new(100 + len, gfp);
16348 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16354 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16355 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16356 netdev->ifindex)) ||
16357 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16358 NL80211_ATTR_PAD) ||
16359 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) ||
16360 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) ||
16362 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16363 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
16365 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
16366 goto nla_put_failure;
16368 genlmsg_end(msg, hdr);
16370 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16377 static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie,
16378 const u8 *buf, size_t len, bool ack,
16379 gfp_t gfp, enum nl80211_commands command)
16381 struct wiphy *wiphy = wdev->wiphy;
16382 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16383 struct net_device *netdev = wdev->netdev;
16384 struct sk_buff *msg;
16387 if (command == NL80211_CMD_FRAME_TX_STATUS)
16388 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
16390 trace_cfg80211_control_port_tx_status(wdev, cookie, ack);
16392 msg = nlmsg_new(100 + len, gfp);
16396 hdr = nl80211hdr_put(msg, 0, 0, 0, command);
16402 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16403 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16404 netdev->ifindex)) ||
16405 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16406 NL80211_ATTR_PAD) ||
16407 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
16408 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16409 NL80211_ATTR_PAD) ||
16410 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
16411 goto nla_put_failure;
16413 genlmsg_end(msg, hdr);
16415 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16416 NL80211_MCGRP_MLME, gfp);
16423 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie,
16424 const u8 *buf, size_t len, bool ack,
16427 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp,
16428 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS);
16430 EXPORT_SYMBOL(cfg80211_control_port_tx_status);
16432 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
16433 const u8 *buf, size_t len, bool ack, gfp_t gfp)
16435 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp,
16436 NL80211_CMD_FRAME_TX_STATUS);
16438 EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
16440 static int __nl80211_rx_control_port(struct net_device *dev,
16441 struct sk_buff *skb,
16442 bool unencrypted, gfp_t gfp)
16444 struct wireless_dev *wdev = dev->ieee80211_ptr;
16445 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16446 struct ethhdr *ehdr = eth_hdr(skb);
16447 const u8 *addr = ehdr->h_source;
16448 u16 proto = be16_to_cpu(skb->protocol);
16449 struct sk_buff *msg;
16451 struct nlattr *frame;
16453 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
16458 msg = nlmsg_new(100 + skb->len, gfp);
16462 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
16468 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16470 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16471 NL80211_ATTR_PAD) ||
16472 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
16473 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
16474 (unencrypted && nla_put_flag(msg,
16475 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
16476 goto nla_put_failure;
16478 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
16480 goto nla_put_failure;
16482 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
16483 genlmsg_end(msg, hdr);
16485 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16492 bool cfg80211_rx_control_port(struct net_device *dev,
16493 struct sk_buff *skb, bool unencrypted)
16497 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
16498 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
16499 trace_cfg80211_return_bool(ret == 0);
16502 EXPORT_SYMBOL(cfg80211_rx_control_port);
16504 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
16505 const char *mac, gfp_t gfp)
16507 struct wireless_dev *wdev = dev->ieee80211_ptr;
16508 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16509 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16515 cb = (void **)msg->cb;
16517 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
16523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16524 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16525 goto nla_put_failure;
16527 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16528 goto nla_put_failure;
16530 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
16532 goto nla_put_failure;
16542 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
16544 void **cb = (void **)msg->cb;
16545 struct cfg80211_registered_device *rdev = cb[2];
16547 nla_nest_end(msg, cb[1]);
16548 genlmsg_end(msg, cb[0]);
16550 memset(msg->cb, 0, sizeof(msg->cb));
16552 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16553 NL80211_MCGRP_MLME, gfp);
16556 void cfg80211_cqm_rssi_notify(struct net_device *dev,
16557 enum nl80211_cqm_rssi_threshold_event rssi_event,
16558 s32 rssi_level, gfp_t gfp)
16560 struct sk_buff *msg;
16561 struct wireless_dev *wdev = dev->ieee80211_ptr;
16562 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16564 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
16566 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
16567 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
16570 if (wdev->cqm_config) {
16571 wdev->cqm_config->last_rssi_event_value = rssi_level;
16573 cfg80211_cqm_rssi_update(rdev, dev);
16575 if (rssi_level == 0)
16576 rssi_level = wdev->cqm_config->last_rssi_event_value;
16579 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16583 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
16585 goto nla_put_failure;
16587 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
16589 goto nla_put_failure;
16591 cfg80211_send_cqm(msg, gfp);
16598 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
16600 void cfg80211_cqm_txe_notify(struct net_device *dev,
16601 const u8 *peer, u32 num_packets,
16602 u32 rate, u32 intvl, gfp_t gfp)
16604 struct sk_buff *msg;
16606 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16610 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
16611 goto nla_put_failure;
16613 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
16614 goto nla_put_failure;
16616 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
16617 goto nla_put_failure;
16619 cfg80211_send_cqm(msg, gfp);
16625 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16627 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
16628 const u8 *peer, u32 num_packets, gfp_t gfp)
16630 struct sk_buff *msg;
16632 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
16634 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16638 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
16639 goto nla_put_failure;
16641 cfg80211_send_cqm(msg, gfp);
16647 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16649 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
16651 struct sk_buff *msg;
16653 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16657 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
16658 goto nla_put_failure;
16660 cfg80211_send_cqm(msg, gfp);
16666 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16668 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
16669 struct net_device *netdev, const u8 *bssid,
16670 const u8 *replay_ctr, gfp_t gfp)
16672 struct sk_buff *msg;
16673 struct nlattr *rekey_attr;
16676 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16680 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
16686 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16687 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16688 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16689 goto nla_put_failure;
16691 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
16693 goto nla_put_failure;
16695 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16696 NL80211_REPLAY_CTR_LEN, replay_ctr))
16697 goto nla_put_failure;
16699 nla_nest_end(msg, rekey_attr);
16701 genlmsg_end(msg, hdr);
16703 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16704 NL80211_MCGRP_MLME, gfp);
16711 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
16712 const u8 *replay_ctr, gfp_t gfp)
16714 struct wireless_dev *wdev = dev->ieee80211_ptr;
16715 struct wiphy *wiphy = wdev->wiphy;
16716 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16718 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16719 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
16721 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
16724 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
16725 struct net_device *netdev, int index,
16726 const u8 *bssid, bool preauth, gfp_t gfp)
16728 struct sk_buff *msg;
16729 struct nlattr *attr;
16732 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16736 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
16742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16743 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16744 goto nla_put_failure;
16746 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
16748 goto nla_put_failure;
16750 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
16751 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
16753 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
16754 goto nla_put_failure;
16756 nla_nest_end(msg, attr);
16758 genlmsg_end(msg, hdr);
16760 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16761 NL80211_MCGRP_MLME, gfp);
16768 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
16769 const u8 *bssid, bool preauth, gfp_t gfp)
16771 struct wireless_dev *wdev = dev->ieee80211_ptr;
16772 struct wiphy *wiphy = wdev->wiphy;
16773 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16775 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
16776 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
16778 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
16780 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
16781 struct net_device *netdev,
16782 struct cfg80211_chan_def *chandef,
16784 enum nl80211_commands notif,
16787 struct sk_buff *msg;
16790 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16794 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
16800 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16801 goto nla_put_failure;
16803 if (nl80211_send_chandef(msg, chandef))
16804 goto nla_put_failure;
16806 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
16807 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
16808 goto nla_put_failure;
16810 genlmsg_end(msg, hdr);
16812 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16813 NL80211_MCGRP_MLME, gfp);
16820 void cfg80211_ch_switch_notify(struct net_device *dev,
16821 struct cfg80211_chan_def *chandef)
16823 struct wireless_dev *wdev = dev->ieee80211_ptr;
16824 struct wiphy *wiphy = wdev->wiphy;
16825 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16827 ASSERT_WDEV_LOCK(wdev);
16829 trace_cfg80211_ch_switch_notify(dev, chandef);
16831 wdev->chandef = *chandef;
16832 wdev->preset_chandef = *chandef;
16834 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16835 !WARN_ON(!wdev->current_bss))
16836 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
16838 cfg80211_sched_dfs_chan_update(rdev);
16840 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16841 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
16843 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
16845 void cfg80211_ch_switch_started_notify(struct net_device *dev,
16846 struct cfg80211_chan_def *chandef,
16849 struct wireless_dev *wdev = dev->ieee80211_ptr;
16850 struct wiphy *wiphy = wdev->wiphy;
16851 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16853 trace_cfg80211_ch_switch_started_notify(dev, chandef);
16855 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16856 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
16858 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
16861 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
16862 const struct cfg80211_chan_def *chandef,
16863 enum nl80211_radar_event event,
16864 struct net_device *netdev, gfp_t gfp)
16866 struct sk_buff *msg;
16869 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16873 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
16879 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16880 goto nla_put_failure;
16882 /* NOP and radar events don't need a netdev parameter */
16884 struct wireless_dev *wdev = netdev->ieee80211_ptr;
16886 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16887 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16889 goto nla_put_failure;
16892 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
16893 goto nla_put_failure;
16895 if (nl80211_send_chandef(msg, chandef))
16896 goto nla_put_failure;
16898 genlmsg_end(msg, hdr);
16900 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16901 NL80211_MCGRP_MLME, gfp);
16908 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
16909 struct sta_opmode_info *sta_opmode,
16912 struct sk_buff *msg;
16913 struct wireless_dev *wdev = dev->ieee80211_ptr;
16914 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
16930 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16931 goto nla_put_failure;
16933 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16934 goto nla_put_failure;
16936 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16937 goto nla_put_failure;
16939 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
16940 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
16941 goto nla_put_failure;
16943 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
16944 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
16945 goto nla_put_failure;
16947 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
16948 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
16949 goto nla_put_failure;
16951 genlmsg_end(msg, hdr);
16953 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16954 NL80211_MCGRP_MLME, gfp);
16961 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
16963 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
16964 u64 cookie, bool acked, s32 ack_signal,
16965 bool is_valid_ack_signal, gfp_t gfp)
16967 struct wireless_dev *wdev = dev->ieee80211_ptr;
16968 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16969 struct sk_buff *msg;
16972 trace_cfg80211_probe_status(dev, addr, cookie, acked);
16974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16979 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
16985 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16986 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16987 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
16988 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16989 NL80211_ATTR_PAD) ||
16990 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
16991 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
16993 goto nla_put_failure;
16995 genlmsg_end(msg, hdr);
16997 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16998 NL80211_MCGRP_MLME, gfp);
17004 EXPORT_SYMBOL(cfg80211_probe_status);
17006 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
17007 size_t len, int freq, int sig_dbm)
17009 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17010 struct sk_buff *msg;
17012 struct cfg80211_beacon_registration *reg;
17014 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
17016 spin_lock_bh(&rdev->beacon_registrations_lock);
17017 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
17018 msg = nlmsg_new(len + 100, GFP_ATOMIC);
17020 spin_unlock_bh(&rdev->beacon_registrations_lock);
17024 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
17026 goto nla_put_failure;
17028 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17030 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
17031 KHZ_TO_MHZ(freq)) ||
17032 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
17035 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
17036 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
17037 goto nla_put_failure;
17039 genlmsg_end(msg, hdr);
17041 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
17043 spin_unlock_bh(&rdev->beacon_registrations_lock);
17047 spin_unlock_bh(&rdev->beacon_registrations_lock);
17050 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
17053 static int cfg80211_net_detect_results(struct sk_buff *msg,
17054 struct cfg80211_wowlan_wakeup *wakeup)
17056 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
17057 struct nlattr *nl_results, *nl_match, *nl_freqs;
17060 nl_results = nla_nest_start_noflag(msg,
17061 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
17065 for (i = 0; i < nd->n_matches; i++) {
17066 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
17068 nl_match = nla_nest_start_noflag(msg, i);
17072 /* The SSID attribute is optional in nl80211, but for
17073 * simplicity reasons it's always present in the
17074 * cfg80211 structure. If a driver can't pass the
17075 * SSID, that needs to be changed. A zero length SSID
17076 * is still a valid SSID (wildcard), so it cannot be
17077 * used for this purpose.
17079 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
17080 match->ssid.ssid)) {
17081 nla_nest_cancel(msg, nl_match);
17085 if (match->n_channels) {
17086 nl_freqs = nla_nest_start_noflag(msg,
17087 NL80211_ATTR_SCAN_FREQUENCIES);
17089 nla_nest_cancel(msg, nl_match);
17093 for (j = 0; j < match->n_channels; j++) {
17094 if (nla_put_u32(msg, j, match->channels[j])) {
17095 nla_nest_cancel(msg, nl_freqs);
17096 nla_nest_cancel(msg, nl_match);
17101 nla_nest_end(msg, nl_freqs);
17104 nla_nest_end(msg, nl_match);
17108 nla_nest_end(msg, nl_results);
17112 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
17113 struct cfg80211_wowlan_wakeup *wakeup,
17116 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17117 struct sk_buff *msg;
17121 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
17124 size += wakeup->packet_present_len;
17126 msg = nlmsg_new(size, gfp);
17130 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
17134 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17135 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17139 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
17140 wdev->netdev->ifindex))
17144 struct nlattr *reasons;
17146 reasons = nla_nest_start_noflag(msg,
17147 NL80211_ATTR_WOWLAN_TRIGGERS);
17151 if (wakeup->disconnect &&
17152 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
17154 if (wakeup->magic_pkt &&
17155 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
17157 if (wakeup->gtk_rekey_failure &&
17158 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
17160 if (wakeup->eap_identity_req &&
17161 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
17163 if (wakeup->four_way_handshake &&
17164 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
17166 if (wakeup->rfkill_release &&
17167 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
17170 if (wakeup->pattern_idx >= 0 &&
17171 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
17172 wakeup->pattern_idx))
17175 if (wakeup->tcp_match &&
17176 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
17179 if (wakeup->tcp_connlost &&
17180 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
17183 if (wakeup->tcp_nomoretokens &&
17185 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
17188 if (wakeup->packet) {
17189 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
17190 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
17192 if (!wakeup->packet_80211) {
17194 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
17196 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
17199 if (wakeup->packet_len &&
17200 nla_put_u32(msg, len_attr, wakeup->packet_len))
17203 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
17208 if (wakeup->net_detect &&
17209 cfg80211_net_detect_results(msg, wakeup))
17212 nla_nest_end(msg, reasons);
17215 genlmsg_end(msg, hdr);
17217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17218 NL80211_MCGRP_MLME, gfp);
17224 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
17227 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
17228 enum nl80211_tdls_operation oper,
17229 u16 reason_code, gfp_t gfp)
17231 struct wireless_dev *wdev = dev->ieee80211_ptr;
17232 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17233 struct sk_buff *msg;
17236 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
17239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
17249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17251 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
17252 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
17253 (reason_code > 0 &&
17254 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
17255 goto nla_put_failure;
17257 genlmsg_end(msg, hdr);
17259 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17260 NL80211_MCGRP_MLME, gfp);
17266 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
17268 static int nl80211_netlink_notify(struct notifier_block * nb,
17269 unsigned long state,
17272 struct netlink_notify *notify = _notify;
17273 struct cfg80211_registered_device *rdev;
17274 struct wireless_dev *wdev;
17275 struct cfg80211_beacon_registration *reg, *tmp;
17277 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
17278 return NOTIFY_DONE;
17282 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
17283 struct cfg80211_sched_scan_request *sched_scan_req;
17285 list_for_each_entry_rcu(sched_scan_req,
17286 &rdev->sched_scan_req_list,
17288 if (sched_scan_req->owner_nlportid == notify->portid) {
17289 sched_scan_req->nl_owner_dead = true;
17290 schedule_work(&rdev->sched_scan_stop_wk);
17294 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
17295 cfg80211_mlme_unregister_socket(wdev, notify->portid);
17297 if (wdev->owner_nlportid == notify->portid) {
17298 wdev->nl_owner_dead = true;
17299 schedule_work(&rdev->destroy_work);
17300 } else if (wdev->conn_owner_nlportid == notify->portid) {
17301 schedule_work(&wdev->disconnect_wk);
17304 cfg80211_release_pmsr(wdev, notify->portid);
17307 spin_lock_bh(&rdev->beacon_registrations_lock);
17308 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
17310 if (reg->nlportid == notify->portid) {
17311 list_del(®->list);
17316 spin_unlock_bh(&rdev->beacon_registrations_lock);
17322 * It is possible that the user space process that is controlling the
17323 * indoor setting disappeared, so notify the regulatory core.
17325 regulatory_netlink_notify(notify->portid);
17329 static struct notifier_block nl80211_netlink_notifier = {
17330 .notifier_call = nl80211_netlink_notify,
17333 void cfg80211_ft_event(struct net_device *netdev,
17334 struct cfg80211_ft_event_params *ft_event)
17336 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
17337 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17338 struct sk_buff *msg;
17341 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
17343 if (!ft_event->target_ap)
17346 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
17351 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
17355 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17356 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17357 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
17360 if (ft_event->ies &&
17361 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
17363 if (ft_event->ric_ies &&
17364 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
17365 ft_event->ric_ies))
17368 genlmsg_end(msg, hdr);
17370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17371 NL80211_MCGRP_MLME, GFP_KERNEL);
17376 EXPORT_SYMBOL(cfg80211_ft_event);
17378 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
17380 struct cfg80211_registered_device *rdev;
17381 struct sk_buff *msg;
17385 rdev = wiphy_to_rdev(wdev->wiphy);
17386 if (!rdev->crit_proto_nlportid)
17389 nlportid = rdev->crit_proto_nlportid;
17390 rdev->crit_proto_nlportid = 0;
17392 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17396 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
17398 goto nla_put_failure;
17400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17401 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17403 goto nla_put_failure;
17405 genlmsg_end(msg, hdr);
17407 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
17413 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
17415 void nl80211_send_ap_stopped(struct wireless_dev *wdev)
17417 struct wiphy *wiphy = wdev->wiphy;
17418 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17419 struct sk_buff *msg;
17422 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17426 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
17430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17431 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
17432 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17436 genlmsg_end(msg, hdr);
17438 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
17439 NL80211_MCGRP_MLME, GFP_KERNEL);
17445 int cfg80211_external_auth_request(struct net_device *dev,
17446 struct cfg80211_external_auth_params *params,
17449 struct wireless_dev *wdev = dev->ieee80211_ptr;
17450 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17451 struct sk_buff *msg;
17454 if (!wdev->conn_owner_nlportid)
17457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
17463 goto nla_put_failure;
17465 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17467 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
17468 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
17470 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
17471 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
17472 params->ssid.ssid))
17473 goto nla_put_failure;
17475 genlmsg_end(msg, hdr);
17476 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
17477 wdev->conn_owner_nlportid);
17484 EXPORT_SYMBOL(cfg80211_external_auth_request);
17486 void cfg80211_update_owe_info_event(struct net_device *netdev,
17487 struct cfg80211_update_owe_info *owe_info,
17490 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
17491 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17492 struct sk_buff *msg;
17495 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
17497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17501 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
17503 goto nla_put_failure;
17505 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17506 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17507 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
17508 goto nla_put_failure;
17510 if (!owe_info->ie_len ||
17511 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
17512 goto nla_put_failure;
17514 genlmsg_end(msg, hdr);
17516 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17517 NL80211_MCGRP_MLME, gfp);
17521 genlmsg_cancel(msg, hdr);
17524 EXPORT_SYMBOL(cfg80211_update_owe_info_event);
17526 /* initialisation/exit functions */
17528 int __init nl80211_init(void)
17532 err = genl_register_family(&nl80211_fam);
17536 err = netlink_register_notifier(&nl80211_netlink_notifier);
17542 genl_unregister_family(&nl80211_fam);
17546 void nl80211_exit(void)
17548 netlink_unregister_notifier(&nl80211_netlink_notifier);
17549 genl_unregister_family(&nl80211_fam);