2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
22 #include <net/inet_connection_sock.h>
28 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
33 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
38 /* the netlink family */
39 static struct genl_family nl80211_fam = {
40 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
44 .maxattr = NL80211_ATTR_MAX,
46 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
50 /* multicast groups */
51 enum nl80211_multicast_groups {
54 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59 static const struct genl_multicast_group nl80211_mcgrps[] = {
60 [NL80211_MCGRP_CONFIG] = { .name = "config", },
61 [NL80211_MCGRP_SCAN] = { .name = "scan", },
62 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
63 [NL80211_MCGRP_MLME] = { .name = "mlme", },
64 #ifdef CONFIG_NL80211_TESTMODE
65 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
69 /* returns ERR_PTR values */
70 static struct wireless_dev *
71 __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
73 struct cfg80211_registered_device *rdev;
74 struct wireless_dev *result = NULL;
75 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
76 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
83 if (!have_ifidx && !have_wdev_id)
84 return ERR_PTR(-EINVAL);
87 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
89 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
90 wiphy_idx = wdev_id >> 32;
93 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
94 struct wireless_dev *wdev;
96 if (wiphy_net(&rdev->wiphy) != netns)
99 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
102 list_for_each_entry(wdev, &rdev->wdev_list, list) {
103 if (have_ifidx && wdev->netdev &&
104 wdev->netdev->ifindex == ifidx) {
108 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
120 return ERR_PTR(-ENODEV);
123 static struct cfg80211_registered_device *
124 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
126 struct cfg80211_registered_device *rdev = NULL, *tmp;
127 struct net_device *netdev;
131 if (!attrs[NL80211_ATTR_WIPHY] &&
132 !attrs[NL80211_ATTR_IFINDEX] &&
133 !attrs[NL80211_ATTR_WDEV])
134 return ERR_PTR(-EINVAL);
136 if (attrs[NL80211_ATTR_WIPHY])
137 rdev = cfg80211_rdev_by_wiphy_idx(
138 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
140 if (attrs[NL80211_ATTR_WDEV]) {
141 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
142 struct wireless_dev *wdev;
145 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
147 /* make sure wdev exists */
148 list_for_each_entry(wdev, &tmp->wdev_list, list) {
149 if (wdev->identifier != (u32)wdev_id)
158 if (rdev && tmp != rdev)
159 return ERR_PTR(-EINVAL);
164 if (attrs[NL80211_ATTR_IFINDEX]) {
165 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
166 netdev = dev_get_by_index(netns, ifindex);
168 if (netdev->ieee80211_ptr)
170 netdev->ieee80211_ptr->wiphy);
176 /* not wireless device -- return error */
178 return ERR_PTR(-EINVAL);
180 /* mismatch -- return error */
181 if (rdev && tmp != rdev)
182 return ERR_PTR(-EINVAL);
189 return ERR_PTR(-ENODEV);
191 if (netns != wiphy_net(&rdev->wiphy))
192 return ERR_PTR(-ENODEV);
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
204 static struct cfg80211_registered_device *
205 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
207 return __cfg80211_rdev_from_attrs(netns, info->attrs);
210 /* policy for the attributes */
211 static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
212 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
213 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
215 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
217 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
219 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
220 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
224 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
229 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
233 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
234 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
236 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
237 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
238 .len = WLAN_MAX_KEY_LEN },
239 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
240 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
241 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
242 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
243 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
245 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
246 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
247 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_DATA_LEN },
249 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
252 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
253 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
255 .len = NL80211_MAX_SUPP_RATES },
256 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
257 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
258 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
259 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
260 .len = IEEE80211_MAX_MESH_ID_LEN },
261 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
263 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
264 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
266 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
270 .len = NL80211_MAX_SUPP_RATES },
271 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
273 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
274 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
276 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
278 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
279 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
280 .len = IEEE80211_MAX_DATA_LEN },
281 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
282 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_SSID_LEN },
286 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
287 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
288 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
289 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
340 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
341 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
343 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
344 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
346 .len = NL80211_HT_CAPABILITY_LEN
348 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
349 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
350 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
351 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
352 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
353 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
354 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
355 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
356 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
357 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
358 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
359 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
360 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
361 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
362 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
363 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
364 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
365 .len = NL80211_VHT_CAPABILITY_LEN,
367 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
368 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
369 .len = IEEE80211_MAX_DATA_LEN },
370 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
371 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
373 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
374 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
375 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
376 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
377 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
378 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
381 /* policy for the key attributes */
382 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
383 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
384 [NL80211_KEY_IDX] = { .type = NLA_U8 },
385 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
386 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
387 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
388 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
389 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
390 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
393 /* policy for the key default flags */
394 static const struct nla_policy
395 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
396 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
397 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
400 /* policy for WoWLAN attributes */
401 static const struct nla_policy
402 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
403 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
404 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
405 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
406 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
407 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
409 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
410 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
411 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
414 static const struct nla_policy
415 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
416 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
417 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
418 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
419 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
420 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
421 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
422 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
423 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
425 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
426 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
428 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
429 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
430 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
433 /* policy for coalesce rule attributes */
434 static const struct nla_policy
435 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
436 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
437 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
438 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
441 /* policy for GTK rekey offload attributes */
442 static const struct nla_policy
443 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
444 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
445 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
446 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
449 static const struct nla_policy
450 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
451 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
452 .len = IEEE80211_MAX_SSID_LEN },
453 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
456 static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
457 struct netlink_callback *cb,
458 struct cfg80211_registered_device **rdev,
459 struct wireless_dev **wdev)
466 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
467 nl80211_fam.attrbuf, nl80211_fam.maxattr,
472 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
473 nl80211_fam.attrbuf);
475 err = PTR_ERR(*wdev);
478 *rdev = wiphy_to_dev((*wdev)->wiphy);
479 /* 0 is the first index - add 1 to parse only once */
480 cb->args[0] = (*rdev)->wiphy_idx + 1;
481 cb->args[1] = (*wdev)->identifier;
483 /* subtract the 1 again here */
484 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
485 struct wireless_dev *tmp;
491 *rdev = wiphy_to_dev(wiphy);
494 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
495 if (tmp->identifier == cb->args[1]) {
513 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
519 static bool is_valid_ie_attr(const struct nlattr *attr)
527 pos = nla_data(attr);
548 /* message building helper */
549 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
552 /* since there is no private header just add the generic one */
553 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
556 static int nl80211_msg_put_channel(struct sk_buff *msg,
557 struct ieee80211_channel *chan,
560 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
562 goto nla_put_failure;
564 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
565 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
566 goto nla_put_failure;
567 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
568 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
569 goto nla_put_failure;
570 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
571 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
572 goto nla_put_failure;
573 if (chan->flags & IEEE80211_CHAN_RADAR) {
574 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
575 goto nla_put_failure;
579 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
581 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
583 goto nla_put_failure;
584 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
586 goto nla_put_failure;
591 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
592 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
593 goto nla_put_failure;
594 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
595 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
596 goto nla_put_failure;
597 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
598 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
599 goto nla_put_failure;
600 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
601 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
602 goto nla_put_failure;
605 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
606 DBM_TO_MBM(chan->max_power)))
607 goto nla_put_failure;
615 /* netlink command implementations */
622 bool def_uni, def_multi;
625 static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
627 struct nlattr *tb[NL80211_KEY_MAX + 1];
628 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
633 k->def = !!tb[NL80211_KEY_DEFAULT];
634 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
643 if (tb[NL80211_KEY_IDX])
644 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
646 if (tb[NL80211_KEY_DATA]) {
647 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
648 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
651 if (tb[NL80211_KEY_SEQ]) {
652 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
653 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
656 if (tb[NL80211_KEY_CIPHER])
657 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
659 if (tb[NL80211_KEY_TYPE]) {
660 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
661 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
665 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
666 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
667 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
668 tb[NL80211_KEY_DEFAULT_TYPES],
669 nl80211_key_default_policy);
673 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
674 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
680 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
682 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
683 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
684 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
687 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
688 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
689 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
692 if (info->attrs[NL80211_ATTR_KEY_IDX])
693 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
695 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
696 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
698 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
699 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
708 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
709 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
710 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
714 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
715 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
716 int err = nla_parse_nested(
717 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
718 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
719 nl80211_key_default_policy);
723 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
724 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
730 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
734 memset(k, 0, sizeof(*k));
738 if (info->attrs[NL80211_ATTR_KEY])
739 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
741 err = nl80211_parse_key_old(info, k);
746 if (k->def && k->defmgmt)
750 if (k->def_uni || !k->def_multi)
756 if (k->idx < 4 || k->idx > 5)
759 if (k->idx < 0 || k->idx > 3)
762 if (k->idx < 0 || k->idx > 5)
770 static struct cfg80211_cached_keys *
771 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
772 struct nlattr *keys, bool *no_ht)
774 struct key_parse parse;
776 struct cfg80211_cached_keys *result;
777 int rem, err, def = 0;
779 result = kzalloc(sizeof(*result), GFP_KERNEL);
781 return ERR_PTR(-ENOMEM);
784 result->defmgmt = -1;
786 nla_for_each_nested(key, keys, rem) {
787 memset(&parse, 0, sizeof(parse));
790 err = nl80211_parse_key_new(key, &parse);
796 if (parse.idx < 0 || parse.idx > 4)
802 result->def = parse.idx;
803 if (!parse.def_uni || !parse.def_multi)
805 } else if (parse.defmgmt)
807 err = cfg80211_validate_key_settings(rdev, &parse.p,
808 parse.idx, false, NULL);
811 result->params[parse.idx].cipher = parse.p.cipher;
812 result->params[parse.idx].key_len = parse.p.key_len;
813 result->params[parse.idx].key = result->data[parse.idx];
814 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
816 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
817 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
829 static int nl80211_key_allowed(struct wireless_dev *wdev)
831 ASSERT_WDEV_LOCK(wdev);
833 switch (wdev->iftype) {
834 case NL80211_IFTYPE_AP:
835 case NL80211_IFTYPE_AP_VLAN:
836 case NL80211_IFTYPE_P2P_GO:
837 case NL80211_IFTYPE_MESH_POINT:
839 case NL80211_IFTYPE_ADHOC:
840 case NL80211_IFTYPE_STATION:
841 case NL80211_IFTYPE_P2P_CLIENT:
842 if (!wdev->current_bss)
852 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
854 struct nlattr *nl_modes = nla_nest_start(msg, attr);
858 goto nla_put_failure;
862 if ((ifmodes & 1) && nla_put_flag(msg, i))
863 goto nla_put_failure;
868 nla_nest_end(msg, nl_modes);
875 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
879 struct nlattr *nl_combis;
882 nl_combis = nla_nest_start(msg,
883 NL80211_ATTR_INTERFACE_COMBINATIONS);
885 goto nla_put_failure;
887 for (i = 0; i < wiphy->n_iface_combinations; i++) {
888 const struct ieee80211_iface_combination *c;
889 struct nlattr *nl_combi, *nl_limits;
891 c = &wiphy->iface_combinations[i];
893 nl_combi = nla_nest_start(msg, i + 1);
895 goto nla_put_failure;
897 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
899 goto nla_put_failure;
901 for (j = 0; j < c->n_limits; j++) {
902 struct nlattr *nl_limit;
904 nl_limit = nla_nest_start(msg, j + 1);
906 goto nla_put_failure;
907 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
909 goto nla_put_failure;
910 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
912 goto nla_put_failure;
913 nla_nest_end(msg, nl_limit);
916 nla_nest_end(msg, nl_limits);
918 if (c->beacon_int_infra_match &&
919 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
920 goto nla_put_failure;
921 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
922 c->num_different_channels) ||
923 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
925 goto nla_put_failure;
927 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
928 c->radar_detect_widths))
929 goto nla_put_failure;
931 nla_nest_end(msg, nl_combi);
934 nla_nest_end(msg, nl_combis);
942 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
945 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
946 struct nlattr *nl_tcp;
951 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
955 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
956 tcp->data_payload_max))
959 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
960 tcp->data_payload_max))
963 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
966 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
967 sizeof(*tcp->tok), tcp->tok))
970 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
971 tcp->data_interval_max))
974 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
975 tcp->wake_payload_max))
978 nla_nest_end(msg, nl_tcp);
982 static int nl80211_send_wowlan(struct sk_buff *msg,
983 struct cfg80211_registered_device *dev,
986 struct nlattr *nl_wowlan;
988 if (!dev->wiphy.wowlan)
991 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
995 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
996 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
997 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
998 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
999 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1001 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1002 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1003 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1005 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1007 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1008 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1009 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1010 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1013 if (dev->wiphy.wowlan->n_patterns) {
1014 struct nl80211_pattern_support pat = {
1015 .max_patterns = dev->wiphy.wowlan->n_patterns,
1016 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1017 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1018 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
1021 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1026 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1029 nla_nest_end(msg, nl_wowlan);
1035 static int nl80211_send_coalesce(struct sk_buff *msg,
1036 struct cfg80211_registered_device *dev)
1038 struct nl80211_coalesce_rule_support rule;
1040 if (!dev->wiphy.coalesce)
1043 rule.max_rules = dev->wiphy.coalesce->n_rules;
1044 rule.max_delay = dev->wiphy.coalesce->max_delay;
1045 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1046 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1047 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1048 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1050 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1056 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1057 struct ieee80211_supported_band *sband)
1059 struct nlattr *nl_rates, *nl_rate;
1060 struct ieee80211_rate *rate;
1064 if (sband->ht_cap.ht_supported &&
1065 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1066 sizeof(sband->ht_cap.mcs),
1067 &sband->ht_cap.mcs) ||
1068 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1069 sband->ht_cap.cap) ||
1070 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1071 sband->ht_cap.ampdu_factor) ||
1072 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1073 sband->ht_cap.ampdu_density)))
1077 if (sband->vht_cap.vht_supported &&
1078 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1079 sizeof(sband->vht_cap.vht_mcs),
1080 &sband->vht_cap.vht_mcs) ||
1081 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1082 sband->vht_cap.cap)))
1086 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1090 for (i = 0; i < sband->n_bitrates; i++) {
1091 nl_rate = nla_nest_start(msg, i);
1095 rate = &sband->bitrates[i];
1096 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1099 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1101 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1104 nla_nest_end(msg, nl_rate);
1107 nla_nest_end(msg, nl_rates);
1113 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1114 const struct ieee80211_txrx_stypes *mgmt_stypes)
1117 struct nlattr *nl_ftypes, *nl_ifs;
1118 enum nl80211_iftype ift;
1124 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1128 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1129 nl_ftypes = nla_nest_start(msg, ift);
1133 stypes = mgmt_stypes[ift].tx;
1136 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1137 (i << 4) | IEEE80211_FTYPE_MGMT))
1142 nla_nest_end(msg, nl_ftypes);
1145 nla_nest_end(msg, nl_ifs);
1147 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1151 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1152 nl_ftypes = nla_nest_start(msg, ift);
1156 stypes = mgmt_stypes[ift].rx;
1159 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1160 (i << 4) | IEEE80211_FTYPE_MGMT))
1165 nla_nest_end(msg, nl_ftypes);
1167 nla_nest_end(msg, nl_ifs);
1172 struct nl80211_dump_wiphy_state {
1175 long split_start, band_start, chan_start;
1179 static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1180 struct sk_buff *msg, u32 portid, u32 seq,
1181 int flags, struct nl80211_dump_wiphy_state *state)
1184 struct nlattr *nl_bands, *nl_band;
1185 struct nlattr *nl_freqs, *nl_freq;
1186 struct nlattr *nl_cmds;
1187 enum ieee80211_band band;
1188 struct ieee80211_channel *chan;
1190 const struct ieee80211_txrx_stypes *mgmt_stypes =
1191 dev->wiphy.mgmt_stypes;
1194 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
1198 if (WARN_ON(!state))
1201 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
1202 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1203 wiphy_name(&dev->wiphy)) ||
1204 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1205 cfg80211_rdev_list_generation))
1206 goto nla_put_failure;
1208 switch (state->split_start) {
1210 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1211 dev->wiphy.retry_short) ||
1212 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1213 dev->wiphy.retry_long) ||
1214 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1215 dev->wiphy.frag_threshold) ||
1216 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1217 dev->wiphy.rts_threshold) ||
1218 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1219 dev->wiphy.coverage_class) ||
1220 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1221 dev->wiphy.max_scan_ssids) ||
1222 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1223 dev->wiphy.max_sched_scan_ssids) ||
1224 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1225 dev->wiphy.max_scan_ie_len) ||
1226 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1227 dev->wiphy.max_sched_scan_ie_len) ||
1228 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1229 dev->wiphy.max_match_sets))
1230 goto nla_put_failure;
1232 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1233 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1234 goto nla_put_failure;
1235 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1236 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1237 goto nla_put_failure;
1238 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1239 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1240 goto nla_put_failure;
1241 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1242 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1243 goto nla_put_failure;
1244 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1245 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1246 goto nla_put_failure;
1247 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1248 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
1249 goto nla_put_failure;
1250 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1251 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1252 goto nla_put_failure;
1254 state->split_start++;
1258 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1259 sizeof(u32) * dev->wiphy.n_cipher_suites,
1260 dev->wiphy.cipher_suites))
1261 goto nla_put_failure;
1263 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1264 dev->wiphy.max_num_pmkids))
1265 goto nla_put_failure;
1267 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1268 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1269 goto nla_put_failure;
1271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1272 dev->wiphy.available_antennas_tx) ||
1273 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1274 dev->wiphy.available_antennas_rx))
1275 goto nla_put_failure;
1277 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1278 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1279 dev->wiphy.probe_resp_offload))
1280 goto nla_put_failure;
1282 if ((dev->wiphy.available_antennas_tx ||
1283 dev->wiphy.available_antennas_rx) &&
1284 dev->ops->get_antenna) {
1285 u32 tx_ant = 0, rx_ant = 0;
1287 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1289 if (nla_put_u32(msg,
1290 NL80211_ATTR_WIPHY_ANTENNA_TX,
1293 NL80211_ATTR_WIPHY_ANTENNA_RX,
1295 goto nla_put_failure;
1299 state->split_start++;
1303 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1304 dev->wiphy.interface_modes))
1305 goto nla_put_failure;
1306 state->split_start++;
1310 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1312 goto nla_put_failure;
1314 for (band = state->band_start;
1315 band < IEEE80211_NUM_BANDS; band++) {
1316 struct ieee80211_supported_band *sband;
1318 sband = dev->wiphy.bands[band];
1323 nl_band = nla_nest_start(msg, band);
1325 goto nla_put_failure;
1327 switch (state->chan_start) {
1329 if (nl80211_send_band_rateinfo(msg, sband))
1330 goto nla_put_failure;
1331 state->chan_start++;
1335 /* add frequencies */
1336 nl_freqs = nla_nest_start(
1337 msg, NL80211_BAND_ATTR_FREQS);
1339 goto nla_put_failure;
1341 for (i = state->chan_start - 1;
1342 i < sband->n_channels;
1344 nl_freq = nla_nest_start(msg, i);
1346 goto nla_put_failure;
1348 chan = &sband->channels[i];
1350 if (nl80211_msg_put_channel(
1353 goto nla_put_failure;
1355 nla_nest_end(msg, nl_freq);
1359 if (i < sband->n_channels)
1360 state->chan_start = i + 2;
1362 state->chan_start = 0;
1363 nla_nest_end(msg, nl_freqs);
1366 nla_nest_end(msg, nl_band);
1369 /* start again here */
1370 if (state->chan_start)
1375 nla_nest_end(msg, nl_bands);
1377 if (band < IEEE80211_NUM_BANDS)
1378 state->band_start = band + 1;
1380 state->band_start = 0;
1382 /* if bands & channels are done, continue outside */
1383 if (state->band_start == 0 && state->chan_start == 0)
1384 state->split_start++;
1388 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1390 goto nla_put_failure;
1393 #define CMD(op, n) \
1395 if (dev->ops->op) { \
1397 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1398 goto nla_put_failure; \
1402 CMD(add_virtual_intf, NEW_INTERFACE);
1403 CMD(change_virtual_intf, SET_INTERFACE);
1404 CMD(add_key, NEW_KEY);
1405 CMD(start_ap, START_AP);
1406 CMD(add_station, NEW_STATION);
1407 CMD(add_mpath, NEW_MPATH);
1408 CMD(update_mesh_config, SET_MESH_CONFIG);
1409 CMD(change_bss, SET_BSS);
1410 CMD(auth, AUTHENTICATE);
1411 CMD(assoc, ASSOCIATE);
1412 CMD(deauth, DEAUTHENTICATE);
1413 CMD(disassoc, DISASSOCIATE);
1414 CMD(join_ibss, JOIN_IBSS);
1415 CMD(join_mesh, JOIN_MESH);
1416 CMD(set_pmksa, SET_PMKSA);
1417 CMD(del_pmksa, DEL_PMKSA);
1418 CMD(flush_pmksa, FLUSH_PMKSA);
1419 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1420 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1421 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1422 CMD(mgmt_tx, FRAME);
1423 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1424 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1426 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1427 goto nla_put_failure;
1429 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1430 dev->ops->join_mesh) {
1432 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1433 goto nla_put_failure;
1435 CMD(set_wds_peer, SET_WDS_PEER);
1436 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1437 CMD(tdls_mgmt, TDLS_MGMT);
1438 CMD(tdls_oper, TDLS_OPER);
1440 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1441 CMD(sched_scan_start, START_SCHED_SCAN);
1442 CMD(probe_client, PROBE_CLIENT);
1443 CMD(set_noack_map, SET_NOACK_MAP);
1444 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1446 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1447 goto nla_put_failure;
1449 CMD(start_p2p_device, START_P2P_DEVICE);
1450 CMD(set_mcast_rate, SET_MCAST_RATE);
1452 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1453 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1454 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1455 CMD(channel_switch, CHANNEL_SWITCH);
1458 #ifdef CONFIG_NL80211_TESTMODE
1459 CMD(testmode_cmd, TESTMODE);
1464 if (dev->ops->connect || dev->ops->auth) {
1466 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1467 goto nla_put_failure;
1470 if (dev->ops->disconnect || dev->ops->deauth) {
1472 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1473 goto nla_put_failure;
1476 nla_nest_end(msg, nl_cmds);
1477 state->split_start++;
1481 if (dev->ops->remain_on_channel &&
1482 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1484 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1485 dev->wiphy.max_remain_on_channel_duration))
1486 goto nla_put_failure;
1488 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1489 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1490 goto nla_put_failure;
1492 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1493 goto nla_put_failure;
1494 state->split_start++;
1499 if (nl80211_send_wowlan(msg, dev, state->split))
1500 goto nla_put_failure;
1501 state->split_start++;
1505 state->split_start++;
1508 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1509 dev->wiphy.software_iftypes))
1510 goto nla_put_failure;
1512 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1514 goto nla_put_failure;
1516 state->split_start++;
1520 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1521 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1522 dev->wiphy.ap_sme_capa))
1523 goto nla_put_failure;
1525 features = dev->wiphy.features;
1527 * We can only add the per-channel limit information if the
1528 * dump is split, otherwise it makes it too big. Therefore
1529 * only advertise it in that case.
1532 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1533 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
1534 goto nla_put_failure;
1536 if (dev->wiphy.ht_capa_mod_mask &&
1537 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1538 sizeof(*dev->wiphy.ht_capa_mod_mask),
1539 dev->wiphy.ht_capa_mod_mask))
1540 goto nla_put_failure;
1542 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1543 dev->wiphy.max_acl_mac_addrs &&
1544 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1545 dev->wiphy.max_acl_mac_addrs))
1546 goto nla_put_failure;
1549 * Any information below this point is only available to
1550 * applications that can deal with it being split. This
1551 * helps ensure that newly added capabilities don't break
1552 * older tools by overrunning their buffers.
1554 * We still increment split_start so that in the split
1555 * case we'll continue with more data in the next round,
1556 * but break unconditionally so unsplit data stops here.
1558 state->split_start++;
1561 if (dev->wiphy.extended_capabilities &&
1562 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1563 dev->wiphy.extended_capabilities_len,
1564 dev->wiphy.extended_capabilities) ||
1565 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1566 dev->wiphy.extended_capabilities_len,
1567 dev->wiphy.extended_capabilities_mask)))
1568 goto nla_put_failure;
1570 if (dev->wiphy.vht_capa_mod_mask &&
1571 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1572 sizeof(*dev->wiphy.vht_capa_mod_mask),
1573 dev->wiphy.vht_capa_mod_mask))
1574 goto nla_put_failure;
1576 state->split_start++;
1579 if (nl80211_send_coalesce(msg, dev))
1580 goto nla_put_failure;
1583 state->split_start = 0;
1586 return genlmsg_end(msg, hdr);
1589 genlmsg_cancel(msg, hdr);
1593 static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1594 struct netlink_callback *cb,
1595 struct nl80211_dump_wiphy_state *state)
1597 struct nlattr **tb = nl80211_fam.attrbuf;
1598 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1599 tb, nl80211_fam.maxattr, nl80211_policy);
1600 /* ignore parse errors for backward compatibility */
1604 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1605 if (tb[NL80211_ATTR_WIPHY])
1606 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1607 if (tb[NL80211_ATTR_WDEV])
1608 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1609 if (tb[NL80211_ATTR_IFINDEX]) {
1610 struct net_device *netdev;
1611 struct cfg80211_registered_device *rdev;
1612 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1614 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1617 if (netdev->ieee80211_ptr) {
1618 rdev = wiphy_to_dev(
1619 netdev->ieee80211_ptr->wiphy);
1620 state->filter_wiphy = rdev->wiphy_idx;
1628 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1631 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
1632 struct cfg80211_registered_device *dev;
1636 state = kzalloc(sizeof(*state), GFP_KERNEL);
1641 state->filter_wiphy = -1;
1642 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1648 cb->args[0] = (long)state;
1651 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
1652 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1654 if (++idx <= state->start)
1656 if (state->filter_wiphy != -1 &&
1657 state->filter_wiphy != dev->wiphy_idx)
1659 /* attempt to fit multiple wiphy data chunks into the skb */
1661 ret = nl80211_send_wiphy(dev, skb,
1662 NETLINK_CB(cb->skb).portid,
1664 NLM_F_MULTI, state);
1667 * If sending the wiphy data didn't fit (ENOBUFS
1668 * or EMSGSIZE returned), this SKB is still
1669 * empty (so it's not too big because another
1670 * wiphy dataset is already in the skb) and
1671 * we've not tried to adjust the dump allocation
1672 * yet ... then adjust the alloc size to be
1673 * bigger, and return 1 but with the empty skb.
1674 * This results in an empty message being RX'ed
1675 * in userspace, but that is ignored.
1677 * We can then retry with the larger buffer.
1679 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1681 cb->min_dump_alloc < 4096) {
1682 cb->min_dump_alloc = 4096;
1689 } while (state->split_start > 0);
1699 static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1701 kfree((void *)cb->args[0]);
1705 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1707 struct sk_buff *msg;
1708 struct cfg80211_registered_device *dev = info->user_ptr[0];
1709 struct nl80211_dump_wiphy_state state = {};
1711 msg = nlmsg_new(4096, GFP_KERNEL);
1715 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1721 return genlmsg_reply(msg, info);
1724 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1725 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1726 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1727 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1728 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1729 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1732 static int parse_txq_params(struct nlattr *tb[],
1733 struct ieee80211_txq_params *txq_params)
1735 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1736 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1737 !tb[NL80211_TXQ_ATTR_AIFS])
1740 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
1741 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1742 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1743 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1744 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1746 if (txq_params->ac >= NL80211_NUM_ACS)
1752 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1755 * You can only set the channel explicitly for WDS interfaces,
1756 * all others have their channel managed via their respective
1757 * "establish a connection" command (connect, join, ...)
1759 * For AP/GO and mesh mode, the channel can be set with the
1760 * channel userspace API, but is only stored and passed to the
1761 * low-level driver when the AP starts or the mesh is joined.
1762 * This is for backward compatibility, userspace can also give
1763 * the channel in the start-ap or join-mesh commands instead.
1765 * Monitors are special as they are normally slaved to
1766 * whatever else is going on, so they have their own special
1767 * operation to set the monitor channel if possible.
1770 wdev->iftype == NL80211_IFTYPE_AP ||
1771 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
1772 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1773 wdev->iftype == NL80211_IFTYPE_P2P_GO;
1776 static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1777 struct genl_info *info,
1778 struct cfg80211_chan_def *chandef)
1782 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1785 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1787 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
1788 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1789 chandef->center_freq1 = control_freq;
1790 chandef->center_freq2 = 0;
1792 /* Primary channel not allowed */
1793 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1796 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1797 enum nl80211_channel_type chantype;
1799 chantype = nla_get_u32(
1800 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1803 case NL80211_CHAN_NO_HT:
1804 case NL80211_CHAN_HT20:
1805 case NL80211_CHAN_HT40PLUS:
1806 case NL80211_CHAN_HT40MINUS:
1807 cfg80211_chandef_create(chandef, chandef->chan,
1813 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1815 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1816 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1817 chandef->center_freq1 =
1819 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1820 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1821 chandef->center_freq2 =
1823 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1826 if (!cfg80211_chandef_valid(chandef))
1829 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1830 IEEE80211_CHAN_DISABLED))
1833 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1834 chandef->width == NL80211_CHAN_WIDTH_10) &&
1835 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1841 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1842 struct wireless_dev *wdev,
1843 struct genl_info *info)
1845 struct cfg80211_chan_def chandef;
1847 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1850 iftype = wdev->iftype;
1852 if (!nl80211_can_set_dev_channel(wdev))
1855 result = nl80211_parse_chandef(rdev, info, &chandef);
1860 case NL80211_IFTYPE_AP:
1861 case NL80211_IFTYPE_P2P_GO:
1862 if (wdev->beacon_interval) {
1866 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
1870 wdev->preset_chandef = chandef;
1873 case NL80211_IFTYPE_MESH_POINT:
1874 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
1876 case NL80211_IFTYPE_MONITOR:
1877 result = cfg80211_set_monitor_channel(rdev, &chandef);
1886 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1889 struct net_device *netdev = info->user_ptr[1];
1891 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
1894 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1897 struct net_device *dev = info->user_ptr[1];
1898 struct wireless_dev *wdev = dev->ieee80211_ptr;
1901 if (!info->attrs[NL80211_ATTR_MAC])
1904 if (netif_running(dev))
1907 if (!rdev->ops->set_wds_peer)
1910 if (wdev->iftype != NL80211_IFTYPE_WDS)
1913 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
1914 return rdev_set_wds_peer(rdev, dev, bssid);
1918 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1920 struct cfg80211_registered_device *rdev;
1921 struct net_device *netdev = NULL;
1922 struct wireless_dev *wdev;
1923 int result = 0, rem_txq_params = 0;
1924 struct nlattr *nl_txq_params;
1926 u8 retry_short = 0, retry_long = 0;
1927 u32 frag_threshold = 0, rts_threshold = 0;
1928 u8 coverage_class = 0;
1933 * Try to find the wiphy and netdev. Normally this
1934 * function shouldn't need the netdev, but this is
1935 * done for backward compatibility -- previously
1936 * setting the channel was done per wiphy, but now
1937 * it is per netdev. Previous userland like hostapd
1938 * also passed a netdev to set_wiphy, so that it is
1939 * possible to let that go to the right netdev!
1942 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1943 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1945 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1946 if (netdev && netdev->ieee80211_ptr)
1947 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1953 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1956 return PTR_ERR(rdev);
1961 wdev = netdev->ieee80211_ptr;
1964 * end workaround code, by now the rdev is available
1965 * and locked, and wdev may or may not be NULL.
1968 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
1969 result = cfg80211_dev_rename(
1970 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
1975 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1976 struct ieee80211_txq_params txq_params;
1977 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1979 if (!rdev->ops->set_txq_params) {
1980 result = -EOPNOTSUPP;
1989 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1990 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1995 if (!netif_running(netdev)) {
2000 nla_for_each_nested(nl_txq_params,
2001 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2003 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2004 nla_data(nl_txq_params),
2005 nla_len(nl_txq_params),
2007 result = parse_txq_params(tb, &txq_params);
2011 result = rdev_set_txq_params(rdev, netdev,
2018 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2019 result = __nl80211_set_channel(rdev,
2020 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2026 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
2027 struct wireless_dev *txp_wdev = wdev;
2028 enum nl80211_tx_power_setting type;
2031 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2034 if (!rdev->ops->set_tx_power) {
2035 result = -EOPNOTSUPP;
2039 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2040 type = nla_get_u32(info->attrs[idx]);
2042 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2043 (type != NL80211_TX_POWER_AUTOMATIC)) {
2048 if (type != NL80211_TX_POWER_AUTOMATIC) {
2049 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2050 mbm = nla_get_u32(info->attrs[idx]);
2053 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
2058 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2059 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2061 if ((!rdev->wiphy.available_antennas_tx &&
2062 !rdev->wiphy.available_antennas_rx) ||
2063 !rdev->ops->set_antenna) {
2064 result = -EOPNOTSUPP;
2068 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2069 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2071 /* reject antenna configurations which don't match the
2072 * available antenna masks, except for the "all" mask */
2073 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2074 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
2079 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2080 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
2082 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
2089 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2090 retry_short = nla_get_u8(
2091 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2092 if (retry_short == 0) {
2096 changed |= WIPHY_PARAM_RETRY_SHORT;
2099 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2100 retry_long = nla_get_u8(
2101 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2102 if (retry_long == 0) {
2106 changed |= WIPHY_PARAM_RETRY_LONG;
2109 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2110 frag_threshold = nla_get_u32(
2111 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2112 if (frag_threshold < 256) {
2116 if (frag_threshold != (u32) -1) {
2118 * Fragments (apart from the last one) are required to
2119 * have even length. Make the fragmentation code
2120 * simpler by stripping LSB should someone try to use
2121 * odd threshold value.
2123 frag_threshold &= ~0x1;
2125 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2128 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2129 rts_threshold = nla_get_u32(
2130 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2131 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2134 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2135 coverage_class = nla_get_u8(
2136 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2137 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2141 u8 old_retry_short, old_retry_long;
2142 u32 old_frag_threshold, old_rts_threshold;
2143 u8 old_coverage_class;
2145 if (!rdev->ops->set_wiphy_params) {
2146 result = -EOPNOTSUPP;
2150 old_retry_short = rdev->wiphy.retry_short;
2151 old_retry_long = rdev->wiphy.retry_long;
2152 old_frag_threshold = rdev->wiphy.frag_threshold;
2153 old_rts_threshold = rdev->wiphy.rts_threshold;
2154 old_coverage_class = rdev->wiphy.coverage_class;
2156 if (changed & WIPHY_PARAM_RETRY_SHORT)
2157 rdev->wiphy.retry_short = retry_short;
2158 if (changed & WIPHY_PARAM_RETRY_LONG)
2159 rdev->wiphy.retry_long = retry_long;
2160 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2161 rdev->wiphy.frag_threshold = frag_threshold;
2162 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2163 rdev->wiphy.rts_threshold = rts_threshold;
2164 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2165 rdev->wiphy.coverage_class = coverage_class;
2167 result = rdev_set_wiphy_params(rdev, changed);
2169 rdev->wiphy.retry_short = old_retry_short;
2170 rdev->wiphy.retry_long = old_retry_long;
2171 rdev->wiphy.frag_threshold = old_frag_threshold;
2172 rdev->wiphy.rts_threshold = old_rts_threshold;
2173 rdev->wiphy.coverage_class = old_coverage_class;
2183 static inline u64 wdev_id(struct wireless_dev *wdev)
2185 return (u64)wdev->identifier |
2186 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2189 static int nl80211_send_chandef(struct sk_buff *msg,
2190 struct cfg80211_chan_def *chandef)
2192 WARN_ON(!cfg80211_chandef_valid(chandef));
2194 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2195 chandef->chan->center_freq))
2197 switch (chandef->width) {
2198 case NL80211_CHAN_WIDTH_20_NOHT:
2199 case NL80211_CHAN_WIDTH_20:
2200 case NL80211_CHAN_WIDTH_40:
2201 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2202 cfg80211_get_chandef_type(chandef)))
2208 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2210 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2212 if (chandef->center_freq2 &&
2213 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
2218 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
2219 struct cfg80211_registered_device *rdev,
2220 struct wireless_dev *wdev)
2222 struct net_device *dev = wdev->netdev;
2225 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
2230 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2231 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
2232 goto nla_put_failure;
2234 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2235 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
2236 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
2237 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
2238 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2239 rdev->devlist_generation ^
2240 (cfg80211_rdev_list_generation << 2)))
2241 goto nla_put_failure;
2243 if (rdev->ops->get_channel) {
2245 struct cfg80211_chan_def chandef;
2247 ret = rdev_get_channel(rdev, wdev, &chandef);
2249 if (nl80211_send_chandef(msg, &chandef))
2250 goto nla_put_failure;
2254 if (wdev->ssid_len) {
2255 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2256 goto nla_put_failure;
2259 return genlmsg_end(msg, hdr);
2262 genlmsg_cancel(msg, hdr);
2266 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2270 int wp_start = cb->args[0];
2271 int if_start = cb->args[1];
2272 struct cfg80211_registered_device *rdev;
2273 struct wireless_dev *wdev;
2276 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2277 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
2279 if (wp_idx < wp_start) {
2285 list_for_each_entry(wdev, &rdev->wdev_list, list) {
2286 if (if_idx < if_start) {
2290 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
2291 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2303 cb->args[0] = wp_idx;
2304 cb->args[1] = if_idx;
2309 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2311 struct sk_buff *msg;
2312 struct cfg80211_registered_device *dev = info->user_ptr[0];
2313 struct wireless_dev *wdev = info->user_ptr[1];
2315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2319 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
2325 return genlmsg_reply(msg, info);
2328 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2329 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2330 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2331 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2332 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2333 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2334 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
2337 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2339 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2347 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2348 nla, mntr_flags_policy))
2351 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2353 *mntrflags |= (1<<flag);
2358 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
2359 struct net_device *netdev, u8 use_4addr,
2360 enum nl80211_iftype iftype)
2363 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
2369 case NL80211_IFTYPE_AP_VLAN:
2370 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2373 case NL80211_IFTYPE_STATION:
2374 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2384 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2387 struct vif_params params;
2389 enum nl80211_iftype otype, ntype;
2390 struct net_device *dev = info->user_ptr[1];
2391 u32 _flags, *flags = NULL;
2392 bool change = false;
2394 memset(¶ms, 0, sizeof(params));
2396 otype = ntype = dev->ieee80211_ptr->iftype;
2398 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2399 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2402 if (ntype > NL80211_IFTYPE_MAX)
2406 if (info->attrs[NL80211_ATTR_MESH_ID]) {
2407 struct wireless_dev *wdev = dev->ieee80211_ptr;
2409 if (ntype != NL80211_IFTYPE_MESH_POINT)
2411 if (netif_running(dev))
2415 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2416 IEEE80211_MAX_MESH_ID_LEN);
2417 wdev->mesh_id_up_len =
2418 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2419 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2420 wdev->mesh_id_up_len);
2424 if (info->attrs[NL80211_ATTR_4ADDR]) {
2425 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2427 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
2431 params.use_4addr = -1;
2434 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2435 if (ntype != NL80211_IFTYPE_MONITOR)
2437 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2446 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
2447 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2451 err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms);
2455 if (!err && params.use_4addr != -1)
2456 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2461 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2464 struct vif_params params;
2465 struct wireless_dev *wdev;
2466 struct sk_buff *msg;
2468 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2471 memset(¶ms, 0, sizeof(params));
2473 if (!info->attrs[NL80211_ATTR_IFNAME])
2476 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2477 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2478 if (type > NL80211_IFTYPE_MAX)
2482 if (!rdev->ops->add_virtual_intf ||
2483 !(rdev->wiphy.interface_modes & (1 << type)))
2486 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2487 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2489 if (!is_valid_ether_addr(params.macaddr))
2490 return -EADDRNOTAVAIL;
2493 if (info->attrs[NL80211_ATTR_4ADDR]) {
2494 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2495 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
2500 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2504 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2505 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2508 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
2509 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2512 wdev = rdev_add_virtual_intf(rdev,
2513 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2514 type, err ? NULL : &flags, ¶ms);
2517 return PTR_ERR(wdev);
2521 case NL80211_IFTYPE_MESH_POINT:
2522 if (!info->attrs[NL80211_ATTR_MESH_ID])
2525 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2526 IEEE80211_MAX_MESH_ID_LEN);
2527 wdev->mesh_id_up_len =
2528 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2529 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2530 wdev->mesh_id_up_len);
2533 case NL80211_IFTYPE_P2P_DEVICE:
2535 * P2P Device doesn't have a netdev, so doesn't go
2536 * through the netdev notifier and must be added here
2538 mutex_init(&wdev->mtx);
2539 INIT_LIST_HEAD(&wdev->event_list);
2540 spin_lock_init(&wdev->event_lock);
2541 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2542 spin_lock_init(&wdev->mgmt_registrations_lock);
2544 wdev->identifier = ++rdev->wdev_id;
2545 list_add_rcu(&wdev->list, &rdev->wdev_list);
2546 rdev->devlist_generation++;
2552 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
2558 return genlmsg_reply(msg, info);
2561 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2564 struct wireless_dev *wdev = info->user_ptr[1];
2566 if (!rdev->ops->del_virtual_intf)
2570 * If we remove a wireless device without a netdev then clear
2571 * user_ptr[1] so that nl80211_post_doit won't dereference it
2572 * to check if it needs to do dev_put(). Otherwise it crashes
2573 * since the wdev has been freed, unlike with a netdev where
2574 * we need the dev_put() for the netdev to really be freed.
2577 info->user_ptr[1] = NULL;
2579 return rdev_del_virtual_intf(rdev, wdev);
2582 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2584 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2585 struct net_device *dev = info->user_ptr[1];
2588 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2591 if (!rdev->ops->set_noack_map)
2594 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2596 return rdev_set_noack_map(rdev, dev, noack_map);
2599 struct get_key_cookie {
2600 struct sk_buff *msg;
2605 static void get_key_callback(void *c, struct key_params *params)
2608 struct get_key_cookie *cookie = c;
2611 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2612 params->key_len, params->key)) ||
2614 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2615 params->seq_len, params->seq)) ||
2617 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2619 goto nla_put_failure;
2621 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2623 goto nla_put_failure;
2626 nla_put(cookie->msg, NL80211_KEY_DATA,
2627 params->key_len, params->key)) ||
2629 nla_put(cookie->msg, NL80211_KEY_SEQ,
2630 params->seq_len, params->seq)) ||
2632 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2634 goto nla_put_failure;
2636 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2637 goto nla_put_failure;
2639 nla_nest_end(cookie->msg, key);
2646 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2650 struct net_device *dev = info->user_ptr[1];
2652 const u8 *mac_addr = NULL;
2654 struct get_key_cookie cookie = {
2658 struct sk_buff *msg;
2660 if (info->attrs[NL80211_ATTR_KEY_IDX])
2661 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2666 if (info->attrs[NL80211_ATTR_MAC])
2667 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2669 pairwise = !!mac_addr;
2670 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2671 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2672 if (kt >= NUM_NL80211_KEYTYPES)
2674 if (kt != NL80211_KEYTYPE_GROUP &&
2675 kt != NL80211_KEYTYPE_PAIRWISE)
2677 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2680 if (!rdev->ops->get_key)
2683 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2687 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
2688 NL80211_CMD_NEW_KEY);
2693 cookie.idx = key_idx;
2695 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2696 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2697 goto nla_put_failure;
2699 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2700 goto nla_put_failure;
2702 if (pairwise && mac_addr &&
2703 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2706 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2713 goto nla_put_failure;
2715 genlmsg_end(msg, hdr);
2716 return genlmsg_reply(msg, info);
2725 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2728 struct key_parse key;
2730 struct net_device *dev = info->user_ptr[1];
2732 err = nl80211_parse_key(info, &key);
2739 /* only support setting default key */
2740 if (!key.def && !key.defmgmt)
2743 wdev_lock(dev->ieee80211_ptr);
2746 if (!rdev->ops->set_default_key) {
2751 err = nl80211_key_allowed(dev->ieee80211_ptr);
2755 err = rdev_set_default_key(rdev, dev, key.idx,
2756 key.def_uni, key.def_multi);
2761 #ifdef CONFIG_CFG80211_WEXT
2762 dev->ieee80211_ptr->wext.default_key = key.idx;
2765 if (key.def_uni || !key.def_multi) {
2770 if (!rdev->ops->set_default_mgmt_key) {
2775 err = nl80211_key_allowed(dev->ieee80211_ptr);
2779 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
2783 #ifdef CONFIG_CFG80211_WEXT
2784 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2789 wdev_unlock(dev->ieee80211_ptr);
2794 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2796 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2798 struct net_device *dev = info->user_ptr[1];
2799 struct key_parse key;
2800 const u8 *mac_addr = NULL;
2802 err = nl80211_parse_key(info, &key);
2809 if (info->attrs[NL80211_ATTR_MAC])
2810 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2812 if (key.type == -1) {
2814 key.type = NL80211_KEYTYPE_PAIRWISE;
2816 key.type = NL80211_KEYTYPE_GROUP;
2820 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2821 key.type != NL80211_KEYTYPE_GROUP)
2824 if (!rdev->ops->add_key)
2827 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2828 key.type == NL80211_KEYTYPE_PAIRWISE,
2832 wdev_lock(dev->ieee80211_ptr);
2833 err = nl80211_key_allowed(dev->ieee80211_ptr);
2835 err = rdev_add_key(rdev, dev, key.idx,
2836 key.type == NL80211_KEYTYPE_PAIRWISE,
2838 wdev_unlock(dev->ieee80211_ptr);
2843 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2847 struct net_device *dev = info->user_ptr[1];
2848 u8 *mac_addr = NULL;
2849 struct key_parse key;
2851 err = nl80211_parse_key(info, &key);
2855 if (info->attrs[NL80211_ATTR_MAC])
2856 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2858 if (key.type == -1) {
2860 key.type = NL80211_KEYTYPE_PAIRWISE;
2862 key.type = NL80211_KEYTYPE_GROUP;
2866 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2867 key.type != NL80211_KEYTYPE_GROUP)
2870 if (!rdev->ops->del_key)
2873 wdev_lock(dev->ieee80211_ptr);
2874 err = nl80211_key_allowed(dev->ieee80211_ptr);
2876 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2877 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2881 err = rdev_del_key(rdev, dev, key.idx,
2882 key.type == NL80211_KEYTYPE_PAIRWISE,
2885 #ifdef CONFIG_CFG80211_WEXT
2887 if (key.idx == dev->ieee80211_ptr->wext.default_key)
2888 dev->ieee80211_ptr->wext.default_key = -1;
2889 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
2890 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2893 wdev_unlock(dev->ieee80211_ptr);
2898 /* This function returns an error or the number of nested attributes */
2899 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2901 struct nlattr *attr;
2902 int n_entries = 0, tmp;
2904 nla_for_each_nested(attr, nl_attr, tmp) {
2905 if (nla_len(attr) != ETH_ALEN)
2915 * This function parses ACL information and allocates memory for ACL data.
2916 * On successful return, the calling function is responsible to free the
2917 * ACL buffer returned by this function.
2919 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2920 struct genl_info *info)
2922 enum nl80211_acl_policy acl_policy;
2923 struct nlattr *attr;
2924 struct cfg80211_acl_data *acl;
2925 int i = 0, n_entries, tmp;
2927 if (!wiphy->max_acl_mac_addrs)
2928 return ERR_PTR(-EOPNOTSUPP);
2930 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2931 return ERR_PTR(-EINVAL);
2933 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2934 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2935 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2936 return ERR_PTR(-EINVAL);
2938 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2939 return ERR_PTR(-EINVAL);
2941 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2943 return ERR_PTR(n_entries);
2945 if (n_entries > wiphy->max_acl_mac_addrs)
2946 return ERR_PTR(-ENOTSUPP);
2948 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2951 return ERR_PTR(-ENOMEM);
2953 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2954 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2958 acl->n_acl_entries = n_entries;
2959 acl->acl_policy = acl_policy;
2964 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2967 struct net_device *dev = info->user_ptr[1];
2968 struct cfg80211_acl_data *acl;
2971 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2972 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2975 if (!dev->ieee80211_ptr->beacon_interval)
2978 acl = parse_acl_data(&rdev->wiphy, info);
2980 return PTR_ERR(acl);
2982 err = rdev_set_mac_acl(rdev, dev, acl);
2989 static int nl80211_parse_beacon(struct nlattr *attrs[],
2990 struct cfg80211_beacon_data *bcn)
2992 bool haveinfo = false;
2994 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2995 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2996 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2997 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
3000 memset(bcn, 0, sizeof(*bcn));
3002 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3003 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3004 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
3010 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3011 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3012 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
3019 if (attrs[NL80211_ATTR_IE]) {
3020 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3021 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
3024 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
3025 bcn->proberesp_ies =
3026 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
3027 bcn->proberesp_ies_len =
3028 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
3031 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
3032 bcn->assocresp_ies =
3033 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
3034 bcn->assocresp_ies_len =
3035 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
3038 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3039 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3040 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
3046 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3047 struct cfg80211_ap_settings *params)
3049 struct wireless_dev *wdev;
3052 list_for_each_entry(wdev, &rdev->wdev_list, list) {
3053 if (wdev->iftype != NL80211_IFTYPE_AP &&
3054 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3057 if (!wdev->preset_chandef.chan)
3060 params->chandef = wdev->preset_chandef;
3068 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3069 enum nl80211_auth_type auth_type,
3070 enum nl80211_commands cmd)
3072 if (auth_type > NL80211_AUTHTYPE_MAX)
3076 case NL80211_CMD_AUTHENTICATE:
3077 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3078 auth_type == NL80211_AUTHTYPE_SAE)
3081 case NL80211_CMD_CONNECT:
3082 case NL80211_CMD_START_AP:
3083 /* SAE not supported yet */
3084 if (auth_type == NL80211_AUTHTYPE_SAE)
3092 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3095 struct net_device *dev = info->user_ptr[1];
3096 struct wireless_dev *wdev = dev->ieee80211_ptr;
3097 struct cfg80211_ap_settings params;
3099 u8 radar_detect_width = 0;
3101 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3105 if (!rdev->ops->start_ap)
3108 if (wdev->beacon_interval)
3111 memset(¶ms, 0, sizeof(params));
3113 /* these are required for START_AP */
3114 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3115 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3116 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3119 err = nl80211_parse_beacon(info->attrs, ¶ms.beacon);
3123 params.beacon_interval =
3124 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3125 params.dtim_period =
3126 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3128 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3133 * In theory, some of these attributes should be required here
3134 * but since they were not used when the command was originally
3135 * added, keep them optional for old user space programs to let
3136 * them continue to work with drivers that do not need the
3137 * additional information -- drivers must check!
3139 if (info->attrs[NL80211_ATTR_SSID]) {
3140 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3142 nla_len(info->attrs[NL80211_ATTR_SSID]);
3143 if (params.ssid_len == 0 ||
3144 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3148 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3149 params.hidden_ssid = nla_get_u32(
3150 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3151 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3152 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3153 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3157 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3159 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3160 params.auth_type = nla_get_u32(
3161 info->attrs[NL80211_ATTR_AUTH_TYPE]);
3162 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3163 NL80211_CMD_START_AP))
3166 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3168 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
3169 NL80211_MAX_NR_CIPHER_SUITES);
3173 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3174 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3176 params.inactivity_timeout = nla_get_u16(
3177 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3180 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3183 params.p2p_ctwindow =
3184 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3185 if (params.p2p_ctwindow > 127)
3187 if (params.p2p_ctwindow != 0 &&
3188 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3192 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3195 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3197 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3200 params.p2p_opp_ps = tmp;
3201 if (params.p2p_opp_ps != 0 &&
3202 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3206 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3207 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
3210 } else if (wdev->preset_chandef.chan) {
3211 params.chandef = wdev->preset_chandef;
3212 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
3215 if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef))
3218 err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef);
3222 radar_detect_width = BIT(params.chandef.width);
3223 params.radar_required = true;
3226 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3227 params.chandef.chan,
3229 radar_detect_width);
3233 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3234 params.acl = parse_acl_data(&rdev->wiphy, info);
3235 if (IS_ERR(params.acl))
3236 return PTR_ERR(params.acl);
3239 err = rdev_start_ap(rdev, dev, ¶ms);
3241 wdev->preset_chandef = params.chandef;
3242 wdev->beacon_interval = params.beacon_interval;
3243 wdev->channel = params.chandef.chan;
3244 wdev->ssid_len = params.ssid_len;
3245 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
3253 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3256 struct net_device *dev = info->user_ptr[1];
3257 struct wireless_dev *wdev = dev->ieee80211_ptr;
3258 struct cfg80211_beacon_data params;
3261 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3262 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3265 if (!rdev->ops->change_beacon)
3268 if (!wdev->beacon_interval)
3271 err = nl80211_parse_beacon(info->attrs, ¶ms);
3275 return rdev_change_beacon(rdev, dev, ¶ms);
3278 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
3280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3281 struct net_device *dev = info->user_ptr[1];
3283 return cfg80211_stop_ap(rdev, dev);
3286 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3287 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3288 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3289 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
3290 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
3291 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
3292 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
3295 static int parse_station_flags(struct genl_info *info,
3296 enum nl80211_iftype iftype,
3297 struct station_parameters *params)
3299 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
3304 * Try parsing the new attribute first so userspace
3305 * can specify both for older kernels.
3307 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3309 struct nl80211_sta_flag_update *sta_flags;
3311 sta_flags = nla_data(nla);
3312 params->sta_flags_mask = sta_flags->mask;
3313 params->sta_flags_set = sta_flags->set;
3314 params->sta_flags_set &= params->sta_flags_mask;
3315 if ((params->sta_flags_mask |
3316 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3321 /* if present, parse the old attribute */
3323 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
3327 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3328 nla, sta_flags_policy))
3332 * Only allow certain flags for interface types so that
3333 * other attributes are silently ignored. Remember that
3334 * this is backward compatibility code with old userspace
3335 * and shouldn't be hit in other cases anyway.
3338 case NL80211_IFTYPE_AP:
3339 case NL80211_IFTYPE_AP_VLAN:
3340 case NL80211_IFTYPE_P2P_GO:
3341 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3342 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3343 BIT(NL80211_STA_FLAG_WME) |
3344 BIT(NL80211_STA_FLAG_MFP);
3346 case NL80211_IFTYPE_P2P_CLIENT:
3347 case NL80211_IFTYPE_STATION:
3348 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3349 BIT(NL80211_STA_FLAG_TDLS_PEER);
3351 case NL80211_IFTYPE_MESH_POINT:
3352 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3353 BIT(NL80211_STA_FLAG_MFP) |
3354 BIT(NL80211_STA_FLAG_AUTHORIZED);
3359 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3361 params->sta_flags_set |= (1<<flag);
3363 /* no longer support new API additions in old API */
3364 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3372 static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3375 struct nlattr *rate;
3379 rate = nla_nest_start(msg, attr);
3383 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3384 bitrate = cfg80211_calculate_bitrate(info);
3385 /* report 16-bit bitrate only if we can */
3386 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
3388 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3390 if (bitrate_compat > 0 &&
3391 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3394 if (info->flags & RATE_INFO_FLAGS_MCS) {
3395 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3397 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3398 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3400 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3401 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3403 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3404 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3406 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3408 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3409 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3411 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3412 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3414 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3415 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3417 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3418 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3420 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3421 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3425 nla_nest_end(msg, rate);
3429 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3438 attr = nla_nest_start(msg, id);
3442 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3443 if (!(mask & BIT(i)))
3446 if (nla_put_u8(msg, i, signal[i]))
3450 nla_nest_end(msg, attr);
3455 static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
3457 struct cfg80211_registered_device *rdev,
3458 struct net_device *dev,
3459 const u8 *mac_addr, struct station_info *sinfo)
3462 struct nlattr *sinfoattr, *bss_param;
3464 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
3468 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3469 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3470 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3471 goto nla_put_failure;
3473 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3475 goto nla_put_failure;
3476 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3477 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3478 sinfo->connected_time))
3479 goto nla_put_failure;
3480 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3481 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3482 sinfo->inactive_time))
3483 goto nla_put_failure;
3484 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3485 STATION_INFO_RX_BYTES64)) &&
3486 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
3487 (u32)sinfo->rx_bytes))
3488 goto nla_put_failure;
3489 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3490 STATION_INFO_TX_BYTES64)) &&
3491 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3492 (u32)sinfo->tx_bytes))
3493 goto nla_put_failure;
3494 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3495 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
3497 goto nla_put_failure;
3498 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3499 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
3501 goto nla_put_failure;
3502 if ((sinfo->filled & STATION_INFO_LLID) &&
3503 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3504 goto nla_put_failure;
3505 if ((sinfo->filled & STATION_INFO_PLID) &&
3506 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3507 goto nla_put_failure;
3508 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3509 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3510 sinfo->plink_state))
3511 goto nla_put_failure;
3512 switch (rdev->wiphy.signal_type) {
3513 case CFG80211_SIGNAL_TYPE_MBM:
3514 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3515 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3517 goto nla_put_failure;
3518 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3519 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3521 goto nla_put_failure;
3526 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3527 if (!nl80211_put_signal(msg, sinfo->chains,
3528 sinfo->chain_signal,
3529 NL80211_STA_INFO_CHAIN_SIGNAL))
3530 goto nla_put_failure;
3532 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3533 if (!nl80211_put_signal(msg, sinfo->chains,
3534 sinfo->chain_signal_avg,
3535 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3536 goto nla_put_failure;
3538 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
3539 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3540 NL80211_STA_INFO_TX_BITRATE))
3541 goto nla_put_failure;
3543 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3544 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3545 NL80211_STA_INFO_RX_BITRATE))
3546 goto nla_put_failure;
3548 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3549 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3551 goto nla_put_failure;
3552 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3553 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3555 goto nla_put_failure;
3556 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3557 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3559 goto nla_put_failure;
3560 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3561 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3563 goto nla_put_failure;
3564 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3565 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3566 sinfo->beacon_loss_count))
3567 goto nla_put_failure;
3568 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3569 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3571 goto nla_put_failure;
3572 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3573 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3575 goto nla_put_failure;
3576 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3577 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3579 goto nla_put_failure;
3580 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3581 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3583 goto nla_put_failure;
3585 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3586 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3587 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3588 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3589 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3590 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3591 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3592 sinfo->bss_param.dtim_period) ||
3593 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3594 sinfo->bss_param.beacon_interval))
3595 goto nla_put_failure;
3597 nla_nest_end(msg, bss_param);
3599 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3600 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3601 sizeof(struct nl80211_sta_flag_update),
3603 goto nla_put_failure;
3604 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3605 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3607 goto nla_put_failure;
3608 nla_nest_end(msg, sinfoattr);
3610 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3611 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3612 sinfo->assoc_req_ies))
3613 goto nla_put_failure;
3615 return genlmsg_end(msg, hdr);
3618 genlmsg_cancel(msg, hdr);
3622 static int nl80211_dump_station(struct sk_buff *skb,
3623 struct netlink_callback *cb)
3625 struct station_info sinfo;
3626 struct cfg80211_registered_device *dev;
3627 struct wireless_dev *wdev;
3628 u8 mac_addr[ETH_ALEN];
3629 int sta_idx = cb->args[2];
3632 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
3636 if (!wdev->netdev) {
3641 if (!dev->ops->dump_station) {
3647 memset(&sinfo, 0, sizeof(sinfo));
3648 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
3655 if (nl80211_send_station(skb,
3656 NETLINK_CB(cb->skb).portid,
3657 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3658 dev, wdev->netdev, mac_addr,
3667 cb->args[2] = sta_idx;
3670 nl80211_finish_wdev_dump(dev);
3675 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3678 struct net_device *dev = info->user_ptr[1];
3679 struct station_info sinfo;
3680 struct sk_buff *msg;
3681 u8 *mac_addr = NULL;
3684 memset(&sinfo, 0, sizeof(sinfo));
3686 if (!info->attrs[NL80211_ATTR_MAC])
3689 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3691 if (!rdev->ops->get_station)
3694 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
3698 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3702 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
3703 rdev, dev, mac_addr, &sinfo) < 0) {
3708 return genlmsg_reply(msg, info);
3711 int cfg80211_check_station_change(struct wiphy *wiphy,
3712 struct station_parameters *params,
3713 enum cfg80211_station_type statype)
3715 if (params->listen_interval != -1)
3720 /* When you run into this, adjust the code below for the new flag */
3721 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3724 case CFG80211_STA_MESH_PEER_KERNEL:
3725 case CFG80211_STA_MESH_PEER_USER:
3727 * No ignoring the TDLS flag here -- the userspace mesh
3728 * code doesn't have the bug of including TDLS in the
3731 if (params->sta_flags_mask &
3732 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3733 BIT(NL80211_STA_FLAG_MFP) |
3734 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3737 case CFG80211_STA_TDLS_PEER_SETUP:
3738 case CFG80211_STA_TDLS_PEER_ACTIVE:
3739 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3741 /* ignore since it can't change */
3742 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3745 /* disallow mesh-specific things */
3746 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3748 if (params->local_pm)
3750 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3754 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3755 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3756 /* TDLS can't be set, ... */
3757 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3760 * ... but don't bother the driver with it. This works around
3761 * a hostapd/wpa_supplicant issue -- it always includes the
3762 * TLDS_PEER flag in the mask even for AP mode.
3764 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3767 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3768 /* reject other things that can't change */
3769 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3771 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3773 if (params->supported_rates)
3775 if (params->ext_capab || params->ht_capa || params->vht_capa)
3779 if (statype != CFG80211_STA_AP_CLIENT) {
3785 case CFG80211_STA_AP_MLME_CLIENT:
3786 /* Use this only for authorizing/unauthorizing a station */
3787 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3790 case CFG80211_STA_AP_CLIENT:
3791 /* accept only the listed bits */
3792 if (params->sta_flags_mask &
3793 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3794 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3795 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3796 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3797 BIT(NL80211_STA_FLAG_WME) |
3798 BIT(NL80211_STA_FLAG_MFP)))
3801 /* but authenticated/associated only if driver handles it */
3802 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3803 params->sta_flags_mask &
3804 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3805 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3808 case CFG80211_STA_IBSS:
3809 case CFG80211_STA_AP_STA:
3810 /* reject any changes other than AUTHORIZED */
3811 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3814 case CFG80211_STA_TDLS_PEER_SETUP:
3815 /* reject any changes other than AUTHORIZED or WME */
3816 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3817 BIT(NL80211_STA_FLAG_WME)))
3819 /* force (at least) rates when authorizing */
3820 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3821 !params->supported_rates)
3824 case CFG80211_STA_TDLS_PEER_ACTIVE:
3825 /* reject any changes */
3827 case CFG80211_STA_MESH_PEER_KERNEL:
3828 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3831 case CFG80211_STA_MESH_PEER_USER:
3832 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3839 EXPORT_SYMBOL(cfg80211_check_station_change);
3842 * Get vlan interface making sure it is running and on the right wiphy.
3844 static struct net_device *get_vlan(struct genl_info *info,
3845 struct cfg80211_registered_device *rdev)
3847 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
3848 struct net_device *v;
3854 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3856 return ERR_PTR(-ENODEV);
3858 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3863 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3864 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3865 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3870 if (!netif_running(v)) {
3878 return ERR_PTR(ret);
3881 static struct nla_policy
3882 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3883 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3884 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3887 static int nl80211_parse_sta_wme(struct genl_info *info,
3888 struct station_parameters *params)
3890 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3894 /* parse WME attributes if present */
3895 if (!info->attrs[NL80211_ATTR_STA_WME])
3898 nla = info->attrs[NL80211_ATTR_STA_WME];
3899 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3900 nl80211_sta_wme_policy);
3904 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3905 params->uapsd_queues = nla_get_u8(
3906 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3907 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3910 if (tb[NL80211_STA_WME_MAX_SP])
3911 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3913 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3916 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3921 static int nl80211_parse_sta_channel_info(struct genl_info *info,
3922 struct station_parameters *params)
3924 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3925 params->supported_channels =
3926 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3927 params->supported_channels_len =
3928 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3930 * Need to include at least one (first channel, number of
3931 * channels) tuple for each subband, and must have proper
3932 * tuples for the rest of the data as well.
3934 if (params->supported_channels_len < 2)
3936 if (params->supported_channels_len % 2)
3940 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3941 params->supported_oper_classes =
3942 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3943 params->supported_oper_classes_len =
3944 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3946 * The value of the Length field of the Supported Operating
3947 * Classes element is between 2 and 253.
3949 if (params->supported_oper_classes_len < 2 ||
3950 params->supported_oper_classes_len > 253)
3956 static int nl80211_set_station_tdls(struct genl_info *info,
3957 struct station_parameters *params)
3960 /* Dummy STA entry gets updated once the peer capabilities are known */
3961 if (info->attrs[NL80211_ATTR_PEER_AID])
3962 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
3963 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3965 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3966 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3968 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3970 err = nl80211_parse_sta_channel_info(info, params);
3974 return nl80211_parse_sta_wme(info, params);
3977 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3980 struct net_device *dev = info->user_ptr[1];
3981 struct station_parameters params;
3985 memset(¶ms, 0, sizeof(params));
3987 params.listen_interval = -1;
3989 if (!rdev->ops->change_station)
3992 if (info->attrs[NL80211_ATTR_STA_AID])
3995 if (!info->attrs[NL80211_ATTR_MAC])
3998 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4000 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4001 params.supported_rates =
4002 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4003 params.supported_rates_len =
4004 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4007 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4009 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4010 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4013 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4015 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4016 params.ext_capab_len =
4017 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4020 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4023 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
4026 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
4027 params.plink_action =
4028 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4029 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4033 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
4034 params.plink_state =
4035 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4036 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4038 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4041 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4042 enum nl80211_mesh_power_mode pm = nla_get_u32(
4043 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4045 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4046 pm > NL80211_MESH_POWER_MAX)
4049 params.local_pm = pm;
4052 /* Include parameters for TDLS peer (will check later) */
4053 err = nl80211_set_station_tdls(info, ¶ms);
4057 params.vlan = get_vlan(info, rdev);
4058 if (IS_ERR(params.vlan))
4059 return PTR_ERR(params.vlan);
4061 switch (dev->ieee80211_ptr->iftype) {
4062 case NL80211_IFTYPE_AP:
4063 case NL80211_IFTYPE_AP_VLAN:
4064 case NL80211_IFTYPE_P2P_GO:
4065 case NL80211_IFTYPE_P2P_CLIENT:
4066 case NL80211_IFTYPE_STATION:
4067 case NL80211_IFTYPE_ADHOC:
4068 case NL80211_IFTYPE_MESH_POINT:
4075 /* driver will call cfg80211_check_station_change() */
4076 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
4080 dev_put(params.vlan);
4085 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4089 struct net_device *dev = info->user_ptr[1];
4090 struct station_parameters params;
4091 u8 *mac_addr = NULL;
4093 memset(¶ms, 0, sizeof(params));
4095 if (!rdev->ops->add_station)
4098 if (!info->attrs[NL80211_ATTR_MAC])
4101 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4104 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4107 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4108 !info->attrs[NL80211_ATTR_PEER_AID])
4111 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4112 params.supported_rates =
4113 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4114 params.supported_rates_len =
4115 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4116 params.listen_interval =
4117 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4119 if (info->attrs[NL80211_ATTR_PEER_AID])
4120 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
4122 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
4123 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4126 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4128 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4129 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4132 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4134 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4135 params.ext_capab_len =
4136 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4139 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4141 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4143 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4145 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4147 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
4148 params.plink_action =
4149 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4150 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4154 err = nl80211_parse_sta_channel_info(info, ¶ms);
4158 err = nl80211_parse_sta_wme(info, ¶ms);
4162 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
4165 /* When you run into this, adjust the code below for the new flag */
4166 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4168 switch (dev->ieee80211_ptr->iftype) {
4169 case NL80211_IFTYPE_AP:
4170 case NL80211_IFTYPE_AP_VLAN:
4171 case NL80211_IFTYPE_P2P_GO:
4172 /* ignore WME attributes if iface/sta is not capable */
4173 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4174 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4175 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4177 /* TDLS peers cannot be added */
4178 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4179 info->attrs[NL80211_ATTR_PEER_AID])
4181 /* but don't bother the driver with it */
4182 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4184 /* allow authenticated/associated only if driver handles it */
4185 if (!(rdev->wiphy.features &
4186 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4187 params.sta_flags_mask &
4188 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4189 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4192 /* must be last in here for error handling */
4193 params.vlan = get_vlan(info, rdev);
4194 if (IS_ERR(params.vlan))
4195 return PTR_ERR(params.vlan);
4197 case NL80211_IFTYPE_MESH_POINT:
4198 /* ignore uAPSD data */
4199 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4201 /* associated is disallowed */
4202 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4204 /* TDLS peers cannot be added */
4205 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4206 info->attrs[NL80211_ATTR_PEER_AID])
4209 case NL80211_IFTYPE_STATION:
4210 case NL80211_IFTYPE_P2P_CLIENT:
4211 /* ignore uAPSD data */
4212 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4214 /* these are disallowed */
4215 if (params.sta_flags_mask &
4216 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4217 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
4219 /* Only TDLS peers can be added */
4220 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4222 /* Can only add if TDLS ... */
4223 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4225 /* ... with external setup is supported */
4226 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4229 * Older wpa_supplicant versions always mark the TDLS peer
4230 * as authorized, but it shouldn't yet be.
4232 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
4238 /* be aware of params.vlan when changing code here */
4240 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
4243 dev_put(params.vlan);
4247 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4250 struct net_device *dev = info->user_ptr[1];
4251 u8 *mac_addr = NULL;
4253 if (info->attrs[NL80211_ATTR_MAC])
4254 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4256 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4257 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4258 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
4259 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4262 if (!rdev->ops->del_station)
4265 return rdev_del_station(rdev, dev, mac_addr);
4268 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
4269 int flags, struct net_device *dev,
4270 u8 *dst, u8 *next_hop,
4271 struct mpath_info *pinfo)
4274 struct nlattr *pinfoattr;
4276 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
4280 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4281 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4282 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4283 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4284 goto nla_put_failure;
4286 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4288 goto nla_put_failure;
4289 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4290 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4292 goto nla_put_failure;
4293 if (((pinfo->filled & MPATH_INFO_SN) &&
4294 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4295 ((pinfo->filled & MPATH_INFO_METRIC) &&
4296 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4298 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4299 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4301 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4302 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4304 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4305 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4306 pinfo->discovery_timeout)) ||
4307 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4308 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4309 pinfo->discovery_retries)))
4310 goto nla_put_failure;
4312 nla_nest_end(msg, pinfoattr);
4314 return genlmsg_end(msg, hdr);
4317 genlmsg_cancel(msg, hdr);
4321 static int nl80211_dump_mpath(struct sk_buff *skb,
4322 struct netlink_callback *cb)
4324 struct mpath_info pinfo;
4325 struct cfg80211_registered_device *dev;
4326 struct wireless_dev *wdev;
4328 u8 next_hop[ETH_ALEN];
4329 int path_idx = cb->args[2];
4332 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
4336 if (!dev->ops->dump_mpath) {
4341 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4347 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4354 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4355 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4356 wdev->netdev, dst, next_hop,
4365 cb->args[2] = path_idx;
4368 nl80211_finish_wdev_dump(dev);
4372 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4376 struct net_device *dev = info->user_ptr[1];
4377 struct mpath_info pinfo;
4378 struct sk_buff *msg;
4380 u8 next_hop[ETH_ALEN];
4382 memset(&pinfo, 0, sizeof(pinfo));
4384 if (!info->attrs[NL80211_ATTR_MAC])
4387 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4389 if (!rdev->ops->get_mpath)
4392 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4395 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
4399 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4403 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4404 dev, dst, next_hop, &pinfo) < 0) {
4409 return genlmsg_reply(msg, info);
4412 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4415 struct net_device *dev = info->user_ptr[1];
4417 u8 *next_hop = NULL;
4419 if (!info->attrs[NL80211_ATTR_MAC])
4422 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4425 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4426 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4428 if (!rdev->ops->change_mpath)
4431 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4434 return rdev_change_mpath(rdev, dev, dst, next_hop);
4437 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4440 struct net_device *dev = info->user_ptr[1];
4442 u8 *next_hop = NULL;
4444 if (!info->attrs[NL80211_ATTR_MAC])
4447 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4450 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4451 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4453 if (!rdev->ops->add_mpath)
4456 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4459 return rdev_add_mpath(rdev, dev, dst, next_hop);
4462 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4465 struct net_device *dev = info->user_ptr[1];
4468 if (info->attrs[NL80211_ATTR_MAC])
4469 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4471 if (!rdev->ops->del_mpath)
4474 return rdev_del_mpath(rdev, dev, dst);
4477 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4480 struct net_device *dev = info->user_ptr[1];
4481 struct bss_parameters params;
4483 memset(¶ms, 0, sizeof(params));
4484 /* default to not changing parameters */
4485 params.use_cts_prot = -1;
4486 params.use_short_preamble = -1;
4487 params.use_short_slot_time = -1;
4488 params.ap_isolate = -1;
4489 params.ht_opmode = -1;
4490 params.p2p_ctwindow = -1;
4491 params.p2p_opp_ps = -1;
4493 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4494 params.use_cts_prot =
4495 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4496 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4497 params.use_short_preamble =
4498 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4499 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4500 params.use_short_slot_time =
4501 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
4502 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4503 params.basic_rates =
4504 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4505 params.basic_rates_len =
4506 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4508 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4509 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
4510 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4512 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
4514 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4515 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4517 params.p2p_ctwindow =
4518 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4519 if (params.p2p_ctwindow < 0)
4521 if (params.p2p_ctwindow != 0 &&
4522 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4526 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4529 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4531 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4534 params.p2p_opp_ps = tmp;
4535 if (params.p2p_opp_ps &&
4536 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4540 if (!rdev->ops->change_bss)
4543 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4544 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4547 return rdev_change_bss(rdev, dev, ¶ms);
4550 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
4551 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4552 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4553 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4554 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4555 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4556 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4559 static int parse_reg_rule(struct nlattr *tb[],
4560 struct ieee80211_reg_rule *reg_rule)
4562 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
4563 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
4565 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4567 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4569 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4571 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4573 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4576 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4578 freq_range->start_freq_khz =
4579 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4580 freq_range->end_freq_khz =
4581 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4582 freq_range->max_bandwidth_khz =
4583 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4585 power_rule->max_eirp =
4586 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4588 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4589 power_rule->max_antenna_gain =
4590 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4595 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4599 enum nl80211_user_reg_hint_type user_reg_hint_type;
4602 * You should only get this when cfg80211 hasn't yet initialized
4603 * completely when built-in to the kernel right between the time
4604 * window between nl80211_init() and regulatory_init(), if that is
4607 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
4608 return -EINPROGRESS;
4610 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4613 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4615 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4616 user_reg_hint_type =
4617 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4619 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4621 switch (user_reg_hint_type) {
4622 case NL80211_USER_REG_HINT_USER:
4623 case NL80211_USER_REG_HINT_CELL_BASE:
4629 r = regulatory_hint_user(data, user_reg_hint_type);
4634 static int nl80211_get_mesh_config(struct sk_buff *skb,
4635 struct genl_info *info)
4637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4638 struct net_device *dev = info->user_ptr[1];
4639 struct wireless_dev *wdev = dev->ieee80211_ptr;
4640 struct mesh_config cur_params;
4643 struct nlattr *pinfoattr;
4644 struct sk_buff *msg;
4646 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4649 if (!rdev->ops->get_mesh_config)
4653 /* If not connected, get default parameters */
4654 if (!wdev->mesh_id_len)
4655 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4657 err = rdev_get_mesh_config(rdev, dev, &cur_params);
4663 /* Draw up a netlink message to send back */
4664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4667 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4668 NL80211_CMD_GET_MESH_CONFIG);
4671 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
4673 goto nla_put_failure;
4674 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4675 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4676 cur_params.dot11MeshRetryTimeout) ||
4677 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4678 cur_params.dot11MeshConfirmTimeout) ||
4679 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4680 cur_params.dot11MeshHoldingTimeout) ||
4681 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4682 cur_params.dot11MeshMaxPeerLinks) ||
4683 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4684 cur_params.dot11MeshMaxRetries) ||
4685 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4686 cur_params.dot11MeshTTL) ||
4687 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4688 cur_params.element_ttl) ||
4689 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4690 cur_params.auto_open_plinks) ||
4691 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4692 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
4693 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4694 cur_params.dot11MeshHWMPmaxPREQretries) ||
4695 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4696 cur_params.path_refresh_time) ||
4697 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4698 cur_params.min_discovery_timeout) ||
4699 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4700 cur_params.dot11MeshHWMPactivePathTimeout) ||
4701 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4702 cur_params.dot11MeshHWMPpreqMinInterval) ||
4703 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4704 cur_params.dot11MeshHWMPperrMinInterval) ||
4705 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4706 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4707 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4708 cur_params.dot11MeshHWMPRootMode) ||
4709 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4710 cur_params.dot11MeshHWMPRannInterval) ||
4711 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4712 cur_params.dot11MeshGateAnnouncementProtocol) ||
4713 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4714 cur_params.dot11MeshForwarding) ||
4715 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
4716 cur_params.rssi_threshold) ||
4717 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
4718 cur_params.ht_opmode) ||
4719 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4720 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4721 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4722 cur_params.dot11MeshHWMProotInterval) ||
4723 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4724 cur_params.dot11MeshHWMPconfirmationInterval) ||
4725 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4726 cur_params.power_mode) ||
4727 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4728 cur_params.dot11MeshAwakeWindowDuration) ||
4729 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4730 cur_params.plink_timeout))
4731 goto nla_put_failure;
4732 nla_nest_end(msg, pinfoattr);
4733 genlmsg_end(msg, hdr);
4734 return genlmsg_reply(msg, info);
4737 genlmsg_cancel(msg, hdr);
4743 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
4744 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4745 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4746 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4747 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4748 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4749 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
4750 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
4751 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
4752 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
4753 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4754 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4755 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4756 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4757 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
4758 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
4759 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
4760 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
4761 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
4762 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
4763 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
4764 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4765 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
4766 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4767 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
4768 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
4769 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4770 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
4771 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
4774 static const struct nla_policy
4775 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
4776 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
4777 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4778 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
4779 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
4780 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
4781 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
4782 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
4783 .len = IEEE80211_MAX_DATA_LEN },
4784 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
4787 static int nl80211_parse_mesh_config(struct genl_info *info,
4788 struct mesh_config *cfg,
4791 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
4794 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4797 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4799 cfg->param = fn(tb[attr]); \
4800 mask |= (1 << (attr - 1)); \
4805 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
4807 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
4808 info->attrs[NL80211_ATTR_MESH_CONFIG],
4809 nl80211_meshconf_params_policy))
4812 /* This makes sure that there aren't more than 32 mesh config
4813 * parameters (otherwise our bitfield scheme would not work.) */
4814 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4816 /* Fill in the params struct */
4817 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
4818 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4820 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
4821 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4823 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
4824 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
4827 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4829 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
4830 mask, NL80211_MESHCONF_MAX_RETRIES,
4832 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
4833 mask, NL80211_MESHCONF_TTL, nla_get_u8);
4834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
4835 mask, NL80211_MESHCONF_ELEMENT_TTL,
4837 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
4838 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4840 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4842 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4844 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
4845 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4847 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
4848 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
4851 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4855 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
4859 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4861 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
4863 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4865 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4866 dot11MeshHWMPnetDiameterTraversalTime,
4868 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4870 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4871 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4873 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4874 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4876 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4877 dot11MeshGateAnnouncementProtocol, 0, 1,
4878 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4880 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
4881 mask, NL80211_MESHCONF_FORWARDING,
4883 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
4884 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4886 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
4887 mask, NL80211_MESHCONF_HT_OPMODE,
4889 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
4891 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4893 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
4894 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4896 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4897 dot11MeshHWMPconfirmationInterval,
4899 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4901 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4902 NL80211_MESH_POWER_ACTIVE,
4903 NL80211_MESH_POWER_MAX,
4904 mask, NL80211_MESHCONF_POWER_MODE,
4906 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4908 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
4909 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4910 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4917 #undef FILL_IN_MESH_PARAM_IF_SET
4920 static int nl80211_parse_mesh_setup(struct genl_info *info,
4921 struct mesh_setup *setup)
4923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4924 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4926 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4928 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4929 info->attrs[NL80211_ATTR_MESH_SETUP],
4930 nl80211_mesh_setup_params_policy))
4933 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4934 setup->sync_method =
4935 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4936 IEEE80211_SYNC_METHOD_VENDOR :
4937 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4939 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4940 setup->path_sel_proto =
4941 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4942 IEEE80211_PATH_PROTOCOL_VENDOR :
4943 IEEE80211_PATH_PROTOCOL_HWMP;
4945 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4946 setup->path_metric =
4947 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4948 IEEE80211_PATH_METRIC_VENDOR :
4949 IEEE80211_PATH_METRIC_AIRTIME;
4952 if (tb[NL80211_MESH_SETUP_IE]) {
4953 struct nlattr *ieattr =
4954 tb[NL80211_MESH_SETUP_IE];
4955 if (!is_valid_ie_attr(ieattr))
4957 setup->ie = nla_data(ieattr);
4958 setup->ie_len = nla_len(ieattr);
4960 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4961 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4963 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
4964 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4965 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
4966 if (setup->is_secure)
4967 setup->user_mpm = true;
4969 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4970 if (!setup->user_mpm)
4973 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4979 static int nl80211_update_mesh_config(struct sk_buff *skb,
4980 struct genl_info *info)
4982 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4983 struct net_device *dev = info->user_ptr[1];
4984 struct wireless_dev *wdev = dev->ieee80211_ptr;
4985 struct mesh_config cfg;
4989 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4992 if (!rdev->ops->update_mesh_config)
4995 err = nl80211_parse_mesh_config(info, &cfg, &mask);
5000 if (!wdev->mesh_id_len)
5004 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
5011 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5013 const struct ieee80211_regdomain *regdom;
5014 struct sk_buff *msg;
5016 struct nlattr *nl_reg_rules;
5019 if (!cfg80211_regdomain)
5022 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5026 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5027 NL80211_CMD_GET_REG);
5031 if (reg_last_request_cell_base() &&
5032 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5033 NL80211_USER_REG_HINT_CELL_BASE))
5034 goto nla_put_failure;
5037 regdom = rcu_dereference(cfg80211_regdomain);
5039 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5040 (regdom->dfs_region &&
5041 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5042 goto nla_put_failure_rcu;
5044 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5046 goto nla_put_failure_rcu;
5048 for (i = 0; i < regdom->n_reg_rules; i++) {
5049 struct nlattr *nl_reg_rule;
5050 const struct ieee80211_reg_rule *reg_rule;
5051 const struct ieee80211_freq_range *freq_range;
5052 const struct ieee80211_power_rule *power_rule;
5054 reg_rule = ®dom->reg_rules[i];
5055 freq_range = ®_rule->freq_range;
5056 power_rule = ®_rule->power_rule;
5058 nl_reg_rule = nla_nest_start(msg, i);
5060 goto nla_put_failure_rcu;
5062 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5064 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5065 freq_range->start_freq_khz) ||
5066 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5067 freq_range->end_freq_khz) ||
5068 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5069 freq_range->max_bandwidth_khz) ||
5070 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5071 power_rule->max_antenna_gain) ||
5072 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5073 power_rule->max_eirp))
5074 goto nla_put_failure_rcu;
5076 nla_nest_end(msg, nl_reg_rule);
5080 nla_nest_end(msg, nl_reg_rules);
5082 genlmsg_end(msg, hdr);
5083 return genlmsg_reply(msg, info);
5085 nla_put_failure_rcu:
5088 genlmsg_cancel(msg, hdr);
5094 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5096 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5097 struct nlattr *nl_reg_rule;
5098 char *alpha2 = NULL;
5099 int rem_reg_rules = 0, r = 0;
5100 u32 num_rules = 0, rule_idx = 0, size_of_regd;
5102 struct ieee80211_regdomain *rd = NULL;
5104 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5107 if (!info->attrs[NL80211_ATTR_REG_RULES])
5110 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5112 if (info->attrs[NL80211_ATTR_DFS_REGION])
5113 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5115 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
5118 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
5122 size_of_regd = sizeof(struct ieee80211_regdomain) +
5123 num_rules * sizeof(struct ieee80211_reg_rule);
5125 rd = kzalloc(size_of_regd, GFP_KERNEL);
5129 rd->n_reg_rules = num_rules;
5130 rd->alpha2[0] = alpha2[0];
5131 rd->alpha2[1] = alpha2[1];
5134 * Disable DFS master mode if the DFS region was
5135 * not supported or known on this kernel.
5137 if (reg_supported_dfs_region(dfs_region))
5138 rd->dfs_region = dfs_region;
5140 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
5142 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5143 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5145 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5151 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5158 /* set_regdom took ownership */
5166 static int validate_scan_freqs(struct nlattr *freqs)
5168 struct nlattr *attr1, *attr2;
5169 int n_channels = 0, tmp1, tmp2;
5171 nla_for_each_nested(attr1, freqs, tmp1) {
5174 * Some hardware has a limited channel list for
5175 * scanning, and it is pretty much nonsensical
5176 * to scan for a channel twice, so disallow that
5177 * and don't require drivers to check that the
5178 * channel list they get isn't longer than what
5179 * they can scan, as long as they can scan all
5180 * the channels they registered at once.
5182 nla_for_each_nested(attr2, freqs, tmp2)
5183 if (attr1 != attr2 &&
5184 nla_get_u32(attr1) == nla_get_u32(attr2))
5191 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5194 struct wireless_dev *wdev = info->user_ptr[1];
5195 struct cfg80211_scan_request *request;
5196 struct nlattr *attr;
5197 struct wiphy *wiphy;
5198 int err, tmp, n_ssids = 0, n_channels, i;
5201 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5204 wiphy = &rdev->wiphy;
5206 if (!rdev->ops->scan)
5209 if (rdev->scan_req) {
5214 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5215 n_channels = validate_scan_freqs(
5216 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5222 enum ieee80211_band band;
5225 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5226 if (wiphy->bands[band])
5227 n_channels += wiphy->bands[band]->n_channels;
5230 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5231 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5234 if (n_ssids > wiphy->max_scan_ssids) {
5239 if (info->attrs[NL80211_ATTR_IE])
5240 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5244 if (ie_len > wiphy->max_scan_ie_len) {
5249 request = kzalloc(sizeof(*request)
5250 + sizeof(*request->ssids) * n_ssids
5251 + sizeof(*request->channels) * n_channels
5252 + ie_len, GFP_KERNEL);
5259 request->ssids = (void *)&request->channels[n_channels];
5260 request->n_ssids = n_ssids;
5263 request->ie = (void *)(request->ssids + n_ssids);
5265 request->ie = (void *)(request->channels + n_channels);
5269 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5270 /* user specified, bail out if channel not found */
5271 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
5272 struct ieee80211_channel *chan;
5274 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5281 /* ignore disabled channels */
5282 if (chan->flags & IEEE80211_CHAN_DISABLED)
5285 request->channels[i] = chan;
5289 enum ieee80211_band band;
5292 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5294 if (!wiphy->bands[band])
5296 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5297 struct ieee80211_channel *chan;
5299 chan = &wiphy->bands[band]->channels[j];
5301 if (chan->flags & IEEE80211_CHAN_DISABLED)
5304 request->channels[i] = chan;
5315 request->n_channels = i;
5318 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5319 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
5320 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
5324 request->ssids[i].ssid_len = nla_len(attr);
5325 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
5330 if (info->attrs[NL80211_ATTR_IE]) {
5331 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5332 memcpy((void *)request->ie,
5333 nla_data(info->attrs[NL80211_ATTR_IE]),
5337 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
5338 if (wiphy->bands[i])
5340 (1 << wiphy->bands[i]->n_bitrates) - 1;
5342 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5343 nla_for_each_nested(attr,
5344 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5346 enum ieee80211_band band = nla_type(attr);
5348 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
5352 err = ieee80211_get_ratemask(wiphy->bands[band],
5355 &request->rates[band]);
5361 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
5362 request->flags = nla_get_u32(
5363 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
5364 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5365 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5366 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5367 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
5374 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5376 request->wdev = wdev;
5377 request->wiphy = &rdev->wiphy;
5378 request->scan_start = jiffies;
5380 rdev->scan_req = request;
5381 err = rdev_scan(rdev, request);
5384 nl80211_send_scan_start(rdev, wdev);
5386 dev_hold(wdev->netdev);
5389 rdev->scan_req = NULL;
5397 static int nl80211_start_sched_scan(struct sk_buff *skb,
5398 struct genl_info *info)
5400 struct cfg80211_sched_scan_request *request;
5401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5402 struct net_device *dev = info->user_ptr[1];
5403 struct nlattr *attr;
5404 struct wiphy *wiphy;
5405 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
5407 enum ieee80211_band band;
5409 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
5411 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5412 !rdev->ops->sched_scan_start)
5415 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5418 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5421 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5425 wiphy = &rdev->wiphy;
5427 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5428 n_channels = validate_scan_freqs(
5429 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5435 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5436 if (wiphy->bands[band])
5437 n_channels += wiphy->bands[band]->n_channels;
5440 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5441 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5445 if (n_ssids > wiphy->max_sched_scan_ssids)
5448 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5449 nla_for_each_nested(attr,
5450 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5454 if (n_match_sets > wiphy->max_match_sets)
5457 if (info->attrs[NL80211_ATTR_IE])
5458 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5462 if (ie_len > wiphy->max_sched_scan_ie_len)
5465 if (rdev->sched_scan_req) {
5470 request = kzalloc(sizeof(*request)
5471 + sizeof(*request->ssids) * n_ssids
5472 + sizeof(*request->match_sets) * n_match_sets
5473 + sizeof(*request->channels) * n_channels
5474 + ie_len, GFP_KERNEL);
5481 request->ssids = (void *)&request->channels[n_channels];
5482 request->n_ssids = n_ssids;
5485 request->ie = (void *)(request->ssids + n_ssids);
5487 request->ie = (void *)(request->channels + n_channels);
5492 request->match_sets = (void *)(request->ie + ie_len);
5493 else if (request->ssids)
5494 request->match_sets =
5495 (void *)(request->ssids + n_ssids);
5497 request->match_sets =
5498 (void *)(request->channels + n_channels);
5500 request->n_match_sets = n_match_sets;
5503 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5504 /* user specified, bail out if channel not found */
5505 nla_for_each_nested(attr,
5506 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5508 struct ieee80211_channel *chan;
5510 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5517 /* ignore disabled channels */
5518 if (chan->flags & IEEE80211_CHAN_DISABLED)
5521 request->channels[i] = chan;
5526 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5528 if (!wiphy->bands[band])
5530 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5531 struct ieee80211_channel *chan;
5533 chan = &wiphy->bands[band]->channels[j];
5535 if (chan->flags & IEEE80211_CHAN_DISABLED)
5538 request->channels[i] = chan;
5549 request->n_channels = i;
5552 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5553 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5555 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
5559 request->ssids[i].ssid_len = nla_len(attr);
5560 memcpy(request->ssids[i].ssid, nla_data(attr),
5567 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5568 nla_for_each_nested(attr,
5569 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5571 struct nlattr *ssid, *rssi;
5573 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5574 nla_data(attr), nla_len(attr),
5575 nl80211_match_policy);
5576 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
5578 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5582 memcpy(request->match_sets[i].ssid.ssid,
5583 nla_data(ssid), nla_len(ssid));
5584 request->match_sets[i].ssid.ssid_len =
5587 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5589 request->rssi_thold = nla_get_u32(rssi);
5591 request->rssi_thold =
5592 NL80211_SCAN_RSSI_THOLD_OFF;
5597 if (info->attrs[NL80211_ATTR_IE]) {
5598 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5599 memcpy((void *)request->ie,
5600 nla_data(info->attrs[NL80211_ATTR_IE]),
5604 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
5605 request->flags = nla_get_u32(
5606 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
5607 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5608 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5609 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5610 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
5617 request->wiphy = &rdev->wiphy;
5618 request->interval = interval;
5619 request->scan_start = jiffies;
5621 err = rdev_sched_scan_start(rdev, dev, request);
5623 rdev->sched_scan_req = request;
5624 nl80211_send_sched_scan(rdev, dev,
5625 NL80211_CMD_START_SCHED_SCAN);
5635 static int nl80211_stop_sched_scan(struct sk_buff *skb,
5636 struct genl_info *info)
5638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5640 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5641 !rdev->ops->sched_scan_stop)
5644 return __cfg80211_stop_sched_scan(rdev, false);
5647 static int nl80211_start_radar_detection(struct sk_buff *skb,
5648 struct genl_info *info)
5650 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5651 struct net_device *dev = info->user_ptr[1];
5652 struct wireless_dev *wdev = dev->ieee80211_ptr;
5653 struct cfg80211_chan_def chandef;
5656 err = nl80211_parse_chandef(rdev, info, &chandef);
5660 if (netif_carrier_ok(dev))
5663 if (wdev->cac_started)
5666 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5673 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5676 if (!rdev->ops->start_radar_detection)
5679 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5680 chandef.chan, CHAN_MODE_SHARED,
5681 BIT(chandef.width));
5685 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5687 wdev->channel = chandef.chan;
5688 wdev->cac_started = true;
5689 wdev->cac_start_time = jiffies;
5694 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5697 struct net_device *dev = info->user_ptr[1];
5698 struct wireless_dev *wdev = dev->ieee80211_ptr;
5699 struct cfg80211_csa_settings params;
5700 /* csa_attrs is defined static to avoid waste of stack size - this
5701 * function is called under RTNL lock, so this should not be a problem.
5703 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5704 u8 radar_detect_width = 0;
5706 bool need_new_beacon = false;
5708 if (!rdev->ops->channel_switch ||
5709 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5712 switch (dev->ieee80211_ptr->iftype) {
5713 case NL80211_IFTYPE_AP:
5714 case NL80211_IFTYPE_P2P_GO:
5715 need_new_beacon = true;
5717 /* useless if AP is not running */
5718 if (!wdev->beacon_interval)
5721 case NL80211_IFTYPE_ADHOC:
5722 case NL80211_IFTYPE_MESH_POINT:
5728 memset(¶ms, 0, sizeof(params));
5730 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5731 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5734 /* only important for AP, IBSS and mesh create IEs internally */
5735 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
5738 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5740 if (!need_new_beacon)
5743 err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after);
5747 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5748 info->attrs[NL80211_ATTR_CSA_IES],
5753 err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa);
5757 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5760 params.counter_offset_beacon =
5761 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5762 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5765 /* sanity check - counters should be the same */
5766 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5770 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5771 params.counter_offset_presp =
5772 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5773 if (params.counter_offset_presp >=
5774 params.beacon_csa.probe_resp_len)
5777 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5783 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
5787 if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef))
5790 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
5791 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5792 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
5793 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5798 radar_detect_width = BIT(params.chandef.width);
5799 params.radar_required = true;
5803 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5804 params.chandef.chan,
5806 radar_detect_width);
5810 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5811 params.block_tx = true;
5813 return rdev_channel_switch(rdev, dev, ¶ms);
5816 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5818 struct cfg80211_registered_device *rdev,
5819 struct wireless_dev *wdev,
5820 struct cfg80211_internal_bss *intbss)
5822 struct cfg80211_bss *res = &intbss->pub;
5823 const struct cfg80211_bss_ies *ies;
5828 ASSERT_WDEV_LOCK(wdev);
5830 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5831 NL80211_CMD_NEW_SCAN_RESULTS);
5835 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5837 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5838 goto nla_put_failure;
5840 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5841 goto nla_put_failure;
5842 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5843 goto nla_put_failure;
5845 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5847 goto nla_put_failure;
5848 if ((!is_zero_ether_addr(res->bssid) &&
5849 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
5850 goto nla_put_failure;
5853 ies = rcu_dereference(res->ies);
5855 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5856 goto fail_unlock_rcu;
5858 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5859 ies->len, ies->data))
5860 goto fail_unlock_rcu;
5862 ies = rcu_dereference(res->beacon_ies);
5864 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5865 goto fail_unlock_rcu;
5866 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5867 ies->len, ies->data))
5868 goto fail_unlock_rcu;
5872 if (res->beacon_interval &&
5873 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5874 goto nla_put_failure;
5875 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5876 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5877 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
5878 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5879 jiffies_to_msecs(jiffies - intbss->ts)))
5880 goto nla_put_failure;
5882 switch (rdev->wiphy.signal_type) {
5883 case CFG80211_SIGNAL_TYPE_MBM:
5884 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5885 goto nla_put_failure;
5887 case CFG80211_SIGNAL_TYPE_UNSPEC:
5888 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5889 goto nla_put_failure;
5895 switch (wdev->iftype) {
5896 case NL80211_IFTYPE_P2P_CLIENT:
5897 case NL80211_IFTYPE_STATION:
5898 if (intbss == wdev->current_bss &&
5899 nla_put_u32(msg, NL80211_BSS_STATUS,
5900 NL80211_BSS_STATUS_ASSOCIATED))
5901 goto nla_put_failure;
5903 case NL80211_IFTYPE_ADHOC:
5904 if (intbss == wdev->current_bss &&
5905 nla_put_u32(msg, NL80211_BSS_STATUS,
5906 NL80211_BSS_STATUS_IBSS_JOINED))
5907 goto nla_put_failure;
5913 nla_nest_end(msg, bss);
5915 return genlmsg_end(msg, hdr);
5920 genlmsg_cancel(msg, hdr);
5924 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
5926 struct cfg80211_registered_device *rdev;
5927 struct cfg80211_internal_bss *scan;
5928 struct wireless_dev *wdev;
5929 int start = cb->args[2], idx = 0;
5932 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5937 spin_lock_bh(&rdev->bss_lock);
5938 cfg80211_bss_expire(rdev);
5940 cb->seq = rdev->bss_generation;
5942 list_for_each_entry(scan, &rdev->bss_list, list) {
5945 if (nl80211_send_bss(skb, cb,
5946 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5947 rdev, wdev, scan) < 0) {
5953 spin_unlock_bh(&rdev->bss_lock);
5957 nl80211_finish_wdev_dump(rdev);
5962 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
5963 int flags, struct net_device *dev,
5964 struct survey_info *survey)
5967 struct nlattr *infoattr;
5969 hdr = nl80211hdr_put(msg, portid, seq, flags,
5970 NL80211_CMD_NEW_SURVEY_RESULTS);
5974 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5975 goto nla_put_failure;
5977 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5979 goto nla_put_failure;
5981 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5982 survey->channel->center_freq))
5983 goto nla_put_failure;
5985 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5986 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5987 goto nla_put_failure;
5988 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5989 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5990 goto nla_put_failure;
5991 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5992 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5993 survey->channel_time))
5994 goto nla_put_failure;
5995 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5996 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5997 survey->channel_time_busy))
5998 goto nla_put_failure;
5999 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6000 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6001 survey->channel_time_ext_busy))
6002 goto nla_put_failure;
6003 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6004 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6005 survey->channel_time_rx))
6006 goto nla_put_failure;
6007 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6008 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6009 survey->channel_time_tx))
6010 goto nla_put_failure;
6012 nla_nest_end(msg, infoattr);
6014 return genlmsg_end(msg, hdr);
6017 genlmsg_cancel(msg, hdr);
6021 static int nl80211_dump_survey(struct sk_buff *skb,
6022 struct netlink_callback *cb)
6024 struct survey_info survey;
6025 struct cfg80211_registered_device *dev;
6026 struct wireless_dev *wdev;
6027 int survey_idx = cb->args[2];
6030 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
6034 if (!wdev->netdev) {
6039 if (!dev->ops->dump_survey) {
6045 struct ieee80211_channel *chan;
6047 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
6053 /* Survey without a channel doesn't make sense */
6054 if (!survey.channel) {
6059 chan = ieee80211_get_channel(&dev->wiphy,
6060 survey.channel->center_freq);
6061 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6066 if (nl80211_send_survey(skb,
6067 NETLINK_CB(cb->skb).portid,
6068 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6069 wdev->netdev, &survey) < 0)
6075 cb->args[2] = survey_idx;
6078 nl80211_finish_wdev_dump(dev);
6082 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6084 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6085 NL80211_WPA_VERSION_2));
6088 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6091 struct net_device *dev = info->user_ptr[1];
6092 struct ieee80211_channel *chan;
6093 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6094 int err, ssid_len, ie_len = 0, sae_data_len = 0;
6095 enum nl80211_auth_type auth_type;
6096 struct key_parse key;
6097 bool local_state_change;
6099 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6102 if (!info->attrs[NL80211_ATTR_MAC])
6105 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6108 if (!info->attrs[NL80211_ATTR_SSID])
6111 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6114 err = nl80211_parse_key(info, &key);
6119 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6121 if (!key.p.key || !key.p.key_len)
6123 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6124 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6125 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6126 key.p.key_len != WLAN_KEY_LEN_WEP104))
6138 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6139 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6148 if (!rdev->ops->auth)
6151 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6152 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6155 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6156 chan = ieee80211_get_channel(&rdev->wiphy,
6157 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6158 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6161 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6162 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6164 if (info->attrs[NL80211_ATTR_IE]) {
6165 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6166 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6169 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
6170 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
6173 if (auth_type == NL80211_AUTHTYPE_SAE &&
6174 !info->attrs[NL80211_ATTR_SAE_DATA])
6177 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6178 if (auth_type != NL80211_AUTHTYPE_SAE)
6180 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6181 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6182 /* need to include at least Auth Transaction and Status Code */
6183 if (sae_data_len < 4)
6187 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6190 * Since we no longer track auth state, ignore
6191 * requests to only change local state.
6193 if (local_state_change)
6196 wdev_lock(dev->ieee80211_ptr);
6197 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6198 ssid, ssid_len, ie, ie_len,
6199 key.p.key, key.p.key_len, key.idx,
6200 sae_data, sae_data_len);
6201 wdev_unlock(dev->ieee80211_ptr);
6205 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6206 struct genl_info *info,
6207 struct cfg80211_crypto_settings *settings,
6210 memset(settings, 0, sizeof(*settings));
6212 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6214 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6216 proto = nla_get_u16(
6217 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6218 settings->control_port_ethertype = cpu_to_be16(proto);
6219 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6222 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6223 settings->control_port_no_encrypt = true;
6225 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6227 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6231 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6232 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6233 settings->n_ciphers_pairwise = len / sizeof(u32);
6235 if (len % sizeof(u32))
6238 if (settings->n_ciphers_pairwise > cipher_limit)
6241 memcpy(settings->ciphers_pairwise, data, len);
6243 for (i = 0; i < settings->n_ciphers_pairwise; i++)
6244 if (!cfg80211_supported_cipher_suite(
6246 settings->ciphers_pairwise[i]))
6250 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6251 settings->cipher_group =
6252 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
6253 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6254 settings->cipher_group))
6258 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6259 settings->wpa_versions =
6260 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6261 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6265 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6269 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6270 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6271 settings->n_akm_suites = len / sizeof(u32);
6273 if (len % sizeof(u32))
6276 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6279 memcpy(settings->akm_suites, data, len);
6285 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6287 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6288 struct net_device *dev = info->user_ptr[1];
6289 struct ieee80211_channel *chan;
6290 struct cfg80211_assoc_request req = {};
6291 const u8 *bssid, *ssid;
6292 int err, ssid_len = 0;
6294 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6297 if (!info->attrs[NL80211_ATTR_MAC] ||
6298 !info->attrs[NL80211_ATTR_SSID] ||
6299 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
6302 if (!rdev->ops->assoc)
6305 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6306 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6309 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6311 chan = ieee80211_get_channel(&rdev->wiphy,
6312 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6313 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6316 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6317 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6319 if (info->attrs[NL80211_ATTR_IE]) {
6320 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6321 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6324 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6325 enum nl80211_mfp mfp =
6326 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6327 if (mfp == NL80211_MFP_REQUIRED)
6329 else if (mfp != NL80211_MFP_NO)
6333 if (info->attrs[NL80211_ATTR_PREV_BSSID])
6334 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
6336 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6337 req.flags |= ASSOC_REQ_DISABLE_HT;
6339 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6340 memcpy(&req.ht_capa_mask,
6341 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6342 sizeof(req.ht_capa_mask));
6344 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6345 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6347 memcpy(&req.ht_capa,
6348 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6349 sizeof(req.ht_capa));
6352 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6353 req.flags |= ASSOC_REQ_DISABLE_VHT;
6355 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6356 memcpy(&req.vht_capa_mask,
6357 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6358 sizeof(req.vht_capa_mask));
6360 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6361 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6363 memcpy(&req.vht_capa,
6364 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6365 sizeof(req.vht_capa));
6368 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
6370 wdev_lock(dev->ieee80211_ptr);
6371 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6372 ssid, ssid_len, &req);
6373 wdev_unlock(dev->ieee80211_ptr);
6379 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6382 struct net_device *dev = info->user_ptr[1];
6383 const u8 *ie = NULL, *bssid;
6384 int ie_len = 0, err;
6386 bool local_state_change;
6388 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6391 if (!info->attrs[NL80211_ATTR_MAC])
6394 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6397 if (!rdev->ops->deauth)
6400 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6401 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6404 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6406 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6407 if (reason_code == 0) {
6408 /* Reason Code 0 is reserved */
6412 if (info->attrs[NL80211_ATTR_IE]) {
6413 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6414 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6417 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6419 wdev_lock(dev->ieee80211_ptr);
6420 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6421 local_state_change);
6422 wdev_unlock(dev->ieee80211_ptr);
6426 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6429 struct net_device *dev = info->user_ptr[1];
6430 const u8 *ie = NULL, *bssid;
6431 int ie_len = 0, err;
6433 bool local_state_change;
6435 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6438 if (!info->attrs[NL80211_ATTR_MAC])
6441 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6444 if (!rdev->ops->disassoc)
6447 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6448 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6451 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6453 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6454 if (reason_code == 0) {
6455 /* Reason Code 0 is reserved */
6459 if (info->attrs[NL80211_ATTR_IE]) {
6460 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6461 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6464 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6466 wdev_lock(dev->ieee80211_ptr);
6467 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6468 local_state_change);
6469 wdev_unlock(dev->ieee80211_ptr);
6474 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6475 int mcast_rate[IEEE80211_NUM_BANDS],
6478 struct wiphy *wiphy = &rdev->wiphy;
6482 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6483 struct ieee80211_supported_band *sband;
6485 sband = wiphy->bands[band];
6489 for (i = 0; i < sband->n_bitrates; i++) {
6490 if (sband->bitrates[i].bitrate == rateval) {
6491 mcast_rate[band] = i + 1;
6501 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6504 struct net_device *dev = info->user_ptr[1];
6505 struct cfg80211_ibss_params ibss;
6506 struct wiphy *wiphy;
6507 struct cfg80211_cached_keys *connkeys = NULL;
6510 memset(&ibss, 0, sizeof(ibss));
6512 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6515 if (!info->attrs[NL80211_ATTR_SSID] ||
6516 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6519 ibss.beacon_interval = 100;
6521 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6522 ibss.beacon_interval =
6523 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6524 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6528 if (!rdev->ops->join_ibss)
6531 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6534 wiphy = &rdev->wiphy;
6536 if (info->attrs[NL80211_ATTR_MAC]) {
6537 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6539 if (!is_valid_ether_addr(ibss.bssid))
6542 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6543 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6545 if (info->attrs[NL80211_ATTR_IE]) {
6546 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6547 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6550 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6554 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
6557 switch (ibss.chandef.width) {
6558 case NL80211_CHAN_WIDTH_5:
6559 case NL80211_CHAN_WIDTH_10:
6560 case NL80211_CHAN_WIDTH_20_NOHT:
6562 case NL80211_CHAN_WIDTH_20:
6563 case NL80211_CHAN_WIDTH_40:
6564 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6570 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
6571 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
6573 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6575 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6577 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6578 struct ieee80211_supported_band *sband =
6579 wiphy->bands[ibss.chandef.chan->band];
6581 err = ieee80211_get_ratemask(sband, rates, n_rates,
6587 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6588 memcpy(&ibss.ht_capa_mask,
6589 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6590 sizeof(ibss.ht_capa_mask));
6592 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6593 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6595 memcpy(&ibss.ht_capa,
6596 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6597 sizeof(ibss.ht_capa));
6600 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6601 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6602 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6605 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6608 connkeys = nl80211_parse_connkeys(rdev,
6609 info->attrs[NL80211_ATTR_KEYS],
6611 if (IS_ERR(connkeys))
6612 return PTR_ERR(connkeys);
6614 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6622 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6624 ibss.userspace_handles_dfs =
6625 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6627 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
6633 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6636 struct net_device *dev = info->user_ptr[1];
6638 if (!rdev->ops->leave_ibss)
6641 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6644 return cfg80211_leave_ibss(rdev, dev, false);
6647 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6649 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6650 struct net_device *dev = info->user_ptr[1];
6651 int mcast_rate[IEEE80211_NUM_BANDS];
6655 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6656 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6659 if (!rdev->ops->set_mcast_rate)
6662 memset(mcast_rate, 0, sizeof(mcast_rate));
6664 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6667 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6668 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6671 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6677 #ifdef CONFIG_NL80211_TESTMODE
6678 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6680 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6681 struct wireless_dev *wdev =
6682 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
6685 if (!rdev->ops->testmode_cmd)
6689 err = PTR_ERR(wdev);
6693 } else if (wdev->wiphy != &rdev->wiphy) {
6697 if (!info->attrs[NL80211_ATTR_TESTDATA])
6700 rdev->testmode_info = info;
6701 err = rdev_testmode_cmd(rdev, wdev,
6702 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6703 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6704 rdev->testmode_info = NULL;
6709 static int nl80211_testmode_dump(struct sk_buff *skb,
6710 struct netlink_callback *cb)
6712 struct cfg80211_registered_device *rdev;
6722 * 0 is a valid index, but not valid for args[0],
6723 * so we need to offset by 1.
6725 phy_idx = cb->args[0] - 1;
6727 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6728 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6733 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6734 nl80211_fam.attrbuf);
6736 err = PTR_ERR(rdev);
6739 phy_idx = rdev->wiphy_idx;
6742 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6744 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6748 data = nla_data((void *)cb->args[1]);
6749 data_len = nla_len((void *)cb->args[1]);
6752 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6758 if (!rdev->ops->testmode_dump) {
6764 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
6765 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6766 NL80211_CMD_TESTMODE);
6767 struct nlattr *tmdata;
6772 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
6773 genlmsg_cancel(skb, hdr);
6777 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6779 genlmsg_cancel(skb, hdr);
6782 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
6783 nla_nest_end(skb, tmdata);
6785 if (err == -ENOBUFS || err == -ENOENT) {
6786 genlmsg_cancel(skb, hdr);
6789 genlmsg_cancel(skb, hdr);
6793 genlmsg_end(skb, hdr);
6798 cb->args[0] = phy_idx + 1;
6804 static struct sk_buff *
6805 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
6806 int approxlen, u32 portid, u32 seq, gfp_t gfp)
6808 struct sk_buff *skb;
6810 struct nlattr *data;
6812 skb = nlmsg_new(approxlen + 100, gfp);
6816 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
6822 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6823 goto nla_put_failure;
6824 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6826 ((void **)skb->cb)[0] = rdev;
6827 ((void **)skb->cb)[1] = hdr;
6828 ((void **)skb->cb)[2] = data;
6837 struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6840 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6842 if (WARN_ON(!rdev->testmode_info))
6845 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
6846 rdev->testmode_info->snd_portid,
6847 rdev->testmode_info->snd_seq,
6850 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6852 int cfg80211_testmode_reply(struct sk_buff *skb)
6854 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6855 void *hdr = ((void **)skb->cb)[1];
6856 struct nlattr *data = ((void **)skb->cb)[2];
6858 if (WARN_ON(!rdev->testmode_info)) {
6863 nla_nest_end(skb, data);
6864 genlmsg_end(skb, hdr);
6865 return genlmsg_reply(skb, rdev->testmode_info);
6867 EXPORT_SYMBOL(cfg80211_testmode_reply);
6869 struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6870 int approxlen, gfp_t gfp)
6872 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6874 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6876 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6878 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6880 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6881 void *hdr = ((void **)skb->cb)[1];
6882 struct nlattr *data = ((void **)skb->cb)[2];
6884 nla_nest_end(skb, data);
6885 genlmsg_end(skb, hdr);
6886 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6887 NL80211_MCGRP_TESTMODE, gfp);
6889 EXPORT_SYMBOL(cfg80211_testmode_event);
6892 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6895 struct net_device *dev = info->user_ptr[1];
6896 struct cfg80211_connect_params connect;
6897 struct wiphy *wiphy;
6898 struct cfg80211_cached_keys *connkeys = NULL;
6901 memset(&connect, 0, sizeof(connect));
6903 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6906 if (!info->attrs[NL80211_ATTR_SSID] ||
6907 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6910 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6912 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
6913 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6914 NL80211_CMD_CONNECT))
6917 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6919 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6921 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
6922 NL80211_MAX_NR_CIPHER_SUITES);
6926 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6927 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6930 wiphy = &rdev->wiphy;
6932 connect.bg_scan_period = -1;
6933 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6934 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6935 connect.bg_scan_period =
6936 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6939 if (info->attrs[NL80211_ATTR_MAC])
6940 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6941 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6942 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6944 if (info->attrs[NL80211_ATTR_IE]) {
6945 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6946 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6949 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6950 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6951 if (connect.mfp != NL80211_MFP_REQUIRED &&
6952 connect.mfp != NL80211_MFP_NO)
6955 connect.mfp = NL80211_MFP_NO;
6958 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6960 ieee80211_get_channel(wiphy,
6961 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6962 if (!connect.channel ||
6963 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6967 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6968 connkeys = nl80211_parse_connkeys(rdev,
6969 info->attrs[NL80211_ATTR_KEYS], NULL);
6970 if (IS_ERR(connkeys))
6971 return PTR_ERR(connkeys);
6974 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6975 connect.flags |= ASSOC_REQ_DISABLE_HT;
6977 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6978 memcpy(&connect.ht_capa_mask,
6979 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6980 sizeof(connect.ht_capa_mask));
6982 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6983 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6987 memcpy(&connect.ht_capa,
6988 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6989 sizeof(connect.ht_capa));
6992 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6993 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6995 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6996 memcpy(&connect.vht_capa_mask,
6997 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6998 sizeof(connect.vht_capa_mask));
7000 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7001 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7005 memcpy(&connect.vht_capa,
7006 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7007 sizeof(connect.vht_capa));
7010 wdev_lock(dev->ieee80211_ptr);
7011 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7012 wdev_unlock(dev->ieee80211_ptr);
7018 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7021 struct net_device *dev = info->user_ptr[1];
7025 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7026 reason = WLAN_REASON_DEAUTH_LEAVING;
7028 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
7034 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7037 wdev_lock(dev->ieee80211_ptr);
7038 ret = cfg80211_disconnect(rdev, dev, reason, true);
7039 wdev_unlock(dev->ieee80211_ptr);
7043 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7050 if (!info->attrs[NL80211_ATTR_PID])
7053 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7055 net = get_net_ns_by_pid(pid);
7057 return PTR_ERR(net);
7061 /* check if anything to do */
7062 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7063 err = cfg80211_switch_netns(rdev, net);
7069 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7072 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7073 struct cfg80211_pmksa *pmksa) = NULL;
7074 struct net_device *dev = info->user_ptr[1];
7075 struct cfg80211_pmksa pmksa;
7077 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7079 if (!info->attrs[NL80211_ATTR_MAC])
7082 if (!info->attrs[NL80211_ATTR_PMKID])
7085 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7086 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7088 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
7089 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7092 switch (info->genlhdr->cmd) {
7093 case NL80211_CMD_SET_PMKSA:
7094 rdev_ops = rdev->ops->set_pmksa;
7096 case NL80211_CMD_DEL_PMKSA:
7097 rdev_ops = rdev->ops->del_pmksa;
7107 return rdev_ops(&rdev->wiphy, dev, &pmksa);
7110 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7113 struct net_device *dev = info->user_ptr[1];
7115 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
7116 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7119 if (!rdev->ops->flush_pmksa)
7122 return rdev_flush_pmksa(rdev, dev);
7125 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7128 struct net_device *dev = info->user_ptr[1];
7129 u8 action_code, dialog_token;
7133 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7134 !rdev->ops->tdls_mgmt)
7137 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7138 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7139 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7140 !info->attrs[NL80211_ATTR_IE] ||
7141 !info->attrs[NL80211_ATTR_MAC])
7144 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7145 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7146 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7147 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7149 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7150 dialog_token, status_code,
7151 nla_data(info->attrs[NL80211_ATTR_IE]),
7152 nla_len(info->attrs[NL80211_ATTR_IE]));
7155 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7158 struct net_device *dev = info->user_ptr[1];
7159 enum nl80211_tdls_operation operation;
7162 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7163 !rdev->ops->tdls_oper)
7166 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7167 !info->attrs[NL80211_ATTR_MAC])
7170 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7171 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7173 return rdev_tdls_oper(rdev, dev, peer, operation);
7176 static int nl80211_remain_on_channel(struct sk_buff *skb,
7177 struct genl_info *info)
7179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7180 struct wireless_dev *wdev = info->user_ptr[1];
7181 struct cfg80211_chan_def chandef;
7182 struct sk_buff *msg;
7188 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7189 !info->attrs[NL80211_ATTR_DURATION])
7192 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7194 if (!rdev->ops->remain_on_channel ||
7195 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
7199 * We should be on that channel for at least a minimum amount of
7200 * time (10ms) but no longer than the driver supports.
7202 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7203 duration > rdev->wiphy.max_remain_on_channel_duration)
7206 err = nl80211_parse_chandef(rdev, info, &chandef);
7210 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7214 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7215 NL80211_CMD_REMAIN_ON_CHANNEL);
7221 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7227 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7228 goto nla_put_failure;
7230 genlmsg_end(msg, hdr);
7232 return genlmsg_reply(msg, info);
7241 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7242 struct genl_info *info)
7244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7245 struct wireless_dev *wdev = info->user_ptr[1];
7248 if (!info->attrs[NL80211_ATTR_COOKIE])
7251 if (!rdev->ops->cancel_remain_on_channel)
7254 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7256 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
7259 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7260 u8 *rates, u8 rates_len)
7265 for (i = 0; i < rates_len; i++) {
7266 int rate = (rates[i] & 0x7f) * 5;
7268 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7269 struct ieee80211_rate *srate =
7270 &sband->bitrates[ridx];
7271 if (rate == srate->bitrate) {
7276 if (ridx == sband->n_bitrates)
7277 return 0; /* rate not found */
7283 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7284 u8 *rates, u8 rates_len,
7285 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7289 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7291 for (i = 0; i < rates_len; i++) {
7294 ridx = rates[i] / 8;
7295 rbit = BIT(rates[i] % 8);
7297 /* check validity */
7298 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
7301 /* check availability */
7302 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7311 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
7312 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7313 .len = NL80211_MAX_SUPP_RATES },
7314 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7315 .len = NL80211_MAX_SUPP_HT_RATES },
7318 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7319 struct genl_info *info)
7321 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
7322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7323 struct cfg80211_bitrate_mask mask;
7325 struct net_device *dev = info->user_ptr[1];
7326 struct nlattr *tx_rates;
7327 struct ieee80211_supported_band *sband;
7329 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7332 if (!rdev->ops->set_bitrate_mask)
7335 memset(&mask, 0, sizeof(mask));
7336 /* Default to all rates enabled */
7337 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7338 sband = rdev->wiphy.bands[i];
7339 mask.control[i].legacy =
7340 sband ? (1 << sband->n_bitrates) - 1 : 0;
7342 memcpy(mask.control[i].mcs,
7343 sband->ht_cap.mcs.rx_mask,
7344 sizeof(mask.control[i].mcs));
7346 memset(mask.control[i].mcs, 0,
7347 sizeof(mask.control[i].mcs));
7351 * The nested attribute uses enum nl80211_band as the index. This maps
7352 * directly to the enum ieee80211_band values used in cfg80211.
7354 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
7355 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7357 enum ieee80211_band band = nla_type(tx_rates);
7358 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7360 sband = rdev->wiphy.bands[band];
7363 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7364 nla_len(tx_rates), nl80211_txattr_policy);
7365 if (tb[NL80211_TXRATE_LEGACY]) {
7366 mask.control[band].legacy = rateset_to_mask(
7368 nla_data(tb[NL80211_TXRATE_LEGACY]),
7369 nla_len(tb[NL80211_TXRATE_LEGACY]));
7370 if ((mask.control[band].legacy == 0) &&
7371 nla_len(tb[NL80211_TXRATE_LEGACY]))
7374 if (tb[NL80211_TXRATE_MCS]) {
7375 if (!ht_rateset_to_mask(
7377 nla_data(tb[NL80211_TXRATE_MCS]),
7378 nla_len(tb[NL80211_TXRATE_MCS]),
7379 mask.control[band].mcs))
7383 if (mask.control[band].legacy == 0) {
7384 /* don't allow empty legacy rates if HT
7385 * is not even supported. */
7386 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7389 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7390 if (mask.control[band].mcs[i])
7393 /* legacy and mcs rates may not be both empty */
7394 if (i == IEEE80211_HT_MCS_MASK_LEN)
7399 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
7402 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
7404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7405 struct wireless_dev *wdev = info->user_ptr[1];
7406 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
7408 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7411 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7412 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
7414 switch (wdev->iftype) {
7415 case NL80211_IFTYPE_STATION:
7416 case NL80211_IFTYPE_ADHOC:
7417 case NL80211_IFTYPE_P2P_CLIENT:
7418 case NL80211_IFTYPE_AP:
7419 case NL80211_IFTYPE_AP_VLAN:
7420 case NL80211_IFTYPE_MESH_POINT:
7421 case NL80211_IFTYPE_P2P_GO:
7422 case NL80211_IFTYPE_P2P_DEVICE:
7428 /* not much point in registering if we can't reply */
7429 if (!rdev->ops->mgmt_tx)
7432 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
7433 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7434 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
7437 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
7439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7440 struct wireless_dev *wdev = info->user_ptr[1];
7441 struct cfg80211_chan_def chandef;
7445 struct sk_buff *msg = NULL;
7446 unsigned int wait = 0;
7447 bool offchan, no_cck, dont_wait_for_ack;
7449 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
7451 if (!info->attrs[NL80211_ATTR_FRAME])
7454 if (!rdev->ops->mgmt_tx)
7457 switch (wdev->iftype) {
7458 case NL80211_IFTYPE_P2P_DEVICE:
7459 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7461 case NL80211_IFTYPE_STATION:
7462 case NL80211_IFTYPE_ADHOC:
7463 case NL80211_IFTYPE_P2P_CLIENT:
7464 case NL80211_IFTYPE_AP:
7465 case NL80211_IFTYPE_AP_VLAN:
7466 case NL80211_IFTYPE_MESH_POINT:
7467 case NL80211_IFTYPE_P2P_GO:
7473 if (info->attrs[NL80211_ATTR_DURATION]) {
7474 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7476 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7479 * We should wait on the channel for at least a minimum amount
7480 * of time (10ms) but no longer than the driver supports.
7482 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7483 wait > rdev->wiphy.max_remain_on_channel_duration)
7488 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7490 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7493 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7495 /* get the channel if any has been specified, otherwise pass NULL to
7496 * the driver. The latter will use the current one
7498 chandef.chan = NULL;
7499 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7500 err = nl80211_parse_chandef(rdev, info, &chandef);
7505 if (!chandef.chan && offchan)
7508 if (!dont_wait_for_ack) {
7509 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7513 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7521 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
7522 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7523 nla_len(info->attrs[NL80211_ATTR_FRAME]),
7524 no_cck, dont_wait_for_ack, &cookie);
7529 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7530 goto nla_put_failure;
7532 genlmsg_end(msg, hdr);
7533 return genlmsg_reply(msg, info);
7545 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7548 struct wireless_dev *wdev = info->user_ptr[1];
7551 if (!info->attrs[NL80211_ATTR_COOKIE])
7554 if (!rdev->ops->mgmt_tx_cancel_wait)
7557 switch (wdev->iftype) {
7558 case NL80211_IFTYPE_STATION:
7559 case NL80211_IFTYPE_ADHOC:
7560 case NL80211_IFTYPE_P2P_CLIENT:
7561 case NL80211_IFTYPE_AP:
7562 case NL80211_IFTYPE_AP_VLAN:
7563 case NL80211_IFTYPE_P2P_GO:
7564 case NL80211_IFTYPE_P2P_DEVICE:
7570 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7572 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
7575 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7578 struct wireless_dev *wdev;
7579 struct net_device *dev = info->user_ptr[1];
7584 if (!info->attrs[NL80211_ATTR_PS_STATE])
7587 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7589 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7592 wdev = dev->ieee80211_ptr;
7594 if (!rdev->ops->set_power_mgmt)
7597 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7599 if (state == wdev->ps)
7602 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
7608 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7610 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7611 enum nl80211_ps_state ps_state;
7612 struct wireless_dev *wdev;
7613 struct net_device *dev = info->user_ptr[1];
7614 struct sk_buff *msg;
7618 wdev = dev->ieee80211_ptr;
7620 if (!rdev->ops->set_power_mgmt)
7623 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7627 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7628 NL80211_CMD_GET_POWER_SAVE);
7635 ps_state = NL80211_PS_ENABLED;
7637 ps_state = NL80211_PS_DISABLED;
7639 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7640 goto nla_put_failure;
7642 genlmsg_end(msg, hdr);
7643 return genlmsg_reply(msg, info);
7652 static struct nla_policy
7653 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7654 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7655 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7656 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
7657 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7658 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7659 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
7662 static int nl80211_set_cqm_txe(struct genl_info *info,
7663 u32 rate, u32 pkts, u32 intvl)
7665 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7666 struct net_device *dev = info->user_ptr[1];
7667 struct wireless_dev *wdev = dev->ieee80211_ptr;
7669 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
7672 if (!rdev->ops->set_cqm_txe_config)
7675 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7676 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7679 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
7682 static int nl80211_set_cqm_rssi(struct genl_info *info,
7683 s32 threshold, u32 hysteresis)
7685 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7686 struct net_device *dev = info->user_ptr[1];
7687 struct wireless_dev *wdev = dev->ieee80211_ptr;
7692 /* disabling - hysteresis should also be zero then */
7696 if (!rdev->ops->set_cqm_rssi_config)
7699 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7700 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7703 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
7706 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7708 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7712 cqm = info->attrs[NL80211_ATTR_CQM];
7716 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7717 nl80211_attr_cqm_policy);
7721 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7722 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7723 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7724 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7726 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7729 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7730 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7731 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7732 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7733 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7734 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7736 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7742 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7745 struct net_device *dev = info->user_ptr[1];
7746 struct mesh_config cfg;
7747 struct mesh_setup setup;
7750 /* start with default */
7751 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
7752 memcpy(&setup, &default_mesh_setup, sizeof(setup));
7754 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
7755 /* and parse parameters if given */
7756 err = nl80211_parse_mesh_config(info, &cfg, NULL);
7761 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7762 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7765 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7766 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7768 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7769 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7770 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7773 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7774 setup.beacon_interval =
7775 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7776 if (setup.beacon_interval < 10 ||
7777 setup.beacon_interval > 10000)
7781 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7783 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7784 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7788 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7789 /* parse additional setup parameters if given */
7790 err = nl80211_parse_mesh_setup(info, &setup);
7796 cfg.auto_open_plinks = false;
7798 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7799 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7803 /* cfg80211_join_mesh() will sort it out */
7804 setup.chandef.chan = NULL;
7807 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7808 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7810 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7811 struct ieee80211_supported_band *sband;
7813 if (!setup.chandef.chan)
7816 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7818 err = ieee80211_get_ratemask(sband, rates, n_rates,
7819 &setup.basic_rates);
7824 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
7827 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7830 struct net_device *dev = info->user_ptr[1];
7832 return cfg80211_leave_mesh(rdev, dev);
7836 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7837 struct cfg80211_registered_device *rdev)
7839 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
7840 struct nlattr *nl_pats, *nl_pat;
7843 if (!wowlan->n_patterns)
7846 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7850 for (i = 0; i < wowlan->n_patterns; i++) {
7851 nl_pat = nla_nest_start(msg, i + 1);
7854 pat_len = wowlan->patterns[i].pattern_len;
7855 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
7856 wowlan->patterns[i].mask) ||
7857 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7858 wowlan->patterns[i].pattern) ||
7859 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
7860 wowlan->patterns[i].pkt_offset))
7862 nla_nest_end(msg, nl_pat);
7864 nla_nest_end(msg, nl_pats);
7869 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7870 struct cfg80211_wowlan_tcp *tcp)
7872 struct nlattr *nl_tcp;
7877 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7881 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7882 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7883 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7884 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7885 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7886 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7887 tcp->payload_len, tcp->payload) ||
7888 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7889 tcp->data_interval) ||
7890 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7891 tcp->wake_len, tcp->wake_data) ||
7892 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7893 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7896 if (tcp->payload_seq.len &&
7897 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7898 sizeof(tcp->payload_seq), &tcp->payload_seq))
7901 if (tcp->payload_tok.len &&
7902 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7903 sizeof(tcp->payload_tok) + tcp->tokens_size,
7907 nla_nest_end(msg, nl_tcp);
7912 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7915 struct sk_buff *msg;
7917 u32 size = NLMSG_DEFAULT_SIZE;
7919 if (!rdev->wiphy.wowlan)
7922 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
7923 /* adjust size to have room for all the data */
7924 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7925 rdev->wiphy.wowlan_config->tcp->payload_len +
7926 rdev->wiphy.wowlan_config->tcp->wake_len +
7927 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
7930 msg = nlmsg_new(size, GFP_KERNEL);
7934 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7935 NL80211_CMD_GET_WOWLAN);
7937 goto nla_put_failure;
7939 if (rdev->wiphy.wowlan_config) {
7940 struct nlattr *nl_wowlan;
7942 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7944 goto nla_put_failure;
7946 if ((rdev->wiphy.wowlan_config->any &&
7947 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7948 (rdev->wiphy.wowlan_config->disconnect &&
7949 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7950 (rdev->wiphy.wowlan_config->magic_pkt &&
7951 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7952 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
7953 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7954 (rdev->wiphy.wowlan_config->eap_identity_req &&
7955 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7956 (rdev->wiphy.wowlan_config->four_way_handshake &&
7957 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7958 (rdev->wiphy.wowlan_config->rfkill_release &&
7959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7960 goto nla_put_failure;
7962 if (nl80211_send_wowlan_patterns(msg, rdev))
7963 goto nla_put_failure;
7965 if (nl80211_send_wowlan_tcp(msg,
7966 rdev->wiphy.wowlan_config->tcp))
7967 goto nla_put_failure;
7969 nla_nest_end(msg, nl_wowlan);
7972 genlmsg_end(msg, hdr);
7973 return genlmsg_reply(msg, info);
7980 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7981 struct nlattr *attr,
7982 struct cfg80211_wowlan *trig)
7984 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7985 struct cfg80211_wowlan_tcp *cfg;
7986 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7987 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7989 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7992 if (!rdev->wiphy.wowlan->tcp)
7995 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7996 nla_data(attr), nla_len(attr),
7997 nl80211_wowlan_tcp_policy);
8001 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8002 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8003 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8004 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8005 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8006 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8007 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8008 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8011 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
8012 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
8015 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
8016 rdev->wiphy.wowlan->tcp->data_interval_max ||
8017 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
8020 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
8021 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
8024 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8025 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8028 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8029 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8031 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8032 tokens_size = tokln - sizeof(*tok);
8034 if (!tok->len || tokens_size % tok->len)
8036 if (!rdev->wiphy.wowlan->tcp->tok)
8038 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
8040 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
8042 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
8044 if (tok->offset + tok->len > data_size)
8048 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8049 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
8050 if (!rdev->wiphy.wowlan->tcp->seq)
8052 if (seq->len == 0 || seq->len > 4)
8054 if (seq->len + seq->offset > data_size)
8058 size = sizeof(*cfg);
8060 size += wake_size + wake_mask_size;
8061 size += tokens_size;
8063 cfg = kzalloc(size, GFP_KERNEL);
8066 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8067 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8068 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8070 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8071 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8075 /* allocate a socket and port for it and use it */
8076 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8077 IPPROTO_TCP, &cfg->sock, 1);
8082 if (inet_csk_get_port(cfg->sock->sk, port)) {
8083 sock_release(cfg->sock);
8087 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8093 cfg->src_port = port;
8096 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8097 cfg->payload_len = data_size;
8098 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8099 memcpy((void *)cfg->payload,
8100 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8103 cfg->payload_seq = *seq;
8104 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8105 cfg->wake_len = wake_size;
8106 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8107 memcpy((void *)cfg->wake_data,
8108 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8110 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8111 data_size + wake_size;
8112 memcpy((void *)cfg->wake_mask,
8113 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8116 cfg->tokens_size = tokens_size;
8117 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8125 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8128 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
8129 struct cfg80211_wowlan new_triggers = {};
8130 struct cfg80211_wowlan *ntrig;
8131 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
8133 bool prev_enabled = rdev->wiphy.wowlan_config;
8138 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8139 cfg80211_rdev_free_wowlan(rdev);
8140 rdev->wiphy.wowlan_config = NULL;
8144 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8145 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8146 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8147 nl80211_wowlan_policy);
8151 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8152 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8154 new_triggers.any = true;
8157 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8158 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8160 new_triggers.disconnect = true;
8163 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8164 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8166 new_triggers.magic_pkt = true;
8169 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8172 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8173 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8175 new_triggers.gtk_rekey_failure = true;
8178 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8179 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8181 new_triggers.eap_identity_req = true;
8184 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8185 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8187 new_triggers.four_way_handshake = true;
8190 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8191 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8193 new_triggers.rfkill_release = true;
8196 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8199 int rem, pat_len, mask_len, pkt_offset;
8200 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8202 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8205 if (n_patterns > wowlan->n_patterns)
8208 new_triggers.patterns = kcalloc(n_patterns,
8209 sizeof(new_triggers.patterns[0]),
8211 if (!new_triggers.patterns)
8214 new_triggers.n_patterns = n_patterns;
8217 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8219 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8220 nla_len(pat), NULL);
8222 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8223 !pat_tb[NL80211_PKTPAT_PATTERN])
8225 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8226 mask_len = DIV_ROUND_UP(pat_len, 8);
8227 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8229 if (pat_len > wowlan->pattern_max_len ||
8230 pat_len < wowlan->pattern_min_len)
8233 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8236 pkt_offset = nla_get_u32(
8237 pat_tb[NL80211_PKTPAT_OFFSET]);
8238 if (pkt_offset > wowlan->max_pkt_offset)
8240 new_triggers.patterns[i].pkt_offset = pkt_offset;
8242 new_triggers.patterns[i].mask =
8243 kmalloc(mask_len + pat_len, GFP_KERNEL);
8244 if (!new_triggers.patterns[i].mask) {
8248 new_triggers.patterns[i].pattern =
8249 new_triggers.patterns[i].mask + mask_len;
8250 memcpy(new_triggers.patterns[i].mask,
8251 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8253 new_triggers.patterns[i].pattern_len = pat_len;
8254 memcpy(new_triggers.patterns[i].pattern,
8255 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8261 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8262 err = nl80211_parse_wowlan_tcp(
8263 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8269 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8274 cfg80211_rdev_free_wowlan(rdev);
8275 rdev->wiphy.wowlan_config = ntrig;
8278 if (rdev->ops->set_wakeup &&
8279 prev_enabled != !!rdev->wiphy.wowlan_config)
8280 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
8284 for (i = 0; i < new_triggers.n_patterns; i++)
8285 kfree(new_triggers.patterns[i].mask);
8286 kfree(new_triggers.patterns);
8287 if (new_triggers.tcp && new_triggers.tcp->sock)
8288 sock_release(new_triggers.tcp->sock);
8289 kfree(new_triggers.tcp);
8294 static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8295 struct cfg80211_registered_device *rdev)
8297 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8299 struct cfg80211_coalesce_rules *rule;
8301 if (!rdev->coalesce->n_rules)
8304 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8308 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8309 nl_rule = nla_nest_start(msg, i + 1);
8313 rule = &rdev->coalesce->rules[i];
8314 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8318 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8322 nl_pats = nla_nest_start(msg,
8323 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8327 for (j = 0; j < rule->n_patterns; j++) {
8328 nl_pat = nla_nest_start(msg, j + 1);
8331 pat_len = rule->patterns[j].pattern_len;
8332 if (nla_put(msg, NL80211_PKTPAT_MASK,
8333 DIV_ROUND_UP(pat_len, 8),
8334 rule->patterns[j].mask) ||
8335 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8336 rule->patterns[j].pattern) ||
8337 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8338 rule->patterns[j].pkt_offset))
8340 nla_nest_end(msg, nl_pat);
8342 nla_nest_end(msg, nl_pats);
8343 nla_nest_end(msg, nl_rule);
8345 nla_nest_end(msg, nl_rules);
8350 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8353 struct sk_buff *msg;
8356 if (!rdev->wiphy.coalesce)
8359 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8363 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8364 NL80211_CMD_GET_COALESCE);
8366 goto nla_put_failure;
8368 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8369 goto nla_put_failure;
8371 genlmsg_end(msg, hdr);
8372 return genlmsg_reply(msg, info);
8379 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8381 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8383 struct cfg80211_coalesce_rules *rule;
8388 for (i = 0; i < coalesce->n_rules; i++) {
8389 rule = &coalesce->rules[i];
8390 for (j = 0; j < rule->n_patterns; j++)
8391 kfree(rule->patterns[j].mask);
8392 kfree(rule->patterns);
8394 kfree(coalesce->rules);
8396 rdev->coalesce = NULL;
8399 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8400 struct nlattr *rule,
8401 struct cfg80211_coalesce_rules *new_rule)
8404 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8405 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8406 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8407 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8409 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8410 nla_len(rule), nl80211_coalesce_policy);
8414 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8416 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8417 if (new_rule->delay > coalesce->max_delay)
8420 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8421 new_rule->condition =
8422 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8423 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8424 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8427 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8430 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8433 if (n_patterns > coalesce->n_patterns)
8436 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8438 if (!new_rule->patterns)
8441 new_rule->n_patterns = n_patterns;
8444 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8446 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8447 nla_len(pat), NULL);
8448 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8449 !pat_tb[NL80211_PKTPAT_PATTERN])
8451 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8452 mask_len = DIV_ROUND_UP(pat_len, 8);
8453 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8455 if (pat_len > coalesce->pattern_max_len ||
8456 pat_len < coalesce->pattern_min_len)
8459 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8462 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8463 if (pkt_offset > coalesce->max_pkt_offset)
8465 new_rule->patterns[i].pkt_offset = pkt_offset;
8467 new_rule->patterns[i].mask =
8468 kmalloc(mask_len + pat_len, GFP_KERNEL);
8469 if (!new_rule->patterns[i].mask)
8471 new_rule->patterns[i].pattern =
8472 new_rule->patterns[i].mask + mask_len;
8473 memcpy(new_rule->patterns[i].mask,
8474 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8475 new_rule->patterns[i].pattern_len = pat_len;
8476 memcpy(new_rule->patterns[i].pattern,
8477 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8484 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8487 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8488 struct cfg80211_coalesce new_coalesce = {};
8489 struct cfg80211_coalesce *n_coalesce;
8490 int err, rem_rule, n_rules = 0, i, j;
8491 struct nlattr *rule;
8492 struct cfg80211_coalesce_rules *tmp_rule;
8494 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8497 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8498 cfg80211_rdev_free_coalesce(rdev);
8499 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8503 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8506 if (n_rules > coalesce->n_rules)
8509 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8511 if (!new_coalesce.rules)
8514 new_coalesce.n_rules = n_rules;
8517 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8519 err = nl80211_parse_coalesce_rule(rdev, rule,
8520 &new_coalesce.rules[i]);
8527 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8531 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8536 cfg80211_rdev_free_coalesce(rdev);
8537 rdev->coalesce = n_coalesce;
8541 for (i = 0; i < new_coalesce.n_rules; i++) {
8542 tmp_rule = &new_coalesce.rules[i];
8543 for (j = 0; j < tmp_rule->n_patterns; j++)
8544 kfree(tmp_rule->patterns[j].mask);
8545 kfree(tmp_rule->patterns);
8547 kfree(new_coalesce.rules);
8552 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8555 struct net_device *dev = info->user_ptr[1];
8556 struct wireless_dev *wdev = dev->ieee80211_ptr;
8557 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8558 struct cfg80211_gtk_rekey_data rekey_data;
8561 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8564 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8565 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8566 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8567 nl80211_rekey_policy);
8571 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8573 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8575 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8578 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8580 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8582 memcpy(rekey_data.replay_ctr,
8583 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8584 NL80211_REPLAY_CTR_LEN);
8587 if (!wdev->current_bss) {
8592 if (!rdev->ops->set_rekey_data) {
8597 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
8603 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8604 struct genl_info *info)
8606 struct net_device *dev = info->user_ptr[1];
8607 struct wireless_dev *wdev = dev->ieee80211_ptr;
8609 if (wdev->iftype != NL80211_IFTYPE_AP &&
8610 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8613 if (wdev->ap_unexpected_nlportid)
8616 wdev->ap_unexpected_nlportid = info->snd_portid;
8620 static int nl80211_probe_client(struct sk_buff *skb,
8621 struct genl_info *info)
8623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8624 struct net_device *dev = info->user_ptr[1];
8625 struct wireless_dev *wdev = dev->ieee80211_ptr;
8626 struct sk_buff *msg;
8632 if (wdev->iftype != NL80211_IFTYPE_AP &&
8633 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8636 if (!info->attrs[NL80211_ATTR_MAC])
8639 if (!rdev->ops->probe_client)
8642 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8646 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8647 NL80211_CMD_PROBE_CLIENT);
8653 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8655 err = rdev_probe_client(rdev, dev, addr, &cookie);
8659 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8660 goto nla_put_failure;
8662 genlmsg_end(msg, hdr);
8664 return genlmsg_reply(msg, info);
8673 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8676 struct cfg80211_beacon_registration *reg, *nreg;
8679 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8682 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8686 /* First, check if already registered. */
8687 spin_lock_bh(&rdev->beacon_registrations_lock);
8688 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8689 if (reg->nlportid == info->snd_portid) {
8694 /* Add it to the list */
8695 nreg->nlportid = info->snd_portid;
8696 list_add(&nreg->list, &rdev->beacon_registrations);
8698 spin_unlock_bh(&rdev->beacon_registrations_lock);
8702 spin_unlock_bh(&rdev->beacon_registrations_lock);
8707 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8710 struct wireless_dev *wdev = info->user_ptr[1];
8713 if (!rdev->ops->start_p2p_device)
8716 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8719 if (wdev->p2p_started)
8722 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8726 err = rdev_start_p2p_device(rdev, wdev);
8730 wdev->p2p_started = true;
8736 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8739 struct wireless_dev *wdev = info->user_ptr[1];
8741 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8744 if (!rdev->ops->stop_p2p_device)
8747 cfg80211_stop_p2p_device(rdev, wdev);
8752 static int nl80211_get_protocol_features(struct sk_buff *skb,
8753 struct genl_info *info)
8756 struct sk_buff *msg;
8758 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8762 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8763 NL80211_CMD_GET_PROTOCOL_FEATURES);
8765 goto nla_put_failure;
8767 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8768 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8769 goto nla_put_failure;
8771 genlmsg_end(msg, hdr);
8772 return genlmsg_reply(msg, info);
8779 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8782 struct cfg80211_update_ft_ies_params ft_params;
8783 struct net_device *dev = info->user_ptr[1];
8785 if (!rdev->ops->update_ft_ies)
8788 if (!info->attrs[NL80211_ATTR_MDID] ||
8789 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8792 memset(&ft_params, 0, sizeof(ft_params));
8793 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8794 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8795 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8797 return rdev_update_ft_ies(rdev, dev, &ft_params);
8800 static int nl80211_crit_protocol_start(struct sk_buff *skb,
8801 struct genl_info *info)
8803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8804 struct wireless_dev *wdev = info->user_ptr[1];
8805 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8809 if (!rdev->ops->crit_proto_start)
8812 if (WARN_ON(!rdev->ops->crit_proto_stop))
8815 if (rdev->crit_proto_nlportid)
8818 /* determine protocol if provided */
8819 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8820 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8822 if (proto >= NUM_NL80211_CRIT_PROTO)
8825 /* timeout must be provided */
8826 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8830 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8832 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8835 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8837 rdev->crit_proto_nlportid = info->snd_portid;
8842 static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8843 struct genl_info *info)
8845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8846 struct wireless_dev *wdev = info->user_ptr[1];
8848 if (!rdev->ops->crit_proto_stop)
8851 if (rdev->crit_proto_nlportid) {
8852 rdev->crit_proto_nlportid = 0;
8853 rdev_crit_proto_stop(rdev, wdev);
8858 #define NL80211_FLAG_NEED_WIPHY 0x01
8859 #define NL80211_FLAG_NEED_NETDEV 0x02
8860 #define NL80211_FLAG_NEED_RTNL 0x04
8861 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8862 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8863 NL80211_FLAG_CHECK_NETDEV_UP)
8864 #define NL80211_FLAG_NEED_WDEV 0x10
8865 /* If a netdev is associated, it must be UP, P2P must be started */
8866 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8867 NL80211_FLAG_CHECK_NETDEV_UP)
8869 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
8870 struct genl_info *info)
8872 struct cfg80211_registered_device *rdev;
8873 struct wireless_dev *wdev;
8874 struct net_device *dev;
8875 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8880 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
8881 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
8885 return PTR_ERR(rdev);
8887 info->user_ptr[0] = rdev;
8888 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8889 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8892 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8897 return PTR_ERR(wdev);
8901 rdev = wiphy_to_dev(wdev->wiphy);
8903 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8910 info->user_ptr[1] = dev;
8912 info->user_ptr[1] = wdev;
8916 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8917 !netif_running(dev)) {
8924 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8925 if (!wdev->p2p_started) {
8932 info->user_ptr[0] = rdev;
8938 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
8939 struct genl_info *info)
8941 if (info->user_ptr[1]) {
8942 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8943 struct wireless_dev *wdev = info->user_ptr[1];
8946 dev_put(wdev->netdev);
8948 dev_put(info->user_ptr[1]);
8951 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8955 static const struct genl_ops nl80211_ops[] = {
8957 .cmd = NL80211_CMD_GET_WIPHY,
8958 .doit = nl80211_get_wiphy,
8959 .dumpit = nl80211_dump_wiphy,
8960 .done = nl80211_dump_wiphy_done,
8961 .policy = nl80211_policy,
8962 /* can be retrieved by unprivileged users */
8963 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8964 NL80211_FLAG_NEED_RTNL,
8967 .cmd = NL80211_CMD_SET_WIPHY,
8968 .doit = nl80211_set_wiphy,
8969 .policy = nl80211_policy,
8970 .flags = GENL_ADMIN_PERM,
8971 .internal_flags = NL80211_FLAG_NEED_RTNL,
8974 .cmd = NL80211_CMD_GET_INTERFACE,
8975 .doit = nl80211_get_interface,
8976 .dumpit = nl80211_dump_interface,
8977 .policy = nl80211_policy,
8978 /* can be retrieved by unprivileged users */
8979 .internal_flags = NL80211_FLAG_NEED_WDEV |
8980 NL80211_FLAG_NEED_RTNL,
8983 .cmd = NL80211_CMD_SET_INTERFACE,
8984 .doit = nl80211_set_interface,
8985 .policy = nl80211_policy,
8986 .flags = GENL_ADMIN_PERM,
8987 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8988 NL80211_FLAG_NEED_RTNL,
8991 .cmd = NL80211_CMD_NEW_INTERFACE,
8992 .doit = nl80211_new_interface,
8993 .policy = nl80211_policy,
8994 .flags = GENL_ADMIN_PERM,
8995 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8996 NL80211_FLAG_NEED_RTNL,
8999 .cmd = NL80211_CMD_DEL_INTERFACE,
9000 .doit = nl80211_del_interface,
9001 .policy = nl80211_policy,
9002 .flags = GENL_ADMIN_PERM,
9003 .internal_flags = NL80211_FLAG_NEED_WDEV |
9004 NL80211_FLAG_NEED_RTNL,
9007 .cmd = NL80211_CMD_GET_KEY,
9008 .doit = nl80211_get_key,
9009 .policy = nl80211_policy,
9010 .flags = GENL_ADMIN_PERM,
9011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9012 NL80211_FLAG_NEED_RTNL,
9015 .cmd = NL80211_CMD_SET_KEY,
9016 .doit = nl80211_set_key,
9017 .policy = nl80211_policy,
9018 .flags = GENL_ADMIN_PERM,
9019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9020 NL80211_FLAG_NEED_RTNL,
9023 .cmd = NL80211_CMD_NEW_KEY,
9024 .doit = nl80211_new_key,
9025 .policy = nl80211_policy,
9026 .flags = GENL_ADMIN_PERM,
9027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9028 NL80211_FLAG_NEED_RTNL,
9031 .cmd = NL80211_CMD_DEL_KEY,
9032 .doit = nl80211_del_key,
9033 .policy = nl80211_policy,
9034 .flags = GENL_ADMIN_PERM,
9035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9036 NL80211_FLAG_NEED_RTNL,
9039 .cmd = NL80211_CMD_SET_BEACON,
9040 .policy = nl80211_policy,
9041 .flags = GENL_ADMIN_PERM,
9042 .doit = nl80211_set_beacon,
9043 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9044 NL80211_FLAG_NEED_RTNL,
9047 .cmd = NL80211_CMD_START_AP,
9048 .policy = nl80211_policy,
9049 .flags = GENL_ADMIN_PERM,
9050 .doit = nl80211_start_ap,
9051 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9052 NL80211_FLAG_NEED_RTNL,
9055 .cmd = NL80211_CMD_STOP_AP,
9056 .policy = nl80211_policy,
9057 .flags = GENL_ADMIN_PERM,
9058 .doit = nl80211_stop_ap,
9059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9060 NL80211_FLAG_NEED_RTNL,
9063 .cmd = NL80211_CMD_GET_STATION,
9064 .doit = nl80211_get_station,
9065 .dumpit = nl80211_dump_station,
9066 .policy = nl80211_policy,
9067 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9068 NL80211_FLAG_NEED_RTNL,
9071 .cmd = NL80211_CMD_SET_STATION,
9072 .doit = nl80211_set_station,
9073 .policy = nl80211_policy,
9074 .flags = GENL_ADMIN_PERM,
9075 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9076 NL80211_FLAG_NEED_RTNL,
9079 .cmd = NL80211_CMD_NEW_STATION,
9080 .doit = nl80211_new_station,
9081 .policy = nl80211_policy,
9082 .flags = GENL_ADMIN_PERM,
9083 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9084 NL80211_FLAG_NEED_RTNL,
9087 .cmd = NL80211_CMD_DEL_STATION,
9088 .doit = nl80211_del_station,
9089 .policy = nl80211_policy,
9090 .flags = GENL_ADMIN_PERM,
9091 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9092 NL80211_FLAG_NEED_RTNL,
9095 .cmd = NL80211_CMD_GET_MPATH,
9096 .doit = nl80211_get_mpath,
9097 .dumpit = nl80211_dump_mpath,
9098 .policy = nl80211_policy,
9099 .flags = GENL_ADMIN_PERM,
9100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9101 NL80211_FLAG_NEED_RTNL,
9104 .cmd = NL80211_CMD_SET_MPATH,
9105 .doit = nl80211_set_mpath,
9106 .policy = nl80211_policy,
9107 .flags = GENL_ADMIN_PERM,
9108 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9109 NL80211_FLAG_NEED_RTNL,
9112 .cmd = NL80211_CMD_NEW_MPATH,
9113 .doit = nl80211_new_mpath,
9114 .policy = nl80211_policy,
9115 .flags = GENL_ADMIN_PERM,
9116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9117 NL80211_FLAG_NEED_RTNL,
9120 .cmd = NL80211_CMD_DEL_MPATH,
9121 .doit = nl80211_del_mpath,
9122 .policy = nl80211_policy,
9123 .flags = GENL_ADMIN_PERM,
9124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9125 NL80211_FLAG_NEED_RTNL,
9128 .cmd = NL80211_CMD_SET_BSS,
9129 .doit = nl80211_set_bss,
9130 .policy = nl80211_policy,
9131 .flags = GENL_ADMIN_PERM,
9132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9133 NL80211_FLAG_NEED_RTNL,
9136 .cmd = NL80211_CMD_GET_REG,
9137 .doit = nl80211_get_reg,
9138 .policy = nl80211_policy,
9139 .internal_flags = NL80211_FLAG_NEED_RTNL,
9140 /* can be retrieved by unprivileged users */
9143 .cmd = NL80211_CMD_SET_REG,
9144 .doit = nl80211_set_reg,
9145 .policy = nl80211_policy,
9146 .flags = GENL_ADMIN_PERM,
9147 .internal_flags = NL80211_FLAG_NEED_RTNL,
9150 .cmd = NL80211_CMD_REQ_SET_REG,
9151 .doit = nl80211_req_set_reg,
9152 .policy = nl80211_policy,
9153 .flags = GENL_ADMIN_PERM,
9156 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9157 .doit = nl80211_get_mesh_config,
9158 .policy = nl80211_policy,
9159 /* can be retrieved by unprivileged users */
9160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9161 NL80211_FLAG_NEED_RTNL,
9164 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9165 .doit = nl80211_update_mesh_config,
9166 .policy = nl80211_policy,
9167 .flags = GENL_ADMIN_PERM,
9168 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9169 NL80211_FLAG_NEED_RTNL,
9172 .cmd = NL80211_CMD_TRIGGER_SCAN,
9173 .doit = nl80211_trigger_scan,
9174 .policy = nl80211_policy,
9175 .flags = GENL_ADMIN_PERM,
9176 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9177 NL80211_FLAG_NEED_RTNL,
9180 .cmd = NL80211_CMD_GET_SCAN,
9181 .policy = nl80211_policy,
9182 .dumpit = nl80211_dump_scan,
9185 .cmd = NL80211_CMD_START_SCHED_SCAN,
9186 .doit = nl80211_start_sched_scan,
9187 .policy = nl80211_policy,
9188 .flags = GENL_ADMIN_PERM,
9189 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9190 NL80211_FLAG_NEED_RTNL,
9193 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9194 .doit = nl80211_stop_sched_scan,
9195 .policy = nl80211_policy,
9196 .flags = GENL_ADMIN_PERM,
9197 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9198 NL80211_FLAG_NEED_RTNL,
9201 .cmd = NL80211_CMD_AUTHENTICATE,
9202 .doit = nl80211_authenticate,
9203 .policy = nl80211_policy,
9204 .flags = GENL_ADMIN_PERM,
9205 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9206 NL80211_FLAG_NEED_RTNL,
9209 .cmd = NL80211_CMD_ASSOCIATE,
9210 .doit = nl80211_associate,
9211 .policy = nl80211_policy,
9212 .flags = GENL_ADMIN_PERM,
9213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9214 NL80211_FLAG_NEED_RTNL,
9217 .cmd = NL80211_CMD_DEAUTHENTICATE,
9218 .doit = nl80211_deauthenticate,
9219 .policy = nl80211_policy,
9220 .flags = GENL_ADMIN_PERM,
9221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9222 NL80211_FLAG_NEED_RTNL,
9225 .cmd = NL80211_CMD_DISASSOCIATE,
9226 .doit = nl80211_disassociate,
9227 .policy = nl80211_policy,
9228 .flags = GENL_ADMIN_PERM,
9229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9230 NL80211_FLAG_NEED_RTNL,
9233 .cmd = NL80211_CMD_JOIN_IBSS,
9234 .doit = nl80211_join_ibss,
9235 .policy = nl80211_policy,
9236 .flags = GENL_ADMIN_PERM,
9237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9238 NL80211_FLAG_NEED_RTNL,
9241 .cmd = NL80211_CMD_LEAVE_IBSS,
9242 .doit = nl80211_leave_ibss,
9243 .policy = nl80211_policy,
9244 .flags = GENL_ADMIN_PERM,
9245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9246 NL80211_FLAG_NEED_RTNL,
9248 #ifdef CONFIG_NL80211_TESTMODE
9250 .cmd = NL80211_CMD_TESTMODE,
9251 .doit = nl80211_testmode_do,
9252 .dumpit = nl80211_testmode_dump,
9253 .policy = nl80211_policy,
9254 .flags = GENL_ADMIN_PERM,
9255 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9256 NL80211_FLAG_NEED_RTNL,
9260 .cmd = NL80211_CMD_CONNECT,
9261 .doit = nl80211_connect,
9262 .policy = nl80211_policy,
9263 .flags = GENL_ADMIN_PERM,
9264 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9265 NL80211_FLAG_NEED_RTNL,
9268 .cmd = NL80211_CMD_DISCONNECT,
9269 .doit = nl80211_disconnect,
9270 .policy = nl80211_policy,
9271 .flags = GENL_ADMIN_PERM,
9272 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9273 NL80211_FLAG_NEED_RTNL,
9276 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9277 .doit = nl80211_wiphy_netns,
9278 .policy = nl80211_policy,
9279 .flags = GENL_ADMIN_PERM,
9280 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9281 NL80211_FLAG_NEED_RTNL,
9284 .cmd = NL80211_CMD_GET_SURVEY,
9285 .policy = nl80211_policy,
9286 .dumpit = nl80211_dump_survey,
9289 .cmd = NL80211_CMD_SET_PMKSA,
9290 .doit = nl80211_setdel_pmksa,
9291 .policy = nl80211_policy,
9292 .flags = GENL_ADMIN_PERM,
9293 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9294 NL80211_FLAG_NEED_RTNL,
9297 .cmd = NL80211_CMD_DEL_PMKSA,
9298 .doit = nl80211_setdel_pmksa,
9299 .policy = nl80211_policy,
9300 .flags = GENL_ADMIN_PERM,
9301 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9302 NL80211_FLAG_NEED_RTNL,
9305 .cmd = NL80211_CMD_FLUSH_PMKSA,
9306 .doit = nl80211_flush_pmksa,
9307 .policy = nl80211_policy,
9308 .flags = GENL_ADMIN_PERM,
9309 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9310 NL80211_FLAG_NEED_RTNL,
9313 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9314 .doit = nl80211_remain_on_channel,
9315 .policy = nl80211_policy,
9316 .flags = GENL_ADMIN_PERM,
9317 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9318 NL80211_FLAG_NEED_RTNL,
9321 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9322 .doit = nl80211_cancel_remain_on_channel,
9323 .policy = nl80211_policy,
9324 .flags = GENL_ADMIN_PERM,
9325 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9326 NL80211_FLAG_NEED_RTNL,
9329 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9330 .doit = nl80211_set_tx_bitrate_mask,
9331 .policy = nl80211_policy,
9332 .flags = GENL_ADMIN_PERM,
9333 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9334 NL80211_FLAG_NEED_RTNL,
9337 .cmd = NL80211_CMD_REGISTER_FRAME,
9338 .doit = nl80211_register_mgmt,
9339 .policy = nl80211_policy,
9340 .flags = GENL_ADMIN_PERM,
9341 .internal_flags = NL80211_FLAG_NEED_WDEV |
9342 NL80211_FLAG_NEED_RTNL,
9345 .cmd = NL80211_CMD_FRAME,
9346 .doit = nl80211_tx_mgmt,
9347 .policy = nl80211_policy,
9348 .flags = GENL_ADMIN_PERM,
9349 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9350 NL80211_FLAG_NEED_RTNL,
9353 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9354 .doit = nl80211_tx_mgmt_cancel_wait,
9355 .policy = nl80211_policy,
9356 .flags = GENL_ADMIN_PERM,
9357 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9358 NL80211_FLAG_NEED_RTNL,
9361 .cmd = NL80211_CMD_SET_POWER_SAVE,
9362 .doit = nl80211_set_power_save,
9363 .policy = nl80211_policy,
9364 .flags = GENL_ADMIN_PERM,
9365 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9366 NL80211_FLAG_NEED_RTNL,
9369 .cmd = NL80211_CMD_GET_POWER_SAVE,
9370 .doit = nl80211_get_power_save,
9371 .policy = nl80211_policy,
9372 /* can be retrieved by unprivileged users */
9373 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9374 NL80211_FLAG_NEED_RTNL,
9377 .cmd = NL80211_CMD_SET_CQM,
9378 .doit = nl80211_set_cqm,
9379 .policy = nl80211_policy,
9380 .flags = GENL_ADMIN_PERM,
9381 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9382 NL80211_FLAG_NEED_RTNL,
9385 .cmd = NL80211_CMD_SET_CHANNEL,
9386 .doit = nl80211_set_channel,
9387 .policy = nl80211_policy,
9388 .flags = GENL_ADMIN_PERM,
9389 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9390 NL80211_FLAG_NEED_RTNL,
9393 .cmd = NL80211_CMD_SET_WDS_PEER,
9394 .doit = nl80211_set_wds_peer,
9395 .policy = nl80211_policy,
9396 .flags = GENL_ADMIN_PERM,
9397 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9398 NL80211_FLAG_NEED_RTNL,
9401 .cmd = NL80211_CMD_JOIN_MESH,
9402 .doit = nl80211_join_mesh,
9403 .policy = nl80211_policy,
9404 .flags = GENL_ADMIN_PERM,
9405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9406 NL80211_FLAG_NEED_RTNL,
9409 .cmd = NL80211_CMD_LEAVE_MESH,
9410 .doit = nl80211_leave_mesh,
9411 .policy = nl80211_policy,
9412 .flags = GENL_ADMIN_PERM,
9413 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9414 NL80211_FLAG_NEED_RTNL,
9418 .cmd = NL80211_CMD_GET_WOWLAN,
9419 .doit = nl80211_get_wowlan,
9420 .policy = nl80211_policy,
9421 /* can be retrieved by unprivileged users */
9422 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9423 NL80211_FLAG_NEED_RTNL,
9426 .cmd = NL80211_CMD_SET_WOWLAN,
9427 .doit = nl80211_set_wowlan,
9428 .policy = nl80211_policy,
9429 .flags = GENL_ADMIN_PERM,
9430 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9431 NL80211_FLAG_NEED_RTNL,
9435 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9436 .doit = nl80211_set_rekey_data,
9437 .policy = nl80211_policy,
9438 .flags = GENL_ADMIN_PERM,
9439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9440 NL80211_FLAG_NEED_RTNL,
9443 .cmd = NL80211_CMD_TDLS_MGMT,
9444 .doit = nl80211_tdls_mgmt,
9445 .policy = nl80211_policy,
9446 .flags = GENL_ADMIN_PERM,
9447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9448 NL80211_FLAG_NEED_RTNL,
9451 .cmd = NL80211_CMD_TDLS_OPER,
9452 .doit = nl80211_tdls_oper,
9453 .policy = nl80211_policy,
9454 .flags = GENL_ADMIN_PERM,
9455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9456 NL80211_FLAG_NEED_RTNL,
9459 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9460 .doit = nl80211_register_unexpected_frame,
9461 .policy = nl80211_policy,
9462 .flags = GENL_ADMIN_PERM,
9463 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9464 NL80211_FLAG_NEED_RTNL,
9467 .cmd = NL80211_CMD_PROBE_CLIENT,
9468 .doit = nl80211_probe_client,
9469 .policy = nl80211_policy,
9470 .flags = GENL_ADMIN_PERM,
9471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9472 NL80211_FLAG_NEED_RTNL,
9475 .cmd = NL80211_CMD_REGISTER_BEACONS,
9476 .doit = nl80211_register_beacons,
9477 .policy = nl80211_policy,
9478 .flags = GENL_ADMIN_PERM,
9479 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9480 NL80211_FLAG_NEED_RTNL,
9483 .cmd = NL80211_CMD_SET_NOACK_MAP,
9484 .doit = nl80211_set_noack_map,
9485 .policy = nl80211_policy,
9486 .flags = GENL_ADMIN_PERM,
9487 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9488 NL80211_FLAG_NEED_RTNL,
9491 .cmd = NL80211_CMD_START_P2P_DEVICE,
9492 .doit = nl80211_start_p2p_device,
9493 .policy = nl80211_policy,
9494 .flags = GENL_ADMIN_PERM,
9495 .internal_flags = NL80211_FLAG_NEED_WDEV |
9496 NL80211_FLAG_NEED_RTNL,
9499 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9500 .doit = nl80211_stop_p2p_device,
9501 .policy = nl80211_policy,
9502 .flags = GENL_ADMIN_PERM,
9503 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9504 NL80211_FLAG_NEED_RTNL,
9507 .cmd = NL80211_CMD_SET_MCAST_RATE,
9508 .doit = nl80211_set_mcast_rate,
9509 .policy = nl80211_policy,
9510 .flags = GENL_ADMIN_PERM,
9511 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9512 NL80211_FLAG_NEED_RTNL,
9515 .cmd = NL80211_CMD_SET_MAC_ACL,
9516 .doit = nl80211_set_mac_acl,
9517 .policy = nl80211_policy,
9518 .flags = GENL_ADMIN_PERM,
9519 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9520 NL80211_FLAG_NEED_RTNL,
9523 .cmd = NL80211_CMD_RADAR_DETECT,
9524 .doit = nl80211_start_radar_detection,
9525 .policy = nl80211_policy,
9526 .flags = GENL_ADMIN_PERM,
9527 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9528 NL80211_FLAG_NEED_RTNL,
9531 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9532 .doit = nl80211_get_protocol_features,
9533 .policy = nl80211_policy,
9536 .cmd = NL80211_CMD_UPDATE_FT_IES,
9537 .doit = nl80211_update_ft_ies,
9538 .policy = nl80211_policy,
9539 .flags = GENL_ADMIN_PERM,
9540 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9541 NL80211_FLAG_NEED_RTNL,
9544 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9545 .doit = nl80211_crit_protocol_start,
9546 .policy = nl80211_policy,
9547 .flags = GENL_ADMIN_PERM,
9548 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9549 NL80211_FLAG_NEED_RTNL,
9552 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9553 .doit = nl80211_crit_protocol_stop,
9554 .policy = nl80211_policy,
9555 .flags = GENL_ADMIN_PERM,
9556 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9557 NL80211_FLAG_NEED_RTNL,
9560 .cmd = NL80211_CMD_GET_COALESCE,
9561 .doit = nl80211_get_coalesce,
9562 .policy = nl80211_policy,
9563 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9564 NL80211_FLAG_NEED_RTNL,
9567 .cmd = NL80211_CMD_SET_COALESCE,
9568 .doit = nl80211_set_coalesce,
9569 .policy = nl80211_policy,
9570 .flags = GENL_ADMIN_PERM,
9571 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9572 NL80211_FLAG_NEED_RTNL,
9575 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9576 .doit = nl80211_channel_switch,
9577 .policy = nl80211_policy,
9578 .flags = GENL_ADMIN_PERM,
9579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9580 NL80211_FLAG_NEED_RTNL,
9584 /* notification functions */
9586 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9588 struct sk_buff *msg;
9589 struct nl80211_dump_wiphy_state state = {};
9591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9595 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
9600 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9601 NL80211_MCGRP_CONFIG, GFP_KERNEL);
9604 static int nl80211_add_scan_req(struct sk_buff *msg,
9605 struct cfg80211_registered_device *rdev)
9607 struct cfg80211_scan_request *req = rdev->scan_req;
9608 struct nlattr *nest;
9614 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9616 goto nla_put_failure;
9617 for (i = 0; i < req->n_ssids; i++) {
9618 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9619 goto nla_put_failure;
9621 nla_nest_end(msg, nest);
9623 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9625 goto nla_put_failure;
9626 for (i = 0; i < req->n_channels; i++) {
9627 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9628 goto nla_put_failure;
9630 nla_nest_end(msg, nest);
9633 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9634 goto nla_put_failure;
9637 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9644 static int nl80211_send_scan_msg(struct sk_buff *msg,
9645 struct cfg80211_registered_device *rdev,
9646 struct wireless_dev *wdev,
9647 u32 portid, u32 seq, int flags,
9652 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
9656 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9657 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9658 wdev->netdev->ifindex)) ||
9659 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9660 goto nla_put_failure;
9662 /* ignore errors and send incomplete event anyway */
9663 nl80211_add_scan_req(msg, rdev);
9665 return genlmsg_end(msg, hdr);
9668 genlmsg_cancel(msg, hdr);
9673 nl80211_send_sched_scan_msg(struct sk_buff *msg,
9674 struct cfg80211_registered_device *rdev,
9675 struct net_device *netdev,
9676 u32 portid, u32 seq, int flags, u32 cmd)
9680 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
9684 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9685 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9686 goto nla_put_failure;
9688 return genlmsg_end(msg, hdr);
9691 genlmsg_cancel(msg, hdr);
9695 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
9696 struct wireless_dev *wdev)
9698 struct sk_buff *msg;
9700 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9704 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
9705 NL80211_CMD_TRIGGER_SCAN) < 0) {
9710 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9711 NL80211_MCGRP_SCAN, GFP_KERNEL);
9714 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
9715 struct wireless_dev *wdev)
9717 struct sk_buff *msg;
9719 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9723 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
9724 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
9729 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9730 NL80211_MCGRP_SCAN, GFP_KERNEL);
9733 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
9734 struct wireless_dev *wdev)
9736 struct sk_buff *msg;
9738 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9742 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
9743 NL80211_CMD_SCAN_ABORTED) < 0) {
9748 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9749 NL80211_MCGRP_SCAN, GFP_KERNEL);
9752 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9753 struct net_device *netdev)
9755 struct sk_buff *msg;
9757 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9761 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9762 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9767 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9768 NL80211_MCGRP_SCAN, GFP_KERNEL);
9771 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9772 struct net_device *netdev, u32 cmd)
9774 struct sk_buff *msg;
9776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9780 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9785 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9786 NL80211_MCGRP_SCAN, GFP_KERNEL);
9790 * This can happen on global regulatory changes or device specific settings
9791 * based on custom world regulatory domains.
9793 void nl80211_send_reg_change_event(struct regulatory_request *request)
9795 struct sk_buff *msg;
9798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9802 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9808 /* Userspace can always count this one always being set */
9809 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9810 goto nla_put_failure;
9812 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9813 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9814 NL80211_REGDOM_TYPE_WORLD))
9815 goto nla_put_failure;
9816 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9817 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9818 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9819 goto nla_put_failure;
9820 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9821 request->intersect) {
9822 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9823 NL80211_REGDOM_TYPE_INTERSECTION))
9824 goto nla_put_failure;
9826 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9827 NL80211_REGDOM_TYPE_COUNTRY) ||
9828 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9830 goto nla_put_failure;
9833 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
9834 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9835 goto nla_put_failure;
9837 genlmsg_end(msg, hdr);
9840 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
9841 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
9847 genlmsg_cancel(msg, hdr);
9851 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9852 struct net_device *netdev,
9853 const u8 *buf, size_t len,
9854 enum nl80211_commands cmd, gfp_t gfp)
9856 struct sk_buff *msg;
9859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9863 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9870 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9871 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9872 goto nla_put_failure;
9874 genlmsg_end(msg, hdr);
9876 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9877 NL80211_MCGRP_MLME, gfp);
9881 genlmsg_cancel(msg, hdr);
9885 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
9886 struct net_device *netdev, const u8 *buf,
9887 size_t len, gfp_t gfp)
9889 nl80211_send_mlme_event(rdev, netdev, buf, len,
9890 NL80211_CMD_AUTHENTICATE, gfp);
9893 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9894 struct net_device *netdev, const u8 *buf,
9895 size_t len, gfp_t gfp)
9897 nl80211_send_mlme_event(rdev, netdev, buf, len,
9898 NL80211_CMD_ASSOCIATE, gfp);
9901 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
9902 struct net_device *netdev, const u8 *buf,
9903 size_t len, gfp_t gfp)
9905 nl80211_send_mlme_event(rdev, netdev, buf, len,
9906 NL80211_CMD_DEAUTHENTICATE, gfp);
9909 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9910 struct net_device *netdev, const u8 *buf,
9911 size_t len, gfp_t gfp)
9913 nl80211_send_mlme_event(rdev, netdev, buf, len,
9914 NL80211_CMD_DISASSOCIATE, gfp);
9917 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9920 struct wireless_dev *wdev = dev->ieee80211_ptr;
9921 struct wiphy *wiphy = wdev->wiphy;
9922 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9923 const struct ieee80211_mgmt *mgmt = (void *)buf;
9926 if (WARN_ON(len < 2))
9929 if (ieee80211_is_deauth(mgmt->frame_control))
9930 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9932 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9934 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9935 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
9937 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
9939 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9940 struct net_device *netdev, int cmd,
9941 const u8 *addr, gfp_t gfp)
9943 struct sk_buff *msg;
9946 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9950 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9956 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9957 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9958 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9959 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9960 goto nla_put_failure;
9962 genlmsg_end(msg, hdr);
9964 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
9965 NL80211_MCGRP_MLME, gfp);
9969 genlmsg_cancel(msg, hdr);
9973 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
9974 struct net_device *netdev, const u8 *addr,
9977 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
9981 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
9982 struct net_device *netdev, const u8 *addr,
9985 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9989 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9990 struct net_device *netdev, const u8 *bssid,
9991 const u8 *req_ie, size_t req_ie_len,
9992 const u8 *resp_ie, size_t resp_ie_len,
9993 u16 status, gfp_t gfp)
9995 struct sk_buff *msg;
9998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10002 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10008 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10009 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10010 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10011 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10013 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10015 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10016 goto nla_put_failure;
10018 genlmsg_end(msg, hdr);
10020 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10021 NL80211_MCGRP_MLME, gfp);
10025 genlmsg_cancel(msg, hdr);
10030 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10031 struct net_device *netdev, const u8 *bssid,
10032 const u8 *req_ie, size_t req_ie_len,
10033 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10035 struct sk_buff *msg;
10038 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10042 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10048 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10049 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10050 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10052 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10054 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10055 goto nla_put_failure;
10057 genlmsg_end(msg, hdr);
10059 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10060 NL80211_MCGRP_MLME, gfp);
10064 genlmsg_cancel(msg, hdr);
10069 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10070 struct net_device *netdev, u16 reason,
10071 const u8 *ie, size_t ie_len, bool from_ap)
10073 struct sk_buff *msg;
10076 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10080 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10086 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10087 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10088 (from_ap && reason &&
10089 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10091 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10092 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10093 goto nla_put_failure;
10095 genlmsg_end(msg, hdr);
10097 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10098 NL80211_MCGRP_MLME, GFP_KERNEL);
10102 genlmsg_cancel(msg, hdr);
10107 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10108 struct net_device *netdev, const u8 *bssid,
10111 struct sk_buff *msg;
10114 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10118 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10124 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10125 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10126 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10127 goto nla_put_failure;
10129 genlmsg_end(msg, hdr);
10131 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10132 NL80211_MCGRP_MLME, gfp);
10136 genlmsg_cancel(msg, hdr);
10140 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10141 const u8* ie, u8 ie_len, gfp_t gfp)
10143 struct wireless_dev *wdev = dev->ieee80211_ptr;
10144 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10145 struct sk_buff *msg;
10148 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10151 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10153 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10157 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10163 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10164 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10165 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10167 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10168 goto nla_put_failure;
10170 genlmsg_end(msg, hdr);
10172 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10173 NL80211_MCGRP_MLME, gfp);
10177 genlmsg_cancel(msg, hdr);
10180 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
10182 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10183 struct net_device *netdev, const u8 *addr,
10184 enum nl80211_key_type key_type, int key_id,
10185 const u8 *tsc, gfp_t gfp)
10187 struct sk_buff *msg;
10190 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10194 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10200 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10201 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10202 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10203 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10205 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10206 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10207 goto nla_put_failure;
10209 genlmsg_end(msg, hdr);
10211 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10212 NL80211_MCGRP_MLME, gfp);
10216 genlmsg_cancel(msg, hdr);
10220 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10221 struct ieee80211_channel *channel_before,
10222 struct ieee80211_channel *channel_after)
10224 struct sk_buff *msg;
10226 struct nlattr *nl_freq;
10228 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
10232 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10239 * Since we are applying the beacon hint to a wiphy we know its
10240 * wiphy_idx is valid
10242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10243 goto nla_put_failure;
10246 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10248 goto nla_put_failure;
10249 if (nl80211_msg_put_channel(msg, channel_before, false))
10250 goto nla_put_failure;
10251 nla_nest_end(msg, nl_freq);
10254 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10256 goto nla_put_failure;
10257 if (nl80211_msg_put_channel(msg, channel_after, false))
10258 goto nla_put_failure;
10259 nla_nest_end(msg, nl_freq);
10261 genlmsg_end(msg, hdr);
10264 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
10265 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
10271 genlmsg_cancel(msg, hdr);
10275 static void nl80211_send_remain_on_chan_event(
10276 int cmd, struct cfg80211_registered_device *rdev,
10277 struct wireless_dev *wdev, u64 cookie,
10278 struct ieee80211_channel *chan,
10279 unsigned int duration, gfp_t gfp)
10281 struct sk_buff *msg;
10284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10288 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10295 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10296 wdev->netdev->ifindex)) ||
10297 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
10298 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
10299 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10300 NL80211_CHAN_NO_HT) ||
10301 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10302 goto nla_put_failure;
10304 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10305 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10306 goto nla_put_failure;
10308 genlmsg_end(msg, hdr);
10310 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10311 NL80211_MCGRP_MLME, gfp);
10315 genlmsg_cancel(msg, hdr);
10319 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10320 struct ieee80211_channel *chan,
10321 unsigned int duration, gfp_t gfp)
10323 struct wiphy *wiphy = wdev->wiphy;
10324 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10326 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
10327 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
10328 rdev, wdev, cookie, chan,
10331 EXPORT_SYMBOL(cfg80211_ready_on_channel);
10333 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10334 struct ieee80211_channel *chan,
10337 struct wiphy *wiphy = wdev->wiphy;
10338 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10340 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
10341 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10342 rdev, wdev, cookie, chan, 0, gfp);
10344 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
10346 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10347 struct station_info *sinfo, gfp_t gfp)
10349 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10350 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10351 struct sk_buff *msg;
10353 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10355 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10359 if (nl80211_send_station(msg, 0, 0, 0,
10360 rdev, dev, mac_addr, sinfo) < 0) {
10365 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10366 NL80211_MCGRP_MLME, gfp);
10368 EXPORT_SYMBOL(cfg80211_new_sta);
10370 void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
10372 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10373 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10374 struct sk_buff *msg;
10377 trace_cfg80211_del_sta(dev, mac_addr);
10379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10383 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10389 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10390 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10391 goto nla_put_failure;
10393 genlmsg_end(msg, hdr);
10395 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10396 NL80211_MCGRP_MLME, gfp);
10400 genlmsg_cancel(msg, hdr);
10403 EXPORT_SYMBOL(cfg80211_del_sta);
10405 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10406 enum nl80211_connect_failed_reason reason,
10409 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10410 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10411 struct sk_buff *msg;
10414 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10418 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10424 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10425 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10426 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10427 goto nla_put_failure;
10429 genlmsg_end(msg, hdr);
10431 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10432 NL80211_MCGRP_MLME, gfp);
10436 genlmsg_cancel(msg, hdr);
10439 EXPORT_SYMBOL(cfg80211_conn_failed);
10441 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10442 const u8 *addr, gfp_t gfp)
10444 struct wireless_dev *wdev = dev->ieee80211_ptr;
10445 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10446 struct sk_buff *msg;
10448 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
10453 msg = nlmsg_new(100, gfp);
10457 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10463 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10464 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10465 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10466 goto nla_put_failure;
10468 genlmsg_end(msg, hdr);
10469 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10473 genlmsg_cancel(msg, hdr);
10478 bool cfg80211_rx_spurious_frame(struct net_device *dev,
10479 const u8 *addr, gfp_t gfp)
10481 struct wireless_dev *wdev = dev->ieee80211_ptr;
10484 trace_cfg80211_rx_spurious_frame(dev, addr);
10486 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10487 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10488 trace_cfg80211_return_bool(false);
10491 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10493 trace_cfg80211_return_bool(ret);
10496 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10498 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10499 const u8 *addr, gfp_t gfp)
10501 struct wireless_dev *wdev = dev->ieee80211_ptr;
10504 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10506 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10507 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10508 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10509 trace_cfg80211_return_bool(false);
10512 ret = __nl80211_unexpected_frame(dev,
10513 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10515 trace_cfg80211_return_bool(ret);
10518 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
10520 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
10521 struct wireless_dev *wdev, u32 nlportid,
10522 int freq, int sig_dbm,
10523 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
10525 struct net_device *netdev = wdev->netdev;
10526 struct sk_buff *msg;
10529 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10533 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10539 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10540 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10541 netdev->ifindex)) ||
10542 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
10543 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10545 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10546 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10548 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
10549 goto nla_put_failure;
10551 genlmsg_end(msg, hdr);
10553 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10556 genlmsg_cancel(msg, hdr);
10561 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10562 const u8 *buf, size_t len, bool ack, gfp_t gfp)
10564 struct wiphy *wiphy = wdev->wiphy;
10565 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10566 struct net_device *netdev = wdev->netdev;
10567 struct sk_buff *msg;
10570 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10576 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
10582 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10583 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10584 netdev->ifindex)) ||
10585 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
10586 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10587 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10588 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10589 goto nla_put_failure;
10591 genlmsg_end(msg, hdr);
10593 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10594 NL80211_MCGRP_MLME, gfp);
10598 genlmsg_cancel(msg, hdr);
10601 EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
10603 void cfg80211_cqm_rssi_notify(struct net_device *dev,
10604 enum nl80211_cqm_rssi_threshold_event rssi_event,
10607 struct wireless_dev *wdev = dev->ieee80211_ptr;
10608 struct wiphy *wiphy = wdev->wiphy;
10609 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10610 struct sk_buff *msg;
10611 struct nlattr *pinfoattr;
10614 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10616 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10620 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10626 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
10628 goto nla_put_failure;
10630 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10632 goto nla_put_failure;
10634 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10636 goto nla_put_failure;
10638 nla_nest_end(msg, pinfoattr);
10640 genlmsg_end(msg, hdr);
10642 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10643 NL80211_MCGRP_MLME, gfp);
10647 genlmsg_cancel(msg, hdr);
10650 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
10652 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10653 struct net_device *netdev, const u8 *bssid,
10654 const u8 *replay_ctr, gfp_t gfp)
10656 struct sk_buff *msg;
10657 struct nlattr *rekey_attr;
10660 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10664 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10670 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10671 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10672 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10673 goto nla_put_failure;
10675 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10677 goto nla_put_failure;
10679 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10680 NL80211_REPLAY_CTR_LEN, replay_ctr))
10681 goto nla_put_failure;
10683 nla_nest_end(msg, rekey_attr);
10685 genlmsg_end(msg, hdr);
10687 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10688 NL80211_MCGRP_MLME, gfp);
10692 genlmsg_cancel(msg, hdr);
10696 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10697 const u8 *replay_ctr, gfp_t gfp)
10699 struct wireless_dev *wdev = dev->ieee80211_ptr;
10700 struct wiphy *wiphy = wdev->wiphy;
10701 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10703 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10704 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10706 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10709 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10710 struct net_device *netdev, int index,
10711 const u8 *bssid, bool preauth, gfp_t gfp)
10713 struct sk_buff *msg;
10714 struct nlattr *attr;
10717 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10721 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10727 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10728 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10729 goto nla_put_failure;
10731 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10733 goto nla_put_failure;
10735 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10736 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10738 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10739 goto nla_put_failure;
10741 nla_nest_end(msg, attr);
10743 genlmsg_end(msg, hdr);
10745 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10746 NL80211_MCGRP_MLME, gfp);
10750 genlmsg_cancel(msg, hdr);
10754 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10755 const u8 *bssid, bool preauth, gfp_t gfp)
10757 struct wireless_dev *wdev = dev->ieee80211_ptr;
10758 struct wiphy *wiphy = wdev->wiphy;
10759 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10761 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10762 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10764 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10766 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10767 struct net_device *netdev,
10768 struct cfg80211_chan_def *chandef,
10771 struct sk_buff *msg;
10774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10778 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10784 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10785 goto nla_put_failure;
10787 if (nl80211_send_chandef(msg, chandef))
10788 goto nla_put_failure;
10790 genlmsg_end(msg, hdr);
10792 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10793 NL80211_MCGRP_MLME, gfp);
10797 genlmsg_cancel(msg, hdr);
10801 void cfg80211_ch_switch_notify(struct net_device *dev,
10802 struct cfg80211_chan_def *chandef)
10804 struct wireless_dev *wdev = dev->ieee80211_ptr;
10805 struct wiphy *wiphy = wdev->wiphy;
10806 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10808 trace_cfg80211_ch_switch_notify(dev, chandef);
10812 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10813 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10814 wdev->iftype != NL80211_IFTYPE_ADHOC &&
10815 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10818 wdev->channel = chandef->chan;
10819 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10824 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10826 void cfg80211_cqm_txe_notify(struct net_device *dev,
10827 const u8 *peer, u32 num_packets,
10828 u32 rate, u32 intvl, gfp_t gfp)
10830 struct wireless_dev *wdev = dev->ieee80211_ptr;
10831 struct wiphy *wiphy = wdev->wiphy;
10832 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10833 struct sk_buff *msg;
10834 struct nlattr *pinfoattr;
10837 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10841 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10847 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10848 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10849 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10850 goto nla_put_failure;
10852 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10854 goto nla_put_failure;
10856 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10857 goto nla_put_failure;
10859 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10860 goto nla_put_failure;
10862 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10863 goto nla_put_failure;
10865 nla_nest_end(msg, pinfoattr);
10867 genlmsg_end(msg, hdr);
10869 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10870 NL80211_MCGRP_MLME, gfp);
10874 genlmsg_cancel(msg, hdr);
10877 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
10880 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10881 struct cfg80211_chan_def *chandef,
10882 enum nl80211_radar_event event,
10883 struct net_device *netdev, gfp_t gfp)
10885 struct sk_buff *msg;
10888 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10892 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10898 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10899 goto nla_put_failure;
10901 /* NOP and radar events don't need a netdev parameter */
10903 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10905 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10906 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10907 goto nla_put_failure;
10910 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10911 goto nla_put_failure;
10913 if (nl80211_send_chandef(msg, chandef))
10914 goto nla_put_failure;
10916 genlmsg_end(msg, hdr);
10918 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10919 NL80211_MCGRP_MLME, gfp);
10923 genlmsg_cancel(msg, hdr);
10927 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10928 const u8 *peer, u32 num_packets, gfp_t gfp)
10930 struct wireless_dev *wdev = dev->ieee80211_ptr;
10931 struct wiphy *wiphy = wdev->wiphy;
10932 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10933 struct sk_buff *msg;
10934 struct nlattr *pinfoattr;
10937 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10939 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10943 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10949 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10950 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10951 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10952 goto nla_put_failure;
10954 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10956 goto nla_put_failure;
10958 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10959 goto nla_put_failure;
10961 nla_nest_end(msg, pinfoattr);
10963 genlmsg_end(msg, hdr);
10965 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10966 NL80211_MCGRP_MLME, gfp);
10970 genlmsg_cancel(msg, hdr);
10973 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
10975 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10976 u64 cookie, bool acked, gfp_t gfp)
10978 struct wireless_dev *wdev = dev->ieee80211_ptr;
10979 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10980 struct sk_buff *msg;
10983 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10985 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10990 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10996 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10997 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10998 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10999 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11000 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11001 goto nla_put_failure;
11003 genlmsg_end(msg, hdr);
11005 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11006 NL80211_MCGRP_MLME, gfp);
11010 genlmsg_cancel(msg, hdr);
11013 EXPORT_SYMBOL(cfg80211_probe_status);
11015 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11016 const u8 *frame, size_t len,
11017 int freq, int sig_dbm)
11019 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11020 struct sk_buff *msg;
11022 struct cfg80211_beacon_registration *reg;
11024 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11026 spin_lock_bh(&rdev->beacon_registrations_lock);
11027 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11028 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11030 spin_unlock_bh(&rdev->beacon_registrations_lock);
11034 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11036 goto nla_put_failure;
11038 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11040 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11042 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11043 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11044 goto nla_put_failure;
11046 genlmsg_end(msg, hdr);
11048 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
11050 spin_unlock_bh(&rdev->beacon_registrations_lock);
11054 spin_unlock_bh(&rdev->beacon_registrations_lock);
11056 genlmsg_cancel(msg, hdr);
11059 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11062 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11063 struct cfg80211_wowlan_wakeup *wakeup,
11066 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11067 struct sk_buff *msg;
11071 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11074 size += wakeup->packet_present_len;
11076 msg = nlmsg_new(size, gfp);
11080 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11084 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11085 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11088 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11089 wdev->netdev->ifindex))
11093 struct nlattr *reasons;
11095 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
11097 if (wakeup->disconnect &&
11098 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11100 if (wakeup->magic_pkt &&
11101 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11103 if (wakeup->gtk_rekey_failure &&
11104 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11106 if (wakeup->eap_identity_req &&
11107 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11109 if (wakeup->four_way_handshake &&
11110 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11112 if (wakeup->rfkill_release &&
11113 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11116 if (wakeup->pattern_idx >= 0 &&
11117 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11118 wakeup->pattern_idx))
11121 if (wakeup->tcp_match)
11122 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
11124 if (wakeup->tcp_connlost)
11126 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
11128 if (wakeup->tcp_nomoretokens)
11130 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
11132 if (wakeup->packet) {
11133 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11134 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11136 if (!wakeup->packet_80211) {
11138 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11140 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11143 if (wakeup->packet_len &&
11144 nla_put_u32(msg, len_attr, wakeup->packet_len))
11147 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11152 nla_nest_end(msg, reasons);
11155 genlmsg_end(msg, hdr);
11157 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11158 NL80211_MCGRP_MLME, gfp);
11164 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11167 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11168 enum nl80211_tdls_operation oper,
11169 u16 reason_code, gfp_t gfp)
11171 struct wireless_dev *wdev = dev->ieee80211_ptr;
11172 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11173 struct sk_buff *msg;
11176 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11183 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11189 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11190 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11191 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11192 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11193 (reason_code > 0 &&
11194 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11195 goto nla_put_failure;
11197 genlmsg_end(msg, hdr);
11199 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11200 NL80211_MCGRP_MLME, gfp);
11204 genlmsg_cancel(msg, hdr);
11207 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11209 static int nl80211_netlink_notify(struct notifier_block * nb,
11210 unsigned long state,
11213 struct netlink_notify *notify = _notify;
11214 struct cfg80211_registered_device *rdev;
11215 struct wireless_dev *wdev;
11216 struct cfg80211_beacon_registration *reg, *tmp;
11218 if (state != NETLINK_URELEASE)
11219 return NOTIFY_DONE;
11223 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
11224 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
11225 cfg80211_mlme_unregister_socket(wdev, notify->portid);
11227 spin_lock_bh(&rdev->beacon_registrations_lock);
11228 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11230 if (reg->nlportid == notify->portid) {
11231 list_del(®->list);
11236 spin_unlock_bh(&rdev->beacon_registrations_lock);
11241 return NOTIFY_DONE;
11244 static struct notifier_block nl80211_netlink_notifier = {
11245 .notifier_call = nl80211_netlink_notify,
11248 void cfg80211_ft_event(struct net_device *netdev,
11249 struct cfg80211_ft_event_params *ft_event)
11251 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11252 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11253 struct sk_buff *msg;
11256 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11258 if (!ft_event->target_ap)
11261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11265 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11271 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11272 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11273 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11275 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11276 if (ft_event->ric_ies)
11277 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11278 ft_event->ric_ies);
11280 genlmsg_end(msg, hdr);
11282 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11283 NL80211_MCGRP_MLME, GFP_KERNEL);
11285 EXPORT_SYMBOL(cfg80211_ft_event);
11287 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11289 struct cfg80211_registered_device *rdev;
11290 struct sk_buff *msg;
11294 rdev = wiphy_to_dev(wdev->wiphy);
11295 if (!rdev->crit_proto_nlportid)
11298 nlportid = rdev->crit_proto_nlportid;
11299 rdev->crit_proto_nlportid = 0;
11301 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11305 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11307 goto nla_put_failure;
11309 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11310 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11311 goto nla_put_failure;
11313 genlmsg_end(msg, hdr);
11315 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11320 genlmsg_cancel(msg, hdr);
11324 EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11326 /* initialisation/exit functions */
11328 int nl80211_init(void)
11332 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11337 err = netlink_register_notifier(&nl80211_netlink_notifier);
11343 genl_unregister_family(&nl80211_fam);
11347 void nl80211_exit(void)
11349 netlink_unregister_notifier(&nl80211_netlink_notifier);
11350 genl_unregister_family(&nl80211_fam);