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_parse_sta_wme(struct genl_info *info,
3363 struct station_parameters *params)
3365 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3369 /* parse WME attributes if present */
3370 if (!info->attrs[NL80211_ATTR_STA_WME])
3373 nla = info->attrs[NL80211_ATTR_STA_WME];
3374 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3375 nl80211_sta_wme_policy);
3379 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3380 params->uapsd_queues = nla_get_u8(
3381 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3382 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3385 if (tb[NL80211_STA_WME_MAX_SP])
3386 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3388 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3391 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3396 static int nl80211_set_station_tdls(struct genl_info *info,
3397 struct station_parameters *params)
3399 /* Dummy STA entry gets updated once the peer capabilities are known */
3400 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3402 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3403 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3405 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3407 return nl80211_parse_sta_wme(info, params);
3410 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3414 struct net_device *dev = info->user_ptr[1];
3415 struct station_parameters params;
3416 u8 *mac_addr = NULL;
3418 memset(¶ms, 0, sizeof(params));
3420 params.listen_interval = -1;
3422 if (info->attrs[NL80211_ATTR_STA_AID])
3425 if (!info->attrs[NL80211_ATTR_MAC])
3428 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3430 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3431 params.supported_rates =
3432 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3433 params.supported_rates_len =
3434 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3437 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3439 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3440 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3443 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3445 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3446 params.ext_capab_len =
3447 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3450 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3453 if (!rdev->ops->change_station)
3456 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3459 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3460 params.plink_action =
3461 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3462 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3466 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
3467 params.plink_state =
3468 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3469 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3471 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3474 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3475 enum nl80211_mesh_power_mode pm = nla_get_u32(
3476 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3478 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3479 pm > NL80211_MESH_POWER_MAX)
3482 params.local_pm = pm;
3485 switch (dev->ieee80211_ptr->iftype) {
3486 case NL80211_IFTYPE_AP:
3487 case NL80211_IFTYPE_AP_VLAN:
3488 case NL80211_IFTYPE_P2P_GO:
3489 /* disallow mesh-specific things */
3490 if (params.plink_action)
3492 if (params.local_pm)
3494 if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3497 /* TDLS can't be set, ... */
3498 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3501 * ... but don't bother the driver with it. This works around
3502 * a hostapd/wpa_supplicant issue -- it always includes the
3503 * TLDS_PEER flag in the mask even for AP mode.
3505 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3507 /* accept only the listed bits */
3508 if (params.sta_flags_mask &
3509 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3510 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3511 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3512 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3513 BIT(NL80211_STA_FLAG_WME) |
3514 BIT(NL80211_STA_FLAG_MFP)))
3517 /* but authenticated/associated only if driver handles it */
3518 if (!(rdev->wiphy.features &
3519 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3520 params.sta_flags_mask &
3521 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3522 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3525 /* reject other things that can't change */
3526 if (params.supported_rates)
3528 if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
3530 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
3532 if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
3533 info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3536 /* must be last in here for error handling */
3537 params.vlan = get_vlan(info, rdev);
3538 if (IS_ERR(params.vlan))
3539 return PTR_ERR(params.vlan);
3541 case NL80211_IFTYPE_P2P_CLIENT:
3542 case NL80211_IFTYPE_STATION:
3544 * Don't allow userspace to change the TDLS_PEER flag,
3545 * but silently ignore attempts to change it since we
3546 * don't have state here to verify that it doesn't try
3547 * to change the flag.
3549 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3550 /* Include parameters for TDLS peer (driver will check) */
3551 err = nl80211_set_station_tdls(info, ¶ms);
3554 /* disallow things sta doesn't support */
3555 if (params.plink_action)
3557 if (params.local_pm)
3559 if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3561 /* reject any changes other than AUTHORIZED or WME (for TDLS) */
3562 if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3563 BIT(NL80211_STA_FLAG_WME)))
3566 case NL80211_IFTYPE_ADHOC:
3567 /* disallow things sta doesn't support */
3568 if (params.plink_action)
3570 if (params.local_pm)
3572 if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3574 if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
3575 info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3577 /* reject any changes other than AUTHORIZED */
3578 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3581 case NL80211_IFTYPE_MESH_POINT:
3582 /* disallow things mesh doesn't support */
3585 if (params.supported_rates)
3587 if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
3589 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
3591 if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
3592 info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3595 * No special handling for TDLS here -- the userspace
3596 * mesh code doesn't have this bug.
3598 if (params.sta_flags_mask &
3599 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3600 BIT(NL80211_STA_FLAG_MFP) |
3601 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3608 /* be aware of params.vlan when changing code here */
3610 err = rdev_change_station(rdev, dev, mac_addr, ¶ms);
3613 dev_put(params.vlan);
3618 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3622 struct net_device *dev = info->user_ptr[1];
3623 struct station_parameters params;
3624 u8 *mac_addr = NULL;
3626 memset(¶ms, 0, sizeof(params));
3628 if (!rdev->ops->add_station)
3631 if (!info->attrs[NL80211_ATTR_MAC])
3634 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3637 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3640 if (!info->attrs[NL80211_ATTR_STA_AID])
3643 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3644 params.supported_rates =
3645 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3646 params.supported_rates_len =
3647 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3648 params.listen_interval =
3649 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3651 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3652 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3655 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3657 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3658 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3661 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3663 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3664 params.ext_capab_len =
3665 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3668 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3670 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3672 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3674 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3676 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
3677 params.plink_action =
3678 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3679 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3683 err = nl80211_parse_sta_wme(info, ¶ms);
3687 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
3690 switch (dev->ieee80211_ptr->iftype) {
3691 case NL80211_IFTYPE_AP:
3692 case NL80211_IFTYPE_AP_VLAN:
3693 case NL80211_IFTYPE_P2P_GO:
3694 /* ignore WME attributes if iface/sta is not capable */
3695 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
3696 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
3697 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
3699 /* TDLS peers cannot be added */
3700 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3702 /* but don't bother the driver with it */
3703 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3705 /* allow authenticated/associated only if driver handles it */
3706 if (!(rdev->wiphy.features &
3707 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3708 params.sta_flags_mask &
3709 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3710 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3713 /* must be last in here for error handling */
3714 params.vlan = get_vlan(info, rdev);
3715 if (IS_ERR(params.vlan))
3716 return PTR_ERR(params.vlan);
3718 case NL80211_IFTYPE_MESH_POINT:
3719 /* ignore uAPSD data */
3720 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
3722 /* associated is disallowed */
3723 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3725 /* TDLS peers cannot be added */
3726 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3729 case NL80211_IFTYPE_STATION:
3730 /* ignore uAPSD data */
3731 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
3733 /* associated is disallowed */
3734 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3736 /* Only TDLS peers can be added */
3737 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3739 /* Can only add if TDLS ... */
3740 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3742 /* ... with external setup is supported */
3743 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3750 /* be aware of params.vlan when changing code here */
3752 err = rdev_add_station(rdev, dev, mac_addr, ¶ms);
3755 dev_put(params.vlan);
3759 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3761 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3762 struct net_device *dev = info->user_ptr[1];
3763 u8 *mac_addr = NULL;
3765 if (info->attrs[NL80211_ATTR_MAC])
3766 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3768 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3769 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3770 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
3771 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3774 if (!rdev->ops->del_station)
3777 return rdev_del_station(rdev, dev, mac_addr);
3780 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
3781 int flags, struct net_device *dev,
3782 u8 *dst, u8 *next_hop,
3783 struct mpath_info *pinfo)
3786 struct nlattr *pinfoattr;
3788 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
3792 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3793 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3794 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3795 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3796 goto nla_put_failure;
3798 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3800 goto nla_put_failure;
3801 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3802 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3804 goto nla_put_failure;
3805 if (((pinfo->filled & MPATH_INFO_SN) &&
3806 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3807 ((pinfo->filled & MPATH_INFO_METRIC) &&
3808 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3810 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3811 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3813 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3814 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3816 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3817 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3818 pinfo->discovery_timeout)) ||
3819 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3820 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3821 pinfo->discovery_retries)))
3822 goto nla_put_failure;
3824 nla_nest_end(msg, pinfoattr);
3826 return genlmsg_end(msg, hdr);
3829 genlmsg_cancel(msg, hdr);
3833 static int nl80211_dump_mpath(struct sk_buff *skb,
3834 struct netlink_callback *cb)
3836 struct mpath_info pinfo;
3837 struct cfg80211_registered_device *dev;
3838 struct net_device *netdev;
3840 u8 next_hop[ETH_ALEN];
3841 int path_idx = cb->args[1];
3844 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3848 if (!dev->ops->dump_mpath) {
3853 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3859 err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
3866 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
3867 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3868 netdev, dst, next_hop,
3877 cb->args[1] = path_idx;
3880 nl80211_finish_netdev_dump(dev);
3884 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3888 struct net_device *dev = info->user_ptr[1];
3889 struct mpath_info pinfo;
3890 struct sk_buff *msg;
3892 u8 next_hop[ETH_ALEN];
3894 memset(&pinfo, 0, sizeof(pinfo));
3896 if (!info->attrs[NL80211_ATTR_MAC])
3899 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3901 if (!rdev->ops->get_mpath)
3904 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3907 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
3911 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3915 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
3916 dev, dst, next_hop, &pinfo) < 0) {
3921 return genlmsg_reply(msg, info);
3924 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3927 struct net_device *dev = info->user_ptr[1];
3929 u8 *next_hop = NULL;
3931 if (!info->attrs[NL80211_ATTR_MAC])
3934 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3937 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3938 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3940 if (!rdev->ops->change_mpath)
3943 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3946 return rdev_change_mpath(rdev, dev, dst, next_hop);
3949 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3952 struct net_device *dev = info->user_ptr[1];
3954 u8 *next_hop = NULL;
3956 if (!info->attrs[NL80211_ATTR_MAC])
3959 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3962 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3963 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3965 if (!rdev->ops->add_mpath)
3968 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3971 return rdev_add_mpath(rdev, dev, dst, next_hop);
3974 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3977 struct net_device *dev = info->user_ptr[1];
3980 if (info->attrs[NL80211_ATTR_MAC])
3981 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3983 if (!rdev->ops->del_mpath)
3986 return rdev_del_mpath(rdev, dev, dst);
3989 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3991 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3992 struct net_device *dev = info->user_ptr[1];
3993 struct bss_parameters params;
3995 memset(¶ms, 0, sizeof(params));
3996 /* default to not changing parameters */
3997 params.use_cts_prot = -1;
3998 params.use_short_preamble = -1;
3999 params.use_short_slot_time = -1;
4000 params.ap_isolate = -1;
4001 params.ht_opmode = -1;
4002 params.p2p_ctwindow = -1;
4003 params.p2p_opp_ps = -1;
4005 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4006 params.use_cts_prot =
4007 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4008 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4009 params.use_short_preamble =
4010 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4011 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4012 params.use_short_slot_time =
4013 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
4014 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4015 params.basic_rates =
4016 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4017 params.basic_rates_len =
4018 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4020 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4021 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
4022 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4024 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
4026 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4027 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4029 params.p2p_ctwindow =
4030 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4031 if (params.p2p_ctwindow < 0)
4033 if (params.p2p_ctwindow != 0 &&
4034 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4038 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4041 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4043 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4046 params.p2p_opp_ps = tmp;
4047 if (params.p2p_opp_ps &&
4048 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4052 if (!rdev->ops->change_bss)
4055 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4056 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4059 return rdev_change_bss(rdev, dev, ¶ms);
4062 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
4063 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4064 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4065 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4066 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4067 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4068 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4071 static int parse_reg_rule(struct nlattr *tb[],
4072 struct ieee80211_reg_rule *reg_rule)
4074 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
4075 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
4077 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4079 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4081 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4083 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4085 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4088 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4090 freq_range->start_freq_khz =
4091 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4092 freq_range->end_freq_khz =
4093 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4094 freq_range->max_bandwidth_khz =
4095 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4097 power_rule->max_eirp =
4098 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4100 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4101 power_rule->max_antenna_gain =
4102 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4107 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4111 enum nl80211_user_reg_hint_type user_reg_hint_type;
4114 * You should only get this when cfg80211 hasn't yet initialized
4115 * completely when built-in to the kernel right between the time
4116 * window between nl80211_init() and regulatory_init(), if that is
4119 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
4120 return -EINPROGRESS;
4122 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4125 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4127 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4128 user_reg_hint_type =
4129 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4131 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4133 switch (user_reg_hint_type) {
4134 case NL80211_USER_REG_HINT_USER:
4135 case NL80211_USER_REG_HINT_CELL_BASE:
4141 r = regulatory_hint_user(data, user_reg_hint_type);
4146 static int nl80211_get_mesh_config(struct sk_buff *skb,
4147 struct genl_info *info)
4149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4150 struct net_device *dev = info->user_ptr[1];
4151 struct wireless_dev *wdev = dev->ieee80211_ptr;
4152 struct mesh_config cur_params;
4155 struct nlattr *pinfoattr;
4156 struct sk_buff *msg;
4158 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4161 if (!rdev->ops->get_mesh_config)
4165 /* If not connected, get default parameters */
4166 if (!wdev->mesh_id_len)
4167 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4169 err = rdev_get_mesh_config(rdev, dev, &cur_params);
4175 /* Draw up a netlink message to send back */
4176 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4179 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4180 NL80211_CMD_GET_MESH_CONFIG);
4183 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
4185 goto nla_put_failure;
4186 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4187 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4188 cur_params.dot11MeshRetryTimeout) ||
4189 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4190 cur_params.dot11MeshConfirmTimeout) ||
4191 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4192 cur_params.dot11MeshHoldingTimeout) ||
4193 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4194 cur_params.dot11MeshMaxPeerLinks) ||
4195 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4196 cur_params.dot11MeshMaxRetries) ||
4197 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4198 cur_params.dot11MeshTTL) ||
4199 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4200 cur_params.element_ttl) ||
4201 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4202 cur_params.auto_open_plinks) ||
4203 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4204 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
4205 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4206 cur_params.dot11MeshHWMPmaxPREQretries) ||
4207 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4208 cur_params.path_refresh_time) ||
4209 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4210 cur_params.min_discovery_timeout) ||
4211 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4212 cur_params.dot11MeshHWMPactivePathTimeout) ||
4213 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4214 cur_params.dot11MeshHWMPpreqMinInterval) ||
4215 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4216 cur_params.dot11MeshHWMPperrMinInterval) ||
4217 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4218 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4219 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4220 cur_params.dot11MeshHWMPRootMode) ||
4221 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4222 cur_params.dot11MeshHWMPRannInterval) ||
4223 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4224 cur_params.dot11MeshGateAnnouncementProtocol) ||
4225 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4226 cur_params.dot11MeshForwarding) ||
4227 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
4228 cur_params.rssi_threshold) ||
4229 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
4230 cur_params.ht_opmode) ||
4231 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4232 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4233 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4234 cur_params.dot11MeshHWMProotInterval) ||
4235 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4236 cur_params.dot11MeshHWMPconfirmationInterval) ||
4237 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4238 cur_params.power_mode) ||
4239 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4240 cur_params.dot11MeshAwakeWindowDuration))
4241 goto nla_put_failure;
4242 nla_nest_end(msg, pinfoattr);
4243 genlmsg_end(msg, hdr);
4244 return genlmsg_reply(msg, info);
4247 genlmsg_cancel(msg, hdr);
4253 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
4254 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4255 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4256 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4257 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4258 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4259 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
4260 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
4261 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
4262 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
4263 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4264 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4265 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4266 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4267 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
4268 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
4269 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
4270 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
4271 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
4272 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
4273 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
4274 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4275 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
4276 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4277 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
4278 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
4279 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4280 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
4283 static const struct nla_policy
4284 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
4285 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
4286 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4287 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
4288 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
4289 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
4290 .len = IEEE80211_MAX_DATA_LEN },
4291 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
4294 static int nl80211_parse_mesh_config(struct genl_info *info,
4295 struct mesh_config *cfg,
4298 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
4301 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4304 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4306 cfg->param = fn(tb[attr]); \
4307 mask |= (1 << (attr - 1)); \
4312 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
4314 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
4315 info->attrs[NL80211_ATTR_MESH_CONFIG],
4316 nl80211_meshconf_params_policy))
4319 /* This makes sure that there aren't more than 32 mesh config
4320 * parameters (otherwise our bitfield scheme would not work.) */
4321 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4323 /* Fill in the params struct */
4324 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
4325 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4327 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
4328 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4330 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
4331 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4333 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
4334 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4336 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
4337 mask, NL80211_MESHCONF_MAX_RETRIES,
4339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
4340 mask, NL80211_MESHCONF_TTL, nla_get_u8);
4341 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
4342 mask, NL80211_MESHCONF_ELEMENT_TTL,
4344 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
4345 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4347 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4349 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4351 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
4352 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4354 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
4355 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4357 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
4358 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4360 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4362 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4364 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
4366 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4368 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
4370 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4372 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4373 dot11MeshHWMPnetDiameterTraversalTime,
4375 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4377 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4378 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4380 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4381 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4383 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4384 dot11MeshGateAnnouncementProtocol, 0, 1,
4385 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4387 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
4388 mask, NL80211_MESHCONF_FORWARDING,
4390 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
4391 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4393 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
4394 mask, NL80211_MESHCONF_HT_OPMODE,
4396 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
4398 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4400 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
4401 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4403 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4404 dot11MeshHWMPconfirmationInterval,
4406 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4408 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4409 NL80211_MESH_POWER_ACTIVE,
4410 NL80211_MESH_POWER_MAX,
4411 mask, NL80211_MESHCONF_POWER_MODE,
4413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4415 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
4421 #undef FILL_IN_MESH_PARAM_IF_SET
4424 static int nl80211_parse_mesh_setup(struct genl_info *info,
4425 struct mesh_setup *setup)
4427 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4429 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4431 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4432 info->attrs[NL80211_ATTR_MESH_SETUP],
4433 nl80211_mesh_setup_params_policy))
4436 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4437 setup->sync_method =
4438 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4439 IEEE80211_SYNC_METHOD_VENDOR :
4440 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4442 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4443 setup->path_sel_proto =
4444 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4445 IEEE80211_PATH_PROTOCOL_VENDOR :
4446 IEEE80211_PATH_PROTOCOL_HWMP;
4448 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4449 setup->path_metric =
4450 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4451 IEEE80211_PATH_METRIC_VENDOR :
4452 IEEE80211_PATH_METRIC_AIRTIME;
4455 if (tb[NL80211_MESH_SETUP_IE]) {
4456 struct nlattr *ieattr =
4457 tb[NL80211_MESH_SETUP_IE];
4458 if (!is_valid_ie_attr(ieattr))
4460 setup->ie = nla_data(ieattr);
4461 setup->ie_len = nla_len(ieattr);
4463 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4464 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
4469 static int nl80211_update_mesh_config(struct sk_buff *skb,
4470 struct genl_info *info)
4472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4473 struct net_device *dev = info->user_ptr[1];
4474 struct wireless_dev *wdev = dev->ieee80211_ptr;
4475 struct mesh_config cfg;
4479 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4482 if (!rdev->ops->update_mesh_config)
4485 err = nl80211_parse_mesh_config(info, &cfg, &mask);
4490 if (!wdev->mesh_id_len)
4494 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
4501 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4503 const struct ieee80211_regdomain *regdom;
4504 struct sk_buff *msg;
4506 struct nlattr *nl_reg_rules;
4510 mutex_lock(&cfg80211_mutex);
4512 if (!cfg80211_regdomain)
4515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4521 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
4522 NL80211_CMD_GET_REG);
4526 if (reg_last_request_cell_base() &&
4527 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4528 NL80211_USER_REG_HINT_CELL_BASE))
4529 goto nla_put_failure;
4532 regdom = rcu_dereference(cfg80211_regdomain);
4534 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4535 (regdom->dfs_region &&
4536 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4537 goto nla_put_failure_rcu;
4539 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4541 goto nla_put_failure_rcu;
4543 for (i = 0; i < regdom->n_reg_rules; i++) {
4544 struct nlattr *nl_reg_rule;
4545 const struct ieee80211_reg_rule *reg_rule;
4546 const struct ieee80211_freq_range *freq_range;
4547 const struct ieee80211_power_rule *power_rule;
4549 reg_rule = ®dom->reg_rules[i];
4550 freq_range = ®_rule->freq_range;
4551 power_rule = ®_rule->power_rule;
4553 nl_reg_rule = nla_nest_start(msg, i);
4555 goto nla_put_failure_rcu;
4557 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4559 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4560 freq_range->start_freq_khz) ||
4561 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4562 freq_range->end_freq_khz) ||
4563 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4564 freq_range->max_bandwidth_khz) ||
4565 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4566 power_rule->max_antenna_gain) ||
4567 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4568 power_rule->max_eirp))
4569 goto nla_put_failure_rcu;
4571 nla_nest_end(msg, nl_reg_rule);
4575 nla_nest_end(msg, nl_reg_rules);
4577 genlmsg_end(msg, hdr);
4578 err = genlmsg_reply(msg, info);
4581 nla_put_failure_rcu:
4584 genlmsg_cancel(msg, hdr);
4589 mutex_unlock(&cfg80211_mutex);
4593 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4595 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4596 struct nlattr *nl_reg_rule;
4597 char *alpha2 = NULL;
4598 int rem_reg_rules = 0, r = 0;
4599 u32 num_rules = 0, rule_idx = 0, size_of_regd;
4601 struct ieee80211_regdomain *rd = NULL;
4603 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4606 if (!info->attrs[NL80211_ATTR_REG_RULES])
4609 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4611 if (info->attrs[NL80211_ATTR_DFS_REGION])
4612 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4614 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4617 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
4621 size_of_regd = sizeof(struct ieee80211_regdomain) +
4622 num_rules * sizeof(struct ieee80211_reg_rule);
4624 rd = kzalloc(size_of_regd, GFP_KERNEL);
4628 rd->n_reg_rules = num_rules;
4629 rd->alpha2[0] = alpha2[0];
4630 rd->alpha2[1] = alpha2[1];
4633 * Disable DFS master mode if the DFS region was
4634 * not supported or known on this kernel.
4636 if (reg_supported_dfs_region(dfs_region))
4637 rd->dfs_region = dfs_region;
4639 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4641 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4642 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4644 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4650 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4656 mutex_lock(&cfg80211_mutex);
4659 /* set_regdom took ownership */
4661 mutex_unlock(&cfg80211_mutex);
4668 static int validate_scan_freqs(struct nlattr *freqs)
4670 struct nlattr *attr1, *attr2;
4671 int n_channels = 0, tmp1, tmp2;
4673 nla_for_each_nested(attr1, freqs, tmp1) {
4676 * Some hardware has a limited channel list for
4677 * scanning, and it is pretty much nonsensical
4678 * to scan for a channel twice, so disallow that
4679 * and don't require drivers to check that the
4680 * channel list they get isn't longer than what
4681 * they can scan, as long as they can scan all
4682 * the channels they registered at once.
4684 nla_for_each_nested(attr2, freqs, tmp2)
4685 if (attr1 != attr2 &&
4686 nla_get_u32(attr1) == nla_get_u32(attr2))
4693 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4696 struct wireless_dev *wdev = info->user_ptr[1];
4697 struct cfg80211_scan_request *request;
4698 struct nlattr *attr;
4699 struct wiphy *wiphy;
4700 int err, tmp, n_ssids = 0, n_channels, i;
4703 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4706 wiphy = &rdev->wiphy;
4708 if (!rdev->ops->scan)
4714 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4715 n_channels = validate_scan_freqs(
4716 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4720 enum ieee80211_band band;
4723 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4724 if (wiphy->bands[band])
4725 n_channels += wiphy->bands[band]->n_channels;
4728 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4729 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4732 if (n_ssids > wiphy->max_scan_ssids)
4735 if (info->attrs[NL80211_ATTR_IE])
4736 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4740 if (ie_len > wiphy->max_scan_ie_len)
4743 request = kzalloc(sizeof(*request)
4744 + sizeof(*request->ssids) * n_ssids
4745 + sizeof(*request->channels) * n_channels
4746 + ie_len, GFP_KERNEL);
4751 request->ssids = (void *)&request->channels[n_channels];
4752 request->n_ssids = n_ssids;
4755 request->ie = (void *)(request->ssids + n_ssids);
4757 request->ie = (void *)(request->channels + n_channels);
4761 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4762 /* user specified, bail out if channel not found */
4763 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
4764 struct ieee80211_channel *chan;
4766 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4773 /* ignore disabled channels */
4774 if (chan->flags & IEEE80211_CHAN_DISABLED)
4777 request->channels[i] = chan;
4781 enum ieee80211_band band;
4784 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4786 if (!wiphy->bands[band])
4788 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4789 struct ieee80211_channel *chan;
4791 chan = &wiphy->bands[band]->channels[j];
4793 if (chan->flags & IEEE80211_CHAN_DISABLED)
4796 request->channels[i] = chan;
4807 request->n_channels = i;
4810 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4811 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
4812 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
4816 request->ssids[i].ssid_len = nla_len(attr);
4817 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
4822 if (info->attrs[NL80211_ATTR_IE]) {
4823 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4824 memcpy((void *)request->ie,
4825 nla_data(info->attrs[NL80211_ATTR_IE]),
4829 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4830 if (wiphy->bands[i])
4832 (1 << wiphy->bands[i]->n_bitrates) - 1;
4834 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4835 nla_for_each_nested(attr,
4836 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4838 enum ieee80211_band band = nla_type(attr);
4840 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
4844 err = ieee80211_get_ratemask(wiphy->bands[band],
4847 &request->rates[band]);
4853 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
4854 request->flags = nla_get_u32(
4855 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
4856 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
4857 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
4858 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
4859 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
4866 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4868 request->wdev = wdev;
4869 request->wiphy = &rdev->wiphy;
4870 request->scan_start = jiffies;
4872 rdev->scan_req = request;
4873 err = rdev_scan(rdev, request);
4876 nl80211_send_scan_start(rdev, wdev);
4878 dev_hold(wdev->netdev);
4881 rdev->scan_req = NULL;
4888 static int nl80211_start_sched_scan(struct sk_buff *skb,
4889 struct genl_info *info)
4891 struct cfg80211_sched_scan_request *request;
4892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4893 struct net_device *dev = info->user_ptr[1];
4894 struct nlattr *attr;
4895 struct wiphy *wiphy;
4896 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
4898 enum ieee80211_band band;
4900 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
4902 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4903 !rdev->ops->sched_scan_start)
4906 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4909 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4912 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4916 wiphy = &rdev->wiphy;
4918 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4919 n_channels = validate_scan_freqs(
4920 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4926 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4927 if (wiphy->bands[band])
4928 n_channels += wiphy->bands[band]->n_channels;
4931 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4932 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4936 if (n_ssids > wiphy->max_sched_scan_ssids)
4939 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4940 nla_for_each_nested(attr,
4941 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4945 if (n_match_sets > wiphy->max_match_sets)
4948 if (info->attrs[NL80211_ATTR_IE])
4949 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4953 if (ie_len > wiphy->max_sched_scan_ie_len)
4956 mutex_lock(&rdev->sched_scan_mtx);
4958 if (rdev->sched_scan_req) {
4963 request = kzalloc(sizeof(*request)
4964 + sizeof(*request->ssids) * n_ssids
4965 + sizeof(*request->match_sets) * n_match_sets
4966 + sizeof(*request->channels) * n_channels
4967 + ie_len, GFP_KERNEL);
4974 request->ssids = (void *)&request->channels[n_channels];
4975 request->n_ssids = n_ssids;
4978 request->ie = (void *)(request->ssids + n_ssids);
4980 request->ie = (void *)(request->channels + n_channels);
4985 request->match_sets = (void *)(request->ie + ie_len);
4986 else if (request->ssids)
4987 request->match_sets =
4988 (void *)(request->ssids + n_ssids);
4990 request->match_sets =
4991 (void *)(request->channels + n_channels);
4993 request->n_match_sets = n_match_sets;
4996 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4997 /* user specified, bail out if channel not found */
4998 nla_for_each_nested(attr,
4999 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5001 struct ieee80211_channel *chan;
5003 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5010 /* ignore disabled channels */
5011 if (chan->flags & IEEE80211_CHAN_DISABLED)
5014 request->channels[i] = chan;
5019 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5021 if (!wiphy->bands[band])
5023 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5024 struct ieee80211_channel *chan;
5026 chan = &wiphy->bands[band]->channels[j];
5028 if (chan->flags & IEEE80211_CHAN_DISABLED)
5031 request->channels[i] = chan;
5042 request->n_channels = i;
5045 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5046 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5048 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
5052 request->ssids[i].ssid_len = nla_len(attr);
5053 memcpy(request->ssids[i].ssid, nla_data(attr),
5060 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5061 nla_for_each_nested(attr,
5062 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5064 struct nlattr *ssid, *rssi;
5066 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5067 nla_data(attr), nla_len(attr),
5068 nl80211_match_policy);
5069 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
5071 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5075 memcpy(request->match_sets[i].ssid.ssid,
5076 nla_data(ssid), nla_len(ssid));
5077 request->match_sets[i].ssid.ssid_len =
5080 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5082 request->rssi_thold = nla_get_u32(rssi);
5084 request->rssi_thold =
5085 NL80211_SCAN_RSSI_THOLD_OFF;
5090 if (info->attrs[NL80211_ATTR_IE]) {
5091 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5092 memcpy((void *)request->ie,
5093 nla_data(info->attrs[NL80211_ATTR_IE]),
5097 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
5098 request->flags = nla_get_u32(
5099 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
5100 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5101 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5102 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5103 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
5110 request->wiphy = &rdev->wiphy;
5111 request->interval = interval;
5112 request->scan_start = jiffies;
5114 err = rdev_sched_scan_start(rdev, dev, request);
5116 rdev->sched_scan_req = request;
5117 nl80211_send_sched_scan(rdev, dev,
5118 NL80211_CMD_START_SCHED_SCAN);
5125 mutex_unlock(&rdev->sched_scan_mtx);
5129 static int nl80211_stop_sched_scan(struct sk_buff *skb,
5130 struct genl_info *info)
5132 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5135 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5136 !rdev->ops->sched_scan_stop)
5139 mutex_lock(&rdev->sched_scan_mtx);
5140 err = __cfg80211_stop_sched_scan(rdev, false);
5141 mutex_unlock(&rdev->sched_scan_mtx);
5146 static int nl80211_start_radar_detection(struct sk_buff *skb,
5147 struct genl_info *info)
5149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5150 struct net_device *dev = info->user_ptr[1];
5151 struct wireless_dev *wdev = dev->ieee80211_ptr;
5152 struct cfg80211_chan_def chandef;
5155 err = nl80211_parse_chandef(rdev, info, &chandef);
5159 if (wdev->cac_started)
5162 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5169 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5172 if (!rdev->ops->start_radar_detection)
5175 mutex_lock(&rdev->devlist_mtx);
5176 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5177 chandef.chan, CHAN_MODE_SHARED,
5178 BIT(chandef.width));
5182 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5184 wdev->channel = chandef.chan;
5185 wdev->cac_started = true;
5186 wdev->cac_start_time = jiffies;
5189 mutex_unlock(&rdev->devlist_mtx);
5194 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5196 struct cfg80211_registered_device *rdev,
5197 struct wireless_dev *wdev,
5198 struct cfg80211_internal_bss *intbss)
5200 struct cfg80211_bss *res = &intbss->pub;
5201 const struct cfg80211_bss_ies *ies;
5206 ASSERT_WDEV_LOCK(wdev);
5208 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5209 NL80211_CMD_NEW_SCAN_RESULTS);
5213 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5215 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
5216 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5217 goto nla_put_failure;
5219 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5221 goto nla_put_failure;
5222 if ((!is_zero_ether_addr(res->bssid) &&
5223 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
5224 goto nla_put_failure;
5227 ies = rcu_dereference(res->ies);
5229 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5230 goto fail_unlock_rcu;
5232 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5233 ies->len, ies->data))
5234 goto fail_unlock_rcu;
5236 ies = rcu_dereference(res->beacon_ies);
5238 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5239 goto fail_unlock_rcu;
5240 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5241 ies->len, ies->data))
5242 goto fail_unlock_rcu;
5246 if (res->beacon_interval &&
5247 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5248 goto nla_put_failure;
5249 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5250 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5251 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5252 jiffies_to_msecs(jiffies - intbss->ts)))
5253 goto nla_put_failure;
5255 switch (rdev->wiphy.signal_type) {
5256 case CFG80211_SIGNAL_TYPE_MBM:
5257 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5258 goto nla_put_failure;
5260 case CFG80211_SIGNAL_TYPE_UNSPEC:
5261 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5262 goto nla_put_failure;
5268 switch (wdev->iftype) {
5269 case NL80211_IFTYPE_P2P_CLIENT:
5270 case NL80211_IFTYPE_STATION:
5271 if (intbss == wdev->current_bss &&
5272 nla_put_u32(msg, NL80211_BSS_STATUS,
5273 NL80211_BSS_STATUS_ASSOCIATED))
5274 goto nla_put_failure;
5276 case NL80211_IFTYPE_ADHOC:
5277 if (intbss == wdev->current_bss &&
5278 nla_put_u32(msg, NL80211_BSS_STATUS,
5279 NL80211_BSS_STATUS_IBSS_JOINED))
5280 goto nla_put_failure;
5286 nla_nest_end(msg, bss);
5288 return genlmsg_end(msg, hdr);
5293 genlmsg_cancel(msg, hdr);
5297 static int nl80211_dump_scan(struct sk_buff *skb,
5298 struct netlink_callback *cb)
5300 struct cfg80211_registered_device *rdev;
5301 struct net_device *dev;
5302 struct cfg80211_internal_bss *scan;
5303 struct wireless_dev *wdev;
5304 int start = cb->args[1], idx = 0;
5307 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
5311 wdev = dev->ieee80211_ptr;
5314 spin_lock_bh(&rdev->bss_lock);
5315 cfg80211_bss_expire(rdev);
5317 cb->seq = rdev->bss_generation;
5319 list_for_each_entry(scan, &rdev->bss_list, list) {
5322 if (nl80211_send_bss(skb, cb,
5323 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5324 rdev, wdev, scan) < 0) {
5330 spin_unlock_bh(&rdev->bss_lock);
5334 nl80211_finish_netdev_dump(rdev);
5339 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
5340 int flags, struct net_device *dev,
5341 struct survey_info *survey)
5344 struct nlattr *infoattr;
5346 hdr = nl80211hdr_put(msg, portid, seq, flags,
5347 NL80211_CMD_NEW_SURVEY_RESULTS);
5351 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5352 goto nla_put_failure;
5354 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5356 goto nla_put_failure;
5358 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5359 survey->channel->center_freq))
5360 goto nla_put_failure;
5362 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5363 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5364 goto nla_put_failure;
5365 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5366 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5367 goto nla_put_failure;
5368 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5369 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5370 survey->channel_time))
5371 goto nla_put_failure;
5372 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5373 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5374 survey->channel_time_busy))
5375 goto nla_put_failure;
5376 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5377 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5378 survey->channel_time_ext_busy))
5379 goto nla_put_failure;
5380 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5381 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5382 survey->channel_time_rx))
5383 goto nla_put_failure;
5384 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5385 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5386 survey->channel_time_tx))
5387 goto nla_put_failure;
5389 nla_nest_end(msg, infoattr);
5391 return genlmsg_end(msg, hdr);
5394 genlmsg_cancel(msg, hdr);
5398 static int nl80211_dump_survey(struct sk_buff *skb,
5399 struct netlink_callback *cb)
5401 struct survey_info survey;
5402 struct cfg80211_registered_device *dev;
5403 struct net_device *netdev;
5404 int survey_idx = cb->args[1];
5407 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
5411 if (!dev->ops->dump_survey) {
5417 struct ieee80211_channel *chan;
5419 res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
5425 /* Survey without a channel doesn't make sense */
5426 if (!survey.channel) {
5431 chan = ieee80211_get_channel(&dev->wiphy,
5432 survey.channel->center_freq);
5433 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5438 if (nl80211_send_survey(skb,
5439 NETLINK_CB(cb->skb).portid,
5440 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5448 cb->args[1] = survey_idx;
5451 nl80211_finish_netdev_dump(dev);
5455 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5457 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5458 NL80211_WPA_VERSION_2));
5461 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5464 struct net_device *dev = info->user_ptr[1];
5465 struct ieee80211_channel *chan;
5466 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5467 int err, ssid_len, ie_len = 0, sae_data_len = 0;
5468 enum nl80211_auth_type auth_type;
5469 struct key_parse key;
5470 bool local_state_change;
5472 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5475 if (!info->attrs[NL80211_ATTR_MAC])
5478 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5481 if (!info->attrs[NL80211_ATTR_SSID])
5484 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5487 err = nl80211_parse_key(info, &key);
5492 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5494 if (!key.p.key || !key.p.key_len)
5496 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5497 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5498 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5499 key.p.key_len != WLAN_KEY_LEN_WEP104))
5511 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5512 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5521 if (!rdev->ops->auth)
5524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5528 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5529 chan = ieee80211_get_channel(&rdev->wiphy,
5530 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5531 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5534 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5535 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5537 if (info->attrs[NL80211_ATTR_IE]) {
5538 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5539 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5542 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5543 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
5546 if (auth_type == NL80211_AUTHTYPE_SAE &&
5547 !info->attrs[NL80211_ATTR_SAE_DATA])
5550 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5551 if (auth_type != NL80211_AUTHTYPE_SAE)
5553 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5554 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5555 /* need to include at least Auth Transaction and Status Code */
5556 if (sae_data_len < 4)
5560 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5563 * Since we no longer track auth state, ignore
5564 * requests to only change local state.
5566 if (local_state_change)
5569 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5570 ssid, ssid_len, ie, ie_len,
5571 key.p.key, key.p.key_len, key.idx,
5572 sae_data, sae_data_len);
5575 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5576 struct genl_info *info,
5577 struct cfg80211_crypto_settings *settings,
5580 memset(settings, 0, sizeof(*settings));
5582 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5584 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5586 proto = nla_get_u16(
5587 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5588 settings->control_port_ethertype = cpu_to_be16(proto);
5589 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5592 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5593 settings->control_port_no_encrypt = true;
5595 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5597 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5601 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5602 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5603 settings->n_ciphers_pairwise = len / sizeof(u32);
5605 if (len % sizeof(u32))
5608 if (settings->n_ciphers_pairwise > cipher_limit)
5611 memcpy(settings->ciphers_pairwise, data, len);
5613 for (i = 0; i < settings->n_ciphers_pairwise; i++)
5614 if (!cfg80211_supported_cipher_suite(
5616 settings->ciphers_pairwise[i]))
5620 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5621 settings->cipher_group =
5622 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
5623 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5624 settings->cipher_group))
5628 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5629 settings->wpa_versions =
5630 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5631 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5635 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5639 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5640 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5641 settings->n_akm_suites = len / sizeof(u32);
5643 if (len % sizeof(u32))
5646 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5649 memcpy(settings->akm_suites, data, len);
5655 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5658 struct net_device *dev = info->user_ptr[1];
5659 struct cfg80211_crypto_settings crypto;
5660 struct ieee80211_channel *chan;
5661 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
5662 int err, ssid_len, ie_len = 0;
5663 bool use_mfp = false;
5665 struct ieee80211_ht_cap *ht_capa = NULL;
5666 struct ieee80211_ht_cap *ht_capa_mask = NULL;
5668 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5671 if (!info->attrs[NL80211_ATTR_MAC] ||
5672 !info->attrs[NL80211_ATTR_SSID] ||
5673 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5676 if (!rdev->ops->assoc)
5679 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5680 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5683 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5685 chan = ieee80211_get_channel(&rdev->wiphy,
5686 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5687 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5690 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5691 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5693 if (info->attrs[NL80211_ATTR_IE]) {
5694 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5695 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5698 if (info->attrs[NL80211_ATTR_USE_MFP]) {
5699 enum nl80211_mfp mfp =
5700 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
5701 if (mfp == NL80211_MFP_REQUIRED)
5703 else if (mfp != NL80211_MFP_NO)
5707 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5708 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5710 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5711 flags |= ASSOC_REQ_DISABLE_HT;
5713 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5715 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5717 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5720 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5723 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
5725 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5726 ssid, ssid_len, ie, ie_len, use_mfp,
5727 &crypto, flags, ht_capa,
5733 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5735 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5736 struct net_device *dev = info->user_ptr[1];
5737 const u8 *ie = NULL, *bssid;
5740 bool local_state_change;
5742 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5745 if (!info->attrs[NL80211_ATTR_MAC])
5748 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5751 if (!rdev->ops->deauth)
5754 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5755 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5758 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5760 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5761 if (reason_code == 0) {
5762 /* Reason Code 0 is reserved */
5766 if (info->attrs[NL80211_ATTR_IE]) {
5767 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5768 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5771 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5773 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5774 local_state_change);
5777 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5780 struct net_device *dev = info->user_ptr[1];
5781 const u8 *ie = NULL, *bssid;
5784 bool local_state_change;
5786 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5789 if (!info->attrs[NL80211_ATTR_MAC])
5792 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5795 if (!rdev->ops->disassoc)
5798 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5799 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5802 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5804 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5805 if (reason_code == 0) {
5806 /* Reason Code 0 is reserved */
5810 if (info->attrs[NL80211_ATTR_IE]) {
5811 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5812 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5815 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5817 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5818 local_state_change);
5822 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5823 int mcast_rate[IEEE80211_NUM_BANDS],
5826 struct wiphy *wiphy = &rdev->wiphy;
5830 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5831 struct ieee80211_supported_band *sband;
5833 sband = wiphy->bands[band];
5837 for (i = 0; i < sband->n_bitrates; i++) {
5838 if (sband->bitrates[i].bitrate == rateval) {
5839 mcast_rate[band] = i + 1;
5849 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5852 struct net_device *dev = info->user_ptr[1];
5853 struct cfg80211_ibss_params ibss;
5854 struct wiphy *wiphy;
5855 struct cfg80211_cached_keys *connkeys = NULL;
5858 memset(&ibss, 0, sizeof(ibss));
5860 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5863 if (!info->attrs[NL80211_ATTR_SSID] ||
5864 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5867 ibss.beacon_interval = 100;
5869 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5870 ibss.beacon_interval =
5871 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5872 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5876 if (!rdev->ops->join_ibss)
5879 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5882 wiphy = &rdev->wiphy;
5884 if (info->attrs[NL80211_ATTR_MAC]) {
5885 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5887 if (!is_valid_ether_addr(ibss.bssid))
5890 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5891 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5893 if (info->attrs[NL80211_ATTR_IE]) {
5894 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5895 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5898 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
5902 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
5905 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
5907 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
5908 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
5911 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
5912 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5914 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5916 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5918 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5919 struct ieee80211_supported_band *sband =
5920 wiphy->bands[ibss.chandef.chan->band];
5922 err = ieee80211_get_ratemask(sband, rates, n_rates,
5928 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5929 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5930 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5933 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5936 connkeys = nl80211_parse_connkeys(rdev,
5937 info->attrs[NL80211_ATTR_KEYS],
5939 if (IS_ERR(connkeys))
5940 return PTR_ERR(connkeys);
5942 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
5950 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5952 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
5958 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5961 struct net_device *dev = info->user_ptr[1];
5963 if (!rdev->ops->leave_ibss)
5966 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5969 return cfg80211_leave_ibss(rdev, dev, false);
5972 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
5974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5975 struct net_device *dev = info->user_ptr[1];
5976 int mcast_rate[IEEE80211_NUM_BANDS];
5980 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5981 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5984 if (!rdev->ops->set_mcast_rate)
5987 memset(mcast_rate, 0, sizeof(mcast_rate));
5989 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
5992 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
5993 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
5996 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6002 #ifdef CONFIG_NL80211_TESTMODE
6003 static struct genl_multicast_group nl80211_testmode_mcgrp = {
6007 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6012 if (!info->attrs[NL80211_ATTR_TESTDATA])
6016 if (rdev->ops->testmode_cmd) {
6017 rdev->testmode_info = info;
6018 err = rdev_testmode_cmd(rdev,
6019 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6020 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6021 rdev->testmode_info = NULL;
6027 static int nl80211_testmode_dump(struct sk_buff *skb,
6028 struct netlink_callback *cb)
6030 struct cfg80211_registered_device *rdev;
6038 * 0 is a valid index, but not valid for args[0],
6039 * so we need to offset by 1.
6041 phy_idx = cb->args[0] - 1;
6043 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6044 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6049 mutex_lock(&cfg80211_mutex);
6050 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6051 nl80211_fam.attrbuf);
6053 mutex_unlock(&cfg80211_mutex);
6054 return PTR_ERR(rdev);
6056 phy_idx = rdev->wiphy_idx;
6058 mutex_unlock(&cfg80211_mutex);
6060 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6062 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6066 data = nla_data((void *)cb->args[1]);
6067 data_len = nla_len((void *)cb->args[1]);
6070 mutex_lock(&cfg80211_mutex);
6071 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6073 mutex_unlock(&cfg80211_mutex);
6076 cfg80211_lock_rdev(rdev);
6077 mutex_unlock(&cfg80211_mutex);
6079 if (!rdev->ops->testmode_dump) {
6085 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
6086 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6087 NL80211_CMD_TESTMODE);
6088 struct nlattr *tmdata;
6090 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
6091 genlmsg_cancel(skb, hdr);
6095 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6097 genlmsg_cancel(skb, hdr);
6100 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
6101 nla_nest_end(skb, tmdata);
6103 if (err == -ENOBUFS || err == -ENOENT) {
6104 genlmsg_cancel(skb, hdr);
6107 genlmsg_cancel(skb, hdr);
6111 genlmsg_end(skb, hdr);
6116 cb->args[0] = phy_idx + 1;
6118 cfg80211_unlock_rdev(rdev);
6122 static struct sk_buff *
6123 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
6124 int approxlen, u32 portid, u32 seq, gfp_t gfp)
6126 struct sk_buff *skb;
6128 struct nlattr *data;
6130 skb = nlmsg_new(approxlen + 100, gfp);
6134 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
6140 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6141 goto nla_put_failure;
6142 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6144 ((void **)skb->cb)[0] = rdev;
6145 ((void **)skb->cb)[1] = hdr;
6146 ((void **)skb->cb)[2] = data;
6155 struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6158 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6160 if (WARN_ON(!rdev->testmode_info))
6163 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
6164 rdev->testmode_info->snd_portid,
6165 rdev->testmode_info->snd_seq,
6168 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6170 int cfg80211_testmode_reply(struct sk_buff *skb)
6172 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6173 void *hdr = ((void **)skb->cb)[1];
6174 struct nlattr *data = ((void **)skb->cb)[2];
6176 if (WARN_ON(!rdev->testmode_info)) {
6181 nla_nest_end(skb, data);
6182 genlmsg_end(skb, hdr);
6183 return genlmsg_reply(skb, rdev->testmode_info);
6185 EXPORT_SYMBOL(cfg80211_testmode_reply);
6187 struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6188 int approxlen, gfp_t gfp)
6190 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6192 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6194 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6196 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6198 void *hdr = ((void **)skb->cb)[1];
6199 struct nlattr *data = ((void **)skb->cb)[2];
6201 nla_nest_end(skb, data);
6202 genlmsg_end(skb, hdr);
6203 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6205 EXPORT_SYMBOL(cfg80211_testmode_event);
6208 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6211 struct net_device *dev = info->user_ptr[1];
6212 struct cfg80211_connect_params connect;
6213 struct wiphy *wiphy;
6214 struct cfg80211_cached_keys *connkeys = NULL;
6217 memset(&connect, 0, sizeof(connect));
6219 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6222 if (!info->attrs[NL80211_ATTR_SSID] ||
6223 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6226 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6228 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
6229 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6230 NL80211_CMD_CONNECT))
6233 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6235 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6237 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
6238 NL80211_MAX_NR_CIPHER_SUITES);
6242 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6243 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6246 wiphy = &rdev->wiphy;
6248 connect.bg_scan_period = -1;
6249 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6250 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6251 connect.bg_scan_period =
6252 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6255 if (info->attrs[NL80211_ATTR_MAC])
6256 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6257 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6258 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6260 if (info->attrs[NL80211_ATTR_IE]) {
6261 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6262 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6265 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6266 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6267 if (connect.mfp != NL80211_MFP_REQUIRED &&
6268 connect.mfp != NL80211_MFP_NO)
6271 connect.mfp = NL80211_MFP_NO;
6274 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6276 ieee80211_get_channel(wiphy,
6277 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6278 if (!connect.channel ||
6279 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6283 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6284 connkeys = nl80211_parse_connkeys(rdev,
6285 info->attrs[NL80211_ATTR_KEYS], NULL);
6286 if (IS_ERR(connkeys))
6287 return PTR_ERR(connkeys);
6290 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6291 connect.flags |= ASSOC_REQ_DISABLE_HT;
6293 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6294 memcpy(&connect.ht_capa_mask,
6295 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6296 sizeof(connect.ht_capa_mask));
6298 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6299 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6303 memcpy(&connect.ht_capa,
6304 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6305 sizeof(connect.ht_capa));
6308 err = cfg80211_connect(rdev, dev, &connect, connkeys);
6314 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6317 struct net_device *dev = info->user_ptr[1];
6320 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6321 reason = WLAN_REASON_DEAUTH_LEAVING;
6323 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6328 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6329 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6332 return cfg80211_disconnect(rdev, dev, reason, true);
6335 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6342 if (!info->attrs[NL80211_ATTR_PID])
6345 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6347 net = get_net_ns_by_pid(pid);
6349 return PTR_ERR(net);
6353 /* check if anything to do */
6354 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6355 err = cfg80211_switch_netns(rdev, net);
6361 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6364 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6365 struct cfg80211_pmksa *pmksa) = NULL;
6366 struct net_device *dev = info->user_ptr[1];
6367 struct cfg80211_pmksa pmksa;
6369 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6371 if (!info->attrs[NL80211_ATTR_MAC])
6374 if (!info->attrs[NL80211_ATTR_PMKID])
6377 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6378 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6380 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6381 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6384 switch (info->genlhdr->cmd) {
6385 case NL80211_CMD_SET_PMKSA:
6386 rdev_ops = rdev->ops->set_pmksa;
6388 case NL80211_CMD_DEL_PMKSA:
6389 rdev_ops = rdev->ops->del_pmksa;
6399 return rdev_ops(&rdev->wiphy, dev, &pmksa);
6402 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6405 struct net_device *dev = info->user_ptr[1];
6407 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6408 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6411 if (!rdev->ops->flush_pmksa)
6414 return rdev_flush_pmksa(rdev, dev);
6417 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6420 struct net_device *dev = info->user_ptr[1];
6421 u8 action_code, dialog_token;
6425 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6426 !rdev->ops->tdls_mgmt)
6429 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6430 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6431 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6432 !info->attrs[NL80211_ATTR_IE] ||
6433 !info->attrs[NL80211_ATTR_MAC])
6436 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6437 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6438 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6439 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6441 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6442 dialog_token, status_code,
6443 nla_data(info->attrs[NL80211_ATTR_IE]),
6444 nla_len(info->attrs[NL80211_ATTR_IE]));
6447 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6450 struct net_device *dev = info->user_ptr[1];
6451 enum nl80211_tdls_operation operation;
6454 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6455 !rdev->ops->tdls_oper)
6458 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6459 !info->attrs[NL80211_ATTR_MAC])
6462 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6463 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6465 return rdev_tdls_oper(rdev, dev, peer, operation);
6468 static int nl80211_remain_on_channel(struct sk_buff *skb,
6469 struct genl_info *info)
6471 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6472 struct wireless_dev *wdev = info->user_ptr[1];
6473 struct cfg80211_chan_def chandef;
6474 struct sk_buff *msg;
6480 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6481 !info->attrs[NL80211_ATTR_DURATION])
6484 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6486 if (!rdev->ops->remain_on_channel ||
6487 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
6491 * We should be on that channel for at least a minimum amount of
6492 * time (10ms) but no longer than the driver supports.
6494 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6495 duration > rdev->wiphy.max_remain_on_channel_duration)
6498 err = nl80211_parse_chandef(rdev, info, &chandef);
6502 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6506 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6507 NL80211_CMD_REMAIN_ON_CHANNEL);
6514 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6520 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6521 goto nla_put_failure;
6523 genlmsg_end(msg, hdr);
6525 return genlmsg_reply(msg, info);
6534 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6535 struct genl_info *info)
6537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6538 struct wireless_dev *wdev = info->user_ptr[1];
6541 if (!info->attrs[NL80211_ATTR_COOKIE])
6544 if (!rdev->ops->cancel_remain_on_channel)
6547 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6549 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
6552 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6553 u8 *rates, u8 rates_len)
6558 for (i = 0; i < rates_len; i++) {
6559 int rate = (rates[i] & 0x7f) * 5;
6561 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6562 struct ieee80211_rate *srate =
6563 &sband->bitrates[ridx];
6564 if (rate == srate->bitrate) {
6569 if (ridx == sband->n_bitrates)
6570 return 0; /* rate not found */
6576 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6577 u8 *rates, u8 rates_len,
6578 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6582 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6584 for (i = 0; i < rates_len; i++) {
6587 ridx = rates[i] / 8;
6588 rbit = BIT(rates[i] % 8);
6590 /* check validity */
6591 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
6594 /* check availability */
6595 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6604 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
6605 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6606 .len = NL80211_MAX_SUPP_RATES },
6607 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6608 .len = NL80211_MAX_SUPP_HT_RATES },
6611 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6612 struct genl_info *info)
6614 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
6615 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6616 struct cfg80211_bitrate_mask mask;
6618 struct net_device *dev = info->user_ptr[1];
6619 struct nlattr *tx_rates;
6620 struct ieee80211_supported_band *sband;
6622 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6625 if (!rdev->ops->set_bitrate_mask)
6628 memset(&mask, 0, sizeof(mask));
6629 /* Default to all rates enabled */
6630 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6631 sband = rdev->wiphy.bands[i];
6632 mask.control[i].legacy =
6633 sband ? (1 << sband->n_bitrates) - 1 : 0;
6635 memcpy(mask.control[i].mcs,
6636 sband->ht_cap.mcs.rx_mask,
6637 sizeof(mask.control[i].mcs));
6639 memset(mask.control[i].mcs, 0,
6640 sizeof(mask.control[i].mcs));
6644 * The nested attribute uses enum nl80211_band as the index. This maps
6645 * directly to the enum ieee80211_band values used in cfg80211.
6647 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
6648 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6650 enum ieee80211_band band = nla_type(tx_rates);
6651 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6653 sband = rdev->wiphy.bands[band];
6656 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6657 nla_len(tx_rates), nl80211_txattr_policy);
6658 if (tb[NL80211_TXRATE_LEGACY]) {
6659 mask.control[band].legacy = rateset_to_mask(
6661 nla_data(tb[NL80211_TXRATE_LEGACY]),
6662 nla_len(tb[NL80211_TXRATE_LEGACY]));
6663 if ((mask.control[band].legacy == 0) &&
6664 nla_len(tb[NL80211_TXRATE_LEGACY]))
6667 if (tb[NL80211_TXRATE_MCS]) {
6668 if (!ht_rateset_to_mask(
6670 nla_data(tb[NL80211_TXRATE_MCS]),
6671 nla_len(tb[NL80211_TXRATE_MCS]),
6672 mask.control[band].mcs))
6676 if (mask.control[band].legacy == 0) {
6677 /* don't allow empty legacy rates if HT
6678 * is not even supported. */
6679 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6682 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6683 if (mask.control[band].mcs[i])
6686 /* legacy and mcs rates may not be both empty */
6687 if (i == IEEE80211_HT_MCS_MASK_LEN)
6692 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
6695 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
6697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6698 struct wireless_dev *wdev = info->user_ptr[1];
6699 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
6701 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6704 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6705 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
6707 switch (wdev->iftype) {
6708 case NL80211_IFTYPE_STATION:
6709 case NL80211_IFTYPE_ADHOC:
6710 case NL80211_IFTYPE_P2P_CLIENT:
6711 case NL80211_IFTYPE_AP:
6712 case NL80211_IFTYPE_AP_VLAN:
6713 case NL80211_IFTYPE_MESH_POINT:
6714 case NL80211_IFTYPE_P2P_GO:
6715 case NL80211_IFTYPE_P2P_DEVICE:
6721 /* not much point in registering if we can't reply */
6722 if (!rdev->ops->mgmt_tx)
6725 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
6726 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6727 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
6730 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
6732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6733 struct wireless_dev *wdev = info->user_ptr[1];
6734 struct cfg80211_chan_def chandef;
6738 struct sk_buff *msg = NULL;
6739 unsigned int wait = 0;
6740 bool offchan, no_cck, dont_wait_for_ack;
6742 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
6744 if (!info->attrs[NL80211_ATTR_FRAME])
6747 if (!rdev->ops->mgmt_tx)
6750 switch (wdev->iftype) {
6751 case NL80211_IFTYPE_STATION:
6752 case NL80211_IFTYPE_ADHOC:
6753 case NL80211_IFTYPE_P2P_CLIENT:
6754 case NL80211_IFTYPE_AP:
6755 case NL80211_IFTYPE_AP_VLAN:
6756 case NL80211_IFTYPE_MESH_POINT:
6757 case NL80211_IFTYPE_P2P_GO:
6758 case NL80211_IFTYPE_P2P_DEVICE:
6764 if (info->attrs[NL80211_ATTR_DURATION]) {
6765 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6767 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6770 * We should wait on the channel for at least a minimum amount
6771 * of time (10ms) but no longer than the driver supports.
6773 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6774 wait > rdev->wiphy.max_remain_on_channel_duration)
6779 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6781 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6784 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6786 err = nl80211_parse_chandef(rdev, info, &chandef);
6790 if (!dont_wait_for_ack) {
6791 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6795 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6804 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
6805 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6806 nla_len(info->attrs[NL80211_ATTR_FRAME]),
6807 no_cck, dont_wait_for_ack, &cookie);
6812 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6813 goto nla_put_failure;
6815 genlmsg_end(msg, hdr);
6816 return genlmsg_reply(msg, info);
6828 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6831 struct wireless_dev *wdev = info->user_ptr[1];
6834 if (!info->attrs[NL80211_ATTR_COOKIE])
6837 if (!rdev->ops->mgmt_tx_cancel_wait)
6840 switch (wdev->iftype) {
6841 case NL80211_IFTYPE_STATION:
6842 case NL80211_IFTYPE_ADHOC:
6843 case NL80211_IFTYPE_P2P_CLIENT:
6844 case NL80211_IFTYPE_AP:
6845 case NL80211_IFTYPE_AP_VLAN:
6846 case NL80211_IFTYPE_P2P_GO:
6847 case NL80211_IFTYPE_P2P_DEVICE:
6853 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6855 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
6858 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6861 struct wireless_dev *wdev;
6862 struct net_device *dev = info->user_ptr[1];
6867 if (!info->attrs[NL80211_ATTR_PS_STATE])
6870 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6872 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6875 wdev = dev->ieee80211_ptr;
6877 if (!rdev->ops->set_power_mgmt)
6880 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6882 if (state == wdev->ps)
6885 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
6891 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6894 enum nl80211_ps_state ps_state;
6895 struct wireless_dev *wdev;
6896 struct net_device *dev = info->user_ptr[1];
6897 struct sk_buff *msg;
6901 wdev = dev->ieee80211_ptr;
6903 if (!rdev->ops->set_power_mgmt)
6906 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6910 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6911 NL80211_CMD_GET_POWER_SAVE);
6918 ps_state = NL80211_PS_ENABLED;
6920 ps_state = NL80211_PS_DISABLED;
6922 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6923 goto nla_put_failure;
6925 genlmsg_end(msg, hdr);
6926 return genlmsg_reply(msg, info);
6935 static struct nla_policy
6936 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6937 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6938 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6939 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6940 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6941 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6942 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
6945 static int nl80211_set_cqm_txe(struct genl_info *info,
6946 u32 rate, u32 pkts, u32 intvl)
6948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6949 struct wireless_dev *wdev;
6950 struct net_device *dev = info->user_ptr[1];
6952 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
6955 wdev = dev->ieee80211_ptr;
6957 if (!rdev->ops->set_cqm_txe_config)
6960 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6961 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6964 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
6967 static int nl80211_set_cqm_rssi(struct genl_info *info,
6968 s32 threshold, u32 hysteresis)
6970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6971 struct wireless_dev *wdev;
6972 struct net_device *dev = info->user_ptr[1];
6977 wdev = dev->ieee80211_ptr;
6979 if (!rdev->ops->set_cqm_rssi_config)
6982 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6983 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6986 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
6989 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6991 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6995 cqm = info->attrs[NL80211_ATTR_CQM];
7001 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7002 nl80211_attr_cqm_policy);
7006 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7007 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7010 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7011 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7012 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
7013 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7014 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7015 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7016 u32 rate, pkts, intvl;
7017 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7018 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7019 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7020 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
7028 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7031 struct net_device *dev = info->user_ptr[1];
7032 struct mesh_config cfg;
7033 struct mesh_setup setup;
7036 /* start with default */
7037 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
7038 memcpy(&setup, &default_mesh_setup, sizeof(setup));
7040 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
7041 /* and parse parameters if given */
7042 err = nl80211_parse_mesh_config(info, &cfg, NULL);
7047 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7048 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7051 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7052 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7054 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7055 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7056 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7059 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7060 setup.beacon_interval =
7061 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7062 if (setup.beacon_interval < 10 ||
7063 setup.beacon_interval > 10000)
7067 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7069 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7070 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7074 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7075 /* parse additional setup parameters if given */
7076 err = nl80211_parse_mesh_setup(info, &setup);
7081 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7082 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7086 /* cfg80211_join_mesh() will sort it out */
7087 setup.chandef.chan = NULL;
7090 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
7093 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7095 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7096 struct net_device *dev = info->user_ptr[1];
7098 return cfg80211_leave_mesh(rdev, dev);
7102 static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7103 struct cfg80211_registered_device *rdev)
7105 struct nlattr *nl_pats, *nl_pat;
7108 if (!rdev->wowlan->n_patterns)
7111 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7115 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7116 nl_pat = nla_nest_start(msg, i + 1);
7119 pat_len = rdev->wowlan->patterns[i].pattern_len;
7120 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7121 DIV_ROUND_UP(pat_len, 8),
7122 rdev->wowlan->patterns[i].mask) ||
7123 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7124 pat_len, rdev->wowlan->patterns[i].pattern) ||
7125 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7126 rdev->wowlan->patterns[i].pkt_offset))
7128 nla_nest_end(msg, nl_pat);
7130 nla_nest_end(msg, nl_pats);
7135 static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7136 struct cfg80211_wowlan_tcp *tcp)
7138 struct nlattr *nl_tcp;
7143 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7147 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7148 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7149 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7150 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7151 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7152 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7153 tcp->payload_len, tcp->payload) ||
7154 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7155 tcp->data_interval) ||
7156 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7157 tcp->wake_len, tcp->wake_data) ||
7158 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7159 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7162 if (tcp->payload_seq.len &&
7163 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7164 sizeof(tcp->payload_seq), &tcp->payload_seq))
7167 if (tcp->payload_tok.len &&
7168 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7169 sizeof(tcp->payload_tok) + tcp->tokens_size,
7176 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7179 struct sk_buff *msg;
7181 u32 size = NLMSG_DEFAULT_SIZE;
7183 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7184 !rdev->wiphy.wowlan.tcp)
7187 if (rdev->wowlan && rdev->wowlan->tcp) {
7188 /* adjust size to have room for all the data */
7189 size += rdev->wowlan->tcp->tokens_size +
7190 rdev->wowlan->tcp->payload_len +
7191 rdev->wowlan->tcp->wake_len +
7192 rdev->wowlan->tcp->wake_len / 8;
7195 msg = nlmsg_new(size, GFP_KERNEL);
7199 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7200 NL80211_CMD_GET_WOWLAN);
7202 goto nla_put_failure;
7205 struct nlattr *nl_wowlan;
7207 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7209 goto nla_put_failure;
7211 if ((rdev->wowlan->any &&
7212 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7213 (rdev->wowlan->disconnect &&
7214 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7215 (rdev->wowlan->magic_pkt &&
7216 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7217 (rdev->wowlan->gtk_rekey_failure &&
7218 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7219 (rdev->wowlan->eap_identity_req &&
7220 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7221 (rdev->wowlan->four_way_handshake &&
7222 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7223 (rdev->wowlan->rfkill_release &&
7224 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7225 goto nla_put_failure;
7227 if (nl80211_send_wowlan_patterns(msg, rdev))
7228 goto nla_put_failure;
7230 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7231 goto nla_put_failure;
7233 nla_nest_end(msg, nl_wowlan);
7236 genlmsg_end(msg, hdr);
7237 return genlmsg_reply(msg, info);
7244 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7245 struct nlattr *attr,
7246 struct cfg80211_wowlan *trig)
7248 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7249 struct cfg80211_wowlan_tcp *cfg;
7250 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7251 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7253 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7256 if (!rdev->wiphy.wowlan.tcp)
7259 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7260 nla_data(attr), nla_len(attr),
7261 nl80211_wowlan_tcp_policy);
7265 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7266 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7267 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7268 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7269 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7270 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7271 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7272 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7275 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7276 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7279 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
7280 rdev->wiphy.wowlan.tcp->data_interval_max)
7283 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7284 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7287 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7288 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7291 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7292 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7294 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7295 tokens_size = tokln - sizeof(*tok);
7297 if (!tok->len || tokens_size % tok->len)
7299 if (!rdev->wiphy.wowlan.tcp->tok)
7301 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7303 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7305 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7307 if (tok->offset + tok->len > data_size)
7311 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7312 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7313 if (!rdev->wiphy.wowlan.tcp->seq)
7315 if (seq->len == 0 || seq->len > 4)
7317 if (seq->len + seq->offset > data_size)
7321 size = sizeof(*cfg);
7323 size += wake_size + wake_mask_size;
7324 size += tokens_size;
7326 cfg = kzalloc(size, GFP_KERNEL);
7329 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7330 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7331 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7333 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7334 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7338 /* allocate a socket and port for it and use it */
7339 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7340 IPPROTO_TCP, &cfg->sock, 1);
7345 if (inet_csk_get_port(cfg->sock->sk, port)) {
7346 sock_release(cfg->sock);
7350 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7356 cfg->src_port = port;
7359 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7360 cfg->payload_len = data_size;
7361 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7362 memcpy((void *)cfg->payload,
7363 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7366 cfg->payload_seq = *seq;
7367 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7368 cfg->wake_len = wake_size;
7369 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7370 memcpy((void *)cfg->wake_data,
7371 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7373 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7374 data_size + wake_size;
7375 memcpy((void *)cfg->wake_mask,
7376 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7379 cfg->tokens_size = tokens_size;
7380 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7388 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7390 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7391 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
7392 struct cfg80211_wowlan new_triggers = {};
7393 struct cfg80211_wowlan *ntrig;
7394 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7396 bool prev_enabled = rdev->wowlan;
7398 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7399 !rdev->wiphy.wowlan.tcp)
7402 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7403 cfg80211_rdev_free_wowlan(rdev);
7404 rdev->wowlan = NULL;
7408 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7409 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7410 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7411 nl80211_wowlan_policy);
7415 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7416 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7418 new_triggers.any = true;
7421 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7422 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7424 new_triggers.disconnect = true;
7427 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7428 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7430 new_triggers.magic_pkt = true;
7433 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7436 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7437 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7439 new_triggers.gtk_rekey_failure = true;
7442 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7443 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7445 new_triggers.eap_identity_req = true;
7448 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7449 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7451 new_triggers.four_way_handshake = true;
7454 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7455 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7457 new_triggers.rfkill_release = true;
7460 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7463 int rem, pat_len, mask_len, pkt_offset;
7464 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7466 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7469 if (n_patterns > wowlan->n_patterns)
7472 new_triggers.patterns = kcalloc(n_patterns,
7473 sizeof(new_triggers.patterns[0]),
7475 if (!new_triggers.patterns)
7478 new_triggers.n_patterns = n_patterns;
7481 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7483 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7484 nla_data(pat), nla_len(pat), NULL);
7486 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7487 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7489 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7490 mask_len = DIV_ROUND_UP(pat_len, 8);
7491 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7494 if (pat_len > wowlan->pattern_max_len ||
7495 pat_len < wowlan->pattern_min_len)
7498 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7501 pkt_offset = nla_get_u32(
7502 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7503 if (pkt_offset > wowlan->max_pkt_offset)
7505 new_triggers.patterns[i].pkt_offset = pkt_offset;
7507 new_triggers.patterns[i].mask =
7508 kmalloc(mask_len + pat_len, GFP_KERNEL);
7509 if (!new_triggers.patterns[i].mask) {
7513 new_triggers.patterns[i].pattern =
7514 new_triggers.patterns[i].mask + mask_len;
7515 memcpy(new_triggers.patterns[i].mask,
7516 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7518 new_triggers.patterns[i].pattern_len = pat_len;
7519 memcpy(new_triggers.patterns[i].pattern,
7520 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7526 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7527 err = nl80211_parse_wowlan_tcp(
7528 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7534 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7539 cfg80211_rdev_free_wowlan(rdev);
7540 rdev->wowlan = ntrig;
7543 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
7544 rdev_set_wakeup(rdev, rdev->wowlan);
7548 for (i = 0; i < new_triggers.n_patterns; i++)
7549 kfree(new_triggers.patterns[i].mask);
7550 kfree(new_triggers.patterns);
7551 if (new_triggers.tcp && new_triggers.tcp->sock)
7552 sock_release(new_triggers.tcp->sock);
7553 kfree(new_triggers.tcp);
7558 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7561 struct net_device *dev = info->user_ptr[1];
7562 struct wireless_dev *wdev = dev->ieee80211_ptr;
7563 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7564 struct cfg80211_gtk_rekey_data rekey_data;
7567 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7570 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7571 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7572 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7573 nl80211_rekey_policy);
7577 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7579 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7581 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7584 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7586 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7588 memcpy(rekey_data.replay_ctr,
7589 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7590 NL80211_REPLAY_CTR_LEN);
7593 if (!wdev->current_bss) {
7598 if (!rdev->ops->set_rekey_data) {
7603 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
7609 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
7610 struct genl_info *info)
7612 struct net_device *dev = info->user_ptr[1];
7613 struct wireless_dev *wdev = dev->ieee80211_ptr;
7615 if (wdev->iftype != NL80211_IFTYPE_AP &&
7616 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7619 if (wdev->ap_unexpected_nlportid)
7622 wdev->ap_unexpected_nlportid = info->snd_portid;
7626 static int nl80211_probe_client(struct sk_buff *skb,
7627 struct genl_info *info)
7629 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7630 struct net_device *dev = info->user_ptr[1];
7631 struct wireless_dev *wdev = dev->ieee80211_ptr;
7632 struct sk_buff *msg;
7638 if (wdev->iftype != NL80211_IFTYPE_AP &&
7639 wdev->iftype != NL80211_IFTYPE_P2P_GO)
7642 if (!info->attrs[NL80211_ATTR_MAC])
7645 if (!rdev->ops->probe_client)
7648 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7652 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7653 NL80211_CMD_PROBE_CLIENT);
7660 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
7662 err = rdev_probe_client(rdev, dev, addr, &cookie);
7666 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7667 goto nla_put_failure;
7669 genlmsg_end(msg, hdr);
7671 return genlmsg_reply(msg, info);
7680 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
7682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7683 struct cfg80211_beacon_registration *reg, *nreg;
7686 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
7689 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
7693 /* First, check if already registered. */
7694 spin_lock_bh(&rdev->beacon_registrations_lock);
7695 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
7696 if (reg->nlportid == info->snd_portid) {
7701 /* Add it to the list */
7702 nreg->nlportid = info->snd_portid;
7703 list_add(&nreg->list, &rdev->beacon_registrations);
7705 spin_unlock_bh(&rdev->beacon_registrations_lock);
7709 spin_unlock_bh(&rdev->beacon_registrations_lock);
7714 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
7716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7717 struct wireless_dev *wdev = info->user_ptr[1];
7720 if (!rdev->ops->start_p2p_device)
7723 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7726 if (wdev->p2p_started)
7729 mutex_lock(&rdev->devlist_mtx);
7730 err = cfg80211_can_add_interface(rdev, wdev->iftype);
7731 mutex_unlock(&rdev->devlist_mtx);
7735 err = rdev_start_p2p_device(rdev, wdev);
7739 wdev->p2p_started = true;
7740 mutex_lock(&rdev->devlist_mtx);
7742 mutex_unlock(&rdev->devlist_mtx);
7747 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
7749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7750 struct wireless_dev *wdev = info->user_ptr[1];
7752 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
7755 if (!rdev->ops->stop_p2p_device)
7758 if (!wdev->p2p_started)
7761 rdev_stop_p2p_device(rdev, wdev);
7762 wdev->p2p_started = false;
7764 mutex_lock(&rdev->devlist_mtx);
7766 mutex_unlock(&rdev->devlist_mtx);
7768 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
7769 rdev->scan_req->aborted = true;
7770 ___cfg80211_scan_done(rdev, true);
7776 #define NL80211_FLAG_NEED_WIPHY 0x01
7777 #define NL80211_FLAG_NEED_NETDEV 0x02
7778 #define NL80211_FLAG_NEED_RTNL 0x04
7779 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
7780 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
7781 NL80211_FLAG_CHECK_NETDEV_UP)
7782 #define NL80211_FLAG_NEED_WDEV 0x10
7783 /* If a netdev is associated, it must be UP, P2P must be started */
7784 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
7785 NL80211_FLAG_CHECK_NETDEV_UP)
7787 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
7788 struct genl_info *info)
7790 struct cfg80211_registered_device *rdev;
7791 struct wireless_dev *wdev;
7792 struct net_device *dev;
7793 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
7798 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
7799 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7803 return PTR_ERR(rdev);
7805 info->user_ptr[0] = rdev;
7806 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
7807 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7808 mutex_lock(&cfg80211_mutex);
7809 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
7812 mutex_unlock(&cfg80211_mutex);
7815 return PTR_ERR(wdev);
7819 rdev = wiphy_to_dev(wdev->wiphy);
7821 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
7823 mutex_unlock(&cfg80211_mutex);
7829 info->user_ptr[1] = dev;
7831 info->user_ptr[1] = wdev;
7835 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
7836 !netif_running(dev)) {
7837 mutex_unlock(&cfg80211_mutex);
7844 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
7845 if (!wdev->p2p_started) {
7846 mutex_unlock(&cfg80211_mutex);
7853 cfg80211_lock_rdev(rdev);
7855 mutex_unlock(&cfg80211_mutex);
7857 info->user_ptr[0] = rdev;
7863 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
7864 struct genl_info *info)
7866 if (info->user_ptr[0])
7867 cfg80211_unlock_rdev(info->user_ptr[0]);
7868 if (info->user_ptr[1]) {
7869 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7870 struct wireless_dev *wdev = info->user_ptr[1];
7873 dev_put(wdev->netdev);
7875 dev_put(info->user_ptr[1]);
7878 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7882 static struct genl_ops nl80211_ops[] = {
7884 .cmd = NL80211_CMD_GET_WIPHY,
7885 .doit = nl80211_get_wiphy,
7886 .dumpit = nl80211_dump_wiphy,
7887 .policy = nl80211_policy,
7888 /* can be retrieved by unprivileged users */
7889 .internal_flags = NL80211_FLAG_NEED_WIPHY,
7892 .cmd = NL80211_CMD_SET_WIPHY,
7893 .doit = nl80211_set_wiphy,
7894 .policy = nl80211_policy,
7895 .flags = GENL_ADMIN_PERM,
7896 .internal_flags = NL80211_FLAG_NEED_RTNL,
7899 .cmd = NL80211_CMD_GET_INTERFACE,
7900 .doit = nl80211_get_interface,
7901 .dumpit = nl80211_dump_interface,
7902 .policy = nl80211_policy,
7903 /* can be retrieved by unprivileged users */
7904 .internal_flags = NL80211_FLAG_NEED_WDEV,
7907 .cmd = NL80211_CMD_SET_INTERFACE,
7908 .doit = nl80211_set_interface,
7909 .policy = nl80211_policy,
7910 .flags = GENL_ADMIN_PERM,
7911 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7912 NL80211_FLAG_NEED_RTNL,
7915 .cmd = NL80211_CMD_NEW_INTERFACE,
7916 .doit = nl80211_new_interface,
7917 .policy = nl80211_policy,
7918 .flags = GENL_ADMIN_PERM,
7919 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7920 NL80211_FLAG_NEED_RTNL,
7923 .cmd = NL80211_CMD_DEL_INTERFACE,
7924 .doit = nl80211_del_interface,
7925 .policy = nl80211_policy,
7926 .flags = GENL_ADMIN_PERM,
7927 .internal_flags = NL80211_FLAG_NEED_WDEV |
7928 NL80211_FLAG_NEED_RTNL,
7931 .cmd = NL80211_CMD_GET_KEY,
7932 .doit = nl80211_get_key,
7933 .policy = nl80211_policy,
7934 .flags = GENL_ADMIN_PERM,
7935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7936 NL80211_FLAG_NEED_RTNL,
7939 .cmd = NL80211_CMD_SET_KEY,
7940 .doit = nl80211_set_key,
7941 .policy = nl80211_policy,
7942 .flags = GENL_ADMIN_PERM,
7943 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7944 NL80211_FLAG_NEED_RTNL,
7947 .cmd = NL80211_CMD_NEW_KEY,
7948 .doit = nl80211_new_key,
7949 .policy = nl80211_policy,
7950 .flags = GENL_ADMIN_PERM,
7951 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7952 NL80211_FLAG_NEED_RTNL,
7955 .cmd = NL80211_CMD_DEL_KEY,
7956 .doit = nl80211_del_key,
7957 .policy = nl80211_policy,
7958 .flags = GENL_ADMIN_PERM,
7959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7960 NL80211_FLAG_NEED_RTNL,
7963 .cmd = NL80211_CMD_SET_BEACON,
7964 .policy = nl80211_policy,
7965 .flags = GENL_ADMIN_PERM,
7966 .doit = nl80211_set_beacon,
7967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7968 NL80211_FLAG_NEED_RTNL,
7971 .cmd = NL80211_CMD_START_AP,
7972 .policy = nl80211_policy,
7973 .flags = GENL_ADMIN_PERM,
7974 .doit = nl80211_start_ap,
7975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7976 NL80211_FLAG_NEED_RTNL,
7979 .cmd = NL80211_CMD_STOP_AP,
7980 .policy = nl80211_policy,
7981 .flags = GENL_ADMIN_PERM,
7982 .doit = nl80211_stop_ap,
7983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7984 NL80211_FLAG_NEED_RTNL,
7987 .cmd = NL80211_CMD_GET_STATION,
7988 .doit = nl80211_get_station,
7989 .dumpit = nl80211_dump_station,
7990 .policy = nl80211_policy,
7991 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7992 NL80211_FLAG_NEED_RTNL,
7995 .cmd = NL80211_CMD_SET_STATION,
7996 .doit = nl80211_set_station,
7997 .policy = nl80211_policy,
7998 .flags = GENL_ADMIN_PERM,
7999 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8000 NL80211_FLAG_NEED_RTNL,
8003 .cmd = NL80211_CMD_NEW_STATION,
8004 .doit = nl80211_new_station,
8005 .policy = nl80211_policy,
8006 .flags = GENL_ADMIN_PERM,
8007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8008 NL80211_FLAG_NEED_RTNL,
8011 .cmd = NL80211_CMD_DEL_STATION,
8012 .doit = nl80211_del_station,
8013 .policy = nl80211_policy,
8014 .flags = GENL_ADMIN_PERM,
8015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8016 NL80211_FLAG_NEED_RTNL,
8019 .cmd = NL80211_CMD_GET_MPATH,
8020 .doit = nl80211_get_mpath,
8021 .dumpit = nl80211_dump_mpath,
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_SET_MPATH,
8029 .doit = nl80211_set_mpath,
8030 .policy = nl80211_policy,
8031 .flags = GENL_ADMIN_PERM,
8032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8033 NL80211_FLAG_NEED_RTNL,
8036 .cmd = NL80211_CMD_NEW_MPATH,
8037 .doit = nl80211_new_mpath,
8038 .policy = nl80211_policy,
8039 .flags = GENL_ADMIN_PERM,
8040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8041 NL80211_FLAG_NEED_RTNL,
8044 .cmd = NL80211_CMD_DEL_MPATH,
8045 .doit = nl80211_del_mpath,
8046 .policy = nl80211_policy,
8047 .flags = GENL_ADMIN_PERM,
8048 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8049 NL80211_FLAG_NEED_RTNL,
8052 .cmd = NL80211_CMD_SET_BSS,
8053 .doit = nl80211_set_bss,
8054 .policy = nl80211_policy,
8055 .flags = GENL_ADMIN_PERM,
8056 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8057 NL80211_FLAG_NEED_RTNL,
8060 .cmd = NL80211_CMD_GET_REG,
8061 .doit = nl80211_get_reg,
8062 .policy = nl80211_policy,
8063 /* can be retrieved by unprivileged users */
8066 .cmd = NL80211_CMD_SET_REG,
8067 .doit = nl80211_set_reg,
8068 .policy = nl80211_policy,
8069 .flags = GENL_ADMIN_PERM,
8072 .cmd = NL80211_CMD_REQ_SET_REG,
8073 .doit = nl80211_req_set_reg,
8074 .policy = nl80211_policy,
8075 .flags = GENL_ADMIN_PERM,
8078 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8079 .doit = nl80211_get_mesh_config,
8080 .policy = nl80211_policy,
8081 /* can be retrieved by unprivileged users */
8082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8083 NL80211_FLAG_NEED_RTNL,
8086 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8087 .doit = nl80211_update_mesh_config,
8088 .policy = nl80211_policy,
8089 .flags = GENL_ADMIN_PERM,
8090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8091 NL80211_FLAG_NEED_RTNL,
8094 .cmd = NL80211_CMD_TRIGGER_SCAN,
8095 .doit = nl80211_trigger_scan,
8096 .policy = nl80211_policy,
8097 .flags = GENL_ADMIN_PERM,
8098 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8099 NL80211_FLAG_NEED_RTNL,
8102 .cmd = NL80211_CMD_GET_SCAN,
8103 .policy = nl80211_policy,
8104 .dumpit = nl80211_dump_scan,
8107 .cmd = NL80211_CMD_START_SCHED_SCAN,
8108 .doit = nl80211_start_sched_scan,
8109 .policy = nl80211_policy,
8110 .flags = GENL_ADMIN_PERM,
8111 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8112 NL80211_FLAG_NEED_RTNL,
8115 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8116 .doit = nl80211_stop_sched_scan,
8117 .policy = nl80211_policy,
8118 .flags = GENL_ADMIN_PERM,
8119 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8120 NL80211_FLAG_NEED_RTNL,
8123 .cmd = NL80211_CMD_AUTHENTICATE,
8124 .doit = nl80211_authenticate,
8125 .policy = nl80211_policy,
8126 .flags = GENL_ADMIN_PERM,
8127 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8128 NL80211_FLAG_NEED_RTNL,
8131 .cmd = NL80211_CMD_ASSOCIATE,
8132 .doit = nl80211_associate,
8133 .policy = nl80211_policy,
8134 .flags = GENL_ADMIN_PERM,
8135 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8136 NL80211_FLAG_NEED_RTNL,
8139 .cmd = NL80211_CMD_DEAUTHENTICATE,
8140 .doit = nl80211_deauthenticate,
8141 .policy = nl80211_policy,
8142 .flags = GENL_ADMIN_PERM,
8143 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8144 NL80211_FLAG_NEED_RTNL,
8147 .cmd = NL80211_CMD_DISASSOCIATE,
8148 .doit = nl80211_disassociate,
8149 .policy = nl80211_policy,
8150 .flags = GENL_ADMIN_PERM,
8151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8152 NL80211_FLAG_NEED_RTNL,
8155 .cmd = NL80211_CMD_JOIN_IBSS,
8156 .doit = nl80211_join_ibss,
8157 .policy = nl80211_policy,
8158 .flags = GENL_ADMIN_PERM,
8159 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8160 NL80211_FLAG_NEED_RTNL,
8163 .cmd = NL80211_CMD_LEAVE_IBSS,
8164 .doit = nl80211_leave_ibss,
8165 .policy = nl80211_policy,
8166 .flags = GENL_ADMIN_PERM,
8167 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8168 NL80211_FLAG_NEED_RTNL,
8170 #ifdef CONFIG_NL80211_TESTMODE
8172 .cmd = NL80211_CMD_TESTMODE,
8173 .doit = nl80211_testmode_do,
8174 .dumpit = nl80211_testmode_dump,
8175 .policy = nl80211_policy,
8176 .flags = GENL_ADMIN_PERM,
8177 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8178 NL80211_FLAG_NEED_RTNL,
8182 .cmd = NL80211_CMD_CONNECT,
8183 .doit = nl80211_connect,
8184 .policy = nl80211_policy,
8185 .flags = GENL_ADMIN_PERM,
8186 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8187 NL80211_FLAG_NEED_RTNL,
8190 .cmd = NL80211_CMD_DISCONNECT,
8191 .doit = nl80211_disconnect,
8192 .policy = nl80211_policy,
8193 .flags = GENL_ADMIN_PERM,
8194 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8195 NL80211_FLAG_NEED_RTNL,
8198 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8199 .doit = nl80211_wiphy_netns,
8200 .policy = nl80211_policy,
8201 .flags = GENL_ADMIN_PERM,
8202 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8203 NL80211_FLAG_NEED_RTNL,
8206 .cmd = NL80211_CMD_GET_SURVEY,
8207 .policy = nl80211_policy,
8208 .dumpit = nl80211_dump_survey,
8211 .cmd = NL80211_CMD_SET_PMKSA,
8212 .doit = nl80211_setdel_pmksa,
8213 .policy = nl80211_policy,
8214 .flags = GENL_ADMIN_PERM,
8215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8216 NL80211_FLAG_NEED_RTNL,
8219 .cmd = NL80211_CMD_DEL_PMKSA,
8220 .doit = nl80211_setdel_pmksa,
8221 .policy = nl80211_policy,
8222 .flags = GENL_ADMIN_PERM,
8223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8224 NL80211_FLAG_NEED_RTNL,
8227 .cmd = NL80211_CMD_FLUSH_PMKSA,
8228 .doit = nl80211_flush_pmksa,
8229 .policy = nl80211_policy,
8230 .flags = GENL_ADMIN_PERM,
8231 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8232 NL80211_FLAG_NEED_RTNL,
8235 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8236 .doit = nl80211_remain_on_channel,
8237 .policy = nl80211_policy,
8238 .flags = GENL_ADMIN_PERM,
8239 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8240 NL80211_FLAG_NEED_RTNL,
8243 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8244 .doit = nl80211_cancel_remain_on_channel,
8245 .policy = nl80211_policy,
8246 .flags = GENL_ADMIN_PERM,
8247 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8248 NL80211_FLAG_NEED_RTNL,
8251 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8252 .doit = nl80211_set_tx_bitrate_mask,
8253 .policy = nl80211_policy,
8254 .flags = GENL_ADMIN_PERM,
8255 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8256 NL80211_FLAG_NEED_RTNL,
8259 .cmd = NL80211_CMD_REGISTER_FRAME,
8260 .doit = nl80211_register_mgmt,
8261 .policy = nl80211_policy,
8262 .flags = GENL_ADMIN_PERM,
8263 .internal_flags = NL80211_FLAG_NEED_WDEV |
8264 NL80211_FLAG_NEED_RTNL,
8267 .cmd = NL80211_CMD_FRAME,
8268 .doit = nl80211_tx_mgmt,
8269 .policy = nl80211_policy,
8270 .flags = GENL_ADMIN_PERM,
8271 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8272 NL80211_FLAG_NEED_RTNL,
8275 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8276 .doit = nl80211_tx_mgmt_cancel_wait,
8277 .policy = nl80211_policy,
8278 .flags = GENL_ADMIN_PERM,
8279 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8280 NL80211_FLAG_NEED_RTNL,
8283 .cmd = NL80211_CMD_SET_POWER_SAVE,
8284 .doit = nl80211_set_power_save,
8285 .policy = nl80211_policy,
8286 .flags = GENL_ADMIN_PERM,
8287 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8288 NL80211_FLAG_NEED_RTNL,
8291 .cmd = NL80211_CMD_GET_POWER_SAVE,
8292 .doit = nl80211_get_power_save,
8293 .policy = nl80211_policy,
8294 /* can be retrieved by unprivileged users */
8295 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8296 NL80211_FLAG_NEED_RTNL,
8299 .cmd = NL80211_CMD_SET_CQM,
8300 .doit = nl80211_set_cqm,
8301 .policy = nl80211_policy,
8302 .flags = GENL_ADMIN_PERM,
8303 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8304 NL80211_FLAG_NEED_RTNL,
8307 .cmd = NL80211_CMD_SET_CHANNEL,
8308 .doit = nl80211_set_channel,
8309 .policy = nl80211_policy,
8310 .flags = GENL_ADMIN_PERM,
8311 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8312 NL80211_FLAG_NEED_RTNL,
8315 .cmd = NL80211_CMD_SET_WDS_PEER,
8316 .doit = nl80211_set_wds_peer,
8317 .policy = nl80211_policy,
8318 .flags = GENL_ADMIN_PERM,
8319 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8320 NL80211_FLAG_NEED_RTNL,
8323 .cmd = NL80211_CMD_JOIN_MESH,
8324 .doit = nl80211_join_mesh,
8325 .policy = nl80211_policy,
8326 .flags = GENL_ADMIN_PERM,
8327 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8328 NL80211_FLAG_NEED_RTNL,
8331 .cmd = NL80211_CMD_LEAVE_MESH,
8332 .doit = nl80211_leave_mesh,
8333 .policy = nl80211_policy,
8334 .flags = GENL_ADMIN_PERM,
8335 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8336 NL80211_FLAG_NEED_RTNL,
8340 .cmd = NL80211_CMD_GET_WOWLAN,
8341 .doit = nl80211_get_wowlan,
8342 .policy = nl80211_policy,
8343 /* can be retrieved by unprivileged users */
8344 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8345 NL80211_FLAG_NEED_RTNL,
8348 .cmd = NL80211_CMD_SET_WOWLAN,
8349 .doit = nl80211_set_wowlan,
8350 .policy = nl80211_policy,
8351 .flags = GENL_ADMIN_PERM,
8352 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8353 NL80211_FLAG_NEED_RTNL,
8357 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8358 .doit = nl80211_set_rekey_data,
8359 .policy = nl80211_policy,
8360 .flags = GENL_ADMIN_PERM,
8361 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8362 NL80211_FLAG_NEED_RTNL,
8365 .cmd = NL80211_CMD_TDLS_MGMT,
8366 .doit = nl80211_tdls_mgmt,
8367 .policy = nl80211_policy,
8368 .flags = GENL_ADMIN_PERM,
8369 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8370 NL80211_FLAG_NEED_RTNL,
8373 .cmd = NL80211_CMD_TDLS_OPER,
8374 .doit = nl80211_tdls_oper,
8375 .policy = nl80211_policy,
8376 .flags = GENL_ADMIN_PERM,
8377 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8378 NL80211_FLAG_NEED_RTNL,
8381 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8382 .doit = nl80211_register_unexpected_frame,
8383 .policy = nl80211_policy,
8384 .flags = GENL_ADMIN_PERM,
8385 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8386 NL80211_FLAG_NEED_RTNL,
8389 .cmd = NL80211_CMD_PROBE_CLIENT,
8390 .doit = nl80211_probe_client,
8391 .policy = nl80211_policy,
8392 .flags = GENL_ADMIN_PERM,
8393 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8394 NL80211_FLAG_NEED_RTNL,
8397 .cmd = NL80211_CMD_REGISTER_BEACONS,
8398 .doit = nl80211_register_beacons,
8399 .policy = nl80211_policy,
8400 .flags = GENL_ADMIN_PERM,
8401 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8402 NL80211_FLAG_NEED_RTNL,
8405 .cmd = NL80211_CMD_SET_NOACK_MAP,
8406 .doit = nl80211_set_noack_map,
8407 .policy = nl80211_policy,
8408 .flags = GENL_ADMIN_PERM,
8409 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8410 NL80211_FLAG_NEED_RTNL,
8413 .cmd = NL80211_CMD_START_P2P_DEVICE,
8414 .doit = nl80211_start_p2p_device,
8415 .policy = nl80211_policy,
8416 .flags = GENL_ADMIN_PERM,
8417 .internal_flags = NL80211_FLAG_NEED_WDEV |
8418 NL80211_FLAG_NEED_RTNL,
8421 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8422 .doit = nl80211_stop_p2p_device,
8423 .policy = nl80211_policy,
8424 .flags = GENL_ADMIN_PERM,
8425 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8426 NL80211_FLAG_NEED_RTNL,
8429 .cmd = NL80211_CMD_SET_MCAST_RATE,
8430 .doit = nl80211_set_mcast_rate,
8431 .policy = nl80211_policy,
8432 .flags = GENL_ADMIN_PERM,
8433 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8434 NL80211_FLAG_NEED_RTNL,
8437 .cmd = NL80211_CMD_SET_MAC_ACL,
8438 .doit = nl80211_set_mac_acl,
8439 .policy = nl80211_policy,
8440 .flags = GENL_ADMIN_PERM,
8441 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8442 NL80211_FLAG_NEED_RTNL,
8445 .cmd = NL80211_CMD_RADAR_DETECT,
8446 .doit = nl80211_start_radar_detection,
8447 .policy = nl80211_policy,
8448 .flags = GENL_ADMIN_PERM,
8449 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8450 NL80211_FLAG_NEED_RTNL,
8454 static struct genl_multicast_group nl80211_mlme_mcgrp = {
8458 /* multicast groups */
8459 static struct genl_multicast_group nl80211_config_mcgrp = {
8462 static struct genl_multicast_group nl80211_scan_mcgrp = {
8465 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8466 .name = "regulatory",
8469 /* notification functions */
8471 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8473 struct sk_buff *msg;
8475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8479 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
8484 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8485 nl80211_config_mcgrp.id, GFP_KERNEL);
8488 static int nl80211_add_scan_req(struct sk_buff *msg,
8489 struct cfg80211_registered_device *rdev)
8491 struct cfg80211_scan_request *req = rdev->scan_req;
8492 struct nlattr *nest;
8495 ASSERT_RDEV_LOCK(rdev);
8500 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
8502 goto nla_put_failure;
8503 for (i = 0; i < req->n_ssids; i++) {
8504 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
8505 goto nla_put_failure;
8507 nla_nest_end(msg, nest);
8509 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8511 goto nla_put_failure;
8512 for (i = 0; i < req->n_channels; i++) {
8513 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
8514 goto nla_put_failure;
8516 nla_nest_end(msg, nest);
8519 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
8520 goto nla_put_failure;
8523 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
8530 static int nl80211_send_scan_msg(struct sk_buff *msg,
8531 struct cfg80211_registered_device *rdev,
8532 struct wireless_dev *wdev,
8533 u32 portid, u32 seq, int flags,
8538 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8542 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8543 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8544 wdev->netdev->ifindex)) ||
8545 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
8546 goto nla_put_failure;
8548 /* ignore errors and send incomplete event anyway */
8549 nl80211_add_scan_req(msg, rdev);
8551 return genlmsg_end(msg, hdr);
8554 genlmsg_cancel(msg, hdr);
8559 nl80211_send_sched_scan_msg(struct sk_buff *msg,
8560 struct cfg80211_registered_device *rdev,
8561 struct net_device *netdev,
8562 u32 portid, u32 seq, int flags, u32 cmd)
8566 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
8570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8571 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8572 goto nla_put_failure;
8574 return genlmsg_end(msg, hdr);
8577 genlmsg_cancel(msg, hdr);
8581 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
8582 struct wireless_dev *wdev)
8584 struct sk_buff *msg;
8586 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8590 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8591 NL80211_CMD_TRIGGER_SCAN) < 0) {
8596 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8597 nl80211_scan_mcgrp.id, GFP_KERNEL);
8600 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
8601 struct wireless_dev *wdev)
8603 struct sk_buff *msg;
8605 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8609 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8610 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
8615 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8616 nl80211_scan_mcgrp.id, GFP_KERNEL);
8619 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
8620 struct wireless_dev *wdev)
8622 struct sk_buff *msg;
8624 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8628 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
8629 NL80211_CMD_SCAN_ABORTED) < 0) {
8634 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8635 nl80211_scan_mcgrp.id, GFP_KERNEL);
8638 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
8639 struct net_device *netdev)
8641 struct sk_buff *msg;
8643 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8647 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
8648 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
8653 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8654 nl80211_scan_mcgrp.id, GFP_KERNEL);
8657 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
8658 struct net_device *netdev, u32 cmd)
8660 struct sk_buff *msg;
8662 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8666 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
8671 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8672 nl80211_scan_mcgrp.id, GFP_KERNEL);
8676 * This can happen on global regulatory changes or device specific settings
8677 * based on custom world regulatory domains.
8679 void nl80211_send_reg_change_event(struct regulatory_request *request)
8681 struct sk_buff *msg;
8684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8688 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
8694 /* Userspace can always count this one always being set */
8695 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
8696 goto nla_put_failure;
8698 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
8699 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8700 NL80211_REGDOM_TYPE_WORLD))
8701 goto nla_put_failure;
8702 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
8703 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8704 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
8705 goto nla_put_failure;
8706 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
8707 request->intersect) {
8708 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8709 NL80211_REGDOM_TYPE_INTERSECTION))
8710 goto nla_put_failure;
8712 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
8713 NL80211_REGDOM_TYPE_COUNTRY) ||
8714 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
8716 goto nla_put_failure;
8719 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
8720 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
8721 goto nla_put_failure;
8723 genlmsg_end(msg, hdr);
8726 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8733 genlmsg_cancel(msg, hdr);
8737 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
8738 struct net_device *netdev,
8739 const u8 *buf, size_t len,
8740 enum nl80211_commands cmd, gfp_t gfp)
8742 struct sk_buff *msg;
8745 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8749 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8755 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8756 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8757 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8758 goto nla_put_failure;
8760 genlmsg_end(msg, hdr);
8762 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8763 nl80211_mlme_mcgrp.id, gfp);
8767 genlmsg_cancel(msg, hdr);
8771 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
8772 struct net_device *netdev, const u8 *buf,
8773 size_t len, gfp_t gfp)
8775 nl80211_send_mlme_event(rdev, netdev, buf, len,
8776 NL80211_CMD_AUTHENTICATE, gfp);
8779 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
8780 struct net_device *netdev, const u8 *buf,
8781 size_t len, gfp_t gfp)
8783 nl80211_send_mlme_event(rdev, netdev, buf, len,
8784 NL80211_CMD_ASSOCIATE, gfp);
8787 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
8788 struct net_device *netdev, const u8 *buf,
8789 size_t len, gfp_t gfp)
8791 nl80211_send_mlme_event(rdev, netdev, buf, len,
8792 NL80211_CMD_DEAUTHENTICATE, gfp);
8795 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
8796 struct net_device *netdev, const u8 *buf,
8797 size_t len, gfp_t gfp)
8799 nl80211_send_mlme_event(rdev, netdev, buf, len,
8800 NL80211_CMD_DISASSOCIATE, gfp);
8803 void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
8804 struct net_device *netdev, const u8 *buf,
8805 size_t len, gfp_t gfp)
8807 nl80211_send_mlme_event(rdev, netdev, buf, len,
8808 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
8811 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
8812 struct net_device *netdev, const u8 *buf,
8813 size_t len, gfp_t gfp)
8815 nl80211_send_mlme_event(rdev, netdev, buf, len,
8816 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
8819 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
8820 struct net_device *netdev, int cmd,
8821 const u8 *addr, gfp_t gfp)
8823 struct sk_buff *msg;
8826 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8830 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8836 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8837 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8838 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
8839 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8840 goto nla_put_failure;
8842 genlmsg_end(msg, hdr);
8844 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8845 nl80211_mlme_mcgrp.id, gfp);
8849 genlmsg_cancel(msg, hdr);
8853 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
8854 struct net_device *netdev, const u8 *addr,
8857 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
8861 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
8862 struct net_device *netdev, const u8 *addr,
8865 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
8869 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
8870 struct net_device *netdev, const u8 *bssid,
8871 const u8 *req_ie, size_t req_ie_len,
8872 const u8 *resp_ie, size_t resp_ie_len,
8873 u16 status, gfp_t gfp)
8875 struct sk_buff *msg;
8878 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8882 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
8888 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8889 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8890 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
8891 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
8893 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8895 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8896 goto nla_put_failure;
8898 genlmsg_end(msg, hdr);
8900 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8901 nl80211_mlme_mcgrp.id, gfp);
8905 genlmsg_cancel(msg, hdr);
8910 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8911 struct net_device *netdev, const u8 *bssid,
8912 const u8 *req_ie, size_t req_ie_len,
8913 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8915 struct sk_buff *msg;
8918 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8922 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8928 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8929 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8930 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
8932 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8934 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8935 goto nla_put_failure;
8937 genlmsg_end(msg, hdr);
8939 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8940 nl80211_mlme_mcgrp.id, gfp);
8944 genlmsg_cancel(msg, hdr);
8949 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
8950 struct net_device *netdev, u16 reason,
8951 const u8 *ie, size_t ie_len, bool from_ap)
8953 struct sk_buff *msg;
8956 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8960 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
8966 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8967 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8968 (from_ap && reason &&
8969 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
8971 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
8972 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8973 goto nla_put_failure;
8975 genlmsg_end(msg, hdr);
8977 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8978 nl80211_mlme_mcgrp.id, GFP_KERNEL);
8982 genlmsg_cancel(msg, hdr);
8987 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
8988 struct net_device *netdev, const u8 *bssid,
8991 struct sk_buff *msg;
8994 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8998 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9004 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9005 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9006 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9007 goto nla_put_failure;
9009 genlmsg_end(msg, hdr);
9011 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9012 nl80211_mlme_mcgrp.id, gfp);
9016 genlmsg_cancel(msg, hdr);
9020 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
9021 struct net_device *netdev,
9022 const u8 *macaddr, const u8* ie, u8 ie_len,
9025 struct sk_buff *msg;
9028 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9032 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9038 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9039 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9040 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
9042 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9043 goto nla_put_failure;
9045 genlmsg_end(msg, hdr);
9047 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9048 nl80211_mlme_mcgrp.id, gfp);
9052 genlmsg_cancel(msg, hdr);
9056 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9057 struct net_device *netdev, const u8 *addr,
9058 enum nl80211_key_type key_type, int key_id,
9059 const u8 *tsc, gfp_t gfp)
9061 struct sk_buff *msg;
9064 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9068 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9074 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9075 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9076 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9077 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9079 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9080 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9081 goto nla_put_failure;
9083 genlmsg_end(msg, hdr);
9085 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9086 nl80211_mlme_mcgrp.id, gfp);
9090 genlmsg_cancel(msg, hdr);
9094 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9095 struct ieee80211_channel *channel_before,
9096 struct ieee80211_channel *channel_after)
9098 struct sk_buff *msg;
9100 struct nlattr *nl_freq;
9102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
9106 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9113 * Since we are applying the beacon hint to a wiphy we know its
9114 * wiphy_idx is valid
9116 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9117 goto nla_put_failure;
9120 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9122 goto nla_put_failure;
9123 if (nl80211_msg_put_channel(msg, channel_before))
9124 goto nla_put_failure;
9125 nla_nest_end(msg, nl_freq);
9128 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9130 goto nla_put_failure;
9131 if (nl80211_msg_put_channel(msg, channel_after))
9132 goto nla_put_failure;
9133 nla_nest_end(msg, nl_freq);
9135 genlmsg_end(msg, hdr);
9138 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9145 genlmsg_cancel(msg, hdr);
9149 static void nl80211_send_remain_on_chan_event(
9150 int cmd, struct cfg80211_registered_device *rdev,
9151 struct wireless_dev *wdev, u64 cookie,
9152 struct ieee80211_channel *chan,
9153 unsigned int duration, gfp_t gfp)
9155 struct sk_buff *msg;
9158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9162 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9169 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9170 wdev->netdev->ifindex)) ||
9171 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
9172 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
9173 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9174 NL80211_CHAN_NO_HT) ||
9175 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9176 goto nla_put_failure;
9178 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9179 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9180 goto nla_put_failure;
9182 genlmsg_end(msg, hdr);
9184 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9185 nl80211_mlme_mcgrp.id, gfp);
9189 genlmsg_cancel(msg, hdr);
9193 void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
9194 struct wireless_dev *wdev, u64 cookie,
9195 struct ieee80211_channel *chan,
9196 unsigned int duration, gfp_t gfp)
9198 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
9199 rdev, wdev, cookie, chan,
9203 void nl80211_send_remain_on_channel_cancel(
9204 struct cfg80211_registered_device *rdev,
9205 struct wireless_dev *wdev,
9206 u64 cookie, struct ieee80211_channel *chan, gfp_t gfp)
9208 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9209 rdev, wdev, cookie, chan, 0, gfp);
9212 void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
9213 struct net_device *dev, const u8 *mac_addr,
9214 struct station_info *sinfo, gfp_t gfp)
9216 struct sk_buff *msg;
9218 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9222 if (nl80211_send_station(msg, 0, 0, 0,
9223 rdev, dev, mac_addr, sinfo) < 0) {
9228 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9229 nl80211_mlme_mcgrp.id, gfp);
9232 void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
9233 struct net_device *dev, const u8 *mac_addr,
9236 struct sk_buff *msg;
9239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9249 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9250 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9251 goto nla_put_failure;
9253 genlmsg_end(msg, hdr);
9255 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9256 nl80211_mlme_mcgrp.id, gfp);
9260 genlmsg_cancel(msg, hdr);
9264 void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
9265 struct net_device *dev, const u8 *mac_addr,
9266 enum nl80211_connect_failed_reason reason,
9269 struct sk_buff *msg;
9272 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9276 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9282 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9283 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9284 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9285 goto nla_put_failure;
9287 genlmsg_end(msg, hdr);
9289 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9290 nl80211_mlme_mcgrp.id, gfp);
9294 genlmsg_cancel(msg, hdr);
9298 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9299 const u8 *addr, gfp_t gfp)
9301 struct wireless_dev *wdev = dev->ieee80211_ptr;
9302 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9303 struct sk_buff *msg;
9306 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
9311 msg = nlmsg_new(100, gfp);
9315 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9322 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9323 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9324 goto nla_put_failure;
9326 err = genlmsg_end(msg, hdr);
9332 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9336 genlmsg_cancel(msg, hdr);
9341 bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
9343 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9347 bool nl80211_unexpected_4addr_frame(struct net_device *dev,
9348 const u8 *addr, gfp_t gfp)
9350 return __nl80211_unexpected_frame(dev,
9351 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9355 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
9356 struct wireless_dev *wdev, u32 nlportid,
9357 int freq, int sig_dbm,
9358 const u8 *buf, size_t len, gfp_t gfp)
9360 struct net_device *netdev = wdev->netdev;
9361 struct sk_buff *msg;
9364 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9368 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9374 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9375 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9376 netdev->ifindex)) ||
9377 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9379 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9380 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9381 goto nla_put_failure;
9383 genlmsg_end(msg, hdr);
9385 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
9388 genlmsg_cancel(msg, hdr);
9393 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
9394 struct wireless_dev *wdev, u64 cookie,
9395 const u8 *buf, size_t len, bool ack,
9398 struct net_device *netdev = wdev->netdev;
9399 struct sk_buff *msg;
9402 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9406 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
9412 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9413 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9414 netdev->ifindex)) ||
9415 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9416 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9417 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9418 goto nla_put_failure;
9420 genlmsg_end(msg, hdr);
9422 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9426 genlmsg_cancel(msg, hdr);
9431 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
9432 struct net_device *netdev,
9433 enum nl80211_cqm_rssi_threshold_event rssi_event,
9436 struct sk_buff *msg;
9437 struct nlattr *pinfoattr;
9440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9451 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9452 goto nla_put_failure;
9454 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9456 goto nla_put_failure;
9458 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
9460 goto nla_put_failure;
9462 nla_nest_end(msg, pinfoattr);
9464 genlmsg_end(msg, hdr);
9466 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9467 nl80211_mlme_mcgrp.id, gfp);
9471 genlmsg_cancel(msg, hdr);
9475 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
9476 struct net_device *netdev, const u8 *bssid,
9477 const u8 *replay_ctr, gfp_t gfp)
9479 struct sk_buff *msg;
9480 struct nlattr *rekey_attr;
9483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9487 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
9493 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9494 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9495 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9496 goto nla_put_failure;
9498 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
9500 goto nla_put_failure;
9502 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
9503 NL80211_REPLAY_CTR_LEN, replay_ctr))
9504 goto nla_put_failure;
9506 nla_nest_end(msg, rekey_attr);
9508 genlmsg_end(msg, hdr);
9510 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9511 nl80211_mlme_mcgrp.id, gfp);
9515 genlmsg_cancel(msg, hdr);
9519 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
9520 struct net_device *netdev, int index,
9521 const u8 *bssid, bool preauth, gfp_t gfp)
9523 struct sk_buff *msg;
9524 struct nlattr *attr;
9527 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9531 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
9537 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9538 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9539 goto nla_put_failure;
9541 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
9543 goto nla_put_failure;
9545 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
9546 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
9548 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
9549 goto nla_put_failure;
9551 nla_nest_end(msg, attr);
9553 genlmsg_end(msg, hdr);
9555 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9556 nl80211_mlme_mcgrp.id, gfp);
9560 genlmsg_cancel(msg, hdr);
9564 void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
9565 struct net_device *netdev,
9566 struct cfg80211_chan_def *chandef, gfp_t gfp)
9568 struct sk_buff *msg;
9571 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9575 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
9581 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9582 goto nla_put_failure;
9584 if (nl80211_send_chandef(msg, chandef))
9585 goto nla_put_failure;
9587 genlmsg_end(msg, hdr);
9589 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9590 nl80211_mlme_mcgrp.id, gfp);
9594 genlmsg_cancel(msg, hdr);
9599 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
9600 struct net_device *netdev, const u8 *peer,
9601 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
9603 struct sk_buff *msg;
9604 struct nlattr *pinfoattr;
9607 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9617 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9618 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9619 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9620 goto nla_put_failure;
9622 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9624 goto nla_put_failure;
9626 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
9627 goto nla_put_failure;
9629 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
9630 goto nla_put_failure;
9632 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
9633 goto nla_put_failure;
9635 nla_nest_end(msg, pinfoattr);
9637 genlmsg_end(msg, hdr);
9639 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9640 nl80211_mlme_mcgrp.id, gfp);
9644 genlmsg_cancel(msg, hdr);
9649 nl80211_radar_notify(struct cfg80211_registered_device *rdev,
9650 struct cfg80211_chan_def *chandef,
9651 enum nl80211_radar_event event,
9652 struct net_device *netdev, gfp_t gfp)
9654 struct sk_buff *msg;
9657 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9661 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
9667 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9668 goto nla_put_failure;
9670 /* NOP and radar events don't need a netdev parameter */
9672 struct wireless_dev *wdev = netdev->ieee80211_ptr;
9674 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9675 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9676 goto nla_put_failure;
9679 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
9680 goto nla_put_failure;
9682 if (nl80211_send_chandef(msg, chandef))
9683 goto nla_put_failure;
9685 if (genlmsg_end(msg, hdr) < 0) {
9690 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9691 nl80211_mlme_mcgrp.id, gfp);
9695 genlmsg_cancel(msg, hdr);
9700 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
9701 struct net_device *netdev, const u8 *peer,
9702 u32 num_packets, gfp_t gfp)
9704 struct sk_buff *msg;
9705 struct nlattr *pinfoattr;
9708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9712 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
9718 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9719 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9720 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
9721 goto nla_put_failure;
9723 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
9725 goto nla_put_failure;
9727 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
9728 goto nla_put_failure;
9730 nla_nest_end(msg, pinfoattr);
9732 genlmsg_end(msg, hdr);
9734 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9735 nl80211_mlme_mcgrp.id, gfp);
9739 genlmsg_cancel(msg, hdr);
9743 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
9744 u64 cookie, bool acked, gfp_t gfp)
9746 struct wireless_dev *wdev = dev->ieee80211_ptr;
9747 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9748 struct sk_buff *msg;
9752 trace_cfg80211_probe_status(dev, addr, cookie, acked);
9754 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9759 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
9765 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9766 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9767 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9768 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9769 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
9770 goto nla_put_failure;
9772 err = genlmsg_end(msg, hdr);
9778 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9779 nl80211_mlme_mcgrp.id, gfp);
9783 genlmsg_cancel(msg, hdr);
9786 EXPORT_SYMBOL(cfg80211_probe_status);
9788 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
9789 const u8 *frame, size_t len,
9790 int freq, int sig_dbm)
9792 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9793 struct sk_buff *msg;
9795 struct cfg80211_beacon_registration *reg;
9797 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
9799 spin_lock_bh(&rdev->beacon_registrations_lock);
9800 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9801 msg = nlmsg_new(len + 100, GFP_ATOMIC);
9803 spin_unlock_bh(&rdev->beacon_registrations_lock);
9807 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
9809 goto nla_put_failure;
9811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9813 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9815 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9816 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
9817 goto nla_put_failure;
9819 genlmsg_end(msg, hdr);
9821 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
9823 spin_unlock_bh(&rdev->beacon_registrations_lock);
9827 spin_unlock_bh(&rdev->beacon_registrations_lock);
9829 genlmsg_cancel(msg, hdr);
9832 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
9835 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
9836 struct cfg80211_wowlan_wakeup *wakeup,
9839 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9840 struct sk_buff *msg;
9842 int err, size = 200;
9844 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
9847 size += wakeup->packet_present_len;
9849 msg = nlmsg_new(size, gfp);
9853 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
9857 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9858 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
9861 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9862 wdev->netdev->ifindex))
9866 struct nlattr *reasons;
9868 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9870 if (wakeup->disconnect &&
9871 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
9873 if (wakeup->magic_pkt &&
9874 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
9876 if (wakeup->gtk_rekey_failure &&
9877 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
9879 if (wakeup->eap_identity_req &&
9880 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
9882 if (wakeup->four_way_handshake &&
9883 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
9885 if (wakeup->rfkill_release &&
9886 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
9889 if (wakeup->pattern_idx >= 0 &&
9890 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
9891 wakeup->pattern_idx))
9894 if (wakeup->tcp_match)
9895 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
9897 if (wakeup->tcp_connlost)
9899 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
9901 if (wakeup->tcp_nomoretokens)
9903 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
9905 if (wakeup->packet) {
9906 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
9907 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
9909 if (!wakeup->packet_80211) {
9911 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
9913 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
9916 if (wakeup->packet_len &&
9917 nla_put_u32(msg, len_attr, wakeup->packet_len))
9920 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
9925 nla_nest_end(msg, reasons);
9928 err = genlmsg_end(msg, hdr);
9932 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9933 nl80211_mlme_mcgrp.id, gfp);
9939 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
9942 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
9943 enum nl80211_tdls_operation oper,
9944 u16 reason_code, gfp_t gfp)
9946 struct wireless_dev *wdev = dev->ieee80211_ptr;
9947 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9948 struct sk_buff *msg;
9952 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
9955 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9959 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
9965 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9966 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9967 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
9968 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
9970 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
9971 goto nla_put_failure;
9973 err = genlmsg_end(msg, hdr);
9979 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9980 nl80211_mlme_mcgrp.id, gfp);
9984 genlmsg_cancel(msg, hdr);
9987 EXPORT_SYMBOL(cfg80211_tdls_oper_request);
9989 static int nl80211_netlink_notify(struct notifier_block * nb,
9990 unsigned long state,
9993 struct netlink_notify *notify = _notify;
9994 struct cfg80211_registered_device *rdev;
9995 struct wireless_dev *wdev;
9996 struct cfg80211_beacon_registration *reg, *tmp;
9998 if (state != NETLINK_URELEASE)
10003 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
10004 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
10005 cfg80211_mlme_unregister_socket(wdev, notify->portid);
10007 spin_lock_bh(&rdev->beacon_registrations_lock);
10008 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10010 if (reg->nlportid == notify->portid) {
10011 list_del(®->list);
10016 spin_unlock_bh(&rdev->beacon_registrations_lock);
10021 return NOTIFY_DONE;
10024 static struct notifier_block nl80211_netlink_notifier = {
10025 .notifier_call = nl80211_netlink_notify,
10028 /* initialisation/exit functions */
10030 int nl80211_init(void)
10034 err = genl_register_family_with_ops(&nl80211_fam,
10035 nl80211_ops, ARRAY_SIZE(nl80211_ops));
10039 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10043 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10047 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10051 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10055 #ifdef CONFIG_NL80211_TESTMODE
10056 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10061 err = netlink_register_notifier(&nl80211_netlink_notifier);
10067 genl_unregister_family(&nl80211_fam);
10071 void nl80211_exit(void)
10073 netlink_unregister_notifier(&nl80211_netlink_notifier);
10074 genl_unregister_family(&nl80211_fam);