2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright 2015-2017 Intel Deutschland GmbH
10 #include <linux/module.h>
11 #include <linux/err.h>
12 #include <linux/slab.h>
13 #include <linux/list.h>
14 #include <linux/if_ether.h>
15 #include <linux/ieee80211.h>
16 #include <linux/nl80211.h>
17 #include <linux/rtnetlink.h>
18 #include <linux/netlink.h>
19 #include <linux/nospec.h>
20 #include <linux/etherdevice.h>
21 #include <net/net_namespace.h>
22 #include <net/genetlink.h>
23 #include <net/cfg80211.h>
25 #include <net/inet_connection_sock.h>
31 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
32 struct genl_info *info,
33 struct cfg80211_crypto_settings *settings,
36 /* the netlink family */
37 static struct genl_family nl80211_fam;
39 /* multicast groups */
40 enum nl80211_multicast_groups {
43 NL80211_MCGRP_REGULATORY,
47 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
50 static const struct genl_multicast_group nl80211_mcgrps[] = {
51 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
52 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
53 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
54 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
55 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
56 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
57 #ifdef CONFIG_NL80211_TESTMODE
58 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
62 /* returns ERR_PTR values */
63 static struct wireless_dev *
64 __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
66 struct cfg80211_registered_device *rdev;
67 struct wireless_dev *result = NULL;
68 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
69 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
76 if (!have_ifidx && !have_wdev_id)
77 return ERR_PTR(-EINVAL);
80 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
82 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
83 wiphy_idx = wdev_id >> 32;
86 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
87 struct wireless_dev *wdev;
89 if (wiphy_net(&rdev->wiphy) != netns)
92 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
95 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
96 if (have_ifidx && wdev->netdev &&
97 wdev->netdev->ifindex == ifidx) {
101 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 return ERR_PTR(-ENODEV);
116 static struct cfg80211_registered_device *
117 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
119 struct cfg80211_registered_device *rdev = NULL, *tmp;
120 struct net_device *netdev;
124 if (!attrs[NL80211_ATTR_WIPHY] &&
125 !attrs[NL80211_ATTR_IFINDEX] &&
126 !attrs[NL80211_ATTR_WDEV])
127 return ERR_PTR(-EINVAL);
129 if (attrs[NL80211_ATTR_WIPHY])
130 rdev = cfg80211_rdev_by_wiphy_idx(
131 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
133 if (attrs[NL80211_ATTR_WDEV]) {
134 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
135 struct wireless_dev *wdev;
138 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
140 /* make sure wdev exists */
141 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
142 if (wdev->identifier != (u32)wdev_id)
151 if (rdev && tmp != rdev)
152 return ERR_PTR(-EINVAL);
157 if (attrs[NL80211_ATTR_IFINDEX]) {
158 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
160 netdev = __dev_get_by_index(netns, ifindex);
162 if (netdev->ieee80211_ptr)
164 netdev->ieee80211_ptr->wiphy);
168 /* not wireless device -- return error */
170 return ERR_PTR(-EINVAL);
172 /* mismatch -- return error */
173 if (rdev && tmp != rdev)
174 return ERR_PTR(-EINVAL);
181 return ERR_PTR(-ENODEV);
183 if (netns != wiphy_net(&rdev->wiphy))
184 return ERR_PTR(-ENODEV);
190 * This function returns a pointer to the driver
191 * that the genl_info item that is passed refers to.
193 * The result of this can be a PTR_ERR and hence must
194 * be checked with IS_ERR() for errors.
196 static struct cfg80211_registered_device *
197 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
199 return __cfg80211_rdev_from_attrs(netns, info->attrs);
202 static int validate_beacon_head(const struct nlattr *attr,
203 struct netlink_ext_ack *extack)
205 const u8 *data = nla_data(attr);
206 unsigned int len = nla_len(attr);
207 const struct element *elem;
208 const struct ieee80211_mgmt *mgmt = (void *)data;
209 unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
215 if (ieee80211_hdrlen(mgmt->frame_control) !=
216 offsetof(struct ieee80211_mgmt, u.beacon))
222 for_each_element(elem, data, len) {
226 if (for_each_element_completed(elem, data, len))
230 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
234 /* policy for the attributes */
235 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
236 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
237 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
239 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
241 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
242 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
243 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
244 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
245 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
247 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
248 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
249 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
250 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
251 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
252 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
254 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
255 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
256 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
258 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
259 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
261 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
262 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
263 .len = WLAN_MAX_KEY_LEN },
264 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
265 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
266 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
267 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
268 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
270 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
271 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
272 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
273 .len = IEEE80211_MAX_DATA_LEN },
274 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
275 .len = IEEE80211_MAX_DATA_LEN },
276 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
277 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
278 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
279 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
280 .len = NL80211_MAX_SUPP_RATES },
281 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
282 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
283 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
284 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_MESH_ID_LEN },
286 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_BINARY,
289 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
290 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
292 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
293 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
294 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
295 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
296 .len = NL80211_MAX_SUPP_RATES },
297 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
299 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
300 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
302 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
304 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
305 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
306 .len = IEEE80211_MAX_DATA_LEN },
307 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
308 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
310 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
311 .len = IEEE80211_MAX_SSID_LEN },
312 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
313 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
314 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
315 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
316 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
317 [NL80211_ATTR_STA_FLAGS2] = {
318 .len = sizeof(struct nl80211_sta_flag_update),
320 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
321 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
322 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
323 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
324 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
325 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
326 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
327 [NL80211_ATTR_PID] = { .type = NLA_U32 },
328 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
329 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
330 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
331 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
332 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
333 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
335 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
336 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
337 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
338 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
339 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
340 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
341 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
342 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
343 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
344 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
345 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
346 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
347 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
348 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
349 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
350 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
351 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
352 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
353 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
354 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
355 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
356 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
357 .len = IEEE80211_MAX_DATA_LEN },
358 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
359 .len = IEEE80211_MAX_DATA_LEN },
360 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
361 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
362 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
363 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
364 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
365 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
366 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
368 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
369 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
370 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
371 .len = IEEE80211_MAX_DATA_LEN },
372 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
373 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
374 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
375 .len = NL80211_HT_CAPABILITY_LEN
377 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
378 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
379 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
380 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
381 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
382 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
383 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
384 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
385 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
386 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
387 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
388 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
389 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
390 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
391 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
392 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
393 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
394 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
395 .len = NL80211_VHT_CAPABILITY_LEN,
397 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
398 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
399 .len = IEEE80211_MAX_DATA_LEN },
400 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
401 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = { .type = NLA_U16 },
402 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
403 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
404 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
405 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
406 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
407 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
408 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
409 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
410 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
411 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
412 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
413 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
414 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
415 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
416 .len = IEEE80211_QOS_MAP_LEN_MAX },
417 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
418 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
419 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
420 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
421 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
422 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
423 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
424 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
425 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
426 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
427 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
428 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
429 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
430 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
431 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
432 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
433 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
434 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
435 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
436 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
437 .len = VHT_MUMIMO_GROUPS_DATA_LEN
439 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
440 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
441 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
442 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
443 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
444 .len = FILS_MAX_KEK_LEN },
445 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
446 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
447 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
448 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
449 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
450 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
452 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
453 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
454 .len = FILS_ERP_MAX_USERNAME_LEN },
455 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
456 .len = FILS_ERP_MAX_REALM_LEN },
457 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
458 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
459 .len = FILS_ERP_MAX_RRK_LEN },
460 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
461 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
462 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
465 /* policy for the key attributes */
466 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
467 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
468 [NL80211_KEY_IDX] = { .type = NLA_U8 },
469 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
470 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
471 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
472 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
473 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
474 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
477 /* policy for the key default flags */
478 static const struct nla_policy
479 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
480 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
481 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
485 /* policy for WoWLAN attributes */
486 static const struct nla_policy
487 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
488 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
489 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
490 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
491 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
492 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
493 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
494 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
495 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
496 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
497 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
500 static const struct nla_policy
501 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
502 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
503 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
504 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
505 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
506 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
507 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
508 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
509 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
511 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
512 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
514 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
515 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
516 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
518 #endif /* CONFIG_PM */
520 /* policy for coalesce rule attributes */
521 static const struct nla_policy
522 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
523 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
524 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
525 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
528 /* policy for GTK rekey offload attributes */
529 static const struct nla_policy
530 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
531 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
532 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
533 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
536 static const struct nla_policy
537 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
538 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
539 .len = IEEE80211_MAX_SSID_LEN },
540 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
541 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
544 static const struct nla_policy
545 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
546 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
547 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
550 static const struct nla_policy
551 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
552 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
553 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
554 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
555 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
559 /* policy for NAN function attributes */
560 static const struct nla_policy
561 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
562 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
563 [NL80211_NAN_FUNC_SERVICE_ID] = {
564 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
565 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
566 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
567 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
568 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
569 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
570 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
571 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
572 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
573 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
574 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
575 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
576 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
577 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
578 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
579 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
582 /* policy for Service Response Filter attributes */
583 static const struct nla_policy
584 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
585 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
586 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
587 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
588 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
589 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
592 /* policy for packet pattern attributes */
593 static const struct nla_policy
594 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
595 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
596 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
597 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
600 static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
601 struct netlink_callback *cb,
602 struct cfg80211_registered_device **rdev,
603 struct wireless_dev **wdev)
608 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
609 genl_family_attrbuf(&nl80211_fam),
610 nl80211_fam.maxattr, nl80211_policy, NULL);
614 *wdev = __cfg80211_wdev_from_attrs(
616 genl_family_attrbuf(&nl80211_fam));
618 return PTR_ERR(*wdev);
619 *rdev = wiphy_to_rdev((*wdev)->wiphy);
620 /* 0 is the first index - add 1 to parse only once */
621 cb->args[0] = (*rdev)->wiphy_idx + 1;
622 cb->args[1] = (*wdev)->identifier;
624 /* subtract the 1 again here */
625 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
626 struct wireless_dev *tmp;
630 *rdev = wiphy_to_rdev(wiphy);
633 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
634 if (tmp->identifier == cb->args[1]) {
648 static bool is_valid_ie_attr(const struct nlattr *attr)
656 pos = nla_data(attr);
677 /* message building helper */
678 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
681 /* since there is no private header just add the generic one */
682 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
685 static int nl80211_msg_put_channel(struct sk_buff *msg,
686 struct ieee80211_channel *chan,
689 /* Some channels must be completely excluded from the
690 * list to protect old user-space tools from breaking
692 if (!large && chan->flags &
693 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
696 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
698 goto nla_put_failure;
700 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
701 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
702 goto nla_put_failure;
703 if (chan->flags & IEEE80211_CHAN_NO_IR) {
704 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
705 goto nla_put_failure;
706 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
707 goto nla_put_failure;
709 if (chan->flags & IEEE80211_CHAN_RADAR) {
710 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
711 goto nla_put_failure;
715 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
717 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
719 goto nla_put_failure;
720 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
722 goto nla_put_failure;
724 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
726 goto nla_put_failure;
731 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
732 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
733 goto nla_put_failure;
734 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
735 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
736 goto nla_put_failure;
737 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
738 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
739 goto nla_put_failure;
740 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
741 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
742 goto nla_put_failure;
743 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
744 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
745 goto nla_put_failure;
746 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
747 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
748 goto nla_put_failure;
749 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
750 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
751 goto nla_put_failure;
752 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
753 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
754 goto nla_put_failure;
757 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
758 DBM_TO_MBM(chan->max_power)))
759 goto nla_put_failure;
767 /* netlink command implementations */
774 bool def_uni, def_multi;
777 static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
779 struct nlattr *tb[NL80211_KEY_MAX + 1];
780 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
781 nl80211_key_policy, NULL);
785 k->def = !!tb[NL80211_KEY_DEFAULT];
786 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
795 if (tb[NL80211_KEY_IDX])
796 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
798 if (tb[NL80211_KEY_DATA]) {
799 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
800 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
803 if (tb[NL80211_KEY_SEQ]) {
804 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
805 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
808 if (tb[NL80211_KEY_CIPHER])
809 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
811 if (tb[NL80211_KEY_TYPE]) {
812 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
813 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
817 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
818 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
820 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
821 tb[NL80211_KEY_DEFAULT_TYPES],
822 nl80211_key_default_policy, NULL);
826 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
827 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
833 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
835 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
836 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
837 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
840 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
841 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
842 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
845 if (info->attrs[NL80211_ATTR_KEY_IDX])
846 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
848 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
849 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
851 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
852 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
861 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
862 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
863 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
867 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
868 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
869 int err = nla_parse_nested(kdt,
870 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
871 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
872 nl80211_key_default_policy,
877 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
878 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
884 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
888 memset(k, 0, sizeof(*k));
892 if (info->attrs[NL80211_ATTR_KEY])
893 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
895 err = nl80211_parse_key_old(info, k);
900 if (k->def && k->defmgmt)
904 if (k->def_uni || !k->def_multi)
910 if (k->idx < 4 || k->idx > 5)
913 if (k->idx < 0 || k->idx > 3)
916 if (k->idx < 0 || k->idx > 5)
924 static struct cfg80211_cached_keys *
925 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
926 struct nlattr *keys, bool *no_ht)
928 struct key_parse parse;
930 struct cfg80211_cached_keys *result;
931 int rem, err, def = 0;
932 bool have_key = false;
934 nla_for_each_nested(key, keys, rem) {
942 result = kzalloc(sizeof(*result), GFP_KERNEL);
944 return ERR_PTR(-ENOMEM);
948 nla_for_each_nested(key, keys, rem) {
949 memset(&parse, 0, sizeof(parse));
952 err = nl80211_parse_key_new(key, &parse);
958 if (parse.idx < 0 || parse.idx > 3)
964 result->def = parse.idx;
965 if (!parse.def_uni || !parse.def_multi)
967 } else if (parse.defmgmt)
969 err = cfg80211_validate_key_settings(rdev, &parse.p,
970 parse.idx, false, NULL);
973 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
974 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
978 result->params[parse.idx].cipher = parse.p.cipher;
979 result->params[parse.idx].key_len = parse.p.key_len;
980 result->params[parse.idx].key = result->data[parse.idx];
981 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
983 /* must be WEP key if we got here */
988 if (result->def < 0) {
999 static int nl80211_key_allowed(struct wireless_dev *wdev)
1001 ASSERT_WDEV_LOCK(wdev);
1003 switch (wdev->iftype) {
1004 case NL80211_IFTYPE_AP:
1005 case NL80211_IFTYPE_AP_VLAN:
1006 case NL80211_IFTYPE_P2P_GO:
1007 case NL80211_IFTYPE_MESH_POINT:
1009 case NL80211_IFTYPE_ADHOC:
1010 case NL80211_IFTYPE_STATION:
1011 case NL80211_IFTYPE_P2P_CLIENT:
1012 if (!wdev->current_bss)
1015 case NL80211_IFTYPE_UNSPECIFIED:
1016 case NL80211_IFTYPE_OCB:
1017 case NL80211_IFTYPE_MONITOR:
1018 case NL80211_IFTYPE_NAN:
1019 case NL80211_IFTYPE_P2P_DEVICE:
1020 case NL80211_IFTYPE_WDS:
1021 case NUM_NL80211_IFTYPES:
1028 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1031 struct ieee80211_channel *chan;
1035 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1036 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1041 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1043 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1047 goto nla_put_failure;
1051 if ((ifmodes & 1) && nla_put_flag(msg, i))
1052 goto nla_put_failure;
1057 nla_nest_end(msg, nl_modes);
1064 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1065 struct sk_buff *msg,
1068 struct nlattr *nl_combis;
1071 nl_combis = nla_nest_start(msg,
1072 NL80211_ATTR_INTERFACE_COMBINATIONS);
1074 goto nla_put_failure;
1076 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1077 const struct ieee80211_iface_combination *c;
1078 struct nlattr *nl_combi, *nl_limits;
1080 c = &wiphy->iface_combinations[i];
1082 nl_combi = nla_nest_start(msg, i + 1);
1084 goto nla_put_failure;
1086 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1088 goto nla_put_failure;
1090 for (j = 0; j < c->n_limits; j++) {
1091 struct nlattr *nl_limit;
1093 nl_limit = nla_nest_start(msg, j + 1);
1095 goto nla_put_failure;
1096 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1098 goto nla_put_failure;
1099 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1100 c->limits[j].types))
1101 goto nla_put_failure;
1102 nla_nest_end(msg, nl_limit);
1105 nla_nest_end(msg, nl_limits);
1107 if (c->beacon_int_infra_match &&
1108 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1109 goto nla_put_failure;
1110 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1111 c->num_different_channels) ||
1112 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1114 goto nla_put_failure;
1116 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1117 c->radar_detect_widths) ||
1118 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1119 c->radar_detect_regions)))
1120 goto nla_put_failure;
1121 if (c->beacon_int_min_gcd &&
1122 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1123 c->beacon_int_min_gcd))
1124 goto nla_put_failure;
1126 nla_nest_end(msg, nl_combi);
1129 nla_nest_end(msg, nl_combis);
1137 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1138 struct sk_buff *msg)
1140 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
1141 struct nlattr *nl_tcp;
1146 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1150 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1151 tcp->data_payload_max))
1154 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1155 tcp->data_payload_max))
1158 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1161 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1162 sizeof(*tcp->tok), tcp->tok))
1165 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1166 tcp->data_interval_max))
1169 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1170 tcp->wake_payload_max))
1173 nla_nest_end(msg, nl_tcp);
1177 static int nl80211_send_wowlan(struct sk_buff *msg,
1178 struct cfg80211_registered_device *rdev,
1181 struct nlattr *nl_wowlan;
1183 if (!rdev->wiphy.wowlan)
1186 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1190 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
1191 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1192 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
1193 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1194 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1195 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1196 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1197 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1198 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1199 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1200 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1201 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1202 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1203 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1204 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1205 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1208 if (rdev->wiphy.wowlan->n_patterns) {
1209 struct nl80211_pattern_support pat = {
1210 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1211 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1212 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1213 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
1216 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1221 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1222 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1223 rdev->wiphy.wowlan->max_nd_match_sets))
1226 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
1229 nla_nest_end(msg, nl_wowlan);
1235 static int nl80211_send_coalesce(struct sk_buff *msg,
1236 struct cfg80211_registered_device *rdev)
1238 struct nl80211_coalesce_rule_support rule;
1240 if (!rdev->wiphy.coalesce)
1243 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1244 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1245 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1246 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1247 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1248 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
1250 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1256 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1257 struct ieee80211_supported_band *sband)
1259 struct nlattr *nl_rates, *nl_rate;
1260 struct ieee80211_rate *rate;
1264 if (sband->ht_cap.ht_supported &&
1265 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1266 sizeof(sband->ht_cap.mcs),
1267 &sband->ht_cap.mcs) ||
1268 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1269 sband->ht_cap.cap) ||
1270 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1271 sband->ht_cap.ampdu_factor) ||
1272 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1273 sband->ht_cap.ampdu_density)))
1277 if (sband->vht_cap.vht_supported &&
1278 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1279 sizeof(sband->vht_cap.vht_mcs),
1280 &sband->vht_cap.vht_mcs) ||
1281 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1282 sband->vht_cap.cap)))
1286 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1290 for (i = 0; i < sband->n_bitrates; i++) {
1291 nl_rate = nla_nest_start(msg, i);
1295 rate = &sband->bitrates[i];
1296 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1299 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1301 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1304 nla_nest_end(msg, nl_rate);
1307 nla_nest_end(msg, nl_rates);
1313 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1314 const struct ieee80211_txrx_stypes *mgmt_stypes)
1317 struct nlattr *nl_ftypes, *nl_ifs;
1318 enum nl80211_iftype ift;
1324 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1328 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1329 nl_ftypes = nla_nest_start(msg, ift);
1333 stypes = mgmt_stypes[ift].tx;
1336 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1337 (i << 4) | IEEE80211_FTYPE_MGMT))
1342 nla_nest_end(msg, nl_ftypes);
1345 nla_nest_end(msg, nl_ifs);
1347 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1351 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1352 nl_ftypes = nla_nest_start(msg, ift);
1356 stypes = mgmt_stypes[ift].rx;
1359 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1360 (i << 4) | IEEE80211_FTYPE_MGMT))
1365 nla_nest_end(msg, nl_ftypes);
1367 nla_nest_end(msg, nl_ifs);
1372 #define CMD(op, n) \
1374 if (rdev->ops->op) { \
1376 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1377 goto nla_put_failure; \
1381 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1382 struct sk_buff *msg)
1387 * do *NOT* add anything into this function, new things need to be
1388 * advertised only to new versions of userspace that can deal with
1389 * the split (and they can't possibly care about new features...
1391 CMD(add_virtual_intf, NEW_INTERFACE);
1392 CMD(change_virtual_intf, SET_INTERFACE);
1393 CMD(add_key, NEW_KEY);
1394 CMD(start_ap, START_AP);
1395 CMD(add_station, NEW_STATION);
1396 CMD(add_mpath, NEW_MPATH);
1397 CMD(update_mesh_config, SET_MESH_CONFIG);
1398 CMD(change_bss, SET_BSS);
1399 CMD(auth, AUTHENTICATE);
1400 CMD(assoc, ASSOCIATE);
1401 CMD(deauth, DEAUTHENTICATE);
1402 CMD(disassoc, DISASSOCIATE);
1403 CMD(join_ibss, JOIN_IBSS);
1404 CMD(join_mesh, JOIN_MESH);
1405 CMD(set_pmksa, SET_PMKSA);
1406 CMD(del_pmksa, DEL_PMKSA);
1407 CMD(flush_pmksa, FLUSH_PMKSA);
1408 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1409 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1410 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1411 CMD(mgmt_tx, FRAME);
1412 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1413 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1415 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1416 goto nla_put_failure;
1418 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1419 rdev->ops->join_mesh) {
1421 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1422 goto nla_put_failure;
1424 CMD(set_wds_peer, SET_WDS_PEER);
1425 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1426 CMD(tdls_mgmt, TDLS_MGMT);
1427 CMD(tdls_oper, TDLS_OPER);
1429 if (rdev->wiphy.max_sched_scan_reqs)
1430 CMD(sched_scan_start, START_SCHED_SCAN);
1431 CMD(probe_client, PROBE_CLIENT);
1432 CMD(set_noack_map, SET_NOACK_MAP);
1433 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1435 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1436 goto nla_put_failure;
1438 CMD(start_p2p_device, START_P2P_DEVICE);
1439 CMD(set_mcast_rate, SET_MCAST_RATE);
1440 #ifdef CONFIG_NL80211_TESTMODE
1441 CMD(testmode_cmd, TESTMODE);
1444 if (rdev->ops->connect || rdev->ops->auth) {
1446 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1447 goto nla_put_failure;
1450 if (rdev->ops->disconnect || rdev->ops->deauth) {
1452 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1453 goto nla_put_failure;
1461 struct nl80211_dump_wiphy_state {
1464 long split_start, band_start, chan_start, capa_start;
1468 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1469 enum nl80211_commands cmd,
1470 struct sk_buff *msg, u32 portid, u32 seq,
1471 int flags, struct nl80211_dump_wiphy_state *state)
1474 struct nlattr *nl_bands, *nl_band;
1475 struct nlattr *nl_freqs, *nl_freq;
1476 struct nlattr *nl_cmds;
1477 enum nl80211_band band;
1478 struct ieee80211_channel *chan;
1480 const struct ieee80211_txrx_stypes *mgmt_stypes =
1481 rdev->wiphy.mgmt_stypes;
1484 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
1488 if (WARN_ON(!state))
1491 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1492 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1493 wiphy_name(&rdev->wiphy)) ||
1494 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1495 cfg80211_rdev_list_generation))
1496 goto nla_put_failure;
1498 if (cmd != NL80211_CMD_NEW_WIPHY)
1501 switch (state->split_start) {
1503 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1504 rdev->wiphy.retry_short) ||
1505 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1506 rdev->wiphy.retry_long) ||
1507 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1508 rdev->wiphy.frag_threshold) ||
1509 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1510 rdev->wiphy.rts_threshold) ||
1511 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1512 rdev->wiphy.coverage_class) ||
1513 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1514 rdev->wiphy.max_scan_ssids) ||
1515 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1516 rdev->wiphy.max_sched_scan_ssids) ||
1517 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1518 rdev->wiphy.max_scan_ie_len) ||
1519 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1520 rdev->wiphy.max_sched_scan_ie_len) ||
1521 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1522 rdev->wiphy.max_match_sets) ||
1523 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1524 rdev->wiphy.max_sched_scan_plans) ||
1525 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1526 rdev->wiphy.max_sched_scan_plan_interval) ||
1527 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1528 rdev->wiphy.max_sched_scan_plan_iterations))
1529 goto nla_put_failure;
1531 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1532 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1533 goto nla_put_failure;
1534 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1535 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1536 goto nla_put_failure;
1537 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1538 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1539 goto nla_put_failure;
1540 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1541 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1542 goto nla_put_failure;
1543 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1544 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1545 goto nla_put_failure;
1546 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1547 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
1548 goto nla_put_failure;
1549 state->split_start++;
1553 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1554 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1555 rdev->wiphy.cipher_suites))
1556 goto nla_put_failure;
1558 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1559 rdev->wiphy.max_num_pmkids))
1560 goto nla_put_failure;
1562 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1563 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1564 goto nla_put_failure;
1566 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1567 rdev->wiphy.available_antennas_tx) ||
1568 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1569 rdev->wiphy.available_antennas_rx))
1570 goto nla_put_failure;
1572 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1573 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1574 rdev->wiphy.probe_resp_offload))
1575 goto nla_put_failure;
1577 if ((rdev->wiphy.available_antennas_tx ||
1578 rdev->wiphy.available_antennas_rx) &&
1579 rdev->ops->get_antenna) {
1580 u32 tx_ant = 0, rx_ant = 0;
1583 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
1585 if (nla_put_u32(msg,
1586 NL80211_ATTR_WIPHY_ANTENNA_TX,
1589 NL80211_ATTR_WIPHY_ANTENNA_RX,
1591 goto nla_put_failure;
1595 state->split_start++;
1599 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1600 rdev->wiphy.interface_modes))
1601 goto nla_put_failure;
1602 state->split_start++;
1606 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1608 goto nla_put_failure;
1610 for (band = state->band_start;
1611 band < NUM_NL80211_BANDS; band++) {
1612 struct ieee80211_supported_band *sband;
1614 sband = rdev->wiphy.bands[band];
1619 nl_band = nla_nest_start(msg, band);
1621 goto nla_put_failure;
1623 switch (state->chan_start) {
1625 if (nl80211_send_band_rateinfo(msg, sband))
1626 goto nla_put_failure;
1627 state->chan_start++;
1631 /* add frequencies */
1632 nl_freqs = nla_nest_start(
1633 msg, NL80211_BAND_ATTR_FREQS);
1635 goto nla_put_failure;
1637 for (i = state->chan_start - 1;
1638 i < sband->n_channels;
1640 nl_freq = nla_nest_start(msg, i);
1642 goto nla_put_failure;
1644 chan = &sband->channels[i];
1646 if (nl80211_msg_put_channel(
1649 goto nla_put_failure;
1651 nla_nest_end(msg, nl_freq);
1655 if (i < sband->n_channels)
1656 state->chan_start = i + 2;
1658 state->chan_start = 0;
1659 nla_nest_end(msg, nl_freqs);
1662 nla_nest_end(msg, nl_band);
1665 /* start again here */
1666 if (state->chan_start)
1671 nla_nest_end(msg, nl_bands);
1673 if (band < NUM_NL80211_BANDS)
1674 state->band_start = band + 1;
1676 state->band_start = 0;
1678 /* if bands & channels are done, continue outside */
1679 if (state->band_start == 0 && state->chan_start == 0)
1680 state->split_start++;
1684 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1686 goto nla_put_failure;
1688 i = nl80211_add_commands_unsplit(rdev, msg);
1690 goto nla_put_failure;
1692 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1693 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1694 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1695 CMD(channel_switch, CHANNEL_SWITCH);
1696 CMD(set_qos_map, SET_QOS_MAP);
1697 if (rdev->wiphy.features &
1698 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
1699 CMD(add_tx_ts, ADD_TX_TS);
1700 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
1701 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
1705 nla_nest_end(msg, nl_cmds);
1706 state->split_start++;
1710 if (rdev->ops->remain_on_channel &&
1711 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1713 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1714 rdev->wiphy.max_remain_on_channel_duration))
1715 goto nla_put_failure;
1717 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1718 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1719 goto nla_put_failure;
1721 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1722 goto nla_put_failure;
1723 state->split_start++;
1728 if (nl80211_send_wowlan(msg, rdev, state->split))
1729 goto nla_put_failure;
1730 state->split_start++;
1734 state->split_start++;
1737 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1738 rdev->wiphy.software_iftypes))
1739 goto nla_put_failure;
1741 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
1743 goto nla_put_failure;
1745 state->split_start++;
1749 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1750 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1751 rdev->wiphy.ap_sme_capa))
1752 goto nla_put_failure;
1754 features = rdev->wiphy.features;
1756 * We can only add the per-channel limit information if the
1757 * dump is split, otherwise it makes it too big. Therefore
1758 * only advertise it in that case.
1761 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1762 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
1763 goto nla_put_failure;
1765 if (rdev->wiphy.ht_capa_mod_mask &&
1766 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1767 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1768 rdev->wiphy.ht_capa_mod_mask))
1769 goto nla_put_failure;
1771 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1772 rdev->wiphy.max_acl_mac_addrs &&
1773 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1774 rdev->wiphy.max_acl_mac_addrs))
1775 goto nla_put_failure;
1778 * Any information below this point is only available to
1779 * applications that can deal with it being split. This
1780 * helps ensure that newly added capabilities don't break
1781 * older tools by overrunning their buffers.
1783 * We still increment split_start so that in the split
1784 * case we'll continue with more data in the next round,
1785 * but break unconditionally so unsplit data stops here.
1788 state->split_start++;
1790 state->split_start = 0;
1793 if (rdev->wiphy.extended_capabilities &&
1794 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1795 rdev->wiphy.extended_capabilities_len,
1796 rdev->wiphy.extended_capabilities) ||
1797 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1798 rdev->wiphy.extended_capabilities_len,
1799 rdev->wiphy.extended_capabilities_mask)))
1800 goto nla_put_failure;
1802 if (rdev->wiphy.vht_capa_mod_mask &&
1803 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1804 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1805 rdev->wiphy.vht_capa_mod_mask))
1806 goto nla_put_failure;
1808 state->split_start++;
1811 if (nl80211_send_coalesce(msg, rdev))
1812 goto nla_put_failure;
1814 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1815 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1816 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1817 goto nla_put_failure;
1819 if (rdev->wiphy.max_ap_assoc_sta &&
1820 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
1821 rdev->wiphy.max_ap_assoc_sta))
1822 goto nla_put_failure;
1824 state->split_start++;
1827 if (rdev->wiphy.n_vendor_commands) {
1828 const struct nl80211_vendor_cmd_info *info;
1829 struct nlattr *nested;
1831 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1833 goto nla_put_failure;
1835 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1836 info = &rdev->wiphy.vendor_commands[i].info;
1837 if (nla_put(msg, i + 1, sizeof(*info), info))
1838 goto nla_put_failure;
1840 nla_nest_end(msg, nested);
1843 if (rdev->wiphy.n_vendor_events) {
1844 const struct nl80211_vendor_cmd_info *info;
1845 struct nlattr *nested;
1847 nested = nla_nest_start(msg,
1848 NL80211_ATTR_VENDOR_EVENTS);
1850 goto nla_put_failure;
1852 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1853 info = &rdev->wiphy.vendor_events[i];
1854 if (nla_put(msg, i + 1, sizeof(*info), info))
1855 goto nla_put_failure;
1857 nla_nest_end(msg, nested);
1859 state->split_start++;
1862 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1863 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1864 rdev->wiphy.max_num_csa_counters))
1865 goto nla_put_failure;
1867 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1868 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1869 goto nla_put_failure;
1871 if (rdev->wiphy.max_sched_scan_reqs &&
1872 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
1873 rdev->wiphy.max_sched_scan_reqs))
1874 goto nla_put_failure;
1876 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1877 sizeof(rdev->wiphy.ext_features),
1878 rdev->wiphy.ext_features))
1879 goto nla_put_failure;
1881 if (rdev->wiphy.bss_select_support) {
1882 struct nlattr *nested;
1883 u32 bss_select_support = rdev->wiphy.bss_select_support;
1885 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1887 goto nla_put_failure;
1890 while (bss_select_support) {
1891 if ((bss_select_support & 1) &&
1892 nla_put_flag(msg, i))
1893 goto nla_put_failure;
1895 bss_select_support >>= 1;
1897 nla_nest_end(msg, nested);
1900 state->split_start++;
1903 if (rdev->wiphy.num_iftype_ext_capab &&
1904 rdev->wiphy.iftype_ext_capab) {
1905 struct nlattr *nested_ext_capab, *nested;
1907 nested = nla_nest_start(msg,
1908 NL80211_ATTR_IFTYPE_EXT_CAPA);
1910 goto nla_put_failure;
1912 for (i = state->capa_start;
1913 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1914 const struct wiphy_iftype_ext_capab *capab;
1916 capab = &rdev->wiphy.iftype_ext_capab[i];
1918 nested_ext_capab = nla_nest_start(msg, i);
1919 if (!nested_ext_capab ||
1920 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1922 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1923 capab->extended_capabilities_len,
1924 capab->extended_capabilities) ||
1925 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1926 capab->extended_capabilities_len,
1927 capab->extended_capabilities_mask))
1928 goto nla_put_failure;
1930 nla_nest_end(msg, nested_ext_capab);
1934 nla_nest_end(msg, nested);
1935 if (i < rdev->wiphy.num_iftype_ext_capab) {
1936 state->capa_start = i + 1;
1941 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
1942 rdev->wiphy.nan_supported_bands))
1943 goto nla_put_failure;
1946 state->split_start = 0;
1950 genlmsg_end(msg, hdr);
1954 genlmsg_cancel(msg, hdr);
1958 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1959 struct netlink_callback *cb,
1960 struct nl80211_dump_wiphy_state *state)
1962 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
1963 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb,
1964 nl80211_fam.maxattr, nl80211_policy, NULL);
1965 /* ignore parse errors for backward compatibility */
1969 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1970 if (tb[NL80211_ATTR_WIPHY])
1971 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1972 if (tb[NL80211_ATTR_WDEV])
1973 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1974 if (tb[NL80211_ATTR_IFINDEX]) {
1975 struct net_device *netdev;
1976 struct cfg80211_registered_device *rdev;
1977 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1979 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
1982 if (netdev->ieee80211_ptr) {
1983 rdev = wiphy_to_rdev(
1984 netdev->ieee80211_ptr->wiphy);
1985 state->filter_wiphy = rdev->wiphy_idx;
1992 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1995 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
1996 struct cfg80211_registered_device *rdev;
2000 state = kzalloc(sizeof(*state), GFP_KERNEL);
2005 state->filter_wiphy = -1;
2006 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2012 cb->args[0] = (long)state;
2015 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2016 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
2018 if (++idx <= state->start)
2020 if (state->filter_wiphy != -1 &&
2021 state->filter_wiphy != rdev->wiphy_idx)
2023 /* attempt to fit multiple wiphy data chunks into the skb */
2025 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2027 NETLINK_CB(cb->skb).portid,
2029 NLM_F_MULTI, state);
2032 * If sending the wiphy data didn't fit (ENOBUFS
2033 * or EMSGSIZE returned), this SKB is still
2034 * empty (so it's not too big because another
2035 * wiphy dataset is already in the skb) and
2036 * we've not tried to adjust the dump allocation
2037 * yet ... then adjust the alloc size to be
2038 * bigger, and return 1 but with the empty skb.
2039 * This results in an empty message being RX'ed
2040 * in userspace, but that is ignored.
2042 * We can then retry with the larger buffer.
2044 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
2045 !skb->len && !state->split &&
2046 cb->min_dump_alloc < 4096) {
2047 cb->min_dump_alloc = 4096;
2048 state->split_start = 0;
2055 } while (state->split_start > 0);
2065 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2067 kfree((void *)cb->args[0]);
2071 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2073 struct sk_buff *msg;
2074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2075 struct nl80211_dump_wiphy_state state = {};
2077 msg = nlmsg_new(4096, GFP_KERNEL);
2081 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2082 info->snd_portid, info->snd_seq, 0,
2088 return genlmsg_reply(msg, info);
2091 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2092 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2093 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2094 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2095 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2096 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2099 static int parse_txq_params(struct nlattr *tb[],
2100 struct ieee80211_txq_params *txq_params)
2104 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
2105 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2106 !tb[NL80211_TXQ_ATTR_AIFS])
2109 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
2110 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2111 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2112 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2113 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2115 if (ac >= NL80211_NUM_ACS)
2117 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
2121 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2124 * You can only set the channel explicitly for WDS interfaces,
2125 * all others have their channel managed via their respective
2126 * "establish a connection" command (connect, join, ...)
2128 * For AP/GO and mesh mode, the channel can be set with the
2129 * channel userspace API, but is only stored and passed to the
2130 * low-level driver when the AP starts or the mesh is joined.
2131 * This is for backward compatibility, userspace can also give
2132 * the channel in the start-ap or join-mesh commands instead.
2134 * Monitors are special as they are normally slaved to
2135 * whatever else is going on, so they have their own special
2136 * operation to set the monitor channel if possible.
2139 wdev->iftype == NL80211_IFTYPE_AP ||
2140 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
2141 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2142 wdev->iftype == NL80211_IFTYPE_P2P_GO;
2145 static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2146 struct genl_info *info,
2147 struct cfg80211_chan_def *chandef)
2151 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2154 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2156 memset(chandef, 0, sizeof(*chandef));
2158 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
2159 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2160 chandef->center_freq1 = control_freq;
2161 chandef->center_freq2 = 0;
2163 /* Primary channel not allowed */
2164 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2167 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2168 enum nl80211_channel_type chantype;
2170 chantype = nla_get_u32(
2171 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2174 case NL80211_CHAN_NO_HT:
2175 case NL80211_CHAN_HT20:
2176 case NL80211_CHAN_HT40PLUS:
2177 case NL80211_CHAN_HT40MINUS:
2178 cfg80211_chandef_create(chandef, chandef->chan,
2184 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2186 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2187 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2188 chandef->center_freq1 =
2190 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2191 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2192 chandef->center_freq2 =
2194 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2197 if (!cfg80211_chandef_valid(chandef))
2200 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2201 IEEE80211_CHAN_DISABLED))
2204 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2205 chandef->width == NL80211_CHAN_WIDTH_10) &&
2206 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2212 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
2213 struct net_device *dev,
2214 struct genl_info *info)
2216 struct cfg80211_chan_def chandef;
2218 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
2219 struct wireless_dev *wdev = NULL;
2222 wdev = dev->ieee80211_ptr;
2223 if (!nl80211_can_set_dev_channel(wdev))
2226 iftype = wdev->iftype;
2228 result = nl80211_parse_chandef(rdev, info, &chandef);
2233 case NL80211_IFTYPE_AP:
2234 case NL80211_IFTYPE_P2P_GO:
2235 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2240 if (wdev->beacon_interval) {
2241 if (!dev || !rdev->ops->set_ap_chanwidth ||
2242 !(rdev->wiphy.features &
2243 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2248 /* Only allow dynamic channel width changes */
2249 if (chandef.chan != wdev->preset_chandef.chan) {
2253 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2257 wdev->preset_chandef = chandef;
2260 case NL80211_IFTYPE_MESH_POINT:
2261 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
2263 case NL80211_IFTYPE_MONITOR:
2264 result = cfg80211_set_monitor_channel(rdev, &chandef);
2273 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2275 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2276 struct net_device *netdev = info->user_ptr[1];
2278 return __nl80211_set_channel(rdev, netdev, info);
2281 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2284 struct net_device *dev = info->user_ptr[1];
2285 struct wireless_dev *wdev = dev->ieee80211_ptr;
2288 if (!info->attrs[NL80211_ATTR_MAC])
2291 if (netif_running(dev))
2294 if (!rdev->ops->set_wds_peer)
2297 if (wdev->iftype != NL80211_IFTYPE_WDS)
2300 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
2301 return rdev_set_wds_peer(rdev, dev, bssid);
2304 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2306 struct cfg80211_registered_device *rdev;
2307 struct net_device *netdev = NULL;
2308 struct wireless_dev *wdev;
2309 int result = 0, rem_txq_params = 0;
2310 struct nlattr *nl_txq_params;
2312 u8 retry_short = 0, retry_long = 0;
2313 u32 frag_threshold = 0, rts_threshold = 0;
2314 u8 coverage_class = 0;
2319 * Try to find the wiphy and netdev. Normally this
2320 * function shouldn't need the netdev, but this is
2321 * done for backward compatibility -- previously
2322 * setting the channel was done per wiphy, but now
2323 * it is per netdev. Previous userland like hostapd
2324 * also passed a netdev to set_wiphy, so that it is
2325 * possible to let that go to the right netdev!
2328 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2329 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2331 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
2332 if (netdev && netdev->ieee80211_ptr)
2333 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
2339 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2342 return PTR_ERR(rdev);
2347 wdev = netdev->ieee80211_ptr;
2350 * end workaround code, by now the rdev is available
2351 * and locked, and wdev may or may not be NULL.
2354 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
2355 result = cfg80211_dev_rename(
2356 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
2361 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2362 struct ieee80211_txq_params txq_params;
2363 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2365 if (!rdev->ops->set_txq_params)
2371 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2372 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2375 if (!netif_running(netdev))
2378 nla_for_each_nested(nl_txq_params,
2379 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2381 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2387 result = parse_txq_params(tb, &txq_params);
2391 result = rdev_set_txq_params(rdev, netdev,
2398 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2399 result = __nl80211_set_channel(
2401 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2407 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
2408 struct wireless_dev *txp_wdev = wdev;
2409 enum nl80211_tx_power_setting type;
2412 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2415 if (!rdev->ops->set_tx_power)
2418 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2419 type = nla_get_u32(info->attrs[idx]);
2421 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2422 (type != NL80211_TX_POWER_AUTOMATIC))
2425 if (type != NL80211_TX_POWER_AUTOMATIC) {
2426 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2427 mbm = nla_get_u32(info->attrs[idx]);
2430 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
2435 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2436 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2439 if ((!rdev->wiphy.available_antennas_tx &&
2440 !rdev->wiphy.available_antennas_rx) ||
2441 !rdev->ops->set_antenna)
2444 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2445 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2447 /* reject antenna configurations which don't match the
2448 * available antenna masks, except for the "all" mask */
2449 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2450 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2453 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2454 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
2456 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
2463 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2464 retry_short = nla_get_u8(
2465 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2466 if (retry_short == 0)
2469 changed |= WIPHY_PARAM_RETRY_SHORT;
2472 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2473 retry_long = nla_get_u8(
2474 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2475 if (retry_long == 0)
2478 changed |= WIPHY_PARAM_RETRY_LONG;
2481 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2482 frag_threshold = nla_get_u32(
2483 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2484 if (frag_threshold < 256)
2487 if (frag_threshold != (u32) -1) {
2489 * Fragments (apart from the last one) are required to
2490 * have even length. Make the fragmentation code
2491 * simpler by stripping LSB should someone try to use
2492 * odd threshold value.
2494 frag_threshold &= ~0x1;
2496 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2499 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2500 rts_threshold = nla_get_u32(
2501 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2502 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2505 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2506 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2509 coverage_class = nla_get_u8(
2510 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2511 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2514 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2515 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2518 changed |= WIPHY_PARAM_DYN_ACK;
2522 u8 old_retry_short, old_retry_long;
2523 u32 old_frag_threshold, old_rts_threshold;
2524 u8 old_coverage_class;
2526 if (!rdev->ops->set_wiphy_params)
2529 old_retry_short = rdev->wiphy.retry_short;
2530 old_retry_long = rdev->wiphy.retry_long;
2531 old_frag_threshold = rdev->wiphy.frag_threshold;
2532 old_rts_threshold = rdev->wiphy.rts_threshold;
2533 old_coverage_class = rdev->wiphy.coverage_class;
2535 if (changed & WIPHY_PARAM_RETRY_SHORT)
2536 rdev->wiphy.retry_short = retry_short;
2537 if (changed & WIPHY_PARAM_RETRY_LONG)
2538 rdev->wiphy.retry_long = retry_long;
2539 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2540 rdev->wiphy.frag_threshold = frag_threshold;
2541 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2542 rdev->wiphy.rts_threshold = rts_threshold;
2543 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2544 rdev->wiphy.coverage_class = coverage_class;
2546 result = rdev_set_wiphy_params(rdev, changed);
2548 rdev->wiphy.retry_short = old_retry_short;
2549 rdev->wiphy.retry_long = old_retry_long;
2550 rdev->wiphy.frag_threshold = old_frag_threshold;
2551 rdev->wiphy.rts_threshold = old_rts_threshold;
2552 rdev->wiphy.coverage_class = old_coverage_class;
2559 static inline u64 wdev_id(struct wireless_dev *wdev)
2561 return (u64)wdev->identifier |
2562 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
2565 static int nl80211_send_chandef(struct sk_buff *msg,
2566 const struct cfg80211_chan_def *chandef)
2568 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2571 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2572 chandef->chan->center_freq))
2574 switch (chandef->width) {
2575 case NL80211_CHAN_WIDTH_20_NOHT:
2576 case NL80211_CHAN_WIDTH_20:
2577 case NL80211_CHAN_WIDTH_40:
2578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2579 cfg80211_get_chandef_type(chandef)))
2585 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2587 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2589 if (chandef->center_freq2 &&
2590 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
2595 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
2596 struct cfg80211_registered_device *rdev,
2597 struct wireless_dev *wdev, bool removal)
2599 struct net_device *dev = wdev->netdev;
2600 u8 cmd = NL80211_CMD_NEW_INTERFACE;
2604 cmd = NL80211_CMD_DEL_INTERFACE;
2606 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
2611 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2612 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
2613 goto nla_put_failure;
2615 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2616 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
2617 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2618 NL80211_ATTR_PAD) ||
2619 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
2620 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2621 rdev->devlist_generation ^
2622 (cfg80211_rdev_list_generation << 2)))
2623 goto nla_put_failure;
2625 if (rdev->ops->get_channel) {
2627 struct cfg80211_chan_def chandef = {};
2629 ret = rdev_get_channel(rdev, wdev, &chandef);
2631 if (nl80211_send_chandef(msg, &chandef))
2632 goto nla_put_failure;
2636 if (rdev->ops->get_tx_power) {
2639 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2641 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2643 goto nla_put_failure;
2646 if (wdev->ssid_len) {
2647 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2648 goto nla_put_failure;
2651 genlmsg_end(msg, hdr);
2655 genlmsg_cancel(msg, hdr);
2659 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2663 int wp_start = cb->args[0];
2664 int if_start = cb->args[1];
2665 int filter_wiphy = -1;
2666 struct cfg80211_registered_device *rdev;
2667 struct wireless_dev *wdev;
2672 struct nl80211_dump_wiphy_state state = {
2676 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2680 filter_wiphy = state.filter_wiphy;
2683 * if filtering, set cb->args[2] to +1 since 0 is the default
2684 * value needed to determine that parsing is necessary.
2686 if (filter_wiphy >= 0)
2687 cb->args[2] = filter_wiphy + 1;
2690 } else if (cb->args[2] > 0) {
2691 filter_wiphy = cb->args[2] - 1;
2694 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2695 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
2697 if (wp_idx < wp_start) {
2702 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2707 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
2708 if (if_idx < if_start) {
2712 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
2713 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2714 rdev, wdev, false) < 0) {
2723 cb->args[0] = wp_idx;
2724 cb->args[1] = if_idx;
2733 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2735 struct sk_buff *msg;
2736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2737 struct wireless_dev *wdev = info->user_ptr[1];
2739 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2743 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
2744 rdev, wdev, false) < 0) {
2749 return genlmsg_reply(msg, info);
2752 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2753 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2754 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2755 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2756 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2757 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2758 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
2761 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2763 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2771 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla,
2772 mntr_flags_policy, NULL))
2775 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2777 *mntrflags |= (1<<flag);
2779 *mntrflags |= MONITOR_FLAG_CHANGED;
2784 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
2785 enum nl80211_iftype type,
2786 struct genl_info *info,
2787 struct vif_params *params)
2789 bool change = false;
2792 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2793 if (type != NL80211_IFTYPE_MONITOR)
2796 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2804 if (params->flags & MONITOR_FLAG_ACTIVE &&
2805 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2808 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2809 const u8 *mumimo_groups;
2810 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2812 if (type != NL80211_IFTYPE_MONITOR)
2815 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2819 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2821 /* bits 0 and 63 are reserved and must be zero */
2822 if ((mumimo_groups[0] & BIT(0)) ||
2823 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
2826 params->vht_mumimo_groups = mumimo_groups;
2830 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2831 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2833 if (type != NL80211_IFTYPE_MONITOR)
2836 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2839 params->vht_mumimo_follow_addr =
2840 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
2844 return change ? 1 : 0;
2847 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
2848 struct net_device *netdev, u8 use_4addr,
2849 enum nl80211_iftype iftype)
2852 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
2858 case NL80211_IFTYPE_AP_VLAN:
2859 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2862 case NL80211_IFTYPE_STATION:
2863 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2873 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2876 struct vif_params params;
2878 enum nl80211_iftype otype, ntype;
2879 struct net_device *dev = info->user_ptr[1];
2880 bool change = false;
2882 memset(¶ms, 0, sizeof(params));
2884 otype = ntype = dev->ieee80211_ptr->iftype;
2886 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2887 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2890 if (ntype > NL80211_IFTYPE_MAX)
2894 if (info->attrs[NL80211_ATTR_MESH_ID]) {
2895 struct wireless_dev *wdev = dev->ieee80211_ptr;
2897 if (ntype != NL80211_IFTYPE_MESH_POINT)
2899 if (netif_running(dev))
2903 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2904 IEEE80211_MAX_MESH_ID_LEN);
2905 wdev->mesh_id_up_len =
2906 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2907 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2908 wdev->mesh_id_up_len);
2912 if (info->attrs[NL80211_ATTR_4ADDR]) {
2913 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2915 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
2919 params.use_4addr = -1;
2922 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms);
2929 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms);
2933 if (!err && params.use_4addr != -1)
2934 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2939 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2942 struct vif_params params;
2943 struct wireless_dev *wdev;
2944 struct sk_buff *msg;
2946 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2948 /* to avoid failing a new interface creation due to pending removal */
2949 cfg80211_destroy_ifaces(rdev);
2951 memset(¶ms, 0, sizeof(params));
2953 if (!info->attrs[NL80211_ATTR_IFNAME])
2956 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2957 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2958 if (type > NL80211_IFTYPE_MAX)
2962 if (!rdev->ops->add_virtual_intf ||
2963 !(rdev->wiphy.interface_modes & (1 << type)))
2966 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
2967 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2968 info->attrs[NL80211_ATTR_MAC]) {
2969 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2971 if (!is_valid_ether_addr(params.macaddr))
2972 return -EADDRNOTAVAIL;
2975 if (info->attrs[NL80211_ATTR_4ADDR]) {
2976 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2977 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
2982 err = nl80211_parse_mon_options(rdev, type, info, ¶ms);
2986 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2990 wdev = rdev_add_virtual_intf(rdev,
2991 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2992 NET_NAME_USER, type, ¶ms);
2993 if (WARN_ON(!wdev)) {
2996 } else if (IS_ERR(wdev)) {
2998 return PTR_ERR(wdev);
3001 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
3002 wdev->owner_nlportid = info->snd_portid;
3005 case NL80211_IFTYPE_MESH_POINT:
3006 if (!info->attrs[NL80211_ATTR_MESH_ID])
3009 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3010 IEEE80211_MAX_MESH_ID_LEN);
3011 wdev->mesh_id_up_len =
3012 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3013 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3014 wdev->mesh_id_up_len);
3017 case NL80211_IFTYPE_NAN:
3018 case NL80211_IFTYPE_P2P_DEVICE:
3020 * P2P Device and NAN do not have a netdev, so don't go
3021 * through the netdev notifier and must be added here
3023 mutex_init(&wdev->mtx);
3024 INIT_LIST_HEAD(&wdev->event_list);
3025 spin_lock_init(&wdev->event_lock);
3026 INIT_LIST_HEAD(&wdev->mgmt_registrations);
3027 spin_lock_init(&wdev->mgmt_registrations_lock);
3029 wdev->identifier = ++rdev->wdev_id;
3030 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
3031 rdev->devlist_generation++;
3037 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
3038 rdev, wdev, false) < 0) {
3044 * For wdevs which have no associated netdev object (e.g. of type
3045 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3046 * For all other types, the event will be generated from the
3050 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
3052 return genlmsg_reply(msg, info);
3055 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3058 struct wireless_dev *wdev = info->user_ptr[1];
3060 if (!rdev->ops->del_virtual_intf)
3064 * If we remove a wireless device without a netdev then clear
3065 * user_ptr[1] so that nl80211_post_doit won't dereference it
3066 * to check if it needs to do dev_put(). Otherwise it crashes
3067 * since the wdev has been freed, unlike with a netdev where
3068 * we need the dev_put() for the netdev to really be freed.
3071 info->user_ptr[1] = NULL;
3073 return rdev_del_virtual_intf(rdev, wdev);
3076 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3079 struct net_device *dev = info->user_ptr[1];
3082 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3085 if (!rdev->ops->set_noack_map)
3088 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3090 return rdev_set_noack_map(rdev, dev, noack_map);
3093 struct get_key_cookie {
3094 struct sk_buff *msg;
3099 static void get_key_callback(void *c, struct key_params *params)
3102 struct get_key_cookie *cookie = c;
3105 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3106 params->key_len, params->key)) ||
3108 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3109 params->seq_len, params->seq)) ||
3111 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3113 goto nla_put_failure;
3115 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3117 goto nla_put_failure;
3120 nla_put(cookie->msg, NL80211_KEY_DATA,
3121 params->key_len, params->key)) ||
3123 nla_put(cookie->msg, NL80211_KEY_SEQ,
3124 params->seq_len, params->seq)) ||
3126 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3128 goto nla_put_failure;
3130 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
3131 goto nla_put_failure;
3133 nla_nest_end(cookie->msg, key);
3140 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3144 struct net_device *dev = info->user_ptr[1];
3146 const u8 *mac_addr = NULL;
3148 struct get_key_cookie cookie = {
3152 struct sk_buff *msg;
3154 if (info->attrs[NL80211_ATTR_KEY_IDX])
3155 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3160 if (info->attrs[NL80211_ATTR_MAC])
3161 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3163 pairwise = !!mac_addr;
3164 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3165 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
3167 if (kt >= NUM_NL80211_KEYTYPES)
3169 if (kt != NL80211_KEYTYPE_GROUP &&
3170 kt != NL80211_KEYTYPE_PAIRWISE)
3172 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3175 if (!rdev->ops->get_key)
3178 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3181 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3185 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
3186 NL80211_CMD_NEW_KEY);
3188 goto nla_put_failure;
3191 cookie.idx = key_idx;
3193 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3194 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3195 goto nla_put_failure;
3197 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3198 goto nla_put_failure;
3200 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3207 goto nla_put_failure;
3209 genlmsg_end(msg, hdr);
3210 return genlmsg_reply(msg, info);
3219 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3222 struct key_parse key;
3224 struct net_device *dev = info->user_ptr[1];
3226 err = nl80211_parse_key(info, &key);
3233 /* only support setting default key */
3234 if (!key.def && !key.defmgmt)
3237 wdev_lock(dev->ieee80211_ptr);
3240 if (!rdev->ops->set_default_key) {
3245 err = nl80211_key_allowed(dev->ieee80211_ptr);
3249 err = rdev_set_default_key(rdev, dev, key.idx,
3250 key.def_uni, key.def_multi);
3255 #ifdef CONFIG_CFG80211_WEXT
3256 dev->ieee80211_ptr->wext.default_key = key.idx;
3259 if (key.def_uni || !key.def_multi) {
3264 if (!rdev->ops->set_default_mgmt_key) {
3269 err = nl80211_key_allowed(dev->ieee80211_ptr);
3273 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
3277 #ifdef CONFIG_CFG80211_WEXT
3278 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3283 wdev_unlock(dev->ieee80211_ptr);
3288 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3292 struct net_device *dev = info->user_ptr[1];
3293 struct key_parse key;
3294 const u8 *mac_addr = NULL;
3296 err = nl80211_parse_key(info, &key);
3303 if (info->attrs[NL80211_ATTR_MAC])
3304 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3306 if (key.type == -1) {
3308 key.type = NL80211_KEYTYPE_PAIRWISE;
3310 key.type = NL80211_KEYTYPE_GROUP;
3314 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3315 key.type != NL80211_KEYTYPE_GROUP)
3318 if (!rdev->ops->add_key)
3321 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3322 key.type == NL80211_KEYTYPE_PAIRWISE,
3326 wdev_lock(dev->ieee80211_ptr);
3327 err = nl80211_key_allowed(dev->ieee80211_ptr);
3329 err = rdev_add_key(rdev, dev, key.idx,
3330 key.type == NL80211_KEYTYPE_PAIRWISE,
3332 wdev_unlock(dev->ieee80211_ptr);
3337 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3341 struct net_device *dev = info->user_ptr[1];
3342 u8 *mac_addr = NULL;
3343 struct key_parse key;
3345 err = nl80211_parse_key(info, &key);
3352 if (info->attrs[NL80211_ATTR_MAC])
3353 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3355 if (key.type == -1) {
3357 key.type = NL80211_KEYTYPE_PAIRWISE;
3359 key.type = NL80211_KEYTYPE_GROUP;
3363 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3364 key.type != NL80211_KEYTYPE_GROUP)
3367 if (!rdev->ops->del_key)
3370 wdev_lock(dev->ieee80211_ptr);
3371 err = nl80211_key_allowed(dev->ieee80211_ptr);
3373 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
3374 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3378 err = rdev_del_key(rdev, dev, key.idx,
3379 key.type == NL80211_KEYTYPE_PAIRWISE,
3382 #ifdef CONFIG_CFG80211_WEXT
3384 if (key.idx == dev->ieee80211_ptr->wext.default_key)
3385 dev->ieee80211_ptr->wext.default_key = -1;
3386 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
3387 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3390 wdev_unlock(dev->ieee80211_ptr);
3395 /* This function returns an error or the number of nested attributes */
3396 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3398 struct nlattr *attr;
3399 int n_entries = 0, tmp;
3401 nla_for_each_nested(attr, nl_attr, tmp) {
3402 if (nla_len(attr) != ETH_ALEN)
3412 * This function parses ACL information and allocates memory for ACL data.
3413 * On successful return, the calling function is responsible to free the
3414 * ACL buffer returned by this function.
3416 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3417 struct genl_info *info)
3419 enum nl80211_acl_policy acl_policy;
3420 struct nlattr *attr;
3421 struct cfg80211_acl_data *acl;
3422 int i = 0, n_entries, tmp;
3424 if (!wiphy->max_acl_mac_addrs)
3425 return ERR_PTR(-EOPNOTSUPP);
3427 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3428 return ERR_PTR(-EINVAL);
3430 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3431 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3432 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3433 return ERR_PTR(-EINVAL);
3435 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3436 return ERR_PTR(-EINVAL);
3438 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3440 return ERR_PTR(n_entries);
3442 if (n_entries > wiphy->max_acl_mac_addrs)
3443 return ERR_PTR(-ENOTSUPP);
3445 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3448 return ERR_PTR(-ENOMEM);
3450 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3451 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3455 acl->n_acl_entries = n_entries;
3456 acl->acl_policy = acl_policy;
3461 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3464 struct net_device *dev = info->user_ptr[1];
3465 struct cfg80211_acl_data *acl;
3468 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3469 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3472 if (!dev->ieee80211_ptr->beacon_interval)
3475 acl = parse_acl_data(&rdev->wiphy, info);
3477 return PTR_ERR(acl);
3479 err = rdev_set_mac_acl(rdev, dev, acl);
3486 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3487 u8 *rates, u8 rates_len)
3492 for (i = 0; i < rates_len; i++) {
3493 int rate = (rates[i] & 0x7f) * 5;
3496 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3497 struct ieee80211_rate *srate =
3498 &sband->bitrates[ridx];
3499 if (rate == srate->bitrate) {
3504 if (ridx == sband->n_bitrates)
3505 return 0; /* rate not found */
3511 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3512 u8 *rates, u8 rates_len,
3513 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3517 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3519 for (i = 0; i < rates_len; i++) {
3522 ridx = rates[i] / 8;
3523 rbit = BIT(rates[i] % 8);
3525 /* check validity */
3526 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3529 /* check availability */
3530 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
3531 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3540 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3544 switch (vht_mcs_map) {
3545 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3547 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3550 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3553 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3563 static void vht_build_mcs_mask(u16 vht_mcs_map,
3564 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3568 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3569 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3574 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3575 struct nl80211_txrate_vht *txrate,
3576 u16 mcs[NL80211_VHT_NSS_MAX])
3578 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3579 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3582 if (!sband->vht_cap.vht_supported)
3585 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3587 /* Build vht_mcs_mask from VHT capabilities */
3588 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3590 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3591 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3592 mcs[i] = txrate->mcs[i];
3600 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3601 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3602 .len = NL80211_MAX_SUPP_RATES },
3603 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3604 .len = NL80211_MAX_SUPP_HT_RATES },
3605 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3606 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3609 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3610 struct cfg80211_bitrate_mask *mask)
3612 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3615 struct nlattr *tx_rates;
3616 struct ieee80211_supported_band *sband;
3619 memset(mask, 0, sizeof(*mask));
3620 /* Default to all rates enabled */
3621 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3622 sband = rdev->wiphy.bands[i];
3627 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3628 memcpy(mask->control[i].ht_mcs,
3629 sband->ht_cap.mcs.rx_mask,
3630 sizeof(mask->control[i].ht_mcs));
3632 if (!sband->vht_cap.vht_supported)
3635 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3636 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3639 /* if no rates are given set it back to the defaults */
3640 if (!info->attrs[NL80211_ATTR_TX_RATES])
3643 /* The nested attribute uses enum nl80211_band as the index. This maps
3644 * directly to the enum nl80211_band values used in cfg80211.
3646 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3647 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3648 enum nl80211_band band = nla_type(tx_rates);
3651 if (band < 0 || band >= NUM_NL80211_BANDS)
3653 sband = rdev->wiphy.bands[band];
3656 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
3657 nl80211_txattr_policy, info->extack);
3660 if (tb[NL80211_TXRATE_LEGACY]) {
3661 mask->control[band].legacy = rateset_to_mask(
3663 nla_data(tb[NL80211_TXRATE_LEGACY]),
3664 nla_len(tb[NL80211_TXRATE_LEGACY]));
3665 if ((mask->control[band].legacy == 0) &&
3666 nla_len(tb[NL80211_TXRATE_LEGACY]))
3669 if (tb[NL80211_TXRATE_HT]) {
3670 if (!ht_rateset_to_mask(
3672 nla_data(tb[NL80211_TXRATE_HT]),
3673 nla_len(tb[NL80211_TXRATE_HT]),
3674 mask->control[band].ht_mcs))
3677 if (tb[NL80211_TXRATE_VHT]) {
3678 if (!vht_set_mcs_mask(
3680 nla_data(tb[NL80211_TXRATE_VHT]),
3681 mask->control[band].vht_mcs))
3684 if (tb[NL80211_TXRATE_GI]) {
3685 mask->control[band].gi =
3686 nla_get_u8(tb[NL80211_TXRATE_GI]);
3687 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3691 if (mask->control[band].legacy == 0) {
3692 /* don't allow empty legacy rates if HT or VHT
3693 * are not even supported.
3695 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3696 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3699 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3700 if (mask->control[band].ht_mcs[i])
3703 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3704 if (mask->control[band].vht_mcs[i])
3707 /* legacy and mcs rates may not be both empty */
3716 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3717 enum nl80211_band band,
3718 struct cfg80211_bitrate_mask *beacon_rate)
3720 u32 count_ht, count_vht, i;
3721 u32 rate = beacon_rate->control[band].legacy;
3723 /* Allow only one rate */
3724 if (hweight32(rate) > 1)
3728 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3729 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
3731 } else if (beacon_rate->control[band].ht_mcs[i]) {
3736 if (count_ht && rate)
3741 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3742 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
3744 } else if (beacon_rate->control[band].vht_mcs[i]) {
3749 if (count_vht && rate)
3753 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3757 !wiphy_ext_feature_isset(&rdev->wiphy,
3758 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3761 !wiphy_ext_feature_isset(&rdev->wiphy,
3762 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3765 !wiphy_ext_feature_isset(&rdev->wiphy,
3766 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3772 static int nl80211_parse_beacon(struct nlattr *attrs[],
3773 struct cfg80211_beacon_data *bcn)
3775 bool haveinfo = false;
3777 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3778 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3779 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3780 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
3783 memset(bcn, 0, sizeof(*bcn));
3785 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3786 int ret = validate_beacon_head(attrs[NL80211_ATTR_BEACON_HEAD],
3792 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3793 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
3799 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3800 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3801 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
3808 if (attrs[NL80211_ATTR_IE]) {
3809 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3810 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
3813 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
3814 bcn->proberesp_ies =
3815 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
3816 bcn->proberesp_ies_len =
3817 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
3820 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
3821 bcn->assocresp_ies =
3822 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
3823 bcn->assocresp_ies_len =
3824 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
3827 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3828 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3829 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
3835 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
3843 for (i = 0; i < rates[1]; i++) {
3844 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
3845 params->ht_required = true;
3846 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
3847 params->vht_required = true;
3852 * Since the nl80211 API didn't include, from the beginning, attributes about
3853 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3854 * benefit of drivers that rebuild IEs in the firmware.
3856 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
3858 const struct cfg80211_beacon_data *bcn = ¶ms->beacon;
3859 size_t ies_len = bcn->tail_len;
3860 const u8 *ies = bcn->tail;
3864 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
3865 nl80211_check_ap_rate_selectors(params, rates);
3867 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
3868 nl80211_check_ap_rate_selectors(params, rates);
3870 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
3871 if (cap && cap[1] >= sizeof(*params->ht_cap))
3872 params->ht_cap = (void *)(cap + 2);
3873 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
3874 if (cap && cap[1] >= sizeof(*params->vht_cap))
3875 params->vht_cap = (void *)(cap + 2);
3878 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3879 struct cfg80211_ap_settings *params)
3881 struct wireless_dev *wdev;
3884 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
3885 if (wdev->iftype != NL80211_IFTYPE_AP &&
3886 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3889 if (!wdev->preset_chandef.chan)
3892 params->chandef = wdev->preset_chandef;
3900 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3901 enum nl80211_auth_type auth_type,
3902 enum nl80211_commands cmd)
3904 if (auth_type > NL80211_AUTHTYPE_MAX)
3908 case NL80211_CMD_AUTHENTICATE:
3909 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3910 auth_type == NL80211_AUTHTYPE_SAE)
3912 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3913 NL80211_EXT_FEATURE_FILS_STA) &&
3914 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3915 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3916 auth_type == NL80211_AUTHTYPE_FILS_PK))
3919 case NL80211_CMD_CONNECT:
3920 /* SAE not supported yet */
3921 if (auth_type == NL80211_AUTHTYPE_SAE)
3923 /* FILS with SK PFS or PK not supported yet */
3924 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3925 auth_type == NL80211_AUTHTYPE_FILS_PK)
3927 if (!wiphy_ext_feature_isset(
3929 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3930 auth_type == NL80211_AUTHTYPE_FILS_SK)
3933 case NL80211_CMD_START_AP:
3934 /* SAE not supported yet */
3935 if (auth_type == NL80211_AUTHTYPE_SAE)
3937 /* FILS not supported yet */
3938 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3939 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3940 auth_type == NL80211_AUTHTYPE_FILS_PK)
3948 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3951 struct net_device *dev = info->user_ptr[1];
3952 struct wireless_dev *wdev = dev->ieee80211_ptr;
3953 struct cfg80211_ap_settings params;
3956 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3957 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3960 if (!rdev->ops->start_ap)
3963 if (wdev->beacon_interval)
3966 memset(¶ms, 0, sizeof(params));
3968 /* these are required for START_AP */
3969 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3970 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3971 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3974 err = nl80211_parse_beacon(info->attrs, ¶ms.beacon);
3978 params.beacon_interval =
3979 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3980 params.dtim_period =
3981 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3983 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3984 params.beacon_interval);
3989 * In theory, some of these attributes should be required here
3990 * but since they were not used when the command was originally
3991 * added, keep them optional for old user space programs to let
3992 * them continue to work with drivers that do not need the
3993 * additional information -- drivers must check!
3995 if (info->attrs[NL80211_ATTR_SSID]) {
3996 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3998 nla_len(info->attrs[NL80211_ATTR_SSID]);
3999 if (params.ssid_len == 0 ||
4000 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4004 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
4005 params.hidden_ssid = nla_get_u32(
4006 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
4007 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
4008 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
4009 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
4013 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4015 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4016 params.auth_type = nla_get_u32(
4017 info->attrs[NL80211_ATTR_AUTH_TYPE]);
4018 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4019 NL80211_CMD_START_AP))
4022 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4024 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
4025 NL80211_MAX_NR_CIPHER_SUITES);
4029 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4030 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4032 params.inactivity_timeout = nla_get_u16(
4033 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4036 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4039 params.p2p_ctwindow =
4040 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4041 if (params.p2p_ctwindow > 127)
4043 if (params.p2p_ctwindow != 0 &&
4044 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4048 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4051 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4053 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4056 params.p2p_opp_ps = tmp;
4057 if (params.p2p_opp_ps != 0 &&
4058 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4062 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4063 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
4066 } else if (wdev->preset_chandef.chan) {
4067 params.chandef = wdev->preset_chandef;
4068 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
4071 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
4075 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4076 err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate);
4080 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4081 ¶ms.beacon_rate);
4086 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4088 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4089 switch (params.smps_mode) {
4090 case NL80211_SMPS_OFF:
4092 case NL80211_SMPS_STATIC:
4093 if (!(rdev->wiphy.features &
4094 NL80211_FEATURE_STATIC_SMPS))
4097 case NL80211_SMPS_DYNAMIC:
4098 if (!(rdev->wiphy.features &
4099 NL80211_FEATURE_DYNAMIC_SMPS))
4106 params.smps_mode = NL80211_SMPS_OFF;
4109 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4110 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4113 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4114 params.acl = parse_acl_data(&rdev->wiphy, info);
4115 if (IS_ERR(params.acl))
4116 return PTR_ERR(params.acl);
4119 nl80211_calculate_ap_params(¶ms);
4122 err = rdev_start_ap(rdev, dev, ¶ms);
4124 wdev->preset_chandef = params.chandef;
4125 wdev->beacon_interval = params.beacon_interval;
4126 wdev->chandef = params.chandef;
4127 wdev->ssid_len = params.ssid_len;
4128 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
4137 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4140 struct net_device *dev = info->user_ptr[1];
4141 struct wireless_dev *wdev = dev->ieee80211_ptr;
4142 struct cfg80211_beacon_data params;
4145 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4146 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4149 if (!rdev->ops->change_beacon)
4152 if (!wdev->beacon_interval)
4155 err = nl80211_parse_beacon(info->attrs, ¶ms);
4160 err = rdev_change_beacon(rdev, dev, ¶ms);
4166 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
4168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4169 struct net_device *dev = info->user_ptr[1];
4171 return cfg80211_stop_ap(rdev, dev, false);
4174 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4175 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4176 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4177 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
4178 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
4179 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
4180 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
4183 static int parse_station_flags(struct genl_info *info,
4184 enum nl80211_iftype iftype,
4185 struct station_parameters *params)
4187 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
4192 * Try parsing the new attribute first so userspace
4193 * can specify both for older kernels.
4195 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4197 struct nl80211_sta_flag_update *sta_flags;
4199 sta_flags = nla_data(nla);
4200 params->sta_flags_mask = sta_flags->mask;
4201 params->sta_flags_set = sta_flags->set;
4202 params->sta_flags_set &= params->sta_flags_mask;
4203 if ((params->sta_flags_mask |
4204 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4209 /* if present, parse the old attribute */
4211 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
4215 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla,
4216 sta_flags_policy, info->extack))
4220 * Only allow certain flags for interface types so that
4221 * other attributes are silently ignored. Remember that
4222 * this is backward compatibility code with old userspace
4223 * and shouldn't be hit in other cases anyway.
4226 case NL80211_IFTYPE_AP:
4227 case NL80211_IFTYPE_AP_VLAN:
4228 case NL80211_IFTYPE_P2P_GO:
4229 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4230 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4231 BIT(NL80211_STA_FLAG_WME) |
4232 BIT(NL80211_STA_FLAG_MFP);
4234 case NL80211_IFTYPE_P2P_CLIENT:
4235 case NL80211_IFTYPE_STATION:
4236 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4237 BIT(NL80211_STA_FLAG_TDLS_PEER);
4239 case NL80211_IFTYPE_MESH_POINT:
4240 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4241 BIT(NL80211_STA_FLAG_MFP) |
4242 BIT(NL80211_STA_FLAG_AUTHORIZED);
4248 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4250 params->sta_flags_set |= (1<<flag);
4252 /* no longer support new API additions in old API */
4253 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4261 static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4264 struct nlattr *rate;
4267 enum nl80211_rate_info rate_flg;
4269 rate = nla_nest_start(msg, attr);
4273 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4274 bitrate = cfg80211_calculate_bitrate(info);
4275 /* report 16-bit bitrate only if we can */
4276 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
4278 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4280 if (bitrate_compat > 0 &&
4281 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4285 case RATE_INFO_BW_5:
4286 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4288 case RATE_INFO_BW_10:
4289 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4294 case RATE_INFO_BW_20:
4297 case RATE_INFO_BW_40:
4298 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4300 case RATE_INFO_BW_80:
4301 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4303 case RATE_INFO_BW_160:
4304 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4308 if (rate_flg && nla_put_flag(msg, rate_flg))
4311 if (info->flags & RATE_INFO_FLAGS_MCS) {
4312 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4314 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4315 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4317 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4318 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4320 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4322 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4323 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4327 nla_nest_end(msg, rate);
4331 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4340 attr = nla_nest_start(msg, id);
4344 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4345 if (!(mask & BIT(i)))
4348 if (nla_put_u8(msg, i, signal[i]))
4352 nla_nest_end(msg, attr);
4357 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4359 struct cfg80211_registered_device *rdev,
4360 struct net_device *dev,
4361 const u8 *mac_addr, struct station_info *sinfo)
4364 struct nlattr *sinfoattr, *bss_param;
4366 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
4370 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4371 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4372 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4373 goto nla_put_failure;
4375 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4377 goto nla_put_failure;
4379 #define PUT_SINFO(attr, memb, type) do { \
4380 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
4381 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4382 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4384 goto nla_put_failure; \
4386 #define PUT_SINFO_U64(attr, memb) do { \
4387 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4388 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4389 sinfo->memb, NL80211_STA_INFO_PAD)) \
4390 goto nla_put_failure; \
4393 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4394 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4396 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4397 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
4398 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
4399 (u32)sinfo->rx_bytes))
4400 goto nla_put_failure;
4402 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4403 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
4404 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4405 (u32)sinfo->tx_bytes))
4406 goto nla_put_failure;
4408 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4409 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
4410 PUT_SINFO(LLID, llid, u16);
4411 PUT_SINFO(PLID, plid, u16);
4412 PUT_SINFO(PLINK_STATE, plink_state, u8);
4413 PUT_SINFO_U64(RX_DURATION, rx_duration);
4415 switch (rdev->wiphy.signal_type) {
4416 case CFG80211_SIGNAL_TYPE_MBM:
4417 PUT_SINFO(SIGNAL, signal, u8);
4418 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
4423 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
4424 if (!nl80211_put_signal(msg, sinfo->chains,
4425 sinfo->chain_signal,
4426 NL80211_STA_INFO_CHAIN_SIGNAL))
4427 goto nla_put_failure;
4429 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
4430 if (!nl80211_put_signal(msg, sinfo->chains,
4431 sinfo->chain_signal_avg,
4432 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4433 goto nla_put_failure;
4435 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
4436 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4437 NL80211_STA_INFO_TX_BITRATE))
4438 goto nla_put_failure;
4440 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
4441 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4442 NL80211_STA_INFO_RX_BITRATE))
4443 goto nla_put_failure;
4446 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4447 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4448 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4449 PUT_SINFO(TX_FAILED, tx_failed, u32);
4450 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4451 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4452 PUT_SINFO(LOCAL_PM, local_pm, u32);
4453 PUT_SINFO(PEER_PM, peer_pm, u32);
4454 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4456 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
4457 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4459 goto nla_put_failure;
4461 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4462 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4463 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4464 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4465 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4466 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4467 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4468 sinfo->bss_param.dtim_period) ||
4469 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4470 sinfo->bss_param.beacon_interval))
4471 goto nla_put_failure;
4473 nla_nest_end(msg, bss_param);
4475 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
4476 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4477 sizeof(struct nl80211_sta_flag_update),
4479 goto nla_put_failure;
4481 PUT_SINFO_U64(T_OFFSET, t_offset);
4482 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4483 PUT_SINFO_U64(BEACON_RX, rx_beacon);
4484 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
4487 #undef PUT_SINFO_U64
4489 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4490 struct nlattr *tidsattr;
4493 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4495 goto nla_put_failure;
4497 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4498 struct cfg80211_tid_stats *tidstats;
4499 struct nlattr *tidattr;
4501 tidstats = &sinfo->pertid[tid];
4503 if (!tidstats->filled)
4506 tidattr = nla_nest_start(msg, tid + 1);
4508 goto nla_put_failure;
4510 #define PUT_TIDVAL_U64(attr, memb) do { \
4511 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
4512 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4513 tidstats->memb, NL80211_TID_STATS_PAD)) \
4514 goto nla_put_failure; \
4517 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4518 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4519 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4520 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
4522 #undef PUT_TIDVAL_U64
4523 nla_nest_end(msg, tidattr);
4526 nla_nest_end(msg, tidsattr);
4529 nla_nest_end(msg, sinfoattr);
4531 if (sinfo->assoc_req_ies_len &&
4532 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4533 sinfo->assoc_req_ies))
4534 goto nla_put_failure;
4536 genlmsg_end(msg, hdr);
4540 genlmsg_cancel(msg, hdr);
4544 static int nl80211_dump_station(struct sk_buff *skb,
4545 struct netlink_callback *cb)
4547 struct station_info sinfo;
4548 struct cfg80211_registered_device *rdev;
4549 struct wireless_dev *wdev;
4550 u8 mac_addr[ETH_ALEN];
4551 int sta_idx = cb->args[2];
4555 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4559 if (!wdev->netdev) {
4564 if (!rdev->ops->dump_station) {
4570 memset(&sinfo, 0, sizeof(sinfo));
4571 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
4578 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
4579 NETLINK_CB(cb->skb).portid,
4580 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4581 rdev, wdev->netdev, mac_addr,
4589 cb->args[2] = sta_idx;
4597 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4600 struct net_device *dev = info->user_ptr[1];
4601 struct station_info sinfo;
4602 struct sk_buff *msg;
4603 u8 *mac_addr = NULL;
4606 memset(&sinfo, 0, sizeof(sinfo));
4608 if (!info->attrs[NL80211_ATTR_MAC])
4611 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4613 if (!rdev->ops->get_station)
4616 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
4620 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4624 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4625 info->snd_portid, info->snd_seq, 0,
4626 rdev, dev, mac_addr, &sinfo) < 0) {
4631 return genlmsg_reply(msg, info);
4634 int cfg80211_check_station_change(struct wiphy *wiphy,
4635 struct station_parameters *params,
4636 enum cfg80211_station_type statype)
4638 if (params->listen_interval != -1 &&
4639 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4642 if (params->support_p2p_ps != -1 &&
4643 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4647 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4648 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4651 /* When you run into this, adjust the code below for the new flag */
4652 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4655 case CFG80211_STA_MESH_PEER_KERNEL:
4656 case CFG80211_STA_MESH_PEER_USER:
4658 * No ignoring the TDLS flag here -- the userspace mesh
4659 * code doesn't have the bug of including TDLS in the
4662 if (params->sta_flags_mask &
4663 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4664 BIT(NL80211_STA_FLAG_MFP) |
4665 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4668 case CFG80211_STA_TDLS_PEER_SETUP:
4669 case CFG80211_STA_TDLS_PEER_ACTIVE:
4670 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4672 /* ignore since it can't change */
4673 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4676 /* disallow mesh-specific things */
4677 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4679 if (params->local_pm)
4681 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4685 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4686 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4687 /* TDLS can't be set, ... */
4688 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4691 * ... but don't bother the driver with it. This works around
4692 * a hostapd/wpa_supplicant issue -- it always includes the
4693 * TLDS_PEER flag in the mask even for AP mode.
4695 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4698 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4699 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
4700 /* reject other things that can't change */
4701 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4703 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4705 if (params->supported_rates)
4707 if (params->ext_capab || params->ht_capa || params->vht_capa)
4711 if (statype != CFG80211_STA_AP_CLIENT &&
4712 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
4718 case CFG80211_STA_AP_MLME_CLIENT:
4719 /* Use this only for authorizing/unauthorizing a station */
4720 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4723 case CFG80211_STA_AP_CLIENT:
4724 case CFG80211_STA_AP_CLIENT_UNASSOC:
4725 /* accept only the listed bits */
4726 if (params->sta_flags_mask &
4727 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4728 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4729 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4730 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4731 BIT(NL80211_STA_FLAG_WME) |
4732 BIT(NL80211_STA_FLAG_MFP)))
4735 /* but authenticated/associated only if driver handles it */
4736 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4737 params->sta_flags_mask &
4738 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4739 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4742 case CFG80211_STA_IBSS:
4743 case CFG80211_STA_AP_STA:
4744 /* reject any changes other than AUTHORIZED */
4745 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4748 case CFG80211_STA_TDLS_PEER_SETUP:
4749 /* reject any changes other than AUTHORIZED or WME */
4750 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4751 BIT(NL80211_STA_FLAG_WME)))
4753 /* force (at least) rates when authorizing */
4754 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4755 !params->supported_rates)
4758 case CFG80211_STA_TDLS_PEER_ACTIVE:
4759 /* reject any changes */
4761 case CFG80211_STA_MESH_PEER_KERNEL:
4762 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4765 case CFG80211_STA_MESH_PEER_USER:
4766 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4767 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
4773 * Older kernel versions ignored this attribute entirely, so don't
4774 * reject attempts to update it but mark it as unused instead so the
4775 * driver won't look at the data.
4777 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
4778 statype != CFG80211_STA_TDLS_PEER_SETUP)
4779 params->opmode_notif_used = false;
4783 EXPORT_SYMBOL(cfg80211_check_station_change);
4786 * Get vlan interface making sure it is running and on the right wiphy.
4788 static struct net_device *get_vlan(struct genl_info *info,
4789 struct cfg80211_registered_device *rdev)
4791 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
4792 struct net_device *v;
4798 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4800 return ERR_PTR(-ENODEV);
4802 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4807 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4808 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4809 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4814 if (!netif_running(v)) {
4822 return ERR_PTR(ret);
4825 static const struct nla_policy
4826 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
4827 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4828 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4831 static int nl80211_parse_sta_wme(struct genl_info *info,
4832 struct station_parameters *params)
4834 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4838 /* parse WME attributes if present */
4839 if (!info->attrs[NL80211_ATTR_STA_WME])
4842 nla = info->attrs[NL80211_ATTR_STA_WME];
4843 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4844 nl80211_sta_wme_policy, info->extack);
4848 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4849 params->uapsd_queues = nla_get_u8(
4850 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4851 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4854 if (tb[NL80211_STA_WME_MAX_SP])
4855 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4857 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4860 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4865 static int nl80211_parse_sta_channel_info(struct genl_info *info,
4866 struct station_parameters *params)
4868 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4869 params->supported_channels =
4870 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4871 params->supported_channels_len =
4872 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4874 * Need to include at least one (first channel, number of
4875 * channels) tuple for each subband, and must have proper
4876 * tuples for the rest of the data as well.
4878 if (params->supported_channels_len < 2)
4880 if (params->supported_channels_len % 2)
4884 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4885 params->supported_oper_classes =
4886 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4887 params->supported_oper_classes_len =
4888 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4890 * The value of the Length field of the Supported Operating
4891 * Classes element is between 2 and 253.
4893 if (params->supported_oper_classes_len < 2 ||
4894 params->supported_oper_classes_len > 253)
4900 static int nl80211_set_station_tdls(struct genl_info *info,
4901 struct station_parameters *params)
4904 /* Dummy STA entry gets updated once the peer capabilities are known */
4905 if (info->attrs[NL80211_ATTR_PEER_AID])
4906 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
4907 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4909 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4910 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4912 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4914 err = nl80211_parse_sta_channel_info(info, params);
4918 return nl80211_parse_sta_wme(info, params);
4921 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4924 struct net_device *dev = info->user_ptr[1];
4925 struct station_parameters params;
4929 memset(¶ms, 0, sizeof(params));
4931 if (!rdev->ops->change_station)
4935 * AID and listen_interval properties can be set only for unassociated
4936 * station. Include these parameters here and will check them in
4937 * cfg80211_check_station_change().
4939 if (info->attrs[NL80211_ATTR_STA_AID])
4940 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
4942 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4943 params.listen_interval =
4944 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4946 params.listen_interval = -1;
4948 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4951 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4952 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4955 params.support_p2p_ps = tmp;
4957 params.support_p2p_ps = -1;
4960 if (!info->attrs[NL80211_ATTR_MAC])
4963 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4965 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4966 params.supported_rates =
4967 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4968 params.supported_rates_len =
4969 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4972 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4974 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4975 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4978 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4980 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4981 params.ext_capab_len =
4982 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4985 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
4988 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
4989 params.plink_action =
4990 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4991 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4995 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
4996 params.plink_state =
4997 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4998 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
5000 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
5001 params.peer_aid = nla_get_u16(
5002 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
5003 if (params.peer_aid > IEEE80211_MAX_AID)
5006 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5009 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
5010 enum nl80211_mesh_power_mode pm = nla_get_u32(
5011 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5013 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
5014 pm > NL80211_MESH_POWER_MAX)
5017 params.local_pm = pm;
5020 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5021 params.opmode_notif_used = true;
5022 params.opmode_notif =
5023 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5026 /* Include parameters for TDLS peer (will check later) */
5027 err = nl80211_set_station_tdls(info, ¶ms);
5031 params.vlan = get_vlan(info, rdev);
5032 if (IS_ERR(params.vlan))
5033 return PTR_ERR(params.vlan);
5035 switch (dev->ieee80211_ptr->iftype) {
5036 case NL80211_IFTYPE_AP:
5037 case NL80211_IFTYPE_AP_VLAN:
5038 case NL80211_IFTYPE_P2P_GO:
5039 case NL80211_IFTYPE_P2P_CLIENT:
5040 case NL80211_IFTYPE_STATION:
5041 case NL80211_IFTYPE_ADHOC:
5042 case NL80211_IFTYPE_MESH_POINT:
5049 /* driver will call cfg80211_check_station_change() */
5050 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
5054 dev_put(params.vlan);
5059 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5063 struct net_device *dev = info->user_ptr[1];
5064 struct station_parameters params;
5065 u8 *mac_addr = NULL;
5066 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5067 BIT(NL80211_STA_FLAG_ASSOCIATED);
5069 memset(¶ms, 0, sizeof(params));
5071 if (!rdev->ops->add_station)
5074 if (!info->attrs[NL80211_ATTR_MAC])
5077 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5080 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
5083 if (!info->attrs[NL80211_ATTR_STA_AID] &&
5084 !info->attrs[NL80211_ATTR_PEER_AID])
5087 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5088 params.supported_rates =
5089 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5090 params.supported_rates_len =
5091 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5092 params.listen_interval =
5093 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5095 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
5098 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5099 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
5102 params.support_p2p_ps = tmp;
5105 * if not specified, assume it's supported for P2P GO interface,
5106 * and is NOT supported for AP interface
5108 params.support_p2p_ps =
5109 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
5112 if (info->attrs[NL80211_ATTR_PEER_AID])
5113 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
5115 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
5116 if (!params.aid || params.aid > IEEE80211_MAX_AID)
5119 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5121 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5122 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5125 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5127 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5128 params.ext_capab_len =
5129 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5132 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5134 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5136 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5138 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
5140 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5141 params.opmode_notif_used = true;
5142 params.opmode_notif =
5143 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5146 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
5147 params.plink_action =
5148 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5149 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5153 err = nl80211_parse_sta_channel_info(info, ¶ms);
5157 err = nl80211_parse_sta_wme(info, ¶ms);
5161 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
5164 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5165 * as userspace might just pass through the capabilities from the IEs
5166 * directly, rather than enforcing this restriction and returning an
5167 * error in this case.
5169 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5170 params.ht_capa = NULL;
5171 params.vht_capa = NULL;
5174 /* When you run into this, adjust the code below for the new flag */
5175 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5177 switch (dev->ieee80211_ptr->iftype) {
5178 case NL80211_IFTYPE_AP:
5179 case NL80211_IFTYPE_AP_VLAN:
5180 case NL80211_IFTYPE_P2P_GO:
5181 /* ignore WME attributes if iface/sta is not capable */
5182 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5183 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5184 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5186 /* TDLS peers cannot be added */
5187 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5188 info->attrs[NL80211_ATTR_PEER_AID])
5190 /* but don't bother the driver with it */
5191 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5193 /* allow authenticated/associated only if driver handles it */
5194 if (!(rdev->wiphy.features &
5195 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5196 params.sta_flags_mask & auth_assoc)
5199 /* Older userspace, or userspace wanting to be compatible with
5200 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5201 * and assoc flags in the mask, but assumes the station will be
5202 * added as associated anyway since this was the required driver
5203 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5205 * In order to not bother drivers with this quirk in the API
5206 * set the flags in both the mask and set for new stations in
5209 if (!(params.sta_flags_mask & auth_assoc)) {
5210 params.sta_flags_mask |= auth_assoc;
5211 params.sta_flags_set |= auth_assoc;
5214 /* must be last in here for error handling */
5215 params.vlan = get_vlan(info, rdev);
5216 if (IS_ERR(params.vlan))
5217 return PTR_ERR(params.vlan);
5219 case NL80211_IFTYPE_MESH_POINT:
5220 /* ignore uAPSD data */
5221 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5223 /* associated is disallowed */
5224 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5226 /* TDLS peers cannot be added */
5227 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5228 info->attrs[NL80211_ATTR_PEER_AID])
5231 case NL80211_IFTYPE_STATION:
5232 case NL80211_IFTYPE_P2P_CLIENT:
5233 /* ignore uAPSD data */
5234 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5236 /* these are disallowed */
5237 if (params.sta_flags_mask &
5238 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5239 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
5241 /* Only TDLS peers can be added */
5242 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5244 /* Can only add if TDLS ... */
5245 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5247 /* ... with external setup is supported */
5248 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5251 * Older wpa_supplicant versions always mark the TDLS peer
5252 * as authorized, but it shouldn't yet be.
5254 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
5260 /* be aware of params.vlan when changing code here */
5262 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
5265 dev_put(params.vlan);
5269 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5272 struct net_device *dev = info->user_ptr[1];
5273 struct station_del_parameters params;
5275 memset(¶ms, 0, sizeof(params));
5277 if (info->attrs[NL80211_ATTR_MAC])
5278 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
5280 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5281 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5282 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
5283 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5286 if (!rdev->ops->del_station)
5289 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5291 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5292 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5293 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5296 /* Default to Deauthentication frame */
5297 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5300 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5301 params.reason_code =
5302 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5303 if (params.reason_code == 0)
5304 return -EINVAL; /* 0 is reserved */
5306 /* Default to reason code 2 */
5307 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5310 return rdev_del_station(rdev, dev, ¶ms);
5313 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
5314 int flags, struct net_device *dev,
5315 u8 *dst, u8 *next_hop,
5316 struct mpath_info *pinfo)
5319 struct nlattr *pinfoattr;
5321 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
5325 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5326 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5327 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5328 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5329 goto nla_put_failure;
5331 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5333 goto nla_put_failure;
5334 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5335 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5337 goto nla_put_failure;
5338 if (((pinfo->filled & MPATH_INFO_SN) &&
5339 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5340 ((pinfo->filled & MPATH_INFO_METRIC) &&
5341 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5343 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5344 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5346 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5347 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5349 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5350 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5351 pinfo->discovery_timeout)) ||
5352 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5353 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5354 pinfo->discovery_retries)))
5355 goto nla_put_failure;
5357 nla_nest_end(msg, pinfoattr);
5359 genlmsg_end(msg, hdr);
5363 genlmsg_cancel(msg, hdr);
5367 static int nl80211_dump_mpath(struct sk_buff *skb,
5368 struct netlink_callback *cb)
5370 struct mpath_info pinfo;
5371 struct cfg80211_registered_device *rdev;
5372 struct wireless_dev *wdev;
5374 u8 next_hop[ETH_ALEN];
5375 int path_idx = cb->args[2];
5379 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5383 if (!rdev->ops->dump_mpath) {
5388 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5394 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
5401 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5402 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5403 wdev->netdev, dst, next_hop,
5411 cb->args[2] = path_idx;
5418 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5422 struct net_device *dev = info->user_ptr[1];
5423 struct mpath_info pinfo;
5424 struct sk_buff *msg;
5426 u8 next_hop[ETH_ALEN];
5428 memset(&pinfo, 0, sizeof(pinfo));
5430 if (!info->attrs[NL80211_ATTR_MAC])
5433 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5435 if (!rdev->ops->get_mpath)
5438 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5441 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
5445 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5449 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5450 dev, dst, next_hop, &pinfo) < 0) {
5455 return genlmsg_reply(msg, info);
5458 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5461 struct net_device *dev = info->user_ptr[1];
5463 u8 *next_hop = NULL;
5465 if (!info->attrs[NL80211_ATTR_MAC])
5468 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5471 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5472 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5474 if (!rdev->ops->change_mpath)
5477 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5480 return rdev_change_mpath(rdev, dev, dst, next_hop);
5483 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5486 struct net_device *dev = info->user_ptr[1];
5488 u8 *next_hop = NULL;
5490 if (!info->attrs[NL80211_ATTR_MAC])
5493 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5496 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5497 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5499 if (!rdev->ops->add_mpath)
5502 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5505 return rdev_add_mpath(rdev, dev, dst, next_hop);
5508 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5511 struct net_device *dev = info->user_ptr[1];
5514 if (info->attrs[NL80211_ATTR_MAC])
5515 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5517 if (!rdev->ops->del_mpath)
5520 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5523 return rdev_del_mpath(rdev, dev, dst);
5526 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5530 struct net_device *dev = info->user_ptr[1];
5531 struct mpath_info pinfo;
5532 struct sk_buff *msg;
5536 memset(&pinfo, 0, sizeof(pinfo));
5538 if (!info->attrs[NL80211_ATTR_MAC])
5541 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5543 if (!rdev->ops->get_mpp)
5546 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5549 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5553 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5557 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5558 dev, dst, mpp, &pinfo) < 0) {
5563 return genlmsg_reply(msg, info);
5566 static int nl80211_dump_mpp(struct sk_buff *skb,
5567 struct netlink_callback *cb)
5569 struct mpath_info pinfo;
5570 struct cfg80211_registered_device *rdev;
5571 struct wireless_dev *wdev;
5574 int path_idx = cb->args[2];
5578 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5582 if (!rdev->ops->dump_mpp) {
5587 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5593 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5600 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5601 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5602 wdev->netdev, dst, mpp,
5610 cb->args[2] = path_idx;
5617 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5620 struct net_device *dev = info->user_ptr[1];
5621 struct wireless_dev *wdev = dev->ieee80211_ptr;
5622 struct bss_parameters params;
5625 memset(¶ms, 0, sizeof(params));
5626 /* default to not changing parameters */
5627 params.use_cts_prot = -1;
5628 params.use_short_preamble = -1;
5629 params.use_short_slot_time = -1;
5630 params.ap_isolate = -1;
5631 params.ht_opmode = -1;
5632 params.p2p_ctwindow = -1;
5633 params.p2p_opp_ps = -1;
5635 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5636 params.use_cts_prot =
5637 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5638 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5639 params.use_short_preamble =
5640 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5641 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5642 params.use_short_slot_time =
5643 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
5644 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5645 params.basic_rates =
5646 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5647 params.basic_rates_len =
5648 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5650 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5651 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
5652 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5654 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
5656 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5657 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5659 params.p2p_ctwindow =
5660 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5661 if (params.p2p_ctwindow < 0)
5663 if (params.p2p_ctwindow != 0 &&
5664 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5668 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5671 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5673 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5676 params.p2p_opp_ps = tmp;
5677 if (params.p2p_opp_ps &&
5678 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5682 if (!rdev->ops->change_bss)
5685 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5686 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5690 err = rdev_change_bss(rdev, dev, ¶ms);
5696 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5700 enum nl80211_user_reg_hint_type user_reg_hint_type;
5704 * You should only get this when cfg80211 hasn't yet initialized
5705 * completely when built-in to the kernel right between the time
5706 * window between nl80211_init() and regulatory_init(), if that is
5709 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
5710 return -EINPROGRESS;
5712 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5713 user_reg_hint_type =
5714 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5716 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5718 switch (user_reg_hint_type) {
5719 case NL80211_USER_REG_HINT_USER:
5720 case NL80211_USER_REG_HINT_CELL_BASE:
5721 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5724 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5725 return regulatory_hint_user(data, user_reg_hint_type);
5726 case NL80211_USER_REG_HINT_INDOOR:
5727 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5728 owner_nlportid = info->snd_portid;
5729 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5735 return regulatory_hint_indoor(is_indoor, owner_nlportid);
5741 static int nl80211_get_mesh_config(struct sk_buff *skb,
5742 struct genl_info *info)
5744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5745 struct net_device *dev = info->user_ptr[1];
5746 struct wireless_dev *wdev = dev->ieee80211_ptr;
5747 struct mesh_config cur_params;
5750 struct nlattr *pinfoattr;
5751 struct sk_buff *msg;
5753 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5756 if (!rdev->ops->get_mesh_config)
5760 /* If not connected, get default parameters */
5761 if (!wdev->mesh_id_len)
5762 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5764 err = rdev_get_mesh_config(rdev, dev, &cur_params);
5770 /* Draw up a netlink message to send back */
5771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5774 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5775 NL80211_CMD_GET_MESH_CONFIG);
5778 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
5780 goto nla_put_failure;
5781 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5782 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5783 cur_params.dot11MeshRetryTimeout) ||
5784 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5785 cur_params.dot11MeshConfirmTimeout) ||
5786 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5787 cur_params.dot11MeshHoldingTimeout) ||
5788 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5789 cur_params.dot11MeshMaxPeerLinks) ||
5790 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5791 cur_params.dot11MeshMaxRetries) ||
5792 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5793 cur_params.dot11MeshTTL) ||
5794 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5795 cur_params.element_ttl) ||
5796 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5797 cur_params.auto_open_plinks) ||
5798 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5799 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
5800 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5801 cur_params.dot11MeshHWMPmaxPREQretries) ||
5802 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5803 cur_params.path_refresh_time) ||
5804 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5805 cur_params.min_discovery_timeout) ||
5806 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5807 cur_params.dot11MeshHWMPactivePathTimeout) ||
5808 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5809 cur_params.dot11MeshHWMPpreqMinInterval) ||
5810 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5811 cur_params.dot11MeshHWMPperrMinInterval) ||
5812 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5813 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5814 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5815 cur_params.dot11MeshHWMPRootMode) ||
5816 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5817 cur_params.dot11MeshHWMPRannInterval) ||
5818 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5819 cur_params.dot11MeshGateAnnouncementProtocol) ||
5820 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5821 cur_params.dot11MeshForwarding) ||
5822 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
5823 cur_params.rssi_threshold) ||
5824 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
5825 cur_params.ht_opmode) ||
5826 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5827 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5828 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5829 cur_params.dot11MeshHWMProotInterval) ||
5830 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5831 cur_params.dot11MeshHWMPconfirmationInterval) ||
5832 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5833 cur_params.power_mode) ||
5834 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
5835 cur_params.dot11MeshAwakeWindowDuration) ||
5836 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5837 cur_params.plink_timeout))
5838 goto nla_put_failure;
5839 nla_nest_end(msg, pinfoattr);
5840 genlmsg_end(msg, hdr);
5841 return genlmsg_reply(msg, info);
5844 genlmsg_cancel(msg, hdr);
5850 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
5851 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5852 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5853 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5854 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5855 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5856 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
5857 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
5858 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
5859 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
5860 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5861 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5862 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5863 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5864 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
5865 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
5866 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
5867 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
5868 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
5869 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
5870 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
5871 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5872 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
5873 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5874 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
5875 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
5876 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5877 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
5878 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
5881 static const struct nla_policy
5882 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
5883 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
5884 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5885 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
5886 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
5887 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
5888 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
5889 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
5890 .len = IEEE80211_MAX_DATA_LEN },
5891 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
5894 static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5896 u8 val = nla_get_u8(nla);
5897 if (val < min || val > max)
5903 static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5905 u8 val = nla_get_u8(nla);
5906 if (val < min || val > max)
5912 static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5914 u16 val = nla_get_u16(nla);
5915 if (val < min || val > max)
5921 static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5923 u32 val = nla_get_u32(nla);
5924 if (val < min || val > max)
5930 static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5932 s32 val = nla_get_s32(nla);
5933 if (val < min || val > max)
5939 static int nl80211_check_power_mode(const struct nlattr *nla,
5940 enum nl80211_mesh_power_mode min,
5941 enum nl80211_mesh_power_mode max,
5942 enum nl80211_mesh_power_mode *out)
5944 u32 val = nla_get_u32(nla);
5945 if (val < min || val > max)
5951 static int nl80211_parse_mesh_config(struct genl_info *info,
5952 struct mesh_config *cfg,
5955 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
5959 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5962 if (fn(tb[attr], min, max, &cfg->param)) \
5964 mask |= (1 << (attr - 1)); \
5968 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
5970 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
5971 info->attrs[NL80211_ATTR_MESH_CONFIG],
5972 nl80211_meshconf_params_policy, info->extack))
5975 /* This makes sure that there aren't more than 32 mesh config
5976 * parameters (otherwise our bitfield scheme would not work.) */
5977 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5979 /* Fill in the params struct */
5980 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
5981 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5983 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
5984 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5986 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
5987 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5989 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
5990 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5992 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
5993 mask, NL80211_MESHCONF_MAX_RETRIES,
5995 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
5996 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
5997 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
5998 mask, NL80211_MESHCONF_ELEMENT_TTL,
6000 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
6001 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6002 nl80211_check_bool);
6003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
6005 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6007 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
6008 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6010 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
6011 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
6013 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
6014 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6016 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
6018 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6020 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
6022 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6024 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
6026 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6028 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
6029 dot11MeshHWMPnetDiameterTraversalTime,
6031 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6033 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
6034 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
6036 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
6037 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6039 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
6040 dot11MeshGateAnnouncementProtocol, 0, 1,
6041 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6042 nl80211_check_bool);
6043 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
6044 mask, NL80211_MESHCONF_FORWARDING,
6045 nl80211_check_bool);
6046 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
6047 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
6050 * Check HT operation mode based on
6051 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
6053 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6054 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6056 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6057 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6058 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
6061 /* NON_HT_STA bit is reserved, but some programs set it */
6062 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
6064 cfg->ht_opmode = ht_opmode;
6065 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
6067 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
6069 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6071 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
6072 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
6074 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
6075 dot11MeshHWMPconfirmationInterval,
6077 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
6079 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
6080 NL80211_MESH_POWER_ACTIVE,
6081 NL80211_MESH_POWER_MAX,
6082 mask, NL80211_MESHCONF_POWER_MODE,
6083 nl80211_check_power_mode);
6084 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
6086 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
6087 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
6088 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
6095 #undef FILL_IN_MESH_PARAM_IF_SET
6098 static int nl80211_parse_mesh_setup(struct genl_info *info,
6099 struct mesh_setup *setup)
6101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6102 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
6104 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6106 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
6107 info->attrs[NL80211_ATTR_MESH_SETUP],
6108 nl80211_mesh_setup_params_policy, info->extack))
6111 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
6112 setup->sync_method =
6113 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
6114 IEEE80211_SYNC_METHOD_VENDOR :
6115 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
6117 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
6118 setup->path_sel_proto =
6119 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
6120 IEEE80211_PATH_PROTOCOL_VENDOR :
6121 IEEE80211_PATH_PROTOCOL_HWMP;
6123 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
6124 setup->path_metric =
6125 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
6126 IEEE80211_PATH_METRIC_VENDOR :
6127 IEEE80211_PATH_METRIC_AIRTIME;
6129 if (tb[NL80211_MESH_SETUP_IE]) {
6130 struct nlattr *ieattr =
6131 tb[NL80211_MESH_SETUP_IE];
6132 if (!is_valid_ie_attr(ieattr))
6134 setup->ie = nla_data(ieattr);
6135 setup->ie_len = nla_len(ieattr);
6137 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6138 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6140 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
6141 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6142 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
6143 if (setup->is_secure)
6144 setup->user_mpm = true;
6146 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6147 if (!setup->user_mpm)
6150 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6156 static int nl80211_update_mesh_config(struct sk_buff *skb,
6157 struct genl_info *info)
6159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6160 struct net_device *dev = info->user_ptr[1];
6161 struct wireless_dev *wdev = dev->ieee80211_ptr;
6162 struct mesh_config cfg;
6166 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6169 if (!rdev->ops->update_mesh_config)
6172 err = nl80211_parse_mesh_config(info, &cfg, &mask);
6177 if (!wdev->mesh_id_len)
6181 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
6188 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6189 struct sk_buff *msg)
6191 struct nlattr *nl_reg_rules;
6194 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6195 (regdom->dfs_region &&
6196 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
6197 goto nla_put_failure;
6199 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6201 goto nla_put_failure;
6203 for (i = 0; i < regdom->n_reg_rules; i++) {
6204 struct nlattr *nl_reg_rule;
6205 const struct ieee80211_reg_rule *reg_rule;
6206 const struct ieee80211_freq_range *freq_range;
6207 const struct ieee80211_power_rule *power_rule;
6208 unsigned int max_bandwidth_khz;
6210 reg_rule = ®dom->reg_rules[i];
6211 freq_range = ®_rule->freq_range;
6212 power_rule = ®_rule->power_rule;
6214 nl_reg_rule = nla_nest_start(msg, i);
6216 goto nla_put_failure;
6218 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6219 if (!max_bandwidth_khz)
6220 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6223 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6225 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6226 freq_range->start_freq_khz) ||
6227 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6228 freq_range->end_freq_khz) ||
6229 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
6230 max_bandwidth_khz) ||
6231 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6232 power_rule->max_antenna_gain) ||
6233 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
6234 power_rule->max_eirp) ||
6235 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6236 reg_rule->dfs_cac_ms))
6237 goto nla_put_failure;
6239 nla_nest_end(msg, nl_reg_rule);
6242 nla_nest_end(msg, nl_reg_rules);
6249 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6251 const struct ieee80211_regdomain *regdom = NULL;
6252 struct cfg80211_registered_device *rdev;
6253 struct wiphy *wiphy = NULL;
6254 struct sk_buff *msg;
6257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6261 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6262 NL80211_CMD_GET_REG);
6266 if (info->attrs[NL80211_ATTR_WIPHY]) {
6269 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6272 return PTR_ERR(rdev);
6275 wiphy = &rdev->wiphy;
6276 self_managed = wiphy->regulatory_flags &
6277 REGULATORY_WIPHY_SELF_MANAGED;
6278 regdom = get_wiphy_regdom(wiphy);
6280 /* a self-managed-reg device must have a private regdom */
6281 if (WARN_ON(!regdom && self_managed)) {
6287 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6288 goto nla_put_failure;
6291 if (!wiphy && reg_last_request_cell_base() &&
6292 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6293 NL80211_USER_REG_HINT_CELL_BASE))
6294 goto nla_put_failure;
6299 regdom = rcu_dereference(cfg80211_regdomain);
6301 if (nl80211_put_regdom(regdom, msg))
6302 goto nla_put_failure_rcu;
6306 genlmsg_end(msg, hdr);
6307 return genlmsg_reply(msg, info);
6309 nla_put_failure_rcu:
6312 genlmsg_cancel(msg, hdr);
6318 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6319 u32 seq, int flags, struct wiphy *wiphy,
6320 const struct ieee80211_regdomain *regdom)
6322 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6323 NL80211_CMD_GET_REG);
6328 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6330 if (nl80211_put_regdom(regdom, msg))
6331 goto nla_put_failure;
6333 if (!wiphy && reg_last_request_cell_base() &&
6334 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6335 NL80211_USER_REG_HINT_CELL_BASE))
6336 goto nla_put_failure;
6339 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6340 goto nla_put_failure;
6342 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6343 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6344 goto nla_put_failure;
6346 genlmsg_end(msg, hdr);
6350 genlmsg_cancel(msg, hdr);
6354 static int nl80211_get_reg_dump(struct sk_buff *skb,
6355 struct netlink_callback *cb)
6357 const struct ieee80211_regdomain *regdom = NULL;
6358 struct cfg80211_registered_device *rdev;
6359 int err, reg_idx, start = cb->args[2];
6363 if (cfg80211_regdomain && start == 0) {
6364 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6366 rtnl_dereference(cfg80211_regdomain));
6371 /* the global regdom is idx 0 */
6373 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6374 regdom = get_wiphy_regdom(&rdev->wiphy);
6378 if (++reg_idx <= start)
6381 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6382 NLM_F_MULTI, &rdev->wiphy, regdom);
6389 cb->args[2] = reg_idx;
6396 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
6397 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6398 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6399 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6400 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6401 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6402 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6403 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6404 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6407 static int parse_reg_rule(struct nlattr *tb[],
6408 struct ieee80211_reg_rule *reg_rule)
6410 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
6411 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
6413 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6415 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6417 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6419 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6421 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6424 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6426 freq_range->start_freq_khz =
6427 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6428 freq_range->end_freq_khz =
6429 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6430 freq_range->max_bandwidth_khz =
6431 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6433 power_rule->max_eirp =
6434 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6436 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6437 power_rule->max_antenna_gain =
6438 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6440 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6441 reg_rule->dfs_cac_ms =
6442 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6447 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6449 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6450 struct nlattr *nl_reg_rule;
6452 int rem_reg_rules, r;
6453 u32 num_rules = 0, rule_idx = 0, size_of_regd;
6454 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
6455 struct ieee80211_regdomain *rd;
6457 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6460 if (!info->attrs[NL80211_ATTR_REG_RULES])
6463 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6465 if (info->attrs[NL80211_ATTR_DFS_REGION])
6466 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6468 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
6471 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
6475 if (!reg_is_valid_request(alpha2))
6478 size_of_regd = sizeof(struct ieee80211_regdomain) +
6479 num_rules * sizeof(struct ieee80211_reg_rule);
6481 rd = kzalloc(size_of_regd, GFP_KERNEL);
6485 rd->n_reg_rules = num_rules;
6486 rd->alpha2[0] = alpha2[0];
6487 rd->alpha2[1] = alpha2[1];
6490 * Disable DFS master mode if the DFS region was
6491 * not supported or known on this kernel.
6493 if (reg_supported_dfs_region(dfs_region))
6494 rd->dfs_region = dfs_region;
6496 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
6498 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
6499 nl_reg_rule, reg_rule_policy,
6503 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6509 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6515 /* set_regdom takes ownership of rd */
6516 return set_regdom(rd, REGD_SOURCE_CRDA);
6521 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
6523 static int validate_scan_freqs(struct nlattr *freqs)
6525 struct nlattr *attr1, *attr2;
6526 int n_channels = 0, tmp1, tmp2;
6528 nla_for_each_nested(attr1, freqs, tmp1)
6529 if (nla_len(attr1) != sizeof(u32))
6532 nla_for_each_nested(attr1, freqs, tmp1) {
6535 * Some hardware has a limited channel list for
6536 * scanning, and it is pretty much nonsensical
6537 * to scan for a channel twice, so disallow that
6538 * and don't require drivers to check that the
6539 * channel list they get isn't longer than what
6540 * they can scan, as long as they can scan all
6541 * the channels they registered at once.
6543 nla_for_each_nested(attr2, freqs, tmp2)
6544 if (attr1 != attr2 &&
6545 nla_get_u32(attr1) == nla_get_u32(attr2))
6552 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
6554 return b < NUM_NL80211_BANDS && wiphy->bands[b];
6557 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6558 struct cfg80211_bss_selection *bss_select)
6560 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6561 struct nlattr *nest;
6566 /* only process one nested attribute */
6567 nest = nla_data(nla);
6568 if (!nla_ok(nest, nla_len(nest)))
6571 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
6572 nl80211_bss_select_policy, NULL);
6576 /* only one attribute may be given */
6577 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6585 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6587 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6588 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6590 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6591 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6592 bss_select->param.band_pref =
6593 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6594 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6598 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6599 struct nl80211_bss_select_rssi_adjust *adj_param;
6601 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6602 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6603 bss_select->param.adjust.band = adj_param->band;
6604 bss_select->param.adjust.delta = adj_param->delta;
6605 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6609 /* user-space did not provide behaviour attribute */
6610 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6613 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6619 static int nl80211_parse_random_mac(struct nlattr **attrs,
6620 u8 *mac_addr, u8 *mac_addr_mask)
6624 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
6625 eth_zero_addr(mac_addr);
6626 eth_zero_addr(mac_addr_mask);
6628 mac_addr_mask[0] = 0x3;
6633 /* need both or none */
6634 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6637 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6638 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6640 /* don't allow or configure an mcast address */
6641 if (!is_multicast_ether_addr(mac_addr_mask) ||
6642 is_multicast_ether_addr(mac_addr))
6646 * allow users to pass a MAC address that has bits set outside
6647 * of the mask, but don't bother drivers with having to deal
6650 for (i = 0; i < ETH_ALEN; i++)
6651 mac_addr[i] &= mac_addr_mask[i];
6656 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
6658 ASSERT_WDEV_LOCK(wdev);
6660 if (!cfg80211_beaconing_iface_active(wdev))
6663 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
6666 return regulatory_pre_cac_allowed(wdev->wiphy);
6669 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6672 struct wireless_dev *wdev = info->user_ptr[1];
6673 struct cfg80211_scan_request *request;
6674 struct nlattr *attr;
6675 struct wiphy *wiphy;
6676 int err, tmp, n_ssids = 0, n_channels, i;
6679 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6682 wiphy = &rdev->wiphy;
6684 if (wdev->iftype == NL80211_IFTYPE_NAN)
6687 if (!rdev->ops->scan)
6690 if (rdev->scan_req || rdev->scan_msg) {
6695 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6696 n_channels = validate_scan_freqs(
6697 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
6703 n_channels = ieee80211_get_num_supported_channels(wiphy);
6706 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6707 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6710 if (n_ssids > wiphy->max_scan_ssids) {
6715 if (info->attrs[NL80211_ATTR_IE])
6716 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6720 if (ie_len > wiphy->max_scan_ie_len) {
6725 request = kzalloc(sizeof(*request)
6726 + sizeof(*request->ssids) * n_ssids
6727 + sizeof(*request->channels) * n_channels
6728 + ie_len, GFP_KERNEL);
6735 request->ssids = (void *)&request->channels[n_channels];
6736 request->n_ssids = n_ssids;
6739 request->ie = (void *)(request->ssids + n_ssids);
6741 request->ie = (void *)(request->channels + n_channels);
6745 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6746 /* user specified, bail out if channel not found */
6747 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
6748 struct ieee80211_channel *chan;
6750 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6757 /* ignore disabled channels */
6758 if (chan->flags & IEEE80211_CHAN_DISABLED)
6761 request->channels[i] = chan;
6765 enum nl80211_band band;
6768 for (band = 0; band < NUM_NL80211_BANDS; band++) {
6771 if (!wiphy->bands[band])
6773 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6774 struct ieee80211_channel *chan;
6776 chan = &wiphy->bands[band]->channels[j];
6778 if (chan->flags & IEEE80211_CHAN_DISABLED)
6781 request->channels[i] = chan;
6792 request->n_channels = i;
6795 if (!cfg80211_off_channel_oper_allowed(wdev)) {
6796 struct ieee80211_channel *chan;
6798 if (request->n_channels != 1) {
6804 chan = request->channels[0];
6805 if (chan->center_freq != wdev->chandef.chan->center_freq) {
6815 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
6816 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
6820 request->ssids[i].ssid_len = nla_len(attr);
6821 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
6826 if (info->attrs[NL80211_ATTR_IE]) {
6827 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6828 memcpy((void *)request->ie,
6829 nla_data(info->attrs[NL80211_ATTR_IE]),
6833 for (i = 0; i < NUM_NL80211_BANDS; i++)
6834 if (wiphy->bands[i])
6836 (1 << wiphy->bands[i]->n_bitrates) - 1;
6838 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6839 nla_for_each_nested(attr,
6840 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6842 enum nl80211_band band = nla_type(attr);
6844 if (band < 0 || band >= NUM_NL80211_BANDS) {
6849 if (!wiphy->bands[band])
6852 err = ieee80211_get_ratemask(wiphy->bands[band],
6855 &request->rates[band]);
6861 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6862 if (!wiphy_ext_feature_isset(wiphy,
6863 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6869 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6870 request->duration_mandatory =
6871 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6874 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
6875 request->flags = nla_get_u32(
6876 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
6877 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6878 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
6883 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6884 if (!(wiphy->features &
6885 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6890 if (wdev->current_bss) {
6895 err = nl80211_parse_random_mac(info->attrs,
6897 request->mac_addr_mask);
6904 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6906 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6907 * BSSID to scan for. This was problematic because that same attribute
6908 * was already used for another purpose (local random MAC address). The
6909 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6910 * compatibility with older userspace components, also use the
6911 * NL80211_ATTR_MAC value here if it can be determined to be used for
6912 * the specific BSSID use case instead of the random MAC address
6913 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6915 if (info->attrs[NL80211_ATTR_BSSID])
6916 memcpy(request->bssid,
6917 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6918 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6919 info->attrs[NL80211_ATTR_MAC])
6920 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6923 eth_broadcast_addr(request->bssid);
6925 request->wdev = wdev;
6926 request->wiphy = &rdev->wiphy;
6927 request->scan_start = jiffies;
6929 rdev->scan_req = request;
6930 err = rdev_scan(rdev, request);
6933 nl80211_send_scan_start(rdev, wdev);
6935 dev_hold(wdev->netdev);
6938 rdev->scan_req = NULL;
6946 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6949 struct wireless_dev *wdev = info->user_ptr[1];
6951 if (!rdev->ops->abort_scan)
6957 if (!rdev->scan_req)
6960 rdev_abort_scan(rdev, wdev);
6965 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6966 struct cfg80211_sched_scan_request *request,
6967 struct nlattr **attrs)
6969 int tmp, err, i = 0;
6970 struct nlattr *attr;
6972 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6976 * If scan plans are not specified,
6977 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
6978 * case one scan plan will be set with the specified scan
6979 * interval and infinite number of iterations.
6981 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6985 request->scan_plans[0].interval =
6986 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6987 if (!request->scan_plans[0].interval)
6990 if (request->scan_plans[0].interval >
6991 wiphy->max_sched_scan_plan_interval)
6992 request->scan_plans[0].interval =
6993 wiphy->max_sched_scan_plan_interval;
6998 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6999 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7001 if (WARN_ON(i >= n_plans))
7004 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
7005 attr, nl80211_plan_policy, NULL);
7009 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
7012 request->scan_plans[i].interval =
7013 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
7014 if (!request->scan_plans[i].interval ||
7015 request->scan_plans[i].interval >
7016 wiphy->max_sched_scan_plan_interval)
7019 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
7020 request->scan_plans[i].iterations =
7021 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
7022 if (!request->scan_plans[i].iterations ||
7023 (request->scan_plans[i].iterations >
7024 wiphy->max_sched_scan_plan_iterations))
7026 } else if (i < n_plans - 1) {
7028 * All scan plans but the last one must specify
7029 * a finite number of iterations
7038 * The last scan plan must not specify the number of
7039 * iterations, it is supposed to run infinitely
7041 if (request->scan_plans[n_plans - 1].iterations)
7047 static struct cfg80211_sched_scan_request *
7048 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
7049 struct nlattr **attrs, int max_match_sets)
7051 struct cfg80211_sched_scan_request *request;
7052 struct nlattr *attr;
7053 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
7054 enum nl80211_band band;
7056 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
7057 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
7059 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
7060 return ERR_PTR(-EINVAL);
7062 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7063 n_channels = validate_scan_freqs(
7064 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
7066 return ERR_PTR(-EINVAL);
7068 n_channels = ieee80211_get_num_supported_channels(wiphy);
7071 if (attrs[NL80211_ATTR_SCAN_SSIDS])
7072 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
7076 if (n_ssids > wiphy->max_sched_scan_ssids)
7077 return ERR_PTR(-EINVAL);
7080 * First, count the number of 'real' matchsets. Due to an issue with
7081 * the old implementation, matchsets containing only the RSSI attribute
7082 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7083 * RSSI for all matchsets, rather than their own matchset for reporting
7084 * all APs with a strong RSSI. This is needed to be compatible with
7085 * older userspace that treated a matchset with only the RSSI as the
7086 * global RSSI for all other matchsets - if there are other matchsets.
7088 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
7089 nla_for_each_nested(attr,
7090 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
7092 struct nlattr *rssi;
7094 err = nla_parse_nested(tb,
7095 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7096 attr, nl80211_match_policy,
7099 return ERR_PTR(err);
7101 /* SSID and BSSID are mutually exclusive */
7102 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
7103 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
7104 return ERR_PTR(-EINVAL);
7106 /* add other standalone attributes here */
7107 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
7108 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
7112 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7114 default_match_rssi = nla_get_s32(rssi);
7118 /* However, if there's no other matchset, add the RSSI one */
7119 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
7122 if (n_match_sets > max_match_sets)
7123 return ERR_PTR(-EINVAL);
7125 if (attrs[NL80211_ATTR_IE])
7126 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
7130 if (ie_len > wiphy->max_sched_scan_ie_len)
7131 return ERR_PTR(-EINVAL);
7133 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7135 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7136 * each scan plan already specifies its own interval
7138 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7139 return ERR_PTR(-EINVAL);
7141 nla_for_each_nested(attr,
7142 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
7146 * The scan interval attribute is kept for backward
7147 * compatibility. If no scan plans are specified and sched scan
7148 * interval is specified, one scan plan will be set with this
7149 * scan interval and infinite number of iterations.
7151 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
7152 return ERR_PTR(-EINVAL);
7157 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
7158 return ERR_PTR(-EINVAL);
7160 if (!wiphy_ext_feature_isset(
7161 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
7162 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7163 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7164 return ERR_PTR(-EINVAL);
7166 request = kzalloc(sizeof(*request)
7167 + sizeof(*request->ssids) * n_ssids
7168 + sizeof(*request->match_sets) * n_match_sets
7169 + sizeof(*request->scan_plans) * n_plans
7170 + sizeof(*request->channels) * n_channels
7171 + ie_len, GFP_KERNEL);
7173 return ERR_PTR(-ENOMEM);
7176 request->ssids = (void *)&request->channels[n_channels];
7177 request->n_ssids = n_ssids;
7180 request->ie = (void *)(request->ssids + n_ssids);
7182 request->ie = (void *)(request->channels + n_channels);
7187 request->match_sets = (void *)(request->ie + ie_len);
7189 request->match_sets =
7190 (void *)(request->ssids + n_ssids);
7192 request->match_sets =
7193 (void *)(request->channels + n_channels);
7195 request->n_match_sets = n_match_sets;
7198 request->scan_plans = (void *)(request->match_sets +
7200 else if (request->ie)
7201 request->scan_plans = (void *)(request->ie + ie_len);
7203 request->scan_plans = (void *)(request->ssids + n_ssids);
7205 request->scan_plans = (void *)(request->channels + n_channels);
7207 request->n_scan_plans = n_plans;
7210 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7211 /* user specified, bail out if channel not found */
7212 nla_for_each_nested(attr,
7213 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
7215 struct ieee80211_channel *chan;
7217 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7224 /* ignore disabled channels */
7225 if (chan->flags & IEEE80211_CHAN_DISABLED)
7228 request->channels[i] = chan;
7233 for (band = 0; band < NUM_NL80211_BANDS; band++) {
7236 if (!wiphy->bands[band])
7238 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7239 struct ieee80211_channel *chan;
7241 chan = &wiphy->bands[band]->channels[j];
7243 if (chan->flags & IEEE80211_CHAN_DISABLED)
7246 request->channels[i] = chan;
7257 request->n_channels = i;
7261 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
7263 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
7267 request->ssids[i].ssid_len = nla_len(attr);
7268 memcpy(request->ssids[i].ssid, nla_data(attr),
7275 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
7276 nla_for_each_nested(attr,
7277 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
7279 struct nlattr *ssid, *bssid, *rssi;
7281 err = nla_parse_nested(tb,
7282 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7283 attr, nl80211_match_policy,
7287 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
7288 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7289 if (ssid || bssid) {
7290 if (WARN_ON(i >= n_match_sets)) {
7291 /* this indicates a programming error,
7292 * the loop above should have verified
7300 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7304 memcpy(request->match_sets[i].ssid.ssid,
7305 nla_data(ssid), nla_len(ssid));
7306 request->match_sets[i].ssid.ssid_len =
7310 if (nla_len(bssid) != ETH_ALEN) {
7314 memcpy(request->match_sets[i].bssid,
7315 nla_data(bssid), ETH_ALEN);
7318 /* special attribute - old implementation w/a */
7319 request->match_sets[i].rssi_thold =
7321 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7323 request->match_sets[i].rssi_thold =
7329 /* there was no other matchset, so the RSSI one is alone */
7330 if (i == 0 && n_match_sets)
7331 request->match_sets[0].rssi_thold = default_match_rssi;
7333 request->min_rssi_thold = INT_MAX;
7334 for (i = 0; i < n_match_sets; i++)
7335 request->min_rssi_thold =
7336 min(request->match_sets[i].rssi_thold,
7337 request->min_rssi_thold);
7339 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
7343 request->ie_len = ie_len;
7344 memcpy((void *)request->ie,
7345 nla_data(attrs[NL80211_ATTR_IE]),
7349 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
7350 request->flags = nla_get_u32(
7351 attrs[NL80211_ATTR_SCAN_FLAGS]);
7352 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7353 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
7358 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7359 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7361 if (!wdev) /* must be net-detect */
7362 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7364 if (!(wiphy->features & flg)) {
7369 if (wdev && wdev->current_bss) {
7374 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7375 request->mac_addr_mask);
7381 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7383 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7385 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7386 request->relative_rssi = nla_get_s8(
7387 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7388 request->relative_rssi_set = true;
7391 if (request->relative_rssi_set &&
7392 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7393 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7395 rssi_adjust = nla_data(
7396 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7397 request->rssi_adjust.band = rssi_adjust->band;
7398 request->rssi_adjust.delta = rssi_adjust->delta;
7399 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7405 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7409 request->scan_start = jiffies;
7415 return ERR_PTR(err);
7418 static int nl80211_start_sched_scan(struct sk_buff *skb,
7419 struct genl_info *info)
7421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7422 struct net_device *dev = info->user_ptr[1];
7423 struct wireless_dev *wdev = dev->ieee80211_ptr;
7424 struct cfg80211_sched_scan_request *sched_scan_req;
7428 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
7431 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
7432 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
7436 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
7438 rdev->wiphy.max_match_sets);
7440 err = PTR_ERR_OR_ZERO(sched_scan_req);
7444 /* leave request id zero for legacy request
7445 * or if driver does not support multi-scheduled scan
7447 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
7448 while (!sched_scan_req->reqid)
7449 sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
7452 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
7456 sched_scan_req->dev = dev;
7457 sched_scan_req->wiphy = &rdev->wiphy;
7459 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7460 sched_scan_req->owner_nlportid = info->snd_portid;
7462 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
7464 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
7468 kfree(sched_scan_req);
7473 static int nl80211_stop_sched_scan(struct sk_buff *skb,
7474 struct genl_info *info)
7476 struct cfg80211_sched_scan_request *req;
7477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7480 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
7483 if (info->attrs[NL80211_ATTR_COOKIE]) {
7484 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7485 return __cfg80211_stop_sched_scan(rdev, cookie, false);
7488 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
7489 struct cfg80211_sched_scan_request,
7491 if (!req || req->reqid ||
7492 (req->owner_nlportid &&
7493 req->owner_nlportid != info->snd_portid))
7496 return cfg80211_stop_sched_scan_req(rdev, req, false);
7499 static int nl80211_start_radar_detection(struct sk_buff *skb,
7500 struct genl_info *info)
7502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7503 struct net_device *dev = info->user_ptr[1];
7504 struct wireless_dev *wdev = dev->ieee80211_ptr;
7505 struct cfg80211_chan_def chandef;
7506 enum nl80211_dfs_regions dfs_region;
7507 unsigned int cac_time_ms;
7510 dfs_region = reg_get_dfs_region(wdev->wiphy);
7511 if (dfs_region == NL80211_DFS_UNSET)
7514 err = nl80211_parse_chandef(rdev, info, &chandef);
7518 if (netif_carrier_ok(dev))
7521 if (wdev->cac_started)
7524 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
7532 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
7535 if (!rdev->ops->start_radar_detection)
7538 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7539 if (WARN_ON(!cac_time_ms))
7540 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7542 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
7544 wdev->chandef = chandef;
7545 wdev->cac_started = true;
7546 wdev->cac_start_time = jiffies;
7547 wdev->cac_time_ms = cac_time_ms;
7552 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7555 struct net_device *dev = info->user_ptr[1];
7556 struct wireless_dev *wdev = dev->ieee80211_ptr;
7557 struct cfg80211_csa_settings params;
7558 /* csa_attrs is defined static to avoid waste of stack size - this
7559 * function is called under RTNL lock, so this should not be a problem.
7561 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
7563 bool need_new_beacon = false;
7564 bool need_handle_dfs_flag = true;
7568 if (!rdev->ops->channel_switch ||
7569 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7572 switch (dev->ieee80211_ptr->iftype) {
7573 case NL80211_IFTYPE_AP:
7574 case NL80211_IFTYPE_P2P_GO:
7575 need_new_beacon = true;
7576 /* For all modes except AP the handle_dfs flag needs to be
7577 * supplied to tell the kernel that userspace will handle radar
7578 * events when they happen. Otherwise a switch to a channel
7579 * requiring DFS will be rejected.
7581 need_handle_dfs_flag = false;
7583 /* useless if AP is not running */
7584 if (!wdev->beacon_interval)
7587 case NL80211_IFTYPE_ADHOC:
7588 if (!wdev->ssid_len)
7591 case NL80211_IFTYPE_MESH_POINT:
7592 if (!wdev->mesh_id_len)
7599 memset(¶ms, 0, sizeof(params));
7601 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7602 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7605 /* only important for AP, IBSS and mesh create IEs internally */
7606 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
7609 /* Even though the attribute is u32, the specification says
7610 * u8, so let's make sure we don't overflow.
7612 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7616 params.count = cs_count;
7618 if (!need_new_beacon)
7621 err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after);
7625 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7626 info->attrs[NL80211_ATTR_CSA_IES],
7627 nl80211_policy, info->extack);
7631 err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa);
7635 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7638 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7639 if (!len || (len % sizeof(u16)))
7642 params.n_counter_offsets_beacon = len / sizeof(u16);
7643 if (rdev->wiphy.max_num_csa_counters &&
7644 (params.n_counter_offsets_beacon >
7645 rdev->wiphy.max_num_csa_counters))
7648 params.counter_offsets_beacon =
7649 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7651 /* sanity checks - counters should fit and be the same */
7652 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7653 u16 offset = params.counter_offsets_beacon[i];
7655 if (offset >= params.beacon_csa.tail_len)
7658 if (params.beacon_csa.tail[offset] != params.count)
7662 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
7663 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7664 if (!len || (len % sizeof(u16)))
7667 params.n_counter_offsets_presp = len / sizeof(u16);
7668 if (rdev->wiphy.max_num_csa_counters &&
7669 (params.n_counter_offsets_presp >
7670 rdev->wiphy.max_num_csa_counters))
7673 params.counter_offsets_presp =
7674 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7676 /* sanity checks - counters should fit and be the same */
7677 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7678 u16 offset = params.counter_offsets_presp[i];
7680 if (offset >= params.beacon_csa.probe_resp_len)
7683 if (params.beacon_csa.probe_resp[offset] !=
7690 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
7694 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef,
7698 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7705 params.radar_required = true;
7706 if (need_handle_dfs_flag &&
7707 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
7712 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7713 params.block_tx = true;
7716 err = rdev_channel_switch(rdev, dev, ¶ms);
7722 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7724 struct cfg80211_registered_device *rdev,
7725 struct wireless_dev *wdev,
7726 struct cfg80211_internal_bss *intbss)
7728 struct cfg80211_bss *res = &intbss->pub;
7729 const struct cfg80211_bss_ies *ies;
7733 ASSERT_WDEV_LOCK(wdev);
7735 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
7736 NL80211_CMD_NEW_SCAN_RESULTS);
7740 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7742 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7743 goto nla_put_failure;
7745 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7746 goto nla_put_failure;
7747 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7749 goto nla_put_failure;
7751 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7753 goto nla_put_failure;
7754 if ((!is_zero_ether_addr(res->bssid) &&
7755 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
7756 goto nla_put_failure;
7759 /* indicate whether we have probe response data or not */
7760 if (rcu_access_pointer(res->proberesp_ies) &&
7761 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7762 goto fail_unlock_rcu;
7764 /* this pointer prefers to be pointed to probe response data
7765 * but is always valid
7767 ies = rcu_dereference(res->ies);
7769 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7771 goto fail_unlock_rcu;
7772 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7773 ies->len, ies->data))
7774 goto fail_unlock_rcu;
7777 /* and this pointer is always (unless driver didn't know) beacon data */
7778 ies = rcu_dereference(res->beacon_ies);
7779 if (ies && ies->from_beacon) {
7780 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7782 goto fail_unlock_rcu;
7783 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7784 ies->len, ies->data))
7785 goto fail_unlock_rcu;
7789 if (res->beacon_interval &&
7790 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7791 goto nla_put_failure;
7792 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7793 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
7794 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
7795 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7796 jiffies_to_msecs(jiffies - intbss->ts)))
7797 goto nla_put_failure;
7799 if (intbss->parent_tsf &&
7800 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7801 intbss->parent_tsf, NL80211_BSS_PAD) ||
7802 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7803 intbss->parent_bssid)))
7804 goto nla_put_failure;
7806 if (intbss->ts_boottime &&
7807 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7808 intbss->ts_boottime, NL80211_BSS_PAD))
7809 goto nla_put_failure;
7811 switch (rdev->wiphy.signal_type) {
7812 case CFG80211_SIGNAL_TYPE_MBM:
7813 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7814 goto nla_put_failure;
7816 case CFG80211_SIGNAL_TYPE_UNSPEC:
7817 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7818 goto nla_put_failure;
7824 switch (wdev->iftype) {
7825 case NL80211_IFTYPE_P2P_CLIENT:
7826 case NL80211_IFTYPE_STATION:
7827 if (intbss == wdev->current_bss &&
7828 nla_put_u32(msg, NL80211_BSS_STATUS,
7829 NL80211_BSS_STATUS_ASSOCIATED))
7830 goto nla_put_failure;
7832 case NL80211_IFTYPE_ADHOC:
7833 if (intbss == wdev->current_bss &&
7834 nla_put_u32(msg, NL80211_BSS_STATUS,
7835 NL80211_BSS_STATUS_IBSS_JOINED))
7836 goto nla_put_failure;
7842 nla_nest_end(msg, bss);
7844 genlmsg_end(msg, hdr);
7850 genlmsg_cancel(msg, hdr);
7854 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
7856 struct cfg80211_registered_device *rdev;
7857 struct cfg80211_internal_bss *scan;
7858 struct wireless_dev *wdev;
7859 int start = cb->args[2], idx = 0;
7863 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
7870 spin_lock_bh(&rdev->bss_lock);
7871 cfg80211_bss_expire(rdev);
7873 cb->seq = rdev->bss_generation;
7875 list_for_each_entry(scan, &rdev->bss_list, list) {
7878 if (nl80211_send_bss(skb, cb,
7879 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7880 rdev, wdev, scan) < 0) {
7886 spin_unlock_bh(&rdev->bss_lock);
7895 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
7896 int flags, struct net_device *dev,
7897 bool allow_radio_stats,
7898 struct survey_info *survey)
7901 struct nlattr *infoattr;
7903 /* skip radio stats if userspace didn't request them */
7904 if (!survey->channel && !allow_radio_stats)
7907 hdr = nl80211hdr_put(msg, portid, seq, flags,
7908 NL80211_CMD_NEW_SURVEY_RESULTS);
7912 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7913 goto nla_put_failure;
7915 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7917 goto nla_put_failure;
7919 if (survey->channel &&
7920 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
7921 survey->channel->center_freq))
7922 goto nla_put_failure;
7924 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7925 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7926 goto nla_put_failure;
7927 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7928 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7929 goto nla_put_failure;
7930 if ((survey->filled & SURVEY_INFO_TIME) &&
7931 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7932 survey->time, NL80211_SURVEY_INFO_PAD))
7933 goto nla_put_failure;
7934 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
7935 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7936 survey->time_busy, NL80211_SURVEY_INFO_PAD))
7937 goto nla_put_failure;
7938 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
7939 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7940 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
7941 goto nla_put_failure;
7942 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
7943 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7944 survey->time_rx, NL80211_SURVEY_INFO_PAD))
7945 goto nla_put_failure;
7946 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
7947 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7948 survey->time_tx, NL80211_SURVEY_INFO_PAD))
7949 goto nla_put_failure;
7950 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
7951 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7952 survey->time_scan, NL80211_SURVEY_INFO_PAD))
7953 goto nla_put_failure;
7955 nla_nest_end(msg, infoattr);
7957 genlmsg_end(msg, hdr);
7961 genlmsg_cancel(msg, hdr);
7965 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
7967 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
7968 struct survey_info survey;
7969 struct cfg80211_registered_device *rdev;
7970 struct wireless_dev *wdev;
7971 int survey_idx = cb->args[2];
7976 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
7980 /* prepare_wdev_dump parsed the attributes */
7981 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7983 if (!wdev->netdev) {
7988 if (!rdev->ops->dump_survey) {
7994 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
8000 /* don't send disabled channels, but do send non-channel data */
8001 if (survey.channel &&
8002 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
8007 if (nl80211_send_survey(skb,
8008 NETLINK_CB(cb->skb).portid,
8009 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8010 wdev->netdev, radio_stats, &survey) < 0)
8016 cb->args[2] = survey_idx;
8023 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
8025 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
8026 NL80211_WPA_VERSION_2));
8029 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
8031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8032 struct net_device *dev = info->user_ptr[1];
8033 struct ieee80211_channel *chan;
8034 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
8035 int err, ssid_len, ie_len = 0, auth_data_len = 0;
8036 enum nl80211_auth_type auth_type;
8037 struct key_parse key;
8038 bool local_state_change;
8040 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8043 if (!info->attrs[NL80211_ATTR_MAC])
8046 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
8049 if (!info->attrs[NL80211_ATTR_SSID])
8052 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8055 err = nl80211_parse_key(info, &key);
8060 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
8062 if (!key.p.key || !key.p.key_len)
8064 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
8065 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
8066 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
8067 key.p.key_len != WLAN_KEY_LEN_WEP104))
8080 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
8081 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
8090 if (!rdev->ops->auth)
8093 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
8094 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8097 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8098 chan = nl80211_get_valid_chan(&rdev->wiphy,
8099 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8103 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8104 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8106 if (info->attrs[NL80211_ATTR_IE]) {
8107 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8108 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8111 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
8112 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
8115 if ((auth_type == NL80211_AUTHTYPE_SAE ||
8116 auth_type == NL80211_AUTHTYPE_FILS_SK ||
8117 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
8118 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
8119 !info->attrs[NL80211_ATTR_AUTH_DATA])
8122 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
8123 if (auth_type != NL80211_AUTHTYPE_SAE &&
8124 auth_type != NL80211_AUTHTYPE_FILS_SK &&
8125 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
8126 auth_type != NL80211_AUTHTYPE_FILS_PK)
8128 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
8129 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
8130 /* need to include at least Auth Transaction and Status Code */
8131 if (auth_data_len < 4)
8135 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8138 * Since we no longer track auth state, ignore
8139 * requests to only change local state.
8141 if (local_state_change)
8144 wdev_lock(dev->ieee80211_ptr);
8145 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
8146 ssid, ssid_len, ie, ie_len,
8147 key.p.key, key.p.key_len, key.idx,
8148 auth_data, auth_data_len);
8149 wdev_unlock(dev->ieee80211_ptr);
8153 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
8154 struct genl_info *info,
8155 struct cfg80211_crypto_settings *settings,
8158 memset(settings, 0, sizeof(*settings));
8160 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
8162 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
8165 proto = nla_get_u16(
8166 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
8167 settings->control_port_ethertype = cpu_to_be16(proto);
8168 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
8171 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
8172 settings->control_port_no_encrypt = true;
8174 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
8176 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
8180 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8181 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
8182 settings->n_ciphers_pairwise = len / sizeof(u32);
8184 if (len % sizeof(u32))
8187 if (settings->n_ciphers_pairwise > cipher_limit)
8190 memcpy(settings->ciphers_pairwise, data, len);
8192 for (i = 0; i < settings->n_ciphers_pairwise; i++)
8193 if (!cfg80211_supported_cipher_suite(
8195 settings->ciphers_pairwise[i]))
8199 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
8200 settings->cipher_group =
8201 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
8202 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
8203 settings->cipher_group))
8207 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8208 settings->wpa_versions =
8209 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8210 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8214 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8218 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8219 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8220 settings->n_akm_suites = len / sizeof(u32);
8222 if (len % sizeof(u32))
8225 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8228 memcpy(settings->akm_suites, data, len);
8231 if (info->attrs[NL80211_ATTR_PMK]) {
8232 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
8234 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8235 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
8237 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
8243 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8246 struct net_device *dev = info->user_ptr[1];
8247 struct ieee80211_channel *chan;
8248 struct cfg80211_assoc_request req = {};
8249 const u8 *bssid, *ssid;
8250 int err, ssid_len = 0;
8252 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8255 if (!info->attrs[NL80211_ATTR_MAC] ||
8256 !info->attrs[NL80211_ATTR_SSID] ||
8257 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
8260 if (!rdev->ops->assoc)
8263 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
8264 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8267 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8269 chan = nl80211_get_valid_chan(&rdev->wiphy,
8270 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8274 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8275 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8277 if (info->attrs[NL80211_ATTR_IE]) {
8278 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8279 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8282 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8283 enum nl80211_mfp mfp =
8284 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8285 if (mfp == NL80211_MFP_REQUIRED)
8287 else if (mfp != NL80211_MFP_NO)
8291 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8292 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8294 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8295 req.flags |= ASSOC_REQ_DISABLE_HT;
8297 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8298 memcpy(&req.ht_capa_mask,
8299 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8300 sizeof(req.ht_capa_mask));
8302 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8303 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8305 memcpy(&req.ht_capa,
8306 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8307 sizeof(req.ht_capa));
8310 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8311 req.flags |= ASSOC_REQ_DISABLE_VHT;
8313 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8314 memcpy(&req.vht_capa_mask,
8315 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8316 sizeof(req.vht_capa_mask));
8318 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8319 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8321 memcpy(&req.vht_capa,
8322 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8323 sizeof(req.vht_capa));
8326 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
8327 if (!((rdev->wiphy.features &
8328 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8329 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8330 !wiphy_ext_feature_isset(&rdev->wiphy,
8331 NL80211_EXT_FEATURE_RRM))
8333 req.flags |= ASSOC_REQ_USE_RRM;
8336 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8337 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8338 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8339 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8342 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8345 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
8347 wdev_lock(dev->ieee80211_ptr);
8349 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8350 ssid, ssid_len, &req);
8352 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8353 dev->ieee80211_ptr->conn_owner_nlportid =
8355 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8359 wdev_unlock(dev->ieee80211_ptr);
8365 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8368 struct net_device *dev = info->user_ptr[1];
8369 const u8 *ie = NULL, *bssid;
8370 int ie_len = 0, err;
8372 bool local_state_change;
8374 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8377 if (!info->attrs[NL80211_ATTR_MAC])
8380 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8383 if (!rdev->ops->deauth)
8386 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
8387 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8390 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8392 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8393 if (reason_code == 0) {
8394 /* Reason Code 0 is reserved */
8398 if (info->attrs[NL80211_ATTR_IE]) {
8399 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8400 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8403 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8405 wdev_lock(dev->ieee80211_ptr);
8406 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8407 local_state_change);
8408 wdev_unlock(dev->ieee80211_ptr);
8412 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8415 struct net_device *dev = info->user_ptr[1];
8416 const u8 *ie = NULL, *bssid;
8417 int ie_len = 0, err;
8419 bool local_state_change;
8421 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8424 if (!info->attrs[NL80211_ATTR_MAC])
8427 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8430 if (!rdev->ops->disassoc)
8433 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
8434 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8437 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8439 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8440 if (reason_code == 0) {
8441 /* Reason Code 0 is reserved */
8445 if (info->attrs[NL80211_ATTR_IE]) {
8446 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8447 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8450 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8452 wdev_lock(dev->ieee80211_ptr);
8453 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8454 local_state_change);
8455 wdev_unlock(dev->ieee80211_ptr);
8460 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
8461 int mcast_rate[NUM_NL80211_BANDS],
8464 struct wiphy *wiphy = &rdev->wiphy;
8468 for (band = 0; band < NUM_NL80211_BANDS; band++) {
8469 struct ieee80211_supported_band *sband;
8471 sband = wiphy->bands[band];
8475 for (i = 0; i < sband->n_bitrates; i++) {
8476 if (sband->bitrates[i].bitrate == rateval) {
8477 mcast_rate[band] = i + 1;
8487 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8490 struct net_device *dev = info->user_ptr[1];
8491 struct cfg80211_ibss_params ibss;
8492 struct wiphy *wiphy;
8493 struct cfg80211_cached_keys *connkeys = NULL;
8496 memset(&ibss, 0, sizeof(ibss));
8498 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8501 if (!info->attrs[NL80211_ATTR_SSID] ||
8502 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8505 ibss.beacon_interval = 100;
8507 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
8508 ibss.beacon_interval =
8509 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8511 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8512 ibss.beacon_interval);
8516 if (!rdev->ops->join_ibss)
8519 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8522 wiphy = &rdev->wiphy;
8524 if (info->attrs[NL80211_ATTR_MAC]) {
8525 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8527 if (!is_valid_ether_addr(ibss.bssid))
8530 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8531 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8533 if (info->attrs[NL80211_ATTR_IE]) {
8534 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8535 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8538 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8542 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8543 NL80211_IFTYPE_ADHOC))
8546 switch (ibss.chandef.width) {
8547 case NL80211_CHAN_WIDTH_5:
8548 case NL80211_CHAN_WIDTH_10:
8549 case NL80211_CHAN_WIDTH_20_NOHT:
8551 case NL80211_CHAN_WIDTH_20:
8552 case NL80211_CHAN_WIDTH_40:
8553 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8556 case NL80211_CHAN_WIDTH_80:
8557 case NL80211_CHAN_WIDTH_80P80:
8558 case NL80211_CHAN_WIDTH_160:
8559 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8561 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8562 NL80211_EXT_FEATURE_VHT_IBSS))
8569 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
8570 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
8572 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8574 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8576 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8577 struct ieee80211_supported_band *sband =
8578 wiphy->bands[ibss.chandef.chan->band];
8580 err = ieee80211_get_ratemask(sband, rates, n_rates,
8586 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8587 memcpy(&ibss.ht_capa_mask,
8588 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8589 sizeof(ibss.ht_capa_mask));
8591 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8592 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8594 memcpy(&ibss.ht_capa,
8595 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8596 sizeof(ibss.ht_capa));
8599 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8600 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8601 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8604 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8607 connkeys = nl80211_parse_connkeys(rdev,
8608 info->attrs[NL80211_ATTR_KEYS],
8610 if (IS_ERR(connkeys))
8611 return PTR_ERR(connkeys);
8613 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8621 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8623 ibss.userspace_handles_dfs =
8624 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8626 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
8632 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8634 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8635 struct net_device *dev = info->user_ptr[1];
8637 if (!rdev->ops->leave_ibss)
8640 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8643 return cfg80211_leave_ibss(rdev, dev, false);
8646 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8649 struct net_device *dev = info->user_ptr[1];
8650 int mcast_rate[NUM_NL80211_BANDS];
8654 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
8655 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8656 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
8659 if (!rdev->ops->set_mcast_rate)
8662 memset(mcast_rate, 0, sizeof(mcast_rate));
8664 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8667 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8668 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8671 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
8676 static struct sk_buff *
8677 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
8678 struct wireless_dev *wdev, int approxlen,
8679 u32 portid, u32 seq, enum nl80211_commands cmd,
8680 enum nl80211_attrs attr,
8681 const struct nl80211_vendor_cmd_info *info,
8684 struct sk_buff *skb;
8686 struct nlattr *data;
8688 skb = nlmsg_new(approxlen + 100, gfp);
8692 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8698 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8699 goto nla_put_failure;
8702 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8704 goto nla_put_failure;
8705 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8707 goto nla_put_failure;
8711 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8712 wdev_id(wdev), NL80211_ATTR_PAD))
8713 goto nla_put_failure;
8715 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8716 wdev->netdev->ifindex))
8717 goto nla_put_failure;
8720 data = nla_nest_start(skb, attr);
8722 goto nla_put_failure;
8724 ((void **)skb->cb)[0] = rdev;
8725 ((void **)skb->cb)[1] = hdr;
8726 ((void **)skb->cb)[2] = data;
8735 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
8736 struct wireless_dev *wdev,
8737 enum nl80211_commands cmd,
8738 enum nl80211_attrs attr,
8739 int vendor_event_idx,
8740 int approxlen, gfp_t gfp)
8742 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
8743 const struct nl80211_vendor_cmd_info *info;
8746 case NL80211_CMD_TESTMODE:
8747 if (WARN_ON(vendor_event_idx != -1))
8751 case NL80211_CMD_VENDOR:
8752 if (WARN_ON(vendor_event_idx < 0 ||
8753 vendor_event_idx >= wiphy->n_vendor_events))
8755 info = &wiphy->vendor_events[vendor_event_idx];
8762 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
8763 cmd, attr, info, gfp);
8765 EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8767 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8769 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8770 void *hdr = ((void **)skb->cb)[1];
8771 struct nlattr *data = ((void **)skb->cb)[2];
8772 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8774 /* clear CB data for netlink core to own from now on */
8775 memset(skb->cb, 0, sizeof(skb->cb));
8777 nla_nest_end(skb, data);
8778 genlmsg_end(skb, hdr);
8780 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8781 mcgrp = NL80211_MCGRP_VENDOR;
8783 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8786 EXPORT_SYMBOL(__cfg80211_send_event_skb);
8788 #ifdef CONFIG_NL80211_TESTMODE
8789 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8791 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8792 struct wireless_dev *wdev =
8793 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
8796 if (!rdev->ops->testmode_cmd)
8800 err = PTR_ERR(wdev);
8804 } else if (wdev->wiphy != &rdev->wiphy) {
8808 if (!info->attrs[NL80211_ATTR_TESTDATA])
8811 rdev->cur_cmd_info = info;
8812 err = rdev_testmode_cmd(rdev, wdev,
8813 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8814 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
8815 rdev->cur_cmd_info = NULL;
8820 static int nl80211_testmode_dump(struct sk_buff *skb,
8821 struct netlink_callback *cb)
8823 struct cfg80211_registered_device *rdev;
8833 * 0 is a valid index, but not valid for args[0],
8834 * so we need to offset by 1.
8836 phy_idx = cb->args[0] - 1;
8838 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8844 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8846 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8847 attrbuf, nl80211_fam.maxattr,
8848 nl80211_policy, NULL);
8852 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
8854 err = PTR_ERR(rdev);
8857 phy_idx = rdev->wiphy_idx;
8859 if (attrbuf[NL80211_ATTR_TESTDATA])
8860 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
8864 data = nla_data((void *)cb->args[1]);
8865 data_len = nla_len((void *)cb->args[1]);
8868 if (!rdev->ops->testmode_dump) {
8874 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
8875 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8876 NL80211_CMD_TESTMODE);
8877 struct nlattr *tmdata;
8882 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
8883 genlmsg_cancel(skb, hdr);
8887 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8889 genlmsg_cancel(skb, hdr);
8892 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
8893 nla_nest_end(skb, tmdata);
8895 if (err == -ENOBUFS || err == -ENOENT) {
8896 genlmsg_cancel(skb, hdr);
8899 genlmsg_cancel(skb, hdr);
8903 genlmsg_end(skb, hdr);
8908 cb->args[0] = phy_idx + 1;
8915 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8918 struct net_device *dev = info->user_ptr[1];
8919 struct cfg80211_connect_params connect;
8920 struct wiphy *wiphy;
8921 struct cfg80211_cached_keys *connkeys = NULL;
8924 memset(&connect, 0, sizeof(connect));
8926 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8929 if (!info->attrs[NL80211_ATTR_SSID] ||
8930 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8933 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8935 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
8936 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8937 NL80211_CMD_CONNECT))
8940 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8942 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8944 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
8945 !wiphy_ext_feature_isset(&rdev->wiphy,
8946 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
8948 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
8950 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
8951 NL80211_MAX_NR_CIPHER_SUITES);
8955 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
8956 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8959 wiphy = &rdev->wiphy;
8961 connect.bg_scan_period = -1;
8962 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8963 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8964 connect.bg_scan_period =
8965 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8968 if (info->attrs[NL80211_ATTR_MAC])
8969 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8970 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8971 connect.bssid_hint =
8972 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
8973 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8974 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8976 if (info->attrs[NL80211_ATTR_IE]) {
8977 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8978 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8981 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8982 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8983 if (connect.mfp != NL80211_MFP_REQUIRED &&
8984 connect.mfp != NL80211_MFP_NO)
8987 connect.mfp = NL80211_MFP_NO;
8990 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8991 connect.prev_bssid =
8992 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8994 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8995 connect.channel = nl80211_get_valid_chan(
8996 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8997 if (!connect.channel)
8999 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
9000 connect.channel_hint = nl80211_get_valid_chan(
9001 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
9002 if (!connect.channel_hint)
9006 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
9007 connkeys = nl80211_parse_connkeys(rdev,
9008 info->attrs[NL80211_ATTR_KEYS], NULL);
9009 if (IS_ERR(connkeys))
9010 return PTR_ERR(connkeys);
9013 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
9014 connect.flags |= ASSOC_REQ_DISABLE_HT;
9016 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9017 memcpy(&connect.ht_capa_mask,
9018 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9019 sizeof(connect.ht_capa_mask));
9021 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9022 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
9026 memcpy(&connect.ht_capa,
9027 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9028 sizeof(connect.ht_capa));
9031 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
9032 connect.flags |= ASSOC_REQ_DISABLE_VHT;
9034 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
9035 memcpy(&connect.vht_capa_mask,
9036 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9037 sizeof(connect.vht_capa_mask));
9039 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
9040 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
9044 memcpy(&connect.vht_capa,
9045 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9046 sizeof(connect.vht_capa));
9049 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
9050 if (!((rdev->wiphy.features &
9051 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9052 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9053 !wiphy_ext_feature_isset(&rdev->wiphy,
9054 NL80211_EXT_FEATURE_RRM)) {
9058 connect.flags |= ASSOC_REQ_USE_RRM;
9061 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
9062 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
9067 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
9068 /* bss selection makes no sense if bssid is set */
9069 if (connect.bssid) {
9074 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
9075 wiphy, &connect.bss_select);
9082 if (wiphy_ext_feature_isset(&rdev->wiphy,
9083 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
9084 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
9085 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
9086 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
9087 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9088 connect.fils_erp_username =
9089 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9090 connect.fils_erp_username_len =
9091 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
9092 connect.fils_erp_realm =
9093 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9094 connect.fils_erp_realm_len =
9095 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
9096 connect.fils_erp_next_seq_num =
9098 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
9099 connect.fils_erp_rrk =
9100 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9101 connect.fils_erp_rrk_len =
9102 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
9103 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
9104 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
9105 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
9106 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
9111 wdev_lock(dev->ieee80211_ptr);
9113 err = cfg80211_connect(rdev, dev, &connect, connkeys,
9114 connect.prev_bssid);
9118 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9119 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9121 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9122 connect.bssid, ETH_ALEN);
9124 memset(dev->ieee80211_ptr->disconnect_bssid,
9128 wdev_unlock(dev->ieee80211_ptr);
9133 static int nl80211_update_connect_params(struct sk_buff *skb,
9134 struct genl_info *info)
9136 struct cfg80211_connect_params connect = {};
9137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9138 struct net_device *dev = info->user_ptr[1];
9139 struct wireless_dev *wdev = dev->ieee80211_ptr;
9143 if (!rdev->ops->update_connect_params)
9146 if (info->attrs[NL80211_ATTR_IE]) {
9147 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9149 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9150 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9151 changed |= UPDATE_ASSOC_IES;
9154 wdev_lock(dev->ieee80211_ptr);
9155 if (!wdev->current_bss)
9158 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
9159 wdev_unlock(dev->ieee80211_ptr);
9164 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
9166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9167 struct net_device *dev = info->user_ptr[1];
9171 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9172 reason = WLAN_REASON_DEAUTH_LEAVING;
9174 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9179 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9180 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9183 wdev_lock(dev->ieee80211_ptr);
9184 ret = cfg80211_disconnect(rdev, dev, reason, true);
9185 wdev_unlock(dev->ieee80211_ptr);
9189 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9195 if (info->attrs[NL80211_ATTR_PID]) {
9196 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9198 net = get_net_ns_by_pid(pid);
9199 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9200 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9202 net = get_net_ns_by_fd(fd);
9208 return PTR_ERR(net);
9212 /* check if anything to do */
9213 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9214 err = cfg80211_switch_netns(rdev, net);
9220 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9223 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9224 struct cfg80211_pmksa *pmksa) = NULL;
9225 struct net_device *dev = info->user_ptr[1];
9226 struct cfg80211_pmksa pmksa;
9228 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9230 if (!info->attrs[NL80211_ATTR_PMKID])
9233 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
9235 if (info->attrs[NL80211_ATTR_MAC]) {
9236 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9237 } else if (info->attrs[NL80211_ATTR_SSID] &&
9238 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9239 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9240 info->attrs[NL80211_ATTR_PMK])) {
9241 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9242 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9244 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9248 if (info->attrs[NL80211_ATTR_PMK]) {
9249 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9250 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9253 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9254 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9257 switch (info->genlhdr->cmd) {
9258 case NL80211_CMD_SET_PMKSA:
9259 rdev_ops = rdev->ops->set_pmksa;
9261 case NL80211_CMD_DEL_PMKSA:
9262 rdev_ops = rdev->ops->del_pmksa;
9272 return rdev_ops(&rdev->wiphy, dev, &pmksa);
9275 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9278 struct net_device *dev = info->user_ptr[1];
9280 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
9281 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9284 if (!rdev->ops->flush_pmksa)
9287 return rdev_flush_pmksa(rdev, dev);
9290 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9292 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9293 struct net_device *dev = info->user_ptr[1];
9294 u8 action_code, dialog_token;
9295 u32 peer_capability = 0;
9300 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9301 !rdev->ops->tdls_mgmt)
9304 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9305 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9306 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9307 !info->attrs[NL80211_ATTR_IE] ||
9308 !info->attrs[NL80211_ATTR_MAC])
9311 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9312 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9313 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9314 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
9315 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
9316 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9318 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
9320 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
9321 dialog_token, status_code, peer_capability,
9323 nla_data(info->attrs[NL80211_ATTR_IE]),
9324 nla_len(info->attrs[NL80211_ATTR_IE]));
9327 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9330 struct net_device *dev = info->user_ptr[1];
9331 enum nl80211_tdls_operation operation;
9334 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9335 !rdev->ops->tdls_oper)
9338 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9339 !info->attrs[NL80211_ATTR_MAC])
9342 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9343 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9345 return rdev_tdls_oper(rdev, dev, peer, operation);
9348 static int nl80211_remain_on_channel(struct sk_buff *skb,
9349 struct genl_info *info)
9351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9352 struct wireless_dev *wdev = info->user_ptr[1];
9353 struct cfg80211_chan_def chandef;
9354 const struct cfg80211_chan_def *compat_chandef;
9355 struct sk_buff *msg;
9361 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9362 !info->attrs[NL80211_ATTR_DURATION])
9365 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9367 if (!rdev->ops->remain_on_channel ||
9368 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
9372 * We should be on that channel for at least a minimum amount of
9373 * time (10ms) but no longer than the driver supports.
9375 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9376 duration > rdev->wiphy.max_remain_on_channel_duration)
9379 err = nl80211_parse_chandef(rdev, info, &chandef);
9384 if (!cfg80211_off_channel_oper_allowed(wdev) &&
9385 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
9386 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
9388 if (compat_chandef != &chandef) {
9395 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9399 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9400 NL80211_CMD_REMAIN_ON_CHANNEL);
9406 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9412 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9414 goto nla_put_failure;
9416 genlmsg_end(msg, hdr);
9418 return genlmsg_reply(msg, info);
9427 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9428 struct genl_info *info)
9430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9431 struct wireless_dev *wdev = info->user_ptr[1];
9434 if (!info->attrs[NL80211_ATTR_COOKIE])
9437 if (!rdev->ops->cancel_remain_on_channel)
9440 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9442 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
9445 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9446 struct genl_info *info)
9448 struct cfg80211_bitrate_mask mask;
9449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9450 struct net_device *dev = info->user_ptr[1];
9453 if (!rdev->ops->set_bitrate_mask)
9456 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9460 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
9463 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
9465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9466 struct wireless_dev *wdev = info->user_ptr[1];
9467 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
9469 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9472 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9473 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
9475 switch (wdev->iftype) {
9476 case NL80211_IFTYPE_STATION:
9477 case NL80211_IFTYPE_ADHOC:
9478 case NL80211_IFTYPE_P2P_CLIENT:
9479 case NL80211_IFTYPE_AP:
9480 case NL80211_IFTYPE_AP_VLAN:
9481 case NL80211_IFTYPE_MESH_POINT:
9482 case NL80211_IFTYPE_P2P_GO:
9483 case NL80211_IFTYPE_P2P_DEVICE:
9485 case NL80211_IFTYPE_NAN:
9490 /* not much point in registering if we can't reply */
9491 if (!rdev->ops->mgmt_tx)
9494 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
9495 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9496 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
9499 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
9501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9502 struct wireless_dev *wdev = info->user_ptr[1];
9503 struct cfg80211_chan_def chandef;
9507 struct sk_buff *msg = NULL;
9508 struct cfg80211_mgmt_tx_params params = {
9509 .dont_wait_for_ack =
9510 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9513 if (!info->attrs[NL80211_ATTR_FRAME])
9516 if (!rdev->ops->mgmt_tx)
9519 switch (wdev->iftype) {
9520 case NL80211_IFTYPE_P2P_DEVICE:
9521 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9523 case NL80211_IFTYPE_STATION:
9524 case NL80211_IFTYPE_ADHOC:
9525 case NL80211_IFTYPE_P2P_CLIENT:
9526 case NL80211_IFTYPE_AP:
9527 case NL80211_IFTYPE_AP_VLAN:
9528 case NL80211_IFTYPE_MESH_POINT:
9529 case NL80211_IFTYPE_P2P_GO:
9531 case NL80211_IFTYPE_NAN:
9536 if (info->attrs[NL80211_ATTR_DURATION]) {
9537 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
9539 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9542 * We should wait on the channel for at least a minimum amount
9543 * of time (10ms) but no longer than the driver supports.
9545 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9546 params.wait > rdev->wiphy.max_remain_on_channel_duration)
9550 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
9552 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
9555 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
9557 /* get the channel if any has been specified, otherwise pass NULL to
9558 * the driver. The latter will use the current one
9560 chandef.chan = NULL;
9561 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9562 err = nl80211_parse_chandef(rdev, info, &chandef);
9567 if (!chandef.chan && params.offchan)
9571 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
9577 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9578 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9580 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9581 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9584 if (len % sizeof(u16))
9587 params.n_csa_offsets = len / sizeof(u16);
9588 params.csa_offsets =
9589 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9591 /* check that all the offsets fit the frame */
9592 for (i = 0; i < params.n_csa_offsets; i++) {
9593 if (params.csa_offsets[i] >= params.len)
9598 if (!params.dont_wait_for_ack) {
9599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9603 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9611 params.chan = chandef.chan;
9612 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie);
9617 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9619 goto nla_put_failure;
9621 genlmsg_end(msg, hdr);
9622 return genlmsg_reply(msg, info);
9634 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9636 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9637 struct wireless_dev *wdev = info->user_ptr[1];
9640 if (!info->attrs[NL80211_ATTR_COOKIE])
9643 if (!rdev->ops->mgmt_tx_cancel_wait)
9646 switch (wdev->iftype) {
9647 case NL80211_IFTYPE_STATION:
9648 case NL80211_IFTYPE_ADHOC:
9649 case NL80211_IFTYPE_P2P_CLIENT:
9650 case NL80211_IFTYPE_AP:
9651 case NL80211_IFTYPE_AP_VLAN:
9652 case NL80211_IFTYPE_P2P_GO:
9653 case NL80211_IFTYPE_P2P_DEVICE:
9655 case NL80211_IFTYPE_NAN:
9660 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9662 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
9665 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9668 struct wireless_dev *wdev;
9669 struct net_device *dev = info->user_ptr[1];
9674 if (!info->attrs[NL80211_ATTR_PS_STATE])
9677 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9679 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9682 wdev = dev->ieee80211_ptr;
9684 if (!rdev->ops->set_power_mgmt)
9687 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9689 if (state == wdev->ps)
9692 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
9698 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9701 enum nl80211_ps_state ps_state;
9702 struct wireless_dev *wdev;
9703 struct net_device *dev = info->user_ptr[1];
9704 struct sk_buff *msg;
9708 wdev = dev->ieee80211_ptr;
9710 if (!rdev->ops->set_power_mgmt)
9713 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9717 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9718 NL80211_CMD_GET_POWER_SAVE);
9725 ps_state = NL80211_PS_ENABLED;
9727 ps_state = NL80211_PS_DISABLED;
9729 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9730 goto nla_put_failure;
9732 genlmsg_end(msg, hdr);
9733 return genlmsg_reply(msg, info);
9742 static const struct nla_policy
9743 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
9744 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
9745 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9746 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
9747 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9748 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9749 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
9750 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
9753 static int nl80211_set_cqm_txe(struct genl_info *info,
9754 u32 rate, u32 pkts, u32 intvl)
9756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9757 struct net_device *dev = info->user_ptr[1];
9758 struct wireless_dev *wdev = dev->ieee80211_ptr;
9760 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
9763 if (!rdev->ops->set_cqm_txe_config)
9766 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9767 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9770 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
9773 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
9774 struct net_device *dev)
9776 struct wireless_dev *wdev = dev->ieee80211_ptr;
9777 s32 last, low, high;
9779 int i, n, low_index;
9782 /* RSSI reporting disabled? */
9783 if (!wdev->cqm_config)
9784 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
9787 * Obtain current RSSI value if possible, if not and no RSSI threshold
9788 * event has been received yet, we should receive an event after a
9789 * connection is established and enough beacons received to calculate
9792 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
9793 rdev->ops->get_station) {
9794 struct station_info sinfo;
9797 mac_addr = wdev->current_bss->pub.bssid;
9799 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
9803 if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
9804 wdev->cqm_config->last_rssi_event_value =
9805 (s8) sinfo.rx_beacon_signal_avg;
9808 last = wdev->cqm_config->last_rssi_event_value;
9809 hyst = wdev->cqm_config->rssi_hyst;
9810 n = wdev->cqm_config->n_rssi_thresholds;
9812 for (i = 0; i < n; i++) {
9813 i = array_index_nospec(i, n);
9814 if (last < wdev->cqm_config->rssi_thresholds[i])
9819 if (low_index >= 0) {
9820 low_index = array_index_nospec(low_index, n);
9821 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
9826 i = array_index_nospec(i, n);
9827 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
9832 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
9835 static int nl80211_set_cqm_rssi(struct genl_info *info,
9836 const s32 *thresholds, int n_thresholds,
9839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9840 struct net_device *dev = info->user_ptr[1];
9841 struct wireless_dev *wdev = dev->ieee80211_ptr;
9845 /* Check all values negative and sorted */
9846 for (i = 0; i < n_thresholds; i++) {
9847 if (thresholds[i] > 0 || thresholds[i] <= prev)
9850 prev = thresholds[i];
9853 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9854 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9858 cfg80211_cqm_config_free(wdev);
9861 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
9862 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
9863 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
9865 return rdev_set_cqm_rssi_config(rdev, dev,
9866 thresholds[0], hysteresis);
9869 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9870 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
9873 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
9878 struct cfg80211_cqm_config *cqm_config;
9880 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
9881 n_thresholds * sizeof(s32), GFP_KERNEL);
9887 cqm_config->rssi_hyst = hysteresis;
9888 cqm_config->n_rssi_thresholds = n_thresholds;
9889 memcpy(cqm_config->rssi_thresholds, thresholds,
9890 n_thresholds * sizeof(s32));
9892 wdev->cqm_config = cqm_config;
9895 err = cfg80211_cqm_rssi_update(rdev, dev);
9903 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9905 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9909 cqm = info->attrs[NL80211_ATTR_CQM];
9913 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9914 nl80211_attr_cqm_policy, info->extack);
9918 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9919 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
9920 const s32 *thresholds =
9921 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9922 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9923 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
9928 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
9932 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9933 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9934 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9935 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9936 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9937 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9939 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9945 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9948 struct net_device *dev = info->user_ptr[1];
9949 struct ocb_setup setup = {};
9952 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9956 return cfg80211_join_ocb(rdev, dev, &setup);
9959 static int nl80211_leave_ocb(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];
9964 return cfg80211_leave_ocb(rdev, dev);
9967 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9970 struct net_device *dev = info->user_ptr[1];
9971 struct mesh_config cfg;
9972 struct mesh_setup setup;
9975 /* start with default */
9976 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
9977 memcpy(&setup, &default_mesh_setup, sizeof(setup));
9979 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
9980 /* and parse parameters if given */
9981 err = nl80211_parse_mesh_config(info, &cfg, NULL);
9986 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9987 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9990 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9991 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9993 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9994 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9995 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9998 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9999 setup.beacon_interval =
10000 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
10002 err = cfg80211_validate_beacon_int(rdev,
10003 NL80211_IFTYPE_MESH_POINT,
10004 setup.beacon_interval);
10009 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
10010 setup.dtim_period =
10011 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
10012 if (setup.dtim_period < 1 || setup.dtim_period > 100)
10016 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
10017 /* parse additional setup parameters if given */
10018 err = nl80211_parse_mesh_setup(info, &setup);
10023 if (setup.user_mpm)
10024 cfg.auto_open_plinks = false;
10026 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10027 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
10031 /* cfg80211_join_mesh() will sort it out */
10032 setup.chandef.chan = NULL;
10035 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
10036 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10038 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
10039 struct ieee80211_supported_band *sband;
10041 if (!setup.chandef.chan)
10044 sband = rdev->wiphy.bands[setup.chandef.chan->band];
10046 err = ieee80211_get_ratemask(sband, rates, n_rates,
10047 &setup.basic_rates);
10052 if (info->attrs[NL80211_ATTR_TX_RATES]) {
10053 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
10057 if (!setup.chandef.chan)
10060 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
10061 &setup.beacon_rate);
10066 setup.userspace_handles_dfs =
10067 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10069 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
10072 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
10074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10075 struct net_device *dev = info->user_ptr[1];
10077 return cfg80211_leave_mesh(rdev, dev);
10081 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10082 struct cfg80211_registered_device *rdev)
10084 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
10085 struct nlattr *nl_pats, *nl_pat;
10088 if (!wowlan->n_patterns)
10091 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10095 for (i = 0; i < wowlan->n_patterns; i++) {
10096 nl_pat = nla_nest_start(msg, i + 1);
10099 pat_len = wowlan->patterns[i].pattern_len;
10100 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
10101 wowlan->patterns[i].mask) ||
10102 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10103 wowlan->patterns[i].pattern) ||
10104 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10105 wowlan->patterns[i].pkt_offset))
10107 nla_nest_end(msg, nl_pat);
10109 nla_nest_end(msg, nl_pats);
10114 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10115 struct cfg80211_wowlan_tcp *tcp)
10117 struct nlattr *nl_tcp;
10122 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10126 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
10127 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
10128 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
10129 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
10130 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
10131 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
10132 tcp->payload_len, tcp->payload) ||
10133 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
10134 tcp->data_interval) ||
10135 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
10136 tcp->wake_len, tcp->wake_data) ||
10137 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
10138 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
10141 if (tcp->payload_seq.len &&
10142 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
10143 sizeof(tcp->payload_seq), &tcp->payload_seq))
10146 if (tcp->payload_tok.len &&
10147 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
10148 sizeof(tcp->payload_tok) + tcp->tokens_size,
10149 &tcp->payload_tok))
10152 nla_nest_end(msg, nl_tcp);
10157 static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10158 struct cfg80211_sched_scan_request *req)
10160 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
10166 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10170 if (req->n_scan_plans == 1 &&
10171 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
10172 req->scan_plans[0].interval * 1000))
10175 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
10178 if (req->relative_rssi_set) {
10179 struct nl80211_bss_select_rssi_adjust rssi_adjust;
10181 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
10182 req->relative_rssi))
10185 rssi_adjust.band = req->rssi_adjust.band;
10186 rssi_adjust.delta = req->rssi_adjust.delta;
10187 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
10188 sizeof(rssi_adjust), &rssi_adjust))
10192 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10196 for (i = 0; i < req->n_channels; i++) {
10197 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10201 nla_nest_end(msg, freqs);
10203 if (req->n_match_sets) {
10204 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
10208 for (i = 0; i < req->n_match_sets; i++) {
10209 match = nla_nest_start(msg, i);
10213 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
10214 req->match_sets[i].ssid.ssid_len,
10215 req->match_sets[i].ssid.ssid))
10217 nla_nest_end(msg, match);
10219 nla_nest_end(msg, matches);
10222 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10226 for (i = 0; i < req->n_scan_plans; i++) {
10227 scan_plan = nla_nest_start(msg, i + 1);
10232 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
10233 req->scan_plans[i].interval) ||
10234 (req->scan_plans[i].iterations &&
10235 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
10236 req->scan_plans[i].iterations)))
10238 nla_nest_end(msg, scan_plan);
10240 nla_nest_end(msg, scan_plans);
10242 nla_nest_end(msg, nd);
10247 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10250 struct sk_buff *msg;
10252 u32 size = NLMSG_DEFAULT_SIZE;
10254 if (!rdev->wiphy.wowlan)
10255 return -EOPNOTSUPP;
10257 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
10258 /* adjust size to have room for all the data */
10259 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
10260 rdev->wiphy.wowlan_config->tcp->payload_len +
10261 rdev->wiphy.wowlan_config->tcp->wake_len +
10262 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
10265 msg = nlmsg_new(size, GFP_KERNEL);
10269 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10270 NL80211_CMD_GET_WOWLAN);
10272 goto nla_put_failure;
10274 if (rdev->wiphy.wowlan_config) {
10275 struct nlattr *nl_wowlan;
10277 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10279 goto nla_put_failure;
10281 if ((rdev->wiphy.wowlan_config->any &&
10282 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
10283 (rdev->wiphy.wowlan_config->disconnect &&
10284 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
10285 (rdev->wiphy.wowlan_config->magic_pkt &&
10286 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
10287 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
10288 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
10289 (rdev->wiphy.wowlan_config->eap_identity_req &&
10290 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
10291 (rdev->wiphy.wowlan_config->four_way_handshake &&
10292 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
10293 (rdev->wiphy.wowlan_config->rfkill_release &&
10294 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
10295 goto nla_put_failure;
10297 if (nl80211_send_wowlan_patterns(msg, rdev))
10298 goto nla_put_failure;
10300 if (nl80211_send_wowlan_tcp(msg,
10301 rdev->wiphy.wowlan_config->tcp))
10302 goto nla_put_failure;
10304 if (nl80211_send_wowlan_nd(
10306 rdev->wiphy.wowlan_config->nd_config))
10307 goto nla_put_failure;
10309 nla_nest_end(msg, nl_wowlan);
10312 genlmsg_end(msg, hdr);
10313 return genlmsg_reply(msg, info);
10320 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10321 struct nlattr *attr,
10322 struct cfg80211_wowlan *trig)
10324 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10325 struct cfg80211_wowlan_tcp *cfg;
10326 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10327 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10329 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10332 if (!rdev->wiphy.wowlan->tcp)
10335 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
10336 nl80211_wowlan_tcp_policy, NULL);
10340 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10341 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10342 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10343 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10344 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10345 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10346 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10347 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10350 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
10351 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
10354 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
10355 rdev->wiphy.wowlan->tcp->data_interval_max ||
10356 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
10359 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
10360 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
10363 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10364 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10367 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10368 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10370 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10371 tokens_size = tokln - sizeof(*tok);
10373 if (!tok->len || tokens_size % tok->len)
10375 if (!rdev->wiphy.wowlan->tcp->tok)
10377 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
10379 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
10381 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
10383 if (tok->offset + tok->len > data_size)
10387 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10388 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
10389 if (!rdev->wiphy.wowlan->tcp->seq)
10391 if (seq->len == 0 || seq->len > 4)
10393 if (seq->len + seq->offset > data_size)
10397 size = sizeof(*cfg);
10399 size += wake_size + wake_mask_size;
10400 size += tokens_size;
10402 cfg = kzalloc(size, GFP_KERNEL);
10405 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10406 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
10407 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10409 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10410 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10414 /* allocate a socket and port for it and use it */
10415 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10416 IPPROTO_TCP, &cfg->sock, 1);
10421 if (inet_csk_get_port(cfg->sock->sk, port)) {
10422 sock_release(cfg->sock);
10424 return -EADDRINUSE;
10426 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10432 cfg->src_port = port;
10435 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10436 cfg->payload_len = data_size;
10437 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10438 memcpy((void *)cfg->payload,
10439 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10442 cfg->payload_seq = *seq;
10443 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10444 cfg->wake_len = wake_size;
10445 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10446 memcpy((void *)cfg->wake_data,
10447 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10449 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10450 data_size + wake_size;
10451 memcpy((void *)cfg->wake_mask,
10452 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10455 cfg->tokens_size = tokens_size;
10456 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10464 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10465 const struct wiphy_wowlan_support *wowlan,
10466 struct nlattr *attr,
10467 struct cfg80211_wowlan *trig)
10469 struct nlattr **tb;
10472 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10476 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10481 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy,
10486 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
10487 wowlan->max_nd_match_sets);
10488 err = PTR_ERR_OR_ZERO(trig->nd_config);
10490 trig->nd_config = NULL;
10497 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10500 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
10501 struct cfg80211_wowlan new_triggers = {};
10502 struct cfg80211_wowlan *ntrig;
10503 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
10505 bool prev_enabled = rdev->wiphy.wowlan_config;
10506 bool regular = false;
10509 return -EOPNOTSUPP;
10511 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10512 cfg80211_rdev_free_wowlan(rdev);
10513 rdev->wiphy.wowlan_config = NULL;
10517 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10518 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
10519 nl80211_wowlan_policy, info->extack);
10523 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10524 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10526 new_triggers.any = true;
10529 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10530 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10532 new_triggers.disconnect = true;
10536 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10537 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10539 new_triggers.magic_pkt = true;
10543 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10546 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10547 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10549 new_triggers.gtk_rekey_failure = true;
10553 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10554 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10556 new_triggers.eap_identity_req = true;
10560 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10561 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10563 new_triggers.four_way_handshake = true;
10567 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10568 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10570 new_triggers.rfkill_release = true;
10574 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10575 struct nlattr *pat;
10576 int n_patterns = 0;
10577 int rem, pat_len, mask_len, pkt_offset;
10578 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10582 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10585 if (n_patterns > wowlan->n_patterns)
10588 new_triggers.patterns = kcalloc(n_patterns,
10589 sizeof(new_triggers.patterns[0]),
10591 if (!new_triggers.patterns)
10594 new_triggers.n_patterns = n_patterns;
10597 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10601 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10602 nl80211_packet_pattern_policy,
10608 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10609 !pat_tb[NL80211_PKTPAT_PATTERN])
10611 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10612 mask_len = DIV_ROUND_UP(pat_len, 8);
10613 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10615 if (pat_len > wowlan->pattern_max_len ||
10616 pat_len < wowlan->pattern_min_len)
10619 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10622 pkt_offset = nla_get_u32(
10623 pat_tb[NL80211_PKTPAT_OFFSET]);
10624 if (pkt_offset > wowlan->max_pkt_offset)
10626 new_triggers.patterns[i].pkt_offset = pkt_offset;
10628 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10633 new_triggers.patterns[i].mask = mask_pat;
10634 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10636 mask_pat += mask_len;
10637 new_triggers.patterns[i].pattern = mask_pat;
10638 new_triggers.patterns[i].pattern_len = pat_len;
10640 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10646 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
10648 err = nl80211_parse_wowlan_tcp(
10649 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10655 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
10657 err = nl80211_parse_wowlan_nd(
10658 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10664 /* The 'any' trigger means the device continues operating more or less
10665 * as in its normal operation mode and wakes up the host on most of the
10666 * normal interrupts (like packet RX, ...)
10667 * It therefore makes little sense to combine with the more constrained
10668 * wakeup trigger modes.
10670 if (new_triggers.any && regular) {
10675 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10680 cfg80211_rdev_free_wowlan(rdev);
10681 rdev->wiphy.wowlan_config = ntrig;
10684 if (rdev->ops->set_wakeup &&
10685 prev_enabled != !!rdev->wiphy.wowlan_config)
10686 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
10690 for (i = 0; i < new_triggers.n_patterns; i++)
10691 kfree(new_triggers.patterns[i].mask);
10692 kfree(new_triggers.patterns);
10693 if (new_triggers.tcp && new_triggers.tcp->sock)
10694 sock_release(new_triggers.tcp->sock);
10695 kfree(new_triggers.tcp);
10696 kfree(new_triggers.nd_config);
10701 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10702 struct cfg80211_registered_device *rdev)
10704 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10706 struct cfg80211_coalesce_rules *rule;
10708 if (!rdev->coalesce->n_rules)
10711 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10715 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10716 nl_rule = nla_nest_start(msg, i + 1);
10720 rule = &rdev->coalesce->rules[i];
10721 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10725 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10729 nl_pats = nla_nest_start(msg,
10730 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10734 for (j = 0; j < rule->n_patterns; j++) {
10735 nl_pat = nla_nest_start(msg, j + 1);
10738 pat_len = rule->patterns[j].pattern_len;
10739 if (nla_put(msg, NL80211_PKTPAT_MASK,
10740 DIV_ROUND_UP(pat_len, 8),
10741 rule->patterns[j].mask) ||
10742 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10743 rule->patterns[j].pattern) ||
10744 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10745 rule->patterns[j].pkt_offset))
10747 nla_nest_end(msg, nl_pat);
10749 nla_nest_end(msg, nl_pats);
10750 nla_nest_end(msg, nl_rule);
10752 nla_nest_end(msg, nl_rules);
10757 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10760 struct sk_buff *msg;
10763 if (!rdev->wiphy.coalesce)
10764 return -EOPNOTSUPP;
10766 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10770 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10771 NL80211_CMD_GET_COALESCE);
10773 goto nla_put_failure;
10775 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10776 goto nla_put_failure;
10778 genlmsg_end(msg, hdr);
10779 return genlmsg_reply(msg, info);
10786 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10788 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10790 struct cfg80211_coalesce_rules *rule;
10795 for (i = 0; i < coalesce->n_rules; i++) {
10796 rule = &coalesce->rules[i];
10797 for (j = 0; j < rule->n_patterns; j++)
10798 kfree(rule->patterns[j].mask);
10799 kfree(rule->patterns);
10801 kfree(coalesce->rules);
10803 rdev->coalesce = NULL;
10806 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10807 struct nlattr *rule,
10808 struct cfg80211_coalesce_rules *new_rule)
10811 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10812 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10813 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10814 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10816 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
10817 nl80211_coalesce_policy, NULL);
10821 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10823 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10824 if (new_rule->delay > coalesce->max_delay)
10827 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10828 new_rule->condition =
10829 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10830 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10831 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10834 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10837 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10840 if (n_patterns > coalesce->n_patterns)
10843 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10845 if (!new_rule->patterns)
10848 new_rule->n_patterns = n_patterns;
10851 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10855 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10856 nl80211_packet_pattern_policy, NULL);
10860 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10861 !pat_tb[NL80211_PKTPAT_PATTERN])
10863 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10864 mask_len = DIV_ROUND_UP(pat_len, 8);
10865 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10867 if (pat_len > coalesce->pattern_max_len ||
10868 pat_len < coalesce->pattern_min_len)
10871 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10874 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10875 if (pkt_offset > coalesce->max_pkt_offset)
10877 new_rule->patterns[i].pkt_offset = pkt_offset;
10879 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10883 new_rule->patterns[i].mask = mask_pat;
10884 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10887 mask_pat += mask_len;
10888 new_rule->patterns[i].pattern = mask_pat;
10889 new_rule->patterns[i].pattern_len = pat_len;
10890 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10898 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10901 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10902 struct cfg80211_coalesce new_coalesce = {};
10903 struct cfg80211_coalesce *n_coalesce;
10904 int err, rem_rule, n_rules = 0, i, j;
10905 struct nlattr *rule;
10906 struct cfg80211_coalesce_rules *tmp_rule;
10908 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10909 return -EOPNOTSUPP;
10911 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10912 cfg80211_rdev_free_coalesce(rdev);
10913 rdev_set_coalesce(rdev, NULL);
10917 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10920 if (n_rules > coalesce->n_rules)
10923 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10925 if (!new_coalesce.rules)
10928 new_coalesce.n_rules = n_rules;
10931 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10933 err = nl80211_parse_coalesce_rule(rdev, rule,
10934 &new_coalesce.rules[i]);
10941 err = rdev_set_coalesce(rdev, &new_coalesce);
10945 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10950 cfg80211_rdev_free_coalesce(rdev);
10951 rdev->coalesce = n_coalesce;
10955 for (i = 0; i < new_coalesce.n_rules; i++) {
10956 tmp_rule = &new_coalesce.rules[i];
10957 for (j = 0; j < tmp_rule->n_patterns; j++)
10958 kfree(tmp_rule->patterns[j].mask);
10959 kfree(tmp_rule->patterns);
10961 kfree(new_coalesce.rules);
10966 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10969 struct net_device *dev = info->user_ptr[1];
10970 struct wireless_dev *wdev = dev->ieee80211_ptr;
10971 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10972 struct cfg80211_gtk_rekey_data rekey_data = {};
10975 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10978 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10979 info->attrs[NL80211_ATTR_REKEY_DATA],
10980 nl80211_rekey_policy, info->extack);
10984 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
10985 !tb[NL80211_REKEY_DATA_KCK])
10987 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10989 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10991 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10994 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10995 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10996 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
10999 if (!wdev->current_bss) {
11004 if (!rdev->ops->set_rekey_data) {
11009 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
11015 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
11016 struct genl_info *info)
11018 struct net_device *dev = info->user_ptr[1];
11019 struct wireless_dev *wdev = dev->ieee80211_ptr;
11021 if (wdev->iftype != NL80211_IFTYPE_AP &&
11022 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11025 if (wdev->ap_unexpected_nlportid)
11028 wdev->ap_unexpected_nlportid = info->snd_portid;
11032 static int nl80211_probe_client(struct sk_buff *skb,
11033 struct genl_info *info)
11035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11036 struct net_device *dev = info->user_ptr[1];
11037 struct wireless_dev *wdev = dev->ieee80211_ptr;
11038 struct sk_buff *msg;
11044 if (wdev->iftype != NL80211_IFTYPE_AP &&
11045 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11046 return -EOPNOTSUPP;
11048 if (!info->attrs[NL80211_ATTR_MAC])
11051 if (!rdev->ops->probe_client)
11052 return -EOPNOTSUPP;
11054 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11058 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11059 NL80211_CMD_PROBE_CLIENT);
11065 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11067 err = rdev_probe_client(rdev, dev, addr, &cookie);
11071 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11073 goto nla_put_failure;
11075 genlmsg_end(msg, hdr);
11077 return genlmsg_reply(msg, info);
11086 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
11088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11089 struct cfg80211_beacon_registration *reg, *nreg;
11092 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
11093 return -EOPNOTSUPP;
11095 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
11099 /* First, check if already registered. */
11100 spin_lock_bh(&rdev->beacon_registrations_lock);
11101 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11102 if (reg->nlportid == info->snd_portid) {
11107 /* Add it to the list */
11108 nreg->nlportid = info->snd_portid;
11109 list_add(&nreg->list, &rdev->beacon_registrations);
11111 spin_unlock_bh(&rdev->beacon_registrations_lock);
11115 spin_unlock_bh(&rdev->beacon_registrations_lock);
11120 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
11122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11123 struct wireless_dev *wdev = info->user_ptr[1];
11126 if (!rdev->ops->start_p2p_device)
11127 return -EOPNOTSUPP;
11129 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11130 return -EOPNOTSUPP;
11132 if (wdev_running(wdev))
11135 if (rfkill_blocked(rdev->rfkill))
11138 err = rdev_start_p2p_device(rdev, wdev);
11142 wdev->is_running = true;
11148 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
11150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11151 struct wireless_dev *wdev = info->user_ptr[1];
11153 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
11154 return -EOPNOTSUPP;
11156 if (!rdev->ops->stop_p2p_device)
11157 return -EOPNOTSUPP;
11159 cfg80211_stop_p2p_device(rdev, wdev);
11164 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
11166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11167 struct wireless_dev *wdev = info->user_ptr[1];
11168 struct cfg80211_nan_conf conf = {};
11171 if (wdev->iftype != NL80211_IFTYPE_NAN)
11172 return -EOPNOTSUPP;
11174 if (wdev_running(wdev))
11177 if (rfkill_blocked(rdev->rfkill))
11180 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
11184 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11185 if (!conf.master_pref)
11188 if (info->attrs[NL80211_ATTR_BANDS]) {
11189 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11191 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11192 return -EOPNOTSUPP;
11194 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11197 conf.bands = bands;
11200 err = rdev_start_nan(rdev, wdev, &conf);
11204 wdev->is_running = true;
11210 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
11212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11213 struct wireless_dev *wdev = info->user_ptr[1];
11215 if (wdev->iftype != NL80211_IFTYPE_NAN)
11216 return -EOPNOTSUPP;
11218 cfg80211_stop_nan(rdev, wdev);
11223 static int validate_nan_filter(struct nlattr *filter_attr)
11225 struct nlattr *attr;
11226 int len = 0, n_entries = 0, rem;
11228 nla_for_each_nested(attr, filter_attr, rem) {
11229 len += nla_len(attr);
11239 static int handle_nan_filter(struct nlattr *attr_filter,
11240 struct cfg80211_nan_func *func,
11243 struct nlattr *attr;
11244 int n_entries, rem, i;
11245 struct cfg80211_nan_func_filter *filter;
11247 n_entries = validate_nan_filter(attr_filter);
11251 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
11253 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
11258 nla_for_each_nested(attr, attr_filter, rem) {
11259 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
11260 filter[i].len = nla_len(attr);
11264 func->num_tx_filters = n_entries;
11265 func->tx_filters = filter;
11267 func->num_rx_filters = n_entries;
11268 func->rx_filters = filter;
11274 static int nl80211_nan_add_func(struct sk_buff *skb,
11275 struct genl_info *info)
11277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11278 struct wireless_dev *wdev = info->user_ptr[1];
11279 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
11280 struct cfg80211_nan_func *func;
11281 struct sk_buff *msg = NULL;
11285 if (wdev->iftype != NL80211_IFTYPE_NAN)
11286 return -EOPNOTSUPP;
11288 if (!wdev_running(wdev))
11291 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11294 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
11295 info->attrs[NL80211_ATTR_NAN_FUNC],
11296 nl80211_nan_func_policy, info->extack);
11300 func = kzalloc(sizeof(*func), GFP_KERNEL);
11304 func->cookie = wdev->wiphy->cookie_counter++;
11306 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11307 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11313 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11315 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11320 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11321 sizeof(func->service_id));
11323 func->close_range =
11324 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11326 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11327 func->serv_spec_info_len =
11328 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11329 func->serv_spec_info =
11330 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11331 func->serv_spec_info_len,
11333 if (!func->serv_spec_info) {
11339 if (tb[NL80211_NAN_FUNC_TTL])
11340 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11342 switch (func->type) {
11343 case NL80211_NAN_FUNC_PUBLISH:
11344 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11349 func->publish_type =
11350 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11351 func->publish_bcast =
11352 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11354 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11355 func->publish_bcast) {
11360 case NL80211_NAN_FUNC_SUBSCRIBE:
11361 func->subscribe_active =
11362 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11364 case NL80211_NAN_FUNC_FOLLOW_UP:
11365 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11366 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
11367 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
11372 func->followup_id =
11373 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11374 func->followup_reqid =
11375 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11376 memcpy(func->followup_dest.addr,
11377 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11378 sizeof(func->followup_dest.addr));
11389 if (tb[NL80211_NAN_FUNC_SRF]) {
11390 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11392 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11393 tb[NL80211_NAN_FUNC_SRF],
11394 nl80211_nan_srf_policy, info->extack);
11398 func->srf_include =
11399 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11401 if (srf_tb[NL80211_NAN_SRF_BF]) {
11402 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11403 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11409 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11411 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11412 func->srf_bf_len, GFP_KERNEL);
11413 if (!func->srf_bf) {
11419 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11421 struct nlattr *attr, *mac_attr =
11422 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11423 int n_entries, rem, i = 0;
11430 n_entries = validate_acl_mac_addrs(mac_attr);
11431 if (n_entries <= 0) {
11436 func->srf_num_macs = n_entries;
11438 kzalloc(sizeof(*func->srf_macs) * n_entries,
11440 if (!func->srf_macs) {
11445 nla_for_each_nested(attr, mac_attr, rem)
11446 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11447 sizeof(*func->srf_macs));
11451 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11452 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11458 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11459 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11465 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11471 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11472 NL80211_CMD_ADD_NAN_FUNCTION);
11473 /* This can't really happen - we just allocated 4KB */
11474 if (WARN_ON(!hdr)) {
11479 err = rdev_add_nan_func(rdev, wdev, func);
11482 cfg80211_free_nan_func(func);
11487 /* propagate the instance id and cookie to userspace */
11488 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11490 goto nla_put_failure;
11492 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11494 goto nla_put_failure;
11496 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11497 func->instance_id))
11498 goto nla_put_failure;
11500 nla_nest_end(msg, func_attr);
11502 genlmsg_end(msg, hdr);
11503 return genlmsg_reply(msg, info);
11510 static int nl80211_nan_del_func(struct sk_buff *skb,
11511 struct genl_info *info)
11513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11514 struct wireless_dev *wdev = info->user_ptr[1];
11517 if (wdev->iftype != NL80211_IFTYPE_NAN)
11518 return -EOPNOTSUPP;
11520 if (!wdev_running(wdev))
11523 if (!info->attrs[NL80211_ATTR_COOKIE])
11526 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11528 rdev_del_nan_func(rdev, wdev, cookie);
11533 static int nl80211_nan_change_config(struct sk_buff *skb,
11534 struct genl_info *info)
11536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11537 struct wireless_dev *wdev = info->user_ptr[1];
11538 struct cfg80211_nan_conf conf = {};
11541 if (wdev->iftype != NL80211_IFTYPE_NAN)
11542 return -EOPNOTSUPP;
11544 if (!wdev_running(wdev))
11547 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11549 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11550 if (conf.master_pref <= 1 || conf.master_pref == 255)
11553 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11556 if (info->attrs[NL80211_ATTR_BANDS]) {
11557 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
11559 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
11560 return -EOPNOTSUPP;
11562 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
11565 conf.bands = bands;
11566 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
11572 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11575 void cfg80211_nan_match(struct wireless_dev *wdev,
11576 struct cfg80211_nan_match_params *match, gfp_t gfp)
11578 struct wiphy *wiphy = wdev->wiphy;
11579 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11580 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11581 struct sk_buff *msg;
11584 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11587 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11591 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11597 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11598 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11599 wdev->netdev->ifindex)) ||
11600 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11602 goto nla_put_failure;
11604 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11605 NL80211_ATTR_PAD) ||
11606 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11607 goto nla_put_failure;
11609 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11611 goto nla_put_failure;
11613 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11614 if (!local_func_attr)
11615 goto nla_put_failure;
11617 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11618 goto nla_put_failure;
11620 nla_nest_end(msg, local_func_attr);
11622 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11623 if (!peer_func_attr)
11624 goto nla_put_failure;
11626 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11627 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11628 goto nla_put_failure;
11630 if (match->info && match->info_len &&
11631 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11633 goto nla_put_failure;
11635 nla_nest_end(msg, peer_func_attr);
11636 nla_nest_end(msg, match_attr);
11637 genlmsg_end(msg, hdr);
11639 if (!wdev->owner_nlportid)
11640 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11641 msg, 0, NL80211_MCGRP_NAN, gfp);
11643 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11644 wdev->owner_nlportid);
11651 EXPORT_SYMBOL(cfg80211_nan_match);
11653 void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11655 enum nl80211_nan_func_term_reason reason,
11656 u64 cookie, gfp_t gfp)
11658 struct wiphy *wiphy = wdev->wiphy;
11659 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11660 struct sk_buff *msg;
11661 struct nlattr *func_attr;
11664 if (WARN_ON(!inst_id))
11667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11671 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11677 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11678 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11679 wdev->netdev->ifindex)) ||
11680 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11682 goto nla_put_failure;
11684 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11686 goto nla_put_failure;
11688 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11690 goto nla_put_failure;
11692 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11693 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11694 goto nla_put_failure;
11696 nla_nest_end(msg, func_attr);
11697 genlmsg_end(msg, hdr);
11699 if (!wdev->owner_nlportid)
11700 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11701 msg, 0, NL80211_MCGRP_NAN, gfp);
11703 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11704 wdev->owner_nlportid);
11711 EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11713 static int nl80211_get_protocol_features(struct sk_buff *skb,
11714 struct genl_info *info)
11717 struct sk_buff *msg;
11719 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11723 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11724 NL80211_CMD_GET_PROTOCOL_FEATURES);
11726 goto nla_put_failure;
11728 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11729 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11730 goto nla_put_failure;
11732 genlmsg_end(msg, hdr);
11733 return genlmsg_reply(msg, info);
11740 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11743 struct cfg80211_update_ft_ies_params ft_params;
11744 struct net_device *dev = info->user_ptr[1];
11746 if (!rdev->ops->update_ft_ies)
11747 return -EOPNOTSUPP;
11749 if (!info->attrs[NL80211_ATTR_MDID] ||
11750 !info->attrs[NL80211_ATTR_IE] ||
11751 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11754 memset(&ft_params, 0, sizeof(ft_params));
11755 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11756 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11757 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11759 return rdev_update_ft_ies(rdev, dev, &ft_params);
11762 static int nl80211_crit_protocol_start(struct sk_buff *skb,
11763 struct genl_info *info)
11765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11766 struct wireless_dev *wdev = info->user_ptr[1];
11767 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11771 if (!rdev->ops->crit_proto_start)
11772 return -EOPNOTSUPP;
11774 if (WARN_ON(!rdev->ops->crit_proto_stop))
11777 if (rdev->crit_proto_nlportid)
11780 /* determine protocol if provided */
11781 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11782 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11784 if (proto >= NUM_NL80211_CRIT_PROTO)
11787 /* timeout must be provided */
11788 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11792 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11794 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11797 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11799 rdev->crit_proto_nlportid = info->snd_portid;
11804 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11805 struct genl_info *info)
11807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11808 struct wireless_dev *wdev = info->user_ptr[1];
11810 if (!rdev->ops->crit_proto_stop)
11811 return -EOPNOTSUPP;
11813 if (rdev->crit_proto_nlportid) {
11814 rdev->crit_proto_nlportid = 0;
11815 rdev_crit_proto_stop(rdev, wdev);
11820 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11823 struct wireless_dev *wdev =
11824 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11828 if (!rdev->wiphy.vendor_commands)
11829 return -EOPNOTSUPP;
11831 if (IS_ERR(wdev)) {
11832 err = PTR_ERR(wdev);
11833 if (err != -EINVAL)
11836 } else if (wdev->wiphy != &rdev->wiphy) {
11840 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11841 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11844 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11845 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11846 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11847 const struct wiphy_vendor_command *vcmd;
11851 vcmd = &rdev->wiphy.vendor_commands[i];
11853 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11856 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11857 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11860 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11864 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11865 if (!wdev_running(wdev))
11873 return -EOPNOTSUPP;
11875 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11876 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11877 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11880 rdev->cur_cmd_info = info;
11881 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11883 rdev->cur_cmd_info = NULL;
11887 return -EOPNOTSUPP;
11890 static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11891 struct netlink_callback *cb,
11892 struct cfg80211_registered_device **rdev,
11893 struct wireless_dev **wdev)
11895 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
11901 unsigned int data_len = 0;
11904 /* subtract the 1 again here */
11905 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11906 struct wireless_dev *tmp;
11910 *rdev = wiphy_to_rdev(wiphy);
11914 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
11915 if (tmp->identifier == cb->args[1] - 1) {
11922 /* keep rtnl locked in successful case */
11926 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf,
11927 nl80211_fam.maxattr, nl80211_policy, NULL);
11931 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
11932 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11935 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
11939 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
11941 return PTR_ERR(*rdev);
11943 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11944 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
11946 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11947 const struct wiphy_vendor_command *vcmd;
11949 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11951 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11955 return -EOPNOTSUPP;
11962 return -EOPNOTSUPP;
11964 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11965 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11966 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11969 /* 0 is the first index - add 1 to parse only once */
11970 cb->args[0] = (*rdev)->wiphy_idx + 1;
11971 /* add 1 to know if it was NULL */
11972 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11973 cb->args[2] = vcmd_idx;
11974 cb->args[3] = (unsigned long)data;
11975 cb->args[4] = data_len;
11977 /* keep rtnl locked in successful case */
11981 static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11982 struct netlink_callback *cb)
11984 struct cfg80211_registered_device *rdev;
11985 struct wireless_dev *wdev;
11986 unsigned int vcmd_idx;
11987 const struct wiphy_vendor_command *vcmd;
11991 struct nlattr *vendor_data;
11994 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11998 vcmd_idx = cb->args[2];
11999 data = (void *)cb->args[3];
12000 data_len = cb->args[4];
12001 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
12003 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
12004 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
12009 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
12015 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
12016 if (!wdev_running(wdev)) {
12024 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
12025 cb->nlh->nlmsg_seq, NLM_F_MULTI,
12026 NL80211_CMD_VENDOR);
12030 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12031 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
12033 NL80211_ATTR_PAD))) {
12034 genlmsg_cancel(skb, hdr);
12038 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
12039 if (!vendor_data) {
12040 genlmsg_cancel(skb, hdr);
12044 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
12045 (unsigned long *)&cb->args[5]);
12046 nla_nest_end(skb, vendor_data);
12048 if (err == -ENOBUFS || err == -ENOENT) {
12049 genlmsg_cancel(skb, hdr);
12052 genlmsg_cancel(skb, hdr);
12056 genlmsg_end(skb, hdr);
12065 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
12066 enum nl80211_commands cmd,
12067 enum nl80211_attrs attr,
12070 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12072 if (WARN_ON(!rdev->cur_cmd_info))
12075 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
12076 rdev->cur_cmd_info->snd_portid,
12077 rdev->cur_cmd_info->snd_seq,
12078 cmd, attr, NULL, GFP_KERNEL);
12080 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
12082 int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
12084 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
12085 void *hdr = ((void **)skb->cb)[1];
12086 struct nlattr *data = ((void **)skb->cb)[2];
12088 /* clear CB data for netlink core to own from now on */
12089 memset(skb->cb, 0, sizeof(skb->cb));
12091 if (WARN_ON(!rdev->cur_cmd_info)) {
12096 nla_nest_end(skb, data);
12097 genlmsg_end(skb, hdr);
12098 return genlmsg_reply(skb, rdev->cur_cmd_info);
12100 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
12102 static int nl80211_set_qos_map(struct sk_buff *skb,
12103 struct genl_info *info)
12105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12106 struct cfg80211_qos_map *qos_map = NULL;
12107 struct net_device *dev = info->user_ptr[1];
12108 u8 *pos, len, num_des, des_len, des;
12111 if (!rdev->ops->set_qos_map)
12112 return -EOPNOTSUPP;
12114 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
12115 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
12116 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
12118 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
12119 len > IEEE80211_QOS_MAP_LEN_MAX)
12122 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
12126 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
12128 des_len = num_des *
12129 sizeof(struct cfg80211_dscp_exception);
12130 memcpy(qos_map->dscp_exception, pos, des_len);
12131 qos_map->num_des = num_des;
12132 for (des = 0; des < num_des; des++) {
12133 if (qos_map->dscp_exception[des].up > 7) {
12140 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
12143 wdev_lock(dev->ieee80211_ptr);
12144 ret = nl80211_key_allowed(dev->ieee80211_ptr);
12146 ret = rdev_set_qos_map(rdev, dev, qos_map);
12147 wdev_unlock(dev->ieee80211_ptr);
12153 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
12155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12156 struct net_device *dev = info->user_ptr[1];
12157 struct wireless_dev *wdev = dev->ieee80211_ptr;
12160 u16 admitted_time = 0;
12163 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
12164 return -EOPNOTSUPP;
12166 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
12167 !info->attrs[NL80211_ATTR_USER_PRIO])
12170 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12171 if (tsid >= IEEE80211_NUM_TIDS)
12174 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
12175 if (up >= IEEE80211_NUM_UPS)
12178 /* WMM uses TIDs 0-7 even for TSPEC */
12179 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
12180 /* TODO: handle 802.11 TSPEC/admission control
12181 * need more attributes for that (e.g. BA session requirement);
12182 * change the WMM adminssion test above to allow both then
12187 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12189 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
12191 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
12192 if (!admitted_time)
12197 switch (wdev->iftype) {
12198 case NL80211_IFTYPE_STATION:
12199 case NL80211_IFTYPE_P2P_CLIENT:
12200 if (wdev->current_bss)
12209 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
12216 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
12218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12219 struct net_device *dev = info->user_ptr[1];
12220 struct wireless_dev *wdev = dev->ieee80211_ptr;
12225 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
12228 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
12229 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
12232 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
12238 static int nl80211_tdls_channel_switch(struct sk_buff *skb,
12239 struct genl_info *info)
12241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12242 struct net_device *dev = info->user_ptr[1];
12243 struct wireless_dev *wdev = dev->ieee80211_ptr;
12244 struct cfg80211_chan_def chandef = {};
12249 if (!rdev->ops->tdls_channel_switch ||
12250 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12251 return -EOPNOTSUPP;
12253 switch (dev->ieee80211_ptr->iftype) {
12254 case NL80211_IFTYPE_STATION:
12255 case NL80211_IFTYPE_P2P_CLIENT:
12258 return -EOPNOTSUPP;
12261 if (!info->attrs[NL80211_ATTR_MAC] ||
12262 !info->attrs[NL80211_ATTR_OPER_CLASS])
12265 err = nl80211_parse_chandef(rdev, info, &chandef);
12270 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12271 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12272 * specification is not defined for them.
12274 if (chandef.chan->band == NL80211_BAND_2GHZ &&
12275 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
12276 chandef.width != NL80211_CHAN_WIDTH_20)
12279 /* we will be active on the TDLS link */
12280 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
12284 /* don't allow switching to DFS channels */
12285 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
12288 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12289 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
12292 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
12298 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12299 struct genl_info *info)
12301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12302 struct net_device *dev = info->user_ptr[1];
12303 struct wireless_dev *wdev = dev->ieee80211_ptr;
12306 if (!rdev->ops->tdls_channel_switch ||
12307 !rdev->ops->tdls_cancel_channel_switch ||
12308 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12309 return -EOPNOTSUPP;
12311 switch (dev->ieee80211_ptr->iftype) {
12312 case NL80211_IFTYPE_STATION:
12313 case NL80211_IFTYPE_P2P_CLIENT:
12316 return -EOPNOTSUPP;
12319 if (!info->attrs[NL80211_ATTR_MAC])
12322 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12325 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12331 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12332 struct genl_info *info)
12334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12335 struct net_device *dev = info->user_ptr[1];
12336 struct wireless_dev *wdev = dev->ieee80211_ptr;
12337 const struct nlattr *nla;
12340 if (!rdev->ops->set_multicast_to_unicast)
12341 return -EOPNOTSUPP;
12343 if (wdev->iftype != NL80211_IFTYPE_AP &&
12344 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12345 return -EOPNOTSUPP;
12347 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12348 enabled = nla_get_flag(nla);
12350 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12353 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
12355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12356 struct net_device *dev = info->user_ptr[1];
12357 struct wireless_dev *wdev = dev->ieee80211_ptr;
12358 struct cfg80211_pmk_conf pmk_conf = {};
12361 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12362 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12363 return -EOPNOTSUPP;
12365 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12366 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12367 return -EOPNOTSUPP;
12369 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
12373 if (!wdev->current_bss) {
12378 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12379 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
12384 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
12385 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
12386 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
12387 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
12392 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
12393 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12395 if (r0_name_len != WLAN_PMK_NAME_LEN) {
12400 pmk_conf.pmk_r0_name =
12401 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
12404 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
12410 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
12412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12413 struct net_device *dev = info->user_ptr[1];
12414 struct wireless_dev *wdev = dev->ieee80211_ptr;
12418 if (wdev->iftype != NL80211_IFTYPE_STATION &&
12419 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
12420 return -EOPNOTSUPP;
12422 if (!wiphy_ext_feature_isset(&rdev->wiphy,
12423 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
12424 return -EOPNOTSUPP;
12426 if (!info->attrs[NL80211_ATTR_MAC])
12430 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
12431 ret = rdev_del_pmk(rdev, dev, aa);
12437 #define NL80211_FLAG_NEED_WIPHY 0x01
12438 #define NL80211_FLAG_NEED_NETDEV 0x02
12439 #define NL80211_FLAG_NEED_RTNL 0x04
12440 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12441 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12442 NL80211_FLAG_CHECK_NETDEV_UP)
12443 #define NL80211_FLAG_NEED_WDEV 0x10
12444 /* If a netdev is associated, it must be UP, P2P must be started */
12445 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12446 NL80211_FLAG_CHECK_NETDEV_UP)
12447 #define NL80211_FLAG_CLEAR_SKB 0x20
12449 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
12450 struct genl_info *info)
12452 struct cfg80211_registered_device *rdev;
12453 struct wireless_dev *wdev;
12454 struct net_device *dev;
12455 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12460 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
12461 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
12462 if (IS_ERR(rdev)) {
12465 return PTR_ERR(rdev);
12467 info->user_ptr[0] = rdev;
12468 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12469 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12472 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12474 if (IS_ERR(wdev)) {
12477 return PTR_ERR(wdev);
12480 dev = wdev->netdev;
12481 rdev = wiphy_to_rdev(wdev->wiphy);
12483 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12490 info->user_ptr[1] = dev;
12492 info->user_ptr[1] = wdev;
12495 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12496 !wdev_running(wdev)) {
12505 info->user_ptr[0] = rdev;
12511 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
12512 struct genl_info *info)
12514 if (info->user_ptr[1]) {
12515 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12516 struct wireless_dev *wdev = info->user_ptr[1];
12519 dev_put(wdev->netdev);
12521 dev_put(info->user_ptr[1]);
12525 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12528 /* If needed, clear the netlink message payload from the SKB
12529 * as it might contain key data that shouldn't stick around on
12530 * the heap after the SKB is freed. The netlink message header
12531 * is still needed for further processing, so leave it intact.
12533 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12534 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12536 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12540 static const struct genl_ops nl80211_ops[] = {
12542 .cmd = NL80211_CMD_GET_WIPHY,
12543 .doit = nl80211_get_wiphy,
12544 .dumpit = nl80211_dump_wiphy,
12545 .done = nl80211_dump_wiphy_done,
12546 .policy = nl80211_policy,
12547 /* can be retrieved by unprivileged users */
12548 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12549 NL80211_FLAG_NEED_RTNL,
12552 .cmd = NL80211_CMD_SET_WIPHY,
12553 .doit = nl80211_set_wiphy,
12554 .policy = nl80211_policy,
12555 .flags = GENL_UNS_ADMIN_PERM,
12556 .internal_flags = NL80211_FLAG_NEED_RTNL,
12559 .cmd = NL80211_CMD_GET_INTERFACE,
12560 .doit = nl80211_get_interface,
12561 .dumpit = nl80211_dump_interface,
12562 .policy = nl80211_policy,
12563 /* can be retrieved by unprivileged users */
12564 .internal_flags = NL80211_FLAG_NEED_WDEV |
12565 NL80211_FLAG_NEED_RTNL,
12568 .cmd = NL80211_CMD_SET_INTERFACE,
12569 .doit = nl80211_set_interface,
12570 .policy = nl80211_policy,
12571 .flags = GENL_UNS_ADMIN_PERM,
12572 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12573 NL80211_FLAG_NEED_RTNL,
12576 .cmd = NL80211_CMD_NEW_INTERFACE,
12577 .doit = nl80211_new_interface,
12578 .policy = nl80211_policy,
12579 .flags = GENL_UNS_ADMIN_PERM,
12580 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12581 NL80211_FLAG_NEED_RTNL,
12584 .cmd = NL80211_CMD_DEL_INTERFACE,
12585 .doit = nl80211_del_interface,
12586 .policy = nl80211_policy,
12587 .flags = GENL_UNS_ADMIN_PERM,
12588 .internal_flags = NL80211_FLAG_NEED_WDEV |
12589 NL80211_FLAG_NEED_RTNL,
12592 .cmd = NL80211_CMD_GET_KEY,
12593 .doit = nl80211_get_key,
12594 .policy = nl80211_policy,
12595 .flags = GENL_UNS_ADMIN_PERM,
12596 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12597 NL80211_FLAG_NEED_RTNL,
12600 .cmd = NL80211_CMD_SET_KEY,
12601 .doit = nl80211_set_key,
12602 .policy = nl80211_policy,
12603 .flags = GENL_UNS_ADMIN_PERM,
12604 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12605 NL80211_FLAG_NEED_RTNL |
12606 NL80211_FLAG_CLEAR_SKB,
12609 .cmd = NL80211_CMD_NEW_KEY,
12610 .doit = nl80211_new_key,
12611 .policy = nl80211_policy,
12612 .flags = GENL_UNS_ADMIN_PERM,
12613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12614 NL80211_FLAG_NEED_RTNL |
12615 NL80211_FLAG_CLEAR_SKB,
12618 .cmd = NL80211_CMD_DEL_KEY,
12619 .doit = nl80211_del_key,
12620 .policy = nl80211_policy,
12621 .flags = GENL_UNS_ADMIN_PERM,
12622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12623 NL80211_FLAG_NEED_RTNL,
12626 .cmd = NL80211_CMD_SET_BEACON,
12627 .policy = nl80211_policy,
12628 .flags = GENL_UNS_ADMIN_PERM,
12629 .doit = nl80211_set_beacon,
12630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12631 NL80211_FLAG_NEED_RTNL,
12634 .cmd = NL80211_CMD_START_AP,
12635 .policy = nl80211_policy,
12636 .flags = GENL_UNS_ADMIN_PERM,
12637 .doit = nl80211_start_ap,
12638 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12639 NL80211_FLAG_NEED_RTNL,
12642 .cmd = NL80211_CMD_STOP_AP,
12643 .policy = nl80211_policy,
12644 .flags = GENL_UNS_ADMIN_PERM,
12645 .doit = nl80211_stop_ap,
12646 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12647 NL80211_FLAG_NEED_RTNL,
12650 .cmd = NL80211_CMD_GET_STATION,
12651 .doit = nl80211_get_station,
12652 .dumpit = nl80211_dump_station,
12653 .policy = nl80211_policy,
12654 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12655 NL80211_FLAG_NEED_RTNL,
12658 .cmd = NL80211_CMD_SET_STATION,
12659 .doit = nl80211_set_station,
12660 .policy = nl80211_policy,
12661 .flags = GENL_UNS_ADMIN_PERM,
12662 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12663 NL80211_FLAG_NEED_RTNL,
12666 .cmd = NL80211_CMD_NEW_STATION,
12667 .doit = nl80211_new_station,
12668 .policy = nl80211_policy,
12669 .flags = GENL_UNS_ADMIN_PERM,
12670 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12671 NL80211_FLAG_NEED_RTNL,
12674 .cmd = NL80211_CMD_DEL_STATION,
12675 .doit = nl80211_del_station,
12676 .policy = nl80211_policy,
12677 .flags = GENL_UNS_ADMIN_PERM,
12678 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12679 NL80211_FLAG_NEED_RTNL,
12682 .cmd = NL80211_CMD_GET_MPATH,
12683 .doit = nl80211_get_mpath,
12684 .dumpit = nl80211_dump_mpath,
12685 .policy = nl80211_policy,
12686 .flags = GENL_UNS_ADMIN_PERM,
12687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12688 NL80211_FLAG_NEED_RTNL,
12691 .cmd = NL80211_CMD_GET_MPP,
12692 .doit = nl80211_get_mpp,
12693 .dumpit = nl80211_dump_mpp,
12694 .policy = nl80211_policy,
12695 .flags = GENL_UNS_ADMIN_PERM,
12696 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12697 NL80211_FLAG_NEED_RTNL,
12700 .cmd = NL80211_CMD_SET_MPATH,
12701 .doit = nl80211_set_mpath,
12702 .policy = nl80211_policy,
12703 .flags = GENL_UNS_ADMIN_PERM,
12704 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12705 NL80211_FLAG_NEED_RTNL,
12708 .cmd = NL80211_CMD_NEW_MPATH,
12709 .doit = nl80211_new_mpath,
12710 .policy = nl80211_policy,
12711 .flags = GENL_UNS_ADMIN_PERM,
12712 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12713 NL80211_FLAG_NEED_RTNL,
12716 .cmd = NL80211_CMD_DEL_MPATH,
12717 .doit = nl80211_del_mpath,
12718 .policy = nl80211_policy,
12719 .flags = GENL_UNS_ADMIN_PERM,
12720 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12721 NL80211_FLAG_NEED_RTNL,
12724 .cmd = NL80211_CMD_SET_BSS,
12725 .doit = nl80211_set_bss,
12726 .policy = nl80211_policy,
12727 .flags = GENL_UNS_ADMIN_PERM,
12728 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12729 NL80211_FLAG_NEED_RTNL,
12732 .cmd = NL80211_CMD_GET_REG,
12733 .doit = nl80211_get_reg_do,
12734 .dumpit = nl80211_get_reg_dump,
12735 .policy = nl80211_policy,
12736 .internal_flags = NL80211_FLAG_NEED_RTNL,
12737 /* can be retrieved by unprivileged users */
12739 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
12741 .cmd = NL80211_CMD_SET_REG,
12742 .doit = nl80211_set_reg,
12743 .policy = nl80211_policy,
12744 .flags = GENL_ADMIN_PERM,
12745 .internal_flags = NL80211_FLAG_NEED_RTNL,
12749 .cmd = NL80211_CMD_REQ_SET_REG,
12750 .doit = nl80211_req_set_reg,
12751 .policy = nl80211_policy,
12752 .flags = GENL_ADMIN_PERM,
12755 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12756 .doit = nl80211_get_mesh_config,
12757 .policy = nl80211_policy,
12758 /* can be retrieved by unprivileged users */
12759 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12760 NL80211_FLAG_NEED_RTNL,
12763 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12764 .doit = nl80211_update_mesh_config,
12765 .policy = nl80211_policy,
12766 .flags = GENL_UNS_ADMIN_PERM,
12767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12768 NL80211_FLAG_NEED_RTNL,
12771 .cmd = NL80211_CMD_TRIGGER_SCAN,
12772 .doit = nl80211_trigger_scan,
12773 .policy = nl80211_policy,
12774 .flags = GENL_UNS_ADMIN_PERM,
12775 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12776 NL80211_FLAG_NEED_RTNL,
12779 .cmd = NL80211_CMD_ABORT_SCAN,
12780 .doit = nl80211_abort_scan,
12781 .policy = nl80211_policy,
12782 .flags = GENL_UNS_ADMIN_PERM,
12783 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12784 NL80211_FLAG_NEED_RTNL,
12787 .cmd = NL80211_CMD_GET_SCAN,
12788 .policy = nl80211_policy,
12789 .dumpit = nl80211_dump_scan,
12792 .cmd = NL80211_CMD_START_SCHED_SCAN,
12793 .doit = nl80211_start_sched_scan,
12794 .policy = nl80211_policy,
12795 .flags = GENL_UNS_ADMIN_PERM,
12796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12797 NL80211_FLAG_NEED_RTNL,
12800 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12801 .doit = nl80211_stop_sched_scan,
12802 .policy = nl80211_policy,
12803 .flags = GENL_UNS_ADMIN_PERM,
12804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12805 NL80211_FLAG_NEED_RTNL,
12808 .cmd = NL80211_CMD_AUTHENTICATE,
12809 .doit = nl80211_authenticate,
12810 .policy = nl80211_policy,
12811 .flags = GENL_UNS_ADMIN_PERM,
12812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12813 NL80211_FLAG_NEED_RTNL |
12814 NL80211_FLAG_CLEAR_SKB,
12817 .cmd = NL80211_CMD_ASSOCIATE,
12818 .doit = nl80211_associate,
12819 .policy = nl80211_policy,
12820 .flags = GENL_UNS_ADMIN_PERM,
12821 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12822 NL80211_FLAG_NEED_RTNL |
12823 NL80211_FLAG_CLEAR_SKB,
12826 .cmd = NL80211_CMD_DEAUTHENTICATE,
12827 .doit = nl80211_deauthenticate,
12828 .policy = nl80211_policy,
12829 .flags = GENL_UNS_ADMIN_PERM,
12830 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12831 NL80211_FLAG_NEED_RTNL,
12834 .cmd = NL80211_CMD_DISASSOCIATE,
12835 .doit = nl80211_disassociate,
12836 .policy = nl80211_policy,
12837 .flags = GENL_UNS_ADMIN_PERM,
12838 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12839 NL80211_FLAG_NEED_RTNL,
12842 .cmd = NL80211_CMD_JOIN_IBSS,
12843 .doit = nl80211_join_ibss,
12844 .policy = nl80211_policy,
12845 .flags = GENL_UNS_ADMIN_PERM,
12846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12847 NL80211_FLAG_NEED_RTNL,
12850 .cmd = NL80211_CMD_LEAVE_IBSS,
12851 .doit = nl80211_leave_ibss,
12852 .policy = nl80211_policy,
12853 .flags = GENL_UNS_ADMIN_PERM,
12854 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12855 NL80211_FLAG_NEED_RTNL,
12857 #ifdef CONFIG_NL80211_TESTMODE
12859 .cmd = NL80211_CMD_TESTMODE,
12860 .doit = nl80211_testmode_do,
12861 .dumpit = nl80211_testmode_dump,
12862 .policy = nl80211_policy,
12863 .flags = GENL_UNS_ADMIN_PERM,
12864 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12865 NL80211_FLAG_NEED_RTNL,
12869 .cmd = NL80211_CMD_CONNECT,
12870 .doit = nl80211_connect,
12871 .policy = nl80211_policy,
12872 .flags = GENL_UNS_ADMIN_PERM,
12873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12874 NL80211_FLAG_NEED_RTNL |
12875 NL80211_FLAG_CLEAR_SKB,
12878 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12879 .doit = nl80211_update_connect_params,
12880 .policy = nl80211_policy,
12881 .flags = GENL_ADMIN_PERM,
12882 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12883 NL80211_FLAG_NEED_RTNL |
12884 NL80211_FLAG_CLEAR_SKB,
12887 .cmd = NL80211_CMD_DISCONNECT,
12888 .doit = nl80211_disconnect,
12889 .policy = nl80211_policy,
12890 .flags = GENL_UNS_ADMIN_PERM,
12891 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12892 NL80211_FLAG_NEED_RTNL,
12895 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12896 .doit = nl80211_wiphy_netns,
12897 .policy = nl80211_policy,
12898 .flags = GENL_UNS_ADMIN_PERM,
12899 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12900 NL80211_FLAG_NEED_RTNL,
12903 .cmd = NL80211_CMD_GET_SURVEY,
12904 .policy = nl80211_policy,
12905 .dumpit = nl80211_dump_survey,
12908 .cmd = NL80211_CMD_SET_PMKSA,
12909 .doit = nl80211_setdel_pmksa,
12910 .policy = nl80211_policy,
12911 .flags = GENL_UNS_ADMIN_PERM,
12912 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12913 NL80211_FLAG_NEED_RTNL |
12914 NL80211_FLAG_CLEAR_SKB,
12917 .cmd = NL80211_CMD_DEL_PMKSA,
12918 .doit = nl80211_setdel_pmksa,
12919 .policy = nl80211_policy,
12920 .flags = GENL_UNS_ADMIN_PERM,
12921 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12922 NL80211_FLAG_NEED_RTNL,
12925 .cmd = NL80211_CMD_FLUSH_PMKSA,
12926 .doit = nl80211_flush_pmksa,
12927 .policy = nl80211_policy,
12928 .flags = GENL_UNS_ADMIN_PERM,
12929 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12930 NL80211_FLAG_NEED_RTNL,
12933 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12934 .doit = nl80211_remain_on_channel,
12935 .policy = nl80211_policy,
12936 .flags = GENL_UNS_ADMIN_PERM,
12937 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12938 NL80211_FLAG_NEED_RTNL,
12941 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12942 .doit = nl80211_cancel_remain_on_channel,
12943 .policy = nl80211_policy,
12944 .flags = GENL_UNS_ADMIN_PERM,
12945 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12946 NL80211_FLAG_NEED_RTNL,
12949 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12950 .doit = nl80211_set_tx_bitrate_mask,
12951 .policy = nl80211_policy,
12952 .flags = GENL_UNS_ADMIN_PERM,
12953 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12954 NL80211_FLAG_NEED_RTNL,
12957 .cmd = NL80211_CMD_REGISTER_FRAME,
12958 .doit = nl80211_register_mgmt,
12959 .policy = nl80211_policy,
12960 .flags = GENL_UNS_ADMIN_PERM,
12961 .internal_flags = NL80211_FLAG_NEED_WDEV |
12962 NL80211_FLAG_NEED_RTNL,
12965 .cmd = NL80211_CMD_FRAME,
12966 .doit = nl80211_tx_mgmt,
12967 .policy = nl80211_policy,
12968 .flags = GENL_UNS_ADMIN_PERM,
12969 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12970 NL80211_FLAG_NEED_RTNL,
12973 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12974 .doit = nl80211_tx_mgmt_cancel_wait,
12975 .policy = nl80211_policy,
12976 .flags = GENL_UNS_ADMIN_PERM,
12977 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12978 NL80211_FLAG_NEED_RTNL,
12981 .cmd = NL80211_CMD_SET_POWER_SAVE,
12982 .doit = nl80211_set_power_save,
12983 .policy = nl80211_policy,
12984 .flags = GENL_UNS_ADMIN_PERM,
12985 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12986 NL80211_FLAG_NEED_RTNL,
12989 .cmd = NL80211_CMD_GET_POWER_SAVE,
12990 .doit = nl80211_get_power_save,
12991 .policy = nl80211_policy,
12992 /* can be retrieved by unprivileged users */
12993 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12994 NL80211_FLAG_NEED_RTNL,
12997 .cmd = NL80211_CMD_SET_CQM,
12998 .doit = nl80211_set_cqm,
12999 .policy = nl80211_policy,
13000 .flags = GENL_UNS_ADMIN_PERM,
13001 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13002 NL80211_FLAG_NEED_RTNL,
13005 .cmd = NL80211_CMD_SET_CHANNEL,
13006 .doit = nl80211_set_channel,
13007 .policy = nl80211_policy,
13008 .flags = GENL_UNS_ADMIN_PERM,
13009 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13010 NL80211_FLAG_NEED_RTNL,
13013 .cmd = NL80211_CMD_SET_WDS_PEER,
13014 .doit = nl80211_set_wds_peer,
13015 .policy = nl80211_policy,
13016 .flags = GENL_UNS_ADMIN_PERM,
13017 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13018 NL80211_FLAG_NEED_RTNL,
13021 .cmd = NL80211_CMD_JOIN_MESH,
13022 .doit = nl80211_join_mesh,
13023 .policy = nl80211_policy,
13024 .flags = GENL_UNS_ADMIN_PERM,
13025 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13026 NL80211_FLAG_NEED_RTNL,
13029 .cmd = NL80211_CMD_LEAVE_MESH,
13030 .doit = nl80211_leave_mesh,
13031 .policy = nl80211_policy,
13032 .flags = GENL_UNS_ADMIN_PERM,
13033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13034 NL80211_FLAG_NEED_RTNL,
13037 .cmd = NL80211_CMD_JOIN_OCB,
13038 .doit = nl80211_join_ocb,
13039 .policy = nl80211_policy,
13040 .flags = GENL_UNS_ADMIN_PERM,
13041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13042 NL80211_FLAG_NEED_RTNL,
13045 .cmd = NL80211_CMD_LEAVE_OCB,
13046 .doit = nl80211_leave_ocb,
13047 .policy = nl80211_policy,
13048 .flags = GENL_UNS_ADMIN_PERM,
13049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13050 NL80211_FLAG_NEED_RTNL,
13054 .cmd = NL80211_CMD_GET_WOWLAN,
13055 .doit = nl80211_get_wowlan,
13056 .policy = nl80211_policy,
13057 /* can be retrieved by unprivileged users */
13058 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13059 NL80211_FLAG_NEED_RTNL,
13062 .cmd = NL80211_CMD_SET_WOWLAN,
13063 .doit = nl80211_set_wowlan,
13064 .policy = nl80211_policy,
13065 .flags = GENL_UNS_ADMIN_PERM,
13066 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13067 NL80211_FLAG_NEED_RTNL,
13071 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
13072 .doit = nl80211_set_rekey_data,
13073 .policy = nl80211_policy,
13074 .flags = GENL_UNS_ADMIN_PERM,
13075 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13076 NL80211_FLAG_NEED_RTNL |
13077 NL80211_FLAG_CLEAR_SKB,
13080 .cmd = NL80211_CMD_TDLS_MGMT,
13081 .doit = nl80211_tdls_mgmt,
13082 .policy = nl80211_policy,
13083 .flags = GENL_UNS_ADMIN_PERM,
13084 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13085 NL80211_FLAG_NEED_RTNL,
13088 .cmd = NL80211_CMD_TDLS_OPER,
13089 .doit = nl80211_tdls_oper,
13090 .policy = nl80211_policy,
13091 .flags = GENL_UNS_ADMIN_PERM,
13092 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13093 NL80211_FLAG_NEED_RTNL,
13096 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
13097 .doit = nl80211_register_unexpected_frame,
13098 .policy = nl80211_policy,
13099 .flags = GENL_UNS_ADMIN_PERM,
13100 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13101 NL80211_FLAG_NEED_RTNL,
13104 .cmd = NL80211_CMD_PROBE_CLIENT,
13105 .doit = nl80211_probe_client,
13106 .policy = nl80211_policy,
13107 .flags = GENL_UNS_ADMIN_PERM,
13108 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13109 NL80211_FLAG_NEED_RTNL,
13112 .cmd = NL80211_CMD_REGISTER_BEACONS,
13113 .doit = nl80211_register_beacons,
13114 .policy = nl80211_policy,
13115 .flags = GENL_UNS_ADMIN_PERM,
13116 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13117 NL80211_FLAG_NEED_RTNL,
13120 .cmd = NL80211_CMD_SET_NOACK_MAP,
13121 .doit = nl80211_set_noack_map,
13122 .policy = nl80211_policy,
13123 .flags = GENL_UNS_ADMIN_PERM,
13124 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13125 NL80211_FLAG_NEED_RTNL,
13128 .cmd = NL80211_CMD_START_P2P_DEVICE,
13129 .doit = nl80211_start_p2p_device,
13130 .policy = nl80211_policy,
13131 .flags = GENL_UNS_ADMIN_PERM,
13132 .internal_flags = NL80211_FLAG_NEED_WDEV |
13133 NL80211_FLAG_NEED_RTNL,
13136 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
13137 .doit = nl80211_stop_p2p_device,
13138 .policy = nl80211_policy,
13139 .flags = GENL_UNS_ADMIN_PERM,
13140 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13141 NL80211_FLAG_NEED_RTNL,
13144 .cmd = NL80211_CMD_START_NAN,
13145 .doit = nl80211_start_nan,
13146 .policy = nl80211_policy,
13147 .flags = GENL_ADMIN_PERM,
13148 .internal_flags = NL80211_FLAG_NEED_WDEV |
13149 NL80211_FLAG_NEED_RTNL,
13152 .cmd = NL80211_CMD_STOP_NAN,
13153 .doit = nl80211_stop_nan,
13154 .policy = nl80211_policy,
13155 .flags = GENL_ADMIN_PERM,
13156 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13157 NL80211_FLAG_NEED_RTNL,
13160 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
13161 .doit = nl80211_nan_add_func,
13162 .policy = nl80211_policy,
13163 .flags = GENL_ADMIN_PERM,
13164 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13165 NL80211_FLAG_NEED_RTNL,
13168 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
13169 .doit = nl80211_nan_del_func,
13170 .policy = nl80211_policy,
13171 .flags = GENL_ADMIN_PERM,
13172 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13173 NL80211_FLAG_NEED_RTNL,
13176 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
13177 .doit = nl80211_nan_change_config,
13178 .policy = nl80211_policy,
13179 .flags = GENL_ADMIN_PERM,
13180 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13181 NL80211_FLAG_NEED_RTNL,
13184 .cmd = NL80211_CMD_SET_MCAST_RATE,
13185 .doit = nl80211_set_mcast_rate,
13186 .policy = nl80211_policy,
13187 .flags = GENL_UNS_ADMIN_PERM,
13188 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13189 NL80211_FLAG_NEED_RTNL,
13192 .cmd = NL80211_CMD_SET_MAC_ACL,
13193 .doit = nl80211_set_mac_acl,
13194 .policy = nl80211_policy,
13195 .flags = GENL_UNS_ADMIN_PERM,
13196 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13197 NL80211_FLAG_NEED_RTNL,
13200 .cmd = NL80211_CMD_RADAR_DETECT,
13201 .doit = nl80211_start_radar_detection,
13202 .policy = nl80211_policy,
13203 .flags = GENL_UNS_ADMIN_PERM,
13204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13205 NL80211_FLAG_NEED_RTNL,
13208 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
13209 .doit = nl80211_get_protocol_features,
13210 .policy = nl80211_policy,
13213 .cmd = NL80211_CMD_UPDATE_FT_IES,
13214 .doit = nl80211_update_ft_ies,
13215 .policy = nl80211_policy,
13216 .flags = GENL_UNS_ADMIN_PERM,
13217 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13218 NL80211_FLAG_NEED_RTNL,
13221 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
13222 .doit = nl80211_crit_protocol_start,
13223 .policy = nl80211_policy,
13224 .flags = GENL_UNS_ADMIN_PERM,
13225 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13226 NL80211_FLAG_NEED_RTNL,
13229 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
13230 .doit = nl80211_crit_protocol_stop,
13231 .policy = nl80211_policy,
13232 .flags = GENL_UNS_ADMIN_PERM,
13233 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13234 NL80211_FLAG_NEED_RTNL,
13237 .cmd = NL80211_CMD_GET_COALESCE,
13238 .doit = nl80211_get_coalesce,
13239 .policy = nl80211_policy,
13240 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13241 NL80211_FLAG_NEED_RTNL,
13244 .cmd = NL80211_CMD_SET_COALESCE,
13245 .doit = nl80211_set_coalesce,
13246 .policy = nl80211_policy,
13247 .flags = GENL_UNS_ADMIN_PERM,
13248 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13249 NL80211_FLAG_NEED_RTNL,
13252 .cmd = NL80211_CMD_CHANNEL_SWITCH,
13253 .doit = nl80211_channel_switch,
13254 .policy = nl80211_policy,
13255 .flags = GENL_UNS_ADMIN_PERM,
13256 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13257 NL80211_FLAG_NEED_RTNL,
13260 .cmd = NL80211_CMD_VENDOR,
13261 .doit = nl80211_vendor_cmd,
13262 .dumpit = nl80211_vendor_cmd_dump,
13263 .policy = nl80211_policy,
13264 .flags = GENL_UNS_ADMIN_PERM,
13265 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13266 NL80211_FLAG_NEED_RTNL |
13267 NL80211_FLAG_CLEAR_SKB,
13270 .cmd = NL80211_CMD_SET_QOS_MAP,
13271 .doit = nl80211_set_qos_map,
13272 .policy = nl80211_policy,
13273 .flags = GENL_UNS_ADMIN_PERM,
13274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13275 NL80211_FLAG_NEED_RTNL,
13278 .cmd = NL80211_CMD_ADD_TX_TS,
13279 .doit = nl80211_add_tx_ts,
13280 .policy = nl80211_policy,
13281 .flags = GENL_UNS_ADMIN_PERM,
13282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13283 NL80211_FLAG_NEED_RTNL,
13286 .cmd = NL80211_CMD_DEL_TX_TS,
13287 .doit = nl80211_del_tx_ts,
13288 .policy = nl80211_policy,
13289 .flags = GENL_UNS_ADMIN_PERM,
13290 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13291 NL80211_FLAG_NEED_RTNL,
13294 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
13295 .doit = nl80211_tdls_channel_switch,
13296 .policy = nl80211_policy,
13297 .flags = GENL_UNS_ADMIN_PERM,
13298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13299 NL80211_FLAG_NEED_RTNL,
13302 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
13303 .doit = nl80211_tdls_cancel_channel_switch,
13304 .policy = nl80211_policy,
13305 .flags = GENL_UNS_ADMIN_PERM,
13306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13307 NL80211_FLAG_NEED_RTNL,
13310 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
13311 .doit = nl80211_set_multicast_to_unicast,
13312 .policy = nl80211_policy,
13313 .flags = GENL_UNS_ADMIN_PERM,
13314 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13315 NL80211_FLAG_NEED_RTNL,
13318 .cmd = NL80211_CMD_SET_PMK,
13319 .doit = nl80211_set_pmk,
13320 .policy = nl80211_policy,
13321 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13322 NL80211_FLAG_NEED_RTNL |
13323 NL80211_FLAG_CLEAR_SKB,
13326 .cmd = NL80211_CMD_DEL_PMK,
13327 .doit = nl80211_del_pmk,
13328 .policy = nl80211_policy,
13329 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13330 NL80211_FLAG_NEED_RTNL,
13335 static struct genl_family nl80211_fam __ro_after_init = {
13336 .name = NL80211_GENL_NAME, /* have users key off the name instead */
13337 .hdrsize = 0, /* no private header */
13338 .version = 1, /* no particular meaning now */
13339 .maxattr = NL80211_ATTR_MAX,
13341 .pre_doit = nl80211_pre_doit,
13342 .post_doit = nl80211_post_doit,
13343 .module = THIS_MODULE,
13344 .ops = nl80211_ops,
13345 .n_ops = ARRAY_SIZE(nl80211_ops),
13346 .mcgrps = nl80211_mcgrps,
13347 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
13350 /* notification functions */
13352 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
13353 enum nl80211_commands cmd)
13355 struct sk_buff *msg;
13356 struct nl80211_dump_wiphy_state state = {};
13358 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13359 cmd != NL80211_CMD_DEL_WIPHY);
13361 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13365 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
13370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13371 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13374 void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13375 struct wireless_dev *wdev,
13376 enum nl80211_commands cmd)
13378 struct sk_buff *msg;
13380 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13381 cmd != NL80211_CMD_DEL_INTERFACE);
13383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13387 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13388 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13393 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13394 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13397 static int nl80211_add_scan_req(struct sk_buff *msg,
13398 struct cfg80211_registered_device *rdev)
13400 struct cfg80211_scan_request *req = rdev->scan_req;
13401 struct nlattr *nest;
13407 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13409 goto nla_put_failure;
13410 for (i = 0; i < req->n_ssids; i++) {
13411 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13412 goto nla_put_failure;
13414 nla_nest_end(msg, nest);
13416 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13418 goto nla_put_failure;
13419 for (i = 0; i < req->n_channels; i++) {
13420 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13421 goto nla_put_failure;
13423 nla_nest_end(msg, nest);
13426 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13427 goto nla_put_failure;
13430 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13431 goto nla_put_failure;
13433 if (req->info.scan_start_tsf &&
13434 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13435 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13436 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13437 req->info.tsf_bssid)))
13438 goto nla_put_failure;
13445 static int nl80211_prep_scan_msg(struct sk_buff *msg,
13446 struct cfg80211_registered_device *rdev,
13447 struct wireless_dev *wdev,
13448 u32 portid, u32 seq, int flags,
13453 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
13457 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13458 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13459 wdev->netdev->ifindex)) ||
13460 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13462 goto nla_put_failure;
13464 /* ignore errors and send incomplete event anyway */
13465 nl80211_add_scan_req(msg, rdev);
13467 genlmsg_end(msg, hdr);
13471 genlmsg_cancel(msg, hdr);
13476 nl80211_prep_sched_scan_msg(struct sk_buff *msg,
13477 struct cfg80211_sched_scan_request *req, u32 cmd)
13481 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
13486 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
13487 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
13488 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
13490 goto nla_put_failure;
13492 genlmsg_end(msg, hdr);
13496 genlmsg_cancel(msg, hdr);
13500 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
13501 struct wireless_dev *wdev)
13503 struct sk_buff *msg;
13505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13509 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
13510 NL80211_CMD_TRIGGER_SCAN) < 0) {
13515 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13516 NL80211_MCGRP_SCAN, GFP_KERNEL);
13519 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13520 struct wireless_dev *wdev, bool aborted)
13522 struct sk_buff *msg;
13524 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13528 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
13529 aborted ? NL80211_CMD_SCAN_ABORTED :
13530 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
13538 /* send message created by nl80211_build_scan_msg() */
13539 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
13540 struct sk_buff *msg)
13545 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13546 NL80211_MCGRP_SCAN, GFP_KERNEL);
13549 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
13551 struct sk_buff *msg;
13553 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13557 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
13562 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
13563 NL80211_MCGRP_SCAN, GFP_KERNEL);
13566 static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13567 struct regulatory_request *request)
13569 /* Userspace can always count this one always being set */
13570 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13571 goto nla_put_failure;
13573 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13574 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13575 NL80211_REGDOM_TYPE_WORLD))
13576 goto nla_put_failure;
13577 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13578 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13579 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13580 goto nla_put_failure;
13581 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13582 request->intersect) {
13583 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13584 NL80211_REGDOM_TYPE_INTERSECTION))
13585 goto nla_put_failure;
13587 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13588 NL80211_REGDOM_TYPE_COUNTRY) ||
13589 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13591 goto nla_put_failure;
13594 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13595 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13598 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13599 goto nla_put_failure;
13602 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13603 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13604 goto nla_put_failure;
13614 * This can happen on global regulatory changes or device specific settings
13615 * based on custom regulatory domains.
13617 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13618 struct regulatory_request *request)
13620 struct sk_buff *msg;
13623 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13627 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13633 if (nl80211_reg_change_event_fill(msg, request) == false)
13634 goto nla_put_failure;
13636 genlmsg_end(msg, hdr);
13639 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
13640 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
13646 genlmsg_cancel(msg, hdr);
13650 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13651 struct net_device *netdev,
13652 const u8 *buf, size_t len,
13653 enum nl80211_commands cmd, gfp_t gfp,
13656 struct sk_buff *msg;
13659 msg = nlmsg_new(100 + len, gfp);
13663 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13669 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13670 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13671 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13672 goto nla_put_failure;
13674 if (uapsd_queues >= 0) {
13675 struct nlattr *nla_wmm =
13676 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13678 goto nla_put_failure;
13680 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13682 goto nla_put_failure;
13684 nla_nest_end(msg, nla_wmm);
13687 genlmsg_end(msg, hdr);
13689 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13690 NL80211_MCGRP_MLME, gfp);
13694 genlmsg_cancel(msg, hdr);
13698 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
13699 struct net_device *netdev, const u8 *buf,
13700 size_t len, gfp_t gfp)
13702 nl80211_send_mlme_event(rdev, netdev, buf, len,
13703 NL80211_CMD_AUTHENTICATE, gfp, -1);
13706 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13707 struct net_device *netdev, const u8 *buf,
13708 size_t len, gfp_t gfp, int uapsd_queues)
13710 nl80211_send_mlme_event(rdev, netdev, buf, len,
13711 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
13714 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
13715 struct net_device *netdev, const u8 *buf,
13716 size_t len, gfp_t gfp)
13718 nl80211_send_mlme_event(rdev, netdev, buf, len,
13719 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
13722 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13723 struct net_device *netdev, const u8 *buf,
13724 size_t len, gfp_t gfp)
13726 nl80211_send_mlme_event(rdev, netdev, buf, len,
13727 NL80211_CMD_DISASSOCIATE, gfp, -1);
13730 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13733 struct wireless_dev *wdev = dev->ieee80211_ptr;
13734 struct wiphy *wiphy = wdev->wiphy;
13735 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13736 const struct ieee80211_mgmt *mgmt = (void *)buf;
13739 if (WARN_ON(len < 2))
13742 if (ieee80211_is_deauth(mgmt->frame_control))
13743 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13745 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13747 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
13748 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
13750 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
13752 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13753 struct net_device *netdev, int cmd,
13754 const u8 *addr, gfp_t gfp)
13756 struct sk_buff *msg;
13759 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13763 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13769 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13770 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13771 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13772 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13773 goto nla_put_failure;
13775 genlmsg_end(msg, hdr);
13777 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13778 NL80211_MCGRP_MLME, gfp);
13782 genlmsg_cancel(msg, hdr);
13786 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
13787 struct net_device *netdev, const u8 *addr,
13790 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
13794 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
13795 struct net_device *netdev, const u8 *addr,
13798 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13802 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
13803 struct net_device *netdev,
13804 struct cfg80211_connect_resp_params *cr,
13807 struct sk_buff *msg;
13810 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13811 cr->fils_kek_len + cr->pmk_len +
13812 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
13816 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13822 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13823 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13825 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
13826 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
13827 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13830 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13831 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13832 cr->timeout_reason))) ||
13834 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13836 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
13838 (cr->update_erp_next_seq_num &&
13839 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13840 cr->fils_erp_next_seq_num)) ||
13841 (cr->status == WLAN_STATUS_SUCCESS &&
13843 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13846 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13848 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
13849 goto nla_put_failure;
13851 genlmsg_end(msg, hdr);
13853 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13854 NL80211_MCGRP_MLME, gfp);
13858 genlmsg_cancel(msg, hdr);
13862 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
13863 struct net_device *netdev,
13864 struct cfg80211_roam_info *info, gfp_t gfp)
13866 struct sk_buff *msg;
13868 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
13870 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
13874 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13880 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13881 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13882 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
13884 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13887 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
13889 (info->authorized &&
13890 nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED)))
13891 goto nla_put_failure;
13893 genlmsg_end(msg, hdr);
13895 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13896 NL80211_MCGRP_MLME, gfp);
13900 genlmsg_cancel(msg, hdr);
13904 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13905 struct net_device *netdev, u16 reason,
13906 const u8 *ie, size_t ie_len, bool from_ap)
13908 struct sk_buff *msg;
13911 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
13915 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13921 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13922 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13923 (from_ap && reason &&
13924 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13926 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13927 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13928 goto nla_put_failure;
13930 genlmsg_end(msg, hdr);
13932 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13933 NL80211_MCGRP_MLME, GFP_KERNEL);
13937 genlmsg_cancel(msg, hdr);
13941 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13942 struct net_device *netdev, const u8 *bssid,
13945 struct sk_buff *msg;
13948 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13952 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13958 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13959 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13960 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13961 goto nla_put_failure;
13963 genlmsg_end(msg, hdr);
13965 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13966 NL80211_MCGRP_MLME, gfp);
13970 genlmsg_cancel(msg, hdr);
13974 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13975 const u8* ie, u8 ie_len, gfp_t gfp)
13977 struct wireless_dev *wdev = dev->ieee80211_ptr;
13978 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
13979 struct sk_buff *msg;
13982 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13985 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13987 msg = nlmsg_new(100 + ie_len, gfp);
13991 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13997 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13998 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13999 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
14001 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
14002 goto nla_put_failure;
14004 genlmsg_end(msg, hdr);
14006 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14007 NL80211_MCGRP_MLME, gfp);
14011 genlmsg_cancel(msg, hdr);
14014 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
14016 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
14017 struct net_device *netdev, const u8 *addr,
14018 enum nl80211_key_type key_type, int key_id,
14019 const u8 *tsc, gfp_t gfp)
14021 struct sk_buff *msg;
14024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14028 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
14034 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14035 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14036 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
14037 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
14039 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
14040 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
14041 goto nla_put_failure;
14043 genlmsg_end(msg, hdr);
14045 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14046 NL80211_MCGRP_MLME, gfp);
14050 genlmsg_cancel(msg, hdr);
14054 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14055 struct ieee80211_channel *channel_before,
14056 struct ieee80211_channel *channel_after)
14058 struct sk_buff *msg;
14060 struct nlattr *nl_freq;
14062 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
14066 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
14073 * Since we are applying the beacon hint to a wiphy we know its
14074 * wiphy_idx is valid
14076 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
14077 goto nla_put_failure;
14080 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
14082 goto nla_put_failure;
14083 if (nl80211_msg_put_channel(msg, channel_before, false))
14084 goto nla_put_failure;
14085 nla_nest_end(msg, nl_freq);
14088 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
14090 goto nla_put_failure;
14091 if (nl80211_msg_put_channel(msg, channel_after, false))
14092 goto nla_put_failure;
14093 nla_nest_end(msg, nl_freq);
14095 genlmsg_end(msg, hdr);
14098 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
14099 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
14105 genlmsg_cancel(msg, hdr);
14109 static void nl80211_send_remain_on_chan_event(
14110 int cmd, struct cfg80211_registered_device *rdev,
14111 struct wireless_dev *wdev, u64 cookie,
14112 struct ieee80211_channel *chan,
14113 unsigned int duration, gfp_t gfp)
14115 struct sk_buff *msg;
14118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14122 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14129 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14130 wdev->netdev->ifindex)) ||
14131 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14132 NL80211_ATTR_PAD) ||
14133 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
14134 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
14135 NL80211_CHAN_NO_HT) ||
14136 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14138 goto nla_put_failure;
14140 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
14141 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
14142 goto nla_put_failure;
14144 genlmsg_end(msg, hdr);
14146 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14147 NL80211_MCGRP_MLME, gfp);
14151 genlmsg_cancel(msg, hdr);
14155 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
14156 struct ieee80211_channel *chan,
14157 unsigned int duration, gfp_t gfp)
14159 struct wiphy *wiphy = wdev->wiphy;
14160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14162 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
14163 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
14164 rdev, wdev, cookie, chan,
14167 EXPORT_SYMBOL(cfg80211_ready_on_channel);
14169 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
14170 struct ieee80211_channel *chan,
14173 struct wiphy *wiphy = wdev->wiphy;
14174 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14176 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
14177 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
14178 rdev, wdev, cookie, chan, 0, gfp);
14180 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
14182 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
14183 struct station_info *sinfo, gfp_t gfp)
14185 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
14186 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14187 struct sk_buff *msg;
14189 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
14191 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14195 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
14196 rdev, dev, mac_addr, sinfo) < 0) {
14201 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14202 NL80211_MCGRP_MLME, gfp);
14204 EXPORT_SYMBOL(cfg80211_new_sta);
14206 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
14207 struct station_info *sinfo, gfp_t gfp)
14209 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
14210 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14211 struct sk_buff *msg;
14212 struct station_info empty_sinfo = {};
14215 sinfo = &empty_sinfo;
14217 trace_cfg80211_del_sta(dev, mac_addr);
14219 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14223 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
14224 rdev, dev, mac_addr, sinfo) < 0) {
14229 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14230 NL80211_MCGRP_MLME, gfp);
14232 EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
14234 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
14235 enum nl80211_connect_failed_reason reason,
14238 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
14239 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14240 struct sk_buff *msg;
14243 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
14247 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
14253 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14254 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
14255 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
14256 goto nla_put_failure;
14258 genlmsg_end(msg, hdr);
14260 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14261 NL80211_MCGRP_MLME, gfp);
14265 genlmsg_cancel(msg, hdr);
14268 EXPORT_SYMBOL(cfg80211_conn_failed);
14270 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
14271 const u8 *addr, gfp_t gfp)
14273 struct wireless_dev *wdev = dev->ieee80211_ptr;
14274 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14275 struct sk_buff *msg;
14277 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
14282 msg = nlmsg_new(100, gfp);
14286 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
14292 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14293 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14294 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
14295 goto nla_put_failure;
14297 genlmsg_end(msg, hdr);
14298 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14302 genlmsg_cancel(msg, hdr);
14307 bool cfg80211_rx_spurious_frame(struct net_device *dev,
14308 const u8 *addr, gfp_t gfp)
14310 struct wireless_dev *wdev = dev->ieee80211_ptr;
14313 trace_cfg80211_rx_spurious_frame(dev, addr);
14315 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14316 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
14317 trace_cfg80211_return_bool(false);
14320 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
14322 trace_cfg80211_return_bool(ret);
14325 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
14327 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
14328 const u8 *addr, gfp_t gfp)
14330 struct wireless_dev *wdev = dev->ieee80211_ptr;
14333 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
14335 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
14336 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
14337 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
14338 trace_cfg80211_return_bool(false);
14341 ret = __nl80211_unexpected_frame(dev,
14342 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14344 trace_cfg80211_return_bool(ret);
14347 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
14349 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
14350 struct wireless_dev *wdev, u32 nlportid,
14351 int freq, int sig_dbm,
14352 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
14354 struct net_device *netdev = wdev->netdev;
14355 struct sk_buff *msg;
14358 msg = nlmsg_new(100 + len, gfp);
14362 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14368 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14369 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14370 netdev->ifindex)) ||
14371 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14372 NL80211_ATTR_PAD) ||
14373 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14375 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14376 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14378 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
14379 goto nla_put_failure;
14381 genlmsg_end(msg, hdr);
14383 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14386 genlmsg_cancel(msg, hdr);
14391 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14392 const u8 *buf, size_t len, bool ack, gfp_t gfp)
14394 struct wiphy *wiphy = wdev->wiphy;
14395 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14396 struct net_device *netdev = wdev->netdev;
14397 struct sk_buff *msg;
14400 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14402 msg = nlmsg_new(100 + len, gfp);
14406 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
14412 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14413 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14414 netdev->ifindex)) ||
14415 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14416 NL80211_ATTR_PAD) ||
14417 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14418 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14419 NL80211_ATTR_PAD) ||
14420 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14421 goto nla_put_failure;
14423 genlmsg_end(msg, hdr);
14425 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14426 NL80211_MCGRP_MLME, gfp);
14430 genlmsg_cancel(msg, hdr);
14433 EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
14435 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14436 const char *mac, gfp_t gfp)
14438 struct wireless_dev *wdev = dev->ieee80211_ptr;
14439 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14440 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14446 cb = (void **)msg->cb;
14448 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14454 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14455 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
14456 goto nla_put_failure;
14458 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
14459 goto nla_put_failure;
14461 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14463 goto nla_put_failure;
14473 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14475 void **cb = (void **)msg->cb;
14476 struct cfg80211_registered_device *rdev = cb[2];
14478 nla_nest_end(msg, cb[1]);
14479 genlmsg_end(msg, cb[0]);
14481 memset(msg->cb, 0, sizeof(msg->cb));
14483 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14484 NL80211_MCGRP_MLME, gfp);
14487 void cfg80211_cqm_rssi_notify(struct net_device *dev,
14488 enum nl80211_cqm_rssi_threshold_event rssi_event,
14489 s32 rssi_level, gfp_t gfp)
14491 struct sk_buff *msg;
14492 struct wireless_dev *wdev = dev->ieee80211_ptr;
14493 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14495 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
14497 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14498 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14501 if (wdev->cqm_config) {
14502 wdev->cqm_config->last_rssi_event_value = rssi_level;
14504 cfg80211_cqm_rssi_update(rdev, dev);
14506 if (rssi_level == 0)
14507 rssi_level = wdev->cqm_config->last_rssi_event_value;
14510 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14514 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14516 goto nla_put_failure;
14518 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
14520 goto nla_put_failure;
14522 cfg80211_send_cqm(msg, gfp);
14529 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
14531 void cfg80211_cqm_txe_notify(struct net_device *dev,
14532 const u8 *peer, u32 num_packets,
14533 u32 rate, u32 intvl, gfp_t gfp)
14535 struct sk_buff *msg;
14537 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14541 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14542 goto nla_put_failure;
14544 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14545 goto nla_put_failure;
14547 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14548 goto nla_put_failure;
14550 cfg80211_send_cqm(msg, gfp);
14556 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14558 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14559 const u8 *peer, u32 num_packets, gfp_t gfp)
14561 struct sk_buff *msg;
14563 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14565 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14569 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14570 goto nla_put_failure;
14572 cfg80211_send_cqm(msg, gfp);
14578 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14580 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14582 struct sk_buff *msg;
14584 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14588 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14589 goto nla_put_failure;
14591 cfg80211_send_cqm(msg, gfp);
14597 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14599 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14600 struct net_device *netdev, const u8 *bssid,
14601 const u8 *replay_ctr, gfp_t gfp)
14603 struct sk_buff *msg;
14604 struct nlattr *rekey_attr;
14607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14617 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14618 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14619 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14620 goto nla_put_failure;
14622 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14624 goto nla_put_failure;
14626 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14627 NL80211_REPLAY_CTR_LEN, replay_ctr))
14628 goto nla_put_failure;
14630 nla_nest_end(msg, rekey_attr);
14632 genlmsg_end(msg, hdr);
14634 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14635 NL80211_MCGRP_MLME, gfp);
14639 genlmsg_cancel(msg, hdr);
14643 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14644 const u8 *replay_ctr, gfp_t gfp)
14646 struct wireless_dev *wdev = dev->ieee80211_ptr;
14647 struct wiphy *wiphy = wdev->wiphy;
14648 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14650 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14651 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14653 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14656 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14657 struct net_device *netdev, int index,
14658 const u8 *bssid, bool preauth, gfp_t gfp)
14660 struct sk_buff *msg;
14661 struct nlattr *attr;
14664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14668 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14674 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14676 goto nla_put_failure;
14678 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14680 goto nla_put_failure;
14682 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14683 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14685 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14686 goto nla_put_failure;
14688 nla_nest_end(msg, attr);
14690 genlmsg_end(msg, hdr);
14692 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14693 NL80211_MCGRP_MLME, gfp);
14697 genlmsg_cancel(msg, hdr);
14701 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14702 const u8 *bssid, bool preauth, gfp_t gfp)
14704 struct wireless_dev *wdev = dev->ieee80211_ptr;
14705 struct wiphy *wiphy = wdev->wiphy;
14706 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14708 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14709 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14711 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14713 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14714 struct net_device *netdev,
14715 struct cfg80211_chan_def *chandef,
14717 enum nl80211_commands notif,
14720 struct sk_buff *msg;
14723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14727 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
14733 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14734 goto nla_put_failure;
14736 if (nl80211_send_chandef(msg, chandef))
14737 goto nla_put_failure;
14739 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14740 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14741 goto nla_put_failure;
14743 genlmsg_end(msg, hdr);
14745 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14746 NL80211_MCGRP_MLME, gfp);
14750 genlmsg_cancel(msg, hdr);
14754 void cfg80211_ch_switch_notify(struct net_device *dev,
14755 struct cfg80211_chan_def *chandef)
14757 struct wireless_dev *wdev = dev->ieee80211_ptr;
14758 struct wiphy *wiphy = wdev->wiphy;
14759 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14761 ASSERT_WDEV_LOCK(wdev);
14763 trace_cfg80211_ch_switch_notify(dev, chandef);
14765 wdev->chandef = *chandef;
14766 wdev->preset_chandef = *chandef;
14768 if (wdev->iftype == NL80211_IFTYPE_STATION &&
14769 !WARN_ON(!wdev->current_bss))
14770 wdev->current_bss->pub.channel = chandef->chan;
14772 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14773 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
14775 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14777 void cfg80211_ch_switch_started_notify(struct net_device *dev,
14778 struct cfg80211_chan_def *chandef,
14781 struct wireless_dev *wdev = dev->ieee80211_ptr;
14782 struct wiphy *wiphy = wdev->wiphy;
14783 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14785 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14787 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14788 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14790 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14793 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
14794 const struct cfg80211_chan_def *chandef,
14795 enum nl80211_radar_event event,
14796 struct net_device *netdev, gfp_t gfp)
14798 struct sk_buff *msg;
14801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14805 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14812 goto nla_put_failure;
14814 /* NOP and radar events don't need a netdev parameter */
14816 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14818 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14819 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14821 goto nla_put_failure;
14824 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14825 goto nla_put_failure;
14827 if (nl80211_send_chandef(msg, chandef))
14828 goto nla_put_failure;
14830 genlmsg_end(msg, hdr);
14832 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14833 NL80211_MCGRP_MLME, gfp);
14837 genlmsg_cancel(msg, hdr);
14841 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14842 u64 cookie, bool acked, gfp_t gfp)
14844 struct wireless_dev *wdev = dev->ieee80211_ptr;
14845 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14846 struct sk_buff *msg;
14849 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14856 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14862 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14863 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14864 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
14865 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14866 NL80211_ATTR_PAD) ||
14867 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14868 goto nla_put_failure;
14870 genlmsg_end(msg, hdr);
14872 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14873 NL80211_MCGRP_MLME, gfp);
14877 genlmsg_cancel(msg, hdr);
14880 EXPORT_SYMBOL(cfg80211_probe_status);
14882 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14883 const u8 *frame, size_t len,
14884 int freq, int sig_dbm)
14886 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14887 struct sk_buff *msg;
14889 struct cfg80211_beacon_registration *reg;
14891 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14893 spin_lock_bh(&rdev->beacon_registrations_lock);
14894 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14895 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14897 spin_unlock_bh(&rdev->beacon_registrations_lock);
14901 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14903 goto nla_put_failure;
14905 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14907 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14909 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14910 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14911 goto nla_put_failure;
14913 genlmsg_end(msg, hdr);
14915 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
14917 spin_unlock_bh(&rdev->beacon_registrations_lock);
14921 spin_unlock_bh(&rdev->beacon_registrations_lock);
14923 genlmsg_cancel(msg, hdr);
14926 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14929 static int cfg80211_net_detect_results(struct sk_buff *msg,
14930 struct cfg80211_wowlan_wakeup *wakeup)
14932 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14933 struct nlattr *nl_results, *nl_match, *nl_freqs;
14936 nl_results = nla_nest_start(
14937 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14941 for (i = 0; i < nd->n_matches; i++) {
14942 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14944 nl_match = nla_nest_start(msg, i);
14948 /* The SSID attribute is optional in nl80211, but for
14949 * simplicity reasons it's always present in the
14950 * cfg80211 structure. If a driver can't pass the
14951 * SSID, that needs to be changed. A zero length SSID
14952 * is still a valid SSID (wildcard), so it cannot be
14953 * used for this purpose.
14955 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14956 match->ssid.ssid)) {
14957 nla_nest_cancel(msg, nl_match);
14961 if (match->n_channels) {
14962 nl_freqs = nla_nest_start(
14963 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14965 nla_nest_cancel(msg, nl_match);
14969 for (j = 0; j < match->n_channels; j++) {
14970 if (nla_put_u32(msg, j, match->channels[j])) {
14971 nla_nest_cancel(msg, nl_freqs);
14972 nla_nest_cancel(msg, nl_match);
14977 nla_nest_end(msg, nl_freqs);
14980 nla_nest_end(msg, nl_match);
14984 nla_nest_end(msg, nl_results);
14988 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14989 struct cfg80211_wowlan_wakeup *wakeup,
14992 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14993 struct sk_buff *msg;
14997 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
15000 size += wakeup->packet_present_len;
15002 msg = nlmsg_new(size, gfp);
15006 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
15010 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15011 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15015 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15016 wdev->netdev->ifindex))
15020 struct nlattr *reasons;
15022 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
15026 if (wakeup->disconnect &&
15027 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
15029 if (wakeup->magic_pkt &&
15030 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
15032 if (wakeup->gtk_rekey_failure &&
15033 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
15035 if (wakeup->eap_identity_req &&
15036 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
15038 if (wakeup->four_way_handshake &&
15039 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
15041 if (wakeup->rfkill_release &&
15042 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
15045 if (wakeup->pattern_idx >= 0 &&
15046 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
15047 wakeup->pattern_idx))
15050 if (wakeup->tcp_match &&
15051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
15054 if (wakeup->tcp_connlost &&
15055 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
15058 if (wakeup->tcp_nomoretokens &&
15060 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
15063 if (wakeup->packet) {
15064 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
15065 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
15067 if (!wakeup->packet_80211) {
15069 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
15071 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
15074 if (wakeup->packet_len &&
15075 nla_put_u32(msg, len_attr, wakeup->packet_len))
15078 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
15083 if (wakeup->net_detect &&
15084 cfg80211_net_detect_results(msg, wakeup))
15087 nla_nest_end(msg, reasons);
15090 genlmsg_end(msg, hdr);
15092 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15093 NL80211_MCGRP_MLME, gfp);
15099 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
15102 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
15103 enum nl80211_tdls_operation oper,
15104 u16 reason_code, gfp_t gfp)
15106 struct wireless_dev *wdev = dev->ieee80211_ptr;
15107 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
15108 struct sk_buff *msg;
15111 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
15114 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15118 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
15124 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15125 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15126 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
15127 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
15128 (reason_code > 0 &&
15129 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
15130 goto nla_put_failure;
15132 genlmsg_end(msg, hdr);
15134 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15135 NL80211_MCGRP_MLME, gfp);
15139 genlmsg_cancel(msg, hdr);
15142 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
15144 static int nl80211_netlink_notify(struct notifier_block * nb,
15145 unsigned long state,
15148 struct netlink_notify *notify = _notify;
15149 struct cfg80211_registered_device *rdev;
15150 struct wireless_dev *wdev;
15151 struct cfg80211_beacon_registration *reg, *tmp;
15153 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
15154 return NOTIFY_DONE;
15158 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
15159 struct cfg80211_sched_scan_request *sched_scan_req;
15161 list_for_each_entry_rcu(sched_scan_req,
15162 &rdev->sched_scan_req_list,
15164 if (sched_scan_req->owner_nlportid == notify->portid) {
15165 sched_scan_req->nl_owner_dead = true;
15166 schedule_work(&rdev->sched_scan_stop_wk);
15170 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
15171 cfg80211_mlme_unregister_socket(wdev, notify->portid);
15173 if (wdev->owner_nlportid == notify->portid) {
15174 wdev->nl_owner_dead = true;
15175 schedule_work(&rdev->destroy_work);
15176 } else if (wdev->conn_owner_nlportid == notify->portid) {
15177 schedule_work(&wdev->disconnect_wk);
15181 spin_lock_bh(&rdev->beacon_registrations_lock);
15182 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
15184 if (reg->nlportid == notify->portid) {
15185 list_del(®->list);
15190 spin_unlock_bh(&rdev->beacon_registrations_lock);
15196 * It is possible that the user space process that is controlling the
15197 * indoor setting disappeared, so notify the regulatory core.
15199 regulatory_netlink_notify(notify->portid);
15203 static struct notifier_block nl80211_netlink_notifier = {
15204 .notifier_call = nl80211_netlink_notify,
15207 void cfg80211_ft_event(struct net_device *netdev,
15208 struct cfg80211_ft_event_params *ft_event)
15210 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
15211 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15212 struct sk_buff *msg;
15215 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
15217 if (!ft_event->target_ap)
15220 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
15224 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
15228 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15229 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15230 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
15233 if (ft_event->ies &&
15234 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
15236 if (ft_event->ric_ies &&
15237 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
15238 ft_event->ric_ies))
15241 genlmsg_end(msg, hdr);
15243 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15244 NL80211_MCGRP_MLME, GFP_KERNEL);
15249 EXPORT_SYMBOL(cfg80211_ft_event);
15251 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
15253 struct cfg80211_registered_device *rdev;
15254 struct sk_buff *msg;
15258 rdev = wiphy_to_rdev(wdev->wiphy);
15259 if (!rdev->crit_proto_nlportid)
15262 nlportid = rdev->crit_proto_nlportid;
15263 rdev->crit_proto_nlportid = 0;
15265 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15269 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
15271 goto nla_put_failure;
15273 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15274 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15276 goto nla_put_failure;
15278 genlmsg_end(msg, hdr);
15280 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
15285 genlmsg_cancel(msg, hdr);
15288 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
15290 void nl80211_send_ap_stopped(struct wireless_dev *wdev)
15292 struct wiphy *wiphy = wdev->wiphy;
15293 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15294 struct sk_buff *msg;
15297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15301 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
15305 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15306 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
15307 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15311 genlmsg_end(msg, hdr);
15313 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
15314 NL80211_MCGRP_MLME, GFP_KERNEL);
15320 /* initialisation/exit functions */
15322 int __init nl80211_init(void)
15326 err = genl_register_family(&nl80211_fam);
15330 err = netlink_register_notifier(&nl80211_netlink_notifier);
15336 genl_unregister_family(&nl80211_fam);
15340 void nl80211_exit(void)
15342 netlink_unregister_notifier(&nl80211_netlink_notifier);
15343 genl_unregister_family(&nl80211_fam);