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(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35 static void nl80211_post_doit(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", /* 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 /* returns ERR_PTR values */
51 static struct wireless_dev *
52 __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
54 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
62 assert_cfg80211_lock();
64 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
74 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
77 if (wiphy_net(&rdev->wiphy) != netns)
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
83 mutex_lock(&rdev->devlist_mtx);
84 list_for_each_entry(wdev, &rdev->wdev_list, list) {
85 if (have_ifidx && wdev->netdev &&
86 wdev->netdev->ifindex == ifidx) {
90 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
95 mutex_unlock(&rdev->devlist_mtx);
103 return ERR_PTR(-ENODEV);
106 static struct cfg80211_registered_device *
107 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
109 struct cfg80211_registered_device *rdev = NULL, *tmp;
110 struct net_device *netdev;
112 assert_cfg80211_lock();
114 if (!attrs[NL80211_ATTR_WIPHY] &&
115 !attrs[NL80211_ATTR_IFINDEX] &&
116 !attrs[NL80211_ATTR_WDEV])
117 return ERR_PTR(-EINVAL);
119 if (attrs[NL80211_ATTR_WIPHY])
120 rdev = cfg80211_rdev_by_wiphy_idx(
121 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
123 if (attrs[NL80211_ATTR_WDEV]) {
124 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
125 struct wireless_dev *wdev;
128 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
130 /* make sure wdev exists */
131 mutex_lock(&tmp->devlist_mtx);
132 list_for_each_entry(wdev, &tmp->wdev_list, list) {
133 if (wdev->identifier != (u32)wdev_id)
138 mutex_unlock(&tmp->devlist_mtx);
143 if (rdev && tmp != rdev)
144 return ERR_PTR(-EINVAL);
149 if (attrs[NL80211_ATTR_IFINDEX]) {
150 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
151 netdev = dev_get_by_index(netns, ifindex);
153 if (netdev->ieee80211_ptr)
155 netdev->ieee80211_ptr->wiphy);
161 /* not wireless device -- return error */
163 return ERR_PTR(-EINVAL);
165 /* mismatch -- return error */
166 if (rdev && tmp != rdev)
167 return ERR_PTR(-EINVAL);
174 return ERR_PTR(-ENODEV);
176 if (netns != wiphy_net(&rdev->wiphy))
177 return ERR_PTR(-ENODEV);
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
202 static struct cfg80211_registered_device *
203 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
205 struct cfg80211_registered_device *rdev;
207 mutex_lock(&cfg80211_mutex);
208 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
214 mutex_lock(&rdev->mtx);
216 mutex_unlock(&cfg80211_mutex);
221 /* policy for the attributes */
222 static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
223 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
224 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
226 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
228 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
231 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
232 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
234 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
235 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
240 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
241 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
242 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
244 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
245 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
247 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
248 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
249 .len = WLAN_MAX_KEY_LEN },
250 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
251 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
252 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
253 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
254 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
256 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
257 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
258 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
259 .len = IEEE80211_MAX_DATA_LEN },
260 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
262 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
263 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
264 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
265 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
266 .len = NL80211_MAX_SUPP_RATES },
267 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
268 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
269 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
270 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
271 .len = IEEE80211_MAX_MESH_ID_LEN },
272 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
274 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
275 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
277 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
280 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
281 .len = NL80211_MAX_SUPP_RATES },
282 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
284 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
285 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
287 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
289 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
290 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
291 .len = IEEE80211_MAX_DATA_LEN },
292 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
293 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
295 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
296 .len = IEEE80211_MAX_SSID_LEN },
297 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
298 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
299 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
300 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
301 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
302 [NL80211_ATTR_STA_FLAGS2] = {
303 .len = sizeof(struct nl80211_sta_flag_update),
305 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
308 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
309 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
310 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
311 [NL80211_ATTR_PID] = { .type = NLA_U32 },
312 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
313 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
314 .len = WLAN_PMKID_LEN },
315 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
316 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
317 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
318 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
319 .len = IEEE80211_MAX_DATA_LEN },
320 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
321 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
322 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
323 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
324 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
327 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
328 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
329 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
330 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
331 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
332 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
333 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
334 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
335 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
336 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
337 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
338 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
339 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
340 .len = IEEE80211_MAX_DATA_LEN },
341 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
343 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
344 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
345 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
346 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
348 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
349 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
351 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
352 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
353 .len = IEEE80211_MAX_DATA_LEN },
354 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
355 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
356 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
357 .len = NL80211_HT_CAPABILITY_LEN
359 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
360 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
361 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
362 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
363 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
364 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
365 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
366 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
367 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
368 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
369 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
370 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
371 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
372 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
373 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
374 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
375 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
376 .len = NL80211_VHT_CAPABILITY_LEN,
378 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
379 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
380 .len = IEEE80211_MAX_DATA_LEN },
383 /* policy for the key attributes */
384 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
385 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
386 [NL80211_KEY_IDX] = { .type = NLA_U8 },
387 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
388 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
389 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
390 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
391 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
392 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
395 /* policy for the key default flags */
396 static const struct nla_policy
397 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
398 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
399 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
402 /* policy for WoWLAN attributes */
403 static const struct nla_policy
404 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
405 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
406 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
407 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
409 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
410 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
411 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
413 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
416 static const struct nla_policy
417 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
418 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
419 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
420 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
421 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
422 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
423 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
424 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
425 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
427 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
428 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
430 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
431 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
432 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
435 /* policy for GTK rekey offload attributes */
436 static const struct nla_policy
437 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
438 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
439 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
440 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
443 static const struct nla_policy
444 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
445 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
446 .len = IEEE80211_MAX_SSID_LEN },
447 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
450 /* ifidx get helper */
451 static int nl80211_get_ifidx(struct netlink_callback *cb)
455 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
456 nl80211_fam.attrbuf, nl80211_fam.maxattr,
461 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
464 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
470 static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
471 struct netlink_callback *cb,
472 struct cfg80211_registered_device **rdev,
473 struct net_device **dev)
475 int ifidx = cb->args[0];
479 ifidx = nl80211_get_ifidx(cb);
487 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
493 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
495 err = PTR_ERR(*rdev);
505 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
507 cfg80211_unlock_rdev(rdev);
512 static bool is_valid_ie_attr(const struct nlattr *attr)
520 pos = nla_data(attr);
541 /* message building helper */
542 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
545 /* since there is no private header just add the generic one */
546 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
549 static int nl80211_msg_put_channel(struct sk_buff *msg,
550 struct ieee80211_channel *chan,
553 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
555 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
565 goto nla_put_failure;
566 if (chan->flags & IEEE80211_CHAN_RADAR) {
567 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
568 goto nla_put_failure;
572 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
574 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
576 goto nla_put_failure;
577 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
579 goto nla_put_failure;
584 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
585 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
586 goto nla_put_failure;
587 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
588 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
589 goto nla_put_failure;
590 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
591 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
592 goto nla_put_failure;
593 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
594 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
595 goto nla_put_failure;
598 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
599 DBM_TO_MBM(chan->max_power)))
600 goto nla_put_failure;
608 /* netlink command implementations */
615 bool def_uni, def_multi;
618 static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
620 struct nlattr *tb[NL80211_KEY_MAX + 1];
621 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
626 k->def = !!tb[NL80211_KEY_DEFAULT];
627 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
636 if (tb[NL80211_KEY_IDX])
637 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
639 if (tb[NL80211_KEY_DATA]) {
640 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
641 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
644 if (tb[NL80211_KEY_SEQ]) {
645 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
646 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
649 if (tb[NL80211_KEY_CIPHER])
650 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
652 if (tb[NL80211_KEY_TYPE]) {
653 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
654 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
658 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
659 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
660 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
661 tb[NL80211_KEY_DEFAULT_TYPES],
662 nl80211_key_default_policy);
666 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
667 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
673 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
675 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
676 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
677 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
680 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
681 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
682 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
685 if (info->attrs[NL80211_ATTR_KEY_IDX])
686 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
688 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
689 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
691 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
692 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
701 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
702 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
703 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
707 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
708 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
709 int err = nla_parse_nested(
710 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
711 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
712 nl80211_key_default_policy);
716 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
717 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
723 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
727 memset(k, 0, sizeof(*k));
731 if (info->attrs[NL80211_ATTR_KEY])
732 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
734 err = nl80211_parse_key_old(info, k);
739 if (k->def && k->defmgmt)
743 if (k->def_uni || !k->def_multi)
749 if (k->idx < 4 || k->idx > 5)
752 if (k->idx < 0 || k->idx > 3)
755 if (k->idx < 0 || k->idx > 5)
763 static struct cfg80211_cached_keys *
764 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
765 struct nlattr *keys, bool *no_ht)
767 struct key_parse parse;
769 struct cfg80211_cached_keys *result;
770 int rem, err, def = 0;
772 result = kzalloc(sizeof(*result), GFP_KERNEL);
774 return ERR_PTR(-ENOMEM);
777 result->defmgmt = -1;
779 nla_for_each_nested(key, keys, rem) {
780 memset(&parse, 0, sizeof(parse));
783 err = nl80211_parse_key_new(key, &parse);
789 if (parse.idx < 0 || parse.idx > 4)
795 result->def = parse.idx;
796 if (!parse.def_uni || !parse.def_multi)
798 } else if (parse.defmgmt)
800 err = cfg80211_validate_key_settings(rdev, &parse.p,
801 parse.idx, false, NULL);
804 result->params[parse.idx].cipher = parse.p.cipher;
805 result->params[parse.idx].key_len = parse.p.key_len;
806 result->params[parse.idx].key = result->data[parse.idx];
807 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
809 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
810 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
822 static int nl80211_key_allowed(struct wireless_dev *wdev)
824 ASSERT_WDEV_LOCK(wdev);
826 switch (wdev->iftype) {
827 case NL80211_IFTYPE_AP:
828 case NL80211_IFTYPE_AP_VLAN:
829 case NL80211_IFTYPE_P2P_GO:
830 case NL80211_IFTYPE_MESH_POINT:
832 case NL80211_IFTYPE_ADHOC:
833 if (!wdev->current_bss)
836 case NL80211_IFTYPE_STATION:
837 case NL80211_IFTYPE_P2P_CLIENT:
838 if (wdev->sme_state != CFG80211_SME_CONNECTED)
848 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
850 struct nlattr *nl_modes = nla_nest_start(msg, attr);
854 goto nla_put_failure;
858 if ((ifmodes & 1) && nla_put_flag(msg, i))
859 goto nla_put_failure;
864 nla_nest_end(msg, nl_modes);
871 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
875 struct nlattr *nl_combis;
878 nl_combis = nla_nest_start(msg,
879 NL80211_ATTR_INTERFACE_COMBINATIONS);
881 goto nla_put_failure;
883 for (i = 0; i < wiphy->n_iface_combinations; i++) {
884 const struct ieee80211_iface_combination *c;
885 struct nlattr *nl_combi, *nl_limits;
887 c = &wiphy->iface_combinations[i];
889 nl_combi = nla_nest_start(msg, i + 1);
891 goto nla_put_failure;
893 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
895 goto nla_put_failure;
897 for (j = 0; j < c->n_limits; j++) {
898 struct nlattr *nl_limit;
900 nl_limit = nla_nest_start(msg, j + 1);
902 goto nla_put_failure;
903 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
905 goto nla_put_failure;
906 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
908 goto nla_put_failure;
909 nla_nest_end(msg, nl_limit);
912 nla_nest_end(msg, nl_limits);
914 if (c->beacon_int_infra_match &&
915 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
916 goto nla_put_failure;
917 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
918 c->num_different_channels) ||
919 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
921 goto nla_put_failure;
923 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
924 c->radar_detect_widths))
925 goto nla_put_failure;
927 nla_nest_end(msg, nl_combi);
930 nla_nest_end(msg, nl_combis);
938 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
941 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
942 struct nlattr *nl_tcp;
947 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
951 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
952 tcp->data_payload_max))
955 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
956 tcp->data_payload_max))
959 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
962 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
963 sizeof(*tcp->tok), tcp->tok))
966 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
967 tcp->data_interval_max))
970 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
971 tcp->wake_payload_max))
974 nla_nest_end(msg, nl_tcp);
978 static int nl80211_send_wowlan(struct sk_buff *msg,
979 struct cfg80211_registered_device *dev,
982 struct nlattr *nl_wowlan;
984 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
987 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
991 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
992 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
993 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
994 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
995 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
996 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
997 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
998 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
999 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1001 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1002 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1003 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1005 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1009 if (dev->wiphy.wowlan.n_patterns) {
1010 struct nl80211_wowlan_pattern_support pat = {
1011 .max_patterns = dev->wiphy.wowlan.n_patterns,
1012 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
1013 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
1014 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
1017 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1022 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1025 nla_nest_end(msg, nl_wowlan);
1031 static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1032 struct ieee80211_supported_band *sband)
1034 struct nlattr *nl_rates, *nl_rate;
1035 struct ieee80211_rate *rate;
1039 if (sband->ht_cap.ht_supported &&
1040 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1041 sizeof(sband->ht_cap.mcs),
1042 &sband->ht_cap.mcs) ||
1043 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1044 sband->ht_cap.cap) ||
1045 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1046 sband->ht_cap.ampdu_factor) ||
1047 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1048 sband->ht_cap.ampdu_density)))
1052 if (sband->vht_cap.vht_supported &&
1053 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1054 sizeof(sband->vht_cap.vht_mcs),
1055 &sband->vht_cap.vht_mcs) ||
1056 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1057 sband->vht_cap.cap)))
1061 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1065 for (i = 0; i < sband->n_bitrates; i++) {
1066 nl_rate = nla_nest_start(msg, i);
1070 rate = &sband->bitrates[i];
1071 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1074 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1076 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1079 nla_nest_end(msg, nl_rate);
1082 nla_nest_end(msg, nl_rates);
1088 nl80211_send_mgmt_stypes(struct sk_buff *msg,
1089 const struct ieee80211_txrx_stypes *mgmt_stypes)
1092 struct nlattr *nl_ftypes, *nl_ifs;
1093 enum nl80211_iftype ift;
1099 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1103 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1104 nl_ftypes = nla_nest_start(msg, ift);
1108 stypes = mgmt_stypes[ift].tx;
1111 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1112 (i << 4) | IEEE80211_FTYPE_MGMT))
1117 nla_nest_end(msg, nl_ftypes);
1120 nla_nest_end(msg, nl_ifs);
1122 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1126 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1127 nl_ftypes = nla_nest_start(msg, ift);
1131 stypes = mgmt_stypes[ift].rx;
1134 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1135 (i << 4) | IEEE80211_FTYPE_MGMT))
1140 nla_nest_end(msg, nl_ftypes);
1142 nla_nest_end(msg, nl_ifs);
1147 static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1148 struct sk_buff *msg, u32 portid, u32 seq,
1149 int flags, bool split, long *split_start,
1150 long *band_start, long *chan_start)
1153 struct nlattr *nl_bands, *nl_band;
1154 struct nlattr *nl_freqs, *nl_freq;
1155 struct nlattr *nl_cmds;
1156 enum ieee80211_band band;
1157 struct ieee80211_channel *chan;
1159 const struct ieee80211_txrx_stypes *mgmt_stypes =
1160 dev->wiphy.mgmt_stypes;
1161 long start = 0, start_chan = 0, start_band = 0;
1164 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
1168 /* allow always using the variables */
1170 split_start = &start;
1171 band_start = &start_band;
1172 chan_start = &start_chan;
1175 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
1176 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1177 wiphy_name(&dev->wiphy)) ||
1178 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1179 cfg80211_rdev_list_generation))
1180 goto nla_put_failure;
1182 switch (*split_start) {
1184 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1185 dev->wiphy.retry_short) ||
1186 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1187 dev->wiphy.retry_long) ||
1188 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1189 dev->wiphy.frag_threshold) ||
1190 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1191 dev->wiphy.rts_threshold) ||
1192 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1193 dev->wiphy.coverage_class) ||
1194 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1195 dev->wiphy.max_scan_ssids) ||
1196 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1197 dev->wiphy.max_sched_scan_ssids) ||
1198 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1199 dev->wiphy.max_scan_ie_len) ||
1200 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1201 dev->wiphy.max_sched_scan_ie_len) ||
1202 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1203 dev->wiphy.max_match_sets))
1204 goto nla_put_failure;
1206 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1213 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1216 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1220 goto nla_put_failure;
1221 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1222 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
1223 goto nla_put_failure;
1229 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1230 sizeof(u32) * dev->wiphy.n_cipher_suites,
1231 dev->wiphy.cipher_suites))
1232 goto nla_put_failure;
1234 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1235 dev->wiphy.max_num_pmkids))
1236 goto nla_put_failure;
1238 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1239 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1240 goto nla_put_failure;
1242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1243 dev->wiphy.available_antennas_tx) ||
1244 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1245 dev->wiphy.available_antennas_rx))
1246 goto nla_put_failure;
1248 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1249 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1250 dev->wiphy.probe_resp_offload))
1251 goto nla_put_failure;
1253 if ((dev->wiphy.available_antennas_tx ||
1254 dev->wiphy.available_antennas_rx) &&
1255 dev->ops->get_antenna) {
1256 u32 tx_ant = 0, rx_ant = 0;
1258 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1260 if (nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_TX,
1264 NL80211_ATTR_WIPHY_ANTENNA_RX,
1266 goto nla_put_failure;
1274 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1275 dev->wiphy.interface_modes))
1276 goto nla_put_failure;
1281 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1283 goto nla_put_failure;
1285 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1286 struct ieee80211_supported_band *sband;
1288 sband = dev->wiphy.bands[band];
1293 nl_band = nla_nest_start(msg, band);
1295 goto nla_put_failure;
1297 switch (*chan_start) {
1299 if (nl80211_send_band_rateinfo(msg, sband))
1300 goto nla_put_failure;
1305 /* add frequencies */
1306 nl_freqs = nla_nest_start(
1307 msg, NL80211_BAND_ATTR_FREQS);
1309 goto nla_put_failure;
1311 for (i = *chan_start - 1;
1312 i < sband->n_channels;
1314 nl_freq = nla_nest_start(msg, i);
1316 goto nla_put_failure;
1318 chan = &sband->channels[i];
1320 if (nl80211_msg_put_channel(msg, chan,
1322 goto nla_put_failure;
1324 nla_nest_end(msg, nl_freq);
1328 if (i < sband->n_channels)
1329 *chan_start = i + 2;
1332 nla_nest_end(msg, nl_freqs);
1335 nla_nest_end(msg, nl_band);
1338 /* start again here */
1344 nla_nest_end(msg, nl_bands);
1346 if (band < IEEE80211_NUM_BANDS)
1347 *band_start = band + 1;
1351 /* if bands & channels are done, continue outside */
1352 if (*band_start == 0 && *chan_start == 0)
1357 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1359 goto nla_put_failure;
1362 #define CMD(op, n) \
1364 if (dev->ops->op) { \
1366 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1367 goto nla_put_failure; \
1371 CMD(add_virtual_intf, NEW_INTERFACE);
1372 CMD(change_virtual_intf, SET_INTERFACE);
1373 CMD(add_key, NEW_KEY);
1374 CMD(start_ap, START_AP);
1375 CMD(add_station, NEW_STATION);
1376 CMD(add_mpath, NEW_MPATH);
1377 CMD(update_mesh_config, SET_MESH_CONFIG);
1378 CMD(change_bss, SET_BSS);
1379 CMD(auth, AUTHENTICATE);
1380 CMD(assoc, ASSOCIATE);
1381 CMD(deauth, DEAUTHENTICATE);
1382 CMD(disassoc, DISASSOCIATE);
1383 CMD(join_ibss, JOIN_IBSS);
1384 CMD(join_mesh, JOIN_MESH);
1385 CMD(set_pmksa, SET_PMKSA);
1386 CMD(del_pmksa, DEL_PMKSA);
1387 CMD(flush_pmksa, FLUSH_PMKSA);
1388 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1389 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1390 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1391 CMD(mgmt_tx, FRAME);
1392 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1393 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1395 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1396 goto nla_put_failure;
1398 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1399 dev->ops->join_mesh) {
1401 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1402 goto nla_put_failure;
1404 CMD(set_wds_peer, SET_WDS_PEER);
1405 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1406 CMD(tdls_mgmt, TDLS_MGMT);
1407 CMD(tdls_oper, TDLS_OPER);
1409 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1410 CMD(sched_scan_start, START_SCHED_SCAN);
1411 CMD(probe_client, PROBE_CLIENT);
1412 CMD(set_noack_map, SET_NOACK_MAP);
1413 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1415 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1416 goto nla_put_failure;
1418 CMD(start_p2p_device, START_P2P_DEVICE);
1419 CMD(set_mcast_rate, SET_MCAST_RATE);
1421 #ifdef CONFIG_NL80211_TESTMODE
1422 CMD(testmode_cmd, TESTMODE);
1427 if (dev->ops->connect || dev->ops->auth) {
1429 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1430 goto nla_put_failure;
1433 if (dev->ops->disconnect || dev->ops->deauth) {
1435 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1436 goto nla_put_failure;
1439 nla_nest_end(msg, nl_cmds);
1444 if (dev->ops->remain_on_channel &&
1445 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1447 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1448 dev->wiphy.max_remain_on_channel_duration))
1449 goto nla_put_failure;
1451 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1452 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1453 goto nla_put_failure;
1455 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1456 goto nla_put_failure;
1462 if (nl80211_send_wowlan(msg, dev, split))
1463 goto nla_put_failure;
1471 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1472 dev->wiphy.software_iftypes))
1473 goto nla_put_failure;
1475 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
1476 goto nla_put_failure;
1482 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1483 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1484 dev->wiphy.ap_sme_capa))
1485 goto nla_put_failure;
1487 features = dev->wiphy.features;
1489 * We can only add the per-channel limit information if the
1490 * dump is split, otherwise it makes it too big. Therefore
1491 * only advertise it in that case.
1494 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1495 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
1496 goto nla_put_failure;
1498 if (dev->wiphy.ht_capa_mod_mask &&
1499 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1500 sizeof(*dev->wiphy.ht_capa_mod_mask),
1501 dev->wiphy.ht_capa_mod_mask))
1502 goto nla_put_failure;
1504 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1505 dev->wiphy.max_acl_mac_addrs &&
1506 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1507 dev->wiphy.max_acl_mac_addrs))
1508 goto nla_put_failure;
1511 * Any information below this point is only available to
1512 * applications that can deal with it being split. This
1513 * helps ensure that newly added capabilities don't break
1514 * older tools by overrunning their buffers.
1516 * We still increment split_start so that in the split
1517 * case we'll continue with more data in the next round,
1518 * but break unconditionally so unsplit data stops here.
1523 if (dev->wiphy.extended_capabilities &&
1524 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1525 dev->wiphy.extended_capabilities_len,
1526 dev->wiphy.extended_capabilities) ||
1527 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1528 dev->wiphy.extended_capabilities_len,
1529 dev->wiphy.extended_capabilities_mask)))
1530 goto nla_put_failure;
1532 if (dev->wiphy.vht_capa_mod_mask &&
1533 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1534 sizeof(*dev->wiphy.vht_capa_mod_mask),
1535 dev->wiphy.vht_capa_mod_mask))
1536 goto nla_put_failure;
1542 return genlmsg_end(msg, hdr);
1545 genlmsg_cancel(msg, hdr);
1549 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1552 int start = cb->args[0];
1553 struct cfg80211_registered_device *dev;
1554 s64 filter_wiphy = -1;
1556 struct nlattr **tb = nl80211_fam.attrbuf;
1559 mutex_lock(&cfg80211_mutex);
1560 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1561 tb, nl80211_fam.maxattr, nl80211_policy);
1563 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1564 if (tb[NL80211_ATTR_WIPHY])
1565 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1566 if (tb[NL80211_ATTR_WDEV])
1567 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1568 if (tb[NL80211_ATTR_IFINDEX]) {
1569 struct net_device *netdev;
1570 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1572 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1574 mutex_unlock(&cfg80211_mutex);
1577 if (netdev->ieee80211_ptr) {
1579 netdev->ieee80211_ptr->wiphy);
1580 filter_wiphy = dev->wiphy_idx;
1586 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
1587 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1591 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1593 /* attempt to fit multiple wiphy data chunks into the skb */
1595 ret = nl80211_send_wiphy(dev, skb,
1596 NETLINK_CB(cb->skb).portid,
1599 split, &cb->args[1],
1604 * If sending the wiphy data didn't fit (ENOBUFS
1605 * or EMSGSIZE returned), this SKB is still
1606 * empty (so it's not too big because another
1607 * wiphy dataset is already in the skb) and
1608 * we've not tried to adjust the dump allocation
1609 * yet ... then adjust the alloc size to be
1610 * bigger, and return 1 but with the empty skb.
1611 * This results in an empty message being RX'ed
1612 * in userspace, but that is ignored.
1614 * We can then retry with the larger buffer.
1616 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1618 cb->min_dump_alloc < 4096) {
1619 cb->min_dump_alloc = 4096;
1620 mutex_unlock(&cfg80211_mutex);
1626 } while (cb->args[1] > 0);
1629 mutex_unlock(&cfg80211_mutex);
1636 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1638 struct sk_buff *msg;
1639 struct cfg80211_registered_device *dev = info->user_ptr[0];
1641 msg = nlmsg_new(4096, GFP_KERNEL);
1645 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1646 false, NULL, NULL, NULL) < 0) {
1651 return genlmsg_reply(msg, info);
1654 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1655 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1656 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1657 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1658 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1659 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1662 static int parse_txq_params(struct nlattr *tb[],
1663 struct ieee80211_txq_params *txq_params)
1665 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1666 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1667 !tb[NL80211_TXQ_ATTR_AIFS])
1670 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
1671 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1672 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1673 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1674 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1676 if (txq_params->ac >= NL80211_NUM_ACS)
1682 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1685 * You can only set the channel explicitly for WDS interfaces,
1686 * all others have their channel managed via their respective
1687 * "establish a connection" command (connect, join, ...)
1689 * For AP/GO and mesh mode, the channel can be set with the
1690 * channel userspace API, but is only stored and passed to the
1691 * low-level driver when the AP starts or the mesh is joined.
1692 * This is for backward compatibility, userspace can also give
1693 * the channel in the start-ap or join-mesh commands instead.
1695 * Monitors are special as they are normally slaved to
1696 * whatever else is going on, so they have their own special
1697 * operation to set the monitor channel if possible.
1700 wdev->iftype == NL80211_IFTYPE_AP ||
1701 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
1702 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1703 wdev->iftype == NL80211_IFTYPE_P2P_GO;
1706 static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1707 struct genl_info *info,
1708 struct cfg80211_chan_def *chandef)
1712 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1715 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1717 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
1718 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1719 chandef->center_freq1 = control_freq;
1720 chandef->center_freq2 = 0;
1722 /* Primary channel not allowed */
1723 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1726 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1727 enum nl80211_channel_type chantype;
1729 chantype = nla_get_u32(
1730 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1733 case NL80211_CHAN_NO_HT:
1734 case NL80211_CHAN_HT20:
1735 case NL80211_CHAN_HT40PLUS:
1736 case NL80211_CHAN_HT40MINUS:
1737 cfg80211_chandef_create(chandef, chandef->chan,
1743 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1745 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1746 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1747 chandef->center_freq1 =
1749 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1750 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1751 chandef->center_freq2 =
1753 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1756 if (!cfg80211_chandef_valid(chandef))
1759 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1760 IEEE80211_CHAN_DISABLED))
1766 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1767 struct wireless_dev *wdev,
1768 struct genl_info *info)
1770 struct cfg80211_chan_def chandef;
1772 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1775 iftype = wdev->iftype;
1777 if (!nl80211_can_set_dev_channel(wdev))
1780 result = nl80211_parse_chandef(rdev, info, &chandef);
1784 mutex_lock(&rdev->devlist_mtx);
1786 case NL80211_IFTYPE_AP:
1787 case NL80211_IFTYPE_P2P_GO:
1788 if (wdev->beacon_interval) {
1792 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
1796 wdev->preset_chandef = chandef;
1799 case NL80211_IFTYPE_MESH_POINT:
1800 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
1802 case NL80211_IFTYPE_MONITOR:
1803 result = cfg80211_set_monitor_channel(rdev, &chandef);
1808 mutex_unlock(&rdev->devlist_mtx);
1813 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1816 struct net_device *netdev = info->user_ptr[1];
1818 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
1821 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1824 struct net_device *dev = info->user_ptr[1];
1825 struct wireless_dev *wdev = dev->ieee80211_ptr;
1828 if (!info->attrs[NL80211_ATTR_MAC])
1831 if (netif_running(dev))
1834 if (!rdev->ops->set_wds_peer)
1837 if (wdev->iftype != NL80211_IFTYPE_WDS)
1840 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
1841 return rdev_set_wds_peer(rdev, dev, bssid);
1845 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1847 struct cfg80211_registered_device *rdev;
1848 struct net_device *netdev = NULL;
1849 struct wireless_dev *wdev;
1850 int result = 0, rem_txq_params = 0;
1851 struct nlattr *nl_txq_params;
1853 u8 retry_short = 0, retry_long = 0;
1854 u32 frag_threshold = 0, rts_threshold = 0;
1855 u8 coverage_class = 0;
1858 * Try to find the wiphy and netdev. Normally this
1859 * function shouldn't need the netdev, but this is
1860 * done for backward compatibility -- previously
1861 * setting the channel was done per wiphy, but now
1862 * it is per netdev. Previous userland like hostapd
1863 * also passed a netdev to set_wiphy, so that it is
1864 * possible to let that go to the right netdev!
1866 mutex_lock(&cfg80211_mutex);
1868 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1869 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1871 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1872 if (netdev && netdev->ieee80211_ptr) {
1873 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1874 mutex_lock(&rdev->mtx);
1880 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1883 mutex_unlock(&cfg80211_mutex);
1884 return PTR_ERR(rdev);
1890 mutex_lock(&rdev->mtx);
1892 wdev = netdev->ieee80211_ptr;
1895 * end workaround code, by now the rdev is available
1896 * and locked, and wdev may or may not be NULL.
1899 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
1900 result = cfg80211_dev_rename(
1901 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
1903 mutex_unlock(&cfg80211_mutex);
1908 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1909 struct ieee80211_txq_params txq_params;
1910 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1912 if (!rdev->ops->set_txq_params) {
1913 result = -EOPNOTSUPP;
1922 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1923 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1928 if (!netif_running(netdev)) {
1933 nla_for_each_nested(nl_txq_params,
1934 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1936 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1937 nla_data(nl_txq_params),
1938 nla_len(nl_txq_params),
1940 result = parse_txq_params(tb, &txq_params);
1944 result = rdev_set_txq_params(rdev, netdev,
1951 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
1952 result = __nl80211_set_channel(rdev,
1953 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1959 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1960 struct wireless_dev *txp_wdev = wdev;
1961 enum nl80211_tx_power_setting type;
1964 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1967 if (!rdev->ops->set_tx_power) {
1968 result = -EOPNOTSUPP;
1972 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1973 type = nla_get_u32(info->attrs[idx]);
1975 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1976 (type != NL80211_TX_POWER_AUTOMATIC)) {
1981 if (type != NL80211_TX_POWER_AUTOMATIC) {
1982 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1983 mbm = nla_get_u32(info->attrs[idx]);
1986 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
1991 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1992 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1994 if ((!rdev->wiphy.available_antennas_tx &&
1995 !rdev->wiphy.available_antennas_rx) ||
1996 !rdev->ops->set_antenna) {
1997 result = -EOPNOTSUPP;
2001 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2002 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2004 /* reject antenna configurations which don't match the
2005 * available antenna masks, except for the "all" mask */
2006 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2007 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
2012 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2013 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
2015 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
2022 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2023 retry_short = nla_get_u8(
2024 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2025 if (retry_short == 0) {
2029 changed |= WIPHY_PARAM_RETRY_SHORT;
2032 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2033 retry_long = nla_get_u8(
2034 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2035 if (retry_long == 0) {
2039 changed |= WIPHY_PARAM_RETRY_LONG;
2042 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2043 frag_threshold = nla_get_u32(
2044 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2045 if (frag_threshold < 256) {
2049 if (frag_threshold != (u32) -1) {
2051 * Fragments (apart from the last one) are required to
2052 * have even length. Make the fragmentation code
2053 * simpler by stripping LSB should someone try to use
2054 * odd threshold value.
2056 frag_threshold &= ~0x1;
2058 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2061 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2062 rts_threshold = nla_get_u32(
2063 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2064 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2067 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2068 coverage_class = nla_get_u8(
2069 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2070 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2074 u8 old_retry_short, old_retry_long;
2075 u32 old_frag_threshold, old_rts_threshold;
2076 u8 old_coverage_class;
2078 if (!rdev->ops->set_wiphy_params) {
2079 result = -EOPNOTSUPP;
2083 old_retry_short = rdev->wiphy.retry_short;
2084 old_retry_long = rdev->wiphy.retry_long;
2085 old_frag_threshold = rdev->wiphy.frag_threshold;
2086 old_rts_threshold = rdev->wiphy.rts_threshold;
2087 old_coverage_class = rdev->wiphy.coverage_class;
2089 if (changed & WIPHY_PARAM_RETRY_SHORT)
2090 rdev->wiphy.retry_short = retry_short;
2091 if (changed & WIPHY_PARAM_RETRY_LONG)
2092 rdev->wiphy.retry_long = retry_long;
2093 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2094 rdev->wiphy.frag_threshold = frag_threshold;
2095 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2096 rdev->wiphy.rts_threshold = rts_threshold;
2097 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2098 rdev->wiphy.coverage_class = coverage_class;
2100 result = rdev_set_wiphy_params(rdev, changed);
2102 rdev->wiphy.retry_short = old_retry_short;
2103 rdev->wiphy.retry_long = old_retry_long;
2104 rdev->wiphy.frag_threshold = old_frag_threshold;
2105 rdev->wiphy.rts_threshold = old_rts_threshold;
2106 rdev->wiphy.coverage_class = old_coverage_class;
2111 mutex_unlock(&rdev->mtx);
2117 static inline u64 wdev_id(struct wireless_dev *wdev)
2119 return (u64)wdev->identifier |
2120 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2123 static int nl80211_send_chandef(struct sk_buff *msg,
2124 struct cfg80211_chan_def *chandef)
2126 WARN_ON(!cfg80211_chandef_valid(chandef));
2128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2129 chandef->chan->center_freq))
2131 switch (chandef->width) {
2132 case NL80211_CHAN_WIDTH_20_NOHT:
2133 case NL80211_CHAN_WIDTH_20:
2134 case NL80211_CHAN_WIDTH_40:
2135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2136 cfg80211_get_chandef_type(chandef)))
2142 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2144 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2146 if (chandef->center_freq2 &&
2147 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
2152 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
2153 struct cfg80211_registered_device *rdev,
2154 struct wireless_dev *wdev)
2156 struct net_device *dev = wdev->netdev;
2159 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
2164 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2165 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
2166 goto nla_put_failure;
2168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2169 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
2170 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
2171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
2172 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2173 rdev->devlist_generation ^
2174 (cfg80211_rdev_list_generation << 2)))
2175 goto nla_put_failure;
2177 if (rdev->ops->get_channel) {
2179 struct cfg80211_chan_def chandef;
2181 ret = rdev_get_channel(rdev, wdev, &chandef);
2183 if (nl80211_send_chandef(msg, &chandef))
2184 goto nla_put_failure;
2188 if (wdev->ssid_len) {
2189 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2190 goto nla_put_failure;
2193 return genlmsg_end(msg, hdr);
2196 genlmsg_cancel(msg, hdr);
2200 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2204 int wp_start = cb->args[0];
2205 int if_start = cb->args[1];
2206 struct cfg80211_registered_device *rdev;
2207 struct wireless_dev *wdev;
2209 mutex_lock(&cfg80211_mutex);
2210 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2211 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
2213 if (wp_idx < wp_start) {
2219 mutex_lock(&rdev->devlist_mtx);
2220 list_for_each_entry(wdev, &rdev->wdev_list, list) {
2221 if (if_idx < if_start) {
2225 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
2226 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2228 mutex_unlock(&rdev->devlist_mtx);
2233 mutex_unlock(&rdev->devlist_mtx);
2238 mutex_unlock(&cfg80211_mutex);
2240 cb->args[0] = wp_idx;
2241 cb->args[1] = if_idx;
2246 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2248 struct sk_buff *msg;
2249 struct cfg80211_registered_device *dev = info->user_ptr[0];
2250 struct wireless_dev *wdev = info->user_ptr[1];
2252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2256 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
2262 return genlmsg_reply(msg, info);
2265 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2266 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2267 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2268 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2269 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2270 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2273 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2275 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2283 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2284 nla, mntr_flags_policy))
2287 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2289 *mntrflags |= (1<<flag);
2294 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
2295 struct net_device *netdev, u8 use_4addr,
2296 enum nl80211_iftype iftype)
2299 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
2305 case NL80211_IFTYPE_AP_VLAN:
2306 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2309 case NL80211_IFTYPE_STATION:
2310 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2320 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2323 struct vif_params params;
2325 enum nl80211_iftype otype, ntype;
2326 struct net_device *dev = info->user_ptr[1];
2327 u32 _flags, *flags = NULL;
2328 bool change = false;
2330 memset(¶ms, 0, sizeof(params));
2332 otype = ntype = dev->ieee80211_ptr->iftype;
2334 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2335 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2338 if (ntype > NL80211_IFTYPE_MAX)
2342 if (info->attrs[NL80211_ATTR_MESH_ID]) {
2343 struct wireless_dev *wdev = dev->ieee80211_ptr;
2345 if (ntype != NL80211_IFTYPE_MESH_POINT)
2347 if (netif_running(dev))
2351 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2352 IEEE80211_MAX_MESH_ID_LEN);
2353 wdev->mesh_id_up_len =
2354 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2355 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2356 wdev->mesh_id_up_len);
2360 if (info->attrs[NL80211_ATTR_4ADDR]) {
2361 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2363 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
2367 params.use_4addr = -1;
2370 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2371 if (ntype != NL80211_IFTYPE_MONITOR)
2373 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2383 err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms);
2387 if (!err && params.use_4addr != -1)
2388 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2393 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2396 struct vif_params params;
2397 struct wireless_dev *wdev;
2398 struct sk_buff *msg;
2400 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2403 memset(¶ms, 0, sizeof(params));
2405 if (!info->attrs[NL80211_ATTR_IFNAME])
2408 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2409 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2410 if (type > NL80211_IFTYPE_MAX)
2414 if (!rdev->ops->add_virtual_intf ||
2415 !(rdev->wiphy.interface_modes & (1 << type)))
2418 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2419 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2421 if (!is_valid_ether_addr(params.macaddr))
2422 return -EADDRNOTAVAIL;
2425 if (info->attrs[NL80211_ATTR_4ADDR]) {
2426 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2427 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
2432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2436 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2437 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2439 wdev = rdev_add_virtual_intf(rdev,
2440 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2441 type, err ? NULL : &flags, ¶ms);
2444 return PTR_ERR(wdev);
2448 case NL80211_IFTYPE_MESH_POINT:
2449 if (!info->attrs[NL80211_ATTR_MESH_ID])
2452 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2453 IEEE80211_MAX_MESH_ID_LEN);
2454 wdev->mesh_id_up_len =
2455 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2456 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2457 wdev->mesh_id_up_len);
2460 case NL80211_IFTYPE_P2P_DEVICE:
2462 * P2P Device doesn't have a netdev, so doesn't go
2463 * through the netdev notifier and must be added here
2465 mutex_init(&wdev->mtx);
2466 INIT_LIST_HEAD(&wdev->event_list);
2467 spin_lock_init(&wdev->event_lock);
2468 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2469 spin_lock_init(&wdev->mgmt_registrations_lock);
2471 mutex_lock(&rdev->devlist_mtx);
2472 wdev->identifier = ++rdev->wdev_id;
2473 list_add_rcu(&wdev->list, &rdev->wdev_list);
2474 rdev->devlist_generation++;
2475 mutex_unlock(&rdev->devlist_mtx);
2481 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
2487 return genlmsg_reply(msg, info);
2490 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2493 struct wireless_dev *wdev = info->user_ptr[1];
2495 if (!rdev->ops->del_virtual_intf)
2499 * If we remove a wireless device without a netdev then clear
2500 * user_ptr[1] so that nl80211_post_doit won't dereference it
2501 * to check if it needs to do dev_put(). Otherwise it crashes
2502 * since the wdev has been freed, unlike with a netdev where
2503 * we need the dev_put() for the netdev to really be freed.
2506 info->user_ptr[1] = NULL;
2508 return rdev_del_virtual_intf(rdev, wdev);
2511 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2514 struct net_device *dev = info->user_ptr[1];
2517 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2520 if (!rdev->ops->set_noack_map)
2523 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2525 return rdev_set_noack_map(rdev, dev, noack_map);
2528 struct get_key_cookie {
2529 struct sk_buff *msg;
2534 static void get_key_callback(void *c, struct key_params *params)
2537 struct get_key_cookie *cookie = c;
2540 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2541 params->key_len, params->key)) ||
2543 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2544 params->seq_len, params->seq)) ||
2546 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2548 goto nla_put_failure;
2550 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2552 goto nla_put_failure;
2555 nla_put(cookie->msg, NL80211_KEY_DATA,
2556 params->key_len, params->key)) ||
2558 nla_put(cookie->msg, NL80211_KEY_SEQ,
2559 params->seq_len, params->seq)) ||
2561 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2563 goto nla_put_failure;
2565 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2566 goto nla_put_failure;
2568 nla_nest_end(cookie->msg, key);
2575 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2579 struct net_device *dev = info->user_ptr[1];
2581 const u8 *mac_addr = NULL;
2583 struct get_key_cookie cookie = {
2587 struct sk_buff *msg;
2589 if (info->attrs[NL80211_ATTR_KEY_IDX])
2590 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2595 if (info->attrs[NL80211_ATTR_MAC])
2596 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2598 pairwise = !!mac_addr;
2599 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2600 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2601 if (kt >= NUM_NL80211_KEYTYPES)
2603 if (kt != NL80211_KEYTYPE_GROUP &&
2604 kt != NL80211_KEYTYPE_PAIRWISE)
2606 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2609 if (!rdev->ops->get_key)
2612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2616 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
2617 NL80211_CMD_NEW_KEY);
2619 return PTR_ERR(hdr);
2622 cookie.idx = key_idx;
2624 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2625 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2626 goto nla_put_failure;
2628 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2629 goto nla_put_failure;
2631 if (pairwise && mac_addr &&
2632 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2635 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2642 goto nla_put_failure;
2644 genlmsg_end(msg, hdr);
2645 return genlmsg_reply(msg, info);
2654 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2657 struct key_parse key;
2659 struct net_device *dev = info->user_ptr[1];
2661 err = nl80211_parse_key(info, &key);
2668 /* only support setting default key */
2669 if (!key.def && !key.defmgmt)
2672 wdev_lock(dev->ieee80211_ptr);
2675 if (!rdev->ops->set_default_key) {
2680 err = nl80211_key_allowed(dev->ieee80211_ptr);
2684 err = rdev_set_default_key(rdev, dev, key.idx,
2685 key.def_uni, key.def_multi);
2690 #ifdef CONFIG_CFG80211_WEXT
2691 dev->ieee80211_ptr->wext.default_key = key.idx;
2694 if (key.def_uni || !key.def_multi) {
2699 if (!rdev->ops->set_default_mgmt_key) {
2704 err = nl80211_key_allowed(dev->ieee80211_ptr);
2708 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
2712 #ifdef CONFIG_CFG80211_WEXT
2713 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2718 wdev_unlock(dev->ieee80211_ptr);
2723 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2727 struct net_device *dev = info->user_ptr[1];
2728 struct key_parse key;
2729 const u8 *mac_addr = NULL;
2731 err = nl80211_parse_key(info, &key);
2738 if (info->attrs[NL80211_ATTR_MAC])
2739 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2741 if (key.type == -1) {
2743 key.type = NL80211_KEYTYPE_PAIRWISE;
2745 key.type = NL80211_KEYTYPE_GROUP;
2749 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2750 key.type != NL80211_KEYTYPE_GROUP)
2753 if (!rdev->ops->add_key)
2756 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2757 key.type == NL80211_KEYTYPE_PAIRWISE,
2761 wdev_lock(dev->ieee80211_ptr);
2762 err = nl80211_key_allowed(dev->ieee80211_ptr);
2764 err = rdev_add_key(rdev, dev, key.idx,
2765 key.type == NL80211_KEYTYPE_PAIRWISE,
2767 wdev_unlock(dev->ieee80211_ptr);
2772 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2776 struct net_device *dev = info->user_ptr[1];
2777 u8 *mac_addr = NULL;
2778 struct key_parse key;
2780 err = nl80211_parse_key(info, &key);
2784 if (info->attrs[NL80211_ATTR_MAC])
2785 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2787 if (key.type == -1) {
2789 key.type = NL80211_KEYTYPE_PAIRWISE;
2791 key.type = NL80211_KEYTYPE_GROUP;
2795 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2796 key.type != NL80211_KEYTYPE_GROUP)
2799 if (!rdev->ops->del_key)
2802 wdev_lock(dev->ieee80211_ptr);
2803 err = nl80211_key_allowed(dev->ieee80211_ptr);
2805 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2806 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2810 err = rdev_del_key(rdev, dev, key.idx,
2811 key.type == NL80211_KEYTYPE_PAIRWISE,
2814 #ifdef CONFIG_CFG80211_WEXT
2816 if (key.idx == dev->ieee80211_ptr->wext.default_key)
2817 dev->ieee80211_ptr->wext.default_key = -1;
2818 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
2819 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2822 wdev_unlock(dev->ieee80211_ptr);
2827 /* This function returns an error or the number of nested attributes */
2828 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2830 struct nlattr *attr;
2831 int n_entries = 0, tmp;
2833 nla_for_each_nested(attr, nl_attr, tmp) {
2834 if (nla_len(attr) != ETH_ALEN)
2844 * This function parses ACL information and allocates memory for ACL data.
2845 * On successful return, the calling function is responsible to free the
2846 * ACL buffer returned by this function.
2848 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2849 struct genl_info *info)
2851 enum nl80211_acl_policy acl_policy;
2852 struct nlattr *attr;
2853 struct cfg80211_acl_data *acl;
2854 int i = 0, n_entries, tmp;
2856 if (!wiphy->max_acl_mac_addrs)
2857 return ERR_PTR(-EOPNOTSUPP);
2859 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2860 return ERR_PTR(-EINVAL);
2862 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2863 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2864 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2865 return ERR_PTR(-EINVAL);
2867 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2868 return ERR_PTR(-EINVAL);
2870 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2872 return ERR_PTR(n_entries);
2874 if (n_entries > wiphy->max_acl_mac_addrs)
2875 return ERR_PTR(-ENOTSUPP);
2877 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2880 return ERR_PTR(-ENOMEM);
2882 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2883 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2887 acl->n_acl_entries = n_entries;
2888 acl->acl_policy = acl_policy;
2893 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2896 struct net_device *dev = info->user_ptr[1];
2897 struct cfg80211_acl_data *acl;
2900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2901 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2904 if (!dev->ieee80211_ptr->beacon_interval)
2907 acl = parse_acl_data(&rdev->wiphy, info);
2909 return PTR_ERR(acl);
2911 err = rdev_set_mac_acl(rdev, dev, acl);
2918 static int nl80211_parse_beacon(struct genl_info *info,
2919 struct cfg80211_beacon_data *bcn)
2921 bool haveinfo = false;
2923 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2924 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2925 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2926 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
2929 memset(bcn, 0, sizeof(*bcn));
2931 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2932 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2933 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2939 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2940 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2942 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2949 if (info->attrs[NL80211_ATTR_IE]) {
2950 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2951 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2954 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
2955 bcn->proberesp_ies =
2956 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2957 bcn->proberesp_ies_len =
2958 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2961 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
2962 bcn->assocresp_ies =
2963 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2964 bcn->assocresp_ies_len =
2965 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2968 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
2970 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
2971 bcn->probe_resp_len =
2972 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2978 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2979 struct cfg80211_ap_settings *params)
2981 struct wireless_dev *wdev;
2984 mutex_lock(&rdev->devlist_mtx);
2986 list_for_each_entry(wdev, &rdev->wdev_list, list) {
2987 if (wdev->iftype != NL80211_IFTYPE_AP &&
2988 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2991 if (!wdev->preset_chandef.chan)
2994 params->chandef = wdev->preset_chandef;
2999 mutex_unlock(&rdev->devlist_mtx);
3004 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3005 enum nl80211_auth_type auth_type,
3006 enum nl80211_commands cmd)
3008 if (auth_type > NL80211_AUTHTYPE_MAX)
3012 case NL80211_CMD_AUTHENTICATE:
3013 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3014 auth_type == NL80211_AUTHTYPE_SAE)
3017 case NL80211_CMD_CONNECT:
3018 case NL80211_CMD_START_AP:
3019 /* SAE not supported yet */
3020 if (auth_type == NL80211_AUTHTYPE_SAE)
3028 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3031 struct net_device *dev = info->user_ptr[1];
3032 struct wireless_dev *wdev = dev->ieee80211_ptr;
3033 struct cfg80211_ap_settings params;
3035 u8 radar_detect_width = 0;
3037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3038 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3041 if (!rdev->ops->start_ap)
3044 if (wdev->beacon_interval)
3047 memset(¶ms, 0, sizeof(params));
3049 /* these are required for START_AP */
3050 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3051 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3052 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3055 err = nl80211_parse_beacon(info, ¶ms.beacon);
3059 params.beacon_interval =
3060 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3061 params.dtim_period =
3062 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3064 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3069 * In theory, some of these attributes should be required here
3070 * but since they were not used when the command was originally
3071 * added, keep them optional for old user space programs to let
3072 * them continue to work with drivers that do not need the
3073 * additional information -- drivers must check!
3075 if (info->attrs[NL80211_ATTR_SSID]) {
3076 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3078 nla_len(info->attrs[NL80211_ATTR_SSID]);
3079 if (params.ssid_len == 0 ||
3080 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3084 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3085 params.hidden_ssid = nla_get_u32(
3086 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3087 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3088 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3089 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3093 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3095 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3096 params.auth_type = nla_get_u32(
3097 info->attrs[NL80211_ATTR_AUTH_TYPE]);
3098 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3099 NL80211_CMD_START_AP))
3102 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3104 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
3105 NL80211_MAX_NR_CIPHER_SUITES);
3109 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3110 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3112 params.inactivity_timeout = nla_get_u16(
3113 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3116 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3119 params.p2p_ctwindow =
3120 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3121 if (params.p2p_ctwindow > 127)
3123 if (params.p2p_ctwindow != 0 &&
3124 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3128 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3131 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3133 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3136 params.p2p_opp_ps = tmp;
3137 if (params.p2p_opp_ps != 0 &&
3138 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3142 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3143 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
3146 } else if (wdev->preset_chandef.chan) {
3147 params.chandef = wdev->preset_chandef;
3148 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
3151 if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef))
3154 err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef);
3158 radar_detect_width = BIT(params.chandef.width);
3159 params.radar_required = true;
3162 mutex_lock(&rdev->devlist_mtx);
3163 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3164 params.chandef.chan,
3166 radar_detect_width);
3167 mutex_unlock(&rdev->devlist_mtx);
3172 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3173 params.acl = parse_acl_data(&rdev->wiphy, info);
3174 if (IS_ERR(params.acl))
3175 return PTR_ERR(params.acl);
3178 err = rdev_start_ap(rdev, dev, ¶ms);
3180 wdev->preset_chandef = params.chandef;
3181 wdev->beacon_interval = params.beacon_interval;
3182 wdev->channel = params.chandef.chan;
3183 wdev->ssid_len = params.ssid_len;
3184 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
3192 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3195 struct net_device *dev = info->user_ptr[1];
3196 struct wireless_dev *wdev = dev->ieee80211_ptr;
3197 struct cfg80211_beacon_data params;
3200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3204 if (!rdev->ops->change_beacon)
3207 if (!wdev->beacon_interval)
3210 err = nl80211_parse_beacon(info, ¶ms);
3214 return rdev_change_beacon(rdev, dev, ¶ms);
3217 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
3219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3220 struct net_device *dev = info->user_ptr[1];
3222 return cfg80211_stop_ap(rdev, dev);
3225 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3226 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3227 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3228 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
3229 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
3230 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
3231 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
3234 static int parse_station_flags(struct genl_info *info,
3235 enum nl80211_iftype iftype,
3236 struct station_parameters *params)
3238 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
3243 * Try parsing the new attribute first so userspace
3244 * can specify both for older kernels.
3246 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3248 struct nl80211_sta_flag_update *sta_flags;
3250 sta_flags = nla_data(nla);
3251 params->sta_flags_mask = sta_flags->mask;
3252 params->sta_flags_set = sta_flags->set;
3253 params->sta_flags_set &= params->sta_flags_mask;
3254 if ((params->sta_flags_mask |
3255 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3260 /* if present, parse the old attribute */
3262 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
3266 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3267 nla, sta_flags_policy))
3271 * Only allow certain flags for interface types so that
3272 * other attributes are silently ignored. Remember that
3273 * this is backward compatibility code with old userspace
3274 * and shouldn't be hit in other cases anyway.
3277 case NL80211_IFTYPE_AP:
3278 case NL80211_IFTYPE_AP_VLAN:
3279 case NL80211_IFTYPE_P2P_GO:
3280 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3281 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3282 BIT(NL80211_STA_FLAG_WME) |
3283 BIT(NL80211_STA_FLAG_MFP);
3285 case NL80211_IFTYPE_P2P_CLIENT:
3286 case NL80211_IFTYPE_STATION:
3287 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3288 BIT(NL80211_STA_FLAG_TDLS_PEER);
3290 case NL80211_IFTYPE_MESH_POINT:
3291 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3292 BIT(NL80211_STA_FLAG_MFP) |
3293 BIT(NL80211_STA_FLAG_AUTHORIZED);
3298 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3300 params->sta_flags_set |= (1<<flag);
3302 /* no longer support new API additions in old API */
3303 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3311 static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3314 struct nlattr *rate;
3318 rate = nla_nest_start(msg, attr);
3322 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3323 bitrate = cfg80211_calculate_bitrate(info);
3324 /* report 16-bit bitrate only if we can */
3325 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
3327 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3329 if (bitrate_compat > 0 &&
3330 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3333 if (info->flags & RATE_INFO_FLAGS_MCS) {
3334 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3336 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3337 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3339 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3340 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3342 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3343 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3345 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3347 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3348 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3350 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3351 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3353 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3354 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3356 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3357 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3359 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3360 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3364 nla_nest_end(msg, rate);
3368 static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
3370 struct cfg80211_registered_device *rdev,
3371 struct net_device *dev,
3372 const u8 *mac_addr, struct station_info *sinfo)
3375 struct nlattr *sinfoattr, *bss_param;
3377 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
3381 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3382 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3383 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3384 goto nla_put_failure;
3386 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3388 goto nla_put_failure;
3389 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3390 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3391 sinfo->connected_time))
3392 goto nla_put_failure;
3393 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3394 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3395 sinfo->inactive_time))
3396 goto nla_put_failure;
3397 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3398 STATION_INFO_RX_BYTES64)) &&
3399 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
3400 (u32)sinfo->rx_bytes))
3401 goto nla_put_failure;
3402 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3403 NL80211_STA_INFO_TX_BYTES64)) &&
3404 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3405 (u32)sinfo->tx_bytes))
3406 goto nla_put_failure;
3407 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3408 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
3410 goto nla_put_failure;
3411 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3412 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
3414 goto nla_put_failure;
3415 if ((sinfo->filled & STATION_INFO_LLID) &&
3416 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_PLID) &&
3419 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3420 goto nla_put_failure;
3421 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3422 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3423 sinfo->plink_state))
3424 goto nla_put_failure;
3425 switch (rdev->wiphy.signal_type) {
3426 case CFG80211_SIGNAL_TYPE_MBM:
3427 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3428 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3430 goto nla_put_failure;
3431 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3432 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3434 goto nla_put_failure;
3439 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
3440 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3441 NL80211_STA_INFO_TX_BITRATE))
3442 goto nla_put_failure;
3444 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3445 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3446 NL80211_STA_INFO_RX_BITRATE))
3447 goto nla_put_failure;
3449 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3452 goto nla_put_failure;
3453 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3454 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3456 goto nla_put_failure;
3457 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3458 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3460 goto nla_put_failure;
3461 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3462 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3464 goto nla_put_failure;
3465 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3466 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3467 sinfo->beacon_loss_count))
3468 goto nla_put_failure;
3469 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3470 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3472 goto nla_put_failure;
3473 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3474 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3476 goto nla_put_failure;
3477 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3478 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3480 goto nla_put_failure;
3481 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3482 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3484 goto nla_put_failure;
3486 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3487 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3488 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3489 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3490 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3491 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3492 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3493 sinfo->bss_param.dtim_period) ||
3494 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3495 sinfo->bss_param.beacon_interval))
3496 goto nla_put_failure;
3498 nla_nest_end(msg, bss_param);
3500 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3501 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3502 sizeof(struct nl80211_sta_flag_update),
3504 goto nla_put_failure;
3505 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3506 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3508 goto nla_put_failure;
3509 nla_nest_end(msg, sinfoattr);
3511 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3512 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3513 sinfo->assoc_req_ies))
3514 goto nla_put_failure;
3516 return genlmsg_end(msg, hdr);
3519 genlmsg_cancel(msg, hdr);
3523 static int nl80211_dump_station(struct sk_buff *skb,
3524 struct netlink_callback *cb)
3526 struct station_info sinfo;
3527 struct cfg80211_registered_device *dev;
3528 struct net_device *netdev;
3529 u8 mac_addr[ETH_ALEN];
3530 int sta_idx = cb->args[1];
3533 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3537 if (!dev->ops->dump_station) {
3543 memset(&sinfo, 0, sizeof(sinfo));
3544 err = rdev_dump_station(dev, netdev, sta_idx,
3551 if (nl80211_send_station(skb,
3552 NETLINK_CB(cb->skb).portid,
3553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3554 dev, netdev, mac_addr,
3563 cb->args[1] = sta_idx;
3566 nl80211_finish_netdev_dump(dev);
3571 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3574 struct net_device *dev = info->user_ptr[1];
3575 struct station_info sinfo;
3576 struct sk_buff *msg;
3577 u8 *mac_addr = NULL;
3580 memset(&sinfo, 0, sizeof(sinfo));
3582 if (!info->attrs[NL80211_ATTR_MAC])
3585 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3587 if (!rdev->ops->get_station)
3590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
3594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3598 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
3599 rdev, dev, mac_addr, &sinfo) < 0) {
3604 return genlmsg_reply(msg, info);
3607 int cfg80211_check_station_change(struct wiphy *wiphy,
3608 struct station_parameters *params,
3609 enum cfg80211_station_type statype)
3611 if (params->listen_interval != -1)
3616 /* When you run into this, adjust the code below for the new flag */
3617 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3620 case CFG80211_STA_MESH_PEER_NONSEC:
3621 case CFG80211_STA_MESH_PEER_SECURE:
3623 * No ignoring the TDLS flag here -- the userspace mesh
3624 * code doesn't have the bug of including TDLS in the
3627 if (params->sta_flags_mask &
3628 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3629 BIT(NL80211_STA_FLAG_MFP) |
3630 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3633 case CFG80211_STA_TDLS_PEER_SETUP:
3634 case CFG80211_STA_TDLS_PEER_ACTIVE:
3635 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3637 /* ignore since it can't change */
3638 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3641 /* disallow mesh-specific things */
3642 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3644 if (params->local_pm)
3646 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3650 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3651 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3652 /* TDLS can't be set, ... */
3653 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3656 * ... but don't bother the driver with it. This works around
3657 * a hostapd/wpa_supplicant issue -- it always includes the
3658 * TLDS_PEER flag in the mask even for AP mode.
3660 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3663 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3664 /* reject other things that can't change */
3665 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3667 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3669 if (params->supported_rates)
3671 if (params->ext_capab || params->ht_capa || params->vht_capa)
3675 if (statype != CFG80211_STA_AP_CLIENT) {
3681 case CFG80211_STA_AP_MLME_CLIENT:
3682 /* Use this only for authorizing/unauthorizing a station */
3683 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3686 case CFG80211_STA_AP_CLIENT:
3687 /* accept only the listed bits */
3688 if (params->sta_flags_mask &
3689 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3691 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3692 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3693 BIT(NL80211_STA_FLAG_WME) |
3694 BIT(NL80211_STA_FLAG_MFP)))
3697 /* but authenticated/associated only if driver handles it */
3698 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3699 params->sta_flags_mask &
3700 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3704 case CFG80211_STA_IBSS:
3705 case CFG80211_STA_AP_STA:
3706 /* reject any changes other than AUTHORIZED */
3707 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3710 case CFG80211_STA_TDLS_PEER_SETUP:
3711 /* reject any changes other than AUTHORIZED or WME */
3712 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3713 BIT(NL80211_STA_FLAG_WME)))
3715 /* force (at least) rates when authorizing */
3716 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3717 !params->supported_rates)
3720 case CFG80211_STA_TDLS_PEER_ACTIVE:
3721 /* reject any changes */
3723 case CFG80211_STA_MESH_PEER_NONSEC:
3724 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3727 case CFG80211_STA_MESH_PEER_SECURE:
3728 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3735 EXPORT_SYMBOL(cfg80211_check_station_change);
3738 * Get vlan interface making sure it is running and on the right wiphy.
3740 static struct net_device *get_vlan(struct genl_info *info,
3741 struct cfg80211_registered_device *rdev)
3743 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
3744 struct net_device *v;
3750 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3752 return ERR_PTR(-ENODEV);
3754 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3759 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3761 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3766 if (!netif_running(v)) {
3774 return ERR_PTR(ret);
3777 static struct nla_policy
3778 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3779 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3780 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3783 static int nl80211_parse_sta_wme(struct genl_info *info,
3784 struct station_parameters *params)
3786 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3790 /* parse WME attributes if present */
3791 if (!info->attrs[NL80211_ATTR_STA_WME])
3794 nla = info->attrs[NL80211_ATTR_STA_WME];
3795 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3796 nl80211_sta_wme_policy);
3800 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3801 params->uapsd_queues = nla_get_u8(
3802 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3803 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3806 if (tb[NL80211_STA_WME_MAX_SP])
3807 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3809 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3812 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3817 static int nl80211_set_station_tdls(struct genl_info *info,
3818 struct station_parameters *params)
3820 /* Dummy STA entry gets updated once the peer capabilities are known */
3821 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3823 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3824 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3826 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3828 return nl80211_parse_sta_wme(info, params);
3831 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3834 struct net_device *dev = info->user_ptr[1];
3835 struct station_parameters params;
3839 memset(¶ms, 0, sizeof(params));
3841 params.listen_interval = -1;
3843 if (!rdev->ops->change_station)
3846 if (info->attrs[NL80211_ATTR_STA_AID])
3849 if (!info->attrs[NL80211_ATTR_MAC])
3852 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3854 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3855 params.supported_rates =
3856 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3857 params.supported_rates_len =
3858 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3861 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3863 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3864 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3867 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3869 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3870 params.ext_capab_len =
3871 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3874 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3877 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3880 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3881 params.plink_action =
3882 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3883 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3887 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
3888 params.plink_state =
3889 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3890 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3892 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3895 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3896 enum nl80211_mesh_power_mode pm = nla_get_u32(
3897 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3899 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3900 pm > NL80211_MESH_POWER_MAX)
3903 params.local_pm = pm;
3906 /* Include parameters for TDLS peer (will check later) */
3907 err = nl80211_set_station_tdls(info, ¶ms);
3911 params.vlan = get_vlan(info, rdev);
3912 if (IS_ERR(params.vlan))
3913 return PTR_ERR(params.vlan);
3915 switch (dev->ieee80211_ptr->iftype) {
3916 case NL80211_IFTYPE_AP:
3917 case NL80211_IFTYPE_AP_VLAN:
3918 case NL80211_IFTYPE_P2P_GO:
3919 case NL80211_IFTYPE_P2P_CLIENT:
3920 case NL80211_IFTYPE_STATION:
3921 case NL80211_IFTYPE_ADHOC:
3922 case NL80211_IFTYPE_MESH_POINT:
3929 /* driver will call cfg80211_check_station_change() */
3930 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
3934 dev_put(params.vlan);
3939 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3943 struct net_device *dev = info->user_ptr[1];
3944 struct station_parameters params;
3945 u8 *mac_addr = NULL;
3947 memset(¶ms, 0, sizeof(params));
3949 if (!rdev->ops->add_station)
3952 if (!info->attrs[NL80211_ATTR_MAC])
3955 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3958 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3961 if (!info->attrs[NL80211_ATTR_STA_AID])
3964 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3965 params.supported_rates =
3966 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3967 params.supported_rates_len =
3968 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3969 params.listen_interval =
3970 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3972 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3973 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3976 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3978 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3979 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3982 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3984 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3985 params.ext_capab_len =
3986 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3989 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3991 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3993 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3995 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3997 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3998 params.plink_action =
3999 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4000 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4004 err = nl80211_parse_sta_wme(info, ¶ms);
4008 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
4011 /* When you run into this, adjust the code below for the new flag */
4012 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4014 switch (dev->ieee80211_ptr->iftype) {
4015 case NL80211_IFTYPE_AP:
4016 case NL80211_IFTYPE_AP_VLAN:
4017 case NL80211_IFTYPE_P2P_GO:
4018 /* ignore WME attributes if iface/sta is not capable */
4019 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4020 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4021 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4023 /* TDLS peers cannot be added */
4024 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4026 /* but don't bother the driver with it */
4027 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4029 /* allow authenticated/associated only if driver handles it */
4030 if (!(rdev->wiphy.features &
4031 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4032 params.sta_flags_mask &
4033 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4034 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4037 /* must be last in here for error handling */
4038 params.vlan = get_vlan(info, rdev);
4039 if (IS_ERR(params.vlan))
4040 return PTR_ERR(params.vlan);
4042 case NL80211_IFTYPE_MESH_POINT:
4043 /* ignore uAPSD data */
4044 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4046 /* associated is disallowed */
4047 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4049 /* TDLS peers cannot be added */
4050 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4053 case NL80211_IFTYPE_STATION:
4054 /* ignore uAPSD data */
4055 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4057 /* these are disallowed */
4058 if (params.sta_flags_mask &
4059 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4060 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
4062 /* Only TDLS peers can be added */
4063 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4065 /* Can only add if TDLS ... */
4066 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4068 /* ... with external setup is supported */
4069 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4072 * Older wpa_supplicant versions always mark the TDLS peer
4073 * as authorized, but it shouldn't yet be.
4075 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
4081 /* be aware of params.vlan when changing code here */
4083 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
4086 dev_put(params.vlan);
4090 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4093 struct net_device *dev = info->user_ptr[1];
4094 u8 *mac_addr = NULL;
4096 if (info->attrs[NL80211_ATTR_MAC])
4097 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4099 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4100 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4101 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
4102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4105 if (!rdev->ops->del_station)
4108 return rdev_del_station(rdev, dev, mac_addr);
4111 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
4112 int flags, struct net_device *dev,
4113 u8 *dst, u8 *next_hop,
4114 struct mpath_info *pinfo)
4117 struct nlattr *pinfoattr;
4119 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
4123 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4124 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4125 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4126 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4127 goto nla_put_failure;
4129 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4131 goto nla_put_failure;
4132 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4133 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4135 goto nla_put_failure;
4136 if (((pinfo->filled & MPATH_INFO_SN) &&
4137 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4138 ((pinfo->filled & MPATH_INFO_METRIC) &&
4139 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4141 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4142 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4144 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4145 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4147 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4148 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4149 pinfo->discovery_timeout)) ||
4150 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4151 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4152 pinfo->discovery_retries)))
4153 goto nla_put_failure;
4155 nla_nest_end(msg, pinfoattr);
4157 return genlmsg_end(msg, hdr);
4160 genlmsg_cancel(msg, hdr);
4164 static int nl80211_dump_mpath(struct sk_buff *skb,
4165 struct netlink_callback *cb)
4167 struct mpath_info pinfo;
4168 struct cfg80211_registered_device *dev;
4169 struct net_device *netdev;
4171 u8 next_hop[ETH_ALEN];
4172 int path_idx = cb->args[1];
4175 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4179 if (!dev->ops->dump_mpath) {
4184 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
4190 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
4197 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4198 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4199 netdev, dst, next_hop,
4208 cb->args[1] = path_idx;
4211 nl80211_finish_netdev_dump(dev);
4215 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4219 struct net_device *dev = info->user_ptr[1];
4220 struct mpath_info pinfo;
4221 struct sk_buff *msg;
4223 u8 next_hop[ETH_ALEN];
4225 memset(&pinfo, 0, sizeof(pinfo));
4227 if (!info->attrs[NL80211_ATTR_MAC])
4230 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4232 if (!rdev->ops->get_mpath)
4235 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4238 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
4242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4246 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4247 dev, dst, next_hop, &pinfo) < 0) {
4252 return genlmsg_reply(msg, info);
4255 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4258 struct net_device *dev = info->user_ptr[1];
4260 u8 *next_hop = NULL;
4262 if (!info->attrs[NL80211_ATTR_MAC])
4265 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4268 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4269 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4271 if (!rdev->ops->change_mpath)
4274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4277 return rdev_change_mpath(rdev, dev, dst, next_hop);
4280 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4283 struct net_device *dev = info->user_ptr[1];
4285 u8 *next_hop = NULL;
4287 if (!info->attrs[NL80211_ATTR_MAC])
4290 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4293 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4294 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4296 if (!rdev->ops->add_mpath)
4299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4302 return rdev_add_mpath(rdev, dev, dst, next_hop);
4305 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4308 struct net_device *dev = info->user_ptr[1];
4311 if (info->attrs[NL80211_ATTR_MAC])
4312 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4314 if (!rdev->ops->del_mpath)
4317 return rdev_del_mpath(rdev, dev, dst);
4320 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4323 struct net_device *dev = info->user_ptr[1];
4324 struct bss_parameters params;
4326 memset(¶ms, 0, sizeof(params));
4327 /* default to not changing parameters */
4328 params.use_cts_prot = -1;
4329 params.use_short_preamble = -1;
4330 params.use_short_slot_time = -1;
4331 params.ap_isolate = -1;
4332 params.ht_opmode = -1;
4333 params.p2p_ctwindow = -1;
4334 params.p2p_opp_ps = -1;
4336 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4337 params.use_cts_prot =
4338 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4339 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4340 params.use_short_preamble =
4341 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4342 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4343 params.use_short_slot_time =
4344 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
4345 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4346 params.basic_rates =
4347 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4348 params.basic_rates_len =
4349 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4351 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4352 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
4353 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4355 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
4357 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4358 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4360 params.p2p_ctwindow =
4361 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4362 if (params.p2p_ctwindow < 0)
4364 if (params.p2p_ctwindow != 0 &&
4365 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4369 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4372 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4374 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4377 params.p2p_opp_ps = tmp;
4378 if (params.p2p_opp_ps &&
4379 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4383 if (!rdev->ops->change_bss)
4386 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4387 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4390 return rdev_change_bss(rdev, dev, ¶ms);
4393 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
4394 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4395 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4396 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4397 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4398 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4399 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4402 static int parse_reg_rule(struct nlattr *tb[],
4403 struct ieee80211_reg_rule *reg_rule)
4405 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
4406 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
4408 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4410 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4412 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4414 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4416 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4419 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4421 freq_range->start_freq_khz =
4422 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4423 freq_range->end_freq_khz =
4424 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4425 freq_range->max_bandwidth_khz =
4426 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4428 power_rule->max_eirp =
4429 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4431 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4432 power_rule->max_antenna_gain =
4433 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4438 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4442 enum nl80211_user_reg_hint_type user_reg_hint_type;
4445 * You should only get this when cfg80211 hasn't yet initialized
4446 * completely when built-in to the kernel right between the time
4447 * window between nl80211_init() and regulatory_init(), if that is
4450 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
4451 return -EINPROGRESS;
4453 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4456 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4458 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4459 user_reg_hint_type =
4460 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4462 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4464 switch (user_reg_hint_type) {
4465 case NL80211_USER_REG_HINT_USER:
4466 case NL80211_USER_REG_HINT_CELL_BASE:
4472 r = regulatory_hint_user(data, user_reg_hint_type);
4477 static int nl80211_get_mesh_config(struct sk_buff *skb,
4478 struct genl_info *info)
4480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4481 struct net_device *dev = info->user_ptr[1];
4482 struct wireless_dev *wdev = dev->ieee80211_ptr;
4483 struct mesh_config cur_params;
4486 struct nlattr *pinfoattr;
4487 struct sk_buff *msg;
4489 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4492 if (!rdev->ops->get_mesh_config)
4496 /* If not connected, get default parameters */
4497 if (!wdev->mesh_id_len)
4498 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4500 err = rdev_get_mesh_config(rdev, dev, &cur_params);
4506 /* Draw up a netlink message to send back */
4507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4510 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4511 NL80211_CMD_GET_MESH_CONFIG);
4514 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
4516 goto nla_put_failure;
4517 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4518 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4519 cur_params.dot11MeshRetryTimeout) ||
4520 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4521 cur_params.dot11MeshConfirmTimeout) ||
4522 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4523 cur_params.dot11MeshHoldingTimeout) ||
4524 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4525 cur_params.dot11MeshMaxPeerLinks) ||
4526 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4527 cur_params.dot11MeshMaxRetries) ||
4528 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4529 cur_params.dot11MeshTTL) ||
4530 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4531 cur_params.element_ttl) ||
4532 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4533 cur_params.auto_open_plinks) ||
4534 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4535 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
4536 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4537 cur_params.dot11MeshHWMPmaxPREQretries) ||
4538 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4539 cur_params.path_refresh_time) ||
4540 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4541 cur_params.min_discovery_timeout) ||
4542 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4543 cur_params.dot11MeshHWMPactivePathTimeout) ||
4544 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4545 cur_params.dot11MeshHWMPpreqMinInterval) ||
4546 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4547 cur_params.dot11MeshHWMPperrMinInterval) ||
4548 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4549 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4550 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4551 cur_params.dot11MeshHWMPRootMode) ||
4552 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4553 cur_params.dot11MeshHWMPRannInterval) ||
4554 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4555 cur_params.dot11MeshGateAnnouncementProtocol) ||
4556 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4557 cur_params.dot11MeshForwarding) ||
4558 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
4559 cur_params.rssi_threshold) ||
4560 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
4561 cur_params.ht_opmode) ||
4562 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4563 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4564 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4565 cur_params.dot11MeshHWMProotInterval) ||
4566 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4567 cur_params.dot11MeshHWMPconfirmationInterval) ||
4568 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4569 cur_params.power_mode) ||
4570 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4571 cur_params.dot11MeshAwakeWindowDuration))
4572 goto nla_put_failure;
4573 nla_nest_end(msg, pinfoattr);
4574 genlmsg_end(msg, hdr);
4575 return genlmsg_reply(msg, info);
4578 genlmsg_cancel(msg, hdr);
4584 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
4585 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4586 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4587 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4588 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4589 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4590 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
4591 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
4592 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
4593 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
4594 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4595 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4596 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4597 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4598 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
4599 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
4600 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
4601 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
4602 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
4603 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
4604 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
4605 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4606 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
4607 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4608 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
4609 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
4610 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4611 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
4614 static const struct nla_policy
4615 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
4616 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
4617 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4618 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
4619 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
4620 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
4621 .len = IEEE80211_MAX_DATA_LEN },
4622 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
4625 static int nl80211_parse_mesh_config(struct genl_info *info,
4626 struct mesh_config *cfg,
4629 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
4632 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4635 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4637 cfg->param = fn(tb[attr]); \
4638 mask |= (1 << (attr - 1)); \
4643 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
4645 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
4646 info->attrs[NL80211_ATTR_MESH_CONFIG],
4647 nl80211_meshconf_params_policy))
4650 /* This makes sure that there aren't more than 32 mesh config
4651 * parameters (otherwise our bitfield scheme would not work.) */
4652 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4654 /* Fill in the params struct */
4655 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
4656 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4658 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
4659 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4661 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
4662 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4664 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
4665 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
4668 mask, NL80211_MESHCONF_MAX_RETRIES,
4670 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
4671 mask, NL80211_MESHCONF_TTL, nla_get_u8);
4672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
4673 mask, NL80211_MESHCONF_ELEMENT_TTL,
4675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
4676 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4680 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
4683 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4685 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
4686 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4688 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
4689 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4691 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4693 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
4697 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4699 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
4701 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4704 dot11MeshHWMPnetDiameterTraversalTime,
4706 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4709 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4711 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4712 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4715 dot11MeshGateAnnouncementProtocol, 0, 1,
4716 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
4719 mask, NL80211_MESHCONF_FORWARDING,
4721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
4722 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4724 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
4725 mask, NL80211_MESHCONF_HT_OPMODE,
4727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
4729 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4731 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
4732 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4734 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4735 dot11MeshHWMPconfirmationInterval,
4737 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4739 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4740 NL80211_MESH_POWER_ACTIVE,
4741 NL80211_MESH_POWER_MAX,
4742 mask, NL80211_MESHCONF_POWER_MODE,
4744 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4746 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
4752 #undef FILL_IN_MESH_PARAM_IF_SET
4755 static int nl80211_parse_mesh_setup(struct genl_info *info,
4756 struct mesh_setup *setup)
4758 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4760 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4762 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4763 info->attrs[NL80211_ATTR_MESH_SETUP],
4764 nl80211_mesh_setup_params_policy))
4767 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4768 setup->sync_method =
4769 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4770 IEEE80211_SYNC_METHOD_VENDOR :
4771 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4773 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4774 setup->path_sel_proto =
4775 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4776 IEEE80211_PATH_PROTOCOL_VENDOR :
4777 IEEE80211_PATH_PROTOCOL_HWMP;
4779 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4780 setup->path_metric =
4781 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4782 IEEE80211_PATH_METRIC_VENDOR :
4783 IEEE80211_PATH_METRIC_AIRTIME;
4786 if (tb[NL80211_MESH_SETUP_IE]) {
4787 struct nlattr *ieattr =
4788 tb[NL80211_MESH_SETUP_IE];
4789 if (!is_valid_ie_attr(ieattr))
4791 setup->ie = nla_data(ieattr);
4792 setup->ie_len = nla_len(ieattr);
4794 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4795 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
4800 static int nl80211_update_mesh_config(struct sk_buff *skb,
4801 struct genl_info *info)
4803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4804 struct net_device *dev = info->user_ptr[1];
4805 struct wireless_dev *wdev = dev->ieee80211_ptr;
4806 struct mesh_config cfg;
4810 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4813 if (!rdev->ops->update_mesh_config)
4816 err = nl80211_parse_mesh_config(info, &cfg, &mask);
4821 if (!wdev->mesh_id_len)
4825 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
4832 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4834 const struct ieee80211_regdomain *regdom;
4835 struct sk_buff *msg;
4837 struct nlattr *nl_reg_rules;
4841 mutex_lock(&cfg80211_mutex);
4843 if (!cfg80211_regdomain)
4846 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4852 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4853 NL80211_CMD_GET_REG);
4857 if (reg_last_request_cell_base() &&
4858 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4859 NL80211_USER_REG_HINT_CELL_BASE))
4860 goto nla_put_failure;
4863 regdom = rcu_dereference(cfg80211_regdomain);
4865 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4866 (regdom->dfs_region &&
4867 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4868 goto nla_put_failure_rcu;
4870 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4872 goto nla_put_failure_rcu;
4874 for (i = 0; i < regdom->n_reg_rules; i++) {
4875 struct nlattr *nl_reg_rule;
4876 const struct ieee80211_reg_rule *reg_rule;
4877 const struct ieee80211_freq_range *freq_range;
4878 const struct ieee80211_power_rule *power_rule;
4880 reg_rule = ®dom->reg_rules[i];
4881 freq_range = ®_rule->freq_range;
4882 power_rule = ®_rule->power_rule;
4884 nl_reg_rule = nla_nest_start(msg, i);
4886 goto nla_put_failure_rcu;
4888 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4890 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4891 freq_range->start_freq_khz) ||
4892 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4893 freq_range->end_freq_khz) ||
4894 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4895 freq_range->max_bandwidth_khz) ||
4896 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4897 power_rule->max_antenna_gain) ||
4898 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4899 power_rule->max_eirp))
4900 goto nla_put_failure_rcu;
4902 nla_nest_end(msg, nl_reg_rule);
4906 nla_nest_end(msg, nl_reg_rules);
4908 genlmsg_end(msg, hdr);
4909 err = genlmsg_reply(msg, info);
4912 nla_put_failure_rcu:
4915 genlmsg_cancel(msg, hdr);
4920 mutex_unlock(&cfg80211_mutex);
4924 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4926 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4927 struct nlattr *nl_reg_rule;
4928 char *alpha2 = NULL;
4929 int rem_reg_rules = 0, r = 0;
4930 u32 num_rules = 0, rule_idx = 0, size_of_regd;
4932 struct ieee80211_regdomain *rd = NULL;
4934 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4937 if (!info->attrs[NL80211_ATTR_REG_RULES])
4940 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4942 if (info->attrs[NL80211_ATTR_DFS_REGION])
4943 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4945 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4948 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
4952 size_of_regd = sizeof(struct ieee80211_regdomain) +
4953 num_rules * sizeof(struct ieee80211_reg_rule);
4955 rd = kzalloc(size_of_regd, GFP_KERNEL);
4959 rd->n_reg_rules = num_rules;
4960 rd->alpha2[0] = alpha2[0];
4961 rd->alpha2[1] = alpha2[1];
4964 * Disable DFS master mode if the DFS region was
4965 * not supported or known on this kernel.
4967 if (reg_supported_dfs_region(dfs_region))
4968 rd->dfs_region = dfs_region;
4970 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4972 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4973 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4975 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4981 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4987 mutex_lock(&cfg80211_mutex);
4990 /* set_regdom took ownership */
4992 mutex_unlock(&cfg80211_mutex);
4999 static int validate_scan_freqs(struct nlattr *freqs)
5001 struct nlattr *attr1, *attr2;
5002 int n_channels = 0, tmp1, tmp2;
5004 nla_for_each_nested(attr1, freqs, tmp1) {
5007 * Some hardware has a limited channel list for
5008 * scanning, and it is pretty much nonsensical
5009 * to scan for a channel twice, so disallow that
5010 * and don't require drivers to check that the
5011 * channel list they get isn't longer than what
5012 * they can scan, as long as they can scan all
5013 * the channels they registered at once.
5015 nla_for_each_nested(attr2, freqs, tmp2)
5016 if (attr1 != attr2 &&
5017 nla_get_u32(attr1) == nla_get_u32(attr2))
5024 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5027 struct wireless_dev *wdev = info->user_ptr[1];
5028 struct cfg80211_scan_request *request;
5029 struct nlattr *attr;
5030 struct wiphy *wiphy;
5031 int err, tmp, n_ssids = 0, n_channels, i;
5034 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5037 wiphy = &rdev->wiphy;
5039 if (!rdev->ops->scan)
5045 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5046 n_channels = validate_scan_freqs(
5047 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5051 enum ieee80211_band band;
5054 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5055 if (wiphy->bands[band])
5056 n_channels += wiphy->bands[band]->n_channels;
5059 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5060 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5063 if (n_ssids > wiphy->max_scan_ssids)
5066 if (info->attrs[NL80211_ATTR_IE])
5067 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5071 if (ie_len > wiphy->max_scan_ie_len)
5074 request = kzalloc(sizeof(*request)
5075 + sizeof(*request->ssids) * n_ssids
5076 + sizeof(*request->channels) * n_channels
5077 + ie_len, GFP_KERNEL);
5082 request->ssids = (void *)&request->channels[n_channels];
5083 request->n_ssids = n_ssids;
5086 request->ie = (void *)(request->ssids + n_ssids);
5088 request->ie = (void *)(request->channels + n_channels);
5092 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5093 /* user specified, bail out if channel not found */
5094 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
5095 struct ieee80211_channel *chan;
5097 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5104 /* ignore disabled channels */
5105 if (chan->flags & IEEE80211_CHAN_DISABLED)
5108 request->channels[i] = chan;
5112 enum ieee80211_band band;
5115 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5117 if (!wiphy->bands[band])
5119 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5120 struct ieee80211_channel *chan;
5122 chan = &wiphy->bands[band]->channels[j];
5124 if (chan->flags & IEEE80211_CHAN_DISABLED)
5127 request->channels[i] = chan;
5138 request->n_channels = i;
5141 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5142 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
5143 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
5147 request->ssids[i].ssid_len = nla_len(attr);
5148 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
5153 if (info->attrs[NL80211_ATTR_IE]) {
5154 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5155 memcpy((void *)request->ie,
5156 nla_data(info->attrs[NL80211_ATTR_IE]),
5160 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
5161 if (wiphy->bands[i])
5163 (1 << wiphy->bands[i]->n_bitrates) - 1;
5165 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5166 nla_for_each_nested(attr,
5167 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5169 enum ieee80211_band band = nla_type(attr);
5171 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
5175 err = ieee80211_get_ratemask(wiphy->bands[band],
5178 &request->rates[band]);
5184 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
5185 request->flags = nla_get_u32(
5186 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
5187 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5188 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5189 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5190 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
5197 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5199 request->wdev = wdev;
5200 request->wiphy = &rdev->wiphy;
5201 request->scan_start = jiffies;
5203 rdev->scan_req = request;
5204 err = rdev_scan(rdev, request);
5207 nl80211_send_scan_start(rdev, wdev);
5209 dev_hold(wdev->netdev);
5212 rdev->scan_req = NULL;
5219 static int nl80211_start_sched_scan(struct sk_buff *skb,
5220 struct genl_info *info)
5222 struct cfg80211_sched_scan_request *request;
5223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5224 struct net_device *dev = info->user_ptr[1];
5225 struct nlattr *attr;
5226 struct wiphy *wiphy;
5227 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
5229 enum ieee80211_band band;
5231 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
5233 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5234 !rdev->ops->sched_scan_start)
5237 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5240 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5243 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5247 wiphy = &rdev->wiphy;
5249 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5250 n_channels = validate_scan_freqs(
5251 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5257 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5258 if (wiphy->bands[band])
5259 n_channels += wiphy->bands[band]->n_channels;
5262 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5263 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5267 if (n_ssids > wiphy->max_sched_scan_ssids)
5270 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5271 nla_for_each_nested(attr,
5272 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5276 if (n_match_sets > wiphy->max_match_sets)
5279 if (info->attrs[NL80211_ATTR_IE])
5280 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5284 if (ie_len > wiphy->max_sched_scan_ie_len)
5287 mutex_lock(&rdev->sched_scan_mtx);
5289 if (rdev->sched_scan_req) {
5294 request = kzalloc(sizeof(*request)
5295 + sizeof(*request->ssids) * n_ssids
5296 + sizeof(*request->match_sets) * n_match_sets
5297 + sizeof(*request->channels) * n_channels
5298 + ie_len, GFP_KERNEL);
5305 request->ssids = (void *)&request->channels[n_channels];
5306 request->n_ssids = n_ssids;
5309 request->ie = (void *)(request->ssids + n_ssids);
5311 request->ie = (void *)(request->channels + n_channels);
5316 request->match_sets = (void *)(request->ie + ie_len);
5317 else if (request->ssids)
5318 request->match_sets =
5319 (void *)(request->ssids + n_ssids);
5321 request->match_sets =
5322 (void *)(request->channels + n_channels);
5324 request->n_match_sets = n_match_sets;
5327 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5328 /* user specified, bail out if channel not found */
5329 nla_for_each_nested(attr,
5330 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5332 struct ieee80211_channel *chan;
5334 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5341 /* ignore disabled channels */
5342 if (chan->flags & IEEE80211_CHAN_DISABLED)
5345 request->channels[i] = chan;
5350 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5352 if (!wiphy->bands[band])
5354 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5355 struct ieee80211_channel *chan;
5357 chan = &wiphy->bands[band]->channels[j];
5359 if (chan->flags & IEEE80211_CHAN_DISABLED)
5362 request->channels[i] = chan;
5373 request->n_channels = i;
5376 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5377 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5379 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
5383 request->ssids[i].ssid_len = nla_len(attr);
5384 memcpy(request->ssids[i].ssid, nla_data(attr),
5391 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5392 nla_for_each_nested(attr,
5393 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5395 struct nlattr *ssid, *rssi;
5397 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5398 nla_data(attr), nla_len(attr),
5399 nl80211_match_policy);
5400 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
5402 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5406 memcpy(request->match_sets[i].ssid.ssid,
5407 nla_data(ssid), nla_len(ssid));
5408 request->match_sets[i].ssid.ssid_len =
5411 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5413 request->rssi_thold = nla_get_u32(rssi);
5415 request->rssi_thold =
5416 NL80211_SCAN_RSSI_THOLD_OFF;
5421 if (info->attrs[NL80211_ATTR_IE]) {
5422 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5423 memcpy((void *)request->ie,
5424 nla_data(info->attrs[NL80211_ATTR_IE]),
5428 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
5429 request->flags = nla_get_u32(
5430 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
5431 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5432 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5433 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5434 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
5441 request->wiphy = &rdev->wiphy;
5442 request->interval = interval;
5443 request->scan_start = jiffies;
5445 err = rdev_sched_scan_start(rdev, dev, request);
5447 rdev->sched_scan_req = request;
5448 nl80211_send_sched_scan(rdev, dev,
5449 NL80211_CMD_START_SCHED_SCAN);
5456 mutex_unlock(&rdev->sched_scan_mtx);
5460 static int nl80211_stop_sched_scan(struct sk_buff *skb,
5461 struct genl_info *info)
5463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5466 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5467 !rdev->ops->sched_scan_stop)
5470 mutex_lock(&rdev->sched_scan_mtx);
5471 err = __cfg80211_stop_sched_scan(rdev, false);
5472 mutex_unlock(&rdev->sched_scan_mtx);
5477 static int nl80211_start_radar_detection(struct sk_buff *skb,
5478 struct genl_info *info)
5480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5481 struct net_device *dev = info->user_ptr[1];
5482 struct wireless_dev *wdev = dev->ieee80211_ptr;
5483 struct cfg80211_chan_def chandef;
5486 err = nl80211_parse_chandef(rdev, info, &chandef);
5490 if (wdev->cac_started)
5493 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5500 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5503 if (!rdev->ops->start_radar_detection)
5506 mutex_lock(&rdev->devlist_mtx);
5507 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5508 chandef.chan, CHAN_MODE_SHARED,
5509 BIT(chandef.width));
5513 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5515 wdev->channel = chandef.chan;
5516 wdev->cac_started = true;
5517 wdev->cac_start_time = jiffies;
5520 mutex_unlock(&rdev->devlist_mtx);
5525 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5527 struct cfg80211_registered_device *rdev,
5528 struct wireless_dev *wdev,
5529 struct cfg80211_internal_bss *intbss)
5531 struct cfg80211_bss *res = &intbss->pub;
5532 const struct cfg80211_bss_ies *ies;
5537 ASSERT_WDEV_LOCK(wdev);
5539 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5540 NL80211_CMD_NEW_SCAN_RESULTS);
5544 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5546 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5547 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5548 goto nla_put_failure;
5550 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5552 goto nla_put_failure;
5553 if ((!is_zero_ether_addr(res->bssid) &&
5554 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
5555 goto nla_put_failure;
5558 ies = rcu_dereference(res->ies);
5560 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5561 goto fail_unlock_rcu;
5563 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5564 ies->len, ies->data))
5565 goto fail_unlock_rcu;
5567 ies = rcu_dereference(res->beacon_ies);
5569 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5570 goto fail_unlock_rcu;
5571 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5572 ies->len, ies->data))
5573 goto fail_unlock_rcu;
5577 if (res->beacon_interval &&
5578 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5579 goto nla_put_failure;
5580 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5581 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5582 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5583 jiffies_to_msecs(jiffies - intbss->ts)))
5584 goto nla_put_failure;
5586 switch (rdev->wiphy.signal_type) {
5587 case CFG80211_SIGNAL_TYPE_MBM:
5588 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5589 goto nla_put_failure;
5591 case CFG80211_SIGNAL_TYPE_UNSPEC:
5592 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5593 goto nla_put_failure;
5599 switch (wdev->iftype) {
5600 case NL80211_IFTYPE_P2P_CLIENT:
5601 case NL80211_IFTYPE_STATION:
5602 if (intbss == wdev->current_bss &&
5603 nla_put_u32(msg, NL80211_BSS_STATUS,
5604 NL80211_BSS_STATUS_ASSOCIATED))
5605 goto nla_put_failure;
5607 case NL80211_IFTYPE_ADHOC:
5608 if (intbss == wdev->current_bss &&
5609 nla_put_u32(msg, NL80211_BSS_STATUS,
5610 NL80211_BSS_STATUS_IBSS_JOINED))
5611 goto nla_put_failure;
5617 nla_nest_end(msg, bss);
5619 return genlmsg_end(msg, hdr);
5624 genlmsg_cancel(msg, hdr);
5628 static int nl80211_dump_scan(struct sk_buff *skb,
5629 struct netlink_callback *cb)
5631 struct cfg80211_registered_device *rdev;
5632 struct net_device *dev;
5633 struct cfg80211_internal_bss *scan;
5634 struct wireless_dev *wdev;
5635 int start = cb->args[1], idx = 0;
5638 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5642 wdev = dev->ieee80211_ptr;
5645 spin_lock_bh(&rdev->bss_lock);
5646 cfg80211_bss_expire(rdev);
5648 cb->seq = rdev->bss_generation;
5650 list_for_each_entry(scan, &rdev->bss_list, list) {
5653 if (nl80211_send_bss(skb, cb,
5654 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5655 rdev, wdev, scan) < 0) {
5661 spin_unlock_bh(&rdev->bss_lock);
5665 nl80211_finish_netdev_dump(rdev);
5670 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
5671 int flags, struct net_device *dev,
5672 struct survey_info *survey)
5675 struct nlattr *infoattr;
5677 hdr = nl80211hdr_put(msg, portid, seq, flags,
5678 NL80211_CMD_NEW_SURVEY_RESULTS);
5682 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5683 goto nla_put_failure;
5685 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5687 goto nla_put_failure;
5689 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5690 survey->channel->center_freq))
5691 goto nla_put_failure;
5693 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5694 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5695 goto nla_put_failure;
5696 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5697 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5698 goto nla_put_failure;
5699 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5700 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5701 survey->channel_time))
5702 goto nla_put_failure;
5703 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5704 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5705 survey->channel_time_busy))
5706 goto nla_put_failure;
5707 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5708 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5709 survey->channel_time_ext_busy))
5710 goto nla_put_failure;
5711 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5712 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5713 survey->channel_time_rx))
5714 goto nla_put_failure;
5715 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5716 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5717 survey->channel_time_tx))
5718 goto nla_put_failure;
5720 nla_nest_end(msg, infoattr);
5722 return genlmsg_end(msg, hdr);
5725 genlmsg_cancel(msg, hdr);
5729 static int nl80211_dump_survey(struct sk_buff *skb,
5730 struct netlink_callback *cb)
5732 struct survey_info survey;
5733 struct cfg80211_registered_device *dev;
5734 struct net_device *netdev;
5735 int survey_idx = cb->args[1];
5738 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5742 if (!dev->ops->dump_survey) {
5748 struct ieee80211_channel *chan;
5750 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
5756 /* Survey without a channel doesn't make sense */
5757 if (!survey.channel) {
5762 chan = ieee80211_get_channel(&dev->wiphy,
5763 survey.channel->center_freq);
5764 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5769 if (nl80211_send_survey(skb,
5770 NETLINK_CB(cb->skb).portid,
5771 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5779 cb->args[1] = survey_idx;
5782 nl80211_finish_netdev_dump(dev);
5786 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5788 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5789 NL80211_WPA_VERSION_2));
5792 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5795 struct net_device *dev = info->user_ptr[1];
5796 struct ieee80211_channel *chan;
5797 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5798 int err, ssid_len, ie_len = 0, sae_data_len = 0;
5799 enum nl80211_auth_type auth_type;
5800 struct key_parse key;
5801 bool local_state_change;
5803 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5806 if (!info->attrs[NL80211_ATTR_MAC])
5809 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5812 if (!info->attrs[NL80211_ATTR_SSID])
5815 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5818 err = nl80211_parse_key(info, &key);
5823 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5825 if (!key.p.key || !key.p.key_len)
5827 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5828 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5829 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5830 key.p.key_len != WLAN_KEY_LEN_WEP104))
5842 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5843 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5852 if (!rdev->ops->auth)
5855 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5856 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5859 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5860 chan = ieee80211_get_channel(&rdev->wiphy,
5861 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5862 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5865 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5866 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5868 if (info->attrs[NL80211_ATTR_IE]) {
5869 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5870 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5873 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5874 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
5877 if (auth_type == NL80211_AUTHTYPE_SAE &&
5878 !info->attrs[NL80211_ATTR_SAE_DATA])
5881 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5882 if (auth_type != NL80211_AUTHTYPE_SAE)
5884 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5885 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5886 /* need to include at least Auth Transaction and Status Code */
5887 if (sae_data_len < 4)
5891 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5894 * Since we no longer track auth state, ignore
5895 * requests to only change local state.
5897 if (local_state_change)
5900 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5901 ssid, ssid_len, ie, ie_len,
5902 key.p.key, key.p.key_len, key.idx,
5903 sae_data, sae_data_len);
5906 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5907 struct genl_info *info,
5908 struct cfg80211_crypto_settings *settings,
5911 memset(settings, 0, sizeof(*settings));
5913 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5915 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5917 proto = nla_get_u16(
5918 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5919 settings->control_port_ethertype = cpu_to_be16(proto);
5920 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5923 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5924 settings->control_port_no_encrypt = true;
5926 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5928 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5932 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5933 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5934 settings->n_ciphers_pairwise = len / sizeof(u32);
5936 if (len % sizeof(u32))
5939 if (settings->n_ciphers_pairwise > cipher_limit)
5942 memcpy(settings->ciphers_pairwise, data, len);
5944 for (i = 0; i < settings->n_ciphers_pairwise; i++)
5945 if (!cfg80211_supported_cipher_suite(
5947 settings->ciphers_pairwise[i]))
5951 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5952 settings->cipher_group =
5953 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
5954 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5955 settings->cipher_group))
5959 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5960 settings->wpa_versions =
5961 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5962 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5966 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5970 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5971 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5972 settings->n_akm_suites = len / sizeof(u32);
5974 if (len % sizeof(u32))
5977 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5980 memcpy(settings->akm_suites, data, len);
5986 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5989 struct net_device *dev = info->user_ptr[1];
5990 struct ieee80211_channel *chan;
5991 struct cfg80211_assoc_request req = {};
5992 const u8 *bssid, *ssid;
5993 int err, ssid_len = 0;
5995 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5998 if (!info->attrs[NL80211_ATTR_MAC] ||
5999 !info->attrs[NL80211_ATTR_SSID] ||
6000 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
6003 if (!rdev->ops->assoc)
6006 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6007 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6010 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6012 chan = ieee80211_get_channel(&rdev->wiphy,
6013 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6014 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6017 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6018 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6020 if (info->attrs[NL80211_ATTR_IE]) {
6021 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6022 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6025 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6026 enum nl80211_mfp mfp =
6027 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6028 if (mfp == NL80211_MFP_REQUIRED)
6030 else if (mfp != NL80211_MFP_NO)
6034 if (info->attrs[NL80211_ATTR_PREV_BSSID])
6035 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
6037 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6038 req.flags |= ASSOC_REQ_DISABLE_HT;
6040 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6041 memcpy(&req.ht_capa_mask,
6042 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6043 sizeof(req.ht_capa_mask));
6045 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6046 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6048 memcpy(&req.ht_capa,
6049 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6050 sizeof(req.ht_capa));
6053 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6054 req.flags |= ASSOC_REQ_DISABLE_VHT;
6056 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6057 memcpy(&req.vht_capa_mask,
6058 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6059 sizeof(req.vht_capa_mask));
6061 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6062 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6064 memcpy(&req.vht_capa,
6065 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6066 sizeof(req.vht_capa));
6069 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
6071 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6072 ssid, ssid_len, &req);
6077 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6080 struct net_device *dev = info->user_ptr[1];
6081 const u8 *ie = NULL, *bssid;
6084 bool local_state_change;
6086 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6089 if (!info->attrs[NL80211_ATTR_MAC])
6092 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6095 if (!rdev->ops->deauth)
6098 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6099 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6102 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6104 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6105 if (reason_code == 0) {
6106 /* Reason Code 0 is reserved */
6110 if (info->attrs[NL80211_ATTR_IE]) {
6111 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6112 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6115 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6117 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6118 local_state_change);
6121 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6124 struct net_device *dev = info->user_ptr[1];
6125 const u8 *ie = NULL, *bssid;
6128 bool local_state_change;
6130 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6133 if (!info->attrs[NL80211_ATTR_MAC])
6136 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6139 if (!rdev->ops->disassoc)
6142 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6143 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6146 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6148 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6149 if (reason_code == 0) {
6150 /* Reason Code 0 is reserved */
6154 if (info->attrs[NL80211_ATTR_IE]) {
6155 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6156 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6159 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6161 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6162 local_state_change);
6166 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6167 int mcast_rate[IEEE80211_NUM_BANDS],
6170 struct wiphy *wiphy = &rdev->wiphy;
6174 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6175 struct ieee80211_supported_band *sband;
6177 sband = wiphy->bands[band];
6181 for (i = 0; i < sband->n_bitrates; i++) {
6182 if (sband->bitrates[i].bitrate == rateval) {
6183 mcast_rate[band] = i + 1;
6193 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6196 struct net_device *dev = info->user_ptr[1];
6197 struct cfg80211_ibss_params ibss;
6198 struct wiphy *wiphy;
6199 struct cfg80211_cached_keys *connkeys = NULL;
6202 memset(&ibss, 0, sizeof(ibss));
6204 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6207 if (!info->attrs[NL80211_ATTR_SSID] ||
6208 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6211 ibss.beacon_interval = 100;
6213 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6214 ibss.beacon_interval =
6215 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6216 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6220 if (!rdev->ops->join_ibss)
6223 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6226 wiphy = &rdev->wiphy;
6228 if (info->attrs[NL80211_ATTR_MAC]) {
6229 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6231 if (!is_valid_ether_addr(ibss.bssid))
6234 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6235 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6237 if (info->attrs[NL80211_ATTR_IE]) {
6238 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6239 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6242 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6246 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
6249 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6251 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6252 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
6255 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
6256 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
6258 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6260 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6262 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6263 struct ieee80211_supported_band *sband =
6264 wiphy->bands[ibss.chandef.chan->band];
6266 err = ieee80211_get_ratemask(sband, rates, n_rates,
6272 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6273 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6274 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6277 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6280 connkeys = nl80211_parse_connkeys(rdev,
6281 info->attrs[NL80211_ATTR_KEYS],
6283 if (IS_ERR(connkeys))
6284 return PTR_ERR(connkeys);
6286 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6294 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6296 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
6302 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6305 struct net_device *dev = info->user_ptr[1];
6307 if (!rdev->ops->leave_ibss)
6310 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6313 return cfg80211_leave_ibss(rdev, dev, false);
6316 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6319 struct net_device *dev = info->user_ptr[1];
6320 int mcast_rate[IEEE80211_NUM_BANDS];
6324 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6325 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6328 if (!rdev->ops->set_mcast_rate)
6331 memset(mcast_rate, 0, sizeof(mcast_rate));
6333 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6336 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6337 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6340 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6346 #ifdef CONFIG_NL80211_TESTMODE
6347 static struct genl_multicast_group nl80211_testmode_mcgrp = {
6351 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6356 if (!info->attrs[NL80211_ATTR_TESTDATA])
6360 if (rdev->ops->testmode_cmd) {
6361 rdev->testmode_info = info;
6362 err = rdev_testmode_cmd(rdev,
6363 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6364 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6365 rdev->testmode_info = NULL;
6371 static int nl80211_testmode_dump(struct sk_buff *skb,
6372 struct netlink_callback *cb)
6374 struct cfg80211_registered_device *rdev;
6382 * 0 is a valid index, but not valid for args[0],
6383 * so we need to offset by 1.
6385 phy_idx = cb->args[0] - 1;
6387 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6388 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6393 mutex_lock(&cfg80211_mutex);
6394 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6395 nl80211_fam.attrbuf);
6397 mutex_unlock(&cfg80211_mutex);
6398 return PTR_ERR(rdev);
6400 phy_idx = rdev->wiphy_idx;
6402 mutex_unlock(&cfg80211_mutex);
6404 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6406 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6410 data = nla_data((void *)cb->args[1]);
6411 data_len = nla_len((void *)cb->args[1]);
6414 mutex_lock(&cfg80211_mutex);
6415 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6417 mutex_unlock(&cfg80211_mutex);
6420 cfg80211_lock_rdev(rdev);
6421 mutex_unlock(&cfg80211_mutex);
6423 if (!rdev->ops->testmode_dump) {
6429 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
6430 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6431 NL80211_CMD_TESTMODE);
6432 struct nlattr *tmdata;
6434 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
6435 genlmsg_cancel(skb, hdr);
6439 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6441 genlmsg_cancel(skb, hdr);
6444 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
6445 nla_nest_end(skb, tmdata);
6447 if (err == -ENOBUFS || err == -ENOENT) {
6448 genlmsg_cancel(skb, hdr);
6451 genlmsg_cancel(skb, hdr);
6455 genlmsg_end(skb, hdr);
6460 cb->args[0] = phy_idx + 1;
6462 cfg80211_unlock_rdev(rdev);
6466 static struct sk_buff *
6467 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
6468 int approxlen, u32 portid, u32 seq, gfp_t gfp)
6470 struct sk_buff *skb;
6472 struct nlattr *data;
6474 skb = nlmsg_new(approxlen + 100, gfp);
6478 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
6484 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6485 goto nla_put_failure;
6486 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6488 ((void **)skb->cb)[0] = rdev;
6489 ((void **)skb->cb)[1] = hdr;
6490 ((void **)skb->cb)[2] = data;
6499 struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6502 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6504 if (WARN_ON(!rdev->testmode_info))
6507 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
6508 rdev->testmode_info->snd_portid,
6509 rdev->testmode_info->snd_seq,
6512 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6514 int cfg80211_testmode_reply(struct sk_buff *skb)
6516 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6517 void *hdr = ((void **)skb->cb)[1];
6518 struct nlattr *data = ((void **)skb->cb)[2];
6520 if (WARN_ON(!rdev->testmode_info)) {
6525 nla_nest_end(skb, data);
6526 genlmsg_end(skb, hdr);
6527 return genlmsg_reply(skb, rdev->testmode_info);
6529 EXPORT_SYMBOL(cfg80211_testmode_reply);
6531 struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6532 int approxlen, gfp_t gfp)
6534 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6536 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6538 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6540 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6542 void *hdr = ((void **)skb->cb)[1];
6543 struct nlattr *data = ((void **)skb->cb)[2];
6545 nla_nest_end(skb, data);
6546 genlmsg_end(skb, hdr);
6547 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6549 EXPORT_SYMBOL(cfg80211_testmode_event);
6552 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6555 struct net_device *dev = info->user_ptr[1];
6556 struct cfg80211_connect_params connect;
6557 struct wiphy *wiphy;
6558 struct cfg80211_cached_keys *connkeys = NULL;
6561 memset(&connect, 0, sizeof(connect));
6563 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6566 if (!info->attrs[NL80211_ATTR_SSID] ||
6567 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6570 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6572 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
6573 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6574 NL80211_CMD_CONNECT))
6577 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6579 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6581 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
6582 NL80211_MAX_NR_CIPHER_SUITES);
6586 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6587 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6590 wiphy = &rdev->wiphy;
6592 connect.bg_scan_period = -1;
6593 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6594 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6595 connect.bg_scan_period =
6596 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6599 if (info->attrs[NL80211_ATTR_MAC])
6600 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6601 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6602 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6604 if (info->attrs[NL80211_ATTR_IE]) {
6605 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6606 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6609 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6610 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6611 if (connect.mfp != NL80211_MFP_REQUIRED &&
6612 connect.mfp != NL80211_MFP_NO)
6615 connect.mfp = NL80211_MFP_NO;
6618 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6620 ieee80211_get_channel(wiphy,
6621 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6622 if (!connect.channel ||
6623 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6627 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6628 connkeys = nl80211_parse_connkeys(rdev,
6629 info->attrs[NL80211_ATTR_KEYS], NULL);
6630 if (IS_ERR(connkeys))
6631 return PTR_ERR(connkeys);
6634 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6635 connect.flags |= ASSOC_REQ_DISABLE_HT;
6637 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6638 memcpy(&connect.ht_capa_mask,
6639 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6640 sizeof(connect.ht_capa_mask));
6642 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6643 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6647 memcpy(&connect.ht_capa,
6648 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6649 sizeof(connect.ht_capa));
6652 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6653 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6655 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6656 memcpy(&connect.vht_capa_mask,
6657 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6658 sizeof(connect.vht_capa_mask));
6660 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6661 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6665 memcpy(&connect.vht_capa,
6666 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6667 sizeof(connect.vht_capa));
6670 err = cfg80211_connect(rdev, dev, &connect, connkeys);
6676 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6679 struct net_device *dev = info->user_ptr[1];
6682 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6683 reason = WLAN_REASON_DEAUTH_LEAVING;
6685 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6690 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6691 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6694 return cfg80211_disconnect(rdev, dev, reason, true);
6697 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6699 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6704 if (!info->attrs[NL80211_ATTR_PID])
6707 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6709 net = get_net_ns_by_pid(pid);
6711 return PTR_ERR(net);
6715 /* check if anything to do */
6716 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6717 err = cfg80211_switch_netns(rdev, net);
6723 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6726 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6727 struct cfg80211_pmksa *pmksa) = NULL;
6728 struct net_device *dev = info->user_ptr[1];
6729 struct cfg80211_pmksa pmksa;
6731 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6733 if (!info->attrs[NL80211_ATTR_MAC])
6736 if (!info->attrs[NL80211_ATTR_PMKID])
6739 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6740 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6742 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6743 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6746 switch (info->genlhdr->cmd) {
6747 case NL80211_CMD_SET_PMKSA:
6748 rdev_ops = rdev->ops->set_pmksa;
6750 case NL80211_CMD_DEL_PMKSA:
6751 rdev_ops = rdev->ops->del_pmksa;
6761 return rdev_ops(&rdev->wiphy, dev, &pmksa);
6764 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6767 struct net_device *dev = info->user_ptr[1];
6769 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6770 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6773 if (!rdev->ops->flush_pmksa)
6776 return rdev_flush_pmksa(rdev, dev);
6779 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6782 struct net_device *dev = info->user_ptr[1];
6783 u8 action_code, dialog_token;
6787 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6788 !rdev->ops->tdls_mgmt)
6791 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6792 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6793 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6794 !info->attrs[NL80211_ATTR_IE] ||
6795 !info->attrs[NL80211_ATTR_MAC])
6798 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6799 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6800 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6801 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6803 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6804 dialog_token, status_code,
6805 nla_data(info->attrs[NL80211_ATTR_IE]),
6806 nla_len(info->attrs[NL80211_ATTR_IE]));
6809 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6812 struct net_device *dev = info->user_ptr[1];
6813 enum nl80211_tdls_operation operation;
6816 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6817 !rdev->ops->tdls_oper)
6820 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6821 !info->attrs[NL80211_ATTR_MAC])
6824 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6825 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6827 return rdev_tdls_oper(rdev, dev, peer, operation);
6830 static int nl80211_remain_on_channel(struct sk_buff *skb,
6831 struct genl_info *info)
6833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6834 struct wireless_dev *wdev = info->user_ptr[1];
6835 struct cfg80211_chan_def chandef;
6836 struct sk_buff *msg;
6842 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6843 !info->attrs[NL80211_ATTR_DURATION])
6846 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6848 if (!rdev->ops->remain_on_channel ||
6849 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
6853 * We should be on that channel for at least a minimum amount of
6854 * time (10ms) but no longer than the driver supports.
6856 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6857 duration > rdev->wiphy.max_remain_on_channel_duration)
6860 err = nl80211_parse_chandef(rdev, info, &chandef);
6864 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6868 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6869 NL80211_CMD_REMAIN_ON_CHANNEL);
6876 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6882 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6883 goto nla_put_failure;
6885 genlmsg_end(msg, hdr);
6887 return genlmsg_reply(msg, info);
6896 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6897 struct genl_info *info)
6899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6900 struct wireless_dev *wdev = info->user_ptr[1];
6903 if (!info->attrs[NL80211_ATTR_COOKIE])
6906 if (!rdev->ops->cancel_remain_on_channel)
6909 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6911 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
6914 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6915 u8 *rates, u8 rates_len)
6920 for (i = 0; i < rates_len; i++) {
6921 int rate = (rates[i] & 0x7f) * 5;
6923 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6924 struct ieee80211_rate *srate =
6925 &sband->bitrates[ridx];
6926 if (rate == srate->bitrate) {
6931 if (ridx == sband->n_bitrates)
6932 return 0; /* rate not found */
6938 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6939 u8 *rates, u8 rates_len,
6940 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6944 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6946 for (i = 0; i < rates_len; i++) {
6949 ridx = rates[i] / 8;
6950 rbit = BIT(rates[i] % 8);
6952 /* check validity */
6953 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
6956 /* check availability */
6957 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6966 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
6967 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6968 .len = NL80211_MAX_SUPP_RATES },
6969 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6970 .len = NL80211_MAX_SUPP_HT_RATES },
6973 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6974 struct genl_info *info)
6976 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
6977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6978 struct cfg80211_bitrate_mask mask;
6980 struct net_device *dev = info->user_ptr[1];
6981 struct nlattr *tx_rates;
6982 struct ieee80211_supported_band *sband;
6984 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6987 if (!rdev->ops->set_bitrate_mask)
6990 memset(&mask, 0, sizeof(mask));
6991 /* Default to all rates enabled */
6992 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6993 sband = rdev->wiphy.bands[i];
6994 mask.control[i].legacy =
6995 sband ? (1 << sband->n_bitrates) - 1 : 0;
6997 memcpy(mask.control[i].mcs,
6998 sband->ht_cap.mcs.rx_mask,
6999 sizeof(mask.control[i].mcs));
7001 memset(mask.control[i].mcs, 0,
7002 sizeof(mask.control[i].mcs));
7006 * The nested attribute uses enum nl80211_band as the index. This maps
7007 * directly to the enum ieee80211_band values used in cfg80211.
7009 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
7010 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7012 enum ieee80211_band band = nla_type(tx_rates);
7013 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7015 sband = rdev->wiphy.bands[band];
7018 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7019 nla_len(tx_rates), nl80211_txattr_policy);
7020 if (tb[NL80211_TXRATE_LEGACY]) {
7021 mask.control[band].legacy = rateset_to_mask(
7023 nla_data(tb[NL80211_TXRATE_LEGACY]),
7024 nla_len(tb[NL80211_TXRATE_LEGACY]));
7025 if ((mask.control[band].legacy == 0) &&
7026 nla_len(tb[NL80211_TXRATE_LEGACY]))
7029 if (tb[NL80211_TXRATE_MCS]) {
7030 if (!ht_rateset_to_mask(
7032 nla_data(tb[NL80211_TXRATE_MCS]),
7033 nla_len(tb[NL80211_TXRATE_MCS]),
7034 mask.control[band].mcs))
7038 if (mask.control[band].legacy == 0) {
7039 /* don't allow empty legacy rates if HT
7040 * is not even supported. */
7041 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7044 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7045 if (mask.control[band].mcs[i])
7048 /* legacy and mcs rates may not be both empty */
7049 if (i == IEEE80211_HT_MCS_MASK_LEN)
7054 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
7057 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
7059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7060 struct wireless_dev *wdev = info->user_ptr[1];
7061 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
7063 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7066 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7067 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
7069 switch (wdev->iftype) {
7070 case NL80211_IFTYPE_STATION:
7071 case NL80211_IFTYPE_ADHOC:
7072 case NL80211_IFTYPE_P2P_CLIENT:
7073 case NL80211_IFTYPE_AP:
7074 case NL80211_IFTYPE_AP_VLAN:
7075 case NL80211_IFTYPE_MESH_POINT:
7076 case NL80211_IFTYPE_P2P_GO:
7077 case NL80211_IFTYPE_P2P_DEVICE:
7083 /* not much point in registering if we can't reply */
7084 if (!rdev->ops->mgmt_tx)
7087 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
7088 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7089 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
7092 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
7094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7095 struct wireless_dev *wdev = info->user_ptr[1];
7096 struct cfg80211_chan_def chandef;
7100 struct sk_buff *msg = NULL;
7101 unsigned int wait = 0;
7102 bool offchan, no_cck, dont_wait_for_ack;
7104 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
7106 if (!info->attrs[NL80211_ATTR_FRAME])
7109 if (!rdev->ops->mgmt_tx)
7112 switch (wdev->iftype) {
7113 case NL80211_IFTYPE_STATION:
7114 case NL80211_IFTYPE_ADHOC:
7115 case NL80211_IFTYPE_P2P_CLIENT:
7116 case NL80211_IFTYPE_AP:
7117 case NL80211_IFTYPE_AP_VLAN:
7118 case NL80211_IFTYPE_MESH_POINT:
7119 case NL80211_IFTYPE_P2P_GO:
7120 case NL80211_IFTYPE_P2P_DEVICE:
7126 if (info->attrs[NL80211_ATTR_DURATION]) {
7127 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7129 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7132 * We should wait on the channel for at least a minimum amount
7133 * of time (10ms) but no longer than the driver supports.
7135 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7136 wait > rdev->wiphy.max_remain_on_channel_duration)
7141 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7143 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7146 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7148 err = nl80211_parse_chandef(rdev, info, &chandef);
7152 if (!dont_wait_for_ack) {
7153 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7157 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7166 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
7167 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7168 nla_len(info->attrs[NL80211_ATTR_FRAME]),
7169 no_cck, dont_wait_for_ack, &cookie);
7174 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7175 goto nla_put_failure;
7177 genlmsg_end(msg, hdr);
7178 return genlmsg_reply(msg, info);
7190 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7193 struct wireless_dev *wdev = info->user_ptr[1];
7196 if (!info->attrs[NL80211_ATTR_COOKIE])
7199 if (!rdev->ops->mgmt_tx_cancel_wait)
7202 switch (wdev->iftype) {
7203 case NL80211_IFTYPE_STATION:
7204 case NL80211_IFTYPE_ADHOC:
7205 case NL80211_IFTYPE_P2P_CLIENT:
7206 case NL80211_IFTYPE_AP:
7207 case NL80211_IFTYPE_AP_VLAN:
7208 case NL80211_IFTYPE_P2P_GO:
7209 case NL80211_IFTYPE_P2P_DEVICE:
7215 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7217 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
7220 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7223 struct wireless_dev *wdev;
7224 struct net_device *dev = info->user_ptr[1];
7229 if (!info->attrs[NL80211_ATTR_PS_STATE])
7232 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7234 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7237 wdev = dev->ieee80211_ptr;
7239 if (!rdev->ops->set_power_mgmt)
7242 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7244 if (state == wdev->ps)
7247 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
7253 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7256 enum nl80211_ps_state ps_state;
7257 struct wireless_dev *wdev;
7258 struct net_device *dev = info->user_ptr[1];
7259 struct sk_buff *msg;
7263 wdev = dev->ieee80211_ptr;
7265 if (!rdev->ops->set_power_mgmt)
7268 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7272 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7273 NL80211_CMD_GET_POWER_SAVE);
7280 ps_state = NL80211_PS_ENABLED;
7282 ps_state = NL80211_PS_DISABLED;
7284 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7285 goto nla_put_failure;
7287 genlmsg_end(msg, hdr);
7288 return genlmsg_reply(msg, info);
7297 static struct nla_policy
7298 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7299 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7300 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7301 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
7302 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7303 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7304 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
7307 static int nl80211_set_cqm_txe(struct genl_info *info,
7308 u32 rate, u32 pkts, u32 intvl)
7310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7311 struct wireless_dev *wdev;
7312 struct net_device *dev = info->user_ptr[1];
7314 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
7317 wdev = dev->ieee80211_ptr;
7319 if (!rdev->ops->set_cqm_txe_config)
7322 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7323 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7326 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
7329 static int nl80211_set_cqm_rssi(struct genl_info *info,
7330 s32 threshold, u32 hysteresis)
7332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7333 struct wireless_dev *wdev;
7334 struct net_device *dev = info->user_ptr[1];
7339 wdev = dev->ieee80211_ptr;
7341 if (!rdev->ops->set_cqm_rssi_config)
7344 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7345 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7348 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
7351 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7353 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7357 cqm = info->attrs[NL80211_ATTR_CQM];
7363 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7364 nl80211_attr_cqm_policy);
7368 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7369 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7372 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7373 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7374 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
7375 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7376 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7377 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7378 u32 rate, pkts, intvl;
7379 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7380 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7381 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7382 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
7390 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7393 struct net_device *dev = info->user_ptr[1];
7394 struct mesh_config cfg;
7395 struct mesh_setup setup;
7398 /* start with default */
7399 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
7400 memcpy(&setup, &default_mesh_setup, sizeof(setup));
7402 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
7403 /* and parse parameters if given */
7404 err = nl80211_parse_mesh_config(info, &cfg, NULL);
7409 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7410 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7413 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7414 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7416 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7417 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7418 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7421 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7422 setup.beacon_interval =
7423 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7424 if (setup.beacon_interval < 10 ||
7425 setup.beacon_interval > 10000)
7429 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7431 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7432 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7436 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7437 /* parse additional setup parameters if given */
7438 err = nl80211_parse_mesh_setup(info, &setup);
7443 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7444 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7448 /* cfg80211_join_mesh() will sort it out */
7449 setup.chandef.chan = NULL;
7452 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
7455 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7458 struct net_device *dev = info->user_ptr[1];
7460 return cfg80211_leave_mesh(rdev, dev);
7464 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7465 struct cfg80211_registered_device *rdev)
7467 struct nlattr *nl_pats, *nl_pat;
7470 if (!rdev->wowlan->n_patterns)
7473 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7477 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7478 nl_pat = nla_nest_start(msg, i + 1);
7481 pat_len = rdev->wowlan->patterns[i].pattern_len;
7482 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7483 DIV_ROUND_UP(pat_len, 8),
7484 rdev->wowlan->patterns[i].mask) ||
7485 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7486 pat_len, rdev->wowlan->patterns[i].pattern) ||
7487 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7488 rdev->wowlan->patterns[i].pkt_offset))
7490 nla_nest_end(msg, nl_pat);
7492 nla_nest_end(msg, nl_pats);
7497 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7498 struct cfg80211_wowlan_tcp *tcp)
7500 struct nlattr *nl_tcp;
7505 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7509 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7510 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7511 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7512 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7513 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7514 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7515 tcp->payload_len, tcp->payload) ||
7516 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7517 tcp->data_interval) ||
7518 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7519 tcp->wake_len, tcp->wake_data) ||
7520 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7521 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7524 if (tcp->payload_seq.len &&
7525 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7526 sizeof(tcp->payload_seq), &tcp->payload_seq))
7529 if (tcp->payload_tok.len &&
7530 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7531 sizeof(tcp->payload_tok) + tcp->tokens_size,
7538 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7541 struct sk_buff *msg;
7543 u32 size = NLMSG_DEFAULT_SIZE;
7545 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7546 !rdev->wiphy.wowlan.tcp)
7549 if (rdev->wowlan && rdev->wowlan->tcp) {
7550 /* adjust size to have room for all the data */
7551 size += rdev->wowlan->tcp->tokens_size +
7552 rdev->wowlan->tcp->payload_len +
7553 rdev->wowlan->tcp->wake_len +
7554 rdev->wowlan->tcp->wake_len / 8;
7557 msg = nlmsg_new(size, GFP_KERNEL);
7561 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7562 NL80211_CMD_GET_WOWLAN);
7564 goto nla_put_failure;
7567 struct nlattr *nl_wowlan;
7569 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7571 goto nla_put_failure;
7573 if ((rdev->wowlan->any &&
7574 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7575 (rdev->wowlan->disconnect &&
7576 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7577 (rdev->wowlan->magic_pkt &&
7578 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7579 (rdev->wowlan->gtk_rekey_failure &&
7580 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7581 (rdev->wowlan->eap_identity_req &&
7582 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7583 (rdev->wowlan->four_way_handshake &&
7584 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7585 (rdev->wowlan->rfkill_release &&
7586 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7587 goto nla_put_failure;
7589 if (nl80211_send_wowlan_patterns(msg, rdev))
7590 goto nla_put_failure;
7592 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7593 goto nla_put_failure;
7595 nla_nest_end(msg, nl_wowlan);
7598 genlmsg_end(msg, hdr);
7599 return genlmsg_reply(msg, info);
7606 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7607 struct nlattr *attr,
7608 struct cfg80211_wowlan *trig)
7610 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7611 struct cfg80211_wowlan_tcp *cfg;
7612 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7613 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7615 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7618 if (!rdev->wiphy.wowlan.tcp)
7621 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7622 nla_data(attr), nla_len(attr),
7623 nl80211_wowlan_tcp_policy);
7627 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7628 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7629 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7630 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7631 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7632 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7633 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7634 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7637 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7638 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7641 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7642 rdev->wiphy.wowlan.tcp->data_interval_max ||
7643 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
7646 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7647 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7650 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7651 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7654 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7655 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7657 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7658 tokens_size = tokln - sizeof(*tok);
7660 if (!tok->len || tokens_size % tok->len)
7662 if (!rdev->wiphy.wowlan.tcp->tok)
7664 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7666 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7668 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7670 if (tok->offset + tok->len > data_size)
7674 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7675 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7676 if (!rdev->wiphy.wowlan.tcp->seq)
7678 if (seq->len == 0 || seq->len > 4)
7680 if (seq->len + seq->offset > data_size)
7684 size = sizeof(*cfg);
7686 size += wake_size + wake_mask_size;
7687 size += tokens_size;
7689 cfg = kzalloc(size, GFP_KERNEL);
7692 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7693 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7694 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7696 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7697 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7701 /* allocate a socket and port for it and use it */
7702 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7703 IPPROTO_TCP, &cfg->sock, 1);
7708 if (inet_csk_get_port(cfg->sock->sk, port)) {
7709 sock_release(cfg->sock);
7713 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7719 cfg->src_port = port;
7722 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7723 cfg->payload_len = data_size;
7724 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7725 memcpy((void *)cfg->payload,
7726 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7729 cfg->payload_seq = *seq;
7730 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7731 cfg->wake_len = wake_size;
7732 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7733 memcpy((void *)cfg->wake_data,
7734 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7736 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7737 data_size + wake_size;
7738 memcpy((void *)cfg->wake_mask,
7739 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7742 cfg->tokens_size = tokens_size;
7743 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7751 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7754 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
7755 struct cfg80211_wowlan new_triggers = {};
7756 struct cfg80211_wowlan *ntrig;
7757 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7759 bool prev_enabled = rdev->wowlan;
7761 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7762 !rdev->wiphy.wowlan.tcp)
7765 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7766 cfg80211_rdev_free_wowlan(rdev);
7767 rdev->wowlan = NULL;
7771 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7772 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7773 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7774 nl80211_wowlan_policy);
7778 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7779 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7781 new_triggers.any = true;
7784 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7785 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7787 new_triggers.disconnect = true;
7790 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7791 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7793 new_triggers.magic_pkt = true;
7796 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7799 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7800 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7802 new_triggers.gtk_rekey_failure = true;
7805 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7806 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7808 new_triggers.eap_identity_req = true;
7811 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7812 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7814 new_triggers.four_way_handshake = true;
7817 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7818 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7820 new_triggers.rfkill_release = true;
7823 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7826 int rem, pat_len, mask_len, pkt_offset;
7827 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7829 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7832 if (n_patterns > wowlan->n_patterns)
7835 new_triggers.patterns = kcalloc(n_patterns,
7836 sizeof(new_triggers.patterns[0]),
7838 if (!new_triggers.patterns)
7841 new_triggers.n_patterns = n_patterns;
7844 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7846 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7847 nla_data(pat), nla_len(pat), NULL);
7849 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7850 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7852 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7853 mask_len = DIV_ROUND_UP(pat_len, 8);
7854 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7857 if (pat_len > wowlan->pattern_max_len ||
7858 pat_len < wowlan->pattern_min_len)
7861 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7864 pkt_offset = nla_get_u32(
7865 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7866 if (pkt_offset > wowlan->max_pkt_offset)
7868 new_triggers.patterns[i].pkt_offset = pkt_offset;
7870 new_triggers.patterns[i].mask =
7871 kmalloc(mask_len + pat_len, GFP_KERNEL);
7872 if (!new_triggers.patterns[i].mask) {
7876 new_triggers.patterns[i].pattern =
7877 new_triggers.patterns[i].mask + mask_len;
7878 memcpy(new_triggers.patterns[i].mask,
7879 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7881 new_triggers.patterns[i].pattern_len = pat_len;
7882 memcpy(new_triggers.patterns[i].pattern,
7883 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7889 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7890 err = nl80211_parse_wowlan_tcp(
7891 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7897 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7902 cfg80211_rdev_free_wowlan(rdev);
7903 rdev->wowlan = ntrig;
7906 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
7907 rdev_set_wakeup(rdev, rdev->wowlan);
7911 for (i = 0; i < new_triggers.n_patterns; i++)
7912 kfree(new_triggers.patterns[i].mask);
7913 kfree(new_triggers.patterns);
7914 if (new_triggers.tcp && new_triggers.tcp->sock)
7915 sock_release(new_triggers.tcp->sock);
7916 kfree(new_triggers.tcp);
7921 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7924 struct net_device *dev = info->user_ptr[1];
7925 struct wireless_dev *wdev = dev->ieee80211_ptr;
7926 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7927 struct cfg80211_gtk_rekey_data rekey_data;
7930 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7933 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7934 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7935 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7936 nl80211_rekey_policy);
7940 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7942 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7944 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7947 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7949 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7951 memcpy(rekey_data.replay_ctr,
7952 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7953 NL80211_REPLAY_CTR_LEN);
7956 if (!wdev->current_bss) {
7961 if (!rdev->ops->set_rekey_data) {
7966 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
7972 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7973 struct genl_info *info)
7975 struct net_device *dev = info->user_ptr[1];
7976 struct wireless_dev *wdev = dev->ieee80211_ptr;
7978 if (wdev->iftype != NL80211_IFTYPE_AP &&
7979 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7982 if (wdev->ap_unexpected_nlportid)
7985 wdev->ap_unexpected_nlportid = info->snd_portid;
7989 static int nl80211_probe_client(struct sk_buff *skb,
7990 struct genl_info *info)
7992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7993 struct net_device *dev = info->user_ptr[1];
7994 struct wireless_dev *wdev = dev->ieee80211_ptr;
7995 struct sk_buff *msg;
8001 if (wdev->iftype != NL80211_IFTYPE_AP &&
8002 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8005 if (!info->attrs[NL80211_ATTR_MAC])
8008 if (!rdev->ops->probe_client)
8011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8015 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8016 NL80211_CMD_PROBE_CLIENT);
8023 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8025 err = rdev_probe_client(rdev, dev, addr, &cookie);
8029 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8030 goto nla_put_failure;
8032 genlmsg_end(msg, hdr);
8034 return genlmsg_reply(msg, info);
8043 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8046 struct cfg80211_beacon_registration *reg, *nreg;
8049 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8052 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8056 /* First, check if already registered. */
8057 spin_lock_bh(&rdev->beacon_registrations_lock);
8058 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8059 if (reg->nlportid == info->snd_portid) {
8064 /* Add it to the list */
8065 nreg->nlportid = info->snd_portid;
8066 list_add(&nreg->list, &rdev->beacon_registrations);
8068 spin_unlock_bh(&rdev->beacon_registrations_lock);
8072 spin_unlock_bh(&rdev->beacon_registrations_lock);
8077 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8079 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8080 struct wireless_dev *wdev = info->user_ptr[1];
8083 if (!rdev->ops->start_p2p_device)
8086 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8089 if (wdev->p2p_started)
8092 mutex_lock(&rdev->devlist_mtx);
8093 err = cfg80211_can_add_interface(rdev, wdev->iftype);
8094 mutex_unlock(&rdev->devlist_mtx);
8098 err = rdev_start_p2p_device(rdev, wdev);
8102 wdev->p2p_started = true;
8103 mutex_lock(&rdev->devlist_mtx);
8105 mutex_unlock(&rdev->devlist_mtx);
8110 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8113 struct wireless_dev *wdev = info->user_ptr[1];
8115 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8118 if (!rdev->ops->stop_p2p_device)
8121 if (!wdev->p2p_started)
8124 rdev_stop_p2p_device(rdev, wdev);
8125 wdev->p2p_started = false;
8127 mutex_lock(&rdev->devlist_mtx);
8129 mutex_unlock(&rdev->devlist_mtx);
8131 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
8132 rdev->scan_req->aborted = true;
8133 ___cfg80211_scan_done(rdev, true);
8139 static int nl80211_get_protocol_features(struct sk_buff *skb,
8140 struct genl_info *info)
8143 struct sk_buff *msg;
8145 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8149 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8150 NL80211_CMD_GET_PROTOCOL_FEATURES);
8152 goto nla_put_failure;
8154 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8155 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8156 goto nla_put_failure;
8158 genlmsg_end(msg, hdr);
8159 return genlmsg_reply(msg, info);
8166 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8169 struct cfg80211_update_ft_ies_params ft_params;
8170 struct net_device *dev = info->user_ptr[1];
8172 if (!rdev->ops->update_ft_ies)
8175 if (!info->attrs[NL80211_ATTR_MDID] ||
8176 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8179 memset(&ft_params, 0, sizeof(ft_params));
8180 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8181 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8182 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8184 return rdev_update_ft_ies(rdev, dev, &ft_params);
8187 #define NL80211_FLAG_NEED_WIPHY 0x01
8188 #define NL80211_FLAG_NEED_NETDEV 0x02
8189 #define NL80211_FLAG_NEED_RTNL 0x04
8190 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8191 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8192 NL80211_FLAG_CHECK_NETDEV_UP)
8193 #define NL80211_FLAG_NEED_WDEV 0x10
8194 /* If a netdev is associated, it must be UP, P2P must be started */
8195 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8196 NL80211_FLAG_CHECK_NETDEV_UP)
8198 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8199 struct genl_info *info)
8201 struct cfg80211_registered_device *rdev;
8202 struct wireless_dev *wdev;
8203 struct net_device *dev;
8204 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8209 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
8210 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
8214 return PTR_ERR(rdev);
8216 info->user_ptr[0] = rdev;
8217 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8218 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8219 mutex_lock(&cfg80211_mutex);
8220 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8223 mutex_unlock(&cfg80211_mutex);
8226 return PTR_ERR(wdev);
8230 rdev = wiphy_to_dev(wdev->wiphy);
8232 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8234 mutex_unlock(&cfg80211_mutex);
8240 info->user_ptr[1] = dev;
8242 info->user_ptr[1] = wdev;
8246 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8247 !netif_running(dev)) {
8248 mutex_unlock(&cfg80211_mutex);
8255 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8256 if (!wdev->p2p_started) {
8257 mutex_unlock(&cfg80211_mutex);
8264 cfg80211_lock_rdev(rdev);
8266 mutex_unlock(&cfg80211_mutex);
8268 info->user_ptr[0] = rdev;
8274 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8275 struct genl_info *info)
8277 if (info->user_ptr[0])
8278 cfg80211_unlock_rdev(info->user_ptr[0]);
8279 if (info->user_ptr[1]) {
8280 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8281 struct wireless_dev *wdev = info->user_ptr[1];
8284 dev_put(wdev->netdev);
8286 dev_put(info->user_ptr[1]);
8289 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8293 static struct genl_ops nl80211_ops[] = {
8295 .cmd = NL80211_CMD_GET_WIPHY,
8296 .doit = nl80211_get_wiphy,
8297 .dumpit = nl80211_dump_wiphy,
8298 .policy = nl80211_policy,
8299 /* can be retrieved by unprivileged users */
8300 .internal_flags = NL80211_FLAG_NEED_WIPHY,
8303 .cmd = NL80211_CMD_SET_WIPHY,
8304 .doit = nl80211_set_wiphy,
8305 .policy = nl80211_policy,
8306 .flags = GENL_ADMIN_PERM,
8307 .internal_flags = NL80211_FLAG_NEED_RTNL,
8310 .cmd = NL80211_CMD_GET_INTERFACE,
8311 .doit = nl80211_get_interface,
8312 .dumpit = nl80211_dump_interface,
8313 .policy = nl80211_policy,
8314 /* can be retrieved by unprivileged users */
8315 .internal_flags = NL80211_FLAG_NEED_WDEV,
8318 .cmd = NL80211_CMD_SET_INTERFACE,
8319 .doit = nl80211_set_interface,
8320 .policy = nl80211_policy,
8321 .flags = GENL_ADMIN_PERM,
8322 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8323 NL80211_FLAG_NEED_RTNL,
8326 .cmd = NL80211_CMD_NEW_INTERFACE,
8327 .doit = nl80211_new_interface,
8328 .policy = nl80211_policy,
8329 .flags = GENL_ADMIN_PERM,
8330 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8331 NL80211_FLAG_NEED_RTNL,
8334 .cmd = NL80211_CMD_DEL_INTERFACE,
8335 .doit = nl80211_del_interface,
8336 .policy = nl80211_policy,
8337 .flags = GENL_ADMIN_PERM,
8338 .internal_flags = NL80211_FLAG_NEED_WDEV |
8339 NL80211_FLAG_NEED_RTNL,
8342 .cmd = NL80211_CMD_GET_KEY,
8343 .doit = nl80211_get_key,
8344 .policy = nl80211_policy,
8345 .flags = GENL_ADMIN_PERM,
8346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8347 NL80211_FLAG_NEED_RTNL,
8350 .cmd = NL80211_CMD_SET_KEY,
8351 .doit = nl80211_set_key,
8352 .policy = nl80211_policy,
8353 .flags = GENL_ADMIN_PERM,
8354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8355 NL80211_FLAG_NEED_RTNL,
8358 .cmd = NL80211_CMD_NEW_KEY,
8359 .doit = nl80211_new_key,
8360 .policy = nl80211_policy,
8361 .flags = GENL_ADMIN_PERM,
8362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8363 NL80211_FLAG_NEED_RTNL,
8366 .cmd = NL80211_CMD_DEL_KEY,
8367 .doit = nl80211_del_key,
8368 .policy = nl80211_policy,
8369 .flags = GENL_ADMIN_PERM,
8370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8371 NL80211_FLAG_NEED_RTNL,
8374 .cmd = NL80211_CMD_SET_BEACON,
8375 .policy = nl80211_policy,
8376 .flags = GENL_ADMIN_PERM,
8377 .doit = nl80211_set_beacon,
8378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8379 NL80211_FLAG_NEED_RTNL,
8382 .cmd = NL80211_CMD_START_AP,
8383 .policy = nl80211_policy,
8384 .flags = GENL_ADMIN_PERM,
8385 .doit = nl80211_start_ap,
8386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8387 NL80211_FLAG_NEED_RTNL,
8390 .cmd = NL80211_CMD_STOP_AP,
8391 .policy = nl80211_policy,
8392 .flags = GENL_ADMIN_PERM,
8393 .doit = nl80211_stop_ap,
8394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8395 NL80211_FLAG_NEED_RTNL,
8398 .cmd = NL80211_CMD_GET_STATION,
8399 .doit = nl80211_get_station,
8400 .dumpit = nl80211_dump_station,
8401 .policy = nl80211_policy,
8402 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8403 NL80211_FLAG_NEED_RTNL,
8406 .cmd = NL80211_CMD_SET_STATION,
8407 .doit = nl80211_set_station,
8408 .policy = nl80211_policy,
8409 .flags = GENL_ADMIN_PERM,
8410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8411 NL80211_FLAG_NEED_RTNL,
8414 .cmd = NL80211_CMD_NEW_STATION,
8415 .doit = nl80211_new_station,
8416 .policy = nl80211_policy,
8417 .flags = GENL_ADMIN_PERM,
8418 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8419 NL80211_FLAG_NEED_RTNL,
8422 .cmd = NL80211_CMD_DEL_STATION,
8423 .doit = nl80211_del_station,
8424 .policy = nl80211_policy,
8425 .flags = GENL_ADMIN_PERM,
8426 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8427 NL80211_FLAG_NEED_RTNL,
8430 .cmd = NL80211_CMD_GET_MPATH,
8431 .doit = nl80211_get_mpath,
8432 .dumpit = nl80211_dump_mpath,
8433 .policy = nl80211_policy,
8434 .flags = GENL_ADMIN_PERM,
8435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8436 NL80211_FLAG_NEED_RTNL,
8439 .cmd = NL80211_CMD_SET_MPATH,
8440 .doit = nl80211_set_mpath,
8441 .policy = nl80211_policy,
8442 .flags = GENL_ADMIN_PERM,
8443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8444 NL80211_FLAG_NEED_RTNL,
8447 .cmd = NL80211_CMD_NEW_MPATH,
8448 .doit = nl80211_new_mpath,
8449 .policy = nl80211_policy,
8450 .flags = GENL_ADMIN_PERM,
8451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8452 NL80211_FLAG_NEED_RTNL,
8455 .cmd = NL80211_CMD_DEL_MPATH,
8456 .doit = nl80211_del_mpath,
8457 .policy = nl80211_policy,
8458 .flags = GENL_ADMIN_PERM,
8459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8460 NL80211_FLAG_NEED_RTNL,
8463 .cmd = NL80211_CMD_SET_BSS,
8464 .doit = nl80211_set_bss,
8465 .policy = nl80211_policy,
8466 .flags = GENL_ADMIN_PERM,
8467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8468 NL80211_FLAG_NEED_RTNL,
8471 .cmd = NL80211_CMD_GET_REG,
8472 .doit = nl80211_get_reg,
8473 .policy = nl80211_policy,
8474 /* can be retrieved by unprivileged users */
8477 .cmd = NL80211_CMD_SET_REG,
8478 .doit = nl80211_set_reg,
8479 .policy = nl80211_policy,
8480 .flags = GENL_ADMIN_PERM,
8483 .cmd = NL80211_CMD_REQ_SET_REG,
8484 .doit = nl80211_req_set_reg,
8485 .policy = nl80211_policy,
8486 .flags = GENL_ADMIN_PERM,
8489 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8490 .doit = nl80211_get_mesh_config,
8491 .policy = nl80211_policy,
8492 /* can be retrieved by unprivileged users */
8493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8494 NL80211_FLAG_NEED_RTNL,
8497 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8498 .doit = nl80211_update_mesh_config,
8499 .policy = nl80211_policy,
8500 .flags = GENL_ADMIN_PERM,
8501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8502 NL80211_FLAG_NEED_RTNL,
8505 .cmd = NL80211_CMD_TRIGGER_SCAN,
8506 .doit = nl80211_trigger_scan,
8507 .policy = nl80211_policy,
8508 .flags = GENL_ADMIN_PERM,
8509 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8510 NL80211_FLAG_NEED_RTNL,
8513 .cmd = NL80211_CMD_GET_SCAN,
8514 .policy = nl80211_policy,
8515 .dumpit = nl80211_dump_scan,
8518 .cmd = NL80211_CMD_START_SCHED_SCAN,
8519 .doit = nl80211_start_sched_scan,
8520 .policy = nl80211_policy,
8521 .flags = GENL_ADMIN_PERM,
8522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8523 NL80211_FLAG_NEED_RTNL,
8526 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8527 .doit = nl80211_stop_sched_scan,
8528 .policy = nl80211_policy,
8529 .flags = GENL_ADMIN_PERM,
8530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8531 NL80211_FLAG_NEED_RTNL,
8534 .cmd = NL80211_CMD_AUTHENTICATE,
8535 .doit = nl80211_authenticate,
8536 .policy = nl80211_policy,
8537 .flags = GENL_ADMIN_PERM,
8538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8539 NL80211_FLAG_NEED_RTNL,
8542 .cmd = NL80211_CMD_ASSOCIATE,
8543 .doit = nl80211_associate,
8544 .policy = nl80211_policy,
8545 .flags = GENL_ADMIN_PERM,
8546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8547 NL80211_FLAG_NEED_RTNL,
8550 .cmd = NL80211_CMD_DEAUTHENTICATE,
8551 .doit = nl80211_deauthenticate,
8552 .policy = nl80211_policy,
8553 .flags = GENL_ADMIN_PERM,
8554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8555 NL80211_FLAG_NEED_RTNL,
8558 .cmd = NL80211_CMD_DISASSOCIATE,
8559 .doit = nl80211_disassociate,
8560 .policy = nl80211_policy,
8561 .flags = GENL_ADMIN_PERM,
8562 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8563 NL80211_FLAG_NEED_RTNL,
8566 .cmd = NL80211_CMD_JOIN_IBSS,
8567 .doit = nl80211_join_ibss,
8568 .policy = nl80211_policy,
8569 .flags = GENL_ADMIN_PERM,
8570 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8571 NL80211_FLAG_NEED_RTNL,
8574 .cmd = NL80211_CMD_LEAVE_IBSS,
8575 .doit = nl80211_leave_ibss,
8576 .policy = nl80211_policy,
8577 .flags = GENL_ADMIN_PERM,
8578 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8579 NL80211_FLAG_NEED_RTNL,
8581 #ifdef CONFIG_NL80211_TESTMODE
8583 .cmd = NL80211_CMD_TESTMODE,
8584 .doit = nl80211_testmode_do,
8585 .dumpit = nl80211_testmode_dump,
8586 .policy = nl80211_policy,
8587 .flags = GENL_ADMIN_PERM,
8588 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8589 NL80211_FLAG_NEED_RTNL,
8593 .cmd = NL80211_CMD_CONNECT,
8594 .doit = nl80211_connect,
8595 .policy = nl80211_policy,
8596 .flags = GENL_ADMIN_PERM,
8597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8598 NL80211_FLAG_NEED_RTNL,
8601 .cmd = NL80211_CMD_DISCONNECT,
8602 .doit = nl80211_disconnect,
8603 .policy = nl80211_policy,
8604 .flags = GENL_ADMIN_PERM,
8605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8606 NL80211_FLAG_NEED_RTNL,
8609 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8610 .doit = nl80211_wiphy_netns,
8611 .policy = nl80211_policy,
8612 .flags = GENL_ADMIN_PERM,
8613 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8614 NL80211_FLAG_NEED_RTNL,
8617 .cmd = NL80211_CMD_GET_SURVEY,
8618 .policy = nl80211_policy,
8619 .dumpit = nl80211_dump_survey,
8622 .cmd = NL80211_CMD_SET_PMKSA,
8623 .doit = nl80211_setdel_pmksa,
8624 .policy = nl80211_policy,
8625 .flags = GENL_ADMIN_PERM,
8626 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8627 NL80211_FLAG_NEED_RTNL,
8630 .cmd = NL80211_CMD_DEL_PMKSA,
8631 .doit = nl80211_setdel_pmksa,
8632 .policy = nl80211_policy,
8633 .flags = GENL_ADMIN_PERM,
8634 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8635 NL80211_FLAG_NEED_RTNL,
8638 .cmd = NL80211_CMD_FLUSH_PMKSA,
8639 .doit = nl80211_flush_pmksa,
8640 .policy = nl80211_policy,
8641 .flags = GENL_ADMIN_PERM,
8642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8643 NL80211_FLAG_NEED_RTNL,
8646 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8647 .doit = nl80211_remain_on_channel,
8648 .policy = nl80211_policy,
8649 .flags = GENL_ADMIN_PERM,
8650 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8651 NL80211_FLAG_NEED_RTNL,
8654 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8655 .doit = nl80211_cancel_remain_on_channel,
8656 .policy = nl80211_policy,
8657 .flags = GENL_ADMIN_PERM,
8658 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8659 NL80211_FLAG_NEED_RTNL,
8662 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8663 .doit = nl80211_set_tx_bitrate_mask,
8664 .policy = nl80211_policy,
8665 .flags = GENL_ADMIN_PERM,
8666 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8667 NL80211_FLAG_NEED_RTNL,
8670 .cmd = NL80211_CMD_REGISTER_FRAME,
8671 .doit = nl80211_register_mgmt,
8672 .policy = nl80211_policy,
8673 .flags = GENL_ADMIN_PERM,
8674 .internal_flags = NL80211_FLAG_NEED_WDEV |
8675 NL80211_FLAG_NEED_RTNL,
8678 .cmd = NL80211_CMD_FRAME,
8679 .doit = nl80211_tx_mgmt,
8680 .policy = nl80211_policy,
8681 .flags = GENL_ADMIN_PERM,
8682 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8683 NL80211_FLAG_NEED_RTNL,
8686 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8687 .doit = nl80211_tx_mgmt_cancel_wait,
8688 .policy = nl80211_policy,
8689 .flags = GENL_ADMIN_PERM,
8690 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8691 NL80211_FLAG_NEED_RTNL,
8694 .cmd = NL80211_CMD_SET_POWER_SAVE,
8695 .doit = nl80211_set_power_save,
8696 .policy = nl80211_policy,
8697 .flags = GENL_ADMIN_PERM,
8698 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8699 NL80211_FLAG_NEED_RTNL,
8702 .cmd = NL80211_CMD_GET_POWER_SAVE,
8703 .doit = nl80211_get_power_save,
8704 .policy = nl80211_policy,
8705 /* can be retrieved by unprivileged users */
8706 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8707 NL80211_FLAG_NEED_RTNL,
8710 .cmd = NL80211_CMD_SET_CQM,
8711 .doit = nl80211_set_cqm,
8712 .policy = nl80211_policy,
8713 .flags = GENL_ADMIN_PERM,
8714 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8715 NL80211_FLAG_NEED_RTNL,
8718 .cmd = NL80211_CMD_SET_CHANNEL,
8719 .doit = nl80211_set_channel,
8720 .policy = nl80211_policy,
8721 .flags = GENL_ADMIN_PERM,
8722 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8723 NL80211_FLAG_NEED_RTNL,
8726 .cmd = NL80211_CMD_SET_WDS_PEER,
8727 .doit = nl80211_set_wds_peer,
8728 .policy = nl80211_policy,
8729 .flags = GENL_ADMIN_PERM,
8730 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8731 NL80211_FLAG_NEED_RTNL,
8734 .cmd = NL80211_CMD_JOIN_MESH,
8735 .doit = nl80211_join_mesh,
8736 .policy = nl80211_policy,
8737 .flags = GENL_ADMIN_PERM,
8738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8739 NL80211_FLAG_NEED_RTNL,
8742 .cmd = NL80211_CMD_LEAVE_MESH,
8743 .doit = nl80211_leave_mesh,
8744 .policy = nl80211_policy,
8745 .flags = GENL_ADMIN_PERM,
8746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8747 NL80211_FLAG_NEED_RTNL,
8751 .cmd = NL80211_CMD_GET_WOWLAN,
8752 .doit = nl80211_get_wowlan,
8753 .policy = nl80211_policy,
8754 /* can be retrieved by unprivileged users */
8755 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8756 NL80211_FLAG_NEED_RTNL,
8759 .cmd = NL80211_CMD_SET_WOWLAN,
8760 .doit = nl80211_set_wowlan,
8761 .policy = nl80211_policy,
8762 .flags = GENL_ADMIN_PERM,
8763 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8764 NL80211_FLAG_NEED_RTNL,
8768 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8769 .doit = nl80211_set_rekey_data,
8770 .policy = nl80211_policy,
8771 .flags = GENL_ADMIN_PERM,
8772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8773 NL80211_FLAG_NEED_RTNL,
8776 .cmd = NL80211_CMD_TDLS_MGMT,
8777 .doit = nl80211_tdls_mgmt,
8778 .policy = nl80211_policy,
8779 .flags = GENL_ADMIN_PERM,
8780 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8781 NL80211_FLAG_NEED_RTNL,
8784 .cmd = NL80211_CMD_TDLS_OPER,
8785 .doit = nl80211_tdls_oper,
8786 .policy = nl80211_policy,
8787 .flags = GENL_ADMIN_PERM,
8788 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8789 NL80211_FLAG_NEED_RTNL,
8792 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8793 .doit = nl80211_register_unexpected_frame,
8794 .policy = nl80211_policy,
8795 .flags = GENL_ADMIN_PERM,
8796 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8797 NL80211_FLAG_NEED_RTNL,
8800 .cmd = NL80211_CMD_PROBE_CLIENT,
8801 .doit = nl80211_probe_client,
8802 .policy = nl80211_policy,
8803 .flags = GENL_ADMIN_PERM,
8804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8805 NL80211_FLAG_NEED_RTNL,
8808 .cmd = NL80211_CMD_REGISTER_BEACONS,
8809 .doit = nl80211_register_beacons,
8810 .policy = nl80211_policy,
8811 .flags = GENL_ADMIN_PERM,
8812 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8813 NL80211_FLAG_NEED_RTNL,
8816 .cmd = NL80211_CMD_SET_NOACK_MAP,
8817 .doit = nl80211_set_noack_map,
8818 .policy = nl80211_policy,
8819 .flags = GENL_ADMIN_PERM,
8820 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8821 NL80211_FLAG_NEED_RTNL,
8824 .cmd = NL80211_CMD_START_P2P_DEVICE,
8825 .doit = nl80211_start_p2p_device,
8826 .policy = nl80211_policy,
8827 .flags = GENL_ADMIN_PERM,
8828 .internal_flags = NL80211_FLAG_NEED_WDEV |
8829 NL80211_FLAG_NEED_RTNL,
8832 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8833 .doit = nl80211_stop_p2p_device,
8834 .policy = nl80211_policy,
8835 .flags = GENL_ADMIN_PERM,
8836 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8837 NL80211_FLAG_NEED_RTNL,
8840 .cmd = NL80211_CMD_SET_MCAST_RATE,
8841 .doit = nl80211_set_mcast_rate,
8842 .policy = nl80211_policy,
8843 .flags = GENL_ADMIN_PERM,
8844 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8845 NL80211_FLAG_NEED_RTNL,
8848 .cmd = NL80211_CMD_SET_MAC_ACL,
8849 .doit = nl80211_set_mac_acl,
8850 .policy = nl80211_policy,
8851 .flags = GENL_ADMIN_PERM,
8852 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8853 NL80211_FLAG_NEED_RTNL,
8856 .cmd = NL80211_CMD_RADAR_DETECT,
8857 .doit = nl80211_start_radar_detection,
8858 .policy = nl80211_policy,
8859 .flags = GENL_ADMIN_PERM,
8860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8861 NL80211_FLAG_NEED_RTNL,
8864 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8865 .doit = nl80211_get_protocol_features,
8866 .policy = nl80211_policy,
8869 .cmd = NL80211_CMD_UPDATE_FT_IES,
8870 .doit = nl80211_update_ft_ies,
8871 .policy = nl80211_policy,
8872 .flags = GENL_ADMIN_PERM,
8873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8874 NL80211_FLAG_NEED_RTNL,
8878 static struct genl_multicast_group nl80211_mlme_mcgrp = {
8882 /* multicast groups */
8883 static struct genl_multicast_group nl80211_config_mcgrp = {
8886 static struct genl_multicast_group nl80211_scan_mcgrp = {
8889 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8890 .name = "regulatory",
8893 /* notification functions */
8895 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8897 struct sk_buff *msg;
8899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8903 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8904 false, NULL, NULL, NULL) < 0) {
8909 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8910 nl80211_config_mcgrp.id, GFP_KERNEL);
8913 static int nl80211_add_scan_req(struct sk_buff *msg,
8914 struct cfg80211_registered_device *rdev)
8916 struct cfg80211_scan_request *req = rdev->scan_req;
8917 struct nlattr *nest;
8920 ASSERT_RDEV_LOCK(rdev);
8925 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8927 goto nla_put_failure;
8928 for (i = 0; i < req->n_ssids; i++) {
8929 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8930 goto nla_put_failure;
8932 nla_nest_end(msg, nest);
8934 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8936 goto nla_put_failure;
8937 for (i = 0; i < req->n_channels; i++) {
8938 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8939 goto nla_put_failure;
8941 nla_nest_end(msg, nest);
8944 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8945 goto nla_put_failure;
8948 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8955 static int nl80211_send_scan_msg(struct sk_buff *msg,
8956 struct cfg80211_registered_device *rdev,
8957 struct wireless_dev *wdev,
8958 u32 portid, u32 seq, int flags,
8963 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8967 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8968 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8969 wdev->netdev->ifindex)) ||
8970 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
8971 goto nla_put_failure;
8973 /* ignore errors and send incomplete event anyway */
8974 nl80211_add_scan_req(msg, rdev);
8976 return genlmsg_end(msg, hdr);
8979 genlmsg_cancel(msg, hdr);
8984 nl80211_send_sched_scan_msg(struct sk_buff *msg,
8985 struct cfg80211_registered_device *rdev,
8986 struct net_device *netdev,
8987 u32 portid, u32 seq, int flags, u32 cmd)
8991 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8995 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8996 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8997 goto nla_put_failure;
8999 return genlmsg_end(msg, hdr);
9002 genlmsg_cancel(msg, hdr);
9006 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
9007 struct wireless_dev *wdev)
9009 struct sk_buff *msg;
9011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9015 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
9016 NL80211_CMD_TRIGGER_SCAN) < 0) {
9021 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9022 nl80211_scan_mcgrp.id, GFP_KERNEL);
9025 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
9026 struct wireless_dev *wdev)
9028 struct sk_buff *msg;
9030 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9034 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
9035 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
9040 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9041 nl80211_scan_mcgrp.id, GFP_KERNEL);
9044 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
9045 struct wireless_dev *wdev)
9047 struct sk_buff *msg;
9049 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9053 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
9054 NL80211_CMD_SCAN_ABORTED) < 0) {
9059 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9060 nl80211_scan_mcgrp.id, GFP_KERNEL);
9063 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9064 struct net_device *netdev)
9066 struct sk_buff *msg;
9068 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9072 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9073 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9078 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9079 nl80211_scan_mcgrp.id, GFP_KERNEL);
9082 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9083 struct net_device *netdev, u32 cmd)
9085 struct sk_buff *msg;
9087 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9091 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9096 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9097 nl80211_scan_mcgrp.id, GFP_KERNEL);
9101 * This can happen on global regulatory changes or device specific settings
9102 * based on custom world regulatory domains.
9104 void nl80211_send_reg_change_event(struct regulatory_request *request)
9106 struct sk_buff *msg;
9109 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9113 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9119 /* Userspace can always count this one always being set */
9120 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9121 goto nla_put_failure;
9123 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9124 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9125 NL80211_REGDOM_TYPE_WORLD))
9126 goto nla_put_failure;
9127 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9128 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9129 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9130 goto nla_put_failure;
9131 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9132 request->intersect) {
9133 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9134 NL80211_REGDOM_TYPE_INTERSECTION))
9135 goto nla_put_failure;
9137 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9138 NL80211_REGDOM_TYPE_COUNTRY) ||
9139 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9141 goto nla_put_failure;
9144 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
9145 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9146 goto nla_put_failure;
9148 genlmsg_end(msg, hdr);
9151 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9158 genlmsg_cancel(msg, hdr);
9162 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9163 struct net_device *netdev,
9164 const u8 *buf, size_t len,
9165 enum nl80211_commands cmd, gfp_t gfp)
9167 struct sk_buff *msg;
9170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9174 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9180 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9181 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9182 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9183 goto nla_put_failure;
9185 genlmsg_end(msg, hdr);
9187 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9188 nl80211_mlme_mcgrp.id, gfp);
9192 genlmsg_cancel(msg, hdr);
9196 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
9197 struct net_device *netdev, const u8 *buf,
9198 size_t len, gfp_t gfp)
9200 nl80211_send_mlme_event(rdev, netdev, buf, len,
9201 NL80211_CMD_AUTHENTICATE, gfp);
9204 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9205 struct net_device *netdev, const u8 *buf,
9206 size_t len, gfp_t gfp)
9208 nl80211_send_mlme_event(rdev, netdev, buf, len,
9209 NL80211_CMD_ASSOCIATE, gfp);
9212 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
9213 struct net_device *netdev, const u8 *buf,
9214 size_t len, gfp_t gfp)
9216 nl80211_send_mlme_event(rdev, netdev, buf, len,
9217 NL80211_CMD_DEAUTHENTICATE, gfp);
9220 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9221 struct net_device *netdev, const u8 *buf,
9222 size_t len, gfp_t gfp)
9224 nl80211_send_mlme_event(rdev, netdev, buf, len,
9225 NL80211_CMD_DISASSOCIATE, gfp);
9228 void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9231 struct wireless_dev *wdev = dev->ieee80211_ptr;
9232 struct wiphy *wiphy = wdev->wiphy;
9233 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9235 trace_cfg80211_send_unprot_deauth(dev);
9236 nl80211_send_mlme_event(rdev, dev, buf, len,
9237 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
9239 EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9241 void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9244 struct wireless_dev *wdev = dev->ieee80211_ptr;
9245 struct wiphy *wiphy = wdev->wiphy;
9246 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9248 trace_cfg80211_send_unprot_disassoc(dev);
9249 nl80211_send_mlme_event(rdev, dev, buf, len,
9250 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9252 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
9254 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9255 struct net_device *netdev, int cmd,
9256 const u8 *addr, gfp_t gfp)
9258 struct sk_buff *msg;
9261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9265 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9272 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9273 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9274 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9275 goto nla_put_failure;
9277 genlmsg_end(msg, hdr);
9279 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9280 nl80211_mlme_mcgrp.id, gfp);
9284 genlmsg_cancel(msg, hdr);
9288 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
9289 struct net_device *netdev, const u8 *addr,
9292 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
9296 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
9297 struct net_device *netdev, const u8 *addr,
9300 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9304 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9305 struct net_device *netdev, const u8 *bssid,
9306 const u8 *req_ie, size_t req_ie_len,
9307 const u8 *resp_ie, size_t resp_ie_len,
9308 u16 status, gfp_t gfp)
9310 struct sk_buff *msg;
9313 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9317 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9323 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9324 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9325 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9326 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9328 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9330 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9331 goto nla_put_failure;
9333 genlmsg_end(msg, hdr);
9335 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9336 nl80211_mlme_mcgrp.id, gfp);
9340 genlmsg_cancel(msg, hdr);
9345 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9346 struct net_device *netdev, const u8 *bssid,
9347 const u8 *req_ie, size_t req_ie_len,
9348 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9350 struct sk_buff *msg;
9353 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9357 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9363 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9364 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9367 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9369 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9370 goto nla_put_failure;
9372 genlmsg_end(msg, hdr);
9374 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9375 nl80211_mlme_mcgrp.id, gfp);
9379 genlmsg_cancel(msg, hdr);
9384 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9385 struct net_device *netdev, u16 reason,
9386 const u8 *ie, size_t ie_len, bool from_ap)
9388 struct sk_buff *msg;
9391 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9395 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9401 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9402 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9403 (from_ap && reason &&
9404 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9406 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9407 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9408 goto nla_put_failure;
9410 genlmsg_end(msg, hdr);
9412 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9413 nl80211_mlme_mcgrp.id, GFP_KERNEL);
9417 genlmsg_cancel(msg, hdr);
9422 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9423 struct net_device *netdev, const u8 *bssid,
9426 struct sk_buff *msg;
9429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9433 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9439 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9440 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9441 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9442 goto nla_put_failure;
9444 genlmsg_end(msg, hdr);
9446 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9447 nl80211_mlme_mcgrp.id, gfp);
9451 genlmsg_cancel(msg, hdr);
9455 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9456 const u8* ie, u8 ie_len, gfp_t gfp)
9458 struct wireless_dev *wdev = dev->ieee80211_ptr;
9459 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9460 struct sk_buff *msg;
9463 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9466 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9472 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9480 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9482 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9483 goto nla_put_failure;
9485 genlmsg_end(msg, hdr);
9487 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9488 nl80211_mlme_mcgrp.id, gfp);
9492 genlmsg_cancel(msg, hdr);
9495 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
9497 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9498 struct net_device *netdev, const u8 *addr,
9499 enum nl80211_key_type key_type, int key_id,
9500 const u8 *tsc, gfp_t gfp)
9502 struct sk_buff *msg;
9505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9517 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9518 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9520 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9521 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9522 goto nla_put_failure;
9524 genlmsg_end(msg, hdr);
9526 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9527 nl80211_mlme_mcgrp.id, gfp);
9531 genlmsg_cancel(msg, hdr);
9535 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9536 struct ieee80211_channel *channel_before,
9537 struct ieee80211_channel *channel_after)
9539 struct sk_buff *msg;
9541 struct nlattr *nl_freq;
9543 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
9547 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9554 * Since we are applying the beacon hint to a wiphy we know its
9555 * wiphy_idx is valid
9557 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9558 goto nla_put_failure;
9561 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9563 goto nla_put_failure;
9564 if (nl80211_msg_put_channel(msg, channel_before, false))
9565 goto nla_put_failure;
9566 nla_nest_end(msg, nl_freq);
9569 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9571 goto nla_put_failure;
9572 if (nl80211_msg_put_channel(msg, channel_after, false))
9573 goto nla_put_failure;
9574 nla_nest_end(msg, nl_freq);
9576 genlmsg_end(msg, hdr);
9579 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9586 genlmsg_cancel(msg, hdr);
9590 static void nl80211_send_remain_on_chan_event(
9591 int cmd, struct cfg80211_registered_device *rdev,
9592 struct wireless_dev *wdev, u64 cookie,
9593 struct ieee80211_channel *chan,
9594 unsigned int duration, gfp_t gfp)
9596 struct sk_buff *msg;
9599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9603 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9609 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9610 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9611 wdev->netdev->ifindex)) ||
9612 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
9613 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
9614 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9615 NL80211_CHAN_NO_HT) ||
9616 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9617 goto nla_put_failure;
9619 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9620 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9621 goto nla_put_failure;
9623 genlmsg_end(msg, hdr);
9625 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9626 nl80211_mlme_mcgrp.id, gfp);
9630 genlmsg_cancel(msg, hdr);
9634 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9635 struct ieee80211_channel *chan,
9636 unsigned int duration, gfp_t gfp)
9638 struct wiphy *wiphy = wdev->wiphy;
9639 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9641 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
9642 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
9643 rdev, wdev, cookie, chan,
9646 EXPORT_SYMBOL(cfg80211_ready_on_channel);
9648 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9649 struct ieee80211_channel *chan,
9652 struct wiphy *wiphy = wdev->wiphy;
9653 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9655 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
9656 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9657 rdev, wdev, cookie, chan, 0, gfp);
9659 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
9661 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9662 struct station_info *sinfo, gfp_t gfp)
9664 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9665 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9666 struct sk_buff *msg;
9668 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9674 if (nl80211_send_station(msg, 0, 0, 0,
9675 rdev, dev, mac_addr, sinfo) < 0) {
9680 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9681 nl80211_mlme_mcgrp.id, gfp);
9683 EXPORT_SYMBOL(cfg80211_new_sta);
9685 void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
9687 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9688 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9689 struct sk_buff *msg;
9692 trace_cfg80211_del_sta(dev, mac_addr);
9694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9698 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9704 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9705 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9706 goto nla_put_failure;
9708 genlmsg_end(msg, hdr);
9710 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9711 nl80211_mlme_mcgrp.id, gfp);
9715 genlmsg_cancel(msg, hdr);
9718 EXPORT_SYMBOL(cfg80211_del_sta);
9720 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9721 enum nl80211_connect_failed_reason reason,
9724 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9725 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9726 struct sk_buff *msg;
9729 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9733 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9739 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9740 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9741 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9742 goto nla_put_failure;
9744 genlmsg_end(msg, hdr);
9746 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9747 nl80211_mlme_mcgrp.id, gfp);
9751 genlmsg_cancel(msg, hdr);
9754 EXPORT_SYMBOL(cfg80211_conn_failed);
9756 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9757 const u8 *addr, gfp_t gfp)
9759 struct wireless_dev *wdev = dev->ieee80211_ptr;
9760 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9761 struct sk_buff *msg;
9764 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
9769 msg = nlmsg_new(100, gfp);
9773 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9779 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9780 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9781 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9782 goto nla_put_failure;
9784 err = genlmsg_end(msg, hdr);
9790 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9794 genlmsg_cancel(msg, hdr);
9799 bool cfg80211_rx_spurious_frame(struct net_device *dev,
9800 const u8 *addr, gfp_t gfp)
9802 struct wireless_dev *wdev = dev->ieee80211_ptr;
9805 trace_cfg80211_rx_spurious_frame(dev, addr);
9807 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9808 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9809 trace_cfg80211_return_bool(false);
9812 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9814 trace_cfg80211_return_bool(ret);
9817 EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9819 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9820 const u8 *addr, gfp_t gfp)
9822 struct wireless_dev *wdev = dev->ieee80211_ptr;
9825 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9827 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9828 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9829 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9830 trace_cfg80211_return_bool(false);
9833 ret = __nl80211_unexpected_frame(dev,
9834 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9836 trace_cfg80211_return_bool(ret);
9839 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
9841 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
9842 struct wireless_dev *wdev, u32 nlportid,
9843 int freq, int sig_dbm,
9844 const u8 *buf, size_t len, gfp_t gfp)
9846 struct net_device *netdev = wdev->netdev;
9847 struct sk_buff *msg;
9850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9860 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9861 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9862 netdev->ifindex)) ||
9863 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9865 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9866 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9867 goto nla_put_failure;
9869 genlmsg_end(msg, hdr);
9871 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9874 genlmsg_cancel(msg, hdr);
9879 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9880 const u8 *buf, size_t len, bool ack, gfp_t gfp)
9882 struct wiphy *wiphy = wdev->wiphy;
9883 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9884 struct net_device *netdev = wdev->netdev;
9885 struct sk_buff *msg;
9888 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9890 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9894 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
9900 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9901 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9902 netdev->ifindex)) ||
9903 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9904 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9905 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9906 goto nla_put_failure;
9908 genlmsg_end(msg, hdr);
9910 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9914 genlmsg_cancel(msg, hdr);
9917 EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
9919 void cfg80211_cqm_rssi_notify(struct net_device *dev,
9920 enum nl80211_cqm_rssi_threshold_event rssi_event,
9923 struct wireless_dev *wdev = dev->ieee80211_ptr;
9924 struct wiphy *wiphy = wdev->wiphy;
9925 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9926 struct sk_buff *msg;
9927 struct nlattr *pinfoattr;
9930 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
9932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9936 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9942 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9943 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
9944 goto nla_put_failure;
9946 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9948 goto nla_put_failure;
9950 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9952 goto nla_put_failure;
9954 nla_nest_end(msg, pinfoattr);
9956 genlmsg_end(msg, hdr);
9958 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9959 nl80211_mlme_mcgrp.id, gfp);
9963 genlmsg_cancel(msg, hdr);
9966 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
9968 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9969 struct net_device *netdev, const u8 *bssid,
9970 const u8 *replay_ctr, gfp_t gfp)
9972 struct sk_buff *msg;
9973 struct nlattr *rekey_attr;
9976 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9980 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9986 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9987 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9988 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9989 goto nla_put_failure;
9991 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9993 goto nla_put_failure;
9995 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9996 NL80211_REPLAY_CTR_LEN, replay_ctr))
9997 goto nla_put_failure;
9999 nla_nest_end(msg, rekey_attr);
10001 genlmsg_end(msg, hdr);
10003 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10004 nl80211_mlme_mcgrp.id, gfp);
10008 genlmsg_cancel(msg, hdr);
10012 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10013 const u8 *replay_ctr, gfp_t gfp)
10015 struct wireless_dev *wdev = dev->ieee80211_ptr;
10016 struct wiphy *wiphy = wdev->wiphy;
10017 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10019 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10020 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10022 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10025 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10026 struct net_device *netdev, int index,
10027 const u8 *bssid, bool preauth, gfp_t gfp)
10029 struct sk_buff *msg;
10030 struct nlattr *attr;
10033 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10037 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10043 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10044 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10045 goto nla_put_failure;
10047 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10049 goto nla_put_failure;
10051 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10052 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10054 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10055 goto nla_put_failure;
10057 nla_nest_end(msg, attr);
10059 genlmsg_end(msg, hdr);
10061 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10062 nl80211_mlme_mcgrp.id, gfp);
10066 genlmsg_cancel(msg, hdr);
10070 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10071 const u8 *bssid, bool preauth, gfp_t gfp)
10073 struct wireless_dev *wdev = dev->ieee80211_ptr;
10074 struct wiphy *wiphy = wdev->wiphy;
10075 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10077 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10078 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10080 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10082 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10083 struct net_device *netdev,
10084 struct cfg80211_chan_def *chandef,
10087 struct sk_buff *msg;
10090 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10094 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10100 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10101 goto nla_put_failure;
10103 if (nl80211_send_chandef(msg, chandef))
10104 goto nla_put_failure;
10106 genlmsg_end(msg, hdr);
10108 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10109 nl80211_mlme_mcgrp.id, gfp);
10113 genlmsg_cancel(msg, hdr);
10117 void cfg80211_ch_switch_notify(struct net_device *dev,
10118 struct cfg80211_chan_def *chandef)
10120 struct wireless_dev *wdev = dev->ieee80211_ptr;
10121 struct wiphy *wiphy = wdev->wiphy;
10122 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10124 trace_cfg80211_ch_switch_notify(dev, chandef);
10128 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10129 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10132 wdev->channel = chandef->chan;
10133 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10138 EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10140 void cfg80211_cqm_txe_notify(struct net_device *dev,
10141 const u8 *peer, u32 num_packets,
10142 u32 rate, u32 intvl, gfp_t gfp)
10144 struct wireless_dev *wdev = dev->ieee80211_ptr;
10145 struct wiphy *wiphy = wdev->wiphy;
10146 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10147 struct sk_buff *msg;
10148 struct nlattr *pinfoattr;
10151 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10155 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10161 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10162 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10163 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10164 goto nla_put_failure;
10166 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10168 goto nla_put_failure;
10170 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10171 goto nla_put_failure;
10173 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10174 goto nla_put_failure;
10176 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10177 goto nla_put_failure;
10179 nla_nest_end(msg, pinfoattr);
10181 genlmsg_end(msg, hdr);
10183 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10184 nl80211_mlme_mcgrp.id, gfp);
10188 genlmsg_cancel(msg, hdr);
10191 EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
10194 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10195 struct cfg80211_chan_def *chandef,
10196 enum nl80211_radar_event event,
10197 struct net_device *netdev, gfp_t gfp)
10199 struct sk_buff *msg;
10202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10206 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10213 goto nla_put_failure;
10215 /* NOP and radar events don't need a netdev parameter */
10217 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10219 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10220 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10221 goto nla_put_failure;
10224 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10225 goto nla_put_failure;
10227 if (nl80211_send_chandef(msg, chandef))
10228 goto nla_put_failure;
10230 if (genlmsg_end(msg, hdr) < 0) {
10235 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10236 nl80211_mlme_mcgrp.id, gfp);
10240 genlmsg_cancel(msg, hdr);
10244 void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10245 const u8 *peer, u32 num_packets, gfp_t gfp)
10247 struct wireless_dev *wdev = dev->ieee80211_ptr;
10248 struct wiphy *wiphy = wdev->wiphy;
10249 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10250 struct sk_buff *msg;
10251 struct nlattr *pinfoattr;
10254 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10256 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10260 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10266 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10267 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10268 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10269 goto nla_put_failure;
10271 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10273 goto nla_put_failure;
10275 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10276 goto nla_put_failure;
10278 nla_nest_end(msg, pinfoattr);
10280 genlmsg_end(msg, hdr);
10282 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10283 nl80211_mlme_mcgrp.id, gfp);
10287 genlmsg_cancel(msg, hdr);
10290 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
10292 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10293 u64 cookie, bool acked, gfp_t gfp)
10295 struct wireless_dev *wdev = dev->ieee80211_ptr;
10296 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10297 struct sk_buff *msg;
10301 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10303 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10308 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10315 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10316 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10317 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10318 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10319 goto nla_put_failure;
10321 err = genlmsg_end(msg, hdr);
10327 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10328 nl80211_mlme_mcgrp.id, gfp);
10332 genlmsg_cancel(msg, hdr);
10335 EXPORT_SYMBOL(cfg80211_probe_status);
10337 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10338 const u8 *frame, size_t len,
10339 int freq, int sig_dbm)
10341 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10342 struct sk_buff *msg;
10344 struct cfg80211_beacon_registration *reg;
10346 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10348 spin_lock_bh(&rdev->beacon_registrations_lock);
10349 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10350 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10352 spin_unlock_bh(&rdev->beacon_registrations_lock);
10356 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10358 goto nla_put_failure;
10360 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10362 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10364 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10365 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10366 goto nla_put_failure;
10368 genlmsg_end(msg, hdr);
10370 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
10372 spin_unlock_bh(&rdev->beacon_registrations_lock);
10376 spin_unlock_bh(&rdev->beacon_registrations_lock);
10378 genlmsg_cancel(msg, hdr);
10381 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10384 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10385 struct cfg80211_wowlan_wakeup *wakeup,
10388 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10389 struct sk_buff *msg;
10391 int err, size = 200;
10393 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10396 size += wakeup->packet_present_len;
10398 msg = nlmsg_new(size, gfp);
10402 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10406 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10407 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10410 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10411 wdev->netdev->ifindex))
10415 struct nlattr *reasons;
10417 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10419 if (wakeup->disconnect &&
10420 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10422 if (wakeup->magic_pkt &&
10423 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10425 if (wakeup->gtk_rekey_failure &&
10426 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10428 if (wakeup->eap_identity_req &&
10429 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10431 if (wakeup->four_way_handshake &&
10432 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10434 if (wakeup->rfkill_release &&
10435 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10438 if (wakeup->pattern_idx >= 0 &&
10439 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10440 wakeup->pattern_idx))
10443 if (wakeup->tcp_match)
10444 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10446 if (wakeup->tcp_connlost)
10448 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10450 if (wakeup->tcp_nomoretokens)
10452 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10454 if (wakeup->packet) {
10455 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10456 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10458 if (!wakeup->packet_80211) {
10460 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10462 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10465 if (wakeup->packet_len &&
10466 nla_put_u32(msg, len_attr, wakeup->packet_len))
10469 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10474 nla_nest_end(msg, reasons);
10477 err = genlmsg_end(msg, hdr);
10481 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10482 nl80211_mlme_mcgrp.id, gfp);
10488 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10491 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10492 enum nl80211_tdls_operation oper,
10493 u16 reason_code, gfp_t gfp)
10495 struct wireless_dev *wdev = dev->ieee80211_ptr;
10496 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10497 struct sk_buff *msg;
10501 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10504 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10508 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10514 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10515 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10516 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10517 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10518 (reason_code > 0 &&
10519 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10520 goto nla_put_failure;
10522 err = genlmsg_end(msg, hdr);
10528 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10529 nl80211_mlme_mcgrp.id, gfp);
10533 genlmsg_cancel(msg, hdr);
10536 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10538 static int nl80211_netlink_notify(struct notifier_block * nb,
10539 unsigned long state,
10542 struct netlink_notify *notify = _notify;
10543 struct cfg80211_registered_device *rdev;
10544 struct wireless_dev *wdev;
10545 struct cfg80211_beacon_registration *reg, *tmp;
10547 if (state != NETLINK_URELEASE)
10548 return NOTIFY_DONE;
10552 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
10553 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
10554 cfg80211_mlme_unregister_socket(wdev, notify->portid);
10556 spin_lock_bh(&rdev->beacon_registrations_lock);
10557 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10559 if (reg->nlportid == notify->portid) {
10560 list_del(®->list);
10565 spin_unlock_bh(&rdev->beacon_registrations_lock);
10570 return NOTIFY_DONE;
10573 static struct notifier_block nl80211_netlink_notifier = {
10574 .notifier_call = nl80211_netlink_notify,
10577 void cfg80211_ft_event(struct net_device *netdev,
10578 struct cfg80211_ft_event_params *ft_event)
10580 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10581 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10582 struct sk_buff *msg;
10586 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10588 if (!ft_event->target_ap)
10591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10595 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10601 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10602 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10603 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10605 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10606 if (ft_event->ric_ies)
10607 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10608 ft_event->ric_ies);
10610 err = genlmsg_end(msg, hdr);
10616 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10617 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10619 EXPORT_SYMBOL(cfg80211_ft_event);
10621 /* initialisation/exit functions */
10623 int nl80211_init(void)
10627 err = genl_register_family_with_ops(&nl80211_fam,
10628 nl80211_ops, ARRAY_SIZE(nl80211_ops));
10632 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10636 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10640 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10644 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10648 #ifdef CONFIG_NL80211_TESTMODE
10649 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10654 err = netlink_register_notifier(&nl80211_netlink_notifier);
10660 genl_unregister_family(&nl80211_fam);
10664 void nl80211_exit(void)
10666 netlink_unregister_notifier(&nl80211_netlink_notifier);
10667 genl_unregister_family(&nl80211_fam);