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 if ((params->sta_flags_mask |
2971 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2976 /* if present, parse the old attribute */
2978 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
2982 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2983 nla, sta_flags_policy))
2987 * Only allow certain flags for interface types so that
2988 * other attributes are silently ignored. Remember that
2989 * this is backward compatibility code with old userspace
2990 * and shouldn't be hit in other cases anyway.
2993 case NL80211_IFTYPE_AP:
2994 case NL80211_IFTYPE_AP_VLAN:
2995 case NL80211_IFTYPE_P2P_GO:
2996 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2997 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2998 BIT(NL80211_STA_FLAG_WME) |
2999 BIT(NL80211_STA_FLAG_MFP);
3001 case NL80211_IFTYPE_P2P_CLIENT:
3002 case NL80211_IFTYPE_STATION:
3003 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3004 BIT(NL80211_STA_FLAG_TDLS_PEER);
3006 case NL80211_IFTYPE_MESH_POINT:
3007 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3008 BIT(NL80211_STA_FLAG_MFP) |
3009 BIT(NL80211_STA_FLAG_AUTHORIZED);
3014 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3016 params->sta_flags_set |= (1<<flag);
3018 /* no longer support new API additions in old API */
3019 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3027 static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3030 struct nlattr *rate;
3034 rate = nla_nest_start(msg, attr);
3038 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3039 bitrate = cfg80211_calculate_bitrate(info);
3040 /* report 16-bit bitrate only if we can */
3041 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
3043 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3045 if (bitrate_compat > 0 &&
3046 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3049 if (info->flags & RATE_INFO_FLAGS_MCS) {
3050 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3052 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3053 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3055 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3056 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3058 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3059 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3061 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3063 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3064 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3066 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3067 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3069 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3070 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3072 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3073 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3075 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3076 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3080 nla_nest_end(msg, rate);
3084 static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
3086 struct cfg80211_registered_device *rdev,
3087 struct net_device *dev,
3088 const u8 *mac_addr, struct station_info *sinfo)
3091 struct nlattr *sinfoattr, *bss_param;
3093 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
3097 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3098 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3099 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3100 goto nla_put_failure;
3102 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3104 goto nla_put_failure;
3105 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3106 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3107 sinfo->connected_time))
3108 goto nla_put_failure;
3109 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3110 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3111 sinfo->inactive_time))
3112 goto nla_put_failure;
3113 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3114 STATION_INFO_RX_BYTES64)) &&
3115 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
3116 (u32)sinfo->rx_bytes))
3117 goto nla_put_failure;
3118 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
3119 NL80211_STA_INFO_TX_BYTES64)) &&
3120 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3121 (u32)sinfo->tx_bytes))
3122 goto nla_put_failure;
3123 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3124 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
3126 goto nla_put_failure;
3127 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3128 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
3130 goto nla_put_failure;
3131 if ((sinfo->filled & STATION_INFO_LLID) &&
3132 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3133 goto nla_put_failure;
3134 if ((sinfo->filled & STATION_INFO_PLID) &&
3135 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3136 goto nla_put_failure;
3137 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3138 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3139 sinfo->plink_state))
3140 goto nla_put_failure;
3141 switch (rdev->wiphy.signal_type) {
3142 case CFG80211_SIGNAL_TYPE_MBM:
3143 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3144 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3146 goto nla_put_failure;
3147 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3148 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3150 goto nla_put_failure;
3155 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
3156 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3157 NL80211_STA_INFO_TX_BITRATE))
3158 goto nla_put_failure;
3160 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3161 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3162 NL80211_STA_INFO_RX_BITRATE))
3163 goto nla_put_failure;
3165 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3166 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3168 goto nla_put_failure;
3169 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3170 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3172 goto nla_put_failure;
3173 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3174 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3176 goto nla_put_failure;
3177 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3178 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3180 goto nla_put_failure;
3181 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3182 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3183 sinfo->beacon_loss_count))
3184 goto nla_put_failure;
3185 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3186 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3188 goto nla_put_failure;
3189 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3190 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3192 goto nla_put_failure;
3193 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3194 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3196 goto nla_put_failure;
3197 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3198 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3200 goto nla_put_failure;
3202 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3203 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3204 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3205 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3206 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3207 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3208 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3209 sinfo->bss_param.dtim_period) ||
3210 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3211 sinfo->bss_param.beacon_interval))
3212 goto nla_put_failure;
3214 nla_nest_end(msg, bss_param);
3216 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3217 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3218 sizeof(struct nl80211_sta_flag_update),
3220 goto nla_put_failure;
3221 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3222 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3224 goto nla_put_failure;
3225 nla_nest_end(msg, sinfoattr);
3227 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3228 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3229 sinfo->assoc_req_ies))
3230 goto nla_put_failure;
3232 return genlmsg_end(msg, hdr);
3235 genlmsg_cancel(msg, hdr);
3239 static int nl80211_dump_station(struct sk_buff *skb,
3240 struct netlink_callback *cb)
3242 struct station_info sinfo;
3243 struct cfg80211_registered_device *dev;
3244 struct net_device *netdev;
3245 u8 mac_addr[ETH_ALEN];
3246 int sta_idx = cb->args[1];
3249 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3253 if (!dev->ops->dump_station) {
3259 memset(&sinfo, 0, sizeof(sinfo));
3260 err = rdev_dump_station(dev, netdev, sta_idx,
3267 if (nl80211_send_station(skb,
3268 NETLINK_CB(cb->skb).portid,
3269 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3270 dev, netdev, mac_addr,
3279 cb->args[1] = sta_idx;
3282 nl80211_finish_netdev_dump(dev);
3287 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3290 struct net_device *dev = info->user_ptr[1];
3291 struct station_info sinfo;
3292 struct sk_buff *msg;
3293 u8 *mac_addr = NULL;
3296 memset(&sinfo, 0, sizeof(sinfo));
3298 if (!info->attrs[NL80211_ATTR_MAC])
3301 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3303 if (!rdev->ops->get_station)
3306 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
3310 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3314 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
3315 rdev, dev, mac_addr, &sinfo) < 0) {
3320 return genlmsg_reply(msg, info);
3324 * Get vlan interface making sure it is running and on the right wiphy.
3326 static struct net_device *get_vlan(struct genl_info *info,
3327 struct cfg80211_registered_device *rdev)
3329 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
3330 struct net_device *v;
3336 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3338 return ERR_PTR(-ENODEV);
3340 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3345 if (!netif_running(v)) {
3353 return ERR_PTR(ret);
3356 static struct nla_policy
3357 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3358 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3359 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3362 static int nl80211_set_station_tdls(struct genl_info *info,
3363 struct station_parameters *params)
3365 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3369 /* Dummy STA entry gets updated once the peer capabilities are known */
3370 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3372 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3373 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3375 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3377 /* parse WME attributes if present */
3378 if (!info->attrs[NL80211_ATTR_STA_WME])
3381 nla = info->attrs[NL80211_ATTR_STA_WME];
3382 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3383 nl80211_sta_wme_policy);
3387 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3388 params->uapsd_queues = nla_get_u8(
3389 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3390 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3393 if (tb[NL80211_STA_WME_MAX_SP])
3394 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3396 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3399 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3404 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3408 struct net_device *dev = info->user_ptr[1];
3409 struct station_parameters params;
3410 u8 *mac_addr = NULL;
3412 memset(¶ms, 0, sizeof(params));
3414 params.listen_interval = -1;
3416 if (info->attrs[NL80211_ATTR_STA_AID])
3419 if (!info->attrs[NL80211_ATTR_MAC])
3422 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3424 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3425 params.supported_rates =
3426 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3427 params.supported_rates_len =
3428 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3431 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3433 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3434 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3437 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3439 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3440 params.ext_capab_len =
3441 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3444 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3447 if (!rdev->ops->change_station)
3450 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3453 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3454 params.plink_action =
3455 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3456 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3460 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
3461 params.plink_state =
3462 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3463 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3465 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3468 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3469 enum nl80211_mesh_power_mode pm = nla_get_u32(
3470 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3472 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3473 pm > NL80211_MESH_POWER_MAX)
3476 params.local_pm = pm;
3479 switch (dev->ieee80211_ptr->iftype) {
3480 case NL80211_IFTYPE_AP:
3481 case NL80211_IFTYPE_AP_VLAN:
3482 case NL80211_IFTYPE_P2P_GO:
3483 /* disallow mesh-specific things */
3484 if (params.plink_action)
3486 if (params.local_pm)
3488 if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3491 /* TDLS can't be set, ... */
3492 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3495 * ... but don't bother the driver with it. This works around
3496 * a hostapd/wpa_supplicant issue -- it always includes the
3497 * TLDS_PEER flag in the mask even for AP mode.
3499 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3501 /* accept only the listed bits */
3502 if (params.sta_flags_mask &
3503 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3504 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3505 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3506 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3507 BIT(NL80211_STA_FLAG_WME) |
3508 BIT(NL80211_STA_FLAG_MFP)))
3511 /* but authenticated/associated only if driver handles it */
3512 if (!(rdev->wiphy.features &
3513 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3514 params.sta_flags_mask &
3515 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3516 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3519 /* reject other things that can't change */
3520 if (params.supported_rates)
3522 if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
3524 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
3526 if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
3527 info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3530 /* must be last in here for error handling */
3531 params.vlan = get_vlan(info, rdev);
3532 if (IS_ERR(params.vlan))
3533 return PTR_ERR(params.vlan);
3535 case NL80211_IFTYPE_P2P_CLIENT:
3536 case NL80211_IFTYPE_STATION:
3538 * Don't allow userspace to change the TDLS_PEER flag,
3539 * but silently ignore attempts to change it since we
3540 * don't have state here to verify that it doesn't try
3541 * to change the flag.
3543 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3544 /* Include parameters for TDLS peer (driver will check) */
3545 err = nl80211_set_station_tdls(info, ¶ms);
3548 /* disallow things sta doesn't support */
3549 if (params.plink_action)
3551 if (params.local_pm)
3553 if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3555 /* reject any changes other than AUTHORIZED or WME (for TDLS) */
3556 if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3557 BIT(NL80211_STA_FLAG_WME)))
3560 case NL80211_IFTYPE_ADHOC:
3561 /* disallow things sta doesn't support */
3562 if (params.plink_action)
3564 if (params.local_pm)
3566 if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3568 if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
3569 info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3571 /* reject any changes other than AUTHORIZED */
3572 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3575 case NL80211_IFTYPE_MESH_POINT:
3576 /* disallow things mesh doesn't support */
3579 if (params.supported_rates)
3581 if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
3583 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
3585 if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
3586 info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3589 * No special handling for TDLS here -- the userspace
3590 * mesh code doesn't have this bug.
3592 if (params.sta_flags_mask &
3593 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3594 BIT(NL80211_STA_FLAG_MFP) |
3595 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3602 /* be aware of params.vlan when changing code here */
3604 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
3607 dev_put(params.vlan);
3612 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3616 struct net_device *dev = info->user_ptr[1];
3617 struct station_parameters params;
3618 u8 *mac_addr = NULL;
3620 memset(¶ms, 0, sizeof(params));
3622 if (!info->attrs[NL80211_ATTR_MAC])
3625 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3628 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3631 if (!info->attrs[NL80211_ATTR_STA_AID])
3634 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3635 params.supported_rates =
3636 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3637 params.supported_rates_len =
3638 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3639 params.listen_interval =
3640 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3642 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3643 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3646 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3648 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3649 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3652 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3654 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3655 params.ext_capab_len =
3656 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3659 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3661 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3663 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3665 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3667 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3668 params.plink_action =
3669 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3670 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3674 if (!rdev->ops->add_station)
3677 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3680 switch (dev->ieee80211_ptr->iftype) {
3681 case NL80211_IFTYPE_AP:
3682 case NL80211_IFTYPE_AP_VLAN:
3683 case NL80211_IFTYPE_P2P_GO:
3684 /* parse WME attributes if sta is WME capable */
3685 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3686 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3687 info->attrs[NL80211_ATTR_STA_WME]) {
3688 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3691 nla = info->attrs[NL80211_ATTR_STA_WME];
3692 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3693 nl80211_sta_wme_policy);
3697 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3698 params.uapsd_queues =
3699 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3700 if (params.uapsd_queues &
3701 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3704 if (tb[NL80211_STA_WME_MAX_SP])
3706 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3709 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3712 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3714 /* TDLS peers cannot be added */
3715 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3717 /* but don't bother the driver with it */
3718 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3720 /* allow authenticated/associated only if driver handles it */
3721 if (!(rdev->wiphy.features &
3722 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3723 params.sta_flags_mask &
3724 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3725 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3728 /* must be last in here for error handling */
3729 params.vlan = get_vlan(info, rdev);
3730 if (IS_ERR(params.vlan))
3731 return PTR_ERR(params.vlan);
3733 case NL80211_IFTYPE_MESH_POINT:
3734 /* associated is disallowed */
3735 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3737 /* TDLS peers cannot be added */
3738 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3741 case NL80211_IFTYPE_STATION:
3742 /* associated is disallowed */
3743 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3745 /* Only TDLS peers can be added */
3746 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3748 /* Can only add if TDLS ... */
3749 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3751 /* ... with external setup is supported */
3752 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3759 /* be aware of params.vlan when changing code here */
3761 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
3764 dev_put(params.vlan);
3768 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3770 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3771 struct net_device *dev = info->user_ptr[1];
3772 u8 *mac_addr = NULL;
3774 if (info->attrs[NL80211_ATTR_MAC])
3775 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3777 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3778 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3779 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
3780 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3783 if (!rdev->ops->del_station)
3786 return rdev_del_station(rdev, dev, mac_addr);
3789 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
3790 int flags, struct net_device *dev,
3791 u8 *dst, u8 *next_hop,
3792 struct mpath_info *pinfo)
3795 struct nlattr *pinfoattr;
3797 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
3801 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3802 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3803 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3804 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3805 goto nla_put_failure;
3807 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3809 goto nla_put_failure;
3810 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3811 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3813 goto nla_put_failure;
3814 if (((pinfo->filled & MPATH_INFO_SN) &&
3815 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3816 ((pinfo->filled & MPATH_INFO_METRIC) &&
3817 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3819 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3820 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3822 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3823 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3825 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3826 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3827 pinfo->discovery_timeout)) ||
3828 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3829 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3830 pinfo->discovery_retries)))
3831 goto nla_put_failure;
3833 nla_nest_end(msg, pinfoattr);
3835 return genlmsg_end(msg, hdr);
3838 genlmsg_cancel(msg, hdr);
3842 static int nl80211_dump_mpath(struct sk_buff *skb,
3843 struct netlink_callback *cb)
3845 struct mpath_info pinfo;
3846 struct cfg80211_registered_device *dev;
3847 struct net_device *netdev;
3849 u8 next_hop[ETH_ALEN];
3850 int path_idx = cb->args[1];
3853 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3857 if (!dev->ops->dump_mpath) {
3862 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3868 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
3875 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
3876 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3877 netdev, dst, next_hop,
3886 cb->args[1] = path_idx;
3889 nl80211_finish_netdev_dump(dev);
3893 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3897 struct net_device *dev = info->user_ptr[1];
3898 struct mpath_info pinfo;
3899 struct sk_buff *msg;
3901 u8 next_hop[ETH_ALEN];
3903 memset(&pinfo, 0, sizeof(pinfo));
3905 if (!info->attrs[NL80211_ATTR_MAC])
3908 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3910 if (!rdev->ops->get_mpath)
3913 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3916 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
3920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3924 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
3925 dev, dst, next_hop, &pinfo) < 0) {
3930 return genlmsg_reply(msg, info);
3933 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3936 struct net_device *dev = info->user_ptr[1];
3938 u8 *next_hop = NULL;
3940 if (!info->attrs[NL80211_ATTR_MAC])
3943 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3946 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3947 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3949 if (!rdev->ops->change_mpath)
3952 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3955 return rdev_change_mpath(rdev, dev, dst, next_hop);
3958 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3961 struct net_device *dev = info->user_ptr[1];
3963 u8 *next_hop = NULL;
3965 if (!info->attrs[NL80211_ATTR_MAC])
3968 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3971 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3972 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3974 if (!rdev->ops->add_mpath)
3977 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3980 return rdev_add_mpath(rdev, dev, dst, next_hop);
3983 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3986 struct net_device *dev = info->user_ptr[1];
3989 if (info->attrs[NL80211_ATTR_MAC])
3990 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3992 if (!rdev->ops->del_mpath)
3995 return rdev_del_mpath(rdev, dev, dst);
3998 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4001 struct net_device *dev = info->user_ptr[1];
4002 struct bss_parameters params;
4004 memset(¶ms, 0, sizeof(params));
4005 /* default to not changing parameters */
4006 params.use_cts_prot = -1;
4007 params.use_short_preamble = -1;
4008 params.use_short_slot_time = -1;
4009 params.ap_isolate = -1;
4010 params.ht_opmode = -1;
4011 params.p2p_ctwindow = -1;
4012 params.p2p_opp_ps = -1;
4014 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4015 params.use_cts_prot =
4016 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4017 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4018 params.use_short_preamble =
4019 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4020 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4021 params.use_short_slot_time =
4022 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
4023 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4024 params.basic_rates =
4025 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4026 params.basic_rates_len =
4027 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4029 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4030 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
4031 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4033 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
4035 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4036 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4038 params.p2p_ctwindow =
4039 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4040 if (params.p2p_ctwindow < 0)
4042 if (params.p2p_ctwindow != 0 &&
4043 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4047 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4050 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4052 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4055 params.p2p_opp_ps = tmp;
4056 if (params.p2p_opp_ps &&
4057 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4061 if (!rdev->ops->change_bss)
4064 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4065 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4068 return rdev_change_bss(rdev, dev, ¶ms);
4071 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
4072 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4073 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4074 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4075 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4076 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4077 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4080 static int parse_reg_rule(struct nlattr *tb[],
4081 struct ieee80211_reg_rule *reg_rule)
4083 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
4084 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
4086 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4088 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4090 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4092 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4094 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4097 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4099 freq_range->start_freq_khz =
4100 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4101 freq_range->end_freq_khz =
4102 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4103 freq_range->max_bandwidth_khz =
4104 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4106 power_rule->max_eirp =
4107 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4109 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4110 power_rule->max_antenna_gain =
4111 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4116 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4120 enum nl80211_user_reg_hint_type user_reg_hint_type;
4123 * You should only get this when cfg80211 hasn't yet initialized
4124 * completely when built-in to the kernel right between the time
4125 * window between nl80211_init() and regulatory_init(), if that is
4128 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
4129 return -EINPROGRESS;
4131 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4134 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4136 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4137 user_reg_hint_type =
4138 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4140 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4142 switch (user_reg_hint_type) {
4143 case NL80211_USER_REG_HINT_USER:
4144 case NL80211_USER_REG_HINT_CELL_BASE:
4150 r = regulatory_hint_user(data, user_reg_hint_type);
4155 static int nl80211_get_mesh_config(struct sk_buff *skb,
4156 struct genl_info *info)
4158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4159 struct net_device *dev = info->user_ptr[1];
4160 struct wireless_dev *wdev = dev->ieee80211_ptr;
4161 struct mesh_config cur_params;
4164 struct nlattr *pinfoattr;
4165 struct sk_buff *msg;
4167 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4170 if (!rdev->ops->get_mesh_config)
4174 /* If not connected, get default parameters */
4175 if (!wdev->mesh_id_len)
4176 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4178 err = rdev_get_mesh_config(rdev, dev, &cur_params);
4184 /* Draw up a netlink message to send back */
4185 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4188 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4189 NL80211_CMD_GET_MESH_CONFIG);
4192 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
4194 goto nla_put_failure;
4195 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4196 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4197 cur_params.dot11MeshRetryTimeout) ||
4198 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4199 cur_params.dot11MeshConfirmTimeout) ||
4200 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4201 cur_params.dot11MeshHoldingTimeout) ||
4202 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4203 cur_params.dot11MeshMaxPeerLinks) ||
4204 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4205 cur_params.dot11MeshMaxRetries) ||
4206 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4207 cur_params.dot11MeshTTL) ||
4208 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4209 cur_params.element_ttl) ||
4210 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4211 cur_params.auto_open_plinks) ||
4212 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4213 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
4214 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4215 cur_params.dot11MeshHWMPmaxPREQretries) ||
4216 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4217 cur_params.path_refresh_time) ||
4218 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4219 cur_params.min_discovery_timeout) ||
4220 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4221 cur_params.dot11MeshHWMPactivePathTimeout) ||
4222 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4223 cur_params.dot11MeshHWMPpreqMinInterval) ||
4224 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4225 cur_params.dot11MeshHWMPperrMinInterval) ||
4226 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4227 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4228 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4229 cur_params.dot11MeshHWMPRootMode) ||
4230 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4231 cur_params.dot11MeshHWMPRannInterval) ||
4232 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4233 cur_params.dot11MeshGateAnnouncementProtocol) ||
4234 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4235 cur_params.dot11MeshForwarding) ||
4236 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
4237 cur_params.rssi_threshold) ||
4238 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
4239 cur_params.ht_opmode) ||
4240 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4241 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4242 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4243 cur_params.dot11MeshHWMProotInterval) ||
4244 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4245 cur_params.dot11MeshHWMPconfirmationInterval) ||
4246 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4247 cur_params.power_mode) ||
4248 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4249 cur_params.dot11MeshAwakeWindowDuration))
4250 goto nla_put_failure;
4251 nla_nest_end(msg, pinfoattr);
4252 genlmsg_end(msg, hdr);
4253 return genlmsg_reply(msg, info);
4256 genlmsg_cancel(msg, hdr);
4262 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
4263 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4264 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4265 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4266 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4267 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4268 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
4269 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
4270 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
4271 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
4272 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4273 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4274 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4275 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4276 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
4277 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
4278 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
4279 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
4280 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
4281 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
4282 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
4283 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4284 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
4285 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4286 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
4287 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
4288 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4289 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
4292 static const struct nla_policy
4293 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
4294 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
4295 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4296 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
4297 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
4298 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
4299 .len = IEEE80211_MAX_DATA_LEN },
4300 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
4303 static int nl80211_parse_mesh_config(struct genl_info *info,
4304 struct mesh_config *cfg,
4307 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
4310 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4313 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4315 cfg->param = fn(tb[attr]); \
4316 mask |= (1 << (attr - 1)); \
4321 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
4323 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
4324 info->attrs[NL80211_ATTR_MESH_CONFIG],
4325 nl80211_meshconf_params_policy))
4328 /* This makes sure that there aren't more than 32 mesh config
4329 * parameters (otherwise our bitfield scheme would not work.) */
4330 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4332 /* Fill in the params struct */
4333 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
4334 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4336 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
4337 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
4340 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4342 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
4343 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4345 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
4346 mask, NL80211_MESHCONF_MAX_RETRIES,
4348 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
4349 mask, NL80211_MESHCONF_TTL, nla_get_u8);
4350 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
4351 mask, NL80211_MESHCONF_ELEMENT_TTL,
4353 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
4354 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4356 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4358 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4360 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
4361 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4363 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
4364 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4366 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
4367 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4369 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4371 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4373 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
4375 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4377 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
4379 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4381 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4382 dot11MeshHWMPnetDiameterTraversalTime,
4384 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4386 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4387 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4389 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4390 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4392 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4393 dot11MeshGateAnnouncementProtocol, 0, 1,
4394 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4396 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
4397 mask, NL80211_MESHCONF_FORWARDING,
4399 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
4400 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4402 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
4403 mask, NL80211_MESHCONF_HT_OPMODE,
4405 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
4407 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
4410 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4412 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4413 dot11MeshHWMPconfirmationInterval,
4415 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4417 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4418 NL80211_MESH_POWER_ACTIVE,
4419 NL80211_MESH_POWER_MAX,
4420 mask, NL80211_MESHCONF_POWER_MODE,
4422 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4424 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
4430 #undef FILL_IN_MESH_PARAM_IF_SET
4433 static int nl80211_parse_mesh_setup(struct genl_info *info,
4434 struct mesh_setup *setup)
4436 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4438 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4440 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4441 info->attrs[NL80211_ATTR_MESH_SETUP],
4442 nl80211_mesh_setup_params_policy))
4445 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4446 setup->sync_method =
4447 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4448 IEEE80211_SYNC_METHOD_VENDOR :
4449 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4451 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4452 setup->path_sel_proto =
4453 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4454 IEEE80211_PATH_PROTOCOL_VENDOR :
4455 IEEE80211_PATH_PROTOCOL_HWMP;
4457 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4458 setup->path_metric =
4459 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4460 IEEE80211_PATH_METRIC_VENDOR :
4461 IEEE80211_PATH_METRIC_AIRTIME;
4464 if (tb[NL80211_MESH_SETUP_IE]) {
4465 struct nlattr *ieattr =
4466 tb[NL80211_MESH_SETUP_IE];
4467 if (!is_valid_ie_attr(ieattr))
4469 setup->ie = nla_data(ieattr);
4470 setup->ie_len = nla_len(ieattr);
4472 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4473 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
4478 static int nl80211_update_mesh_config(struct sk_buff *skb,
4479 struct genl_info *info)
4481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4482 struct net_device *dev = info->user_ptr[1];
4483 struct wireless_dev *wdev = dev->ieee80211_ptr;
4484 struct mesh_config cfg;
4488 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4491 if (!rdev->ops->update_mesh_config)
4494 err = nl80211_parse_mesh_config(info, &cfg, &mask);
4499 if (!wdev->mesh_id_len)
4503 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
4510 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4512 const struct ieee80211_regdomain *regdom;
4513 struct sk_buff *msg;
4515 struct nlattr *nl_reg_rules;
4519 mutex_lock(&cfg80211_mutex);
4521 if (!cfg80211_regdomain)
4524 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4530 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4531 NL80211_CMD_GET_REG);
4535 if (reg_last_request_cell_base() &&
4536 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4537 NL80211_USER_REG_HINT_CELL_BASE))
4538 goto nla_put_failure;
4541 regdom = rcu_dereference(cfg80211_regdomain);
4543 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4544 (regdom->dfs_region &&
4545 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4546 goto nla_put_failure_rcu;
4548 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4550 goto nla_put_failure_rcu;
4552 for (i = 0; i < regdom->n_reg_rules; i++) {
4553 struct nlattr *nl_reg_rule;
4554 const struct ieee80211_reg_rule *reg_rule;
4555 const struct ieee80211_freq_range *freq_range;
4556 const struct ieee80211_power_rule *power_rule;
4558 reg_rule = ®dom->reg_rules[i];
4559 freq_range = ®_rule->freq_range;
4560 power_rule = ®_rule->power_rule;
4562 nl_reg_rule = nla_nest_start(msg, i);
4564 goto nla_put_failure_rcu;
4566 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4568 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4569 freq_range->start_freq_khz) ||
4570 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4571 freq_range->end_freq_khz) ||
4572 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4573 freq_range->max_bandwidth_khz) ||
4574 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4575 power_rule->max_antenna_gain) ||
4576 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4577 power_rule->max_eirp))
4578 goto nla_put_failure_rcu;
4580 nla_nest_end(msg, nl_reg_rule);
4584 nla_nest_end(msg, nl_reg_rules);
4586 genlmsg_end(msg, hdr);
4587 err = genlmsg_reply(msg, info);
4590 nla_put_failure_rcu:
4593 genlmsg_cancel(msg, hdr);
4598 mutex_unlock(&cfg80211_mutex);
4602 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4604 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4605 struct nlattr *nl_reg_rule;
4606 char *alpha2 = NULL;
4607 int rem_reg_rules = 0, r = 0;
4608 u32 num_rules = 0, rule_idx = 0, size_of_regd;
4610 struct ieee80211_regdomain *rd = NULL;
4612 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4615 if (!info->attrs[NL80211_ATTR_REG_RULES])
4618 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4620 if (info->attrs[NL80211_ATTR_DFS_REGION])
4621 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4623 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4626 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
4630 size_of_regd = sizeof(struct ieee80211_regdomain) +
4631 num_rules * sizeof(struct ieee80211_reg_rule);
4633 rd = kzalloc(size_of_regd, GFP_KERNEL);
4637 rd->n_reg_rules = num_rules;
4638 rd->alpha2[0] = alpha2[0];
4639 rd->alpha2[1] = alpha2[1];
4642 * Disable DFS master mode if the DFS region was
4643 * not supported or known on this kernel.
4645 if (reg_supported_dfs_region(dfs_region))
4646 rd->dfs_region = dfs_region;
4648 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4650 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4651 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4653 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4659 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4665 mutex_lock(&cfg80211_mutex);
4668 /* set_regdom took ownership */
4670 mutex_unlock(&cfg80211_mutex);
4677 static int validate_scan_freqs(struct nlattr *freqs)
4679 struct nlattr *attr1, *attr2;
4680 int n_channels = 0, tmp1, tmp2;
4682 nla_for_each_nested(attr1, freqs, tmp1) {
4685 * Some hardware has a limited channel list for
4686 * scanning, and it is pretty much nonsensical
4687 * to scan for a channel twice, so disallow that
4688 * and don't require drivers to check that the
4689 * channel list they get isn't longer than what
4690 * they can scan, as long as they can scan all
4691 * the channels they registered at once.
4693 nla_for_each_nested(attr2, freqs, tmp2)
4694 if (attr1 != attr2 &&
4695 nla_get_u32(attr1) == nla_get_u32(attr2))
4702 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4705 struct wireless_dev *wdev = info->user_ptr[1];
4706 struct cfg80211_scan_request *request;
4707 struct nlattr *attr;
4708 struct wiphy *wiphy;
4709 int err, tmp, n_ssids = 0, n_channels, i;
4712 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4715 wiphy = &rdev->wiphy;
4717 if (!rdev->ops->scan)
4723 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4724 n_channels = validate_scan_freqs(
4725 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4729 enum ieee80211_band band;
4732 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4733 if (wiphy->bands[band])
4734 n_channels += wiphy->bands[band]->n_channels;
4737 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4738 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4741 if (n_ssids > wiphy->max_scan_ssids)
4744 if (info->attrs[NL80211_ATTR_IE])
4745 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4749 if (ie_len > wiphy->max_scan_ie_len)
4752 request = kzalloc(sizeof(*request)
4753 + sizeof(*request->ssids) * n_ssids
4754 + sizeof(*request->channels) * n_channels
4755 + ie_len, GFP_KERNEL);
4760 request->ssids = (void *)&request->channels[n_channels];
4761 request->n_ssids = n_ssids;
4764 request->ie = (void *)(request->ssids + n_ssids);
4766 request->ie = (void *)(request->channels + n_channels);
4770 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4771 /* user specified, bail out if channel not found */
4772 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
4773 struct ieee80211_channel *chan;
4775 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4782 /* ignore disabled channels */
4783 if (chan->flags & IEEE80211_CHAN_DISABLED)
4786 request->channels[i] = chan;
4790 enum ieee80211_band band;
4793 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4795 if (!wiphy->bands[band])
4797 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4798 struct ieee80211_channel *chan;
4800 chan = &wiphy->bands[band]->channels[j];
4802 if (chan->flags & IEEE80211_CHAN_DISABLED)
4805 request->channels[i] = chan;
4816 request->n_channels = i;
4819 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4820 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
4821 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
4825 request->ssids[i].ssid_len = nla_len(attr);
4826 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
4831 if (info->attrs[NL80211_ATTR_IE]) {
4832 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4833 memcpy((void *)request->ie,
4834 nla_data(info->attrs[NL80211_ATTR_IE]),
4838 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4839 if (wiphy->bands[i])
4841 (1 << wiphy->bands[i]->n_bitrates) - 1;
4843 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4844 nla_for_each_nested(attr,
4845 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4847 enum ieee80211_band band = nla_type(attr);
4849 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
4853 err = ieee80211_get_ratemask(wiphy->bands[band],
4856 &request->rates[band]);
4862 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
4863 request->flags = nla_get_u32(
4864 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
4865 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
4866 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
4867 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
4868 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
4875 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4877 request->wdev = wdev;
4878 request->wiphy = &rdev->wiphy;
4879 request->scan_start = jiffies;
4881 rdev->scan_req = request;
4882 err = rdev_scan(rdev, request);
4885 nl80211_send_scan_start(rdev, wdev);
4887 dev_hold(wdev->netdev);
4890 rdev->scan_req = NULL;
4897 static int nl80211_start_sched_scan(struct sk_buff *skb,
4898 struct genl_info *info)
4900 struct cfg80211_sched_scan_request *request;
4901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4902 struct net_device *dev = info->user_ptr[1];
4903 struct nlattr *attr;
4904 struct wiphy *wiphy;
4905 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
4907 enum ieee80211_band band;
4909 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
4911 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4912 !rdev->ops->sched_scan_start)
4915 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4918 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4921 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4925 wiphy = &rdev->wiphy;
4927 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4928 n_channels = validate_scan_freqs(
4929 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4935 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4936 if (wiphy->bands[band])
4937 n_channels += wiphy->bands[band]->n_channels;
4940 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4941 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4945 if (n_ssids > wiphy->max_sched_scan_ssids)
4948 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4949 nla_for_each_nested(attr,
4950 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4954 if (n_match_sets > wiphy->max_match_sets)
4957 if (info->attrs[NL80211_ATTR_IE])
4958 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4962 if (ie_len > wiphy->max_sched_scan_ie_len)
4965 mutex_lock(&rdev->sched_scan_mtx);
4967 if (rdev->sched_scan_req) {
4972 request = kzalloc(sizeof(*request)
4973 + sizeof(*request->ssids) * n_ssids
4974 + sizeof(*request->match_sets) * n_match_sets
4975 + sizeof(*request->channels) * n_channels
4976 + ie_len, GFP_KERNEL);
4983 request->ssids = (void *)&request->channels[n_channels];
4984 request->n_ssids = n_ssids;
4987 request->ie = (void *)(request->ssids + n_ssids);
4989 request->ie = (void *)(request->channels + n_channels);
4994 request->match_sets = (void *)(request->ie + ie_len);
4995 else if (request->ssids)
4996 request->match_sets =
4997 (void *)(request->ssids + n_ssids);
4999 request->match_sets =
5000 (void *)(request->channels + n_channels);
5002 request->n_match_sets = n_match_sets;
5005 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5006 /* user specified, bail out if channel not found */
5007 nla_for_each_nested(attr,
5008 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5010 struct ieee80211_channel *chan;
5012 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5019 /* ignore disabled channels */
5020 if (chan->flags & IEEE80211_CHAN_DISABLED)
5023 request->channels[i] = chan;
5028 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5030 if (!wiphy->bands[band])
5032 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5033 struct ieee80211_channel *chan;
5035 chan = &wiphy->bands[band]->channels[j];
5037 if (chan->flags & IEEE80211_CHAN_DISABLED)
5040 request->channels[i] = chan;
5051 request->n_channels = i;
5054 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5055 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5057 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
5061 request->ssids[i].ssid_len = nla_len(attr);
5062 memcpy(request->ssids[i].ssid, nla_data(attr),
5069 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5070 nla_for_each_nested(attr,
5071 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5073 struct nlattr *ssid, *rssi;
5075 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5076 nla_data(attr), nla_len(attr),
5077 nl80211_match_policy);
5078 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
5080 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5084 memcpy(request->match_sets[i].ssid.ssid,
5085 nla_data(ssid), nla_len(ssid));
5086 request->match_sets[i].ssid.ssid_len =
5089 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5091 request->rssi_thold = nla_get_u32(rssi);
5093 request->rssi_thold =
5094 NL80211_SCAN_RSSI_THOLD_OFF;
5099 if (info->attrs[NL80211_ATTR_IE]) {
5100 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5101 memcpy((void *)request->ie,
5102 nla_data(info->attrs[NL80211_ATTR_IE]),
5106 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
5107 request->flags = nla_get_u32(
5108 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
5109 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5110 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5111 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5112 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
5119 request->wiphy = &rdev->wiphy;
5120 request->interval = interval;
5121 request->scan_start = jiffies;
5123 err = rdev_sched_scan_start(rdev, dev, request);
5125 rdev->sched_scan_req = request;
5126 nl80211_send_sched_scan(rdev, dev,
5127 NL80211_CMD_START_SCHED_SCAN);
5134 mutex_unlock(&rdev->sched_scan_mtx);
5138 static int nl80211_stop_sched_scan(struct sk_buff *skb,
5139 struct genl_info *info)
5141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5144 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5145 !rdev->ops->sched_scan_stop)
5148 mutex_lock(&rdev->sched_scan_mtx);
5149 err = __cfg80211_stop_sched_scan(rdev, false);
5150 mutex_unlock(&rdev->sched_scan_mtx);
5155 static int nl80211_start_radar_detection(struct sk_buff *skb,
5156 struct genl_info *info)
5158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5159 struct net_device *dev = info->user_ptr[1];
5160 struct wireless_dev *wdev = dev->ieee80211_ptr;
5161 struct cfg80211_chan_def chandef;
5164 err = nl80211_parse_chandef(rdev, info, &chandef);
5168 if (wdev->cac_started)
5171 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5178 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5181 if (!rdev->ops->start_radar_detection)
5184 mutex_lock(&rdev->devlist_mtx);
5185 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5186 chandef.chan, CHAN_MODE_SHARED,
5187 BIT(chandef.width));
5191 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5193 wdev->channel = chandef.chan;
5194 wdev->cac_started = true;
5195 wdev->cac_start_time = jiffies;
5198 mutex_unlock(&rdev->devlist_mtx);
5203 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5205 struct cfg80211_registered_device *rdev,
5206 struct wireless_dev *wdev,
5207 struct cfg80211_internal_bss *intbss)
5209 struct cfg80211_bss *res = &intbss->pub;
5210 const struct cfg80211_bss_ies *ies;
5215 ASSERT_WDEV_LOCK(wdev);
5217 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5218 NL80211_CMD_NEW_SCAN_RESULTS);
5222 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5224 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5225 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5226 goto nla_put_failure;
5228 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5230 goto nla_put_failure;
5231 if ((!is_zero_ether_addr(res->bssid) &&
5232 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
5233 goto nla_put_failure;
5236 ies = rcu_dereference(res->ies);
5238 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5239 goto fail_unlock_rcu;
5241 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5242 ies->len, ies->data))
5243 goto fail_unlock_rcu;
5245 ies = rcu_dereference(res->beacon_ies);
5247 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5248 goto fail_unlock_rcu;
5249 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5250 ies->len, ies->data))
5251 goto fail_unlock_rcu;
5255 if (res->beacon_interval &&
5256 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5257 goto nla_put_failure;
5258 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5259 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5260 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5261 jiffies_to_msecs(jiffies - intbss->ts)))
5262 goto nla_put_failure;
5264 switch (rdev->wiphy.signal_type) {
5265 case CFG80211_SIGNAL_TYPE_MBM:
5266 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5267 goto nla_put_failure;
5269 case CFG80211_SIGNAL_TYPE_UNSPEC:
5270 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5271 goto nla_put_failure;
5277 switch (wdev->iftype) {
5278 case NL80211_IFTYPE_P2P_CLIENT:
5279 case NL80211_IFTYPE_STATION:
5280 if (intbss == wdev->current_bss &&
5281 nla_put_u32(msg, NL80211_BSS_STATUS,
5282 NL80211_BSS_STATUS_ASSOCIATED))
5283 goto nla_put_failure;
5285 case NL80211_IFTYPE_ADHOC:
5286 if (intbss == wdev->current_bss &&
5287 nla_put_u32(msg, NL80211_BSS_STATUS,
5288 NL80211_BSS_STATUS_IBSS_JOINED))
5289 goto nla_put_failure;
5295 nla_nest_end(msg, bss);
5297 return genlmsg_end(msg, hdr);
5302 genlmsg_cancel(msg, hdr);
5306 static int nl80211_dump_scan(struct sk_buff *skb,
5307 struct netlink_callback *cb)
5309 struct cfg80211_registered_device *rdev;
5310 struct net_device *dev;
5311 struct cfg80211_internal_bss *scan;
5312 struct wireless_dev *wdev;
5313 int start = cb->args[1], idx = 0;
5316 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5320 wdev = dev->ieee80211_ptr;
5323 spin_lock_bh(&rdev->bss_lock);
5324 cfg80211_bss_expire(rdev);
5326 cb->seq = rdev->bss_generation;
5328 list_for_each_entry(scan, &rdev->bss_list, list) {
5331 if (nl80211_send_bss(skb, cb,
5332 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5333 rdev, wdev, scan) < 0) {
5339 spin_unlock_bh(&rdev->bss_lock);
5343 nl80211_finish_netdev_dump(rdev);
5348 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
5349 int flags, struct net_device *dev,
5350 struct survey_info *survey)
5353 struct nlattr *infoattr;
5355 hdr = nl80211hdr_put(msg, portid, seq, flags,
5356 NL80211_CMD_NEW_SURVEY_RESULTS);
5360 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5361 goto nla_put_failure;
5363 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5365 goto nla_put_failure;
5367 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5368 survey->channel->center_freq))
5369 goto nla_put_failure;
5371 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5372 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5373 goto nla_put_failure;
5374 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5375 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5376 goto nla_put_failure;
5377 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5378 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5379 survey->channel_time))
5380 goto nla_put_failure;
5381 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5382 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5383 survey->channel_time_busy))
5384 goto nla_put_failure;
5385 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5386 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5387 survey->channel_time_ext_busy))
5388 goto nla_put_failure;
5389 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5390 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5391 survey->channel_time_rx))
5392 goto nla_put_failure;
5393 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5394 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5395 survey->channel_time_tx))
5396 goto nla_put_failure;
5398 nla_nest_end(msg, infoattr);
5400 return genlmsg_end(msg, hdr);
5403 genlmsg_cancel(msg, hdr);
5407 static int nl80211_dump_survey(struct sk_buff *skb,
5408 struct netlink_callback *cb)
5410 struct survey_info survey;
5411 struct cfg80211_registered_device *dev;
5412 struct net_device *netdev;
5413 int survey_idx = cb->args[1];
5416 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5420 if (!dev->ops->dump_survey) {
5426 struct ieee80211_channel *chan;
5428 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
5434 /* Survey without a channel doesn't make sense */
5435 if (!survey.channel) {
5440 chan = ieee80211_get_channel(&dev->wiphy,
5441 survey.channel->center_freq);
5442 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5447 if (nl80211_send_survey(skb,
5448 NETLINK_CB(cb->skb).portid,
5449 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5457 cb->args[1] = survey_idx;
5460 nl80211_finish_netdev_dump(dev);
5464 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5466 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5467 NL80211_WPA_VERSION_2));
5470 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5473 struct net_device *dev = info->user_ptr[1];
5474 struct ieee80211_channel *chan;
5475 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5476 int err, ssid_len, ie_len = 0, sae_data_len = 0;
5477 enum nl80211_auth_type auth_type;
5478 struct key_parse key;
5479 bool local_state_change;
5481 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5484 if (!info->attrs[NL80211_ATTR_MAC])
5487 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5490 if (!info->attrs[NL80211_ATTR_SSID])
5493 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5496 err = nl80211_parse_key(info, &key);
5501 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5503 if (!key.p.key || !key.p.key_len)
5505 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5506 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5507 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5508 key.p.key_len != WLAN_KEY_LEN_WEP104))
5520 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5521 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5530 if (!rdev->ops->auth)
5533 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5534 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5537 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5538 chan = ieee80211_get_channel(&rdev->wiphy,
5539 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5540 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5543 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5544 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5546 if (info->attrs[NL80211_ATTR_IE]) {
5547 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5548 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5551 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5552 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
5555 if (auth_type == NL80211_AUTHTYPE_SAE &&
5556 !info->attrs[NL80211_ATTR_SAE_DATA])
5559 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5560 if (auth_type != NL80211_AUTHTYPE_SAE)
5562 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5563 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5564 /* need to include at least Auth Transaction and Status Code */
5565 if (sae_data_len < 4)
5569 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5572 * Since we no longer track auth state, ignore
5573 * requests to only change local state.
5575 if (local_state_change)
5578 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5579 ssid, ssid_len, ie, ie_len,
5580 key.p.key, key.p.key_len, key.idx,
5581 sae_data, sae_data_len);
5584 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5585 struct genl_info *info,
5586 struct cfg80211_crypto_settings *settings,
5589 memset(settings, 0, sizeof(*settings));
5591 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5593 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5595 proto = nla_get_u16(
5596 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5597 settings->control_port_ethertype = cpu_to_be16(proto);
5598 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5601 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5602 settings->control_port_no_encrypt = true;
5604 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5606 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5610 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5611 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5612 settings->n_ciphers_pairwise = len / sizeof(u32);
5614 if (len % sizeof(u32))
5617 if (settings->n_ciphers_pairwise > cipher_limit)
5620 memcpy(settings->ciphers_pairwise, data, len);
5622 for (i = 0; i < settings->n_ciphers_pairwise; i++)
5623 if (!cfg80211_supported_cipher_suite(
5625 settings->ciphers_pairwise[i]))
5629 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5630 settings->cipher_group =
5631 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
5632 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5633 settings->cipher_group))
5637 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5638 settings->wpa_versions =
5639 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5640 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5644 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5648 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5649 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5650 settings->n_akm_suites = len / sizeof(u32);
5652 if (len % sizeof(u32))
5655 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5658 memcpy(settings->akm_suites, data, len);
5664 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5667 struct net_device *dev = info->user_ptr[1];
5668 struct cfg80211_crypto_settings crypto;
5669 struct ieee80211_channel *chan;
5670 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
5671 int err, ssid_len, ie_len = 0;
5672 bool use_mfp = false;
5674 struct ieee80211_ht_cap *ht_capa = NULL;
5675 struct ieee80211_ht_cap *ht_capa_mask = NULL;
5677 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5680 if (!info->attrs[NL80211_ATTR_MAC] ||
5681 !info->attrs[NL80211_ATTR_SSID] ||
5682 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5685 if (!rdev->ops->assoc)
5688 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5689 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5692 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5694 chan = ieee80211_get_channel(&rdev->wiphy,
5695 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5696 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5699 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5700 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5702 if (info->attrs[NL80211_ATTR_IE]) {
5703 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5704 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5707 if (info->attrs[NL80211_ATTR_USE_MFP]) {
5708 enum nl80211_mfp mfp =
5709 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
5710 if (mfp == NL80211_MFP_REQUIRED)
5712 else if (mfp != NL80211_MFP_NO)
5716 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5717 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5719 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5720 flags |= ASSOC_REQ_DISABLE_HT;
5722 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5724 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5726 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5729 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5732 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
5734 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5735 ssid, ssid_len, ie, ie_len, use_mfp,
5736 &crypto, flags, ht_capa,
5742 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5745 struct net_device *dev = info->user_ptr[1];
5746 const u8 *ie = NULL, *bssid;
5749 bool local_state_change;
5751 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5754 if (!info->attrs[NL80211_ATTR_MAC])
5757 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5760 if (!rdev->ops->deauth)
5763 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5764 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5767 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5769 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5770 if (reason_code == 0) {
5771 /* Reason Code 0 is reserved */
5775 if (info->attrs[NL80211_ATTR_IE]) {
5776 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5777 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5780 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5782 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5783 local_state_change);
5786 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5789 struct net_device *dev = info->user_ptr[1];
5790 const u8 *ie = NULL, *bssid;
5793 bool local_state_change;
5795 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5798 if (!info->attrs[NL80211_ATTR_MAC])
5801 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5804 if (!rdev->ops->disassoc)
5807 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5808 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5811 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5813 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5814 if (reason_code == 0) {
5815 /* Reason Code 0 is reserved */
5819 if (info->attrs[NL80211_ATTR_IE]) {
5820 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5821 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5824 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5826 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5827 local_state_change);
5831 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5832 int mcast_rate[IEEE80211_NUM_BANDS],
5835 struct wiphy *wiphy = &rdev->wiphy;
5839 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5840 struct ieee80211_supported_band *sband;
5842 sband = wiphy->bands[band];
5846 for (i = 0; i < sband->n_bitrates; i++) {
5847 if (sband->bitrates[i].bitrate == rateval) {
5848 mcast_rate[band] = i + 1;
5858 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5861 struct net_device *dev = info->user_ptr[1];
5862 struct cfg80211_ibss_params ibss;
5863 struct wiphy *wiphy;
5864 struct cfg80211_cached_keys *connkeys = NULL;
5867 memset(&ibss, 0, sizeof(ibss));
5869 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5872 if (!info->attrs[NL80211_ATTR_SSID] ||
5873 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5876 ibss.beacon_interval = 100;
5878 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5879 ibss.beacon_interval =
5880 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5881 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5885 if (!rdev->ops->join_ibss)
5888 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5891 wiphy = &rdev->wiphy;
5893 if (info->attrs[NL80211_ATTR_MAC]) {
5894 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5896 if (!is_valid_ether_addr(ibss.bssid))
5899 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5900 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5902 if (info->attrs[NL80211_ATTR_IE]) {
5903 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5904 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5907 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
5911 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
5914 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
5916 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
5917 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
5920 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
5921 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5923 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5925 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5927 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5928 struct ieee80211_supported_band *sband =
5929 wiphy->bands[ibss.chandef.chan->band];
5931 err = ieee80211_get_ratemask(sband, rates, n_rates,
5937 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5938 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5939 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5942 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5945 connkeys = nl80211_parse_connkeys(rdev,
5946 info->attrs[NL80211_ATTR_KEYS],
5948 if (IS_ERR(connkeys))
5949 return PTR_ERR(connkeys);
5951 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
5959 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5961 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
5967 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5970 struct net_device *dev = info->user_ptr[1];
5972 if (!rdev->ops->leave_ibss)
5975 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5978 return cfg80211_leave_ibss(rdev, dev, false);
5981 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
5983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5984 struct net_device *dev = info->user_ptr[1];
5985 int mcast_rate[IEEE80211_NUM_BANDS];
5989 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5990 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5993 if (!rdev->ops->set_mcast_rate)
5996 memset(mcast_rate, 0, sizeof(mcast_rate));
5998 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6001 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6002 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6005 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6011 #ifdef CONFIG_NL80211_TESTMODE
6012 static struct genl_multicast_group nl80211_testmode_mcgrp = {
6016 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6021 if (!info->attrs[NL80211_ATTR_TESTDATA])
6025 if (rdev->ops->testmode_cmd) {
6026 rdev->testmode_info = info;
6027 err = rdev_testmode_cmd(rdev,
6028 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6029 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6030 rdev->testmode_info = NULL;
6036 static int nl80211_testmode_dump(struct sk_buff *skb,
6037 struct netlink_callback *cb)
6039 struct cfg80211_registered_device *rdev;
6047 * 0 is a valid index, but not valid for args[0],
6048 * so we need to offset by 1.
6050 phy_idx = cb->args[0] - 1;
6052 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6053 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6058 mutex_lock(&cfg80211_mutex);
6059 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6060 nl80211_fam.attrbuf);
6062 mutex_unlock(&cfg80211_mutex);
6063 return PTR_ERR(rdev);
6065 phy_idx = rdev->wiphy_idx;
6067 mutex_unlock(&cfg80211_mutex);
6069 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6071 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6075 data = nla_data((void *)cb->args[1]);
6076 data_len = nla_len((void *)cb->args[1]);
6079 mutex_lock(&cfg80211_mutex);
6080 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6082 mutex_unlock(&cfg80211_mutex);
6085 cfg80211_lock_rdev(rdev);
6086 mutex_unlock(&cfg80211_mutex);
6088 if (!rdev->ops->testmode_dump) {
6094 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
6095 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6096 NL80211_CMD_TESTMODE);
6097 struct nlattr *tmdata;
6099 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
6100 genlmsg_cancel(skb, hdr);
6104 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6106 genlmsg_cancel(skb, hdr);
6109 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
6110 nla_nest_end(skb, tmdata);
6112 if (err == -ENOBUFS || err == -ENOENT) {
6113 genlmsg_cancel(skb, hdr);
6116 genlmsg_cancel(skb, hdr);
6120 genlmsg_end(skb, hdr);
6125 cb->args[0] = phy_idx + 1;
6127 cfg80211_unlock_rdev(rdev);
6131 static struct sk_buff *
6132 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
6133 int approxlen, u32 portid, u32 seq, gfp_t gfp)
6135 struct sk_buff *skb;
6137 struct nlattr *data;
6139 skb = nlmsg_new(approxlen + 100, gfp);
6143 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
6149 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6150 goto nla_put_failure;
6151 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6153 ((void **)skb->cb)[0] = rdev;
6154 ((void **)skb->cb)[1] = hdr;
6155 ((void **)skb->cb)[2] = data;
6164 struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6167 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6169 if (WARN_ON(!rdev->testmode_info))
6172 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
6173 rdev->testmode_info->snd_portid,
6174 rdev->testmode_info->snd_seq,
6177 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6179 int cfg80211_testmode_reply(struct sk_buff *skb)
6181 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6182 void *hdr = ((void **)skb->cb)[1];
6183 struct nlattr *data = ((void **)skb->cb)[2];
6185 if (WARN_ON(!rdev->testmode_info)) {
6190 nla_nest_end(skb, data);
6191 genlmsg_end(skb, hdr);
6192 return genlmsg_reply(skb, rdev->testmode_info);
6194 EXPORT_SYMBOL(cfg80211_testmode_reply);
6196 struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6197 int approxlen, gfp_t gfp)
6199 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6201 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6203 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6205 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6207 void *hdr = ((void **)skb->cb)[1];
6208 struct nlattr *data = ((void **)skb->cb)[2];
6210 nla_nest_end(skb, data);
6211 genlmsg_end(skb, hdr);
6212 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6214 EXPORT_SYMBOL(cfg80211_testmode_event);
6217 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6220 struct net_device *dev = info->user_ptr[1];
6221 struct cfg80211_connect_params connect;
6222 struct wiphy *wiphy;
6223 struct cfg80211_cached_keys *connkeys = NULL;
6226 memset(&connect, 0, sizeof(connect));
6228 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6231 if (!info->attrs[NL80211_ATTR_SSID] ||
6232 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6235 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6237 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
6238 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6239 NL80211_CMD_CONNECT))
6242 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6244 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6246 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
6247 NL80211_MAX_NR_CIPHER_SUITES);
6251 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6252 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6255 wiphy = &rdev->wiphy;
6257 connect.bg_scan_period = -1;
6258 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6259 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6260 connect.bg_scan_period =
6261 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6264 if (info->attrs[NL80211_ATTR_MAC])
6265 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6266 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6267 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6269 if (info->attrs[NL80211_ATTR_IE]) {
6270 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6271 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6274 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6275 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6276 if (connect.mfp != NL80211_MFP_REQUIRED &&
6277 connect.mfp != NL80211_MFP_NO)
6280 connect.mfp = NL80211_MFP_NO;
6283 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6285 ieee80211_get_channel(wiphy,
6286 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6287 if (!connect.channel ||
6288 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6292 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6293 connkeys = nl80211_parse_connkeys(rdev,
6294 info->attrs[NL80211_ATTR_KEYS], NULL);
6295 if (IS_ERR(connkeys))
6296 return PTR_ERR(connkeys);
6299 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6300 connect.flags |= ASSOC_REQ_DISABLE_HT;
6302 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6303 memcpy(&connect.ht_capa_mask,
6304 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6305 sizeof(connect.ht_capa_mask));
6307 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6308 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6312 memcpy(&connect.ht_capa,
6313 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6314 sizeof(connect.ht_capa));
6317 err = cfg80211_connect(rdev, dev, &connect, connkeys);
6323 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6326 struct net_device *dev = info->user_ptr[1];
6329 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6330 reason = WLAN_REASON_DEAUTH_LEAVING;
6332 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6337 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6338 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6341 return cfg80211_disconnect(rdev, dev, reason, true);
6344 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6351 if (!info->attrs[NL80211_ATTR_PID])
6354 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6356 net = get_net_ns_by_pid(pid);
6358 return PTR_ERR(net);
6362 /* check if anything to do */
6363 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6364 err = cfg80211_switch_netns(rdev, net);
6370 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6373 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6374 struct cfg80211_pmksa *pmksa) = NULL;
6375 struct net_device *dev = info->user_ptr[1];
6376 struct cfg80211_pmksa pmksa;
6378 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6380 if (!info->attrs[NL80211_ATTR_MAC])
6383 if (!info->attrs[NL80211_ATTR_PMKID])
6386 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6387 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6390 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6393 switch (info->genlhdr->cmd) {
6394 case NL80211_CMD_SET_PMKSA:
6395 rdev_ops = rdev->ops->set_pmksa;
6397 case NL80211_CMD_DEL_PMKSA:
6398 rdev_ops = rdev->ops->del_pmksa;
6408 return rdev_ops(&rdev->wiphy, dev, &pmksa);
6411 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6414 struct net_device *dev = info->user_ptr[1];
6416 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6417 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6420 if (!rdev->ops->flush_pmksa)
6423 return rdev_flush_pmksa(rdev, dev);
6426 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6428 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6429 struct net_device *dev = info->user_ptr[1];
6430 u8 action_code, dialog_token;
6434 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6435 !rdev->ops->tdls_mgmt)
6438 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6439 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6440 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6441 !info->attrs[NL80211_ATTR_IE] ||
6442 !info->attrs[NL80211_ATTR_MAC])
6445 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6446 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6447 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6448 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6450 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6451 dialog_token, status_code,
6452 nla_data(info->attrs[NL80211_ATTR_IE]),
6453 nla_len(info->attrs[NL80211_ATTR_IE]));
6456 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6459 struct net_device *dev = info->user_ptr[1];
6460 enum nl80211_tdls_operation operation;
6463 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6464 !rdev->ops->tdls_oper)
6467 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6468 !info->attrs[NL80211_ATTR_MAC])
6471 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6472 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6474 return rdev_tdls_oper(rdev, dev, peer, operation);
6477 static int nl80211_remain_on_channel(struct sk_buff *skb,
6478 struct genl_info *info)
6480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6481 struct wireless_dev *wdev = info->user_ptr[1];
6482 struct cfg80211_chan_def chandef;
6483 struct sk_buff *msg;
6489 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6490 !info->attrs[NL80211_ATTR_DURATION])
6493 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6495 if (!rdev->ops->remain_on_channel ||
6496 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
6500 * We should be on that channel for at least a minimum amount of
6501 * time (10ms) but no longer than the driver supports.
6503 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6504 duration > rdev->wiphy.max_remain_on_channel_duration)
6507 err = nl80211_parse_chandef(rdev, info, &chandef);
6511 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6515 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6516 NL80211_CMD_REMAIN_ON_CHANNEL);
6523 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6529 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6530 goto nla_put_failure;
6532 genlmsg_end(msg, hdr);
6534 return genlmsg_reply(msg, info);
6543 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6544 struct genl_info *info)
6546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6547 struct wireless_dev *wdev = info->user_ptr[1];
6550 if (!info->attrs[NL80211_ATTR_COOKIE])
6553 if (!rdev->ops->cancel_remain_on_channel)
6556 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6558 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
6561 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6562 u8 *rates, u8 rates_len)
6567 for (i = 0; i < rates_len; i++) {
6568 int rate = (rates[i] & 0x7f) * 5;
6570 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6571 struct ieee80211_rate *srate =
6572 &sband->bitrates[ridx];
6573 if (rate == srate->bitrate) {
6578 if (ridx == sband->n_bitrates)
6579 return 0; /* rate not found */
6585 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6586 u8 *rates, u8 rates_len,
6587 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6591 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6593 for (i = 0; i < rates_len; i++) {
6596 ridx = rates[i] / 8;
6597 rbit = BIT(rates[i] % 8);
6599 /* check validity */
6600 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
6603 /* check availability */
6604 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6613 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
6614 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6615 .len = NL80211_MAX_SUPP_RATES },
6616 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6617 .len = NL80211_MAX_SUPP_HT_RATES },
6620 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6621 struct genl_info *info)
6623 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
6624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6625 struct cfg80211_bitrate_mask mask;
6627 struct net_device *dev = info->user_ptr[1];
6628 struct nlattr *tx_rates;
6629 struct ieee80211_supported_band *sband;
6631 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6634 if (!rdev->ops->set_bitrate_mask)
6637 memset(&mask, 0, sizeof(mask));
6638 /* Default to all rates enabled */
6639 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6640 sband = rdev->wiphy.bands[i];
6641 mask.control[i].legacy =
6642 sband ? (1 << sband->n_bitrates) - 1 : 0;
6644 memcpy(mask.control[i].mcs,
6645 sband->ht_cap.mcs.rx_mask,
6646 sizeof(mask.control[i].mcs));
6648 memset(mask.control[i].mcs, 0,
6649 sizeof(mask.control[i].mcs));
6653 * The nested attribute uses enum nl80211_band as the index. This maps
6654 * directly to the enum ieee80211_band values used in cfg80211.
6656 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
6657 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6659 enum ieee80211_band band = nla_type(tx_rates);
6660 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6662 sband = rdev->wiphy.bands[band];
6665 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6666 nla_len(tx_rates), nl80211_txattr_policy);
6667 if (tb[NL80211_TXRATE_LEGACY]) {
6668 mask.control[band].legacy = rateset_to_mask(
6670 nla_data(tb[NL80211_TXRATE_LEGACY]),
6671 nla_len(tb[NL80211_TXRATE_LEGACY]));
6672 if ((mask.control[band].legacy == 0) &&
6673 nla_len(tb[NL80211_TXRATE_LEGACY]))
6676 if (tb[NL80211_TXRATE_MCS]) {
6677 if (!ht_rateset_to_mask(
6679 nla_data(tb[NL80211_TXRATE_MCS]),
6680 nla_len(tb[NL80211_TXRATE_MCS]),
6681 mask.control[band].mcs))
6685 if (mask.control[band].legacy == 0) {
6686 /* don't allow empty legacy rates if HT
6687 * is not even supported. */
6688 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6691 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6692 if (mask.control[band].mcs[i])
6695 /* legacy and mcs rates may not be both empty */
6696 if (i == IEEE80211_HT_MCS_MASK_LEN)
6701 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
6704 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
6706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6707 struct wireless_dev *wdev = info->user_ptr[1];
6708 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
6710 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6713 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6714 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
6716 switch (wdev->iftype) {
6717 case NL80211_IFTYPE_STATION:
6718 case NL80211_IFTYPE_ADHOC:
6719 case NL80211_IFTYPE_P2P_CLIENT:
6720 case NL80211_IFTYPE_AP:
6721 case NL80211_IFTYPE_AP_VLAN:
6722 case NL80211_IFTYPE_MESH_POINT:
6723 case NL80211_IFTYPE_P2P_GO:
6724 case NL80211_IFTYPE_P2P_DEVICE:
6730 /* not much point in registering if we can't reply */
6731 if (!rdev->ops->mgmt_tx)
6734 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
6735 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6736 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
6739 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
6741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6742 struct wireless_dev *wdev = info->user_ptr[1];
6743 struct cfg80211_chan_def chandef;
6747 struct sk_buff *msg = NULL;
6748 unsigned int wait = 0;
6749 bool offchan, no_cck, dont_wait_for_ack;
6751 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
6753 if (!info->attrs[NL80211_ATTR_FRAME])
6756 if (!rdev->ops->mgmt_tx)
6759 switch (wdev->iftype) {
6760 case NL80211_IFTYPE_STATION:
6761 case NL80211_IFTYPE_ADHOC:
6762 case NL80211_IFTYPE_P2P_CLIENT:
6763 case NL80211_IFTYPE_AP:
6764 case NL80211_IFTYPE_AP_VLAN:
6765 case NL80211_IFTYPE_MESH_POINT:
6766 case NL80211_IFTYPE_P2P_GO:
6767 case NL80211_IFTYPE_P2P_DEVICE:
6773 if (info->attrs[NL80211_ATTR_DURATION]) {
6774 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6776 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6779 * We should wait on the channel for at least a minimum amount
6780 * of time (10ms) but no longer than the driver supports.
6782 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6783 wait > rdev->wiphy.max_remain_on_channel_duration)
6788 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6790 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6793 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6795 err = nl80211_parse_chandef(rdev, info, &chandef);
6799 if (!dont_wait_for_ack) {
6800 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6804 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6813 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
6814 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6815 nla_len(info->attrs[NL80211_ATTR_FRAME]),
6816 no_cck, dont_wait_for_ack, &cookie);
6821 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6822 goto nla_put_failure;
6824 genlmsg_end(msg, hdr);
6825 return genlmsg_reply(msg, info);
6837 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6840 struct wireless_dev *wdev = info->user_ptr[1];
6843 if (!info->attrs[NL80211_ATTR_COOKIE])
6846 if (!rdev->ops->mgmt_tx_cancel_wait)
6849 switch (wdev->iftype) {
6850 case NL80211_IFTYPE_STATION:
6851 case NL80211_IFTYPE_ADHOC:
6852 case NL80211_IFTYPE_P2P_CLIENT:
6853 case NL80211_IFTYPE_AP:
6854 case NL80211_IFTYPE_AP_VLAN:
6855 case NL80211_IFTYPE_P2P_GO:
6856 case NL80211_IFTYPE_P2P_DEVICE:
6862 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6864 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
6867 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6870 struct wireless_dev *wdev;
6871 struct net_device *dev = info->user_ptr[1];
6876 if (!info->attrs[NL80211_ATTR_PS_STATE])
6879 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6881 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6884 wdev = dev->ieee80211_ptr;
6886 if (!rdev->ops->set_power_mgmt)
6889 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6891 if (state == wdev->ps)
6894 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
6900 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6903 enum nl80211_ps_state ps_state;
6904 struct wireless_dev *wdev;
6905 struct net_device *dev = info->user_ptr[1];
6906 struct sk_buff *msg;
6910 wdev = dev->ieee80211_ptr;
6912 if (!rdev->ops->set_power_mgmt)
6915 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6919 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6920 NL80211_CMD_GET_POWER_SAVE);
6927 ps_state = NL80211_PS_ENABLED;
6929 ps_state = NL80211_PS_DISABLED;
6931 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6932 goto nla_put_failure;
6934 genlmsg_end(msg, hdr);
6935 return genlmsg_reply(msg, info);
6944 static struct nla_policy
6945 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6946 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6947 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6948 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6949 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6950 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6951 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
6954 static int nl80211_set_cqm_txe(struct genl_info *info,
6955 u32 rate, u32 pkts, u32 intvl)
6957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6958 struct wireless_dev *wdev;
6959 struct net_device *dev = info->user_ptr[1];
6961 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
6964 wdev = dev->ieee80211_ptr;
6966 if (!rdev->ops->set_cqm_txe_config)
6969 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6970 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6973 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
6976 static int nl80211_set_cqm_rssi(struct genl_info *info,
6977 s32 threshold, u32 hysteresis)
6979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6980 struct wireless_dev *wdev;
6981 struct net_device *dev = info->user_ptr[1];
6986 wdev = dev->ieee80211_ptr;
6988 if (!rdev->ops->set_cqm_rssi_config)
6991 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6992 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6995 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
6998 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7000 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7004 cqm = info->attrs[NL80211_ATTR_CQM];
7010 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7011 nl80211_attr_cqm_policy);
7015 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7016 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7019 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7020 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7021 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
7022 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7023 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7024 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7025 u32 rate, pkts, intvl;
7026 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7027 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7028 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7029 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
7037 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7040 struct net_device *dev = info->user_ptr[1];
7041 struct mesh_config cfg;
7042 struct mesh_setup setup;
7045 /* start with default */
7046 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
7047 memcpy(&setup, &default_mesh_setup, sizeof(setup));
7049 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
7050 /* and parse parameters if given */
7051 err = nl80211_parse_mesh_config(info, &cfg, NULL);
7056 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7057 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7060 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7061 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7063 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7064 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7065 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7068 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7069 setup.beacon_interval =
7070 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7071 if (setup.beacon_interval < 10 ||
7072 setup.beacon_interval > 10000)
7076 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7078 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7079 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7083 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7084 /* parse additional setup parameters if given */
7085 err = nl80211_parse_mesh_setup(info, &setup);
7090 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7091 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7095 /* cfg80211_join_mesh() will sort it out */
7096 setup.chandef.chan = NULL;
7099 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
7102 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7105 struct net_device *dev = info->user_ptr[1];
7107 return cfg80211_leave_mesh(rdev, dev);
7111 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7112 struct cfg80211_registered_device *rdev)
7114 struct nlattr *nl_pats, *nl_pat;
7117 if (!rdev->wowlan->n_patterns)
7120 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7124 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7125 nl_pat = nla_nest_start(msg, i + 1);
7128 pat_len = rdev->wowlan->patterns[i].pattern_len;
7129 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7130 DIV_ROUND_UP(pat_len, 8),
7131 rdev->wowlan->patterns[i].mask) ||
7132 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7133 pat_len, rdev->wowlan->patterns[i].pattern) ||
7134 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7135 rdev->wowlan->patterns[i].pkt_offset))
7137 nla_nest_end(msg, nl_pat);
7139 nla_nest_end(msg, nl_pats);
7144 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7145 struct cfg80211_wowlan_tcp *tcp)
7147 struct nlattr *nl_tcp;
7152 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7156 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7157 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7158 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7159 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7160 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7161 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7162 tcp->payload_len, tcp->payload) ||
7163 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7164 tcp->data_interval) ||
7165 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7166 tcp->wake_len, tcp->wake_data) ||
7167 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7168 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7171 if (tcp->payload_seq.len &&
7172 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7173 sizeof(tcp->payload_seq), &tcp->payload_seq))
7176 if (tcp->payload_tok.len &&
7177 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7178 sizeof(tcp->payload_tok) + tcp->tokens_size,
7185 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7188 struct sk_buff *msg;
7190 u32 size = NLMSG_DEFAULT_SIZE;
7192 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7193 !rdev->wiphy.wowlan.tcp)
7196 if (rdev->wowlan && rdev->wowlan->tcp) {
7197 /* adjust size to have room for all the data */
7198 size += rdev->wowlan->tcp->tokens_size +
7199 rdev->wowlan->tcp->payload_len +
7200 rdev->wowlan->tcp->wake_len +
7201 rdev->wowlan->tcp->wake_len / 8;
7204 msg = nlmsg_new(size, GFP_KERNEL);
7208 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7209 NL80211_CMD_GET_WOWLAN);
7211 goto nla_put_failure;
7214 struct nlattr *nl_wowlan;
7216 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7218 goto nla_put_failure;
7220 if ((rdev->wowlan->any &&
7221 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7222 (rdev->wowlan->disconnect &&
7223 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7224 (rdev->wowlan->magic_pkt &&
7225 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7226 (rdev->wowlan->gtk_rekey_failure &&
7227 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7228 (rdev->wowlan->eap_identity_req &&
7229 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7230 (rdev->wowlan->four_way_handshake &&
7231 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7232 (rdev->wowlan->rfkill_release &&
7233 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7234 goto nla_put_failure;
7236 if (nl80211_send_wowlan_patterns(msg, rdev))
7237 goto nla_put_failure;
7239 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7240 goto nla_put_failure;
7242 nla_nest_end(msg, nl_wowlan);
7245 genlmsg_end(msg, hdr);
7246 return genlmsg_reply(msg, info);
7253 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7254 struct nlattr *attr,
7255 struct cfg80211_wowlan *trig)
7257 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7258 struct cfg80211_wowlan_tcp *cfg;
7259 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7260 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7262 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7265 if (!rdev->wiphy.wowlan.tcp)
7268 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7269 nla_data(attr), nla_len(attr),
7270 nl80211_wowlan_tcp_policy);
7274 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7275 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7276 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7277 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7278 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7279 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7280 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7281 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7284 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7285 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7288 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7289 rdev->wiphy.wowlan.tcp->data_interval_max)
7292 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7293 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7296 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7297 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7300 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7301 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7303 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7304 tokens_size = tokln - sizeof(*tok);
7306 if (!tok->len || tokens_size % tok->len)
7308 if (!rdev->wiphy.wowlan.tcp->tok)
7310 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7312 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7314 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7316 if (tok->offset + tok->len > data_size)
7320 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7321 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7322 if (!rdev->wiphy.wowlan.tcp->seq)
7324 if (seq->len == 0 || seq->len > 4)
7326 if (seq->len + seq->offset > data_size)
7330 size = sizeof(*cfg);
7332 size += wake_size + wake_mask_size;
7333 size += tokens_size;
7335 cfg = kzalloc(size, GFP_KERNEL);
7338 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7339 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7340 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7342 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7343 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7347 /* allocate a socket and port for it and use it */
7348 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7349 IPPROTO_TCP, &cfg->sock, 1);
7354 if (inet_csk_get_port(cfg->sock->sk, port)) {
7355 sock_release(cfg->sock);
7359 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7365 cfg->src_port = port;
7368 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7369 cfg->payload_len = data_size;
7370 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7371 memcpy((void *)cfg->payload,
7372 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7375 cfg->payload_seq = *seq;
7376 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7377 cfg->wake_len = wake_size;
7378 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7379 memcpy((void *)cfg->wake_data,
7380 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7382 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7383 data_size + wake_size;
7384 memcpy((void *)cfg->wake_mask,
7385 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7388 cfg->tokens_size = tokens_size;
7389 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7397 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7400 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
7401 struct cfg80211_wowlan new_triggers = {};
7402 struct cfg80211_wowlan *ntrig;
7403 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7405 bool prev_enabled = rdev->wowlan;
7407 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7408 !rdev->wiphy.wowlan.tcp)
7411 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7412 cfg80211_rdev_free_wowlan(rdev);
7413 rdev->wowlan = NULL;
7417 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7418 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7419 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7420 nl80211_wowlan_policy);
7424 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7425 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7427 new_triggers.any = true;
7430 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7431 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7433 new_triggers.disconnect = true;
7436 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7437 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7439 new_triggers.magic_pkt = true;
7442 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7445 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7446 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7448 new_triggers.gtk_rekey_failure = true;
7451 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7452 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7454 new_triggers.eap_identity_req = true;
7457 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7458 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7460 new_triggers.four_way_handshake = true;
7463 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7464 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7466 new_triggers.rfkill_release = true;
7469 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7472 int rem, pat_len, mask_len, pkt_offset;
7473 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7475 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7478 if (n_patterns > wowlan->n_patterns)
7481 new_triggers.patterns = kcalloc(n_patterns,
7482 sizeof(new_triggers.patterns[0]),
7484 if (!new_triggers.patterns)
7487 new_triggers.n_patterns = n_patterns;
7490 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7492 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7493 nla_data(pat), nla_len(pat), NULL);
7495 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7496 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7498 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7499 mask_len = DIV_ROUND_UP(pat_len, 8);
7500 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7503 if (pat_len > wowlan->pattern_max_len ||
7504 pat_len < wowlan->pattern_min_len)
7507 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7510 pkt_offset = nla_get_u32(
7511 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7512 if (pkt_offset > wowlan->max_pkt_offset)
7514 new_triggers.patterns[i].pkt_offset = pkt_offset;
7516 new_triggers.patterns[i].mask =
7517 kmalloc(mask_len + pat_len, GFP_KERNEL);
7518 if (!new_triggers.patterns[i].mask) {
7522 new_triggers.patterns[i].pattern =
7523 new_triggers.patterns[i].mask + mask_len;
7524 memcpy(new_triggers.patterns[i].mask,
7525 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7527 new_triggers.patterns[i].pattern_len = pat_len;
7528 memcpy(new_triggers.patterns[i].pattern,
7529 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7535 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7536 err = nl80211_parse_wowlan_tcp(
7537 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7543 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7548 cfg80211_rdev_free_wowlan(rdev);
7549 rdev->wowlan = ntrig;
7552 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
7553 rdev_set_wakeup(rdev, rdev->wowlan);
7557 for (i = 0; i < new_triggers.n_patterns; i++)
7558 kfree(new_triggers.patterns[i].mask);
7559 kfree(new_triggers.patterns);
7560 if (new_triggers.tcp && new_triggers.tcp->sock)
7561 sock_release(new_triggers.tcp->sock);
7562 kfree(new_triggers.tcp);
7567 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7570 struct net_device *dev = info->user_ptr[1];
7571 struct wireless_dev *wdev = dev->ieee80211_ptr;
7572 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7573 struct cfg80211_gtk_rekey_data rekey_data;
7576 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7579 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7580 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7581 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7582 nl80211_rekey_policy);
7586 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7588 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7590 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7593 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7595 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7597 memcpy(rekey_data.replay_ctr,
7598 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7599 NL80211_REPLAY_CTR_LEN);
7602 if (!wdev->current_bss) {
7607 if (!rdev->ops->set_rekey_data) {
7612 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
7618 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7619 struct genl_info *info)
7621 struct net_device *dev = info->user_ptr[1];
7622 struct wireless_dev *wdev = dev->ieee80211_ptr;
7624 if (wdev->iftype != NL80211_IFTYPE_AP &&
7625 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7628 if (wdev->ap_unexpected_nlportid)
7631 wdev->ap_unexpected_nlportid = info->snd_portid;
7635 static int nl80211_probe_client(struct sk_buff *skb,
7636 struct genl_info *info)
7638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7639 struct net_device *dev = info->user_ptr[1];
7640 struct wireless_dev *wdev = dev->ieee80211_ptr;
7641 struct sk_buff *msg;
7647 if (wdev->iftype != NL80211_IFTYPE_AP &&
7648 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7651 if (!info->attrs[NL80211_ATTR_MAC])
7654 if (!rdev->ops->probe_client)
7657 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7661 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7662 NL80211_CMD_PROBE_CLIENT);
7669 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7671 err = rdev_probe_client(rdev, dev, addr, &cookie);
7675 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7676 goto nla_put_failure;
7678 genlmsg_end(msg, hdr);
7680 return genlmsg_reply(msg, info);
7689 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
7691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7692 struct cfg80211_beacon_registration *reg, *nreg;
7695 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
7698 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
7702 /* First, check if already registered. */
7703 spin_lock_bh(&rdev->beacon_registrations_lock);
7704 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
7705 if (reg->nlportid == info->snd_portid) {
7710 /* Add it to the list */
7711 nreg->nlportid = info->snd_portid;
7712 list_add(&nreg->list, &rdev->beacon_registrations);
7714 spin_unlock_bh(&rdev->beacon_registrations_lock);
7718 spin_unlock_bh(&rdev->beacon_registrations_lock);
7723 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
7725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7726 struct wireless_dev *wdev = info->user_ptr[1];
7729 if (!rdev->ops->start_p2p_device)
7732 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7735 if (wdev->p2p_started)
7738 mutex_lock(&rdev->devlist_mtx);
7739 err = cfg80211_can_add_interface(rdev, wdev->iftype);
7740 mutex_unlock(&rdev->devlist_mtx);
7744 err = rdev_start_p2p_device(rdev, wdev);
7748 wdev->p2p_started = true;
7749 mutex_lock(&rdev->devlist_mtx);
7751 mutex_unlock(&rdev->devlist_mtx);
7756 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
7758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7759 struct wireless_dev *wdev = info->user_ptr[1];
7761 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7764 if (!rdev->ops->stop_p2p_device)
7767 if (!wdev->p2p_started)
7770 rdev_stop_p2p_device(rdev, wdev);
7771 wdev->p2p_started = false;
7773 mutex_lock(&rdev->devlist_mtx);
7775 mutex_unlock(&rdev->devlist_mtx);
7777 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
7778 rdev->scan_req->aborted = true;
7779 ___cfg80211_scan_done(rdev, true);
7785 #define NL80211_FLAG_NEED_WIPHY 0x01
7786 #define NL80211_FLAG_NEED_NETDEV 0x02
7787 #define NL80211_FLAG_NEED_RTNL 0x04
7788 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
7789 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
7790 NL80211_FLAG_CHECK_NETDEV_UP)
7791 #define NL80211_FLAG_NEED_WDEV 0x10
7792 /* If a netdev is associated, it must be UP, P2P must be started */
7793 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
7794 NL80211_FLAG_CHECK_NETDEV_UP)
7796 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
7797 struct genl_info *info)
7799 struct cfg80211_registered_device *rdev;
7800 struct wireless_dev *wdev;
7801 struct net_device *dev;
7802 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
7807 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
7808 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7812 return PTR_ERR(rdev);
7814 info->user_ptr[0] = rdev;
7815 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
7816 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7817 mutex_lock(&cfg80211_mutex);
7818 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
7821 mutex_unlock(&cfg80211_mutex);
7824 return PTR_ERR(wdev);
7828 rdev = wiphy_to_dev(wdev->wiphy);
7830 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
7832 mutex_unlock(&cfg80211_mutex);
7838 info->user_ptr[1] = dev;
7840 info->user_ptr[1] = wdev;
7844 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
7845 !netif_running(dev)) {
7846 mutex_unlock(&cfg80211_mutex);
7853 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
7854 if (!wdev->p2p_started) {
7855 mutex_unlock(&cfg80211_mutex);
7862 cfg80211_lock_rdev(rdev);
7864 mutex_unlock(&cfg80211_mutex);
7866 info->user_ptr[0] = rdev;
7872 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
7873 struct genl_info *info)
7875 if (info->user_ptr[0])
7876 cfg80211_unlock_rdev(info->user_ptr[0]);
7877 if (info->user_ptr[1]) {
7878 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7879 struct wireless_dev *wdev = info->user_ptr[1];
7882 dev_put(wdev->netdev);
7884 dev_put(info->user_ptr[1]);
7887 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7891 static struct genl_ops nl80211_ops[] = {
7893 .cmd = NL80211_CMD_GET_WIPHY,
7894 .doit = nl80211_get_wiphy,
7895 .dumpit = nl80211_dump_wiphy,
7896 .policy = nl80211_policy,
7897 /* can be retrieved by unprivileged users */
7898 .internal_flags = NL80211_FLAG_NEED_WIPHY,
7901 .cmd = NL80211_CMD_SET_WIPHY,
7902 .doit = nl80211_set_wiphy,
7903 .policy = nl80211_policy,
7904 .flags = GENL_ADMIN_PERM,
7905 .internal_flags = NL80211_FLAG_NEED_RTNL,
7908 .cmd = NL80211_CMD_GET_INTERFACE,
7909 .doit = nl80211_get_interface,
7910 .dumpit = nl80211_dump_interface,
7911 .policy = nl80211_policy,
7912 /* can be retrieved by unprivileged users */
7913 .internal_flags = NL80211_FLAG_NEED_WDEV,
7916 .cmd = NL80211_CMD_SET_INTERFACE,
7917 .doit = nl80211_set_interface,
7918 .policy = nl80211_policy,
7919 .flags = GENL_ADMIN_PERM,
7920 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7921 NL80211_FLAG_NEED_RTNL,
7924 .cmd = NL80211_CMD_NEW_INTERFACE,
7925 .doit = nl80211_new_interface,
7926 .policy = nl80211_policy,
7927 .flags = GENL_ADMIN_PERM,
7928 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7929 NL80211_FLAG_NEED_RTNL,
7932 .cmd = NL80211_CMD_DEL_INTERFACE,
7933 .doit = nl80211_del_interface,
7934 .policy = nl80211_policy,
7935 .flags = GENL_ADMIN_PERM,
7936 .internal_flags = NL80211_FLAG_NEED_WDEV |
7937 NL80211_FLAG_NEED_RTNL,
7940 .cmd = NL80211_CMD_GET_KEY,
7941 .doit = nl80211_get_key,
7942 .policy = nl80211_policy,
7943 .flags = GENL_ADMIN_PERM,
7944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7945 NL80211_FLAG_NEED_RTNL,
7948 .cmd = NL80211_CMD_SET_KEY,
7949 .doit = nl80211_set_key,
7950 .policy = nl80211_policy,
7951 .flags = GENL_ADMIN_PERM,
7952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7953 NL80211_FLAG_NEED_RTNL,
7956 .cmd = NL80211_CMD_NEW_KEY,
7957 .doit = nl80211_new_key,
7958 .policy = nl80211_policy,
7959 .flags = GENL_ADMIN_PERM,
7960 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7961 NL80211_FLAG_NEED_RTNL,
7964 .cmd = NL80211_CMD_DEL_KEY,
7965 .doit = nl80211_del_key,
7966 .policy = nl80211_policy,
7967 .flags = GENL_ADMIN_PERM,
7968 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7969 NL80211_FLAG_NEED_RTNL,
7972 .cmd = NL80211_CMD_SET_BEACON,
7973 .policy = nl80211_policy,
7974 .flags = GENL_ADMIN_PERM,
7975 .doit = nl80211_set_beacon,
7976 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7977 NL80211_FLAG_NEED_RTNL,
7980 .cmd = NL80211_CMD_START_AP,
7981 .policy = nl80211_policy,
7982 .flags = GENL_ADMIN_PERM,
7983 .doit = nl80211_start_ap,
7984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7985 NL80211_FLAG_NEED_RTNL,
7988 .cmd = NL80211_CMD_STOP_AP,
7989 .policy = nl80211_policy,
7990 .flags = GENL_ADMIN_PERM,
7991 .doit = nl80211_stop_ap,
7992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7993 NL80211_FLAG_NEED_RTNL,
7996 .cmd = NL80211_CMD_GET_STATION,
7997 .doit = nl80211_get_station,
7998 .dumpit = nl80211_dump_station,
7999 .policy = nl80211_policy,
8000 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8001 NL80211_FLAG_NEED_RTNL,
8004 .cmd = NL80211_CMD_SET_STATION,
8005 .doit = nl80211_set_station,
8006 .policy = nl80211_policy,
8007 .flags = GENL_ADMIN_PERM,
8008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8009 NL80211_FLAG_NEED_RTNL,
8012 .cmd = NL80211_CMD_NEW_STATION,
8013 .doit = nl80211_new_station,
8014 .policy = nl80211_policy,
8015 .flags = GENL_ADMIN_PERM,
8016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8017 NL80211_FLAG_NEED_RTNL,
8020 .cmd = NL80211_CMD_DEL_STATION,
8021 .doit = nl80211_del_station,
8022 .policy = nl80211_policy,
8023 .flags = GENL_ADMIN_PERM,
8024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8025 NL80211_FLAG_NEED_RTNL,
8028 .cmd = NL80211_CMD_GET_MPATH,
8029 .doit = nl80211_get_mpath,
8030 .dumpit = nl80211_dump_mpath,
8031 .policy = nl80211_policy,
8032 .flags = GENL_ADMIN_PERM,
8033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8034 NL80211_FLAG_NEED_RTNL,
8037 .cmd = NL80211_CMD_SET_MPATH,
8038 .doit = nl80211_set_mpath,
8039 .policy = nl80211_policy,
8040 .flags = GENL_ADMIN_PERM,
8041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8042 NL80211_FLAG_NEED_RTNL,
8045 .cmd = NL80211_CMD_NEW_MPATH,
8046 .doit = nl80211_new_mpath,
8047 .policy = nl80211_policy,
8048 .flags = GENL_ADMIN_PERM,
8049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8050 NL80211_FLAG_NEED_RTNL,
8053 .cmd = NL80211_CMD_DEL_MPATH,
8054 .doit = nl80211_del_mpath,
8055 .policy = nl80211_policy,
8056 .flags = GENL_ADMIN_PERM,
8057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8058 NL80211_FLAG_NEED_RTNL,
8061 .cmd = NL80211_CMD_SET_BSS,
8062 .doit = nl80211_set_bss,
8063 .policy = nl80211_policy,
8064 .flags = GENL_ADMIN_PERM,
8065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8066 NL80211_FLAG_NEED_RTNL,
8069 .cmd = NL80211_CMD_GET_REG,
8070 .doit = nl80211_get_reg,
8071 .policy = nl80211_policy,
8072 /* can be retrieved by unprivileged users */
8075 .cmd = NL80211_CMD_SET_REG,
8076 .doit = nl80211_set_reg,
8077 .policy = nl80211_policy,
8078 .flags = GENL_ADMIN_PERM,
8081 .cmd = NL80211_CMD_REQ_SET_REG,
8082 .doit = nl80211_req_set_reg,
8083 .policy = nl80211_policy,
8084 .flags = GENL_ADMIN_PERM,
8087 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8088 .doit = nl80211_get_mesh_config,
8089 .policy = nl80211_policy,
8090 /* can be retrieved by unprivileged users */
8091 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8092 NL80211_FLAG_NEED_RTNL,
8095 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8096 .doit = nl80211_update_mesh_config,
8097 .policy = nl80211_policy,
8098 .flags = GENL_ADMIN_PERM,
8099 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8100 NL80211_FLAG_NEED_RTNL,
8103 .cmd = NL80211_CMD_TRIGGER_SCAN,
8104 .doit = nl80211_trigger_scan,
8105 .policy = nl80211_policy,
8106 .flags = GENL_ADMIN_PERM,
8107 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8108 NL80211_FLAG_NEED_RTNL,
8111 .cmd = NL80211_CMD_GET_SCAN,
8112 .policy = nl80211_policy,
8113 .dumpit = nl80211_dump_scan,
8116 .cmd = NL80211_CMD_START_SCHED_SCAN,
8117 .doit = nl80211_start_sched_scan,
8118 .policy = nl80211_policy,
8119 .flags = GENL_ADMIN_PERM,
8120 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8121 NL80211_FLAG_NEED_RTNL,
8124 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8125 .doit = nl80211_stop_sched_scan,
8126 .policy = nl80211_policy,
8127 .flags = GENL_ADMIN_PERM,
8128 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8129 NL80211_FLAG_NEED_RTNL,
8132 .cmd = NL80211_CMD_AUTHENTICATE,
8133 .doit = nl80211_authenticate,
8134 .policy = nl80211_policy,
8135 .flags = GENL_ADMIN_PERM,
8136 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8137 NL80211_FLAG_NEED_RTNL,
8140 .cmd = NL80211_CMD_ASSOCIATE,
8141 .doit = nl80211_associate,
8142 .policy = nl80211_policy,
8143 .flags = GENL_ADMIN_PERM,
8144 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8145 NL80211_FLAG_NEED_RTNL,
8148 .cmd = NL80211_CMD_DEAUTHENTICATE,
8149 .doit = nl80211_deauthenticate,
8150 .policy = nl80211_policy,
8151 .flags = GENL_ADMIN_PERM,
8152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8153 NL80211_FLAG_NEED_RTNL,
8156 .cmd = NL80211_CMD_DISASSOCIATE,
8157 .doit = nl80211_disassociate,
8158 .policy = nl80211_policy,
8159 .flags = GENL_ADMIN_PERM,
8160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8161 NL80211_FLAG_NEED_RTNL,
8164 .cmd = NL80211_CMD_JOIN_IBSS,
8165 .doit = nl80211_join_ibss,
8166 .policy = nl80211_policy,
8167 .flags = GENL_ADMIN_PERM,
8168 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8169 NL80211_FLAG_NEED_RTNL,
8172 .cmd = NL80211_CMD_LEAVE_IBSS,
8173 .doit = nl80211_leave_ibss,
8174 .policy = nl80211_policy,
8175 .flags = GENL_ADMIN_PERM,
8176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8177 NL80211_FLAG_NEED_RTNL,
8179 #ifdef CONFIG_NL80211_TESTMODE
8181 .cmd = NL80211_CMD_TESTMODE,
8182 .doit = nl80211_testmode_do,
8183 .dumpit = nl80211_testmode_dump,
8184 .policy = nl80211_policy,
8185 .flags = GENL_ADMIN_PERM,
8186 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8187 NL80211_FLAG_NEED_RTNL,
8191 .cmd = NL80211_CMD_CONNECT,
8192 .doit = nl80211_connect,
8193 .policy = nl80211_policy,
8194 .flags = GENL_ADMIN_PERM,
8195 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8196 NL80211_FLAG_NEED_RTNL,
8199 .cmd = NL80211_CMD_DISCONNECT,
8200 .doit = nl80211_disconnect,
8201 .policy = nl80211_policy,
8202 .flags = GENL_ADMIN_PERM,
8203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8204 NL80211_FLAG_NEED_RTNL,
8207 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8208 .doit = nl80211_wiphy_netns,
8209 .policy = nl80211_policy,
8210 .flags = GENL_ADMIN_PERM,
8211 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8212 NL80211_FLAG_NEED_RTNL,
8215 .cmd = NL80211_CMD_GET_SURVEY,
8216 .policy = nl80211_policy,
8217 .dumpit = nl80211_dump_survey,
8220 .cmd = NL80211_CMD_SET_PMKSA,
8221 .doit = nl80211_setdel_pmksa,
8222 .policy = nl80211_policy,
8223 .flags = GENL_ADMIN_PERM,
8224 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8225 NL80211_FLAG_NEED_RTNL,
8228 .cmd = NL80211_CMD_DEL_PMKSA,
8229 .doit = nl80211_setdel_pmksa,
8230 .policy = nl80211_policy,
8231 .flags = GENL_ADMIN_PERM,
8232 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8233 NL80211_FLAG_NEED_RTNL,
8236 .cmd = NL80211_CMD_FLUSH_PMKSA,
8237 .doit = nl80211_flush_pmksa,
8238 .policy = nl80211_policy,
8239 .flags = GENL_ADMIN_PERM,
8240 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8241 NL80211_FLAG_NEED_RTNL,
8244 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8245 .doit = nl80211_remain_on_channel,
8246 .policy = nl80211_policy,
8247 .flags = GENL_ADMIN_PERM,
8248 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8249 NL80211_FLAG_NEED_RTNL,
8252 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8253 .doit = nl80211_cancel_remain_on_channel,
8254 .policy = nl80211_policy,
8255 .flags = GENL_ADMIN_PERM,
8256 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8257 NL80211_FLAG_NEED_RTNL,
8260 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8261 .doit = nl80211_set_tx_bitrate_mask,
8262 .policy = nl80211_policy,
8263 .flags = GENL_ADMIN_PERM,
8264 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8265 NL80211_FLAG_NEED_RTNL,
8268 .cmd = NL80211_CMD_REGISTER_FRAME,
8269 .doit = nl80211_register_mgmt,
8270 .policy = nl80211_policy,
8271 .flags = GENL_ADMIN_PERM,
8272 .internal_flags = NL80211_FLAG_NEED_WDEV |
8273 NL80211_FLAG_NEED_RTNL,
8276 .cmd = NL80211_CMD_FRAME,
8277 .doit = nl80211_tx_mgmt,
8278 .policy = nl80211_policy,
8279 .flags = GENL_ADMIN_PERM,
8280 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8281 NL80211_FLAG_NEED_RTNL,
8284 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8285 .doit = nl80211_tx_mgmt_cancel_wait,
8286 .policy = nl80211_policy,
8287 .flags = GENL_ADMIN_PERM,
8288 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8289 NL80211_FLAG_NEED_RTNL,
8292 .cmd = NL80211_CMD_SET_POWER_SAVE,
8293 .doit = nl80211_set_power_save,
8294 .policy = nl80211_policy,
8295 .flags = GENL_ADMIN_PERM,
8296 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8297 NL80211_FLAG_NEED_RTNL,
8300 .cmd = NL80211_CMD_GET_POWER_SAVE,
8301 .doit = nl80211_get_power_save,
8302 .policy = nl80211_policy,
8303 /* can be retrieved by unprivileged users */
8304 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8305 NL80211_FLAG_NEED_RTNL,
8308 .cmd = NL80211_CMD_SET_CQM,
8309 .doit = nl80211_set_cqm,
8310 .policy = nl80211_policy,
8311 .flags = GENL_ADMIN_PERM,
8312 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8313 NL80211_FLAG_NEED_RTNL,
8316 .cmd = NL80211_CMD_SET_CHANNEL,
8317 .doit = nl80211_set_channel,
8318 .policy = nl80211_policy,
8319 .flags = GENL_ADMIN_PERM,
8320 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8321 NL80211_FLAG_NEED_RTNL,
8324 .cmd = NL80211_CMD_SET_WDS_PEER,
8325 .doit = nl80211_set_wds_peer,
8326 .policy = nl80211_policy,
8327 .flags = GENL_ADMIN_PERM,
8328 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8329 NL80211_FLAG_NEED_RTNL,
8332 .cmd = NL80211_CMD_JOIN_MESH,
8333 .doit = nl80211_join_mesh,
8334 .policy = nl80211_policy,
8335 .flags = GENL_ADMIN_PERM,
8336 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8337 NL80211_FLAG_NEED_RTNL,
8340 .cmd = NL80211_CMD_LEAVE_MESH,
8341 .doit = nl80211_leave_mesh,
8342 .policy = nl80211_policy,
8343 .flags = GENL_ADMIN_PERM,
8344 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8345 NL80211_FLAG_NEED_RTNL,
8349 .cmd = NL80211_CMD_GET_WOWLAN,
8350 .doit = nl80211_get_wowlan,
8351 .policy = nl80211_policy,
8352 /* can be retrieved by unprivileged users */
8353 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8354 NL80211_FLAG_NEED_RTNL,
8357 .cmd = NL80211_CMD_SET_WOWLAN,
8358 .doit = nl80211_set_wowlan,
8359 .policy = nl80211_policy,
8360 .flags = GENL_ADMIN_PERM,
8361 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8362 NL80211_FLAG_NEED_RTNL,
8366 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8367 .doit = nl80211_set_rekey_data,
8368 .policy = nl80211_policy,
8369 .flags = GENL_ADMIN_PERM,
8370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8371 NL80211_FLAG_NEED_RTNL,
8374 .cmd = NL80211_CMD_TDLS_MGMT,
8375 .doit = nl80211_tdls_mgmt,
8376 .policy = nl80211_policy,
8377 .flags = GENL_ADMIN_PERM,
8378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8379 NL80211_FLAG_NEED_RTNL,
8382 .cmd = NL80211_CMD_TDLS_OPER,
8383 .doit = nl80211_tdls_oper,
8384 .policy = nl80211_policy,
8385 .flags = GENL_ADMIN_PERM,
8386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8387 NL80211_FLAG_NEED_RTNL,
8390 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8391 .doit = nl80211_register_unexpected_frame,
8392 .policy = nl80211_policy,
8393 .flags = GENL_ADMIN_PERM,
8394 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8395 NL80211_FLAG_NEED_RTNL,
8398 .cmd = NL80211_CMD_PROBE_CLIENT,
8399 .doit = nl80211_probe_client,
8400 .policy = nl80211_policy,
8401 .flags = GENL_ADMIN_PERM,
8402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8403 NL80211_FLAG_NEED_RTNL,
8406 .cmd = NL80211_CMD_REGISTER_BEACONS,
8407 .doit = nl80211_register_beacons,
8408 .policy = nl80211_policy,
8409 .flags = GENL_ADMIN_PERM,
8410 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8411 NL80211_FLAG_NEED_RTNL,
8414 .cmd = NL80211_CMD_SET_NOACK_MAP,
8415 .doit = nl80211_set_noack_map,
8416 .policy = nl80211_policy,
8417 .flags = GENL_ADMIN_PERM,
8418 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8419 NL80211_FLAG_NEED_RTNL,
8422 .cmd = NL80211_CMD_START_P2P_DEVICE,
8423 .doit = nl80211_start_p2p_device,
8424 .policy = nl80211_policy,
8425 .flags = GENL_ADMIN_PERM,
8426 .internal_flags = NL80211_FLAG_NEED_WDEV |
8427 NL80211_FLAG_NEED_RTNL,
8430 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8431 .doit = nl80211_stop_p2p_device,
8432 .policy = nl80211_policy,
8433 .flags = GENL_ADMIN_PERM,
8434 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8435 NL80211_FLAG_NEED_RTNL,
8438 .cmd = NL80211_CMD_SET_MCAST_RATE,
8439 .doit = nl80211_set_mcast_rate,
8440 .policy = nl80211_policy,
8441 .flags = GENL_ADMIN_PERM,
8442 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8443 NL80211_FLAG_NEED_RTNL,
8446 .cmd = NL80211_CMD_SET_MAC_ACL,
8447 .doit = nl80211_set_mac_acl,
8448 .policy = nl80211_policy,
8449 .flags = GENL_ADMIN_PERM,
8450 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8451 NL80211_FLAG_NEED_RTNL,
8454 .cmd = NL80211_CMD_RADAR_DETECT,
8455 .doit = nl80211_start_radar_detection,
8456 .policy = nl80211_policy,
8457 .flags = GENL_ADMIN_PERM,
8458 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8459 NL80211_FLAG_NEED_RTNL,
8463 static struct genl_multicast_group nl80211_mlme_mcgrp = {
8467 /* multicast groups */
8468 static struct genl_multicast_group nl80211_config_mcgrp = {
8471 static struct genl_multicast_group nl80211_scan_mcgrp = {
8474 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8475 .name = "regulatory",
8478 /* notification functions */
8480 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8482 struct sk_buff *msg;
8484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8488 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
8493 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8494 nl80211_config_mcgrp.id, GFP_KERNEL);
8497 static int nl80211_add_scan_req(struct sk_buff *msg,
8498 struct cfg80211_registered_device *rdev)
8500 struct cfg80211_scan_request *req = rdev->scan_req;
8501 struct nlattr *nest;
8504 ASSERT_RDEV_LOCK(rdev);
8509 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8511 goto nla_put_failure;
8512 for (i = 0; i < req->n_ssids; i++) {
8513 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8514 goto nla_put_failure;
8516 nla_nest_end(msg, nest);
8518 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8520 goto nla_put_failure;
8521 for (i = 0; i < req->n_channels; i++) {
8522 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8523 goto nla_put_failure;
8525 nla_nest_end(msg, nest);
8528 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8529 goto nla_put_failure;
8532 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8539 static int nl80211_send_scan_msg(struct sk_buff *msg,
8540 struct cfg80211_registered_device *rdev,
8541 struct wireless_dev *wdev,
8542 u32 portid, u32 seq, int flags,
8547 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8551 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8552 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8553 wdev->netdev->ifindex)) ||
8554 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
8555 goto nla_put_failure;
8557 /* ignore errors and send incomplete event anyway */
8558 nl80211_add_scan_req(msg, rdev);
8560 return genlmsg_end(msg, hdr);
8563 genlmsg_cancel(msg, hdr);
8568 nl80211_send_sched_scan_msg(struct sk_buff *msg,
8569 struct cfg80211_registered_device *rdev,
8570 struct net_device *netdev,
8571 u32 portid, u32 seq, int flags, u32 cmd)
8575 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8579 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8580 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8581 goto nla_put_failure;
8583 return genlmsg_end(msg, hdr);
8586 genlmsg_cancel(msg, hdr);
8590 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
8591 struct wireless_dev *wdev)
8593 struct sk_buff *msg;
8595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8599 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8600 NL80211_CMD_TRIGGER_SCAN) < 0) {
8605 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8606 nl80211_scan_mcgrp.id, GFP_KERNEL);
8609 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
8610 struct wireless_dev *wdev)
8612 struct sk_buff *msg;
8614 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8618 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8619 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
8624 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8625 nl80211_scan_mcgrp.id, GFP_KERNEL);
8628 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
8629 struct wireless_dev *wdev)
8631 struct sk_buff *msg;
8633 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8637 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8638 NL80211_CMD_SCAN_ABORTED) < 0) {
8643 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8644 nl80211_scan_mcgrp.id, GFP_KERNEL);
8647 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
8648 struct net_device *netdev)
8650 struct sk_buff *msg;
8652 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8656 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
8657 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
8662 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8663 nl80211_scan_mcgrp.id, GFP_KERNEL);
8666 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
8667 struct net_device *netdev, u32 cmd)
8669 struct sk_buff *msg;
8671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8675 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
8680 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8681 nl80211_scan_mcgrp.id, GFP_KERNEL);
8685 * This can happen on global regulatory changes or device specific settings
8686 * based on custom world regulatory domains.
8688 void nl80211_send_reg_change_event(struct regulatory_request *request)
8690 struct sk_buff *msg;
8693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8697 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
8703 /* Userspace can always count this one always being set */
8704 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
8705 goto nla_put_failure;
8707 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
8708 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8709 NL80211_REGDOM_TYPE_WORLD))
8710 goto nla_put_failure;
8711 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
8712 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8713 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
8714 goto nla_put_failure;
8715 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
8716 request->intersect) {
8717 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8718 NL80211_REGDOM_TYPE_INTERSECTION))
8719 goto nla_put_failure;
8721 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8722 NL80211_REGDOM_TYPE_COUNTRY) ||
8723 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
8725 goto nla_put_failure;
8728 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
8729 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
8730 goto nla_put_failure;
8732 genlmsg_end(msg, hdr);
8735 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8742 genlmsg_cancel(msg, hdr);
8746 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
8747 struct net_device *netdev,
8748 const u8 *buf, size_t len,
8749 enum nl80211_commands cmd, gfp_t gfp)
8751 struct sk_buff *msg;
8754 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8758 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8764 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8765 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8766 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8767 goto nla_put_failure;
8769 genlmsg_end(msg, hdr);
8771 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8772 nl80211_mlme_mcgrp.id, gfp);
8776 genlmsg_cancel(msg, hdr);
8780 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
8781 struct net_device *netdev, const u8 *buf,
8782 size_t len, gfp_t gfp)
8784 nl80211_send_mlme_event(rdev, netdev, buf, len,
8785 NL80211_CMD_AUTHENTICATE, gfp);
8788 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
8789 struct net_device *netdev, const u8 *buf,
8790 size_t len, gfp_t gfp)
8792 nl80211_send_mlme_event(rdev, netdev, buf, len,
8793 NL80211_CMD_ASSOCIATE, gfp);
8796 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
8797 struct net_device *netdev, const u8 *buf,
8798 size_t len, gfp_t gfp)
8800 nl80211_send_mlme_event(rdev, netdev, buf, len,
8801 NL80211_CMD_DEAUTHENTICATE, gfp);
8804 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
8805 struct net_device *netdev, const u8 *buf,
8806 size_t len, gfp_t gfp)
8808 nl80211_send_mlme_event(rdev, netdev, buf, len,
8809 NL80211_CMD_DISASSOCIATE, gfp);
8812 void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
8813 struct net_device *netdev, const u8 *buf,
8814 size_t len, gfp_t gfp)
8816 nl80211_send_mlme_event(rdev, netdev, buf, len,
8817 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
8820 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
8821 struct net_device *netdev, const u8 *buf,
8822 size_t len, gfp_t gfp)
8824 nl80211_send_mlme_event(rdev, netdev, buf, len,
8825 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
8828 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
8829 struct net_device *netdev, int cmd,
8830 const u8 *addr, gfp_t gfp)
8832 struct sk_buff *msg;
8835 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8839 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8845 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8846 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8847 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
8848 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8849 goto nla_put_failure;
8851 genlmsg_end(msg, hdr);
8853 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8854 nl80211_mlme_mcgrp.id, gfp);
8858 genlmsg_cancel(msg, hdr);
8862 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
8863 struct net_device *netdev, const u8 *addr,
8866 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
8870 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
8871 struct net_device *netdev, const u8 *addr,
8874 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
8878 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
8879 struct net_device *netdev, const u8 *bssid,
8880 const u8 *req_ie, size_t req_ie_len,
8881 const u8 *resp_ie, size_t resp_ie_len,
8882 u16 status, gfp_t gfp)
8884 struct sk_buff *msg;
8887 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8891 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
8897 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8898 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8899 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
8900 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
8902 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8904 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8905 goto nla_put_failure;
8907 genlmsg_end(msg, hdr);
8909 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8910 nl80211_mlme_mcgrp.id, gfp);
8914 genlmsg_cancel(msg, hdr);
8919 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8920 struct net_device *netdev, const u8 *bssid,
8921 const u8 *req_ie, size_t req_ie_len,
8922 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8924 struct sk_buff *msg;
8927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8931 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8937 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8938 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8939 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
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_disconnected(struct cfg80211_registered_device *rdev,
8959 struct net_device *netdev, u16 reason,
8960 const u8 *ie, size_t ie_len, bool from_ap)
8962 struct sk_buff *msg;
8965 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8969 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
8975 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8976 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8977 (from_ap && reason &&
8978 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
8980 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
8981 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8982 goto nla_put_failure;
8984 genlmsg_end(msg, hdr);
8986 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8987 nl80211_mlme_mcgrp.id, GFP_KERNEL);
8991 genlmsg_cancel(msg, hdr);
8996 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
8997 struct net_device *netdev, const u8 *bssid,
9000 struct sk_buff *msg;
9003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9007 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9013 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9014 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9015 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9016 goto nla_put_failure;
9018 genlmsg_end(msg, hdr);
9020 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9021 nl80211_mlme_mcgrp.id, gfp);
9025 genlmsg_cancel(msg, hdr);
9029 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
9030 struct net_device *netdev,
9031 const u8 *macaddr, const u8* ie, u8 ie_len,
9034 struct sk_buff *msg;
9037 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9041 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9047 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9048 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9049 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
9051 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9052 goto nla_put_failure;
9054 genlmsg_end(msg, hdr);
9056 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9057 nl80211_mlme_mcgrp.id, gfp);
9061 genlmsg_cancel(msg, hdr);
9065 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9066 struct net_device *netdev, const u8 *addr,
9067 enum nl80211_key_type key_type, int key_id,
9068 const u8 *tsc, gfp_t gfp)
9070 struct sk_buff *msg;
9073 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9077 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9083 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9084 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9085 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9086 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9088 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9089 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9090 goto nla_put_failure;
9092 genlmsg_end(msg, hdr);
9094 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9095 nl80211_mlme_mcgrp.id, gfp);
9099 genlmsg_cancel(msg, hdr);
9103 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9104 struct ieee80211_channel *channel_before,
9105 struct ieee80211_channel *channel_after)
9107 struct sk_buff *msg;
9109 struct nlattr *nl_freq;
9111 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
9115 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9122 * Since we are applying the beacon hint to a wiphy we know its
9123 * wiphy_idx is valid
9125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9126 goto nla_put_failure;
9129 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9131 goto nla_put_failure;
9132 if (nl80211_msg_put_channel(msg, channel_before))
9133 goto nla_put_failure;
9134 nla_nest_end(msg, nl_freq);
9137 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9139 goto nla_put_failure;
9140 if (nl80211_msg_put_channel(msg, channel_after))
9141 goto nla_put_failure;
9142 nla_nest_end(msg, nl_freq);
9144 genlmsg_end(msg, hdr);
9147 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9154 genlmsg_cancel(msg, hdr);
9158 static void nl80211_send_remain_on_chan_event(
9159 int cmd, struct cfg80211_registered_device *rdev,
9160 struct wireless_dev *wdev, u64 cookie,
9161 struct ieee80211_channel *chan,
9162 unsigned int duration, gfp_t gfp)
9164 struct sk_buff *msg;
9167 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9171 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9178 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9179 wdev->netdev->ifindex)) ||
9180 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
9181 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
9182 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9183 NL80211_CHAN_NO_HT) ||
9184 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9185 goto nla_put_failure;
9187 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9188 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9189 goto nla_put_failure;
9191 genlmsg_end(msg, hdr);
9193 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9194 nl80211_mlme_mcgrp.id, gfp);
9198 genlmsg_cancel(msg, hdr);
9202 void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
9203 struct wireless_dev *wdev, u64 cookie,
9204 struct ieee80211_channel *chan,
9205 unsigned int duration, gfp_t gfp)
9207 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
9208 rdev, wdev, cookie, chan,
9212 void nl80211_send_remain_on_channel_cancel(
9213 struct cfg80211_registered_device *rdev,
9214 struct wireless_dev *wdev,
9215 u64 cookie, struct ieee80211_channel *chan, gfp_t gfp)
9217 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9218 rdev, wdev, cookie, chan, 0, gfp);
9221 void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
9222 struct net_device *dev, const u8 *mac_addr,
9223 struct station_info *sinfo, gfp_t gfp)
9225 struct sk_buff *msg;
9227 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9231 if (nl80211_send_station(msg, 0, 0, 0,
9232 rdev, dev, mac_addr, sinfo) < 0) {
9237 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9238 nl80211_mlme_mcgrp.id, gfp);
9241 void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
9242 struct net_device *dev, const u8 *mac_addr,
9245 struct sk_buff *msg;
9248 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9252 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9258 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9259 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9260 goto nla_put_failure;
9262 genlmsg_end(msg, hdr);
9264 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9265 nl80211_mlme_mcgrp.id, gfp);
9269 genlmsg_cancel(msg, hdr);
9273 void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
9274 struct net_device *dev, const u8 *mac_addr,
9275 enum nl80211_connect_failed_reason reason,
9278 struct sk_buff *msg;
9281 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9285 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9291 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9292 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9293 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9294 goto nla_put_failure;
9296 genlmsg_end(msg, hdr);
9298 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9299 nl80211_mlme_mcgrp.id, gfp);
9303 genlmsg_cancel(msg, hdr);
9307 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9308 const u8 *addr, gfp_t gfp)
9310 struct wireless_dev *wdev = dev->ieee80211_ptr;
9311 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9312 struct sk_buff *msg;
9315 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
9320 msg = nlmsg_new(100, gfp);
9324 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9330 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9331 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9332 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9333 goto nla_put_failure;
9335 err = genlmsg_end(msg, hdr);
9341 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9345 genlmsg_cancel(msg, hdr);
9350 bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
9352 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9356 bool nl80211_unexpected_4addr_frame(struct net_device *dev,
9357 const u8 *addr, gfp_t gfp)
9359 return __nl80211_unexpected_frame(dev,
9360 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9364 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
9365 struct wireless_dev *wdev, u32 nlportid,
9366 int freq, int sig_dbm,
9367 const u8 *buf, size_t len, gfp_t gfp)
9369 struct net_device *netdev = wdev->netdev;
9370 struct sk_buff *msg;
9373 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9377 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9383 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9384 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9385 netdev->ifindex)) ||
9386 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9388 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9389 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9390 goto nla_put_failure;
9392 genlmsg_end(msg, hdr);
9394 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9397 genlmsg_cancel(msg, hdr);
9402 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
9403 struct wireless_dev *wdev, u64 cookie,
9404 const u8 *buf, size_t len, bool ack,
9407 struct net_device *netdev = wdev->netdev;
9408 struct sk_buff *msg;
9411 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9415 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
9421 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9422 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9423 netdev->ifindex)) ||
9424 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9425 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9426 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9427 goto nla_put_failure;
9429 genlmsg_end(msg, hdr);
9431 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9435 genlmsg_cancel(msg, hdr);
9440 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
9441 struct net_device *netdev,
9442 enum nl80211_cqm_rssi_threshold_event rssi_event,
9445 struct sk_buff *msg;
9446 struct nlattr *pinfoattr;
9449 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9453 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9459 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9460 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9461 goto nla_put_failure;
9463 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9465 goto nla_put_failure;
9467 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9469 goto nla_put_failure;
9471 nla_nest_end(msg, pinfoattr);
9473 genlmsg_end(msg, hdr);
9475 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9476 nl80211_mlme_mcgrp.id, gfp);
9480 genlmsg_cancel(msg, hdr);
9484 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9485 struct net_device *netdev, const u8 *bssid,
9486 const u8 *replay_ctr, gfp_t gfp)
9488 struct sk_buff *msg;
9489 struct nlattr *rekey_attr;
9492 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9496 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9502 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9503 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9504 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9505 goto nla_put_failure;
9507 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9509 goto nla_put_failure;
9511 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9512 NL80211_REPLAY_CTR_LEN, replay_ctr))
9513 goto nla_put_failure;
9515 nla_nest_end(msg, rekey_attr);
9517 genlmsg_end(msg, hdr);
9519 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9520 nl80211_mlme_mcgrp.id, gfp);
9524 genlmsg_cancel(msg, hdr);
9528 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9529 struct net_device *netdev, int index,
9530 const u8 *bssid, bool preauth, gfp_t gfp)
9532 struct sk_buff *msg;
9533 struct nlattr *attr;
9536 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9540 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
9546 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9547 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9548 goto nla_put_failure;
9550 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
9552 goto nla_put_failure;
9554 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
9555 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
9557 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
9558 goto nla_put_failure;
9560 nla_nest_end(msg, attr);
9562 genlmsg_end(msg, hdr);
9564 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9565 nl80211_mlme_mcgrp.id, gfp);
9569 genlmsg_cancel(msg, hdr);
9573 void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
9574 struct net_device *netdev,
9575 struct cfg80211_chan_def *chandef, gfp_t gfp)
9577 struct sk_buff *msg;
9580 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9584 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
9590 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9591 goto nla_put_failure;
9593 if (nl80211_send_chandef(msg, chandef))
9594 goto nla_put_failure;
9596 genlmsg_end(msg, hdr);
9598 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9599 nl80211_mlme_mcgrp.id, gfp);
9603 genlmsg_cancel(msg, hdr);
9608 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
9609 struct net_device *netdev, const u8 *peer,
9610 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
9612 struct sk_buff *msg;
9613 struct nlattr *pinfoattr;
9616 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9620 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9626 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9628 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9629 goto nla_put_failure;
9631 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9633 goto nla_put_failure;
9635 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
9636 goto nla_put_failure;
9638 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
9639 goto nla_put_failure;
9641 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
9642 goto nla_put_failure;
9644 nla_nest_end(msg, pinfoattr);
9646 genlmsg_end(msg, hdr);
9648 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9649 nl80211_mlme_mcgrp.id, gfp);
9653 genlmsg_cancel(msg, hdr);
9658 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
9659 struct cfg80211_chan_def *chandef,
9660 enum nl80211_radar_event event,
9661 struct net_device *netdev, gfp_t gfp)
9663 struct sk_buff *msg;
9666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9670 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
9676 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9677 goto nla_put_failure;
9679 /* NOP and radar events don't need a netdev parameter */
9681 struct wireless_dev *wdev = netdev->ieee80211_ptr;
9683 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9684 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9685 goto nla_put_failure;
9688 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
9689 goto nla_put_failure;
9691 if (nl80211_send_chandef(msg, chandef))
9692 goto nla_put_failure;
9694 if (genlmsg_end(msg, hdr) < 0) {
9699 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9700 nl80211_mlme_mcgrp.id, gfp);
9704 genlmsg_cancel(msg, hdr);
9709 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
9710 struct net_device *netdev, const u8 *peer,
9711 u32 num_packets, gfp_t gfp)
9713 struct sk_buff *msg;
9714 struct nlattr *pinfoattr;
9717 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9721 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9727 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9728 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9729 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9730 goto nla_put_failure;
9732 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9734 goto nla_put_failure;
9736 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
9737 goto nla_put_failure;
9739 nla_nest_end(msg, pinfoattr);
9741 genlmsg_end(msg, hdr);
9743 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9744 nl80211_mlme_mcgrp.id, gfp);
9748 genlmsg_cancel(msg, hdr);
9752 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
9753 u64 cookie, bool acked, gfp_t gfp)
9755 struct wireless_dev *wdev = dev->ieee80211_ptr;
9756 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9757 struct sk_buff *msg;
9761 trace_cfg80211_probe_status(dev, addr, cookie, acked);
9763 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9768 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
9774 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9775 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9776 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9777 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9778 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
9779 goto nla_put_failure;
9781 err = genlmsg_end(msg, hdr);
9787 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9788 nl80211_mlme_mcgrp.id, gfp);
9792 genlmsg_cancel(msg, hdr);
9795 EXPORT_SYMBOL(cfg80211_probe_status);
9797 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
9798 const u8 *frame, size_t len,
9799 int freq, int sig_dbm)
9801 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9802 struct sk_buff *msg;
9804 struct cfg80211_beacon_registration *reg;
9806 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
9808 spin_lock_bh(&rdev->beacon_registrations_lock);
9809 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9810 msg = nlmsg_new(len + 100, GFP_ATOMIC);
9812 spin_unlock_bh(&rdev->beacon_registrations_lock);
9816 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9818 goto nla_put_failure;
9820 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9822 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9824 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9825 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
9826 goto nla_put_failure;
9828 genlmsg_end(msg, hdr);
9830 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
9832 spin_unlock_bh(&rdev->beacon_registrations_lock);
9836 spin_unlock_bh(&rdev->beacon_registrations_lock);
9838 genlmsg_cancel(msg, hdr);
9841 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
9844 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
9845 struct cfg80211_wowlan_wakeup *wakeup,
9848 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9849 struct sk_buff *msg;
9851 int err, size = 200;
9853 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
9856 size += wakeup->packet_present_len;
9858 msg = nlmsg_new(size, gfp);
9862 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
9866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9867 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9870 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9871 wdev->netdev->ifindex))
9875 struct nlattr *reasons;
9877 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9879 if (wakeup->disconnect &&
9880 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
9882 if (wakeup->magic_pkt &&
9883 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
9885 if (wakeup->gtk_rekey_failure &&
9886 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
9888 if (wakeup->eap_identity_req &&
9889 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
9891 if (wakeup->four_way_handshake &&
9892 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
9894 if (wakeup->rfkill_release &&
9895 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
9898 if (wakeup->pattern_idx >= 0 &&
9899 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
9900 wakeup->pattern_idx))
9903 if (wakeup->tcp_match)
9904 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
9906 if (wakeup->tcp_connlost)
9908 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
9910 if (wakeup->tcp_nomoretokens)
9912 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
9914 if (wakeup->packet) {
9915 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
9916 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
9918 if (!wakeup->packet_80211) {
9920 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
9922 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
9925 if (wakeup->packet_len &&
9926 nla_put_u32(msg, len_attr, wakeup->packet_len))
9929 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
9934 nla_nest_end(msg, reasons);
9937 err = genlmsg_end(msg, hdr);
9941 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9942 nl80211_mlme_mcgrp.id, gfp);
9948 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
9951 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
9952 enum nl80211_tdls_operation oper,
9953 u16 reason_code, gfp_t gfp)
9955 struct wireless_dev *wdev = dev->ieee80211_ptr;
9956 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9957 struct sk_buff *msg;
9961 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
9964 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9968 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
9974 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9975 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9976 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
9977 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
9979 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
9980 goto nla_put_failure;
9982 err = genlmsg_end(msg, hdr);
9988 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9989 nl80211_mlme_mcgrp.id, gfp);
9993 genlmsg_cancel(msg, hdr);
9996 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
9998 static int nl80211_netlink_notify(struct notifier_block * nb,
9999 unsigned long state,
10002 struct netlink_notify *notify = _notify;
10003 struct cfg80211_registered_device *rdev;
10004 struct wireless_dev *wdev;
10005 struct cfg80211_beacon_registration *reg, *tmp;
10007 if (state != NETLINK_URELEASE)
10008 return NOTIFY_DONE;
10012 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
10013 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
10014 cfg80211_mlme_unregister_socket(wdev, notify->portid);
10016 spin_lock_bh(&rdev->beacon_registrations_lock);
10017 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10019 if (reg->nlportid == notify->portid) {
10020 list_del(®->list);
10025 spin_unlock_bh(&rdev->beacon_registrations_lock);
10030 return NOTIFY_DONE;
10033 static struct notifier_block nl80211_netlink_notifier = {
10034 .notifier_call = nl80211_netlink_notify,
10037 /* initialisation/exit functions */
10039 int nl80211_init(void)
10043 err = genl_register_family_with_ops(&nl80211_fam,
10044 nl80211_ops, ARRAY_SIZE(nl80211_ops));
10048 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10052 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10056 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10060 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10064 #ifdef CONFIG_NL80211_TESTMODE
10065 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10070 err = netlink_register_notifier(&nl80211_netlink_notifier);
10076 genl_unregister_family(&nl80211_fam);
10080 void nl80211_exit(void)
10082 netlink_unregister_notifier(&nl80211_netlink_notifier);
10083 genl_unregister_family(&nl80211_fam);