1 // SPDX-License-Identifier: GPL-2.0-only
3 * This is the new netlink-based wireless configuration interface.
5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright 2015-2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2020 Intel Corporation
12 #include <linux/module.h>
13 #include <linux/err.h>
14 #include <linux/slab.h>
15 #include <linux/list.h>
16 #include <linux/if_ether.h>
17 #include <linux/ieee80211.h>
18 #include <linux/nl80211.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/netlink.h>
21 #include <linux/nospec.h>
22 #include <linux/etherdevice.h>
23 #include <linux/if_vlan.h>
24 #include <net/net_namespace.h>
25 #include <net/genetlink.h>
26 #include <net/cfg80211.h>
28 #include <net/inet_connection_sock.h>
34 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
35 struct genl_info
*info
,
36 struct cfg80211_crypto_settings
*settings
,
39 /* the netlink family */
40 static struct genl_family nl80211_fam
;
42 /* multicast groups */
43 enum nl80211_multicast_groups
{
46 NL80211_MCGRP_REGULATORY
,
50 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
53 static const struct genl_multicast_group nl80211_mcgrps
[] = {
54 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
55 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
56 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
57 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
58 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
59 [NL80211_MCGRP_NAN
] = { .name
= NL80211_MULTICAST_GROUP_NAN
},
60 #ifdef CONFIG_NL80211_TESTMODE
61 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
65 /* returns ERR_PTR values */
66 static struct wireless_dev
*
67 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
69 struct cfg80211_registered_device
*rdev
;
70 struct wireless_dev
*result
= NULL
;
71 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
72 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
79 if (!have_ifidx
&& !have_wdev_id
)
80 return ERR_PTR(-EINVAL
);
83 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
85 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
86 wiphy_idx
= wdev_id
>> 32;
89 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
90 struct wireless_dev
*wdev
;
92 if (wiphy_net(&rdev
->wiphy
) != netns
)
95 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
98 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
99 if (have_ifidx
&& wdev
->netdev
&&
100 wdev
->netdev
->ifindex
== ifidx
) {
104 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
116 return ERR_PTR(-ENODEV
);
119 static struct cfg80211_registered_device
*
120 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
122 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
123 struct net_device
*netdev
;
127 if (!attrs
[NL80211_ATTR_WIPHY
] &&
128 !attrs
[NL80211_ATTR_IFINDEX
] &&
129 !attrs
[NL80211_ATTR_WDEV
])
130 return ERR_PTR(-EINVAL
);
132 if (attrs
[NL80211_ATTR_WIPHY
])
133 rdev
= cfg80211_rdev_by_wiphy_idx(
134 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
136 if (attrs
[NL80211_ATTR_WDEV
]) {
137 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
138 struct wireless_dev
*wdev
;
141 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
143 /* make sure wdev exists */
144 list_for_each_entry(wdev
, &tmp
->wiphy
.wdev_list
, list
) {
145 if (wdev
->identifier
!= (u32
)wdev_id
)
154 if (rdev
&& tmp
!= rdev
)
155 return ERR_PTR(-EINVAL
);
160 if (attrs
[NL80211_ATTR_IFINDEX
]) {
161 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
163 netdev
= __dev_get_by_index(netns
, ifindex
);
165 if (netdev
->ieee80211_ptr
)
167 netdev
->ieee80211_ptr
->wiphy
);
171 /* not wireless device -- return error */
173 return ERR_PTR(-EINVAL
);
175 /* mismatch -- return error */
176 if (rdev
&& tmp
!= rdev
)
177 return ERR_PTR(-EINVAL
);
184 return ERR_PTR(-ENODEV
);
186 if (netns
!= wiphy_net(&rdev
->wiphy
))
187 return ERR_PTR(-ENODEV
);
193 * This function returns a pointer to the driver
194 * that the genl_info item that is passed refers to.
196 * The result of this can be a PTR_ERR and hence must
197 * be checked with IS_ERR() for errors.
199 static struct cfg80211_registered_device
*
200 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
202 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
205 static int validate_beacon_head(const struct nlattr
*attr
,
206 struct netlink_ext_ack
*extack
)
208 const u8
*data
= nla_data(attr
);
209 unsigned int len
= nla_len(attr
);
210 const struct element
*elem
;
211 const struct ieee80211_mgmt
*mgmt
= (void *)data
;
212 bool s1g_bcn
= ieee80211_is_s1g_beacon(mgmt
->frame_control
);
213 unsigned int fixedlen
, hdrlen
;
216 fixedlen
= offsetof(struct ieee80211_ext
,
217 u
.s1g_beacon
.variable
);
218 hdrlen
= offsetof(struct ieee80211_ext
, u
.s1g_beacon
);
220 fixedlen
= offsetof(struct ieee80211_mgmt
,
222 hdrlen
= offsetof(struct ieee80211_mgmt
, u
.beacon
);
228 if (ieee80211_hdrlen(mgmt
->frame_control
) != hdrlen
)
234 for_each_element(elem
, data
, len
) {
238 if (for_each_element_completed(elem
, data
, len
))
242 NL_SET_ERR_MSG_ATTR(extack
, attr
, "malformed beacon head");
246 static int validate_ie_attr(const struct nlattr
*attr
,
247 struct netlink_ext_ack
*extack
)
249 const u8
*data
= nla_data(attr
);
250 unsigned int len
= nla_len(attr
);
251 const struct element
*elem
;
253 for_each_element(elem
, data
, len
) {
257 if (for_each_element_completed(elem
, data
, len
))
260 NL_SET_ERR_MSG_ATTR(extack
, attr
, "malformed information elements");
264 /* policy for the attributes */
265 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
];
267 static const struct nla_policy
268 nl80211_ftm_responder_policy
[NL80211_FTM_RESP_ATTR_MAX
+ 1] = {
269 [NL80211_FTM_RESP_ATTR_ENABLED
] = { .type
= NLA_FLAG
, },
270 [NL80211_FTM_RESP_ATTR_LCI
] = { .type
= NLA_BINARY
,
272 [NL80211_FTM_RESP_ATTR_CIVICLOC
] = { .type
= NLA_BINARY
,
276 static const struct nla_policy
277 nl80211_pmsr_ftm_req_attr_policy
[NL80211_PMSR_FTM_REQ_ATTR_MAX
+ 1] = {
278 [NL80211_PMSR_FTM_REQ_ATTR_ASAP
] = { .type
= NLA_FLAG
},
279 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE
] = { .type
= NLA_U32
},
280 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP
] =
281 NLA_POLICY_MAX(NLA_U8
, 15),
282 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD
] = { .type
= NLA_U16
},
283 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION
] =
284 NLA_POLICY_MAX(NLA_U8
, 15),
285 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST
] =
286 NLA_POLICY_MAX(NLA_U8
, 31),
287 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES
] = { .type
= NLA_U8
},
288 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI
] = { .type
= NLA_FLAG
},
289 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC
] = { .type
= NLA_FLAG
},
290 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED
] = { .type
= NLA_FLAG
},
291 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED
] = { .type
= NLA_FLAG
},
294 static const struct nla_policy
295 nl80211_pmsr_req_data_policy
[NL80211_PMSR_TYPE_MAX
+ 1] = {
296 [NL80211_PMSR_TYPE_FTM
] =
297 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy
),
300 static const struct nla_policy
301 nl80211_pmsr_req_attr_policy
[NL80211_PMSR_REQ_ATTR_MAX
+ 1] = {
302 [NL80211_PMSR_REQ_ATTR_DATA
] =
303 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy
),
304 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF
] = { .type
= NLA_FLAG
},
307 static const struct nla_policy
308 nl80211_psmr_peer_attr_policy
[NL80211_PMSR_PEER_ATTR_MAX
+ 1] = {
309 [NL80211_PMSR_PEER_ATTR_ADDR
] = NLA_POLICY_ETH_ADDR
,
310 [NL80211_PMSR_PEER_ATTR_CHAN
] = NLA_POLICY_NESTED(nl80211_policy
),
311 [NL80211_PMSR_PEER_ATTR_REQ
] =
312 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy
),
313 [NL80211_PMSR_PEER_ATTR_RESP
] = { .type
= NLA_REJECT
},
316 static const struct nla_policy
317 nl80211_pmsr_attr_policy
[NL80211_PMSR_ATTR_MAX
+ 1] = {
318 [NL80211_PMSR_ATTR_MAX_PEERS
] = { .type
= NLA_REJECT
},
319 [NL80211_PMSR_ATTR_REPORT_AP_TSF
] = { .type
= NLA_REJECT
},
320 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR
] = { .type
= NLA_REJECT
},
321 [NL80211_PMSR_ATTR_TYPE_CAPA
] = { .type
= NLA_REJECT
},
322 [NL80211_PMSR_ATTR_PEERS
] =
323 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy
),
326 static const struct nla_policy
327 he_obss_pd_policy
[NL80211_HE_OBSS_PD_ATTR_MAX
+ 1] = {
328 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET
] =
329 NLA_POLICY_RANGE(NLA_U8
, 1, 20),
330 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET
] =
331 NLA_POLICY_RANGE(NLA_U8
, 1, 20),
332 [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET
] =
333 NLA_POLICY_RANGE(NLA_U8
, 1, 20),
334 [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP
] =
335 NLA_POLICY_EXACT_LEN(8),
336 [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP
] =
337 NLA_POLICY_EXACT_LEN(8),
338 [NL80211_HE_OBSS_PD_ATTR_SR_CTRL
] = { .type
= NLA_U8
},
341 static const struct nla_policy
342 he_bss_color_policy
[NL80211_HE_BSS_COLOR_ATTR_MAX
+ 1] = {
343 [NL80211_HE_BSS_COLOR_ATTR_COLOR
] = NLA_POLICY_RANGE(NLA_U8
, 1, 63),
344 [NL80211_HE_BSS_COLOR_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
345 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL
] = { .type
= NLA_FLAG
},
348 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
349 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
350 .len
= NL80211_MAX_SUPP_RATES
},
351 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
352 .len
= NL80211_MAX_SUPP_HT_RATES
},
353 [NL80211_TXRATE_VHT
] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht
)),
354 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
355 [NL80211_TXRATE_HE
] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he
)),
356 [NL80211_TXRATE_HE_GI
] = NLA_POLICY_RANGE(NLA_U8
,
357 NL80211_RATE_INFO_HE_GI_0_8
,
358 NL80211_RATE_INFO_HE_GI_3_2
),
359 [NL80211_TXRATE_HE_LTF
] = NLA_POLICY_RANGE(NLA_U8
,
360 NL80211_RATE_INFO_HE_1XLTF
,
361 NL80211_RATE_INFO_HE_4XLTF
),
364 static const struct nla_policy
365 nl80211_tid_config_attr_policy
[NL80211_TID_CONFIG_ATTR_MAX
+ 1] = {
366 [NL80211_TID_CONFIG_ATTR_VIF_SUPP
] = { .type
= NLA_U64
},
367 [NL80211_TID_CONFIG_ATTR_PEER_SUPP
] = { .type
= NLA_U64
},
368 [NL80211_TID_CONFIG_ATTR_OVERRIDE
] = { .type
= NLA_FLAG
},
369 [NL80211_TID_CONFIG_ATTR_TIDS
] = NLA_POLICY_RANGE(NLA_U16
, 1, 0xff),
370 [NL80211_TID_CONFIG_ATTR_NOACK
] =
371 NLA_POLICY_MAX(NLA_U8
, NL80211_TID_CONFIG_DISABLE
),
372 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT
] = NLA_POLICY_MIN(NLA_U8
, 1),
373 [NL80211_TID_CONFIG_ATTR_RETRY_LONG
] = NLA_POLICY_MIN(NLA_U8
, 1),
374 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
] =
375 NLA_POLICY_MAX(NLA_U8
, NL80211_TID_CONFIG_DISABLE
),
376 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
] =
377 NLA_POLICY_MAX(NLA_U8
, NL80211_TID_CONFIG_DISABLE
),
378 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL
] =
379 NLA_POLICY_MAX(NLA_U8
, NL80211_TID_CONFIG_DISABLE
),
380 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
] =
381 NLA_POLICY_MAX(NLA_U8
, NL80211_TX_RATE_FIXED
),
382 [NL80211_TID_CONFIG_ATTR_TX_RATE
] =
383 NLA_POLICY_NESTED(nl80211_txattr_policy
),
386 static const struct nla_policy
387 nl80211_fils_discovery_policy
[NL80211_FILS_DISCOVERY_ATTR_MAX
+ 1] = {
388 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN
] = NLA_POLICY_MAX(NLA_U32
, 10000),
389 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX
] = NLA_POLICY_MAX(NLA_U32
, 10000),
390 NLA_POLICY_RANGE(NLA_BINARY
,
391 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN
,
392 IEEE80211_MAX_DATA_LEN
),
395 static const struct nla_policy
396 nl80211_unsol_bcast_probe_resp_policy
[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX
+ 1] = {
397 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT
] = NLA_POLICY_MAX(NLA_U32
, 20),
398 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL
] = { .type
= NLA_BINARY
,
399 .len
= IEEE80211_MAX_DATA_LEN
}
402 static const struct nla_policy
403 sar_specs_policy
[NL80211_SAR_ATTR_SPECS_MAX
+ 1] = {
404 [NL80211_SAR_ATTR_SPECS_POWER
] = { .type
= NLA_S32
},
405 [NL80211_SAR_ATTR_SPECS_RANGE_INDEX
] = {.type
= NLA_U32
},
408 static const struct nla_policy
409 sar_policy
[NL80211_SAR_ATTR_MAX
+ 1] = {
410 [NL80211_SAR_ATTR_TYPE
] = NLA_POLICY_MAX(NLA_U32
, NUM_NL80211_SAR_TYPE
),
411 [NL80211_SAR_ATTR_SPECS
] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy
),
414 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
415 [0] = { .strict_start_type
= NL80211_ATTR_HE_OBSS_PD
},
416 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
417 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
419 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
421 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
422 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
423 [NL80211_ATTR_WIPHY_EDMG_CHANNELS
] = NLA_POLICY_RANGE(NLA_U8
,
424 NL80211_EDMG_CHANNELS_MIN
,
425 NL80211_EDMG_CHANNELS_MAX
),
426 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
] = NLA_POLICY_RANGE(NLA_U8
,
427 NL80211_EDMG_BW_CONFIG_MIN
,
428 NL80211_EDMG_BW_CONFIG_MAX
),
430 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
431 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
432 [NL80211_ATTR_CENTER_FREQ1_OFFSET
] = NLA_POLICY_RANGE(NLA_U32
, 0, 999),
433 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
435 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = NLA_POLICY_MIN(NLA_U8
, 1),
436 [NL80211_ATTR_WIPHY_RETRY_LONG
] = NLA_POLICY_MIN(NLA_U8
, 1),
437 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
438 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
439 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
440 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
442 [NL80211_ATTR_IFTYPE
] = NLA_POLICY_MAX(NLA_U32
, NL80211_IFTYPE_MAX
),
443 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
444 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
446 [NL80211_ATTR_MAC
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
447 [NL80211_ATTR_PREV_BSSID
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
449 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
450 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
451 .len
= WLAN_MAX_KEY_LEN
},
452 [NL80211_ATTR_KEY_IDX
] = NLA_POLICY_MAX(NLA_U8
, 7),
453 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
454 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
455 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
456 [NL80211_ATTR_KEY_TYPE
] =
457 NLA_POLICY_MAX(NLA_U32
, NUM_NL80211_KEYTYPES
),
459 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
460 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
461 [NL80211_ATTR_BEACON_HEAD
] =
462 NLA_POLICY_VALIDATE_FN(NLA_BINARY
, validate_beacon_head
,
463 IEEE80211_MAX_DATA_LEN
),
464 [NL80211_ATTR_BEACON_TAIL
] =
465 NLA_POLICY_VALIDATE_FN(NLA_BINARY
, validate_ie_attr
,
466 IEEE80211_MAX_DATA_LEN
),
467 [NL80211_ATTR_STA_AID
] =
468 NLA_POLICY_RANGE(NLA_U16
, 1, IEEE80211_MAX_AID
),
469 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
470 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
471 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
472 .len
= NL80211_MAX_SUPP_RATES
},
473 [NL80211_ATTR_STA_PLINK_ACTION
] =
474 NLA_POLICY_MAX(NLA_U8
, NUM_NL80211_PLINK_ACTIONS
- 1),
475 [NL80211_ATTR_STA_TX_POWER_SETTING
] =
476 NLA_POLICY_RANGE(NLA_U8
,
477 NL80211_TX_POWER_AUTOMATIC
,
478 NL80211_TX_POWER_FIXED
),
479 [NL80211_ATTR_STA_TX_POWER
] = { .type
= NLA_S16
},
480 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
481 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
482 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
483 .len
= IEEE80211_MAX_MESH_ID_LEN
},
484 [NL80211_ATTR_MPATH_NEXT_HOP
] = NLA_POLICY_ETH_ADDR_COMPAT
,
486 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
487 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
489 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
490 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
491 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
492 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
493 .len
= NL80211_MAX_SUPP_RATES
},
494 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
496 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
497 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
499 [NL80211_ATTR_HT_CAPABILITY
] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN
),
501 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
502 [NL80211_ATTR_IE
] = NLA_POLICY_VALIDATE_FN(NLA_BINARY
,
504 IEEE80211_MAX_DATA_LEN
),
505 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
506 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
508 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
509 .len
= IEEE80211_MAX_SSID_LEN
},
510 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
511 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
512 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
513 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
514 [NL80211_ATTR_USE_MFP
] = NLA_POLICY_RANGE(NLA_U32
,
516 NL80211_MFP_OPTIONAL
),
517 [NL80211_ATTR_STA_FLAGS2
] = {
518 .len
= sizeof(struct nl80211_sta_flag_update
),
520 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
521 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
522 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
523 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211
] = { .type
= NLA_FLAG
},
524 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
525 [NL80211_ATTR_STATUS_CODE
] = { .type
= NLA_U16
},
526 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
527 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
528 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
529 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
530 [NL80211_ATTR_PMKID
] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN
),
531 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
532 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
533 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
534 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
535 .len
= IEEE80211_MAX_DATA_LEN
},
536 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
537 [NL80211_ATTR_PS_STATE
] = NLA_POLICY_RANGE(NLA_U32
,
540 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
541 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
542 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
543 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
544 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
545 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
546 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
547 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
548 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
549 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
550 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
551 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
552 [NL80211_ATTR_STA_PLINK_STATE
] =
553 NLA_POLICY_MAX(NLA_U8
, NUM_NL80211_PLINK_STATES
- 1),
554 [NL80211_ATTR_MEASUREMENT_DURATION
] = { .type
= NLA_U16
},
555 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
] = { .type
= NLA_FLAG
},
556 [NL80211_ATTR_MESH_PEER_AID
] =
557 NLA_POLICY_RANGE(NLA_U16
, 1, IEEE80211_MAX_AID
),
558 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
559 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
560 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
561 [NL80211_ATTR_HIDDEN_SSID
] =
562 NLA_POLICY_RANGE(NLA_U32
,
563 NL80211_HIDDEN_SSID_NOT_IN_USE
,
564 NL80211_HIDDEN_SSID_ZERO_CONTENTS
),
565 [NL80211_ATTR_IE_PROBE_RESP
] =
566 NLA_POLICY_VALIDATE_FN(NLA_BINARY
, validate_ie_attr
,
567 IEEE80211_MAX_DATA_LEN
),
568 [NL80211_ATTR_IE_ASSOC_RESP
] =
569 NLA_POLICY_VALIDATE_FN(NLA_BINARY
, validate_ie_attr
,
570 IEEE80211_MAX_DATA_LEN
),
571 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
572 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
573 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
574 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
575 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
576 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
577 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
578 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
579 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
580 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
581 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
582 .len
= IEEE80211_MAX_DATA_LEN
},
583 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
584 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
585 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
586 .len
= NL80211_HT_CAPABILITY_LEN
588 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
589 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
590 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
591 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
592 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
594 /* need to include at least Auth Transaction and Status Code */
595 [NL80211_ATTR_AUTH_DATA
] = NLA_POLICY_MIN_LEN(4),
597 [NL80211_ATTR_VHT_CAPABILITY
] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN
),
598 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
599 [NL80211_ATTR_P2P_CTWINDOW
] = NLA_POLICY_MAX(NLA_U8
, 127),
600 [NL80211_ATTR_P2P_OPPPS
] = NLA_POLICY_MAX(NLA_U8
, 1),
601 [NL80211_ATTR_LOCAL_MESH_POWER_MODE
] =
602 NLA_POLICY_RANGE(NLA_U32
,
603 NL80211_MESH_POWER_UNKNOWN
+ 1,
604 NL80211_MESH_POWER_MAX
),
605 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
606 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
607 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
608 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
609 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
610 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
611 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
612 .len
= NL80211_VHT_CAPABILITY_LEN
,
614 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
615 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
616 .len
= IEEE80211_MAX_DATA_LEN
},
617 [NL80211_ATTR_CRIT_PROT_ID
] = { .type
= NLA_U16
},
618 [NL80211_ATTR_MAX_CRIT_PROT_DURATION
] =
619 NLA_POLICY_MAX(NLA_U16
, NL80211_CRIT_PROTO_MAX_DURATION
),
620 [NL80211_ATTR_PEER_AID
] =
621 NLA_POLICY_RANGE(NLA_U16
, 1, IEEE80211_MAX_AID
),
622 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
623 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
624 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
625 [NL80211_ATTR_CNTDWN_OFFS_BEACON
] = { .type
= NLA_BINARY
},
626 [NL80211_ATTR_CNTDWN_OFFS_PRESP
] = { .type
= NLA_BINARY
},
627 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = NLA_POLICY_MIN_LEN(2),
629 * The value of the Length field of the Supported Operating
630 * Classes element is between 2 and 253.
632 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] =
633 NLA_POLICY_RANGE(NLA_BINARY
, 2, 253),
634 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
635 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
636 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
637 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
638 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
639 [NL80211_ATTR_QOS_MAP
] = NLA_POLICY_RANGE(NLA_BINARY
,
640 IEEE80211_QOS_MAP_LEN_MIN
,
641 IEEE80211_QOS_MAP_LEN_MAX
),
642 [NL80211_ATTR_MAC_HINT
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
643 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
644 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
645 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
646 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
647 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
648 [NL80211_ATTR_TSID
] = NLA_POLICY_MAX(NLA_U8
, IEEE80211_NUM_TIDS
- 1),
649 [NL80211_ATTR_USER_PRIO
] =
650 NLA_POLICY_MAX(NLA_U8
, IEEE80211_NUM_UPS
- 1),
651 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
652 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
653 [NL80211_ATTR_OPER_CLASS
] = { .type
= NLA_U8
},
654 [NL80211_ATTR_MAC_MASK
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
655 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
656 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
657 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
658 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
659 [NL80211_ATTR_PBSS
] = { .type
= NLA_FLAG
},
660 [NL80211_ATTR_BSS_SELECT
] = { .type
= NLA_NESTED
},
661 [NL80211_ATTR_STA_SUPPORT_P2P_PS
] =
662 NLA_POLICY_MAX(NLA_U8
, NUM_NL80211_P2P_PS_STATUS
- 1),
663 [NL80211_ATTR_MU_MIMO_GROUP_DATA
] = {
664 .len
= VHT_MUMIMO_GROUPS_DATA_LEN
666 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
667 [NL80211_ATTR_NAN_MASTER_PREF
] = NLA_POLICY_MIN(NLA_U8
, 1),
668 [NL80211_ATTR_BANDS
] = { .type
= NLA_U32
},
669 [NL80211_ATTR_NAN_FUNC
] = { .type
= NLA_NESTED
},
670 [NL80211_ATTR_FILS_KEK
] = { .type
= NLA_BINARY
,
671 .len
= FILS_MAX_KEK_LEN
},
672 [NL80211_ATTR_FILS_NONCES
] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN
),
673 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
] = { .type
= NLA_FLAG
, },
674 [NL80211_ATTR_BSSID
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
675 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] = { .type
= NLA_S8
},
676 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
] = {
677 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
679 [NL80211_ATTR_TIMEOUT_REASON
] = { .type
= NLA_U32
},
680 [NL80211_ATTR_FILS_ERP_USERNAME
] = { .type
= NLA_BINARY
,
681 .len
= FILS_ERP_MAX_USERNAME_LEN
},
682 [NL80211_ATTR_FILS_ERP_REALM
] = { .type
= NLA_BINARY
,
683 .len
= FILS_ERP_MAX_REALM_LEN
},
684 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] = { .type
= NLA_U16
},
685 [NL80211_ATTR_FILS_ERP_RRK
] = { .type
= NLA_BINARY
,
686 .len
= FILS_ERP_MAX_RRK_LEN
},
687 [NL80211_ATTR_FILS_CACHE_ID
] = NLA_POLICY_EXACT_LEN_WARN(2),
688 [NL80211_ATTR_PMK
] = { .type
= NLA_BINARY
, .len
= PMK_MAX_LEN
},
689 [NL80211_ATTR_PMKR0_NAME
] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN
),
690 [NL80211_ATTR_SCHED_SCAN_MULTI
] = { .type
= NLA_FLAG
},
691 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
] = { .type
= NLA_FLAG
},
693 [NL80211_ATTR_TXQ_LIMIT
] = { .type
= NLA_U32
},
694 [NL80211_ATTR_TXQ_MEMORY_LIMIT
] = { .type
= NLA_U32
},
695 [NL80211_ATTR_TXQ_QUANTUM
] = { .type
= NLA_U32
},
696 [NL80211_ATTR_HE_CAPABILITY
] =
697 NLA_POLICY_RANGE(NLA_BINARY
,
698 NL80211_HE_MIN_CAPABILITY_LEN
,
699 NL80211_HE_MAX_CAPABILITY_LEN
),
700 [NL80211_ATTR_FTM_RESPONDER
] =
701 NLA_POLICY_NESTED(nl80211_ftm_responder_policy
),
702 [NL80211_ATTR_TIMEOUT
] = NLA_POLICY_MIN(NLA_U32
, 1),
703 [NL80211_ATTR_PEER_MEASUREMENTS
] =
704 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy
),
705 [NL80211_ATTR_AIRTIME_WEIGHT
] = NLA_POLICY_MIN(NLA_U16
, 1),
706 [NL80211_ATTR_SAE_PASSWORD
] = { .type
= NLA_BINARY
,
707 .len
= SAE_PASSWORD_MAX_LEN
},
708 [NL80211_ATTR_TWT_RESPONDER
] = { .type
= NLA_FLAG
},
709 [NL80211_ATTR_HE_OBSS_PD
] = NLA_POLICY_NESTED(he_obss_pd_policy
),
710 [NL80211_ATTR_VLAN_ID
] = NLA_POLICY_RANGE(NLA_U16
, 1, VLAN_N_VID
- 2),
711 [NL80211_ATTR_HE_BSS_COLOR
] = NLA_POLICY_NESTED(he_bss_color_policy
),
712 [NL80211_ATTR_TID_CONFIG
] =
713 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy
),
714 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH
] = { .type
= NLA_FLAG
},
715 [NL80211_ATTR_PMK_LIFETIME
] = NLA_POLICY_MIN(NLA_U32
, 1),
716 [NL80211_ATTR_PMK_REAUTH_THRESHOLD
] = NLA_POLICY_RANGE(NLA_U8
, 1, 100),
717 [NL80211_ATTR_RECEIVE_MULTICAST
] = { .type
= NLA_FLAG
},
718 [NL80211_ATTR_WIPHY_FREQ_OFFSET
] = NLA_POLICY_RANGE(NLA_U32
, 0, 999),
719 [NL80211_ATTR_SCAN_FREQ_KHZ
] = { .type
= NLA_NESTED
},
720 [NL80211_ATTR_HE_6GHZ_CAPABILITY
] =
721 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa
)),
722 [NL80211_ATTR_FILS_DISCOVERY
] =
723 NLA_POLICY_NESTED(nl80211_fils_discovery_policy
),
724 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP
] =
725 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy
),
726 [NL80211_ATTR_S1G_CAPABILITY
] =
727 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN
),
728 [NL80211_ATTR_S1G_CAPABILITY_MASK
] =
729 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN
),
730 [NL80211_ATTR_SAE_PWE
] =
731 NLA_POLICY_RANGE(NLA_U8
, NL80211_SAE_PWE_HUNT_AND_PECK
,
732 NL80211_SAE_PWE_BOTH
),
733 [NL80211_ATTR_RECONNECT_REQUESTED
] = { .type
= NLA_REJECT
},
734 [NL80211_ATTR_SAR_SPEC
] = NLA_POLICY_NESTED(sar_policy
),
737 /* policy for the key attributes */
738 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
739 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
740 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
741 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
742 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
743 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
744 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
745 [NL80211_KEY_TYPE
] = NLA_POLICY_MAX(NLA_U32
, NUM_NL80211_KEYTYPES
- 1),
746 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
747 [NL80211_KEY_MODE
] = NLA_POLICY_RANGE(NLA_U8
, 0, NL80211_KEY_SET_TX
),
750 /* policy for the key default flags */
751 static const struct nla_policy
752 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
753 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
754 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
758 /* policy for WoWLAN attributes */
759 static const struct nla_policy
760 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
761 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
762 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
763 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
764 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
765 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
766 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
767 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
768 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
769 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
770 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
773 static const struct nla_policy
774 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
775 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
776 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
777 [NL80211_WOWLAN_TCP_DST_MAC
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
778 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
779 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
780 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = NLA_POLICY_MIN_LEN(1),
781 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
782 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
784 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
785 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
787 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
788 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = NLA_POLICY_MIN_LEN(1),
789 [NL80211_WOWLAN_TCP_WAKE_MASK
] = NLA_POLICY_MIN_LEN(1),
791 #endif /* CONFIG_PM */
793 /* policy for coalesce rule attributes */
794 static const struct nla_policy
795 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
796 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
797 [NL80211_ATTR_COALESCE_RULE_CONDITION
] =
798 NLA_POLICY_RANGE(NLA_U32
,
799 NL80211_COALESCE_CONDITION_MATCH
,
800 NL80211_COALESCE_CONDITION_NO_MATCH
),
801 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
804 /* policy for GTK rekey offload attributes */
805 static const struct nla_policy
806 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
807 [NL80211_REKEY_DATA_KEK
] = {
809 .len
= NL80211_KEK_EXT_LEN
811 [NL80211_REKEY_DATA_KCK
] = {
813 .len
= NL80211_KCK_EXT_LEN
815 [NL80211_REKEY_DATA_REPLAY_CTR
] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN
),
816 [NL80211_REKEY_DATA_AKM
] = { .type
= NLA_U32
},
819 static const struct nla_policy
820 nl80211_match_band_rssi_policy
[NUM_NL80211_BANDS
] = {
821 [NL80211_BAND_2GHZ
] = { .type
= NLA_S32
},
822 [NL80211_BAND_5GHZ
] = { .type
= NLA_S32
},
823 [NL80211_BAND_6GHZ
] = { .type
= NLA_S32
},
824 [NL80211_BAND_60GHZ
] = { .type
= NLA_S32
},
827 static const struct nla_policy
828 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
829 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
830 .len
= IEEE80211_MAX_SSID_LEN
},
831 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
832 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
833 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI
] =
834 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy
),
837 static const struct nla_policy
838 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
839 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
840 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
843 static const struct nla_policy
844 nl80211_bss_select_policy
[NL80211_BSS_SELECT_ATTR_MAX
+ 1] = {
845 [NL80211_BSS_SELECT_ATTR_RSSI
] = { .type
= NLA_FLAG
},
846 [NL80211_BSS_SELECT_ATTR_BAND_PREF
] = { .type
= NLA_U32
},
847 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
] = {
848 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
852 /* policy for NAN function attributes */
853 static const struct nla_policy
854 nl80211_nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
855 [NL80211_NAN_FUNC_TYPE
] =
856 NLA_POLICY_MAX(NLA_U8
, NL80211_NAN_FUNC_MAX_TYPE
),
857 [NL80211_NAN_FUNC_SERVICE_ID
] = {
858 .len
= NL80211_NAN_FUNC_SERVICE_ID_LEN
},
859 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
860 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
861 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
862 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
863 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
864 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN
),
865 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
866 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
867 [NL80211_NAN_FUNC_SERVICE_INFO
] = { .type
= NLA_BINARY
,
868 .len
= NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN
},
869 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
870 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
871 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
872 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
873 [NL80211_NAN_FUNC_TERM_REASON
] = { .type
= NLA_U8
},
876 /* policy for Service Response Filter attributes */
877 static const struct nla_policy
878 nl80211_nan_srf_policy
[NL80211_NAN_SRF_ATTR_MAX
+ 1] = {
879 [NL80211_NAN_SRF_INCLUDE
] = { .type
= NLA_FLAG
},
880 [NL80211_NAN_SRF_BF
] = { .type
= NLA_BINARY
,
881 .len
= NL80211_NAN_FUNC_SRF_MAX_LEN
},
882 [NL80211_NAN_SRF_BF_IDX
] = { .type
= NLA_U8
},
883 [NL80211_NAN_SRF_MAC_ADDRS
] = { .type
= NLA_NESTED
},
886 /* policy for packet pattern attributes */
887 static const struct nla_policy
888 nl80211_packet_pattern_policy
[MAX_NL80211_PKTPAT
+ 1] = {
889 [NL80211_PKTPAT_MASK
] = { .type
= NLA_BINARY
, },
890 [NL80211_PKTPAT_PATTERN
] = { .type
= NLA_BINARY
, },
891 [NL80211_PKTPAT_OFFSET
] = { .type
= NLA_U32
},
894 int nl80211_prepare_wdev_dump(struct netlink_callback
*cb
,
895 struct cfg80211_registered_device
**rdev
,
896 struct wireless_dev
**wdev
)
901 struct nlattr
**attrbuf
;
903 attrbuf
= kcalloc(NUM_NL80211_ATTR
, sizeof(*attrbuf
),
908 err
= nlmsg_parse_deprecated(cb
->nlh
,
909 GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
910 attrbuf
, nl80211_fam
.maxattr
,
911 nl80211_policy
, NULL
);
917 *wdev
= __cfg80211_wdev_from_attrs(sock_net(cb
->skb
->sk
),
921 return PTR_ERR(*wdev
);
922 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
923 /* 0 is the first index - add 1 to parse only once */
924 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
925 cb
->args
[1] = (*wdev
)->identifier
;
927 /* subtract the 1 again here */
928 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
929 struct wireless_dev
*tmp
;
933 *rdev
= wiphy_to_rdev(wiphy
);
936 list_for_each_entry(tmp
, &(*rdev
)->wiphy
.wdev_list
, list
) {
937 if (tmp
->identifier
== cb
->args
[1]) {
950 /* message building helper */
951 void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
954 /* since there is no private header just add the generic one */
955 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
958 static int nl80211_msg_put_wmm_rules(struct sk_buff
*msg
,
959 const struct ieee80211_reg_rule
*rule
)
962 struct nlattr
*nl_wmm_rules
=
963 nla_nest_start_noflag(msg
, NL80211_FREQUENCY_ATTR_WMM
);
966 goto nla_put_failure
;
968 for (j
= 0; j
< IEEE80211_NUM_ACS
; j
++) {
969 struct nlattr
*nl_wmm_rule
= nla_nest_start_noflag(msg
, j
);
972 goto nla_put_failure
;
974 if (nla_put_u16(msg
, NL80211_WMMR_CW_MIN
,
975 rule
->wmm_rule
.client
[j
].cw_min
) ||
976 nla_put_u16(msg
, NL80211_WMMR_CW_MAX
,
977 rule
->wmm_rule
.client
[j
].cw_max
) ||
978 nla_put_u8(msg
, NL80211_WMMR_AIFSN
,
979 rule
->wmm_rule
.client
[j
].aifsn
) ||
980 nla_put_u16(msg
, NL80211_WMMR_TXOP
,
981 rule
->wmm_rule
.client
[j
].cot
))
982 goto nla_put_failure
;
984 nla_nest_end(msg
, nl_wmm_rule
);
986 nla_nest_end(msg
, nl_wmm_rules
);
994 static int nl80211_msg_put_channel(struct sk_buff
*msg
, struct wiphy
*wiphy
,
995 struct ieee80211_channel
*chan
,
998 /* Some channels must be completely excluded from the
999 * list to protect old user-space tools from breaking
1001 if (!large
&& chan
->flags
&
1002 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
1004 if (!large
&& chan
->freq_offset
)
1007 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
1009 goto nla_put_failure
;
1011 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_OFFSET
, chan
->freq_offset
))
1012 goto nla_put_failure
;
1014 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
1015 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
1016 goto nla_put_failure
;
1017 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
1018 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
1019 goto nla_put_failure
;
1020 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
1021 goto nla_put_failure
;
1023 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
1024 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
1025 goto nla_put_failure
;
1029 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
1031 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
1033 goto nla_put_failure
;
1034 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
1036 goto nla_put_failure
;
1037 if (nla_put_u32(msg
,
1038 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
1040 goto nla_put_failure
;
1045 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
1046 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
1047 goto nla_put_failure
;
1048 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
1049 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
1050 goto nla_put_failure
;
1051 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
1052 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
1053 goto nla_put_failure
;
1054 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
1055 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
1056 goto nla_put_failure
;
1057 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
1058 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
1059 goto nla_put_failure
;
1060 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
1061 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
1062 goto nla_put_failure
;
1063 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
1064 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
1065 goto nla_put_failure
;
1066 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
1067 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
1068 goto nla_put_failure
;
1069 if ((chan
->flags
& IEEE80211_CHAN_NO_HE
) &&
1070 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HE
))
1071 goto nla_put_failure
;
1072 if ((chan
->flags
& IEEE80211_CHAN_1MHZ
) &&
1073 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_1MHZ
))
1074 goto nla_put_failure
;
1075 if ((chan
->flags
& IEEE80211_CHAN_2MHZ
) &&
1076 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_2MHZ
))
1077 goto nla_put_failure
;
1078 if ((chan
->flags
& IEEE80211_CHAN_4MHZ
) &&
1079 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_4MHZ
))
1080 goto nla_put_failure
;
1081 if ((chan
->flags
& IEEE80211_CHAN_8MHZ
) &&
1082 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_8MHZ
))
1083 goto nla_put_failure
;
1084 if ((chan
->flags
& IEEE80211_CHAN_16MHZ
) &&
1085 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_16MHZ
))
1086 goto nla_put_failure
;
1089 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
1090 DBM_TO_MBM(chan
->max_power
)))
1091 goto nla_put_failure
;
1094 const struct ieee80211_reg_rule
*rule
=
1095 freq_reg_info(wiphy
, MHZ_TO_KHZ(chan
->center_freq
));
1097 if (!IS_ERR_OR_NULL(rule
) && rule
->has_wmm
) {
1098 if (nl80211_msg_put_wmm_rules(msg
, rule
))
1099 goto nla_put_failure
;
1109 static bool nl80211_put_txq_stats(struct sk_buff
*msg
,
1110 struct cfg80211_txq_stats
*txqstats
,
1113 struct nlattr
*txqattr
;
1115 #define PUT_TXQVAL_U32(attr, memb) do { \
1116 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1117 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1121 txqattr
= nla_nest_start_noflag(msg
, attrtype
);
1125 PUT_TXQVAL_U32(BACKLOG_BYTES
, backlog_bytes
);
1126 PUT_TXQVAL_U32(BACKLOG_PACKETS
, backlog_packets
);
1127 PUT_TXQVAL_U32(FLOWS
, flows
);
1128 PUT_TXQVAL_U32(DROPS
, drops
);
1129 PUT_TXQVAL_U32(ECN_MARKS
, ecn_marks
);
1130 PUT_TXQVAL_U32(OVERLIMIT
, overlimit
);
1131 PUT_TXQVAL_U32(OVERMEMORY
, overmemory
);
1132 PUT_TXQVAL_U32(COLLISIONS
, collisions
);
1133 PUT_TXQVAL_U32(TX_BYTES
, tx_bytes
);
1134 PUT_TXQVAL_U32(TX_PACKETS
, tx_packets
);
1135 PUT_TXQVAL_U32(MAX_FLOWS
, max_flows
);
1136 nla_nest_end(msg
, txqattr
);
1138 #undef PUT_TXQVAL_U32
1142 /* netlink command implementations */
1145 struct key_params p
;
1148 bool def
, defmgmt
, defbeacon
;
1149 bool def_uni
, def_multi
;
1152 static int nl80211_parse_key_new(struct genl_info
*info
, struct nlattr
*key
,
1153 struct key_parse
*k
)
1155 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
1156 int err
= nla_parse_nested_deprecated(tb
, NL80211_KEY_MAX
, key
,
1162 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
1163 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
1164 k
->defbeacon
= !!tb
[NL80211_KEY_DEFAULT_BEACON
];
1168 k
->def_multi
= true;
1170 if (k
->defmgmt
|| k
->defbeacon
)
1171 k
->def_multi
= true;
1173 if (tb
[NL80211_KEY_IDX
])
1174 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
1176 if (tb
[NL80211_KEY_DATA
]) {
1177 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
1178 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
1181 if (tb
[NL80211_KEY_SEQ
]) {
1182 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
1183 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
1186 if (tb
[NL80211_KEY_CIPHER
])
1187 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
1189 if (tb
[NL80211_KEY_TYPE
])
1190 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
1192 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
1193 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
1195 err
= nla_parse_nested_deprecated(kdt
,
1196 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
1197 tb
[NL80211_KEY_DEFAULT_TYPES
],
1198 nl80211_key_default_policy
,
1203 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
1204 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
1207 if (tb
[NL80211_KEY_MODE
])
1208 k
->p
.mode
= nla_get_u8(tb
[NL80211_KEY_MODE
]);
1213 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
1215 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
1216 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
1217 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
1220 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
1221 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
1222 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
1225 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1226 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1228 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
1229 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
1231 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
1232 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
1236 k
->def_multi
= true;
1239 k
->def_multi
= true;
1241 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
])
1242 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1244 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
1245 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
1246 int err
= nla_parse_nested_deprecated(kdt
,
1247 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
1248 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
1249 nl80211_key_default_policy
,
1254 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
1255 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
1261 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
1265 memset(k
, 0, sizeof(*k
));
1269 if (info
->attrs
[NL80211_ATTR_KEY
])
1270 err
= nl80211_parse_key_new(info
, info
->attrs
[NL80211_ATTR_KEY
], k
);
1272 err
= nl80211_parse_key_old(info
, k
);
1277 if ((k
->def
? 1 : 0) + (k
->defmgmt
? 1 : 0) +
1278 (k
->defbeacon
? 1 : 0) > 1) {
1279 GENL_SET_ERR_MSG(info
,
1280 "key with multiple default flags is invalid");
1284 if (k
->defmgmt
|| k
->defbeacon
) {
1285 if (k
->def_uni
|| !k
->def_multi
) {
1286 GENL_SET_ERR_MSG(info
,
1287 "defmgmt/defbeacon key must be mcast");
1294 if (k
->idx
< 4 || k
->idx
> 5) {
1295 GENL_SET_ERR_MSG(info
,
1296 "defmgmt key idx not 4 or 5");
1299 } else if (k
->defbeacon
) {
1300 if (k
->idx
< 6 || k
->idx
> 7) {
1301 GENL_SET_ERR_MSG(info
,
1302 "defbeacon key idx not 6 or 7");
1305 } else if (k
->def
) {
1306 if (k
->idx
< 0 || k
->idx
> 3) {
1307 GENL_SET_ERR_MSG(info
, "def key idx not 0-3");
1311 if (k
->idx
< 0 || k
->idx
> 7) {
1312 GENL_SET_ERR_MSG(info
, "key idx not 0-7");
1321 static struct cfg80211_cached_keys
*
1322 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
1323 struct genl_info
*info
, bool *no_ht
)
1325 struct nlattr
*keys
= info
->attrs
[NL80211_ATTR_KEYS
];
1326 struct key_parse parse
;
1328 struct cfg80211_cached_keys
*result
;
1329 int rem
, err
, def
= 0;
1330 bool have_key
= false;
1332 nla_for_each_nested(key
, keys
, rem
) {
1340 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
1342 return ERR_PTR(-ENOMEM
);
1346 nla_for_each_nested(key
, keys
, rem
) {
1347 memset(&parse
, 0, sizeof(parse
));
1350 err
= nl80211_parse_key_new(info
, key
, &parse
);
1356 if (parse
.idx
< 0 || parse
.idx
> 3) {
1357 GENL_SET_ERR_MSG(info
, "key index out of range [0-3]");
1362 GENL_SET_ERR_MSG(info
,
1363 "only one key can be default");
1367 result
->def
= parse
.idx
;
1368 if (!parse
.def_uni
|| !parse
.def_multi
)
1370 } else if (parse
.defmgmt
)
1372 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
1373 parse
.idx
, false, NULL
);
1376 if (parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1377 parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
) {
1378 GENL_SET_ERR_MSG(info
, "connect key must be WEP");
1382 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
1383 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
1384 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
1385 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
1387 /* must be WEP key if we got here */
1392 if (result
->def
< 0) {
1394 GENL_SET_ERR_MSG(info
, "need a default/TX key");
1401 return ERR_PTR(err
);
1404 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
1406 ASSERT_WDEV_LOCK(wdev
);
1408 switch (wdev
->iftype
) {
1409 case NL80211_IFTYPE_AP
:
1410 case NL80211_IFTYPE_AP_VLAN
:
1411 case NL80211_IFTYPE_P2P_GO
:
1412 case NL80211_IFTYPE_MESH_POINT
:
1414 case NL80211_IFTYPE_ADHOC
:
1415 case NL80211_IFTYPE_STATION
:
1416 case NL80211_IFTYPE_P2P_CLIENT
:
1417 if (!wdev
->current_bss
)
1420 case NL80211_IFTYPE_UNSPECIFIED
:
1421 case NL80211_IFTYPE_OCB
:
1422 case NL80211_IFTYPE_MONITOR
:
1423 case NL80211_IFTYPE_NAN
:
1424 case NL80211_IFTYPE_P2P_DEVICE
:
1425 case NL80211_IFTYPE_WDS
:
1426 case NUM_NL80211_IFTYPES
:
1433 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
1436 struct ieee80211_channel
*chan
;
1438 chan
= ieee80211_get_channel_khz(wiphy
, freq
);
1439 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
1444 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
1446 struct nlattr
*nl_modes
= nla_nest_start_noflag(msg
, attr
);
1450 goto nla_put_failure
;
1454 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
1455 goto nla_put_failure
;
1460 nla_nest_end(msg
, nl_modes
);
1467 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
1468 struct sk_buff
*msg
,
1471 struct nlattr
*nl_combis
;
1474 nl_combis
= nla_nest_start_noflag(msg
,
1475 NL80211_ATTR_INTERFACE_COMBINATIONS
);
1477 goto nla_put_failure
;
1479 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
1480 const struct ieee80211_iface_combination
*c
;
1481 struct nlattr
*nl_combi
, *nl_limits
;
1483 c
= &wiphy
->iface_combinations
[i
];
1485 nl_combi
= nla_nest_start_noflag(msg
, i
+ 1);
1487 goto nla_put_failure
;
1489 nl_limits
= nla_nest_start_noflag(msg
,
1490 NL80211_IFACE_COMB_LIMITS
);
1492 goto nla_put_failure
;
1494 for (j
= 0; j
< c
->n_limits
; j
++) {
1495 struct nlattr
*nl_limit
;
1497 nl_limit
= nla_nest_start_noflag(msg
, j
+ 1);
1499 goto nla_put_failure
;
1500 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
1502 goto nla_put_failure
;
1503 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
1504 c
->limits
[j
].types
))
1505 goto nla_put_failure
;
1506 nla_nest_end(msg
, nl_limit
);
1509 nla_nest_end(msg
, nl_limits
);
1511 if (c
->beacon_int_infra_match
&&
1512 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
1513 goto nla_put_failure
;
1514 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
1515 c
->num_different_channels
) ||
1516 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
1518 goto nla_put_failure
;
1520 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1521 c
->radar_detect_widths
) ||
1522 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1523 c
->radar_detect_regions
)))
1524 goto nla_put_failure
;
1525 if (c
->beacon_int_min_gcd
&&
1526 nla_put_u32(msg
, NL80211_IFACE_COMB_BI_MIN_GCD
,
1527 c
->beacon_int_min_gcd
))
1528 goto nla_put_failure
;
1530 nla_nest_end(msg
, nl_combi
);
1533 nla_nest_end(msg
, nl_combis
);
1541 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1542 struct sk_buff
*msg
)
1544 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1545 struct nlattr
*nl_tcp
;
1550 nl_tcp
= nla_nest_start_noflag(msg
,
1551 NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1555 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1556 tcp
->data_payload_max
))
1559 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1560 tcp
->data_payload_max
))
1563 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1566 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1567 sizeof(*tcp
->tok
), tcp
->tok
))
1570 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1571 tcp
->data_interval_max
))
1574 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1575 tcp
->wake_payload_max
))
1578 nla_nest_end(msg
, nl_tcp
);
1582 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1583 struct cfg80211_registered_device
*rdev
,
1586 struct nlattr
*nl_wowlan
;
1588 if (!rdev
->wiphy
.wowlan
)
1591 nl_wowlan
= nla_nest_start_noflag(msg
,
1592 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1596 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1597 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1598 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1599 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1600 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1601 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1602 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1603 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1604 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1605 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1606 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1607 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1608 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1609 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1610 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1611 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1614 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1615 struct nl80211_pattern_support pat
= {
1616 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1617 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1618 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1619 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1622 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1627 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1628 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1629 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1632 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1635 nla_nest_end(msg
, nl_wowlan
);
1641 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1642 struct cfg80211_registered_device
*rdev
)
1644 struct nl80211_coalesce_rule_support rule
;
1646 if (!rdev
->wiphy
.coalesce
)
1649 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1650 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1651 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1652 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1653 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1654 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1656 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1663 nl80211_send_iftype_data(struct sk_buff
*msg
,
1664 const struct ieee80211_supported_band
*sband
,
1665 const struct ieee80211_sband_iftype_data
*iftdata
)
1667 const struct ieee80211_sta_he_cap
*he_cap
= &iftdata
->he_cap
;
1669 if (nl80211_put_iftypes(msg
, NL80211_BAND_IFTYPE_ATTR_IFTYPES
,
1670 iftdata
->types_mask
))
1673 if (he_cap
->has_he
) {
1674 if (nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
,
1675 sizeof(he_cap
->he_cap_elem
.mac_cap_info
),
1676 he_cap
->he_cap_elem
.mac_cap_info
) ||
1677 nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
,
1678 sizeof(he_cap
->he_cap_elem
.phy_cap_info
),
1679 he_cap
->he_cap_elem
.phy_cap_info
) ||
1680 nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
,
1681 sizeof(he_cap
->he_mcs_nss_supp
),
1682 &he_cap
->he_mcs_nss_supp
) ||
1683 nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
,
1684 sizeof(he_cap
->ppe_thres
), he_cap
->ppe_thres
))
1688 if (sband
->band
== NL80211_BAND_6GHZ
&&
1689 nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA
,
1690 sizeof(iftdata
->he_6ghz_capa
),
1691 &iftdata
->he_6ghz_capa
))
1697 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1698 struct ieee80211_supported_band
*sband
,
1701 struct nlattr
*nl_rates
, *nl_rate
;
1702 struct ieee80211_rate
*rate
;
1706 if (sband
->ht_cap
.ht_supported
&&
1707 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1708 sizeof(sband
->ht_cap
.mcs
),
1709 &sband
->ht_cap
.mcs
) ||
1710 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1711 sband
->ht_cap
.cap
) ||
1712 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1713 sband
->ht_cap
.ampdu_factor
) ||
1714 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1715 sband
->ht_cap
.ampdu_density
)))
1719 if (sband
->vht_cap
.vht_supported
&&
1720 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1721 sizeof(sband
->vht_cap
.vht_mcs
),
1722 &sband
->vht_cap
.vht_mcs
) ||
1723 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1724 sband
->vht_cap
.cap
)))
1727 if (large
&& sband
->n_iftype_data
) {
1728 struct nlattr
*nl_iftype_data
=
1729 nla_nest_start_noflag(msg
,
1730 NL80211_BAND_ATTR_IFTYPE_DATA
);
1733 if (!nl_iftype_data
)
1736 for (i
= 0; i
< sband
->n_iftype_data
; i
++) {
1737 struct nlattr
*iftdata
;
1739 iftdata
= nla_nest_start_noflag(msg
, i
+ 1);
1743 err
= nl80211_send_iftype_data(msg
, sband
,
1744 &sband
->iftype_data
[i
]);
1748 nla_nest_end(msg
, iftdata
);
1751 nla_nest_end(msg
, nl_iftype_data
);
1755 if (large
&& sband
->edmg_cap
.channels
&&
1756 (nla_put_u8(msg
, NL80211_BAND_ATTR_EDMG_CHANNELS
,
1757 sband
->edmg_cap
.channels
) ||
1758 nla_put_u8(msg
, NL80211_BAND_ATTR_EDMG_BW_CONFIG
,
1759 sband
->edmg_cap
.bw_config
)))
1764 nl_rates
= nla_nest_start_noflag(msg
, NL80211_BAND_ATTR_RATES
);
1768 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1769 nl_rate
= nla_nest_start_noflag(msg
, i
);
1773 rate
= &sband
->bitrates
[i
];
1774 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1777 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1779 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1782 nla_nest_end(msg
, nl_rate
);
1785 nla_nest_end(msg
, nl_rates
);
1791 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1792 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1795 struct nlattr
*nl_ftypes
, *nl_ifs
;
1796 enum nl80211_iftype ift
;
1802 nl_ifs
= nla_nest_start_noflag(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1806 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1807 nl_ftypes
= nla_nest_start_noflag(msg
, ift
);
1811 stypes
= mgmt_stypes
[ift
].tx
;
1814 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1815 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1820 nla_nest_end(msg
, nl_ftypes
);
1823 nla_nest_end(msg
, nl_ifs
);
1825 nl_ifs
= nla_nest_start_noflag(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1829 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1830 nl_ftypes
= nla_nest_start_noflag(msg
, ift
);
1834 stypes
= mgmt_stypes
[ift
].rx
;
1837 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1838 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1843 nla_nest_end(msg
, nl_ftypes
);
1845 nla_nest_end(msg
, nl_ifs
);
1850 #define CMD(op, n) \
1852 if (rdev->ops->op) { \
1854 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1855 goto nla_put_failure; \
1859 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device
*rdev
,
1860 struct sk_buff
*msg
)
1865 * do *NOT* add anything into this function, new things need to be
1866 * advertised only to new versions of userspace that can deal with
1867 * the split (and they can't possibly care about new features...
1869 CMD(add_virtual_intf
, NEW_INTERFACE
);
1870 CMD(change_virtual_intf
, SET_INTERFACE
);
1871 CMD(add_key
, NEW_KEY
);
1872 CMD(start_ap
, START_AP
);
1873 CMD(add_station
, NEW_STATION
);
1874 CMD(add_mpath
, NEW_MPATH
);
1875 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1876 CMD(change_bss
, SET_BSS
);
1877 CMD(auth
, AUTHENTICATE
);
1878 CMD(assoc
, ASSOCIATE
);
1879 CMD(deauth
, DEAUTHENTICATE
);
1880 CMD(disassoc
, DISASSOCIATE
);
1881 CMD(join_ibss
, JOIN_IBSS
);
1882 CMD(join_mesh
, JOIN_MESH
);
1883 CMD(set_pmksa
, SET_PMKSA
);
1884 CMD(del_pmksa
, DEL_PMKSA
);
1885 CMD(flush_pmksa
, FLUSH_PMKSA
);
1886 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1887 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1888 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1889 CMD(mgmt_tx
, FRAME
);
1890 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1891 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1893 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1894 goto nla_put_failure
;
1896 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1897 rdev
->ops
->join_mesh
) {
1899 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1900 goto nla_put_failure
;
1902 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1903 CMD(tdls_mgmt
, TDLS_MGMT
);
1904 CMD(tdls_oper
, TDLS_OPER
);
1906 if (rdev
->wiphy
.max_sched_scan_reqs
)
1907 CMD(sched_scan_start
, START_SCHED_SCAN
);
1908 CMD(probe_client
, PROBE_CLIENT
);
1909 CMD(set_noack_map
, SET_NOACK_MAP
);
1910 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1912 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1913 goto nla_put_failure
;
1915 CMD(start_p2p_device
, START_P2P_DEVICE
);
1916 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1917 #ifdef CONFIG_NL80211_TESTMODE
1918 CMD(testmode_cmd
, TESTMODE
);
1921 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1923 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1924 goto nla_put_failure
;
1927 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1929 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1930 goto nla_put_failure
;
1939 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities
*cap
,
1940 struct sk_buff
*msg
)
1944 if (!cap
->ftm
.supported
)
1947 ftm
= nla_nest_start_noflag(msg
, NL80211_PMSR_TYPE_FTM
);
1951 if (cap
->ftm
.asap
&& nla_put_flag(msg
, NL80211_PMSR_FTM_CAPA_ATTR_ASAP
))
1953 if (cap
->ftm
.non_asap
&&
1954 nla_put_flag(msg
, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP
))
1956 if (cap
->ftm
.request_lci
&&
1957 nla_put_flag(msg
, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI
))
1959 if (cap
->ftm
.request_civicloc
&&
1960 nla_put_flag(msg
, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC
))
1962 if (nla_put_u32(msg
, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES
,
1963 cap
->ftm
.preambles
))
1965 if (nla_put_u32(msg
, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS
,
1966 cap
->ftm
.bandwidths
))
1968 if (cap
->ftm
.max_bursts_exponent
>= 0 &&
1969 nla_put_u32(msg
, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT
,
1970 cap
->ftm
.max_bursts_exponent
))
1972 if (cap
->ftm
.max_ftms_per_burst
&&
1973 nla_put_u32(msg
, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST
,
1974 cap
->ftm
.max_ftms_per_burst
))
1976 if (cap
->ftm
.trigger_based
&&
1977 nla_put_flag(msg
, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED
))
1979 if (cap
->ftm
.non_trigger_based
&&
1980 nla_put_flag(msg
, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED
))
1983 nla_nest_end(msg
, ftm
);
1987 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device
*rdev
,
1988 struct sk_buff
*msg
)
1990 const struct cfg80211_pmsr_capabilities
*cap
= rdev
->wiphy
.pmsr_capa
;
1991 struct nlattr
*pmsr
, *caps
;
1997 * we don't need to clean up anything here since the caller
1998 * will genlmsg_cancel() if we fail
2001 pmsr
= nla_nest_start_noflag(msg
, NL80211_ATTR_PEER_MEASUREMENTS
);
2005 if (nla_put_u32(msg
, NL80211_PMSR_ATTR_MAX_PEERS
, cap
->max_peers
))
2008 if (cap
->report_ap_tsf
&&
2009 nla_put_flag(msg
, NL80211_PMSR_ATTR_REPORT_AP_TSF
))
2012 if (cap
->randomize_mac_addr
&&
2013 nla_put_flag(msg
, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR
))
2016 caps
= nla_nest_start_noflag(msg
, NL80211_PMSR_ATTR_TYPE_CAPA
);
2020 if (nl80211_send_pmsr_ftm_capa(cap
, msg
))
2023 nla_nest_end(msg
, caps
);
2024 nla_nest_end(msg
, pmsr
);
2030 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device
*rdev
,
2031 struct sk_buff
*msg
)
2034 struct nlattr
*nested
, *nested_akms
;
2035 const struct wiphy_iftype_akm_suites
*iftype_akms
;
2037 if (!rdev
->wiphy
.num_iftype_akm_suites
||
2038 !rdev
->wiphy
.iftype_akm_suites
)
2041 nested
= nla_nest_start(msg
, NL80211_ATTR_IFTYPE_AKM_SUITES
);
2045 for (i
= 0; i
< rdev
->wiphy
.num_iftype_akm_suites
; i
++) {
2046 nested_akms
= nla_nest_start(msg
, i
+ 1);
2050 iftype_akms
= &rdev
->wiphy
.iftype_akm_suites
[i
];
2052 if (nl80211_put_iftypes(msg
, NL80211_IFTYPE_AKM_ATTR_IFTYPES
,
2053 iftype_akms
->iftypes_mask
))
2056 if (nla_put(msg
, NL80211_IFTYPE_AKM_ATTR_SUITES
,
2057 sizeof(u32
) * iftype_akms
->n_akm_suites
,
2058 iftype_akms
->akm_suites
)) {
2061 nla_nest_end(msg
, nested_akms
);
2064 nla_nest_end(msg
, nested
);
2070 nl80211_put_tid_config_support(struct cfg80211_registered_device
*rdev
,
2071 struct sk_buff
*msg
)
2073 struct nlattr
*supp
;
2075 if (!rdev
->wiphy
.tid_config_support
.vif
&&
2076 !rdev
->wiphy
.tid_config_support
.peer
)
2079 supp
= nla_nest_start(msg
, NL80211_ATTR_TID_CONFIG
);
2083 if (rdev
->wiphy
.tid_config_support
.vif
&&
2084 nla_put_u64_64bit(msg
, NL80211_TID_CONFIG_ATTR_VIF_SUPP
,
2085 rdev
->wiphy
.tid_config_support
.vif
,
2086 NL80211_TID_CONFIG_ATTR_PAD
))
2089 if (rdev
->wiphy
.tid_config_support
.peer
&&
2090 nla_put_u64_64bit(msg
, NL80211_TID_CONFIG_ATTR_PEER_SUPP
,
2091 rdev
->wiphy
.tid_config_support
.peer
,
2092 NL80211_TID_CONFIG_ATTR_PAD
))
2095 /* for now we just use the same value ... makes more sense */
2096 if (nla_put_u8(msg
, NL80211_TID_CONFIG_ATTR_RETRY_SHORT
,
2097 rdev
->wiphy
.tid_config_support
.max_retry
))
2099 if (nla_put_u8(msg
, NL80211_TID_CONFIG_ATTR_RETRY_LONG
,
2100 rdev
->wiphy
.tid_config_support
.max_retry
))
2103 nla_nest_end(msg
, supp
);
2107 nla_nest_cancel(msg
, supp
);
2112 nl80211_put_sar_specs(struct cfg80211_registered_device
*rdev
,
2113 struct sk_buff
*msg
)
2115 struct nlattr
*sar_capa
, *specs
, *sub_freq_range
;
2119 if (!rdev
->wiphy
.sar_capa
)
2122 num_freq_ranges
= rdev
->wiphy
.sar_capa
->num_freq_ranges
;
2124 sar_capa
= nla_nest_start(msg
, NL80211_ATTR_SAR_SPEC
);
2128 if (nla_put_u32(msg
, NL80211_SAR_ATTR_TYPE
, rdev
->wiphy
.sar_capa
->type
))
2131 specs
= nla_nest_start(msg
, NL80211_SAR_ATTR_SPECS
);
2135 /* report supported freq_ranges */
2136 for (i
= 0; i
< num_freq_ranges
; i
++) {
2137 sub_freq_range
= nla_nest_start(msg
, i
+ 1);
2138 if (!sub_freq_range
)
2141 if (nla_put_u32(msg
, NL80211_SAR_ATTR_SPECS_START_FREQ
,
2142 rdev
->wiphy
.sar_capa
->freq_ranges
[i
].start_freq
))
2145 if (nla_put_u32(msg
, NL80211_SAR_ATTR_SPECS_END_FREQ
,
2146 rdev
->wiphy
.sar_capa
->freq_ranges
[i
].end_freq
))
2149 nla_nest_end(msg
, sub_freq_range
);
2152 nla_nest_end(msg
, specs
);
2153 nla_nest_end(msg
, sar_capa
);
2157 nla_nest_cancel(msg
, sar_capa
);
2161 struct nl80211_dump_wiphy_state
{
2164 long split_start
, band_start
, chan_start
, capa_start
;
2168 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
2169 enum nl80211_commands cmd
,
2170 struct sk_buff
*msg
, u32 portid
, u32 seq
,
2171 int flags
, struct nl80211_dump_wiphy_state
*state
)
2174 struct nlattr
*nl_bands
, *nl_band
;
2175 struct nlattr
*nl_freqs
, *nl_freq
;
2176 struct nlattr
*nl_cmds
;
2177 enum nl80211_band band
;
2178 struct ieee80211_channel
*chan
;
2180 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
2181 rdev
->wiphy
.mgmt_stypes
;
2184 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2188 if (WARN_ON(!state
))
2191 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2192 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
2193 wiphy_name(&rdev
->wiphy
)) ||
2194 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2195 cfg80211_rdev_list_generation
))
2196 goto nla_put_failure
;
2198 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
2201 switch (state
->split_start
) {
2203 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
2204 rdev
->wiphy
.retry_short
) ||
2205 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
2206 rdev
->wiphy
.retry_long
) ||
2207 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
2208 rdev
->wiphy
.frag_threshold
) ||
2209 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
2210 rdev
->wiphy
.rts_threshold
) ||
2211 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
2212 rdev
->wiphy
.coverage_class
) ||
2213 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
2214 rdev
->wiphy
.max_scan_ssids
) ||
2215 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
2216 rdev
->wiphy
.max_sched_scan_ssids
) ||
2217 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
2218 rdev
->wiphy
.max_scan_ie_len
) ||
2219 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
2220 rdev
->wiphy
.max_sched_scan_ie_len
) ||
2221 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
2222 rdev
->wiphy
.max_match_sets
))
2223 goto nla_put_failure
;
2225 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
2226 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
2227 goto nla_put_failure
;
2228 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
2229 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
2230 goto nla_put_failure
;
2231 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
2232 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
2233 goto nla_put_failure
;
2234 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
2235 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
2236 goto nla_put_failure
;
2237 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
2238 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
2239 goto nla_put_failure
;
2240 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
2241 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
2242 goto nla_put_failure
;
2243 state
->split_start
++;
2248 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
2249 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
2250 rdev
->wiphy
.cipher_suites
))
2251 goto nla_put_failure
;
2253 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
2254 rdev
->wiphy
.max_num_pmkids
))
2255 goto nla_put_failure
;
2257 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
2258 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
2259 goto nla_put_failure
;
2261 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
2262 rdev
->wiphy
.available_antennas_tx
) ||
2263 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
2264 rdev
->wiphy
.available_antennas_rx
))
2265 goto nla_put_failure
;
2267 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
2268 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
2269 rdev
->wiphy
.probe_resp_offload
))
2270 goto nla_put_failure
;
2272 if ((rdev
->wiphy
.available_antennas_tx
||
2273 rdev
->wiphy
.available_antennas_rx
) &&
2274 rdev
->ops
->get_antenna
) {
2275 u32 tx_ant
= 0, rx_ant
= 0;
2278 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
2280 if (nla_put_u32(msg
,
2281 NL80211_ATTR_WIPHY_ANTENNA_TX
,
2284 NL80211_ATTR_WIPHY_ANTENNA_RX
,
2286 goto nla_put_failure
;
2290 state
->split_start
++;
2295 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
2296 rdev
->wiphy
.interface_modes
))
2297 goto nla_put_failure
;
2298 state
->split_start
++;
2303 nl_bands
= nla_nest_start_noflag(msg
,
2304 NL80211_ATTR_WIPHY_BANDS
);
2306 goto nla_put_failure
;
2308 for (band
= state
->band_start
;
2309 band
< NUM_NL80211_BANDS
; band
++) {
2310 struct ieee80211_supported_band
*sband
;
2312 /* omit higher bands for ancient software */
2313 if (band
> NL80211_BAND_5GHZ
&& !state
->split
)
2316 sband
= rdev
->wiphy
.bands
[band
];
2321 nl_band
= nla_nest_start_noflag(msg
, band
);
2323 goto nla_put_failure
;
2325 switch (state
->chan_start
) {
2327 if (nl80211_send_band_rateinfo(msg
, sband
,
2329 goto nla_put_failure
;
2330 state
->chan_start
++;
2335 /* add frequencies */
2336 nl_freqs
= nla_nest_start_noflag(msg
,
2337 NL80211_BAND_ATTR_FREQS
);
2339 goto nla_put_failure
;
2341 for (i
= state
->chan_start
- 1;
2342 i
< sband
->n_channels
;
2344 nl_freq
= nla_nest_start_noflag(msg
,
2347 goto nla_put_failure
;
2349 chan
= &sband
->channels
[i
];
2351 if (nl80211_msg_put_channel(
2352 msg
, &rdev
->wiphy
, chan
,
2354 goto nla_put_failure
;
2356 nla_nest_end(msg
, nl_freq
);
2360 if (i
< sband
->n_channels
)
2361 state
->chan_start
= i
+ 2;
2363 state
->chan_start
= 0;
2364 nla_nest_end(msg
, nl_freqs
);
2367 nla_nest_end(msg
, nl_band
);
2370 /* start again here */
2371 if (state
->chan_start
)
2376 nla_nest_end(msg
, nl_bands
);
2378 if (band
< NUM_NL80211_BANDS
)
2379 state
->band_start
= band
+ 1;
2381 state
->band_start
= 0;
2383 /* if bands & channels are done, continue outside */
2384 if (state
->band_start
== 0 && state
->chan_start
== 0)
2385 state
->split_start
++;
2390 nl_cmds
= nla_nest_start_noflag(msg
,
2391 NL80211_ATTR_SUPPORTED_COMMANDS
);
2393 goto nla_put_failure
;
2395 i
= nl80211_add_commands_unsplit(rdev
, msg
);
2397 goto nla_put_failure
;
2399 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
2400 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
2401 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
2402 CMD(channel_switch
, CHANNEL_SWITCH
);
2403 CMD(set_qos_map
, SET_QOS_MAP
);
2404 if (rdev
->wiphy
.features
&
2405 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
2406 CMD(add_tx_ts
, ADD_TX_TS
);
2407 CMD(set_multicast_to_unicast
, SET_MULTICAST_TO_UNICAST
);
2408 CMD(update_connect_params
, UPDATE_CONNECT_PARAMS
);
2409 CMD(update_ft_ies
, UPDATE_FT_IES
);
2410 if (rdev
->wiphy
.sar_capa
)
2411 CMD(set_sar_specs
, SET_SAR_SPECS
);
2415 nla_nest_end(msg
, nl_cmds
);
2416 state
->split_start
++;
2421 if (rdev
->ops
->remain_on_channel
&&
2422 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
2424 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
2425 rdev
->wiphy
.max_remain_on_channel_duration
))
2426 goto nla_put_failure
;
2428 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
2429 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
2430 goto nla_put_failure
;
2432 state
->split_start
++;
2438 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
2439 goto nla_put_failure
;
2440 state
->split_start
++;
2444 state
->split_start
++;
2448 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
2449 rdev
->wiphy
.software_iftypes
))
2450 goto nla_put_failure
;
2452 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
2454 goto nla_put_failure
;
2456 state
->split_start
++;
2461 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
2462 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
2463 rdev
->wiphy
.ap_sme_capa
))
2464 goto nla_put_failure
;
2466 features
= rdev
->wiphy
.features
;
2468 * We can only add the per-channel limit information if the
2469 * dump is split, otherwise it makes it too big. Therefore
2470 * only advertise it in that case.
2473 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
2474 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
2475 goto nla_put_failure
;
2477 if (rdev
->wiphy
.ht_capa_mod_mask
&&
2478 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
2479 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
2480 rdev
->wiphy
.ht_capa_mod_mask
))
2481 goto nla_put_failure
;
2483 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
2484 rdev
->wiphy
.max_acl_mac_addrs
&&
2485 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
2486 rdev
->wiphy
.max_acl_mac_addrs
))
2487 goto nla_put_failure
;
2490 * Any information below this point is only available to
2491 * applications that can deal with it being split. This
2492 * helps ensure that newly added capabilities don't break
2493 * older tools by overrunning their buffers.
2495 * We still increment split_start so that in the split
2496 * case we'll continue with more data in the next round,
2497 * but break unconditionally so unsplit data stops here.
2500 state
->split_start
++;
2502 state
->split_start
= 0;
2505 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
2506 goto nla_put_failure
;
2508 if (nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
2509 rdev
->wiphy
.max_sched_scan_plans
) ||
2510 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
2511 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
2512 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
2513 rdev
->wiphy
.max_sched_scan_plan_iterations
))
2514 goto nla_put_failure
;
2516 if (rdev
->wiphy
.extended_capabilities
&&
2517 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
2518 rdev
->wiphy
.extended_capabilities_len
,
2519 rdev
->wiphy
.extended_capabilities
) ||
2520 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
2521 rdev
->wiphy
.extended_capabilities_len
,
2522 rdev
->wiphy
.extended_capabilities_mask
)))
2523 goto nla_put_failure
;
2525 if (rdev
->wiphy
.vht_capa_mod_mask
&&
2526 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
2527 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
2528 rdev
->wiphy
.vht_capa_mod_mask
))
2529 goto nla_put_failure
;
2531 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
,
2532 rdev
->wiphy
.perm_addr
))
2533 goto nla_put_failure
;
2535 if (!is_zero_ether_addr(rdev
->wiphy
.addr_mask
) &&
2536 nla_put(msg
, NL80211_ATTR_MAC_MASK
, ETH_ALEN
,
2537 rdev
->wiphy
.addr_mask
))
2538 goto nla_put_failure
;
2540 if (rdev
->wiphy
.n_addresses
> 1) {
2543 attr
= nla_nest_start(msg
, NL80211_ATTR_MAC_ADDRS
);
2545 goto nla_put_failure
;
2547 for (i
= 0; i
< rdev
->wiphy
.n_addresses
; i
++)
2548 if (nla_put(msg
, i
+ 1, ETH_ALEN
,
2549 rdev
->wiphy
.addresses
[i
].addr
))
2550 goto nla_put_failure
;
2552 nla_nest_end(msg
, attr
);
2555 state
->split_start
++;
2558 if (nl80211_send_coalesce(msg
, rdev
))
2559 goto nla_put_failure
;
2561 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
2562 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
2563 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
2564 goto nla_put_failure
;
2566 if (rdev
->wiphy
.max_ap_assoc_sta
&&
2567 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
2568 rdev
->wiphy
.max_ap_assoc_sta
))
2569 goto nla_put_failure
;
2571 state
->split_start
++;
2574 if (rdev
->wiphy
.n_vendor_commands
) {
2575 const struct nl80211_vendor_cmd_info
*info
;
2576 struct nlattr
*nested
;
2578 nested
= nla_nest_start_noflag(msg
,
2579 NL80211_ATTR_VENDOR_DATA
);
2581 goto nla_put_failure
;
2583 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
2584 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
2585 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
2586 goto nla_put_failure
;
2588 nla_nest_end(msg
, nested
);
2591 if (rdev
->wiphy
.n_vendor_events
) {
2592 const struct nl80211_vendor_cmd_info
*info
;
2593 struct nlattr
*nested
;
2595 nested
= nla_nest_start_noflag(msg
,
2596 NL80211_ATTR_VENDOR_EVENTS
);
2598 goto nla_put_failure
;
2600 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
2601 info
= &rdev
->wiphy
.vendor_events
[i
];
2602 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
2603 goto nla_put_failure
;
2605 nla_nest_end(msg
, nested
);
2607 state
->split_start
++;
2610 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
2611 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
2612 rdev
->wiphy
.max_num_csa_counters
))
2613 goto nla_put_failure
;
2615 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
2616 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
2617 goto nla_put_failure
;
2619 if (rdev
->wiphy
.max_sched_scan_reqs
&&
2620 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_MAX_REQS
,
2621 rdev
->wiphy
.max_sched_scan_reqs
))
2622 goto nla_put_failure
;
2624 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
2625 sizeof(rdev
->wiphy
.ext_features
),
2626 rdev
->wiphy
.ext_features
))
2627 goto nla_put_failure
;
2629 if (rdev
->wiphy
.bss_select_support
) {
2630 struct nlattr
*nested
;
2631 u32 bss_select_support
= rdev
->wiphy
.bss_select_support
;
2633 nested
= nla_nest_start_noflag(msg
,
2634 NL80211_ATTR_BSS_SELECT
);
2636 goto nla_put_failure
;
2639 while (bss_select_support
) {
2640 if ((bss_select_support
& 1) &&
2641 nla_put_flag(msg
, i
))
2642 goto nla_put_failure
;
2644 bss_select_support
>>= 1;
2646 nla_nest_end(msg
, nested
);
2649 state
->split_start
++;
2652 if (rdev
->wiphy
.num_iftype_ext_capab
&&
2653 rdev
->wiphy
.iftype_ext_capab
) {
2654 struct nlattr
*nested_ext_capab
, *nested
;
2656 nested
= nla_nest_start_noflag(msg
,
2657 NL80211_ATTR_IFTYPE_EXT_CAPA
);
2659 goto nla_put_failure
;
2661 for (i
= state
->capa_start
;
2662 i
< rdev
->wiphy
.num_iftype_ext_capab
; i
++) {
2663 const struct wiphy_iftype_ext_capab
*capab
;
2665 capab
= &rdev
->wiphy
.iftype_ext_capab
[i
];
2667 nested_ext_capab
= nla_nest_start_noflag(msg
,
2669 if (!nested_ext_capab
||
2670 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
2672 nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
2673 capab
->extended_capabilities_len
,
2674 capab
->extended_capabilities
) ||
2675 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
2676 capab
->extended_capabilities_len
,
2677 capab
->extended_capabilities_mask
))
2678 goto nla_put_failure
;
2680 nla_nest_end(msg
, nested_ext_capab
);
2684 nla_nest_end(msg
, nested
);
2685 if (i
< rdev
->wiphy
.num_iftype_ext_capab
) {
2686 state
->capa_start
= i
+ 1;
2691 if (nla_put_u32(msg
, NL80211_ATTR_BANDS
,
2692 rdev
->wiphy
.nan_supported_bands
))
2693 goto nla_put_failure
;
2695 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
2696 NL80211_EXT_FEATURE_TXQS
)) {
2697 struct cfg80211_txq_stats txqstats
= {};
2700 res
= rdev_get_txq_stats(rdev
, NULL
, &txqstats
);
2702 !nl80211_put_txq_stats(msg
, &txqstats
,
2703 NL80211_ATTR_TXQ_STATS
))
2704 goto nla_put_failure
;
2706 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_LIMIT
,
2707 rdev
->wiphy
.txq_limit
))
2708 goto nla_put_failure
;
2709 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_MEMORY_LIMIT
,
2710 rdev
->wiphy
.txq_memory_limit
))
2711 goto nla_put_failure
;
2712 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_QUANTUM
,
2713 rdev
->wiphy
.txq_quantum
))
2714 goto nla_put_failure
;
2717 state
->split_start
++;
2720 if (nl80211_send_pmsr_capa(rdev
, msg
))
2721 goto nla_put_failure
;
2723 state
->split_start
++;
2726 if (rdev
->wiphy
.akm_suites
&&
2727 nla_put(msg
, NL80211_ATTR_AKM_SUITES
,
2728 sizeof(u32
) * rdev
->wiphy
.n_akm_suites
,
2729 rdev
->wiphy
.akm_suites
))
2730 goto nla_put_failure
;
2732 if (nl80211_put_iftype_akm_suites(rdev
, msg
))
2733 goto nla_put_failure
;
2735 if (nl80211_put_tid_config_support(rdev
, msg
))
2736 goto nla_put_failure
;
2737 state
->split_start
++;
2740 if (nl80211_put_sar_specs(rdev
, msg
))
2741 goto nla_put_failure
;
2744 state
->split_start
= 0;
2748 genlmsg_end(msg
, hdr
);
2752 genlmsg_cancel(msg
, hdr
);
2756 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
2757 struct netlink_callback
*cb
,
2758 struct nl80211_dump_wiphy_state
*state
)
2760 struct nlattr
**tb
= kcalloc(NUM_NL80211_ATTR
, sizeof(*tb
), GFP_KERNEL
);
2766 ret
= nlmsg_parse_deprecated(cb
->nlh
,
2767 GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2768 tb
, nl80211_fam
.maxattr
,
2769 nl80211_policy
, NULL
);
2770 /* ignore parse errors for backward compatibility */
2776 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
2777 if (tb
[NL80211_ATTR_WIPHY
])
2778 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
2779 if (tb
[NL80211_ATTR_WDEV
])
2780 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
2781 if (tb
[NL80211_ATTR_IFINDEX
]) {
2782 struct net_device
*netdev
;
2783 struct cfg80211_registered_device
*rdev
;
2784 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2786 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2791 if (netdev
->ieee80211_ptr
) {
2792 rdev
= wiphy_to_rdev(
2793 netdev
->ieee80211_ptr
->wiphy
);
2794 state
->filter_wiphy
= rdev
->wiphy_idx
;
2804 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2807 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
2808 struct cfg80211_registered_device
*rdev
;
2812 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
2817 state
->filter_wiphy
= -1;
2818 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
2824 cb
->args
[0] = (long)state
;
2827 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2828 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2830 if (++idx
<= state
->start
)
2832 if (state
->filter_wiphy
!= -1 &&
2833 state
->filter_wiphy
!= rdev
->wiphy_idx
)
2835 /* attempt to fit multiple wiphy data chunks into the skb */
2837 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
2839 NETLINK_CB(cb
->skb
).portid
,
2841 NLM_F_MULTI
, state
);
2844 * If sending the wiphy data didn't fit (ENOBUFS
2845 * or EMSGSIZE returned), this SKB is still
2846 * empty (so it's not too big because another
2847 * wiphy dataset is already in the skb) and
2848 * we've not tried to adjust the dump allocation
2849 * yet ... then adjust the alloc size to be
2850 * bigger, and return 1 but with the empty skb.
2851 * This results in an empty message being RX'ed
2852 * in userspace, but that is ignored.
2854 * We can then retry with the larger buffer.
2856 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
2857 !skb
->len
&& !state
->split
&&
2858 cb
->min_dump_alloc
< 4096) {
2859 cb
->min_dump_alloc
= 4096;
2860 state
->split_start
= 0;
2867 } while (state
->split_start
> 0);
2877 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
2879 kfree((void *)cb
->args
[0]);
2883 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2885 struct sk_buff
*msg
;
2886 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2887 struct nl80211_dump_wiphy_state state
= {};
2889 msg
= nlmsg_new(4096, GFP_KERNEL
);
2893 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
2894 info
->snd_portid
, info
->snd_seq
, 0,
2900 return genlmsg_reply(msg
, info
);
2903 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
2904 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
2905 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
2906 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
2907 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
2908 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
2911 static int parse_txq_params(struct nlattr
*tb
[],
2912 struct ieee80211_txq_params
*txq_params
)
2916 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
2917 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
2918 !tb
[NL80211_TXQ_ATTR_AIFS
])
2921 ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
2922 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
2923 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
2924 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
2925 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
2927 if (ac
>= NL80211_NUM_ACS
)
2929 txq_params
->ac
= array_index_nospec(ac
, NL80211_NUM_ACS
);
2933 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
2936 * You can only set the channel explicitly for some interfaces,
2937 * most have their channel managed via their respective
2938 * "establish a connection" command (connect, join, ...)
2940 * For AP/GO and mesh mode, the channel can be set with the
2941 * channel userspace API, but is only stored and passed to the
2942 * low-level driver when the AP starts or the mesh is joined.
2943 * This is for backward compatibility, userspace can also give
2944 * the channel in the start-ap or join-mesh commands instead.
2946 * Monitors are special as they are normally slaved to
2947 * whatever else is going on, so they have their own special
2948 * operation to set the monitor channel if possible.
2951 wdev
->iftype
== NL80211_IFTYPE_AP
||
2952 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
2953 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
2954 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
2957 int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
2958 struct genl_info
*info
,
2959 struct cfg80211_chan_def
*chandef
)
2961 struct netlink_ext_ack
*extack
= info
->extack
;
2962 struct nlattr
**attrs
= info
->attrs
;
2965 if (!attrs
[NL80211_ATTR_WIPHY_FREQ
])
2968 control_freq
= MHZ_TO_KHZ(
2969 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2970 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
])
2972 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
]);
2974 memset(chandef
, 0, sizeof(*chandef
));
2975 chandef
->chan
= ieee80211_get_channel_khz(&rdev
->wiphy
, control_freq
);
2976 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
2977 chandef
->center_freq1
= KHZ_TO_MHZ(control_freq
);
2978 chandef
->freq1_offset
= control_freq
% 1000;
2979 chandef
->center_freq2
= 0;
2981 /* Primary channel not allowed */
2982 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
) {
2983 NL_SET_ERR_MSG_ATTR(extack
, attrs
[NL80211_ATTR_WIPHY_FREQ
],
2984 "Channel is disabled");
2988 if (attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2989 enum nl80211_channel_type chantype
;
2991 chantype
= nla_get_u32(attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2994 case NL80211_CHAN_NO_HT
:
2995 case NL80211_CHAN_HT20
:
2996 case NL80211_CHAN_HT40PLUS
:
2997 case NL80211_CHAN_HT40MINUS
:
2998 cfg80211_chandef_create(chandef
, chandef
->chan
,
3000 /* user input for center_freq is incorrect */
3001 if (attrs
[NL80211_ATTR_CENTER_FREQ1
] &&
3002 chandef
->center_freq1
!= nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ1
])) {
3003 NL_SET_ERR_MSG_ATTR(extack
,
3004 attrs
[NL80211_ATTR_CENTER_FREQ1
],
3005 "bad center frequency 1");
3008 /* center_freq2 must be zero */
3009 if (attrs
[NL80211_ATTR_CENTER_FREQ2
] &&
3010 nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ2
])) {
3011 NL_SET_ERR_MSG_ATTR(extack
,
3012 attrs
[NL80211_ATTR_CENTER_FREQ2
],
3013 "center frequency 2 can't be used");
3018 NL_SET_ERR_MSG_ATTR(extack
,
3019 attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
],
3020 "invalid channel type");
3023 } else if (attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
3025 nla_get_u32(attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
3026 if (attrs
[NL80211_ATTR_CENTER_FREQ1
]) {
3027 chandef
->center_freq1
=
3028 nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ1
]);
3029 if (attrs
[NL80211_ATTR_CENTER_FREQ1_OFFSET
])
3030 chandef
->freq1_offset
= nla_get_u32(
3031 attrs
[NL80211_ATTR_CENTER_FREQ1_OFFSET
]);
3033 chandef
->freq1_offset
= 0;
3035 if (attrs
[NL80211_ATTR_CENTER_FREQ2
])
3036 chandef
->center_freq2
=
3037 nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ2
]);
3040 if (info
->attrs
[NL80211_ATTR_WIPHY_EDMG_CHANNELS
]) {
3041 chandef
->edmg
.channels
=
3042 nla_get_u8(info
->attrs
[NL80211_ATTR_WIPHY_EDMG_CHANNELS
]);
3044 if (info
->attrs
[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
])
3045 chandef
->edmg
.bw_config
=
3046 nla_get_u8(info
->attrs
[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
]);
3048 chandef
->edmg
.bw_config
= 0;
3049 chandef
->edmg
.channels
= 0;
3052 if (!cfg80211_chandef_valid(chandef
)) {
3053 NL_SET_ERR_MSG(extack
, "invalid channel definition");
3057 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
3058 IEEE80211_CHAN_DISABLED
)) {
3059 NL_SET_ERR_MSG(extack
, "(extension) channel is disabled");
3063 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
3064 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
3065 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
)) {
3066 NL_SET_ERR_MSG(extack
, "5/10 MHz not supported");
3073 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
3074 struct net_device
*dev
,
3075 struct genl_info
*info
)
3077 struct cfg80211_chan_def chandef
;
3079 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
3080 struct wireless_dev
*wdev
= NULL
;
3083 wdev
= dev
->ieee80211_ptr
;
3084 if (!nl80211_can_set_dev_channel(wdev
))
3087 iftype
= wdev
->iftype
;
3089 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
3094 case NL80211_IFTYPE_AP
:
3095 case NL80211_IFTYPE_P2P_GO
:
3096 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
3101 if (wdev
->beacon_interval
) {
3102 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
3103 !(rdev
->wiphy
.features
&
3104 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
3109 /* Only allow dynamic channel width changes */
3110 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
3114 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
3118 wdev
->preset_chandef
= chandef
;
3121 case NL80211_IFTYPE_MESH_POINT
:
3122 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
3124 case NL80211_IFTYPE_MONITOR
:
3125 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
3134 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
3136 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3137 struct net_device
*netdev
= info
->user_ptr
[1];
3139 return __nl80211_set_channel(rdev
, netdev
, info
);
3142 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
3144 struct cfg80211_registered_device
*rdev
;
3145 struct net_device
*netdev
= NULL
;
3146 struct wireless_dev
*wdev
;
3147 int result
= 0, rem_txq_params
= 0;
3148 struct nlattr
*nl_txq_params
;
3150 u8 retry_short
= 0, retry_long
= 0;
3151 u32 frag_threshold
= 0, rts_threshold
= 0;
3152 u8 coverage_class
= 0;
3153 u32 txq_limit
= 0, txq_memory_limit
= 0, txq_quantum
= 0;
3158 * Try to find the wiphy and netdev. Normally this
3159 * function shouldn't need the netdev, but this is
3160 * done for backward compatibility -- previously
3161 * setting the channel was done per wiphy, but now
3162 * it is per netdev. Previous userland like hostapd
3163 * also passed a netdev to set_wiphy, so that it is
3164 * possible to let that go to the right netdev!
3167 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
3168 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
3170 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
3171 if (netdev
&& netdev
->ieee80211_ptr
)
3172 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
3178 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
3181 return PTR_ERR(rdev
);
3186 wdev
= netdev
->ieee80211_ptr
;
3189 * end workaround code, by now the rdev is available
3190 * and locked, and wdev may or may not be NULL.
3193 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
3194 result
= cfg80211_dev_rename(
3195 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
3200 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
3201 struct ieee80211_txq_params txq_params
;
3202 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
3204 if (!rdev
->ops
->set_txq_params
)
3210 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3211 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3214 if (!netif_running(netdev
))
3217 nla_for_each_nested(nl_txq_params
,
3218 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
3220 result
= nla_parse_nested_deprecated(tb
,
3221 NL80211_TXQ_ATTR_MAX
,
3227 result
= parse_txq_params(tb
, &txq_params
);
3231 result
= rdev_set_txq_params(rdev
, netdev
,
3238 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3239 result
= __nl80211_set_channel(
3241 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
3247 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
3248 struct wireless_dev
*txp_wdev
= wdev
;
3249 enum nl80211_tx_power_setting type
;
3252 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
3255 if (!rdev
->ops
->set_tx_power
)
3258 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
3259 type
= nla_get_u32(info
->attrs
[idx
]);
3261 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
3262 (type
!= NL80211_TX_POWER_AUTOMATIC
))
3265 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
3266 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
3267 mbm
= nla_get_u32(info
->attrs
[idx
]);
3270 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
3275 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
3276 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
3279 if ((!rdev
->wiphy
.available_antennas_tx
&&
3280 !rdev
->wiphy
.available_antennas_rx
) ||
3281 !rdev
->ops
->set_antenna
)
3284 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
3285 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
3287 /* reject antenna configurations which don't match the
3288 * available antenna masks, except for the "all" mask */
3289 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
3290 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
3293 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
3294 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
3296 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
3303 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
3304 retry_short
= nla_get_u8(
3305 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
3307 changed
|= WIPHY_PARAM_RETRY_SHORT
;
3310 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
3311 retry_long
= nla_get_u8(
3312 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
3314 changed
|= WIPHY_PARAM_RETRY_LONG
;
3317 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
3318 frag_threshold
= nla_get_u32(
3319 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
3320 if (frag_threshold
< 256)
3323 if (frag_threshold
!= (u32
) -1) {
3325 * Fragments (apart from the last one) are required to
3326 * have even length. Make the fragmentation code
3327 * simpler by stripping LSB should someone try to use
3328 * odd threshold value.
3330 frag_threshold
&= ~0x1;
3332 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
3335 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
3336 rts_threshold
= nla_get_u32(
3337 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
3338 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
3341 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
3342 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
3345 coverage_class
= nla_get_u8(
3346 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
3347 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
3350 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
3351 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
3354 changed
|= WIPHY_PARAM_DYN_ACK
;
3357 if (info
->attrs
[NL80211_ATTR_TXQ_LIMIT
]) {
3358 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
3359 NL80211_EXT_FEATURE_TXQS
))
3361 txq_limit
= nla_get_u32(
3362 info
->attrs
[NL80211_ATTR_TXQ_LIMIT
]);
3363 changed
|= WIPHY_PARAM_TXQ_LIMIT
;
3366 if (info
->attrs
[NL80211_ATTR_TXQ_MEMORY_LIMIT
]) {
3367 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
3368 NL80211_EXT_FEATURE_TXQS
))
3370 txq_memory_limit
= nla_get_u32(
3371 info
->attrs
[NL80211_ATTR_TXQ_MEMORY_LIMIT
]);
3372 changed
|= WIPHY_PARAM_TXQ_MEMORY_LIMIT
;
3375 if (info
->attrs
[NL80211_ATTR_TXQ_QUANTUM
]) {
3376 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
3377 NL80211_EXT_FEATURE_TXQS
))
3379 txq_quantum
= nla_get_u32(
3380 info
->attrs
[NL80211_ATTR_TXQ_QUANTUM
]);
3381 changed
|= WIPHY_PARAM_TXQ_QUANTUM
;
3385 u8 old_retry_short
, old_retry_long
;
3386 u32 old_frag_threshold
, old_rts_threshold
;
3387 u8 old_coverage_class
;
3388 u32 old_txq_limit
, old_txq_memory_limit
, old_txq_quantum
;
3390 if (!rdev
->ops
->set_wiphy_params
)
3393 old_retry_short
= rdev
->wiphy
.retry_short
;
3394 old_retry_long
= rdev
->wiphy
.retry_long
;
3395 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
3396 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
3397 old_coverage_class
= rdev
->wiphy
.coverage_class
;
3398 old_txq_limit
= rdev
->wiphy
.txq_limit
;
3399 old_txq_memory_limit
= rdev
->wiphy
.txq_memory_limit
;
3400 old_txq_quantum
= rdev
->wiphy
.txq_quantum
;
3402 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
3403 rdev
->wiphy
.retry_short
= retry_short
;
3404 if (changed
& WIPHY_PARAM_RETRY_LONG
)
3405 rdev
->wiphy
.retry_long
= retry_long
;
3406 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
3407 rdev
->wiphy
.frag_threshold
= frag_threshold
;
3408 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
3409 rdev
->wiphy
.rts_threshold
= rts_threshold
;
3410 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
3411 rdev
->wiphy
.coverage_class
= coverage_class
;
3412 if (changed
& WIPHY_PARAM_TXQ_LIMIT
)
3413 rdev
->wiphy
.txq_limit
= txq_limit
;
3414 if (changed
& WIPHY_PARAM_TXQ_MEMORY_LIMIT
)
3415 rdev
->wiphy
.txq_memory_limit
= txq_memory_limit
;
3416 if (changed
& WIPHY_PARAM_TXQ_QUANTUM
)
3417 rdev
->wiphy
.txq_quantum
= txq_quantum
;
3419 result
= rdev_set_wiphy_params(rdev
, changed
);
3421 rdev
->wiphy
.retry_short
= old_retry_short
;
3422 rdev
->wiphy
.retry_long
= old_retry_long
;
3423 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
3424 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
3425 rdev
->wiphy
.coverage_class
= old_coverage_class
;
3426 rdev
->wiphy
.txq_limit
= old_txq_limit
;
3427 rdev
->wiphy
.txq_memory_limit
= old_txq_memory_limit
;
3428 rdev
->wiphy
.txq_quantum
= old_txq_quantum
;
3435 static int nl80211_send_chandef(struct sk_buff
*msg
,
3436 const struct cfg80211_chan_def
*chandef
)
3438 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
3441 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
3442 chandef
->chan
->center_freq
))
3444 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_OFFSET
,
3445 chandef
->chan
->freq_offset
))
3447 switch (chandef
->width
) {
3448 case NL80211_CHAN_WIDTH_20_NOHT
:
3449 case NL80211_CHAN_WIDTH_20
:
3450 case NL80211_CHAN_WIDTH_40
:
3451 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
3452 cfg80211_get_chandef_type(chandef
)))
3458 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
3460 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
3462 if (chandef
->center_freq2
&&
3463 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
3468 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
3469 struct cfg80211_registered_device
*rdev
,
3470 struct wireless_dev
*wdev
,
3471 enum nl80211_commands cmd
)
3473 struct net_device
*dev
= wdev
->netdev
;
3476 WARN_ON(cmd
!= NL80211_CMD_NEW_INTERFACE
&&
3477 cmd
!= NL80211_CMD_DEL_INTERFACE
&&
3478 cmd
!= NL80211_CMD_SET_INTERFACE
);
3480 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
3485 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3486 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
3487 goto nla_put_failure
;
3489 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
3490 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
3491 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
3492 NL80211_ATTR_PAD
) ||
3493 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
3494 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
3495 rdev
->devlist_generation
^
3496 (cfg80211_rdev_list_generation
<< 2)) ||
3497 nla_put_u8(msg
, NL80211_ATTR_4ADDR
, wdev
->use_4addr
))
3498 goto nla_put_failure
;
3500 if (rdev
->ops
->get_channel
) {
3502 struct cfg80211_chan_def chandef
= {};
3504 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
3506 if (nl80211_send_chandef(msg
, &chandef
))
3507 goto nla_put_failure
;
3511 if (rdev
->ops
->get_tx_power
) {
3514 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
3516 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
3518 goto nla_put_failure
;
3522 switch (wdev
->iftype
) {
3523 case NL80211_IFTYPE_AP
:
3524 if (wdev
->ssid_len
&&
3525 nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
3526 goto nla_put_failure_locked
;
3528 case NL80211_IFTYPE_STATION
:
3529 case NL80211_IFTYPE_P2P_CLIENT
:
3530 case NL80211_IFTYPE_ADHOC
: {
3532 if (!wdev
->current_bss
)
3535 ssid_ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
3538 nla_put(msg
, NL80211_ATTR_SSID
, ssid_ie
[1], ssid_ie
+ 2))
3539 goto nla_put_failure_rcu_locked
;
3549 if (rdev
->ops
->get_txq_stats
) {
3550 struct cfg80211_txq_stats txqstats
= {};
3551 int ret
= rdev_get_txq_stats(rdev
, wdev
, &txqstats
);
3554 !nl80211_put_txq_stats(msg
, &txqstats
,
3555 NL80211_ATTR_TXQ_STATS
))
3556 goto nla_put_failure
;
3559 genlmsg_end(msg
, hdr
);
3562 nla_put_failure_rcu_locked
:
3564 nla_put_failure_locked
:
3567 genlmsg_cancel(msg
, hdr
);
3571 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3575 int wp_start
= cb
->args
[0];
3576 int if_start
= cb
->args
[1];
3577 int filter_wiphy
= -1;
3578 struct cfg80211_registered_device
*rdev
;
3579 struct wireless_dev
*wdev
;
3584 struct nl80211_dump_wiphy_state state
= {
3588 ret
= nl80211_dump_wiphy_parse(skb
, cb
, &state
);
3592 filter_wiphy
= state
.filter_wiphy
;
3595 * if filtering, set cb->args[2] to +1 since 0 is the default
3596 * value needed to determine that parsing is necessary.
3598 if (filter_wiphy
>= 0)
3599 cb
->args
[2] = filter_wiphy
+ 1;
3602 } else if (cb
->args
[2] > 0) {
3603 filter_wiphy
= cb
->args
[2] - 1;
3606 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
3607 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
3609 if (wp_idx
< wp_start
) {
3614 if (filter_wiphy
>= 0 && filter_wiphy
!= rdev
->wiphy_idx
)
3619 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
3620 if (if_idx
< if_start
) {
3624 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
3625 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3627 NL80211_CMD_NEW_INTERFACE
) < 0) {
3636 cb
->args
[0] = wp_idx
;
3637 cb
->args
[1] = if_idx
;
3646 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3648 struct sk_buff
*msg
;
3649 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3650 struct wireless_dev
*wdev
= info
->user_ptr
[1];
3652 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3656 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3657 rdev
, wdev
, NL80211_CMD_NEW_INTERFACE
) < 0) {
3662 return genlmsg_reply(msg
, info
);
3665 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
3666 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
3667 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
3668 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
3669 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
3670 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
3671 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
3674 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
3676 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
3684 if (nla_parse_nested_deprecated(flags
, NL80211_MNTR_FLAG_MAX
, nla
, mntr_flags_policy
, NULL
))
3687 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
3689 *mntrflags
|= (1<<flag
);
3691 *mntrflags
|= MONITOR_FLAG_CHANGED
;
3696 static int nl80211_parse_mon_options(struct cfg80211_registered_device
*rdev
,
3697 enum nl80211_iftype type
,
3698 struct genl_info
*info
,
3699 struct vif_params
*params
)
3701 bool change
= false;
3704 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
3705 if (type
!= NL80211_IFTYPE_MONITOR
)
3708 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
3716 if (params
->flags
& MONITOR_FLAG_ACTIVE
&&
3717 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
3720 if (info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]) {
3721 const u8
*mumimo_groups
;
3722 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
3724 if (type
!= NL80211_IFTYPE_MONITOR
)
3727 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
3731 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]);
3733 /* bits 0 and 63 are reserved and must be zero */
3734 if ((mumimo_groups
[0] & BIT(0)) ||
3735 (mumimo_groups
[VHT_MUMIMO_GROUPS_DATA_LEN
- 1] & BIT(7)))
3738 params
->vht_mumimo_groups
= mumimo_groups
;
3742 if (info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]) {
3743 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
3745 if (type
!= NL80211_IFTYPE_MONITOR
)
3748 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
3751 params
->vht_mumimo_follow_addr
=
3752 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]);
3756 return change
? 1 : 0;
3759 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
3760 struct net_device
*netdev
, u8 use_4addr
,
3761 enum nl80211_iftype iftype
)
3764 if (netdev
&& netif_is_bridge_port(netdev
))
3770 case NL80211_IFTYPE_AP_VLAN
:
3771 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
3774 case NL80211_IFTYPE_STATION
:
3775 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
3785 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3787 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3788 struct vif_params params
;
3790 enum nl80211_iftype otype
, ntype
;
3791 struct net_device
*dev
= info
->user_ptr
[1];
3792 bool change
= false;
3794 memset(¶ms
, 0, sizeof(params
));
3796 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
3798 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
3799 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
3804 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
3805 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3807 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
3809 if (netif_running(dev
))
3813 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
3814 IEEE80211_MAX_MESH_ID_LEN
);
3815 wdev
->mesh_id_up_len
=
3816 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
3817 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
3818 wdev
->mesh_id_up_len
);
3822 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
3823 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
3825 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
3829 params
.use_4addr
= -1;
3832 err
= nl80211_parse_mon_options(rdev
, ntype
, info
, ¶ms
);
3839 err
= cfg80211_change_iface(rdev
, dev
, ntype
, ¶ms
);
3843 if (!err
&& params
.use_4addr
!= -1)
3844 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
3846 if (change
&& !err
) {
3847 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3849 nl80211_notify_iface(rdev
, wdev
, NL80211_CMD_SET_INTERFACE
);
3855 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3857 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3858 struct vif_params params
;
3859 struct wireless_dev
*wdev
;
3860 struct sk_buff
*msg
;
3862 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
3864 /* to avoid failing a new interface creation due to pending removal */
3865 cfg80211_destroy_ifaces(rdev
);
3867 memset(¶ms
, 0, sizeof(params
));
3869 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
3872 if (info
->attrs
[NL80211_ATTR_IFTYPE
])
3873 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
3875 if (!rdev
->ops
->add_virtual_intf
)
3878 if ((type
== NL80211_IFTYPE_P2P_DEVICE
|| type
== NL80211_IFTYPE_NAN
||
3879 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
3880 info
->attrs
[NL80211_ATTR_MAC
]) {
3881 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
3883 if (!is_valid_ether_addr(params
.macaddr
))
3884 return -EADDRNOTAVAIL
;
3887 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
3888 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
3889 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
3894 if (!cfg80211_iftype_allowed(&rdev
->wiphy
, type
, params
.use_4addr
, 0))
3897 err
= nl80211_parse_mon_options(rdev
, type
, info
, ¶ms
);
3901 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3905 wdev
= rdev_add_virtual_intf(rdev
,
3906 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
3907 NET_NAME_USER
, type
, ¶ms
);
3908 if (WARN_ON(!wdev
)) {
3911 } else if (IS_ERR(wdev
)) {
3913 return PTR_ERR(wdev
);
3916 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
3917 wdev
->owner_nlportid
= info
->snd_portid
;
3920 case NL80211_IFTYPE_MESH_POINT
:
3921 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
3924 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
3925 IEEE80211_MAX_MESH_ID_LEN
);
3926 wdev
->mesh_id_up_len
=
3927 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
3928 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
3929 wdev
->mesh_id_up_len
);
3932 case NL80211_IFTYPE_NAN
:
3933 case NL80211_IFTYPE_P2P_DEVICE
:
3935 * P2P Device and NAN do not have a netdev, so don't go
3936 * through the netdev notifier and must be added here
3938 cfg80211_init_wdev(wdev
);
3939 cfg80211_register_wdev(rdev
, wdev
);
3945 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3946 rdev
, wdev
, NL80211_CMD_NEW_INTERFACE
) < 0) {
3951 return genlmsg_reply(msg
, info
);
3954 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3956 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3957 struct wireless_dev
*wdev
= info
->user_ptr
[1];
3959 if (!rdev
->ops
->del_virtual_intf
)
3963 * If we remove a wireless device without a netdev then clear
3964 * user_ptr[1] so that nl80211_post_doit won't dereference it
3965 * to check if it needs to do dev_put(). Otherwise it crashes
3966 * since the wdev has been freed, unlike with a netdev where
3967 * we need the dev_put() for the netdev to really be freed.
3970 info
->user_ptr
[1] = NULL
;
3972 return rdev_del_virtual_intf(rdev
, wdev
);
3975 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
3977 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3978 struct net_device
*dev
= info
->user_ptr
[1];
3981 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
3984 if (!rdev
->ops
->set_noack_map
)
3987 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
3989 return rdev_set_noack_map(rdev
, dev
, noack_map
);
3992 struct get_key_cookie
{
3993 struct sk_buff
*msg
;
3998 static void get_key_callback(void *c
, struct key_params
*params
)
4001 struct get_key_cookie
*cookie
= c
;
4004 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
4005 params
->key_len
, params
->key
)) ||
4007 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
4008 params
->seq_len
, params
->seq
)) ||
4010 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
4012 goto nla_put_failure
;
4014 key
= nla_nest_start_noflag(cookie
->msg
, NL80211_ATTR_KEY
);
4016 goto nla_put_failure
;
4019 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
4020 params
->key_len
, params
->key
)) ||
4022 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
4023 params
->seq_len
, params
->seq
)) ||
4025 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
4027 goto nla_put_failure
;
4029 if (nla_put_u8(cookie
->msg
, NL80211_KEY_IDX
, cookie
->idx
))
4030 goto nla_put_failure
;
4032 nla_nest_end(cookie
->msg
, key
);
4039 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
4041 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4043 struct net_device
*dev
= info
->user_ptr
[1];
4045 const u8
*mac_addr
= NULL
;
4047 struct get_key_cookie cookie
= {
4051 struct sk_buff
*msg
;
4052 bool bigtk_support
= false;
4054 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
4055 NL80211_EXT_FEATURE_BEACON_PROTECTION
))
4056 bigtk_support
= true;
4058 if ((dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_STATION
||
4059 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_CLIENT
) &&
4060 wiphy_ext_feature_isset(&rdev
->wiphy
,
4061 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT
))
4062 bigtk_support
= true;
4064 if (info
->attrs
[NL80211_ATTR_KEY_IDX
]) {
4065 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
4067 if (key_idx
>= 6 && key_idx
<= 7 && !bigtk_support
) {
4068 GENL_SET_ERR_MSG(info
, "BIGTK not supported");
4073 if (info
->attrs
[NL80211_ATTR_MAC
])
4074 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4076 pairwise
= !!mac_addr
;
4077 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
4078 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
4080 if (kt
!= NL80211_KEYTYPE_GROUP
&&
4081 kt
!= NL80211_KEYTYPE_PAIRWISE
)
4083 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
4086 if (!rdev
->ops
->get_key
)
4089 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
4092 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4096 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4097 NL80211_CMD_NEW_KEY
);
4099 goto nla_put_failure
;
4102 cookie
.idx
= key_idx
;
4104 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4105 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
4106 goto nla_put_failure
;
4108 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
4109 goto nla_put_failure
;
4111 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
4118 goto nla_put_failure
;
4120 genlmsg_end(msg
, hdr
);
4121 return genlmsg_reply(msg
, info
);
4130 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
4132 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4133 struct key_parse key
;
4135 struct net_device
*dev
= info
->user_ptr
[1];
4137 err
= nl80211_parse_key(info
, &key
);
4144 /* Only support setting default key and
4145 * Extended Key ID action NL80211_KEY_SET_TX.
4147 if (!key
.def
&& !key
.defmgmt
&& !key
.defbeacon
&&
4148 !(key
.p
.mode
== NL80211_KEY_SET_TX
))
4151 wdev_lock(dev
->ieee80211_ptr
);
4154 if (!rdev
->ops
->set_default_key
) {
4159 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
4163 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
4164 key
.def_uni
, key
.def_multi
);
4169 #ifdef CONFIG_CFG80211_WEXT
4170 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
4172 } else if (key
.defmgmt
) {
4173 if (key
.def_uni
|| !key
.def_multi
) {
4178 if (!rdev
->ops
->set_default_mgmt_key
) {
4183 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
4187 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
4191 #ifdef CONFIG_CFG80211_WEXT
4192 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
4194 } else if (key
.defbeacon
) {
4195 if (key
.def_uni
|| !key
.def_multi
) {
4200 if (!rdev
->ops
->set_default_beacon_key
) {
4205 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
4209 err
= rdev_set_default_beacon_key(rdev
, dev
, key
.idx
);
4212 } else if (key
.p
.mode
== NL80211_KEY_SET_TX
&&
4213 wiphy_ext_feature_isset(&rdev
->wiphy
,
4214 NL80211_EXT_FEATURE_EXT_KEY_ID
)) {
4215 u8
*mac_addr
= NULL
;
4217 if (info
->attrs
[NL80211_ATTR_MAC
])
4218 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4220 if (!mac_addr
|| key
.idx
< 0 || key
.idx
> 1) {
4225 err
= rdev_add_key(rdev
, dev
, key
.idx
,
4226 NL80211_KEYTYPE_PAIRWISE
,
4232 wdev_unlock(dev
->ieee80211_ptr
);
4237 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
4239 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4241 struct net_device
*dev
= info
->user_ptr
[1];
4242 struct key_parse key
;
4243 const u8
*mac_addr
= NULL
;
4245 err
= nl80211_parse_key(info
, &key
);
4250 GENL_SET_ERR_MSG(info
, "no key");
4254 if (info
->attrs
[NL80211_ATTR_MAC
])
4255 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4257 if (key
.type
== -1) {
4259 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
4261 key
.type
= NL80211_KEYTYPE_GROUP
;
4265 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
4266 key
.type
!= NL80211_KEYTYPE_GROUP
) {
4267 GENL_SET_ERR_MSG(info
, "key type not pairwise or group");
4271 if (key
.type
== NL80211_KEYTYPE_GROUP
&&
4272 info
->attrs
[NL80211_ATTR_VLAN_ID
])
4273 key
.p
.vlan_id
= nla_get_u16(info
->attrs
[NL80211_ATTR_VLAN_ID
]);
4275 if (!rdev
->ops
->add_key
)
4278 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
4279 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
4281 GENL_SET_ERR_MSG(info
, "key setting validation failed");
4285 wdev_lock(dev
->ieee80211_ptr
);
4286 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
4288 GENL_SET_ERR_MSG(info
, "key not allowed");
4290 err
= rdev_add_key(rdev
, dev
, key
.idx
,
4291 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
4294 GENL_SET_ERR_MSG(info
, "key addition failed");
4296 wdev_unlock(dev
->ieee80211_ptr
);
4301 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
4303 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4305 struct net_device
*dev
= info
->user_ptr
[1];
4306 u8
*mac_addr
= NULL
;
4307 struct key_parse key
;
4309 err
= nl80211_parse_key(info
, &key
);
4313 if (info
->attrs
[NL80211_ATTR_MAC
])
4314 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4316 if (key
.type
== -1) {
4318 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
4320 key
.type
= NL80211_KEYTYPE_GROUP
;
4324 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
4325 key
.type
!= NL80211_KEYTYPE_GROUP
)
4328 if (!cfg80211_valid_key_idx(rdev
, key
.idx
,
4329 key
.type
== NL80211_KEYTYPE_PAIRWISE
))
4332 if (!rdev
->ops
->del_key
)
4335 wdev_lock(dev
->ieee80211_ptr
);
4336 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
4338 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
4339 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
4343 err
= rdev_del_key(rdev
, dev
, key
.idx
,
4344 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
4347 #ifdef CONFIG_CFG80211_WEXT
4349 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
4350 dev
->ieee80211_ptr
->wext
.default_key
= -1;
4351 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
4352 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
4355 wdev_unlock(dev
->ieee80211_ptr
);
4360 /* This function returns an error or the number of nested attributes */
4361 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
4363 struct nlattr
*attr
;
4364 int n_entries
= 0, tmp
;
4366 nla_for_each_nested(attr
, nl_attr
, tmp
) {
4367 if (nla_len(attr
) != ETH_ALEN
)
4377 * This function parses ACL information and allocates memory for ACL data.
4378 * On successful return, the calling function is responsible to free the
4379 * ACL buffer returned by this function.
4381 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
4382 struct genl_info
*info
)
4384 enum nl80211_acl_policy acl_policy
;
4385 struct nlattr
*attr
;
4386 struct cfg80211_acl_data
*acl
;
4387 int i
= 0, n_entries
, tmp
;
4389 if (!wiphy
->max_acl_mac_addrs
)
4390 return ERR_PTR(-EOPNOTSUPP
);
4392 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
4393 return ERR_PTR(-EINVAL
);
4395 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
4396 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
4397 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
4398 return ERR_PTR(-EINVAL
);
4400 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
4401 return ERR_PTR(-EINVAL
);
4403 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
4405 return ERR_PTR(n_entries
);
4407 if (n_entries
> wiphy
->max_acl_mac_addrs
)
4408 return ERR_PTR(-ENOTSUPP
);
4410 acl
= kzalloc(struct_size(acl
, mac_addrs
, n_entries
), GFP_KERNEL
);
4412 return ERR_PTR(-ENOMEM
);
4414 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
4415 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
4419 acl
->n_acl_entries
= n_entries
;
4420 acl
->acl_policy
= acl_policy
;
4425 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
4427 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4428 struct net_device
*dev
= info
->user_ptr
[1];
4429 struct cfg80211_acl_data
*acl
;
4432 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4433 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4436 if (!dev
->ieee80211_ptr
->beacon_interval
)
4439 acl
= parse_acl_data(&rdev
->wiphy
, info
);
4441 return PTR_ERR(acl
);
4443 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
4450 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4451 u8
*rates
, u8 rates_len
)
4456 for (i
= 0; i
< rates_len
; i
++) {
4457 int rate
= (rates
[i
] & 0x7f) * 5;
4460 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4461 struct ieee80211_rate
*srate
=
4462 &sband
->bitrates
[ridx
];
4463 if (rate
== srate
->bitrate
) {
4468 if (ridx
== sband
->n_bitrates
)
4469 return 0; /* rate not found */
4475 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
4476 u8
*rates
, u8 rates_len
,
4477 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
4481 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
4483 for (i
= 0; i
< rates_len
; i
++) {
4486 ridx
= rates
[i
] / 8;
4487 rbit
= BIT(rates
[i
] % 8);
4489 /* check validity */
4490 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
4493 /* check availability */
4494 ridx
= array_index_nospec(ridx
, IEEE80211_HT_MCS_MASK_LEN
);
4495 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
4504 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
4508 switch (vht_mcs_map
) {
4509 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
4511 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
4514 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
4517 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
4527 static void vht_build_mcs_mask(u16 vht_mcs_map
,
4528 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
4532 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
4533 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
4538 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
4539 struct nl80211_txrate_vht
*txrate
,
4540 u16 mcs
[NL80211_VHT_NSS_MAX
])
4542 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
4543 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
4546 if (!sband
->vht_cap
.vht_supported
)
4549 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
4551 /* Build vht_mcs_mask from VHT capabilities */
4552 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
4554 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4555 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
4556 mcs
[i
] = txrate
->mcs
[i
];
4564 static u16
he_mcs_map_to_mcs_mask(u8 he_mcs_map
)
4566 switch (he_mcs_map
) {
4567 case IEEE80211_HE_MCS_NOT_SUPPORTED
:
4569 case IEEE80211_HE_MCS_SUPPORT_0_7
:
4571 case IEEE80211_HE_MCS_SUPPORT_0_9
:
4573 case IEEE80211_HE_MCS_SUPPORT_0_11
:
4581 static void he_build_mcs_mask(u16 he_mcs_map
,
4582 u16 he_mcs_mask
[NL80211_HE_NSS_MAX
])
4586 for (nss
= 0; nss
< NL80211_HE_NSS_MAX
; nss
++) {
4587 he_mcs_mask
[nss
] = he_mcs_map_to_mcs_mask(he_mcs_map
& 0x03);
4592 static u16
he_get_txmcsmap(struct genl_info
*info
,
4593 const struct ieee80211_sta_he_cap
*he_cap
)
4595 struct net_device
*dev
= info
->user_ptr
[1];
4596 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4599 switch (wdev
->chandef
.width
) {
4600 case NL80211_CHAN_WIDTH_80P80
:
4601 tx_mcs
= he_cap
->he_mcs_nss_supp
.tx_mcs_80p80
;
4603 case NL80211_CHAN_WIDTH_160
:
4604 tx_mcs
= he_cap
->he_mcs_nss_supp
.tx_mcs_160
;
4607 tx_mcs
= he_cap
->he_mcs_nss_supp
.tx_mcs_80
;
4610 return le16_to_cpu(tx_mcs
);
4613 static bool he_set_mcs_mask(struct genl_info
*info
,
4614 struct wireless_dev
*wdev
,
4615 struct ieee80211_supported_band
*sband
,
4616 struct nl80211_txrate_he
*txrate
,
4617 u16 mcs
[NL80211_HE_NSS_MAX
])
4619 const struct ieee80211_sta_he_cap
*he_cap
;
4620 u16 tx_mcs_mask
[NL80211_HE_NSS_MAX
] = {};
4624 he_cap
= ieee80211_get_he_iftype_cap(sband
, wdev
->iftype
);
4628 memset(mcs
, 0, sizeof(u16
) * NL80211_HE_NSS_MAX
);
4630 tx_mcs_map
= he_get_txmcsmap(info
, he_cap
);
4632 /* Build he_mcs_mask from HE capabilities */
4633 he_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
4635 for (i
= 0; i
< NL80211_HE_NSS_MAX
; i
++) {
4636 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
4637 mcs
[i
] = txrate
->mcs
[i
];
4645 static int nl80211_parse_tx_bitrate_mask(struct genl_info
*info
,
4646 struct nlattr
*attrs
[],
4647 enum nl80211_attrs attr
,
4648 struct cfg80211_bitrate_mask
*mask
,
4649 struct net_device
*dev
,
4650 bool default_all_enabled
)
4652 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4653 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4654 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4656 struct nlattr
*tx_rates
;
4657 struct ieee80211_supported_band
*sband
;
4658 u16 vht_tx_mcs_map
, he_tx_mcs_map
;
4660 memset(mask
, 0, sizeof(*mask
));
4661 /* Default to all rates enabled */
4662 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
4663 const struct ieee80211_sta_he_cap
*he_cap
;
4665 if (!default_all_enabled
)
4668 sband
= rdev
->wiphy
.bands
[i
];
4673 mask
->control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
4674 memcpy(mask
->control
[i
].ht_mcs
,
4675 sband
->ht_cap
.mcs
.rx_mask
,
4676 sizeof(mask
->control
[i
].ht_mcs
));
4678 if (!sband
->vht_cap
.vht_supported
)
4681 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
4682 vht_build_mcs_mask(vht_tx_mcs_map
, mask
->control
[i
].vht_mcs
);
4684 he_cap
= ieee80211_get_he_iftype_cap(sband
, wdev
->iftype
);
4688 he_tx_mcs_map
= he_get_txmcsmap(info
, he_cap
);
4689 he_build_mcs_mask(he_tx_mcs_map
, mask
->control
[i
].he_mcs
);
4691 mask
->control
[i
].he_gi
= 0xFF;
4692 mask
->control
[i
].he_ltf
= 0xFF;
4695 /* if no rates are given set it back to the defaults */
4699 /* The nested attribute uses enum nl80211_band as the index. This maps
4700 * directly to the enum nl80211_band values used in cfg80211.
4702 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
4703 nla_for_each_nested(tx_rates
, attrs
[attr
], rem
) {
4704 enum nl80211_band band
= nla_type(tx_rates
);
4707 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
4709 sband
= rdev
->wiphy
.bands
[band
];
4712 err
= nla_parse_nested_deprecated(tb
, NL80211_TXRATE_MAX
,
4714 nl80211_txattr_policy
,
4718 if (tb
[NL80211_TXRATE_LEGACY
]) {
4719 mask
->control
[band
].legacy
= rateset_to_mask(
4721 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4722 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4723 if ((mask
->control
[band
].legacy
== 0) &&
4724 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
4727 if (tb
[NL80211_TXRATE_HT
]) {
4728 if (!ht_rateset_to_mask(
4730 nla_data(tb
[NL80211_TXRATE_HT
]),
4731 nla_len(tb
[NL80211_TXRATE_HT
]),
4732 mask
->control
[band
].ht_mcs
))
4736 if (tb
[NL80211_TXRATE_VHT
]) {
4737 if (!vht_set_mcs_mask(
4739 nla_data(tb
[NL80211_TXRATE_VHT
]),
4740 mask
->control
[band
].vht_mcs
))
4744 if (tb
[NL80211_TXRATE_GI
]) {
4745 mask
->control
[band
].gi
=
4746 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
4747 if (mask
->control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
4750 if (tb
[NL80211_TXRATE_HE
] &&
4751 !he_set_mcs_mask(info
, wdev
, sband
,
4752 nla_data(tb
[NL80211_TXRATE_HE
]),
4753 mask
->control
[band
].he_mcs
))
4756 if (tb
[NL80211_TXRATE_HE_GI
])
4757 mask
->control
[band
].he_gi
=
4758 nla_get_u8(tb
[NL80211_TXRATE_HE_GI
]);
4759 if (tb
[NL80211_TXRATE_HE_LTF
])
4760 mask
->control
[band
].he_ltf
=
4761 nla_get_u8(tb
[NL80211_TXRATE_HE_LTF
]);
4763 if (mask
->control
[band
].legacy
== 0) {
4764 /* don't allow empty legacy rates if HT, VHT or HE
4765 * are not even supported.
4767 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
4768 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
||
4769 ieee80211_get_he_iftype_cap(sband
, wdev
->iftype
)))
4772 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
4773 if (mask
->control
[band
].ht_mcs
[i
])
4776 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
4777 if (mask
->control
[band
].vht_mcs
[i
])
4780 for (i
= 0; i
< NL80211_HE_NSS_MAX
; i
++)
4781 if (mask
->control
[band
].he_mcs
[i
])
4784 /* legacy and mcs rates may not be both empty */
4793 static int validate_beacon_tx_rate(struct cfg80211_registered_device
*rdev
,
4794 enum nl80211_band band
,
4795 struct cfg80211_bitrate_mask
*beacon_rate
)
4797 u32 count_ht
, count_vht
, count_he
, i
;
4798 u32 rate
= beacon_rate
->control
[band
].legacy
;
4800 /* Allow only one rate */
4801 if (hweight32(rate
) > 1)
4805 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
4806 if (hweight8(beacon_rate
->control
[band
].ht_mcs
[i
]) > 1) {
4808 } else if (beacon_rate
->control
[band
].ht_mcs
[i
]) {
4813 if (count_ht
&& rate
)
4818 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4819 if (hweight16(beacon_rate
->control
[band
].vht_mcs
[i
]) > 1) {
4821 } else if (beacon_rate
->control
[band
].vht_mcs
[i
]) {
4826 if (count_vht
&& rate
)
4831 for (i
= 0; i
< NL80211_HE_NSS_MAX
; i
++) {
4832 if (hweight16(beacon_rate
->control
[band
].he_mcs
[i
]) > 1) {
4834 } else if (beacon_rate
->control
[band
].he_mcs
[i
]) {
4839 if (count_he
&& rate
)
4843 if ((count_ht
&& count_vht
&& count_he
) ||
4844 (!rate
&& !count_ht
&& !count_vht
&& !count_he
))
4848 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4849 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
))
4852 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4853 NL80211_EXT_FEATURE_BEACON_RATE_HT
))
4856 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4857 NL80211_EXT_FEATURE_BEACON_RATE_VHT
))
4860 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4861 NL80211_EXT_FEATURE_BEACON_RATE_HE
))
4867 static int nl80211_parse_beacon(struct cfg80211_registered_device
*rdev
,
4868 struct nlattr
*attrs
[],
4869 struct cfg80211_beacon_data
*bcn
)
4871 bool haveinfo
= false;
4874 memset(bcn
, 0, sizeof(*bcn
));
4876 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
4877 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
4878 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
4884 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
4885 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
4886 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
4893 if (attrs
[NL80211_ATTR_IE
]) {
4894 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
4895 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
4898 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
4899 bcn
->proberesp_ies
=
4900 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
4901 bcn
->proberesp_ies_len
=
4902 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
4905 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
4906 bcn
->assocresp_ies
=
4907 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
4908 bcn
->assocresp_ies_len
=
4909 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
4912 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
4913 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
4914 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
4917 if (attrs
[NL80211_ATTR_FTM_RESPONDER
]) {
4918 struct nlattr
*tb
[NL80211_FTM_RESP_ATTR_MAX
+ 1];
4920 err
= nla_parse_nested_deprecated(tb
,
4921 NL80211_FTM_RESP_ATTR_MAX
,
4922 attrs
[NL80211_ATTR_FTM_RESPONDER
],
4927 if (tb
[NL80211_FTM_RESP_ATTR_ENABLED
] &&
4928 wiphy_ext_feature_isset(&rdev
->wiphy
,
4929 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
))
4930 bcn
->ftm_responder
= 1;
4934 if (tb
[NL80211_FTM_RESP_ATTR_LCI
]) {
4935 bcn
->lci
= nla_data(tb
[NL80211_FTM_RESP_ATTR_LCI
]);
4936 bcn
->lci_len
= nla_len(tb
[NL80211_FTM_RESP_ATTR_LCI
]);
4939 if (tb
[NL80211_FTM_RESP_ATTR_CIVICLOC
]) {
4940 bcn
->civicloc
= nla_data(tb
[NL80211_FTM_RESP_ATTR_CIVICLOC
]);
4941 bcn
->civicloc_len
= nla_len(tb
[NL80211_FTM_RESP_ATTR_CIVICLOC
]);
4944 bcn
->ftm_responder
= -1;
4950 static int nl80211_parse_he_obss_pd(struct nlattr
*attrs
,
4951 struct ieee80211_he_obss_pd
*he_obss_pd
)
4953 struct nlattr
*tb
[NL80211_HE_OBSS_PD_ATTR_MAX
+ 1];
4956 err
= nla_parse_nested(tb
, NL80211_HE_OBSS_PD_ATTR_MAX
, attrs
,
4957 he_obss_pd_policy
, NULL
);
4961 if (!tb
[NL80211_HE_OBSS_PD_ATTR_SR_CTRL
])
4964 he_obss_pd
->sr_ctrl
= nla_get_u8(tb
[NL80211_HE_OBSS_PD_ATTR_SR_CTRL
]);
4966 if (tb
[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET
])
4967 he_obss_pd
->min_offset
=
4968 nla_get_u8(tb
[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET
]);
4969 if (tb
[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET
])
4970 he_obss_pd
->max_offset
=
4971 nla_get_u8(tb
[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET
]);
4972 if (tb
[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET
])
4973 he_obss_pd
->non_srg_max_offset
=
4974 nla_get_u8(tb
[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET
]);
4976 if (he_obss_pd
->min_offset
> he_obss_pd
->max_offset
)
4979 if (tb
[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP
])
4980 memcpy(he_obss_pd
->bss_color_bitmap
,
4981 nla_data(tb
[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP
]),
4982 sizeof(he_obss_pd
->bss_color_bitmap
));
4984 if (tb
[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP
])
4985 memcpy(he_obss_pd
->partial_bssid_bitmap
,
4986 nla_data(tb
[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP
]),
4987 sizeof(he_obss_pd
->partial_bssid_bitmap
));
4989 he_obss_pd
->enable
= true;
4994 static int nl80211_parse_he_bss_color(struct nlattr
*attrs
,
4995 struct cfg80211_he_bss_color
*he_bss_color
)
4997 struct nlattr
*tb
[NL80211_HE_BSS_COLOR_ATTR_MAX
+ 1];
5000 err
= nla_parse_nested(tb
, NL80211_HE_BSS_COLOR_ATTR_MAX
, attrs
,
5001 he_bss_color_policy
, NULL
);
5005 if (!tb
[NL80211_HE_BSS_COLOR_ATTR_COLOR
])
5008 he_bss_color
->color
=
5009 nla_get_u8(tb
[NL80211_HE_BSS_COLOR_ATTR_COLOR
]);
5010 he_bss_color
->enabled
=
5011 !nla_get_flag(tb
[NL80211_HE_BSS_COLOR_ATTR_DISABLED
]);
5012 he_bss_color
->partial
=
5013 nla_get_flag(tb
[NL80211_HE_BSS_COLOR_ATTR_PARTIAL
]);
5018 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device
*rdev
,
5019 struct nlattr
*attrs
,
5020 struct cfg80211_ap_settings
*params
)
5022 struct nlattr
*tb
[NL80211_FILS_DISCOVERY_ATTR_MAX
+ 1];
5024 struct cfg80211_fils_discovery
*fd
= ¶ms
->fils_discovery
;
5026 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
5027 NL80211_EXT_FEATURE_FILS_DISCOVERY
))
5030 ret
= nla_parse_nested(tb
, NL80211_FILS_DISCOVERY_ATTR_MAX
, attrs
,
5035 if (!tb
[NL80211_FILS_DISCOVERY_ATTR_INT_MIN
] ||
5036 !tb
[NL80211_FILS_DISCOVERY_ATTR_INT_MAX
] ||
5037 !tb
[NL80211_FILS_DISCOVERY_ATTR_TMPL
])
5040 fd
->tmpl_len
= nla_len(tb
[NL80211_FILS_DISCOVERY_ATTR_TMPL
]);
5041 fd
->tmpl
= nla_data(tb
[NL80211_FILS_DISCOVERY_ATTR_TMPL
]);
5042 fd
->min_interval
= nla_get_u32(tb
[NL80211_FILS_DISCOVERY_ATTR_INT_MIN
]);
5043 fd
->max_interval
= nla_get_u32(tb
[NL80211_FILS_DISCOVERY_ATTR_INT_MAX
]);
5049 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device
*rdev
,
5050 struct nlattr
*attrs
,
5051 struct cfg80211_ap_settings
*params
)
5053 struct nlattr
*tb
[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX
+ 1];
5055 struct cfg80211_unsol_bcast_probe_resp
*presp
=
5056 ¶ms
->unsol_bcast_probe_resp
;
5058 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
5059 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP
))
5062 ret
= nla_parse_nested(tb
, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX
,
5067 if (!tb
[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT
] ||
5068 !tb
[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL
])
5071 presp
->tmpl
= nla_data(tb
[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL
]);
5072 presp
->tmpl_len
= nla_len(tb
[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL
]);
5073 presp
->interval
= nla_get_u32(tb
[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT
]);
5077 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings
*params
,
5085 for (i
= 0; i
< rates
[1]; i
++) {
5086 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HT_PHY
)
5087 params
->ht_required
= true;
5088 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)
5089 params
->vht_required
= true;
5090 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HE_PHY
)
5091 params
->he_required
= true;
5092 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E
)
5093 params
->sae_h2e_required
= true;
5098 * Since the nl80211 API didn't include, from the beginning, attributes about
5099 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
5100 * benefit of drivers that rebuild IEs in the firmware.
5102 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings
*params
)
5104 const struct cfg80211_beacon_data
*bcn
= ¶ms
->beacon
;
5105 size_t ies_len
= bcn
->tail_len
;
5106 const u8
*ies
= bcn
->tail
;
5110 rates
= cfg80211_find_ie(WLAN_EID_SUPP_RATES
, ies
, ies_len
);
5111 nl80211_check_ap_rate_selectors(params
, rates
);
5113 rates
= cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES
, ies
, ies_len
);
5114 nl80211_check_ap_rate_selectors(params
, rates
);
5116 cap
= cfg80211_find_ie(WLAN_EID_HT_CAPABILITY
, ies
, ies_len
);
5117 if (cap
&& cap
[1] >= sizeof(*params
->ht_cap
))
5118 params
->ht_cap
= (void *)(cap
+ 2);
5119 cap
= cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY
, ies
, ies_len
);
5120 if (cap
&& cap
[1] >= sizeof(*params
->vht_cap
))
5121 params
->vht_cap
= (void *)(cap
+ 2);
5122 cap
= cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY
, ies
, ies_len
);
5123 if (cap
&& cap
[1] >= sizeof(*params
->he_cap
) + 1)
5124 params
->he_cap
= (void *)(cap
+ 3);
5125 cap
= cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION
, ies
, ies_len
);
5126 if (cap
&& cap
[1] >= sizeof(*params
->he_oper
) + 1)
5127 params
->he_oper
= (void *)(cap
+ 3);
5130 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
5131 struct cfg80211_ap_settings
*params
)
5133 struct wireless_dev
*wdev
;
5136 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
5137 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
5138 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5141 if (!wdev
->preset_chandef
.chan
)
5144 params
->chandef
= wdev
->preset_chandef
;
5152 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
5153 enum nl80211_auth_type auth_type
,
5154 enum nl80211_commands cmd
)
5156 if (auth_type
> NL80211_AUTHTYPE_MAX
)
5160 case NL80211_CMD_AUTHENTICATE
:
5161 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
5162 auth_type
== NL80211_AUTHTYPE_SAE
)
5164 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
5165 NL80211_EXT_FEATURE_FILS_STA
) &&
5166 (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
5167 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
5168 auth_type
== NL80211_AUTHTYPE_FILS_PK
))
5171 case NL80211_CMD_CONNECT
:
5172 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
5173 !wiphy_ext_feature_isset(&rdev
->wiphy
,
5174 NL80211_EXT_FEATURE_SAE_OFFLOAD
) &&
5175 auth_type
== NL80211_AUTHTYPE_SAE
)
5178 /* FILS with SK PFS or PK not supported yet */
5179 if (auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
5180 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
5182 if (!wiphy_ext_feature_isset(
5184 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
5185 auth_type
== NL80211_AUTHTYPE_FILS_SK
)
5188 case NL80211_CMD_START_AP
:
5189 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
5190 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP
) &&
5191 auth_type
== NL80211_AUTHTYPE_SAE
)
5193 /* FILS not supported yet */
5194 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
5195 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
5196 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
5204 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
5206 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5207 struct net_device
*dev
= info
->user_ptr
[1];
5208 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5209 struct cfg80211_ap_settings params
;
5212 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5213 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5216 if (!rdev
->ops
->start_ap
)
5219 if (wdev
->beacon_interval
)
5222 memset(¶ms
, 0, sizeof(params
));
5224 /* these are required for START_AP */
5225 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
5226 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
5227 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
5230 err
= nl80211_parse_beacon(rdev
, info
->attrs
, ¶ms
.beacon
);
5234 params
.beacon_interval
=
5235 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5236 params
.dtim_period
=
5237 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
5239 err
= cfg80211_validate_beacon_int(rdev
, dev
->ieee80211_ptr
->iftype
,
5240 params
.beacon_interval
);
5245 * In theory, some of these attributes should be required here
5246 * but since they were not used when the command was originally
5247 * added, keep them optional for old user space programs to let
5248 * them continue to work with drivers that do not need the
5249 * additional information -- drivers must check!
5251 if (info
->attrs
[NL80211_ATTR_SSID
]) {
5252 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5254 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5255 if (params
.ssid_len
== 0)
5259 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
])
5260 params
.hidden_ssid
= nla_get_u32(
5261 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
5263 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5265 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5266 params
.auth_type
= nla_get_u32(
5267 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5268 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
5269 NL80211_CMD_START_AP
))
5272 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5274 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
5275 NL80211_MAX_NR_CIPHER_SUITES
);
5279 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
5280 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
5282 params
.inactivity_timeout
= nla_get_u16(
5283 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
5286 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
5287 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5289 params
.p2p_ctwindow
=
5290 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
5291 if (params
.p2p_ctwindow
!= 0 &&
5292 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
5296 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
5299 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5301 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
5302 params
.p2p_opp_ps
= tmp
;
5303 if (params
.p2p_opp_ps
!= 0 &&
5304 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
5308 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5309 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
5312 } else if (wdev
->preset_chandef
.chan
) {
5313 params
.chandef
= wdev
->preset_chandef
;
5314 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
5317 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
5321 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
5322 err
= nl80211_parse_tx_bitrate_mask(info
, info
->attrs
,
5323 NL80211_ATTR_TX_RATES
,
5324 ¶ms
.beacon_rate
,
5329 err
= validate_beacon_tx_rate(rdev
, params
.chandef
.chan
->band
,
5330 ¶ms
.beacon_rate
);
5335 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
5337 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
5338 switch (params
.smps_mode
) {
5339 case NL80211_SMPS_OFF
:
5341 case NL80211_SMPS_STATIC
:
5342 if (!(rdev
->wiphy
.features
&
5343 NL80211_FEATURE_STATIC_SMPS
))
5346 case NL80211_SMPS_DYNAMIC
:
5347 if (!(rdev
->wiphy
.features
&
5348 NL80211_FEATURE_DYNAMIC_SMPS
))
5355 params
.smps_mode
= NL80211_SMPS_OFF
;
5358 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
5359 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
5362 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
5363 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
5364 if (IS_ERR(params
.acl
))
5365 return PTR_ERR(params
.acl
);
5368 params
.twt_responder
=
5369 nla_get_flag(info
->attrs
[NL80211_ATTR_TWT_RESPONDER
]);
5371 if (info
->attrs
[NL80211_ATTR_HE_OBSS_PD
]) {
5372 err
= nl80211_parse_he_obss_pd(
5373 info
->attrs
[NL80211_ATTR_HE_OBSS_PD
],
5374 ¶ms
.he_obss_pd
);
5379 if (info
->attrs
[NL80211_ATTR_HE_BSS_COLOR
]) {
5380 err
= nl80211_parse_he_bss_color(
5381 info
->attrs
[NL80211_ATTR_HE_BSS_COLOR
],
5382 ¶ms
.he_bss_color
);
5387 if (info
->attrs
[NL80211_ATTR_FILS_DISCOVERY
]) {
5388 err
= nl80211_parse_fils_discovery(rdev
,
5389 info
->attrs
[NL80211_ATTR_FILS_DISCOVERY
],
5395 if (info
->attrs
[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP
]) {
5396 err
= nl80211_parse_unsol_bcast_probe_resp(
5397 rdev
, info
->attrs
[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP
],
5403 nl80211_calculate_ap_params(¶ms
);
5405 if (info
->attrs
[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
])
5406 params
.flags
|= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT
;
5409 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
5411 wdev
->preset_chandef
= params
.chandef
;
5412 wdev
->beacon_interval
= params
.beacon_interval
;
5413 wdev
->chandef
= params
.chandef
;
5414 wdev
->ssid_len
= params
.ssid_len
;
5415 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
5417 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
5418 wdev
->conn_owner_nlportid
= info
->snd_portid
;
5428 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
5430 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5431 struct net_device
*dev
= info
->user_ptr
[1];
5432 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5433 struct cfg80211_beacon_data params
;
5436 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5437 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5440 if (!rdev
->ops
->change_beacon
)
5443 if (!wdev
->beacon_interval
)
5446 err
= nl80211_parse_beacon(rdev
, info
->attrs
, ¶ms
);
5451 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
5457 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
5459 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5460 struct net_device
*dev
= info
->user_ptr
[1];
5462 return cfg80211_stop_ap(rdev
, dev
, false);
5465 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
5466 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
5467 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
5468 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
5469 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
5470 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
5471 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
5474 static int parse_station_flags(struct genl_info
*info
,
5475 enum nl80211_iftype iftype
,
5476 struct station_parameters
*params
)
5478 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
5483 * Try parsing the new attribute first so userspace
5484 * can specify both for older kernels.
5486 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
5488 struct nl80211_sta_flag_update
*sta_flags
;
5490 sta_flags
= nla_data(nla
);
5491 params
->sta_flags_mask
= sta_flags
->mask
;
5492 params
->sta_flags_set
= sta_flags
->set
;
5493 params
->sta_flags_set
&= params
->sta_flags_mask
;
5494 if ((params
->sta_flags_mask
|
5495 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
5500 /* if present, parse the old attribute */
5502 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
5506 if (nla_parse_nested_deprecated(flags
, NL80211_STA_FLAG_MAX
, nla
, sta_flags_policy
, info
->extack
))
5510 * Only allow certain flags for interface types so that
5511 * other attributes are silently ignored. Remember that
5512 * this is backward compatibility code with old userspace
5513 * and shouldn't be hit in other cases anyway.
5516 case NL80211_IFTYPE_AP
:
5517 case NL80211_IFTYPE_AP_VLAN
:
5518 case NL80211_IFTYPE_P2P_GO
:
5519 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5520 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
5521 BIT(NL80211_STA_FLAG_WME
) |
5522 BIT(NL80211_STA_FLAG_MFP
);
5524 case NL80211_IFTYPE_P2P_CLIENT
:
5525 case NL80211_IFTYPE_STATION
:
5526 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5527 BIT(NL80211_STA_FLAG_TDLS_PEER
);
5529 case NL80211_IFTYPE_MESH_POINT
:
5530 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5531 BIT(NL80211_STA_FLAG_MFP
) |
5532 BIT(NL80211_STA_FLAG_AUTHORIZED
);
5538 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
5540 params
->sta_flags_set
|= (1<<flag
);
5542 /* no longer support new API additions in old API */
5543 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
5551 bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
, int attr
)
5553 struct nlattr
*rate
;
5556 enum nl80211_rate_info rate_flg
;
5558 rate
= nla_nest_start_noflag(msg
, attr
);
5562 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
5563 bitrate
= cfg80211_calculate_bitrate(info
);
5564 /* report 16-bit bitrate only if we can */
5565 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
5567 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
5569 if (bitrate_compat
> 0 &&
5570 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
5574 case RATE_INFO_BW_5
:
5575 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
5577 case RATE_INFO_BW_10
:
5578 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
5583 case RATE_INFO_BW_20
:
5586 case RATE_INFO_BW_40
:
5587 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
5589 case RATE_INFO_BW_80
:
5590 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
5592 case RATE_INFO_BW_160
:
5593 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
5595 case RATE_INFO_BW_HE_RU
:
5597 WARN_ON(!(info
->flags
& RATE_INFO_FLAGS_HE_MCS
));
5600 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
5603 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
5604 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
5606 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
5607 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
5609 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
5610 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
5612 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
5614 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
5615 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
5617 } else if (info
->flags
& RATE_INFO_FLAGS_HE_MCS
) {
5618 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_MCS
, info
->mcs
))
5620 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_NSS
, info
->nss
))
5622 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_GI
, info
->he_gi
))
5624 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_DCM
, info
->he_dcm
))
5626 if (info
->bw
== RATE_INFO_BW_HE_RU
&&
5627 nla_put_u8(msg
, NL80211_RATE_INFO_HE_RU_ALLOC
,
5632 nla_nest_end(msg
, rate
);
5636 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
5645 attr
= nla_nest_start_noflag(msg
, id
);
5649 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
5650 if (!(mask
& BIT(i
)))
5653 if (nla_put_u8(msg
, i
, signal
[i
]))
5657 nla_nest_end(msg
, attr
);
5662 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
5664 struct cfg80211_registered_device
*rdev
,
5665 struct net_device
*dev
,
5666 const u8
*mac_addr
, struct station_info
*sinfo
)
5669 struct nlattr
*sinfoattr
, *bss_param
;
5671 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
5673 cfg80211_sinfo_release_content(sinfo
);
5677 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5678 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
5679 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
5680 goto nla_put_failure
;
5682 sinfoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_STA_INFO
);
5684 goto nla_put_failure
;
5686 #define PUT_SINFO(attr, memb, type) do { \
5687 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
5688 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5689 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5691 goto nla_put_failure; \
5693 #define PUT_SINFO_U64(attr, memb) do { \
5694 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
5695 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5696 sinfo->memb, NL80211_STA_INFO_PAD)) \
5697 goto nla_put_failure; \
5700 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
5701 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
5702 PUT_SINFO_U64(ASSOC_AT_BOOTTIME
, assoc_at
);
5704 if (sinfo
->filled
& (BIT_ULL(NL80211_STA_INFO_RX_BYTES
) |
5705 BIT_ULL(NL80211_STA_INFO_RX_BYTES64
)) &&
5706 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
5707 (u32
)sinfo
->rx_bytes
))
5708 goto nla_put_failure
;
5710 if (sinfo
->filled
& (BIT_ULL(NL80211_STA_INFO_TX_BYTES
) |
5711 BIT_ULL(NL80211_STA_INFO_TX_BYTES64
)) &&
5712 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
5713 (u32
)sinfo
->tx_bytes
))
5714 goto nla_put_failure
;
5716 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
5717 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
5718 PUT_SINFO(LLID
, llid
, u16
);
5719 PUT_SINFO(PLID
, plid
, u16
);
5720 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
5721 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
5722 PUT_SINFO_U64(TX_DURATION
, tx_duration
);
5724 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
5725 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
))
5726 PUT_SINFO(AIRTIME_WEIGHT
, airtime_weight
, u16
);
5728 switch (rdev
->wiphy
.signal_type
) {
5729 case CFG80211_SIGNAL_TYPE_MBM
:
5730 PUT_SINFO(SIGNAL
, signal
, u8
);
5731 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
5736 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
5737 if (!nl80211_put_signal(msg
, sinfo
->chains
,
5738 sinfo
->chain_signal
,
5739 NL80211_STA_INFO_CHAIN_SIGNAL
))
5740 goto nla_put_failure
;
5742 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
5743 if (!nl80211_put_signal(msg
, sinfo
->chains
,
5744 sinfo
->chain_signal_avg
,
5745 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
5746 goto nla_put_failure
;
5748 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_TX_BITRATE
)) {
5749 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
5750 NL80211_STA_INFO_TX_BITRATE
))
5751 goto nla_put_failure
;
5753 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_RX_BITRATE
)) {
5754 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
5755 NL80211_STA_INFO_RX_BITRATE
))
5756 goto nla_put_failure
;
5759 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
5760 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
5761 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
5762 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
5763 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
5764 PUT_SINFO(AIRTIME_LINK_METRIC
, airtime_link_metric
, u32
);
5765 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
5766 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
5767 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
5768 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
5769 PUT_SINFO(CONNECTED_TO_GATE
, connected_to_gate
, u8
);
5770 PUT_SINFO(CONNECTED_TO_AS
, connected_to_as
, u8
);
5772 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_BSS_PARAM
)) {
5773 bss_param
= nla_nest_start_noflag(msg
,
5774 NL80211_STA_INFO_BSS_PARAM
);
5776 goto nla_put_failure
;
5778 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
5779 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
5780 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
5781 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
5782 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
5783 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
5784 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
5785 sinfo
->bss_param
.dtim_period
) ||
5786 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
5787 sinfo
->bss_param
.beacon_interval
))
5788 goto nla_put_failure
;
5790 nla_nest_end(msg
, bss_param
);
5792 if ((sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_STA_FLAGS
)) &&
5793 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
5794 sizeof(struct nl80211_sta_flag_update
),
5796 goto nla_put_failure
;
5798 PUT_SINFO_U64(T_OFFSET
, t_offset
);
5799 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
5800 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
5801 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
5802 PUT_SINFO(RX_MPDUS
, rx_mpdu_count
, u32
);
5803 PUT_SINFO(FCS_ERROR_COUNT
, fcs_err_count
, u32
);
5804 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
5805 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT
)) {
5806 PUT_SINFO(ACK_SIGNAL
, ack_signal
, u8
);
5807 PUT_SINFO(ACK_SIGNAL_AVG
, avg_ack_signal
, s8
);
5811 #undef PUT_SINFO_U64
5813 if (sinfo
->pertid
) {
5814 struct nlattr
*tidsattr
;
5817 tidsattr
= nla_nest_start_noflag(msg
,
5818 NL80211_STA_INFO_TID_STATS
);
5820 goto nla_put_failure
;
5822 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
5823 struct cfg80211_tid_stats
*tidstats
;
5824 struct nlattr
*tidattr
;
5826 tidstats
= &sinfo
->pertid
[tid
];
5828 if (!tidstats
->filled
)
5831 tidattr
= nla_nest_start_noflag(msg
, tid
+ 1);
5833 goto nla_put_failure
;
5835 #define PUT_TIDVAL_U64(attr, memb) do { \
5836 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
5837 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5838 tidstats->memb, NL80211_TID_STATS_PAD)) \
5839 goto nla_put_failure; \
5842 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
5843 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
5844 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
5845 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
5847 #undef PUT_TIDVAL_U64
5848 if ((tidstats
->filled
&
5849 BIT(NL80211_TID_STATS_TXQ_STATS
)) &&
5850 !nl80211_put_txq_stats(msg
, &tidstats
->txq_stats
,
5851 NL80211_TID_STATS_TXQ_STATS
))
5852 goto nla_put_failure
;
5854 nla_nest_end(msg
, tidattr
);
5857 nla_nest_end(msg
, tidsattr
);
5860 nla_nest_end(msg
, sinfoattr
);
5862 if (sinfo
->assoc_req_ies_len
&&
5863 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
5864 sinfo
->assoc_req_ies
))
5865 goto nla_put_failure
;
5867 cfg80211_sinfo_release_content(sinfo
);
5868 genlmsg_end(msg
, hdr
);
5872 cfg80211_sinfo_release_content(sinfo
);
5873 genlmsg_cancel(msg
, hdr
);
5877 static int nl80211_dump_station(struct sk_buff
*skb
,
5878 struct netlink_callback
*cb
)
5880 struct station_info sinfo
;
5881 struct cfg80211_registered_device
*rdev
;
5882 struct wireless_dev
*wdev
;
5883 u8 mac_addr
[ETH_ALEN
];
5884 int sta_idx
= cb
->args
[2];
5888 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
5892 if (!wdev
->netdev
) {
5897 if (!rdev
->ops
->dump_station
) {
5903 memset(&sinfo
, 0, sizeof(sinfo
));
5904 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
5911 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
5912 NETLINK_CB(cb
->skb
).portid
,
5913 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5914 rdev
, wdev
->netdev
, mac_addr
,
5922 cb
->args
[2] = sta_idx
;
5930 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
5932 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5933 struct net_device
*dev
= info
->user_ptr
[1];
5934 struct station_info sinfo
;
5935 struct sk_buff
*msg
;
5936 u8
*mac_addr
= NULL
;
5939 memset(&sinfo
, 0, sizeof(sinfo
));
5941 if (!info
->attrs
[NL80211_ATTR_MAC
])
5944 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5946 if (!rdev
->ops
->get_station
)
5949 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
5953 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5955 cfg80211_sinfo_release_content(&sinfo
);
5959 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
5960 info
->snd_portid
, info
->snd_seq
, 0,
5961 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
5966 return genlmsg_reply(msg
, info
);
5969 int cfg80211_check_station_change(struct wiphy
*wiphy
,
5970 struct station_parameters
*params
,
5971 enum cfg80211_station_type statype
)
5973 if (params
->listen_interval
!= -1 &&
5974 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
5977 if (params
->support_p2p_ps
!= -1 &&
5978 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
5982 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
5983 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
5986 /* When you run into this, adjust the code below for the new flag */
5987 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
5990 case CFG80211_STA_MESH_PEER_KERNEL
:
5991 case CFG80211_STA_MESH_PEER_USER
:
5993 * No ignoring the TDLS flag here -- the userspace mesh
5994 * code doesn't have the bug of including TDLS in the
5997 if (params
->sta_flags_mask
&
5998 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5999 BIT(NL80211_STA_FLAG_MFP
) |
6000 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
6003 case CFG80211_STA_TDLS_PEER_SETUP
:
6004 case CFG80211_STA_TDLS_PEER_ACTIVE
:
6005 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
6007 /* ignore since it can't change */
6008 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
6011 /* disallow mesh-specific things */
6012 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
6014 if (params
->local_pm
)
6016 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
6020 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
6021 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
6022 /* TDLS can't be set, ... */
6023 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
6026 * ... but don't bother the driver with it. This works around
6027 * a hostapd/wpa_supplicant issue -- it always includes the
6028 * TLDS_PEER flag in the mask even for AP mode.
6030 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
6033 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
6034 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
6035 /* reject other things that can't change */
6036 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
6038 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
6040 if (params
->supported_rates
)
6042 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
||
6047 if (statype
!= CFG80211_STA_AP_CLIENT
&&
6048 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
6054 case CFG80211_STA_AP_MLME_CLIENT
:
6055 /* Use this only for authorizing/unauthorizing a station */
6056 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
6059 case CFG80211_STA_AP_CLIENT
:
6060 case CFG80211_STA_AP_CLIENT_UNASSOC
:
6061 /* accept only the listed bits */
6062 if (params
->sta_flags_mask
&
6063 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
6064 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
6065 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
6066 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
6067 BIT(NL80211_STA_FLAG_WME
) |
6068 BIT(NL80211_STA_FLAG_MFP
)))
6071 /* but authenticated/associated only if driver handles it */
6072 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
6073 params
->sta_flags_mask
&
6074 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
6075 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
6078 case CFG80211_STA_IBSS
:
6079 case CFG80211_STA_AP_STA
:
6080 /* reject any changes other than AUTHORIZED */
6081 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
6084 case CFG80211_STA_TDLS_PEER_SETUP
:
6085 /* reject any changes other than AUTHORIZED or WME */
6086 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
6087 BIT(NL80211_STA_FLAG_WME
)))
6089 /* force (at least) rates when authorizing */
6090 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
6091 !params
->supported_rates
)
6094 case CFG80211_STA_TDLS_PEER_ACTIVE
:
6095 /* reject any changes */
6097 case CFG80211_STA_MESH_PEER_KERNEL
:
6098 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
6101 case CFG80211_STA_MESH_PEER_USER
:
6102 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
6103 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
6109 * Older kernel versions ignored this attribute entirely, so don't
6110 * reject attempts to update it but mark it as unused instead so the
6111 * driver won't look at the data.
6113 if (statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
&&
6114 statype
!= CFG80211_STA_TDLS_PEER_SETUP
)
6115 params
->opmode_notif_used
= false;
6119 EXPORT_SYMBOL(cfg80211_check_station_change
);
6122 * Get vlan interface making sure it is running and on the right wiphy.
6124 static struct net_device
*get_vlan(struct genl_info
*info
,
6125 struct cfg80211_registered_device
*rdev
)
6127 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
6128 struct net_device
*v
;
6134 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
6136 return ERR_PTR(-ENODEV
);
6138 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
6143 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
6144 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
6145 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
6150 if (!netif_running(v
)) {
6158 return ERR_PTR(ret
);
6161 static const struct nla_policy
6162 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
6163 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
6164 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
6167 static int nl80211_parse_sta_wme(struct genl_info
*info
,
6168 struct station_parameters
*params
)
6170 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
6174 /* parse WME attributes if present */
6175 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
6178 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
6179 err
= nla_parse_nested_deprecated(tb
, NL80211_STA_WME_MAX
, nla
,
6180 nl80211_sta_wme_policy
,
6185 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
6186 params
->uapsd_queues
= nla_get_u8(
6187 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
6188 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
6191 if (tb
[NL80211_STA_WME_MAX_SP
])
6192 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
6194 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
6197 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
6202 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
6203 struct station_parameters
*params
)
6205 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
6206 params
->supported_channels
=
6207 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
6208 params
->supported_channels_len
=
6209 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
6211 * Need to include at least one (first channel, number of
6212 * channels) tuple for each subband (checked in policy),
6213 * and must have proper tuples for the rest of the data as well.
6215 if (params
->supported_channels_len
% 2)
6219 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
6220 params
->supported_oper_classes
=
6221 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
6222 params
->supported_oper_classes_len
=
6223 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
6228 static int nl80211_set_station_tdls(struct genl_info
*info
,
6229 struct station_parameters
*params
)
6232 /* Dummy STA entry gets updated once the peer capabilities are known */
6233 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
6234 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
6235 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
6237 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
6238 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
6240 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
6241 if (info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]) {
6243 nla_data(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
6244 params
->he_capa_len
=
6245 nla_len(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
6248 err
= nl80211_parse_sta_channel_info(info
, params
);
6252 return nl80211_parse_sta_wme(info
, params
);
6255 static int nl80211_parse_sta_txpower_setting(struct genl_info
*info
,
6256 struct station_parameters
*params
)
6258 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6261 if (info
->attrs
[NL80211_ATTR_STA_TX_POWER_SETTING
]) {
6262 if (!rdev
->ops
->set_tx_power
||
6263 !wiphy_ext_feature_isset(&rdev
->wiphy
,
6264 NL80211_EXT_FEATURE_STA_TX_PWR
))
6267 idx
= NL80211_ATTR_STA_TX_POWER_SETTING
;
6268 params
->txpwr
.type
= nla_get_u8(info
->attrs
[idx
]);
6270 if (params
->txpwr
.type
== NL80211_TX_POWER_LIMITED
) {
6271 idx
= NL80211_ATTR_STA_TX_POWER
;
6273 if (info
->attrs
[idx
])
6274 params
->txpwr
.power
=
6275 nla_get_s16(info
->attrs
[idx
]);
6279 params
->sta_modify_mask
|= STATION_PARAM_APPLY_STA_TXPOWER
;
6285 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
6287 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6288 struct net_device
*dev
= info
->user_ptr
[1];
6289 struct station_parameters params
;
6293 memset(¶ms
, 0, sizeof(params
));
6295 if (!rdev
->ops
->change_station
)
6299 * AID and listen_interval properties can be set only for unassociated
6300 * station. Include these parameters here and will check them in
6301 * cfg80211_check_station_change().
6303 if (info
->attrs
[NL80211_ATTR_STA_AID
])
6304 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
6306 if (info
->attrs
[NL80211_ATTR_VLAN_ID
])
6307 params
.vlan_id
= nla_get_u16(info
->attrs
[NL80211_ATTR_VLAN_ID
]);
6309 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
6310 params
.listen_interval
=
6311 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
6313 params
.listen_interval
= -1;
6315 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
])
6316 params
.support_p2p_ps
=
6317 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
6319 params
.support_p2p_ps
= -1;
6321 if (!info
->attrs
[NL80211_ATTR_MAC
])
6324 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6326 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
6327 params
.supported_rates
=
6328 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
6329 params
.supported_rates_len
=
6330 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
6333 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
6335 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
6336 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
6339 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
6341 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
6342 params
.ext_capab_len
=
6343 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
6346 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
6349 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
6350 params
.plink_action
=
6351 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
6353 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
6354 params
.plink_state
=
6355 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
6356 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
])
6357 params
.peer_aid
= nla_get_u16(
6358 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
6359 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
6362 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
])
6363 params
.local_pm
= nla_get_u32(
6364 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
6366 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
6367 params
.opmode_notif_used
= true;
6368 params
.opmode_notif
=
6369 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
6372 if (info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
])
6373 params
.he_6ghz_capa
=
6374 nla_data(info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
]);
6376 if (info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
])
6377 params
.airtime_weight
=
6378 nla_get_u16(info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
]);
6380 if (params
.airtime_weight
&&
6381 !wiphy_ext_feature_isset(&rdev
->wiphy
,
6382 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
))
6385 err
= nl80211_parse_sta_txpower_setting(info
, ¶ms
);
6389 /* Include parameters for TDLS peer (will check later) */
6390 err
= nl80211_set_station_tdls(info
, ¶ms
);
6394 params
.vlan
= get_vlan(info
, rdev
);
6395 if (IS_ERR(params
.vlan
))
6396 return PTR_ERR(params
.vlan
);
6398 switch (dev
->ieee80211_ptr
->iftype
) {
6399 case NL80211_IFTYPE_AP
:
6400 case NL80211_IFTYPE_AP_VLAN
:
6401 case NL80211_IFTYPE_P2P_GO
:
6402 case NL80211_IFTYPE_P2P_CLIENT
:
6403 case NL80211_IFTYPE_STATION
:
6404 case NL80211_IFTYPE_ADHOC
:
6405 case NL80211_IFTYPE_MESH_POINT
:
6412 /* driver will call cfg80211_check_station_change() */
6413 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
6417 dev_put(params
.vlan
);
6422 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
6424 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6426 struct net_device
*dev
= info
->user_ptr
[1];
6427 struct station_parameters params
;
6428 u8
*mac_addr
= NULL
;
6429 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
6430 BIT(NL80211_STA_FLAG_ASSOCIATED
);
6432 memset(¶ms
, 0, sizeof(params
));
6434 if (!rdev
->ops
->add_station
)
6437 if (!info
->attrs
[NL80211_ATTR_MAC
])
6440 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
6443 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
6446 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
6447 !info
->attrs
[NL80211_ATTR_PEER_AID
])
6450 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6451 params
.supported_rates
=
6452 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
6453 params
.supported_rates_len
=
6454 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
6455 params
.listen_interval
=
6456 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
6458 if (info
->attrs
[NL80211_ATTR_VLAN_ID
])
6459 params
.vlan_id
= nla_get_u16(info
->attrs
[NL80211_ATTR_VLAN_ID
]);
6461 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
6462 params
.support_p2p_ps
=
6463 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
6466 * if not specified, assume it's supported for P2P GO interface,
6467 * and is NOT supported for AP interface
6469 params
.support_p2p_ps
=
6470 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
6473 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
6474 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
6476 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
6478 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
6480 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
6481 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
6484 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
6486 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
6487 params
.ext_capab_len
=
6488 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
6491 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
6493 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
6495 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
6497 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
6499 if (info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]) {
6501 nla_data(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
6502 params
.he_capa_len
=
6503 nla_len(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
6506 if (info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
])
6507 params
.he_6ghz_capa
=
6508 nla_data(info
->attrs
[NL80211_ATTR_HE_6GHZ_CAPABILITY
]);
6510 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
6511 params
.opmode_notif_used
= true;
6512 params
.opmode_notif
=
6513 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
6516 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
6517 params
.plink_action
=
6518 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
6520 if (info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
])
6521 params
.airtime_weight
=
6522 nla_get_u16(info
->attrs
[NL80211_ATTR_AIRTIME_WEIGHT
]);
6524 if (params
.airtime_weight
&&
6525 !wiphy_ext_feature_isset(&rdev
->wiphy
,
6526 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
))
6529 err
= nl80211_parse_sta_txpower_setting(info
, ¶ms
);
6533 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
6537 err
= nl80211_parse_sta_wme(info
, ¶ms
);
6541 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
6544 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
6545 * as userspace might just pass through the capabilities from the IEs
6546 * directly, rather than enforcing this restriction and returning an
6547 * error in this case.
6549 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
6550 params
.ht_capa
= NULL
;
6551 params
.vht_capa
= NULL
;
6553 /* HE requires WME */
6554 if (params
.he_capa_len
|| params
.he_6ghz_capa
)
6558 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
6559 if (params
.he_6ghz_capa
&& (params
.ht_capa
|| params
.vht_capa
))
6562 /* When you run into this, adjust the code below for the new flag */
6563 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
6565 switch (dev
->ieee80211_ptr
->iftype
) {
6566 case NL80211_IFTYPE_AP
:
6567 case NL80211_IFTYPE_AP_VLAN
:
6568 case NL80211_IFTYPE_P2P_GO
:
6569 /* ignore WME attributes if iface/sta is not capable */
6570 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
6571 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
6572 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
6574 /* TDLS peers cannot be added */
6575 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
6576 info
->attrs
[NL80211_ATTR_PEER_AID
])
6578 /* but don't bother the driver with it */
6579 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
6581 /* allow authenticated/associated only if driver handles it */
6582 if (!(rdev
->wiphy
.features
&
6583 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
6584 params
.sta_flags_mask
& auth_assoc
)
6587 /* Older userspace, or userspace wanting to be compatible with
6588 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
6589 * and assoc flags in the mask, but assumes the station will be
6590 * added as associated anyway since this was the required driver
6591 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
6593 * In order to not bother drivers with this quirk in the API
6594 * set the flags in both the mask and set for new stations in
6597 if (!(params
.sta_flags_mask
& auth_assoc
)) {
6598 params
.sta_flags_mask
|= auth_assoc
;
6599 params
.sta_flags_set
|= auth_assoc
;
6602 /* must be last in here for error handling */
6603 params
.vlan
= get_vlan(info
, rdev
);
6604 if (IS_ERR(params
.vlan
))
6605 return PTR_ERR(params
.vlan
);
6607 case NL80211_IFTYPE_MESH_POINT
:
6608 /* ignore uAPSD data */
6609 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
6611 /* associated is disallowed */
6612 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
6614 /* TDLS peers cannot be added */
6615 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
6616 info
->attrs
[NL80211_ATTR_PEER_AID
])
6619 case NL80211_IFTYPE_STATION
:
6620 case NL80211_IFTYPE_P2P_CLIENT
:
6621 /* ignore uAPSD data */
6622 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
6624 /* these are disallowed */
6625 if (params
.sta_flags_mask
&
6626 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
6627 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
6629 /* Only TDLS peers can be added */
6630 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
6632 /* Can only add if TDLS ... */
6633 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
6635 /* ... with external setup is supported */
6636 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
6639 * Older wpa_supplicant versions always mark the TDLS peer
6640 * as authorized, but it shouldn't yet be.
6642 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
6648 /* be aware of params.vlan when changing code here */
6650 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
6653 dev_put(params
.vlan
);
6657 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
6659 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6660 struct net_device
*dev
= info
->user_ptr
[1];
6661 struct station_del_parameters params
;
6663 memset(¶ms
, 0, sizeof(params
));
6665 if (info
->attrs
[NL80211_ATTR_MAC
])
6666 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6668 switch (dev
->ieee80211_ptr
->iftype
) {
6669 case NL80211_IFTYPE_AP
:
6670 case NL80211_IFTYPE_AP_VLAN
:
6671 case NL80211_IFTYPE_MESH_POINT
:
6672 case NL80211_IFTYPE_P2P_GO
:
6673 /* always accept these */
6675 case NL80211_IFTYPE_ADHOC
:
6676 /* conditionally accept */
6677 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
6678 NL80211_EXT_FEATURE_DEL_IBSS_STA
))
6685 if (!rdev
->ops
->del_station
)
6688 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
6690 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
6691 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
6692 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
6695 /* Default to Deauthentication frame */
6696 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
6699 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
6700 params
.reason_code
=
6701 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6702 if (params
.reason_code
== 0)
6703 return -EINVAL
; /* 0 is reserved */
6705 /* Default to reason code 2 */
6706 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
6709 return rdev_del_station(rdev
, dev
, ¶ms
);
6712 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
6713 int flags
, struct net_device
*dev
,
6714 u8
*dst
, u8
*next_hop
,
6715 struct mpath_info
*pinfo
)
6718 struct nlattr
*pinfoattr
;
6720 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
6724 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
6725 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
6726 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
6727 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
6728 goto nla_put_failure
;
6730 pinfoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_MPATH_INFO
);
6732 goto nla_put_failure
;
6733 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
6734 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
6736 goto nla_put_failure
;
6737 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
6738 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
6739 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
6740 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
6742 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
6743 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
6745 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
6746 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
6748 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
6749 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
6750 pinfo
->discovery_timeout
)) ||
6751 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
6752 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
6753 pinfo
->discovery_retries
)) ||
6754 ((pinfo
->filled
& MPATH_INFO_HOP_COUNT
) &&
6755 nla_put_u8(msg
, NL80211_MPATH_INFO_HOP_COUNT
,
6756 pinfo
->hop_count
)) ||
6757 ((pinfo
->filled
& MPATH_INFO_PATH_CHANGE
) &&
6758 nla_put_u32(msg
, NL80211_MPATH_INFO_PATH_CHANGE
,
6759 pinfo
->path_change_count
)))
6760 goto nla_put_failure
;
6762 nla_nest_end(msg
, pinfoattr
);
6764 genlmsg_end(msg
, hdr
);
6768 genlmsg_cancel(msg
, hdr
);
6772 static int nl80211_dump_mpath(struct sk_buff
*skb
,
6773 struct netlink_callback
*cb
)
6775 struct mpath_info pinfo
;
6776 struct cfg80211_registered_device
*rdev
;
6777 struct wireless_dev
*wdev
;
6779 u8 next_hop
[ETH_ALEN
];
6780 int path_idx
= cb
->args
[2];
6784 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
6788 if (!rdev
->ops
->dump_mpath
) {
6793 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
6799 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
6806 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
6807 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6808 wdev
->netdev
, dst
, next_hop
,
6816 cb
->args
[2] = path_idx
;
6823 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6825 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6827 struct net_device
*dev
= info
->user_ptr
[1];
6828 struct mpath_info pinfo
;
6829 struct sk_buff
*msg
;
6831 u8 next_hop
[ETH_ALEN
];
6833 memset(&pinfo
, 0, sizeof(pinfo
));
6835 if (!info
->attrs
[NL80211_ATTR_MAC
])
6838 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6840 if (!rdev
->ops
->get_mpath
)
6843 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6846 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
6850 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6854 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6855 dev
, dst
, next_hop
, &pinfo
) < 0) {
6860 return genlmsg_reply(msg
, info
);
6863 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6865 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6866 struct net_device
*dev
= info
->user_ptr
[1];
6868 u8
*next_hop
= NULL
;
6870 if (!info
->attrs
[NL80211_ATTR_MAC
])
6873 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
6876 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6877 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
6879 if (!rdev
->ops
->change_mpath
)
6882 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6885 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
6888 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6890 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6891 struct net_device
*dev
= info
->user_ptr
[1];
6893 u8
*next_hop
= NULL
;
6895 if (!info
->attrs
[NL80211_ATTR_MAC
])
6898 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
6901 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6902 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
6904 if (!rdev
->ops
->add_mpath
)
6907 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6910 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
6913 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
6915 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6916 struct net_device
*dev
= info
->user_ptr
[1];
6919 if (info
->attrs
[NL80211_ATTR_MAC
])
6920 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6922 if (!rdev
->ops
->del_mpath
)
6925 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6928 return rdev_del_mpath(rdev
, dev
, dst
);
6931 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
6933 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6935 struct net_device
*dev
= info
->user_ptr
[1];
6936 struct mpath_info pinfo
;
6937 struct sk_buff
*msg
;
6941 memset(&pinfo
, 0, sizeof(pinfo
));
6943 if (!info
->attrs
[NL80211_ATTR_MAC
])
6946 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6948 if (!rdev
->ops
->get_mpp
)
6951 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6954 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
6958 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6962 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6963 dev
, dst
, mpp
, &pinfo
) < 0) {
6968 return genlmsg_reply(msg
, info
);
6971 static int nl80211_dump_mpp(struct sk_buff
*skb
,
6972 struct netlink_callback
*cb
)
6974 struct mpath_info pinfo
;
6975 struct cfg80211_registered_device
*rdev
;
6976 struct wireless_dev
*wdev
;
6979 int path_idx
= cb
->args
[2];
6983 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
6987 if (!rdev
->ops
->dump_mpp
) {
6992 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
6998 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
7005 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
7006 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7007 wdev
->netdev
, dst
, mpp
,
7015 cb
->args
[2] = path_idx
;
7022 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
7024 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7025 struct net_device
*dev
= info
->user_ptr
[1];
7026 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7027 struct bss_parameters params
;
7030 memset(¶ms
, 0, sizeof(params
));
7031 /* default to not changing parameters */
7032 params
.use_cts_prot
= -1;
7033 params
.use_short_preamble
= -1;
7034 params
.use_short_slot_time
= -1;
7035 params
.ap_isolate
= -1;
7036 params
.ht_opmode
= -1;
7037 params
.p2p_ctwindow
= -1;
7038 params
.p2p_opp_ps
= -1;
7040 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
7041 params
.use_cts_prot
=
7042 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
7043 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
7044 params
.use_short_preamble
=
7045 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
7046 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
7047 params
.use_short_slot_time
=
7048 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
7049 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7050 params
.basic_rates
=
7051 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7052 params
.basic_rates_len
=
7053 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7055 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
7056 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
7057 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
7059 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
7061 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
7062 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
7064 params
.p2p_ctwindow
=
7065 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
7066 if (params
.p2p_ctwindow
!= 0 &&
7067 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
7071 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
7074 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
7076 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
7077 params
.p2p_opp_ps
= tmp
;
7078 if (params
.p2p_opp_ps
&&
7079 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
7083 if (!rdev
->ops
->change_bss
)
7086 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
7087 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
7091 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
7097 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
7101 enum nl80211_user_reg_hint_type user_reg_hint_type
;
7105 * You should only get this when cfg80211 hasn't yet initialized
7106 * completely when built-in to the kernel right between the time
7107 * window between nl80211_init() and regulatory_init(), if that is
7110 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
7111 return -EINPROGRESS
;
7113 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
7114 user_reg_hint_type
=
7115 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
7117 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
7119 switch (user_reg_hint_type
) {
7120 case NL80211_USER_REG_HINT_USER
:
7121 case NL80211_USER_REG_HINT_CELL_BASE
:
7122 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
7125 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
7126 return regulatory_hint_user(data
, user_reg_hint_type
);
7127 case NL80211_USER_REG_HINT_INDOOR
:
7128 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
7129 owner_nlportid
= info
->snd_portid
;
7130 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
7136 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
7142 static int nl80211_reload_regdb(struct sk_buff
*skb
, struct genl_info
*info
)
7144 return reg_reload_regdb();
7147 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
7148 struct genl_info
*info
)
7150 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7151 struct net_device
*dev
= info
->user_ptr
[1];
7152 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7153 struct mesh_config cur_params
;
7156 struct nlattr
*pinfoattr
;
7157 struct sk_buff
*msg
;
7159 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
7162 if (!rdev
->ops
->get_mesh_config
)
7166 /* If not connected, get default parameters */
7167 if (!wdev
->mesh_id_len
)
7168 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
7170 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
7176 /* Draw up a netlink message to send back */
7177 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7180 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7181 NL80211_CMD_GET_MESH_CONFIG
);
7184 pinfoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_MESH_CONFIG
);
7186 goto nla_put_failure
;
7187 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
7188 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
7189 cur_params
.dot11MeshRetryTimeout
) ||
7190 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
7191 cur_params
.dot11MeshConfirmTimeout
) ||
7192 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
7193 cur_params
.dot11MeshHoldingTimeout
) ||
7194 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
7195 cur_params
.dot11MeshMaxPeerLinks
) ||
7196 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
7197 cur_params
.dot11MeshMaxRetries
) ||
7198 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
7199 cur_params
.dot11MeshTTL
) ||
7200 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
7201 cur_params
.element_ttl
) ||
7202 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
7203 cur_params
.auto_open_plinks
) ||
7204 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
7205 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
7206 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
7207 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
7208 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
7209 cur_params
.path_refresh_time
) ||
7210 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
7211 cur_params
.min_discovery_timeout
) ||
7212 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
7213 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
7214 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
7215 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
7216 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
7217 cur_params
.dot11MeshHWMPperrMinInterval
) ||
7218 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
7219 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
7220 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
7221 cur_params
.dot11MeshHWMPRootMode
) ||
7222 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
7223 cur_params
.dot11MeshHWMPRannInterval
) ||
7224 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
7225 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
7226 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
7227 cur_params
.dot11MeshForwarding
) ||
7228 nla_put_s32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
7229 cur_params
.rssi_threshold
) ||
7230 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
7231 cur_params
.ht_opmode
) ||
7232 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
7233 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
7234 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
7235 cur_params
.dot11MeshHWMProotInterval
) ||
7236 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
7237 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
7238 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
7239 cur_params
.power_mode
) ||
7240 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
7241 cur_params
.dot11MeshAwakeWindowDuration
) ||
7242 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
7243 cur_params
.plink_timeout
) ||
7244 nla_put_u8(msg
, NL80211_MESHCONF_CONNECTED_TO_GATE
,
7245 cur_params
.dot11MeshConnectedToMeshGate
) ||
7246 nla_put_u8(msg
, NL80211_MESHCONF_NOLEARN
,
7247 cur_params
.dot11MeshNolearn
) ||
7248 nla_put_u8(msg
, NL80211_MESHCONF_CONNECTED_TO_AS
,
7249 cur_params
.dot11MeshConnectedToAuthServer
))
7250 goto nla_put_failure
;
7251 nla_nest_end(msg
, pinfoattr
);
7252 genlmsg_end(msg
, hdr
);
7253 return genlmsg_reply(msg
, info
);
7261 static const struct nla_policy
7262 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
7263 [NL80211_MESHCONF_RETRY_TIMEOUT
] =
7264 NLA_POLICY_RANGE(NLA_U16
, 1, 255),
7265 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] =
7266 NLA_POLICY_RANGE(NLA_U16
, 1, 255),
7267 [NL80211_MESHCONF_HOLDING_TIMEOUT
] =
7268 NLA_POLICY_RANGE(NLA_U16
, 1, 255),
7269 [NL80211_MESHCONF_MAX_PEER_LINKS
] =
7270 NLA_POLICY_RANGE(NLA_U16
, 0, 255),
7271 [NL80211_MESHCONF_MAX_RETRIES
] = NLA_POLICY_MAX(NLA_U8
, 16),
7272 [NL80211_MESHCONF_TTL
] = NLA_POLICY_MIN(NLA_U8
, 1),
7273 [NL80211_MESHCONF_ELEMENT_TTL
] = NLA_POLICY_MIN(NLA_U8
, 1),
7274 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = NLA_POLICY_MAX(NLA_U8
, 1),
7275 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] =
7276 NLA_POLICY_RANGE(NLA_U32
, 1, 255),
7277 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
7278 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
7279 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = NLA_POLICY_MIN(NLA_U16
, 1),
7280 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
7281 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] =
7282 NLA_POLICY_MIN(NLA_U16
, 1),
7283 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] =
7284 NLA_POLICY_MIN(NLA_U16
, 1),
7285 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] =
7286 NLA_POLICY_MIN(NLA_U16
, 1),
7287 [NL80211_MESHCONF_HWMP_ROOTMODE
] = NLA_POLICY_MAX(NLA_U8
, 4),
7288 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] =
7289 NLA_POLICY_MIN(NLA_U16
, 1),
7290 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = NLA_POLICY_MAX(NLA_U8
, 1),
7291 [NL80211_MESHCONF_FORWARDING
] = NLA_POLICY_MAX(NLA_U8
, 1),
7292 [NL80211_MESHCONF_RSSI_THRESHOLD
] =
7293 NLA_POLICY_RANGE(NLA_S32
, -255, 0),
7294 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
7295 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
7296 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] =
7297 NLA_POLICY_MIN(NLA_U16
, 1),
7298 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] =
7299 NLA_POLICY_MIN(NLA_U16
, 1),
7300 [NL80211_MESHCONF_POWER_MODE
] =
7301 NLA_POLICY_RANGE(NLA_U32
,
7302 NL80211_MESH_POWER_ACTIVE
,
7303 NL80211_MESH_POWER_MAX
),
7304 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
7305 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
7306 [NL80211_MESHCONF_CONNECTED_TO_GATE
] = NLA_POLICY_RANGE(NLA_U8
, 0, 1),
7307 [NL80211_MESHCONF_NOLEARN
] = NLA_POLICY_RANGE(NLA_U8
, 0, 1),
7308 [NL80211_MESHCONF_CONNECTED_TO_AS
] = NLA_POLICY_RANGE(NLA_U8
, 0, 1),
7311 static const struct nla_policy
7312 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
7313 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
7314 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
7315 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
7316 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
7317 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
7318 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
7319 [NL80211_MESH_SETUP_IE
] =
7320 NLA_POLICY_VALIDATE_FN(NLA_BINARY
, validate_ie_attr
,
7321 IEEE80211_MAX_DATA_LEN
),
7322 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
7325 static int nl80211_parse_mesh_config(struct genl_info
*info
,
7326 struct mesh_config
*cfg
,
7329 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
7333 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
7336 cfg->param = fn(tb[attr]); \
7337 mask |= BIT((attr) - 1); \
7341 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
7343 if (nla_parse_nested_deprecated(tb
, NL80211_MESHCONF_ATTR_MAX
, info
->attrs
[NL80211_ATTR_MESH_CONFIG
], nl80211_meshconf_params_policy
, info
->extack
))
7346 /* This makes sure that there aren't more than 32 mesh config
7347 * parameters (otherwise our bitfield scheme would not work.) */
7348 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
7350 /* Fill in the params struct */
7351 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, mask
,
7352 NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
7353 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, mask
,
7354 NL80211_MESHCONF_CONFIRM_TIMEOUT
,
7356 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, mask
,
7357 NL80211_MESHCONF_HOLDING_TIMEOUT
,
7359 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, mask
,
7360 NL80211_MESHCONF_MAX_PEER_LINKS
,
7362 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, mask
,
7363 NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
7364 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, mask
,
7365 NL80211_MESHCONF_TTL
, nla_get_u8
);
7366 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, mask
,
7367 NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
7368 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, mask
,
7369 NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
7371 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
7373 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
7375 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, mask
,
7376 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
7378 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, mask
,
7379 NL80211_MESHCONF_PATH_REFRESH_TIME
,
7381 if (mask
& BIT(NL80211_MESHCONF_PATH_REFRESH_TIME
) &&
7382 (cfg
->path_refresh_time
< 1 || cfg
->path_refresh_time
> 65535))
7384 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, mask
,
7385 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
7387 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
7389 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
7391 if (mask
& BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
) &&
7392 (cfg
->dot11MeshHWMPactivePathTimeout
< 1 ||
7393 cfg
->dot11MeshHWMPactivePathTimeout
> 65535))
7395 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
, mask
,
7396 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
7398 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
, mask
,
7399 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
7401 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
7402 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
7403 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
7405 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
7406 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
7407 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
7408 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
7410 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshGateAnnouncementProtocol
,
7411 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
7413 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, mask
,
7414 NL80211_MESHCONF_FORWARDING
, nla_get_u8
);
7415 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, mask
,
7416 NL80211_MESHCONF_RSSI_THRESHOLD
,
7418 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConnectedToMeshGate
, mask
,
7419 NL80211_MESHCONF_CONNECTED_TO_GATE
,
7421 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConnectedToAuthServer
, mask
,
7422 NL80211_MESHCONF_CONNECTED_TO_AS
,
7425 * Check HT operation mode based on
7426 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
7428 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
7429 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
7431 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
7432 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
7433 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
7436 /* NON_HT_STA bit is reserved, but some programs set it */
7437 ht_opmode
&= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
;
7439 cfg
->ht_opmode
= ht_opmode
;
7440 mask
|= (1 << (NL80211_MESHCONF_HT_OPMODE
- 1));
7442 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
7443 dot11MeshHWMPactivePathToRootTimeout
, mask
,
7444 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
7446 if (mask
& BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
) &&
7447 (cfg
->dot11MeshHWMPactivePathToRootTimeout
< 1 ||
7448 cfg
->dot11MeshHWMPactivePathToRootTimeout
> 65535))
7450 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, mask
,
7451 NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
7453 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPconfirmationInterval
,
7455 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
7457 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
, mask
,
7458 NL80211_MESHCONF_POWER_MODE
, nla_get_u32
);
7459 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
, mask
,
7460 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
7461 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, mask
,
7462 NL80211_MESHCONF_PLINK_TIMEOUT
, nla_get_u32
);
7463 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNolearn
, mask
,
7464 NL80211_MESHCONF_NOLEARN
, nla_get_u8
);
7470 #undef FILL_IN_MESH_PARAM_IF_SET
7473 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
7474 struct mesh_setup
*setup
)
7476 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7477 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
7479 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
7481 if (nla_parse_nested_deprecated(tb
, NL80211_MESH_SETUP_ATTR_MAX
, info
->attrs
[NL80211_ATTR_MESH_SETUP
], nl80211_mesh_setup_params_policy
, info
->extack
))
7484 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
7485 setup
->sync_method
=
7486 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
7487 IEEE80211_SYNC_METHOD_VENDOR
:
7488 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
7490 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
7491 setup
->path_sel_proto
=
7492 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
7493 IEEE80211_PATH_PROTOCOL_VENDOR
:
7494 IEEE80211_PATH_PROTOCOL_HWMP
;
7496 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
7497 setup
->path_metric
=
7498 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
7499 IEEE80211_PATH_METRIC_VENDOR
:
7500 IEEE80211_PATH_METRIC_AIRTIME
;
7502 if (tb
[NL80211_MESH_SETUP_IE
]) {
7503 struct nlattr
*ieattr
=
7504 tb
[NL80211_MESH_SETUP_IE
];
7505 setup
->ie
= nla_data(ieattr
);
7506 setup
->ie_len
= nla_len(ieattr
);
7508 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
7509 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
7511 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
7512 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
7513 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
7514 if (setup
->is_secure
)
7515 setup
->user_mpm
= true;
7517 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
7518 if (!setup
->user_mpm
)
7521 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
7527 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
7528 struct genl_info
*info
)
7530 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7531 struct net_device
*dev
= info
->user_ptr
[1];
7532 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7533 struct mesh_config cfg
;
7537 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
7540 if (!rdev
->ops
->update_mesh_config
)
7543 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
7548 if (!wdev
->mesh_id_len
)
7552 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
7559 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
7560 struct sk_buff
*msg
)
7562 struct nlattr
*nl_reg_rules
;
7565 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
7566 (regdom
->dfs_region
&&
7567 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
7568 goto nla_put_failure
;
7570 nl_reg_rules
= nla_nest_start_noflag(msg
, NL80211_ATTR_REG_RULES
);
7572 goto nla_put_failure
;
7574 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
7575 struct nlattr
*nl_reg_rule
;
7576 const struct ieee80211_reg_rule
*reg_rule
;
7577 const struct ieee80211_freq_range
*freq_range
;
7578 const struct ieee80211_power_rule
*power_rule
;
7579 unsigned int max_bandwidth_khz
;
7581 reg_rule
= ®dom
->reg_rules
[i
];
7582 freq_range
= ®_rule
->freq_range
;
7583 power_rule
= ®_rule
->power_rule
;
7585 nl_reg_rule
= nla_nest_start_noflag(msg
, i
);
7587 goto nla_put_failure
;
7589 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
7590 if (!max_bandwidth_khz
)
7591 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
7594 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
7596 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
7597 freq_range
->start_freq_khz
) ||
7598 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
7599 freq_range
->end_freq_khz
) ||
7600 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
7601 max_bandwidth_khz
) ||
7602 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
7603 power_rule
->max_antenna_gain
) ||
7604 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
7605 power_rule
->max_eirp
) ||
7606 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
7607 reg_rule
->dfs_cac_ms
))
7608 goto nla_put_failure
;
7610 nla_nest_end(msg
, nl_reg_rule
);
7613 nla_nest_end(msg
, nl_reg_rules
);
7620 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
7622 const struct ieee80211_regdomain
*regdom
= NULL
;
7623 struct cfg80211_registered_device
*rdev
;
7624 struct wiphy
*wiphy
= NULL
;
7625 struct sk_buff
*msg
;
7628 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7632 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7633 NL80211_CMD_GET_REG
);
7637 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
7640 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
7643 return PTR_ERR(rdev
);
7646 wiphy
= &rdev
->wiphy
;
7647 self_managed
= wiphy
->regulatory_flags
&
7648 REGULATORY_WIPHY_SELF_MANAGED
;
7649 regdom
= get_wiphy_regdom(wiphy
);
7651 /* a self-managed-reg device must have a private regdom */
7652 if (WARN_ON(!regdom
&& self_managed
)) {
7658 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
7659 goto nla_put_failure
;
7662 if (!wiphy
&& reg_last_request_cell_base() &&
7663 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
7664 NL80211_USER_REG_HINT_CELL_BASE
))
7665 goto nla_put_failure
;
7670 regdom
= rcu_dereference(cfg80211_regdomain
);
7672 if (nl80211_put_regdom(regdom
, msg
))
7673 goto nla_put_failure_rcu
;
7677 genlmsg_end(msg
, hdr
);
7678 return genlmsg_reply(msg
, info
);
7680 nla_put_failure_rcu
:
7688 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
7689 u32 seq
, int flags
, struct wiphy
*wiphy
,
7690 const struct ieee80211_regdomain
*regdom
)
7692 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
7693 NL80211_CMD_GET_REG
);
7698 genl_dump_check_consistent(cb
, hdr
);
7700 if (nl80211_put_regdom(regdom
, msg
))
7701 goto nla_put_failure
;
7703 if (!wiphy
&& reg_last_request_cell_base() &&
7704 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
7705 NL80211_USER_REG_HINT_CELL_BASE
))
7706 goto nla_put_failure
;
7709 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
7710 goto nla_put_failure
;
7712 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
7713 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
7714 goto nla_put_failure
;
7716 genlmsg_end(msg
, hdr
);
7720 genlmsg_cancel(msg
, hdr
);
7724 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
7725 struct netlink_callback
*cb
)
7727 const struct ieee80211_regdomain
*regdom
= NULL
;
7728 struct cfg80211_registered_device
*rdev
;
7729 int err
, reg_idx
, start
= cb
->args
[2];
7733 if (cfg80211_regdomain
&& start
== 0) {
7734 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
7736 rtnl_dereference(cfg80211_regdomain
));
7741 /* the global regdom is idx 0 */
7743 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
7744 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
7748 if (++reg_idx
<= start
)
7751 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
7752 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
7759 cb
->args
[2] = reg_idx
;
7766 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
7767 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
7768 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
7769 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
7770 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
7771 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
7772 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
7773 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
7774 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
7777 static int parse_reg_rule(struct nlattr
*tb
[],
7778 struct ieee80211_reg_rule
*reg_rule
)
7780 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
7781 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
7783 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
7785 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
7787 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
7789 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
7791 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
7794 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
7796 freq_range
->start_freq_khz
=
7797 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
7798 freq_range
->end_freq_khz
=
7799 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
7800 freq_range
->max_bandwidth_khz
=
7801 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
7803 power_rule
->max_eirp
=
7804 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
7806 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
7807 power_rule
->max_antenna_gain
=
7808 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
7810 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
7811 reg_rule
->dfs_cac_ms
=
7812 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
7817 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
7819 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
7820 struct nlattr
*nl_reg_rule
;
7822 int rem_reg_rules
, r
;
7823 u32 num_rules
= 0, rule_idx
= 0;
7824 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
7825 struct ieee80211_regdomain
*rd
;
7827 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
7830 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
7833 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
7835 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
7836 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
7838 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
7841 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
7845 if (!reg_is_valid_request(alpha2
))
7848 rd
= kzalloc(struct_size(rd
, reg_rules
, num_rules
), GFP_KERNEL
);
7852 rd
->n_reg_rules
= num_rules
;
7853 rd
->alpha2
[0] = alpha2
[0];
7854 rd
->alpha2
[1] = alpha2
[1];
7857 * Disable DFS master mode if the DFS region was
7858 * not supported or known on this kernel.
7860 if (reg_supported_dfs_region(dfs_region
))
7861 rd
->dfs_region
= dfs_region
;
7863 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
7865 r
= nla_parse_nested_deprecated(tb
, NL80211_REG_RULE_ATTR_MAX
,
7866 nl_reg_rule
, reg_rule_policy
,
7870 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
7876 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
7882 /* set_regdom takes ownership of rd */
7883 return set_regdom(rd
, REGD_SOURCE_CRDA
);
7888 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
7890 static int validate_scan_freqs(struct nlattr
*freqs
)
7892 struct nlattr
*attr1
, *attr2
;
7893 int n_channels
= 0, tmp1
, tmp2
;
7895 nla_for_each_nested(attr1
, freqs
, tmp1
)
7896 if (nla_len(attr1
) != sizeof(u32
))
7899 nla_for_each_nested(attr1
, freqs
, tmp1
) {
7902 * Some hardware has a limited channel list for
7903 * scanning, and it is pretty much nonsensical
7904 * to scan for a channel twice, so disallow that
7905 * and don't require drivers to check that the
7906 * channel list they get isn't longer than what
7907 * they can scan, as long as they can scan all
7908 * the channels they registered at once.
7910 nla_for_each_nested(attr2
, freqs
, tmp2
)
7911 if (attr1
!= attr2
&&
7912 nla_get_u32(attr1
) == nla_get_u32(attr2
))
7919 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
7921 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
7924 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
7925 struct cfg80211_bss_selection
*bss_select
)
7927 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
7928 struct nlattr
*nest
;
7933 /* only process one nested attribute */
7934 nest
= nla_data(nla
);
7935 if (!nla_ok(nest
, nla_len(nest
)))
7938 err
= nla_parse_nested_deprecated(attr
, NL80211_BSS_SELECT_ATTR_MAX
,
7939 nest
, nl80211_bss_select_policy
,
7944 /* only one attribute may be given */
7945 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
7953 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
7955 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
7956 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
7958 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
7959 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
7960 bss_select
->param
.band_pref
=
7961 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
7962 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
7966 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
7967 struct nl80211_bss_select_rssi_adjust
*adj_param
;
7969 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
7970 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
7971 bss_select
->param
.adjust
.band
= adj_param
->band
;
7972 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
7973 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
7977 /* user-space did not provide behaviour attribute */
7978 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
7981 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
7987 int nl80211_parse_random_mac(struct nlattr
**attrs
,
7988 u8
*mac_addr
, u8
*mac_addr_mask
)
7992 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
7993 eth_zero_addr(mac_addr
);
7994 eth_zero_addr(mac_addr_mask
);
7996 mac_addr_mask
[0] = 0x3;
8001 /* need both or none */
8002 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
8005 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
8006 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
8008 /* don't allow or configure an mcast address */
8009 if (!is_multicast_ether_addr(mac_addr_mask
) ||
8010 is_multicast_ether_addr(mac_addr
))
8014 * allow users to pass a MAC address that has bits set outside
8015 * of the mask, but don't bother drivers with having to deal
8018 for (i
= 0; i
< ETH_ALEN
; i
++)
8019 mac_addr
[i
] &= mac_addr_mask
[i
];
8024 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev
*wdev
)
8026 ASSERT_WDEV_LOCK(wdev
);
8028 if (!cfg80211_beaconing_iface_active(wdev
))
8031 if (!(wdev
->chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
))
8034 return regulatory_pre_cac_allowed(wdev
->wiphy
);
8037 static bool nl80211_check_scan_feat(struct wiphy
*wiphy
, u32 flags
, u32 flag
,
8038 enum nl80211_ext_feature_index feat
)
8040 if (!(flags
& flag
))
8042 if (wiphy_ext_feature_isset(wiphy
, feat
))
8048 nl80211_check_scan_flags(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
8049 void *request
, struct nlattr
**attrs
,
8052 u8
*mac_addr
, *mac_addr_mask
;
8054 enum nl80211_feature_flags randomness_flag
;
8056 if (!attrs
[NL80211_ATTR_SCAN_FLAGS
])
8059 if (is_sched_scan
) {
8060 struct cfg80211_sched_scan_request
*req
= request
;
8062 randomness_flag
= wdev
?
8063 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
:
8064 NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
8065 flags
= &req
->flags
;
8066 mac_addr
= req
->mac_addr
;
8067 mac_addr_mask
= req
->mac_addr_mask
;
8069 struct cfg80211_scan_request
*req
= request
;
8071 randomness_flag
= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
8072 flags
= &req
->flags
;
8073 mac_addr
= req
->mac_addr
;
8074 mac_addr_mask
= req
->mac_addr_mask
;
8077 *flags
= nla_get_u32(attrs
[NL80211_ATTR_SCAN_FLAGS
]);
8079 if (((*flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
8080 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
8081 !nl80211_check_scan_feat(wiphy
, *flags
,
8082 NL80211_SCAN_FLAG_LOW_SPAN
,
8083 NL80211_EXT_FEATURE_LOW_SPAN_SCAN
) ||
8084 !nl80211_check_scan_feat(wiphy
, *flags
,
8085 NL80211_SCAN_FLAG_LOW_POWER
,
8086 NL80211_EXT_FEATURE_LOW_POWER_SCAN
) ||
8087 !nl80211_check_scan_feat(wiphy
, *flags
,
8088 NL80211_SCAN_FLAG_HIGH_ACCURACY
,
8089 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN
) ||
8090 !nl80211_check_scan_feat(wiphy
, *flags
,
8091 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME
,
8092 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME
) ||
8093 !nl80211_check_scan_feat(wiphy
, *flags
,
8094 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP
,
8095 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP
) ||
8096 !nl80211_check_scan_feat(wiphy
, *flags
,
8097 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
,
8098 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
) ||
8099 !nl80211_check_scan_feat(wiphy
, *flags
,
8100 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE
,
8101 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE
) ||
8102 !nl80211_check_scan_feat(wiphy
, *flags
,
8103 NL80211_SCAN_FLAG_RANDOM_SN
,
8104 NL80211_EXT_FEATURE_SCAN_RANDOM_SN
) ||
8105 !nl80211_check_scan_feat(wiphy
, *flags
,
8106 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT
,
8107 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT
))
8110 if (*flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
8113 if (!(wiphy
->features
& randomness_flag
) ||
8114 (wdev
&& wdev
->current_bss
))
8117 err
= nl80211_parse_random_mac(attrs
, mac_addr
, mac_addr_mask
);
8125 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
8127 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8128 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8129 struct cfg80211_scan_request
*request
;
8130 struct nlattr
*scan_freqs
= NULL
;
8131 bool scan_freqs_khz
= false;
8132 struct nlattr
*attr
;
8133 struct wiphy
*wiphy
;
8134 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
8137 wiphy
= &rdev
->wiphy
;
8139 if (wdev
->iftype
== NL80211_IFTYPE_NAN
)
8142 if (!rdev
->ops
->scan
)
8145 if (rdev
->scan_req
|| rdev
->scan_msg
)
8148 if (info
->attrs
[NL80211_ATTR_SCAN_FREQ_KHZ
]) {
8149 if (!wiphy_ext_feature_isset(wiphy
,
8150 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ
))
8152 scan_freqs
= info
->attrs
[NL80211_ATTR_SCAN_FREQ_KHZ
];
8153 scan_freqs_khz
= true;
8154 } else if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
])
8155 scan_freqs
= info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
];
8158 n_channels
= validate_scan_freqs(scan_freqs
);
8162 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
8165 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
8166 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
8169 if (n_ssids
> wiphy
->max_scan_ssids
)
8172 if (info
->attrs
[NL80211_ATTR_IE
])
8173 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8177 if (ie_len
> wiphy
->max_scan_ie_len
)
8180 request
= kzalloc(sizeof(*request
)
8181 + sizeof(*request
->ssids
) * n_ssids
8182 + sizeof(*request
->channels
) * n_channels
8183 + ie_len
, GFP_KERNEL
);
8188 request
->ssids
= (void *)&request
->channels
[n_channels
];
8189 request
->n_ssids
= n_ssids
;
8192 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
8194 request
->ie
= (void *)(request
->channels
+ n_channels
);
8199 /* user specified, bail out if channel not found */
8200 nla_for_each_nested(attr
, scan_freqs
, tmp
) {
8201 struct ieee80211_channel
*chan
;
8202 int freq
= nla_get_u32(attr
);
8204 if (!scan_freqs_khz
)
8205 freq
= MHZ_TO_KHZ(freq
);
8207 chan
= ieee80211_get_channel_khz(wiphy
, freq
);
8213 /* ignore disabled channels */
8214 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
8217 request
->channels
[i
] = chan
;
8221 enum nl80211_band band
;
8224 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8227 if (!wiphy
->bands
[band
])
8229 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
8230 struct ieee80211_channel
*chan
;
8232 chan
= &wiphy
->bands
[band
]->channels
[j
];
8234 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
8237 request
->channels
[i
] = chan
;
8248 request
->n_channels
= i
;
8251 if (!cfg80211_off_channel_oper_allowed(wdev
)) {
8252 struct ieee80211_channel
*chan
;
8254 if (request
->n_channels
!= 1) {
8260 chan
= request
->channels
[0];
8261 if (chan
->center_freq
!= wdev
->chandef
.chan
->center_freq
) {
8271 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
8272 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
8276 request
->ssids
[i
].ssid_len
= nla_len(attr
);
8277 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
8282 if (info
->attrs
[NL80211_ATTR_IE
]) {
8283 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8284 memcpy((void *)request
->ie
,
8285 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
8289 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
8290 if (wiphy
->bands
[i
])
8292 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
8294 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
8295 nla_for_each_nested(attr
,
8296 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
8298 enum nl80211_band band
= nla_type(attr
);
8300 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
8305 if (!wiphy
->bands
[band
])
8308 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
8311 &request
->rates
[band
]);
8317 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
8319 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
8320 request
->duration_mandatory
=
8321 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
8324 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, info
->attrs
,
8330 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
8332 /* Initial implementation used NL80211_ATTR_MAC to set the specific
8333 * BSSID to scan for. This was problematic because that same attribute
8334 * was already used for another purpose (local random MAC address). The
8335 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
8336 * compatibility with older userspace components, also use the
8337 * NL80211_ATTR_MAC value here if it can be determined to be used for
8338 * the specific BSSID use case instead of the random MAC address
8339 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
8341 if (info
->attrs
[NL80211_ATTR_BSSID
])
8342 memcpy(request
->bssid
,
8343 nla_data(info
->attrs
[NL80211_ATTR_BSSID
]), ETH_ALEN
);
8344 else if (!(request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) &&
8345 info
->attrs
[NL80211_ATTR_MAC
])
8346 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
8349 eth_broadcast_addr(request
->bssid
);
8351 request
->wdev
= wdev
;
8352 request
->wiphy
= &rdev
->wiphy
;
8353 request
->scan_start
= jiffies
;
8355 rdev
->scan_req
= request
;
8356 err
= cfg80211_scan(rdev
);
8361 nl80211_send_scan_start(rdev
, wdev
);
8363 dev_hold(wdev
->netdev
);
8368 rdev
->scan_req
= NULL
;
8374 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
8376 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8377 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8379 if (!rdev
->ops
->abort_scan
)
8385 if (!rdev
->scan_req
)
8388 rdev_abort_scan(rdev
, wdev
);
8393 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
8394 struct cfg80211_sched_scan_request
*request
,
8395 struct nlattr
**attrs
)
8397 int tmp
, err
, i
= 0;
8398 struct nlattr
*attr
;
8400 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
8404 * If scan plans are not specified,
8405 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
8406 * case one scan plan will be set with the specified scan
8407 * interval and infinite number of iterations.
8409 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
8413 request
->scan_plans
[0].interval
=
8414 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
8415 if (!request
->scan_plans
[0].interval
)
8418 if (request
->scan_plans
[0].interval
>
8419 wiphy
->max_sched_scan_plan_interval
)
8420 request
->scan_plans
[0].interval
=
8421 wiphy
->max_sched_scan_plan_interval
;
8426 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
8427 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
8429 if (WARN_ON(i
>= n_plans
))
8432 err
= nla_parse_nested_deprecated(plan
,
8433 NL80211_SCHED_SCAN_PLAN_MAX
,
8434 attr
, nl80211_plan_policy
,
8439 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
8442 request
->scan_plans
[i
].interval
=
8443 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
8444 if (!request
->scan_plans
[i
].interval
||
8445 request
->scan_plans
[i
].interval
>
8446 wiphy
->max_sched_scan_plan_interval
)
8449 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
8450 request
->scan_plans
[i
].iterations
=
8451 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
8452 if (!request
->scan_plans
[i
].iterations
||
8453 (request
->scan_plans
[i
].iterations
>
8454 wiphy
->max_sched_scan_plan_iterations
))
8456 } else if (i
< n_plans
- 1) {
8458 * All scan plans but the last one must specify
8459 * a finite number of iterations
8468 * The last scan plan must not specify the number of
8469 * iterations, it is supposed to run infinitely
8471 if (request
->scan_plans
[n_plans
- 1].iterations
)
8478 nl80211_parse_sched_scan_per_band_rssi(struct wiphy
*wiphy
,
8479 struct cfg80211_match_set
*match_sets
,
8480 struct nlattr
*tb_band_rssi
,
8483 struct nlattr
*attr
;
8484 int i
, tmp
, ret
= 0;
8486 if (!wiphy_ext_feature_isset(wiphy
,
8487 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD
)) {
8491 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
8492 match_sets
->per_band_rssi_thold
[i
] =
8493 NL80211_SCAN_RSSI_THOLD_OFF
;
8497 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
8498 match_sets
->per_band_rssi_thold
[i
] = rssi_thold
;
8500 nla_for_each_nested(attr
, tb_band_rssi
, tmp
) {
8501 enum nl80211_band band
= nla_type(attr
);
8503 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
8506 match_sets
->per_band_rssi_thold
[band
] = nla_get_s32(attr
);
8512 static struct cfg80211_sched_scan_request
*
8513 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
8514 struct nlattr
**attrs
, int max_match_sets
)
8516 struct cfg80211_sched_scan_request
*request
;
8517 struct nlattr
*attr
;
8518 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
8519 enum nl80211_band band
;
8521 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
8522 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
8524 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
8525 n_channels
= validate_scan_freqs(
8526 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
8528 return ERR_PTR(-EINVAL
);
8530 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
8533 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
8534 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
8538 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
8539 return ERR_PTR(-EINVAL
);
8542 * First, count the number of 'real' matchsets. Due to an issue with
8543 * the old implementation, matchsets containing only the RSSI attribute
8544 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
8545 * RSSI for all matchsets, rather than their own matchset for reporting
8546 * all APs with a strong RSSI. This is needed to be compatible with
8547 * older userspace that treated a matchset with only the RSSI as the
8548 * global RSSI for all other matchsets - if there are other matchsets.
8550 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
8551 nla_for_each_nested(attr
,
8552 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
8554 struct nlattr
*rssi
;
8556 err
= nla_parse_nested_deprecated(tb
,
8557 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
8559 nl80211_match_policy
,
8562 return ERR_PTR(err
);
8564 /* SSID and BSSID are mutually exclusive */
8565 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] &&
8566 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
])
8567 return ERR_PTR(-EINVAL
);
8569 /* add other standalone attributes here */
8570 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] ||
8571 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
]) {
8575 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
8577 default_match_rssi
= nla_get_s32(rssi
);
8581 /* However, if there's no other matchset, add the RSSI one */
8582 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
8585 if (n_match_sets
> max_match_sets
)
8586 return ERR_PTR(-EINVAL
);
8588 if (attrs
[NL80211_ATTR_IE
])
8589 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
8593 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
8594 return ERR_PTR(-EINVAL
);
8596 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
8598 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
8599 * each scan plan already specifies its own interval
8601 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
8602 return ERR_PTR(-EINVAL
);
8604 nla_for_each_nested(attr
,
8605 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
8609 * The scan interval attribute is kept for backward
8610 * compatibility. If no scan plans are specified and sched scan
8611 * interval is specified, one scan plan will be set with this
8612 * scan interval and infinite number of iterations.
8614 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
8615 return ERR_PTR(-EINVAL
);
8620 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
8621 return ERR_PTR(-EINVAL
);
8623 if (!wiphy_ext_feature_isset(
8624 wiphy
, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI
) &&
8625 (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] ||
8626 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]))
8627 return ERR_PTR(-EINVAL
);
8629 request
= kzalloc(sizeof(*request
)
8630 + sizeof(*request
->ssids
) * n_ssids
8631 + sizeof(*request
->match_sets
) * n_match_sets
8632 + sizeof(*request
->scan_plans
) * n_plans
8633 + sizeof(*request
->channels
) * n_channels
8634 + ie_len
, GFP_KERNEL
);
8636 return ERR_PTR(-ENOMEM
);
8639 request
->ssids
= (void *)&request
->channels
[n_channels
];
8640 request
->n_ssids
= n_ssids
;
8643 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
8645 request
->ie
= (void *)(request
->channels
+ n_channels
);
8650 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
8652 request
->match_sets
=
8653 (void *)(request
->ssids
+ n_ssids
);
8655 request
->match_sets
=
8656 (void *)(request
->channels
+ n_channels
);
8658 request
->n_match_sets
= n_match_sets
;
8661 request
->scan_plans
= (void *)(request
->match_sets
+
8663 else if (request
->ie
)
8664 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
8666 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
8668 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
8670 request
->n_scan_plans
= n_plans
;
8673 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
8674 /* user specified, bail out if channel not found */
8675 nla_for_each_nested(attr
,
8676 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
8678 struct ieee80211_channel
*chan
;
8680 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
8687 /* ignore disabled channels */
8688 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
8691 request
->channels
[i
] = chan
;
8696 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8699 if (!wiphy
->bands
[band
])
8701 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
8702 struct ieee80211_channel
*chan
;
8704 chan
= &wiphy
->bands
[band
]->channels
[j
];
8706 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
8709 request
->channels
[i
] = chan
;
8720 request
->n_channels
= i
;
8724 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
8726 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
8730 request
->ssids
[i
].ssid_len
= nla_len(attr
);
8731 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
8738 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
8739 nla_for_each_nested(attr
,
8740 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
8742 struct nlattr
*ssid
, *bssid
, *rssi
;
8744 err
= nla_parse_nested_deprecated(tb
,
8745 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
8747 nl80211_match_policy
,
8751 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
8752 bssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
];
8754 if (!ssid
&& !bssid
) {
8759 if (WARN_ON(i
>= n_match_sets
)) {
8760 /* this indicates a programming error,
8761 * the loop above should have verified
8769 memcpy(request
->match_sets
[i
].ssid
.ssid
,
8770 nla_data(ssid
), nla_len(ssid
));
8771 request
->match_sets
[i
].ssid
.ssid_len
=
8775 memcpy(request
->match_sets
[i
].bssid
,
8776 nla_data(bssid
), ETH_ALEN
);
8778 /* special attribute - old implementation w/a */
8779 request
->match_sets
[i
].rssi_thold
= default_match_rssi
;
8780 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
8782 request
->match_sets
[i
].rssi_thold
=
8785 /* Parse per band RSSI attribute */
8786 err
= nl80211_parse_sched_scan_per_band_rssi(wiphy
,
8787 &request
->match_sets
[i
],
8788 tb
[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI
],
8789 request
->match_sets
[i
].rssi_thold
);
8796 /* there was no other matchset, so the RSSI one is alone */
8797 if (i
== 0 && n_match_sets
)
8798 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
8800 request
->min_rssi_thold
= INT_MAX
;
8801 for (i
= 0; i
< n_match_sets
; i
++)
8802 request
->min_rssi_thold
=
8803 min(request
->match_sets
[i
].rssi_thold
,
8804 request
->min_rssi_thold
);
8806 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
8810 request
->ie_len
= ie_len
;
8811 memcpy((void *)request
->ie
,
8812 nla_data(attrs
[NL80211_ATTR_IE
]),
8816 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, attrs
, true);
8820 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
8822 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
8824 if (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]) {
8825 request
->relative_rssi
= nla_get_s8(
8826 attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]);
8827 request
->relative_rssi_set
= true;
8830 if (request
->relative_rssi_set
&&
8831 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]) {
8832 struct nl80211_bss_select_rssi_adjust
*rssi_adjust
;
8834 rssi_adjust
= nla_data(
8835 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]);
8836 request
->rssi_adjust
.band
= rssi_adjust
->band
;
8837 request
->rssi_adjust
.delta
= rssi_adjust
->delta
;
8838 if (!is_band_valid(wiphy
, request
->rssi_adjust
.band
)) {
8844 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
8848 request
->scan_start
= jiffies
;
8854 return ERR_PTR(err
);
8857 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
8858 struct genl_info
*info
)
8860 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8861 struct net_device
*dev
= info
->user_ptr
[1];
8862 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8863 struct cfg80211_sched_scan_request
*sched_scan_req
;
8867 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_start
)
8870 want_multi
= info
->attrs
[NL80211_ATTR_SCHED_SCAN_MULTI
];
8871 err
= cfg80211_sched_scan_req_possible(rdev
, want_multi
);
8875 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
8877 rdev
->wiphy
.max_match_sets
);
8879 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
8883 /* leave request id zero for legacy request
8884 * or if driver does not support multi-scheduled scan
8886 if (want_multi
&& rdev
->wiphy
.max_sched_scan_reqs
> 1)
8887 sched_scan_req
->reqid
= cfg80211_assign_cookie(rdev
);
8889 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
8893 sched_scan_req
->dev
= dev
;
8894 sched_scan_req
->wiphy
= &rdev
->wiphy
;
8896 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
8897 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
8899 cfg80211_add_sched_scan_req(rdev
, sched_scan_req
);
8901 nl80211_send_sched_scan(sched_scan_req
, NL80211_CMD_START_SCHED_SCAN
);
8905 kfree(sched_scan_req
);
8910 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
8911 struct genl_info
*info
)
8913 struct cfg80211_sched_scan_request
*req
;
8914 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8917 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_stop
)
8920 if (info
->attrs
[NL80211_ATTR_COOKIE
]) {
8921 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8922 return __cfg80211_stop_sched_scan(rdev
, cookie
, false);
8925 req
= list_first_or_null_rcu(&rdev
->sched_scan_req_list
,
8926 struct cfg80211_sched_scan_request
,
8928 if (!req
|| req
->reqid
||
8929 (req
->owner_nlportid
&&
8930 req
->owner_nlportid
!= info
->snd_portid
))
8933 return cfg80211_stop_sched_scan_req(rdev
, req
, false);
8936 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
8937 struct genl_info
*info
)
8939 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8940 struct net_device
*dev
= info
->user_ptr
[1];
8941 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8942 struct wiphy
*wiphy
= wdev
->wiphy
;
8943 struct cfg80211_chan_def chandef
;
8944 enum nl80211_dfs_regions dfs_region
;
8945 unsigned int cac_time_ms
;
8948 dfs_region
= reg_get_dfs_region(wiphy
);
8949 if (dfs_region
== NL80211_DFS_UNSET
)
8952 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8956 if (netif_carrier_ok(dev
))
8959 if (wdev
->cac_started
)
8962 err
= cfg80211_chandef_dfs_required(wiphy
, &chandef
, wdev
->iftype
);
8969 if (!cfg80211_chandef_dfs_usable(wiphy
, &chandef
))
8972 /* CAC start is offloaded to HW and can't be started manually */
8973 if (wiphy_ext_feature_isset(wiphy
, NL80211_EXT_FEATURE_DFS_OFFLOAD
))
8976 if (!rdev
->ops
->start_radar_detection
)
8979 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
8980 if (WARN_ON(!cac_time_ms
))
8981 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
8983 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
8985 wdev
->chandef
= chandef
;
8986 wdev
->cac_started
= true;
8987 wdev
->cac_start_time
= jiffies
;
8988 wdev
->cac_time_ms
= cac_time_ms
;
8993 static int nl80211_notify_radar_detection(struct sk_buff
*skb
,
8994 struct genl_info
*info
)
8996 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8997 struct net_device
*dev
= info
->user_ptr
[1];
8998 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8999 struct wiphy
*wiphy
= wdev
->wiphy
;
9000 struct cfg80211_chan_def chandef
;
9001 enum nl80211_dfs_regions dfs_region
;
9004 dfs_region
= reg_get_dfs_region(wiphy
);
9005 if (dfs_region
== NL80211_DFS_UNSET
) {
9006 GENL_SET_ERR_MSG(info
,
9007 "DFS Region is not set. Unexpected Radar indication");
9011 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9013 GENL_SET_ERR_MSG(info
, "Unable to extract chandef info");
9017 err
= cfg80211_chandef_dfs_required(wiphy
, &chandef
, wdev
->iftype
);
9019 GENL_SET_ERR_MSG(info
, "chandef is invalid");
9024 GENL_SET_ERR_MSG(info
,
9025 "Unexpected Radar indication for chandef/iftype");
9029 /* Do not process this notification if radar is already detected
9030 * by kernel on this channel, and return success.
9032 if (chandef
.chan
->dfs_state
== NL80211_DFS_UNAVAILABLE
)
9035 cfg80211_set_dfs_state(wiphy
, &chandef
, NL80211_DFS_UNAVAILABLE
);
9037 cfg80211_sched_dfs_chan_update(rdev
);
9039 rdev
->radar_chandef
= chandef
;
9041 /* Propagate this notification to other radios as well */
9042 queue_work(cfg80211_wq
, &rdev
->propagate_radar_detect_wk
);
9047 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
9049 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9050 struct net_device
*dev
= info
->user_ptr
[1];
9051 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9052 struct cfg80211_csa_settings params
;
9053 /* csa_attrs is defined static to avoid waste of stack size - this
9054 * function is called under RTNL lock, so this should not be a problem.
9056 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
9058 bool need_new_beacon
= false;
9059 bool need_handle_dfs_flag
= true;
9063 if (!rdev
->ops
->channel_switch
||
9064 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
9067 switch (dev
->ieee80211_ptr
->iftype
) {
9068 case NL80211_IFTYPE_AP
:
9069 case NL80211_IFTYPE_P2P_GO
:
9070 need_new_beacon
= true;
9071 /* For all modes except AP the handle_dfs flag needs to be
9072 * supplied to tell the kernel that userspace will handle radar
9073 * events when they happen. Otherwise a switch to a channel
9074 * requiring DFS will be rejected.
9076 need_handle_dfs_flag
= false;
9078 /* useless if AP is not running */
9079 if (!wdev
->beacon_interval
)
9082 case NL80211_IFTYPE_ADHOC
:
9083 if (!wdev
->ssid_len
)
9086 case NL80211_IFTYPE_MESH_POINT
:
9087 if (!wdev
->mesh_id_len
)
9094 memset(¶ms
, 0, sizeof(params
));
9095 params
.beacon_csa
.ftm_responder
= -1;
9097 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
9098 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
9101 /* only important for AP, IBSS and mesh create IEs internally */
9102 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
9105 /* Even though the attribute is u32, the specification says
9106 * u8, so let's make sure we don't overflow.
9108 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
9112 params
.count
= cs_count
;
9114 if (!need_new_beacon
)
9117 err
= nl80211_parse_beacon(rdev
, info
->attrs
, ¶ms
.beacon_after
);
9121 err
= nla_parse_nested_deprecated(csa_attrs
, NL80211_ATTR_MAX
,
9122 info
->attrs
[NL80211_ATTR_CSA_IES
],
9123 nl80211_policy
, info
->extack
);
9127 err
= nl80211_parse_beacon(rdev
, csa_attrs
, ¶ms
.beacon_csa
);
9131 if (!csa_attrs
[NL80211_ATTR_CNTDWN_OFFS_BEACON
])
9134 len
= nla_len(csa_attrs
[NL80211_ATTR_CNTDWN_OFFS_BEACON
]);
9135 if (!len
|| (len
% sizeof(u16
)))
9138 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
9139 if (rdev
->wiphy
.max_num_csa_counters
&&
9140 (params
.n_counter_offsets_beacon
>
9141 rdev
->wiphy
.max_num_csa_counters
))
9144 params
.counter_offsets_beacon
=
9145 nla_data(csa_attrs
[NL80211_ATTR_CNTDWN_OFFS_BEACON
]);
9147 /* sanity checks - counters should fit and be the same */
9148 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
9149 u16 offset
= params
.counter_offsets_beacon
[i
];
9151 if (offset
>= params
.beacon_csa
.tail_len
)
9154 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
9158 if (csa_attrs
[NL80211_ATTR_CNTDWN_OFFS_PRESP
]) {
9159 len
= nla_len(csa_attrs
[NL80211_ATTR_CNTDWN_OFFS_PRESP
]);
9160 if (!len
|| (len
% sizeof(u16
)))
9163 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
9164 if (rdev
->wiphy
.max_num_csa_counters
&&
9165 (params
.n_counter_offsets_presp
>
9166 rdev
->wiphy
.max_num_csa_counters
))
9169 params
.counter_offsets_presp
=
9170 nla_data(csa_attrs
[NL80211_ATTR_CNTDWN_OFFS_PRESP
]);
9172 /* sanity checks - counters should fit and be the same */
9173 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
9174 u16 offset
= params
.counter_offsets_presp
[i
];
9176 if (offset
>= params
.beacon_csa
.probe_resp_len
)
9179 if (params
.beacon_csa
.probe_resp
[offset
] !=
9186 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
9190 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
9194 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
9201 params
.radar_required
= true;
9202 if (need_handle_dfs_flag
&&
9203 !nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
])) {
9208 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
9209 params
.block_tx
= true;
9212 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
9218 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
9220 struct cfg80211_registered_device
*rdev
,
9221 struct wireless_dev
*wdev
,
9222 struct cfg80211_internal_bss
*intbss
)
9224 struct cfg80211_bss
*res
= &intbss
->pub
;
9225 const struct cfg80211_bss_ies
*ies
;
9229 ASSERT_WDEV_LOCK(wdev
);
9231 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
9232 NL80211_CMD_NEW_SCAN_RESULTS
);
9236 genl_dump_check_consistent(cb
, hdr
);
9238 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
9239 goto nla_put_failure
;
9241 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
9242 goto nla_put_failure
;
9243 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
9245 goto nla_put_failure
;
9247 bss
= nla_nest_start_noflag(msg
, NL80211_ATTR_BSS
);
9249 goto nla_put_failure
;
9250 if ((!is_zero_ether_addr(res
->bssid
) &&
9251 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
9252 goto nla_put_failure
;
9255 /* indicate whether we have probe response data or not */
9256 if (rcu_access_pointer(res
->proberesp_ies
) &&
9257 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
9258 goto fail_unlock_rcu
;
9260 /* this pointer prefers to be pointed to probe response data
9261 * but is always valid
9263 ies
= rcu_dereference(res
->ies
);
9265 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
9267 goto fail_unlock_rcu
;
9268 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
9269 ies
->len
, ies
->data
))
9270 goto fail_unlock_rcu
;
9273 /* and this pointer is always (unless driver didn't know) beacon data */
9274 ies
= rcu_dereference(res
->beacon_ies
);
9275 if (ies
&& ies
->from_beacon
) {
9276 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
9278 goto fail_unlock_rcu
;
9279 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
9280 ies
->len
, ies
->data
))
9281 goto fail_unlock_rcu
;
9285 if (res
->beacon_interval
&&
9286 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
9287 goto nla_put_failure
;
9288 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
9289 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
9290 nla_put_u32(msg
, NL80211_BSS_FREQUENCY_OFFSET
,
9291 res
->channel
->freq_offset
) ||
9292 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
9293 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
9294 jiffies_to_msecs(jiffies
- intbss
->ts
)))
9295 goto nla_put_failure
;
9297 if (intbss
->parent_tsf
&&
9298 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
9299 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
9300 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
9301 intbss
->parent_bssid
)))
9302 goto nla_put_failure
;
9304 if (intbss
->ts_boottime
&&
9305 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
9306 intbss
->ts_boottime
, NL80211_BSS_PAD
))
9307 goto nla_put_failure
;
9309 if (!nl80211_put_signal(msg
, intbss
->pub
.chains
,
9310 intbss
->pub
.chain_signal
,
9311 NL80211_BSS_CHAIN_SIGNAL
))
9312 goto nla_put_failure
;
9314 switch (rdev
->wiphy
.signal_type
) {
9315 case CFG80211_SIGNAL_TYPE_MBM
:
9316 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
9317 goto nla_put_failure
;
9319 case CFG80211_SIGNAL_TYPE_UNSPEC
:
9320 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
9321 goto nla_put_failure
;
9327 switch (wdev
->iftype
) {
9328 case NL80211_IFTYPE_P2P_CLIENT
:
9329 case NL80211_IFTYPE_STATION
:
9330 if (intbss
== wdev
->current_bss
&&
9331 nla_put_u32(msg
, NL80211_BSS_STATUS
,
9332 NL80211_BSS_STATUS_ASSOCIATED
))
9333 goto nla_put_failure
;
9335 case NL80211_IFTYPE_ADHOC
:
9336 if (intbss
== wdev
->current_bss
&&
9337 nla_put_u32(msg
, NL80211_BSS_STATUS
,
9338 NL80211_BSS_STATUS_IBSS_JOINED
))
9339 goto nla_put_failure
;
9345 nla_nest_end(msg
, bss
);
9347 genlmsg_end(msg
, hdr
);
9353 genlmsg_cancel(msg
, hdr
);
9357 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
9359 struct cfg80211_registered_device
*rdev
;
9360 struct cfg80211_internal_bss
*scan
;
9361 struct wireless_dev
*wdev
;
9362 int start
= cb
->args
[2], idx
= 0;
9366 err
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
9373 spin_lock_bh(&rdev
->bss_lock
);
9376 * dump_scan will be called multiple times to break up the scan results
9377 * into multiple messages. It is unlikely that any more bss-es will be
9378 * expired after the first call, so only call only call this on the
9379 * first dump_scan invocation.
9382 cfg80211_bss_expire(rdev
);
9384 cb
->seq
= rdev
->bss_generation
;
9386 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
9389 if (nl80211_send_bss(skb
, cb
,
9390 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
9391 rdev
, wdev
, scan
) < 0) {
9397 spin_unlock_bh(&rdev
->bss_lock
);
9406 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
9407 int flags
, struct net_device
*dev
,
9408 bool allow_radio_stats
,
9409 struct survey_info
*survey
)
9412 struct nlattr
*infoattr
;
9414 /* skip radio stats if userspace didn't request them */
9415 if (!survey
->channel
&& !allow_radio_stats
)
9418 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
9419 NL80211_CMD_NEW_SURVEY_RESULTS
);
9423 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
9424 goto nla_put_failure
;
9426 infoattr
= nla_nest_start_noflag(msg
, NL80211_ATTR_SURVEY_INFO
);
9428 goto nla_put_failure
;
9430 if (survey
->channel
&&
9431 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
9432 survey
->channel
->center_freq
))
9433 goto nla_put_failure
;
9435 if (survey
->channel
&& survey
->channel
->freq_offset
&&
9436 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY_OFFSET
,
9437 survey
->channel
->freq_offset
))
9438 goto nla_put_failure
;
9440 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
9441 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
9442 goto nla_put_failure
;
9443 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
9444 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
9445 goto nla_put_failure
;
9446 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
9447 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
9448 survey
->time
, NL80211_SURVEY_INFO_PAD
))
9449 goto nla_put_failure
;
9450 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
9451 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
9452 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
9453 goto nla_put_failure
;
9454 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
9455 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
9456 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
9457 goto nla_put_failure
;
9458 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
9459 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
9460 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
9461 goto nla_put_failure
;
9462 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
9463 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
9464 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
9465 goto nla_put_failure
;
9466 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
9467 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
9468 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
9469 goto nla_put_failure
;
9470 if ((survey
->filled
& SURVEY_INFO_TIME_BSS_RX
) &&
9471 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BSS_RX
,
9472 survey
->time_bss_rx
, NL80211_SURVEY_INFO_PAD
))
9473 goto nla_put_failure
;
9475 nla_nest_end(msg
, infoattr
);
9477 genlmsg_end(msg
, hdr
);
9481 genlmsg_cancel(msg
, hdr
);
9485 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
9487 struct nlattr
**attrbuf
;
9488 struct survey_info survey
;
9489 struct cfg80211_registered_device
*rdev
;
9490 struct wireless_dev
*wdev
;
9491 int survey_idx
= cb
->args
[2];
9495 attrbuf
= kcalloc(NUM_NL80211_ATTR
, sizeof(*attrbuf
), GFP_KERNEL
);
9500 res
= nl80211_prepare_wdev_dump(cb
, &rdev
, &wdev
);
9504 /* prepare_wdev_dump parsed the attributes */
9505 radio_stats
= attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
9507 if (!wdev
->netdev
) {
9512 if (!rdev
->ops
->dump_survey
) {
9518 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
9524 /* don't send disabled channels, but do send non-channel data */
9525 if (survey
.channel
&&
9526 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
9531 if (nl80211_send_survey(skb
,
9532 NETLINK_CB(cb
->skb
).portid
,
9533 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
9534 wdev
->netdev
, radio_stats
, &survey
) < 0)
9540 cb
->args
[2] = survey_idx
;
9548 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
9550 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
9551 NL80211_WPA_VERSION_2
|
9552 NL80211_WPA_VERSION_3
));
9555 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
9557 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9558 struct net_device
*dev
= info
->user_ptr
[1];
9559 struct ieee80211_channel
*chan
;
9560 const u8
*bssid
, *ssid
, *ie
= NULL
, *auth_data
= NULL
;
9561 int err
, ssid_len
, ie_len
= 0, auth_data_len
= 0;
9562 enum nl80211_auth_type auth_type
;
9563 struct key_parse key
;
9564 bool local_state_change
;
9567 if (!info
->attrs
[NL80211_ATTR_MAC
])
9570 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
9573 if (!info
->attrs
[NL80211_ATTR_SSID
])
9576 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9579 err
= nl80211_parse_key(info
, &key
);
9584 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
9586 if (!key
.p
.key
|| !key
.p
.key_len
)
9588 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
9589 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
9590 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
9591 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
9604 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
9605 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
9614 if (!rdev
->ops
->auth
)
9617 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9618 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9621 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9622 freq
= MHZ_TO_KHZ(nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
9623 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
])
9625 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
]);
9627 chan
= nl80211_get_valid_chan(&rdev
->wiphy
, freq
);
9631 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9632 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9634 if (info
->attrs
[NL80211_ATTR_IE
]) {
9635 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9636 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9639 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
9640 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
9643 if ((auth_type
== NL80211_AUTHTYPE_SAE
||
9644 auth_type
== NL80211_AUTHTYPE_FILS_SK
||
9645 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
9646 auth_type
== NL80211_AUTHTYPE_FILS_PK
) &&
9647 !info
->attrs
[NL80211_ATTR_AUTH_DATA
])
9650 if (info
->attrs
[NL80211_ATTR_AUTH_DATA
]) {
9651 if (auth_type
!= NL80211_AUTHTYPE_SAE
&&
9652 auth_type
!= NL80211_AUTHTYPE_FILS_SK
&&
9653 auth_type
!= NL80211_AUTHTYPE_FILS_SK_PFS
&&
9654 auth_type
!= NL80211_AUTHTYPE_FILS_PK
)
9656 auth_data
= nla_data(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
9657 auth_data_len
= nla_len(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
9660 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
9663 * Since we no longer track auth state, ignore
9664 * requests to only change local state.
9666 if (local_state_change
)
9669 wdev_lock(dev
->ieee80211_ptr
);
9670 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
9671 ssid
, ssid_len
, ie
, ie_len
,
9672 key
.p
.key
, key
.p
.key_len
, key
.idx
,
9673 auth_data
, auth_data_len
);
9674 wdev_unlock(dev
->ieee80211_ptr
);
9678 static int validate_pae_over_nl80211(struct cfg80211_registered_device
*rdev
,
9679 struct genl_info
*info
)
9681 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9682 GENL_SET_ERR_MSG(info
, "SOCKET_OWNER not set");
9686 if (!rdev
->ops
->tx_control_port
||
9687 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9688 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
9694 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
9695 struct genl_info
*info
,
9696 struct cfg80211_crypto_settings
*settings
,
9699 memset(settings
, 0, sizeof(*settings
));
9701 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
9703 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
9706 proto
= nla_get_u16(
9707 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
9708 settings
->control_port_ethertype
= cpu_to_be16(proto
);
9709 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
9712 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
9713 settings
->control_port_no_encrypt
= true;
9715 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
9717 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
9718 int r
= validate_pae_over_nl80211(rdev
, info
);
9723 settings
->control_port_over_nl80211
= true;
9725 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH
])
9726 settings
->control_port_no_preauth
= true;
9729 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
9733 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
9734 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
9735 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
9737 if (len
% sizeof(u32
))
9740 if (settings
->n_ciphers_pairwise
> cipher_limit
)
9743 memcpy(settings
->ciphers_pairwise
, data
, len
);
9745 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
9746 if (!cfg80211_supported_cipher_suite(
9748 settings
->ciphers_pairwise
[i
]))
9752 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
9753 settings
->cipher_group
=
9754 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
9755 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
9756 settings
->cipher_group
))
9760 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
9761 settings
->wpa_versions
=
9762 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
9763 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
9767 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
9771 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
9772 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
9773 settings
->n_akm_suites
= len
/ sizeof(u32
);
9775 if (len
% sizeof(u32
))
9778 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
9781 memcpy(settings
->akm_suites
, data
, len
);
9784 if (info
->attrs
[NL80211_ATTR_PMK
]) {
9785 if (nla_len(info
->attrs
[NL80211_ATTR_PMK
]) != WLAN_PMK_LEN
)
9787 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
9788 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK
) &&
9789 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9790 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK
))
9792 settings
->psk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
9795 if (info
->attrs
[NL80211_ATTR_SAE_PASSWORD
]) {
9796 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
9797 NL80211_EXT_FEATURE_SAE_OFFLOAD
) &&
9798 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9799 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP
))
9802 nla_data(info
->attrs
[NL80211_ATTR_SAE_PASSWORD
]);
9803 settings
->sae_pwd_len
=
9804 nla_len(info
->attrs
[NL80211_ATTR_SAE_PASSWORD
]);
9807 if (info
->attrs
[NL80211_ATTR_SAE_PWE
])
9809 nla_get_u8(info
->attrs
[NL80211_ATTR_SAE_PWE
]);
9811 settings
->sae_pwe
= NL80211_SAE_PWE_UNSPECIFIED
;
9816 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
9818 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9819 struct net_device
*dev
= info
->user_ptr
[1];
9820 struct ieee80211_channel
*chan
;
9821 struct cfg80211_assoc_request req
= {};
9822 const u8
*bssid
, *ssid
;
9823 int err
, ssid_len
= 0;
9826 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
9827 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
9830 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
9831 !info
->attrs
[NL80211_ATTR_SSID
] ||
9832 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9835 if (!rdev
->ops
->assoc
)
9838 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9839 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9842 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9844 freq
= MHZ_TO_KHZ(nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
9845 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
])
9847 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
]);
9848 chan
= nl80211_get_valid_chan(&rdev
->wiphy
, freq
);
9852 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9853 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9855 if (info
->attrs
[NL80211_ATTR_IE
]) {
9856 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9857 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9860 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
9861 enum nl80211_mfp mfp
=
9862 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
9863 if (mfp
== NL80211_MFP_REQUIRED
)
9865 else if (mfp
!= NL80211_MFP_NO
)
9869 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
9870 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
9872 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
9873 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
9875 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9876 memcpy(&req
.ht_capa_mask
,
9877 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
9878 sizeof(req
.ht_capa_mask
));
9880 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
9881 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9883 memcpy(&req
.ht_capa
,
9884 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
9885 sizeof(req
.ht_capa
));
9888 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
9889 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
9891 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
9892 memcpy(&req
.vht_capa_mask
,
9893 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
9894 sizeof(req
.vht_capa_mask
));
9896 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
9897 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
9899 memcpy(&req
.vht_capa
,
9900 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
9901 sizeof(req
.vht_capa
));
9904 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
9905 if (!((rdev
->wiphy
.features
&
9906 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
9907 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
9908 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9909 NL80211_EXT_FEATURE_RRM
))
9911 req
.flags
|= ASSOC_REQ_USE_RRM
;
9914 if (info
->attrs
[NL80211_ATTR_FILS_KEK
]) {
9915 req
.fils_kek
= nla_data(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
9916 req
.fils_kek_len
= nla_len(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
9917 if (!info
->attrs
[NL80211_ATTR_FILS_NONCES
])
9920 nla_data(info
->attrs
[NL80211_ATTR_FILS_NONCES
]);
9923 if (info
->attrs
[NL80211_ATTR_S1G_CAPABILITY_MASK
]) {
9924 if (!info
->attrs
[NL80211_ATTR_S1G_CAPABILITY
])
9926 memcpy(&req
.s1g_capa_mask
,
9927 nla_data(info
->attrs
[NL80211_ATTR_S1G_CAPABILITY_MASK
]),
9928 sizeof(req
.s1g_capa_mask
));
9931 if (info
->attrs
[NL80211_ATTR_S1G_CAPABILITY
]) {
9932 if (!info
->attrs
[NL80211_ATTR_S1G_CAPABILITY_MASK
])
9934 memcpy(&req
.s1g_capa
,
9935 nla_data(info
->attrs
[NL80211_ATTR_S1G_CAPABILITY
]),
9936 sizeof(req
.s1g_capa
));
9939 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
9941 wdev_lock(dev
->ieee80211_ptr
);
9943 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
9944 ssid
, ssid_len
, &req
);
9946 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9947 dev
->ieee80211_ptr
->conn_owner_nlportid
=
9949 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
9953 wdev_unlock(dev
->ieee80211_ptr
);
9959 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
9961 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9962 struct net_device
*dev
= info
->user_ptr
[1];
9963 const u8
*ie
= NULL
, *bssid
;
9964 int ie_len
= 0, err
;
9966 bool local_state_change
;
9968 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
9969 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
9972 if (!info
->attrs
[NL80211_ATTR_MAC
])
9975 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
9978 if (!rdev
->ops
->deauth
)
9981 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9982 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9985 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9987 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
9988 if (reason_code
== 0) {
9989 /* Reason Code 0 is reserved */
9993 if (info
->attrs
[NL80211_ATTR_IE
]) {
9994 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9995 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9998 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
10000 wdev_lock(dev
->ieee80211_ptr
);
10001 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
10002 local_state_change
);
10003 wdev_unlock(dev
->ieee80211_ptr
);
10007 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
10009 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10010 struct net_device
*dev
= info
->user_ptr
[1];
10011 const u8
*ie
= NULL
, *bssid
;
10012 int ie_len
= 0, err
;
10014 bool local_state_change
;
10016 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
10017 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
10020 if (!info
->attrs
[NL80211_ATTR_MAC
])
10023 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
10026 if (!rdev
->ops
->disassoc
)
10027 return -EOPNOTSUPP
;
10029 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10030 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10031 return -EOPNOTSUPP
;
10033 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10035 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
10036 if (reason_code
== 0) {
10037 /* Reason Code 0 is reserved */
10041 if (info
->attrs
[NL80211_ATTR_IE
]) {
10042 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10043 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10046 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
10048 wdev_lock(dev
->ieee80211_ptr
);
10049 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
10050 local_state_change
);
10051 wdev_unlock(dev
->ieee80211_ptr
);
10056 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
10057 int mcast_rate
[NUM_NL80211_BANDS
],
10060 struct wiphy
*wiphy
= &rdev
->wiphy
;
10061 bool found
= false;
10064 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
10065 struct ieee80211_supported_band
*sband
;
10067 sband
= wiphy
->bands
[band
];
10071 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
10072 if (sband
->bitrates
[i
].bitrate
== rateval
) {
10073 mcast_rate
[band
] = i
+ 1;
10083 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
10085 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10086 struct net_device
*dev
= info
->user_ptr
[1];
10087 struct cfg80211_ibss_params ibss
;
10088 struct wiphy
*wiphy
;
10089 struct cfg80211_cached_keys
*connkeys
= NULL
;
10092 memset(&ibss
, 0, sizeof(ibss
));
10094 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
10095 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
10098 ibss
.beacon_interval
= 100;
10100 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
])
10101 ibss
.beacon_interval
=
10102 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
10104 err
= cfg80211_validate_beacon_int(rdev
, NL80211_IFTYPE_ADHOC
,
10105 ibss
.beacon_interval
);
10109 if (!rdev
->ops
->join_ibss
)
10110 return -EOPNOTSUPP
;
10112 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
10113 return -EOPNOTSUPP
;
10115 wiphy
= &rdev
->wiphy
;
10117 if (info
->attrs
[NL80211_ATTR_MAC
]) {
10118 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10120 if (!is_valid_ether_addr(ibss
.bssid
))
10123 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
10124 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
10126 if (info
->attrs
[NL80211_ATTR_IE
]) {
10127 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10128 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10131 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
10135 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
10136 NL80211_IFTYPE_ADHOC
))
10139 switch (ibss
.chandef
.width
) {
10140 case NL80211_CHAN_WIDTH_5
:
10141 case NL80211_CHAN_WIDTH_10
:
10142 case NL80211_CHAN_WIDTH_20_NOHT
:
10144 case NL80211_CHAN_WIDTH_20
:
10145 case NL80211_CHAN_WIDTH_40
:
10146 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
10149 case NL80211_CHAN_WIDTH_80
:
10150 case NL80211_CHAN_WIDTH_80P80
:
10151 case NL80211_CHAN_WIDTH_160
:
10152 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
10154 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
10155 NL80211_EXT_FEATURE_VHT_IBSS
))
10162 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
10163 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
10165 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
10167 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10169 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10170 struct ieee80211_supported_band
*sband
=
10171 wiphy
->bands
[ibss
.chandef
.chan
->band
];
10173 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
10174 &ibss
.basic_rates
);
10179 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
10180 memcpy(&ibss
.ht_capa_mask
,
10181 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
10182 sizeof(ibss
.ht_capa_mask
));
10184 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
10185 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
10187 memcpy(&ibss
.ht_capa
,
10188 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
10189 sizeof(ibss
.ht_capa
));
10192 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
10193 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
10194 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
10197 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
10198 bool no_ht
= false;
10200 connkeys
= nl80211_parse_connkeys(rdev
, info
, &no_ht
);
10201 if (IS_ERR(connkeys
))
10202 return PTR_ERR(connkeys
);
10204 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
10206 kfree_sensitive(connkeys
);
10211 ibss
.control_port
=
10212 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
10214 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
10215 int r
= validate_pae_over_nl80211(rdev
, info
);
10218 kfree_sensitive(connkeys
);
10222 ibss
.control_port_over_nl80211
= true;
10225 ibss
.userspace_handles_dfs
=
10226 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
10228 wdev_lock(dev
->ieee80211_ptr
);
10229 err
= __cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
10231 kfree_sensitive(connkeys
);
10232 else if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
10233 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
10234 wdev_unlock(dev
->ieee80211_ptr
);
10239 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
10241 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10242 struct net_device
*dev
= info
->user_ptr
[1];
10244 if (!rdev
->ops
->leave_ibss
)
10245 return -EOPNOTSUPP
;
10247 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
10248 return -EOPNOTSUPP
;
10250 return cfg80211_leave_ibss(rdev
, dev
, false);
10253 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
10255 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10256 struct net_device
*dev
= info
->user_ptr
[1];
10257 int mcast_rate
[NUM_NL80211_BANDS
];
10261 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
10262 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
10263 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
10264 return -EOPNOTSUPP
;
10266 if (!rdev
->ops
->set_mcast_rate
)
10267 return -EOPNOTSUPP
;
10269 memset(mcast_rate
, 0, sizeof(mcast_rate
));
10271 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
10274 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
10275 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
10278 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
10283 static struct sk_buff
*
10284 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
10285 struct wireless_dev
*wdev
, int approxlen
,
10286 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
10287 enum nl80211_attrs attr
,
10288 const struct nl80211_vendor_cmd_info
*info
,
10291 struct sk_buff
*skb
;
10293 struct nlattr
*data
;
10295 skb
= nlmsg_new(approxlen
+ 100, gfp
);
10299 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
10305 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10306 goto nla_put_failure
;
10309 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
10311 goto nla_put_failure
;
10312 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
10314 goto nla_put_failure
;
10318 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
10319 wdev_id(wdev
), NL80211_ATTR_PAD
))
10320 goto nla_put_failure
;
10321 if (wdev
->netdev
&&
10322 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
10323 wdev
->netdev
->ifindex
))
10324 goto nla_put_failure
;
10327 data
= nla_nest_start_noflag(skb
, attr
);
10329 goto nla_put_failure
;
10331 ((void **)skb
->cb
)[0] = rdev
;
10332 ((void **)skb
->cb
)[1] = hdr
;
10333 ((void **)skb
->cb
)[2] = data
;
10342 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
10343 struct wireless_dev
*wdev
,
10344 enum nl80211_commands cmd
,
10345 enum nl80211_attrs attr
,
10346 unsigned int portid
,
10347 int vendor_event_idx
,
10348 int approxlen
, gfp_t gfp
)
10350 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10351 const struct nl80211_vendor_cmd_info
*info
;
10354 case NL80211_CMD_TESTMODE
:
10355 if (WARN_ON(vendor_event_idx
!= -1))
10359 case NL80211_CMD_VENDOR
:
10360 if (WARN_ON(vendor_event_idx
< 0 ||
10361 vendor_event_idx
>= wiphy
->n_vendor_events
))
10363 info
= &wiphy
->vendor_events
[vendor_event_idx
];
10370 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, portid
, 0,
10371 cmd
, attr
, info
, gfp
);
10373 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
10375 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
10377 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
10378 void *hdr
= ((void **)skb
->cb
)[1];
10379 struct nlmsghdr
*nlhdr
= nlmsg_hdr(skb
);
10380 struct nlattr
*data
= ((void **)skb
->cb
)[2];
10381 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
10383 /* clear CB data for netlink core to own from now on */
10384 memset(skb
->cb
, 0, sizeof(skb
->cb
));
10386 nla_nest_end(skb
, data
);
10387 genlmsg_end(skb
, hdr
);
10389 if (nlhdr
->nlmsg_pid
) {
10390 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), skb
,
10393 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
10394 mcgrp
= NL80211_MCGRP_VENDOR
;
10396 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
10397 skb
, 0, mcgrp
, gfp
);
10400 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
10402 #ifdef CONFIG_NL80211_TESTMODE
10403 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
10405 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10406 struct wireless_dev
*wdev
=
10407 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
10410 if (!rdev
->ops
->testmode_cmd
)
10411 return -EOPNOTSUPP
;
10413 if (IS_ERR(wdev
)) {
10414 err
= PTR_ERR(wdev
);
10415 if (err
!= -EINVAL
)
10418 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
10422 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
10425 rdev
->cur_cmd_info
= info
;
10426 err
= rdev_testmode_cmd(rdev
, wdev
,
10427 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
10428 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
10429 rdev
->cur_cmd_info
= NULL
;
10434 static int nl80211_testmode_dump(struct sk_buff
*skb
,
10435 struct netlink_callback
*cb
)
10437 struct cfg80211_registered_device
*rdev
;
10438 struct nlattr
**attrbuf
= NULL
;
10448 * 0 is a valid index, but not valid for args[0],
10449 * so we need to offset by 1.
10451 phy_idx
= cb
->args
[0] - 1;
10453 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
10459 attrbuf
= kcalloc(NUM_NL80211_ATTR
, sizeof(*attrbuf
),
10466 err
= nlmsg_parse_deprecated(cb
->nlh
,
10467 GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
10468 attrbuf
, nl80211_fam
.maxattr
,
10469 nl80211_policy
, NULL
);
10473 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
10474 if (IS_ERR(rdev
)) {
10475 err
= PTR_ERR(rdev
);
10478 phy_idx
= rdev
->wiphy_idx
;
10480 if (attrbuf
[NL80211_ATTR_TESTDATA
])
10481 cb
->args
[1] = (long)attrbuf
[NL80211_ATTR_TESTDATA
];
10485 data
= nla_data((void *)cb
->args
[1]);
10486 data_len
= nla_len((void *)cb
->args
[1]);
10489 if (!rdev
->ops
->testmode_dump
) {
10495 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
10496 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
10497 NL80211_CMD_TESTMODE
);
10498 struct nlattr
*tmdata
;
10503 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
10504 genlmsg_cancel(skb
, hdr
);
10508 tmdata
= nla_nest_start_noflag(skb
, NL80211_ATTR_TESTDATA
);
10510 genlmsg_cancel(skb
, hdr
);
10513 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
10514 nla_nest_end(skb
, tmdata
);
10516 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
10517 genlmsg_cancel(skb
, hdr
);
10520 genlmsg_cancel(skb
, hdr
);
10524 genlmsg_end(skb
, hdr
);
10529 cb
->args
[0] = phy_idx
+ 1;
10537 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
10539 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10540 struct net_device
*dev
= info
->user_ptr
[1];
10541 struct cfg80211_connect_params connect
;
10542 struct wiphy
*wiphy
;
10543 struct cfg80211_cached_keys
*connkeys
= NULL
;
10547 memset(&connect
, 0, sizeof(connect
));
10549 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
10550 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
10553 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
10554 connect
.auth_type
=
10555 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
10556 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
10557 NL80211_CMD_CONNECT
))
10560 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
10562 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
10564 if (info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
] &&
10565 !wiphy_ext_feature_isset(&rdev
->wiphy
,
10566 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
10568 connect
.want_1x
= info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
];
10570 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
10571 NL80211_MAX_NR_CIPHER_SUITES
);
10575 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10576 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10577 return -EOPNOTSUPP
;
10579 wiphy
= &rdev
->wiphy
;
10581 connect
.bg_scan_period
= -1;
10582 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
10583 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
10584 connect
.bg_scan_period
=
10585 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
10588 if (info
->attrs
[NL80211_ATTR_MAC
])
10589 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10590 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
10591 connect
.bssid_hint
=
10592 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
10593 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
10594 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
10596 if (info
->attrs
[NL80211_ATTR_IE
]) {
10597 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10598 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10601 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
10602 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
10603 if (connect
.mfp
== NL80211_MFP_OPTIONAL
&&
10604 !wiphy_ext_feature_isset(&rdev
->wiphy
,
10605 NL80211_EXT_FEATURE_MFP_OPTIONAL
))
10606 return -EOPNOTSUPP
;
10608 connect
.mfp
= NL80211_MFP_NO
;
10611 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
10612 connect
.prev_bssid
=
10613 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
10615 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
10616 freq
= MHZ_TO_KHZ(nla_get_u32(
10617 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
10618 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
])
10620 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_OFFSET
]);
10623 connect
.channel
= nl80211_get_valid_chan(wiphy
, freq
);
10624 if (!connect
.channel
)
10626 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
10627 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
10628 freq
= MHZ_TO_KHZ(freq
);
10629 connect
.channel_hint
= nl80211_get_valid_chan(wiphy
, freq
);
10630 if (!connect
.channel_hint
)
10634 if (info
->attrs
[NL80211_ATTR_WIPHY_EDMG_CHANNELS
]) {
10635 connect
.edmg
.channels
=
10636 nla_get_u8(info
->attrs
[NL80211_ATTR_WIPHY_EDMG_CHANNELS
]);
10638 if (info
->attrs
[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
])
10639 connect
.edmg
.bw_config
=
10640 nla_get_u8(info
->attrs
[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
]);
10643 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
10644 connkeys
= nl80211_parse_connkeys(rdev
, info
, NULL
);
10645 if (IS_ERR(connkeys
))
10646 return PTR_ERR(connkeys
);
10649 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
10650 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
10652 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
10653 memcpy(&connect
.ht_capa_mask
,
10654 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
10655 sizeof(connect
.ht_capa_mask
));
10657 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
10658 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
10659 kfree_sensitive(connkeys
);
10662 memcpy(&connect
.ht_capa
,
10663 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
10664 sizeof(connect
.ht_capa
));
10667 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
10668 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
10670 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
10671 memcpy(&connect
.vht_capa_mask
,
10672 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
10673 sizeof(connect
.vht_capa_mask
));
10675 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
10676 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
10677 kfree_sensitive(connkeys
);
10680 memcpy(&connect
.vht_capa
,
10681 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
10682 sizeof(connect
.vht_capa
));
10685 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
10686 if (!((rdev
->wiphy
.features
&
10687 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
10688 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
10689 !wiphy_ext_feature_isset(&rdev
->wiphy
,
10690 NL80211_EXT_FEATURE_RRM
)) {
10691 kfree_sensitive(connkeys
);
10694 connect
.flags
|= ASSOC_REQ_USE_RRM
;
10697 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
10698 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
10699 kfree_sensitive(connkeys
);
10700 return -EOPNOTSUPP
;
10703 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
10704 /* bss selection makes no sense if bssid is set */
10705 if (connect
.bssid
) {
10706 kfree_sensitive(connkeys
);
10710 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
10711 wiphy
, &connect
.bss_select
);
10713 kfree_sensitive(connkeys
);
10718 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
10719 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
10720 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
10721 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
10722 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
10723 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10724 connect
.fils_erp_username
=
10725 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10726 connect
.fils_erp_username_len
=
10727 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10728 connect
.fils_erp_realm
=
10729 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10730 connect
.fils_erp_realm_len
=
10731 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10732 connect
.fils_erp_next_seq_num
=
10734 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
10735 connect
.fils_erp_rrk
=
10736 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10737 connect
.fils_erp_rrk_len
=
10738 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10739 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
10740 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
10741 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
10742 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10743 kfree_sensitive(connkeys
);
10747 if (nla_get_flag(info
->attrs
[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
])) {
10748 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
10749 kfree_sensitive(connkeys
);
10750 GENL_SET_ERR_MSG(info
,
10751 "external auth requires connection ownership");
10754 connect
.flags
|= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT
;
10757 wdev_lock(dev
->ieee80211_ptr
);
10759 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
10760 connect
.prev_bssid
);
10762 kfree_sensitive(connkeys
);
10764 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
10765 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
10767 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
10768 connect
.bssid
, ETH_ALEN
);
10770 eth_zero_addr(dev
->ieee80211_ptr
->disconnect_bssid
);
10773 wdev_unlock(dev
->ieee80211_ptr
);
10778 static int nl80211_update_connect_params(struct sk_buff
*skb
,
10779 struct genl_info
*info
)
10781 struct cfg80211_connect_params connect
= {};
10782 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10783 struct net_device
*dev
= info
->user_ptr
[1];
10784 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10785 bool fils_sk_offload
;
10790 if (!rdev
->ops
->update_connect_params
)
10791 return -EOPNOTSUPP
;
10793 if (info
->attrs
[NL80211_ATTR_IE
]) {
10794 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10795 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10796 changed
|= UPDATE_ASSOC_IES
;
10799 fils_sk_offload
= wiphy_ext_feature_isset(&rdev
->wiphy
,
10800 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
);
10803 * when driver supports fils-sk offload all attributes must be
10804 * provided. So the else covers "fils-sk-not-all" and
10805 * "no-fils-sk-any".
10807 if (fils_sk_offload
&&
10808 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
10809 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
10810 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
10811 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10812 connect
.fils_erp_username
=
10813 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10814 connect
.fils_erp_username_len
=
10815 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
10816 connect
.fils_erp_realm
=
10817 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10818 connect
.fils_erp_realm_len
=
10819 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
10820 connect
.fils_erp_next_seq_num
=
10822 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
10823 connect
.fils_erp_rrk
=
10824 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10825 connect
.fils_erp_rrk_len
=
10826 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
10827 changed
|= UPDATE_FILS_ERP_INFO
;
10828 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
10829 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
10830 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
10831 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
10835 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
10836 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
10837 if (!nl80211_valid_auth_type(rdev
, auth_type
,
10838 NL80211_CMD_CONNECT
))
10841 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
&&
10842 fils_sk_offload
&& !(changed
& UPDATE_FILS_ERP_INFO
))
10845 connect
.auth_type
= auth_type
;
10846 changed
|= UPDATE_AUTH_TYPE
;
10849 wdev_lock(dev
->ieee80211_ptr
);
10850 if (!wdev
->current_bss
)
10853 ret
= rdev_update_connect_params(rdev
, dev
, &connect
, changed
);
10854 wdev_unlock(dev
->ieee80211_ptr
);
10859 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
10861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10862 struct net_device
*dev
= info
->user_ptr
[1];
10866 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
10867 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
10870 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
10871 reason
= WLAN_REASON_DEAUTH_LEAVING
;
10873 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
10878 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10879 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10880 return -EOPNOTSUPP
;
10882 wdev_lock(dev
->ieee80211_ptr
);
10883 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
10884 wdev_unlock(dev
->ieee80211_ptr
);
10888 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
10890 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10894 if (info
->attrs
[NL80211_ATTR_PID
]) {
10895 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
10897 net
= get_net_ns_by_pid(pid
);
10898 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
10899 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
10901 net
= get_net_ns_by_fd(fd
);
10907 return PTR_ERR(net
);
10911 /* check if anything to do */
10912 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
10913 err
= cfg80211_switch_netns(rdev
, net
);
10919 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
10921 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10922 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
10923 struct cfg80211_pmksa
*pmksa
) = NULL
;
10924 struct net_device
*dev
= info
->user_ptr
[1];
10925 struct cfg80211_pmksa pmksa
;
10927 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
10929 if (!info
->attrs
[NL80211_ATTR_PMKID
])
10932 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
10934 if (info
->attrs
[NL80211_ATTR_MAC
]) {
10935 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10936 } else if (info
->attrs
[NL80211_ATTR_SSID
] &&
10937 info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
] &&
10938 (info
->genlhdr
->cmd
== NL80211_CMD_DEL_PMKSA
||
10939 info
->attrs
[NL80211_ATTR_PMK
])) {
10940 pmksa
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
10941 pmksa
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
10943 nla_data(info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
]);
10947 if (info
->attrs
[NL80211_ATTR_PMK
]) {
10948 pmksa
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
10949 pmksa
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
10952 if (info
->attrs
[NL80211_ATTR_PMK_LIFETIME
])
10953 pmksa
.pmk_lifetime
=
10954 nla_get_u32(info
->attrs
[NL80211_ATTR_PMK_LIFETIME
]);
10956 if (info
->attrs
[NL80211_ATTR_PMK_REAUTH_THRESHOLD
])
10957 pmksa
.pmk_reauth_threshold
=
10959 info
->attrs
[NL80211_ATTR_PMK_REAUTH_THRESHOLD
]);
10961 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10962 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
10963 !(dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_AP
&&
10964 wiphy_ext_feature_isset(&rdev
->wiphy
,
10965 NL80211_EXT_FEATURE_AP_PMKSA_CACHING
)))
10966 return -EOPNOTSUPP
;
10968 switch (info
->genlhdr
->cmd
) {
10969 case NL80211_CMD_SET_PMKSA
:
10970 rdev_ops
= rdev
->ops
->set_pmksa
;
10972 case NL80211_CMD_DEL_PMKSA
:
10973 rdev_ops
= rdev
->ops
->del_pmksa
;
10981 return -EOPNOTSUPP
;
10983 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
10986 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
10988 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10989 struct net_device
*dev
= info
->user_ptr
[1];
10991 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
10992 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10993 return -EOPNOTSUPP
;
10995 if (!rdev
->ops
->flush_pmksa
)
10996 return -EOPNOTSUPP
;
10998 return rdev_flush_pmksa(rdev
, dev
);
11001 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
11003 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11004 struct net_device
*dev
= info
->user_ptr
[1];
11005 u8 action_code
, dialog_token
;
11006 u32 peer_capability
= 0;
11011 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
11012 !rdev
->ops
->tdls_mgmt
)
11013 return -EOPNOTSUPP
;
11015 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
11016 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
11017 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
11018 !info
->attrs
[NL80211_ATTR_IE
] ||
11019 !info
->attrs
[NL80211_ATTR_MAC
])
11022 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11023 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
11024 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
11025 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
11026 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
11027 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
11029 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
11031 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
11032 dialog_token
, status_code
, peer_capability
,
11034 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
11035 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
11038 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
11040 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11041 struct net_device
*dev
= info
->user_ptr
[1];
11042 enum nl80211_tdls_operation operation
;
11045 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
11046 !rdev
->ops
->tdls_oper
)
11047 return -EOPNOTSUPP
;
11049 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
11050 !info
->attrs
[NL80211_ATTR_MAC
])
11053 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
11054 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11056 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
11059 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
11060 struct genl_info
*info
)
11062 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11063 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11064 struct cfg80211_chan_def chandef
;
11065 const struct cfg80211_chan_def
*compat_chandef
;
11066 struct sk_buff
*msg
;
11072 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
11073 !info
->attrs
[NL80211_ATTR_DURATION
])
11076 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
11078 if (!rdev
->ops
->remain_on_channel
||
11079 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
11080 return -EOPNOTSUPP
;
11083 * We should be on that channel for at least a minimum amount of
11084 * time (10ms) but no longer than the driver supports.
11086 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
11087 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
11090 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
11095 if (!cfg80211_off_channel_oper_allowed(wdev
) &&
11096 !cfg80211_chandef_identical(&wdev
->chandef
, &chandef
)) {
11097 compat_chandef
= cfg80211_chandef_compatible(&wdev
->chandef
,
11099 if (compat_chandef
!= &chandef
) {
11106 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11110 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11111 NL80211_CMD_REMAIN_ON_CHANNEL
);
11117 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
11118 duration
, &cookie
);
11123 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11125 goto nla_put_failure
;
11127 genlmsg_end(msg
, hdr
);
11129 return genlmsg_reply(msg
, info
);
11138 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
11139 struct genl_info
*info
)
11141 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11142 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11145 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
11148 if (!rdev
->ops
->cancel_remain_on_channel
)
11149 return -EOPNOTSUPP
;
11151 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
11153 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
11156 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
11157 struct genl_info
*info
)
11159 struct cfg80211_bitrate_mask mask
;
11160 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11161 struct net_device
*dev
= info
->user_ptr
[1];
11164 if (!rdev
->ops
->set_bitrate_mask
)
11165 return -EOPNOTSUPP
;
11167 err
= nl80211_parse_tx_bitrate_mask(info
, info
->attrs
,
11168 NL80211_ATTR_TX_RATES
, &mask
,
11173 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
11176 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
11178 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11179 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11180 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
11182 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
11185 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
11186 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
11188 switch (wdev
->iftype
) {
11189 case NL80211_IFTYPE_STATION
:
11190 case NL80211_IFTYPE_ADHOC
:
11191 case NL80211_IFTYPE_P2P_CLIENT
:
11192 case NL80211_IFTYPE_AP
:
11193 case NL80211_IFTYPE_AP_VLAN
:
11194 case NL80211_IFTYPE_MESH_POINT
:
11195 case NL80211_IFTYPE_P2P_GO
:
11196 case NL80211_IFTYPE_P2P_DEVICE
:
11198 case NL80211_IFTYPE_NAN
:
11200 return -EOPNOTSUPP
;
11203 /* not much point in registering if we can't reply */
11204 if (!rdev
->ops
->mgmt_tx
)
11205 return -EOPNOTSUPP
;
11207 if (info
->attrs
[NL80211_ATTR_RECEIVE_MULTICAST
] &&
11208 !wiphy_ext_feature_isset(&rdev
->wiphy
,
11209 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS
)) {
11210 GENL_SET_ERR_MSG(info
,
11211 "multicast RX registrations are not supported");
11212 return -EOPNOTSUPP
;
11215 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
11216 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
11217 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
11218 info
->attrs
[NL80211_ATTR_RECEIVE_MULTICAST
],
11222 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
11224 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11225 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11226 struct cfg80211_chan_def chandef
;
11230 struct sk_buff
*msg
= NULL
;
11231 struct cfg80211_mgmt_tx_params params
= {
11232 .dont_wait_for_ack
=
11233 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
11236 if (!info
->attrs
[NL80211_ATTR_FRAME
])
11239 if (!rdev
->ops
->mgmt_tx
)
11240 return -EOPNOTSUPP
;
11242 switch (wdev
->iftype
) {
11243 case NL80211_IFTYPE_P2P_DEVICE
:
11244 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
11247 case NL80211_IFTYPE_STATION
:
11248 case NL80211_IFTYPE_ADHOC
:
11249 case NL80211_IFTYPE_P2P_CLIENT
:
11250 case NL80211_IFTYPE_AP
:
11251 case NL80211_IFTYPE_AP_VLAN
:
11252 case NL80211_IFTYPE_MESH_POINT
:
11253 case NL80211_IFTYPE_P2P_GO
:
11255 case NL80211_IFTYPE_NAN
:
11257 return -EOPNOTSUPP
;
11260 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
11261 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
11263 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
11266 * We should wait on the channel for at least a minimum amount
11267 * of time (10ms) but no longer than the driver supports.
11269 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
11270 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
11274 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
11276 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
11279 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
11281 /* get the channel if any has been specified, otherwise pass NULL to
11282 * the driver. The latter will use the current one
11284 chandef
.chan
= NULL
;
11285 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
11286 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
11291 if (!chandef
.chan
&& params
.offchan
)
11295 if (params
.offchan
&& !cfg80211_off_channel_oper_allowed(wdev
)) {
11301 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
11302 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
11304 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
11305 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
11308 if (len
% sizeof(u16
))
11311 params
.n_csa_offsets
= len
/ sizeof(u16
);
11312 params
.csa_offsets
=
11313 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
11315 /* check that all the offsets fit the frame */
11316 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
11317 if (params
.csa_offsets
[i
] >= params
.len
)
11322 if (!params
.dont_wait_for_ack
) {
11323 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11327 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11328 NL80211_CMD_FRAME
);
11335 params
.chan
= chandef
.chan
;
11336 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
11341 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11343 goto nla_put_failure
;
11345 genlmsg_end(msg
, hdr
);
11346 return genlmsg_reply(msg
, info
);
11358 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
11360 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11361 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11364 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
11367 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
11368 return -EOPNOTSUPP
;
11370 switch (wdev
->iftype
) {
11371 case NL80211_IFTYPE_STATION
:
11372 case NL80211_IFTYPE_ADHOC
:
11373 case NL80211_IFTYPE_P2P_CLIENT
:
11374 case NL80211_IFTYPE_AP
:
11375 case NL80211_IFTYPE_AP_VLAN
:
11376 case NL80211_IFTYPE_P2P_GO
:
11377 case NL80211_IFTYPE_P2P_DEVICE
:
11379 case NL80211_IFTYPE_NAN
:
11381 return -EOPNOTSUPP
;
11384 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
11386 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
11389 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
11391 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11392 struct wireless_dev
*wdev
;
11393 struct net_device
*dev
= info
->user_ptr
[1];
11398 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
11401 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
11403 wdev
= dev
->ieee80211_ptr
;
11405 if (!rdev
->ops
->set_power_mgmt
)
11406 return -EOPNOTSUPP
;
11408 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
11410 if (state
== wdev
->ps
)
11413 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
11419 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
11421 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11422 enum nl80211_ps_state ps_state
;
11423 struct wireless_dev
*wdev
;
11424 struct net_device
*dev
= info
->user_ptr
[1];
11425 struct sk_buff
*msg
;
11429 wdev
= dev
->ieee80211_ptr
;
11431 if (!rdev
->ops
->set_power_mgmt
)
11432 return -EOPNOTSUPP
;
11434 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11438 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11439 NL80211_CMD_GET_POWER_SAVE
);
11446 ps_state
= NL80211_PS_ENABLED
;
11448 ps_state
= NL80211_PS_DISABLED
;
11450 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
11451 goto nla_put_failure
;
11453 genlmsg_end(msg
, hdr
);
11454 return genlmsg_reply(msg
, info
);
11463 static const struct nla_policy
11464 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
11465 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_BINARY
},
11466 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
11467 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
11468 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
11469 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
11470 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
11471 [NL80211_ATTR_CQM_RSSI_LEVEL
] = { .type
= NLA_S32
},
11474 static int nl80211_set_cqm_txe(struct genl_info
*info
,
11475 u32 rate
, u32 pkts
, u32 intvl
)
11477 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11478 struct net_device
*dev
= info
->user_ptr
[1];
11479 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11481 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
11484 if (!rdev
->ops
->set_cqm_txe_config
)
11485 return -EOPNOTSUPP
;
11487 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
11488 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
11489 return -EOPNOTSUPP
;
11491 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
11494 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device
*rdev
,
11495 struct net_device
*dev
)
11497 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11498 s32 last
, low
, high
;
11500 int i
, n
, low_index
;
11503 /* RSSI reporting disabled? */
11504 if (!wdev
->cqm_config
)
11505 return rdev_set_cqm_rssi_range_config(rdev
, dev
, 0, 0);
11508 * Obtain current RSSI value if possible, if not and no RSSI threshold
11509 * event has been received yet, we should receive an event after a
11510 * connection is established and enough beacons received to calculate
11513 if (!wdev
->cqm_config
->last_rssi_event_value
&& wdev
->current_bss
&&
11514 rdev
->ops
->get_station
) {
11515 struct station_info sinfo
= {};
11518 mac_addr
= wdev
->current_bss
->pub
.bssid
;
11520 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
11524 cfg80211_sinfo_release_content(&sinfo
);
11525 if (sinfo
.filled
& BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG
))
11526 wdev
->cqm_config
->last_rssi_event_value
=
11527 (s8
) sinfo
.rx_beacon_signal_avg
;
11530 last
= wdev
->cqm_config
->last_rssi_event_value
;
11531 hyst
= wdev
->cqm_config
->rssi_hyst
;
11532 n
= wdev
->cqm_config
->n_rssi_thresholds
;
11534 for (i
= 0; i
< n
; i
++) {
11535 i
= array_index_nospec(i
, n
);
11536 if (last
< wdev
->cqm_config
->rssi_thresholds
[i
])
11541 if (low_index
>= 0) {
11542 low_index
= array_index_nospec(low_index
, n
);
11543 low
= wdev
->cqm_config
->rssi_thresholds
[low_index
] - hyst
;
11548 i
= array_index_nospec(i
, n
);
11549 high
= wdev
->cqm_config
->rssi_thresholds
[i
] + hyst
- 1;
11554 return rdev_set_cqm_rssi_range_config(rdev
, dev
, low
, high
);
11557 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
11558 const s32
*thresholds
, int n_thresholds
,
11561 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11562 struct net_device
*dev
= info
->user_ptr
[1];
11563 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11565 s32 prev
= S32_MIN
;
11567 /* Check all values negative and sorted */
11568 for (i
= 0; i
< n_thresholds
; i
++) {
11569 if (thresholds
[i
] > 0 || thresholds
[i
] <= prev
)
11572 prev
= thresholds
[i
];
11575 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
11576 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
11577 return -EOPNOTSUPP
;
11580 cfg80211_cqm_config_free(wdev
);
11583 if (n_thresholds
<= 1 && rdev
->ops
->set_cqm_rssi_config
) {
11584 if (n_thresholds
== 0 || thresholds
[0] == 0) /* Disabling */
11585 return rdev_set_cqm_rssi_config(rdev
, dev
, 0, 0);
11587 return rdev_set_cqm_rssi_config(rdev
, dev
,
11588 thresholds
[0], hysteresis
);
11591 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
11592 NL80211_EXT_FEATURE_CQM_RSSI_LIST
))
11593 return -EOPNOTSUPP
;
11595 if (n_thresholds
== 1 && thresholds
[0] == 0) /* Disabling */
11599 if (n_thresholds
) {
11600 struct cfg80211_cqm_config
*cqm_config
;
11602 cqm_config
= kzalloc(sizeof(struct cfg80211_cqm_config
) +
11603 n_thresholds
* sizeof(s32
), GFP_KERNEL
);
11609 cqm_config
->rssi_hyst
= hysteresis
;
11610 cqm_config
->n_rssi_thresholds
= n_thresholds
;
11611 memcpy(cqm_config
->rssi_thresholds
, thresholds
,
11612 n_thresholds
* sizeof(s32
));
11614 wdev
->cqm_config
= cqm_config
;
11617 err
= cfg80211_cqm_rssi_update(rdev
, dev
);
11625 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
11627 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
11628 struct nlattr
*cqm
;
11631 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
11635 err
= nla_parse_nested_deprecated(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
11636 nl80211_attr_cqm_policy
,
11641 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
11642 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
11643 const s32
*thresholds
=
11644 nla_data(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
11645 int len
= nla_len(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
11646 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
11651 return nl80211_set_cqm_rssi(info
, thresholds
, len
/ 4,
11655 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
11656 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
11657 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
11658 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
11659 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
11660 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
11662 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
11668 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
11670 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11671 struct net_device
*dev
= info
->user_ptr
[1];
11672 struct ocb_setup setup
= {};
11675 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
11679 return cfg80211_join_ocb(rdev
, dev
, &setup
);
11682 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
11684 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11685 struct net_device
*dev
= info
->user_ptr
[1];
11687 return cfg80211_leave_ocb(rdev
, dev
);
11690 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
11692 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11693 struct net_device
*dev
= info
->user_ptr
[1];
11694 struct mesh_config cfg
;
11695 struct mesh_setup setup
;
11698 /* start with default */
11699 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
11700 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
11702 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
11703 /* and parse parameters if given */
11704 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
11709 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
11710 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
11713 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
11714 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
11716 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
11717 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
11718 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
11721 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
11722 setup
.beacon_interval
=
11723 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
11725 err
= cfg80211_validate_beacon_int(rdev
,
11726 NL80211_IFTYPE_MESH_POINT
,
11727 setup
.beacon_interval
);
11732 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
11733 setup
.dtim_period
=
11734 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
11735 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
11739 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
11740 /* parse additional setup parameters if given */
11741 err
= nl80211_parse_mesh_setup(info
, &setup
);
11746 if (setup
.user_mpm
)
11747 cfg
.auto_open_plinks
= false;
11749 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
11750 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
11754 /* __cfg80211_join_mesh() will sort it out */
11755 setup
.chandef
.chan
= NULL
;
11758 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
11759 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
11761 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
11762 struct ieee80211_supported_band
*sband
;
11764 if (!setup
.chandef
.chan
)
11767 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
11769 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
11770 &setup
.basic_rates
);
11775 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
11776 err
= nl80211_parse_tx_bitrate_mask(info
, info
->attrs
,
11777 NL80211_ATTR_TX_RATES
,
11778 &setup
.beacon_rate
,
11783 if (!setup
.chandef
.chan
)
11786 err
= validate_beacon_tx_rate(rdev
, setup
.chandef
.chan
->band
,
11787 &setup
.beacon_rate
);
11792 setup
.userspace_handles_dfs
=
11793 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
11795 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
11796 int r
= validate_pae_over_nl80211(rdev
, info
);
11801 setup
.control_port_over_nl80211
= true;
11804 wdev_lock(dev
->ieee80211_ptr
);
11805 err
= __cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
11806 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
11807 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
11808 wdev_unlock(dev
->ieee80211_ptr
);
11813 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
11815 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11816 struct net_device
*dev
= info
->user_ptr
[1];
11818 return cfg80211_leave_mesh(rdev
, dev
);
11822 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
11823 struct cfg80211_registered_device
*rdev
)
11825 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
11826 struct nlattr
*nl_pats
, *nl_pat
;
11829 if (!wowlan
->n_patterns
)
11832 nl_pats
= nla_nest_start_noflag(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
11836 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
11837 nl_pat
= nla_nest_start_noflag(msg
, i
+ 1);
11840 pat_len
= wowlan
->patterns
[i
].pattern_len
;
11841 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
11842 wowlan
->patterns
[i
].mask
) ||
11843 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
11844 wowlan
->patterns
[i
].pattern
) ||
11845 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
11846 wowlan
->patterns
[i
].pkt_offset
))
11848 nla_nest_end(msg
, nl_pat
);
11850 nla_nest_end(msg
, nl_pats
);
11855 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
11856 struct cfg80211_wowlan_tcp
*tcp
)
11858 struct nlattr
*nl_tcp
;
11863 nl_tcp
= nla_nest_start_noflag(msg
,
11864 NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
11868 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
11869 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
11870 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
11871 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
11872 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
11873 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
11874 tcp
->payload_len
, tcp
->payload
) ||
11875 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
11876 tcp
->data_interval
) ||
11877 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
11878 tcp
->wake_len
, tcp
->wake_data
) ||
11879 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
11880 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
11883 if (tcp
->payload_seq
.len
&&
11884 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
11885 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
11888 if (tcp
->payload_tok
.len
&&
11889 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
11890 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
11891 &tcp
->payload_tok
))
11894 nla_nest_end(msg
, nl_tcp
);
11899 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
11900 struct cfg80211_sched_scan_request
*req
)
11902 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
11908 nd
= nla_nest_start_noflag(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
11912 if (req
->n_scan_plans
== 1 &&
11913 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
11914 req
->scan_plans
[0].interval
* 1000))
11917 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
11920 if (req
->relative_rssi_set
) {
11921 struct nl80211_bss_select_rssi_adjust rssi_adjust
;
11923 if (nla_put_s8(msg
, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
,
11924 req
->relative_rssi
))
11927 rssi_adjust
.band
= req
->rssi_adjust
.band
;
11928 rssi_adjust
.delta
= req
->rssi_adjust
.delta
;
11929 if (nla_put(msg
, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
,
11930 sizeof(rssi_adjust
), &rssi_adjust
))
11934 freqs
= nla_nest_start_noflag(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
11938 for (i
= 0; i
< req
->n_channels
; i
++) {
11939 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
11943 nla_nest_end(msg
, freqs
);
11945 if (req
->n_match_sets
) {
11946 matches
= nla_nest_start_noflag(msg
,
11947 NL80211_ATTR_SCHED_SCAN_MATCH
);
11951 for (i
= 0; i
< req
->n_match_sets
; i
++) {
11952 match
= nla_nest_start_noflag(msg
, i
);
11956 if (nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
11957 req
->match_sets
[i
].ssid
.ssid_len
,
11958 req
->match_sets
[i
].ssid
.ssid
))
11960 nla_nest_end(msg
, match
);
11962 nla_nest_end(msg
, matches
);
11965 scan_plans
= nla_nest_start_noflag(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
11969 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
11970 scan_plan
= nla_nest_start_noflag(msg
, i
+ 1);
11974 if (nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
11975 req
->scan_plans
[i
].interval
) ||
11976 (req
->scan_plans
[i
].iterations
&&
11977 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
11978 req
->scan_plans
[i
].iterations
)))
11980 nla_nest_end(msg
, scan_plan
);
11982 nla_nest_end(msg
, scan_plans
);
11984 nla_nest_end(msg
, nd
);
11989 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
11991 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11992 struct sk_buff
*msg
;
11994 u32 size
= NLMSG_DEFAULT_SIZE
;
11996 if (!rdev
->wiphy
.wowlan
)
11997 return -EOPNOTSUPP
;
11999 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
12000 /* adjust size to have room for all the data */
12001 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
12002 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
12003 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
12004 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
12007 msg
= nlmsg_new(size
, GFP_KERNEL
);
12011 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12012 NL80211_CMD_GET_WOWLAN
);
12014 goto nla_put_failure
;
12016 if (rdev
->wiphy
.wowlan_config
) {
12017 struct nlattr
*nl_wowlan
;
12019 nl_wowlan
= nla_nest_start_noflag(msg
,
12020 NL80211_ATTR_WOWLAN_TRIGGERS
);
12022 goto nla_put_failure
;
12024 if ((rdev
->wiphy
.wowlan_config
->any
&&
12025 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
12026 (rdev
->wiphy
.wowlan_config
->disconnect
&&
12027 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
12028 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
12029 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
12030 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
12031 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
12032 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
12033 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
12034 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
12035 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
12036 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
12037 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
12038 goto nla_put_failure
;
12040 if (nl80211_send_wowlan_patterns(msg
, rdev
))
12041 goto nla_put_failure
;
12043 if (nl80211_send_wowlan_tcp(msg
,
12044 rdev
->wiphy
.wowlan_config
->tcp
))
12045 goto nla_put_failure
;
12047 if (nl80211_send_wowlan_nd(
12049 rdev
->wiphy
.wowlan_config
->nd_config
))
12050 goto nla_put_failure
;
12052 nla_nest_end(msg
, nl_wowlan
);
12055 genlmsg_end(msg
, hdr
);
12056 return genlmsg_reply(msg
, info
);
12063 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
12064 struct nlattr
*attr
,
12065 struct cfg80211_wowlan
*trig
)
12067 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
12068 struct cfg80211_wowlan_tcp
*cfg
;
12069 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
12070 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
12072 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
12075 if (!rdev
->wiphy
.wowlan
->tcp
)
12078 err
= nla_parse_nested_deprecated(tb
, MAX_NL80211_WOWLAN_TCP
, attr
,
12079 nl80211_wowlan_tcp_policy
, NULL
);
12083 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
12084 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
12085 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
12086 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
12087 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
12088 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
12089 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
12090 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
12093 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
12094 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
12097 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
12098 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
12099 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
12102 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
12103 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
12106 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
12107 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
12110 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
12111 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
12113 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
12114 tokens_size
= tokln
- sizeof(*tok
);
12116 if (!tok
->len
|| tokens_size
% tok
->len
)
12118 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
12120 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
12122 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
12124 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
12126 if (tok
->offset
+ tok
->len
> data_size
)
12130 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
12131 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
12132 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
12134 if (seq
->len
== 0 || seq
->len
> 4)
12136 if (seq
->len
+ seq
->offset
> data_size
)
12140 size
= sizeof(*cfg
);
12142 size
+= wake_size
+ wake_mask_size
;
12143 size
+= tokens_size
;
12145 cfg
= kzalloc(size
, GFP_KERNEL
);
12148 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
12149 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
12150 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
12152 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
12153 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
12157 /* allocate a socket and port for it and use it */
12158 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
12159 IPPROTO_TCP
, &cfg
->sock
, 1);
12164 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
12165 sock_release(cfg
->sock
);
12167 return -EADDRINUSE
;
12169 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
12175 cfg
->src_port
= port
;
12178 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
12179 cfg
->payload_len
= data_size
;
12180 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
12181 memcpy((void *)cfg
->payload
,
12182 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
12185 cfg
->payload_seq
= *seq
;
12186 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
12187 cfg
->wake_len
= wake_size
;
12188 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
12189 memcpy((void *)cfg
->wake_data
,
12190 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
12192 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
12193 data_size
+ wake_size
;
12194 memcpy((void *)cfg
->wake_mask
,
12195 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
12198 cfg
->tokens_size
= tokens_size
;
12199 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
12207 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
12208 const struct wiphy_wowlan_support
*wowlan
,
12209 struct nlattr
*attr
,
12210 struct cfg80211_wowlan
*trig
)
12212 struct nlattr
**tb
;
12215 tb
= kcalloc(NUM_NL80211_ATTR
, sizeof(*tb
), GFP_KERNEL
);
12219 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
12224 err
= nla_parse_nested_deprecated(tb
, NL80211_ATTR_MAX
, attr
,
12225 nl80211_policy
, NULL
);
12229 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
,
12230 wowlan
->max_nd_match_sets
);
12231 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
12233 trig
->nd_config
= NULL
;
12240 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
12242 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12243 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
12244 struct cfg80211_wowlan new_triggers
= {};
12245 struct cfg80211_wowlan
*ntrig
;
12246 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
12248 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
12249 bool regular
= false;
12252 return -EOPNOTSUPP
;
12254 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
12255 cfg80211_rdev_free_wowlan(rdev
);
12256 rdev
->wiphy
.wowlan_config
= NULL
;
12260 err
= nla_parse_nested_deprecated(tb
, MAX_NL80211_WOWLAN_TRIG
,
12261 info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
],
12262 nl80211_wowlan_policy
, info
->extack
);
12266 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
12267 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
12269 new_triggers
.any
= true;
12272 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
12273 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
12275 new_triggers
.disconnect
= true;
12279 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
12280 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
12282 new_triggers
.magic_pkt
= true;
12286 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
12289 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
12290 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
12292 new_triggers
.gtk_rekey_failure
= true;
12296 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
12297 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
12299 new_triggers
.eap_identity_req
= true;
12303 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
12304 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
12306 new_triggers
.four_way_handshake
= true;
12310 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
12311 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
12313 new_triggers
.rfkill_release
= true;
12317 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
12318 struct nlattr
*pat
;
12319 int n_patterns
= 0;
12320 int rem
, pat_len
, mask_len
, pkt_offset
;
12321 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
12325 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
12328 if (n_patterns
> wowlan
->n_patterns
)
12331 new_triggers
.patterns
= kcalloc(n_patterns
,
12332 sizeof(new_triggers
.patterns
[0]),
12334 if (!new_triggers
.patterns
)
12337 new_triggers
.n_patterns
= n_patterns
;
12340 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
12344 err
= nla_parse_nested_deprecated(pat_tb
,
12345 MAX_NL80211_PKTPAT
,
12347 nl80211_packet_pattern_policy
,
12353 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
12354 !pat_tb
[NL80211_PKTPAT_PATTERN
])
12356 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
12357 mask_len
= DIV_ROUND_UP(pat_len
, 8);
12358 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
12360 if (pat_len
> wowlan
->pattern_max_len
||
12361 pat_len
< wowlan
->pattern_min_len
)
12364 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
12367 pkt_offset
= nla_get_u32(
12368 pat_tb
[NL80211_PKTPAT_OFFSET
]);
12369 if (pkt_offset
> wowlan
->max_pkt_offset
)
12371 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
12373 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
12378 new_triggers
.patterns
[i
].mask
= mask_pat
;
12379 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
12381 mask_pat
+= mask_len
;
12382 new_triggers
.patterns
[i
].pattern
= mask_pat
;
12383 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
12385 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
12391 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
12393 err
= nl80211_parse_wowlan_tcp(
12394 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
12400 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
12402 err
= nl80211_parse_wowlan_nd(
12403 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
12409 /* The 'any' trigger means the device continues operating more or less
12410 * as in its normal operation mode and wakes up the host on most of the
12411 * normal interrupts (like packet RX, ...)
12412 * It therefore makes little sense to combine with the more constrained
12413 * wakeup trigger modes.
12415 if (new_triggers
.any
&& regular
) {
12420 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
12425 cfg80211_rdev_free_wowlan(rdev
);
12426 rdev
->wiphy
.wowlan_config
= ntrig
;
12429 if (rdev
->ops
->set_wakeup
&&
12430 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
12431 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
12435 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
12436 kfree(new_triggers
.patterns
[i
].mask
);
12437 kfree(new_triggers
.patterns
);
12438 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
12439 sock_release(new_triggers
.tcp
->sock
);
12440 kfree(new_triggers
.tcp
);
12441 kfree(new_triggers
.nd_config
);
12446 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
12447 struct cfg80211_registered_device
*rdev
)
12449 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
12451 struct cfg80211_coalesce_rules
*rule
;
12453 if (!rdev
->coalesce
->n_rules
)
12456 nl_rules
= nla_nest_start_noflag(msg
, NL80211_ATTR_COALESCE_RULE
);
12460 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
12461 nl_rule
= nla_nest_start_noflag(msg
, i
+ 1);
12465 rule
= &rdev
->coalesce
->rules
[i
];
12466 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
12470 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
12474 nl_pats
= nla_nest_start_noflag(msg
,
12475 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
12479 for (j
= 0; j
< rule
->n_patterns
; j
++) {
12480 nl_pat
= nla_nest_start_noflag(msg
, j
+ 1);
12483 pat_len
= rule
->patterns
[j
].pattern_len
;
12484 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
12485 DIV_ROUND_UP(pat_len
, 8),
12486 rule
->patterns
[j
].mask
) ||
12487 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
12488 rule
->patterns
[j
].pattern
) ||
12489 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
12490 rule
->patterns
[j
].pkt_offset
))
12492 nla_nest_end(msg
, nl_pat
);
12494 nla_nest_end(msg
, nl_pats
);
12495 nla_nest_end(msg
, nl_rule
);
12497 nla_nest_end(msg
, nl_rules
);
12502 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
12504 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12505 struct sk_buff
*msg
;
12508 if (!rdev
->wiphy
.coalesce
)
12509 return -EOPNOTSUPP
;
12511 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12515 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12516 NL80211_CMD_GET_COALESCE
);
12518 goto nla_put_failure
;
12520 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
12521 goto nla_put_failure
;
12523 genlmsg_end(msg
, hdr
);
12524 return genlmsg_reply(msg
, info
);
12531 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
12533 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
12535 struct cfg80211_coalesce_rules
*rule
;
12540 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
12541 rule
= &coalesce
->rules
[i
];
12542 for (j
= 0; j
< rule
->n_patterns
; j
++)
12543 kfree(rule
->patterns
[j
].mask
);
12544 kfree(rule
->patterns
);
12546 kfree(coalesce
->rules
);
12548 rdev
->coalesce
= NULL
;
12551 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
12552 struct nlattr
*rule
,
12553 struct cfg80211_coalesce_rules
*new_rule
)
12556 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
12557 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
12558 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
12559 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
12561 err
= nla_parse_nested_deprecated(tb
, NL80211_ATTR_COALESCE_RULE_MAX
,
12562 rule
, nl80211_coalesce_policy
, NULL
);
12566 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
12568 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
12569 if (new_rule
->delay
> coalesce
->max_delay
)
12572 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
12573 new_rule
->condition
=
12574 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
12576 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
12579 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
12582 if (n_patterns
> coalesce
->n_patterns
)
12585 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
12587 if (!new_rule
->patterns
)
12590 new_rule
->n_patterns
= n_patterns
;
12593 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
12597 err
= nla_parse_nested_deprecated(pat_tb
, MAX_NL80211_PKTPAT
,
12599 nl80211_packet_pattern_policy
,
12604 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
12605 !pat_tb
[NL80211_PKTPAT_PATTERN
])
12607 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
12608 mask_len
= DIV_ROUND_UP(pat_len
, 8);
12609 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
12611 if (pat_len
> coalesce
->pattern_max_len
||
12612 pat_len
< coalesce
->pattern_min_len
)
12615 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
12618 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
12619 if (pkt_offset
> coalesce
->max_pkt_offset
)
12621 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
12623 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
12627 new_rule
->patterns
[i
].mask
= mask_pat
;
12628 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
12631 mask_pat
+= mask_len
;
12632 new_rule
->patterns
[i
].pattern
= mask_pat
;
12633 new_rule
->patterns
[i
].pattern_len
= pat_len
;
12634 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
12642 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
12644 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12645 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
12646 struct cfg80211_coalesce new_coalesce
= {};
12647 struct cfg80211_coalesce
*n_coalesce
;
12648 int err
, rem_rule
, n_rules
= 0, i
, j
;
12649 struct nlattr
*rule
;
12650 struct cfg80211_coalesce_rules
*tmp_rule
;
12652 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
12653 return -EOPNOTSUPP
;
12655 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
12656 cfg80211_rdev_free_coalesce(rdev
);
12657 rdev_set_coalesce(rdev
, NULL
);
12661 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
12664 if (n_rules
> coalesce
->n_rules
)
12667 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
12669 if (!new_coalesce
.rules
)
12672 new_coalesce
.n_rules
= n_rules
;
12675 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
12677 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
12678 &new_coalesce
.rules
[i
]);
12685 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
12689 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
12694 cfg80211_rdev_free_coalesce(rdev
);
12695 rdev
->coalesce
= n_coalesce
;
12699 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
12700 tmp_rule
= &new_coalesce
.rules
[i
];
12701 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
12702 kfree(tmp_rule
->patterns
[j
].mask
);
12703 kfree(tmp_rule
->patterns
);
12705 kfree(new_coalesce
.rules
);
12710 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
12712 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12713 struct net_device
*dev
= info
->user_ptr
[1];
12714 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12715 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
12716 struct cfg80211_gtk_rekey_data rekey_data
= {};
12719 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
12722 err
= nla_parse_nested_deprecated(tb
, MAX_NL80211_REKEY_DATA
,
12723 info
->attrs
[NL80211_ATTR_REKEY_DATA
],
12724 nl80211_rekey_policy
, info
->extack
);
12728 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
12729 !tb
[NL80211_REKEY_DATA_KCK
])
12731 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
&&
12732 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK
&&
12733 nla_len(tb
[NL80211_REKEY_DATA_KEK
]) == NL80211_KEK_EXT_LEN
))
12735 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
&&
12736 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK
&&
12737 nla_len(tb
[NL80211_REKEY_DATA_KEK
]) == NL80211_KCK_EXT_LEN
))
12740 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
12741 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
12742 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
12743 rekey_data
.kek_len
= nla_len(tb
[NL80211_REKEY_DATA_KEK
]);
12744 rekey_data
.kck_len
= nla_len(tb
[NL80211_REKEY_DATA_KCK
]);
12745 if (tb
[NL80211_REKEY_DATA_AKM
])
12746 rekey_data
.akm
= nla_get_u32(tb
[NL80211_REKEY_DATA_AKM
]);
12749 if (!wdev
->current_bss
) {
12754 if (!rdev
->ops
->set_rekey_data
) {
12759 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
12765 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
12766 struct genl_info
*info
)
12768 struct net_device
*dev
= info
->user_ptr
[1];
12769 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12771 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12772 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12775 if (wdev
->ap_unexpected_nlportid
)
12778 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
12782 static int nl80211_probe_client(struct sk_buff
*skb
,
12783 struct genl_info
*info
)
12785 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12786 struct net_device
*dev
= info
->user_ptr
[1];
12787 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12788 struct sk_buff
*msg
;
12794 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12795 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12796 return -EOPNOTSUPP
;
12798 if (!info
->attrs
[NL80211_ATTR_MAC
])
12801 if (!rdev
->ops
->probe_client
)
12802 return -EOPNOTSUPP
;
12804 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12808 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12809 NL80211_CMD_PROBE_CLIENT
);
12815 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12817 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
12821 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
12823 goto nla_put_failure
;
12825 genlmsg_end(msg
, hdr
);
12827 return genlmsg_reply(msg
, info
);
12836 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
12838 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12839 struct cfg80211_beacon_registration
*reg
, *nreg
;
12842 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
12843 return -EOPNOTSUPP
;
12845 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
12849 /* First, check if already registered. */
12850 spin_lock_bh(&rdev
->beacon_registrations_lock
);
12851 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
12852 if (reg
->nlportid
== info
->snd_portid
) {
12857 /* Add it to the list */
12858 nreg
->nlportid
= info
->snd_portid
;
12859 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
12861 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12865 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12870 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
12872 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12873 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12876 if (!rdev
->ops
->start_p2p_device
)
12877 return -EOPNOTSUPP
;
12879 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
12880 return -EOPNOTSUPP
;
12882 if (wdev_running(wdev
))
12885 if (rfkill_blocked(rdev
->rfkill
))
12888 err
= rdev_start_p2p_device(rdev
, wdev
);
12892 wdev
->is_running
= true;
12898 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
12900 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12901 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12903 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
12904 return -EOPNOTSUPP
;
12906 if (!rdev
->ops
->stop_p2p_device
)
12907 return -EOPNOTSUPP
;
12909 cfg80211_stop_p2p_device(rdev
, wdev
);
12914 static int nl80211_start_nan(struct sk_buff
*skb
, struct genl_info
*info
)
12916 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12917 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12918 struct cfg80211_nan_conf conf
= {};
12921 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12922 return -EOPNOTSUPP
;
12924 if (wdev_running(wdev
))
12927 if (rfkill_blocked(rdev
->rfkill
))
12930 if (!info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
])
12934 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
12936 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
12937 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
12939 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
12940 return -EOPNOTSUPP
;
12942 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
12945 conf
.bands
= bands
;
12948 err
= rdev_start_nan(rdev
, wdev
, &conf
);
12952 wdev
->is_running
= true;
12958 static int nl80211_stop_nan(struct sk_buff
*skb
, struct genl_info
*info
)
12960 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12961 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12963 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12964 return -EOPNOTSUPP
;
12966 cfg80211_stop_nan(rdev
, wdev
);
12971 static int validate_nan_filter(struct nlattr
*filter_attr
)
12973 struct nlattr
*attr
;
12974 int len
= 0, n_entries
= 0, rem
;
12976 nla_for_each_nested(attr
, filter_attr
, rem
) {
12977 len
+= nla_len(attr
);
12987 static int handle_nan_filter(struct nlattr
*attr_filter
,
12988 struct cfg80211_nan_func
*func
,
12991 struct nlattr
*attr
;
12992 int n_entries
, rem
, i
;
12993 struct cfg80211_nan_func_filter
*filter
;
12995 n_entries
= validate_nan_filter(attr_filter
);
12999 BUILD_BUG_ON(sizeof(*func
->rx_filters
) != sizeof(*func
->tx_filters
));
13001 filter
= kcalloc(n_entries
, sizeof(*func
->rx_filters
), GFP_KERNEL
);
13006 nla_for_each_nested(attr
, attr_filter
, rem
) {
13007 filter
[i
].filter
= nla_memdup(attr
, GFP_KERNEL
);
13008 filter
[i
].len
= nla_len(attr
);
13012 func
->num_tx_filters
= n_entries
;
13013 func
->tx_filters
= filter
;
13015 func
->num_rx_filters
= n_entries
;
13016 func
->rx_filters
= filter
;
13022 static int nl80211_nan_add_func(struct sk_buff
*skb
,
13023 struct genl_info
*info
)
13025 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13026 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13027 struct nlattr
*tb
[NUM_NL80211_NAN_FUNC_ATTR
], *func_attr
;
13028 struct cfg80211_nan_func
*func
;
13029 struct sk_buff
*msg
= NULL
;
13033 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
13034 return -EOPNOTSUPP
;
13036 if (!wdev_running(wdev
))
13039 if (!info
->attrs
[NL80211_ATTR_NAN_FUNC
])
13042 err
= nla_parse_nested_deprecated(tb
, NL80211_NAN_FUNC_ATTR_MAX
,
13043 info
->attrs
[NL80211_ATTR_NAN_FUNC
],
13044 nl80211_nan_func_policy
,
13049 func
= kzalloc(sizeof(*func
), GFP_KERNEL
);
13053 func
->cookie
= cfg80211_assign_cookie(rdev
);
13055 if (!tb
[NL80211_NAN_FUNC_TYPE
]) {
13061 func
->type
= nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]);
13063 if (!tb
[NL80211_NAN_FUNC_SERVICE_ID
]) {
13068 memcpy(func
->service_id
, nla_data(tb
[NL80211_NAN_FUNC_SERVICE_ID
]),
13069 sizeof(func
->service_id
));
13071 func
->close_range
=
13072 nla_get_flag(tb
[NL80211_NAN_FUNC_CLOSE_RANGE
]);
13074 if (tb
[NL80211_NAN_FUNC_SERVICE_INFO
]) {
13075 func
->serv_spec_info_len
=
13076 nla_len(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]);
13077 func
->serv_spec_info
=
13078 kmemdup(nla_data(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]),
13079 func
->serv_spec_info_len
,
13081 if (!func
->serv_spec_info
) {
13087 if (tb
[NL80211_NAN_FUNC_TTL
])
13088 func
->ttl
= nla_get_u32(tb
[NL80211_NAN_FUNC_TTL
]);
13090 switch (func
->type
) {
13091 case NL80211_NAN_FUNC_PUBLISH
:
13092 if (!tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]) {
13097 func
->publish_type
=
13098 nla_get_u8(tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]);
13099 func
->publish_bcast
=
13100 nla_get_flag(tb
[NL80211_NAN_FUNC_PUBLISH_BCAST
]);
13102 if ((!(func
->publish_type
& NL80211_NAN_SOLICITED_PUBLISH
)) &&
13103 func
->publish_bcast
) {
13108 case NL80211_NAN_FUNC_SUBSCRIBE
:
13109 func
->subscribe_active
=
13110 nla_get_flag(tb
[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
]);
13112 case NL80211_NAN_FUNC_FOLLOW_UP
:
13113 if (!tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
] ||
13114 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] ||
13115 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]) {
13120 func
->followup_id
=
13121 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
]);
13122 func
->followup_reqid
=
13123 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]);
13124 memcpy(func
->followup_dest
.addr
,
13125 nla_data(tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]),
13126 sizeof(func
->followup_dest
.addr
));
13137 if (tb
[NL80211_NAN_FUNC_SRF
]) {
13138 struct nlattr
*srf_tb
[NUM_NL80211_NAN_SRF_ATTR
];
13140 err
= nla_parse_nested_deprecated(srf_tb
,
13141 NL80211_NAN_SRF_ATTR_MAX
,
13142 tb
[NL80211_NAN_FUNC_SRF
],
13143 nl80211_nan_srf_policy
,
13148 func
->srf_include
=
13149 nla_get_flag(srf_tb
[NL80211_NAN_SRF_INCLUDE
]);
13151 if (srf_tb
[NL80211_NAN_SRF_BF
]) {
13152 if (srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
] ||
13153 !srf_tb
[NL80211_NAN_SRF_BF_IDX
]) {
13159 nla_len(srf_tb
[NL80211_NAN_SRF_BF
]);
13161 kmemdup(nla_data(srf_tb
[NL80211_NAN_SRF_BF
]),
13162 func
->srf_bf_len
, GFP_KERNEL
);
13163 if (!func
->srf_bf
) {
13169 nla_get_u8(srf_tb
[NL80211_NAN_SRF_BF_IDX
]);
13171 struct nlattr
*attr
, *mac_attr
=
13172 srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
];
13173 int n_entries
, rem
, i
= 0;
13180 n_entries
= validate_acl_mac_addrs(mac_attr
);
13181 if (n_entries
<= 0) {
13186 func
->srf_num_macs
= n_entries
;
13188 kcalloc(n_entries
, sizeof(*func
->srf_macs
),
13190 if (!func
->srf_macs
) {
13195 nla_for_each_nested(attr
, mac_attr
, rem
)
13196 memcpy(func
->srf_macs
[i
++].addr
, nla_data(attr
),
13197 sizeof(*func
->srf_macs
));
13201 if (tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
]) {
13202 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
],
13208 if (tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
]) {
13209 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
],
13215 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13221 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
13222 NL80211_CMD_ADD_NAN_FUNCTION
);
13223 /* This can't really happen - we just allocated 4KB */
13224 if (WARN_ON(!hdr
)) {
13229 err
= rdev_add_nan_func(rdev
, wdev
, func
);
13232 cfg80211_free_nan_func(func
);
13237 /* propagate the instance id and cookie to userspace */
13238 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, func
->cookie
,
13240 goto nla_put_failure
;
13242 func_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_NAN_FUNC
);
13244 goto nla_put_failure
;
13246 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
,
13247 func
->instance_id
))
13248 goto nla_put_failure
;
13250 nla_nest_end(msg
, func_attr
);
13252 genlmsg_end(msg
, hdr
);
13253 return genlmsg_reply(msg
, info
);
13260 static int nl80211_nan_del_func(struct sk_buff
*skb
,
13261 struct genl_info
*info
)
13263 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13264 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13267 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
13268 return -EOPNOTSUPP
;
13270 if (!wdev_running(wdev
))
13273 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
13276 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
13278 rdev_del_nan_func(rdev
, wdev
, cookie
);
13283 static int nl80211_nan_change_config(struct sk_buff
*skb
,
13284 struct genl_info
*info
)
13286 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13287 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13288 struct cfg80211_nan_conf conf
= {};
13291 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
13292 return -EOPNOTSUPP
;
13294 if (!wdev_running(wdev
))
13297 if (info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]) {
13299 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
13300 if (conf
.master_pref
<= 1 || conf
.master_pref
== 255)
13303 changed
|= CFG80211_NAN_CONF_CHANGED_PREF
;
13306 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
13307 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
13309 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
13310 return -EOPNOTSUPP
;
13312 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
13315 conf
.bands
= bands
;
13316 changed
|= CFG80211_NAN_CONF_CHANGED_BANDS
;
13322 return rdev_nan_change_conf(rdev
, wdev
, &conf
, changed
);
13325 void cfg80211_nan_match(struct wireless_dev
*wdev
,
13326 struct cfg80211_nan_match_params
*match
, gfp_t gfp
)
13328 struct wiphy
*wiphy
= wdev
->wiphy
;
13329 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13330 struct nlattr
*match_attr
, *local_func_attr
, *peer_func_attr
;
13331 struct sk_buff
*msg
;
13334 if (WARN_ON(!match
->inst_id
|| !match
->peer_inst_id
|| !match
->addr
))
13337 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13341 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NAN_MATCH
);
13347 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13348 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13349 wdev
->netdev
->ifindex
)) ||
13350 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13352 goto nla_put_failure
;
13354 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, match
->cookie
,
13355 NL80211_ATTR_PAD
) ||
13356 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, match
->addr
))
13357 goto nla_put_failure
;
13359 match_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_NAN_MATCH
);
13361 goto nla_put_failure
;
13363 local_func_attr
= nla_nest_start_noflag(msg
,
13364 NL80211_NAN_MATCH_FUNC_LOCAL
);
13365 if (!local_func_attr
)
13366 goto nla_put_failure
;
13368 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->inst_id
))
13369 goto nla_put_failure
;
13371 nla_nest_end(msg
, local_func_attr
);
13373 peer_func_attr
= nla_nest_start_noflag(msg
,
13374 NL80211_NAN_MATCH_FUNC_PEER
);
13375 if (!peer_func_attr
)
13376 goto nla_put_failure
;
13378 if (nla_put_u8(msg
, NL80211_NAN_FUNC_TYPE
, match
->type
) ||
13379 nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->peer_inst_id
))
13380 goto nla_put_failure
;
13382 if (match
->info
&& match
->info_len
&&
13383 nla_put(msg
, NL80211_NAN_FUNC_SERVICE_INFO
, match
->info_len
,
13385 goto nla_put_failure
;
13387 nla_nest_end(msg
, peer_func_attr
);
13388 nla_nest_end(msg
, match_attr
);
13389 genlmsg_end(msg
, hdr
);
13391 if (!wdev
->owner_nlportid
)
13392 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
13393 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
13395 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
13396 wdev
->owner_nlportid
);
13403 EXPORT_SYMBOL(cfg80211_nan_match
);
13405 void cfg80211_nan_func_terminated(struct wireless_dev
*wdev
,
13407 enum nl80211_nan_func_term_reason reason
,
13408 u64 cookie
, gfp_t gfp
)
13410 struct wiphy
*wiphy
= wdev
->wiphy
;
13411 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13412 struct sk_buff
*msg
;
13413 struct nlattr
*func_attr
;
13416 if (WARN_ON(!inst_id
))
13419 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13423 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION
);
13429 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13430 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13431 wdev
->netdev
->ifindex
)) ||
13432 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13434 goto nla_put_failure
;
13436 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
13438 goto nla_put_failure
;
13440 func_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_NAN_FUNC
);
13442 goto nla_put_failure
;
13444 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, inst_id
) ||
13445 nla_put_u8(msg
, NL80211_NAN_FUNC_TERM_REASON
, reason
))
13446 goto nla_put_failure
;
13448 nla_nest_end(msg
, func_attr
);
13449 genlmsg_end(msg
, hdr
);
13451 if (!wdev
->owner_nlportid
)
13452 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
13453 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
13455 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
13456 wdev
->owner_nlportid
);
13463 EXPORT_SYMBOL(cfg80211_nan_func_terminated
);
13465 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
13466 struct genl_info
*info
)
13469 struct sk_buff
*msg
;
13471 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13475 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
13476 NL80211_CMD_GET_PROTOCOL_FEATURES
);
13478 goto nla_put_failure
;
13480 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
13481 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
13482 goto nla_put_failure
;
13484 genlmsg_end(msg
, hdr
);
13485 return genlmsg_reply(msg
, info
);
13492 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
13494 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13495 struct cfg80211_update_ft_ies_params ft_params
;
13496 struct net_device
*dev
= info
->user_ptr
[1];
13498 if (!rdev
->ops
->update_ft_ies
)
13499 return -EOPNOTSUPP
;
13501 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
13502 !info
->attrs
[NL80211_ATTR_IE
])
13505 memset(&ft_params
, 0, sizeof(ft_params
));
13506 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
13507 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
13508 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
13510 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
13513 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
13514 struct genl_info
*info
)
13516 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13517 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13518 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
13522 if (!rdev
->ops
->crit_proto_start
)
13523 return -EOPNOTSUPP
;
13525 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
13528 if (rdev
->crit_proto_nlportid
)
13531 /* determine protocol if provided */
13532 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
13533 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
13535 if (proto
>= NUM_NL80211_CRIT_PROTO
)
13538 /* timeout must be provided */
13539 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
13543 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
13545 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
13547 rdev
->crit_proto_nlportid
= info
->snd_portid
;
13552 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
13553 struct genl_info
*info
)
13555 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13556 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13558 if (!rdev
->ops
->crit_proto_stop
)
13559 return -EOPNOTSUPP
;
13561 if (rdev
->crit_proto_nlportid
) {
13562 rdev
->crit_proto_nlportid
= 0;
13563 rdev_crit_proto_stop(rdev
, wdev
);
13568 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command
*vcmd
,
13569 struct nlattr
*attr
,
13570 struct netlink_ext_ack
*extack
)
13572 if (vcmd
->policy
== VENDOR_CMD_RAW_DATA
) {
13573 if (attr
->nla_type
& NLA_F_NESTED
) {
13574 NL_SET_ERR_MSG_ATTR(extack
, attr
,
13575 "unexpected nested data");
13582 if (!(attr
->nla_type
& NLA_F_NESTED
)) {
13583 NL_SET_ERR_MSG_ATTR(extack
, attr
, "expected nested data");
13587 return nla_validate_nested(attr
, vcmd
->maxattr
, vcmd
->policy
, extack
);
13590 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
13592 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13593 struct wireless_dev
*wdev
=
13594 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
13598 if (!rdev
->wiphy
.vendor_commands
)
13599 return -EOPNOTSUPP
;
13601 if (IS_ERR(wdev
)) {
13602 err
= PTR_ERR(wdev
);
13603 if (err
!= -EINVAL
)
13606 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
13610 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
13611 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
13614 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
13615 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
13616 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
13617 const struct wiphy_vendor_command
*vcmd
;
13621 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
13623 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
13626 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
13627 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
13630 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
13634 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
13635 if (!wdev_running(wdev
))
13643 return -EOPNOTSUPP
;
13645 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
13646 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
13647 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
13649 err
= nl80211_vendor_check_policy(vcmd
,
13650 info
->attrs
[NL80211_ATTR_VENDOR_DATA
],
13656 rdev
->cur_cmd_info
= info
;
13657 err
= vcmd
->doit(&rdev
->wiphy
, wdev
, data
, len
);
13658 rdev
->cur_cmd_info
= NULL
;
13662 return -EOPNOTSUPP
;
13665 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
13666 struct netlink_callback
*cb
,
13667 struct cfg80211_registered_device
**rdev
,
13668 struct wireless_dev
**wdev
)
13670 struct nlattr
**attrbuf
;
13676 unsigned int data_len
= 0;
13679 /* subtract the 1 again here */
13680 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
13681 struct wireless_dev
*tmp
;
13685 *rdev
= wiphy_to_rdev(wiphy
);
13689 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
13690 if (tmp
->identifier
== cb
->args
[1] - 1) {
13697 /* keep rtnl locked in successful case */
13701 attrbuf
= kcalloc(NUM_NL80211_ATTR
, sizeof(*attrbuf
), GFP_KERNEL
);
13705 err
= nlmsg_parse_deprecated(cb
->nlh
,
13706 GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
13707 attrbuf
, nl80211_fam
.maxattr
,
13708 nl80211_policy
, NULL
);
13712 if (!attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
13713 !attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]) {
13718 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
13722 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
13723 if (IS_ERR(*rdev
)) {
13724 err
= PTR_ERR(*rdev
);
13728 vid
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_ID
]);
13729 subcmd
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
13731 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
13732 const struct wiphy_vendor_command
*vcmd
;
13734 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
13736 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
13739 if (!vcmd
->dumpit
) {
13748 if (vcmd_idx
< 0) {
13753 if (attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
13754 data
= nla_data(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
13755 data_len
= nla_len(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
13757 err
= nl80211_vendor_check_policy(
13758 &(*rdev
)->wiphy
.vendor_commands
[vcmd_idx
],
13759 attrbuf
[NL80211_ATTR_VENDOR_DATA
],
13765 /* 0 is the first index - add 1 to parse only once */
13766 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
13767 /* add 1 to know if it was NULL */
13768 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
13769 cb
->args
[2] = vcmd_idx
;
13770 cb
->args
[3] = (unsigned long)data
;
13771 cb
->args
[4] = data_len
;
13773 /* keep rtnl locked in successful case */
13780 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
13781 struct netlink_callback
*cb
)
13783 struct cfg80211_registered_device
*rdev
;
13784 struct wireless_dev
*wdev
;
13785 unsigned int vcmd_idx
;
13786 const struct wiphy_vendor_command
*vcmd
;
13790 struct nlattr
*vendor_data
;
13793 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
13797 vcmd_idx
= cb
->args
[2];
13798 data
= (void *)cb
->args
[3];
13799 data_len
= cb
->args
[4];
13800 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
13802 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
13803 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
13808 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
13814 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
13815 if (!wdev_running(wdev
)) {
13823 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
13824 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
13825 NL80211_CMD_VENDOR
);
13829 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13830 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
13832 NL80211_ATTR_PAD
))) {
13833 genlmsg_cancel(skb
, hdr
);
13837 vendor_data
= nla_nest_start_noflag(skb
,
13838 NL80211_ATTR_VENDOR_DATA
);
13839 if (!vendor_data
) {
13840 genlmsg_cancel(skb
, hdr
);
13844 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
13845 (unsigned long *)&cb
->args
[5]);
13846 nla_nest_end(skb
, vendor_data
);
13848 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
13849 genlmsg_cancel(skb
, hdr
);
13851 } else if (err
<= 0) {
13852 genlmsg_cancel(skb
, hdr
);
13856 genlmsg_end(skb
, hdr
);
13865 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
13866 enum nl80211_commands cmd
,
13867 enum nl80211_attrs attr
,
13870 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13872 if (WARN_ON(!rdev
->cur_cmd_info
))
13875 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
13876 rdev
->cur_cmd_info
->snd_portid
,
13877 rdev
->cur_cmd_info
->snd_seq
,
13878 cmd
, attr
, NULL
, GFP_KERNEL
);
13880 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
13882 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
13884 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
13885 void *hdr
= ((void **)skb
->cb
)[1];
13886 struct nlattr
*data
= ((void **)skb
->cb
)[2];
13888 /* clear CB data for netlink core to own from now on */
13889 memset(skb
->cb
, 0, sizeof(skb
->cb
));
13891 if (WARN_ON(!rdev
->cur_cmd_info
)) {
13896 nla_nest_end(skb
, data
);
13897 genlmsg_end(skb
, hdr
);
13898 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
13900 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
13902 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy
*wiphy
)
13904 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13906 if (WARN_ON(!rdev
->cur_cmd_info
))
13909 return rdev
->cur_cmd_info
->snd_portid
;
13911 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender
);
13913 static int nl80211_set_qos_map(struct sk_buff
*skb
,
13914 struct genl_info
*info
)
13916 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13917 struct cfg80211_qos_map
*qos_map
= NULL
;
13918 struct net_device
*dev
= info
->user_ptr
[1];
13919 u8
*pos
, len
, num_des
, des_len
, des
;
13922 if (!rdev
->ops
->set_qos_map
)
13923 return -EOPNOTSUPP
;
13925 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
13926 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
13927 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
13932 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
13936 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
13938 des_len
= num_des
*
13939 sizeof(struct cfg80211_dscp_exception
);
13940 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
13941 qos_map
->num_des
= num_des
;
13942 for (des
= 0; des
< num_des
; des
++) {
13943 if (qos_map
->dscp_exception
[des
].up
> 7) {
13950 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
13953 wdev_lock(dev
->ieee80211_ptr
);
13954 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
13956 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
13957 wdev_unlock(dev
->ieee80211_ptr
);
13963 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
13965 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13966 struct net_device
*dev
= info
->user_ptr
[1];
13967 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13970 u16 admitted_time
= 0;
13973 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
13974 return -EOPNOTSUPP
;
13976 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
13977 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
13980 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
13981 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
13983 /* WMM uses TIDs 0-7 even for TSPEC */
13984 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
13985 /* TODO: handle 802.11 TSPEC/admission control
13986 * need more attributes for that (e.g. BA session requirement);
13987 * change the WMM adminssion test above to allow both then
13992 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13994 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
13996 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
13997 if (!admitted_time
)
14002 switch (wdev
->iftype
) {
14003 case NL80211_IFTYPE_STATION
:
14004 case NL80211_IFTYPE_P2P_CLIENT
:
14005 if (wdev
->current_bss
)
14014 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
14021 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
14023 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14024 struct net_device
*dev
= info
->user_ptr
[1];
14025 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14030 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
14033 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
14034 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14037 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
14043 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
14044 struct genl_info
*info
)
14046 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14047 struct net_device
*dev
= info
->user_ptr
[1];
14048 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14049 struct cfg80211_chan_def chandef
= {};
14054 if (!rdev
->ops
->tdls_channel_switch
||
14055 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
14056 return -EOPNOTSUPP
;
14058 switch (dev
->ieee80211_ptr
->iftype
) {
14059 case NL80211_IFTYPE_STATION
:
14060 case NL80211_IFTYPE_P2P_CLIENT
:
14063 return -EOPNOTSUPP
;
14066 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
14067 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
14070 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
14075 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
14076 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
14077 * specification is not defined for them.
14079 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
14080 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
14081 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
14084 /* we will be active on the TDLS link */
14085 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
14089 /* don't allow switching to DFS channels */
14090 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
14093 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14094 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
14097 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
14103 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
14104 struct genl_info
*info
)
14106 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14107 struct net_device
*dev
= info
->user_ptr
[1];
14108 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14111 if (!rdev
->ops
->tdls_channel_switch
||
14112 !rdev
->ops
->tdls_cancel_channel_switch
||
14113 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
14114 return -EOPNOTSUPP
;
14116 switch (dev
->ieee80211_ptr
->iftype
) {
14117 case NL80211_IFTYPE_STATION
:
14118 case NL80211_IFTYPE_P2P_CLIENT
:
14121 return -EOPNOTSUPP
;
14124 if (!info
->attrs
[NL80211_ATTR_MAC
])
14127 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14130 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
14136 static int nl80211_set_multicast_to_unicast(struct sk_buff
*skb
,
14137 struct genl_info
*info
)
14139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14140 struct net_device
*dev
= info
->user_ptr
[1];
14141 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14142 const struct nlattr
*nla
;
14145 if (!rdev
->ops
->set_multicast_to_unicast
)
14146 return -EOPNOTSUPP
;
14148 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14149 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
14150 return -EOPNOTSUPP
;
14152 nla
= info
->attrs
[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
];
14153 enabled
= nla_get_flag(nla
);
14155 return rdev_set_multicast_to_unicast(rdev
, dev
, enabled
);
14158 static int nl80211_set_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
14160 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14161 struct net_device
*dev
= info
->user_ptr
[1];
14162 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14163 struct cfg80211_pmk_conf pmk_conf
= {};
14166 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
14167 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
14168 return -EOPNOTSUPP
;
14170 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
14171 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
14172 return -EOPNOTSUPP
;
14174 if (!info
->attrs
[NL80211_ATTR_MAC
] || !info
->attrs
[NL80211_ATTR_PMK
])
14178 if (!wdev
->current_bss
) {
14183 pmk_conf
.aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14184 if (memcmp(pmk_conf
.aa
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
)) {
14189 pmk_conf
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
14190 pmk_conf
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
14191 if (pmk_conf
.pmk_len
!= WLAN_PMK_LEN
&&
14192 pmk_conf
.pmk_len
!= WLAN_PMK_LEN_SUITE_B_192
) {
14197 if (info
->attrs
[NL80211_ATTR_PMKR0_NAME
])
14198 pmk_conf
.pmk_r0_name
=
14199 nla_data(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
14201 ret
= rdev_set_pmk(rdev
, dev
, &pmk_conf
);
14207 static int nl80211_del_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
14209 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14210 struct net_device
*dev
= info
->user_ptr
[1];
14211 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14215 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
14216 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
14217 return -EOPNOTSUPP
;
14219 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
14220 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
14221 return -EOPNOTSUPP
;
14223 if (!info
->attrs
[NL80211_ATTR_MAC
])
14227 aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14228 ret
= rdev_del_pmk(rdev
, dev
, aa
);
14234 static int nl80211_external_auth(struct sk_buff
*skb
, struct genl_info
*info
)
14236 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14237 struct net_device
*dev
= info
->user_ptr
[1];
14238 struct cfg80211_external_auth_params params
;
14240 if (!rdev
->ops
->external_auth
)
14241 return -EOPNOTSUPP
;
14243 if (!info
->attrs
[NL80211_ATTR_SSID
] &&
14244 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
14245 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
14248 if (!info
->attrs
[NL80211_ATTR_BSSID
])
14251 if (!info
->attrs
[NL80211_ATTR_STATUS_CODE
])
14254 memset(¶ms
, 0, sizeof(params
));
14256 if (info
->attrs
[NL80211_ATTR_SSID
]) {
14257 params
.ssid
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
14258 if (params
.ssid
.ssid_len
== 0)
14260 memcpy(params
.ssid
.ssid
,
14261 nla_data(info
->attrs
[NL80211_ATTR_SSID
]),
14262 params
.ssid
.ssid_len
);
14265 memcpy(params
.bssid
, nla_data(info
->attrs
[NL80211_ATTR_BSSID
]),
14268 params
.status
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
14270 if (info
->attrs
[NL80211_ATTR_PMKID
])
14271 params
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
14273 return rdev_external_auth(rdev
, dev
, ¶ms
);
14276 static int nl80211_tx_control_port(struct sk_buff
*skb
, struct genl_info
*info
)
14278 bool dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
14279 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14280 struct net_device
*dev
= info
->user_ptr
[1];
14281 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14290 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
14291 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
14292 return -EOPNOTSUPP
;
14294 if (!rdev
->ops
->tx_control_port
)
14295 return -EOPNOTSUPP
;
14297 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
14298 !info
->attrs
[NL80211_ATTR_MAC
] ||
14299 !info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
14300 GENL_SET_ERR_MSG(info
, "Frame, MAC or ethertype missing");
14306 switch (wdev
->iftype
) {
14307 case NL80211_IFTYPE_AP
:
14308 case NL80211_IFTYPE_P2P_GO
:
14309 case NL80211_IFTYPE_MESH_POINT
:
14311 case NL80211_IFTYPE_ADHOC
:
14312 case NL80211_IFTYPE_STATION
:
14313 case NL80211_IFTYPE_P2P_CLIENT
:
14314 if (wdev
->current_bss
)
14325 buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
14326 len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
14327 dest
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14328 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
14330 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
]);
14332 err
= rdev_tx_control_port(rdev
, dev
, buf
, len
,
14333 dest
, cpu_to_be16(proto
), noencrypt
,
14334 dont_wait_for_ack
? NULL
: &cookie
);
14335 if (!err
&& !dont_wait_for_ack
)
14336 nl_set_extack_cookie_u64(info
->extack
, cookie
);
14343 static int nl80211_get_ftm_responder_stats(struct sk_buff
*skb
,
14344 struct genl_info
*info
)
14346 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14347 struct net_device
*dev
= info
->user_ptr
[1];
14348 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14349 struct cfg80211_ftm_responder_stats ftm_stats
= {};
14350 struct sk_buff
*msg
;
14352 struct nlattr
*ftm_stats_attr
;
14355 if (wdev
->iftype
!= NL80211_IFTYPE_AP
|| !wdev
->beacon_interval
)
14356 return -EOPNOTSUPP
;
14358 err
= rdev_get_ftm_responder_stats(rdev
, dev
, &ftm_stats
);
14362 if (!ftm_stats
.filled
)
14365 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14369 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
14370 NL80211_CMD_GET_FTM_RESPONDER_STATS
);
14372 goto nla_put_failure
;
14374 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
14375 goto nla_put_failure
;
14377 ftm_stats_attr
= nla_nest_start_noflag(msg
,
14378 NL80211_ATTR_FTM_RESPONDER_STATS
);
14379 if (!ftm_stats_attr
)
14380 goto nla_put_failure
;
14382 #define SET_FTM(field, name, type) \
14383 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14384 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
14385 ftm_stats.field)) \
14386 goto nla_put_failure; } while (0)
14387 #define SET_FTM_U64(field, name) \
14388 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14389 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
14390 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
14391 goto nla_put_failure; } while (0)
14393 SET_FTM(success_num
, SUCCESS_NUM
, u32
);
14394 SET_FTM(partial_num
, PARTIAL_NUM
, u32
);
14395 SET_FTM(failed_num
, FAILED_NUM
, u32
);
14396 SET_FTM(asap_num
, ASAP_NUM
, u32
);
14397 SET_FTM(non_asap_num
, NON_ASAP_NUM
, u32
);
14398 SET_FTM_U64(total_duration_ms
, TOTAL_DURATION_MSEC
);
14399 SET_FTM(unknown_triggers_num
, UNKNOWN_TRIGGERS_NUM
, u32
);
14400 SET_FTM(reschedule_requests_num
, RESCHEDULE_REQUESTS_NUM
, u32
);
14401 SET_FTM(out_of_window_triggers_num
, OUT_OF_WINDOW_TRIGGERS_NUM
, u32
);
14404 nla_nest_end(msg
, ftm_stats_attr
);
14406 genlmsg_end(msg
, hdr
);
14407 return genlmsg_reply(msg
, info
);
14414 static int nl80211_update_owe_info(struct sk_buff
*skb
, struct genl_info
*info
)
14416 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14417 struct cfg80211_update_owe_info owe_info
;
14418 struct net_device
*dev
= info
->user_ptr
[1];
14420 if (!rdev
->ops
->update_owe_info
)
14421 return -EOPNOTSUPP
;
14423 if (!info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
14424 !info
->attrs
[NL80211_ATTR_MAC
])
14427 memset(&owe_info
, 0, sizeof(owe_info
));
14428 owe_info
.status
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
14429 nla_memcpy(owe_info
.peer
, info
->attrs
[NL80211_ATTR_MAC
], ETH_ALEN
);
14431 if (info
->attrs
[NL80211_ATTR_IE
]) {
14432 owe_info
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
14433 owe_info
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
14436 return rdev_update_owe_info(rdev
, dev
, &owe_info
);
14439 static int nl80211_probe_mesh_link(struct sk_buff
*skb
, struct genl_info
*info
)
14441 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14442 struct net_device
*dev
= info
->user_ptr
[1];
14443 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14444 struct station_info sinfo
= {};
14450 if (!rdev
->ops
->probe_mesh_link
|| !rdev
->ops
->get_station
)
14451 return -EOPNOTSUPP
;
14453 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
14454 !info
->attrs
[NL80211_ATTR_FRAME
]) {
14455 GENL_SET_ERR_MSG(info
, "Frame or MAC missing");
14459 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
14460 return -EOPNOTSUPP
;
14462 dest
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14463 buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
14464 len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
14466 if (len
< sizeof(struct ethhdr
))
14469 if (!ether_addr_equal(buf
, dest
) || is_multicast_ether_addr(buf
) ||
14470 !ether_addr_equal(buf
+ ETH_ALEN
, dev
->dev_addr
))
14473 err
= rdev_get_station(rdev
, dev
, dest
, &sinfo
);
14477 cfg80211_sinfo_release_content(&sinfo
);
14479 return rdev_probe_mesh_link(rdev
, dev
, dest
, buf
, len
);
14482 static int parse_tid_conf(struct cfg80211_registered_device
*rdev
,
14483 struct nlattr
*attrs
[], struct net_device
*dev
,
14484 struct cfg80211_tid_cfg
*tid_conf
,
14485 struct genl_info
*info
, const u8
*peer
)
14487 struct netlink_ext_ack
*extack
= info
->extack
;
14491 if (!attrs
[NL80211_TID_CONFIG_ATTR_TIDS
])
14494 tid_conf
->config_override
=
14495 nla_get_flag(attrs
[NL80211_TID_CONFIG_ATTR_OVERRIDE
]);
14496 tid_conf
->tids
= nla_get_u16(attrs
[NL80211_TID_CONFIG_ATTR_TIDS
]);
14498 if (tid_conf
->config_override
) {
14499 if (rdev
->ops
->reset_tid_config
) {
14500 err
= rdev_reset_tid_config(rdev
, dev
, peer
,
14509 if (attrs
[NL80211_TID_CONFIG_ATTR_NOACK
]) {
14510 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
14512 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_NOACK
]);
14515 if (attrs
[NL80211_TID_CONFIG_ATTR_RETRY_SHORT
]) {
14516 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT
);
14517 tid_conf
->retry_short
=
14518 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_RETRY_SHORT
]);
14520 if (tid_conf
->retry_short
> rdev
->wiphy
.max_data_retry_count
)
14524 if (attrs
[NL80211_TID_CONFIG_ATTR_RETRY_LONG
]) {
14525 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
14526 tid_conf
->retry_long
=
14527 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_RETRY_LONG
]);
14529 if (tid_conf
->retry_long
> rdev
->wiphy
.max_data_retry_count
)
14533 if (attrs
[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
]) {
14534 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
);
14536 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
]);
14539 if (attrs
[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
]) {
14540 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
);
14542 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
]);
14545 if (attrs
[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL
]) {
14546 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL
);
14548 nla_get_u8(attrs
[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL
]);
14551 if (attrs
[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
]) {
14552 u32 idx
= NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
, attr
;
14554 tid_conf
->txrate_type
= nla_get_u8(attrs
[idx
]);
14556 if (tid_conf
->txrate_type
!= NL80211_TX_RATE_AUTOMATIC
) {
14557 attr
= NL80211_TID_CONFIG_ATTR_TX_RATE
;
14558 err
= nl80211_parse_tx_bitrate_mask(info
, attrs
, attr
,
14559 &tid_conf
->txrate_mask
, dev
,
14564 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
);
14566 tid_conf
->mask
|= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
);
14570 mask
= rdev
->wiphy
.tid_config_support
.peer
;
14572 mask
= rdev
->wiphy
.tid_config_support
.vif
;
14574 if (tid_conf
->mask
& ~mask
) {
14575 NL_SET_ERR_MSG(extack
, "unsupported TID configuration");
14582 static int nl80211_set_tid_config(struct sk_buff
*skb
,
14583 struct genl_info
*info
)
14585 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14586 struct nlattr
*attrs
[NL80211_TID_CONFIG_ATTR_MAX
+ 1];
14587 struct net_device
*dev
= info
->user_ptr
[1];
14588 struct cfg80211_tid_config
*tid_config
;
14589 struct nlattr
*tid
;
14590 int conf_idx
= 0, rem_conf
;
14594 if (!info
->attrs
[NL80211_ATTR_TID_CONFIG
])
14597 if (!rdev
->ops
->set_tid_config
)
14598 return -EOPNOTSUPP
;
14600 nla_for_each_nested(tid
, info
->attrs
[NL80211_ATTR_TID_CONFIG
],
14604 tid_config
= kzalloc(struct_size(tid_config
, tid_conf
, num_conf
),
14609 tid_config
->n_tid_conf
= num_conf
;
14611 if (info
->attrs
[NL80211_ATTR_MAC
])
14612 tid_config
->peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
14614 nla_for_each_nested(tid
, info
->attrs
[NL80211_ATTR_TID_CONFIG
],
14616 ret
= nla_parse_nested(attrs
, NL80211_TID_CONFIG_ATTR_MAX
,
14622 ret
= parse_tid_conf(rdev
, attrs
, dev
,
14623 &tid_config
->tid_conf
[conf_idx
],
14624 info
, tid_config
->peer
);
14631 ret
= rdev_set_tid_config(rdev
, dev
, tid_config
);
14638 #define NL80211_FLAG_NEED_WIPHY 0x01
14639 #define NL80211_FLAG_NEED_NETDEV 0x02
14640 #define NL80211_FLAG_NEED_RTNL 0x04
14641 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
14642 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
14643 NL80211_FLAG_CHECK_NETDEV_UP)
14644 #define NL80211_FLAG_NEED_WDEV 0x10
14645 /* If a netdev is associated, it must be UP, P2P must be started */
14646 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
14647 NL80211_FLAG_CHECK_NETDEV_UP)
14648 #define NL80211_FLAG_CLEAR_SKB 0x20
14650 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
14651 struct genl_info
*info
)
14653 struct cfg80211_registered_device
*rdev
;
14654 struct wireless_dev
*wdev
;
14655 struct net_device
*dev
;
14656 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
14661 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
14662 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
14663 if (IS_ERR(rdev
)) {
14666 return PTR_ERR(rdev
);
14668 info
->user_ptr
[0] = rdev
;
14669 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
14670 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
14673 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
14675 if (IS_ERR(wdev
)) {
14678 return PTR_ERR(wdev
);
14681 dev
= wdev
->netdev
;
14682 rdev
= wiphy_to_rdev(wdev
->wiphy
);
14684 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
14691 info
->user_ptr
[1] = dev
;
14693 info
->user_ptr
[1] = wdev
;
14696 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
14697 !wdev_running(wdev
)) {
14706 info
->user_ptr
[0] = rdev
;
14712 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
14713 struct genl_info
*info
)
14715 if (info
->user_ptr
[1]) {
14716 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
14717 struct wireless_dev
*wdev
= info
->user_ptr
[1];
14720 dev_put(wdev
->netdev
);
14722 dev_put(info
->user_ptr
[1]);
14726 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
14729 /* If needed, clear the netlink message payload from the SKB
14730 * as it might contain key data that shouldn't stick around on
14731 * the heap after the SKB is freed. The netlink message header
14732 * is still needed for further processing, so leave it intact.
14734 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
14735 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
14737 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
14741 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device
*rdev
,
14742 struct cfg80211_sar_specs
*sar_specs
,
14743 struct nlattr
*spec
[], int index
)
14745 u32 range_index
, i
;
14747 if (!sar_specs
|| !spec
)
14750 if (!spec
[NL80211_SAR_ATTR_SPECS_POWER
] ||
14751 !spec
[NL80211_SAR_ATTR_SPECS_RANGE_INDEX
])
14754 range_index
= nla_get_u32(spec
[NL80211_SAR_ATTR_SPECS_RANGE_INDEX
]);
14756 /* check if range_index exceeds num_freq_ranges */
14757 if (range_index
>= rdev
->wiphy
.sar_capa
->num_freq_ranges
)
14760 /* check if range_index duplicates */
14761 for (i
= 0; i
< index
; i
++) {
14762 if (sar_specs
->sub_specs
[i
].freq_range_index
== range_index
)
14766 sar_specs
->sub_specs
[index
].power
=
14767 nla_get_s32(spec
[NL80211_SAR_ATTR_SPECS_POWER
]);
14769 sar_specs
->sub_specs
[index
].freq_range_index
= range_index
;
14774 static int nl80211_set_sar_specs(struct sk_buff
*skb
, struct genl_info
*info
)
14776 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
14777 struct nlattr
*spec
[NL80211_SAR_ATTR_SPECS_MAX
+ 1];
14778 struct nlattr
*tb
[NL80211_SAR_ATTR_MAX
+ 1];
14779 struct cfg80211_sar_specs
*sar_spec
;
14780 enum nl80211_sar_type type
;
14781 struct nlattr
*spec_list
;
14785 if (!rdev
->wiphy
.sar_capa
|| !rdev
->ops
->set_sar_specs
)
14786 return -EOPNOTSUPP
;
14788 if (!info
->attrs
[NL80211_ATTR_SAR_SPEC
])
14791 nla_parse_nested(tb
, NL80211_SAR_ATTR_MAX
,
14792 info
->attrs
[NL80211_ATTR_SAR_SPEC
],
14795 if (!tb
[NL80211_SAR_ATTR_TYPE
] || !tb
[NL80211_SAR_ATTR_SPECS
])
14798 type
= nla_get_u32(tb
[NL80211_SAR_ATTR_TYPE
]);
14799 if (type
!= rdev
->wiphy
.sar_capa
->type
)
14803 nla_for_each_nested(spec_list
, tb
[NL80211_SAR_ATTR_SPECS
], rem
)
14806 if (specs
> rdev
->wiphy
.sar_capa
->num_freq_ranges
)
14809 sar_spec
= kzalloc(sizeof(*sar_spec
) +
14810 specs
* sizeof(struct cfg80211_sar_sub_specs
),
14815 sar_spec
->type
= type
;
14817 nla_for_each_nested(spec_list
, tb
[NL80211_SAR_ATTR_SPECS
], rem
) {
14818 nla_parse_nested(spec
, NL80211_SAR_ATTR_SPECS_MAX
,
14819 spec_list
, NULL
, NULL
);
14822 case NL80211_SAR_TYPE_POWER
:
14823 if (nl80211_set_sar_sub_specs(rdev
, sar_spec
,
14836 sar_spec
->num_sub_specs
= specs
;
14838 rdev
->cur_cmd_info
= info
;
14839 err
= rdev_set_sar_specs(rdev
, sar_spec
);
14840 rdev
->cur_cmd_info
= NULL
;
14846 static const struct genl_ops nl80211_ops
[] = {
14848 .cmd
= NL80211_CMD_GET_WIPHY
,
14849 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14850 .doit
= nl80211_get_wiphy
,
14851 .dumpit
= nl80211_dump_wiphy
,
14852 .done
= nl80211_dump_wiphy_done
,
14853 /* can be retrieved by unprivileged users */
14854 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14855 NL80211_FLAG_NEED_RTNL
,
14859 static const struct genl_small_ops nl80211_small_ops
[] = {
14861 .cmd
= NL80211_CMD_SET_WIPHY
,
14862 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14863 .doit
= nl80211_set_wiphy
,
14864 .flags
= GENL_UNS_ADMIN_PERM
,
14865 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
14868 .cmd
= NL80211_CMD_GET_INTERFACE
,
14869 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14870 .doit
= nl80211_get_interface
,
14871 .dumpit
= nl80211_dump_interface
,
14872 /* can be retrieved by unprivileged users */
14873 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
14874 NL80211_FLAG_NEED_RTNL
,
14877 .cmd
= NL80211_CMD_SET_INTERFACE
,
14878 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14879 .doit
= nl80211_set_interface
,
14880 .flags
= GENL_UNS_ADMIN_PERM
,
14881 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14882 NL80211_FLAG_NEED_RTNL
,
14885 .cmd
= NL80211_CMD_NEW_INTERFACE
,
14886 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14887 .doit
= nl80211_new_interface
,
14888 .flags
= GENL_UNS_ADMIN_PERM
,
14889 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
14890 NL80211_FLAG_NEED_RTNL
,
14893 .cmd
= NL80211_CMD_DEL_INTERFACE
,
14894 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14895 .doit
= nl80211_del_interface
,
14896 .flags
= GENL_UNS_ADMIN_PERM
,
14897 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
14898 NL80211_FLAG_NEED_RTNL
,
14901 .cmd
= NL80211_CMD_GET_KEY
,
14902 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14903 .doit
= nl80211_get_key
,
14904 .flags
= GENL_UNS_ADMIN_PERM
,
14905 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14906 NL80211_FLAG_NEED_RTNL
,
14909 .cmd
= NL80211_CMD_SET_KEY
,
14910 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14911 .doit
= nl80211_set_key
,
14912 .flags
= GENL_UNS_ADMIN_PERM
,
14913 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14914 NL80211_FLAG_NEED_RTNL
|
14915 NL80211_FLAG_CLEAR_SKB
,
14918 .cmd
= NL80211_CMD_NEW_KEY
,
14919 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14920 .doit
= nl80211_new_key
,
14921 .flags
= GENL_UNS_ADMIN_PERM
,
14922 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14923 NL80211_FLAG_NEED_RTNL
|
14924 NL80211_FLAG_CLEAR_SKB
,
14927 .cmd
= NL80211_CMD_DEL_KEY
,
14928 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14929 .doit
= nl80211_del_key
,
14930 .flags
= GENL_UNS_ADMIN_PERM
,
14931 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14932 NL80211_FLAG_NEED_RTNL
,
14935 .cmd
= NL80211_CMD_SET_BEACON
,
14936 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14937 .flags
= GENL_UNS_ADMIN_PERM
,
14938 .doit
= nl80211_set_beacon
,
14939 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14940 NL80211_FLAG_NEED_RTNL
,
14943 .cmd
= NL80211_CMD_START_AP
,
14944 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14945 .flags
= GENL_UNS_ADMIN_PERM
,
14946 .doit
= nl80211_start_ap
,
14947 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14948 NL80211_FLAG_NEED_RTNL
,
14951 .cmd
= NL80211_CMD_STOP_AP
,
14952 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14953 .flags
= GENL_UNS_ADMIN_PERM
,
14954 .doit
= nl80211_stop_ap
,
14955 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14956 NL80211_FLAG_NEED_RTNL
,
14959 .cmd
= NL80211_CMD_GET_STATION
,
14960 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14961 .doit
= nl80211_get_station
,
14962 .dumpit
= nl80211_dump_station
,
14963 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
14964 NL80211_FLAG_NEED_RTNL
,
14967 .cmd
= NL80211_CMD_SET_STATION
,
14968 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14969 .doit
= nl80211_set_station
,
14970 .flags
= GENL_UNS_ADMIN_PERM
,
14971 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14972 NL80211_FLAG_NEED_RTNL
,
14975 .cmd
= NL80211_CMD_NEW_STATION
,
14976 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14977 .doit
= nl80211_new_station
,
14978 .flags
= GENL_UNS_ADMIN_PERM
,
14979 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14980 NL80211_FLAG_NEED_RTNL
,
14983 .cmd
= NL80211_CMD_DEL_STATION
,
14984 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14985 .doit
= nl80211_del_station
,
14986 .flags
= GENL_UNS_ADMIN_PERM
,
14987 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14988 NL80211_FLAG_NEED_RTNL
,
14991 .cmd
= NL80211_CMD_GET_MPATH
,
14992 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
14993 .doit
= nl80211_get_mpath
,
14994 .dumpit
= nl80211_dump_mpath
,
14995 .flags
= GENL_UNS_ADMIN_PERM
,
14996 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
14997 NL80211_FLAG_NEED_RTNL
,
15000 .cmd
= NL80211_CMD_GET_MPP
,
15001 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15002 .doit
= nl80211_get_mpp
,
15003 .dumpit
= nl80211_dump_mpp
,
15004 .flags
= GENL_UNS_ADMIN_PERM
,
15005 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15006 NL80211_FLAG_NEED_RTNL
,
15009 .cmd
= NL80211_CMD_SET_MPATH
,
15010 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15011 .doit
= nl80211_set_mpath
,
15012 .flags
= GENL_UNS_ADMIN_PERM
,
15013 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15014 NL80211_FLAG_NEED_RTNL
,
15017 .cmd
= NL80211_CMD_NEW_MPATH
,
15018 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15019 .doit
= nl80211_new_mpath
,
15020 .flags
= GENL_UNS_ADMIN_PERM
,
15021 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15022 NL80211_FLAG_NEED_RTNL
,
15025 .cmd
= NL80211_CMD_DEL_MPATH
,
15026 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15027 .doit
= nl80211_del_mpath
,
15028 .flags
= GENL_UNS_ADMIN_PERM
,
15029 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15030 NL80211_FLAG_NEED_RTNL
,
15033 .cmd
= NL80211_CMD_SET_BSS
,
15034 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15035 .doit
= nl80211_set_bss
,
15036 .flags
= GENL_UNS_ADMIN_PERM
,
15037 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15038 NL80211_FLAG_NEED_RTNL
,
15041 .cmd
= NL80211_CMD_GET_REG
,
15042 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15043 .doit
= nl80211_get_reg_do
,
15044 .dumpit
= nl80211_get_reg_dump
,
15045 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
15046 /* can be retrieved by unprivileged users */
15048 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
15050 .cmd
= NL80211_CMD_SET_REG
,
15051 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15052 .doit
= nl80211_set_reg
,
15053 .flags
= GENL_ADMIN_PERM
,
15054 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
15058 .cmd
= NL80211_CMD_REQ_SET_REG
,
15059 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15060 .doit
= nl80211_req_set_reg
,
15061 .flags
= GENL_ADMIN_PERM
,
15064 .cmd
= NL80211_CMD_RELOAD_REGDB
,
15065 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15066 .doit
= nl80211_reload_regdb
,
15067 .flags
= GENL_ADMIN_PERM
,
15070 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
15071 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15072 .doit
= nl80211_get_mesh_config
,
15073 /* can be retrieved by unprivileged users */
15074 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15075 NL80211_FLAG_NEED_RTNL
,
15078 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
15079 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15080 .doit
= nl80211_update_mesh_config
,
15081 .flags
= GENL_UNS_ADMIN_PERM
,
15082 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15083 NL80211_FLAG_NEED_RTNL
,
15086 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
15087 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15088 .doit
= nl80211_trigger_scan
,
15089 .flags
= GENL_UNS_ADMIN_PERM
,
15090 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15091 NL80211_FLAG_NEED_RTNL
,
15094 .cmd
= NL80211_CMD_ABORT_SCAN
,
15095 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15096 .doit
= nl80211_abort_scan
,
15097 .flags
= GENL_UNS_ADMIN_PERM
,
15098 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15099 NL80211_FLAG_NEED_RTNL
,
15102 .cmd
= NL80211_CMD_GET_SCAN
,
15103 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15104 .dumpit
= nl80211_dump_scan
,
15107 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
15108 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15109 .doit
= nl80211_start_sched_scan
,
15110 .flags
= GENL_UNS_ADMIN_PERM
,
15111 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15112 NL80211_FLAG_NEED_RTNL
,
15115 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
15116 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15117 .doit
= nl80211_stop_sched_scan
,
15118 .flags
= GENL_UNS_ADMIN_PERM
,
15119 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15120 NL80211_FLAG_NEED_RTNL
,
15123 .cmd
= NL80211_CMD_AUTHENTICATE
,
15124 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15125 .doit
= nl80211_authenticate
,
15126 .flags
= GENL_UNS_ADMIN_PERM
,
15127 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15128 NL80211_FLAG_NEED_RTNL
|
15129 NL80211_FLAG_CLEAR_SKB
,
15132 .cmd
= NL80211_CMD_ASSOCIATE
,
15133 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15134 .doit
= nl80211_associate
,
15135 .flags
= GENL_UNS_ADMIN_PERM
,
15136 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15137 NL80211_FLAG_NEED_RTNL
|
15138 NL80211_FLAG_CLEAR_SKB
,
15141 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
15142 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15143 .doit
= nl80211_deauthenticate
,
15144 .flags
= GENL_UNS_ADMIN_PERM
,
15145 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15146 NL80211_FLAG_NEED_RTNL
,
15149 .cmd
= NL80211_CMD_DISASSOCIATE
,
15150 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15151 .doit
= nl80211_disassociate
,
15152 .flags
= GENL_UNS_ADMIN_PERM
,
15153 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15154 NL80211_FLAG_NEED_RTNL
,
15157 .cmd
= NL80211_CMD_JOIN_IBSS
,
15158 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15159 .doit
= nl80211_join_ibss
,
15160 .flags
= GENL_UNS_ADMIN_PERM
,
15161 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15162 NL80211_FLAG_NEED_RTNL
,
15165 .cmd
= NL80211_CMD_LEAVE_IBSS
,
15166 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15167 .doit
= nl80211_leave_ibss
,
15168 .flags
= GENL_UNS_ADMIN_PERM
,
15169 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15170 NL80211_FLAG_NEED_RTNL
,
15172 #ifdef CONFIG_NL80211_TESTMODE
15174 .cmd
= NL80211_CMD_TESTMODE
,
15175 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15176 .doit
= nl80211_testmode_do
,
15177 .dumpit
= nl80211_testmode_dump
,
15178 .flags
= GENL_UNS_ADMIN_PERM
,
15179 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15180 NL80211_FLAG_NEED_RTNL
,
15184 .cmd
= NL80211_CMD_CONNECT
,
15185 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15186 .doit
= nl80211_connect
,
15187 .flags
= GENL_UNS_ADMIN_PERM
,
15188 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15189 NL80211_FLAG_NEED_RTNL
|
15190 NL80211_FLAG_CLEAR_SKB
,
15193 .cmd
= NL80211_CMD_UPDATE_CONNECT_PARAMS
,
15194 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15195 .doit
= nl80211_update_connect_params
,
15196 .flags
= GENL_ADMIN_PERM
,
15197 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15198 NL80211_FLAG_NEED_RTNL
|
15199 NL80211_FLAG_CLEAR_SKB
,
15202 .cmd
= NL80211_CMD_DISCONNECT
,
15203 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15204 .doit
= nl80211_disconnect
,
15205 .flags
= GENL_UNS_ADMIN_PERM
,
15206 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15207 NL80211_FLAG_NEED_RTNL
,
15210 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
15211 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15212 .doit
= nl80211_wiphy_netns
,
15213 .flags
= GENL_UNS_ADMIN_PERM
,
15214 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15215 NL80211_FLAG_NEED_RTNL
,
15218 .cmd
= NL80211_CMD_GET_SURVEY
,
15219 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15220 .dumpit
= nl80211_dump_survey
,
15223 .cmd
= NL80211_CMD_SET_PMKSA
,
15224 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15225 .doit
= nl80211_setdel_pmksa
,
15226 .flags
= GENL_UNS_ADMIN_PERM
,
15227 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15228 NL80211_FLAG_NEED_RTNL
|
15229 NL80211_FLAG_CLEAR_SKB
,
15232 .cmd
= NL80211_CMD_DEL_PMKSA
,
15233 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15234 .doit
= nl80211_setdel_pmksa
,
15235 .flags
= GENL_UNS_ADMIN_PERM
,
15236 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15237 NL80211_FLAG_NEED_RTNL
,
15240 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
15241 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15242 .doit
= nl80211_flush_pmksa
,
15243 .flags
= GENL_UNS_ADMIN_PERM
,
15244 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15245 NL80211_FLAG_NEED_RTNL
,
15248 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
15249 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15250 .doit
= nl80211_remain_on_channel
,
15251 .flags
= GENL_UNS_ADMIN_PERM
,
15252 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15253 NL80211_FLAG_NEED_RTNL
,
15256 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
15257 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15258 .doit
= nl80211_cancel_remain_on_channel
,
15259 .flags
= GENL_UNS_ADMIN_PERM
,
15260 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15261 NL80211_FLAG_NEED_RTNL
,
15264 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
15265 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15266 .doit
= nl80211_set_tx_bitrate_mask
,
15267 .flags
= GENL_UNS_ADMIN_PERM
,
15268 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15269 NL80211_FLAG_NEED_RTNL
,
15272 .cmd
= NL80211_CMD_REGISTER_FRAME
,
15273 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15274 .doit
= nl80211_register_mgmt
,
15275 .flags
= GENL_UNS_ADMIN_PERM
,
15276 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
15277 NL80211_FLAG_NEED_RTNL
,
15280 .cmd
= NL80211_CMD_FRAME
,
15281 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15282 .doit
= nl80211_tx_mgmt
,
15283 .flags
= GENL_UNS_ADMIN_PERM
,
15284 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15285 NL80211_FLAG_NEED_RTNL
,
15288 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
15289 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15290 .doit
= nl80211_tx_mgmt_cancel_wait
,
15291 .flags
= GENL_UNS_ADMIN_PERM
,
15292 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15293 NL80211_FLAG_NEED_RTNL
,
15296 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
15297 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15298 .doit
= nl80211_set_power_save
,
15299 .flags
= GENL_UNS_ADMIN_PERM
,
15300 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15301 NL80211_FLAG_NEED_RTNL
,
15304 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
15305 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15306 .doit
= nl80211_get_power_save
,
15307 /* can be retrieved by unprivileged users */
15308 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15309 NL80211_FLAG_NEED_RTNL
,
15312 .cmd
= NL80211_CMD_SET_CQM
,
15313 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15314 .doit
= nl80211_set_cqm
,
15315 .flags
= GENL_UNS_ADMIN_PERM
,
15316 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15317 NL80211_FLAG_NEED_RTNL
,
15320 .cmd
= NL80211_CMD_SET_CHANNEL
,
15321 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15322 .doit
= nl80211_set_channel
,
15323 .flags
= GENL_UNS_ADMIN_PERM
,
15324 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15325 NL80211_FLAG_NEED_RTNL
,
15328 .cmd
= NL80211_CMD_JOIN_MESH
,
15329 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15330 .doit
= nl80211_join_mesh
,
15331 .flags
= GENL_UNS_ADMIN_PERM
,
15332 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15333 NL80211_FLAG_NEED_RTNL
,
15336 .cmd
= NL80211_CMD_LEAVE_MESH
,
15337 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15338 .doit
= nl80211_leave_mesh
,
15339 .flags
= GENL_UNS_ADMIN_PERM
,
15340 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15341 NL80211_FLAG_NEED_RTNL
,
15344 .cmd
= NL80211_CMD_JOIN_OCB
,
15345 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15346 .doit
= nl80211_join_ocb
,
15347 .flags
= GENL_UNS_ADMIN_PERM
,
15348 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15349 NL80211_FLAG_NEED_RTNL
,
15352 .cmd
= NL80211_CMD_LEAVE_OCB
,
15353 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15354 .doit
= nl80211_leave_ocb
,
15355 .flags
= GENL_UNS_ADMIN_PERM
,
15356 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15357 NL80211_FLAG_NEED_RTNL
,
15361 .cmd
= NL80211_CMD_GET_WOWLAN
,
15362 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15363 .doit
= nl80211_get_wowlan
,
15364 /* can be retrieved by unprivileged users */
15365 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15366 NL80211_FLAG_NEED_RTNL
,
15369 .cmd
= NL80211_CMD_SET_WOWLAN
,
15370 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15371 .doit
= nl80211_set_wowlan
,
15372 .flags
= GENL_UNS_ADMIN_PERM
,
15373 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15374 NL80211_FLAG_NEED_RTNL
,
15378 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
15379 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15380 .doit
= nl80211_set_rekey_data
,
15381 .flags
= GENL_UNS_ADMIN_PERM
,
15382 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15383 NL80211_FLAG_NEED_RTNL
|
15384 NL80211_FLAG_CLEAR_SKB
,
15387 .cmd
= NL80211_CMD_TDLS_MGMT
,
15388 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15389 .doit
= nl80211_tdls_mgmt
,
15390 .flags
= GENL_UNS_ADMIN_PERM
,
15391 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15392 NL80211_FLAG_NEED_RTNL
,
15395 .cmd
= NL80211_CMD_TDLS_OPER
,
15396 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15397 .doit
= nl80211_tdls_oper
,
15398 .flags
= GENL_UNS_ADMIN_PERM
,
15399 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15400 NL80211_FLAG_NEED_RTNL
,
15403 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
15404 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15405 .doit
= nl80211_register_unexpected_frame
,
15406 .flags
= GENL_UNS_ADMIN_PERM
,
15407 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15408 NL80211_FLAG_NEED_RTNL
,
15411 .cmd
= NL80211_CMD_PROBE_CLIENT
,
15412 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15413 .doit
= nl80211_probe_client
,
15414 .flags
= GENL_UNS_ADMIN_PERM
,
15415 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15416 NL80211_FLAG_NEED_RTNL
,
15419 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
15420 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15421 .doit
= nl80211_register_beacons
,
15422 .flags
= GENL_UNS_ADMIN_PERM
,
15423 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15424 NL80211_FLAG_NEED_RTNL
,
15427 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
15428 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15429 .doit
= nl80211_set_noack_map
,
15430 .flags
= GENL_UNS_ADMIN_PERM
,
15431 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15432 NL80211_FLAG_NEED_RTNL
,
15435 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
15436 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15437 .doit
= nl80211_start_p2p_device
,
15438 .flags
= GENL_UNS_ADMIN_PERM
,
15439 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
15440 NL80211_FLAG_NEED_RTNL
,
15443 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
15444 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15445 .doit
= nl80211_stop_p2p_device
,
15446 .flags
= GENL_UNS_ADMIN_PERM
,
15447 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15448 NL80211_FLAG_NEED_RTNL
,
15451 .cmd
= NL80211_CMD_START_NAN
,
15452 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15453 .doit
= nl80211_start_nan
,
15454 .flags
= GENL_ADMIN_PERM
,
15455 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
15456 NL80211_FLAG_NEED_RTNL
,
15459 .cmd
= NL80211_CMD_STOP_NAN
,
15460 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15461 .doit
= nl80211_stop_nan
,
15462 .flags
= GENL_ADMIN_PERM
,
15463 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15464 NL80211_FLAG_NEED_RTNL
,
15467 .cmd
= NL80211_CMD_ADD_NAN_FUNCTION
,
15468 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15469 .doit
= nl80211_nan_add_func
,
15470 .flags
= GENL_ADMIN_PERM
,
15471 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15472 NL80211_FLAG_NEED_RTNL
,
15475 .cmd
= NL80211_CMD_DEL_NAN_FUNCTION
,
15476 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15477 .doit
= nl80211_nan_del_func
,
15478 .flags
= GENL_ADMIN_PERM
,
15479 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15480 NL80211_FLAG_NEED_RTNL
,
15483 .cmd
= NL80211_CMD_CHANGE_NAN_CONFIG
,
15484 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15485 .doit
= nl80211_nan_change_config
,
15486 .flags
= GENL_ADMIN_PERM
,
15487 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15488 NL80211_FLAG_NEED_RTNL
,
15491 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
15492 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15493 .doit
= nl80211_set_mcast_rate
,
15494 .flags
= GENL_UNS_ADMIN_PERM
,
15495 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15496 NL80211_FLAG_NEED_RTNL
,
15499 .cmd
= NL80211_CMD_SET_MAC_ACL
,
15500 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15501 .doit
= nl80211_set_mac_acl
,
15502 .flags
= GENL_UNS_ADMIN_PERM
,
15503 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15504 NL80211_FLAG_NEED_RTNL
,
15507 .cmd
= NL80211_CMD_RADAR_DETECT
,
15508 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15509 .doit
= nl80211_start_radar_detection
,
15510 .flags
= GENL_UNS_ADMIN_PERM
,
15511 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15512 NL80211_FLAG_NEED_RTNL
,
15515 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
15516 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15517 .doit
= nl80211_get_protocol_features
,
15520 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
15521 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15522 .doit
= nl80211_update_ft_ies
,
15523 .flags
= GENL_UNS_ADMIN_PERM
,
15524 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15525 NL80211_FLAG_NEED_RTNL
,
15528 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
15529 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15530 .doit
= nl80211_crit_protocol_start
,
15531 .flags
= GENL_UNS_ADMIN_PERM
,
15532 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15533 NL80211_FLAG_NEED_RTNL
,
15536 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
15537 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15538 .doit
= nl80211_crit_protocol_stop
,
15539 .flags
= GENL_UNS_ADMIN_PERM
,
15540 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15541 NL80211_FLAG_NEED_RTNL
,
15544 .cmd
= NL80211_CMD_GET_COALESCE
,
15545 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15546 .doit
= nl80211_get_coalesce
,
15547 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15548 NL80211_FLAG_NEED_RTNL
,
15551 .cmd
= NL80211_CMD_SET_COALESCE
,
15552 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15553 .doit
= nl80211_set_coalesce
,
15554 .flags
= GENL_UNS_ADMIN_PERM
,
15555 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15556 NL80211_FLAG_NEED_RTNL
,
15559 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
15560 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15561 .doit
= nl80211_channel_switch
,
15562 .flags
= GENL_UNS_ADMIN_PERM
,
15563 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15564 NL80211_FLAG_NEED_RTNL
,
15567 .cmd
= NL80211_CMD_VENDOR
,
15568 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15569 .doit
= nl80211_vendor_cmd
,
15570 .dumpit
= nl80211_vendor_cmd_dump
,
15571 .flags
= GENL_UNS_ADMIN_PERM
,
15572 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15573 NL80211_FLAG_NEED_RTNL
|
15574 NL80211_FLAG_CLEAR_SKB
,
15577 .cmd
= NL80211_CMD_SET_QOS_MAP
,
15578 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15579 .doit
= nl80211_set_qos_map
,
15580 .flags
= GENL_UNS_ADMIN_PERM
,
15581 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15582 NL80211_FLAG_NEED_RTNL
,
15585 .cmd
= NL80211_CMD_ADD_TX_TS
,
15586 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15587 .doit
= nl80211_add_tx_ts
,
15588 .flags
= GENL_UNS_ADMIN_PERM
,
15589 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15590 NL80211_FLAG_NEED_RTNL
,
15593 .cmd
= NL80211_CMD_DEL_TX_TS
,
15594 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15595 .doit
= nl80211_del_tx_ts
,
15596 .flags
= GENL_UNS_ADMIN_PERM
,
15597 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15598 NL80211_FLAG_NEED_RTNL
,
15601 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
15602 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15603 .doit
= nl80211_tdls_channel_switch
,
15604 .flags
= GENL_UNS_ADMIN_PERM
,
15605 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15606 NL80211_FLAG_NEED_RTNL
,
15609 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
15610 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15611 .doit
= nl80211_tdls_cancel_channel_switch
,
15612 .flags
= GENL_UNS_ADMIN_PERM
,
15613 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15614 NL80211_FLAG_NEED_RTNL
,
15617 .cmd
= NL80211_CMD_SET_MULTICAST_TO_UNICAST
,
15618 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15619 .doit
= nl80211_set_multicast_to_unicast
,
15620 .flags
= GENL_UNS_ADMIN_PERM
,
15621 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15622 NL80211_FLAG_NEED_RTNL
,
15625 .cmd
= NL80211_CMD_SET_PMK
,
15626 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15627 .doit
= nl80211_set_pmk
,
15628 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15629 NL80211_FLAG_NEED_RTNL
|
15630 NL80211_FLAG_CLEAR_SKB
,
15633 .cmd
= NL80211_CMD_DEL_PMK
,
15634 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15635 .doit
= nl80211_del_pmk
,
15636 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15637 NL80211_FLAG_NEED_RTNL
,
15640 .cmd
= NL80211_CMD_EXTERNAL_AUTH
,
15641 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15642 .doit
= nl80211_external_auth
,
15643 .flags
= GENL_ADMIN_PERM
,
15644 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15645 NL80211_FLAG_NEED_RTNL
,
15648 .cmd
= NL80211_CMD_CONTROL_PORT_FRAME
,
15649 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15650 .doit
= nl80211_tx_control_port
,
15651 .flags
= GENL_UNS_ADMIN_PERM
,
15652 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15653 NL80211_FLAG_NEED_RTNL
,
15656 .cmd
= NL80211_CMD_GET_FTM_RESPONDER_STATS
,
15657 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15658 .doit
= nl80211_get_ftm_responder_stats
,
15659 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15660 NL80211_FLAG_NEED_RTNL
,
15663 .cmd
= NL80211_CMD_PEER_MEASUREMENT_START
,
15664 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15665 .doit
= nl80211_pmsr_start
,
15666 .flags
= GENL_UNS_ADMIN_PERM
,
15667 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
15668 NL80211_FLAG_NEED_RTNL
,
15671 .cmd
= NL80211_CMD_NOTIFY_RADAR
,
15672 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15673 .doit
= nl80211_notify_radar_detection
,
15674 .flags
= GENL_UNS_ADMIN_PERM
,
15675 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15676 NL80211_FLAG_NEED_RTNL
,
15679 .cmd
= NL80211_CMD_UPDATE_OWE_INFO
,
15680 .doit
= nl80211_update_owe_info
,
15681 .flags
= GENL_ADMIN_PERM
,
15682 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15683 NL80211_FLAG_NEED_RTNL
,
15686 .cmd
= NL80211_CMD_PROBE_MESH_LINK
,
15687 .doit
= nl80211_probe_mesh_link
,
15688 .flags
= GENL_UNS_ADMIN_PERM
,
15689 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
15690 NL80211_FLAG_NEED_RTNL
,
15693 .cmd
= NL80211_CMD_SET_TID_CONFIG
,
15694 .doit
= nl80211_set_tid_config
,
15695 .flags
= GENL_UNS_ADMIN_PERM
,
15696 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
15697 NL80211_FLAG_NEED_RTNL
,
15700 .cmd
= NL80211_CMD_SET_SAR_SPECS
,
15701 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
15702 .doit
= nl80211_set_sar_specs
,
15703 .flags
= GENL_UNS_ADMIN_PERM
,
15704 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
15705 NL80211_FLAG_NEED_RTNL
,
15709 static struct genl_family nl80211_fam __ro_after_init
= {
15710 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
15711 .hdrsize
= 0, /* no private header */
15712 .version
= 1, /* no particular meaning now */
15713 .maxattr
= NL80211_ATTR_MAX
,
15714 .policy
= nl80211_policy
,
15716 .pre_doit
= nl80211_pre_doit
,
15717 .post_doit
= nl80211_post_doit
,
15718 .module
= THIS_MODULE
,
15719 .ops
= nl80211_ops
,
15720 .n_ops
= ARRAY_SIZE(nl80211_ops
),
15721 .small_ops
= nl80211_small_ops
,
15722 .n_small_ops
= ARRAY_SIZE(nl80211_small_ops
),
15723 .mcgrps
= nl80211_mcgrps
,
15724 .n_mcgrps
= ARRAY_SIZE(nl80211_mcgrps
),
15725 .parallel_ops
= true,
15728 /* notification functions */
15730 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
15731 enum nl80211_commands cmd
)
15733 struct sk_buff
*msg
;
15734 struct nl80211_dump_wiphy_state state
= {};
15736 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
15737 cmd
!= NL80211_CMD_DEL_WIPHY
);
15739 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15743 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
15748 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15749 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
15752 void nl80211_notify_iface(struct cfg80211_registered_device
*rdev
,
15753 struct wireless_dev
*wdev
,
15754 enum nl80211_commands cmd
)
15756 struct sk_buff
*msg
;
15758 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15762 if (nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
, cmd
) < 0) {
15767 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15768 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
15771 static int nl80211_add_scan_req(struct sk_buff
*msg
,
15772 struct cfg80211_registered_device
*rdev
)
15774 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
15775 struct nlattr
*nest
;
15777 struct cfg80211_scan_info
*info
;
15782 nest
= nla_nest_start_noflag(msg
, NL80211_ATTR_SCAN_SSIDS
);
15784 goto nla_put_failure
;
15785 for (i
= 0; i
< req
->n_ssids
; i
++) {
15786 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
15787 goto nla_put_failure
;
15789 nla_nest_end(msg
, nest
);
15791 if (req
->flags
& NL80211_SCAN_FLAG_FREQ_KHZ
) {
15792 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQ_KHZ
);
15794 goto nla_put_failure
;
15795 for (i
= 0; i
< req
->n_channels
; i
++) {
15796 if (nla_put_u32(msg
, i
,
15797 ieee80211_channel_to_khz(req
->channels
[i
])))
15798 goto nla_put_failure
;
15800 nla_nest_end(msg
, nest
);
15802 nest
= nla_nest_start_noflag(msg
,
15803 NL80211_ATTR_SCAN_FREQUENCIES
);
15805 goto nla_put_failure
;
15806 for (i
= 0; i
< req
->n_channels
; i
++) {
15807 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
15808 goto nla_put_failure
;
15810 nla_nest_end(msg
, nest
);
15814 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
15815 goto nla_put_failure
;
15818 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
15819 goto nla_put_failure
;
15821 info
= rdev
->int_scan_req
? &rdev
->int_scan_req
->info
:
15822 &rdev
->scan_req
->info
;
15823 if (info
->scan_start_tsf
&&
15824 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
15825 info
->scan_start_tsf
, NL80211_BSS_PAD
) ||
15826 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
15828 goto nla_put_failure
;
15835 static int nl80211_prep_scan_msg(struct sk_buff
*msg
,
15836 struct cfg80211_registered_device
*rdev
,
15837 struct wireless_dev
*wdev
,
15838 u32 portid
, u32 seq
, int flags
,
15843 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
15847 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15848 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
15849 wdev
->netdev
->ifindex
)) ||
15850 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15852 goto nla_put_failure
;
15854 /* ignore errors and send incomplete event anyway */
15855 nl80211_add_scan_req(msg
, rdev
);
15857 genlmsg_end(msg
, hdr
);
15861 genlmsg_cancel(msg
, hdr
);
15866 nl80211_prep_sched_scan_msg(struct sk_buff
*msg
,
15867 struct cfg80211_sched_scan_request
*req
, u32 cmd
)
15871 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
15875 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
,
15876 wiphy_to_rdev(req
->wiphy
)->wiphy_idx
) ||
15877 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, req
->dev
->ifindex
) ||
15878 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, req
->reqid
,
15880 goto nla_put_failure
;
15882 genlmsg_end(msg
, hdr
);
15886 genlmsg_cancel(msg
, hdr
);
15890 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
15891 struct wireless_dev
*wdev
)
15893 struct sk_buff
*msg
;
15895 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15899 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
15900 NL80211_CMD_TRIGGER_SCAN
) < 0) {
15905 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15906 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
15909 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
15910 struct wireless_dev
*wdev
, bool aborted
)
15912 struct sk_buff
*msg
;
15914 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15918 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
15919 aborted
? NL80211_CMD_SCAN_ABORTED
:
15920 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
15928 /* send message created by nl80211_build_scan_msg() */
15929 void nl80211_send_scan_msg(struct cfg80211_registered_device
*rdev
,
15930 struct sk_buff
*msg
)
15935 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15936 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
15939 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request
*req
, u32 cmd
)
15941 struct sk_buff
*msg
;
15943 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15947 if (nl80211_prep_sched_scan_msg(msg
, req
, cmd
) < 0) {
15952 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(req
->wiphy
), msg
, 0,
15953 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
15956 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
15957 struct regulatory_request
*request
)
15959 /* Userspace can always count this one always being set */
15960 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
15961 goto nla_put_failure
;
15963 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
15964 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15965 NL80211_REGDOM_TYPE_WORLD
))
15966 goto nla_put_failure
;
15967 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
15968 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15969 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
15970 goto nla_put_failure
;
15971 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
15972 request
->intersect
) {
15973 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15974 NL80211_REGDOM_TYPE_INTERSECTION
))
15975 goto nla_put_failure
;
15977 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
15978 NL80211_REGDOM_TYPE_COUNTRY
) ||
15979 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
15981 goto nla_put_failure
;
15984 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
15985 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
15988 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
15989 goto nla_put_failure
;
15992 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
15993 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
15994 goto nla_put_failure
;
16004 * This can happen on global regulatory changes or device specific settings
16005 * based on custom regulatory domains.
16007 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
16008 struct regulatory_request
*request
)
16010 struct sk_buff
*msg
;
16013 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
16017 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
16019 goto nla_put_failure
;
16021 if (!nl80211_reg_change_event_fill(msg
, request
))
16022 goto nla_put_failure
;
16024 genlmsg_end(msg
, hdr
);
16027 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
16028 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
16037 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
16038 struct net_device
*netdev
,
16039 const u8
*buf
, size_t len
,
16040 enum nl80211_commands cmd
, gfp_t gfp
,
16041 int uapsd_queues
, const u8
*req_ies
,
16042 size_t req_ies_len
, bool reconnect
)
16044 struct sk_buff
*msg
;
16047 msg
= nlmsg_new(100 + len
+ req_ies_len
, gfp
);
16051 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
16057 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16058 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16059 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
16061 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ies_len
, req_ies
)))
16062 goto nla_put_failure
;
16064 if (reconnect
&& nla_put_flag(msg
, NL80211_ATTR_RECONNECT_REQUESTED
))
16065 goto nla_put_failure
;
16067 if (uapsd_queues
>= 0) {
16068 struct nlattr
*nla_wmm
=
16069 nla_nest_start_noflag(msg
, NL80211_ATTR_STA_WME
);
16071 goto nla_put_failure
;
16073 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
16075 goto nla_put_failure
;
16077 nla_nest_end(msg
, nla_wmm
);
16080 genlmsg_end(msg
, hdr
);
16082 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16083 NL80211_MCGRP_MLME
, gfp
);
16090 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
16091 struct net_device
*netdev
, const u8
*buf
,
16092 size_t len
, gfp_t gfp
)
16094 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
16095 NL80211_CMD_AUTHENTICATE
, gfp
, -1, NULL
, 0,
16099 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
16100 struct net_device
*netdev
, const u8
*buf
,
16101 size_t len
, gfp_t gfp
, int uapsd_queues
,
16102 const u8
*req_ies
, size_t req_ies_len
)
16104 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
16105 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
,
16106 req_ies
, req_ies_len
, false);
16109 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
16110 struct net_device
*netdev
, const u8
*buf
,
16111 size_t len
, bool reconnect
, gfp_t gfp
)
16113 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
16114 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1, NULL
, 0,
16118 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
16119 struct net_device
*netdev
, const u8
*buf
,
16120 size_t len
, bool reconnect
, gfp_t gfp
)
16122 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
16123 NL80211_CMD_DISASSOCIATE
, gfp
, -1, NULL
, 0,
16127 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
16130 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16131 struct wiphy
*wiphy
= wdev
->wiphy
;
16132 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16133 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
16136 if (WARN_ON(len
< 2))
16139 if (ieee80211_is_deauth(mgmt
->frame_control
)) {
16140 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
16141 } else if (ieee80211_is_disassoc(mgmt
->frame_control
)) {
16142 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
16143 } else if (ieee80211_is_beacon(mgmt
->frame_control
)) {
16144 if (wdev
->unprot_beacon_reported
&&
16145 elapsed_jiffies_msecs(wdev
->unprot_beacon_reported
) < 10000)
16147 cmd
= NL80211_CMD_UNPROT_BEACON
;
16148 wdev
->unprot_beacon_reported
= jiffies
;
16153 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
16154 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1,
16157 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
16159 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
16160 struct net_device
*netdev
, int cmd
,
16161 const u8
*addr
, gfp_t gfp
)
16163 struct sk_buff
*msg
;
16166 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16170 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
16176 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16177 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16178 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
16179 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
16180 goto nla_put_failure
;
16182 genlmsg_end(msg
, hdr
);
16184 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16185 NL80211_MCGRP_MLME
, gfp
);
16192 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
16193 struct net_device
*netdev
, const u8
*addr
,
16196 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
16200 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
16201 struct net_device
*netdev
, const u8
*addr
,
16204 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
16208 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
16209 struct net_device
*netdev
,
16210 struct cfg80211_connect_resp_params
*cr
,
16213 struct sk_buff
*msg
;
16216 msg
= nlmsg_new(100 + cr
->req_ie_len
+ cr
->resp_ie_len
+
16217 cr
->fils
.kek_len
+ cr
->fils
.pmk_len
+
16218 (cr
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
16222 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
16228 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16229 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16231 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, cr
->bssid
)) ||
16232 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
16233 cr
->status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
16236 (nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
16237 nla_put_u32(msg
, NL80211_ATTR_TIMEOUT_REASON
,
16238 cr
->timeout_reason
))) ||
16240 nla_put(msg
, NL80211_ATTR_REQ_IE
, cr
->req_ie_len
, cr
->req_ie
)) ||
16242 nla_put(msg
, NL80211_ATTR_RESP_IE
, cr
->resp_ie_len
,
16244 (cr
->fils
.update_erp_next_seq_num
&&
16245 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
16246 cr
->fils
.erp_next_seq_num
)) ||
16247 (cr
->status
== WLAN_STATUS_SUCCESS
&&
16249 nla_put(msg
, NL80211_ATTR_FILS_KEK
, cr
->fils
.kek_len
,
16252 nla_put(msg
, NL80211_ATTR_PMK
, cr
->fils
.pmk_len
, cr
->fils
.pmk
)) ||
16254 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, cr
->fils
.pmkid
)))))
16255 goto nla_put_failure
;
16257 genlmsg_end(msg
, hdr
);
16259 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16260 NL80211_MCGRP_MLME
, gfp
);
16267 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
16268 struct net_device
*netdev
,
16269 struct cfg80211_roam_info
*info
, gfp_t gfp
)
16271 struct sk_buff
*msg
;
16273 const u8
*bssid
= info
->bss
? info
->bss
->bssid
: info
->bssid
;
16275 msg
= nlmsg_new(100 + info
->req_ie_len
+ info
->resp_ie_len
+
16276 info
->fils
.kek_len
+ info
->fils
.pmk_len
+
16277 (info
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
16281 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
16287 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16288 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16289 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
16291 nla_put(msg
, NL80211_ATTR_REQ_IE
, info
->req_ie_len
,
16294 nla_put(msg
, NL80211_ATTR_RESP_IE
, info
->resp_ie_len
,
16296 (info
->fils
.update_erp_next_seq_num
&&
16297 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
16298 info
->fils
.erp_next_seq_num
)) ||
16300 nla_put(msg
, NL80211_ATTR_FILS_KEK
, info
->fils
.kek_len
,
16301 info
->fils
.kek
)) ||
16303 nla_put(msg
, NL80211_ATTR_PMK
, info
->fils
.pmk_len
, info
->fils
.pmk
)) ||
16304 (info
->fils
.pmkid
&&
16305 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, info
->fils
.pmkid
)))
16306 goto nla_put_failure
;
16308 genlmsg_end(msg
, hdr
);
16310 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16311 NL80211_MCGRP_MLME
, gfp
);
16318 void nl80211_send_port_authorized(struct cfg80211_registered_device
*rdev
,
16319 struct net_device
*netdev
, const u8
*bssid
)
16321 struct sk_buff
*msg
;
16324 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
16328 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED
);
16334 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16335 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16336 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
16337 goto nla_put_failure
;
16339 genlmsg_end(msg
, hdr
);
16341 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16342 NL80211_MCGRP_MLME
, GFP_KERNEL
);
16349 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
16350 struct net_device
*netdev
, u16 reason
,
16351 const u8
*ie
, size_t ie_len
, bool from_ap
)
16353 struct sk_buff
*msg
;
16356 msg
= nlmsg_new(100 + ie_len
, GFP_KERNEL
);
16360 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
16366 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16367 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16369 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
16371 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
16372 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
16373 goto nla_put_failure
;
16375 genlmsg_end(msg
, hdr
);
16377 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16378 NL80211_MCGRP_MLME
, GFP_KERNEL
);
16385 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
16386 struct net_device
*netdev
, const u8
*bssid
,
16389 struct sk_buff
*msg
;
16392 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16396 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
16402 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16403 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16404 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
16405 goto nla_put_failure
;
16407 genlmsg_end(msg
, hdr
);
16409 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16410 NL80211_MCGRP_MLME
, gfp
);
16417 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
16418 const u8
*ie
, u8 ie_len
,
16419 int sig_dbm
, gfp_t gfp
)
16421 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16422 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16423 struct sk_buff
*msg
;
16426 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
16429 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
16431 msg
= nlmsg_new(100 + ie_len
, gfp
);
16435 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
16441 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16442 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16443 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
16445 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)) ||
16447 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)))
16448 goto nla_put_failure
;
16450 genlmsg_end(msg
, hdr
);
16452 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16453 NL80211_MCGRP_MLME
, gfp
);
16459 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
16461 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
16462 struct net_device
*netdev
, const u8
*addr
,
16463 enum nl80211_key_type key_type
, int key_id
,
16464 const u8
*tsc
, gfp_t gfp
)
16466 struct sk_buff
*msg
;
16469 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16473 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
16479 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16480 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16481 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
16482 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
16484 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
16485 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
16486 goto nla_put_failure
;
16488 genlmsg_end(msg
, hdr
);
16490 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16491 NL80211_MCGRP_MLME
, gfp
);
16498 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
16499 struct ieee80211_channel
*channel_before
,
16500 struct ieee80211_channel
*channel_after
)
16502 struct sk_buff
*msg
;
16504 struct nlattr
*nl_freq
;
16506 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
16510 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
16517 * Since we are applying the beacon hint to a wiphy we know its
16518 * wiphy_idx is valid
16520 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
16521 goto nla_put_failure
;
16524 nl_freq
= nla_nest_start_noflag(msg
, NL80211_ATTR_FREQ_BEFORE
);
16526 goto nla_put_failure
;
16528 if (nl80211_msg_put_channel(msg
, wiphy
, channel_before
, false))
16529 goto nla_put_failure
;
16530 nla_nest_end(msg
, nl_freq
);
16533 nl_freq
= nla_nest_start_noflag(msg
, NL80211_ATTR_FREQ_AFTER
);
16535 goto nla_put_failure
;
16537 if (nl80211_msg_put_channel(msg
, wiphy
, channel_after
, false))
16538 goto nla_put_failure
;
16539 nla_nest_end(msg
, nl_freq
);
16541 genlmsg_end(msg
, hdr
);
16544 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
16545 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
16554 static void nl80211_send_remain_on_chan_event(
16555 int cmd
, struct cfg80211_registered_device
*rdev
,
16556 struct wireless_dev
*wdev
, u64 cookie
,
16557 struct ieee80211_channel
*chan
,
16558 unsigned int duration
, gfp_t gfp
)
16560 struct sk_buff
*msg
;
16563 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16567 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
16573 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16574 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
16575 wdev
->netdev
->ifindex
)) ||
16576 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16577 NL80211_ATTR_PAD
) ||
16578 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
16579 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
16580 NL80211_CHAN_NO_HT
) ||
16581 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
16583 goto nla_put_failure
;
16585 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
16586 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
16587 goto nla_put_failure
;
16589 genlmsg_end(msg
, hdr
);
16591 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16592 NL80211_MCGRP_MLME
, gfp
);
16599 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
16600 struct ieee80211_channel
*chan
,
16601 unsigned int duration
, gfp_t gfp
)
16603 struct wiphy
*wiphy
= wdev
->wiphy
;
16604 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16606 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
16607 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
16608 rdev
, wdev
, cookie
, chan
,
16611 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
16613 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
16614 struct ieee80211_channel
*chan
,
16617 struct wiphy
*wiphy
= wdev
->wiphy
;
16618 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16620 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
16621 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
16622 rdev
, wdev
, cookie
, chan
, 0, gfp
);
16624 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
16626 void cfg80211_tx_mgmt_expired(struct wireless_dev
*wdev
, u64 cookie
,
16627 struct ieee80211_channel
*chan
,
16630 struct wiphy
*wiphy
= wdev
->wiphy
;
16631 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16633 trace_cfg80211_tx_mgmt_expired(wdev
, cookie
, chan
);
16634 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL
,
16635 rdev
, wdev
, cookie
, chan
, 0, gfp
);
16637 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired
);
16639 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
16640 struct station_info
*sinfo
, gfp_t gfp
)
16642 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
16643 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16644 struct sk_buff
*msg
;
16646 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
16648 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16652 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
16653 rdev
, dev
, mac_addr
, sinfo
) < 0) {
16658 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16659 NL80211_MCGRP_MLME
, gfp
);
16661 EXPORT_SYMBOL(cfg80211_new_sta
);
16663 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
16664 struct station_info
*sinfo
, gfp_t gfp
)
16666 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
16667 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16668 struct sk_buff
*msg
;
16669 struct station_info empty_sinfo
= {};
16672 sinfo
= &empty_sinfo
;
16674 trace_cfg80211_del_sta(dev
, mac_addr
);
16676 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16678 cfg80211_sinfo_release_content(sinfo
);
16682 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
16683 rdev
, dev
, mac_addr
, sinfo
) < 0) {
16688 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16689 NL80211_MCGRP_MLME
, gfp
);
16691 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
16693 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
16694 enum nl80211_connect_failed_reason reason
,
16697 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
16698 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16699 struct sk_buff
*msg
;
16702 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
16706 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
16712 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16713 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
16714 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
16715 goto nla_put_failure
;
16717 genlmsg_end(msg
, hdr
);
16719 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16720 NL80211_MCGRP_MLME
, gfp
);
16726 EXPORT_SYMBOL(cfg80211_conn_failed
);
16728 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
16729 const u8
*addr
, gfp_t gfp
)
16731 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16732 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16733 struct sk_buff
*msg
;
16735 u32 nlportid
= READ_ONCE(wdev
->ap_unexpected_nlportid
);
16740 msg
= nlmsg_new(100, gfp
);
16744 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
16750 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16751 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16752 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
16753 goto nla_put_failure
;
16755 genlmsg_end(msg
, hdr
);
16756 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
16764 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
16765 const u8
*addr
, gfp_t gfp
)
16767 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16770 trace_cfg80211_rx_spurious_frame(dev
, addr
);
16772 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
16773 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
16774 trace_cfg80211_return_bool(false);
16777 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
16779 trace_cfg80211_return_bool(ret
);
16782 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
16784 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
16785 const u8
*addr
, gfp_t gfp
)
16787 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16790 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
16792 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
16793 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
16794 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
16795 trace_cfg80211_return_bool(false);
16798 ret
= __nl80211_unexpected_frame(dev
,
16799 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
16801 trace_cfg80211_return_bool(ret
);
16804 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
16806 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
16807 struct wireless_dev
*wdev
, u32 nlportid
,
16808 int freq
, int sig_dbm
,
16809 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
16811 struct net_device
*netdev
= wdev
->netdev
;
16812 struct sk_buff
*msg
;
16815 msg
= nlmsg_new(100 + len
, gfp
);
16819 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
16825 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16826 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
16827 netdev
->ifindex
)) ||
16828 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16829 NL80211_ATTR_PAD
) ||
16830 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, KHZ_TO_MHZ(freq
)) ||
16831 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_OFFSET
, freq
% 1000) ||
16833 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
16834 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
16836 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
16837 goto nla_put_failure
;
16839 genlmsg_end(msg
, hdr
);
16841 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
16848 static void nl80211_frame_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
16849 const u8
*buf
, size_t len
, bool ack
,
16850 gfp_t gfp
, enum nl80211_commands command
)
16852 struct wiphy
*wiphy
= wdev
->wiphy
;
16853 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16854 struct net_device
*netdev
= wdev
->netdev
;
16855 struct sk_buff
*msg
;
16858 if (command
== NL80211_CMD_FRAME_TX_STATUS
)
16859 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
16861 trace_cfg80211_control_port_tx_status(wdev
, cookie
, ack
);
16863 msg
= nlmsg_new(100 + len
, gfp
);
16867 hdr
= nl80211hdr_put(msg
, 0, 0, 0, command
);
16873 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16874 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
16875 netdev
->ifindex
)) ||
16876 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16877 NL80211_ATTR_PAD
) ||
16878 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
16879 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
16880 NL80211_ATTR_PAD
) ||
16881 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
16882 goto nla_put_failure
;
16884 genlmsg_end(msg
, hdr
);
16886 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16887 NL80211_MCGRP_MLME
, gfp
);
16894 void cfg80211_control_port_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
16895 const u8
*buf
, size_t len
, bool ack
,
16898 nl80211_frame_tx_status(wdev
, cookie
, buf
, len
, ack
, gfp
,
16899 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS
);
16901 EXPORT_SYMBOL(cfg80211_control_port_tx_status
);
16903 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
16904 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
16906 nl80211_frame_tx_status(wdev
, cookie
, buf
, len
, ack
, gfp
,
16907 NL80211_CMD_FRAME_TX_STATUS
);
16909 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
16911 static int __nl80211_rx_control_port(struct net_device
*dev
,
16912 struct sk_buff
*skb
,
16913 bool unencrypted
, gfp_t gfp
)
16915 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16916 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16917 struct ethhdr
*ehdr
= eth_hdr(skb
);
16918 const u8
*addr
= ehdr
->h_source
;
16919 u16 proto
= be16_to_cpu(skb
->protocol
);
16920 struct sk_buff
*msg
;
16922 struct nlattr
*frame
;
16924 u32 nlportid
= READ_ONCE(wdev
->conn_owner_nlportid
);
16929 msg
= nlmsg_new(100 + skb
->len
, gfp
);
16933 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME
);
16939 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16940 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16941 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16942 NL80211_ATTR_PAD
) ||
16943 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
16944 nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, proto
) ||
16945 (unencrypted
&& nla_put_flag(msg
,
16946 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
16947 goto nla_put_failure
;
16949 frame
= nla_reserve(msg
, NL80211_ATTR_FRAME
, skb
->len
);
16951 goto nla_put_failure
;
16953 skb_copy_bits(skb
, 0, nla_data(frame
), skb
->len
);
16954 genlmsg_end(msg
, hdr
);
16956 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
16963 bool cfg80211_rx_control_port(struct net_device
*dev
,
16964 struct sk_buff
*skb
, bool unencrypted
)
16968 trace_cfg80211_rx_control_port(dev
, skb
, unencrypted
);
16969 ret
= __nl80211_rx_control_port(dev
, skb
, unencrypted
, GFP_ATOMIC
);
16970 trace_cfg80211_return_bool(ret
== 0);
16973 EXPORT_SYMBOL(cfg80211_rx_control_port
);
16975 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
16976 const char *mac
, gfp_t gfp
)
16978 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16979 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16980 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16986 cb
= (void **)msg
->cb
;
16988 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
16994 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16995 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
16996 goto nla_put_failure
;
16998 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
16999 goto nla_put_failure
;
17001 cb
[1] = nla_nest_start_noflag(msg
, NL80211_ATTR_CQM
);
17003 goto nla_put_failure
;
17013 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
17015 void **cb
= (void **)msg
->cb
;
17016 struct cfg80211_registered_device
*rdev
= cb
[2];
17018 nla_nest_end(msg
, cb
[1]);
17019 genlmsg_end(msg
, cb
[0]);
17021 memset(msg
->cb
, 0, sizeof(msg
->cb
));
17023 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17024 NL80211_MCGRP_MLME
, gfp
);
17027 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
17028 enum nl80211_cqm_rssi_threshold_event rssi_event
,
17029 s32 rssi_level
, gfp_t gfp
)
17031 struct sk_buff
*msg
;
17032 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17033 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17035 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
, rssi_level
);
17037 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
17038 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
17041 if (wdev
->cqm_config
) {
17042 wdev
->cqm_config
->last_rssi_event_value
= rssi_level
;
17044 cfg80211_cqm_rssi_update(rdev
, dev
);
17046 if (rssi_level
== 0)
17047 rssi_level
= wdev
->cqm_config
->last_rssi_event_value
;
17050 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
17054 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
17056 goto nla_put_failure
;
17058 if (rssi_level
&& nla_put_s32(msg
, NL80211_ATTR_CQM_RSSI_LEVEL
,
17060 goto nla_put_failure
;
17062 cfg80211_send_cqm(msg
, gfp
);
17069 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
17071 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
17072 const u8
*peer
, u32 num_packets
,
17073 u32 rate
, u32 intvl
, gfp_t gfp
)
17075 struct sk_buff
*msg
;
17077 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
17081 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
17082 goto nla_put_failure
;
17084 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
17085 goto nla_put_failure
;
17087 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
17088 goto nla_put_failure
;
17090 cfg80211_send_cqm(msg
, gfp
);
17096 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
17098 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
17099 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
17101 struct sk_buff
*msg
;
17103 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
17105 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
17109 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
17110 goto nla_put_failure
;
17112 cfg80211_send_cqm(msg
, gfp
);
17118 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
17120 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
17122 struct sk_buff
*msg
;
17124 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
17128 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
17129 goto nla_put_failure
;
17131 cfg80211_send_cqm(msg
, gfp
);
17137 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
17139 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
17140 struct net_device
*netdev
, const u8
*bssid
,
17141 const u8
*replay_ctr
, gfp_t gfp
)
17143 struct sk_buff
*msg
;
17144 struct nlattr
*rekey_attr
;
17147 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17151 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
17157 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17158 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
17159 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
17160 goto nla_put_failure
;
17162 rekey_attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_REKEY_DATA
);
17164 goto nla_put_failure
;
17166 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
17167 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
17168 goto nla_put_failure
;
17170 nla_nest_end(msg
, rekey_attr
);
17172 genlmsg_end(msg
, hdr
);
17174 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17175 NL80211_MCGRP_MLME
, gfp
);
17182 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
17183 const u8
*replay_ctr
, gfp_t gfp
)
17185 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17186 struct wiphy
*wiphy
= wdev
->wiphy
;
17187 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17189 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
17190 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
17192 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
17195 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
17196 struct net_device
*netdev
, int index
,
17197 const u8
*bssid
, bool preauth
, gfp_t gfp
)
17199 struct sk_buff
*msg
;
17200 struct nlattr
*attr
;
17203 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17207 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
17213 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17214 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
17215 goto nla_put_failure
;
17217 attr
= nla_nest_start_noflag(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
17219 goto nla_put_failure
;
17221 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
17222 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
17224 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
17225 goto nla_put_failure
;
17227 nla_nest_end(msg
, attr
);
17229 genlmsg_end(msg
, hdr
);
17231 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17232 NL80211_MCGRP_MLME
, gfp
);
17239 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
17240 const u8
*bssid
, bool preauth
, gfp_t gfp
)
17242 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17243 struct wiphy
*wiphy
= wdev
->wiphy
;
17244 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17246 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
17247 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
17249 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
17251 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
17252 struct net_device
*netdev
,
17253 struct cfg80211_chan_def
*chandef
,
17255 enum nl80211_commands notif
,
17256 u8 count
, bool quiet
)
17258 struct sk_buff
*msg
;
17261 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17265 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
17271 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
17272 goto nla_put_failure
;
17274 if (nl80211_send_chandef(msg
, chandef
))
17275 goto nla_put_failure
;
17277 if (notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) {
17278 if (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
))
17279 goto nla_put_failure
;
17281 nla_put_flag(msg
, NL80211_ATTR_CH_SWITCH_BLOCK_TX
))
17282 goto nla_put_failure
;
17285 genlmsg_end(msg
, hdr
);
17287 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17288 NL80211_MCGRP_MLME
, gfp
);
17295 void cfg80211_ch_switch_notify(struct net_device
*dev
,
17296 struct cfg80211_chan_def
*chandef
)
17298 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17299 struct wiphy
*wiphy
= wdev
->wiphy
;
17300 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17302 ASSERT_WDEV_LOCK(wdev
);
17304 trace_cfg80211_ch_switch_notify(dev
, chandef
);
17306 wdev
->chandef
= *chandef
;
17307 wdev
->preset_chandef
= *chandef
;
17309 if (wdev
->iftype
== NL80211_IFTYPE_STATION
&&
17310 !WARN_ON(!wdev
->current_bss
))
17311 cfg80211_update_assoc_bss_entry(wdev
, chandef
->chan
);
17313 cfg80211_sched_dfs_chan_update(rdev
);
17315 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
17316 NL80211_CMD_CH_SWITCH_NOTIFY
, 0, false);
17318 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
17320 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
17321 struct cfg80211_chan_def
*chandef
,
17322 u8 count
, bool quiet
)
17324 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17325 struct wiphy
*wiphy
= wdev
->wiphy
;
17326 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17328 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
17330 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
17331 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
,
17334 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
17337 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
17338 const struct cfg80211_chan_def
*chandef
,
17339 enum nl80211_radar_event event
,
17340 struct net_device
*netdev
, gfp_t gfp
)
17342 struct sk_buff
*msg
;
17345 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17349 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
17355 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
17356 goto nla_put_failure
;
17358 /* NOP and radar events don't need a netdev parameter */
17360 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
17362 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
17363 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
17365 goto nla_put_failure
;
17368 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
17369 goto nla_put_failure
;
17371 if (nl80211_send_chandef(msg
, chandef
))
17372 goto nla_put_failure
;
17374 genlmsg_end(msg
, hdr
);
17376 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17377 NL80211_MCGRP_MLME
, gfp
);
17384 void cfg80211_sta_opmode_change_notify(struct net_device
*dev
, const u8
*mac
,
17385 struct sta_opmode_info
*sta_opmode
,
17388 struct sk_buff
*msg
;
17389 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17390 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17396 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17400 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED
);
17406 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
17407 goto nla_put_failure
;
17409 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
17410 goto nla_put_failure
;
17412 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
17413 goto nla_put_failure
;
17415 if ((sta_opmode
->changed
& STA_OPMODE_SMPS_MODE_CHANGED
) &&
17416 nla_put_u8(msg
, NL80211_ATTR_SMPS_MODE
, sta_opmode
->smps_mode
))
17417 goto nla_put_failure
;
17419 if ((sta_opmode
->changed
& STA_OPMODE_MAX_BW_CHANGED
) &&
17420 nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, sta_opmode
->bw
))
17421 goto nla_put_failure
;
17423 if ((sta_opmode
->changed
& STA_OPMODE_N_SS_CHANGED
) &&
17424 nla_put_u8(msg
, NL80211_ATTR_NSS
, sta_opmode
->rx_nss
))
17425 goto nla_put_failure
;
17427 genlmsg_end(msg
, hdr
);
17429 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17430 NL80211_MCGRP_MLME
, gfp
);
17437 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify
);
17439 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
17440 u64 cookie
, bool acked
, s32 ack_signal
,
17441 bool is_valid_ack_signal
, gfp_t gfp
)
17443 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17444 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17445 struct sk_buff
*msg
;
17448 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
17450 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17455 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
17461 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17462 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
17463 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
17464 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
17465 NL80211_ATTR_PAD
) ||
17466 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)) ||
17467 (is_valid_ack_signal
&& nla_put_s32(msg
, NL80211_ATTR_ACK_SIGNAL
,
17469 goto nla_put_failure
;
17471 genlmsg_end(msg
, hdr
);
17473 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17474 NL80211_MCGRP_MLME
, gfp
);
17480 EXPORT_SYMBOL(cfg80211_probe_status
);
17482 void cfg80211_report_obss_beacon_khz(struct wiphy
*wiphy
, const u8
*frame
,
17483 size_t len
, int freq
, int sig_dbm
)
17485 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17486 struct sk_buff
*msg
;
17488 struct cfg80211_beacon_registration
*reg
;
17490 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
17492 spin_lock_bh(&rdev
->beacon_registrations_lock
);
17493 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
17494 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
17496 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17500 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
17502 goto nla_put_failure
;
17504 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17506 (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
17507 KHZ_TO_MHZ(freq
)) ||
17508 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_OFFSET
,
17511 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
17512 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
17513 goto nla_put_failure
;
17515 genlmsg_end(msg
, hdr
);
17517 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
17519 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17523 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17526 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz
);
17529 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
17530 struct cfg80211_wowlan_wakeup
*wakeup
)
17532 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
17533 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
17536 nl_results
= nla_nest_start_noflag(msg
,
17537 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
17541 for (i
= 0; i
< nd
->n_matches
; i
++) {
17542 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
17544 nl_match
= nla_nest_start_noflag(msg
, i
);
17548 /* The SSID attribute is optional in nl80211, but for
17549 * simplicity reasons it's always present in the
17550 * cfg80211 structure. If a driver can't pass the
17551 * SSID, that needs to be changed. A zero length SSID
17552 * is still a valid SSID (wildcard), so it cannot be
17553 * used for this purpose.
17555 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
17556 match
->ssid
.ssid
)) {
17557 nla_nest_cancel(msg
, nl_match
);
17561 if (match
->n_channels
) {
17562 nl_freqs
= nla_nest_start_noflag(msg
,
17563 NL80211_ATTR_SCAN_FREQUENCIES
);
17565 nla_nest_cancel(msg
, nl_match
);
17569 for (j
= 0; j
< match
->n_channels
; j
++) {
17570 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
17571 nla_nest_cancel(msg
, nl_freqs
);
17572 nla_nest_cancel(msg
, nl_match
);
17577 nla_nest_end(msg
, nl_freqs
);
17580 nla_nest_end(msg
, nl_match
);
17584 nla_nest_end(msg
, nl_results
);
17588 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
17589 struct cfg80211_wowlan_wakeup
*wakeup
,
17592 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17593 struct sk_buff
*msg
;
17597 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
17600 size
+= wakeup
->packet_present_len
;
17602 msg
= nlmsg_new(size
, gfp
);
17606 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
17610 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17611 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
17615 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
17616 wdev
->netdev
->ifindex
))
17620 struct nlattr
*reasons
;
17622 reasons
= nla_nest_start_noflag(msg
,
17623 NL80211_ATTR_WOWLAN_TRIGGERS
);
17627 if (wakeup
->disconnect
&&
17628 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
17630 if (wakeup
->magic_pkt
&&
17631 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
17633 if (wakeup
->gtk_rekey_failure
&&
17634 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
17636 if (wakeup
->eap_identity_req
&&
17637 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
17639 if (wakeup
->four_way_handshake
&&
17640 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
17642 if (wakeup
->rfkill_release
&&
17643 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
17646 if (wakeup
->pattern_idx
>= 0 &&
17647 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
17648 wakeup
->pattern_idx
))
17651 if (wakeup
->tcp_match
&&
17652 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
17655 if (wakeup
->tcp_connlost
&&
17656 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
17659 if (wakeup
->tcp_nomoretokens
&&
17661 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
17664 if (wakeup
->packet
) {
17665 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
17666 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
17668 if (!wakeup
->packet_80211
) {
17670 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
17672 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
17675 if (wakeup
->packet_len
&&
17676 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
17679 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
17684 if (wakeup
->net_detect
&&
17685 cfg80211_net_detect_results(msg
, wakeup
))
17688 nla_nest_end(msg
, reasons
);
17691 genlmsg_end(msg
, hdr
);
17693 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17694 NL80211_MCGRP_MLME
, gfp
);
17700 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
17703 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
17704 enum nl80211_tdls_operation oper
,
17705 u16 reason_code
, gfp_t gfp
)
17707 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17708 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17709 struct sk_buff
*msg
;
17712 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
17715 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17719 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
17725 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17726 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
17727 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
17728 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
17729 (reason_code
> 0 &&
17730 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
17731 goto nla_put_failure
;
17733 genlmsg_end(msg
, hdr
);
17735 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17736 NL80211_MCGRP_MLME
, gfp
);
17742 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
17744 static int nl80211_netlink_notify(struct notifier_block
* nb
,
17745 unsigned long state
,
17748 struct netlink_notify
*notify
= _notify
;
17749 struct cfg80211_registered_device
*rdev
;
17750 struct wireless_dev
*wdev
;
17751 struct cfg80211_beacon_registration
*reg
, *tmp
;
17753 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
17754 return NOTIFY_DONE
;
17758 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
17759 struct cfg80211_sched_scan_request
*sched_scan_req
;
17761 list_for_each_entry_rcu(sched_scan_req
,
17762 &rdev
->sched_scan_req_list
,
17764 if (sched_scan_req
->owner_nlportid
== notify
->portid
) {
17765 sched_scan_req
->nl_owner_dead
= true;
17766 schedule_work(&rdev
->sched_scan_stop_wk
);
17770 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
17771 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
17773 if (wdev
->owner_nlportid
== notify
->portid
) {
17774 wdev
->nl_owner_dead
= true;
17775 schedule_work(&rdev
->destroy_work
);
17776 } else if (wdev
->conn_owner_nlportid
== notify
->portid
) {
17777 schedule_work(&wdev
->disconnect_wk
);
17780 cfg80211_release_pmsr(wdev
, notify
->portid
);
17783 spin_lock_bh(&rdev
->beacon_registrations_lock
);
17784 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
17786 if (reg
->nlportid
== notify
->portid
) {
17787 list_del(®
->list
);
17792 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
17798 * It is possible that the user space process that is controlling the
17799 * indoor setting disappeared, so notify the regulatory core.
17801 regulatory_netlink_notify(notify
->portid
);
17805 static struct notifier_block nl80211_netlink_notifier
= {
17806 .notifier_call
= nl80211_netlink_notify
,
17809 void cfg80211_ft_event(struct net_device
*netdev
,
17810 struct cfg80211_ft_event_params
*ft_event
)
17812 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
17813 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17814 struct sk_buff
*msg
;
17817 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
17819 if (!ft_event
->target_ap
)
17822 msg
= nlmsg_new(100 + ft_event
->ies_len
+ ft_event
->ric_ies_len
,
17827 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
17831 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17832 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
17833 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
17836 if (ft_event
->ies
&&
17837 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
17839 if (ft_event
->ric_ies
&&
17840 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
17841 ft_event
->ric_ies
))
17844 genlmsg_end(msg
, hdr
);
17846 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17847 NL80211_MCGRP_MLME
, GFP_KERNEL
);
17852 EXPORT_SYMBOL(cfg80211_ft_event
);
17854 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
17856 struct cfg80211_registered_device
*rdev
;
17857 struct sk_buff
*msg
;
17861 rdev
= wiphy_to_rdev(wdev
->wiphy
);
17862 if (!rdev
->crit_proto_nlportid
)
17865 nlportid
= rdev
->crit_proto_nlportid
;
17866 rdev
->crit_proto_nlportid
= 0;
17868 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17872 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
17874 goto nla_put_failure
;
17876 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17877 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
17879 goto nla_put_failure
;
17881 genlmsg_end(msg
, hdr
);
17883 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
17889 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
17891 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
17893 struct wiphy
*wiphy
= wdev
->wiphy
;
17894 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17895 struct sk_buff
*msg
;
17898 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
17902 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
17906 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17907 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
17908 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
17912 genlmsg_end(msg
, hdr
);
17914 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
17915 NL80211_MCGRP_MLME
, GFP_KERNEL
);
17921 int cfg80211_external_auth_request(struct net_device
*dev
,
17922 struct cfg80211_external_auth_params
*params
,
17925 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
17926 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
17927 struct sk_buff
*msg
;
17930 if (!wdev
->conn_owner_nlportid
)
17933 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17937 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH
);
17939 goto nla_put_failure
;
17941 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17942 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
17943 nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, params
->key_mgmt_suite
) ||
17944 nla_put_u32(msg
, NL80211_ATTR_EXTERNAL_AUTH_ACTION
,
17946 nla_put(msg
, NL80211_ATTR_BSSID
, ETH_ALEN
, params
->bssid
) ||
17947 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid
.ssid_len
,
17948 params
->ssid
.ssid
))
17949 goto nla_put_failure
;
17951 genlmsg_end(msg
, hdr
);
17952 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
17953 wdev
->conn_owner_nlportid
);
17960 EXPORT_SYMBOL(cfg80211_external_auth_request
);
17962 void cfg80211_update_owe_info_event(struct net_device
*netdev
,
17963 struct cfg80211_update_owe_info
*owe_info
,
17966 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
17967 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
17968 struct sk_buff
*msg
;
17971 trace_cfg80211_update_owe_info_event(wiphy
, netdev
, owe_info
);
17973 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
17977 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO
);
17979 goto nla_put_failure
;
17981 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
17982 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
17983 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, owe_info
->peer
))
17984 goto nla_put_failure
;
17986 if (!owe_info
->ie_len
||
17987 nla_put(msg
, NL80211_ATTR_IE
, owe_info
->ie_len
, owe_info
->ie
))
17988 goto nla_put_failure
;
17990 genlmsg_end(msg
, hdr
);
17992 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
17993 NL80211_MCGRP_MLME
, gfp
);
17997 genlmsg_cancel(msg
, hdr
);
18000 EXPORT_SYMBOL(cfg80211_update_owe_info_event
);
18002 /* initialisation/exit functions */
18004 int __init
nl80211_init(void)
18008 err
= genl_register_family(&nl80211_fam
);
18012 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
18018 genl_unregister_family(&nl80211_fam
);
18022 void nl80211_exit(void)
18024 netlink_unregister_notifier(&nl80211_netlink_notifier
);
18025 genl_unregister_family(&nl80211_fam
);