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, },
375 /* policy for the key attributes */
376 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
377 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
378 [NL80211_KEY_IDX] = { .type = NLA_U8 },
379 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
380 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
381 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
382 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
383 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
384 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
387 /* policy for the key default flags */
388 static const struct nla_policy
389 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
390 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
391 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
394 /* policy for WoWLAN attributes */
395 static const struct nla_policy
396 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
397 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
398 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
399 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
400 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
401 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
402 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
403 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
404 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
405 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
408 static const struct nla_policy
409 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
410 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
411 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
412 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
413 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
414 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
415 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
416 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
417 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
419 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
420 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
422 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
423 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
424 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
427 /* policy for GTK rekey offload attributes */
428 static const struct nla_policy
429 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
430 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
431 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
432 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
435 static const struct nla_policy
436 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
437 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
438 .len = IEEE80211_MAX_SSID_LEN },
439 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
442 /* ifidx get helper */
443 static int nl80211_get_ifidx(struct netlink_callback *cb)
447 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
448 nl80211_fam.attrbuf, nl80211_fam.maxattr,
453 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
456 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
462 static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
463 struct netlink_callback *cb,
464 struct cfg80211_registered_device **rdev,
465 struct net_device **dev)
467 int ifidx = cb->args[0];
471 ifidx = nl80211_get_ifidx(cb);
479 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
485 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
487 err = PTR_ERR(*rdev);
497 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
499 cfg80211_unlock_rdev(rdev);
504 static bool is_valid_ie_attr(const struct nlattr *attr)
512 pos = nla_data(attr);
533 /* message building helper */
534 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
537 /* since there is no private header just add the generic one */
538 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
541 static int nl80211_msg_put_channel(struct sk_buff *msg,
542 struct ieee80211_channel *chan)
544 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
546 goto nla_put_failure;
548 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
549 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
550 goto nla_put_failure;
551 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
552 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
553 goto nla_put_failure;
554 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
555 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
556 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
559 goto nla_put_failure;
561 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
562 DBM_TO_MBM(chan->max_power)))
563 goto nla_put_failure;
571 /* netlink command implementations */
578 bool def_uni, def_multi;
581 static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
583 struct nlattr *tb[NL80211_KEY_MAX + 1];
584 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
589 k->def = !!tb[NL80211_KEY_DEFAULT];
590 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
599 if (tb[NL80211_KEY_IDX])
600 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
602 if (tb[NL80211_KEY_DATA]) {
603 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
604 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
607 if (tb[NL80211_KEY_SEQ]) {
608 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
609 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
612 if (tb[NL80211_KEY_CIPHER])
613 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
615 if (tb[NL80211_KEY_TYPE]) {
616 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
617 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
621 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
622 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
623 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
624 tb[NL80211_KEY_DEFAULT_TYPES],
625 nl80211_key_default_policy);
629 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
630 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
636 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
638 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
639 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
640 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
643 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
644 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
645 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
648 if (info->attrs[NL80211_ATTR_KEY_IDX])
649 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
651 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
652 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
654 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
655 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
664 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
665 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
666 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
670 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
671 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
672 int err = nla_parse_nested(
673 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
674 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
675 nl80211_key_default_policy);
679 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
680 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
686 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
690 memset(k, 0, sizeof(*k));
694 if (info->attrs[NL80211_ATTR_KEY])
695 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
697 err = nl80211_parse_key_old(info, k);
702 if (k->def && k->defmgmt)
706 if (k->def_uni || !k->def_multi)
712 if (k->idx < 4 || k->idx > 5)
715 if (k->idx < 0 || k->idx > 3)
718 if (k->idx < 0 || k->idx > 5)
726 static struct cfg80211_cached_keys *
727 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
728 struct nlattr *keys, bool *no_ht)
730 struct key_parse parse;
732 struct cfg80211_cached_keys *result;
733 int rem, err, def = 0;
735 result = kzalloc(sizeof(*result), GFP_KERNEL);
737 return ERR_PTR(-ENOMEM);
740 result->defmgmt = -1;
742 nla_for_each_nested(key, keys, rem) {
743 memset(&parse, 0, sizeof(parse));
746 err = nl80211_parse_key_new(key, &parse);
752 if (parse.idx < 0 || parse.idx > 4)
758 result->def = parse.idx;
759 if (!parse.def_uni || !parse.def_multi)
761 } else if (parse.defmgmt)
763 err = cfg80211_validate_key_settings(rdev, &parse.p,
764 parse.idx, false, NULL);
767 result->params[parse.idx].cipher = parse.p.cipher;
768 result->params[parse.idx].key_len = parse.p.key_len;
769 result->params[parse.idx].key = result->data[parse.idx];
770 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
772 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
773 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
785 static int nl80211_key_allowed(struct wireless_dev *wdev)
787 ASSERT_WDEV_LOCK(wdev);
789 switch (wdev->iftype) {
790 case NL80211_IFTYPE_AP:
791 case NL80211_IFTYPE_AP_VLAN:
792 case NL80211_IFTYPE_P2P_GO:
793 case NL80211_IFTYPE_MESH_POINT:
795 case NL80211_IFTYPE_ADHOC:
796 if (!wdev->current_bss)
799 case NL80211_IFTYPE_STATION:
800 case NL80211_IFTYPE_P2P_CLIENT:
801 if (wdev->sme_state != CFG80211_SME_CONNECTED)
811 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
813 struct nlattr *nl_modes = nla_nest_start(msg, attr);
817 goto nla_put_failure;
821 if ((ifmodes & 1) && nla_put_flag(msg, i))
822 goto nla_put_failure;
827 nla_nest_end(msg, nl_modes);
834 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
837 struct nlattr *nl_combis;
840 nl_combis = nla_nest_start(msg,
841 NL80211_ATTR_INTERFACE_COMBINATIONS);
843 goto nla_put_failure;
845 for (i = 0; i < wiphy->n_iface_combinations; i++) {
846 const struct ieee80211_iface_combination *c;
847 struct nlattr *nl_combi, *nl_limits;
849 c = &wiphy->iface_combinations[i];
851 nl_combi = nla_nest_start(msg, i + 1);
853 goto nla_put_failure;
855 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
857 goto nla_put_failure;
859 for (j = 0; j < c->n_limits; j++) {
860 struct nlattr *nl_limit;
862 nl_limit = nla_nest_start(msg, j + 1);
864 goto nla_put_failure;
865 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
867 goto nla_put_failure;
868 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
870 goto nla_put_failure;
871 nla_nest_end(msg, nl_limit);
874 nla_nest_end(msg, nl_limits);
876 if (c->beacon_int_infra_match &&
877 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
878 goto nla_put_failure;
879 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
880 c->num_different_channels) ||
881 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
883 goto nla_put_failure;
885 nla_nest_end(msg, nl_combi);
888 nla_nest_end(msg, nl_combis);
895 static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags,
896 struct cfg80211_registered_device *dev)
899 struct nlattr *nl_bands, *nl_band;
900 struct nlattr *nl_freqs, *nl_freq;
901 struct nlattr *nl_rates, *nl_rate;
902 struct nlattr *nl_cmds;
903 enum ieee80211_band band;
904 struct ieee80211_channel *chan;
905 struct ieee80211_rate *rate;
907 const struct ieee80211_txrx_stypes *mgmt_stypes =
908 dev->wiphy.mgmt_stypes;
910 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
914 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
915 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
916 nla_put_u32(msg, NL80211_ATTR_GENERATION,
917 cfg80211_rdev_list_generation) ||
918 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
919 dev->wiphy.retry_short) ||
920 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
921 dev->wiphy.retry_long) ||
922 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
923 dev->wiphy.frag_threshold) ||
924 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
925 dev->wiphy.rts_threshold) ||
926 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
927 dev->wiphy.coverage_class) ||
928 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
929 dev->wiphy.max_scan_ssids) ||
930 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
931 dev->wiphy.max_sched_scan_ssids) ||
932 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
933 dev->wiphy.max_scan_ie_len) ||
934 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
935 dev->wiphy.max_sched_scan_ie_len) ||
936 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
937 dev->wiphy.max_match_sets))
938 goto nla_put_failure;
940 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
941 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
942 goto nla_put_failure;
943 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
944 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
945 goto nla_put_failure;
946 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
947 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
948 goto nla_put_failure;
949 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
950 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
951 goto nla_put_failure;
952 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
953 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
954 goto nla_put_failure;
955 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
956 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
957 goto nla_put_failure;
959 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
960 sizeof(u32) * dev->wiphy.n_cipher_suites,
961 dev->wiphy.cipher_suites))
962 goto nla_put_failure;
964 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
965 dev->wiphy.max_num_pmkids))
966 goto nla_put_failure;
968 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
969 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
970 goto nla_put_failure;
972 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
973 dev->wiphy.available_antennas_tx) ||
974 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
975 dev->wiphy.available_antennas_rx))
976 goto nla_put_failure;
978 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
979 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
980 dev->wiphy.probe_resp_offload))
981 goto nla_put_failure;
983 if ((dev->wiphy.available_antennas_tx ||
984 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
985 u32 tx_ant = 0, rx_ant = 0;
987 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
989 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
991 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
993 goto nla_put_failure;
997 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
998 dev->wiphy.interface_modes))
999 goto nla_put_failure;
1001 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1003 goto nla_put_failure;
1005 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1006 if (!dev->wiphy.bands[band])
1009 nl_band = nla_nest_start(msg, band);
1011 goto nla_put_failure;
1014 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
1015 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1016 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
1017 &dev->wiphy.bands[band]->ht_cap.mcs) ||
1018 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1019 dev->wiphy.bands[band]->ht_cap.cap) ||
1020 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1021 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
1022 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1023 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
1024 goto nla_put_failure;
1027 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
1028 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1029 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
1030 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
1031 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1032 dev->wiphy.bands[band]->vht_cap.cap)))
1033 goto nla_put_failure;
1035 /* add frequencies */
1036 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
1038 goto nla_put_failure;
1040 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
1041 nl_freq = nla_nest_start(msg, i);
1043 goto nla_put_failure;
1045 chan = &dev->wiphy.bands[band]->channels[i];
1047 if (nl80211_msg_put_channel(msg, chan))
1048 goto nla_put_failure;
1050 nla_nest_end(msg, nl_freq);
1053 nla_nest_end(msg, nl_freqs);
1056 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1058 goto nla_put_failure;
1060 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1061 nl_rate = nla_nest_start(msg, i);
1063 goto nla_put_failure;
1065 rate = &dev->wiphy.bands[band]->bitrates[i];
1066 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1068 goto nla_put_failure;
1069 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1071 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1072 goto nla_put_failure;
1074 nla_nest_end(msg, nl_rate);
1077 nla_nest_end(msg, nl_rates);
1079 nla_nest_end(msg, nl_band);
1081 nla_nest_end(msg, nl_bands);
1083 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1085 goto nla_put_failure;
1088 #define CMD(op, n) \
1090 if (dev->ops->op) { \
1092 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1093 goto nla_put_failure; \
1097 CMD(add_virtual_intf, NEW_INTERFACE);
1098 CMD(change_virtual_intf, SET_INTERFACE);
1099 CMD(add_key, NEW_KEY);
1100 CMD(start_ap, START_AP);
1101 CMD(add_station, NEW_STATION);
1102 CMD(add_mpath, NEW_MPATH);
1103 CMD(update_mesh_config, SET_MESH_CONFIG);
1104 CMD(change_bss, SET_BSS);
1105 CMD(auth, AUTHENTICATE);
1106 CMD(assoc, ASSOCIATE);
1107 CMD(deauth, DEAUTHENTICATE);
1108 CMD(disassoc, DISASSOCIATE);
1109 CMD(join_ibss, JOIN_IBSS);
1110 CMD(join_mesh, JOIN_MESH);
1111 CMD(set_pmksa, SET_PMKSA);
1112 CMD(del_pmksa, DEL_PMKSA);
1113 CMD(flush_pmksa, FLUSH_PMKSA);
1114 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1115 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1116 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1117 CMD(mgmt_tx, FRAME);
1118 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1119 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1121 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1122 goto nla_put_failure;
1124 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1125 dev->ops->join_mesh) {
1127 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1128 goto nla_put_failure;
1130 CMD(set_wds_peer, SET_WDS_PEER);
1131 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1132 CMD(tdls_mgmt, TDLS_MGMT);
1133 CMD(tdls_oper, TDLS_OPER);
1135 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1136 CMD(sched_scan_start, START_SCHED_SCAN);
1137 CMD(probe_client, PROBE_CLIENT);
1138 CMD(set_noack_map, SET_NOACK_MAP);
1139 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1141 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1142 goto nla_put_failure;
1144 CMD(start_p2p_device, START_P2P_DEVICE);
1145 CMD(set_mcast_rate, SET_MCAST_RATE);
1147 #ifdef CONFIG_NL80211_TESTMODE
1148 CMD(testmode_cmd, TESTMODE);
1153 if (dev->ops->connect || dev->ops->auth) {
1155 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1156 goto nla_put_failure;
1159 if (dev->ops->disconnect || dev->ops->deauth) {
1161 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1162 goto nla_put_failure;
1165 nla_nest_end(msg, nl_cmds);
1167 if (dev->ops->remain_on_channel &&
1168 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1169 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1170 dev->wiphy.max_remain_on_channel_duration))
1171 goto nla_put_failure;
1173 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1174 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1175 goto nla_put_failure;
1179 struct nlattr *nl_ftypes, *nl_ifs;
1180 enum nl80211_iftype ift;
1182 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1184 goto nla_put_failure;
1186 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1187 nl_ftypes = nla_nest_start(msg, ift);
1189 goto nla_put_failure;
1191 stypes = mgmt_stypes[ift].tx;
1194 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1195 (i << 4) | IEEE80211_FTYPE_MGMT))
1196 goto nla_put_failure;
1200 nla_nest_end(msg, nl_ftypes);
1203 nla_nest_end(msg, nl_ifs);
1205 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1207 goto nla_put_failure;
1209 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1210 nl_ftypes = nla_nest_start(msg, ift);
1212 goto nla_put_failure;
1214 stypes = mgmt_stypes[ift].rx;
1217 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1218 (i << 4) | IEEE80211_FTYPE_MGMT))
1219 goto nla_put_failure;
1223 nla_nest_end(msg, nl_ftypes);
1225 nla_nest_end(msg, nl_ifs);
1229 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1230 struct nlattr *nl_wowlan;
1232 nl_wowlan = nla_nest_start(msg,
1233 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1235 goto nla_put_failure;
1237 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1238 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1239 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1240 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1241 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1242 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1243 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1244 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1245 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1246 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1247 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1248 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1249 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1250 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1251 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1252 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1253 goto nla_put_failure;
1254 if (dev->wiphy.wowlan.n_patterns) {
1255 struct nl80211_wowlan_pattern_support pat = {
1256 .max_patterns = dev->wiphy.wowlan.n_patterns,
1258 dev->wiphy.wowlan.pattern_min_len,
1260 dev->wiphy.wowlan.pattern_max_len,
1262 dev->wiphy.wowlan.max_pkt_offset,
1264 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1266 goto nla_put_failure;
1269 nla_nest_end(msg, nl_wowlan);
1273 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1274 dev->wiphy.software_iftypes))
1275 goto nla_put_failure;
1277 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1278 goto nla_put_failure;
1280 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1281 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1282 dev->wiphy.ap_sme_capa))
1283 goto nla_put_failure;
1285 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1286 dev->wiphy.features))
1287 goto nla_put_failure;
1289 if (dev->wiphy.ht_capa_mod_mask &&
1290 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1291 sizeof(*dev->wiphy.ht_capa_mod_mask),
1292 dev->wiphy.ht_capa_mod_mask))
1293 goto nla_put_failure;
1295 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1296 dev->wiphy.max_acl_mac_addrs &&
1297 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1298 dev->wiphy.max_acl_mac_addrs))
1299 goto nla_put_failure;
1301 return genlmsg_end(msg, hdr);
1304 genlmsg_cancel(msg, hdr);
1308 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1311 int start = cb->args[0];
1312 struct cfg80211_registered_device *dev;
1314 mutex_lock(&cfg80211_mutex);
1315 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
1316 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1320 ret = nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid,
1321 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1325 * If sending the wiphy data didn't fit (ENOBUFS or
1326 * EMSGSIZE returned), this SKB is still empty (so
1327 * it's not too big because another wiphy dataset is
1328 * already in the skb) and we've not tried to adjust
1329 * the dump allocation yet ... then adjust the alloc
1330 * size to be bigger, and return 1 but with the empty
1331 * skb. This results in an empty message being RX'ed
1332 * in userspace, but that is ignored.
1334 * We can then retry with the larger buffer.
1336 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1338 cb->min_dump_alloc < 4096) {
1339 cb->min_dump_alloc = 4096;
1340 mutex_unlock(&cfg80211_mutex);
1347 mutex_unlock(&cfg80211_mutex);
1354 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1356 struct sk_buff *msg;
1357 struct cfg80211_registered_device *dev = info->user_ptr[0];
1359 msg = nlmsg_new(4096, GFP_KERNEL);
1363 if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) {
1368 return genlmsg_reply(msg, info);
1371 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1372 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1373 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1374 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1375 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1376 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1379 static int parse_txq_params(struct nlattr *tb[],
1380 struct ieee80211_txq_params *txq_params)
1382 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1383 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1384 !tb[NL80211_TXQ_ATTR_AIFS])
1387 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
1388 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1389 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1390 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1391 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1393 if (txq_params->ac >= NL80211_NUM_ACS)
1399 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1402 * You can only set the channel explicitly for WDS interfaces,
1403 * all others have their channel managed via their respective
1404 * "establish a connection" command (connect, join, ...)
1406 * For AP/GO and mesh mode, the channel can be set with the
1407 * channel userspace API, but is only stored and passed to the
1408 * low-level driver when the AP starts or the mesh is joined.
1409 * This is for backward compatibility, userspace can also give
1410 * the channel in the start-ap or join-mesh commands instead.
1412 * Monitors are special as they are normally slaved to
1413 * whatever else is going on, so they have their own special
1414 * operation to set the monitor channel if possible.
1417 wdev->iftype == NL80211_IFTYPE_AP ||
1418 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
1419 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1420 wdev->iftype == NL80211_IFTYPE_P2P_GO;
1423 static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1424 struct genl_info *info,
1425 struct cfg80211_chan_def *chandef)
1429 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1432 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1434 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
1435 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1436 chandef->center_freq1 = control_freq;
1437 chandef->center_freq2 = 0;
1439 /* Primary channel not allowed */
1440 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1443 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1444 enum nl80211_channel_type chantype;
1446 chantype = nla_get_u32(
1447 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1450 case NL80211_CHAN_NO_HT:
1451 case NL80211_CHAN_HT20:
1452 case NL80211_CHAN_HT40PLUS:
1453 case NL80211_CHAN_HT40MINUS:
1454 cfg80211_chandef_create(chandef, chandef->chan,
1460 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1462 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1463 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1464 chandef->center_freq1 =
1466 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1467 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1468 chandef->center_freq2 =
1470 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1473 if (!cfg80211_chandef_valid(chandef))
1476 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1477 IEEE80211_CHAN_DISABLED))
1483 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1484 struct wireless_dev *wdev,
1485 struct genl_info *info)
1487 struct cfg80211_chan_def chandef;
1489 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1492 iftype = wdev->iftype;
1494 if (!nl80211_can_set_dev_channel(wdev))
1497 result = nl80211_parse_chandef(rdev, info, &chandef);
1501 mutex_lock(&rdev->devlist_mtx);
1503 case NL80211_IFTYPE_AP:
1504 case NL80211_IFTYPE_P2P_GO:
1505 if (wdev->beacon_interval) {
1509 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
1513 wdev->preset_chandef = chandef;
1516 case NL80211_IFTYPE_MESH_POINT:
1517 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
1519 case NL80211_IFTYPE_MONITOR:
1520 result = cfg80211_set_monitor_channel(rdev, &chandef);
1525 mutex_unlock(&rdev->devlist_mtx);
1530 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1533 struct net_device *netdev = info->user_ptr[1];
1535 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
1538 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1541 struct net_device *dev = info->user_ptr[1];
1542 struct wireless_dev *wdev = dev->ieee80211_ptr;
1545 if (!info->attrs[NL80211_ATTR_MAC])
1548 if (netif_running(dev))
1551 if (!rdev->ops->set_wds_peer)
1554 if (wdev->iftype != NL80211_IFTYPE_WDS)
1557 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
1558 return rdev_set_wds_peer(rdev, dev, bssid);
1562 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1564 struct cfg80211_registered_device *rdev;
1565 struct net_device *netdev = NULL;
1566 struct wireless_dev *wdev;
1567 int result = 0, rem_txq_params = 0;
1568 struct nlattr *nl_txq_params;
1570 u8 retry_short = 0, retry_long = 0;
1571 u32 frag_threshold = 0, rts_threshold = 0;
1572 u8 coverage_class = 0;
1575 * Try to find the wiphy and netdev. Normally this
1576 * function shouldn't need the netdev, but this is
1577 * done for backward compatibility -- previously
1578 * setting the channel was done per wiphy, but now
1579 * it is per netdev. Previous userland like hostapd
1580 * also passed a netdev to set_wiphy, so that it is
1581 * possible to let that go to the right netdev!
1583 mutex_lock(&cfg80211_mutex);
1585 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1586 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1588 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1589 if (netdev && netdev->ieee80211_ptr) {
1590 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1591 mutex_lock(&rdev->mtx);
1597 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1600 mutex_unlock(&cfg80211_mutex);
1601 return PTR_ERR(rdev);
1607 mutex_lock(&rdev->mtx);
1609 wdev = netdev->ieee80211_ptr;
1612 * end workaround code, by now the rdev is available
1613 * and locked, and wdev may or may not be NULL.
1616 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
1617 result = cfg80211_dev_rename(
1618 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
1620 mutex_unlock(&cfg80211_mutex);
1625 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1626 struct ieee80211_txq_params txq_params;
1627 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1629 if (!rdev->ops->set_txq_params) {
1630 result = -EOPNOTSUPP;
1639 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1640 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1645 if (!netif_running(netdev)) {
1650 nla_for_each_nested(nl_txq_params,
1651 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1653 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1654 nla_data(nl_txq_params),
1655 nla_len(nl_txq_params),
1657 result = parse_txq_params(tb, &txq_params);
1661 result = rdev_set_txq_params(rdev, netdev,
1668 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
1669 result = __nl80211_set_channel(rdev,
1670 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1676 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1677 struct wireless_dev *txp_wdev = wdev;
1678 enum nl80211_tx_power_setting type;
1681 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1684 if (!rdev->ops->set_tx_power) {
1685 result = -EOPNOTSUPP;
1689 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1690 type = nla_get_u32(info->attrs[idx]);
1692 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1693 (type != NL80211_TX_POWER_AUTOMATIC)) {
1698 if (type != NL80211_TX_POWER_AUTOMATIC) {
1699 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1700 mbm = nla_get_u32(info->attrs[idx]);
1703 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
1708 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1709 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1711 if ((!rdev->wiphy.available_antennas_tx &&
1712 !rdev->wiphy.available_antennas_rx) ||
1713 !rdev->ops->set_antenna) {
1714 result = -EOPNOTSUPP;
1718 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1719 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1721 /* reject antenna configurations which don't match the
1722 * available antenna masks, except for the "all" mask */
1723 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1724 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
1729 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1730 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
1732 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
1739 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1740 retry_short = nla_get_u8(
1741 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1742 if (retry_short == 0) {
1746 changed |= WIPHY_PARAM_RETRY_SHORT;
1749 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1750 retry_long = nla_get_u8(
1751 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1752 if (retry_long == 0) {
1756 changed |= WIPHY_PARAM_RETRY_LONG;
1759 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1760 frag_threshold = nla_get_u32(
1761 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1762 if (frag_threshold < 256) {
1766 if (frag_threshold != (u32) -1) {
1768 * Fragments (apart from the last one) are required to
1769 * have even length. Make the fragmentation code
1770 * simpler by stripping LSB should someone try to use
1771 * odd threshold value.
1773 frag_threshold &= ~0x1;
1775 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1778 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1779 rts_threshold = nla_get_u32(
1780 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1781 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1784 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1785 coverage_class = nla_get_u8(
1786 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1787 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1791 u8 old_retry_short, old_retry_long;
1792 u32 old_frag_threshold, old_rts_threshold;
1793 u8 old_coverage_class;
1795 if (!rdev->ops->set_wiphy_params) {
1796 result = -EOPNOTSUPP;
1800 old_retry_short = rdev->wiphy.retry_short;
1801 old_retry_long = rdev->wiphy.retry_long;
1802 old_frag_threshold = rdev->wiphy.frag_threshold;
1803 old_rts_threshold = rdev->wiphy.rts_threshold;
1804 old_coverage_class = rdev->wiphy.coverage_class;
1806 if (changed & WIPHY_PARAM_RETRY_SHORT)
1807 rdev->wiphy.retry_short = retry_short;
1808 if (changed & WIPHY_PARAM_RETRY_LONG)
1809 rdev->wiphy.retry_long = retry_long;
1810 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1811 rdev->wiphy.frag_threshold = frag_threshold;
1812 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1813 rdev->wiphy.rts_threshold = rts_threshold;
1814 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1815 rdev->wiphy.coverage_class = coverage_class;
1817 result = rdev_set_wiphy_params(rdev, changed);
1819 rdev->wiphy.retry_short = old_retry_short;
1820 rdev->wiphy.retry_long = old_retry_long;
1821 rdev->wiphy.frag_threshold = old_frag_threshold;
1822 rdev->wiphy.rts_threshold = old_rts_threshold;
1823 rdev->wiphy.coverage_class = old_coverage_class;
1828 mutex_unlock(&rdev->mtx);
1834 static inline u64 wdev_id(struct wireless_dev *wdev)
1836 return (u64)wdev->identifier |
1837 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
1840 static int nl80211_send_chandef(struct sk_buff *msg,
1841 struct cfg80211_chan_def *chandef)
1843 WARN_ON(!cfg80211_chandef_valid(chandef));
1845 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1846 chandef->chan->center_freq))
1848 switch (chandef->width) {
1849 case NL80211_CHAN_WIDTH_20_NOHT:
1850 case NL80211_CHAN_WIDTH_20:
1851 case NL80211_CHAN_WIDTH_40:
1852 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1853 cfg80211_get_chandef_type(chandef)))
1859 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
1861 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
1863 if (chandef->center_freq2 &&
1864 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
1869 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
1870 struct cfg80211_registered_device *rdev,
1871 struct wireless_dev *wdev)
1873 struct net_device *dev = wdev->netdev;
1876 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1881 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1882 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
1883 goto nla_put_failure;
1885 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1886 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
1887 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
1888 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
1889 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1890 rdev->devlist_generation ^
1891 (cfg80211_rdev_list_generation << 2)))
1892 goto nla_put_failure;
1894 if (rdev->ops->get_channel) {
1896 struct cfg80211_chan_def chandef;
1898 ret = rdev_get_channel(rdev, wdev, &chandef);
1900 if (nl80211_send_chandef(msg, &chandef))
1901 goto nla_put_failure;
1905 if (wdev->ssid_len) {
1906 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
1907 goto nla_put_failure;
1910 return genlmsg_end(msg, hdr);
1913 genlmsg_cancel(msg, hdr);
1917 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1921 int wp_start = cb->args[0];
1922 int if_start = cb->args[1];
1923 struct cfg80211_registered_device *rdev;
1924 struct wireless_dev *wdev;
1926 mutex_lock(&cfg80211_mutex);
1927 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1928 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
1930 if (wp_idx < wp_start) {
1936 mutex_lock(&rdev->devlist_mtx);
1937 list_for_each_entry(wdev, &rdev->wdev_list, list) {
1938 if (if_idx < if_start) {
1942 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
1943 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1945 mutex_unlock(&rdev->devlist_mtx);
1950 mutex_unlock(&rdev->devlist_mtx);
1955 mutex_unlock(&cfg80211_mutex);
1957 cb->args[0] = wp_idx;
1958 cb->args[1] = if_idx;
1963 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1965 struct sk_buff *msg;
1966 struct cfg80211_registered_device *dev = info->user_ptr[0];
1967 struct wireless_dev *wdev = info->user_ptr[1];
1969 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1973 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
1979 return genlmsg_reply(msg, info);
1982 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1983 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1984 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1985 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1986 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1987 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1990 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1992 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2000 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2001 nla, mntr_flags_policy))
2004 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2006 *mntrflags |= (1<<flag);
2011 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
2012 struct net_device *netdev, u8 use_4addr,
2013 enum nl80211_iftype iftype)
2016 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
2022 case NL80211_IFTYPE_AP_VLAN:
2023 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2026 case NL80211_IFTYPE_STATION:
2027 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2037 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2040 struct vif_params params;
2042 enum nl80211_iftype otype, ntype;
2043 struct net_device *dev = info->user_ptr[1];
2044 u32 _flags, *flags = NULL;
2045 bool change = false;
2047 memset(¶ms, 0, sizeof(params));
2049 otype = ntype = dev->ieee80211_ptr->iftype;
2051 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2052 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2055 if (ntype > NL80211_IFTYPE_MAX)
2059 if (info->attrs[NL80211_ATTR_MESH_ID]) {
2060 struct wireless_dev *wdev = dev->ieee80211_ptr;
2062 if (ntype != NL80211_IFTYPE_MESH_POINT)
2064 if (netif_running(dev))
2068 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2069 IEEE80211_MAX_MESH_ID_LEN);
2070 wdev->mesh_id_up_len =
2071 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2072 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2073 wdev->mesh_id_up_len);
2077 if (info->attrs[NL80211_ATTR_4ADDR]) {
2078 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2080 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
2084 params.use_4addr = -1;
2087 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
2088 if (ntype != NL80211_IFTYPE_MONITOR)
2090 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2100 err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms);
2104 if (!err && params.use_4addr != -1)
2105 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2110 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2113 struct vif_params params;
2114 struct wireless_dev *wdev;
2115 struct sk_buff *msg;
2117 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
2120 memset(¶ms, 0, sizeof(params));
2122 if (!info->attrs[NL80211_ATTR_IFNAME])
2125 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2126 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2127 if (type > NL80211_IFTYPE_MAX)
2131 if (!rdev->ops->add_virtual_intf ||
2132 !(rdev->wiphy.interface_modes & (1 << type)))
2135 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2136 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2138 if (!is_valid_ether_addr(params.macaddr))
2139 return -EADDRNOTAVAIL;
2142 if (info->attrs[NL80211_ATTR_4ADDR]) {
2143 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2144 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
2149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2153 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2154 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2156 wdev = rdev_add_virtual_intf(rdev,
2157 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2158 type, err ? NULL : &flags, ¶ms);
2161 return PTR_ERR(wdev);
2165 case NL80211_IFTYPE_MESH_POINT:
2166 if (!info->attrs[NL80211_ATTR_MESH_ID])
2169 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2170 IEEE80211_MAX_MESH_ID_LEN);
2171 wdev->mesh_id_up_len =
2172 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2173 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2174 wdev->mesh_id_up_len);
2177 case NL80211_IFTYPE_P2P_DEVICE:
2179 * P2P Device doesn't have a netdev, so doesn't go
2180 * through the netdev notifier and must be added here
2182 mutex_init(&wdev->mtx);
2183 INIT_LIST_HEAD(&wdev->event_list);
2184 spin_lock_init(&wdev->event_lock);
2185 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2186 spin_lock_init(&wdev->mgmt_registrations_lock);
2188 mutex_lock(&rdev->devlist_mtx);
2189 wdev->identifier = ++rdev->wdev_id;
2190 list_add_rcu(&wdev->list, &rdev->wdev_list);
2191 rdev->devlist_generation++;
2192 mutex_unlock(&rdev->devlist_mtx);
2198 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
2204 return genlmsg_reply(msg, info);
2207 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2210 struct wireless_dev *wdev = info->user_ptr[1];
2212 if (!rdev->ops->del_virtual_intf)
2216 * If we remove a wireless device without a netdev then clear
2217 * user_ptr[1] so that nl80211_post_doit won't dereference it
2218 * to check if it needs to do dev_put(). Otherwise it crashes
2219 * since the wdev has been freed, unlike with a netdev where
2220 * we need the dev_put() for the netdev to really be freed.
2223 info->user_ptr[1] = NULL;
2225 return rdev_del_virtual_intf(rdev, wdev);
2228 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2231 struct net_device *dev = info->user_ptr[1];
2234 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2237 if (!rdev->ops->set_noack_map)
2240 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2242 return rdev_set_noack_map(rdev, dev, noack_map);
2245 struct get_key_cookie {
2246 struct sk_buff *msg;
2251 static void get_key_callback(void *c, struct key_params *params)
2254 struct get_key_cookie *cookie = c;
2257 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2258 params->key_len, params->key)) ||
2260 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2261 params->seq_len, params->seq)) ||
2263 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2265 goto nla_put_failure;
2267 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2269 goto nla_put_failure;
2272 nla_put(cookie->msg, NL80211_KEY_DATA,
2273 params->key_len, params->key)) ||
2275 nla_put(cookie->msg, NL80211_KEY_SEQ,
2276 params->seq_len, params->seq)) ||
2278 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2280 goto nla_put_failure;
2282 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2283 goto nla_put_failure;
2285 nla_nest_end(cookie->msg, key);
2292 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2296 struct net_device *dev = info->user_ptr[1];
2298 const u8 *mac_addr = NULL;
2300 struct get_key_cookie cookie = {
2304 struct sk_buff *msg;
2306 if (info->attrs[NL80211_ATTR_KEY_IDX])
2307 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2312 if (info->attrs[NL80211_ATTR_MAC])
2313 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2315 pairwise = !!mac_addr;
2316 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2317 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2318 if (kt >= NUM_NL80211_KEYTYPES)
2320 if (kt != NL80211_KEYTYPE_GROUP &&
2321 kt != NL80211_KEYTYPE_PAIRWISE)
2323 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2326 if (!rdev->ops->get_key)
2329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2333 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
2334 NL80211_CMD_NEW_KEY);
2336 return PTR_ERR(hdr);
2339 cookie.idx = key_idx;
2341 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2342 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2343 goto nla_put_failure;
2345 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2346 goto nla_put_failure;
2348 if (pairwise && mac_addr &&
2349 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2352 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2359 goto nla_put_failure;
2361 genlmsg_end(msg, hdr);
2362 return genlmsg_reply(msg, info);
2371 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2374 struct key_parse key;
2376 struct net_device *dev = info->user_ptr[1];
2378 err = nl80211_parse_key(info, &key);
2385 /* only support setting default key */
2386 if (!key.def && !key.defmgmt)
2389 wdev_lock(dev->ieee80211_ptr);
2392 if (!rdev->ops->set_default_key) {
2397 err = nl80211_key_allowed(dev->ieee80211_ptr);
2401 err = rdev_set_default_key(rdev, dev, key.idx,
2402 key.def_uni, key.def_multi);
2407 #ifdef CONFIG_CFG80211_WEXT
2408 dev->ieee80211_ptr->wext.default_key = key.idx;
2411 if (key.def_uni || !key.def_multi) {
2416 if (!rdev->ops->set_default_mgmt_key) {
2421 err = nl80211_key_allowed(dev->ieee80211_ptr);
2425 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
2429 #ifdef CONFIG_CFG80211_WEXT
2430 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2435 wdev_unlock(dev->ieee80211_ptr);
2440 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2444 struct net_device *dev = info->user_ptr[1];
2445 struct key_parse key;
2446 const u8 *mac_addr = NULL;
2448 err = nl80211_parse_key(info, &key);
2455 if (info->attrs[NL80211_ATTR_MAC])
2456 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2458 if (key.type == -1) {
2460 key.type = NL80211_KEYTYPE_PAIRWISE;
2462 key.type = NL80211_KEYTYPE_GROUP;
2466 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2467 key.type != NL80211_KEYTYPE_GROUP)
2470 if (!rdev->ops->add_key)
2473 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2474 key.type == NL80211_KEYTYPE_PAIRWISE,
2478 wdev_lock(dev->ieee80211_ptr);
2479 err = nl80211_key_allowed(dev->ieee80211_ptr);
2481 err = rdev_add_key(rdev, dev, key.idx,
2482 key.type == NL80211_KEYTYPE_PAIRWISE,
2484 wdev_unlock(dev->ieee80211_ptr);
2489 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2491 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2493 struct net_device *dev = info->user_ptr[1];
2494 u8 *mac_addr = NULL;
2495 struct key_parse key;
2497 err = nl80211_parse_key(info, &key);
2501 if (info->attrs[NL80211_ATTR_MAC])
2502 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2504 if (key.type == -1) {
2506 key.type = NL80211_KEYTYPE_PAIRWISE;
2508 key.type = NL80211_KEYTYPE_GROUP;
2512 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2513 key.type != NL80211_KEYTYPE_GROUP)
2516 if (!rdev->ops->del_key)
2519 wdev_lock(dev->ieee80211_ptr);
2520 err = nl80211_key_allowed(dev->ieee80211_ptr);
2522 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2523 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2527 err = rdev_del_key(rdev, dev, key.idx,
2528 key.type == NL80211_KEYTYPE_PAIRWISE,
2531 #ifdef CONFIG_CFG80211_WEXT
2533 if (key.idx == dev->ieee80211_ptr->wext.default_key)
2534 dev->ieee80211_ptr->wext.default_key = -1;
2535 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
2536 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2539 wdev_unlock(dev->ieee80211_ptr);
2544 /* This function returns an error or the number of nested attributes */
2545 static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2547 struct nlattr *attr;
2548 int n_entries = 0, tmp;
2550 nla_for_each_nested(attr, nl_attr, tmp) {
2551 if (nla_len(attr) != ETH_ALEN)
2561 * This function parses ACL information and allocates memory for ACL data.
2562 * On successful return, the calling function is responsible to free the
2563 * ACL buffer returned by this function.
2565 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2566 struct genl_info *info)
2568 enum nl80211_acl_policy acl_policy;
2569 struct nlattr *attr;
2570 struct cfg80211_acl_data *acl;
2571 int i = 0, n_entries, tmp;
2573 if (!wiphy->max_acl_mac_addrs)
2574 return ERR_PTR(-EOPNOTSUPP);
2576 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2577 return ERR_PTR(-EINVAL);
2579 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2580 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2581 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2582 return ERR_PTR(-EINVAL);
2584 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2585 return ERR_PTR(-EINVAL);
2587 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2589 return ERR_PTR(n_entries);
2591 if (n_entries > wiphy->max_acl_mac_addrs)
2592 return ERR_PTR(-ENOTSUPP);
2594 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2597 return ERR_PTR(-ENOMEM);
2599 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2600 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2604 acl->n_acl_entries = n_entries;
2605 acl->acl_policy = acl_policy;
2610 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2613 struct net_device *dev = info->user_ptr[1];
2614 struct cfg80211_acl_data *acl;
2617 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2618 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2621 if (!dev->ieee80211_ptr->beacon_interval)
2624 acl = parse_acl_data(&rdev->wiphy, info);
2626 return PTR_ERR(acl);
2628 err = rdev_set_mac_acl(rdev, dev, acl);
2635 static int nl80211_parse_beacon(struct genl_info *info,
2636 struct cfg80211_beacon_data *bcn)
2638 bool haveinfo = false;
2640 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2641 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2642 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2643 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
2646 memset(bcn, 0, sizeof(*bcn));
2648 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2649 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2650 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2656 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2657 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2659 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2666 if (info->attrs[NL80211_ATTR_IE]) {
2667 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2668 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2671 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
2672 bcn->proberesp_ies =
2673 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2674 bcn->proberesp_ies_len =
2675 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2678 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
2679 bcn->assocresp_ies =
2680 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2681 bcn->assocresp_ies_len =
2682 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2685 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
2687 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
2688 bcn->probe_resp_len =
2689 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2695 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2696 struct cfg80211_ap_settings *params)
2698 struct wireless_dev *wdev;
2701 mutex_lock(&rdev->devlist_mtx);
2703 list_for_each_entry(wdev, &rdev->wdev_list, list) {
2704 if (wdev->iftype != NL80211_IFTYPE_AP &&
2705 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2708 if (!wdev->preset_chandef.chan)
2711 params->chandef = wdev->preset_chandef;
2716 mutex_unlock(&rdev->devlist_mtx);
2721 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2722 enum nl80211_auth_type auth_type,
2723 enum nl80211_commands cmd)
2725 if (auth_type > NL80211_AUTHTYPE_MAX)
2729 case NL80211_CMD_AUTHENTICATE:
2730 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2731 auth_type == NL80211_AUTHTYPE_SAE)
2734 case NL80211_CMD_CONNECT:
2735 case NL80211_CMD_START_AP:
2736 /* SAE not supported yet */
2737 if (auth_type == NL80211_AUTHTYPE_SAE)
2745 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2748 struct net_device *dev = info->user_ptr[1];
2749 struct wireless_dev *wdev = dev->ieee80211_ptr;
2750 struct cfg80211_ap_settings params;
2752 u8 radar_detect_width = 0;
2754 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2755 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2758 if (!rdev->ops->start_ap)
2761 if (wdev->beacon_interval)
2764 memset(¶ms, 0, sizeof(params));
2766 /* these are required for START_AP */
2767 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2768 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2769 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2772 err = nl80211_parse_beacon(info, ¶ms.beacon);
2776 params.beacon_interval =
2777 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2778 params.dtim_period =
2779 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2781 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2786 * In theory, some of these attributes should be required here
2787 * but since they were not used when the command was originally
2788 * added, keep them optional for old user space programs to let
2789 * them continue to work with drivers that do not need the
2790 * additional information -- drivers must check!
2792 if (info->attrs[NL80211_ATTR_SSID]) {
2793 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2795 nla_len(info->attrs[NL80211_ATTR_SSID]);
2796 if (params.ssid_len == 0 ||
2797 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2801 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2802 params.hidden_ssid = nla_get_u32(
2803 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2804 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2805 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2806 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2810 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2812 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2813 params.auth_type = nla_get_u32(
2814 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2815 if (!nl80211_valid_auth_type(rdev, params.auth_type,
2816 NL80211_CMD_START_AP))
2819 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2821 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
2822 NL80211_MAX_NR_CIPHER_SUITES);
2826 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2827 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2829 params.inactivity_timeout = nla_get_u16(
2830 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2833 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
2834 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2836 params.p2p_ctwindow =
2837 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
2838 if (params.p2p_ctwindow > 127)
2840 if (params.p2p_ctwindow != 0 &&
2841 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
2845 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
2848 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2850 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
2853 params.p2p_opp_ps = tmp;
2854 if (params.p2p_opp_ps != 0 &&
2855 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
2859 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2860 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef);
2863 } else if (wdev->preset_chandef.chan) {
2864 params.chandef = wdev->preset_chandef;
2865 } else if (!nl80211_get_ap_channel(rdev, ¶ms))
2868 if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef))
2871 err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef);
2875 radar_detect_width = BIT(params.chandef.width);
2876 params.radar_required = true;
2879 mutex_lock(&rdev->devlist_mtx);
2880 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
2881 params.chandef.chan,
2883 radar_detect_width);
2884 mutex_unlock(&rdev->devlist_mtx);
2889 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
2890 params.acl = parse_acl_data(&rdev->wiphy, info);
2891 if (IS_ERR(params.acl))
2892 return PTR_ERR(params.acl);
2895 err = rdev_start_ap(rdev, dev, ¶ms);
2897 wdev->preset_chandef = params.chandef;
2898 wdev->beacon_interval = params.beacon_interval;
2899 wdev->channel = params.chandef.chan;
2900 wdev->ssid_len = params.ssid_len;
2901 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
2909 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2912 struct net_device *dev = info->user_ptr[1];
2913 struct wireless_dev *wdev = dev->ieee80211_ptr;
2914 struct cfg80211_beacon_data params;
2917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2921 if (!rdev->ops->change_beacon)
2924 if (!wdev->beacon_interval)
2927 err = nl80211_parse_beacon(info, ¶ms);
2931 return rdev_change_beacon(rdev, dev, ¶ms);
2934 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
2936 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2937 struct net_device *dev = info->user_ptr[1];
2939 return cfg80211_stop_ap(rdev, dev);
2942 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2943 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2944 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2945 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
2946 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
2947 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
2948 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
2951 static int parse_station_flags(struct genl_info *info,
2952 enum nl80211_iftype iftype,
2953 struct station_parameters *params)
2955 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
2960 * Try parsing the new attribute first so userspace
2961 * can specify both for older kernels.
2963 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2965 struct nl80211_sta_flag_update *sta_flags;
2967 sta_flags = nla_data(nla);
2968 params->sta_flags_mask = sta_flags->mask;
2969 params->sta_flags_set = sta_flags->set;
2970 params->sta_flags_set &= params->sta_flags_mask;
2971 if ((params->sta_flags_mask |
2972 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2977 /* if present, parse the old attribute */
2979 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
2983 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2984 nla, sta_flags_policy))
2988 * Only allow certain flags for interface types so that
2989 * other attributes are silently ignored. Remember that
2990 * this is backward compatibility code with old userspace
2991 * and shouldn't be hit in other cases anyway.
2994 case NL80211_IFTYPE_AP:
2995 case NL80211_IFTYPE_AP_VLAN:
2996 case NL80211_IFTYPE_P2P_GO:
2997 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2998 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2999 BIT(NL80211_STA_FLAG_WME) |
3000 BIT(NL80211_STA_FLAG_MFP);
3002 case NL80211_IFTYPE_P2P_CLIENT:
3003 case NL80211_IFTYPE_STATION:
3004 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3005 BIT(NL80211_STA_FLAG_TDLS_PEER);
3007 case NL80211_IFTYPE_MESH_POINT:
3008 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3009 BIT(NL80211_STA_FLAG_MFP) |
3010 BIT(NL80211_STA_FLAG_AUTHORIZED);
3015 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3017 params->sta_flags_set |= (1<<flag);
3019 /* no longer support new API additions in old API */
3020 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3028 static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3031 struct nlattr *rate;
3035 rate = nla_nest_start(msg, attr);
3039 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3040 bitrate = cfg80211_calculate_bitrate(info);
3041 /* report 16-bit bitrate only if we can */
3042 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
3044 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3046 if (bitrate_compat > 0 &&
3047 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3050 if (info->flags & RATE_INFO_FLAGS_MCS) {
3051 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3053 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3054 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3056 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3057 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3059 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3060 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3062 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3064 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3065 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3067 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3068 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3070 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3071 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3073 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3074 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3076 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3077 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3081 nla_nest_end(msg, rate);
3085 static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
3087 struct cfg80211_registered_device *rdev,
3088 struct net_device *dev,
3089 const u8 *mac_addr, struct station_info *sinfo)
3092 struct nlattr *sinfoattr, *bss_param;
3094 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
3098 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3099 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3100 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3101 goto nla_put_failure;
3103 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3105 goto nla_put_failure;
3106 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3107 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3108 sinfo->connected_time))
3109 goto nla_put_failure;
3110 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3111 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3112 sinfo->inactive_time))
3113 goto nla_put_failure;
3114 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3115 STATION_INFO_RX_BYTES64)) &&
3116 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
3117 (u32)sinfo->rx_bytes))
3118 goto nla_put_failure;
3119 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3120 NL80211_STA_INFO_TX_BYTES64)) &&
3121 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3122 (u32)sinfo->tx_bytes))
3123 goto nla_put_failure;
3124 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3125 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
3127 goto nla_put_failure;
3128 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3129 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
3131 goto nla_put_failure;
3132 if ((sinfo->filled & STATION_INFO_LLID) &&
3133 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3134 goto nla_put_failure;
3135 if ((sinfo->filled & STATION_INFO_PLID) &&
3136 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3137 goto nla_put_failure;
3138 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3139 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3140 sinfo->plink_state))
3141 goto nla_put_failure;
3142 switch (rdev->wiphy.signal_type) {
3143 case CFG80211_SIGNAL_TYPE_MBM:
3144 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3145 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3147 goto nla_put_failure;
3148 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3149 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3151 goto nla_put_failure;
3156 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
3157 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3158 NL80211_STA_INFO_TX_BITRATE))
3159 goto nla_put_failure;
3161 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3162 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3163 NL80211_STA_INFO_RX_BITRATE))
3164 goto nla_put_failure;
3166 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3167 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3169 goto nla_put_failure;
3170 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3171 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3173 goto nla_put_failure;
3174 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3175 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3177 goto nla_put_failure;
3178 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3179 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3181 goto nla_put_failure;
3182 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3183 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3184 sinfo->beacon_loss_count))
3185 goto nla_put_failure;
3186 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3187 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3189 goto nla_put_failure;
3190 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3191 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3193 goto nla_put_failure;
3194 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3195 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3197 goto nla_put_failure;
3198 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3199 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3201 goto nla_put_failure;
3203 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3204 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3205 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3206 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3207 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3208 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3209 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3210 sinfo->bss_param.dtim_period) ||
3211 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3212 sinfo->bss_param.beacon_interval))
3213 goto nla_put_failure;
3215 nla_nest_end(msg, bss_param);
3217 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3218 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3219 sizeof(struct nl80211_sta_flag_update),
3221 goto nla_put_failure;
3222 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3223 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3225 goto nla_put_failure;
3226 nla_nest_end(msg, sinfoattr);
3228 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3229 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3230 sinfo->assoc_req_ies))
3231 goto nla_put_failure;
3233 return genlmsg_end(msg, hdr);
3236 genlmsg_cancel(msg, hdr);
3240 static int nl80211_dump_station(struct sk_buff *skb,
3241 struct netlink_callback *cb)
3243 struct station_info sinfo;
3244 struct cfg80211_registered_device *dev;
3245 struct net_device *netdev;
3246 u8 mac_addr[ETH_ALEN];
3247 int sta_idx = cb->args[1];
3250 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3254 if (!dev->ops->dump_station) {
3260 memset(&sinfo, 0, sizeof(sinfo));
3261 err = rdev_dump_station(dev, netdev, sta_idx,
3268 if (nl80211_send_station(skb,
3269 NETLINK_CB(cb->skb).portid,
3270 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3271 dev, netdev, mac_addr,
3280 cb->args[1] = sta_idx;
3283 nl80211_finish_netdev_dump(dev);
3288 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3291 struct net_device *dev = info->user_ptr[1];
3292 struct station_info sinfo;
3293 struct sk_buff *msg;
3294 u8 *mac_addr = NULL;
3297 memset(&sinfo, 0, sizeof(sinfo));
3299 if (!info->attrs[NL80211_ATTR_MAC])
3302 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3304 if (!rdev->ops->get_station)
3307 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
3311 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3315 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
3316 rdev, dev, mac_addr, &sinfo) < 0) {
3321 return genlmsg_reply(msg, info);
3324 int cfg80211_check_station_change(struct wiphy *wiphy,
3325 struct station_parameters *params,
3326 enum cfg80211_station_type statype)
3328 if (params->listen_interval != -1)
3333 /* When you run into this, adjust the code below for the new flag */
3334 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3337 case CFG80211_STA_MESH_PEER_NONSEC:
3338 case CFG80211_STA_MESH_PEER_SECURE:
3340 * No ignoring the TDLS flag here -- the userspace mesh
3341 * code doesn't have the bug of including TDLS in the
3344 if (params->sta_flags_mask &
3345 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3346 BIT(NL80211_STA_FLAG_MFP) |
3347 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3350 case CFG80211_STA_TDLS_PEER_SETUP:
3351 case CFG80211_STA_TDLS_PEER_ACTIVE:
3352 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3354 /* ignore since it can't change */
3355 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3358 /* disallow mesh-specific things */
3359 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3361 if (params->local_pm)
3363 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3367 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3368 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3369 /* TDLS can't be set, ... */
3370 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3373 * ... but don't bother the driver with it. This works around
3374 * a hostapd/wpa_supplicant issue -- it always includes the
3375 * TLDS_PEER flag in the mask even for AP mode.
3377 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3380 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3381 /* reject other things that can't change */
3382 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3384 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3386 if (params->supported_rates)
3388 if (params->ext_capab || params->ht_capa || params->vht_capa)
3392 if (statype != CFG80211_STA_AP_CLIENT) {
3398 case CFG80211_STA_AP_MLME_CLIENT:
3399 /* Use this only for authorizing/unauthorizing a station */
3400 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3403 case CFG80211_STA_AP_CLIENT:
3404 /* accept only the listed bits */
3405 if (params->sta_flags_mask &
3406 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3407 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3408 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3409 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3410 BIT(NL80211_STA_FLAG_WME) |
3411 BIT(NL80211_STA_FLAG_MFP)))
3414 /* but authenticated/associated only if driver handles it */
3415 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3416 params->sta_flags_mask &
3417 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3418 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3421 case CFG80211_STA_IBSS:
3422 case CFG80211_STA_AP_STA:
3423 /* reject any changes other than AUTHORIZED */
3424 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3427 case CFG80211_STA_TDLS_PEER_SETUP:
3428 /* reject any changes other than AUTHORIZED or WME */
3429 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3430 BIT(NL80211_STA_FLAG_WME)))
3432 /* force (at least) rates when authorizing */
3433 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3434 !params->supported_rates)
3437 case CFG80211_STA_TDLS_PEER_ACTIVE:
3438 /* reject any changes */
3440 case CFG80211_STA_MESH_PEER_NONSEC:
3441 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3444 case CFG80211_STA_MESH_PEER_SECURE:
3445 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3452 EXPORT_SYMBOL(cfg80211_check_station_change);
3455 * Get vlan interface making sure it is running and on the right wiphy.
3457 static struct net_device *get_vlan(struct genl_info *info,
3458 struct cfg80211_registered_device *rdev)
3460 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
3461 struct net_device *v;
3467 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3469 return ERR_PTR(-ENODEV);
3471 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3476 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3477 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3478 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3483 if (!netif_running(v)) {
3491 return ERR_PTR(ret);
3494 static struct nla_policy
3495 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3496 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3497 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3500 static int nl80211_parse_sta_wme(struct genl_info *info,
3501 struct station_parameters *params)
3503 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3507 /* parse WME attributes if present */
3508 if (!info->attrs[NL80211_ATTR_STA_WME])
3511 nla = info->attrs[NL80211_ATTR_STA_WME];
3512 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3513 nl80211_sta_wme_policy);
3517 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3518 params->uapsd_queues = nla_get_u8(
3519 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3520 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3523 if (tb[NL80211_STA_WME_MAX_SP])
3524 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3526 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3529 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3534 static int nl80211_set_station_tdls(struct genl_info *info,
3535 struct station_parameters *params)
3537 /* Dummy STA entry gets updated once the peer capabilities are known */
3538 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3540 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3541 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3543 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3545 return nl80211_parse_sta_wme(info, params);
3548 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3550 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3551 struct net_device *dev = info->user_ptr[1];
3552 struct station_parameters params;
3556 memset(¶ms, 0, sizeof(params));
3558 params.listen_interval = -1;
3560 if (!rdev->ops->change_station)
3563 if (info->attrs[NL80211_ATTR_STA_AID])
3566 if (!info->attrs[NL80211_ATTR_MAC])
3569 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3571 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3572 params.supported_rates =
3573 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3574 params.supported_rates_len =
3575 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3578 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3580 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3581 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3584 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3586 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3587 params.ext_capab_len =
3588 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3591 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3594 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3597 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3598 params.plink_action =
3599 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3600 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3604 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
3605 params.plink_state =
3606 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3607 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3609 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3612 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3613 enum nl80211_mesh_power_mode pm = nla_get_u32(
3614 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3616 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3617 pm > NL80211_MESH_POWER_MAX)
3620 params.local_pm = pm;
3623 /* Include parameters for TDLS peer (will check later) */
3624 err = nl80211_set_station_tdls(info, ¶ms);
3628 params.vlan = get_vlan(info, rdev);
3629 if (IS_ERR(params.vlan))
3630 return PTR_ERR(params.vlan);
3632 switch (dev->ieee80211_ptr->iftype) {
3633 case NL80211_IFTYPE_AP:
3634 case NL80211_IFTYPE_AP_VLAN:
3635 case NL80211_IFTYPE_P2P_GO:
3636 case NL80211_IFTYPE_P2P_CLIENT:
3637 case NL80211_IFTYPE_STATION:
3638 case NL80211_IFTYPE_ADHOC:
3639 case NL80211_IFTYPE_MESH_POINT:
3646 /* driver will call cfg80211_check_station_change() */
3647 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
3651 dev_put(params.vlan);
3656 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3660 struct net_device *dev = info->user_ptr[1];
3661 struct station_parameters params;
3662 u8 *mac_addr = NULL;
3664 memset(¶ms, 0, sizeof(params));
3666 if (!rdev->ops->add_station)
3669 if (!info->attrs[NL80211_ATTR_MAC])
3672 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3675 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3678 if (!info->attrs[NL80211_ATTR_STA_AID])
3681 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3682 params.supported_rates =
3683 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3684 params.supported_rates_len =
3685 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3686 params.listen_interval =
3687 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3689 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3690 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3693 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3695 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3696 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3699 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3701 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3702 params.ext_capab_len =
3703 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3706 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3708 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3710 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3712 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3714 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3715 params.plink_action =
3716 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3717 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3721 err = nl80211_parse_sta_wme(info, ¶ms);
3725 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3728 /* When you run into this, adjust the code below for the new flag */
3729 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3731 switch (dev->ieee80211_ptr->iftype) {
3732 case NL80211_IFTYPE_AP:
3733 case NL80211_IFTYPE_AP_VLAN:
3734 case NL80211_IFTYPE_P2P_GO:
3735 /* ignore WME attributes if iface/sta is not capable */
3736 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
3737 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
3738 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
3740 /* TDLS peers cannot be added */
3741 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3743 /* but don't bother the driver with it */
3744 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3746 /* allow authenticated/associated only if driver handles it */
3747 if (!(rdev->wiphy.features &
3748 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3749 params.sta_flags_mask &
3750 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3751 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3754 /* must be last in here for error handling */
3755 params.vlan = get_vlan(info, rdev);
3756 if (IS_ERR(params.vlan))
3757 return PTR_ERR(params.vlan);
3759 case NL80211_IFTYPE_MESH_POINT:
3760 /* ignore uAPSD data */
3761 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
3763 /* associated is disallowed */
3764 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3766 /* TDLS peers cannot be added */
3767 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3770 case NL80211_IFTYPE_STATION:
3771 /* ignore uAPSD data */
3772 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
3774 /* these are disallowed */
3775 if (params.sta_flags_mask &
3776 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
3777 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
3779 /* Only TDLS peers can be added */
3780 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3782 /* Can only add if TDLS ... */
3783 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3785 /* ... with external setup is supported */
3786 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3789 * Older wpa_supplicant versions always mark the TDLS peer
3790 * as authorized, but it shouldn't yet be.
3792 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
3798 /* be aware of params.vlan when changing code here */
3800 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
3803 dev_put(params.vlan);
3807 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3810 struct net_device *dev = info->user_ptr[1];
3811 u8 *mac_addr = NULL;
3813 if (info->attrs[NL80211_ATTR_MAC])
3814 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3816 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3817 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3818 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
3819 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3822 if (!rdev->ops->del_station)
3825 return rdev_del_station(rdev, dev, mac_addr);
3828 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
3829 int flags, struct net_device *dev,
3830 u8 *dst, u8 *next_hop,
3831 struct mpath_info *pinfo)
3834 struct nlattr *pinfoattr;
3836 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
3840 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3841 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3842 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3843 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3844 goto nla_put_failure;
3846 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3848 goto nla_put_failure;
3849 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3850 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3852 goto nla_put_failure;
3853 if (((pinfo->filled & MPATH_INFO_SN) &&
3854 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3855 ((pinfo->filled & MPATH_INFO_METRIC) &&
3856 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3858 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3859 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3861 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3862 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3864 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3865 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3866 pinfo->discovery_timeout)) ||
3867 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3868 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3869 pinfo->discovery_retries)))
3870 goto nla_put_failure;
3872 nla_nest_end(msg, pinfoattr);
3874 return genlmsg_end(msg, hdr);
3877 genlmsg_cancel(msg, hdr);
3881 static int nl80211_dump_mpath(struct sk_buff *skb,
3882 struct netlink_callback *cb)
3884 struct mpath_info pinfo;
3885 struct cfg80211_registered_device *dev;
3886 struct net_device *netdev;
3888 u8 next_hop[ETH_ALEN];
3889 int path_idx = cb->args[1];
3892 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3896 if (!dev->ops->dump_mpath) {
3901 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3907 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
3914 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
3915 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3916 netdev, dst, next_hop,
3925 cb->args[1] = path_idx;
3928 nl80211_finish_netdev_dump(dev);
3932 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3934 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3936 struct net_device *dev = info->user_ptr[1];
3937 struct mpath_info pinfo;
3938 struct sk_buff *msg;
3940 u8 next_hop[ETH_ALEN];
3942 memset(&pinfo, 0, sizeof(pinfo));
3944 if (!info->attrs[NL80211_ATTR_MAC])
3947 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3949 if (!rdev->ops->get_mpath)
3952 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3955 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
3959 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3963 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
3964 dev, dst, next_hop, &pinfo) < 0) {
3969 return genlmsg_reply(msg, info);
3972 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3975 struct net_device *dev = info->user_ptr[1];
3977 u8 *next_hop = NULL;
3979 if (!info->attrs[NL80211_ATTR_MAC])
3982 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3985 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3986 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3988 if (!rdev->ops->change_mpath)
3991 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3994 return rdev_change_mpath(rdev, dev, dst, next_hop);
3997 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4000 struct net_device *dev = info->user_ptr[1];
4002 u8 *next_hop = NULL;
4004 if (!info->attrs[NL80211_ATTR_MAC])
4007 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4010 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4011 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4013 if (!rdev->ops->add_mpath)
4016 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4019 return rdev_add_mpath(rdev, dev, dst, next_hop);
4022 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4025 struct net_device *dev = info->user_ptr[1];
4028 if (info->attrs[NL80211_ATTR_MAC])
4029 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4031 if (!rdev->ops->del_mpath)
4034 return rdev_del_mpath(rdev, dev, dst);
4037 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4040 struct net_device *dev = info->user_ptr[1];
4041 struct bss_parameters params;
4043 memset(¶ms, 0, sizeof(params));
4044 /* default to not changing parameters */
4045 params.use_cts_prot = -1;
4046 params.use_short_preamble = -1;
4047 params.use_short_slot_time = -1;
4048 params.ap_isolate = -1;
4049 params.ht_opmode = -1;
4050 params.p2p_ctwindow = -1;
4051 params.p2p_opp_ps = -1;
4053 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4054 params.use_cts_prot =
4055 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4056 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4057 params.use_short_preamble =
4058 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4059 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4060 params.use_short_slot_time =
4061 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
4062 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4063 params.basic_rates =
4064 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4065 params.basic_rates_len =
4066 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4068 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4069 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
4070 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4072 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
4074 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4075 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4077 params.p2p_ctwindow =
4078 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4079 if (params.p2p_ctwindow < 0)
4081 if (params.p2p_ctwindow != 0 &&
4082 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4086 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4089 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4091 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4094 params.p2p_opp_ps = tmp;
4095 if (params.p2p_opp_ps &&
4096 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4100 if (!rdev->ops->change_bss)
4103 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4104 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4107 return rdev_change_bss(rdev, dev, ¶ms);
4110 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
4111 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4112 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4113 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4114 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4115 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4116 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4119 static int parse_reg_rule(struct nlattr *tb[],
4120 struct ieee80211_reg_rule *reg_rule)
4122 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
4123 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
4125 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4127 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4129 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4131 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4133 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4136 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4138 freq_range->start_freq_khz =
4139 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4140 freq_range->end_freq_khz =
4141 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4142 freq_range->max_bandwidth_khz =
4143 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4145 power_rule->max_eirp =
4146 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4148 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4149 power_rule->max_antenna_gain =
4150 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4155 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4159 enum nl80211_user_reg_hint_type user_reg_hint_type;
4162 * You should only get this when cfg80211 hasn't yet initialized
4163 * completely when built-in to the kernel right between the time
4164 * window between nl80211_init() and regulatory_init(), if that is
4167 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
4168 return -EINPROGRESS;
4170 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4173 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4175 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4176 user_reg_hint_type =
4177 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4179 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4181 switch (user_reg_hint_type) {
4182 case NL80211_USER_REG_HINT_USER:
4183 case NL80211_USER_REG_HINT_CELL_BASE:
4189 r = regulatory_hint_user(data, user_reg_hint_type);
4194 static int nl80211_get_mesh_config(struct sk_buff *skb,
4195 struct genl_info *info)
4197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4198 struct net_device *dev = info->user_ptr[1];
4199 struct wireless_dev *wdev = dev->ieee80211_ptr;
4200 struct mesh_config cur_params;
4203 struct nlattr *pinfoattr;
4204 struct sk_buff *msg;
4206 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4209 if (!rdev->ops->get_mesh_config)
4213 /* If not connected, get default parameters */
4214 if (!wdev->mesh_id_len)
4215 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4217 err = rdev_get_mesh_config(rdev, dev, &cur_params);
4223 /* Draw up a netlink message to send back */
4224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4227 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4228 NL80211_CMD_GET_MESH_CONFIG);
4231 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
4233 goto nla_put_failure;
4234 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4235 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4236 cur_params.dot11MeshRetryTimeout) ||
4237 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4238 cur_params.dot11MeshConfirmTimeout) ||
4239 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4240 cur_params.dot11MeshHoldingTimeout) ||
4241 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4242 cur_params.dot11MeshMaxPeerLinks) ||
4243 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4244 cur_params.dot11MeshMaxRetries) ||
4245 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4246 cur_params.dot11MeshTTL) ||
4247 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4248 cur_params.element_ttl) ||
4249 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4250 cur_params.auto_open_plinks) ||
4251 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4252 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
4253 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4254 cur_params.dot11MeshHWMPmaxPREQretries) ||
4255 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4256 cur_params.path_refresh_time) ||
4257 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4258 cur_params.min_discovery_timeout) ||
4259 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4260 cur_params.dot11MeshHWMPactivePathTimeout) ||
4261 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4262 cur_params.dot11MeshHWMPpreqMinInterval) ||
4263 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4264 cur_params.dot11MeshHWMPperrMinInterval) ||
4265 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4266 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4267 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4268 cur_params.dot11MeshHWMPRootMode) ||
4269 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4270 cur_params.dot11MeshHWMPRannInterval) ||
4271 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4272 cur_params.dot11MeshGateAnnouncementProtocol) ||
4273 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4274 cur_params.dot11MeshForwarding) ||
4275 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
4276 cur_params.rssi_threshold) ||
4277 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
4278 cur_params.ht_opmode) ||
4279 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4280 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4281 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4282 cur_params.dot11MeshHWMProotInterval) ||
4283 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4284 cur_params.dot11MeshHWMPconfirmationInterval) ||
4285 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4286 cur_params.power_mode) ||
4287 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4288 cur_params.dot11MeshAwakeWindowDuration))
4289 goto nla_put_failure;
4290 nla_nest_end(msg, pinfoattr);
4291 genlmsg_end(msg, hdr);
4292 return genlmsg_reply(msg, info);
4295 genlmsg_cancel(msg, hdr);
4301 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
4302 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4303 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4304 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4305 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4306 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4307 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
4308 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
4309 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
4310 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
4311 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4312 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4313 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4314 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4315 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
4316 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
4317 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
4318 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
4319 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
4320 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
4321 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
4322 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4323 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
4324 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4325 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
4326 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
4327 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4328 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
4331 static const struct nla_policy
4332 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
4333 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
4334 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4335 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
4336 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
4337 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
4338 .len = IEEE80211_MAX_DATA_LEN },
4339 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
4342 static int nl80211_parse_mesh_config(struct genl_info *info,
4343 struct mesh_config *cfg,
4346 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
4349 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4352 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4354 cfg->param = fn(tb[attr]); \
4355 mask |= (1 << (attr - 1)); \
4360 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
4362 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
4363 info->attrs[NL80211_ATTR_MESH_CONFIG],
4364 nl80211_meshconf_params_policy))
4367 /* This makes sure that there aren't more than 32 mesh config
4368 * parameters (otherwise our bitfield scheme would not work.) */
4369 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4371 /* Fill in the params struct */
4372 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
4373 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4375 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
4376 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
4379 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4381 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
4382 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4384 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
4385 mask, NL80211_MESHCONF_MAX_RETRIES,
4387 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
4388 mask, NL80211_MESHCONF_TTL, nla_get_u8);
4389 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
4390 mask, NL80211_MESHCONF_ELEMENT_TTL,
4392 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
4393 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4395 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4397 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4399 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
4400 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4402 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
4403 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4405 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
4406 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4408 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4410 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4412 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
4414 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4416 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
4418 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4420 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4421 dot11MeshHWMPnetDiameterTraversalTime,
4423 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4425 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4426 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4428 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4429 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4431 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4432 dot11MeshGateAnnouncementProtocol, 0, 1,
4433 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
4436 mask, NL80211_MESHCONF_FORWARDING,
4438 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
4439 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4441 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
4442 mask, NL80211_MESHCONF_HT_OPMODE,
4444 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
4446 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4448 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
4449 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4451 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4452 dot11MeshHWMPconfirmationInterval,
4454 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4456 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4457 NL80211_MESH_POWER_ACTIVE,
4458 NL80211_MESH_POWER_MAX,
4459 mask, NL80211_MESHCONF_POWER_MODE,
4461 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4463 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
4469 #undef FILL_IN_MESH_PARAM_IF_SET
4472 static int nl80211_parse_mesh_setup(struct genl_info *info,
4473 struct mesh_setup *setup)
4475 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4477 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4479 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4480 info->attrs[NL80211_ATTR_MESH_SETUP],
4481 nl80211_mesh_setup_params_policy))
4484 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4485 setup->sync_method =
4486 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4487 IEEE80211_SYNC_METHOD_VENDOR :
4488 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4490 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4491 setup->path_sel_proto =
4492 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4493 IEEE80211_PATH_PROTOCOL_VENDOR :
4494 IEEE80211_PATH_PROTOCOL_HWMP;
4496 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4497 setup->path_metric =
4498 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4499 IEEE80211_PATH_METRIC_VENDOR :
4500 IEEE80211_PATH_METRIC_AIRTIME;
4503 if (tb[NL80211_MESH_SETUP_IE]) {
4504 struct nlattr *ieattr =
4505 tb[NL80211_MESH_SETUP_IE];
4506 if (!is_valid_ie_attr(ieattr))
4508 setup->ie = nla_data(ieattr);
4509 setup->ie_len = nla_len(ieattr);
4511 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4512 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
4517 static int nl80211_update_mesh_config(struct sk_buff *skb,
4518 struct genl_info *info)
4520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4521 struct net_device *dev = info->user_ptr[1];
4522 struct wireless_dev *wdev = dev->ieee80211_ptr;
4523 struct mesh_config cfg;
4527 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4530 if (!rdev->ops->update_mesh_config)
4533 err = nl80211_parse_mesh_config(info, &cfg, &mask);
4538 if (!wdev->mesh_id_len)
4542 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
4549 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4551 const struct ieee80211_regdomain *regdom;
4552 struct sk_buff *msg;
4554 struct nlattr *nl_reg_rules;
4558 mutex_lock(&cfg80211_mutex);
4560 if (!cfg80211_regdomain)
4563 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4569 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4570 NL80211_CMD_GET_REG);
4574 if (reg_last_request_cell_base() &&
4575 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4576 NL80211_USER_REG_HINT_CELL_BASE))
4577 goto nla_put_failure;
4580 regdom = rcu_dereference(cfg80211_regdomain);
4582 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4583 (regdom->dfs_region &&
4584 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4585 goto nla_put_failure_rcu;
4587 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4589 goto nla_put_failure_rcu;
4591 for (i = 0; i < regdom->n_reg_rules; i++) {
4592 struct nlattr *nl_reg_rule;
4593 const struct ieee80211_reg_rule *reg_rule;
4594 const struct ieee80211_freq_range *freq_range;
4595 const struct ieee80211_power_rule *power_rule;
4597 reg_rule = ®dom->reg_rules[i];
4598 freq_range = ®_rule->freq_range;
4599 power_rule = ®_rule->power_rule;
4601 nl_reg_rule = nla_nest_start(msg, i);
4603 goto nla_put_failure_rcu;
4605 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4607 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4608 freq_range->start_freq_khz) ||
4609 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4610 freq_range->end_freq_khz) ||
4611 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4612 freq_range->max_bandwidth_khz) ||
4613 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4614 power_rule->max_antenna_gain) ||
4615 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4616 power_rule->max_eirp))
4617 goto nla_put_failure_rcu;
4619 nla_nest_end(msg, nl_reg_rule);
4623 nla_nest_end(msg, nl_reg_rules);
4625 genlmsg_end(msg, hdr);
4626 err = genlmsg_reply(msg, info);
4629 nla_put_failure_rcu:
4632 genlmsg_cancel(msg, hdr);
4637 mutex_unlock(&cfg80211_mutex);
4641 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4643 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4644 struct nlattr *nl_reg_rule;
4645 char *alpha2 = NULL;
4646 int rem_reg_rules = 0, r = 0;
4647 u32 num_rules = 0, rule_idx = 0, size_of_regd;
4649 struct ieee80211_regdomain *rd = NULL;
4651 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4654 if (!info->attrs[NL80211_ATTR_REG_RULES])
4657 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4659 if (info->attrs[NL80211_ATTR_DFS_REGION])
4660 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4662 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4665 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
4669 size_of_regd = sizeof(struct ieee80211_regdomain) +
4670 num_rules * sizeof(struct ieee80211_reg_rule);
4672 rd = kzalloc(size_of_regd, GFP_KERNEL);
4676 rd->n_reg_rules = num_rules;
4677 rd->alpha2[0] = alpha2[0];
4678 rd->alpha2[1] = alpha2[1];
4681 * Disable DFS master mode if the DFS region was
4682 * not supported or known on this kernel.
4684 if (reg_supported_dfs_region(dfs_region))
4685 rd->dfs_region = dfs_region;
4687 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4689 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4690 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4692 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4698 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4704 mutex_lock(&cfg80211_mutex);
4707 /* set_regdom took ownership */
4709 mutex_unlock(&cfg80211_mutex);
4716 static int validate_scan_freqs(struct nlattr *freqs)
4718 struct nlattr *attr1, *attr2;
4719 int n_channels = 0, tmp1, tmp2;
4721 nla_for_each_nested(attr1, freqs, tmp1) {
4724 * Some hardware has a limited channel list for
4725 * scanning, and it is pretty much nonsensical
4726 * to scan for a channel twice, so disallow that
4727 * and don't require drivers to check that the
4728 * channel list they get isn't longer than what
4729 * they can scan, as long as they can scan all
4730 * the channels they registered at once.
4732 nla_for_each_nested(attr2, freqs, tmp2)
4733 if (attr1 != attr2 &&
4734 nla_get_u32(attr1) == nla_get_u32(attr2))
4741 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4744 struct wireless_dev *wdev = info->user_ptr[1];
4745 struct cfg80211_scan_request *request;
4746 struct nlattr *attr;
4747 struct wiphy *wiphy;
4748 int err, tmp, n_ssids = 0, n_channels, i;
4751 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4754 wiphy = &rdev->wiphy;
4756 if (!rdev->ops->scan)
4762 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4763 n_channels = validate_scan_freqs(
4764 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4768 enum ieee80211_band band;
4771 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4772 if (wiphy->bands[band])
4773 n_channels += wiphy->bands[band]->n_channels;
4776 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4777 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4780 if (n_ssids > wiphy->max_scan_ssids)
4783 if (info->attrs[NL80211_ATTR_IE])
4784 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4788 if (ie_len > wiphy->max_scan_ie_len)
4791 request = kzalloc(sizeof(*request)
4792 + sizeof(*request->ssids) * n_ssids
4793 + sizeof(*request->channels) * n_channels
4794 + ie_len, GFP_KERNEL);
4799 request->ssids = (void *)&request->channels[n_channels];
4800 request->n_ssids = n_ssids;
4803 request->ie = (void *)(request->ssids + n_ssids);
4805 request->ie = (void *)(request->channels + n_channels);
4809 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4810 /* user specified, bail out if channel not found */
4811 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
4812 struct ieee80211_channel *chan;
4814 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4821 /* ignore disabled channels */
4822 if (chan->flags & IEEE80211_CHAN_DISABLED)
4825 request->channels[i] = chan;
4829 enum ieee80211_band band;
4832 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4834 if (!wiphy->bands[band])
4836 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4837 struct ieee80211_channel *chan;
4839 chan = &wiphy->bands[band]->channels[j];
4841 if (chan->flags & IEEE80211_CHAN_DISABLED)
4844 request->channels[i] = chan;
4855 request->n_channels = i;
4858 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4859 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
4860 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
4864 request->ssids[i].ssid_len = nla_len(attr);
4865 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
4870 if (info->attrs[NL80211_ATTR_IE]) {
4871 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4872 memcpy((void *)request->ie,
4873 nla_data(info->attrs[NL80211_ATTR_IE]),
4877 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4878 if (wiphy->bands[i])
4880 (1 << wiphy->bands[i]->n_bitrates) - 1;
4882 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4883 nla_for_each_nested(attr,
4884 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4886 enum ieee80211_band band = nla_type(attr);
4888 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
4892 err = ieee80211_get_ratemask(wiphy->bands[band],
4895 &request->rates[band]);
4901 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
4902 request->flags = nla_get_u32(
4903 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
4904 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
4905 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
4906 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
4907 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
4914 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4916 request->wdev = wdev;
4917 request->wiphy = &rdev->wiphy;
4918 request->scan_start = jiffies;
4920 rdev->scan_req = request;
4921 err = rdev_scan(rdev, request);
4924 nl80211_send_scan_start(rdev, wdev);
4926 dev_hold(wdev->netdev);
4929 rdev->scan_req = NULL;
4936 static int nl80211_start_sched_scan(struct sk_buff *skb,
4937 struct genl_info *info)
4939 struct cfg80211_sched_scan_request *request;
4940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4941 struct net_device *dev = info->user_ptr[1];
4942 struct nlattr *attr;
4943 struct wiphy *wiphy;
4944 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
4946 enum ieee80211_band band;
4948 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
4950 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4951 !rdev->ops->sched_scan_start)
4954 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4957 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4960 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4964 wiphy = &rdev->wiphy;
4966 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4967 n_channels = validate_scan_freqs(
4968 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4974 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4975 if (wiphy->bands[band])
4976 n_channels += wiphy->bands[band]->n_channels;
4979 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4980 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4984 if (n_ssids > wiphy->max_sched_scan_ssids)
4987 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4988 nla_for_each_nested(attr,
4989 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4993 if (n_match_sets > wiphy->max_match_sets)
4996 if (info->attrs[NL80211_ATTR_IE])
4997 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5001 if (ie_len > wiphy->max_sched_scan_ie_len)
5004 mutex_lock(&rdev->sched_scan_mtx);
5006 if (rdev->sched_scan_req) {
5011 request = kzalloc(sizeof(*request)
5012 + sizeof(*request->ssids) * n_ssids
5013 + sizeof(*request->match_sets) * n_match_sets
5014 + sizeof(*request->channels) * n_channels
5015 + ie_len, GFP_KERNEL);
5022 request->ssids = (void *)&request->channels[n_channels];
5023 request->n_ssids = n_ssids;
5026 request->ie = (void *)(request->ssids + n_ssids);
5028 request->ie = (void *)(request->channels + n_channels);
5033 request->match_sets = (void *)(request->ie + ie_len);
5034 else if (request->ssids)
5035 request->match_sets =
5036 (void *)(request->ssids + n_ssids);
5038 request->match_sets =
5039 (void *)(request->channels + n_channels);
5041 request->n_match_sets = n_match_sets;
5044 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5045 /* user specified, bail out if channel not found */
5046 nla_for_each_nested(attr,
5047 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5049 struct ieee80211_channel *chan;
5051 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5058 /* ignore disabled channels */
5059 if (chan->flags & IEEE80211_CHAN_DISABLED)
5062 request->channels[i] = chan;
5067 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5069 if (!wiphy->bands[band])
5071 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5072 struct ieee80211_channel *chan;
5074 chan = &wiphy->bands[band]->channels[j];
5076 if (chan->flags & IEEE80211_CHAN_DISABLED)
5079 request->channels[i] = chan;
5090 request->n_channels = i;
5093 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5094 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5096 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
5100 request->ssids[i].ssid_len = nla_len(attr);
5101 memcpy(request->ssids[i].ssid, nla_data(attr),
5108 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5109 nla_for_each_nested(attr,
5110 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5112 struct nlattr *ssid, *rssi;
5114 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5115 nla_data(attr), nla_len(attr),
5116 nl80211_match_policy);
5117 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
5119 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5123 memcpy(request->match_sets[i].ssid.ssid,
5124 nla_data(ssid), nla_len(ssid));
5125 request->match_sets[i].ssid.ssid_len =
5128 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5130 request->rssi_thold = nla_get_u32(rssi);
5132 request->rssi_thold =
5133 NL80211_SCAN_RSSI_THOLD_OFF;
5138 if (info->attrs[NL80211_ATTR_IE]) {
5139 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5140 memcpy((void *)request->ie,
5141 nla_data(info->attrs[NL80211_ATTR_IE]),
5145 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
5146 request->flags = nla_get_u32(
5147 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
5148 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5149 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5150 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5151 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
5158 request->wiphy = &rdev->wiphy;
5159 request->interval = interval;
5160 request->scan_start = jiffies;
5162 err = rdev_sched_scan_start(rdev, dev, request);
5164 rdev->sched_scan_req = request;
5165 nl80211_send_sched_scan(rdev, dev,
5166 NL80211_CMD_START_SCHED_SCAN);
5173 mutex_unlock(&rdev->sched_scan_mtx);
5177 static int nl80211_stop_sched_scan(struct sk_buff *skb,
5178 struct genl_info *info)
5180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5183 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5184 !rdev->ops->sched_scan_stop)
5187 mutex_lock(&rdev->sched_scan_mtx);
5188 err = __cfg80211_stop_sched_scan(rdev, false);
5189 mutex_unlock(&rdev->sched_scan_mtx);
5194 static int nl80211_start_radar_detection(struct sk_buff *skb,
5195 struct genl_info *info)
5197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5198 struct net_device *dev = info->user_ptr[1];
5199 struct wireless_dev *wdev = dev->ieee80211_ptr;
5200 struct cfg80211_chan_def chandef;
5203 err = nl80211_parse_chandef(rdev, info, &chandef);
5207 if (wdev->cac_started)
5210 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5217 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5220 if (!rdev->ops->start_radar_detection)
5223 mutex_lock(&rdev->devlist_mtx);
5224 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5225 chandef.chan, CHAN_MODE_SHARED,
5226 BIT(chandef.width));
5230 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5232 wdev->channel = chandef.chan;
5233 wdev->cac_started = true;
5234 wdev->cac_start_time = jiffies;
5237 mutex_unlock(&rdev->devlist_mtx);
5242 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5244 struct cfg80211_registered_device *rdev,
5245 struct wireless_dev *wdev,
5246 struct cfg80211_internal_bss *intbss)
5248 struct cfg80211_bss *res = &intbss->pub;
5249 const struct cfg80211_bss_ies *ies;
5254 ASSERT_WDEV_LOCK(wdev);
5256 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5257 NL80211_CMD_NEW_SCAN_RESULTS);
5261 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5263 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5264 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5265 goto nla_put_failure;
5267 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5269 goto nla_put_failure;
5270 if ((!is_zero_ether_addr(res->bssid) &&
5271 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
5272 goto nla_put_failure;
5275 ies = rcu_dereference(res->ies);
5277 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5278 goto fail_unlock_rcu;
5280 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5281 ies->len, ies->data))
5282 goto fail_unlock_rcu;
5284 ies = rcu_dereference(res->beacon_ies);
5286 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5287 goto fail_unlock_rcu;
5288 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5289 ies->len, ies->data))
5290 goto fail_unlock_rcu;
5294 if (res->beacon_interval &&
5295 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5296 goto nla_put_failure;
5297 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5298 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5299 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5300 jiffies_to_msecs(jiffies - intbss->ts)))
5301 goto nla_put_failure;
5303 switch (rdev->wiphy.signal_type) {
5304 case CFG80211_SIGNAL_TYPE_MBM:
5305 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5306 goto nla_put_failure;
5308 case CFG80211_SIGNAL_TYPE_UNSPEC:
5309 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5310 goto nla_put_failure;
5316 switch (wdev->iftype) {
5317 case NL80211_IFTYPE_P2P_CLIENT:
5318 case NL80211_IFTYPE_STATION:
5319 if (intbss == wdev->current_bss &&
5320 nla_put_u32(msg, NL80211_BSS_STATUS,
5321 NL80211_BSS_STATUS_ASSOCIATED))
5322 goto nla_put_failure;
5324 case NL80211_IFTYPE_ADHOC:
5325 if (intbss == wdev->current_bss &&
5326 nla_put_u32(msg, NL80211_BSS_STATUS,
5327 NL80211_BSS_STATUS_IBSS_JOINED))
5328 goto nla_put_failure;
5334 nla_nest_end(msg, bss);
5336 return genlmsg_end(msg, hdr);
5341 genlmsg_cancel(msg, hdr);
5345 static int nl80211_dump_scan(struct sk_buff *skb,
5346 struct netlink_callback *cb)
5348 struct cfg80211_registered_device *rdev;
5349 struct net_device *dev;
5350 struct cfg80211_internal_bss *scan;
5351 struct wireless_dev *wdev;
5352 int start = cb->args[1], idx = 0;
5355 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5359 wdev = dev->ieee80211_ptr;
5362 spin_lock_bh(&rdev->bss_lock);
5363 cfg80211_bss_expire(rdev);
5365 cb->seq = rdev->bss_generation;
5367 list_for_each_entry(scan, &rdev->bss_list, list) {
5370 if (nl80211_send_bss(skb, cb,
5371 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5372 rdev, wdev, scan) < 0) {
5378 spin_unlock_bh(&rdev->bss_lock);
5382 nl80211_finish_netdev_dump(rdev);
5387 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
5388 int flags, struct net_device *dev,
5389 struct survey_info *survey)
5392 struct nlattr *infoattr;
5394 hdr = nl80211hdr_put(msg, portid, seq, flags,
5395 NL80211_CMD_NEW_SURVEY_RESULTS);
5399 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5400 goto nla_put_failure;
5402 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5404 goto nla_put_failure;
5406 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5407 survey->channel->center_freq))
5408 goto nla_put_failure;
5410 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5411 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5412 goto nla_put_failure;
5413 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5414 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5415 goto nla_put_failure;
5416 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5417 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5418 survey->channel_time))
5419 goto nla_put_failure;
5420 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5421 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5422 survey->channel_time_busy))
5423 goto nla_put_failure;
5424 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5425 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5426 survey->channel_time_ext_busy))
5427 goto nla_put_failure;
5428 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5429 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5430 survey->channel_time_rx))
5431 goto nla_put_failure;
5432 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5433 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5434 survey->channel_time_tx))
5435 goto nla_put_failure;
5437 nla_nest_end(msg, infoattr);
5439 return genlmsg_end(msg, hdr);
5442 genlmsg_cancel(msg, hdr);
5446 static int nl80211_dump_survey(struct sk_buff *skb,
5447 struct netlink_callback *cb)
5449 struct survey_info survey;
5450 struct cfg80211_registered_device *dev;
5451 struct net_device *netdev;
5452 int survey_idx = cb->args[1];
5455 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5459 if (!dev->ops->dump_survey) {
5465 struct ieee80211_channel *chan;
5467 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
5473 /* Survey without a channel doesn't make sense */
5474 if (!survey.channel) {
5479 chan = ieee80211_get_channel(&dev->wiphy,
5480 survey.channel->center_freq);
5481 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5486 if (nl80211_send_survey(skb,
5487 NETLINK_CB(cb->skb).portid,
5488 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5496 cb->args[1] = survey_idx;
5499 nl80211_finish_netdev_dump(dev);
5503 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5505 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5506 NL80211_WPA_VERSION_2));
5509 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5512 struct net_device *dev = info->user_ptr[1];
5513 struct ieee80211_channel *chan;
5514 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5515 int err, ssid_len, ie_len = 0, sae_data_len = 0;
5516 enum nl80211_auth_type auth_type;
5517 struct key_parse key;
5518 bool local_state_change;
5520 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5523 if (!info->attrs[NL80211_ATTR_MAC])
5526 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5529 if (!info->attrs[NL80211_ATTR_SSID])
5532 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5535 err = nl80211_parse_key(info, &key);
5540 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5542 if (!key.p.key || !key.p.key_len)
5544 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5545 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5546 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5547 key.p.key_len != WLAN_KEY_LEN_WEP104))
5559 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5560 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5569 if (!rdev->ops->auth)
5572 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5573 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5576 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5577 chan = ieee80211_get_channel(&rdev->wiphy,
5578 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5579 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5582 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5583 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5585 if (info->attrs[NL80211_ATTR_IE]) {
5586 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5587 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5590 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5591 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
5594 if (auth_type == NL80211_AUTHTYPE_SAE &&
5595 !info->attrs[NL80211_ATTR_SAE_DATA])
5598 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5599 if (auth_type != NL80211_AUTHTYPE_SAE)
5601 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5602 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5603 /* need to include at least Auth Transaction and Status Code */
5604 if (sae_data_len < 4)
5608 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5611 * Since we no longer track auth state, ignore
5612 * requests to only change local state.
5614 if (local_state_change)
5617 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5618 ssid, ssid_len, ie, ie_len,
5619 key.p.key, key.p.key_len, key.idx,
5620 sae_data, sae_data_len);
5623 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5624 struct genl_info *info,
5625 struct cfg80211_crypto_settings *settings,
5628 memset(settings, 0, sizeof(*settings));
5630 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5632 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5634 proto = nla_get_u16(
5635 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5636 settings->control_port_ethertype = cpu_to_be16(proto);
5637 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5640 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5641 settings->control_port_no_encrypt = true;
5643 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5645 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5649 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5650 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5651 settings->n_ciphers_pairwise = len / sizeof(u32);
5653 if (len % sizeof(u32))
5656 if (settings->n_ciphers_pairwise > cipher_limit)
5659 memcpy(settings->ciphers_pairwise, data, len);
5661 for (i = 0; i < settings->n_ciphers_pairwise; i++)
5662 if (!cfg80211_supported_cipher_suite(
5664 settings->ciphers_pairwise[i]))
5668 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5669 settings->cipher_group =
5670 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
5671 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5672 settings->cipher_group))
5676 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5677 settings->wpa_versions =
5678 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5679 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5683 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5687 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5688 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5689 settings->n_akm_suites = len / sizeof(u32);
5691 if (len % sizeof(u32))
5694 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5697 memcpy(settings->akm_suites, data, len);
5703 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5705 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5706 struct net_device *dev = info->user_ptr[1];
5707 struct cfg80211_crypto_settings crypto;
5708 struct ieee80211_channel *chan;
5709 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
5710 int err, ssid_len, ie_len = 0;
5711 bool use_mfp = false;
5713 struct ieee80211_ht_cap *ht_capa = NULL;
5714 struct ieee80211_ht_cap *ht_capa_mask = NULL;
5716 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5719 if (!info->attrs[NL80211_ATTR_MAC] ||
5720 !info->attrs[NL80211_ATTR_SSID] ||
5721 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5724 if (!rdev->ops->assoc)
5727 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5728 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5731 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5733 chan = ieee80211_get_channel(&rdev->wiphy,
5734 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5735 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5738 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5739 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5741 if (info->attrs[NL80211_ATTR_IE]) {
5742 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5743 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5746 if (info->attrs[NL80211_ATTR_USE_MFP]) {
5747 enum nl80211_mfp mfp =
5748 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
5749 if (mfp == NL80211_MFP_REQUIRED)
5751 else if (mfp != NL80211_MFP_NO)
5755 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5756 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5758 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5759 flags |= ASSOC_REQ_DISABLE_HT;
5761 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5763 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5765 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5768 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5771 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
5773 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5774 ssid, ssid_len, ie, ie_len, use_mfp,
5775 &crypto, flags, ht_capa,
5781 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5784 struct net_device *dev = info->user_ptr[1];
5785 const u8 *ie = NULL, *bssid;
5788 bool local_state_change;
5790 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5793 if (!info->attrs[NL80211_ATTR_MAC])
5796 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5799 if (!rdev->ops->deauth)
5802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5803 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5806 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5808 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5809 if (reason_code == 0) {
5810 /* Reason Code 0 is reserved */
5814 if (info->attrs[NL80211_ATTR_IE]) {
5815 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5816 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5819 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5821 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5822 local_state_change);
5825 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5828 struct net_device *dev = info->user_ptr[1];
5829 const u8 *ie = NULL, *bssid;
5832 bool local_state_change;
5834 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5837 if (!info->attrs[NL80211_ATTR_MAC])
5840 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5843 if (!rdev->ops->disassoc)
5846 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5847 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5850 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5852 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5853 if (reason_code == 0) {
5854 /* Reason Code 0 is reserved */
5858 if (info->attrs[NL80211_ATTR_IE]) {
5859 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5860 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5863 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5865 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5866 local_state_change);
5870 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5871 int mcast_rate[IEEE80211_NUM_BANDS],
5874 struct wiphy *wiphy = &rdev->wiphy;
5878 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5879 struct ieee80211_supported_band *sband;
5881 sband = wiphy->bands[band];
5885 for (i = 0; i < sband->n_bitrates; i++) {
5886 if (sband->bitrates[i].bitrate == rateval) {
5887 mcast_rate[band] = i + 1;
5897 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5900 struct net_device *dev = info->user_ptr[1];
5901 struct cfg80211_ibss_params ibss;
5902 struct wiphy *wiphy;
5903 struct cfg80211_cached_keys *connkeys = NULL;
5906 memset(&ibss, 0, sizeof(ibss));
5908 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5911 if (!info->attrs[NL80211_ATTR_SSID] ||
5912 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5915 ibss.beacon_interval = 100;
5917 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5918 ibss.beacon_interval =
5919 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5920 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5924 if (!rdev->ops->join_ibss)
5927 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5930 wiphy = &rdev->wiphy;
5932 if (info->attrs[NL80211_ATTR_MAC]) {
5933 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5935 if (!is_valid_ether_addr(ibss.bssid))
5938 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5939 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5941 if (info->attrs[NL80211_ATTR_IE]) {
5942 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5943 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5946 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
5950 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
5953 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
5955 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
5956 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
5959 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
5960 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5962 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5964 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5966 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5967 struct ieee80211_supported_band *sband =
5968 wiphy->bands[ibss.chandef.chan->band];
5970 err = ieee80211_get_ratemask(sband, rates, n_rates,
5976 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5977 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5978 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5981 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5984 connkeys = nl80211_parse_connkeys(rdev,
5985 info->attrs[NL80211_ATTR_KEYS],
5987 if (IS_ERR(connkeys))
5988 return PTR_ERR(connkeys);
5990 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
5998 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6000 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
6006 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6008 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6009 struct net_device *dev = info->user_ptr[1];
6011 if (!rdev->ops->leave_ibss)
6014 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6017 return cfg80211_leave_ibss(rdev, dev, false);
6020 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6023 struct net_device *dev = info->user_ptr[1];
6024 int mcast_rate[IEEE80211_NUM_BANDS];
6028 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6029 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6032 if (!rdev->ops->set_mcast_rate)
6035 memset(mcast_rate, 0, sizeof(mcast_rate));
6037 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6040 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6041 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6044 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6050 #ifdef CONFIG_NL80211_TESTMODE
6051 static struct genl_multicast_group nl80211_testmode_mcgrp = {
6055 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6060 if (!info->attrs[NL80211_ATTR_TESTDATA])
6064 if (rdev->ops->testmode_cmd) {
6065 rdev->testmode_info = info;
6066 err = rdev_testmode_cmd(rdev,
6067 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6068 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6069 rdev->testmode_info = NULL;
6075 static int nl80211_testmode_dump(struct sk_buff *skb,
6076 struct netlink_callback *cb)
6078 struct cfg80211_registered_device *rdev;
6086 * 0 is a valid index, but not valid for args[0],
6087 * so we need to offset by 1.
6089 phy_idx = cb->args[0] - 1;
6091 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6092 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6097 mutex_lock(&cfg80211_mutex);
6098 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6099 nl80211_fam.attrbuf);
6101 mutex_unlock(&cfg80211_mutex);
6102 return PTR_ERR(rdev);
6104 phy_idx = rdev->wiphy_idx;
6106 mutex_unlock(&cfg80211_mutex);
6108 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6110 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6114 data = nla_data((void *)cb->args[1]);
6115 data_len = nla_len((void *)cb->args[1]);
6118 mutex_lock(&cfg80211_mutex);
6119 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6121 mutex_unlock(&cfg80211_mutex);
6124 cfg80211_lock_rdev(rdev);
6125 mutex_unlock(&cfg80211_mutex);
6127 if (!rdev->ops->testmode_dump) {
6133 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
6134 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6135 NL80211_CMD_TESTMODE);
6136 struct nlattr *tmdata;
6138 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
6139 genlmsg_cancel(skb, hdr);
6143 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6145 genlmsg_cancel(skb, hdr);
6148 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
6149 nla_nest_end(skb, tmdata);
6151 if (err == -ENOBUFS || err == -ENOENT) {
6152 genlmsg_cancel(skb, hdr);
6155 genlmsg_cancel(skb, hdr);
6159 genlmsg_end(skb, hdr);
6164 cb->args[0] = phy_idx + 1;
6166 cfg80211_unlock_rdev(rdev);
6170 static struct sk_buff *
6171 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
6172 int approxlen, u32 portid, u32 seq, gfp_t gfp)
6174 struct sk_buff *skb;
6176 struct nlattr *data;
6178 skb = nlmsg_new(approxlen + 100, gfp);
6182 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
6188 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6189 goto nla_put_failure;
6190 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6192 ((void **)skb->cb)[0] = rdev;
6193 ((void **)skb->cb)[1] = hdr;
6194 ((void **)skb->cb)[2] = data;
6203 struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6206 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6208 if (WARN_ON(!rdev->testmode_info))
6211 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
6212 rdev->testmode_info->snd_portid,
6213 rdev->testmode_info->snd_seq,
6216 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6218 int cfg80211_testmode_reply(struct sk_buff *skb)
6220 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6221 void *hdr = ((void **)skb->cb)[1];
6222 struct nlattr *data = ((void **)skb->cb)[2];
6224 if (WARN_ON(!rdev->testmode_info)) {
6229 nla_nest_end(skb, data);
6230 genlmsg_end(skb, hdr);
6231 return genlmsg_reply(skb, rdev->testmode_info);
6233 EXPORT_SYMBOL(cfg80211_testmode_reply);
6235 struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6236 int approxlen, gfp_t gfp)
6238 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6240 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6242 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6244 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6246 void *hdr = ((void **)skb->cb)[1];
6247 struct nlattr *data = ((void **)skb->cb)[2];
6249 nla_nest_end(skb, data);
6250 genlmsg_end(skb, hdr);
6251 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6253 EXPORT_SYMBOL(cfg80211_testmode_event);
6256 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6259 struct net_device *dev = info->user_ptr[1];
6260 struct cfg80211_connect_params connect;
6261 struct wiphy *wiphy;
6262 struct cfg80211_cached_keys *connkeys = NULL;
6265 memset(&connect, 0, sizeof(connect));
6267 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6270 if (!info->attrs[NL80211_ATTR_SSID] ||
6271 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6274 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6276 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
6277 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6278 NL80211_CMD_CONNECT))
6281 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6283 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6285 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
6286 NL80211_MAX_NR_CIPHER_SUITES);
6290 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6291 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6294 wiphy = &rdev->wiphy;
6296 connect.bg_scan_period = -1;
6297 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6298 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6299 connect.bg_scan_period =
6300 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6303 if (info->attrs[NL80211_ATTR_MAC])
6304 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6305 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6306 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6308 if (info->attrs[NL80211_ATTR_IE]) {
6309 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6310 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6313 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6314 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6315 if (connect.mfp != NL80211_MFP_REQUIRED &&
6316 connect.mfp != NL80211_MFP_NO)
6319 connect.mfp = NL80211_MFP_NO;
6322 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6324 ieee80211_get_channel(wiphy,
6325 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6326 if (!connect.channel ||
6327 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6331 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6332 connkeys = nl80211_parse_connkeys(rdev,
6333 info->attrs[NL80211_ATTR_KEYS], NULL);
6334 if (IS_ERR(connkeys))
6335 return PTR_ERR(connkeys);
6338 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6339 connect.flags |= ASSOC_REQ_DISABLE_HT;
6341 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6342 memcpy(&connect.ht_capa_mask,
6343 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6344 sizeof(connect.ht_capa_mask));
6346 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6347 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6351 memcpy(&connect.ht_capa,
6352 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6353 sizeof(connect.ht_capa));
6356 err = cfg80211_connect(rdev, dev, &connect, connkeys);
6362 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6365 struct net_device *dev = info->user_ptr[1];
6368 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6369 reason = WLAN_REASON_DEAUTH_LEAVING;
6371 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6376 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6377 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6380 return cfg80211_disconnect(rdev, dev, reason, true);
6383 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6390 if (!info->attrs[NL80211_ATTR_PID])
6393 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6395 net = get_net_ns_by_pid(pid);
6397 return PTR_ERR(net);
6401 /* check if anything to do */
6402 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6403 err = cfg80211_switch_netns(rdev, net);
6409 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6412 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6413 struct cfg80211_pmksa *pmksa) = NULL;
6414 struct net_device *dev = info->user_ptr[1];
6415 struct cfg80211_pmksa pmksa;
6417 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6419 if (!info->attrs[NL80211_ATTR_MAC])
6422 if (!info->attrs[NL80211_ATTR_PMKID])
6425 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6426 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6428 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6429 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6432 switch (info->genlhdr->cmd) {
6433 case NL80211_CMD_SET_PMKSA:
6434 rdev_ops = rdev->ops->set_pmksa;
6436 case NL80211_CMD_DEL_PMKSA:
6437 rdev_ops = rdev->ops->del_pmksa;
6447 return rdev_ops(&rdev->wiphy, dev, &pmksa);
6450 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6453 struct net_device *dev = info->user_ptr[1];
6455 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6456 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6459 if (!rdev->ops->flush_pmksa)
6462 return rdev_flush_pmksa(rdev, dev);
6465 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6468 struct net_device *dev = info->user_ptr[1];
6469 u8 action_code, dialog_token;
6473 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6474 !rdev->ops->tdls_mgmt)
6477 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6478 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6479 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6480 !info->attrs[NL80211_ATTR_IE] ||
6481 !info->attrs[NL80211_ATTR_MAC])
6484 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6485 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6486 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6487 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6489 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6490 dialog_token, status_code,
6491 nla_data(info->attrs[NL80211_ATTR_IE]),
6492 nla_len(info->attrs[NL80211_ATTR_IE]));
6495 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6498 struct net_device *dev = info->user_ptr[1];
6499 enum nl80211_tdls_operation operation;
6502 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6503 !rdev->ops->tdls_oper)
6506 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6507 !info->attrs[NL80211_ATTR_MAC])
6510 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6511 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6513 return rdev_tdls_oper(rdev, dev, peer, operation);
6516 static int nl80211_remain_on_channel(struct sk_buff *skb,
6517 struct genl_info *info)
6519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6520 struct wireless_dev *wdev = info->user_ptr[1];
6521 struct cfg80211_chan_def chandef;
6522 struct sk_buff *msg;
6528 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6529 !info->attrs[NL80211_ATTR_DURATION])
6532 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6534 if (!rdev->ops->remain_on_channel ||
6535 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
6539 * We should be on that channel for at least a minimum amount of
6540 * time (10ms) but no longer than the driver supports.
6542 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6543 duration > rdev->wiphy.max_remain_on_channel_duration)
6546 err = nl80211_parse_chandef(rdev, info, &chandef);
6550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6554 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6555 NL80211_CMD_REMAIN_ON_CHANNEL);
6562 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6568 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6569 goto nla_put_failure;
6571 genlmsg_end(msg, hdr);
6573 return genlmsg_reply(msg, info);
6582 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6583 struct genl_info *info)
6585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6586 struct wireless_dev *wdev = info->user_ptr[1];
6589 if (!info->attrs[NL80211_ATTR_COOKIE])
6592 if (!rdev->ops->cancel_remain_on_channel)
6595 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6597 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
6600 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6601 u8 *rates, u8 rates_len)
6606 for (i = 0; i < rates_len; i++) {
6607 int rate = (rates[i] & 0x7f) * 5;
6609 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6610 struct ieee80211_rate *srate =
6611 &sband->bitrates[ridx];
6612 if (rate == srate->bitrate) {
6617 if (ridx == sband->n_bitrates)
6618 return 0; /* rate not found */
6624 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6625 u8 *rates, u8 rates_len,
6626 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6630 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6632 for (i = 0; i < rates_len; i++) {
6635 ridx = rates[i] / 8;
6636 rbit = BIT(rates[i] % 8);
6638 /* check validity */
6639 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
6642 /* check availability */
6643 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6652 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
6653 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6654 .len = NL80211_MAX_SUPP_RATES },
6655 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6656 .len = NL80211_MAX_SUPP_HT_RATES },
6659 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6660 struct genl_info *info)
6662 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
6663 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6664 struct cfg80211_bitrate_mask mask;
6666 struct net_device *dev = info->user_ptr[1];
6667 struct nlattr *tx_rates;
6668 struct ieee80211_supported_band *sband;
6670 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6673 if (!rdev->ops->set_bitrate_mask)
6676 memset(&mask, 0, sizeof(mask));
6677 /* Default to all rates enabled */
6678 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6679 sband = rdev->wiphy.bands[i];
6680 mask.control[i].legacy =
6681 sband ? (1 << sband->n_bitrates) - 1 : 0;
6683 memcpy(mask.control[i].mcs,
6684 sband->ht_cap.mcs.rx_mask,
6685 sizeof(mask.control[i].mcs));
6687 memset(mask.control[i].mcs, 0,
6688 sizeof(mask.control[i].mcs));
6692 * The nested attribute uses enum nl80211_band as the index. This maps
6693 * directly to the enum ieee80211_band values used in cfg80211.
6695 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
6696 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6698 enum ieee80211_band band = nla_type(tx_rates);
6699 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6701 sband = rdev->wiphy.bands[band];
6704 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6705 nla_len(tx_rates), nl80211_txattr_policy);
6706 if (tb[NL80211_TXRATE_LEGACY]) {
6707 mask.control[band].legacy = rateset_to_mask(
6709 nla_data(tb[NL80211_TXRATE_LEGACY]),
6710 nla_len(tb[NL80211_TXRATE_LEGACY]));
6711 if ((mask.control[band].legacy == 0) &&
6712 nla_len(tb[NL80211_TXRATE_LEGACY]))
6715 if (tb[NL80211_TXRATE_MCS]) {
6716 if (!ht_rateset_to_mask(
6718 nla_data(tb[NL80211_TXRATE_MCS]),
6719 nla_len(tb[NL80211_TXRATE_MCS]),
6720 mask.control[band].mcs))
6724 if (mask.control[band].legacy == 0) {
6725 /* don't allow empty legacy rates if HT
6726 * is not even supported. */
6727 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6730 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6731 if (mask.control[band].mcs[i])
6734 /* legacy and mcs rates may not be both empty */
6735 if (i == IEEE80211_HT_MCS_MASK_LEN)
6740 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
6743 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
6745 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6746 struct wireless_dev *wdev = info->user_ptr[1];
6747 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
6749 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6752 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6753 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
6755 switch (wdev->iftype) {
6756 case NL80211_IFTYPE_STATION:
6757 case NL80211_IFTYPE_ADHOC:
6758 case NL80211_IFTYPE_P2P_CLIENT:
6759 case NL80211_IFTYPE_AP:
6760 case NL80211_IFTYPE_AP_VLAN:
6761 case NL80211_IFTYPE_MESH_POINT:
6762 case NL80211_IFTYPE_P2P_GO:
6763 case NL80211_IFTYPE_P2P_DEVICE:
6769 /* not much point in registering if we can't reply */
6770 if (!rdev->ops->mgmt_tx)
6773 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
6774 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6775 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
6778 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
6780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6781 struct wireless_dev *wdev = info->user_ptr[1];
6782 struct cfg80211_chan_def chandef;
6786 struct sk_buff *msg = NULL;
6787 unsigned int wait = 0;
6788 bool offchan, no_cck, dont_wait_for_ack;
6790 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
6792 if (!info->attrs[NL80211_ATTR_FRAME])
6795 if (!rdev->ops->mgmt_tx)
6798 switch (wdev->iftype) {
6799 case NL80211_IFTYPE_STATION:
6800 case NL80211_IFTYPE_ADHOC:
6801 case NL80211_IFTYPE_P2P_CLIENT:
6802 case NL80211_IFTYPE_AP:
6803 case NL80211_IFTYPE_AP_VLAN:
6804 case NL80211_IFTYPE_MESH_POINT:
6805 case NL80211_IFTYPE_P2P_GO:
6806 case NL80211_IFTYPE_P2P_DEVICE:
6812 if (info->attrs[NL80211_ATTR_DURATION]) {
6813 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6815 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6818 * We should wait on the channel for at least a minimum amount
6819 * of time (10ms) but no longer than the driver supports.
6821 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6822 wait > rdev->wiphy.max_remain_on_channel_duration)
6827 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6829 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6832 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6834 err = nl80211_parse_chandef(rdev, info, &chandef);
6838 if (!dont_wait_for_ack) {
6839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6843 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6852 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
6853 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6854 nla_len(info->attrs[NL80211_ATTR_FRAME]),
6855 no_cck, dont_wait_for_ack, &cookie);
6860 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6861 goto nla_put_failure;
6863 genlmsg_end(msg, hdr);
6864 return genlmsg_reply(msg, info);
6876 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6879 struct wireless_dev *wdev = info->user_ptr[1];
6882 if (!info->attrs[NL80211_ATTR_COOKIE])
6885 if (!rdev->ops->mgmt_tx_cancel_wait)
6888 switch (wdev->iftype) {
6889 case NL80211_IFTYPE_STATION:
6890 case NL80211_IFTYPE_ADHOC:
6891 case NL80211_IFTYPE_P2P_CLIENT:
6892 case NL80211_IFTYPE_AP:
6893 case NL80211_IFTYPE_AP_VLAN:
6894 case NL80211_IFTYPE_P2P_GO:
6895 case NL80211_IFTYPE_P2P_DEVICE:
6901 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6903 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
6906 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6909 struct wireless_dev *wdev;
6910 struct net_device *dev = info->user_ptr[1];
6915 if (!info->attrs[NL80211_ATTR_PS_STATE])
6918 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6920 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6923 wdev = dev->ieee80211_ptr;
6925 if (!rdev->ops->set_power_mgmt)
6928 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6930 if (state == wdev->ps)
6933 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
6939 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6942 enum nl80211_ps_state ps_state;
6943 struct wireless_dev *wdev;
6944 struct net_device *dev = info->user_ptr[1];
6945 struct sk_buff *msg;
6949 wdev = dev->ieee80211_ptr;
6951 if (!rdev->ops->set_power_mgmt)
6954 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6958 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6959 NL80211_CMD_GET_POWER_SAVE);
6966 ps_state = NL80211_PS_ENABLED;
6968 ps_state = NL80211_PS_DISABLED;
6970 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6971 goto nla_put_failure;
6973 genlmsg_end(msg, hdr);
6974 return genlmsg_reply(msg, info);
6983 static struct nla_policy
6984 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6985 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6986 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6987 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6988 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6989 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6990 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
6993 static int nl80211_set_cqm_txe(struct genl_info *info,
6994 u32 rate, u32 pkts, u32 intvl)
6996 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6997 struct wireless_dev *wdev;
6998 struct net_device *dev = info->user_ptr[1];
7000 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
7003 wdev = dev->ieee80211_ptr;
7005 if (!rdev->ops->set_cqm_txe_config)
7008 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7009 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7012 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
7015 static int nl80211_set_cqm_rssi(struct genl_info *info,
7016 s32 threshold, u32 hysteresis)
7018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7019 struct wireless_dev *wdev;
7020 struct net_device *dev = info->user_ptr[1];
7025 wdev = dev->ieee80211_ptr;
7027 if (!rdev->ops->set_cqm_rssi_config)
7030 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7031 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7034 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
7037 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7039 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7043 cqm = info->attrs[NL80211_ATTR_CQM];
7049 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7050 nl80211_attr_cqm_policy);
7054 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7055 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7058 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7059 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7060 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
7061 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7062 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7063 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7064 u32 rate, pkts, intvl;
7065 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7066 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7067 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7068 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
7076 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7079 struct net_device *dev = info->user_ptr[1];
7080 struct mesh_config cfg;
7081 struct mesh_setup setup;
7084 /* start with default */
7085 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
7086 memcpy(&setup, &default_mesh_setup, sizeof(setup));
7088 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
7089 /* and parse parameters if given */
7090 err = nl80211_parse_mesh_config(info, &cfg, NULL);
7095 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7096 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7099 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7100 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7102 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7103 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7104 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7107 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7108 setup.beacon_interval =
7109 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7110 if (setup.beacon_interval < 10 ||
7111 setup.beacon_interval > 10000)
7115 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7117 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7118 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7122 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7123 /* parse additional setup parameters if given */
7124 err = nl80211_parse_mesh_setup(info, &setup);
7129 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7130 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7134 /* cfg80211_join_mesh() will sort it out */
7135 setup.chandef.chan = NULL;
7138 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
7141 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7144 struct net_device *dev = info->user_ptr[1];
7146 return cfg80211_leave_mesh(rdev, dev);
7150 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7151 struct cfg80211_registered_device *rdev)
7153 struct nlattr *nl_pats, *nl_pat;
7156 if (!rdev->wowlan->n_patterns)
7159 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7163 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7164 nl_pat = nla_nest_start(msg, i + 1);
7167 pat_len = rdev->wowlan->patterns[i].pattern_len;
7168 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7169 DIV_ROUND_UP(pat_len, 8),
7170 rdev->wowlan->patterns[i].mask) ||
7171 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7172 pat_len, rdev->wowlan->patterns[i].pattern) ||
7173 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7174 rdev->wowlan->patterns[i].pkt_offset))
7176 nla_nest_end(msg, nl_pat);
7178 nla_nest_end(msg, nl_pats);
7183 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7184 struct cfg80211_wowlan_tcp *tcp)
7186 struct nlattr *nl_tcp;
7191 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7195 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7196 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7197 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7198 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7199 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7200 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7201 tcp->payload_len, tcp->payload) ||
7202 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7203 tcp->data_interval) ||
7204 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7205 tcp->wake_len, tcp->wake_data) ||
7206 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7207 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7210 if (tcp->payload_seq.len &&
7211 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7212 sizeof(tcp->payload_seq), &tcp->payload_seq))
7215 if (tcp->payload_tok.len &&
7216 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7217 sizeof(tcp->payload_tok) + tcp->tokens_size,
7224 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7227 struct sk_buff *msg;
7229 u32 size = NLMSG_DEFAULT_SIZE;
7231 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7232 !rdev->wiphy.wowlan.tcp)
7235 if (rdev->wowlan && rdev->wowlan->tcp) {
7236 /* adjust size to have room for all the data */
7237 size += rdev->wowlan->tcp->tokens_size +
7238 rdev->wowlan->tcp->payload_len +
7239 rdev->wowlan->tcp->wake_len +
7240 rdev->wowlan->tcp->wake_len / 8;
7243 msg = nlmsg_new(size, GFP_KERNEL);
7247 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7248 NL80211_CMD_GET_WOWLAN);
7250 goto nla_put_failure;
7253 struct nlattr *nl_wowlan;
7255 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7257 goto nla_put_failure;
7259 if ((rdev->wowlan->any &&
7260 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7261 (rdev->wowlan->disconnect &&
7262 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7263 (rdev->wowlan->magic_pkt &&
7264 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7265 (rdev->wowlan->gtk_rekey_failure &&
7266 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7267 (rdev->wowlan->eap_identity_req &&
7268 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7269 (rdev->wowlan->four_way_handshake &&
7270 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7271 (rdev->wowlan->rfkill_release &&
7272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7273 goto nla_put_failure;
7275 if (nl80211_send_wowlan_patterns(msg, rdev))
7276 goto nla_put_failure;
7278 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7279 goto nla_put_failure;
7281 nla_nest_end(msg, nl_wowlan);
7284 genlmsg_end(msg, hdr);
7285 return genlmsg_reply(msg, info);
7292 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7293 struct nlattr *attr,
7294 struct cfg80211_wowlan *trig)
7296 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7297 struct cfg80211_wowlan_tcp *cfg;
7298 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7299 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7301 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7304 if (!rdev->wiphy.wowlan.tcp)
7307 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7308 nla_data(attr), nla_len(attr),
7309 nl80211_wowlan_tcp_policy);
7313 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7314 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7315 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7316 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7317 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7318 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7319 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7320 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7323 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7324 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7327 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7328 rdev->wiphy.wowlan.tcp->data_interval_max)
7331 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7332 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7335 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7336 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7339 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7340 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7342 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7343 tokens_size = tokln - sizeof(*tok);
7345 if (!tok->len || tokens_size % tok->len)
7347 if (!rdev->wiphy.wowlan.tcp->tok)
7349 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7351 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7353 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7355 if (tok->offset + tok->len > data_size)
7359 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7360 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7361 if (!rdev->wiphy.wowlan.tcp->seq)
7363 if (seq->len == 0 || seq->len > 4)
7365 if (seq->len + seq->offset > data_size)
7369 size = sizeof(*cfg);
7371 size += wake_size + wake_mask_size;
7372 size += tokens_size;
7374 cfg = kzalloc(size, GFP_KERNEL);
7377 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7378 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7379 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7381 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7382 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7386 /* allocate a socket and port for it and use it */
7387 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7388 IPPROTO_TCP, &cfg->sock, 1);
7393 if (inet_csk_get_port(cfg->sock->sk, port)) {
7394 sock_release(cfg->sock);
7398 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7404 cfg->src_port = port;
7407 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7408 cfg->payload_len = data_size;
7409 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7410 memcpy((void *)cfg->payload,
7411 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7414 cfg->payload_seq = *seq;
7415 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7416 cfg->wake_len = wake_size;
7417 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7418 memcpy((void *)cfg->wake_data,
7419 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7421 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7422 data_size + wake_size;
7423 memcpy((void *)cfg->wake_mask,
7424 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7427 cfg->tokens_size = tokens_size;
7428 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7436 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7439 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
7440 struct cfg80211_wowlan new_triggers = {};
7441 struct cfg80211_wowlan *ntrig;
7442 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7444 bool prev_enabled = rdev->wowlan;
7446 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7447 !rdev->wiphy.wowlan.tcp)
7450 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7451 cfg80211_rdev_free_wowlan(rdev);
7452 rdev->wowlan = NULL;
7456 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7457 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7458 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7459 nl80211_wowlan_policy);
7463 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7464 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7466 new_triggers.any = true;
7469 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7470 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7472 new_triggers.disconnect = true;
7475 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7476 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7478 new_triggers.magic_pkt = true;
7481 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7484 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7485 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7487 new_triggers.gtk_rekey_failure = true;
7490 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7491 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7493 new_triggers.eap_identity_req = true;
7496 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7497 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7499 new_triggers.four_way_handshake = true;
7502 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7503 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7505 new_triggers.rfkill_release = true;
7508 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7511 int rem, pat_len, mask_len, pkt_offset;
7512 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7514 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7517 if (n_patterns > wowlan->n_patterns)
7520 new_triggers.patterns = kcalloc(n_patterns,
7521 sizeof(new_triggers.patterns[0]),
7523 if (!new_triggers.patterns)
7526 new_triggers.n_patterns = n_patterns;
7529 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7531 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7532 nla_data(pat), nla_len(pat), NULL);
7534 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7535 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7537 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7538 mask_len = DIV_ROUND_UP(pat_len, 8);
7539 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7542 if (pat_len > wowlan->pattern_max_len ||
7543 pat_len < wowlan->pattern_min_len)
7546 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7549 pkt_offset = nla_get_u32(
7550 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7551 if (pkt_offset > wowlan->max_pkt_offset)
7553 new_triggers.patterns[i].pkt_offset = pkt_offset;
7555 new_triggers.patterns[i].mask =
7556 kmalloc(mask_len + pat_len, GFP_KERNEL);
7557 if (!new_triggers.patterns[i].mask) {
7561 new_triggers.patterns[i].pattern =
7562 new_triggers.patterns[i].mask + mask_len;
7563 memcpy(new_triggers.patterns[i].mask,
7564 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7566 new_triggers.patterns[i].pattern_len = pat_len;
7567 memcpy(new_triggers.patterns[i].pattern,
7568 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7574 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7575 err = nl80211_parse_wowlan_tcp(
7576 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7582 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7587 cfg80211_rdev_free_wowlan(rdev);
7588 rdev->wowlan = ntrig;
7591 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
7592 rdev_set_wakeup(rdev, rdev->wowlan);
7596 for (i = 0; i < new_triggers.n_patterns; i++)
7597 kfree(new_triggers.patterns[i].mask);
7598 kfree(new_triggers.patterns);
7599 if (new_triggers.tcp && new_triggers.tcp->sock)
7600 sock_release(new_triggers.tcp->sock);
7601 kfree(new_triggers.tcp);
7606 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7608 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7609 struct net_device *dev = info->user_ptr[1];
7610 struct wireless_dev *wdev = dev->ieee80211_ptr;
7611 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7612 struct cfg80211_gtk_rekey_data rekey_data;
7615 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7618 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7619 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7620 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7621 nl80211_rekey_policy);
7625 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7627 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7629 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7632 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7634 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7636 memcpy(rekey_data.replay_ctr,
7637 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7638 NL80211_REPLAY_CTR_LEN);
7641 if (!wdev->current_bss) {
7646 if (!rdev->ops->set_rekey_data) {
7651 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
7657 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7658 struct genl_info *info)
7660 struct net_device *dev = info->user_ptr[1];
7661 struct wireless_dev *wdev = dev->ieee80211_ptr;
7663 if (wdev->iftype != NL80211_IFTYPE_AP &&
7664 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7667 if (wdev->ap_unexpected_nlportid)
7670 wdev->ap_unexpected_nlportid = info->snd_portid;
7674 static int nl80211_probe_client(struct sk_buff *skb,
7675 struct genl_info *info)
7677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7678 struct net_device *dev = info->user_ptr[1];
7679 struct wireless_dev *wdev = dev->ieee80211_ptr;
7680 struct sk_buff *msg;
7686 if (wdev->iftype != NL80211_IFTYPE_AP &&
7687 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7690 if (!info->attrs[NL80211_ATTR_MAC])
7693 if (!rdev->ops->probe_client)
7696 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7700 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7701 NL80211_CMD_PROBE_CLIENT);
7708 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7710 err = rdev_probe_client(rdev, dev, addr, &cookie);
7714 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7715 goto nla_put_failure;
7717 genlmsg_end(msg, hdr);
7719 return genlmsg_reply(msg, info);
7728 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
7730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7731 struct cfg80211_beacon_registration *reg, *nreg;
7734 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
7737 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
7741 /* First, check if already registered. */
7742 spin_lock_bh(&rdev->beacon_registrations_lock);
7743 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
7744 if (reg->nlportid == info->snd_portid) {
7749 /* Add it to the list */
7750 nreg->nlportid = info->snd_portid;
7751 list_add(&nreg->list, &rdev->beacon_registrations);
7753 spin_unlock_bh(&rdev->beacon_registrations_lock);
7757 spin_unlock_bh(&rdev->beacon_registrations_lock);
7762 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
7764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7765 struct wireless_dev *wdev = info->user_ptr[1];
7768 if (!rdev->ops->start_p2p_device)
7771 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7774 if (wdev->p2p_started)
7777 mutex_lock(&rdev->devlist_mtx);
7778 err = cfg80211_can_add_interface(rdev, wdev->iftype);
7779 mutex_unlock(&rdev->devlist_mtx);
7783 err = rdev_start_p2p_device(rdev, wdev);
7787 wdev->p2p_started = true;
7788 mutex_lock(&rdev->devlist_mtx);
7790 mutex_unlock(&rdev->devlist_mtx);
7795 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
7797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7798 struct wireless_dev *wdev = info->user_ptr[1];
7800 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7803 if (!rdev->ops->stop_p2p_device)
7806 if (!wdev->p2p_started)
7809 rdev_stop_p2p_device(rdev, wdev);
7810 wdev->p2p_started = false;
7812 mutex_lock(&rdev->devlist_mtx);
7814 mutex_unlock(&rdev->devlist_mtx);
7816 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
7817 rdev->scan_req->aborted = true;
7818 ___cfg80211_scan_done(rdev, true);
7824 #define NL80211_FLAG_NEED_WIPHY 0x01
7825 #define NL80211_FLAG_NEED_NETDEV 0x02
7826 #define NL80211_FLAG_NEED_RTNL 0x04
7827 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
7828 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
7829 NL80211_FLAG_CHECK_NETDEV_UP)
7830 #define NL80211_FLAG_NEED_WDEV 0x10
7831 /* If a netdev is associated, it must be UP, P2P must be started */
7832 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
7833 NL80211_FLAG_CHECK_NETDEV_UP)
7835 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
7836 struct genl_info *info)
7838 struct cfg80211_registered_device *rdev;
7839 struct wireless_dev *wdev;
7840 struct net_device *dev;
7841 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
7846 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
7847 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7851 return PTR_ERR(rdev);
7853 info->user_ptr[0] = rdev;
7854 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
7855 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7856 mutex_lock(&cfg80211_mutex);
7857 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
7860 mutex_unlock(&cfg80211_mutex);
7863 return PTR_ERR(wdev);
7867 rdev = wiphy_to_dev(wdev->wiphy);
7869 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
7871 mutex_unlock(&cfg80211_mutex);
7877 info->user_ptr[1] = dev;
7879 info->user_ptr[1] = wdev;
7883 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
7884 !netif_running(dev)) {
7885 mutex_unlock(&cfg80211_mutex);
7892 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
7893 if (!wdev->p2p_started) {
7894 mutex_unlock(&cfg80211_mutex);
7901 cfg80211_lock_rdev(rdev);
7903 mutex_unlock(&cfg80211_mutex);
7905 info->user_ptr[0] = rdev;
7911 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
7912 struct genl_info *info)
7914 if (info->user_ptr[0])
7915 cfg80211_unlock_rdev(info->user_ptr[0]);
7916 if (info->user_ptr[1]) {
7917 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7918 struct wireless_dev *wdev = info->user_ptr[1];
7921 dev_put(wdev->netdev);
7923 dev_put(info->user_ptr[1]);
7926 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7930 static struct genl_ops nl80211_ops[] = {
7932 .cmd = NL80211_CMD_GET_WIPHY,
7933 .doit = nl80211_get_wiphy,
7934 .dumpit = nl80211_dump_wiphy,
7935 .policy = nl80211_policy,
7936 /* can be retrieved by unprivileged users */
7937 .internal_flags = NL80211_FLAG_NEED_WIPHY,
7940 .cmd = NL80211_CMD_SET_WIPHY,
7941 .doit = nl80211_set_wiphy,
7942 .policy = nl80211_policy,
7943 .flags = GENL_ADMIN_PERM,
7944 .internal_flags = NL80211_FLAG_NEED_RTNL,
7947 .cmd = NL80211_CMD_GET_INTERFACE,
7948 .doit = nl80211_get_interface,
7949 .dumpit = nl80211_dump_interface,
7950 .policy = nl80211_policy,
7951 /* can be retrieved by unprivileged users */
7952 .internal_flags = NL80211_FLAG_NEED_WDEV,
7955 .cmd = NL80211_CMD_SET_INTERFACE,
7956 .doit = nl80211_set_interface,
7957 .policy = nl80211_policy,
7958 .flags = GENL_ADMIN_PERM,
7959 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7960 NL80211_FLAG_NEED_RTNL,
7963 .cmd = NL80211_CMD_NEW_INTERFACE,
7964 .doit = nl80211_new_interface,
7965 .policy = nl80211_policy,
7966 .flags = GENL_ADMIN_PERM,
7967 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7968 NL80211_FLAG_NEED_RTNL,
7971 .cmd = NL80211_CMD_DEL_INTERFACE,
7972 .doit = nl80211_del_interface,
7973 .policy = nl80211_policy,
7974 .flags = GENL_ADMIN_PERM,
7975 .internal_flags = NL80211_FLAG_NEED_WDEV |
7976 NL80211_FLAG_NEED_RTNL,
7979 .cmd = NL80211_CMD_GET_KEY,
7980 .doit = nl80211_get_key,
7981 .policy = nl80211_policy,
7982 .flags = GENL_ADMIN_PERM,
7983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7984 NL80211_FLAG_NEED_RTNL,
7987 .cmd = NL80211_CMD_SET_KEY,
7988 .doit = nl80211_set_key,
7989 .policy = nl80211_policy,
7990 .flags = GENL_ADMIN_PERM,
7991 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7992 NL80211_FLAG_NEED_RTNL,
7995 .cmd = NL80211_CMD_NEW_KEY,
7996 .doit = nl80211_new_key,
7997 .policy = nl80211_policy,
7998 .flags = GENL_ADMIN_PERM,
7999 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8000 NL80211_FLAG_NEED_RTNL,
8003 .cmd = NL80211_CMD_DEL_KEY,
8004 .doit = nl80211_del_key,
8005 .policy = nl80211_policy,
8006 .flags = GENL_ADMIN_PERM,
8007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8008 NL80211_FLAG_NEED_RTNL,
8011 .cmd = NL80211_CMD_SET_BEACON,
8012 .policy = nl80211_policy,
8013 .flags = GENL_ADMIN_PERM,
8014 .doit = nl80211_set_beacon,
8015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8016 NL80211_FLAG_NEED_RTNL,
8019 .cmd = NL80211_CMD_START_AP,
8020 .policy = nl80211_policy,
8021 .flags = GENL_ADMIN_PERM,
8022 .doit = nl80211_start_ap,
8023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8024 NL80211_FLAG_NEED_RTNL,
8027 .cmd = NL80211_CMD_STOP_AP,
8028 .policy = nl80211_policy,
8029 .flags = GENL_ADMIN_PERM,
8030 .doit = nl80211_stop_ap,
8031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8032 NL80211_FLAG_NEED_RTNL,
8035 .cmd = NL80211_CMD_GET_STATION,
8036 .doit = nl80211_get_station,
8037 .dumpit = nl80211_dump_station,
8038 .policy = nl80211_policy,
8039 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8040 NL80211_FLAG_NEED_RTNL,
8043 .cmd = NL80211_CMD_SET_STATION,
8044 .doit = nl80211_set_station,
8045 .policy = nl80211_policy,
8046 .flags = GENL_ADMIN_PERM,
8047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8048 NL80211_FLAG_NEED_RTNL,
8051 .cmd = NL80211_CMD_NEW_STATION,
8052 .doit = nl80211_new_station,
8053 .policy = nl80211_policy,
8054 .flags = GENL_ADMIN_PERM,
8055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8056 NL80211_FLAG_NEED_RTNL,
8059 .cmd = NL80211_CMD_DEL_STATION,
8060 .doit = nl80211_del_station,
8061 .policy = nl80211_policy,
8062 .flags = GENL_ADMIN_PERM,
8063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8064 NL80211_FLAG_NEED_RTNL,
8067 .cmd = NL80211_CMD_GET_MPATH,
8068 .doit = nl80211_get_mpath,
8069 .dumpit = nl80211_dump_mpath,
8070 .policy = nl80211_policy,
8071 .flags = GENL_ADMIN_PERM,
8072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8073 NL80211_FLAG_NEED_RTNL,
8076 .cmd = NL80211_CMD_SET_MPATH,
8077 .doit = nl80211_set_mpath,
8078 .policy = nl80211_policy,
8079 .flags = GENL_ADMIN_PERM,
8080 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8081 NL80211_FLAG_NEED_RTNL,
8084 .cmd = NL80211_CMD_NEW_MPATH,
8085 .doit = nl80211_new_mpath,
8086 .policy = nl80211_policy,
8087 .flags = GENL_ADMIN_PERM,
8088 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8089 NL80211_FLAG_NEED_RTNL,
8092 .cmd = NL80211_CMD_DEL_MPATH,
8093 .doit = nl80211_del_mpath,
8094 .policy = nl80211_policy,
8095 .flags = GENL_ADMIN_PERM,
8096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8097 NL80211_FLAG_NEED_RTNL,
8100 .cmd = NL80211_CMD_SET_BSS,
8101 .doit = nl80211_set_bss,
8102 .policy = nl80211_policy,
8103 .flags = GENL_ADMIN_PERM,
8104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8105 NL80211_FLAG_NEED_RTNL,
8108 .cmd = NL80211_CMD_GET_REG,
8109 .doit = nl80211_get_reg,
8110 .policy = nl80211_policy,
8111 /* can be retrieved by unprivileged users */
8114 .cmd = NL80211_CMD_SET_REG,
8115 .doit = nl80211_set_reg,
8116 .policy = nl80211_policy,
8117 .flags = GENL_ADMIN_PERM,
8120 .cmd = NL80211_CMD_REQ_SET_REG,
8121 .doit = nl80211_req_set_reg,
8122 .policy = nl80211_policy,
8123 .flags = GENL_ADMIN_PERM,
8126 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8127 .doit = nl80211_get_mesh_config,
8128 .policy = nl80211_policy,
8129 /* can be retrieved by unprivileged users */
8130 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8131 NL80211_FLAG_NEED_RTNL,
8134 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8135 .doit = nl80211_update_mesh_config,
8136 .policy = nl80211_policy,
8137 .flags = GENL_ADMIN_PERM,
8138 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8139 NL80211_FLAG_NEED_RTNL,
8142 .cmd = NL80211_CMD_TRIGGER_SCAN,
8143 .doit = nl80211_trigger_scan,
8144 .policy = nl80211_policy,
8145 .flags = GENL_ADMIN_PERM,
8146 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8147 NL80211_FLAG_NEED_RTNL,
8150 .cmd = NL80211_CMD_GET_SCAN,
8151 .policy = nl80211_policy,
8152 .dumpit = nl80211_dump_scan,
8155 .cmd = NL80211_CMD_START_SCHED_SCAN,
8156 .doit = nl80211_start_sched_scan,
8157 .policy = nl80211_policy,
8158 .flags = GENL_ADMIN_PERM,
8159 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8160 NL80211_FLAG_NEED_RTNL,
8163 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8164 .doit = nl80211_stop_sched_scan,
8165 .policy = nl80211_policy,
8166 .flags = GENL_ADMIN_PERM,
8167 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8168 NL80211_FLAG_NEED_RTNL,
8171 .cmd = NL80211_CMD_AUTHENTICATE,
8172 .doit = nl80211_authenticate,
8173 .policy = nl80211_policy,
8174 .flags = GENL_ADMIN_PERM,
8175 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8176 NL80211_FLAG_NEED_RTNL,
8179 .cmd = NL80211_CMD_ASSOCIATE,
8180 .doit = nl80211_associate,
8181 .policy = nl80211_policy,
8182 .flags = GENL_ADMIN_PERM,
8183 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8184 NL80211_FLAG_NEED_RTNL,
8187 .cmd = NL80211_CMD_DEAUTHENTICATE,
8188 .doit = nl80211_deauthenticate,
8189 .policy = nl80211_policy,
8190 .flags = GENL_ADMIN_PERM,
8191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8192 NL80211_FLAG_NEED_RTNL,
8195 .cmd = NL80211_CMD_DISASSOCIATE,
8196 .doit = nl80211_disassociate,
8197 .policy = nl80211_policy,
8198 .flags = GENL_ADMIN_PERM,
8199 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8200 NL80211_FLAG_NEED_RTNL,
8203 .cmd = NL80211_CMD_JOIN_IBSS,
8204 .doit = nl80211_join_ibss,
8205 .policy = nl80211_policy,
8206 .flags = GENL_ADMIN_PERM,
8207 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8208 NL80211_FLAG_NEED_RTNL,
8211 .cmd = NL80211_CMD_LEAVE_IBSS,
8212 .doit = nl80211_leave_ibss,
8213 .policy = nl80211_policy,
8214 .flags = GENL_ADMIN_PERM,
8215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8216 NL80211_FLAG_NEED_RTNL,
8218 #ifdef CONFIG_NL80211_TESTMODE
8220 .cmd = NL80211_CMD_TESTMODE,
8221 .doit = nl80211_testmode_do,
8222 .dumpit = nl80211_testmode_dump,
8223 .policy = nl80211_policy,
8224 .flags = GENL_ADMIN_PERM,
8225 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8226 NL80211_FLAG_NEED_RTNL,
8230 .cmd = NL80211_CMD_CONNECT,
8231 .doit = nl80211_connect,
8232 .policy = nl80211_policy,
8233 .flags = GENL_ADMIN_PERM,
8234 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8235 NL80211_FLAG_NEED_RTNL,
8238 .cmd = NL80211_CMD_DISCONNECT,
8239 .doit = nl80211_disconnect,
8240 .policy = nl80211_policy,
8241 .flags = GENL_ADMIN_PERM,
8242 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8243 NL80211_FLAG_NEED_RTNL,
8246 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8247 .doit = nl80211_wiphy_netns,
8248 .policy = nl80211_policy,
8249 .flags = GENL_ADMIN_PERM,
8250 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8251 NL80211_FLAG_NEED_RTNL,
8254 .cmd = NL80211_CMD_GET_SURVEY,
8255 .policy = nl80211_policy,
8256 .dumpit = nl80211_dump_survey,
8259 .cmd = NL80211_CMD_SET_PMKSA,
8260 .doit = nl80211_setdel_pmksa,
8261 .policy = nl80211_policy,
8262 .flags = GENL_ADMIN_PERM,
8263 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8264 NL80211_FLAG_NEED_RTNL,
8267 .cmd = NL80211_CMD_DEL_PMKSA,
8268 .doit = nl80211_setdel_pmksa,
8269 .policy = nl80211_policy,
8270 .flags = GENL_ADMIN_PERM,
8271 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8272 NL80211_FLAG_NEED_RTNL,
8275 .cmd = NL80211_CMD_FLUSH_PMKSA,
8276 .doit = nl80211_flush_pmksa,
8277 .policy = nl80211_policy,
8278 .flags = GENL_ADMIN_PERM,
8279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8280 NL80211_FLAG_NEED_RTNL,
8283 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8284 .doit = nl80211_remain_on_channel,
8285 .policy = nl80211_policy,
8286 .flags = GENL_ADMIN_PERM,
8287 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8288 NL80211_FLAG_NEED_RTNL,
8291 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8292 .doit = nl80211_cancel_remain_on_channel,
8293 .policy = nl80211_policy,
8294 .flags = GENL_ADMIN_PERM,
8295 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8296 NL80211_FLAG_NEED_RTNL,
8299 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8300 .doit = nl80211_set_tx_bitrate_mask,
8301 .policy = nl80211_policy,
8302 .flags = GENL_ADMIN_PERM,
8303 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8304 NL80211_FLAG_NEED_RTNL,
8307 .cmd = NL80211_CMD_REGISTER_FRAME,
8308 .doit = nl80211_register_mgmt,
8309 .policy = nl80211_policy,
8310 .flags = GENL_ADMIN_PERM,
8311 .internal_flags = NL80211_FLAG_NEED_WDEV |
8312 NL80211_FLAG_NEED_RTNL,
8315 .cmd = NL80211_CMD_FRAME,
8316 .doit = nl80211_tx_mgmt,
8317 .policy = nl80211_policy,
8318 .flags = GENL_ADMIN_PERM,
8319 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8320 NL80211_FLAG_NEED_RTNL,
8323 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8324 .doit = nl80211_tx_mgmt_cancel_wait,
8325 .policy = nl80211_policy,
8326 .flags = GENL_ADMIN_PERM,
8327 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8328 NL80211_FLAG_NEED_RTNL,
8331 .cmd = NL80211_CMD_SET_POWER_SAVE,
8332 .doit = nl80211_set_power_save,
8333 .policy = nl80211_policy,
8334 .flags = GENL_ADMIN_PERM,
8335 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8336 NL80211_FLAG_NEED_RTNL,
8339 .cmd = NL80211_CMD_GET_POWER_SAVE,
8340 .doit = nl80211_get_power_save,
8341 .policy = nl80211_policy,
8342 /* can be retrieved by unprivileged users */
8343 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8344 NL80211_FLAG_NEED_RTNL,
8347 .cmd = NL80211_CMD_SET_CQM,
8348 .doit = nl80211_set_cqm,
8349 .policy = nl80211_policy,
8350 .flags = GENL_ADMIN_PERM,
8351 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8352 NL80211_FLAG_NEED_RTNL,
8355 .cmd = NL80211_CMD_SET_CHANNEL,
8356 .doit = nl80211_set_channel,
8357 .policy = nl80211_policy,
8358 .flags = GENL_ADMIN_PERM,
8359 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8360 NL80211_FLAG_NEED_RTNL,
8363 .cmd = NL80211_CMD_SET_WDS_PEER,
8364 .doit = nl80211_set_wds_peer,
8365 .policy = nl80211_policy,
8366 .flags = GENL_ADMIN_PERM,
8367 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8368 NL80211_FLAG_NEED_RTNL,
8371 .cmd = NL80211_CMD_JOIN_MESH,
8372 .doit = nl80211_join_mesh,
8373 .policy = nl80211_policy,
8374 .flags = GENL_ADMIN_PERM,
8375 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8376 NL80211_FLAG_NEED_RTNL,
8379 .cmd = NL80211_CMD_LEAVE_MESH,
8380 .doit = nl80211_leave_mesh,
8381 .policy = nl80211_policy,
8382 .flags = GENL_ADMIN_PERM,
8383 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8384 NL80211_FLAG_NEED_RTNL,
8388 .cmd = NL80211_CMD_GET_WOWLAN,
8389 .doit = nl80211_get_wowlan,
8390 .policy = nl80211_policy,
8391 /* can be retrieved by unprivileged users */
8392 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8393 NL80211_FLAG_NEED_RTNL,
8396 .cmd = NL80211_CMD_SET_WOWLAN,
8397 .doit = nl80211_set_wowlan,
8398 .policy = nl80211_policy,
8399 .flags = GENL_ADMIN_PERM,
8400 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8401 NL80211_FLAG_NEED_RTNL,
8405 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8406 .doit = nl80211_set_rekey_data,
8407 .policy = nl80211_policy,
8408 .flags = GENL_ADMIN_PERM,
8409 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8410 NL80211_FLAG_NEED_RTNL,
8413 .cmd = NL80211_CMD_TDLS_MGMT,
8414 .doit = nl80211_tdls_mgmt,
8415 .policy = nl80211_policy,
8416 .flags = GENL_ADMIN_PERM,
8417 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8418 NL80211_FLAG_NEED_RTNL,
8421 .cmd = NL80211_CMD_TDLS_OPER,
8422 .doit = nl80211_tdls_oper,
8423 .policy = nl80211_policy,
8424 .flags = GENL_ADMIN_PERM,
8425 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8426 NL80211_FLAG_NEED_RTNL,
8429 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8430 .doit = nl80211_register_unexpected_frame,
8431 .policy = nl80211_policy,
8432 .flags = GENL_ADMIN_PERM,
8433 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8434 NL80211_FLAG_NEED_RTNL,
8437 .cmd = NL80211_CMD_PROBE_CLIENT,
8438 .doit = nl80211_probe_client,
8439 .policy = nl80211_policy,
8440 .flags = GENL_ADMIN_PERM,
8441 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8442 NL80211_FLAG_NEED_RTNL,
8445 .cmd = NL80211_CMD_REGISTER_BEACONS,
8446 .doit = nl80211_register_beacons,
8447 .policy = nl80211_policy,
8448 .flags = GENL_ADMIN_PERM,
8449 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8450 NL80211_FLAG_NEED_RTNL,
8453 .cmd = NL80211_CMD_SET_NOACK_MAP,
8454 .doit = nl80211_set_noack_map,
8455 .policy = nl80211_policy,
8456 .flags = GENL_ADMIN_PERM,
8457 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8458 NL80211_FLAG_NEED_RTNL,
8461 .cmd = NL80211_CMD_START_P2P_DEVICE,
8462 .doit = nl80211_start_p2p_device,
8463 .policy = nl80211_policy,
8464 .flags = GENL_ADMIN_PERM,
8465 .internal_flags = NL80211_FLAG_NEED_WDEV |
8466 NL80211_FLAG_NEED_RTNL,
8469 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8470 .doit = nl80211_stop_p2p_device,
8471 .policy = nl80211_policy,
8472 .flags = GENL_ADMIN_PERM,
8473 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8474 NL80211_FLAG_NEED_RTNL,
8477 .cmd = NL80211_CMD_SET_MCAST_RATE,
8478 .doit = nl80211_set_mcast_rate,
8479 .policy = nl80211_policy,
8480 .flags = GENL_ADMIN_PERM,
8481 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8482 NL80211_FLAG_NEED_RTNL,
8485 .cmd = NL80211_CMD_SET_MAC_ACL,
8486 .doit = nl80211_set_mac_acl,
8487 .policy = nl80211_policy,
8488 .flags = GENL_ADMIN_PERM,
8489 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8490 NL80211_FLAG_NEED_RTNL,
8493 .cmd = NL80211_CMD_RADAR_DETECT,
8494 .doit = nl80211_start_radar_detection,
8495 .policy = nl80211_policy,
8496 .flags = GENL_ADMIN_PERM,
8497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8498 NL80211_FLAG_NEED_RTNL,
8502 static struct genl_multicast_group nl80211_mlme_mcgrp = {
8506 /* multicast groups */
8507 static struct genl_multicast_group nl80211_config_mcgrp = {
8510 static struct genl_multicast_group nl80211_scan_mcgrp = {
8513 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8514 .name = "regulatory",
8517 /* notification functions */
8519 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8521 struct sk_buff *msg;
8523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8527 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
8532 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8533 nl80211_config_mcgrp.id, GFP_KERNEL);
8536 static int nl80211_add_scan_req(struct sk_buff *msg,
8537 struct cfg80211_registered_device *rdev)
8539 struct cfg80211_scan_request *req = rdev->scan_req;
8540 struct nlattr *nest;
8543 ASSERT_RDEV_LOCK(rdev);
8548 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8550 goto nla_put_failure;
8551 for (i = 0; i < req->n_ssids; i++) {
8552 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8553 goto nla_put_failure;
8555 nla_nest_end(msg, nest);
8557 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8559 goto nla_put_failure;
8560 for (i = 0; i < req->n_channels; i++) {
8561 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8562 goto nla_put_failure;
8564 nla_nest_end(msg, nest);
8567 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8568 goto nla_put_failure;
8571 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8578 static int nl80211_send_scan_msg(struct sk_buff *msg,
8579 struct cfg80211_registered_device *rdev,
8580 struct wireless_dev *wdev,
8581 u32 portid, u32 seq, int flags,
8586 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8590 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8591 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8592 wdev->netdev->ifindex)) ||
8593 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
8594 goto nla_put_failure;
8596 /* ignore errors and send incomplete event anyway */
8597 nl80211_add_scan_req(msg, rdev);
8599 return genlmsg_end(msg, hdr);
8602 genlmsg_cancel(msg, hdr);
8607 nl80211_send_sched_scan_msg(struct sk_buff *msg,
8608 struct cfg80211_registered_device *rdev,
8609 struct net_device *netdev,
8610 u32 portid, u32 seq, int flags, u32 cmd)
8614 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8618 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8619 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8620 goto nla_put_failure;
8622 return genlmsg_end(msg, hdr);
8625 genlmsg_cancel(msg, hdr);
8629 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
8630 struct wireless_dev *wdev)
8632 struct sk_buff *msg;
8634 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8638 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8639 NL80211_CMD_TRIGGER_SCAN) < 0) {
8644 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8645 nl80211_scan_mcgrp.id, GFP_KERNEL);
8648 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
8649 struct wireless_dev *wdev)
8651 struct sk_buff *msg;
8653 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8657 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8658 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
8663 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8664 nl80211_scan_mcgrp.id, GFP_KERNEL);
8667 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
8668 struct wireless_dev *wdev)
8670 struct sk_buff *msg;
8672 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8676 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8677 NL80211_CMD_SCAN_ABORTED) < 0) {
8682 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8683 nl80211_scan_mcgrp.id, GFP_KERNEL);
8686 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
8687 struct net_device *netdev)
8689 struct sk_buff *msg;
8691 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8695 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
8696 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
8701 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8702 nl80211_scan_mcgrp.id, GFP_KERNEL);
8705 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
8706 struct net_device *netdev, u32 cmd)
8708 struct sk_buff *msg;
8710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8714 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
8719 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8720 nl80211_scan_mcgrp.id, GFP_KERNEL);
8724 * This can happen on global regulatory changes or device specific settings
8725 * based on custom world regulatory domains.
8727 void nl80211_send_reg_change_event(struct regulatory_request *request)
8729 struct sk_buff *msg;
8732 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8736 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
8742 /* Userspace can always count this one always being set */
8743 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
8744 goto nla_put_failure;
8746 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
8747 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8748 NL80211_REGDOM_TYPE_WORLD))
8749 goto nla_put_failure;
8750 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
8751 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8752 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
8753 goto nla_put_failure;
8754 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
8755 request->intersect) {
8756 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8757 NL80211_REGDOM_TYPE_INTERSECTION))
8758 goto nla_put_failure;
8760 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8761 NL80211_REGDOM_TYPE_COUNTRY) ||
8762 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
8764 goto nla_put_failure;
8767 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
8768 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
8769 goto nla_put_failure;
8771 genlmsg_end(msg, hdr);
8774 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8781 genlmsg_cancel(msg, hdr);
8785 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
8786 struct net_device *netdev,
8787 const u8 *buf, size_t len,
8788 enum nl80211_commands cmd, gfp_t gfp)
8790 struct sk_buff *msg;
8793 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8797 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8803 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8804 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8805 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8806 goto nla_put_failure;
8808 genlmsg_end(msg, hdr);
8810 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8811 nl80211_mlme_mcgrp.id, gfp);
8815 genlmsg_cancel(msg, hdr);
8819 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
8820 struct net_device *netdev, const u8 *buf,
8821 size_t len, gfp_t gfp)
8823 nl80211_send_mlme_event(rdev, netdev, buf, len,
8824 NL80211_CMD_AUTHENTICATE, gfp);
8827 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
8828 struct net_device *netdev, const u8 *buf,
8829 size_t len, gfp_t gfp)
8831 nl80211_send_mlme_event(rdev, netdev, buf, len,
8832 NL80211_CMD_ASSOCIATE, gfp);
8835 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
8836 struct net_device *netdev, const u8 *buf,
8837 size_t len, gfp_t gfp)
8839 nl80211_send_mlme_event(rdev, netdev, buf, len,
8840 NL80211_CMD_DEAUTHENTICATE, gfp);
8843 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
8844 struct net_device *netdev, const u8 *buf,
8845 size_t len, gfp_t gfp)
8847 nl80211_send_mlme_event(rdev, netdev, buf, len,
8848 NL80211_CMD_DISASSOCIATE, gfp);
8851 void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
8852 struct net_device *netdev, const u8 *buf,
8853 size_t len, gfp_t gfp)
8855 nl80211_send_mlme_event(rdev, netdev, buf, len,
8856 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
8859 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
8860 struct net_device *netdev, const u8 *buf,
8861 size_t len, gfp_t gfp)
8863 nl80211_send_mlme_event(rdev, netdev, buf, len,
8864 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
8867 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
8868 struct net_device *netdev, int cmd,
8869 const u8 *addr, gfp_t gfp)
8871 struct sk_buff *msg;
8874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8878 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8884 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8885 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8886 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
8887 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8888 goto nla_put_failure;
8890 genlmsg_end(msg, hdr);
8892 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8893 nl80211_mlme_mcgrp.id, gfp);
8897 genlmsg_cancel(msg, hdr);
8901 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
8902 struct net_device *netdev, const u8 *addr,
8905 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
8909 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
8910 struct net_device *netdev, const u8 *addr,
8913 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
8917 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
8918 struct net_device *netdev, const u8 *bssid,
8919 const u8 *req_ie, size_t req_ie_len,
8920 const u8 *resp_ie, size_t resp_ie_len,
8921 u16 status, gfp_t gfp)
8923 struct sk_buff *msg;
8926 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8930 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
8936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8937 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8938 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
8939 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
8941 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8943 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8944 goto nla_put_failure;
8946 genlmsg_end(msg, hdr);
8948 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8949 nl80211_mlme_mcgrp.id, gfp);
8953 genlmsg_cancel(msg, hdr);
8958 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8959 struct net_device *netdev, const u8 *bssid,
8960 const u8 *req_ie, size_t req_ie_len,
8961 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8963 struct sk_buff *msg;
8966 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8970 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8976 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8977 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8978 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
8980 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8982 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8983 goto nla_put_failure;
8985 genlmsg_end(msg, hdr);
8987 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8988 nl80211_mlme_mcgrp.id, gfp);
8992 genlmsg_cancel(msg, hdr);
8997 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
8998 struct net_device *netdev, u16 reason,
8999 const u8 *ie, size_t ie_len, bool from_ap)
9001 struct sk_buff *msg;
9004 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9008 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9014 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9015 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9016 (from_ap && reason &&
9017 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9019 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9020 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9021 goto nla_put_failure;
9023 genlmsg_end(msg, hdr);
9025 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9026 nl80211_mlme_mcgrp.id, GFP_KERNEL);
9030 genlmsg_cancel(msg, hdr);
9035 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9036 struct net_device *netdev, const u8 *bssid,
9039 struct sk_buff *msg;
9042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9053 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9054 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9055 goto nla_put_failure;
9057 genlmsg_end(msg, hdr);
9059 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9060 nl80211_mlme_mcgrp.id, gfp);
9064 genlmsg_cancel(msg, hdr);
9068 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
9069 struct net_device *netdev,
9070 const u8 *macaddr, const u8* ie, u8 ie_len,
9073 struct sk_buff *msg;
9076 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9080 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9086 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9087 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9088 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
9090 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9091 goto nla_put_failure;
9093 genlmsg_end(msg, hdr);
9095 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9096 nl80211_mlme_mcgrp.id, gfp);
9100 genlmsg_cancel(msg, hdr);
9104 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9105 struct net_device *netdev, const u8 *addr,
9106 enum nl80211_key_type key_type, int key_id,
9107 const u8 *tsc, gfp_t gfp)
9109 struct sk_buff *msg;
9112 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9116 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9122 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9123 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9124 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9125 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9127 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9128 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9129 goto nla_put_failure;
9131 genlmsg_end(msg, hdr);
9133 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9134 nl80211_mlme_mcgrp.id, gfp);
9138 genlmsg_cancel(msg, hdr);
9142 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9143 struct ieee80211_channel *channel_before,
9144 struct ieee80211_channel *channel_after)
9146 struct sk_buff *msg;
9148 struct nlattr *nl_freq;
9150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
9154 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9161 * Since we are applying the beacon hint to a wiphy we know its
9162 * wiphy_idx is valid
9164 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9165 goto nla_put_failure;
9168 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9170 goto nla_put_failure;
9171 if (nl80211_msg_put_channel(msg, channel_before))
9172 goto nla_put_failure;
9173 nla_nest_end(msg, nl_freq);
9176 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9178 goto nla_put_failure;
9179 if (nl80211_msg_put_channel(msg, channel_after))
9180 goto nla_put_failure;
9181 nla_nest_end(msg, nl_freq);
9183 genlmsg_end(msg, hdr);
9186 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9193 genlmsg_cancel(msg, hdr);
9197 static void nl80211_send_remain_on_chan_event(
9198 int cmd, struct cfg80211_registered_device *rdev,
9199 struct wireless_dev *wdev, u64 cookie,
9200 struct ieee80211_channel *chan,
9201 unsigned int duration, gfp_t gfp)
9203 struct sk_buff *msg;
9206 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9210 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9216 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9217 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9218 wdev->netdev->ifindex)) ||
9219 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
9220 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
9221 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9222 NL80211_CHAN_NO_HT) ||
9223 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9224 goto nla_put_failure;
9226 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9227 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9228 goto nla_put_failure;
9230 genlmsg_end(msg, hdr);
9232 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9233 nl80211_mlme_mcgrp.id, gfp);
9237 genlmsg_cancel(msg, hdr);
9241 void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
9242 struct wireless_dev *wdev, u64 cookie,
9243 struct ieee80211_channel *chan,
9244 unsigned int duration, gfp_t gfp)
9246 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
9247 rdev, wdev, cookie, chan,
9251 void nl80211_send_remain_on_channel_cancel(
9252 struct cfg80211_registered_device *rdev,
9253 struct wireless_dev *wdev,
9254 u64 cookie, struct ieee80211_channel *chan, gfp_t gfp)
9256 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9257 rdev, wdev, cookie, chan, 0, gfp);
9260 void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
9261 struct net_device *dev, const u8 *mac_addr,
9262 struct station_info *sinfo, gfp_t gfp)
9264 struct sk_buff *msg;
9266 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9270 if (nl80211_send_station(msg, 0, 0, 0,
9271 rdev, dev, mac_addr, sinfo) < 0) {
9276 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9277 nl80211_mlme_mcgrp.id, gfp);
9280 void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
9281 struct net_device *dev, const u8 *mac_addr,
9284 struct sk_buff *msg;
9287 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9291 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9297 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9298 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9299 goto nla_put_failure;
9301 genlmsg_end(msg, hdr);
9303 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9304 nl80211_mlme_mcgrp.id, gfp);
9308 genlmsg_cancel(msg, hdr);
9312 void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
9313 struct net_device *dev, const u8 *mac_addr,
9314 enum nl80211_connect_failed_reason reason,
9317 struct sk_buff *msg;
9320 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9324 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9330 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9331 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9332 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9333 goto nla_put_failure;
9335 genlmsg_end(msg, hdr);
9337 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9338 nl80211_mlme_mcgrp.id, gfp);
9342 genlmsg_cancel(msg, hdr);
9346 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9347 const u8 *addr, gfp_t gfp)
9349 struct wireless_dev *wdev = dev->ieee80211_ptr;
9350 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9351 struct sk_buff *msg;
9354 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
9359 msg = nlmsg_new(100, gfp);
9363 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9370 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9371 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9372 goto nla_put_failure;
9374 err = genlmsg_end(msg, hdr);
9380 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9384 genlmsg_cancel(msg, hdr);
9389 bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
9391 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9395 bool nl80211_unexpected_4addr_frame(struct net_device *dev,
9396 const u8 *addr, gfp_t gfp)
9398 return __nl80211_unexpected_frame(dev,
9399 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9403 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
9404 struct wireless_dev *wdev, u32 nlportid,
9405 int freq, int sig_dbm,
9406 const u8 *buf, size_t len, gfp_t gfp)
9408 struct net_device *netdev = wdev->netdev;
9409 struct sk_buff *msg;
9412 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9416 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9422 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9423 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9424 netdev->ifindex)) ||
9425 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9427 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9428 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9429 goto nla_put_failure;
9431 genlmsg_end(msg, hdr);
9433 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9436 genlmsg_cancel(msg, hdr);
9441 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
9442 struct wireless_dev *wdev, u64 cookie,
9443 const u8 *buf, size_t len, bool ack,
9446 struct net_device *netdev = wdev->netdev;
9447 struct sk_buff *msg;
9450 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9454 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
9460 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9461 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9462 netdev->ifindex)) ||
9463 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9464 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9465 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9466 goto nla_put_failure;
9468 genlmsg_end(msg, hdr);
9470 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9474 genlmsg_cancel(msg, hdr);
9479 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
9480 struct net_device *netdev,
9481 enum nl80211_cqm_rssi_threshold_event rssi_event,
9484 struct sk_buff *msg;
9485 struct nlattr *pinfoattr;
9488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9492 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9499 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9500 goto nla_put_failure;
9502 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9504 goto nla_put_failure;
9506 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9508 goto nla_put_failure;
9510 nla_nest_end(msg, pinfoattr);
9512 genlmsg_end(msg, hdr);
9514 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9515 nl80211_mlme_mcgrp.id, gfp);
9519 genlmsg_cancel(msg, hdr);
9523 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9524 struct net_device *netdev, const u8 *bssid,
9525 const u8 *replay_ctr, gfp_t gfp)
9527 struct sk_buff *msg;
9528 struct nlattr *rekey_attr;
9531 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9535 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9541 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9542 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9543 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9544 goto nla_put_failure;
9546 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9548 goto nla_put_failure;
9550 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9551 NL80211_REPLAY_CTR_LEN, replay_ctr))
9552 goto nla_put_failure;
9554 nla_nest_end(msg, rekey_attr);
9556 genlmsg_end(msg, hdr);
9558 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9559 nl80211_mlme_mcgrp.id, gfp);
9563 genlmsg_cancel(msg, hdr);
9567 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9568 struct net_device *netdev, int index,
9569 const u8 *bssid, bool preauth, gfp_t gfp)
9571 struct sk_buff *msg;
9572 struct nlattr *attr;
9575 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9579 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
9585 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9586 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9587 goto nla_put_failure;
9589 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
9591 goto nla_put_failure;
9593 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
9594 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
9596 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
9597 goto nla_put_failure;
9599 nla_nest_end(msg, attr);
9601 genlmsg_end(msg, hdr);
9603 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9604 nl80211_mlme_mcgrp.id, gfp);
9608 genlmsg_cancel(msg, hdr);
9612 void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
9613 struct net_device *netdev,
9614 struct cfg80211_chan_def *chandef, gfp_t gfp)
9616 struct sk_buff *msg;
9619 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9623 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
9629 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9630 goto nla_put_failure;
9632 if (nl80211_send_chandef(msg, chandef))
9633 goto nla_put_failure;
9635 genlmsg_end(msg, hdr);
9637 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9638 nl80211_mlme_mcgrp.id, gfp);
9642 genlmsg_cancel(msg, hdr);
9647 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
9648 struct net_device *netdev, const u8 *peer,
9649 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
9651 struct sk_buff *msg;
9652 struct nlattr *pinfoattr;
9655 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9659 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9665 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9666 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9667 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9668 goto nla_put_failure;
9670 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9672 goto nla_put_failure;
9674 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
9675 goto nla_put_failure;
9677 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
9678 goto nla_put_failure;
9680 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
9681 goto nla_put_failure;
9683 nla_nest_end(msg, pinfoattr);
9685 genlmsg_end(msg, hdr);
9687 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9688 nl80211_mlme_mcgrp.id, gfp);
9692 genlmsg_cancel(msg, hdr);
9697 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
9698 struct cfg80211_chan_def *chandef,
9699 enum nl80211_radar_event event,
9700 struct net_device *netdev, gfp_t gfp)
9702 struct sk_buff *msg;
9705 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9709 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
9715 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9716 goto nla_put_failure;
9718 /* NOP and radar events don't need a netdev parameter */
9720 struct wireless_dev *wdev = netdev->ieee80211_ptr;
9722 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9723 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9724 goto nla_put_failure;
9727 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
9728 goto nla_put_failure;
9730 if (nl80211_send_chandef(msg, chandef))
9731 goto nla_put_failure;
9733 if (genlmsg_end(msg, hdr) < 0) {
9738 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9739 nl80211_mlme_mcgrp.id, gfp);
9743 genlmsg_cancel(msg, hdr);
9748 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
9749 struct net_device *netdev, const u8 *peer,
9750 u32 num_packets, gfp_t gfp)
9752 struct sk_buff *msg;
9753 struct nlattr *pinfoattr;
9756 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9760 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9766 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9767 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9768 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9769 goto nla_put_failure;
9771 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9773 goto nla_put_failure;
9775 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
9776 goto nla_put_failure;
9778 nla_nest_end(msg, pinfoattr);
9780 genlmsg_end(msg, hdr);
9782 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9783 nl80211_mlme_mcgrp.id, gfp);
9787 genlmsg_cancel(msg, hdr);
9791 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
9792 u64 cookie, bool acked, gfp_t gfp)
9794 struct wireless_dev *wdev = dev->ieee80211_ptr;
9795 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9796 struct sk_buff *msg;
9800 trace_cfg80211_probe_status(dev, addr, cookie, acked);
9802 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9807 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
9813 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9814 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9815 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9816 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9817 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
9818 goto nla_put_failure;
9820 err = genlmsg_end(msg, hdr);
9826 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9827 nl80211_mlme_mcgrp.id, gfp);
9831 genlmsg_cancel(msg, hdr);
9834 EXPORT_SYMBOL(cfg80211_probe_status);
9836 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
9837 const u8 *frame, size_t len,
9838 int freq, int sig_dbm)
9840 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9841 struct sk_buff *msg;
9843 struct cfg80211_beacon_registration *reg;
9845 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
9847 spin_lock_bh(&rdev->beacon_registrations_lock);
9848 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9849 msg = nlmsg_new(len + 100, GFP_ATOMIC);
9851 spin_unlock_bh(&rdev->beacon_registrations_lock);
9855 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9857 goto nla_put_failure;
9859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9861 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9863 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9864 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
9865 goto nla_put_failure;
9867 genlmsg_end(msg, hdr);
9869 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
9871 spin_unlock_bh(&rdev->beacon_registrations_lock);
9875 spin_unlock_bh(&rdev->beacon_registrations_lock);
9877 genlmsg_cancel(msg, hdr);
9880 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
9883 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
9884 struct cfg80211_wowlan_wakeup *wakeup,
9887 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9888 struct sk_buff *msg;
9890 int err, size = 200;
9892 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
9895 size += wakeup->packet_present_len;
9897 msg = nlmsg_new(size, gfp);
9901 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
9905 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9906 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9909 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9910 wdev->netdev->ifindex))
9914 struct nlattr *reasons;
9916 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9918 if (wakeup->disconnect &&
9919 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
9921 if (wakeup->magic_pkt &&
9922 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
9924 if (wakeup->gtk_rekey_failure &&
9925 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
9927 if (wakeup->eap_identity_req &&
9928 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
9930 if (wakeup->four_way_handshake &&
9931 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
9933 if (wakeup->rfkill_release &&
9934 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
9937 if (wakeup->pattern_idx >= 0 &&
9938 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
9939 wakeup->pattern_idx))
9942 if (wakeup->tcp_match)
9943 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
9945 if (wakeup->tcp_connlost)
9947 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
9949 if (wakeup->tcp_nomoretokens)
9951 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
9953 if (wakeup->packet) {
9954 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
9955 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
9957 if (!wakeup->packet_80211) {
9959 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
9961 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
9964 if (wakeup->packet_len &&
9965 nla_put_u32(msg, len_attr, wakeup->packet_len))
9968 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
9973 nla_nest_end(msg, reasons);
9976 err = genlmsg_end(msg, hdr);
9980 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9981 nl80211_mlme_mcgrp.id, gfp);
9987 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
9990 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
9991 enum nl80211_tdls_operation oper,
9992 u16 reason_code, gfp_t gfp)
9994 struct wireless_dev *wdev = dev->ieee80211_ptr;
9995 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9996 struct sk_buff *msg;
10000 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10007 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10013 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10014 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10015 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10016 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10017 (reason_code > 0 &&
10018 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10019 goto nla_put_failure;
10021 err = genlmsg_end(msg, hdr);
10027 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10028 nl80211_mlme_mcgrp.id, gfp);
10032 genlmsg_cancel(msg, hdr);
10035 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10037 static int nl80211_netlink_notify(struct notifier_block * nb,
10038 unsigned long state,
10041 struct netlink_notify *notify = _notify;
10042 struct cfg80211_registered_device *rdev;
10043 struct wireless_dev *wdev;
10044 struct cfg80211_beacon_registration *reg, *tmp;
10046 if (state != NETLINK_URELEASE)
10047 return NOTIFY_DONE;
10051 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
10052 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
10053 cfg80211_mlme_unregister_socket(wdev, notify->portid);
10055 spin_lock_bh(&rdev->beacon_registrations_lock);
10056 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10058 if (reg->nlportid == notify->portid) {
10059 list_del(®->list);
10064 spin_unlock_bh(&rdev->beacon_registrations_lock);
10069 return NOTIFY_DONE;
10072 static struct notifier_block nl80211_netlink_notifier = {
10073 .notifier_call = nl80211_netlink_notify,
10076 /* initialisation/exit functions */
10078 int nl80211_init(void)
10082 err = genl_register_family_with_ops(&nl80211_fam,
10083 nl80211_ops, ARRAY_SIZE(nl80211_ops));
10087 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10091 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10095 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10099 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10103 #ifdef CONFIG_NL80211_TESTMODE
10104 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10109 err = netlink_register_notifier(&nl80211_netlink_notifier);
10115 genl_unregister_family(&nl80211_fam);
10119 void nl80211_exit(void)
10121 netlink_unregister_notifier(&nl80211_netlink_notifier);
10122 genl_unregister_family(&nl80211_fam);