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
);
4175 if (info
->attrs
[NL80211_ATTR_MAC
])
4176 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4178 if (key
.type
== -1) {
4180 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
4182 key
.type
= NL80211_KEYTYPE_GROUP
;
4186 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
4187 key
.type
!= NL80211_KEYTYPE_GROUP
)
4190 if (!rdev
->ops
->del_key
)
4193 wdev_lock(dev
->ieee80211_ptr
);
4194 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
4196 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
4197 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
4201 err
= rdev_del_key(rdev
, dev
, key
.idx
,
4202 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
4205 #ifdef CONFIG_CFG80211_WEXT
4207 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
4208 dev
->ieee80211_ptr
->wext
.default_key
= -1;
4209 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
4210 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
4213 wdev_unlock(dev
->ieee80211_ptr
);
4218 /* This function returns an error or the number of nested attributes */
4219 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
4221 struct nlattr
*attr
;
4222 int n_entries
= 0, tmp
;
4224 nla_for_each_nested(attr
, nl_attr
, tmp
) {
4225 if (nla_len(attr
) != ETH_ALEN
)
4235 * This function parses ACL information and allocates memory for ACL data.
4236 * On successful return, the calling function is responsible to free the
4237 * ACL buffer returned by this function.
4239 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
4240 struct genl_info
*info
)
4242 enum nl80211_acl_policy acl_policy
;
4243 struct nlattr
*attr
;
4244 struct cfg80211_acl_data
*acl
;
4245 int i
= 0, n_entries
, tmp
;
4247 if (!wiphy
->max_acl_mac_addrs
)
4248 return ERR_PTR(-EOPNOTSUPP
);
4250 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
4251 return ERR_PTR(-EINVAL
);
4253 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
4254 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
4255 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
4256 return ERR_PTR(-EINVAL
);
4258 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
4259 return ERR_PTR(-EINVAL
);
4261 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
4263 return ERR_PTR(n_entries
);
4265 if (n_entries
> wiphy
->max_acl_mac_addrs
)
4266 return ERR_PTR(-ENOTSUPP
);
4268 acl
= kzalloc(struct_size(acl
, mac_addrs
, n_entries
), GFP_KERNEL
);
4270 return ERR_PTR(-ENOMEM
);
4272 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
4273 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
4277 acl
->n_acl_entries
= n_entries
;
4278 acl
->acl_policy
= acl_policy
;
4283 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
4285 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4286 struct net_device
*dev
= info
->user_ptr
[1];
4287 struct cfg80211_acl_data
*acl
;
4290 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4291 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4294 if (!dev
->ieee80211_ptr
->beacon_interval
)
4297 acl
= parse_acl_data(&rdev
->wiphy
, info
);
4299 return PTR_ERR(acl
);
4301 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
4308 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4309 u8
*rates
, u8 rates_len
)
4314 for (i
= 0; i
< rates_len
; i
++) {
4315 int rate
= (rates
[i
] & 0x7f) * 5;
4318 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4319 struct ieee80211_rate
*srate
=
4320 &sband
->bitrates
[ridx
];
4321 if (rate
== srate
->bitrate
) {
4326 if (ridx
== sband
->n_bitrates
)
4327 return 0; /* rate not found */
4333 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
4334 u8
*rates
, u8 rates_len
,
4335 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
4339 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
4341 for (i
= 0; i
< rates_len
; i
++) {
4344 ridx
= rates
[i
] / 8;
4345 rbit
= BIT(rates
[i
] % 8);
4347 /* check validity */
4348 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
4351 /* check availability */
4352 ridx
= array_index_nospec(ridx
, IEEE80211_HT_MCS_MASK_LEN
);
4353 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
4362 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
4366 switch (vht_mcs_map
) {
4367 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
4369 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
4372 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
4375 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
4385 static void vht_build_mcs_mask(u16 vht_mcs_map
,
4386 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
4390 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
4391 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
4396 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
4397 struct nl80211_txrate_vht
*txrate
,
4398 u16 mcs
[NL80211_VHT_NSS_MAX
])
4400 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
4401 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
4404 if (!sband
->vht_cap
.vht_supported
)
4407 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
4409 /* Build vht_mcs_mask from VHT capabilities */
4410 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
4412 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4413 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
4414 mcs
[i
] = txrate
->mcs
[i
];
4422 static int nl80211_parse_tx_bitrate_mask(struct genl_info
*info
,
4423 struct nlattr
*attrs
[],
4424 enum nl80211_attrs attr
,
4425 struct cfg80211_bitrate_mask
*mask
)
4427 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4428 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4430 struct nlattr
*tx_rates
;
4431 struct ieee80211_supported_band
*sband
;
4434 memset(mask
, 0, sizeof(*mask
));
4435 /* Default to all rates enabled */
4436 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
4437 sband
= rdev
->wiphy
.bands
[i
];
4442 mask
->control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
4443 memcpy(mask
->control
[i
].ht_mcs
,
4444 sband
->ht_cap
.mcs
.rx_mask
,
4445 sizeof(mask
->control
[i
].ht_mcs
));
4447 if (!sband
->vht_cap
.vht_supported
)
4450 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
4451 vht_build_mcs_mask(vht_tx_mcs_map
, mask
->control
[i
].vht_mcs
);
4454 /* if no rates are given set it back to the defaults */
4458 /* The nested attribute uses enum nl80211_band as the index. This maps
4459 * directly to the enum nl80211_band values used in cfg80211.
4461 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
4462 nla_for_each_nested(tx_rates
, attrs
[attr
], rem
) {
4463 enum nl80211_band band
= nla_type(tx_rates
);
4466 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
4468 sband
= rdev
->wiphy
.bands
[band
];
4471 err
= nla_parse_nested_deprecated(tb
, NL80211_TXRATE_MAX
,
4473 nl80211_txattr_policy
,
4477 if (tb
[NL80211_TXRATE_LEGACY
]) {
4478 mask
->control
[band
].legacy
= rateset_to_mask(
4480 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4481 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4482 if ((mask
->control
[band
].legacy
== 0) &&
4483 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
4486 if (tb
[NL80211_TXRATE_HT
]) {
4487 if (!ht_rateset_to_mask(
4489 nla_data(tb
[NL80211_TXRATE_HT
]),
4490 nla_len(tb
[NL80211_TXRATE_HT
]),
4491 mask
->control
[band
].ht_mcs
))
4494 if (tb
[NL80211_TXRATE_VHT
]) {
4495 if (!vht_set_mcs_mask(
4497 nla_data(tb
[NL80211_TXRATE_VHT
]),
4498 mask
->control
[band
].vht_mcs
))
4501 if (tb
[NL80211_TXRATE_GI
]) {
4502 mask
->control
[band
].gi
=
4503 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
4504 if (mask
->control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
4508 if (mask
->control
[band
].legacy
== 0) {
4509 /* don't allow empty legacy rates if HT or VHT
4510 * are not even supported.
4512 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
4513 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
4516 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
4517 if (mask
->control
[band
].ht_mcs
[i
])
4520 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
4521 if (mask
->control
[band
].vht_mcs
[i
])
4524 /* legacy and mcs rates may not be both empty */
4533 static int validate_beacon_tx_rate(struct cfg80211_registered_device
*rdev
,
4534 enum nl80211_band band
,
4535 struct cfg80211_bitrate_mask
*beacon_rate
)
4537 u32 count_ht
, count_vht
, i
;
4538 u32 rate
= beacon_rate
->control
[band
].legacy
;
4540 /* Allow only one rate */
4541 if (hweight32(rate
) > 1)
4545 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
4546 if (hweight8(beacon_rate
->control
[band
].ht_mcs
[i
]) > 1) {
4548 } else if (beacon_rate
->control
[band
].ht_mcs
[i
]) {
4553 if (count_ht
&& rate
)
4558 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4559 if (hweight16(beacon_rate
->control
[band
].vht_mcs
[i
]) > 1) {
4561 } else if (beacon_rate
->control
[band
].vht_mcs
[i
]) {
4566 if (count_vht
&& rate
)
4570 if ((count_ht
&& count_vht
) || (!rate
&& !count_ht
&& !count_vht
))
4574 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4575 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
))
4578 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4579 NL80211_EXT_FEATURE_BEACON_RATE_HT
))
4582 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4583 NL80211_EXT_FEATURE_BEACON_RATE_VHT
))
4589 static int nl80211_parse_beacon(struct cfg80211_registered_device
*rdev
,
4590 struct nlattr
*attrs
[],
4591 struct cfg80211_beacon_data
*bcn
)
4593 bool haveinfo
= false;
4596 memset(bcn
, 0, sizeof(*bcn
));
4598 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
4599 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
4600 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
4606 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
4607 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
4608 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
4615 if (attrs
[NL80211_ATTR_IE
]) {
4616 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
4617 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
4620 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
4621 bcn
->proberesp_ies
=
4622 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
4623 bcn
->proberesp_ies_len
=
4624 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
4627 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
4628 bcn
->assocresp_ies
=
4629 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
4630 bcn
->assocresp_ies_len
=
4631 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
4634 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
4635 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
4636 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
4639 if (attrs
[NL80211_ATTR_FTM_RESPONDER
]) {
4640 struct nlattr
*tb
[NL80211_FTM_RESP_ATTR_MAX
+ 1];
4642 err
= nla_parse_nested_deprecated(tb
,
4643 NL80211_FTM_RESP_ATTR_MAX
,
4644 attrs
[NL80211_ATTR_FTM_RESPONDER
],
4649 if (tb
[NL80211_FTM_RESP_ATTR_ENABLED
] &&
4650 wiphy_ext_feature_isset(&rdev
->wiphy
,
4651 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
))
4652 bcn
->ftm_responder
= 1;
4656 if (tb
[NL80211_FTM_RESP_ATTR_LCI
]) {
4657 bcn
->lci
= nla_data(tb
[NL80211_FTM_RESP_ATTR_LCI
]);
4658 bcn
->lci_len
= nla_len(tb
[NL80211_FTM_RESP_ATTR_LCI
]);
4661 if (tb
[NL80211_FTM_RESP_ATTR_CIVICLOC
]) {
4662 bcn
->civicloc
= nla_data(tb
[NL80211_FTM_RESP_ATTR_CIVICLOC
]);
4663 bcn
->civicloc_len
= nla_len(tb
[NL80211_FTM_RESP_ATTR_CIVICLOC
]);
4666 bcn
->ftm_responder
= -1;
4672 static int nl80211_parse_he_obss_pd(struct nlattr
*attrs
,
4673 struct ieee80211_he_obss_pd
*he_obss_pd
)
4675 struct nlattr
*tb
[NL80211_HE_OBSS_PD_ATTR_MAX
+ 1];
4678 err
= nla_parse_nested(tb
, NL80211_HE_OBSS_PD_ATTR_MAX
, attrs
,
4679 he_obss_pd_policy
, NULL
);
4683 if (!tb
[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET
] ||
4684 !tb
[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET
])
4687 he_obss_pd
->min_offset
=
4688 nla_get_u32(tb
[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET
]);
4689 he_obss_pd
->max_offset
=
4690 nla_get_u32(tb
[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET
]);
4692 if (he_obss_pd
->min_offset
>= he_obss_pd
->max_offset
)
4695 he_obss_pd
->enable
= true;
4700 static int nl80211_parse_he_bss_color(struct nlattr
*attrs
,
4701 struct cfg80211_he_bss_color
*he_bss_color
)
4703 struct nlattr
*tb
[NL80211_HE_BSS_COLOR_ATTR_MAX
+ 1];
4706 err
= nla_parse_nested(tb
, NL80211_HE_BSS_COLOR_ATTR_MAX
, attrs
,
4707 he_bss_color_policy
, NULL
);
4711 if (!tb
[NL80211_HE_BSS_COLOR_ATTR_COLOR
])
4714 he_bss_color
->color
=
4715 nla_get_u8(tb
[NL80211_HE_BSS_COLOR_ATTR_COLOR
]);
4716 he_bss_color
->enabled
=
4717 !nla_get_flag(tb
[NL80211_HE_BSS_COLOR_ATTR_DISABLED
]);
4718 he_bss_color
->partial
=
4719 nla_get_flag(tb
[NL80211_HE_BSS_COLOR_ATTR_PARTIAL
]);
4724 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings
*params
,
4732 for (i
= 0; i
< rates
[1]; i
++) {
4733 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HT_PHY
)
4734 params
->ht_required
= true;
4735 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)
4736 params
->vht_required
= true;
4737 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HE_PHY
)
4738 params
->he_required
= true;
4743 * Since the nl80211 API didn't include, from the beginning, attributes about
4744 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4745 * benefit of drivers that rebuild IEs in the firmware.
4747 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings
*params
)
4749 const struct cfg80211_beacon_data
*bcn
= ¶ms
->beacon
;
4750 size_t ies_len
= bcn
->tail_len
;
4751 const u8
*ies
= bcn
->tail
;
4755 rates
= cfg80211_find_ie(WLAN_EID_SUPP_RATES
, ies
, ies_len
);
4756 nl80211_check_ap_rate_selectors(params
, rates
);
4758 rates
= cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES
, ies
, ies_len
);
4759 nl80211_check_ap_rate_selectors(params
, rates
);
4761 cap
= cfg80211_find_ie(WLAN_EID_HT_CAPABILITY
, ies
, ies_len
);
4762 if (cap
&& cap
[1] >= sizeof(*params
->ht_cap
))
4763 params
->ht_cap
= (void *)(cap
+ 2);
4764 cap
= cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY
, ies
, ies_len
);
4765 if (cap
&& cap
[1] >= sizeof(*params
->vht_cap
))
4766 params
->vht_cap
= (void *)(cap
+ 2);
4767 cap
= cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY
, ies
, ies_len
);
4768 if (cap
&& cap
[1] >= sizeof(*params
->he_cap
) + 1)
4769 params
->he_cap
= (void *)(cap
+ 3);
4770 cap
= cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION
, ies
, ies_len
);
4771 if (cap
&& cap
[1] >= sizeof(*params
->he_oper
) + 1)
4772 params
->he_oper
= (void *)(cap
+ 3);
4775 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
4776 struct cfg80211_ap_settings
*params
)
4778 struct wireless_dev
*wdev
;
4781 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
4782 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
4783 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4786 if (!wdev
->preset_chandef
.chan
)
4789 params
->chandef
= wdev
->preset_chandef
;
4797 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
4798 enum nl80211_auth_type auth_type
,
4799 enum nl80211_commands cmd
)
4801 if (auth_type
> NL80211_AUTHTYPE_MAX
)
4805 case NL80211_CMD_AUTHENTICATE
:
4806 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
4807 auth_type
== NL80211_AUTHTYPE_SAE
)
4809 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
4810 NL80211_EXT_FEATURE_FILS_STA
) &&
4811 (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
4812 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4813 auth_type
== NL80211_AUTHTYPE_FILS_PK
))
4816 case NL80211_CMD_CONNECT
:
4817 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
4818 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4819 NL80211_EXT_FEATURE_SAE_OFFLOAD
) &&
4820 auth_type
== NL80211_AUTHTYPE_SAE
)
4823 /* FILS with SK PFS or PK not supported yet */
4824 if (auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4825 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
4827 if (!wiphy_ext_feature_isset(
4829 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
4830 auth_type
== NL80211_AUTHTYPE_FILS_SK
)
4833 case NL80211_CMD_START_AP
:
4834 /* SAE not supported yet */
4835 if (auth_type
== NL80211_AUTHTYPE_SAE
)
4837 /* FILS not supported yet */
4838 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
4839 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4840 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
4848 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
4850 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4851 struct net_device
*dev
= info
->user_ptr
[1];
4852 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4853 struct cfg80211_ap_settings params
;
4856 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4857 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4860 if (!rdev
->ops
->start_ap
)
4863 if (wdev
->beacon_interval
)
4866 memset(¶ms
, 0, sizeof(params
));
4868 /* these are required for START_AP */
4869 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
4870 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
4871 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
4874 err
= nl80211_parse_beacon(rdev
, info
->attrs
, ¶ms
.beacon
);
4878 params
.beacon_interval
=
4879 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4880 params
.dtim_period
=
4881 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
4883 err
= cfg80211_validate_beacon_int(rdev
, dev
->ieee80211_ptr
->iftype
,
4884 params
.beacon_interval
);
4889 * In theory, some of these attributes should be required here
4890 * but since they were not used when the command was originally
4891 * added, keep them optional for old user space programs to let
4892 * them continue to work with drivers that do not need the
4893 * additional information -- drivers must check!
4895 if (info
->attrs
[NL80211_ATTR_SSID
]) {
4896 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4898 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4899 if (params
.ssid_len
== 0 ||
4900 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
4904 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
])
4905 params
.hidden_ssid
= nla_get_u32(
4906 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
4908 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4910 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4911 params
.auth_type
= nla_get_u32(
4912 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4913 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
4914 NL80211_CMD_START_AP
))
4917 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4919 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
4920 NL80211_MAX_NR_CIPHER_SUITES
);
4924 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
4925 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
4927 params
.inactivity_timeout
= nla_get_u16(
4928 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
4931 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4932 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4934 params
.p2p_ctwindow
=
4935 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4936 if (params
.p2p_ctwindow
!= 0 &&
4937 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4941 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4944 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4946 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4947 params
.p2p_opp_ps
= tmp
;
4948 if (params
.p2p_opp_ps
!= 0 &&
4949 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4953 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4954 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
4957 } else if (wdev
->preset_chandef
.chan
) {
4958 params
.chandef
= wdev
->preset_chandef
;
4959 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
4962 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
4966 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
4967 err
= nl80211_parse_tx_bitrate_mask(info
, info
->attrs
,
4968 NL80211_ATTR_TX_RATES
,
4969 ¶ms
.beacon_rate
);
4973 err
= validate_beacon_tx_rate(rdev
, params
.chandef
.chan
->band
,
4974 ¶ms
.beacon_rate
);
4979 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
4981 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
4982 switch (params
.smps_mode
) {
4983 case NL80211_SMPS_OFF
:
4985 case NL80211_SMPS_STATIC
:
4986 if (!(rdev
->wiphy
.features
&
4987 NL80211_FEATURE_STATIC_SMPS
))
4990 case NL80211_SMPS_DYNAMIC
:
4991 if (!(rdev
->wiphy
.features
&
4992 NL80211_FEATURE_DYNAMIC_SMPS
))
4999 params
.smps_mode
= NL80211_SMPS_OFF
;
5002 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
5003 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
5006 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
5007 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
5008 if (IS_ERR(params
.acl
))
5009 return PTR_ERR(params
.acl
);
5012 params
.twt_responder
=
5013 nla_get_flag(info
->attrs
[NL80211_ATTR_TWT_RESPONDER
]);
5015 if (info
->attrs
[NL80211_ATTR_HE_OBSS_PD
]) {
5016 err
= nl80211_parse_he_obss_pd(
5017 info
->attrs
[NL80211_ATTR_HE_OBSS_PD
],
5018 ¶ms
.he_obss_pd
);
5023 if (info
->attrs
[NL80211_ATTR_HE_BSS_COLOR
]) {
5024 err
= nl80211_parse_he_bss_color(
5025 info
->attrs
[NL80211_ATTR_HE_BSS_COLOR
],
5026 ¶ms
.he_bss_color
);
5031 nl80211_calculate_ap_params(¶ms
);
5033 if (info
->attrs
[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
])
5034 params
.flags
|= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT
;
5037 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
5039 wdev
->preset_chandef
= params
.chandef
;
5040 wdev
->beacon_interval
= params
.beacon_interval
;
5041 wdev
->chandef
= params
.chandef
;
5042 wdev
->ssid_len
= params
.ssid_len
;
5043 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
5045 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
5046 wdev
->conn_owner_nlportid
= info
->snd_portid
;
5056 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
5058 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5059 struct net_device
*dev
= info
->user_ptr
[1];
5060 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5061 struct cfg80211_beacon_data params
;
5064 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5065 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5068 if (!rdev
->ops
->change_beacon
)
5071 if (!wdev
->beacon_interval
)
5074 err
= nl80211_parse_beacon(rdev
, info
->attrs
, ¶ms
);
5079 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
5085 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
5087 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5088 struct net_device
*dev
= info
->user_ptr
[1];
5090 return cfg80211_stop_ap(rdev
, dev
, false);
5093 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
5094 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
5095 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
5096 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
5097 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
5098 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
5099 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
5102 static int parse_station_flags(struct genl_info
*info
,
5103 enum nl80211_iftype iftype
,
5104 struct station_parameters
*params
)
5106 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
5111 * Try parsing the new attribute first so userspace
5112 * can specify both for older kernels.
5114 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
5116 struct nl80211_sta_flag_update
*sta_flags
;
5118 sta_flags
= nla_data(nla
);
5119 params
->sta_flags_mask
= sta_flags
->mask
;
5120 params
->sta_flags_set
= sta_flags
->set
;
5121 params
->sta_flags_set
&= params
->sta_flags_mask
;
5122 if ((params
->sta_flags_mask
|
5123 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
5128 /* if present, parse the old attribute */
5130 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
5134 if (nla_parse_nested_deprecated(flags
, NL80211_STA_FLAG_MAX
, nla
, sta_flags_policy
, info
->extack
))
5138 * Only allow certain flags for interface types so that
5139 * other attributes are silently ignored. Remember that
5140 * this is backward compatibility code with old userspace
5141 * and shouldn't be hit in other cases anyway.
5144 case NL80211_IFTYPE_AP
:
5145 case NL80211_IFTYPE_AP_VLAN
:
5146 case NL80211_IFTYPE_P2P_GO
:
5147 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5148 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
5149 BIT(NL80211_STA_FLAG_WME
) |
5150 BIT(NL80211_STA_FLAG_MFP
);
5152 case NL80211_IFTYPE_P2P_CLIENT
:
5153 case NL80211_IFTYPE_STATION
:
5154 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5155 BIT(NL80211_STA_FLAG_TDLS_PEER
);
5157 case NL80211_IFTYPE_MESH_POINT
:
5158 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5159 BIT(NL80211_STA_FLAG_MFP
) |
5160 BIT(NL80211_STA_FLAG_AUTHORIZED
);
5166 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
5168 params
->sta_flags_set
|= (1<<flag
);
5170 /* no longer support new API additions in old API */
5171 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
5179 bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
, int attr
)
5181 struct nlattr
*rate
;
5184 enum nl80211_rate_info rate_flg
;
5186 rate
= nla_nest_start_noflag(msg
, attr
);
5190 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
5191 bitrate
= cfg80211_calculate_bitrate(info
);
5192 /* report 16-bit bitrate only if we can */
5193 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
5195 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
5197 if (bitrate_compat
> 0 &&
5198 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
5202 case RATE_INFO_BW_5
:
5203 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
5205 case RATE_INFO_BW_10
:
5206 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
5211 case RATE_INFO_BW_20
:
5214 case RATE_INFO_BW_40
:
5215 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
5217 case RATE_INFO_BW_80
:
5218 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
5220 case RATE_INFO_BW_160
:
5221 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
5223 case RATE_INFO_BW_HE_RU
:
5225 WARN_ON(!(info
->flags
& RATE_INFO_FLAGS_HE_MCS
));
5228 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
5231 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
5232 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
5234 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
5235 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
5237 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
5238 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
5240 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
5242 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
5243 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
5245 } else if (info
->flags
& RATE_INFO_FLAGS_HE_MCS
) {
5246 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_MCS
, info
->mcs
))
5248 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_NSS
, info
->nss
))
5250 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_GI
, info
->he_gi
))
5252 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_DCM
, info
->he_dcm
))
5254 if (info
->bw
== RATE_INFO_BW_HE_RU
&&
5255 nla_put_u8(msg
, NL80211_RATE_INFO_HE_RU_ALLOC
,
5260 nla_nest_end(msg
, rate
);
5264 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
5273 attr
= nla_nest_start_noflag(msg
, id
);
5277 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
5278 if (!(mask
& BIT(i
)))
5281 if (nla_put_u8(msg
, i
, signal
[i
]))
5285 nla_nest_end(msg
, attr
);
5290 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
5292 struct cfg80211_registered_device
*rdev
,
5293 struct net_device
*dev
,
5294 const u8
*mac_addr
, struct station_info
*sinfo
)
5297 struct nlattr
*sinfoattr
, *bss_param
;
5299 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
5301 cfg80211_sinfo_release_content(sinfo
);
5305 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5306 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
5307 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
5308 goto nla_put_failure
;
5310 sinfoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_STA_INFO
);
5312 goto nla_put_failure
;
5314 #define PUT_SINFO(attr, memb, type) do { \
5315 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
5316 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5317 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5319 goto nla_put_failure; \
5321 #define PUT_SINFO_U64(attr, memb) do { \
5322 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5323 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5324 sinfo->memb, NL80211_STA_INFO_PAD)) \
5325 goto nla_put_failure; \
5328 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
5329 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
5330 PUT_SINFO_U64(ASSOC_AT_BOOTTIME
, assoc_at
);
5332 if (sinfo
->filled
& (BIT_ULL(NL80211_STA_INFO_RX_BYTES
) |
5333 BIT_ULL(NL80211_STA_INFO_RX_BYTES64
)) &&
5334 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
5335 (u32
)sinfo
->rx_bytes
))
5336 goto nla_put_failure
;
5338 if (sinfo
->filled
& (BIT_ULL(NL80211_STA_INFO_TX_BYTES
) |
5339 BIT_ULL(NL80211_STA_INFO_TX_BYTES64
)) &&
5340 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
5341 (u32
)sinfo
->tx_bytes
))
5342 goto nla_put_failure
;
5344 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
5345 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
5346 PUT_SINFO(LLID
, llid
, u16
);
5347 PUT_SINFO(PLID
, plid
, u16
);
5348 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
5349 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
5350 PUT_SINFO_U64(TX_DURATION
, tx_duration
);
5352 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
5353 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
))
5354 PUT_SINFO(AIRTIME_WEIGHT
, airtime_weight
, u16
);
5356 switch (rdev
->wiphy
.signal_type
) {
5357 case CFG80211_SIGNAL_TYPE_MBM
:
5358 PUT_SINFO(SIGNAL
, signal
, u8
);
5359 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
5364 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
5365 if (!nl80211_put_signal(msg
, sinfo
->chains
,
5366 sinfo
->chain_signal
,
5367 NL80211_STA_INFO_CHAIN_SIGNAL
))
5368 goto nla_put_failure
;
5370 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
5371 if (!nl80211_put_signal(msg
, sinfo
->chains
,
5372 sinfo
->chain_signal_avg
,
5373 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
5374 goto nla_put_failure
;
5376 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_TX_BITRATE
)) {
5377 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
5378 NL80211_STA_INFO_TX_BITRATE
))
5379 goto nla_put_failure
;
5381 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_RX_BITRATE
)) {
5382 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
5383 NL80211_STA_INFO_RX_BITRATE
))
5384 goto nla_put_failure
;
5387 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
5388 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
5389 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
5390 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
5391 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
5392 PUT_SINFO(AIRTIME_LINK_METRIC
, airtime_link_metric
, u32
);
5393 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
5394 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
5395 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
5396 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
5397 PUT_SINFO(CONNECTED_TO_GATE
, connected_to_gate
, u8
);
5398 PUT_SINFO(CONNECTED_TO_AS
, connected_to_as
, u8
);
5400 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_BSS_PARAM
)) {
5401 bss_param
= nla_nest_start_noflag(msg
,
5402 NL80211_STA_INFO_BSS_PARAM
);
5404 goto nla_put_failure
;
5406 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
5407 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
5408 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
5409 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
5410 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
5411 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
5412 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
5413 sinfo
->bss_param
.dtim_period
) ||
5414 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
5415 sinfo
->bss_param
.beacon_interval
))
5416 goto nla_put_failure
;
5418 nla_nest_end(msg
, bss_param
);
5420 if ((sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_STA_FLAGS
)) &&
5421 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
5422 sizeof(struct nl80211_sta_flag_update
),
5424 goto nla_put_failure
;
5426 PUT_SINFO_U64(T_OFFSET
, t_offset
);
5427 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
5428 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
5429 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
5430 PUT_SINFO(RX_MPDUS
, rx_mpdu_count
, u32
);
5431 PUT_SINFO(FCS_ERROR_COUNT
, fcs_err_count
, u32
);
5432 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
5433 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT
)) {
5434 PUT_SINFO(ACK_SIGNAL
, ack_signal
, u8
);
5435 PUT_SINFO(ACK_SIGNAL_AVG
, avg_ack_signal
, s8
);
5439 #undef PUT_SINFO_U64
5441 if (sinfo
->pertid
) {
5442 struct nlattr
*tidsattr
;
5445 tidsattr
= nla_nest_start_noflag(msg
,
5446 NL80211_STA_INFO_TID_STATS
);
5448 goto nla_put_failure
;
5450 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
5451 struct cfg80211_tid_stats
*tidstats
;
5452 struct nlattr
*tidattr
;
5454 tidstats
= &sinfo
->pertid
[tid
];
5456 if (!tidstats
->filled
)
5459 tidattr
= nla_nest_start_noflag(msg
, tid
+ 1);
5461 goto nla_put_failure
;
5463 #define PUT_TIDVAL_U64(attr, memb) do { \
5464 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
5465 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5466 tidstats->memb, NL80211_TID_STATS_PAD)) \
5467 goto nla_put_failure; \
5470 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
5471 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
5472 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
5473 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
5475 #undef PUT_TIDVAL_U64
5476 if ((tidstats
->filled
&
5477 BIT(NL80211_TID_STATS_TXQ_STATS
)) &&
5478 !nl80211_put_txq_stats(msg
, &tidstats
->txq_stats
,
5479 NL80211_TID_STATS_TXQ_STATS
))
5480 goto nla_put_failure
;
5482 nla_nest_end(msg
, tidattr
);
5485 nla_nest_end(msg
, tidsattr
);
5488 nla_nest_end(msg
, sinfoattr
);
5490 if (sinfo
->assoc_req_ies_len
&&
5491 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
5492 sinfo
->assoc_req_ies
))
5493 goto nla_put_failure
;
5495 cfg80211_sinfo_release_content(sinfo
);
5496 genlmsg_end(msg
, hdr
);
5500 cfg80211_sinfo_release_content(sinfo
);
5501 genlmsg_cancel(msg
, hdr
);
5505 static int nl80211_dump_station(struct sk_buff
*skb
,
5506 struct netlink_callback
*cb
)
5508 struct station_info sinfo
;
5509 struct cfg80211_registered_device
*rdev
;
5510 struct wireless_dev
*wdev
;
5511 u8 mac_addr
[ETH_ALEN
];
5512 int sta_idx
= cb
->args
[2];
5516 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
5520 if (!wdev
->netdev
) {
5525 if (!rdev
->ops
->dump_station
) {
5531 memset(&sinfo
, 0, sizeof(sinfo
));
5532 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
5539 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
5540 NETLINK_CB(cb
->skb
).portid
,
5541 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5542 rdev
, wdev
->netdev
, mac_addr
,
5550 cb
->args
[2] = sta_idx
;
5558 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
5560 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5561 struct net_device
*dev
= info
->user_ptr
[1];
5562 struct station_info sinfo
;
5563 struct sk_buff
*msg
;
5564 u8
*mac_addr
= NULL
;
5567 memset(&sinfo
, 0, sizeof(sinfo
));
5569 if (!info
->attrs
[NL80211_ATTR_MAC
])
5572 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5574 if (!rdev
->ops
->get_station
)
5577 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
5581 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5583 cfg80211_sinfo_release_content(&sinfo
);
5587 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
5588 info
->snd_portid
, info
->snd_seq
, 0,
5589 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
5594 return genlmsg_reply(msg
, info
);
5597 int cfg80211_check_station_change(struct wiphy
*wiphy
,
5598 struct station_parameters
*params
,
5599 enum cfg80211_station_type statype
)
5601 if (params
->listen_interval
!= -1 &&
5602 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
5605 if (params
->support_p2p_ps
!= -1 &&
5606 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
5610 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
5611 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
5614 /* When you run into this, adjust the code below for the new flag */
5615 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
5618 case CFG80211_STA_MESH_PEER_KERNEL
:
5619 case CFG80211_STA_MESH_PEER_USER
:
5621 * No ignoring the TDLS flag here -- the userspace mesh
5622 * code doesn't have the bug of including TDLS in the
5625 if (params
->sta_flags_mask
&
5626 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5627 BIT(NL80211_STA_FLAG_MFP
) |
5628 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
5631 case CFG80211_STA_TDLS_PEER_SETUP
:
5632 case CFG80211_STA_TDLS_PEER_ACTIVE
:
5633 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
5635 /* ignore since it can't change */
5636 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
5639 /* disallow mesh-specific things */
5640 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
5642 if (params
->local_pm
)
5644 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
5648 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
5649 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
5650 /* TDLS can't be set, ... */
5651 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
5654 * ... but don't bother the driver with it. This works around
5655 * a hostapd/wpa_supplicant issue -- it always includes the
5656 * TLDS_PEER flag in the mask even for AP mode.
5658 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
5661 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
5662 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
5663 /* reject other things that can't change */
5664 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
5666 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
5668 if (params
->supported_rates
)
5670 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
||
5675 if (statype
!= CFG80211_STA_AP_CLIENT
&&
5676 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
5682 case CFG80211_STA_AP_MLME_CLIENT
:
5683 /* Use this only for authorizing/unauthorizing a station */
5684 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
5687 case CFG80211_STA_AP_CLIENT
:
5688 case CFG80211_STA_AP_CLIENT_UNASSOC
:
5689 /* accept only the listed bits */
5690 if (params
->sta_flags_mask
&
5691 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5692 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5693 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
5694 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
5695 BIT(NL80211_STA_FLAG_WME
) |
5696 BIT(NL80211_STA_FLAG_MFP
)))
5699 /* but authenticated/associated only if driver handles it */
5700 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
5701 params
->sta_flags_mask
&
5702 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5703 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
5706 case CFG80211_STA_IBSS
:
5707 case CFG80211_STA_AP_STA
:
5708 /* reject any changes other than AUTHORIZED */
5709 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
5712 case CFG80211_STA_TDLS_PEER_SETUP
:
5713 /* reject any changes other than AUTHORIZED or WME */
5714 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5715 BIT(NL80211_STA_FLAG_WME
)))
5717 /* force (at least) rates when authorizing */
5718 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
5719 !params
->supported_rates
)
5722 case CFG80211_STA_TDLS_PEER_ACTIVE
:
5723 /* reject any changes */
5725 case CFG80211_STA_MESH_PEER_KERNEL
:
5726 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
5729 case CFG80211_STA_MESH_PEER_USER
:
5730 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
5731 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
5737 * Older kernel versions ignored this attribute entirely, so don't
5738 * reject attempts to update it but mark it as unused instead so the
5739 * driver won't look at the data.
5741 if (statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
&&
5742 statype
!= CFG80211_STA_TDLS_PEER_SETUP
)
5743 params
->opmode_notif_used
= false;
5747 EXPORT_SYMBOL(cfg80211_check_station_change
);
5750 * Get vlan interface making sure it is running and on the right wiphy.
5752 static struct net_device
*get_vlan(struct genl_info
*info
,
5753 struct cfg80211_registered_device
*rdev
)
5755 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
5756 struct net_device
*v
;
5762 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
5764 return ERR_PTR(-ENODEV
);
5766 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
5771 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5772 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5773 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
5778 if (!netif_running(v
)) {
5786 return ERR_PTR(ret
);
5789 static const struct nla_policy
5790 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
5791 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
5792 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
5795 static int nl80211_parse_sta_wme(struct genl_info
*info
,
5796 struct station_parameters
*params
)
5798 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
5802 /* parse WME attributes if present */
5803 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
5806 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
5807 err
= nla_parse_nested_deprecated(tb
, NL80211_STA_WME_MAX
, nla
,
5808 nl80211_sta_wme_policy
,
5813 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
5814 params
->uapsd_queues
= nla_get_u8(
5815 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
5816 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
5819 if (tb
[NL80211_STA_WME_MAX_SP
])
5820 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
5822 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
5825 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
5830 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
5831 struct station_parameters
*params
)
5833 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
5834 params
->supported_channels
=
5835 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
5836 params
->supported_channels_len
=
5837 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
5839 * Need to include at least one (first channel, number of
5840 * channels) tuple for each subband, and must have proper
5841 * tuples for the rest of the data as well.
5843 if (params
->supported_channels_len
< 2)
5845 if (params
->supported_channels_len
% 2)
5849 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
5850 params
->supported_oper_classes
=
5851 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
5852 params
->supported_oper_classes_len
=
5853 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
5855 * The value of the Length field of the Supported Operating
5856 * Classes element is between 2 and 253.
5858 if (params
->supported_oper_classes_len
< 2 ||
5859 params
->supported_oper_classes_len
> 253)
5865 static int nl80211_set_station_tdls(struct genl_info
*info
,
5866 struct station_parameters
*params
)
5869 /* Dummy STA entry gets updated once the peer capabilities are known */
5870 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
5871 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
5872 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
5874 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5875 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
5877 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
5878 if (info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]) {
5880 nla_data(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
5881 params
->he_capa_len
=
5882 nla_len(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
5884 if (params
->he_capa_len
< NL80211_HE_MIN_CAPABILITY_LEN
)
5888 err
= nl80211_parse_sta_channel_info(info
, params
);
5892 return nl80211_parse_sta_wme(info
, params
);
5895 static int nl80211_parse_sta_txpower_setting(struct genl_info
*info
,
5896 struct station_parameters
*params
)
5898 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5901 if (info
->attrs
[NL80211_ATTR_STA_TX_POWER_SETTING
]) {
5902 if (!rdev
->ops
->set_tx_power
||
5903 !wiphy_ext_feature_isset(&rdev
->wiphy
,
5904 NL80211_EXT_FEATURE_STA_TX_PWR
))
5907 idx
= NL80211_ATTR_STA_TX_POWER_SETTING
;
5908 params
->txpwr
.type
= nla_get_u8(info
->attrs
[idx
]);
5910 if (params
->txpwr
.type
== NL80211_TX_POWER_LIMITED
) {
5911 idx
= NL80211_ATTR_STA_TX_POWER
;
5913 if (info
->attrs
[idx
])
5914 params
->txpwr
.power
=
5915 nla_get_s16(info
->attrs
[idx
]);
5919 params
->sta_modify_mask
|= STATION_PARAM_APPLY_STA_TXPOWER
;
5925 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
5927 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5928 struct net_device
*dev
= info
->user_ptr
[1];
5929 struct station_parameters params
;
5933 memset(¶ms
, 0, sizeof(params
));
5935 if (!rdev
->ops
->change_station
)
5939 * AID and listen_interval properties can be set only for unassociated
5940 * station. Include these parameters here and will check them in
5941 * cfg80211_check_station_change().
5943 if (info
->attrs
[NL80211_ATTR_STA_AID
])
5944 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
5946 if (info
->attrs
[NL80211_ATTR_VLAN_ID
])
5947 params
.vlan_id
= nla_get_u16(info
->attrs
[NL80211_ATTR_VLAN_ID
]);
5949 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
5950 params
.listen_interval
=
5951 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
5953 params
.listen_interval
= -1;
5955 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
])
5956 params
.support_p2p_ps
=
5957 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
5959 params
.support_p2p_ps
= -1;
5961 if (!info
->attrs
[NL80211_ATTR_MAC
])
5964 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5966 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
5967 params
.supported_rates
=
5968 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5969 params
.supported_rates_len
=
5970 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5973 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
5975 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
5976 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
5979 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
5981 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5982 params
.ext_capab_len
=
5983 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5986 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
5989 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
5990 params
.plink_action
=
5991 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
5993 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
5994 params
.plink_state
=
5995 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
5996 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
])
5997 params
.peer_aid
= nla_get_u16(
5998 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
5999 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
6002 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
])
6003 params
.local_pm
= nla_get_u32(
6004 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
6006 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
6007 params
.opmode_notif_used
= true;
6008 params
.opmode_notif
=
6009 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
6012 if (info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
])
6013 params
.he_6ghz_capa
=
6014 nla_data(info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
]);
6016 if (info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
])
6017 params
.airtime_weight
=
6018 nla_get_u16(info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
]);
6020 if (params
.airtime_weight
&&
6021 !wiphy_ext_feature_isset(&rdev
->wiphy
,
6022 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
))
6025 err
= nl80211_parse_sta_txpower_setting(info
, ¶ms
);
6029 /* Include parameters for TDLS peer (will check later) */
6030 err
= nl80211_set_station_tdls(info
, ¶ms
);
6034 params
.vlan
= get_vlan(info
, rdev
);
6035 if (IS_ERR(params
.vlan
))
6036 return PTR_ERR(params
.vlan
);
6038 switch (dev
->ieee80211_ptr
->iftype
) {
6039 case NL80211_IFTYPE_AP
:
6040 case NL80211_IFTYPE_AP_VLAN
:
6041 case NL80211_IFTYPE_P2P_GO
:
6042 case NL80211_IFTYPE_P2P_CLIENT
:
6043 case NL80211_IFTYPE_STATION
:
6044 case NL80211_IFTYPE_ADHOC
:
6045 case NL80211_IFTYPE_MESH_POINT
:
6052 /* driver will call cfg80211_check_station_change() */
6053 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
6057 dev_put(params
.vlan
);
6062 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
6064 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6066 struct net_device
*dev
= info
->user_ptr
[1];
6067 struct station_parameters params
;
6068 u8
*mac_addr
= NULL
;
6069 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
6070 BIT(NL80211_STA_FLAG_ASSOCIATED
);
6072 memset(¶ms
, 0, sizeof(params
));
6074 if (!rdev
->ops
->add_station
)
6077 if (!info
->attrs
[NL80211_ATTR_MAC
])
6080 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
6083 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
6086 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
6087 !info
->attrs
[NL80211_ATTR_PEER_AID
])
6090 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6091 params
.supported_rates
=
6092 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
6093 params
.supported_rates_len
=
6094 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
6095 params
.listen_interval
=
6096 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
6098 if (info
->attrs
[NL80211_ATTR_VLAN_ID
])
6099 params
.vlan_id
= nla_get_u16(info
->attrs
[NL80211_ATTR_VLAN_ID
]);
6101 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
6102 params
.support_p2p_ps
=
6103 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
6106 * if not specified, assume it's supported for P2P GO interface,
6107 * and is NOT supported for AP interface
6109 params
.support_p2p_ps
=
6110 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
6113 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
6114 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
6116 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
6118 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
6120 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
6121 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
6124 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
6126 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
6127 params
.ext_capab_len
=
6128 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
6131 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
6133 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
6135 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
6137 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
6139 if (info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]) {
6141 nla_data(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
6142 params
.he_capa_len
=
6143 nla_len(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
6145 /* max len is validated in nla policy */
6146 if (params
.he_capa_len
< NL80211_HE_MIN_CAPABILITY_LEN
)
6150 if (info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
])
6151 params
.he_6ghz_capa
=
6152 nla_data(info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
]);
6154 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
6155 params
.opmode_notif_used
= true;
6156 params
.opmode_notif
=
6157 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
6160 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
6161 params
.plink_action
=
6162 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
6164 if (info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
])
6165 params
.airtime_weight
=
6166 nla_get_u16(info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
]);
6168 if (params
.airtime_weight
&&
6169 !wiphy_ext_feature_isset(&rdev
->wiphy
,
6170 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
))
6173 err
= nl80211_parse_sta_txpower_setting(info
, ¶ms
);
6177 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
6181 err
= nl80211_parse_sta_wme(info
, ¶ms
);
6185 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
6188 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
6189 * as userspace might just pass through the capabilities from the IEs
6190 * directly, rather than enforcing this restriction and returning an
6191 * error in this case.
6193 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
6194 params
.ht_capa
= NULL
;
6195 params
.vht_capa
= NULL
;
6197 /* HE requires WME */
6198 if (params
.he_capa_len
|| params
.he_6ghz_capa
)
6202 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
6203 if (params
.he_6ghz_capa
&& (params
.ht_capa
|| params
.vht_capa
))
6206 /* When you run into this, adjust the code below for the new flag */
6207 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
6209 switch (dev
->ieee80211_ptr
->iftype
) {
6210 case NL80211_IFTYPE_AP
:
6211 case NL80211_IFTYPE_AP_VLAN
:
6212 case NL80211_IFTYPE_P2P_GO
:
6213 /* ignore WME attributes if iface/sta is not capable */
6214 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
6215 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
6216 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
6218 /* TDLS peers cannot be added */
6219 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
6220 info
->attrs
[NL80211_ATTR_PEER_AID
])
6222 /* but don't bother the driver with it */
6223 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
6225 /* allow authenticated/associated only if driver handles it */
6226 if (!(rdev
->wiphy
.features
&
6227 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
6228 params
.sta_flags_mask
& auth_assoc
)
6231 /* Older userspace, or userspace wanting to be compatible with
6232 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
6233 * and assoc flags in the mask, but assumes the station will be
6234 * added as associated anyway since this was the required driver
6235 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
6237 * In order to not bother drivers with this quirk in the API
6238 * set the flags in both the mask and set for new stations in
6241 if (!(params
.sta_flags_mask
& auth_assoc
)) {
6242 params
.sta_flags_mask
|= auth_assoc
;
6243 params
.sta_flags_set
|= auth_assoc
;
6246 /* must be last in here for error handling */
6247 params
.vlan
= get_vlan(info
, rdev
);
6248 if (IS_ERR(params
.vlan
))
6249 return PTR_ERR(params
.vlan
);
6251 case NL80211_IFTYPE_MESH_POINT
:
6252 /* ignore uAPSD data */
6253 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
6255 /* associated is disallowed */
6256 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
6258 /* TDLS peers cannot be added */
6259 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
6260 info
->attrs
[NL80211_ATTR_PEER_AID
])
6263 case NL80211_IFTYPE_STATION
:
6264 case NL80211_IFTYPE_P2P_CLIENT
:
6265 /* ignore uAPSD data */
6266 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
6268 /* these are disallowed */
6269 if (params
.sta_flags_mask
&
6270 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
6271 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
6273 /* Only TDLS peers can be added */
6274 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
6276 /* Can only add if TDLS ... */
6277 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
6279 /* ... with external setup is supported */
6280 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
6283 * Older wpa_supplicant versions always mark the TDLS peer
6284 * as authorized, but it shouldn't yet be.
6286 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
6292 /* be aware of params.vlan when changing code here */
6294 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
6297 dev_put(params
.vlan
);
6301 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
6303 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6304 struct net_device
*dev
= info
->user_ptr
[1];
6305 struct station_del_parameters params
;
6307 memset(¶ms
, 0, sizeof(params
));
6309 if (info
->attrs
[NL80211_ATTR_MAC
])
6310 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6312 switch (dev
->ieee80211_ptr
->iftype
) {
6313 case NL80211_IFTYPE_AP
:
6314 case NL80211_IFTYPE_AP_VLAN
:
6315 case NL80211_IFTYPE_MESH_POINT
:
6316 case NL80211_IFTYPE_P2P_GO
:
6317 /* always accept these */
6319 case NL80211_IFTYPE_ADHOC
:
6320 /* conditionally accept */
6321 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
6322 NL80211_EXT_FEATURE_DEL_IBSS_STA
))
6329 if (!rdev
->ops
->del_station
)
6332 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
6334 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
6335 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
6336 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
6339 /* Default to Deauthentication frame */
6340 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
6343 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
6344 params
.reason_code
=
6345 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6346 if (params
.reason_code
== 0)
6347 return -EINVAL
; /* 0 is reserved */
6349 /* Default to reason code 2 */
6350 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
6353 return rdev_del_station(rdev
, dev
, ¶ms
);
6356 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
6357 int flags
, struct net_device
*dev
,
6358 u8
*dst
, u8
*next_hop
,
6359 struct mpath_info
*pinfo
)
6362 struct nlattr
*pinfoattr
;
6364 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
6368 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
6369 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
6370 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
6371 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
6372 goto nla_put_failure
;
6374 pinfoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_MPATH_INFO
);
6376 goto nla_put_failure
;
6377 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
6378 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
6380 goto nla_put_failure
;
6381 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
6382 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
6383 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
6384 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
6386 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
6387 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
6389 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
6390 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
6392 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
6393 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
6394 pinfo
->discovery_timeout
)) ||
6395 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
6396 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
6397 pinfo
->discovery_retries
)) ||
6398 ((pinfo
->filled
& MPATH_INFO_HOP_COUNT
) &&
6399 nla_put_u8(msg
, NL80211_MPATH_INFO_HOP_COUNT
,
6400 pinfo
->hop_count
)) ||
6401 ((pinfo
->filled
& MPATH_INFO_PATH_CHANGE
) &&
6402 nla_put_u32(msg
, NL80211_MPATH_INFO_PATH_CHANGE
,
6403 pinfo
->path_change_count
)))
6404 goto nla_put_failure
;
6406 nla_nest_end(msg
, pinfoattr
);
6408 genlmsg_end(msg
, hdr
);
6412 genlmsg_cancel(msg
, hdr
);
6416 static int nl80211_dump_mpath(struct sk_buff
*skb
,
6417 struct netlink_callback
*cb
)
6419 struct mpath_info pinfo
;
6420 struct cfg80211_registered_device
*rdev
;
6421 struct wireless_dev
*wdev
;
6423 u8 next_hop
[ETH_ALEN
];
6424 int path_idx
= cb
->args
[2];
6428 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
6432 if (!rdev
->ops
->dump_mpath
) {
6437 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
6443 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
6450 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
6451 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6452 wdev
->netdev
, dst
, next_hop
,
6460 cb
->args
[2] = path_idx
;
6467 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6469 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6471 struct net_device
*dev
= info
->user_ptr
[1];
6472 struct mpath_info pinfo
;
6473 struct sk_buff
*msg
;
6475 u8 next_hop
[ETH_ALEN
];
6477 memset(&pinfo
, 0, sizeof(pinfo
));
6479 if (!info
->attrs
[NL80211_ATTR_MAC
])
6482 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6484 if (!rdev
->ops
->get_mpath
)
6487 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6490 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
6494 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6498 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6499 dev
, dst
, next_hop
, &pinfo
) < 0) {
6504 return genlmsg_reply(msg
, info
);
6507 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6509 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6510 struct net_device
*dev
= info
->user_ptr
[1];
6512 u8
*next_hop
= NULL
;
6514 if (!info
->attrs
[NL80211_ATTR_MAC
])
6517 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
6520 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6521 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
6523 if (!rdev
->ops
->change_mpath
)
6526 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6529 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
6532 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6534 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6535 struct net_device
*dev
= info
->user_ptr
[1];
6537 u8
*next_hop
= NULL
;
6539 if (!info
->attrs
[NL80211_ATTR_MAC
])
6542 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
6545 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6546 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
6548 if (!rdev
->ops
->add_mpath
)
6551 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6554 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
6557 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6559 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6560 struct net_device
*dev
= info
->user_ptr
[1];
6563 if (info
->attrs
[NL80211_ATTR_MAC
])
6564 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6566 if (!rdev
->ops
->del_mpath
)
6569 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6572 return rdev_del_mpath(rdev
, dev
, dst
);
6575 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
6577 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6579 struct net_device
*dev
= info
->user_ptr
[1];
6580 struct mpath_info pinfo
;
6581 struct sk_buff
*msg
;
6585 memset(&pinfo
, 0, sizeof(pinfo
));
6587 if (!info
->attrs
[NL80211_ATTR_MAC
])
6590 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6592 if (!rdev
->ops
->get_mpp
)
6595 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6598 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
6602 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6606 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6607 dev
, dst
, mpp
, &pinfo
) < 0) {
6612 return genlmsg_reply(msg
, info
);
6615 static int nl80211_dump_mpp(struct sk_buff
*skb
,
6616 struct netlink_callback
*cb
)
6618 struct mpath_info pinfo
;
6619 struct cfg80211_registered_device
*rdev
;
6620 struct wireless_dev
*wdev
;
6623 int path_idx
= cb
->args
[2];
6627 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
6631 if (!rdev
->ops
->dump_mpp
) {
6636 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
6642 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
6649 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
6650 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6651 wdev
->netdev
, dst
, mpp
,
6659 cb
->args
[2] = path_idx
;
6666 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
6668 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6669 struct net_device
*dev
= info
->user_ptr
[1];
6670 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6671 struct bss_parameters params
;
6674 memset(¶ms
, 0, sizeof(params
));
6675 /* default to not changing parameters */
6676 params
.use_cts_prot
= -1;
6677 params
.use_short_preamble
= -1;
6678 params
.use_short_slot_time
= -1;
6679 params
.ap_isolate
= -1;
6680 params
.ht_opmode
= -1;
6681 params
.p2p_ctwindow
= -1;
6682 params
.p2p_opp_ps
= -1;
6684 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
6685 params
.use_cts_prot
=
6686 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
6687 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
6688 params
.use_short_preamble
=
6689 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
6690 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
6691 params
.use_short_slot_time
=
6692 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
6693 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6694 params
.basic_rates
=
6695 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6696 params
.basic_rates_len
=
6697 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6699 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
6700 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
6701 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
6703 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
6705 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
6706 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6708 params
.p2p_ctwindow
=
6709 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
6710 if (params
.p2p_ctwindow
!= 0 &&
6711 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
6715 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
6718 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6720 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
6721 params
.p2p_opp_ps
= tmp
;
6722 if (params
.p2p_opp_ps
&&
6723 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
6727 if (!rdev
->ops
->change_bss
)
6730 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
6731 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6735 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
6741 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
6745 enum nl80211_user_reg_hint_type user_reg_hint_type
;
6749 * You should only get this when cfg80211 hasn't yet initialized
6750 * completely when built-in to the kernel right between the time
6751 * window between nl80211_init() and regulatory_init(), if that is
6754 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
6755 return -EINPROGRESS
;
6757 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
6758 user_reg_hint_type
=
6759 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
6761 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
6763 switch (user_reg_hint_type
) {
6764 case NL80211_USER_REG_HINT_USER
:
6765 case NL80211_USER_REG_HINT_CELL_BASE
:
6766 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
6769 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
6770 return regulatory_hint_user(data
, user_reg_hint_type
);
6771 case NL80211_USER_REG_HINT_INDOOR
:
6772 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
6773 owner_nlportid
= info
->snd_portid
;
6774 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
6780 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
6786 static int nl80211_reload_regdb(struct sk_buff
*skb
, struct genl_info
*info
)
6788 return reg_reload_regdb();
6791 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
6792 struct genl_info
*info
)
6794 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6795 struct net_device
*dev
= info
->user_ptr
[1];
6796 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6797 struct mesh_config cur_params
;
6800 struct nlattr
*pinfoattr
;
6801 struct sk_buff
*msg
;
6803 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6806 if (!rdev
->ops
->get_mesh_config
)
6810 /* If not connected, get default parameters */
6811 if (!wdev
->mesh_id_len
)
6812 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
6814 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
6820 /* Draw up a netlink message to send back */
6821 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6824 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6825 NL80211_CMD_GET_MESH_CONFIG
);
6828 pinfoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_MESH_CONFIG
);
6830 goto nla_put_failure
;
6831 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
6832 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
6833 cur_params
.dot11MeshRetryTimeout
) ||
6834 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
6835 cur_params
.dot11MeshConfirmTimeout
) ||
6836 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
6837 cur_params
.dot11MeshHoldingTimeout
) ||
6838 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
6839 cur_params
.dot11MeshMaxPeerLinks
) ||
6840 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
6841 cur_params
.dot11MeshMaxRetries
) ||
6842 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
6843 cur_params
.dot11MeshTTL
) ||
6844 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
6845 cur_params
.element_ttl
) ||
6846 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
6847 cur_params
.auto_open_plinks
) ||
6848 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
6849 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
6850 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
6851 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
6852 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
6853 cur_params
.path_refresh_time
) ||
6854 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
6855 cur_params
.min_discovery_timeout
) ||
6856 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
6857 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
6858 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
6859 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
6860 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
6861 cur_params
.dot11MeshHWMPperrMinInterval
) ||
6862 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
6863 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
6864 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
6865 cur_params
.dot11MeshHWMPRootMode
) ||
6866 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
6867 cur_params
.dot11MeshHWMPRannInterval
) ||
6868 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
6869 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
6870 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
6871 cur_params
.dot11MeshForwarding
) ||
6872 nla_put_s32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
6873 cur_params
.rssi_threshold
) ||
6874 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
6875 cur_params
.ht_opmode
) ||
6876 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
6877 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
6878 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
6879 cur_params
.dot11MeshHWMProotInterval
) ||
6880 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
6881 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
6882 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
6883 cur_params
.power_mode
) ||
6884 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
6885 cur_params
.dot11MeshAwakeWindowDuration
) ||
6886 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
6887 cur_params
.plink_timeout
) ||
6888 nla_put_u8(msg
, NL80211_MESHCONF_CONNECTED_TO_GATE
,
6889 cur_params
.dot11MeshConnectedToMeshGate
) ||
6890 nla_put_u8(msg
, NL80211_MESHCONF_NOLEARN
,
6891 cur_params
.dot11MeshNolearn
) ||
6892 nla_put_u8(msg
, NL80211_MESHCONF_CONNECTED_TO_AS
,
6893 cur_params
.dot11MeshConnectedToAuthServer
))
6894 goto nla_put_failure
;
6895 nla_nest_end(msg
, pinfoattr
);
6896 genlmsg_end(msg
, hdr
);
6897 return genlmsg_reply(msg
, info
);
6905 static const struct nla_policy
6906 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
6907 [NL80211_MESHCONF_RETRY_TIMEOUT
] =
6908 NLA_POLICY_RANGE(NLA_U16
, 1, 255),
6909 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] =
6910 NLA_POLICY_RANGE(NLA_U16
, 1, 255),
6911 [NL80211_MESHCONF_HOLDING_TIMEOUT
] =
6912 NLA_POLICY_RANGE(NLA_U16
, 1, 255),
6913 [NL80211_MESHCONF_MAX_PEER_LINKS
] =
6914 NLA_POLICY_RANGE(NLA_U16
, 0, 255),
6915 [NL80211_MESHCONF_MAX_RETRIES
] = NLA_POLICY_MAX(NLA_U8
, 16),
6916 [NL80211_MESHCONF_TTL
] = NLA_POLICY_MIN(NLA_U8
, 1),
6917 [NL80211_MESHCONF_ELEMENT_TTL
] = NLA_POLICY_MIN(NLA_U8
, 1),
6918 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = NLA_POLICY_MAX(NLA_U8
, 1),
6919 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] =
6920 NLA_POLICY_RANGE(NLA_U32
, 1, 255),
6921 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
6922 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
6923 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = NLA_POLICY_MIN(NLA_U16
, 1),
6924 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
6925 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] =
6926 NLA_POLICY_MIN(NLA_U16
, 1),
6927 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] =
6928 NLA_POLICY_MIN(NLA_U16
, 1),
6929 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] =
6930 NLA_POLICY_MIN(NLA_U16
, 1),
6931 [NL80211_MESHCONF_HWMP_ROOTMODE
] = NLA_POLICY_MAX(NLA_U8
, 4),
6932 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] =
6933 NLA_POLICY_MIN(NLA_U16
, 1),
6934 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = NLA_POLICY_MAX(NLA_U8
, 1),
6935 [NL80211_MESHCONF_FORWARDING
] = NLA_POLICY_MAX(NLA_U8
, 1),
6936 [NL80211_MESHCONF_RSSI_THRESHOLD
] =
6937 NLA_POLICY_RANGE(NLA_S32
, -255, 0),
6938 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
6939 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
6940 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] =
6941 NLA_POLICY_MIN(NLA_U16
, 1),
6942 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] =
6943 NLA_POLICY_MIN(NLA_U16
, 1),
6944 [NL80211_MESHCONF_POWER_MODE
] =
6945 NLA_POLICY_RANGE(NLA_U32
,
6946 NL80211_MESH_POWER_ACTIVE
,
6947 NL80211_MESH_POWER_MAX
),
6948 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
6949 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
6950 [NL80211_MESHCONF_CONNECTED_TO_GATE
] = NLA_POLICY_RANGE(NLA_U8
, 0, 1),
6951 [NL80211_MESHCONF_NOLEARN
] = NLA_POLICY_RANGE(NLA_U8
, 0, 1),
6952 [NL80211_MESHCONF_CONNECTED_TO_AS
] = NLA_POLICY_RANGE(NLA_U8
, 0, 1),
6955 static const struct nla_policy
6956 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
6957 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
6958 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
6959 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
6960 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
6961 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
6962 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
6963 [NL80211_MESH_SETUP_IE
] =
6964 NLA_POLICY_VALIDATE_FN(NLA_BINARY
, validate_ie_attr
,
6965 IEEE80211_MAX_DATA_LEN
),
6966 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
6969 static int nl80211_parse_mesh_config(struct genl_info
*info
,
6970 struct mesh_config
*cfg
,
6973 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
6977 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6980 cfg->param = fn(tb[attr]); \
6981 mask |= BIT((attr) - 1); \
6985 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
6987 if (nla_parse_nested_deprecated(tb
, NL80211_MESHCONF_ATTR_MAX
, info
->attrs
[NL80211_ATTR_MESH_CONFIG
], nl80211_meshconf_params_policy
, info
->extack
))
6990 /* This makes sure that there aren't more than 32 mesh config
6991 * parameters (otherwise our bitfield scheme would not work.) */
6992 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
6994 /* Fill in the params struct */
6995 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, mask
,
6996 NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
6997 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, mask
,
6998 NL80211_MESHCONF_CONFIRM_TIMEOUT
,
7000 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, mask
,
7001 NL80211_MESHCONF_HOLDING_TIMEOUT
,
7003 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, mask
,
7004 NL80211_MESHCONF_MAX_PEER_LINKS
,
7006 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, mask
,
7007 NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
7008 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, mask
,
7009 NL80211_MESHCONF_TTL
, nla_get_u8
);
7010 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, mask
,
7011 NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
7012 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, mask
,
7013 NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
7015 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
7017 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
7019 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, mask
,
7020 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
7022 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, mask
,
7023 NL80211_MESHCONF_PATH_REFRESH_TIME
,
7025 if (mask
& BIT(NL80211_MESHCONF_PATH_REFRESH_TIME
) &&
7026 (cfg
->path_refresh_time
< 1 || cfg
->path_refresh_time
> 65535))
7028 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, mask
,
7029 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
7031 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
7033 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
7035 if (mask
& BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
) &&
7036 (cfg
->dot11MeshHWMPactivePathTimeout
< 1 ||
7037 cfg
->dot11MeshHWMPactivePathTimeout
> 65535))
7039 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
, mask
,
7040 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
7042 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
, mask
,
7043 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
7045 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
7046 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
7047 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
7049 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
7050 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
7051 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
7052 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
7054 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshGateAnnouncementProtocol
,
7055 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
7057 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, mask
,
7058 NL80211_MESHCONF_FORWARDING
, nla_get_u8
);
7059 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, mask
,
7060 NL80211_MESHCONF_RSSI_THRESHOLD
,
7062 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConnectedToMeshGate
, mask
,
7063 NL80211_MESHCONF_CONNECTED_TO_GATE
,
7065 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConnectedToAuthServer
, mask
,
7066 NL80211_MESHCONF_CONNECTED_TO_AS
,
7069 * Check HT operation mode based on
7070 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
7072 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
7073 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
7075 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
7076 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
7077 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
7080 /* NON_HT_STA bit is reserved, but some programs set it */
7081 ht_opmode
&= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
;
7083 cfg
->ht_opmode
= ht_opmode
;
7084 mask
|= (1 << (NL80211_MESHCONF_HT_OPMODE
- 1));
7086 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
7087 dot11MeshHWMPactivePathToRootTimeout
, mask
,
7088 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
7090 if (mask
& BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
) &&
7091 (cfg
->dot11MeshHWMPactivePathToRootTimeout
< 1 ||
7092 cfg
->dot11MeshHWMPactivePathToRootTimeout
> 65535))
7094 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, mask
,
7095 NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
7097 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPconfirmationInterval
,
7099 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
7101 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
, mask
,
7102 NL80211_MESHCONF_POWER_MODE
, nla_get_u32
);
7103 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
, mask
,
7104 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
7105 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, mask
,
7106 NL80211_MESHCONF_PLINK_TIMEOUT
, nla_get_u32
);
7107 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNolearn
, mask
,
7108 NL80211_MESHCONF_NOLEARN
, nla_get_u8
);
7114 #undef FILL_IN_MESH_PARAM_IF_SET
7117 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
7118 struct mesh_setup
*setup
)
7120 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7121 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
7123 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
7125 if (nla_parse_nested_deprecated(tb
, NL80211_MESH_SETUP_ATTR_MAX
, info
->attrs
[NL80211_ATTR_MESH_SETUP
], nl80211_mesh_setup_params_policy
, info
->extack
))
7128 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
7129 setup
->sync_method
=
7130 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
7131 IEEE80211_SYNC_METHOD_VENDOR
:
7132 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
7134 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
7135 setup
->path_sel_proto
=
7136 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
7137 IEEE80211_PATH_PROTOCOL_VENDOR
:
7138 IEEE80211_PATH_PROTOCOL_HWMP
;
7140 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
7141 setup
->path_metric
=
7142 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
7143 IEEE80211_PATH_METRIC_VENDOR
:
7144 IEEE80211_PATH_METRIC_AIRTIME
;
7146 if (tb
[NL80211_MESH_SETUP_IE
]) {
7147 struct nlattr
*ieattr
=
7148 tb
[NL80211_MESH_SETUP_IE
];
7149 setup
->ie
= nla_data(ieattr
);
7150 setup
->ie_len
= nla_len(ieattr
);
7152 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
7153 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
7155 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
7156 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
7157 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
7158 if (setup
->is_secure
)
7159 setup
->user_mpm
= true;
7161 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
7162 if (!setup
->user_mpm
)
7165 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
7171 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
7172 struct genl_info
*info
)
7174 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7175 struct net_device
*dev
= info
->user_ptr
[1];
7176 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7177 struct mesh_config cfg
;
7181 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
7184 if (!rdev
->ops
->update_mesh_config
)
7187 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
7192 if (!wdev
->mesh_id_len
)
7196 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
7203 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
7204 struct sk_buff
*msg
)
7206 struct nlattr
*nl_reg_rules
;
7209 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
7210 (regdom
->dfs_region
&&
7211 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
7212 goto nla_put_failure
;
7214 nl_reg_rules
= nla_nest_start_noflag(msg
, NL80211_ATTR_REG_RULES
);
7216 goto nla_put_failure
;
7218 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
7219 struct nlattr
*nl_reg_rule
;
7220 const struct ieee80211_reg_rule
*reg_rule
;
7221 const struct ieee80211_freq_range
*freq_range
;
7222 const struct ieee80211_power_rule
*power_rule
;
7223 unsigned int max_bandwidth_khz
;
7225 reg_rule
= ®dom
->reg_rules
[i
];
7226 freq_range
= ®_rule
->freq_range
;
7227 power_rule
= ®_rule
->power_rule
;
7229 nl_reg_rule
= nla_nest_start_noflag(msg
, i
);
7231 goto nla_put_failure
;
7233 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
7234 if (!max_bandwidth_khz
)
7235 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
7238 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
7240 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
7241 freq_range
->start_freq_khz
) ||
7242 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
7243 freq_range
->end_freq_khz
) ||
7244 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
7245 max_bandwidth_khz
) ||
7246 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
7247 power_rule
->max_antenna_gain
) ||
7248 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
7249 power_rule
->max_eirp
) ||
7250 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
7251 reg_rule
->dfs_cac_ms
))
7252 goto nla_put_failure
;
7254 nla_nest_end(msg
, nl_reg_rule
);
7257 nla_nest_end(msg
, nl_reg_rules
);
7264 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
7266 const struct ieee80211_regdomain
*regdom
= NULL
;
7267 struct cfg80211_registered_device
*rdev
;
7268 struct wiphy
*wiphy
= NULL
;
7269 struct sk_buff
*msg
;
7272 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7276 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7277 NL80211_CMD_GET_REG
);
7281 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
7284 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
7287 return PTR_ERR(rdev
);
7290 wiphy
= &rdev
->wiphy
;
7291 self_managed
= wiphy
->regulatory_flags
&
7292 REGULATORY_WIPHY_SELF_MANAGED
;
7293 regdom
= get_wiphy_regdom(wiphy
);
7295 /* a self-managed-reg device must have a private regdom */
7296 if (WARN_ON(!regdom
&& self_managed
)) {
7302 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
7303 goto nla_put_failure
;
7306 if (!wiphy
&& reg_last_request_cell_base() &&
7307 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
7308 NL80211_USER_REG_HINT_CELL_BASE
))
7309 goto nla_put_failure
;
7314 regdom
= rcu_dereference(cfg80211_regdomain
);
7316 if (nl80211_put_regdom(regdom
, msg
))
7317 goto nla_put_failure_rcu
;
7321 genlmsg_end(msg
, hdr
);
7322 return genlmsg_reply(msg
, info
);
7324 nla_put_failure_rcu
:
7332 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
7333 u32 seq
, int flags
, struct wiphy
*wiphy
,
7334 const struct ieee80211_regdomain
*regdom
)
7336 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
7337 NL80211_CMD_GET_REG
);
7342 genl_dump_check_consistent(cb
, hdr
);
7344 if (nl80211_put_regdom(regdom
, msg
))
7345 goto nla_put_failure
;
7347 if (!wiphy
&& reg_last_request_cell_base() &&
7348 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
7349 NL80211_USER_REG_HINT_CELL_BASE
))
7350 goto nla_put_failure
;
7353 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
7354 goto nla_put_failure
;
7356 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
7357 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
7358 goto nla_put_failure
;
7360 genlmsg_end(msg
, hdr
);
7364 genlmsg_cancel(msg
, hdr
);
7368 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
7369 struct netlink_callback
*cb
)
7371 const struct ieee80211_regdomain
*regdom
= NULL
;
7372 struct cfg80211_registered_device
*rdev
;
7373 int err
, reg_idx
, start
= cb
->args
[2];
7377 if (cfg80211_regdomain
&& start
== 0) {
7378 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
7380 rtnl_dereference(cfg80211_regdomain
));
7385 /* the global regdom is idx 0 */
7387 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
7388 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
7392 if (++reg_idx
<= start
)
7395 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
7396 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
7403 cb
->args
[2] = reg_idx
;
7410 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
7411 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
7412 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
7413 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
7414 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
7415 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
7416 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
7417 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
7418 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
7421 static int parse_reg_rule(struct nlattr
*tb
[],
7422 struct ieee80211_reg_rule
*reg_rule
)
7424 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
7425 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
7427 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
7429 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
7431 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
7433 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
7435 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
7438 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
7440 freq_range
->start_freq_khz
=
7441 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
7442 freq_range
->end_freq_khz
=
7443 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
7444 freq_range
->max_bandwidth_khz
=
7445 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
7447 power_rule
->max_eirp
=
7448 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
7450 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
7451 power_rule
->max_antenna_gain
=
7452 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
7454 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
7455 reg_rule
->dfs_cac_ms
=
7456 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
7461 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
7463 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
7464 struct nlattr
*nl_reg_rule
;
7466 int rem_reg_rules
, r
;
7467 u32 num_rules
= 0, rule_idx
= 0;
7468 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
7469 struct ieee80211_regdomain
*rd
;
7471 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
7474 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
7477 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
7479 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
7480 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
7482 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
7485 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
7489 if (!reg_is_valid_request(alpha2
))
7492 rd
= kzalloc(struct_size(rd
, reg_rules
, num_rules
), GFP_KERNEL
);
7496 rd
->n_reg_rules
= num_rules
;
7497 rd
->alpha2
[0] = alpha2
[0];
7498 rd
->alpha2
[1] = alpha2
[1];
7501 * Disable DFS master mode if the DFS region was
7502 * not supported or known on this kernel.
7504 if (reg_supported_dfs_region(dfs_region
))
7505 rd
->dfs_region
= dfs_region
;
7507 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
7509 r
= nla_parse_nested_deprecated(tb
, NL80211_REG_RULE_ATTR_MAX
,
7510 nl_reg_rule
, reg_rule_policy
,
7514 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
7520 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
7526 /* set_regdom takes ownership of rd */
7527 return set_regdom(rd
, REGD_SOURCE_CRDA
);
7532 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
7534 static int validate_scan_freqs(struct nlattr
*freqs
)
7536 struct nlattr
*attr1
, *attr2
;
7537 int n_channels
= 0, tmp1
, tmp2
;
7539 nla_for_each_nested(attr1
, freqs
, tmp1
)
7540 if (nla_len(attr1
) != sizeof(u32
))
7543 nla_for_each_nested(attr1
, freqs
, tmp1
) {
7546 * Some hardware has a limited channel list for
7547 * scanning, and it is pretty much nonsensical
7548 * to scan for a channel twice, so disallow that
7549 * and don't require drivers to check that the
7550 * channel list they get isn't longer than what
7551 * they can scan, as long as they can scan all
7552 * the channels they registered at once.
7554 nla_for_each_nested(attr2
, freqs
, tmp2
)
7555 if (attr1
!= attr2
&&
7556 nla_get_u32(attr1
) == nla_get_u32(attr2
))
7563 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
7565 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
7568 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
7569 struct cfg80211_bss_selection
*bss_select
)
7571 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
7572 struct nlattr
*nest
;
7577 /* only process one nested attribute */
7578 nest
= nla_data(nla
);
7579 if (!nla_ok(nest
, nla_len(nest
)))
7582 err
= nla_parse_nested_deprecated(attr
, NL80211_BSS_SELECT_ATTR_MAX
,
7583 nest
, nl80211_bss_select_policy
,
7588 /* only one attribute may be given */
7589 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
7597 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
7599 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
7600 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
7602 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
7603 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
7604 bss_select
->param
.band_pref
=
7605 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
7606 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
7610 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
7611 struct nl80211_bss_select_rssi_adjust
*adj_param
;
7613 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
7614 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
7615 bss_select
->param
.adjust
.band
= adj_param
->band
;
7616 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
7617 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
7621 /* user-space did not provide behaviour attribute */
7622 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
7625 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
7631 int nl80211_parse_random_mac(struct nlattr
**attrs
,
7632 u8
*mac_addr
, u8
*mac_addr_mask
)
7636 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
7637 eth_zero_addr(mac_addr
);
7638 eth_zero_addr(mac_addr_mask
);
7640 mac_addr_mask
[0] = 0x3;
7645 /* need both or none */
7646 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
7649 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
7650 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
7652 /* don't allow or configure an mcast address */
7653 if (!is_multicast_ether_addr(mac_addr_mask
) ||
7654 is_multicast_ether_addr(mac_addr
))
7658 * allow users to pass a MAC address that has bits set outside
7659 * of the mask, but don't bother drivers with having to deal
7662 for (i
= 0; i
< ETH_ALEN
; i
++)
7663 mac_addr
[i
] &= mac_addr_mask
[i
];
7668 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev
*wdev
)
7670 ASSERT_WDEV_LOCK(wdev
);
7672 if (!cfg80211_beaconing_iface_active(wdev
))
7675 if (!(wdev
->chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
))
7678 return regulatory_pre_cac_allowed(wdev
->wiphy
);
7681 static bool nl80211_check_scan_feat(struct wiphy
*wiphy
, u32 flags
, u32 flag
,
7682 enum nl80211_ext_feature_index feat
)
7684 if (!(flags
& flag
))
7686 if (wiphy_ext_feature_isset(wiphy
, feat
))
7692 nl80211_check_scan_flags(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
7693 void *request
, struct nlattr
**attrs
,
7696 u8
*mac_addr
, *mac_addr_mask
;
7698 enum nl80211_feature_flags randomness_flag
;
7700 if (!attrs
[NL80211_ATTR_SCAN_FLAGS
])
7703 if (is_sched_scan
) {
7704 struct cfg80211_sched_scan_request
*req
= request
;
7706 randomness_flag
= wdev
?
7707 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
:
7708 NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
7709 flags
= &req
->flags
;
7710 mac_addr
= req
->mac_addr
;
7711 mac_addr_mask
= req
->mac_addr_mask
;
7713 struct cfg80211_scan_request
*req
= request
;
7715 randomness_flag
= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
7716 flags
= &req
->flags
;
7717 mac_addr
= req
->mac_addr
;
7718 mac_addr_mask
= req
->mac_addr_mask
;
7721 *flags
= nla_get_u32(attrs
[NL80211_ATTR_SCAN_FLAGS
]);
7723 if (((*flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
7724 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
7725 !nl80211_check_scan_feat(wiphy
, *flags
,
7726 NL80211_SCAN_FLAG_LOW_SPAN
,
7727 NL80211_EXT_FEATURE_LOW_SPAN_SCAN
) ||
7728 !nl80211_check_scan_feat(wiphy
, *flags
,
7729 NL80211_SCAN_FLAG_LOW_POWER
,
7730 NL80211_EXT_FEATURE_LOW_POWER_SCAN
) ||
7731 !nl80211_check_scan_feat(wiphy
, *flags
,
7732 NL80211_SCAN_FLAG_HIGH_ACCURACY
,
7733 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN
) ||
7734 !nl80211_check_scan_feat(wiphy
, *flags
,
7735 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME
,
7736 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME
) ||
7737 !nl80211_check_scan_feat(wiphy
, *flags
,
7738 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP
,
7739 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP
) ||
7740 !nl80211_check_scan_feat(wiphy
, *flags
,
7741 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
,
7742 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
) ||
7743 !nl80211_check_scan_feat(wiphy
, *flags
,
7744 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE
,
7745 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE
) ||
7746 !nl80211_check_scan_feat(wiphy
, *flags
,
7747 NL80211_SCAN_FLAG_RANDOM_SN
,
7748 NL80211_EXT_FEATURE_SCAN_RANDOM_SN
) ||
7749 !nl80211_check_scan_feat(wiphy
, *flags
,
7750 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT
,
7751 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT
))
7754 if (*flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
7757 if (!(wiphy
->features
& randomness_flag
) ||
7758 (wdev
&& wdev
->current_bss
))
7761 err
= nl80211_parse_random_mac(attrs
, mac_addr
, mac_addr_mask
);
7769 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
7771 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7772 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7773 struct cfg80211_scan_request
*request
;
7774 struct nlattr
*scan_freqs
= NULL
;
7775 bool scan_freqs_khz
= false;
7776 struct nlattr
*attr
;
7777 struct wiphy
*wiphy
;
7778 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
7781 wiphy
= &rdev
->wiphy
;
7783 if (wdev
->iftype
== NL80211_IFTYPE_NAN
)
7786 if (!rdev
->ops
->scan
)
7789 if (rdev
->scan_req
|| rdev
->scan_msg
)
7792 if (info
->attrs
[NL80211_ATTR_SCAN_FREQ_KHZ
]) {
7793 if (!wiphy_ext_feature_isset(wiphy
,
7794 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ
))
7796 scan_freqs
= info
->attrs
[NL80211_ATTR_SCAN_FREQ_KHZ
];
7797 scan_freqs_khz
= true;
7798 } else if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
])
7799 scan_freqs
= info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
];
7802 n_channels
= validate_scan_freqs(scan_freqs
);
7806 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
7809 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
7810 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
7813 if (n_ssids
> wiphy
->max_scan_ssids
)
7816 if (info
->attrs
[NL80211_ATTR_IE
])
7817 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7821 if (ie_len
> wiphy
->max_scan_ie_len
)
7824 request
= kzalloc(sizeof(*request
)
7825 + sizeof(*request
->ssids
) * n_ssids
7826 + sizeof(*request
->channels
) * n_channels
7827 + ie_len
, GFP_KERNEL
);
7832 request
->ssids
= (void *)&request
->channels
[n_channels
];
7833 request
->n_ssids
= n_ssids
;
7836 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
7838 request
->ie
= (void *)(request
->channels
+ n_channels
);
7843 /* user specified, bail out if channel not found */
7844 nla_for_each_nested(attr
, scan_freqs
, tmp
) {
7845 struct ieee80211_channel
*chan
;
7846 int freq
= nla_get_u32(attr
);
7848 if (!scan_freqs_khz
)
7849 freq
= MHZ_TO_KHZ(freq
);
7851 chan
= ieee80211_get_channel_khz(wiphy
, freq
);
7857 /* ignore disabled channels */
7858 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7861 request
->channels
[i
] = chan
;
7865 enum nl80211_band band
;
7868 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7871 if (!wiphy
->bands
[band
])
7873 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
7874 struct ieee80211_channel
*chan
;
7876 chan
= &wiphy
->bands
[band
]->channels
[j
];
7878 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7881 request
->channels
[i
] = chan
;
7892 request
->n_channels
= i
;
7895 if (!cfg80211_off_channel_oper_allowed(wdev
)) {
7896 struct ieee80211_channel
*chan
;
7898 if (request
->n_channels
!= 1) {
7904 chan
= request
->channels
[0];
7905 if (chan
->center_freq
!= wdev
->chandef
.chan
->center_freq
) {
7915 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
7916 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7920 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7921 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
7926 if (info
->attrs
[NL80211_ATTR_IE
]) {
7927 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7928 memcpy((void *)request
->ie
,
7929 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
7933 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
7934 if (wiphy
->bands
[i
])
7936 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
7938 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
7939 nla_for_each_nested(attr
,
7940 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
7942 enum nl80211_band band
= nla_type(attr
);
7944 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
7949 if (!wiphy
->bands
[band
])
7952 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
7955 &request
->rates
[band
]);
7961 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
7962 if (!wiphy_ext_feature_isset(wiphy
,
7963 NL80211_EXT_FEATURE_SET_SCAN_DWELL
)) {
7969 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
7970 request
->duration_mandatory
=
7971 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
7974 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, info
->attrs
,
7980 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7982 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7983 * BSSID to scan for. This was problematic because that same attribute
7984 * was already used for another purpose (local random MAC address). The
7985 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7986 * compatibility with older userspace components, also use the
7987 * NL80211_ATTR_MAC value here if it can be determined to be used for
7988 * the specific BSSID use case instead of the random MAC address
7989 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7991 if (info
->attrs
[NL80211_ATTR_BSSID
])
7992 memcpy(request
->bssid
,
7993 nla_data(info
->attrs
[NL80211_ATTR_BSSID
]), ETH_ALEN
);
7994 else if (!(request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) &&
7995 info
->attrs
[NL80211_ATTR_MAC
])
7996 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
7999 eth_broadcast_addr(request
->bssid
);
8001 request
->wdev
= wdev
;
8002 request
->wiphy
= &rdev
->wiphy
;
8003 request
->scan_start
= jiffies
;
8005 rdev
->scan_req
= request
;
8006 err
= rdev_scan(rdev
, request
);
8011 nl80211_send_scan_start(rdev
, wdev
);
8013 dev_hold(wdev
->netdev
);
8018 rdev
->scan_req
= NULL
;
8024 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
8026 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8027 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8029 if (!rdev
->ops
->abort_scan
)
8035 if (!rdev
->scan_req
)
8038 rdev_abort_scan(rdev
, wdev
);
8043 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
8044 struct cfg80211_sched_scan_request
*request
,
8045 struct nlattr
**attrs
)
8047 int tmp
, err
, i
= 0;
8048 struct nlattr
*attr
;
8050 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
8054 * If scan plans are not specified,
8055 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
8056 * case one scan plan will be set with the specified scan
8057 * interval and infinite number of iterations.
8059 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
8063 request
->scan_plans
[0].interval
=
8064 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
8065 if (!request
->scan_plans
[0].interval
)
8068 if (request
->scan_plans
[0].interval
>
8069 wiphy
->max_sched_scan_plan_interval
)
8070 request
->scan_plans
[0].interval
=
8071 wiphy
->max_sched_scan_plan_interval
;
8076 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
8077 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
8079 if (WARN_ON(i
>= n_plans
))
8082 err
= nla_parse_nested_deprecated(plan
,
8083 NL80211_SCHED_SCAN_PLAN_MAX
,
8084 attr
, nl80211_plan_policy
,
8089 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
8092 request
->scan_plans
[i
].interval
=
8093 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
8094 if (!request
->scan_plans
[i
].interval
||
8095 request
->scan_plans
[i
].interval
>
8096 wiphy
->max_sched_scan_plan_interval
)
8099 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
8100 request
->scan_plans
[i
].iterations
=
8101 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
8102 if (!request
->scan_plans
[i
].iterations
||
8103 (request
->scan_plans
[i
].iterations
>
8104 wiphy
->max_sched_scan_plan_iterations
))
8106 } else if (i
< n_plans
- 1) {
8108 * All scan plans but the last one must specify
8109 * a finite number of iterations
8118 * The last scan plan must not specify the number of
8119 * iterations, it is supposed to run infinitely
8121 if (request
->scan_plans
[n_plans
- 1].iterations
)
8128 nl80211_parse_sched_scan_per_band_rssi(struct wiphy
*wiphy
,
8129 struct cfg80211_match_set
*match_sets
,
8130 struct nlattr
*tb_band_rssi
,
8133 struct nlattr
*attr
;
8134 int i
, tmp
, ret
= 0;
8136 if (!wiphy_ext_feature_isset(wiphy
,
8137 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD
)) {
8141 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
8142 match_sets
->per_band_rssi_thold
[i
] =
8143 NL80211_SCAN_RSSI_THOLD_OFF
;
8147 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
8148 match_sets
->per_band_rssi_thold
[i
] = rssi_thold
;
8150 nla_for_each_nested(attr
, tb_band_rssi
, tmp
) {
8151 enum nl80211_band band
= nla_type(attr
);
8153 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
8156 match_sets
->per_band_rssi_thold
[band
] = nla_get_s32(attr
);
8162 static struct cfg80211_sched_scan_request
*
8163 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
8164 struct nlattr
**attrs
, int max_match_sets
)
8166 struct cfg80211_sched_scan_request
*request
;
8167 struct nlattr
*attr
;
8168 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
8169 enum nl80211_band band
;
8171 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
8172 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
8174 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
8175 n_channels
= validate_scan_freqs(
8176 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
8178 return ERR_PTR(-EINVAL
);
8180 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
8183 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
8184 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
8188 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
8189 return ERR_PTR(-EINVAL
);
8192 * First, count the number of 'real' matchsets. Due to an issue with
8193 * the old implementation, matchsets containing only the RSSI attribute
8194 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
8195 * RSSI for all matchsets, rather than their own matchset for reporting
8196 * all APs with a strong RSSI. This is needed to be compatible with
8197 * older userspace that treated a matchset with only the RSSI as the
8198 * global RSSI for all other matchsets - if there are other matchsets.
8200 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
8201 nla_for_each_nested(attr
,
8202 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
8204 struct nlattr
*rssi
;
8206 err
= nla_parse_nested_deprecated(tb
,
8207 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
8209 nl80211_match_policy
,
8212 return ERR_PTR(err
);
8214 /* SSID and BSSID are mutually exclusive */
8215 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] &&
8216 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
])
8217 return ERR_PTR(-EINVAL
);
8219 /* add other standalone attributes here */
8220 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] ||
8221 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
]) {
8225 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
8227 default_match_rssi
= nla_get_s32(rssi
);
8231 /* However, if there's no other matchset, add the RSSI one */
8232 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
8235 if (n_match_sets
> max_match_sets
)
8236 return ERR_PTR(-EINVAL
);
8238 if (attrs
[NL80211_ATTR_IE
])
8239 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
8243 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
8244 return ERR_PTR(-EINVAL
);
8246 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
8248 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
8249 * each scan plan already specifies its own interval
8251 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
8252 return ERR_PTR(-EINVAL
);
8254 nla_for_each_nested(attr
,
8255 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
8259 * The scan interval attribute is kept for backward
8260 * compatibility. If no scan plans are specified and sched scan
8261 * interval is specified, one scan plan will be set with this
8262 * scan interval and infinite number of iterations.
8264 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
8265 return ERR_PTR(-EINVAL
);
8270 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
8271 return ERR_PTR(-EINVAL
);
8273 if (!wiphy_ext_feature_isset(
8274 wiphy
, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI
) &&
8275 (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] ||
8276 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]))
8277 return ERR_PTR(-EINVAL
);
8279 request
= kzalloc(sizeof(*request
)
8280 + sizeof(*request
->ssids
) * n_ssids
8281 + sizeof(*request
->match_sets
) * n_match_sets
8282 + sizeof(*request
->scan_plans
) * n_plans
8283 + sizeof(*request
->channels
) * n_channels
8284 + ie_len
, GFP_KERNEL
);
8286 return ERR_PTR(-ENOMEM
);
8289 request
->ssids
= (void *)&request
->channels
[n_channels
];
8290 request
->n_ssids
= n_ssids
;
8293 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
8295 request
->ie
= (void *)(request
->channels
+ n_channels
);
8300 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
8302 request
->match_sets
=
8303 (void *)(request
->ssids
+ n_ssids
);
8305 request
->match_sets
=
8306 (void *)(request
->channels
+ n_channels
);
8308 request
->n_match_sets
= n_match_sets
;
8311 request
->scan_plans
= (void *)(request
->match_sets
+
8313 else if (request
->ie
)
8314 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
8316 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
8318 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
8320 request
->n_scan_plans
= n_plans
;
8323 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
8324 /* user specified, bail out if channel not found */
8325 nla_for_each_nested(attr
,
8326 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
8328 struct ieee80211_channel
*chan
;
8330 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
8337 /* ignore disabled channels */
8338 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
8341 request
->channels
[i
] = chan
;
8346 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8349 if (!wiphy
->bands
[band
])
8351 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
8352 struct ieee80211_channel
*chan
;
8354 chan
= &wiphy
->bands
[band
]->channels
[j
];
8356 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
8359 request
->channels
[i
] = chan
;
8370 request
->n_channels
= i
;
8374 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
8376 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
8380 request
->ssids
[i
].ssid_len
= nla_len(attr
);
8381 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
8388 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
8389 nla_for_each_nested(attr
,
8390 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
8392 struct nlattr
*ssid
, *bssid
, *rssi
;
8394 err
= nla_parse_nested_deprecated(tb
,
8395 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
8397 nl80211_match_policy
,
8401 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
8402 bssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
];
8404 if (!ssid
&& !bssid
) {
8409 if (WARN_ON(i
>= n_match_sets
)) {
8410 /* this indicates a programming error,
8411 * the loop above should have verified
8419 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
8423 memcpy(request
->match_sets
[i
].ssid
.ssid
,
8424 nla_data(ssid
), nla_len(ssid
));
8425 request
->match_sets
[i
].ssid
.ssid_len
=
8429 if (nla_len(bssid
) != ETH_ALEN
) {
8433 memcpy(request
->match_sets
[i
].bssid
,
8434 nla_data(bssid
), ETH_ALEN
);
8437 /* special attribute - old implementation w/a */
8438 request
->match_sets
[i
].rssi_thold
= default_match_rssi
;
8439 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
8441 request
->match_sets
[i
].rssi_thold
=
8444 /* Parse per band RSSI attribute */
8445 err
= nl80211_parse_sched_scan_per_band_rssi(wiphy
,
8446 &request
->match_sets
[i
],
8447 tb
[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI
],
8448 request
->match_sets
[i
].rssi_thold
);
8455 /* there was no other matchset, so the RSSI one is alone */
8456 if (i
== 0 && n_match_sets
)
8457 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
8459 request
->min_rssi_thold
= INT_MAX
;
8460 for (i
= 0; i
< n_match_sets
; i
++)
8461 request
->min_rssi_thold
=
8462 min(request
->match_sets
[i
].rssi_thold
,
8463 request
->min_rssi_thold
);
8465 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
8469 request
->ie_len
= ie_len
;
8470 memcpy((void *)request
->ie
,
8471 nla_data(attrs
[NL80211_ATTR_IE
]),
8475 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, attrs
, true);
8479 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
8481 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
8483 if (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]) {
8484 request
->relative_rssi
= nla_get_s8(
8485 attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]);
8486 request
->relative_rssi_set
= true;
8489 if (request
->relative_rssi_set
&&
8490 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]) {
8491 struct nl80211_bss_select_rssi_adjust
*rssi_adjust
;
8493 rssi_adjust
= nla_data(
8494 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]);
8495 request
->rssi_adjust
.band
= rssi_adjust
->band
;
8496 request
->rssi_adjust
.delta
= rssi_adjust
->delta
;
8497 if (!is_band_valid(wiphy
, request
->rssi_adjust
.band
)) {
8503 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
8507 request
->scan_start
= jiffies
;
8513 return ERR_PTR(err
);
8516 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
8517 struct genl_info
*info
)
8519 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8520 struct net_device
*dev
= info
->user_ptr
[1];
8521 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8522 struct cfg80211_sched_scan_request
*sched_scan_req
;
8526 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_start
)
8529 want_multi
= info
->attrs
[NL80211_ATTR_SCHED_SCAN_MULTI
];
8530 err
= cfg80211_sched_scan_req_possible(rdev
, want_multi
);
8534 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
8536 rdev
->wiphy
.max_match_sets
);
8538 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
8542 /* leave request id zero for legacy request
8543 * or if driver does not support multi-scheduled scan
8545 if (want_multi
&& rdev
->wiphy
.max_sched_scan_reqs
> 1)
8546 sched_scan_req
->reqid
= cfg80211_assign_cookie(rdev
);
8548 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
8552 sched_scan_req
->dev
= dev
;
8553 sched_scan_req
->wiphy
= &rdev
->wiphy
;
8555 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
8556 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
8558 cfg80211_add_sched_scan_req(rdev
, sched_scan_req
);
8560 nl80211_send_sched_scan(sched_scan_req
, NL80211_CMD_START_SCHED_SCAN
);
8564 kfree(sched_scan_req
);
8569 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
8570 struct genl_info
*info
)
8572 struct cfg80211_sched_scan_request
*req
;
8573 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8576 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_stop
)
8579 if (info
->attrs
[NL80211_ATTR_COOKIE
]) {
8580 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8581 return __cfg80211_stop_sched_scan(rdev
, cookie
, false);
8584 req
= list_first_or_null_rcu(&rdev
->sched_scan_req_list
,
8585 struct cfg80211_sched_scan_request
,
8587 if (!req
|| req
->reqid
||
8588 (req
->owner_nlportid
&&
8589 req
->owner_nlportid
!= info
->snd_portid
))
8592 return cfg80211_stop_sched_scan_req(rdev
, req
, false);
8595 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
8596 struct genl_info
*info
)
8598 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8599 struct net_device
*dev
= info
->user_ptr
[1];
8600 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8601 struct wiphy
*wiphy
= wdev
->wiphy
;
8602 struct cfg80211_chan_def chandef
;
8603 enum nl80211_dfs_regions dfs_region
;
8604 unsigned int cac_time_ms
;
8607 dfs_region
= reg_get_dfs_region(wiphy
);
8608 if (dfs_region
== NL80211_DFS_UNSET
)
8611 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8615 if (netif_carrier_ok(dev
))
8618 if (wdev
->cac_started
)
8621 err
= cfg80211_chandef_dfs_required(wiphy
, &chandef
, wdev
->iftype
);
8628 if (!cfg80211_chandef_dfs_usable(wiphy
, &chandef
))
8631 /* CAC start is offloaded to HW and can't be started manually */
8632 if (wiphy_ext_feature_isset(wiphy
, NL80211_EXT_FEATURE_DFS_OFFLOAD
))
8635 if (!rdev
->ops
->start_radar_detection
)
8638 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
8639 if (WARN_ON(!cac_time_ms
))
8640 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
8642 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
8644 wdev
->chandef
= chandef
;
8645 wdev
->cac_started
= true;
8646 wdev
->cac_start_time
= jiffies
;
8647 wdev
->cac_time_ms
= cac_time_ms
;
8652 static int nl80211_notify_radar_detection(struct sk_buff
*skb
,
8653 struct genl_info
*info
)
8655 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8656 struct net_device
*dev
= info
->user_ptr
[1];
8657 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8658 struct wiphy
*wiphy
= wdev
->wiphy
;
8659 struct cfg80211_chan_def chandef
;
8660 enum nl80211_dfs_regions dfs_region
;
8663 dfs_region
= reg_get_dfs_region(wiphy
);
8664 if (dfs_region
== NL80211_DFS_UNSET
) {
8665 GENL_SET_ERR_MSG(info
,
8666 "DFS Region is not set. Unexpected Radar indication");
8670 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8672 GENL_SET_ERR_MSG(info
, "Unable to extract chandef info");
8676 err
= cfg80211_chandef_dfs_required(wiphy
, &chandef
, wdev
->iftype
);
8678 GENL_SET_ERR_MSG(info
, "chandef is invalid");
8683 GENL_SET_ERR_MSG(info
,
8684 "Unexpected Radar indication for chandef/iftype");
8688 /* Do not process this notification if radar is already detected
8689 * by kernel on this channel, and return success.
8691 if (chandef
.chan
->dfs_state
== NL80211_DFS_UNAVAILABLE
)
8694 cfg80211_set_dfs_state(wiphy
, &chandef
, NL80211_DFS_UNAVAILABLE
);
8696 cfg80211_sched_dfs_chan_update(rdev
);
8698 rdev
->radar_chandef
= chandef
;
8700 /* Propagate this notification to other radios as well */
8701 queue_work(cfg80211_wq
, &rdev
->propagate_radar_detect_wk
);
8706 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
8708 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8709 struct net_device
*dev
= info
->user_ptr
[1];
8710 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8711 struct cfg80211_csa_settings params
;
8712 /* csa_attrs is defined static to avoid waste of stack size - this
8713 * function is called under RTNL lock, so this should not be a problem.
8715 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
8717 bool need_new_beacon
= false;
8718 bool need_handle_dfs_flag
= true;
8722 if (!rdev
->ops
->channel_switch
||
8723 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
8726 switch (dev
->ieee80211_ptr
->iftype
) {
8727 case NL80211_IFTYPE_AP
:
8728 case NL80211_IFTYPE_P2P_GO
:
8729 need_new_beacon
= true;
8730 /* For all modes except AP the handle_dfs flag needs to be
8731 * supplied to tell the kernel that userspace will handle radar
8732 * events when they happen. Otherwise a switch to a channel
8733 * requiring DFS will be rejected.
8735 need_handle_dfs_flag
= false;
8737 /* useless if AP is not running */
8738 if (!wdev
->beacon_interval
)
8741 case NL80211_IFTYPE_ADHOC
:
8742 if (!wdev
->ssid_len
)
8745 case NL80211_IFTYPE_MESH_POINT
:
8746 if (!wdev
->mesh_id_len
)
8753 memset(¶ms
, 0, sizeof(params
));
8754 params
.beacon_csa
.ftm_responder
= -1;
8756 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
8757 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
8760 /* only important for AP, IBSS and mesh create IEs internally */
8761 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
8764 /* Even though the attribute is u32, the specification says
8765 * u8, so let's make sure we don't overflow.
8767 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
8771 params
.count
= cs_count
;
8773 if (!need_new_beacon
)
8776 err
= nl80211_parse_beacon(rdev
, info
->attrs
, ¶ms
.beacon_after
);
8780 err
= nla_parse_nested_deprecated(csa_attrs
, NL80211_ATTR_MAX
,
8781 info
->attrs
[NL80211_ATTR_CSA_IES
],
8782 nl80211_policy
, info
->extack
);
8786 err
= nl80211_parse_beacon(rdev
, csa_attrs
, ¶ms
.beacon_csa
);
8790 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
8793 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
8794 if (!len
|| (len
% sizeof(u16
)))
8797 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
8798 if (rdev
->wiphy
.max_num_csa_counters
&&
8799 (params
.n_counter_offsets_beacon
>
8800 rdev
->wiphy
.max_num_csa_counters
))
8803 params
.counter_offsets_beacon
=
8804 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
8806 /* sanity checks - counters should fit and be the same */
8807 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
8808 u16 offset
= params
.counter_offsets_beacon
[i
];
8810 if (offset
>= params
.beacon_csa
.tail_len
)
8813 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
8817 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
8818 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
8819 if (!len
|| (len
% sizeof(u16
)))
8822 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
8823 if (rdev
->wiphy
.max_num_csa_counters
&&
8824 (params
.n_counter_offsets_presp
>
8825 rdev
->wiphy
.max_num_csa_counters
))
8828 params
.counter_offsets_presp
=
8829 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
8831 /* sanity checks - counters should fit and be the same */
8832 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
8833 u16 offset
= params
.counter_offsets_presp
[i
];
8835 if (offset
>= params
.beacon_csa
.probe_resp_len
)
8838 if (params
.beacon_csa
.probe_resp
[offset
] !=
8845 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
8849 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
8853 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
8860 params
.radar_required
= true;
8861 if (need_handle_dfs_flag
&&
8862 !nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
])) {
8867 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
8868 params
.block_tx
= true;
8871 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
8877 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
8879 struct cfg80211_registered_device
*rdev
,
8880 struct wireless_dev
*wdev
,
8881 struct cfg80211_internal_bss
*intbss
)
8883 struct cfg80211_bss
*res
= &intbss
->pub
;
8884 const struct cfg80211_bss_ies
*ies
;
8888 ASSERT_WDEV_LOCK(wdev
);
8890 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
8891 NL80211_CMD_NEW_SCAN_RESULTS
);
8895 genl_dump_check_consistent(cb
, hdr
);
8897 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
8898 goto nla_put_failure
;
8900 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
8901 goto nla_put_failure
;
8902 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
8904 goto nla_put_failure
;
8906 bss
= nla_nest_start_noflag(msg
, NL80211_ATTR_BSS
);
8908 goto nla_put_failure
;
8909 if ((!is_zero_ether_addr(res
->bssid
) &&
8910 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
8911 goto nla_put_failure
;
8914 /* indicate whether we have probe response data or not */
8915 if (rcu_access_pointer(res
->proberesp_ies
) &&
8916 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
8917 goto fail_unlock_rcu
;
8919 /* this pointer prefers to be pointed to probe response data
8920 * but is always valid
8922 ies
= rcu_dereference(res
->ies
);
8924 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
8926 goto fail_unlock_rcu
;
8927 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
8928 ies
->len
, ies
->data
))
8929 goto fail_unlock_rcu
;
8932 /* and this pointer is always (unless driver didn't know) beacon data */
8933 ies
= rcu_dereference(res
->beacon_ies
);
8934 if (ies
&& ies
->from_beacon
) {
8935 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
8937 goto fail_unlock_rcu
;
8938 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
8939 ies
->len
, ies
->data
))
8940 goto fail_unlock_rcu
;
8944 if (res
->beacon_interval
&&
8945 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
8946 goto nla_put_failure
;
8947 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
8948 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
8949 nla_put_u32(msg
, NL80211_BSS_FREQUENCY_OFFSET
,
8950 res
->channel
->freq_offset
) ||
8951 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
8952 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
8953 jiffies_to_msecs(jiffies
- intbss
->ts
)))
8954 goto nla_put_failure
;
8956 if (intbss
->parent_tsf
&&
8957 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
8958 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
8959 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
8960 intbss
->parent_bssid
)))
8961 goto nla_put_failure
;
8963 if (intbss
->ts_boottime
&&
8964 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
8965 intbss
->ts_boottime
, NL80211_BSS_PAD
))
8966 goto nla_put_failure
;
8968 if (!nl80211_put_signal(msg
, intbss
->pub
.chains
,
8969 intbss
->pub
.chain_signal
,
8970 NL80211_BSS_CHAIN_SIGNAL
))
8971 goto nla_put_failure
;
8973 switch (rdev
->wiphy
.signal_type
) {
8974 case CFG80211_SIGNAL_TYPE_MBM
:
8975 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
8976 goto nla_put_failure
;
8978 case CFG80211_SIGNAL_TYPE_UNSPEC
:
8979 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
8980 goto nla_put_failure
;
8986 switch (wdev
->iftype
) {
8987 case NL80211_IFTYPE_P2P_CLIENT
:
8988 case NL80211_IFTYPE_STATION
:
8989 if (intbss
== wdev
->current_bss
&&
8990 nla_put_u32(msg
, NL80211_BSS_STATUS
,
8991 NL80211_BSS_STATUS_ASSOCIATED
))
8992 goto nla_put_failure
;
8994 case NL80211_IFTYPE_ADHOC
:
8995 if (intbss
== wdev
->current_bss
&&
8996 nla_put_u32(msg
, NL80211_BSS_STATUS
,
8997 NL80211_BSS_STATUS_IBSS_JOINED
))
8998 goto nla_put_failure
;
9004 nla_nest_end(msg
, bss
);
9006 genlmsg_end(msg
, hdr
);
9012 genlmsg_cancel(msg
, hdr
);
9016 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
9018 struct cfg80211_registered_device
*rdev
;
9019 struct cfg80211_internal_bss
*scan
;
9020 struct wireless_dev
*wdev
;
9021 int start
= cb
->args
[2], idx
= 0;
9025 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
9032 spin_lock_bh(&rdev
->bss_lock
);
9035 * dump_scan will be called multiple times to break up the scan results
9036 * into multiple messages. It is unlikely that any more bss-es will be
9037 * expired after the first call, so only call only call this on the
9038 * first dump_scan invocation.
9041 cfg80211_bss_expire(rdev
);
9043 cb
->seq
= rdev
->bss_generation
;
9045 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
9048 if (nl80211_send_bss(skb
, cb
,
9049 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
9050 rdev
, wdev
, scan
) < 0) {
9056 spin_unlock_bh(&rdev
->bss_lock
);
9065 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
9066 int flags
, struct net_device
*dev
,
9067 bool allow_radio_stats
,
9068 struct survey_info
*survey
)
9071 struct nlattr
*infoattr
;
9073 /* skip radio stats if userspace didn't request them */
9074 if (!survey
->channel
&& !allow_radio_stats
)
9077 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
9078 NL80211_CMD_NEW_SURVEY_RESULTS
);
9082 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
9083 goto nla_put_failure
;
9085 infoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_SURVEY_INFO
);
9087 goto nla_put_failure
;
9089 if (survey
->channel
&&
9090 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
9091 survey
->channel
->center_freq
))
9092 goto nla_put_failure
;
9094 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
9095 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
9096 goto nla_put_failure
;
9097 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
9098 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
9099 goto nla_put_failure
;
9100 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
9101 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
9102 survey
->time
, NL80211_SURVEY_INFO_PAD
))
9103 goto nla_put_failure
;
9104 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
9105 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
9106 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
9107 goto nla_put_failure
;
9108 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
9109 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
9110 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
9111 goto nla_put_failure
;
9112 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
9113 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
9114 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
9115 goto nla_put_failure
;
9116 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
9117 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
9118 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
9119 goto nla_put_failure
;
9120 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
9121 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
9122 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
9123 goto nla_put_failure
;
9124 if ((survey
->filled
& SURVEY_INFO_TIME_BSS_RX
) &&
9125 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BSS_RX
,
9126 survey
->time_bss_rx
, NL80211_SURVEY_INFO_PAD
))
9127 goto nla_put_failure
;
9129 nla_nest_end(msg
, infoattr
);
9131 genlmsg_end(msg
, hdr
);
9135 genlmsg_cancel(msg
, hdr
);
9139 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
9141 struct nlattr
**attrbuf
;
9142 struct survey_info survey
;
9143 struct cfg80211_registered_device
*rdev
;
9144 struct wireless_dev
*wdev
;
9145 int survey_idx
= cb
->args
[2];
9149 attrbuf
= kcalloc(NUM_NL80211_ATTR
, sizeof(*attrbuf
), GFP_KERNEL
);
9154 res
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
9158 /* prepare_wdev_dump parsed the attributes */
9159 radio_stats
= attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
9161 if (!wdev
->netdev
) {
9166 if (!rdev
->ops
->dump_survey
) {
9172 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
9178 /* don't send disabled channels, but do send non-channel data */
9179 if (survey
.channel
&&
9180 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
9185 if (nl80211_send_survey(skb
,
9186 NETLINK_CB(cb
->skb
).portid
,
9187 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
9188 wdev
->netdev
, radio_stats
, &survey
) < 0)
9194 cb
->args
[2] = survey_idx
;
9202 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
9204 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
9205 NL80211_WPA_VERSION_2
|
9206 NL80211_WPA_VERSION_3
));
9209 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
9211 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9212 struct net_device
*dev
= info
->user_ptr
[1];
9213 struct ieee80211_channel
*chan
;
9214 const u8
*bssid
, *ssid
, *ie
= NULL
, *auth_data
= NULL
;
9215 int err
, ssid_len
, ie_len
= 0, auth_data_len
= 0;
9216 enum nl80211_auth_type auth_type
;
9217 struct key_parse key
;
9218 bool local_state_change
;
9221 if (!info
->attrs
[NL80211_ATTR_MAC
])
9224 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
9227 if (!info
->attrs
[NL80211_ATTR_SSID
])
9230 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9233 err
= nl80211_parse_key(info
, &key
);
9238 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
9240 if (!key
.p
.key
|| !key
.p
.key_len
)
9242 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
9243 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
9244 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
9245 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
9258 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
9259 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
9268 if (!rdev
->ops
->auth
)
9271 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9272 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9275 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9276 freq
= MHZ_TO_KHZ(nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
9277 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
])
9279 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
]);
9281 chan
= nl80211_get_valid_chan(&rdev
->wiphy
, freq
);
9285 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9286 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9288 if (info
->attrs
[NL80211_ATTR_IE
]) {
9289 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9290 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9293 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
9294 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
9297 if ((auth_type
== NL80211_AUTHTYPE_SAE
||
9298 auth_type
== NL80211_AUTHTYPE_FILS_SK
||
9299 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
9300 auth_type
== NL80211_AUTHTYPE_FILS_PK
) &&
9301 !info
->attrs
[NL80211_ATTR_AUTH_DATA
])
9304 if (info
->attrs
[NL80211_ATTR_AUTH_DATA
]) {
9305 if (auth_type
!= NL80211_AUTHTYPE_SAE
&&
9306 auth_type
!= NL80211_AUTHTYPE_FILS_SK
&&
9307 auth_type
!= NL80211_AUTHTYPE_FILS_SK_PFS
&&
9308 auth_type
!= NL80211_AUTHTYPE_FILS_PK
)
9310 auth_data
= nla_data(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
9311 auth_data_len
= nla_len(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
9312 /* need to include at least Auth Transaction and Status Code */
9313 if (auth_data_len
< 4)
9317 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
9320 * Since we no longer track auth state, ignore
9321 * requests to only change local state.
9323 if (local_state_change
)
9326 wdev_lock(dev
->ieee80211_ptr
);
9327 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
9328 ssid
, ssid_len
, ie
, ie_len
,
9329 key
.p
.key
, key
.p
.key_len
, key
.idx
,
9330 auth_data
, auth_data_len
);
9331 wdev_unlock(dev
->ieee80211_ptr
);
9335 static int validate_pae_over_nl80211(struct cfg80211_registered_device
*rdev
,
9336 struct genl_info
*info
)
9338 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9339 GENL_SET_ERR_MSG(info
, "SOCKET_OWNER not set");
9343 if (!rdev
->ops
->tx_control_port
||
9344 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9345 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
9351 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
9352 struct genl_info
*info
,
9353 struct cfg80211_crypto_settings
*settings
,
9356 memset(settings
, 0, sizeof(*settings
));
9358 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
9360 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
9363 proto
= nla_get_u16(
9364 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
9365 settings
->control_port_ethertype
= cpu_to_be16(proto
);
9366 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
9369 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
9370 settings
->control_port_no_encrypt
= true;
9372 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
9374 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
9375 int r
= validate_pae_over_nl80211(rdev
, info
);
9380 settings
->control_port_over_nl80211
= true;
9382 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH
])
9383 settings
->control_port_no_preauth
= true;
9386 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
9390 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
9391 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
9392 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
9394 if (len
% sizeof(u32
))
9397 if (settings
->n_ciphers_pairwise
> cipher_limit
)
9400 memcpy(settings
->ciphers_pairwise
, data
, len
);
9402 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
9403 if (!cfg80211_supported_cipher_suite(
9405 settings
->ciphers_pairwise
[i
]))
9409 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
9410 settings
->cipher_group
=
9411 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
9412 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
9413 settings
->cipher_group
))
9417 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
9418 settings
->wpa_versions
=
9419 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
9420 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
9424 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
9428 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
9429 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
9430 settings
->n_akm_suites
= len
/ sizeof(u32
);
9432 if (len
% sizeof(u32
))
9435 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
9438 memcpy(settings
->akm_suites
, data
, len
);
9441 if (info
->attrs
[NL80211_ATTR_PMK
]) {
9442 if (nla_len(info
->attrs
[NL80211_ATTR_PMK
]) != WLAN_PMK_LEN
)
9444 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
9445 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK
) &&
9446 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9447 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK
))
9449 settings
->psk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
9452 if (info
->attrs
[NL80211_ATTR_SAE_PASSWORD
]) {
9453 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
9454 NL80211_EXT_FEATURE_SAE_OFFLOAD
))
9457 nla_data(info
->attrs
[NL80211_ATTR_SAE_PASSWORD
]);
9458 settings
->sae_pwd_len
=
9459 nla_len(info
->attrs
[NL80211_ATTR_SAE_PASSWORD
]);
9465 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
9467 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9468 struct net_device
*dev
= info
->user_ptr
[1];
9469 struct ieee80211_channel
*chan
;
9470 struct cfg80211_assoc_request req
= {};
9471 const u8
*bssid
, *ssid
;
9472 int err
, ssid_len
= 0;
9475 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
9476 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
9479 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
9480 !info
->attrs
[NL80211_ATTR_SSID
] ||
9481 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9484 if (!rdev
->ops
->assoc
)
9487 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9488 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9491 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9493 freq
= MHZ_TO_KHZ(nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
9494 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
])
9496 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
]);
9497 chan
= nl80211_get_valid_chan(&rdev
->wiphy
, freq
);
9501 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9502 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9504 if (info
->attrs
[NL80211_ATTR_IE
]) {
9505 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9506 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9509 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
9510 enum nl80211_mfp mfp
=
9511 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
9512 if (mfp
== NL80211_MFP_REQUIRED
)
9514 else if (mfp
!= NL80211_MFP_NO
)
9518 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
9519 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
9521 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
9522 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
9524 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9525 memcpy(&req
.ht_capa_mask
,
9526 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
9527 sizeof(req
.ht_capa_mask
));
9529 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
9530 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9532 memcpy(&req
.ht_capa
,
9533 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
9534 sizeof(req
.ht_capa
));
9537 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
9538 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
9540 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
9541 memcpy(&req
.vht_capa_mask
,
9542 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
9543 sizeof(req
.vht_capa_mask
));
9545 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
9546 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
9548 memcpy(&req
.vht_capa
,
9549 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
9550 sizeof(req
.vht_capa
));
9553 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
9554 if (!((rdev
->wiphy
.features
&
9555 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
9556 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
9557 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9558 NL80211_EXT_FEATURE_RRM
))
9560 req
.flags
|= ASSOC_REQ_USE_RRM
;
9563 if (info
->attrs
[NL80211_ATTR_FILS_KEK
]) {
9564 req
.fils_kek
= nla_data(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
9565 req
.fils_kek_len
= nla_len(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
9566 if (!info
->attrs
[NL80211_ATTR_FILS_NONCES
])
9569 nla_data(info
->attrs
[NL80211_ATTR_FILS_NONCES
]);
9572 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
9574 wdev_lock(dev
->ieee80211_ptr
);
9576 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
9577 ssid
, ssid_len
, &req
);
9579 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9580 dev
->ieee80211_ptr
->conn_owner_nlportid
=
9582 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
9586 wdev_unlock(dev
->ieee80211_ptr
);
9592 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
9594 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9595 struct net_device
*dev
= info
->user_ptr
[1];
9596 const u8
*ie
= NULL
, *bssid
;
9597 int ie_len
= 0, err
;
9599 bool local_state_change
;
9601 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
9602 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
9605 if (!info
->attrs
[NL80211_ATTR_MAC
])
9608 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
9611 if (!rdev
->ops
->deauth
)
9614 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9615 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9618 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9620 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
9621 if (reason_code
== 0) {
9622 /* Reason Code 0 is reserved */
9626 if (info
->attrs
[NL80211_ATTR_IE
]) {
9627 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9628 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9631 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
9633 wdev_lock(dev
->ieee80211_ptr
);
9634 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
9635 local_state_change
);
9636 wdev_unlock(dev
->ieee80211_ptr
);
9640 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
9642 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9643 struct net_device
*dev
= info
->user_ptr
[1];
9644 const u8
*ie
= NULL
, *bssid
;
9645 int ie_len
= 0, err
;
9647 bool local_state_change
;
9649 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
9650 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
9653 if (!info
->attrs
[NL80211_ATTR_MAC
])
9656 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
9659 if (!rdev
->ops
->disassoc
)
9662 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9663 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9666 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9668 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
9669 if (reason_code
== 0) {
9670 /* Reason Code 0 is reserved */
9674 if (info
->attrs
[NL80211_ATTR_IE
]) {
9675 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9676 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9679 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
9681 wdev_lock(dev
->ieee80211_ptr
);
9682 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
9683 local_state_change
);
9684 wdev_unlock(dev
->ieee80211_ptr
);
9689 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
9690 int mcast_rate
[NUM_NL80211_BANDS
],
9693 struct wiphy
*wiphy
= &rdev
->wiphy
;
9697 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
9698 struct ieee80211_supported_band
*sband
;
9700 sband
= wiphy
->bands
[band
];
9704 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
9705 if (sband
->bitrates
[i
].bitrate
== rateval
) {
9706 mcast_rate
[band
] = i
+ 1;
9716 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
9718 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9719 struct net_device
*dev
= info
->user_ptr
[1];
9720 struct cfg80211_ibss_params ibss
;
9721 struct wiphy
*wiphy
;
9722 struct cfg80211_cached_keys
*connkeys
= NULL
;
9725 memset(&ibss
, 0, sizeof(ibss
));
9727 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
9728 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
9731 ibss
.beacon_interval
= 100;
9733 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
])
9734 ibss
.beacon_interval
=
9735 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
9737 err
= cfg80211_validate_beacon_int(rdev
, NL80211_IFTYPE_ADHOC
,
9738 ibss
.beacon_interval
);
9742 if (!rdev
->ops
->join_ibss
)
9745 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
9748 wiphy
= &rdev
->wiphy
;
9750 if (info
->attrs
[NL80211_ATTR_MAC
]) {
9751 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9753 if (!is_valid_ether_addr(ibss
.bssid
))
9756 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9757 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9759 if (info
->attrs
[NL80211_ATTR_IE
]) {
9760 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9761 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9764 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
9768 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
9769 NL80211_IFTYPE_ADHOC
))
9772 switch (ibss
.chandef
.width
) {
9773 case NL80211_CHAN_WIDTH_5
:
9774 case NL80211_CHAN_WIDTH_10
:
9775 case NL80211_CHAN_WIDTH_20_NOHT
:
9777 case NL80211_CHAN_WIDTH_20
:
9778 case NL80211_CHAN_WIDTH_40
:
9779 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
9782 case NL80211_CHAN_WIDTH_80
:
9783 case NL80211_CHAN_WIDTH_80P80
:
9784 case NL80211_CHAN_WIDTH_160
:
9785 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
9787 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
9788 NL80211_EXT_FEATURE_VHT_IBSS
))
9795 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
9796 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
9798 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
9800 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9802 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9803 struct ieee80211_supported_band
*sband
=
9804 wiphy
->bands
[ibss
.chandef
.chan
->band
];
9806 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
9812 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9813 memcpy(&ibss
.ht_capa_mask
,
9814 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
9815 sizeof(ibss
.ht_capa_mask
));
9817 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
9818 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9820 memcpy(&ibss
.ht_capa
,
9821 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
9822 sizeof(ibss
.ht_capa
));
9825 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
9826 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
9827 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
9830 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
9833 connkeys
= nl80211_parse_connkeys(rdev
, info
, &no_ht
);
9834 if (IS_ERR(connkeys
))
9835 return PTR_ERR(connkeys
);
9837 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
9839 kfree_sensitive(connkeys
);
9845 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
9847 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
9848 int r
= validate_pae_over_nl80211(rdev
, info
);
9851 kfree_sensitive(connkeys
);
9855 ibss
.control_port_over_nl80211
= true;
9858 ibss
.userspace_handles_dfs
=
9859 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
9861 wdev_lock(dev
->ieee80211_ptr
);
9862 err
= __cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
9864 kfree_sensitive(connkeys
);
9865 else if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
9866 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
9867 wdev_unlock(dev
->ieee80211_ptr
);
9872 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
9874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9875 struct net_device
*dev
= info
->user_ptr
[1];
9877 if (!rdev
->ops
->leave_ibss
)
9880 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
9883 return cfg80211_leave_ibss(rdev
, dev
, false);
9886 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
9888 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9889 struct net_device
*dev
= info
->user_ptr
[1];
9890 int mcast_rate
[NUM_NL80211_BANDS
];
9894 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
9895 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
9896 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
9899 if (!rdev
->ops
->set_mcast_rate
)
9902 memset(mcast_rate
, 0, sizeof(mcast_rate
));
9904 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
9907 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
9908 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
9911 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
9916 static struct sk_buff
*
9917 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
9918 struct wireless_dev
*wdev
, int approxlen
,
9919 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
9920 enum nl80211_attrs attr
,
9921 const struct nl80211_vendor_cmd_info
*info
,
9924 struct sk_buff
*skb
;
9926 struct nlattr
*data
;
9928 skb
= nlmsg_new(approxlen
+ 100, gfp
);
9932 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
9938 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
9939 goto nla_put_failure
;
9942 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
9944 goto nla_put_failure
;
9945 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
9947 goto nla_put_failure
;
9951 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
9952 wdev_id(wdev
), NL80211_ATTR_PAD
))
9953 goto nla_put_failure
;
9955 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
9956 wdev
->netdev
->ifindex
))
9957 goto nla_put_failure
;
9960 data
= nla_nest_start_noflag(skb
, attr
);
9962 goto nla_put_failure
;
9964 ((void **)skb
->cb
)[0] = rdev
;
9965 ((void **)skb
->cb
)[1] = hdr
;
9966 ((void **)skb
->cb
)[2] = data
;
9975 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
9976 struct wireless_dev
*wdev
,
9977 enum nl80211_commands cmd
,
9978 enum nl80211_attrs attr
,
9979 unsigned int portid
,
9980 int vendor_event_idx
,
9981 int approxlen
, gfp_t gfp
)
9983 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
9984 const struct nl80211_vendor_cmd_info
*info
;
9987 case NL80211_CMD_TESTMODE
:
9988 if (WARN_ON(vendor_event_idx
!= -1))
9992 case NL80211_CMD_VENDOR
:
9993 if (WARN_ON(vendor_event_idx
< 0 ||
9994 vendor_event_idx
>= wiphy
->n_vendor_events
))
9996 info
= &wiphy
->vendor_events
[vendor_event_idx
];
10003 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, portid
, 0,
10004 cmd
, attr
, info
, gfp
);
10006 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
10008 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
10010 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
10011 void *hdr
= ((void **)skb
->cb
)[1];
10012 struct nlmsghdr
*nlhdr
= nlmsg_hdr(skb
);
10013 struct nlattr
*data
= ((void **)skb
->cb
)[2];
10014 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
10016 /* clear CB data for netlink core to own from now on */
10017 memset(skb
->cb
, 0, sizeof(skb
->cb
));
10019 nla_nest_end(skb
, data
);
10020 genlmsg_end(skb
, hdr
);
10022 if (nlhdr
->nlmsg_pid
) {
10023 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), skb
,
10026 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
10027 mcgrp
= NL80211_MCGRP_VENDOR
;
10029 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
10030 skb
, 0, mcgrp
, gfp
);
10033 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
10035 #ifdef CONFIG_NL80211_TESTMODE
10036 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
10038 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10039 struct wireless_dev
*wdev
=
10040 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
10043 if (!rdev
->ops
->testmode_cmd
)
10044 return -EOPNOTSUPP
;
10046 if (IS_ERR(wdev
)) {
10047 err
= PTR_ERR(wdev
);
10048 if (err
!= -EINVAL
)
10051 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
10055 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
10058 rdev
->cur_cmd_info
= info
;
10059 err
= rdev_testmode_cmd(rdev
, wdev
,
10060 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
10061 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
10062 rdev
->cur_cmd_info
= NULL
;
10067 static int nl80211_testmode_dump(struct sk_buff
*skb
,
10068 struct netlink_callback
*cb
)
10070 struct cfg80211_registered_device
*rdev
;
10071 struct nlattr
**attrbuf
= NULL
;
10081 * 0 is a valid index, but not valid for args[0],
10082 * so we need to offset by 1.
10084 phy_idx
= cb
->args
[0] - 1;
10086 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
10092 attrbuf
= kcalloc(NUM_NL80211_ATTR
, sizeof(*attrbuf
),
10099 err
= nlmsg_parse_deprecated(cb
->nlh
,
10100 GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
10101 attrbuf
, nl80211_fam
.maxattr
,
10102 nl80211_policy
, NULL
);
10106 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
10107 if (IS_ERR(rdev
)) {
10108 err
= PTR_ERR(rdev
);
10111 phy_idx
= rdev
->wiphy_idx
;
10113 if (attrbuf
[NL80211_ATTR_TESTDATA
])
10114 cb
->args
[1] = (long)attrbuf
[NL80211_ATTR_TESTDATA
];
10118 data
= nla_data((void *)cb
->args
[1]);
10119 data_len
= nla_len((void *)cb
->args
[1]);
10122 if (!rdev
->ops
->testmode_dump
) {
10128 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
10129 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
10130 NL80211_CMD_TESTMODE
);
10131 struct nlattr
*tmdata
;
10136 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
10137 genlmsg_cancel(skb
, hdr
);
10141 tmdata
= nla_nest_start_noflag(skb
, NL80211_ATTR_TESTDATA
);
10143 genlmsg_cancel(skb
, hdr
);
10146 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
10147 nla_nest_end(skb
, tmdata
);
10149 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
10150 genlmsg_cancel(skb
, hdr
);
10153 genlmsg_cancel(skb
, hdr
);
10157 genlmsg_end(skb
, hdr
);
10162 cb
->args
[0] = phy_idx
+ 1;
10170 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
10172 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10173 struct net_device
*dev
= info
->user_ptr
[1];
10174 struct cfg80211_connect_params connect
;
10175 struct wiphy
*wiphy
;
10176 struct cfg80211_cached_keys
*connkeys
= NULL
;
10180 memset(&connect
, 0, sizeof(connect
));
10182 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
10183 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
10186 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
10187 connect
.auth_type
=
10188 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
10189 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
10190 NL80211_CMD_CONNECT
))
10193 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
10195 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
10197 if (info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
] &&
10198 !wiphy_ext_feature_isset(&rdev
->wiphy
,
10199 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
10201 connect
.want_1x
= info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
];
10203 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
10204 NL80211_MAX_NR_CIPHER_SUITES
);
10208 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10209 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10210 return -EOPNOTSUPP
;
10212 wiphy
= &rdev
->wiphy
;
10214 connect
.bg_scan_period
= -1;
10215 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
10216 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
10217 connect
.bg_scan_period
=
10218 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
10221 if (info
->attrs
[NL80211_ATTR_MAC
])
10222 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10223 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
10224 connect
.bssid_hint
=
10225 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
10226 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
10227 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
10229 if (info
->attrs
[NL80211_ATTR_IE
]) {
10230 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10231 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10234 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
10235 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
10236 if (connect
.mfp
== NL80211_MFP_OPTIONAL
&&
10237 !wiphy_ext_feature_isset(&rdev
->wiphy
,
10238 NL80211_EXT_FEATURE_MFP_OPTIONAL
))
10239 return -EOPNOTSUPP
;
10241 connect
.mfp
= NL80211_MFP_NO
;
10244 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
10245 connect
.prev_bssid
=
10246 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
10248 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
10249 freq
= MHZ_TO_KHZ(nla_get_u32(
10250 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
10251 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
])
10253 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
]);
10256 connect
.channel
= nl80211_get_valid_chan(wiphy
, freq
);
10257 if (!connect
.channel
)
10259 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
10260 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
10261 freq
= MHZ_TO_KHZ(freq
);
10262 connect
.channel_hint
= nl80211_get_valid_chan(wiphy
, freq
);
10263 if (!connect
.channel_hint
)
10267 if (info
->attrs
[NL80211_ATTR_WIPHY_EDMG_CHANNELS
]) {
10268 connect
.edmg
.channels
=
10269 nla_get_u8(info
->attrs
[NL80211_ATTR_WIPHY_EDMG_CHANNELS
]);
10271 if (info
->attrs
[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
])
10272 connect
.edmg
.bw_config
=
10273 nla_get_u8(info
->attrs
[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
]);
10276 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
10277 connkeys
= nl80211_parse_connkeys(rdev
, info
, NULL
);
10278 if (IS_ERR(connkeys
))
10279 return PTR_ERR(connkeys
);
10282 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
10283 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
10285 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
10286 memcpy(&connect
.ht_capa_mask
,
10287 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
10288 sizeof(connect
.ht_capa_mask
));
10290 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
10291 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
10292 kfree_sensitive(connkeys
);
10295 memcpy(&connect
.ht_capa
,
10296 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
10297 sizeof(connect
.ht_capa
));
10300 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
10301 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
10303 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
10304 memcpy(&connect
.vht_capa_mask
,
10305 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
10306 sizeof(connect
.vht_capa_mask
));
10308 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
10309 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
10310 kfree_sensitive(connkeys
);
10313 memcpy(&connect
.vht_capa
,
10314 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
10315 sizeof(connect
.vht_capa
));
10318 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
10319 if (!((rdev
->wiphy
.features
&
10320 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
10321 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
10322 !wiphy_ext_feature_isset(&rdev
->wiphy
,
10323 NL80211_EXT_FEATURE_RRM
)) {
10324 kfree_sensitive(connkeys
);
10327 connect
.flags
|= ASSOC_REQ_USE_RRM
;
10330 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
10331 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
10332 kfree_sensitive(connkeys
);
10333 return -EOPNOTSUPP
;
10336 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
10337 /* bss selection makes no sense if bssid is set */
10338 if (connect
.bssid
) {
10339 kfree_sensitive(connkeys
);
10343 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
10344 wiphy
, &connect
.bss_select
);
10346 kfree_sensitive(connkeys
);
10351 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
10352 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
10353 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
10354 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
10355 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
10356 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10357 connect
.fils_erp_username
=
10358 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10359 connect
.fils_erp_username_len
=
10360 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10361 connect
.fils_erp_realm
=
10362 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10363 connect
.fils_erp_realm_len
=
10364 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10365 connect
.fils_erp_next_seq_num
=
10367 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
10368 connect
.fils_erp_rrk
=
10369 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10370 connect
.fils_erp_rrk_len
=
10371 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10372 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
10373 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
10374 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
10375 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10376 kfree_sensitive(connkeys
);
10380 if (nla_get_flag(info
->attrs
[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
])) {
10381 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
10382 kfree_sensitive(connkeys
);
10383 GENL_SET_ERR_MSG(info
,
10384 "external auth requires connection ownership");
10387 connect
.flags
|= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT
;
10390 wdev_lock(dev
->ieee80211_ptr
);
10392 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
10393 connect
.prev_bssid
);
10395 kfree_sensitive(connkeys
);
10397 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
10398 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
10400 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
10401 connect
.bssid
, ETH_ALEN
);
10403 eth_zero_addr(dev
->ieee80211_ptr
->disconnect_bssid
);
10406 wdev_unlock(dev
->ieee80211_ptr
);
10411 static int nl80211_update_connect_params(struct sk_buff
*skb
,
10412 struct genl_info
*info
)
10414 struct cfg80211_connect_params connect
= {};
10415 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10416 struct net_device
*dev
= info
->user_ptr
[1];
10417 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10418 bool fils_sk_offload
;
10423 if (!rdev
->ops
->update_connect_params
)
10424 return -EOPNOTSUPP
;
10426 if (info
->attrs
[NL80211_ATTR_IE
]) {
10427 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10428 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10429 changed
|= UPDATE_ASSOC_IES
;
10432 fils_sk_offload
= wiphy_ext_feature_isset(&rdev
->wiphy
,
10433 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
);
10436 * when driver supports fils-sk offload all attributes must be
10437 * provided. So the else covers "fils-sk-not-all" and
10438 * "no-fils-sk-any".
10440 if (fils_sk_offload
&&
10441 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
10442 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
10443 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
10444 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10445 connect
.fils_erp_username
=
10446 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10447 connect
.fils_erp_username_len
=
10448 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10449 connect
.fils_erp_realm
=
10450 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10451 connect
.fils_erp_realm_len
=
10452 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10453 connect
.fils_erp_next_seq_num
=
10455 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
10456 connect
.fils_erp_rrk
=
10457 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10458 connect
.fils_erp_rrk_len
=
10459 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10460 changed
|= UPDATE_FILS_ERP_INFO
;
10461 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
10462 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
10463 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
10464 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10468 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
10469 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
10470 if (!nl80211_valid_auth_type(rdev
, auth_type
,
10471 NL80211_CMD_CONNECT
))
10474 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
&&
10475 fils_sk_offload
&& !(changed
& UPDATE_FILS_ERP_INFO
))
10478 connect
.auth_type
= auth_type
;
10479 changed
|= UPDATE_AUTH_TYPE
;
10482 wdev_lock(dev
->ieee80211_ptr
);
10483 if (!wdev
->current_bss
)
10486 ret
= rdev_update_connect_params(rdev
, dev
, &connect
, changed
);
10487 wdev_unlock(dev
->ieee80211_ptr
);
10492 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
10494 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10495 struct net_device
*dev
= info
->user_ptr
[1];
10499 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
10500 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
10503 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
10504 reason
= WLAN_REASON_DEAUTH_LEAVING
;
10506 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
10511 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10512 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10513 return -EOPNOTSUPP
;
10515 wdev_lock(dev
->ieee80211_ptr
);
10516 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
10517 wdev_unlock(dev
->ieee80211_ptr
);
10521 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
10523 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10527 if (info
->attrs
[NL80211_ATTR_PID
]) {
10528 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
10530 net
= get_net_ns_by_pid(pid
);
10531 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
10532 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
10534 net
= get_net_ns_by_fd(fd
);
10540 return PTR_ERR(net
);
10544 /* check if anything to do */
10545 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
10546 err
= cfg80211_switch_netns(rdev
, net
);
10552 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
10554 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10555 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
10556 struct cfg80211_pmksa
*pmksa
) = NULL
;
10557 struct net_device
*dev
= info
->user_ptr
[1];
10558 struct cfg80211_pmksa pmksa
;
10560 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
10562 if (!info
->attrs
[NL80211_ATTR_PMKID
])
10565 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
10567 if (info
->attrs
[NL80211_ATTR_MAC
]) {
10568 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10569 } else if (info
->attrs
[NL80211_ATTR_SSID
] &&
10570 info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
] &&
10571 (info
->genlhdr
->cmd
== NL80211_CMD_DEL_PMKSA
||
10572 info
->attrs
[NL80211_ATTR_PMK
])) {
10573 pmksa
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
10574 pmksa
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
10576 nla_data(info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
]);
10580 if (info
->attrs
[NL80211_ATTR_PMK
]) {
10581 pmksa
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
10582 pmksa
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
10585 if (info
->attrs
[NL80211_ATTR_PMK_LIFETIME
])
10586 pmksa
.pmk_lifetime
=
10587 nla_get_u32(info
->attrs
[NL80211_ATTR_PMK_LIFETIME
]);
10589 if (info
->attrs
[NL80211_ATTR_PMK_REAUTH_THRESHOLD
])
10590 pmksa
.pmk_reauth_threshold
=
10592 info
->attrs
[NL80211_ATTR_PMK_REAUTH_THRESHOLD
]);
10594 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10595 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
10596 !(dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_AP
&&
10597 wiphy_ext_feature_isset(&rdev
->wiphy
,
10598 NL80211_EXT_FEATURE_AP_PMKSA_CACHING
)))
10599 return -EOPNOTSUPP
;
10601 switch (info
->genlhdr
->cmd
) {
10602 case NL80211_CMD_SET_PMKSA
:
10603 rdev_ops
= rdev
->ops
->set_pmksa
;
10605 case NL80211_CMD_DEL_PMKSA
:
10606 rdev_ops
= rdev
->ops
->del_pmksa
;
10614 return -EOPNOTSUPP
;
10616 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
10619 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
10621 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10622 struct net_device
*dev
= info
->user_ptr
[1];
10624 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10625 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10626 return -EOPNOTSUPP
;
10628 if (!rdev
->ops
->flush_pmksa
)
10629 return -EOPNOTSUPP
;
10631 return rdev_flush_pmksa(rdev
, dev
);
10634 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
10636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10637 struct net_device
*dev
= info
->user_ptr
[1];
10638 u8 action_code
, dialog_token
;
10639 u32 peer_capability
= 0;
10644 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
10645 !rdev
->ops
->tdls_mgmt
)
10646 return -EOPNOTSUPP
;
10648 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
10649 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
10650 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
10651 !info
->attrs
[NL80211_ATTR_IE
] ||
10652 !info
->attrs
[NL80211_ATTR_MAC
])
10655 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10656 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
10657 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
10658 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
10659 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
10660 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
10662 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
10664 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
10665 dialog_token
, status_code
, peer_capability
,
10667 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
10668 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
10671 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
10673 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10674 struct net_device
*dev
= info
->user_ptr
[1];
10675 enum nl80211_tdls_operation operation
;
10678 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
10679 !rdev
->ops
->tdls_oper
)
10680 return -EOPNOTSUPP
;
10682 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
10683 !info
->attrs
[NL80211_ATTR_MAC
])
10686 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
10687 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10689 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
10692 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
10693 struct genl_info
*info
)
10695 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10696 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10697 struct cfg80211_chan_def chandef
;
10698 const struct cfg80211_chan_def
*compat_chandef
;
10699 struct sk_buff
*msg
;
10705 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
10706 !info
->attrs
[NL80211_ATTR_DURATION
])
10709 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
10711 if (!rdev
->ops
->remain_on_channel
||
10712 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
10713 return -EOPNOTSUPP
;
10716 * We should be on that channel for at least a minimum amount of
10717 * time (10ms) but no longer than the driver supports.
10719 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
10720 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
10723 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
10728 if (!cfg80211_off_channel_oper_allowed(wdev
) &&
10729 !cfg80211_chandef_identical(&wdev
->chandef
, &chandef
)) {
10730 compat_chandef
= cfg80211_chandef_compatible(&wdev
->chandef
,
10732 if (compat_chandef
!= &chandef
) {
10739 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10743 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10744 NL80211_CMD_REMAIN_ON_CHANNEL
);
10750 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
10751 duration
, &cookie
);
10756 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
10758 goto nla_put_failure
;
10760 genlmsg_end(msg
, hdr
);
10762 return genlmsg_reply(msg
, info
);
10771 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
10772 struct genl_info
*info
)
10774 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10775 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10778 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
10781 if (!rdev
->ops
->cancel_remain_on_channel
)
10782 return -EOPNOTSUPP
;
10784 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
10786 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
10789 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
10790 struct genl_info
*info
)
10792 struct cfg80211_bitrate_mask mask
;
10793 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10794 struct net_device
*dev
= info
->user_ptr
[1];
10797 if (!rdev
->ops
->set_bitrate_mask
)
10798 return -EOPNOTSUPP
;
10800 err
= nl80211_parse_tx_bitrate_mask(info
, info
->attrs
,
10801 NL80211_ATTR_TX_RATES
, &mask
);
10805 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
10808 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
10810 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10811 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10812 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
10814 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
10817 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
10818 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
10820 switch (wdev
->iftype
) {
10821 case NL80211_IFTYPE_STATION
:
10822 case NL80211_IFTYPE_ADHOC
:
10823 case NL80211_IFTYPE_P2P_CLIENT
:
10824 case NL80211_IFTYPE_AP
:
10825 case NL80211_IFTYPE_AP_VLAN
:
10826 case NL80211_IFTYPE_MESH_POINT
:
10827 case NL80211_IFTYPE_P2P_GO
:
10828 case NL80211_IFTYPE_P2P_DEVICE
:
10830 case NL80211_IFTYPE_NAN
:
10832 return -EOPNOTSUPP
;
10835 /* not much point in registering if we can't reply */
10836 if (!rdev
->ops
->mgmt_tx
)
10837 return -EOPNOTSUPP
;
10839 if (info
->attrs
[NL80211_ATTR_RECEIVE_MULTICAST
] &&
10840 !wiphy_ext_feature_isset(&rdev
->wiphy
,
10841 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS
)) {
10842 GENL_SET_ERR_MSG(info
,
10843 "multicast RX registrations are not supported");
10844 return -EOPNOTSUPP
;
10847 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
10848 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
10849 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
10850 info
->attrs
[NL80211_ATTR_RECEIVE_MULTICAST
],
10854 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
10856 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10857 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10858 struct cfg80211_chan_def chandef
;
10862 struct sk_buff
*msg
= NULL
;
10863 struct cfg80211_mgmt_tx_params params
= {
10864 .dont_wait_for_ack
=
10865 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
10868 if (!info
->attrs
[NL80211_ATTR_FRAME
])
10871 if (!rdev
->ops
->mgmt_tx
)
10872 return -EOPNOTSUPP
;
10874 switch (wdev
->iftype
) {
10875 case NL80211_IFTYPE_P2P_DEVICE
:
10876 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
10878 case NL80211_IFTYPE_STATION
:
10879 case NL80211_IFTYPE_ADHOC
:
10880 case NL80211_IFTYPE_P2P_CLIENT
:
10881 case NL80211_IFTYPE_AP
:
10882 case NL80211_IFTYPE_AP_VLAN
:
10883 case NL80211_IFTYPE_MESH_POINT
:
10884 case NL80211_IFTYPE_P2P_GO
:
10886 case NL80211_IFTYPE_NAN
:
10888 return -EOPNOTSUPP
;
10891 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
10892 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
10894 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
10897 * We should wait on the channel for at least a minimum amount
10898 * of time (10ms) but no longer than the driver supports.
10900 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
10901 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
10905 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
10907 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
10910 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
10912 /* get the channel if any has been specified, otherwise pass NULL to
10913 * the driver. The latter will use the current one
10915 chandef
.chan
= NULL
;
10916 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
10917 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
10922 if (!chandef
.chan
&& params
.offchan
)
10926 if (params
.offchan
&& !cfg80211_off_channel_oper_allowed(wdev
)) {
10932 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
10933 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
10935 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
10936 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
10939 if (len
% sizeof(u16
))
10942 params
.n_csa_offsets
= len
/ sizeof(u16
);
10943 params
.csa_offsets
=
10944 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
10946 /* check that all the offsets fit the frame */
10947 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
10948 if (params
.csa_offsets
[i
] >= params
.len
)
10953 if (!params
.dont_wait_for_ack
) {
10954 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10958 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10959 NL80211_CMD_FRAME
);
10966 params
.chan
= chandef
.chan
;
10967 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
10972 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
10974 goto nla_put_failure
;
10976 genlmsg_end(msg
, hdr
);
10977 return genlmsg_reply(msg
, info
);
10989 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
10991 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10992 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10995 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
10998 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
10999 return -EOPNOTSUPP
;
11001 switch (wdev
->iftype
) {
11002 case NL80211_IFTYPE_STATION
:
11003 case NL80211_IFTYPE_ADHOC
:
11004 case NL80211_IFTYPE_P2P_CLIENT
:
11005 case NL80211_IFTYPE_AP
:
11006 case NL80211_IFTYPE_AP_VLAN
:
11007 case NL80211_IFTYPE_P2P_GO
:
11008 case NL80211_IFTYPE_P2P_DEVICE
:
11010 case NL80211_IFTYPE_NAN
:
11012 return -EOPNOTSUPP
;
11015 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
11017 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
11020 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
11022 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11023 struct wireless_dev
*wdev
;
11024 struct net_device
*dev
= info
->user_ptr
[1];
11029 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
11032 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
11034 wdev
= dev
->ieee80211_ptr
;
11036 if (!rdev
->ops
->set_power_mgmt
)
11037 return -EOPNOTSUPP
;
11039 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
11041 if (state
== wdev
->ps
)
11044 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
11050 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
11052 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11053 enum nl80211_ps_state ps_state
;
11054 struct wireless_dev
*wdev
;
11055 struct net_device
*dev
= info
->user_ptr
[1];
11056 struct sk_buff
*msg
;
11060 wdev
= dev
->ieee80211_ptr
;
11062 if (!rdev
->ops
->set_power_mgmt
)
11063 return -EOPNOTSUPP
;
11065 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11069 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11070 NL80211_CMD_GET_POWER_SAVE
);
11077 ps_state
= NL80211_PS_ENABLED
;
11079 ps_state
= NL80211_PS_DISABLED
;
11081 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
11082 goto nla_put_failure
;
11084 genlmsg_end(msg
, hdr
);
11085 return genlmsg_reply(msg
, info
);
11094 static const struct nla_policy
11095 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
11096 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_BINARY
},
11097 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
11098 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
11099 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
11100 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
11101 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
11102 [NL80211_ATTR_CQM_RSSI_LEVEL
] = { .type
= NLA_S32
},
11105 static int nl80211_set_cqm_txe(struct genl_info
*info
,
11106 u32 rate
, u32 pkts
, u32 intvl
)
11108 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11109 struct net_device
*dev
= info
->user_ptr
[1];
11110 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11112 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
11115 if (!rdev
->ops
->set_cqm_txe_config
)
11116 return -EOPNOTSUPP
;
11118 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
11119 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
11120 return -EOPNOTSUPP
;
11122 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
11125 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device
*rdev
,
11126 struct net_device
*dev
)
11128 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11129 s32 last
, low
, high
;
11131 int i
, n
, low_index
;
11134 /* RSSI reporting disabled? */
11135 if (!wdev
->cqm_config
)
11136 return rdev_set_cqm_rssi_range_config(rdev
, dev
, 0, 0);
11139 * Obtain current RSSI value if possible, if not and no RSSI threshold
11140 * event has been received yet, we should receive an event after a
11141 * connection is established and enough beacons received to calculate
11144 if (!wdev
->cqm_config
->last_rssi_event_value
&& wdev
->current_bss
&&
11145 rdev
->ops
->get_station
) {
11146 struct station_info sinfo
= {};
11149 mac_addr
= wdev
->current_bss
->pub
.bssid
;
11151 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
11155 cfg80211_sinfo_release_content(&sinfo
);
11156 if (sinfo
.filled
& BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG
))
11157 wdev
->cqm_config
->last_rssi_event_value
=
11158 (s8
) sinfo
.rx_beacon_signal_avg
;
11161 last
= wdev
->cqm_config
->last_rssi_event_value
;
11162 hyst
= wdev
->cqm_config
->rssi_hyst
;
11163 n
= wdev
->cqm_config
->n_rssi_thresholds
;
11165 for (i
= 0; i
< n
; i
++) {
11166 i
= array_index_nospec(i
, n
);
11167 if (last
< wdev
->cqm_config
->rssi_thresholds
[i
])
11172 if (low_index
>= 0) {
11173 low_index
= array_index_nospec(low_index
, n
);
11174 low
= wdev
->cqm_config
->rssi_thresholds
[low_index
] - hyst
;
11179 i
= array_index_nospec(i
, n
);
11180 high
= wdev
->cqm_config
->rssi_thresholds
[i
] + hyst
- 1;
11185 return rdev_set_cqm_rssi_range_config(rdev
, dev
, low
, high
);
11188 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
11189 const s32
*thresholds
, int n_thresholds
,
11192 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11193 struct net_device
*dev
= info
->user_ptr
[1];
11194 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11196 s32 prev
= S32_MIN
;
11198 /* Check all values negative and sorted */
11199 for (i
= 0; i
< n_thresholds
; i
++) {
11200 if (thresholds
[i
] > 0 || thresholds
[i
] <= prev
)
11203 prev
= thresholds
[i
];
11206 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
11207 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
11208 return -EOPNOTSUPP
;
11211 cfg80211_cqm_config_free(wdev
);
11214 if (n_thresholds
<= 1 && rdev
->ops
->set_cqm_rssi_config
) {
11215 if (n_thresholds
== 0 || thresholds
[0] == 0) /* Disabling */
11216 return rdev_set_cqm_rssi_config(rdev
, dev
, 0, 0);
11218 return rdev_set_cqm_rssi_config(rdev
, dev
,
11219 thresholds
[0], hysteresis
);
11222 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
11223 NL80211_EXT_FEATURE_CQM_RSSI_LIST
))
11224 return -EOPNOTSUPP
;
11226 if (n_thresholds
== 1 && thresholds
[0] == 0) /* Disabling */
11230 if (n_thresholds
) {
11231 struct cfg80211_cqm_config
*cqm_config
;
11233 cqm_config
= kzalloc(sizeof(struct cfg80211_cqm_config
) +
11234 n_thresholds
* sizeof(s32
), GFP_KERNEL
);
11240 cqm_config
->rssi_hyst
= hysteresis
;
11241 cqm_config
->n_rssi_thresholds
= n_thresholds
;
11242 memcpy(cqm_config
->rssi_thresholds
, thresholds
,
11243 n_thresholds
* sizeof(s32
));
11245 wdev
->cqm_config
= cqm_config
;
11248 err
= cfg80211_cqm_rssi_update(rdev
, dev
);
11256 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
11258 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
11259 struct nlattr
*cqm
;
11262 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
11266 err
= nla_parse_nested_deprecated(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
11267 nl80211_attr_cqm_policy
,
11272 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
11273 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
11274 const s32
*thresholds
=
11275 nla_data(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
11276 int len
= nla_len(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
11277 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
11282 return nl80211_set_cqm_rssi(info
, thresholds
, len
/ 4,
11286 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
11287 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
11288 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
11289 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
11290 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
11291 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
11293 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
11299 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
11301 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11302 struct net_device
*dev
= info
->user_ptr
[1];
11303 struct ocb_setup setup
= {};
11306 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
11310 return cfg80211_join_ocb(rdev
, dev
, &setup
);
11313 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
11315 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11316 struct net_device
*dev
= info
->user_ptr
[1];
11318 return cfg80211_leave_ocb(rdev
, dev
);
11321 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
11323 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11324 struct net_device
*dev
= info
->user_ptr
[1];
11325 struct mesh_config cfg
;
11326 struct mesh_setup setup
;
11329 /* start with default */
11330 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
11331 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
11333 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
11334 /* and parse parameters if given */
11335 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
11340 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
11341 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
11344 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
11345 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
11347 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
11348 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
11349 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
11352 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
11353 setup
.beacon_interval
=
11354 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
11356 err
= cfg80211_validate_beacon_int(rdev
,
11357 NL80211_IFTYPE_MESH_POINT
,
11358 setup
.beacon_interval
);
11363 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
11364 setup
.dtim_period
=
11365 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
11366 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
11370 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
11371 /* parse additional setup parameters if given */
11372 err
= nl80211_parse_mesh_setup(info
, &setup
);
11377 if (setup
.user_mpm
)
11378 cfg
.auto_open_plinks
= false;
11380 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
11381 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
11385 /* __cfg80211_join_mesh() will sort it out */
11386 setup
.chandef
.chan
= NULL
;
11389 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
11390 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
11392 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
11393 struct ieee80211_supported_band
*sband
;
11395 if (!setup
.chandef
.chan
)
11398 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
11400 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
11401 &setup
.basic_rates
);
11406 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
11407 err
= nl80211_parse_tx_bitrate_mask(info
, info
->attrs
,
11408 NL80211_ATTR_TX_RATES
,
11409 &setup
.beacon_rate
);
11413 if (!setup
.chandef
.chan
)
11416 err
= validate_beacon_tx_rate(rdev
, setup
.chandef
.chan
->band
,
11417 &setup
.beacon_rate
);
11422 setup
.userspace_handles_dfs
=
11423 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
11425 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
11426 int r
= validate_pae_over_nl80211(rdev
, info
);
11431 setup
.control_port_over_nl80211
= true;
11434 wdev_lock(dev
->ieee80211_ptr
);
11435 err
= __cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
11436 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
11437 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
11438 wdev_unlock(dev
->ieee80211_ptr
);
11443 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
11445 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11446 struct net_device
*dev
= info
->user_ptr
[1];
11448 return cfg80211_leave_mesh(rdev
, dev
);
11452 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
11453 struct cfg80211_registered_device
*rdev
)
11455 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
11456 struct nlattr
*nl_pats
, *nl_pat
;
11459 if (!wowlan
->n_patterns
)
11462 nl_pats
= nla_nest_start_noflag(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
11466 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
11467 nl_pat
= nla_nest_start_noflag(msg
, i
+ 1);
11470 pat_len
= wowlan
->patterns
[i
].pattern_len
;
11471 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
11472 wowlan
->patterns
[i
].mask
) ||
11473 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
11474 wowlan
->patterns
[i
].pattern
) ||
11475 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
11476 wowlan
->patterns
[i
].pkt_offset
))
11478 nla_nest_end(msg
, nl_pat
);
11480 nla_nest_end(msg
, nl_pats
);
11485 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
11486 struct cfg80211_wowlan_tcp
*tcp
)
11488 struct nlattr
*nl_tcp
;
11493 nl_tcp
= nla_nest_start_noflag(msg
,
11494 NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
11498 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
11499 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
11500 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
11501 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
11502 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
11503 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
11504 tcp
->payload_len
, tcp
->payload
) ||
11505 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
11506 tcp
->data_interval
) ||
11507 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
11508 tcp
->wake_len
, tcp
->wake_data
) ||
11509 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
11510 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
11513 if (tcp
->payload_seq
.len
&&
11514 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
11515 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
11518 if (tcp
->payload_tok
.len
&&
11519 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
11520 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
11521 &tcp
->payload_tok
))
11524 nla_nest_end(msg
, nl_tcp
);
11529 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
11530 struct cfg80211_sched_scan_request
*req
)
11532 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
11538 nd
= nla_nest_start_noflag(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
11542 if (req
->n_scan_plans
== 1 &&
11543 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
11544 req
->scan_plans
[0].interval
* 1000))
11547 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
11550 if (req
->relative_rssi_set
) {
11551 struct nl80211_bss_select_rssi_adjust rssi_adjust
;
11553 if (nla_put_s8(msg
, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
,
11554 req
->relative_rssi
))
11557 rssi_adjust
.band
= req
->rssi_adjust
.band
;
11558 rssi_adjust
.delta
= req
->rssi_adjust
.delta
;
11559 if (nla_put(msg
, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
,
11560 sizeof(rssi_adjust
), &rssi_adjust
))
11564 freqs
= nla_nest_start_noflag(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
11568 for (i
= 0; i
< req
->n_channels
; i
++) {
11569 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
11573 nla_nest_end(msg
, freqs
);
11575 if (req
->n_match_sets
) {
11576 matches
= nla_nest_start_noflag(msg
,
11577 NL80211_ATTR_SCHED_SCAN_MATCH
);
11581 for (i
= 0; i
< req
->n_match_sets
; i
++) {
11582 match
= nla_nest_start_noflag(msg
, i
);
11586 if (nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
11587 req
->match_sets
[i
].ssid
.ssid_len
,
11588 req
->match_sets
[i
].ssid
.ssid
))
11590 nla_nest_end(msg
, match
);
11592 nla_nest_end(msg
, matches
);
11595 scan_plans
= nla_nest_start_noflag(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
11599 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
11600 scan_plan
= nla_nest_start_noflag(msg
, i
+ 1);
11604 if (nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
11605 req
->scan_plans
[i
].interval
) ||
11606 (req
->scan_plans
[i
].iterations
&&
11607 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
11608 req
->scan_plans
[i
].iterations
)))
11610 nla_nest_end(msg
, scan_plan
);
11612 nla_nest_end(msg
, scan_plans
);
11614 nla_nest_end(msg
, nd
);
11619 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
11621 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11622 struct sk_buff
*msg
;
11624 u32 size
= NLMSG_DEFAULT_SIZE
;
11626 if (!rdev
->wiphy
.wowlan
)
11627 return -EOPNOTSUPP
;
11629 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
11630 /* adjust size to have room for all the data */
11631 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
11632 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
11633 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
11634 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
11637 msg
= nlmsg_new(size
, GFP_KERNEL
);
11641 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11642 NL80211_CMD_GET_WOWLAN
);
11644 goto nla_put_failure
;
11646 if (rdev
->wiphy
.wowlan_config
) {
11647 struct nlattr
*nl_wowlan
;
11649 nl_wowlan
= nla_nest_start_noflag(msg
,
11650 NL80211_ATTR_WOWLAN_TRIGGERS
);
11652 goto nla_put_failure
;
11654 if ((rdev
->wiphy
.wowlan_config
->any
&&
11655 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
11656 (rdev
->wiphy
.wowlan_config
->disconnect
&&
11657 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
11658 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
11659 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
11660 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
11661 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
11662 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
11663 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
11664 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
11665 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
11666 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
11667 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
11668 goto nla_put_failure
;
11670 if (nl80211_send_wowlan_patterns(msg
, rdev
))
11671 goto nla_put_failure
;
11673 if (nl80211_send_wowlan_tcp(msg
,
11674 rdev
->wiphy
.wowlan_config
->tcp
))
11675 goto nla_put_failure
;
11677 if (nl80211_send_wowlan_nd(
11679 rdev
->wiphy
.wowlan_config
->nd_config
))
11680 goto nla_put_failure
;
11682 nla_nest_end(msg
, nl_wowlan
);
11685 genlmsg_end(msg
, hdr
);
11686 return genlmsg_reply(msg
, info
);
11693 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
11694 struct nlattr
*attr
,
11695 struct cfg80211_wowlan
*trig
)
11697 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
11698 struct cfg80211_wowlan_tcp
*cfg
;
11699 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
11700 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
11702 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
11705 if (!rdev
->wiphy
.wowlan
->tcp
)
11708 err
= nla_parse_nested_deprecated(tb
, MAX_NL80211_WOWLAN_TCP
, attr
,
11709 nl80211_wowlan_tcp_policy
, NULL
);
11713 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
11714 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
11715 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
11716 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
11717 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
11718 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
11719 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
11720 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
11723 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
11724 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
11727 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
11728 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
11729 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
11732 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
11733 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
11736 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
11737 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
11740 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
11741 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
11743 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
11744 tokens_size
= tokln
- sizeof(*tok
);
11746 if (!tok
->len
|| tokens_size
% tok
->len
)
11748 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
11750 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
11752 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
11754 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
11756 if (tok
->offset
+ tok
->len
> data_size
)
11760 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
11761 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
11762 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
11764 if (seq
->len
== 0 || seq
->len
> 4)
11766 if (seq
->len
+ seq
->offset
> data_size
)
11770 size
= sizeof(*cfg
);
11772 size
+= wake_size
+ wake_mask_size
;
11773 size
+= tokens_size
;
11775 cfg
= kzalloc(size
, GFP_KERNEL
);
11778 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
11779 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
11780 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
11782 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
11783 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
11787 /* allocate a socket and port for it and use it */
11788 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
11789 IPPROTO_TCP
, &cfg
->sock
, 1);
11794 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
11795 sock_release(cfg
->sock
);
11797 return -EADDRINUSE
;
11799 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
11805 cfg
->src_port
= port
;
11808 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
11809 cfg
->payload_len
= data_size
;
11810 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
11811 memcpy((void *)cfg
->payload
,
11812 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
11815 cfg
->payload_seq
= *seq
;
11816 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
11817 cfg
->wake_len
= wake_size
;
11818 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
11819 memcpy((void *)cfg
->wake_data
,
11820 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
11822 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
11823 data_size
+ wake_size
;
11824 memcpy((void *)cfg
->wake_mask
,
11825 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
11828 cfg
->tokens_size
= tokens_size
;
11829 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
11837 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
11838 const struct wiphy_wowlan_support
*wowlan
,
11839 struct nlattr
*attr
,
11840 struct cfg80211_wowlan
*trig
)
11842 struct nlattr
**tb
;
11845 tb
= kcalloc(NUM_NL80211_ATTR
, sizeof(*tb
), GFP_KERNEL
);
11849 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
11854 err
= nla_parse_nested_deprecated(tb
, NL80211_ATTR_MAX
, attr
,
11855 nl80211_policy
, NULL
);
11859 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
,
11860 wowlan
->max_nd_match_sets
);
11861 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
11863 trig
->nd_config
= NULL
;
11870 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
11872 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11873 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
11874 struct cfg80211_wowlan new_triggers
= {};
11875 struct cfg80211_wowlan
*ntrig
;
11876 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
11878 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
11879 bool regular
= false;
11882 return -EOPNOTSUPP
;
11884 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
11885 cfg80211_rdev_free_wowlan(rdev
);
11886 rdev
->wiphy
.wowlan_config
= NULL
;
11890 err
= nla_parse_nested_deprecated(tb
, MAX_NL80211_WOWLAN_TRIG
,
11891 info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
],
11892 nl80211_wowlan_policy
, info
->extack
);
11896 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
11897 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
11899 new_triggers
.any
= true;
11902 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
11903 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
11905 new_triggers
.disconnect
= true;
11909 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
11910 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
11912 new_triggers
.magic_pkt
= true;
11916 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
11919 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
11920 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
11922 new_triggers
.gtk_rekey_failure
= true;
11926 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
11927 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
11929 new_triggers
.eap_identity_req
= true;
11933 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
11934 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
11936 new_triggers
.four_way_handshake
= true;
11940 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
11941 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
11943 new_triggers
.rfkill_release
= true;
11947 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
11948 struct nlattr
*pat
;
11949 int n_patterns
= 0;
11950 int rem
, pat_len
, mask_len
, pkt_offset
;
11951 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
11955 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
11958 if (n_patterns
> wowlan
->n_patterns
)
11961 new_triggers
.patterns
= kcalloc(n_patterns
,
11962 sizeof(new_triggers
.patterns
[0]),
11964 if (!new_triggers
.patterns
)
11967 new_triggers
.n_patterns
= n_patterns
;
11970 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
11974 err
= nla_parse_nested_deprecated(pat_tb
,
11975 MAX_NL80211_PKTPAT
,
11977 nl80211_packet_pattern_policy
,
11983 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
11984 !pat_tb
[NL80211_PKTPAT_PATTERN
])
11986 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
11987 mask_len
= DIV_ROUND_UP(pat_len
, 8);
11988 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
11990 if (pat_len
> wowlan
->pattern_max_len
||
11991 pat_len
< wowlan
->pattern_min_len
)
11994 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
11997 pkt_offset
= nla_get_u32(
11998 pat_tb
[NL80211_PKTPAT_OFFSET
]);
11999 if (pkt_offset
> wowlan
->max_pkt_offset
)
12001 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
12003 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
12008 new_triggers
.patterns
[i
].mask
= mask_pat
;
12009 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
12011 mask_pat
+= mask_len
;
12012 new_triggers
.patterns
[i
].pattern
= mask_pat
;
12013 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
12015 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
12021 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
12023 err
= nl80211_parse_wowlan_tcp(
12024 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
12030 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
12032 err
= nl80211_parse_wowlan_nd(
12033 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
12039 /* The 'any' trigger means the device continues operating more or less
12040 * as in its normal operation mode and wakes up the host on most of the
12041 * normal interrupts (like packet RX, ...)
12042 * It therefore makes little sense to combine with the more constrained
12043 * wakeup trigger modes.
12045 if (new_triggers
.any
&& regular
) {
12050 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
12055 cfg80211_rdev_free_wowlan(rdev
);
12056 rdev
->wiphy
.wowlan_config
= ntrig
;
12059 if (rdev
->ops
->set_wakeup
&&
12060 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
12061 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
12065 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
12066 kfree(new_triggers
.patterns
[i
].mask
);
12067 kfree(new_triggers
.patterns
);
12068 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
12069 sock_release(new_triggers
.tcp
->sock
);
12070 kfree(new_triggers
.tcp
);
12071 kfree(new_triggers
.nd_config
);
12076 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
12077 struct cfg80211_registered_device
*rdev
)
12079 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
12081 struct cfg80211_coalesce_rules
*rule
;
12083 if (!rdev
->coalesce
->n_rules
)
12086 nl_rules
= nla_nest_start_noflag(msg
, NL80211_ATTR_COALESCE_RULE
);
12090 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
12091 nl_rule
= nla_nest_start_noflag(msg
, i
+ 1);
12095 rule
= &rdev
->coalesce
->rules
[i
];
12096 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
12100 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
12104 nl_pats
= nla_nest_start_noflag(msg
,
12105 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
12109 for (j
= 0; j
< rule
->n_patterns
; j
++) {
12110 nl_pat
= nla_nest_start_noflag(msg
, j
+ 1);
12113 pat_len
= rule
->patterns
[j
].pattern_len
;
12114 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
12115 DIV_ROUND_UP(pat_len
, 8),
12116 rule
->patterns
[j
].mask
) ||
12117 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
12118 rule
->patterns
[j
].pattern
) ||
12119 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
12120 rule
->patterns
[j
].pkt_offset
))
12122 nla_nest_end(msg
, nl_pat
);
12124 nla_nest_end(msg
, nl_pats
);
12125 nla_nest_end(msg
, nl_rule
);
12127 nla_nest_end(msg
, nl_rules
);
12132 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
12134 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12135 struct sk_buff
*msg
;
12138 if (!rdev
->wiphy
.coalesce
)
12139 return -EOPNOTSUPP
;
12141 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12145 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12146 NL80211_CMD_GET_COALESCE
);
12148 goto nla_put_failure
;
12150 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
12151 goto nla_put_failure
;
12153 genlmsg_end(msg
, hdr
);
12154 return genlmsg_reply(msg
, info
);
12161 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
12163 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
12165 struct cfg80211_coalesce_rules
*rule
;
12170 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
12171 rule
= &coalesce
->rules
[i
];
12172 for (j
= 0; j
< rule
->n_patterns
; j
++)
12173 kfree(rule
->patterns
[j
].mask
);
12174 kfree(rule
->patterns
);
12176 kfree(coalesce
->rules
);
12178 rdev
->coalesce
= NULL
;
12181 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
12182 struct nlattr
*rule
,
12183 struct cfg80211_coalesce_rules
*new_rule
)
12186 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
12187 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
12188 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
12189 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
12191 err
= nla_parse_nested_deprecated(tb
, NL80211_ATTR_COALESCE_RULE_MAX
,
12192 rule
, nl80211_coalesce_policy
, NULL
);
12196 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
12198 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
12199 if (new_rule
->delay
> coalesce
->max_delay
)
12202 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
12203 new_rule
->condition
=
12204 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
12206 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
12209 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
12212 if (n_patterns
> coalesce
->n_patterns
)
12215 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
12217 if (!new_rule
->patterns
)
12220 new_rule
->n_patterns
= n_patterns
;
12223 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
12227 err
= nla_parse_nested_deprecated(pat_tb
, MAX_NL80211_PKTPAT
,
12229 nl80211_packet_pattern_policy
,
12234 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
12235 !pat_tb
[NL80211_PKTPAT_PATTERN
])
12237 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
12238 mask_len
= DIV_ROUND_UP(pat_len
, 8);
12239 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
12241 if (pat_len
> coalesce
->pattern_max_len
||
12242 pat_len
< coalesce
->pattern_min_len
)
12245 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
12248 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
12249 if (pkt_offset
> coalesce
->max_pkt_offset
)
12251 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
12253 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
12257 new_rule
->patterns
[i
].mask
= mask_pat
;
12258 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
12261 mask_pat
+= mask_len
;
12262 new_rule
->patterns
[i
].pattern
= mask_pat
;
12263 new_rule
->patterns
[i
].pattern_len
= pat_len
;
12264 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
12272 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
12274 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12275 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
12276 struct cfg80211_coalesce new_coalesce
= {};
12277 struct cfg80211_coalesce
*n_coalesce
;
12278 int err
, rem_rule
, n_rules
= 0, i
, j
;
12279 struct nlattr
*rule
;
12280 struct cfg80211_coalesce_rules
*tmp_rule
;
12282 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
12283 return -EOPNOTSUPP
;
12285 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
12286 cfg80211_rdev_free_coalesce(rdev
);
12287 rdev_set_coalesce(rdev
, NULL
);
12291 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
12294 if (n_rules
> coalesce
->n_rules
)
12297 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
12299 if (!new_coalesce
.rules
)
12302 new_coalesce
.n_rules
= n_rules
;
12305 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
12307 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
12308 &new_coalesce
.rules
[i
]);
12315 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
12319 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
12324 cfg80211_rdev_free_coalesce(rdev
);
12325 rdev
->coalesce
= n_coalesce
;
12329 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
12330 tmp_rule
= &new_coalesce
.rules
[i
];
12331 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
12332 kfree(tmp_rule
->patterns
[j
].mask
);
12333 kfree(tmp_rule
->patterns
);
12335 kfree(new_coalesce
.rules
);
12340 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
12342 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12343 struct net_device
*dev
= info
->user_ptr
[1];
12344 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12345 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
12346 struct cfg80211_gtk_rekey_data rekey_data
;
12349 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
12352 err
= nla_parse_nested_deprecated(tb
, MAX_NL80211_REKEY_DATA
,
12353 info
->attrs
[NL80211_ATTR_REKEY_DATA
],
12354 nl80211_rekey_policy
, info
->extack
);
12358 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
12359 !tb
[NL80211_REKEY_DATA_KCK
])
12361 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
12363 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
&&
12364 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK
&&
12365 nla_len(tb
[NL80211_REKEY_DATA_KEK
]) == NL80211_KEK_EXT_LEN
))
12367 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
&&
12368 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK
&&
12369 nla_len(tb
[NL80211_REKEY_DATA_KEK
]) == NL80211_KCK_EXT_LEN
))
12372 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
12373 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
12374 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
12375 rekey_data
.kek_len
= nla_len(tb
[NL80211_REKEY_DATA_KEK
]);
12376 rekey_data
.kck_len
= nla_len(tb
[NL80211_REKEY_DATA_KCK
]);
12377 if (tb
[NL80211_REKEY_DATA_AKM
])
12378 rekey_data
.akm
= nla_get_u32(tb
[NL80211_REKEY_DATA_AKM
]);
12381 if (!wdev
->current_bss
) {
12386 if (!rdev
->ops
->set_rekey_data
) {
12391 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
12397 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
12398 struct genl_info
*info
)
12400 struct net_device
*dev
= info
->user_ptr
[1];
12401 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12403 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12404 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12407 if (wdev
->ap_unexpected_nlportid
)
12410 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
12414 static int nl80211_probe_client(struct sk_buff
*skb
,
12415 struct genl_info
*info
)
12417 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12418 struct net_device
*dev
= info
->user_ptr
[1];
12419 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12420 struct sk_buff
*msg
;
12426 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12427 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12428 return -EOPNOTSUPP
;
12430 if (!info
->attrs
[NL80211_ATTR_MAC
])
12433 if (!rdev
->ops
->probe_client
)
12434 return -EOPNOTSUPP
;
12436 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12440 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12441 NL80211_CMD_PROBE_CLIENT
);
12447 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12449 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
12453 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
12455 goto nla_put_failure
;
12457 genlmsg_end(msg
, hdr
);
12459 return genlmsg_reply(msg
, info
);
12468 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
12470 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12471 struct cfg80211_beacon_registration
*reg
, *nreg
;
12474 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
12475 return -EOPNOTSUPP
;
12477 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
12481 /* First, check if already registered. */
12482 spin_lock_bh(&rdev
->beacon_registrations_lock
);
12483 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
12484 if (reg
->nlportid
== info
->snd_portid
) {
12489 /* Add it to the list */
12490 nreg
->nlportid
= info
->snd_portid
;
12491 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
12493 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12497 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12502 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
12504 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12505 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12508 if (!rdev
->ops
->start_p2p_device
)
12509 return -EOPNOTSUPP
;
12511 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
12512 return -EOPNOTSUPP
;
12514 if (wdev_running(wdev
))
12517 if (rfkill_blocked(rdev
->rfkill
))
12520 err
= rdev_start_p2p_device(rdev
, wdev
);
12524 wdev
->is_running
= true;
12530 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
12532 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12533 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12535 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
12536 return -EOPNOTSUPP
;
12538 if (!rdev
->ops
->stop_p2p_device
)
12539 return -EOPNOTSUPP
;
12541 cfg80211_stop_p2p_device(rdev
, wdev
);
12546 static int nl80211_start_nan(struct sk_buff
*skb
, struct genl_info
*info
)
12548 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12549 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12550 struct cfg80211_nan_conf conf
= {};
12553 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12554 return -EOPNOTSUPP
;
12556 if (wdev_running(wdev
))
12559 if (rfkill_blocked(rdev
->rfkill
))
12562 if (!info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
])
12566 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
12568 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
12569 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
12571 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
12572 return -EOPNOTSUPP
;
12574 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
12577 conf
.bands
= bands
;
12580 err
= rdev_start_nan(rdev
, wdev
, &conf
);
12584 wdev
->is_running
= true;
12590 static int nl80211_stop_nan(struct sk_buff
*skb
, struct genl_info
*info
)
12592 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12593 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12595 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12596 return -EOPNOTSUPP
;
12598 cfg80211_stop_nan(rdev
, wdev
);
12603 static int validate_nan_filter(struct nlattr
*filter_attr
)
12605 struct nlattr
*attr
;
12606 int len
= 0, n_entries
= 0, rem
;
12608 nla_for_each_nested(attr
, filter_attr
, rem
) {
12609 len
+= nla_len(attr
);
12619 static int handle_nan_filter(struct nlattr
*attr_filter
,
12620 struct cfg80211_nan_func
*func
,
12623 struct nlattr
*attr
;
12624 int n_entries
, rem
, i
;
12625 struct cfg80211_nan_func_filter
*filter
;
12627 n_entries
= validate_nan_filter(attr_filter
);
12631 BUILD_BUG_ON(sizeof(*func
->rx_filters
) != sizeof(*func
->tx_filters
));
12633 filter
= kcalloc(n_entries
, sizeof(*func
->rx_filters
), GFP_KERNEL
);
12638 nla_for_each_nested(attr
, attr_filter
, rem
) {
12639 filter
[i
].filter
= nla_memdup(attr
, GFP_KERNEL
);
12640 filter
[i
].len
= nla_len(attr
);
12644 func
->num_tx_filters
= n_entries
;
12645 func
->tx_filters
= filter
;
12647 func
->num_rx_filters
= n_entries
;
12648 func
->rx_filters
= filter
;
12654 static int nl80211_nan_add_func(struct sk_buff
*skb
,
12655 struct genl_info
*info
)
12657 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12658 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12659 struct nlattr
*tb
[NUM_NL80211_NAN_FUNC_ATTR
], *func_attr
;
12660 struct cfg80211_nan_func
*func
;
12661 struct sk_buff
*msg
= NULL
;
12665 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12666 return -EOPNOTSUPP
;
12668 if (!wdev_running(wdev
))
12671 if (!info
->attrs
[NL80211_ATTR_NAN_FUNC
])
12674 err
= nla_parse_nested_deprecated(tb
, NL80211_NAN_FUNC_ATTR_MAX
,
12675 info
->attrs
[NL80211_ATTR_NAN_FUNC
],
12676 nl80211_nan_func_policy
,
12681 func
= kzalloc(sizeof(*func
), GFP_KERNEL
);
12685 func
->cookie
= cfg80211_assign_cookie(rdev
);
12687 if (!tb
[NL80211_NAN_FUNC_TYPE
] ||
12688 nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]) > NL80211_NAN_FUNC_MAX_TYPE
) {
12694 func
->type
= nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]);
12696 if (!tb
[NL80211_NAN_FUNC_SERVICE_ID
]) {
12701 memcpy(func
->service_id
, nla_data(tb
[NL80211_NAN_FUNC_SERVICE_ID
]),
12702 sizeof(func
->service_id
));
12704 func
->close_range
=
12705 nla_get_flag(tb
[NL80211_NAN_FUNC_CLOSE_RANGE
]);
12707 if (tb
[NL80211_NAN_FUNC_SERVICE_INFO
]) {
12708 func
->serv_spec_info_len
=
12709 nla_len(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]);
12710 func
->serv_spec_info
=
12711 kmemdup(nla_data(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]),
12712 func
->serv_spec_info_len
,
12714 if (!func
->serv_spec_info
) {
12720 if (tb
[NL80211_NAN_FUNC_TTL
])
12721 func
->ttl
= nla_get_u32(tb
[NL80211_NAN_FUNC_TTL
]);
12723 switch (func
->type
) {
12724 case NL80211_NAN_FUNC_PUBLISH
:
12725 if (!tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]) {
12730 func
->publish_type
=
12731 nla_get_u8(tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]);
12732 func
->publish_bcast
=
12733 nla_get_flag(tb
[NL80211_NAN_FUNC_PUBLISH_BCAST
]);
12735 if ((!(func
->publish_type
& NL80211_NAN_SOLICITED_PUBLISH
)) &&
12736 func
->publish_bcast
) {
12741 case NL80211_NAN_FUNC_SUBSCRIBE
:
12742 func
->subscribe_active
=
12743 nla_get_flag(tb
[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
]);
12745 case NL80211_NAN_FUNC_FOLLOW_UP
:
12746 if (!tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
] ||
12747 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] ||
12748 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]) {
12753 func
->followup_id
=
12754 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
]);
12755 func
->followup_reqid
=
12756 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]);
12757 memcpy(func
->followup_dest
.addr
,
12758 nla_data(tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]),
12759 sizeof(func
->followup_dest
.addr
));
12770 if (tb
[NL80211_NAN_FUNC_SRF
]) {
12771 struct nlattr
*srf_tb
[NUM_NL80211_NAN_SRF_ATTR
];
12773 err
= nla_parse_nested_deprecated(srf_tb
,
12774 NL80211_NAN_SRF_ATTR_MAX
,
12775 tb
[NL80211_NAN_FUNC_SRF
],
12776 nl80211_nan_srf_policy
,
12781 func
->srf_include
=
12782 nla_get_flag(srf_tb
[NL80211_NAN_SRF_INCLUDE
]);
12784 if (srf_tb
[NL80211_NAN_SRF_BF
]) {
12785 if (srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
] ||
12786 !srf_tb
[NL80211_NAN_SRF_BF_IDX
]) {
12792 nla_len(srf_tb
[NL80211_NAN_SRF_BF
]);
12794 kmemdup(nla_data(srf_tb
[NL80211_NAN_SRF_BF
]),
12795 func
->srf_bf_len
, GFP_KERNEL
);
12796 if (!func
->srf_bf
) {
12802 nla_get_u8(srf_tb
[NL80211_NAN_SRF_BF_IDX
]);
12804 struct nlattr
*attr
, *mac_attr
=
12805 srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
];
12806 int n_entries
, rem
, i
= 0;
12813 n_entries
= validate_acl_mac_addrs(mac_attr
);
12814 if (n_entries
<= 0) {
12819 func
->srf_num_macs
= n_entries
;
12821 kcalloc(n_entries
, sizeof(*func
->srf_macs
),
12823 if (!func
->srf_macs
) {
12828 nla_for_each_nested(attr
, mac_attr
, rem
)
12829 memcpy(func
->srf_macs
[i
++].addr
, nla_data(attr
),
12830 sizeof(*func
->srf_macs
));
12834 if (tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
]) {
12835 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
],
12841 if (tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
]) {
12842 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
],
12848 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12854 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12855 NL80211_CMD_ADD_NAN_FUNCTION
);
12856 /* This can't really happen - we just allocated 4KB */
12857 if (WARN_ON(!hdr
)) {
12862 err
= rdev_add_nan_func(rdev
, wdev
, func
);
12865 cfg80211_free_nan_func(func
);
12870 /* propagate the instance id and cookie to userspace */
12871 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, func
->cookie
,
12873 goto nla_put_failure
;
12875 func_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_NAN_FUNC
);
12877 goto nla_put_failure
;
12879 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
,
12880 func
->instance_id
))
12881 goto nla_put_failure
;
12883 nla_nest_end(msg
, func_attr
);
12885 genlmsg_end(msg
, hdr
);
12886 return genlmsg_reply(msg
, info
);
12893 static int nl80211_nan_del_func(struct sk_buff
*skb
,
12894 struct genl_info
*info
)
12896 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12897 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12900 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12901 return -EOPNOTSUPP
;
12903 if (!wdev_running(wdev
))
12906 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
12909 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
12911 rdev_del_nan_func(rdev
, wdev
, cookie
);
12916 static int nl80211_nan_change_config(struct sk_buff
*skb
,
12917 struct genl_info
*info
)
12919 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12920 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12921 struct cfg80211_nan_conf conf
= {};
12924 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12925 return -EOPNOTSUPP
;
12927 if (!wdev_running(wdev
))
12930 if (info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]) {
12932 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
12933 if (conf
.master_pref
<= 1 || conf
.master_pref
== 255)
12936 changed
|= CFG80211_NAN_CONF_CHANGED_PREF
;
12939 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
12940 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
12942 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
12943 return -EOPNOTSUPP
;
12945 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
12948 conf
.bands
= bands
;
12949 changed
|= CFG80211_NAN_CONF_CHANGED_BANDS
;
12955 return rdev_nan_change_conf(rdev
, wdev
, &conf
, changed
);
12958 void cfg80211_nan_match(struct wireless_dev
*wdev
,
12959 struct cfg80211_nan_match_params
*match
, gfp_t gfp
)
12961 struct wiphy
*wiphy
= wdev
->wiphy
;
12962 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12963 struct nlattr
*match_attr
, *local_func_attr
, *peer_func_attr
;
12964 struct sk_buff
*msg
;
12967 if (WARN_ON(!match
->inst_id
|| !match
->peer_inst_id
|| !match
->addr
))
12970 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12974 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NAN_MATCH
);
12980 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12981 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12982 wdev
->netdev
->ifindex
)) ||
12983 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12985 goto nla_put_failure
;
12987 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, match
->cookie
,
12988 NL80211_ATTR_PAD
) ||
12989 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, match
->addr
))
12990 goto nla_put_failure
;
12992 match_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_NAN_MATCH
);
12994 goto nla_put_failure
;
12996 local_func_attr
= nla_nest_start_noflag(msg
,
12997 NL80211_NAN_MATCH_FUNC_LOCAL
);
12998 if (!local_func_attr
)
12999 goto nla_put_failure
;
13001 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->inst_id
))
13002 goto nla_put_failure
;
13004 nla_nest_end(msg
, local_func_attr
);
13006 peer_func_attr
= nla_nest_start_noflag(msg
,
13007 NL80211_NAN_MATCH_FUNC_PEER
);
13008 if (!peer_func_attr
)
13009 goto nla_put_failure
;
13011 if (nla_put_u8(msg
, NL80211_NAN_FUNC_TYPE
, match
->type
) ||
13012 nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->peer_inst_id
))
13013 goto nla_put_failure
;
13015 if (match
->info
&& match
->info_len
&&
13016 nla_put(msg
, NL80211_NAN_FUNC_SERVICE_INFO
, match
->info_len
,
13018 goto nla_put_failure
;
13020 nla_nest_end(msg
, peer_func_attr
);
13021 nla_nest_end(msg
, match_attr
);
13022 genlmsg_end(msg
, hdr
);
13024 if (!wdev
->owner_nlportid
)
13025 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
13026 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
13028 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
13029 wdev
->owner_nlportid
);
13036 EXPORT_SYMBOL(cfg80211_nan_match
);
13038 void cfg80211_nan_func_terminated(struct wireless_dev
*wdev
,
13040 enum nl80211_nan_func_term_reason reason
,
13041 u64 cookie
, gfp_t gfp
)
13043 struct wiphy
*wiphy
= wdev
->wiphy
;
13044 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13045 struct sk_buff
*msg
;
13046 struct nlattr
*func_attr
;
13049 if (WARN_ON(!inst_id
))
13052 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13056 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION
);
13062 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13063 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13064 wdev
->netdev
->ifindex
)) ||
13065 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13067 goto nla_put_failure
;
13069 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
13071 goto nla_put_failure
;
13073 func_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_NAN_FUNC
);
13075 goto nla_put_failure
;
13077 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, inst_id
) ||
13078 nla_put_u8(msg
, NL80211_NAN_FUNC_TERM_REASON
, reason
))
13079 goto nla_put_failure
;
13081 nla_nest_end(msg
, func_attr
);
13082 genlmsg_end(msg
, hdr
);
13084 if (!wdev
->owner_nlportid
)
13085 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
13086 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
13088 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
13089 wdev
->owner_nlportid
);
13096 EXPORT_SYMBOL(cfg80211_nan_func_terminated
);
13098 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
13099 struct genl_info
*info
)
13102 struct sk_buff
*msg
;
13104 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13108 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
13109 NL80211_CMD_GET_PROTOCOL_FEATURES
);
13111 goto nla_put_failure
;
13113 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
13114 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
13115 goto nla_put_failure
;
13117 genlmsg_end(msg
, hdr
);
13118 return genlmsg_reply(msg
, info
);
13125 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
13127 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13128 struct cfg80211_update_ft_ies_params ft_params
;
13129 struct net_device
*dev
= info
->user_ptr
[1];
13131 if (!rdev
->ops
->update_ft_ies
)
13132 return -EOPNOTSUPP
;
13134 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
13135 !info
->attrs
[NL80211_ATTR_IE
])
13138 memset(&ft_params
, 0, sizeof(ft_params
));
13139 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
13140 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
13141 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
13143 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
13146 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
13147 struct genl_info
*info
)
13149 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13150 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13151 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
13155 if (!rdev
->ops
->crit_proto_start
)
13156 return -EOPNOTSUPP
;
13158 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
13161 if (rdev
->crit_proto_nlportid
)
13164 /* determine protocol if provided */
13165 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
13166 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
13168 if (proto
>= NUM_NL80211_CRIT_PROTO
)
13171 /* timeout must be provided */
13172 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
13176 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
13178 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
13181 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
13183 rdev
->crit_proto_nlportid
= info
->snd_portid
;
13188 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
13189 struct genl_info
*info
)
13191 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13192 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13194 if (!rdev
->ops
->crit_proto_stop
)
13195 return -EOPNOTSUPP
;
13197 if (rdev
->crit_proto_nlportid
) {
13198 rdev
->crit_proto_nlportid
= 0;
13199 rdev_crit_proto_stop(rdev
, wdev
);
13204 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command
*vcmd
,
13205 struct nlattr
*attr
,
13206 struct netlink_ext_ack
*extack
)
13208 if (vcmd
->policy
== VENDOR_CMD_RAW_DATA
) {
13209 if (attr
->nla_type
& NLA_F_NESTED
) {
13210 NL_SET_ERR_MSG_ATTR(extack
, attr
,
13211 "unexpected nested data");
13218 if (!(attr
->nla_type
& NLA_F_NESTED
)) {
13219 NL_SET_ERR_MSG_ATTR(extack
, attr
, "expected nested data");
13223 return nla_validate_nested(attr
, vcmd
->maxattr
, vcmd
->policy
, extack
);
13226 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
13228 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13229 struct wireless_dev
*wdev
=
13230 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
13234 if (!rdev
->wiphy
.vendor_commands
)
13235 return -EOPNOTSUPP
;
13237 if (IS_ERR(wdev
)) {
13238 err
= PTR_ERR(wdev
);
13239 if (err
!= -EINVAL
)
13242 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
13246 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
13247 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
13250 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
13251 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
13252 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
13253 const struct wiphy_vendor_command
*vcmd
;
13257 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
13259 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
13262 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
13263 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
13266 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
13270 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
13271 if (!wdev_running(wdev
))
13279 return -EOPNOTSUPP
;
13281 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
13282 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
13283 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
13285 err
= nl80211_vendor_check_policy(vcmd
,
13286 info
->attrs
[NL80211_ATTR_VENDOR_DATA
],
13292 rdev
->cur_cmd_info
= info
;
13293 err
= vcmd
->doit(&rdev
->wiphy
, wdev
, data
, len
);
13294 rdev
->cur_cmd_info
= NULL
;
13298 return -EOPNOTSUPP
;
13301 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
13302 struct netlink_callback
*cb
,
13303 struct cfg80211_registered_device
**rdev
,
13304 struct wireless_dev
**wdev
)
13306 struct nlattr
**attrbuf
;
13312 unsigned int data_len
= 0;
13315 /* subtract the 1 again here */
13316 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
13317 struct wireless_dev
*tmp
;
13321 *rdev
= wiphy_to_rdev(wiphy
);
13325 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
13326 if (tmp
->identifier
== cb
->args
[1] - 1) {
13333 /* keep rtnl locked in successful case */
13337 attrbuf
= kcalloc(NUM_NL80211_ATTR
, sizeof(*attrbuf
), GFP_KERNEL
);
13341 err
= nlmsg_parse_deprecated(cb
->nlh
,
13342 GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
13343 attrbuf
, nl80211_fam
.maxattr
,
13344 nl80211_policy
, NULL
);
13348 if (!attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
13349 !attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]) {
13354 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
13358 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
13359 if (IS_ERR(*rdev
)) {
13360 err
= PTR_ERR(*rdev
);
13364 vid
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_ID
]);
13365 subcmd
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
13367 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
13368 const struct wiphy_vendor_command
*vcmd
;
13370 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
13372 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
13375 if (!vcmd
->dumpit
) {
13384 if (vcmd_idx
< 0) {
13389 if (attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
13390 data
= nla_data(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
13391 data_len
= nla_len(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
13393 err
= nl80211_vendor_check_policy(
13394 &(*rdev
)->wiphy
.vendor_commands
[vcmd_idx
],
13395 attrbuf
[NL80211_ATTR_VENDOR_DATA
],
13401 /* 0 is the first index - add 1 to parse only once */
13402 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
13403 /* add 1 to know if it was NULL */
13404 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
13405 cb
->args
[2] = vcmd_idx
;
13406 cb
->args
[3] = (unsigned long)data
;
13407 cb
->args
[4] = data_len
;
13409 /* keep rtnl locked in successful case */
13416 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
13417 struct netlink_callback
*cb
)
13419 struct cfg80211_registered_device
*rdev
;
13420 struct wireless_dev
*wdev
;
13421 unsigned int vcmd_idx
;
13422 const struct wiphy_vendor_command
*vcmd
;
13426 struct nlattr
*vendor_data
;
13429 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
13433 vcmd_idx
= cb
->args
[2];
13434 data
= (void *)cb
->args
[3];
13435 data_len
= cb
->args
[4];
13436 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
13438 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
13439 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
13444 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
13450 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
13451 if (!wdev_running(wdev
)) {
13459 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
13460 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
13461 NL80211_CMD_VENDOR
);
13465 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13466 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
13468 NL80211_ATTR_PAD
))) {
13469 genlmsg_cancel(skb
, hdr
);
13473 vendor_data
= nla_nest_start_noflag(skb
,
13474 NL80211_ATTR_VENDOR_DATA
);
13475 if (!vendor_data
) {
13476 genlmsg_cancel(skb
, hdr
);
13480 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
13481 (unsigned long *)&cb
->args
[5]);
13482 nla_nest_end(skb
, vendor_data
);
13484 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
13485 genlmsg_cancel(skb
, hdr
);
13487 } else if (err
<= 0) {
13488 genlmsg_cancel(skb
, hdr
);
13492 genlmsg_end(skb
, hdr
);
13501 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
13502 enum nl80211_commands cmd
,
13503 enum nl80211_attrs attr
,
13506 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13508 if (WARN_ON(!rdev
->cur_cmd_info
))
13511 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
13512 rdev
->cur_cmd_info
->snd_portid
,
13513 rdev
->cur_cmd_info
->snd_seq
,
13514 cmd
, attr
, NULL
, GFP_KERNEL
);
13516 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
13518 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
13520 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
13521 void *hdr
= ((void **)skb
->cb
)[1];
13522 struct nlattr
*data
= ((void **)skb
->cb
)[2];
13524 /* clear CB data for netlink core to own from now on */
13525 memset(skb
->cb
, 0, sizeof(skb
->cb
));
13527 if (WARN_ON(!rdev
->cur_cmd_info
)) {
13532 nla_nest_end(skb
, data
);
13533 genlmsg_end(skb
, hdr
);
13534 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
13536 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
13538 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy
*wiphy
)
13540 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13542 if (WARN_ON(!rdev
->cur_cmd_info
))
13545 return rdev
->cur_cmd_info
->snd_portid
;
13547 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender
);
13549 static int nl80211_set_qos_map(struct sk_buff
*skb
,
13550 struct genl_info
*info
)
13552 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13553 struct cfg80211_qos_map
*qos_map
= NULL
;
13554 struct net_device
*dev
= info
->user_ptr
[1];
13555 u8
*pos
, len
, num_des
, des_len
, des
;
13558 if (!rdev
->ops
->set_qos_map
)
13559 return -EOPNOTSUPP
;
13561 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
13562 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
13563 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
13565 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
13566 len
> IEEE80211_QOS_MAP_LEN_MAX
)
13569 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
13573 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
13575 des_len
= num_des
*
13576 sizeof(struct cfg80211_dscp_exception
);
13577 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
13578 qos_map
->num_des
= num_des
;
13579 for (des
= 0; des
< num_des
; des
++) {
13580 if (qos_map
->dscp_exception
[des
].up
> 7) {
13587 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
13590 wdev_lock(dev
->ieee80211_ptr
);
13591 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
13593 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
13594 wdev_unlock(dev
->ieee80211_ptr
);
13600 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
13602 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13603 struct net_device
*dev
= info
->user_ptr
[1];
13604 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13607 u16 admitted_time
= 0;
13610 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
13611 return -EOPNOTSUPP
;
13613 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
13614 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
13617 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
13618 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
13620 /* WMM uses TIDs 0-7 even for TSPEC */
13621 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
13622 /* TODO: handle 802.11 TSPEC/admission control
13623 * need more attributes for that (e.g. BA session requirement);
13624 * change the WMM adminssion test above to allow both then
13629 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13631 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
13633 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
13634 if (!admitted_time
)
13639 switch (wdev
->iftype
) {
13640 case NL80211_IFTYPE_STATION
:
13641 case NL80211_IFTYPE_P2P_CLIENT
:
13642 if (wdev
->current_bss
)
13651 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
13658 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
13660 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13661 struct net_device
*dev
= info
->user_ptr
[1];
13662 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13667 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
13670 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
13671 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13674 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
13680 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
13681 struct genl_info
*info
)
13683 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13684 struct net_device
*dev
= info
->user_ptr
[1];
13685 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13686 struct cfg80211_chan_def chandef
= {};
13691 if (!rdev
->ops
->tdls_channel_switch
||
13692 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
13693 return -EOPNOTSUPP
;
13695 switch (dev
->ieee80211_ptr
->iftype
) {
13696 case NL80211_IFTYPE_STATION
:
13697 case NL80211_IFTYPE_P2P_CLIENT
:
13700 return -EOPNOTSUPP
;
13703 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
13704 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
13707 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
13712 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13713 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13714 * specification is not defined for them.
13716 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
13717 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
13718 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
13721 /* we will be active on the TDLS link */
13722 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
13726 /* don't allow switching to DFS channels */
13727 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
13730 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13731 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
13734 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
13740 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
13741 struct genl_info
*info
)
13743 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13744 struct net_device
*dev
= info
->user_ptr
[1];
13745 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13748 if (!rdev
->ops
->tdls_channel_switch
||
13749 !rdev
->ops
->tdls_cancel_channel_switch
||
13750 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
13751 return -EOPNOTSUPP
;
13753 switch (dev
->ieee80211_ptr
->iftype
) {
13754 case NL80211_IFTYPE_STATION
:
13755 case NL80211_IFTYPE_P2P_CLIENT
:
13758 return -EOPNOTSUPP
;
13761 if (!info
->attrs
[NL80211_ATTR_MAC
])
13764 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13767 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
13773 static int nl80211_set_multicast_to_unicast(struct sk_buff
*skb
,
13774 struct genl_info
*info
)
13776 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13777 struct net_device
*dev
= info
->user_ptr
[1];
13778 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13779 const struct nlattr
*nla
;
13782 if (!rdev
->ops
->set_multicast_to_unicast
)
13783 return -EOPNOTSUPP
;
13785 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
13786 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
13787 return -EOPNOTSUPP
;
13789 nla
= info
->attrs
[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
];
13790 enabled
= nla_get_flag(nla
);
13792 return rdev_set_multicast_to_unicast(rdev
, dev
, enabled
);
13795 static int nl80211_set_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
13797 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13798 struct net_device
*dev
= info
->user_ptr
[1];
13799 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13800 struct cfg80211_pmk_conf pmk_conf
= {};
13803 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
13804 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
13805 return -EOPNOTSUPP
;
13807 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
13808 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
13809 return -EOPNOTSUPP
;
13811 if (!info
->attrs
[NL80211_ATTR_MAC
] || !info
->attrs
[NL80211_ATTR_PMK
])
13815 if (!wdev
->current_bss
) {
13820 pmk_conf
.aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13821 if (memcmp(pmk_conf
.aa
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
)) {
13826 pmk_conf
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
13827 pmk_conf
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
13828 if (pmk_conf
.pmk_len
!= WLAN_PMK_LEN
&&
13829 pmk_conf
.pmk_len
!= WLAN_PMK_LEN_SUITE_B_192
) {
13834 if (info
->attrs
[NL80211_ATTR_PMKR0_NAME
]) {
13835 int r0_name_len
= nla_len(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
13837 if (r0_name_len
!= WLAN_PMK_NAME_LEN
) {
13842 pmk_conf
.pmk_r0_name
=
13843 nla_data(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
13846 ret
= rdev_set_pmk(rdev
, dev
, &pmk_conf
);
13852 static int nl80211_del_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
13854 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13855 struct net_device
*dev
= info
->user_ptr
[1];
13856 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13860 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
13861 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
13862 return -EOPNOTSUPP
;
13864 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
13865 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
13866 return -EOPNOTSUPP
;
13868 if (!info
->attrs
[NL80211_ATTR_MAC
])
13872 aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13873 ret
= rdev_del_pmk(rdev
, dev
, aa
);
13879 static int nl80211_external_auth(struct sk_buff
*skb
, struct genl_info
*info
)
13881 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13882 struct net_device
*dev
= info
->user_ptr
[1];
13883 struct cfg80211_external_auth_params params
;
13885 if (!rdev
->ops
->external_auth
)
13886 return -EOPNOTSUPP
;
13888 if (!info
->attrs
[NL80211_ATTR_SSID
] &&
13889 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
13890 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
13893 if (!info
->attrs
[NL80211_ATTR_BSSID
])
13896 if (!info
->attrs
[NL80211_ATTR_STATUS_CODE
])
13899 memset(¶ms
, 0, sizeof(params
));
13901 if (info
->attrs
[NL80211_ATTR_SSID
]) {
13902 params
.ssid
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
13903 if (params
.ssid
.ssid_len
== 0 ||
13904 params
.ssid
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
13906 memcpy(params
.ssid
.ssid
,
13907 nla_data(info
->attrs
[NL80211_ATTR_SSID
]),
13908 params
.ssid
.ssid_len
);
13911 memcpy(params
.bssid
, nla_data(info
->attrs
[NL80211_ATTR_BSSID
]),
13914 params
.status
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
13916 if (info
->attrs
[NL80211_ATTR_PMKID
])
13917 params
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
13919 return rdev_external_auth(rdev
, dev
, ¶ms
);
13922 static int nl80211_tx_control_port(struct sk_buff
*skb
, struct genl_info
*info
)
13924 bool dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
13925 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13926 struct net_device
*dev
= info
->user_ptr
[1];
13927 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13936 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
13937 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
13938 return -EOPNOTSUPP
;
13940 if (!rdev
->ops
->tx_control_port
)
13941 return -EOPNOTSUPP
;
13943 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
13944 !info
->attrs
[NL80211_ATTR_MAC
] ||
13945 !info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
13946 GENL_SET_ERR_MSG(info
, "Frame, MAC or ethertype missing");
13952 switch (wdev
->iftype
) {
13953 case NL80211_IFTYPE_AP
:
13954 case NL80211_IFTYPE_P2P_GO
:
13955 case NL80211_IFTYPE_MESH_POINT
:
13957 case NL80211_IFTYPE_ADHOC
:
13958 case NL80211_IFTYPE_STATION
:
13959 case NL80211_IFTYPE_P2P_CLIENT
:
13960 if (wdev
->current_bss
)
13971 buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
13972 len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
13973 dest
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13974 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
13976 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
]);
13978 err
= rdev_tx_control_port(rdev
, dev
, buf
, len
,
13979 dest
, cpu_to_be16(proto
), noencrypt
,
13980 dont_wait_for_ack
? NULL
: &cookie
);
13981 if (!err
&& !dont_wait_for_ack
)
13982 nl_set_extack_cookie_u64(info
->extack
, cookie
);
13989 static int nl80211_get_ftm_responder_stats(struct sk_buff
*skb
,
13990 struct genl_info
*info
)
13992 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13993 struct net_device
*dev
= info
->user_ptr
[1];
13994 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13995 struct cfg80211_ftm_responder_stats ftm_stats
= {};
13996 struct sk_buff
*msg
;
13998 struct nlattr
*ftm_stats_attr
;
14001 if (wdev
->iftype
!= NL80211_IFTYPE_AP
|| !wdev
->beacon_interval
)
14002 return -EOPNOTSUPP
;
14004 err
= rdev_get_ftm_responder_stats(rdev
, dev
, &ftm_stats
);
14008 if (!ftm_stats
.filled
)
14011 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14015 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
14016 NL80211_CMD_GET_FTM_RESPONDER_STATS
);
14018 goto nla_put_failure
;
14020 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
14021 goto nla_put_failure
;
14023 ftm_stats_attr
= nla_nest_start_noflag(msg
,
14024 NL80211_ATTR_FTM_RESPONDER_STATS
);
14025 if (!ftm_stats_attr
)
14026 goto nla_put_failure
;
14028 #define SET_FTM(field, name, type) \
14029 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14030 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
14031 ftm_stats.field)) \
14032 goto nla_put_failure; } while (0)
14033 #define SET_FTM_U64(field, name) \
14034 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14035 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
14036 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
14037 goto nla_put_failure; } while (0)
14039 SET_FTM(success_num
, SUCCESS_NUM
, u32
);
14040 SET_FTM(partial_num
, PARTIAL_NUM
, u32
);
14041 SET_FTM(failed_num
, FAILED_NUM
, u32
);
14042 SET_FTM(asap_num
, ASAP_NUM
, u32
);
14043 SET_FTM(non_asap_num
, NON_ASAP_NUM
, u32
);
14044 SET_FTM_U64(total_duration_ms
, TOTAL_DURATION_MSEC
);
14045 SET_FTM(unknown_triggers_num
, UNKNOWN_TRIGGERS_NUM
, u32
);
14046 SET_FTM(reschedule_requests_num
, RESCHEDULE_REQUESTS_NUM
, u32
);
14047 SET_FTM(out_of_window_triggers_num
, OUT_OF_WINDOW_TRIGGERS_NUM
, u32
);
14050 nla_nest_end(msg
, ftm_stats_attr
);
14052 genlmsg_end(msg
, hdr
);
14053 return genlmsg_reply(msg
, info
);
14060 static int nl80211_update_owe_info(struct sk_buff
*skb
, struct genl_info
*info
)
14062 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14063 struct cfg80211_update_owe_info owe_info
;
14064 struct net_device
*dev
= info
->user_ptr
[1];
14066 if (!rdev
->ops
->update_owe_info
)
14067 return -EOPNOTSUPP
;
14069 if (!info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
14070 !info
->attrs
[NL80211_ATTR_MAC
])
14073 memset(&owe_info
, 0, sizeof(owe_info
));
14074 owe_info
.status
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
14075 nla_memcpy(owe_info
.peer
, info
->attrs
[NL80211_ATTR_MAC
], ETH_ALEN
);
14077 if (info
->attrs
[NL80211_ATTR_IE
]) {
14078 owe_info
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
14079 owe_info
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
14082 return rdev_update_owe_info(rdev
, dev
, &owe_info
);
14085 static int nl80211_probe_mesh_link(struct sk_buff
*skb
, struct genl_info
*info
)
14087 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14088 struct net_device
*dev
= info
->user_ptr
[1];
14089 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14090 struct station_info sinfo
= {};
14096 if (!rdev
->ops
->probe_mesh_link
|| !rdev
->ops
->get_station
)
14097 return -EOPNOTSUPP
;
14099 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
14100 !info
->attrs
[NL80211_ATTR_FRAME
]) {
14101 GENL_SET_ERR_MSG(info
, "Frame or MAC missing");
14105 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
14106 return -EOPNOTSUPP
;
14108 dest
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14109 buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
14110 len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
14112 if (len
< sizeof(struct ethhdr
))
14115 if (!ether_addr_equal(buf
, dest
) || is_multicast_ether_addr(buf
) ||
14116 !ether_addr_equal(buf
+ ETH_ALEN
, dev
->dev_addr
))
14119 err
= rdev_get_station(rdev
, dev
, dest
, &sinfo
);
14123 cfg80211_sinfo_release_content(&sinfo
);
14125 return rdev_probe_mesh_link(rdev
, dev
, dest
, buf
, len
);
14128 static int parse_tid_conf(struct cfg80211_registered_device
*rdev
,
14129 struct nlattr
*attrs
[], struct net_device
*dev
,
14130 struct cfg80211_tid_cfg
*tid_conf
,
14131 struct genl_info
*info
, const u8
*peer
)
14133 struct netlink_ext_ack
*extack
= info
->extack
;
14137 if (!attrs
[NL80211_TID_CONFIG_ATTR_TIDS
])
14140 tid_conf
->config_override
=
14141 nla_get_flag(attrs
[NL80211_TID_CONFIG_ATTR_OVERRIDE
]);
14142 tid_conf
->tids
= nla_get_u16(attrs
[NL80211_TID_CONFIG_ATTR_TIDS
]);
14144 if (tid_conf
->config_override
) {
14145 if (rdev
->ops
->reset_tid_config
) {
14146 err
= rdev_reset_tid_config(rdev
, dev
, peer
,
14155 if (attrs
[NL80211_TID_CONFIG_ATTR_NOACK
]) {
14156 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
14158 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_NOACK
]);
14161 if (attrs
[NL80211_TID_CONFIG_ATTR_RETRY_SHORT
]) {
14162 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT
);
14163 tid_conf
->retry_short
=
14164 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_RETRY_SHORT
]);
14166 if (tid_conf
->retry_short
> rdev
->wiphy
.max_data_retry_count
)
14170 if (attrs
[NL80211_TID_CONFIG_ATTR_RETRY_LONG
]) {
14171 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
14172 tid_conf
->retry_long
=
14173 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_RETRY_LONG
]);
14175 if (tid_conf
->retry_long
> rdev
->wiphy
.max_data_retry_count
)
14179 if (attrs
[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
]) {
14180 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
);
14182 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
]);
14185 if (attrs
[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
]) {
14186 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
);
14188 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
]);
14191 if (attrs
[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL
]) {
14192 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL
);
14194 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL
]);
14197 if (attrs
[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
]) {
14198 u32 idx
= NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
, attr
;
14200 tid_conf
->txrate_type
= nla_get_u8(attrs
[idx
]);
14202 if (tid_conf
->txrate_type
!= NL80211_TX_RATE_AUTOMATIC
) {
14203 attr
= NL80211_TID_CONFIG_ATTR_TX_RATE
;
14204 err
= nl80211_parse_tx_bitrate_mask(info
, attrs
, attr
,
14205 &tid_conf
->txrate_mask
);
14209 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
);
14211 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
);
14215 mask
= rdev
->wiphy
.tid_config_support
.peer
;
14217 mask
= rdev
->wiphy
.tid_config_support
.vif
;
14219 if (tid_conf
->mask
& ~mask
) {
14220 NL_SET_ERR_MSG(extack
, "unsupported TID configuration");
14227 static int nl80211_set_tid_config(struct sk_buff
*skb
,
14228 struct genl_info
*info
)
14230 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14231 struct nlattr
*attrs
[NL80211_TID_CONFIG_ATTR_MAX
+ 1];
14232 struct net_device
*dev
= info
->user_ptr
[1];
14233 struct cfg80211_tid_config
*tid_config
;
14234 struct nlattr
*tid
;
14235 int conf_idx
= 0, rem_conf
;
14239 if (!info
->attrs
[NL80211_ATTR_TID_CONFIG
])
14242 if (!rdev
->ops
->set_tid_config
)
14243 return -EOPNOTSUPP
;
14245 nla_for_each_nested(tid
, info
->attrs
[NL80211_ATTR_TID_CONFIG
],
14249 tid_config
= kzalloc(struct_size(tid_config
, tid_conf
, num_conf
),
14254 tid_config
->n_tid_conf
= num_conf
;
14256 if (info
->attrs
[NL80211_ATTR_MAC
])
14257 tid_config
->peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14259 nla_for_each_nested(tid
, info
->attrs
[NL80211_ATTR_TID_CONFIG
],
14261 ret
= nla_parse_nested(attrs
, NL80211_TID_CONFIG_ATTR_MAX
,
14267 ret
= parse_tid_conf(rdev
, attrs
, dev
,
14268 &tid_config
->tid_conf
[conf_idx
],
14269 info
, tid_config
->peer
);
14276 ret
= rdev_set_tid_config(rdev
, dev
, tid_config
);
14283 #define NL80211_FLAG_NEED_WIPHY 0x01
14284 #define NL80211_FLAG_NEED_NETDEV 0x02
14285 #define NL80211_FLAG_NEED_RTNL 0x04
14286 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
14287 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
14288 NL80211_FLAG_CHECK_NETDEV_UP)
14289 #define NL80211_FLAG_NEED_WDEV 0x10
14290 /* If a netdev is associated, it must be UP, P2P must be started */
14291 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
14292 NL80211_FLAG_CHECK_NETDEV_UP)
14293 #define NL80211_FLAG_CLEAR_SKB 0x20
14295 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
14296 struct genl_info
*info
)
14298 struct cfg80211_registered_device
*rdev
;
14299 struct wireless_dev
*wdev
;
14300 struct net_device
*dev
;
14301 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
14306 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
14307 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
14308 if (IS_ERR(rdev
)) {
14311 return PTR_ERR(rdev
);
14313 info
->user_ptr
[0] = rdev
;
14314 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
14315 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
14318 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
14320 if (IS_ERR(wdev
)) {
14323 return PTR_ERR(wdev
);
14326 dev
= wdev
->netdev
;
14327 rdev
= wiphy_to_rdev(wdev
->wiphy
);
14329 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
14336 info
->user_ptr
[1] = dev
;
14338 info
->user_ptr
[1] = wdev
;
14341 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
14342 !wdev_running(wdev
)) {
14351 info
->user_ptr
[0] = rdev
;
14357 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
14358 struct genl_info
*info
)
14360 if (info
->user_ptr
[1]) {
14361 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
14362 struct wireless_dev
*wdev
= info
->user_ptr
[1];
14365 dev_put(wdev
->netdev
);
14367 dev_put(info
->user_ptr
[1]);
14371 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
14374 /* If needed, clear the netlink message payload from the SKB
14375 * as it might contain key data that shouldn't stick around on
14376 * the heap after the SKB is freed. The netlink message header
14377 * is still needed for further processing, so leave it intact.
14379 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
14380 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
14382 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
14386 static const struct genl_ops nl80211_ops
[] = {
14388 .cmd
= NL80211_CMD_GET_WIPHY
,
14389 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14390 .doit
= nl80211_get_wiphy
,
14391 .dumpit
= nl80211_dump_wiphy
,
14392 .done
= nl80211_dump_wiphy_done
,
14393 /* can be retrieved by unprivileged users */
14394 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14395 NL80211_FLAG_NEED_RTNL
,
14398 .cmd
= NL80211_CMD_SET_WIPHY
,
14399 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14400 .doit
= nl80211_set_wiphy
,
14401 .flags
= GENL_UNS_ADMIN_PERM
,
14402 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
14405 .cmd
= NL80211_CMD_GET_INTERFACE
,
14406 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14407 .doit
= nl80211_get_interface
,
14408 .dumpit
= nl80211_dump_interface
,
14409 /* can be retrieved by unprivileged users */
14410 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
14411 NL80211_FLAG_NEED_RTNL
,
14414 .cmd
= NL80211_CMD_SET_INTERFACE
,
14415 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14416 .doit
= nl80211_set_interface
,
14417 .flags
= GENL_UNS_ADMIN_PERM
,
14418 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14419 NL80211_FLAG_NEED_RTNL
,
14422 .cmd
= NL80211_CMD_NEW_INTERFACE
,
14423 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14424 .doit
= nl80211_new_interface
,
14425 .flags
= GENL_UNS_ADMIN_PERM
,
14426 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14427 NL80211_FLAG_NEED_RTNL
,
14430 .cmd
= NL80211_CMD_DEL_INTERFACE
,
14431 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14432 .doit
= nl80211_del_interface
,
14433 .flags
= GENL_UNS_ADMIN_PERM
,
14434 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
14435 NL80211_FLAG_NEED_RTNL
,
14438 .cmd
= NL80211_CMD_GET_KEY
,
14439 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14440 .doit
= nl80211_get_key
,
14441 .flags
= GENL_UNS_ADMIN_PERM
,
14442 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14443 NL80211_FLAG_NEED_RTNL
,
14446 .cmd
= NL80211_CMD_SET_KEY
,
14447 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14448 .doit
= nl80211_set_key
,
14449 .flags
= GENL_UNS_ADMIN_PERM
,
14450 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14451 NL80211_FLAG_NEED_RTNL
|
14452 NL80211_FLAG_CLEAR_SKB
,
14455 .cmd
= NL80211_CMD_NEW_KEY
,
14456 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14457 .doit
= nl80211_new_key
,
14458 .flags
= GENL_UNS_ADMIN_PERM
,
14459 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14460 NL80211_FLAG_NEED_RTNL
|
14461 NL80211_FLAG_CLEAR_SKB
,
14464 .cmd
= NL80211_CMD_DEL_KEY
,
14465 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14466 .doit
= nl80211_del_key
,
14467 .flags
= GENL_UNS_ADMIN_PERM
,
14468 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14469 NL80211_FLAG_NEED_RTNL
,
14472 .cmd
= NL80211_CMD_SET_BEACON
,
14473 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14474 .flags
= GENL_UNS_ADMIN_PERM
,
14475 .doit
= nl80211_set_beacon
,
14476 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14477 NL80211_FLAG_NEED_RTNL
,
14480 .cmd
= NL80211_CMD_START_AP
,
14481 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14482 .flags
= GENL_UNS_ADMIN_PERM
,
14483 .doit
= nl80211_start_ap
,
14484 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14485 NL80211_FLAG_NEED_RTNL
,
14488 .cmd
= NL80211_CMD_STOP_AP
,
14489 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14490 .flags
= GENL_UNS_ADMIN_PERM
,
14491 .doit
= nl80211_stop_ap
,
14492 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14493 NL80211_FLAG_NEED_RTNL
,
14496 .cmd
= NL80211_CMD_GET_STATION
,
14497 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14498 .doit
= nl80211_get_station
,
14499 .dumpit
= nl80211_dump_station
,
14500 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14501 NL80211_FLAG_NEED_RTNL
,
14504 .cmd
= NL80211_CMD_SET_STATION
,
14505 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14506 .doit
= nl80211_set_station
,
14507 .flags
= GENL_UNS_ADMIN_PERM
,
14508 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14509 NL80211_FLAG_NEED_RTNL
,
14512 .cmd
= NL80211_CMD_NEW_STATION
,
14513 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14514 .doit
= nl80211_new_station
,
14515 .flags
= GENL_UNS_ADMIN_PERM
,
14516 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14517 NL80211_FLAG_NEED_RTNL
,
14520 .cmd
= NL80211_CMD_DEL_STATION
,
14521 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14522 .doit
= nl80211_del_station
,
14523 .flags
= GENL_UNS_ADMIN_PERM
,
14524 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14525 NL80211_FLAG_NEED_RTNL
,
14528 .cmd
= NL80211_CMD_GET_MPATH
,
14529 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14530 .doit
= nl80211_get_mpath
,
14531 .dumpit
= nl80211_dump_mpath
,
14532 .flags
= GENL_UNS_ADMIN_PERM
,
14533 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14534 NL80211_FLAG_NEED_RTNL
,
14537 .cmd
= NL80211_CMD_GET_MPP
,
14538 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14539 .doit
= nl80211_get_mpp
,
14540 .dumpit
= nl80211_dump_mpp
,
14541 .flags
= GENL_UNS_ADMIN_PERM
,
14542 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14543 NL80211_FLAG_NEED_RTNL
,
14546 .cmd
= NL80211_CMD_SET_MPATH
,
14547 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14548 .doit
= nl80211_set_mpath
,
14549 .flags
= GENL_UNS_ADMIN_PERM
,
14550 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14551 NL80211_FLAG_NEED_RTNL
,
14554 .cmd
= NL80211_CMD_NEW_MPATH
,
14555 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14556 .doit
= nl80211_new_mpath
,
14557 .flags
= GENL_UNS_ADMIN_PERM
,
14558 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14559 NL80211_FLAG_NEED_RTNL
,
14562 .cmd
= NL80211_CMD_DEL_MPATH
,
14563 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14564 .doit
= nl80211_del_mpath
,
14565 .flags
= GENL_UNS_ADMIN_PERM
,
14566 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14567 NL80211_FLAG_NEED_RTNL
,
14570 .cmd
= NL80211_CMD_SET_BSS
,
14571 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14572 .doit
= nl80211_set_bss
,
14573 .flags
= GENL_UNS_ADMIN_PERM
,
14574 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14575 NL80211_FLAG_NEED_RTNL
,
14578 .cmd
= NL80211_CMD_GET_REG
,
14579 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14580 .doit
= nl80211_get_reg_do
,
14581 .dumpit
= nl80211_get_reg_dump
,
14582 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
14583 /* can be retrieved by unprivileged users */
14585 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
14587 .cmd
= NL80211_CMD_SET_REG
,
14588 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14589 .doit
= nl80211_set_reg
,
14590 .flags
= GENL_ADMIN_PERM
,
14591 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
14595 .cmd
= NL80211_CMD_REQ_SET_REG
,
14596 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14597 .doit
= nl80211_req_set_reg
,
14598 .flags
= GENL_ADMIN_PERM
,
14601 .cmd
= NL80211_CMD_RELOAD_REGDB
,
14602 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14603 .doit
= nl80211_reload_regdb
,
14604 .flags
= GENL_ADMIN_PERM
,
14607 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
14608 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14609 .doit
= nl80211_get_mesh_config
,
14610 /* can be retrieved by unprivileged users */
14611 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14612 NL80211_FLAG_NEED_RTNL
,
14615 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
14616 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14617 .doit
= nl80211_update_mesh_config
,
14618 .flags
= GENL_UNS_ADMIN_PERM
,
14619 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14620 NL80211_FLAG_NEED_RTNL
,
14623 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
14624 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14625 .doit
= nl80211_trigger_scan
,
14626 .flags
= GENL_UNS_ADMIN_PERM
,
14627 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
14628 NL80211_FLAG_NEED_RTNL
,
14631 .cmd
= NL80211_CMD_ABORT_SCAN
,
14632 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14633 .doit
= nl80211_abort_scan
,
14634 .flags
= GENL_UNS_ADMIN_PERM
,
14635 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
14636 NL80211_FLAG_NEED_RTNL
,
14639 .cmd
= NL80211_CMD_GET_SCAN
,
14640 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14641 .dumpit
= nl80211_dump_scan
,
14644 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
14645 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14646 .doit
= nl80211_start_sched_scan
,
14647 .flags
= GENL_UNS_ADMIN_PERM
,
14648 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14649 NL80211_FLAG_NEED_RTNL
,
14652 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
14653 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14654 .doit
= nl80211_stop_sched_scan
,
14655 .flags
= GENL_UNS_ADMIN_PERM
,
14656 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14657 NL80211_FLAG_NEED_RTNL
,
14660 .cmd
= NL80211_CMD_AUTHENTICATE
,
14661 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14662 .doit
= nl80211_authenticate
,
14663 .flags
= GENL_UNS_ADMIN_PERM
,
14664 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14665 NL80211_FLAG_NEED_RTNL
|
14666 NL80211_FLAG_CLEAR_SKB
,
14669 .cmd
= NL80211_CMD_ASSOCIATE
,
14670 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14671 .doit
= nl80211_associate
,
14672 .flags
= GENL_UNS_ADMIN_PERM
,
14673 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14674 NL80211_FLAG_NEED_RTNL
|
14675 NL80211_FLAG_CLEAR_SKB
,
14678 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
14679 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14680 .doit
= nl80211_deauthenticate
,
14681 .flags
= GENL_UNS_ADMIN_PERM
,
14682 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14683 NL80211_FLAG_NEED_RTNL
,
14686 .cmd
= NL80211_CMD_DISASSOCIATE
,
14687 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14688 .doit
= nl80211_disassociate
,
14689 .flags
= GENL_UNS_ADMIN_PERM
,
14690 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14691 NL80211_FLAG_NEED_RTNL
,
14694 .cmd
= NL80211_CMD_JOIN_IBSS
,
14695 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14696 .doit
= nl80211_join_ibss
,
14697 .flags
= GENL_UNS_ADMIN_PERM
,
14698 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14699 NL80211_FLAG_NEED_RTNL
,
14702 .cmd
= NL80211_CMD_LEAVE_IBSS
,
14703 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14704 .doit
= nl80211_leave_ibss
,
14705 .flags
= GENL_UNS_ADMIN_PERM
,
14706 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14707 NL80211_FLAG_NEED_RTNL
,
14709 #ifdef CONFIG_NL80211_TESTMODE
14711 .cmd
= NL80211_CMD_TESTMODE
,
14712 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14713 .doit
= nl80211_testmode_do
,
14714 .dumpit
= nl80211_testmode_dump
,
14715 .flags
= GENL_UNS_ADMIN_PERM
,
14716 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14717 NL80211_FLAG_NEED_RTNL
,
14721 .cmd
= NL80211_CMD_CONNECT
,
14722 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14723 .doit
= nl80211_connect
,
14724 .flags
= GENL_UNS_ADMIN_PERM
,
14725 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14726 NL80211_FLAG_NEED_RTNL
|
14727 NL80211_FLAG_CLEAR_SKB
,
14730 .cmd
= NL80211_CMD_UPDATE_CONNECT_PARAMS
,
14731 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14732 .doit
= nl80211_update_connect_params
,
14733 .flags
= GENL_ADMIN_PERM
,
14734 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14735 NL80211_FLAG_NEED_RTNL
|
14736 NL80211_FLAG_CLEAR_SKB
,
14739 .cmd
= NL80211_CMD_DISCONNECT
,
14740 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14741 .doit
= nl80211_disconnect
,
14742 .flags
= GENL_UNS_ADMIN_PERM
,
14743 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14744 NL80211_FLAG_NEED_RTNL
,
14747 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
14748 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14749 .doit
= nl80211_wiphy_netns
,
14750 .flags
= GENL_UNS_ADMIN_PERM
,
14751 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14752 NL80211_FLAG_NEED_RTNL
,
14755 .cmd
= NL80211_CMD_GET_SURVEY
,
14756 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14757 .dumpit
= nl80211_dump_survey
,
14760 .cmd
= NL80211_CMD_SET_PMKSA
,
14761 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14762 .doit
= nl80211_setdel_pmksa
,
14763 .flags
= GENL_UNS_ADMIN_PERM
,
14764 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14765 NL80211_FLAG_NEED_RTNL
|
14766 NL80211_FLAG_CLEAR_SKB
,
14769 .cmd
= NL80211_CMD_DEL_PMKSA
,
14770 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14771 .doit
= nl80211_setdel_pmksa
,
14772 .flags
= GENL_UNS_ADMIN_PERM
,
14773 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14774 NL80211_FLAG_NEED_RTNL
,
14777 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
14778 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14779 .doit
= nl80211_flush_pmksa
,
14780 .flags
= GENL_UNS_ADMIN_PERM
,
14781 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14782 NL80211_FLAG_NEED_RTNL
,
14785 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
14786 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14787 .doit
= nl80211_remain_on_channel
,
14788 .flags
= GENL_UNS_ADMIN_PERM
,
14789 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
14790 NL80211_FLAG_NEED_RTNL
,
14793 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
14794 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14795 .doit
= nl80211_cancel_remain_on_channel
,
14796 .flags
= GENL_UNS_ADMIN_PERM
,
14797 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
14798 NL80211_FLAG_NEED_RTNL
,
14801 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
14802 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14803 .doit
= nl80211_set_tx_bitrate_mask
,
14804 .flags
= GENL_UNS_ADMIN_PERM
,
14805 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14806 NL80211_FLAG_NEED_RTNL
,
14809 .cmd
= NL80211_CMD_REGISTER_FRAME
,
14810 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14811 .doit
= nl80211_register_mgmt
,
14812 .flags
= GENL_UNS_ADMIN_PERM
,
14813 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
14814 NL80211_FLAG_NEED_RTNL
,
14817 .cmd
= NL80211_CMD_FRAME
,
14818 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14819 .doit
= nl80211_tx_mgmt
,
14820 .flags
= GENL_UNS_ADMIN_PERM
,
14821 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
14822 NL80211_FLAG_NEED_RTNL
,
14825 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
14826 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14827 .doit
= nl80211_tx_mgmt_cancel_wait
,
14828 .flags
= GENL_UNS_ADMIN_PERM
,
14829 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
14830 NL80211_FLAG_NEED_RTNL
,
14833 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
14834 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14835 .doit
= nl80211_set_power_save
,
14836 .flags
= GENL_UNS_ADMIN_PERM
,
14837 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14838 NL80211_FLAG_NEED_RTNL
,
14841 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
14842 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14843 .doit
= nl80211_get_power_save
,
14844 /* can be retrieved by unprivileged users */
14845 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14846 NL80211_FLAG_NEED_RTNL
,
14849 .cmd
= NL80211_CMD_SET_CQM
,
14850 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14851 .doit
= nl80211_set_cqm
,
14852 .flags
= GENL_UNS_ADMIN_PERM
,
14853 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14854 NL80211_FLAG_NEED_RTNL
,
14857 .cmd
= NL80211_CMD_SET_CHANNEL
,
14858 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14859 .doit
= nl80211_set_channel
,
14860 .flags
= GENL_UNS_ADMIN_PERM
,
14861 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14862 NL80211_FLAG_NEED_RTNL
,
14865 .cmd
= NL80211_CMD_SET_WDS_PEER
,
14866 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14867 .doit
= nl80211_set_wds_peer
,
14868 .flags
= GENL_UNS_ADMIN_PERM
,
14869 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14870 NL80211_FLAG_NEED_RTNL
,
14873 .cmd
= NL80211_CMD_JOIN_MESH
,
14874 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14875 .doit
= nl80211_join_mesh
,
14876 .flags
= GENL_UNS_ADMIN_PERM
,
14877 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14878 NL80211_FLAG_NEED_RTNL
,
14881 .cmd
= NL80211_CMD_LEAVE_MESH
,
14882 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14883 .doit
= nl80211_leave_mesh
,
14884 .flags
= GENL_UNS_ADMIN_PERM
,
14885 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14886 NL80211_FLAG_NEED_RTNL
,
14889 .cmd
= NL80211_CMD_JOIN_OCB
,
14890 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14891 .doit
= nl80211_join_ocb
,
14892 .flags
= GENL_UNS_ADMIN_PERM
,
14893 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14894 NL80211_FLAG_NEED_RTNL
,
14897 .cmd
= NL80211_CMD_LEAVE_OCB
,
14898 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14899 .doit
= nl80211_leave_ocb
,
14900 .flags
= GENL_UNS_ADMIN_PERM
,
14901 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14902 NL80211_FLAG_NEED_RTNL
,
14906 .cmd
= NL80211_CMD_GET_WOWLAN
,
14907 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14908 .doit
= nl80211_get_wowlan
,
14909 /* can be retrieved by unprivileged users */
14910 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14911 NL80211_FLAG_NEED_RTNL
,
14914 .cmd
= NL80211_CMD_SET_WOWLAN
,
14915 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14916 .doit
= nl80211_set_wowlan
,
14917 .flags
= GENL_UNS_ADMIN_PERM
,
14918 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14919 NL80211_FLAG_NEED_RTNL
,
14923 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
14924 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14925 .doit
= nl80211_set_rekey_data
,
14926 .flags
= GENL_UNS_ADMIN_PERM
,
14927 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14928 NL80211_FLAG_NEED_RTNL
|
14929 NL80211_FLAG_CLEAR_SKB
,
14932 .cmd
= NL80211_CMD_TDLS_MGMT
,
14933 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14934 .doit
= nl80211_tdls_mgmt
,
14935 .flags
= GENL_UNS_ADMIN_PERM
,
14936 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14937 NL80211_FLAG_NEED_RTNL
,
14940 .cmd
= NL80211_CMD_TDLS_OPER
,
14941 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14942 .doit
= nl80211_tdls_oper
,
14943 .flags
= GENL_UNS_ADMIN_PERM
,
14944 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14945 NL80211_FLAG_NEED_RTNL
,
14948 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
14949 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14950 .doit
= nl80211_register_unexpected_frame
,
14951 .flags
= GENL_UNS_ADMIN_PERM
,
14952 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14953 NL80211_FLAG_NEED_RTNL
,
14956 .cmd
= NL80211_CMD_PROBE_CLIENT
,
14957 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14958 .doit
= nl80211_probe_client
,
14959 .flags
= GENL_UNS_ADMIN_PERM
,
14960 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14961 NL80211_FLAG_NEED_RTNL
,
14964 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
14965 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14966 .doit
= nl80211_register_beacons
,
14967 .flags
= GENL_UNS_ADMIN_PERM
,
14968 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14969 NL80211_FLAG_NEED_RTNL
,
14972 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
14973 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14974 .doit
= nl80211_set_noack_map
,
14975 .flags
= GENL_UNS_ADMIN_PERM
,
14976 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14977 NL80211_FLAG_NEED_RTNL
,
14980 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
14981 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14982 .doit
= nl80211_start_p2p_device
,
14983 .flags
= GENL_UNS_ADMIN_PERM
,
14984 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
14985 NL80211_FLAG_NEED_RTNL
,
14988 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
14989 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14990 .doit
= nl80211_stop_p2p_device
,
14991 .flags
= GENL_UNS_ADMIN_PERM
,
14992 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
14993 NL80211_FLAG_NEED_RTNL
,
14996 .cmd
= NL80211_CMD_START_NAN
,
14997 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14998 .doit
= nl80211_start_nan
,
14999 .flags
= GENL_ADMIN_PERM
,
15000 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
15001 NL80211_FLAG_NEED_RTNL
,
15004 .cmd
= NL80211_CMD_STOP_NAN
,
15005 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15006 .doit
= nl80211_stop_nan
,
15007 .flags
= GENL_ADMIN_PERM
,
15008 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15009 NL80211_FLAG_NEED_RTNL
,
15012 .cmd
= NL80211_CMD_ADD_NAN_FUNCTION
,
15013 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15014 .doit
= nl80211_nan_add_func
,
15015 .flags
= GENL_ADMIN_PERM
,
15016 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15017 NL80211_FLAG_NEED_RTNL
,
15020 .cmd
= NL80211_CMD_DEL_NAN_FUNCTION
,
15021 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15022 .doit
= nl80211_nan_del_func
,
15023 .flags
= GENL_ADMIN_PERM
,
15024 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15025 NL80211_FLAG_NEED_RTNL
,
15028 .cmd
= NL80211_CMD_CHANGE_NAN_CONFIG
,
15029 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15030 .doit
= nl80211_nan_change_config
,
15031 .flags
= GENL_ADMIN_PERM
,
15032 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15033 NL80211_FLAG_NEED_RTNL
,
15036 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
15037 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15038 .doit
= nl80211_set_mcast_rate
,
15039 .flags
= GENL_UNS_ADMIN_PERM
,
15040 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15041 NL80211_FLAG_NEED_RTNL
,
15044 .cmd
= NL80211_CMD_SET_MAC_ACL
,
15045 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15046 .doit
= nl80211_set_mac_acl
,
15047 .flags
= GENL_UNS_ADMIN_PERM
,
15048 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15049 NL80211_FLAG_NEED_RTNL
,
15052 .cmd
= NL80211_CMD_RADAR_DETECT
,
15053 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15054 .doit
= nl80211_start_radar_detection
,
15055 .flags
= GENL_UNS_ADMIN_PERM
,
15056 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15057 NL80211_FLAG_NEED_RTNL
,
15060 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
15061 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15062 .doit
= nl80211_get_protocol_features
,
15065 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
15066 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15067 .doit
= nl80211_update_ft_ies
,
15068 .flags
= GENL_UNS_ADMIN_PERM
,
15069 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15070 NL80211_FLAG_NEED_RTNL
,
15073 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
15074 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15075 .doit
= nl80211_crit_protocol_start
,
15076 .flags
= GENL_UNS_ADMIN_PERM
,
15077 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15078 NL80211_FLAG_NEED_RTNL
,
15081 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
15082 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15083 .doit
= nl80211_crit_protocol_stop
,
15084 .flags
= GENL_UNS_ADMIN_PERM
,
15085 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15086 NL80211_FLAG_NEED_RTNL
,
15089 .cmd
= NL80211_CMD_GET_COALESCE
,
15090 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15091 .doit
= nl80211_get_coalesce
,
15092 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15093 NL80211_FLAG_NEED_RTNL
,
15096 .cmd
= NL80211_CMD_SET_COALESCE
,
15097 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15098 .doit
= nl80211_set_coalesce
,
15099 .flags
= GENL_UNS_ADMIN_PERM
,
15100 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15101 NL80211_FLAG_NEED_RTNL
,
15104 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
15105 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15106 .doit
= nl80211_channel_switch
,
15107 .flags
= GENL_UNS_ADMIN_PERM
,
15108 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15109 NL80211_FLAG_NEED_RTNL
,
15112 .cmd
= NL80211_CMD_VENDOR
,
15113 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15114 .doit
= nl80211_vendor_cmd
,
15115 .dumpit
= nl80211_vendor_cmd_dump
,
15116 .flags
= GENL_UNS_ADMIN_PERM
,
15117 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15118 NL80211_FLAG_NEED_RTNL
|
15119 NL80211_FLAG_CLEAR_SKB
,
15122 .cmd
= NL80211_CMD_SET_QOS_MAP
,
15123 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15124 .doit
= nl80211_set_qos_map
,
15125 .flags
= GENL_UNS_ADMIN_PERM
,
15126 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15127 NL80211_FLAG_NEED_RTNL
,
15130 .cmd
= NL80211_CMD_ADD_TX_TS
,
15131 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15132 .doit
= nl80211_add_tx_ts
,
15133 .flags
= GENL_UNS_ADMIN_PERM
,
15134 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15135 NL80211_FLAG_NEED_RTNL
,
15138 .cmd
= NL80211_CMD_DEL_TX_TS
,
15139 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15140 .doit
= nl80211_del_tx_ts
,
15141 .flags
= GENL_UNS_ADMIN_PERM
,
15142 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15143 NL80211_FLAG_NEED_RTNL
,
15146 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
15147 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15148 .doit
= nl80211_tdls_channel_switch
,
15149 .flags
= GENL_UNS_ADMIN_PERM
,
15150 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15151 NL80211_FLAG_NEED_RTNL
,
15154 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
15155 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15156 .doit
= nl80211_tdls_cancel_channel_switch
,
15157 .flags
= GENL_UNS_ADMIN_PERM
,
15158 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15159 NL80211_FLAG_NEED_RTNL
,
15162 .cmd
= NL80211_CMD_SET_MULTICAST_TO_UNICAST
,
15163 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15164 .doit
= nl80211_set_multicast_to_unicast
,
15165 .flags
= GENL_UNS_ADMIN_PERM
,
15166 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15167 NL80211_FLAG_NEED_RTNL
,
15170 .cmd
= NL80211_CMD_SET_PMK
,
15171 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15172 .doit
= nl80211_set_pmk
,
15173 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15174 NL80211_FLAG_NEED_RTNL
|
15175 NL80211_FLAG_CLEAR_SKB
,
15178 .cmd
= NL80211_CMD_DEL_PMK
,
15179 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15180 .doit
= nl80211_del_pmk
,
15181 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15182 NL80211_FLAG_NEED_RTNL
,
15185 .cmd
= NL80211_CMD_EXTERNAL_AUTH
,
15186 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15187 .doit
= nl80211_external_auth
,
15188 .flags
= GENL_ADMIN_PERM
,
15189 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15190 NL80211_FLAG_NEED_RTNL
,
15193 .cmd
= NL80211_CMD_CONTROL_PORT_FRAME
,
15194 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15195 .doit
= nl80211_tx_control_port
,
15196 .flags
= GENL_UNS_ADMIN_PERM
,
15197 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15198 NL80211_FLAG_NEED_RTNL
,
15201 .cmd
= NL80211_CMD_GET_FTM_RESPONDER_STATS
,
15202 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15203 .doit
= nl80211_get_ftm_responder_stats
,
15204 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15205 NL80211_FLAG_NEED_RTNL
,
15208 .cmd
= NL80211_CMD_PEER_MEASUREMENT_START
,
15209 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15210 .doit
= nl80211_pmsr_start
,
15211 .flags
= GENL_UNS_ADMIN_PERM
,
15212 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15213 NL80211_FLAG_NEED_RTNL
,
15216 .cmd
= NL80211_CMD_NOTIFY_RADAR
,
15217 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15218 .doit
= nl80211_notify_radar_detection
,
15219 .flags
= GENL_UNS_ADMIN_PERM
,
15220 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15221 NL80211_FLAG_NEED_RTNL
,
15224 .cmd
= NL80211_CMD_UPDATE_OWE_INFO
,
15225 .doit
= nl80211_update_owe_info
,
15226 .flags
= GENL_ADMIN_PERM
,
15227 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15228 NL80211_FLAG_NEED_RTNL
,
15231 .cmd
= NL80211_CMD_PROBE_MESH_LINK
,
15232 .doit
= nl80211_probe_mesh_link
,
15233 .flags
= GENL_UNS_ADMIN_PERM
,
15234 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15235 NL80211_FLAG_NEED_RTNL
,
15238 .cmd
= NL80211_CMD_SET_TID_CONFIG
,
15239 .doit
= nl80211_set_tid_config
,
15240 .flags
= GENL_UNS_ADMIN_PERM
,
15241 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15242 NL80211_FLAG_NEED_RTNL
,
15246 static struct genl_family nl80211_fam __ro_after_init
= {
15247 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
15248 .hdrsize
= 0, /* no private header */
15249 .version
= 1, /* no particular meaning now */
15250 .maxattr
= NL80211_ATTR_MAX
,
15251 .policy
= nl80211_policy
,
15253 .pre_doit
= nl80211_pre_doit
,
15254 .post_doit
= nl80211_post_doit
,
15255 .module
= THIS_MODULE
,
15256 .ops
= nl80211_ops
,
15257 .n_ops
= ARRAY_SIZE(nl80211_ops
),
15258 .mcgrps
= nl80211_mcgrps
,
15259 .n_mcgrps
= ARRAY_SIZE(nl80211_mcgrps
),
15260 .parallel_ops
= true,
15263 /* notification functions */
15265 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
15266 enum nl80211_commands cmd
)
15268 struct sk_buff
*msg
;
15269 struct nl80211_dump_wiphy_state state
= {};
15271 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
15272 cmd
!= NL80211_CMD_DEL_WIPHY
);
15274 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15278 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
15283 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15284 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
15287 void nl80211_notify_iface(struct cfg80211_registered_device
*rdev
,
15288 struct wireless_dev
*wdev
,
15289 enum nl80211_commands cmd
)
15291 struct sk_buff
*msg
;
15293 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15297 if (nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
, cmd
) < 0) {
15302 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15303 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
15306 static int nl80211_add_scan_req(struct sk_buff
*msg
,
15307 struct cfg80211_registered_device
*rdev
)
15309 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
15310 struct nlattr
*nest
;
15316 nest
= nla_nest_start_noflag(msg
, NL80211_ATTR_SCAN_SSIDS
);
15318 goto nla_put_failure
;
15319 for (i
= 0; i
< req
->n_ssids
; i
++) {
15320 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
15321 goto nla_put_failure
;
15323 nla_nest_end(msg
, nest
);
15325 if (req
->flags
& NL80211_SCAN_FLAG_FREQ_KHZ
) {
15326 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQ_KHZ
);
15328 goto nla_put_failure
;
15329 for (i
= 0; i
< req
->n_channels
; i
++) {
15330 if (nla_put_u32(msg
, i
,
15331 ieee80211_channel_to_khz(req
->channels
[i
])))
15332 goto nla_put_failure
;
15334 nla_nest_end(msg
, nest
);
15336 nest
= nla_nest_start_noflag(msg
,
15337 NL80211_ATTR_SCAN_FREQUENCIES
);
15339 goto nla_put_failure
;
15340 for (i
= 0; i
< req
->n_channels
; i
++) {
15341 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
15342 goto nla_put_failure
;
15344 nla_nest_end(msg
, nest
);
15348 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
15349 goto nla_put_failure
;
15352 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
15353 goto nla_put_failure
;
15355 if (req
->info
.scan_start_tsf
&&
15356 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
15357 req
->info
.scan_start_tsf
, NL80211_BSS_PAD
) ||
15358 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
15359 req
->info
.tsf_bssid
)))
15360 goto nla_put_failure
;
15367 static int nl80211_prep_scan_msg(struct sk_buff
*msg
,
15368 struct cfg80211_registered_device
*rdev
,
15369 struct wireless_dev
*wdev
,
15370 u32 portid
, u32 seq
, int flags
,
15375 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
15379 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15380 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
15381 wdev
->netdev
->ifindex
)) ||
15382 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15384 goto nla_put_failure
;
15386 /* ignore errors and send incomplete event anyway */
15387 nl80211_add_scan_req(msg
, rdev
);
15389 genlmsg_end(msg
, hdr
);
15393 genlmsg_cancel(msg
, hdr
);
15398 nl80211_prep_sched_scan_msg(struct sk_buff
*msg
,
15399 struct cfg80211_sched_scan_request
*req
, u32 cmd
)
15403 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
15407 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
,
15408 wiphy_to_rdev(req
->wiphy
)->wiphy_idx
) ||
15409 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, req
->dev
->ifindex
) ||
15410 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, req
->reqid
,
15412 goto nla_put_failure
;
15414 genlmsg_end(msg
, hdr
);
15418 genlmsg_cancel(msg
, hdr
);
15422 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
15423 struct wireless_dev
*wdev
)
15425 struct sk_buff
*msg
;
15427 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15431 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
15432 NL80211_CMD_TRIGGER_SCAN
) < 0) {
15437 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15438 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
15441 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
15442 struct wireless_dev
*wdev
, bool aborted
)
15444 struct sk_buff
*msg
;
15446 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15450 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
15451 aborted
? NL80211_CMD_SCAN_ABORTED
:
15452 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
15460 /* send message created by nl80211_build_scan_msg() */
15461 void nl80211_send_scan_msg(struct cfg80211_registered_device
*rdev
,
15462 struct sk_buff
*msg
)
15467 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15468 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
15471 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request
*req
, u32 cmd
)
15473 struct sk_buff
*msg
;
15475 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15479 if (nl80211_prep_sched_scan_msg(msg
, req
, cmd
) < 0) {
15484 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(req
->wiphy
), msg
, 0,
15485 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
15488 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
15489 struct regulatory_request
*request
)
15491 /* Userspace can always count this one always being set */
15492 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
15493 goto nla_put_failure
;
15495 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
15496 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15497 NL80211_REGDOM_TYPE_WORLD
))
15498 goto nla_put_failure
;
15499 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
15500 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15501 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
15502 goto nla_put_failure
;
15503 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
15504 request
->intersect
) {
15505 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15506 NL80211_REGDOM_TYPE_INTERSECTION
))
15507 goto nla_put_failure
;
15509 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15510 NL80211_REGDOM_TYPE_COUNTRY
) ||
15511 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
15513 goto nla_put_failure
;
15516 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
15517 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
15520 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
15521 goto nla_put_failure
;
15524 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
15525 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
15526 goto nla_put_failure
;
15536 * This can happen on global regulatory changes or device specific settings
15537 * based on custom regulatory domains.
15539 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
15540 struct regulatory_request
*request
)
15542 struct sk_buff
*msg
;
15545 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15549 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
15551 goto nla_put_failure
;
15553 if (!nl80211_reg_change_event_fill(msg
, request
))
15554 goto nla_put_failure
;
15556 genlmsg_end(msg
, hdr
);
15559 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
15560 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
15569 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
15570 struct net_device
*netdev
,
15571 const u8
*buf
, size_t len
,
15572 enum nl80211_commands cmd
, gfp_t gfp
,
15573 int uapsd_queues
, const u8
*req_ies
,
15574 size_t req_ies_len
)
15576 struct sk_buff
*msg
;
15579 msg
= nlmsg_new(100 + len
+ req_ies_len
, gfp
);
15583 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
15589 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15590 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15591 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
15593 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ies_len
, req_ies
)))
15594 goto nla_put_failure
;
15596 if (uapsd_queues
>= 0) {
15597 struct nlattr
*nla_wmm
=
15598 nla_nest_start_noflag(msg
, NL80211_ATTR_STA_WME
);
15600 goto nla_put_failure
;
15602 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
15604 goto nla_put_failure
;
15606 nla_nest_end(msg
, nla_wmm
);
15609 genlmsg_end(msg
, hdr
);
15611 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15612 NL80211_MCGRP_MLME
, gfp
);
15619 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
15620 struct net_device
*netdev
, const u8
*buf
,
15621 size_t len
, gfp_t gfp
)
15623 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
15624 NL80211_CMD_AUTHENTICATE
, gfp
, -1, NULL
, 0);
15627 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
15628 struct net_device
*netdev
, const u8
*buf
,
15629 size_t len
, gfp_t gfp
, int uapsd_queues
,
15630 const u8
*req_ies
, size_t req_ies_len
)
15632 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
15633 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
,
15634 req_ies
, req_ies_len
);
15637 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
15638 struct net_device
*netdev
, const u8
*buf
,
15639 size_t len
, gfp_t gfp
)
15641 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
15642 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1, NULL
, 0);
15645 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
15646 struct net_device
*netdev
, const u8
*buf
,
15647 size_t len
, gfp_t gfp
)
15649 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
15650 NL80211_CMD_DISASSOCIATE
, gfp
, -1, NULL
, 0);
15653 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
15656 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15657 struct wiphy
*wiphy
= wdev
->wiphy
;
15658 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15659 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
15662 if (WARN_ON(len
< 2))
15665 if (ieee80211_is_deauth(mgmt
->frame_control
)) {
15666 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
15667 } else if (ieee80211_is_disassoc(mgmt
->frame_control
)) {
15668 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
15669 } else if (ieee80211_is_beacon(mgmt
->frame_control
)) {
15670 if (wdev
->unprot_beacon_reported
&&
15671 elapsed_jiffies_msecs(wdev
->unprot_beacon_reported
) < 10000)
15673 cmd
= NL80211_CMD_UNPROT_BEACON
;
15674 wdev
->unprot_beacon_reported
= jiffies
;
15679 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
15680 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1,
15683 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
15685 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
15686 struct net_device
*netdev
, int cmd
,
15687 const u8
*addr
, gfp_t gfp
)
15689 struct sk_buff
*msg
;
15692 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15696 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
15702 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15703 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15704 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
15705 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
15706 goto nla_put_failure
;
15708 genlmsg_end(msg
, hdr
);
15710 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15711 NL80211_MCGRP_MLME
, gfp
);
15718 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
15719 struct net_device
*netdev
, const u8
*addr
,
15722 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
15726 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
15727 struct net_device
*netdev
, const u8
*addr
,
15730 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
15734 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
15735 struct net_device
*netdev
,
15736 struct cfg80211_connect_resp_params
*cr
,
15739 struct sk_buff
*msg
;
15742 msg
= nlmsg_new(100 + cr
->req_ie_len
+ cr
->resp_ie_len
+
15743 cr
->fils
.kek_len
+ cr
->fils
.pmk_len
+
15744 (cr
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
15748 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
15754 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15755 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15757 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, cr
->bssid
)) ||
15758 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
15759 cr
->status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
15762 (nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
15763 nla_put_u32(msg
, NL80211_ATTR_TIMEOUT_REASON
,
15764 cr
->timeout_reason
))) ||
15766 nla_put(msg
, NL80211_ATTR_REQ_IE
, cr
->req_ie_len
, cr
->req_ie
)) ||
15768 nla_put(msg
, NL80211_ATTR_RESP_IE
, cr
->resp_ie_len
,
15770 (cr
->fils
.update_erp_next_seq_num
&&
15771 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
15772 cr
->fils
.erp_next_seq_num
)) ||
15773 (cr
->status
== WLAN_STATUS_SUCCESS
&&
15775 nla_put(msg
, NL80211_ATTR_FILS_KEK
, cr
->fils
.kek_len
,
15778 nla_put(msg
, NL80211_ATTR_PMK
, cr
->fils
.pmk_len
, cr
->fils
.pmk
)) ||
15780 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, cr
->fils
.pmkid
)))))
15781 goto nla_put_failure
;
15783 genlmsg_end(msg
, hdr
);
15785 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15786 NL80211_MCGRP_MLME
, gfp
);
15793 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
15794 struct net_device
*netdev
,
15795 struct cfg80211_roam_info
*info
, gfp_t gfp
)
15797 struct sk_buff
*msg
;
15799 const u8
*bssid
= info
->bss
? info
->bss
->bssid
: info
->bssid
;
15801 msg
= nlmsg_new(100 + info
->req_ie_len
+ info
->resp_ie_len
+
15802 info
->fils
.kek_len
+ info
->fils
.pmk_len
+
15803 (info
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
15807 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
15813 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15814 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15815 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
15817 nla_put(msg
, NL80211_ATTR_REQ_IE
, info
->req_ie_len
,
15820 nla_put(msg
, NL80211_ATTR_RESP_IE
, info
->resp_ie_len
,
15822 (info
->fils
.update_erp_next_seq_num
&&
15823 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
15824 info
->fils
.erp_next_seq_num
)) ||
15826 nla_put(msg
, NL80211_ATTR_FILS_KEK
, info
->fils
.kek_len
,
15827 info
->fils
.kek
)) ||
15829 nla_put(msg
, NL80211_ATTR_PMK
, info
->fils
.pmk_len
, info
->fils
.pmk
)) ||
15830 (info
->fils
.pmkid
&&
15831 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, info
->fils
.pmkid
)))
15832 goto nla_put_failure
;
15834 genlmsg_end(msg
, hdr
);
15836 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15837 NL80211_MCGRP_MLME
, gfp
);
15844 void nl80211_send_port_authorized(struct cfg80211_registered_device
*rdev
,
15845 struct net_device
*netdev
, const u8
*bssid
)
15847 struct sk_buff
*msg
;
15850 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15854 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED
);
15860 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15861 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15862 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
15863 goto nla_put_failure
;
15865 genlmsg_end(msg
, hdr
);
15867 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15868 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15875 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
15876 struct net_device
*netdev
, u16 reason
,
15877 const u8
*ie
, size_t ie_len
, bool from_ap
)
15879 struct sk_buff
*msg
;
15882 msg
= nlmsg_new(100 + ie_len
, GFP_KERNEL
);
15886 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
15892 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15893 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15895 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
15897 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
15898 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
15899 goto nla_put_failure
;
15901 genlmsg_end(msg
, hdr
);
15903 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15904 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15911 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
15912 struct net_device
*netdev
, const u8
*bssid
,
15915 struct sk_buff
*msg
;
15918 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15922 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
15928 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15929 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15930 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
15931 goto nla_put_failure
;
15933 genlmsg_end(msg
, hdr
);
15935 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15936 NL80211_MCGRP_MLME
, gfp
);
15943 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
15944 const u8
*ie
, u8 ie_len
,
15945 int sig_dbm
, gfp_t gfp
)
15947 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15948 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15949 struct sk_buff
*msg
;
15952 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
15955 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
15957 msg
= nlmsg_new(100 + ie_len
, gfp
);
15961 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
15967 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15968 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15969 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
15971 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)) ||
15973 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)))
15974 goto nla_put_failure
;
15976 genlmsg_end(msg
, hdr
);
15978 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15979 NL80211_MCGRP_MLME
, gfp
);
15985 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
15987 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
15988 struct net_device
*netdev
, const u8
*addr
,
15989 enum nl80211_key_type key_type
, int key_id
,
15990 const u8
*tsc
, gfp_t gfp
)
15992 struct sk_buff
*msg
;
15995 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15999 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
16005 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16006 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16007 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
16008 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
16010 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
16011 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
16012 goto nla_put_failure
;
16014 genlmsg_end(msg
, hdr
);
16016 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16017 NL80211_MCGRP_MLME
, gfp
);
16024 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
16025 struct ieee80211_channel
*channel_before
,
16026 struct ieee80211_channel
*channel_after
)
16028 struct sk_buff
*msg
;
16030 struct nlattr
*nl_freq
;
16032 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
16036 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
16043 * Since we are applying the beacon hint to a wiphy we know its
16044 * wiphy_idx is valid
16046 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
16047 goto nla_put_failure
;
16050 nl_freq
= nla_nest_start_noflag(msg
, NL80211_ATTR_FREQ_BEFORE
);
16052 goto nla_put_failure
;
16054 if (nl80211_msg_put_channel(msg
, wiphy
, channel_before
, false))
16055 goto nla_put_failure
;
16056 nla_nest_end(msg
, nl_freq
);
16059 nl_freq
= nla_nest_start_noflag(msg
, NL80211_ATTR_FREQ_AFTER
);
16061 goto nla_put_failure
;
16063 if (nl80211_msg_put_channel(msg
, wiphy
, channel_after
, false))
16064 goto nla_put_failure
;
16065 nla_nest_end(msg
, nl_freq
);
16067 genlmsg_end(msg
, hdr
);
16070 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
16071 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
16080 static void nl80211_send_remain_on_chan_event(
16081 int cmd
, struct cfg80211_registered_device
*rdev
,
16082 struct wireless_dev
*wdev
, u64 cookie
,
16083 struct ieee80211_channel
*chan
,
16084 unsigned int duration
, gfp_t gfp
)
16086 struct sk_buff
*msg
;
16089 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16093 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
16099 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16100 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
16101 wdev
->netdev
->ifindex
)) ||
16102 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16103 NL80211_ATTR_PAD
) ||
16104 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
16105 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
16106 NL80211_CHAN_NO_HT
) ||
16107 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
16109 goto nla_put_failure
;
16111 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
16112 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
16113 goto nla_put_failure
;
16115 genlmsg_end(msg
, hdr
);
16117 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16118 NL80211_MCGRP_MLME
, gfp
);
16125 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
16126 struct ieee80211_channel
*chan
,
16127 unsigned int duration
, gfp_t gfp
)
16129 struct wiphy
*wiphy
= wdev
->wiphy
;
16130 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16132 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
16133 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
16134 rdev
, wdev
, cookie
, chan
,
16137 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
16139 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
16140 struct ieee80211_channel
*chan
,
16143 struct wiphy
*wiphy
= wdev
->wiphy
;
16144 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16146 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
16147 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
16148 rdev
, wdev
, cookie
, chan
, 0, gfp
);
16150 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
16152 void cfg80211_tx_mgmt_expired(struct wireless_dev
*wdev
, u64 cookie
,
16153 struct ieee80211_channel
*chan
,
16156 struct wiphy
*wiphy
= wdev
->wiphy
;
16157 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16159 trace_cfg80211_tx_mgmt_expired(wdev
, cookie
, chan
);
16160 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL
,
16161 rdev
, wdev
, cookie
, chan
, 0, gfp
);
16163 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired
);
16165 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
16166 struct station_info
*sinfo
, gfp_t gfp
)
16168 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
16169 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16170 struct sk_buff
*msg
;
16172 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
16174 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16178 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
16179 rdev
, dev
, mac_addr
, sinfo
) < 0) {
16184 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16185 NL80211_MCGRP_MLME
, gfp
);
16187 EXPORT_SYMBOL(cfg80211_new_sta
);
16189 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
16190 struct station_info
*sinfo
, gfp_t gfp
)
16192 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
16193 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16194 struct sk_buff
*msg
;
16195 struct station_info empty_sinfo
= {};
16198 sinfo
= &empty_sinfo
;
16200 trace_cfg80211_del_sta(dev
, mac_addr
);
16202 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16204 cfg80211_sinfo_release_content(sinfo
);
16208 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
16209 rdev
, dev
, mac_addr
, sinfo
) < 0) {
16214 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16215 NL80211_MCGRP_MLME
, gfp
);
16217 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
16219 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
16220 enum nl80211_connect_failed_reason reason
,
16223 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
16224 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16225 struct sk_buff
*msg
;
16228 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
16232 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
16238 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16239 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
16240 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
16241 goto nla_put_failure
;
16243 genlmsg_end(msg
, hdr
);
16245 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16246 NL80211_MCGRP_MLME
, gfp
);
16252 EXPORT_SYMBOL(cfg80211_conn_failed
);
16254 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
16255 const u8
*addr
, gfp_t gfp
)
16257 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16258 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16259 struct sk_buff
*msg
;
16261 u32 nlportid
= READ_ONCE(wdev
->ap_unexpected_nlportid
);
16266 msg
= nlmsg_new(100, gfp
);
16270 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
16276 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16277 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16278 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
16279 goto nla_put_failure
;
16281 genlmsg_end(msg
, hdr
);
16282 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
16290 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
16291 const u8
*addr
, gfp_t gfp
)
16293 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16296 trace_cfg80211_rx_spurious_frame(dev
, addr
);
16298 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
16299 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
16300 trace_cfg80211_return_bool(false);
16303 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
16305 trace_cfg80211_return_bool(ret
);
16308 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
16310 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
16311 const u8
*addr
, gfp_t gfp
)
16313 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16316 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
16318 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
16319 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
16320 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
16321 trace_cfg80211_return_bool(false);
16324 ret
= __nl80211_unexpected_frame(dev
,
16325 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
16327 trace_cfg80211_return_bool(ret
);
16330 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
16332 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
16333 struct wireless_dev
*wdev
, u32 nlportid
,
16334 int freq
, int sig_dbm
,
16335 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
16337 struct net_device
*netdev
= wdev
->netdev
;
16338 struct sk_buff
*msg
;
16341 msg
= nlmsg_new(100 + len
, gfp
);
16345 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
16351 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16352 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
16353 netdev
->ifindex
)) ||
16354 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16355 NL80211_ATTR_PAD
) ||
16356 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, KHZ_TO_MHZ(freq
)) ||
16357 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_OFFSET
, freq
% 1000) ||
16359 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
16360 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
16362 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
16363 goto nla_put_failure
;
16365 genlmsg_end(msg
, hdr
);
16367 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
16374 static void nl80211_frame_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
16375 const u8
*buf
, size_t len
, bool ack
,
16376 gfp_t gfp
, enum nl80211_commands command
)
16378 struct wiphy
*wiphy
= wdev
->wiphy
;
16379 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16380 struct net_device
*netdev
= wdev
->netdev
;
16381 struct sk_buff
*msg
;
16384 if (command
== NL80211_CMD_FRAME_TX_STATUS
)
16385 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
16387 trace_cfg80211_control_port_tx_status(wdev
, cookie
, ack
);
16389 msg
= nlmsg_new(100 + len
, gfp
);
16393 hdr
= nl80211hdr_put(msg
, 0, 0, 0, command
);
16399 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16400 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
16401 netdev
->ifindex
)) ||
16402 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16403 NL80211_ATTR_PAD
) ||
16404 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
16405 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
16406 NL80211_ATTR_PAD
) ||
16407 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
16408 goto nla_put_failure
;
16410 genlmsg_end(msg
, hdr
);
16412 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16413 NL80211_MCGRP_MLME
, gfp
);
16420 void cfg80211_control_port_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
16421 const u8
*buf
, size_t len
, bool ack
,
16424 nl80211_frame_tx_status(wdev
, cookie
, buf
, len
, ack
, gfp
,
16425 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS
);
16427 EXPORT_SYMBOL(cfg80211_control_port_tx_status
);
16429 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
16430 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
16432 nl80211_frame_tx_status(wdev
, cookie
, buf
, len
, ack
, gfp
,
16433 NL80211_CMD_FRAME_TX_STATUS
);
16435 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
16437 static int __nl80211_rx_control_port(struct net_device
*dev
,
16438 struct sk_buff
*skb
,
16439 bool unencrypted
, gfp_t gfp
)
16441 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16442 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16443 struct ethhdr
*ehdr
= eth_hdr(skb
);
16444 const u8
*addr
= ehdr
->h_source
;
16445 u16 proto
= be16_to_cpu(skb
->protocol
);
16446 struct sk_buff
*msg
;
16448 struct nlattr
*frame
;
16450 u32 nlportid
= READ_ONCE(wdev
->conn_owner_nlportid
);
16455 msg
= nlmsg_new(100 + skb
->len
, gfp
);
16459 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME
);
16465 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16466 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16467 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16468 NL80211_ATTR_PAD
) ||
16469 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
16470 nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, proto
) ||
16471 (unencrypted
&& nla_put_flag(msg
,
16472 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
16473 goto nla_put_failure
;
16475 frame
= nla_reserve(msg
, NL80211_ATTR_FRAME
, skb
->len
);
16477 goto nla_put_failure
;
16479 skb_copy_bits(skb
, 0, nla_data(frame
), skb
->len
);
16480 genlmsg_end(msg
, hdr
);
16482 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
16489 bool cfg80211_rx_control_port(struct net_device
*dev
,
16490 struct sk_buff
*skb
, bool unencrypted
)
16494 trace_cfg80211_rx_control_port(dev
, skb
, unencrypted
);
16495 ret
= __nl80211_rx_control_port(dev
, skb
, unencrypted
, GFP_ATOMIC
);
16496 trace_cfg80211_return_bool(ret
== 0);
16499 EXPORT_SYMBOL(cfg80211_rx_control_port
);
16501 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
16502 const char *mac
, gfp_t gfp
)
16504 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16505 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16506 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16512 cb
= (void **)msg
->cb
;
16514 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
16520 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16521 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
16522 goto nla_put_failure
;
16524 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
16525 goto nla_put_failure
;
16527 cb
[1] = nla_nest_start_noflag(msg
, NL80211_ATTR_CQM
);
16529 goto nla_put_failure
;
16539 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
16541 void **cb
= (void **)msg
->cb
;
16542 struct cfg80211_registered_device
*rdev
= cb
[2];
16544 nla_nest_end(msg
, cb
[1]);
16545 genlmsg_end(msg
, cb
[0]);
16547 memset(msg
->cb
, 0, sizeof(msg
->cb
));
16549 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16550 NL80211_MCGRP_MLME
, gfp
);
16553 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
16554 enum nl80211_cqm_rssi_threshold_event rssi_event
,
16555 s32 rssi_level
, gfp_t gfp
)
16557 struct sk_buff
*msg
;
16558 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16559 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16561 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
, rssi_level
);
16563 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
16564 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
16567 if (wdev
->cqm_config
) {
16568 wdev
->cqm_config
->last_rssi_event_value
= rssi_level
;
16570 cfg80211_cqm_rssi_update(rdev
, dev
);
16572 if (rssi_level
== 0)
16573 rssi_level
= wdev
->cqm_config
->last_rssi_event_value
;
16576 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
16580 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
16582 goto nla_put_failure
;
16584 if (rssi_level
&& nla_put_s32(msg
, NL80211_ATTR_CQM_RSSI_LEVEL
,
16586 goto nla_put_failure
;
16588 cfg80211_send_cqm(msg
, gfp
);
16595 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
16597 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
16598 const u8
*peer
, u32 num_packets
,
16599 u32 rate
, u32 intvl
, gfp_t gfp
)
16601 struct sk_buff
*msg
;
16603 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
16607 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
16608 goto nla_put_failure
;
16610 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
16611 goto nla_put_failure
;
16613 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
16614 goto nla_put_failure
;
16616 cfg80211_send_cqm(msg
, gfp
);
16622 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
16624 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
16625 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
16627 struct sk_buff
*msg
;
16629 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
16631 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
16635 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
16636 goto nla_put_failure
;
16638 cfg80211_send_cqm(msg
, gfp
);
16644 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
16646 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
16648 struct sk_buff
*msg
;
16650 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
16654 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
16655 goto nla_put_failure
;
16657 cfg80211_send_cqm(msg
, gfp
);
16663 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
16665 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
16666 struct net_device
*netdev
, const u8
*bssid
,
16667 const u8
*replay_ctr
, gfp_t gfp
)
16669 struct sk_buff
*msg
;
16670 struct nlattr
*rekey_attr
;
16673 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16677 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
16683 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16684 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16685 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
16686 goto nla_put_failure
;
16688 rekey_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_REKEY_DATA
);
16690 goto nla_put_failure
;
16692 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
16693 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
16694 goto nla_put_failure
;
16696 nla_nest_end(msg
, rekey_attr
);
16698 genlmsg_end(msg
, hdr
);
16700 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16701 NL80211_MCGRP_MLME
, gfp
);
16708 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
16709 const u8
*replay_ctr
, gfp_t gfp
)
16711 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16712 struct wiphy
*wiphy
= wdev
->wiphy
;
16713 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16715 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
16716 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
16718 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
16721 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
16722 struct net_device
*netdev
, int index
,
16723 const u8
*bssid
, bool preauth
, gfp_t gfp
)
16725 struct sk_buff
*msg
;
16726 struct nlattr
*attr
;
16729 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16733 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
16739 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16740 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
16741 goto nla_put_failure
;
16743 attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
16745 goto nla_put_failure
;
16747 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
16748 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
16750 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
16751 goto nla_put_failure
;
16753 nla_nest_end(msg
, attr
);
16755 genlmsg_end(msg
, hdr
);
16757 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16758 NL80211_MCGRP_MLME
, gfp
);
16765 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
16766 const u8
*bssid
, bool preauth
, gfp_t gfp
)
16768 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16769 struct wiphy
*wiphy
= wdev
->wiphy
;
16770 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16772 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
16773 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
16775 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
16777 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
16778 struct net_device
*netdev
,
16779 struct cfg80211_chan_def
*chandef
,
16781 enum nl80211_commands notif
,
16784 struct sk_buff
*msg
;
16787 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16791 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
16797 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
16798 goto nla_put_failure
;
16800 if (nl80211_send_chandef(msg
, chandef
))
16801 goto nla_put_failure
;
16803 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
16804 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
16805 goto nla_put_failure
;
16807 genlmsg_end(msg
, hdr
);
16809 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16810 NL80211_MCGRP_MLME
, gfp
);
16817 void cfg80211_ch_switch_notify(struct net_device
*dev
,
16818 struct cfg80211_chan_def
*chandef
)
16820 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16821 struct wiphy
*wiphy
= wdev
->wiphy
;
16822 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16824 ASSERT_WDEV_LOCK(wdev
);
16826 trace_cfg80211_ch_switch_notify(dev
, chandef
);
16828 wdev
->chandef
= *chandef
;
16829 wdev
->preset_chandef
= *chandef
;
16831 if (wdev
->iftype
== NL80211_IFTYPE_STATION
&&
16832 !WARN_ON(!wdev
->current_bss
))
16833 cfg80211_update_assoc_bss_entry(wdev
, chandef
->chan
);
16835 cfg80211_sched_dfs_chan_update(rdev
);
16837 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
16838 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
16840 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
16842 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
16843 struct cfg80211_chan_def
*chandef
,
16846 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16847 struct wiphy
*wiphy
= wdev
->wiphy
;
16848 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16850 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
16852 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
16853 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
16855 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
16858 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
16859 const struct cfg80211_chan_def
*chandef
,
16860 enum nl80211_radar_event event
,
16861 struct net_device
*netdev
, gfp_t gfp
)
16863 struct sk_buff
*msg
;
16866 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16870 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
16876 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
16877 goto nla_put_failure
;
16879 /* NOP and radar events don't need a netdev parameter */
16881 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
16883 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16884 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16886 goto nla_put_failure
;
16889 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
16890 goto nla_put_failure
;
16892 if (nl80211_send_chandef(msg
, chandef
))
16893 goto nla_put_failure
;
16895 genlmsg_end(msg
, hdr
);
16897 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16898 NL80211_MCGRP_MLME
, gfp
);
16905 void cfg80211_sta_opmode_change_notify(struct net_device
*dev
, const u8
*mac
,
16906 struct sta_opmode_info
*sta_opmode
,
16909 struct sk_buff
*msg
;
16910 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16911 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16917 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16921 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED
);
16927 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
16928 goto nla_put_failure
;
16930 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
16931 goto nla_put_failure
;
16933 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
16934 goto nla_put_failure
;
16936 if ((sta_opmode
->changed
& STA_OPMODE_SMPS_MODE_CHANGED
) &&
16937 nla_put_u8(msg
, NL80211_ATTR_SMPS_MODE
, sta_opmode
->smps_mode
))
16938 goto nla_put_failure
;
16940 if ((sta_opmode
->changed
& STA_OPMODE_MAX_BW_CHANGED
) &&
16941 nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, sta_opmode
->bw
))
16942 goto nla_put_failure
;
16944 if ((sta_opmode
->changed
& STA_OPMODE_N_SS_CHANGED
) &&
16945 nla_put_u8(msg
, NL80211_ATTR_NSS
, sta_opmode
->rx_nss
))
16946 goto nla_put_failure
;
16948 genlmsg_end(msg
, hdr
);
16950 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16951 NL80211_MCGRP_MLME
, gfp
);
16958 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify
);
16960 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
16961 u64 cookie
, bool acked
, s32 ack_signal
,
16962 bool is_valid_ack_signal
, gfp_t gfp
)
16964 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16965 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16966 struct sk_buff
*msg
;
16969 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
16971 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16976 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
16982 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16983 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16984 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
16985 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
16986 NL80211_ATTR_PAD
) ||
16987 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)) ||
16988 (is_valid_ack_signal
&& nla_put_s32(msg
, NL80211_ATTR_ACK_SIGNAL
,
16990 goto nla_put_failure
;
16992 genlmsg_end(msg
, hdr
);
16994 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16995 NL80211_MCGRP_MLME
, gfp
);
17001 EXPORT_SYMBOL(cfg80211_probe_status
);
17003 void cfg80211_report_obss_beacon_khz(struct wiphy
*wiphy
, const u8
*frame
,
17004 size_t len
, int freq
, int sig_dbm
)
17006 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17007 struct sk_buff
*msg
;
17009 struct cfg80211_beacon_registration
*reg
;
17011 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
17013 spin_lock_bh(&rdev
->beacon_registrations_lock
);
17014 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
17015 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
17017 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17021 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
17023 goto nla_put_failure
;
17025 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17027 (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
17028 KHZ_TO_MHZ(freq
)) ||
17029 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_OFFSET
,
17032 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
17033 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
17034 goto nla_put_failure
;
17036 genlmsg_end(msg
, hdr
);
17038 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
17040 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17044 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17047 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz
);
17050 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
17051 struct cfg80211_wowlan_wakeup
*wakeup
)
17053 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
17054 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
17057 nl_results
= nla_nest_start_noflag(msg
,
17058 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
17062 for (i
= 0; i
< nd
->n_matches
; i
++) {
17063 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
17065 nl_match
= nla_nest_start_noflag(msg
, i
);
17069 /* The SSID attribute is optional in nl80211, but for
17070 * simplicity reasons it's always present in the
17071 * cfg80211 structure. If a driver can't pass the
17072 * SSID, that needs to be changed. A zero length SSID
17073 * is still a valid SSID (wildcard), so it cannot be
17074 * used for this purpose.
17076 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
17077 match
->ssid
.ssid
)) {
17078 nla_nest_cancel(msg
, nl_match
);
17082 if (match
->n_channels
) {
17083 nl_freqs
= nla_nest_start_noflag(msg
,
17084 NL80211_ATTR_SCAN_FREQUENCIES
);
17086 nla_nest_cancel(msg
, nl_match
);
17090 for (j
= 0; j
< match
->n_channels
; j
++) {
17091 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
17092 nla_nest_cancel(msg
, nl_freqs
);
17093 nla_nest_cancel(msg
, nl_match
);
17098 nla_nest_end(msg
, nl_freqs
);
17101 nla_nest_end(msg
, nl_match
);
17105 nla_nest_end(msg
, nl_results
);
17109 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
17110 struct cfg80211_wowlan_wakeup
*wakeup
,
17113 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17114 struct sk_buff
*msg
;
17118 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
17121 size
+= wakeup
->packet_present_len
;
17123 msg
= nlmsg_new(size
, gfp
);
17127 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
17131 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17132 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
17136 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
17137 wdev
->netdev
->ifindex
))
17141 struct nlattr
*reasons
;
17143 reasons
= nla_nest_start_noflag(msg
,
17144 NL80211_ATTR_WOWLAN_TRIGGERS
);
17148 if (wakeup
->disconnect
&&
17149 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
17151 if (wakeup
->magic_pkt
&&
17152 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
17154 if (wakeup
->gtk_rekey_failure
&&
17155 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
17157 if (wakeup
->eap_identity_req
&&
17158 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
17160 if (wakeup
->four_way_handshake
&&
17161 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
17163 if (wakeup
->rfkill_release
&&
17164 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
17167 if (wakeup
->pattern_idx
>= 0 &&
17168 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
17169 wakeup
->pattern_idx
))
17172 if (wakeup
->tcp_match
&&
17173 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
17176 if (wakeup
->tcp_connlost
&&
17177 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
17180 if (wakeup
->tcp_nomoretokens
&&
17182 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
17185 if (wakeup
->packet
) {
17186 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
17187 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
17189 if (!wakeup
->packet_80211
) {
17191 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
17193 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
17196 if (wakeup
->packet_len
&&
17197 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
17200 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
17205 if (wakeup
->net_detect
&&
17206 cfg80211_net_detect_results(msg
, wakeup
))
17209 nla_nest_end(msg
, reasons
);
17212 genlmsg_end(msg
, hdr
);
17214 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17215 NL80211_MCGRP_MLME
, gfp
);
17221 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
17224 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
17225 enum nl80211_tdls_operation oper
,
17226 u16 reason_code
, gfp_t gfp
)
17228 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17229 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17230 struct sk_buff
*msg
;
17233 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
17236 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17240 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
17246 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17247 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
17248 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
17249 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
17250 (reason_code
> 0 &&
17251 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
17252 goto nla_put_failure
;
17254 genlmsg_end(msg
, hdr
);
17256 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17257 NL80211_MCGRP_MLME
, gfp
);
17263 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
17265 static int nl80211_netlink_notify(struct notifier_block
* nb
,
17266 unsigned long state
,
17269 struct netlink_notify
*notify
= _notify
;
17270 struct cfg80211_registered_device
*rdev
;
17271 struct wireless_dev
*wdev
;
17272 struct cfg80211_beacon_registration
*reg
, *tmp
;
17274 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
17275 return NOTIFY_DONE
;
17279 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
17280 struct cfg80211_sched_scan_request
*sched_scan_req
;
17282 list_for_each_entry_rcu(sched_scan_req
,
17283 &rdev
->sched_scan_req_list
,
17285 if (sched_scan_req
->owner_nlportid
== notify
->portid
) {
17286 sched_scan_req
->nl_owner_dead
= true;
17287 schedule_work(&rdev
->sched_scan_stop_wk
);
17291 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
17292 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
17294 if (wdev
->owner_nlportid
== notify
->portid
) {
17295 wdev
->nl_owner_dead
= true;
17296 schedule_work(&rdev
->destroy_work
);
17297 } else if (wdev
->conn_owner_nlportid
== notify
->portid
) {
17298 schedule_work(&wdev
->disconnect_wk
);
17301 cfg80211_release_pmsr(wdev
, notify
->portid
);
17304 spin_lock_bh(&rdev
->beacon_registrations_lock
);
17305 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
17307 if (reg
->nlportid
== notify
->portid
) {
17308 list_del(®
->list
);
17313 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17319 * It is possible that the user space process that is controlling the
17320 * indoor setting disappeared, so notify the regulatory core.
17322 regulatory_netlink_notify(notify
->portid
);
17326 static struct notifier_block nl80211_netlink_notifier
= {
17327 .notifier_call
= nl80211_netlink_notify
,
17330 void cfg80211_ft_event(struct net_device
*netdev
,
17331 struct cfg80211_ft_event_params
*ft_event
)
17333 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
17334 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17335 struct sk_buff
*msg
;
17338 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
17340 if (!ft_event
->target_ap
)
17343 msg
= nlmsg_new(100 + ft_event
->ies_len
+ ft_event
->ric_ies_len
,
17348 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
17352 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17353 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
17354 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
17357 if (ft_event
->ies
&&
17358 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
17360 if (ft_event
->ric_ies
&&
17361 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
17362 ft_event
->ric_ies
))
17365 genlmsg_end(msg
, hdr
);
17367 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17368 NL80211_MCGRP_MLME
, GFP_KERNEL
);
17373 EXPORT_SYMBOL(cfg80211_ft_event
);
17375 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
17377 struct cfg80211_registered_device
*rdev
;
17378 struct sk_buff
*msg
;
17382 rdev
= wiphy_to_rdev(wdev
->wiphy
);
17383 if (!rdev
->crit_proto_nlportid
)
17386 nlportid
= rdev
->crit_proto_nlportid
;
17387 rdev
->crit_proto_nlportid
= 0;
17389 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17393 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
17395 goto nla_put_failure
;
17397 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17398 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
17400 goto nla_put_failure
;
17402 genlmsg_end(msg
, hdr
);
17404 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
17410 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
17412 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
17414 struct wiphy
*wiphy
= wdev
->wiphy
;
17415 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17416 struct sk_buff
*msg
;
17419 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
17423 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
17427 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17428 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
17429 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
17433 genlmsg_end(msg
, hdr
);
17435 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
17436 NL80211_MCGRP_MLME
, GFP_KERNEL
);
17442 int cfg80211_external_auth_request(struct net_device
*dev
,
17443 struct cfg80211_external_auth_params
*params
,
17446 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17447 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17448 struct sk_buff
*msg
;
17451 if (!wdev
->conn_owner_nlportid
)
17454 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17458 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH
);
17460 goto nla_put_failure
;
17462 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17463 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
17464 nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, params
->key_mgmt_suite
) ||
17465 nla_put_u32(msg
, NL80211_ATTR_EXTERNAL_AUTH_ACTION
,
17467 nla_put(msg
, NL80211_ATTR_BSSID
, ETH_ALEN
, params
->bssid
) ||
17468 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid
.ssid_len
,
17469 params
->ssid
.ssid
))
17470 goto nla_put_failure
;
17472 genlmsg_end(msg
, hdr
);
17473 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
17474 wdev
->conn_owner_nlportid
);
17481 EXPORT_SYMBOL(cfg80211_external_auth_request
);
17483 void cfg80211_update_owe_info_event(struct net_device
*netdev
,
17484 struct cfg80211_update_owe_info
*owe_info
,
17487 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
17488 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17489 struct sk_buff
*msg
;
17492 trace_cfg80211_update_owe_info_event(wiphy
, netdev
, owe_info
);
17494 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17498 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO
);
17500 goto nla_put_failure
;
17502 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17503 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
17504 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, owe_info
->peer
))
17505 goto nla_put_failure
;
17507 if (!owe_info
->ie_len
||
17508 nla_put(msg
, NL80211_ATTR_IE
, owe_info
->ie_len
, owe_info
->ie
))
17509 goto nla_put_failure
;
17511 genlmsg_end(msg
, hdr
);
17513 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17514 NL80211_MCGRP_MLME
, gfp
);
17518 genlmsg_cancel(msg
, hdr
);
17521 EXPORT_SYMBOL(cfg80211_update_owe_info_event
);
17523 /* initialisation/exit functions */
17525 int __init
nl80211_init(void)
17529 err
= genl_register_family(&nl80211_fam
);
17533 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
17539 genl_unregister_family(&nl80211_fam
);
17543 void nl80211_exit(void)
17545 netlink_unregister_notifier(&nl80211_netlink_notifier
);
17546 genl_unregister_family(&nl80211_fam
);