perf bpf: Move perf_event_output() from stdio.h to bpf.h
[linux/fpc-iii.git] / net / mac80211 / cfg.c
blob818aa006034950785768d80a3f5ba8ad5f2f7f0f
1 /*
2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2015 Intel Mobile Communications GmbH
6 * Copyright (C) 2015-2017 Intel Deutschland GmbH
7 * Copyright (C) 2018 Intel Corporation
9 * This file is GPLv2 as found in COPYING.
12 #include <linux/ieee80211.h>
13 #include <linux/nl80211.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/slab.h>
16 #include <net/net_namespace.h>
17 #include <linux/rcupdate.h>
18 #include <linux/if_ether.h>
19 #include <net/cfg80211.h>
20 #include "ieee80211_i.h"
21 #include "driver-ops.h"
22 #include "rate.h"
23 #include "mesh.h"
24 #include "wme.h"
26 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
27 struct vif_params *params)
29 bool mu_mimo_groups = false;
30 bool mu_mimo_follow = false;
32 if (params->vht_mumimo_groups) {
33 u64 membership;
35 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
37 memcpy(sdata->vif.bss_conf.mu_group.membership,
38 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
39 memcpy(sdata->vif.bss_conf.mu_group.position,
40 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
41 WLAN_USER_POSITION_LEN);
42 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
43 /* don't care about endianness - just check for 0 */
44 memcpy(&membership, params->vht_mumimo_groups,
45 WLAN_MEMBERSHIP_LEN);
46 mu_mimo_groups = membership != 0;
49 if (params->vht_mumimo_follow_addr) {
50 mu_mimo_follow =
51 is_valid_ether_addr(params->vht_mumimo_follow_addr);
52 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
53 params->vht_mumimo_follow_addr);
56 sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
59 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
60 struct vif_params *params)
62 struct ieee80211_local *local = sdata->local;
63 struct ieee80211_sub_if_data *monitor_sdata;
65 /* check flags first */
66 if (params->flags && ieee80211_sdata_running(sdata)) {
67 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
70 * Prohibit MONITOR_FLAG_COOK_FRAMES and
71 * MONITOR_FLAG_ACTIVE to be changed while the
72 * interface is up.
73 * Else we would need to add a lot of cruft
74 * to update everything:
75 * cooked_mntrs, monitor and all fif_* counters
76 * reconfigure hardware
78 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
79 return -EBUSY;
82 /* also validate MU-MIMO change */
83 monitor_sdata = rtnl_dereference(local->monitor_sdata);
85 if (!monitor_sdata &&
86 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
87 return -EOPNOTSUPP;
89 /* apply all changes now - no failures allowed */
91 if (monitor_sdata)
92 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
94 if (params->flags) {
95 if (ieee80211_sdata_running(sdata)) {
96 ieee80211_adjust_monitor_flags(sdata, -1);
97 sdata->u.mntr.flags = params->flags;
98 ieee80211_adjust_monitor_flags(sdata, 1);
100 ieee80211_configure_filter(local);
101 } else {
103 * Because the interface is down, ieee80211_do_stop
104 * and ieee80211_do_open take care of "everything"
105 * mentioned in the comment above.
107 sdata->u.mntr.flags = params->flags;
111 return 0;
114 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
115 const char *name,
116 unsigned char name_assign_type,
117 enum nl80211_iftype type,
118 struct vif_params *params)
120 struct ieee80211_local *local = wiphy_priv(wiphy);
121 struct wireless_dev *wdev;
122 struct ieee80211_sub_if_data *sdata;
123 int err;
125 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
126 if (err)
127 return ERR_PTR(err);
129 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
131 if (type == NL80211_IFTYPE_MONITOR) {
132 err = ieee80211_set_mon_options(sdata, params);
133 if (err) {
134 ieee80211_if_remove(sdata);
135 return NULL;
139 return wdev;
142 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
144 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
146 return 0;
149 static int ieee80211_change_iface(struct wiphy *wiphy,
150 struct net_device *dev,
151 enum nl80211_iftype type,
152 struct vif_params *params)
154 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
155 int ret;
157 ret = ieee80211_if_change_type(sdata, type);
158 if (ret)
159 return ret;
161 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
162 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
163 ieee80211_check_fast_rx_iface(sdata);
164 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
165 sdata->u.mgd.use_4addr = params->use_4addr;
168 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
169 ret = ieee80211_set_mon_options(sdata, params);
170 if (ret)
171 return ret;
174 return 0;
177 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
178 struct wireless_dev *wdev)
180 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
181 int ret;
183 mutex_lock(&sdata->local->chanctx_mtx);
184 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
185 mutex_unlock(&sdata->local->chanctx_mtx);
186 if (ret < 0)
187 return ret;
189 return ieee80211_do_open(wdev, true);
192 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
193 struct wireless_dev *wdev)
195 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
198 static int ieee80211_start_nan(struct wiphy *wiphy,
199 struct wireless_dev *wdev,
200 struct cfg80211_nan_conf *conf)
202 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
203 int ret;
205 mutex_lock(&sdata->local->chanctx_mtx);
206 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
207 mutex_unlock(&sdata->local->chanctx_mtx);
208 if (ret < 0)
209 return ret;
211 ret = ieee80211_do_open(wdev, true);
212 if (ret)
213 return ret;
215 ret = drv_start_nan(sdata->local, sdata, conf);
216 if (ret)
217 ieee80211_sdata_stop(sdata);
219 sdata->u.nan.conf = *conf;
221 return ret;
224 static void ieee80211_stop_nan(struct wiphy *wiphy,
225 struct wireless_dev *wdev)
227 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
229 drv_stop_nan(sdata->local, sdata);
230 ieee80211_sdata_stop(sdata);
233 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
234 struct wireless_dev *wdev,
235 struct cfg80211_nan_conf *conf,
236 u32 changes)
238 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
239 struct cfg80211_nan_conf new_conf;
240 int ret = 0;
242 if (sdata->vif.type != NL80211_IFTYPE_NAN)
243 return -EOPNOTSUPP;
245 if (!ieee80211_sdata_running(sdata))
246 return -ENETDOWN;
248 new_conf = sdata->u.nan.conf;
250 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
251 new_conf.master_pref = conf->master_pref;
253 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
254 new_conf.bands = conf->bands;
256 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
257 if (!ret)
258 sdata->u.nan.conf = new_conf;
260 return ret;
263 static int ieee80211_add_nan_func(struct wiphy *wiphy,
264 struct wireless_dev *wdev,
265 struct cfg80211_nan_func *nan_func)
267 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
268 int ret;
270 if (sdata->vif.type != NL80211_IFTYPE_NAN)
271 return -EOPNOTSUPP;
273 if (!ieee80211_sdata_running(sdata))
274 return -ENETDOWN;
276 spin_lock_bh(&sdata->u.nan.func_lock);
278 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
279 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
280 GFP_ATOMIC);
281 spin_unlock_bh(&sdata->u.nan.func_lock);
283 if (ret < 0)
284 return ret;
286 nan_func->instance_id = ret;
288 WARN_ON(nan_func->instance_id == 0);
290 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
291 if (ret) {
292 spin_lock_bh(&sdata->u.nan.func_lock);
293 idr_remove(&sdata->u.nan.function_inst_ids,
294 nan_func->instance_id);
295 spin_unlock_bh(&sdata->u.nan.func_lock);
298 return ret;
301 static struct cfg80211_nan_func *
302 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
303 u64 cookie)
305 struct cfg80211_nan_func *func;
306 int id;
308 lockdep_assert_held(&sdata->u.nan.func_lock);
310 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
311 if (func->cookie == cookie)
312 return func;
315 return NULL;
318 static void ieee80211_del_nan_func(struct wiphy *wiphy,
319 struct wireless_dev *wdev, u64 cookie)
321 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
322 struct cfg80211_nan_func *func;
323 u8 instance_id = 0;
325 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
326 !ieee80211_sdata_running(sdata))
327 return;
329 spin_lock_bh(&sdata->u.nan.func_lock);
331 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
332 if (func)
333 instance_id = func->instance_id;
335 spin_unlock_bh(&sdata->u.nan.func_lock);
337 if (instance_id)
338 drv_del_nan_func(sdata->local, sdata, instance_id);
341 static int ieee80211_set_noack_map(struct wiphy *wiphy,
342 struct net_device *dev,
343 u16 noack_map)
345 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
347 sdata->noack_map = noack_map;
349 ieee80211_check_fast_xmit_iface(sdata);
351 return 0;
354 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
355 u8 key_idx, bool pairwise, const u8 *mac_addr,
356 struct key_params *params)
358 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
359 struct ieee80211_local *local = sdata->local;
360 struct sta_info *sta = NULL;
361 const struct ieee80211_cipher_scheme *cs = NULL;
362 struct ieee80211_key *key;
363 int err;
365 if (!ieee80211_sdata_running(sdata))
366 return -ENETDOWN;
368 /* reject WEP and TKIP keys if WEP failed to initialize */
369 switch (params->cipher) {
370 case WLAN_CIPHER_SUITE_WEP40:
371 case WLAN_CIPHER_SUITE_TKIP:
372 case WLAN_CIPHER_SUITE_WEP104:
373 if (IS_ERR(local->wep_tx_tfm))
374 return -EINVAL;
375 break;
376 case WLAN_CIPHER_SUITE_CCMP:
377 case WLAN_CIPHER_SUITE_CCMP_256:
378 case WLAN_CIPHER_SUITE_AES_CMAC:
379 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
380 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
381 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
382 case WLAN_CIPHER_SUITE_GCMP:
383 case WLAN_CIPHER_SUITE_GCMP_256:
384 break;
385 default:
386 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
387 break;
390 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
391 params->key, params->seq_len, params->seq,
392 cs);
393 if (IS_ERR(key))
394 return PTR_ERR(key);
396 if (pairwise)
397 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
399 mutex_lock(&local->sta_mtx);
401 if (mac_addr) {
402 sta = sta_info_get_bss(sdata, mac_addr);
404 * The ASSOC test makes sure the driver is ready to
405 * receive the key. When wpa_supplicant has roamed
406 * using FT, it attempts to set the key before
407 * association has completed, this rejects that attempt
408 * so it will set the key again after association.
410 * TODO: accept the key if we have a station entry and
411 * add it to the device after the station.
413 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
414 ieee80211_key_free_unused(key);
415 err = -ENOENT;
416 goto out_unlock;
420 switch (sdata->vif.type) {
421 case NL80211_IFTYPE_STATION:
422 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
423 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
424 break;
425 case NL80211_IFTYPE_AP:
426 case NL80211_IFTYPE_AP_VLAN:
427 /* Keys without a station are used for TX only */
428 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
429 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
430 break;
431 case NL80211_IFTYPE_ADHOC:
432 /* no MFP (yet) */
433 break;
434 case NL80211_IFTYPE_MESH_POINT:
435 #ifdef CONFIG_MAC80211_MESH
436 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
437 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
438 break;
439 #endif
440 case NL80211_IFTYPE_WDS:
441 case NL80211_IFTYPE_MONITOR:
442 case NL80211_IFTYPE_P2P_DEVICE:
443 case NL80211_IFTYPE_NAN:
444 case NL80211_IFTYPE_UNSPECIFIED:
445 case NUM_NL80211_IFTYPES:
446 case NL80211_IFTYPE_P2P_CLIENT:
447 case NL80211_IFTYPE_P2P_GO:
448 case NL80211_IFTYPE_OCB:
449 /* shouldn't happen */
450 WARN_ON_ONCE(1);
451 break;
454 if (sta)
455 sta->cipher_scheme = cs;
457 err = ieee80211_key_link(key, sdata, sta);
459 out_unlock:
460 mutex_unlock(&local->sta_mtx);
462 return err;
465 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
466 u8 key_idx, bool pairwise, const u8 *mac_addr)
468 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
469 struct ieee80211_local *local = sdata->local;
470 struct sta_info *sta;
471 struct ieee80211_key *key = NULL;
472 int ret;
474 mutex_lock(&local->sta_mtx);
475 mutex_lock(&local->key_mtx);
477 if (mac_addr) {
478 ret = -ENOENT;
480 sta = sta_info_get_bss(sdata, mac_addr);
481 if (!sta)
482 goto out_unlock;
484 if (pairwise)
485 key = key_mtx_dereference(local, sta->ptk[key_idx]);
486 else
487 key = key_mtx_dereference(local, sta->gtk[key_idx]);
488 } else
489 key = key_mtx_dereference(local, sdata->keys[key_idx]);
491 if (!key) {
492 ret = -ENOENT;
493 goto out_unlock;
496 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
498 ret = 0;
499 out_unlock:
500 mutex_unlock(&local->key_mtx);
501 mutex_unlock(&local->sta_mtx);
503 return ret;
506 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
507 u8 key_idx, bool pairwise, const u8 *mac_addr,
508 void *cookie,
509 void (*callback)(void *cookie,
510 struct key_params *params))
512 struct ieee80211_sub_if_data *sdata;
513 struct sta_info *sta = NULL;
514 u8 seq[6] = {0};
515 struct key_params params;
516 struct ieee80211_key *key = NULL;
517 u64 pn64;
518 u32 iv32;
519 u16 iv16;
520 int err = -ENOENT;
521 struct ieee80211_key_seq kseq = {};
523 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
525 rcu_read_lock();
527 if (mac_addr) {
528 sta = sta_info_get_bss(sdata, mac_addr);
529 if (!sta)
530 goto out;
532 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
533 key = rcu_dereference(sta->ptk[key_idx]);
534 else if (!pairwise &&
535 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
536 key = rcu_dereference(sta->gtk[key_idx]);
537 } else
538 key = rcu_dereference(sdata->keys[key_idx]);
540 if (!key)
541 goto out;
543 memset(&params, 0, sizeof(params));
545 params.cipher = key->conf.cipher;
547 switch (key->conf.cipher) {
548 case WLAN_CIPHER_SUITE_TKIP:
549 pn64 = atomic64_read(&key->conf.tx_pn);
550 iv32 = TKIP_PN_TO_IV32(pn64);
551 iv16 = TKIP_PN_TO_IV16(pn64);
553 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
554 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
555 drv_get_key_seq(sdata->local, key, &kseq);
556 iv32 = kseq.tkip.iv32;
557 iv16 = kseq.tkip.iv16;
560 seq[0] = iv16 & 0xff;
561 seq[1] = (iv16 >> 8) & 0xff;
562 seq[2] = iv32 & 0xff;
563 seq[3] = (iv32 >> 8) & 0xff;
564 seq[4] = (iv32 >> 16) & 0xff;
565 seq[5] = (iv32 >> 24) & 0xff;
566 params.seq = seq;
567 params.seq_len = 6;
568 break;
569 case WLAN_CIPHER_SUITE_CCMP:
570 case WLAN_CIPHER_SUITE_CCMP_256:
571 case WLAN_CIPHER_SUITE_AES_CMAC:
572 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
573 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
574 offsetof(typeof(kseq), aes_cmac));
575 /* fall through */
576 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
577 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
578 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
579 offsetof(typeof(kseq), aes_gmac));
580 /* fall through */
581 case WLAN_CIPHER_SUITE_GCMP:
582 case WLAN_CIPHER_SUITE_GCMP_256:
583 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
584 offsetof(typeof(kseq), gcmp));
586 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
587 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
588 drv_get_key_seq(sdata->local, key, &kseq);
589 memcpy(seq, kseq.ccmp.pn, 6);
590 } else {
591 pn64 = atomic64_read(&key->conf.tx_pn);
592 seq[0] = pn64;
593 seq[1] = pn64 >> 8;
594 seq[2] = pn64 >> 16;
595 seq[3] = pn64 >> 24;
596 seq[4] = pn64 >> 32;
597 seq[5] = pn64 >> 40;
599 params.seq = seq;
600 params.seq_len = 6;
601 break;
602 default:
603 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
604 break;
605 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
606 break;
607 drv_get_key_seq(sdata->local, key, &kseq);
608 params.seq = kseq.hw.seq;
609 params.seq_len = kseq.hw.seq_len;
610 break;
613 params.key = key->conf.key;
614 params.key_len = key->conf.keylen;
616 callback(cookie, &params);
617 err = 0;
619 out:
620 rcu_read_unlock();
621 return err;
624 static int ieee80211_config_default_key(struct wiphy *wiphy,
625 struct net_device *dev,
626 u8 key_idx, bool uni,
627 bool multi)
629 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
631 ieee80211_set_default_key(sdata, key_idx, uni, multi);
633 return 0;
636 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
637 struct net_device *dev,
638 u8 key_idx)
640 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
642 ieee80211_set_default_mgmt_key(sdata, key_idx);
644 return 0;
647 void sta_set_rate_info_tx(struct sta_info *sta,
648 const struct ieee80211_tx_rate *rate,
649 struct rate_info *rinfo)
651 rinfo->flags = 0;
652 if (rate->flags & IEEE80211_TX_RC_MCS) {
653 rinfo->flags |= RATE_INFO_FLAGS_MCS;
654 rinfo->mcs = rate->idx;
655 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
656 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
657 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
658 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
659 } else {
660 struct ieee80211_supported_band *sband;
661 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
662 u16 brate;
664 sband = ieee80211_get_sband(sta->sdata);
665 if (sband) {
666 brate = sband->bitrates[rate->idx].bitrate;
667 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
670 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
671 rinfo->bw = RATE_INFO_BW_40;
672 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
673 rinfo->bw = RATE_INFO_BW_80;
674 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
675 rinfo->bw = RATE_INFO_BW_160;
676 else
677 rinfo->bw = RATE_INFO_BW_20;
678 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
679 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
682 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
683 int idx, u8 *mac, struct station_info *sinfo)
685 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
686 struct ieee80211_local *local = sdata->local;
687 struct sta_info *sta;
688 int ret = -ENOENT;
690 mutex_lock(&local->sta_mtx);
692 sta = sta_info_get_by_idx(sdata, idx);
693 if (sta) {
694 ret = 0;
695 memcpy(mac, sta->sta.addr, ETH_ALEN);
696 sta_set_sinfo(sta, sinfo, true);
699 mutex_unlock(&local->sta_mtx);
701 return ret;
704 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
705 int idx, struct survey_info *survey)
707 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
709 return drv_get_survey(local, idx, survey);
712 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
713 const u8 *mac, struct station_info *sinfo)
715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
716 struct ieee80211_local *local = sdata->local;
717 struct sta_info *sta;
718 int ret = -ENOENT;
720 mutex_lock(&local->sta_mtx);
722 sta = sta_info_get_bss(sdata, mac);
723 if (sta) {
724 ret = 0;
725 sta_set_sinfo(sta, sinfo, true);
728 mutex_unlock(&local->sta_mtx);
730 return ret;
733 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
734 struct cfg80211_chan_def *chandef)
736 struct ieee80211_local *local = wiphy_priv(wiphy);
737 struct ieee80211_sub_if_data *sdata;
738 int ret = 0;
740 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
741 return 0;
743 mutex_lock(&local->mtx);
744 if (local->use_chanctx) {
745 sdata = rtnl_dereference(local->monitor_sdata);
746 if (sdata) {
747 ieee80211_vif_release_channel(sdata);
748 ret = ieee80211_vif_use_channel(sdata, chandef,
749 IEEE80211_CHANCTX_EXCLUSIVE);
751 } else if (local->open_count == local->monitors) {
752 local->_oper_chandef = *chandef;
753 ieee80211_hw_config(local, 0);
756 if (ret == 0)
757 local->monitor_chandef = *chandef;
758 mutex_unlock(&local->mtx);
760 return ret;
763 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
764 const u8 *resp, size_t resp_len,
765 const struct ieee80211_csa_settings *csa)
767 struct probe_resp *new, *old;
769 if (!resp || !resp_len)
770 return 1;
772 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
774 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
775 if (!new)
776 return -ENOMEM;
778 new->len = resp_len;
779 memcpy(new->data, resp, resp_len);
781 if (csa)
782 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
783 csa->n_counter_offsets_presp *
784 sizeof(new->csa_counter_offsets[0]));
786 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
787 if (old)
788 kfree_rcu(old, rcu_head);
790 return 0;
793 static int ieee80211_set_ftm_responder_params(
794 struct ieee80211_sub_if_data *sdata,
795 const u8 *lci, size_t lci_len,
796 const u8 *civicloc, size_t civicloc_len)
798 struct ieee80211_ftm_responder_params *new, *old;
799 struct ieee80211_bss_conf *bss_conf;
800 u8 *pos;
801 int len;
803 if ((!lci || !lci_len) && (!civicloc || !civicloc_len))
804 return 1;
806 bss_conf = &sdata->vif.bss_conf;
807 old = bss_conf->ftmr_params;
808 len = lci_len + civicloc_len;
810 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
811 if (!new)
812 return -ENOMEM;
814 pos = (u8 *)(new + 1);
815 if (lci_len) {
816 new->lci_len = lci_len;
817 new->lci = pos;
818 memcpy(pos, lci, lci_len);
819 pos += lci_len;
822 if (civicloc_len) {
823 new->civicloc_len = civicloc_len;
824 new->civicloc = pos;
825 memcpy(pos, civicloc, civicloc_len);
826 pos += civicloc_len;
829 bss_conf->ftmr_params = new;
830 kfree(old);
832 return 0;
835 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
836 struct cfg80211_beacon_data *params,
837 const struct ieee80211_csa_settings *csa)
839 struct beacon_data *new, *old;
840 int new_head_len, new_tail_len;
841 int size, err;
842 u32 changed = BSS_CHANGED_BEACON;
844 old = sdata_dereference(sdata->u.ap.beacon, sdata);
847 /* Need to have a beacon head if we don't have one yet */
848 if (!params->head && !old)
849 return -EINVAL;
851 /* new or old head? */
852 if (params->head)
853 new_head_len = params->head_len;
854 else
855 new_head_len = old->head_len;
857 /* new or old tail? */
858 if (params->tail || !old)
859 /* params->tail_len will be zero for !params->tail */
860 new_tail_len = params->tail_len;
861 else
862 new_tail_len = old->tail_len;
864 size = sizeof(*new) + new_head_len + new_tail_len;
866 new = kzalloc(size, GFP_KERNEL);
867 if (!new)
868 return -ENOMEM;
870 /* start filling the new info now */
873 * pointers go into the block we allocated,
874 * memory is | beacon_data | head | tail |
876 new->head = ((u8 *) new) + sizeof(*new);
877 new->tail = new->head + new_head_len;
878 new->head_len = new_head_len;
879 new->tail_len = new_tail_len;
881 if (csa) {
882 new->csa_current_counter = csa->count;
883 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
884 csa->n_counter_offsets_beacon *
885 sizeof(new->csa_counter_offsets[0]));
888 /* copy in head */
889 if (params->head)
890 memcpy(new->head, params->head, new_head_len);
891 else
892 memcpy(new->head, old->head, new_head_len);
894 /* copy in optional tail */
895 if (params->tail)
896 memcpy(new->tail, params->tail, new_tail_len);
897 else
898 if (old)
899 memcpy(new->tail, old->tail, new_tail_len);
901 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
902 params->probe_resp_len, csa);
903 if (err < 0)
904 return err;
905 if (err == 0)
906 changed |= BSS_CHANGED_AP_PROBE_RESP;
908 if (params->ftm_responder != -1) {
909 sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
910 err = ieee80211_set_ftm_responder_params(sdata,
911 params->lci,
912 params->lci_len,
913 params->civicloc,
914 params->civicloc_len);
916 if (err < 0)
917 return err;
919 changed |= BSS_CHANGED_FTM_RESPONDER;
922 rcu_assign_pointer(sdata->u.ap.beacon, new);
924 if (old)
925 kfree_rcu(old, rcu_head);
927 return changed;
930 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
931 struct cfg80211_ap_settings *params)
933 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
934 struct ieee80211_local *local = sdata->local;
935 struct beacon_data *old;
936 struct ieee80211_sub_if_data *vlan;
937 u32 changed = BSS_CHANGED_BEACON_INT |
938 BSS_CHANGED_BEACON_ENABLED |
939 BSS_CHANGED_BEACON |
940 BSS_CHANGED_SSID |
941 BSS_CHANGED_P2P_PS |
942 BSS_CHANGED_TXPOWER;
943 int err;
945 old = sdata_dereference(sdata->u.ap.beacon, sdata);
946 if (old)
947 return -EALREADY;
949 switch (params->smps_mode) {
950 case NL80211_SMPS_OFF:
951 sdata->smps_mode = IEEE80211_SMPS_OFF;
952 break;
953 case NL80211_SMPS_STATIC:
954 sdata->smps_mode = IEEE80211_SMPS_STATIC;
955 break;
956 case NL80211_SMPS_DYNAMIC:
957 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
958 break;
959 default:
960 return -EINVAL;
962 sdata->u.ap.req_smps = sdata->smps_mode;
964 sdata->needed_rx_chains = sdata->local->rx_chains;
966 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
968 if (params->he_cap)
969 sdata->vif.bss_conf.he_support = true;
971 mutex_lock(&local->mtx);
972 err = ieee80211_vif_use_channel(sdata, &params->chandef,
973 IEEE80211_CHANCTX_SHARED);
974 if (!err)
975 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
976 mutex_unlock(&local->mtx);
977 if (err)
978 return err;
981 * Apply control port protocol, this allows us to
982 * not encrypt dynamic WEP control frames.
984 sdata->control_port_protocol = params->crypto.control_port_ethertype;
985 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
986 sdata->control_port_over_nl80211 =
987 params->crypto.control_port_over_nl80211;
988 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
989 &params->crypto,
990 sdata->vif.type);
992 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
993 vlan->control_port_protocol =
994 params->crypto.control_port_ethertype;
995 vlan->control_port_no_encrypt =
996 params->crypto.control_port_no_encrypt;
997 vlan->control_port_over_nl80211 =
998 params->crypto.control_port_over_nl80211;
999 vlan->encrypt_headroom =
1000 ieee80211_cs_headroom(sdata->local,
1001 &params->crypto,
1002 vlan->vif.type);
1005 sdata->vif.bss_conf.dtim_period = params->dtim_period;
1006 sdata->vif.bss_conf.enable_beacon = true;
1007 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
1009 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1010 if (params->ssid_len)
1011 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1012 params->ssid_len);
1013 sdata->vif.bss_conf.hidden_ssid =
1014 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1016 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1017 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1018 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1019 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1020 if (params->p2p_opp_ps)
1021 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1022 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1024 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
1025 if (err < 0) {
1026 ieee80211_vif_release_channel(sdata);
1027 return err;
1029 changed |= err;
1031 err = drv_start_ap(sdata->local, sdata);
1032 if (err) {
1033 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1035 if (old)
1036 kfree_rcu(old, rcu_head);
1037 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1038 ieee80211_vif_release_channel(sdata);
1039 return err;
1042 ieee80211_recalc_dtim(local, sdata);
1043 ieee80211_bss_info_change_notify(sdata, changed);
1045 netif_carrier_on(dev);
1046 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1047 netif_carrier_on(vlan->dev);
1049 return 0;
1052 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1053 struct cfg80211_beacon_data *params)
1055 struct ieee80211_sub_if_data *sdata;
1056 struct beacon_data *old;
1057 int err;
1059 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1060 sdata_assert_lock(sdata);
1062 /* don't allow changing the beacon while CSA is in place - offset
1063 * of channel switch counter may change
1065 if (sdata->vif.csa_active)
1066 return -EBUSY;
1068 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1069 if (!old)
1070 return -ENOENT;
1072 err = ieee80211_assign_beacon(sdata, params, NULL);
1073 if (err < 0)
1074 return err;
1075 ieee80211_bss_info_change_notify(sdata, err);
1076 return 0;
1079 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1081 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1082 struct ieee80211_sub_if_data *vlan;
1083 struct ieee80211_local *local = sdata->local;
1084 struct beacon_data *old_beacon;
1085 struct probe_resp *old_probe_resp;
1086 struct cfg80211_chan_def chandef;
1088 sdata_assert_lock(sdata);
1090 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
1091 if (!old_beacon)
1092 return -ENOENT;
1093 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
1095 /* abort any running channel switch */
1096 mutex_lock(&local->mtx);
1097 sdata->vif.csa_active = false;
1098 if (sdata->csa_block_tx) {
1099 ieee80211_wake_vif_queues(local, sdata,
1100 IEEE80211_QUEUE_STOP_REASON_CSA);
1101 sdata->csa_block_tx = false;
1104 mutex_unlock(&local->mtx);
1106 kfree(sdata->u.ap.next_beacon);
1107 sdata->u.ap.next_beacon = NULL;
1109 /* turn off carrier for this interface and dependent VLANs */
1110 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1111 netif_carrier_off(vlan->dev);
1112 netif_carrier_off(dev);
1114 /* remove beacon and probe response */
1115 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1116 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1117 kfree_rcu(old_beacon, rcu_head);
1118 if (old_probe_resp)
1119 kfree_rcu(old_probe_resp, rcu_head);
1120 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
1122 kfree(sdata->vif.bss_conf.ftmr_params);
1123 sdata->vif.bss_conf.ftmr_params = NULL;
1125 __sta_info_flush(sdata, true);
1126 ieee80211_free_keys(sdata, true);
1128 sdata->vif.bss_conf.enable_beacon = false;
1129 sdata->vif.bss_conf.ssid_len = 0;
1130 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1131 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1133 if (sdata->wdev.cac_started) {
1134 chandef = sdata->vif.bss_conf.chandef;
1135 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1136 cfg80211_cac_event(sdata->dev, &chandef,
1137 NL80211_RADAR_CAC_ABORTED,
1138 GFP_KERNEL);
1141 drv_stop_ap(sdata->local, sdata);
1143 /* free all potentially still buffered bcast frames */
1144 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1145 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1147 mutex_lock(&local->mtx);
1148 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
1149 ieee80211_vif_release_channel(sdata);
1150 mutex_unlock(&local->mtx);
1152 return 0;
1155 static int sta_apply_auth_flags(struct ieee80211_local *local,
1156 struct sta_info *sta,
1157 u32 mask, u32 set)
1159 int ret;
1161 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1162 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1163 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1164 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1165 if (ret)
1166 return ret;
1169 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1170 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1171 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1173 * When peer becomes associated, init rate control as
1174 * well. Some drivers require rate control initialized
1175 * before drv_sta_state() is called.
1177 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1178 rate_control_rate_init(sta);
1180 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1181 if (ret)
1182 return ret;
1185 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1186 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1187 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1188 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1189 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1190 else
1191 ret = 0;
1192 if (ret)
1193 return ret;
1196 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1197 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1198 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1199 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1200 if (ret)
1201 return ret;
1204 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1205 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1206 test_sta_flag(sta, WLAN_STA_AUTH)) {
1207 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1208 if (ret)
1209 return ret;
1212 return 0;
1215 static void sta_apply_mesh_params(struct ieee80211_local *local,
1216 struct sta_info *sta,
1217 struct station_parameters *params)
1219 #ifdef CONFIG_MAC80211_MESH
1220 struct ieee80211_sub_if_data *sdata = sta->sdata;
1221 u32 changed = 0;
1223 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1224 switch (params->plink_state) {
1225 case NL80211_PLINK_ESTAB:
1226 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1227 changed = mesh_plink_inc_estab_count(sdata);
1228 sta->mesh->plink_state = params->plink_state;
1229 sta->mesh->aid = params->peer_aid;
1231 ieee80211_mps_sta_status_update(sta);
1232 changed |= ieee80211_mps_set_sta_local_pm(sta,
1233 sdata->u.mesh.mshcfg.power_mode);
1234 break;
1235 case NL80211_PLINK_LISTEN:
1236 case NL80211_PLINK_BLOCKED:
1237 case NL80211_PLINK_OPN_SNT:
1238 case NL80211_PLINK_OPN_RCVD:
1239 case NL80211_PLINK_CNF_RCVD:
1240 case NL80211_PLINK_HOLDING:
1241 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1242 changed = mesh_plink_dec_estab_count(sdata);
1243 sta->mesh->plink_state = params->plink_state;
1245 ieee80211_mps_sta_status_update(sta);
1246 changed |= ieee80211_mps_set_sta_local_pm(sta,
1247 NL80211_MESH_POWER_UNKNOWN);
1248 break;
1249 default:
1250 /* nothing */
1251 break;
1255 switch (params->plink_action) {
1256 case NL80211_PLINK_ACTION_NO_ACTION:
1257 /* nothing */
1258 break;
1259 case NL80211_PLINK_ACTION_OPEN:
1260 changed |= mesh_plink_open(sta);
1261 break;
1262 case NL80211_PLINK_ACTION_BLOCK:
1263 changed |= mesh_plink_block(sta);
1264 break;
1267 if (params->local_pm)
1268 changed |= ieee80211_mps_set_sta_local_pm(sta,
1269 params->local_pm);
1271 ieee80211_mbss_info_change_notify(sdata, changed);
1272 #endif
1275 static int sta_apply_parameters(struct ieee80211_local *local,
1276 struct sta_info *sta,
1277 struct station_parameters *params)
1279 int ret = 0;
1280 struct ieee80211_supported_band *sband;
1281 struct ieee80211_sub_if_data *sdata = sta->sdata;
1282 u32 mask, set;
1284 sband = ieee80211_get_sband(sdata);
1285 if (!sband)
1286 return -EINVAL;
1288 mask = params->sta_flags_mask;
1289 set = params->sta_flags_set;
1291 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1293 * In mesh mode, ASSOCIATED isn't part of the nl80211
1294 * API but must follow AUTHENTICATED for driver state.
1296 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1297 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1298 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1299 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1300 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1302 * TDLS -- everything follows authorized, but
1303 * only becoming authorized is possible, not
1304 * going back
1306 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1307 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1308 BIT(NL80211_STA_FLAG_ASSOCIATED);
1309 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1310 BIT(NL80211_STA_FLAG_ASSOCIATED);
1314 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1315 local->hw.queues >= IEEE80211_NUM_ACS)
1316 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1318 /* auth flags will be set later for TDLS,
1319 * and for unassociated stations that move to assocaited */
1320 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1321 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1322 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1323 ret = sta_apply_auth_flags(local, sta, mask, set);
1324 if (ret)
1325 return ret;
1328 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1329 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1330 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1331 else
1332 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1335 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1336 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1337 if (set & BIT(NL80211_STA_FLAG_MFP))
1338 set_sta_flag(sta, WLAN_STA_MFP);
1339 else
1340 clear_sta_flag(sta, WLAN_STA_MFP);
1343 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1344 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1345 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1346 else
1347 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1350 /* mark TDLS channel switch support, if the AP allows it */
1351 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1352 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1353 params->ext_capab_len >= 4 &&
1354 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1355 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1357 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1358 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1359 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1360 params->ext_capab_len >= 8 &&
1361 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1362 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1364 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1365 sta->sta.uapsd_queues = params->uapsd_queues;
1366 sta->sta.max_sp = params->max_sp;
1369 /* The sender might not have sent the last bit, consider it to be 0 */
1370 if (params->ext_capab_len >= 8) {
1371 u8 val = (params->ext_capab[7] &
1372 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1374 /* we did get all the bits, take the MSB as well */
1375 if (params->ext_capab_len >= 9) {
1376 u8 val_msb = params->ext_capab[8] &
1377 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1378 val_msb <<= 1;
1379 val |= val_msb;
1382 switch (val) {
1383 case 1:
1384 sta->sta.max_amsdu_subframes = 32;
1385 break;
1386 case 2:
1387 sta->sta.max_amsdu_subframes = 16;
1388 break;
1389 case 3:
1390 sta->sta.max_amsdu_subframes = 8;
1391 break;
1392 default:
1393 sta->sta.max_amsdu_subframes = 0;
1398 * cfg80211 validates this (1-2007) and allows setting the AID
1399 * only when creating a new station entry
1401 if (params->aid)
1402 sta->sta.aid = params->aid;
1405 * Some of the following updates would be racy if called on an
1406 * existing station, via ieee80211_change_station(). However,
1407 * all such changes are rejected by cfg80211 except for updates
1408 * changing the supported rates on an existing but not yet used
1409 * TDLS peer.
1412 if (params->listen_interval >= 0)
1413 sta->listen_interval = params->listen_interval;
1415 if (params->supported_rates) {
1416 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1417 sband, params->supported_rates,
1418 params->supported_rates_len,
1419 &sta->sta.supp_rates[sband->band]);
1422 if (params->ht_capa)
1423 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1424 params->ht_capa, sta);
1426 /* VHT can override some HT caps such as the A-MSDU max length */
1427 if (params->vht_capa)
1428 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1429 params->vht_capa, sta);
1431 if (params->he_capa)
1432 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1433 (void *)params->he_capa,
1434 params->he_capa_len, sta);
1436 if (params->opmode_notif_used) {
1437 /* returned value is only needed for rc update, but the
1438 * rc isn't initialized here yet, so ignore it
1440 __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
1441 sband->band);
1444 if (params->support_p2p_ps >= 0)
1445 sta->sta.support_p2p_ps = params->support_p2p_ps;
1447 if (ieee80211_vif_is_mesh(&sdata->vif))
1448 sta_apply_mesh_params(local, sta, params);
1450 /* set the STA state after all sta info from usermode has been set */
1451 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1452 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1453 ret = sta_apply_auth_flags(local, sta, mask, set);
1454 if (ret)
1455 return ret;
1458 return 0;
1461 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1462 const u8 *mac,
1463 struct station_parameters *params)
1465 struct ieee80211_local *local = wiphy_priv(wiphy);
1466 struct sta_info *sta;
1467 struct ieee80211_sub_if_data *sdata;
1468 int err;
1469 int layer2_update;
1471 if (params->vlan) {
1472 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1474 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1475 sdata->vif.type != NL80211_IFTYPE_AP)
1476 return -EINVAL;
1477 } else
1478 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1480 if (ether_addr_equal(mac, sdata->vif.addr))
1481 return -EINVAL;
1483 if (is_multicast_ether_addr(mac))
1484 return -EINVAL;
1486 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1487 if (!sta)
1488 return -ENOMEM;
1490 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1491 sta->sta.tdls = true;
1493 err = sta_apply_parameters(local, sta, params);
1494 if (err) {
1495 sta_info_free(local, sta);
1496 return err;
1500 * for TDLS and for unassociated station, rate control should be
1501 * initialized only when rates are known and station is marked
1502 * authorized/associated
1504 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1505 test_sta_flag(sta, WLAN_STA_ASSOC))
1506 rate_control_rate_init(sta);
1508 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1509 sdata->vif.type == NL80211_IFTYPE_AP;
1511 err = sta_info_insert_rcu(sta);
1512 if (err) {
1513 rcu_read_unlock();
1514 return err;
1517 if (layer2_update)
1518 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
1520 rcu_read_unlock();
1522 return 0;
1525 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1526 struct station_del_parameters *params)
1528 struct ieee80211_sub_if_data *sdata;
1530 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1532 if (params->mac)
1533 return sta_info_destroy_addr_bss(sdata, params->mac);
1535 sta_info_flush(sdata);
1536 return 0;
1539 static int ieee80211_change_station(struct wiphy *wiphy,
1540 struct net_device *dev, const u8 *mac,
1541 struct station_parameters *params)
1543 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1544 struct ieee80211_local *local = wiphy_priv(wiphy);
1545 struct sta_info *sta;
1546 struct ieee80211_sub_if_data *vlansdata;
1547 enum cfg80211_station_type statype;
1548 int err;
1550 mutex_lock(&local->sta_mtx);
1552 sta = sta_info_get_bss(sdata, mac);
1553 if (!sta) {
1554 err = -ENOENT;
1555 goto out_err;
1558 switch (sdata->vif.type) {
1559 case NL80211_IFTYPE_MESH_POINT:
1560 if (sdata->u.mesh.user_mpm)
1561 statype = CFG80211_STA_MESH_PEER_USER;
1562 else
1563 statype = CFG80211_STA_MESH_PEER_KERNEL;
1564 break;
1565 case NL80211_IFTYPE_ADHOC:
1566 statype = CFG80211_STA_IBSS;
1567 break;
1568 case NL80211_IFTYPE_STATION:
1569 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1570 statype = CFG80211_STA_AP_STA;
1571 break;
1573 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1574 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1575 else
1576 statype = CFG80211_STA_TDLS_PEER_SETUP;
1577 break;
1578 case NL80211_IFTYPE_AP:
1579 case NL80211_IFTYPE_AP_VLAN:
1580 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1581 statype = CFG80211_STA_AP_CLIENT;
1582 else
1583 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1584 break;
1585 default:
1586 err = -EOPNOTSUPP;
1587 goto out_err;
1590 err = cfg80211_check_station_change(wiphy, params, statype);
1591 if (err)
1592 goto out_err;
1594 if (params->vlan && params->vlan != sta->sdata->dev) {
1595 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1597 if (params->vlan->ieee80211_ptr->use_4addr) {
1598 if (vlansdata->u.vlan.sta) {
1599 err = -EBUSY;
1600 goto out_err;
1603 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1604 __ieee80211_check_fast_rx_iface(vlansdata);
1607 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1608 sta->sdata->u.vlan.sta)
1609 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1611 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1612 ieee80211_vif_dec_num_mcast(sta->sdata);
1614 sta->sdata = vlansdata;
1615 ieee80211_check_fast_xmit(sta);
1617 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1618 ieee80211_vif_inc_num_mcast(sta->sdata);
1620 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
1623 err = sta_apply_parameters(local, sta, params);
1624 if (err)
1625 goto out_err;
1627 mutex_unlock(&local->sta_mtx);
1629 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1630 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1631 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1632 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1633 sta_info_tx_streams(sta) != 1) {
1634 ht_dbg(sta->sdata,
1635 "%pM just authorized and MIMO capable - update SMPS\n",
1636 sta->sta.addr);
1637 ieee80211_send_smps_action(sta->sdata,
1638 sta->sdata->bss->req_smps,
1639 sta->sta.addr,
1640 sta->sdata->vif.bss_conf.bssid);
1643 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1644 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1645 ieee80211_recalc_ps(local);
1646 ieee80211_recalc_ps_vif(sdata);
1649 return 0;
1650 out_err:
1651 mutex_unlock(&local->sta_mtx);
1652 return err;
1655 #ifdef CONFIG_MAC80211_MESH
1656 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1657 const u8 *dst, const u8 *next_hop)
1659 struct ieee80211_sub_if_data *sdata;
1660 struct mesh_path *mpath;
1661 struct sta_info *sta;
1663 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1665 rcu_read_lock();
1666 sta = sta_info_get(sdata, next_hop);
1667 if (!sta) {
1668 rcu_read_unlock();
1669 return -ENOENT;
1672 mpath = mesh_path_add(sdata, dst);
1673 if (IS_ERR(mpath)) {
1674 rcu_read_unlock();
1675 return PTR_ERR(mpath);
1678 mesh_path_fix_nexthop(mpath, sta);
1680 rcu_read_unlock();
1681 return 0;
1684 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1685 const u8 *dst)
1687 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1689 if (dst)
1690 return mesh_path_del(sdata, dst);
1692 mesh_path_flush_by_iface(sdata);
1693 return 0;
1696 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1697 const u8 *dst, const u8 *next_hop)
1699 struct ieee80211_sub_if_data *sdata;
1700 struct mesh_path *mpath;
1701 struct sta_info *sta;
1703 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1705 rcu_read_lock();
1707 sta = sta_info_get(sdata, next_hop);
1708 if (!sta) {
1709 rcu_read_unlock();
1710 return -ENOENT;
1713 mpath = mesh_path_lookup(sdata, dst);
1714 if (!mpath) {
1715 rcu_read_unlock();
1716 return -ENOENT;
1719 mesh_path_fix_nexthop(mpath, sta);
1721 rcu_read_unlock();
1722 return 0;
1725 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1726 struct mpath_info *pinfo)
1728 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1730 if (next_hop_sta)
1731 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1732 else
1733 eth_zero_addr(next_hop);
1735 memset(pinfo, 0, sizeof(*pinfo));
1737 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
1739 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1740 MPATH_INFO_SN |
1741 MPATH_INFO_METRIC |
1742 MPATH_INFO_EXPTIME |
1743 MPATH_INFO_DISCOVERY_TIMEOUT |
1744 MPATH_INFO_DISCOVERY_RETRIES |
1745 MPATH_INFO_FLAGS;
1747 pinfo->frame_qlen = mpath->frame_queue.qlen;
1748 pinfo->sn = mpath->sn;
1749 pinfo->metric = mpath->metric;
1750 if (time_before(jiffies, mpath->exp_time))
1751 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1752 pinfo->discovery_timeout =
1753 jiffies_to_msecs(mpath->discovery_timeout);
1754 pinfo->discovery_retries = mpath->discovery_retries;
1755 if (mpath->flags & MESH_PATH_ACTIVE)
1756 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1757 if (mpath->flags & MESH_PATH_RESOLVING)
1758 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1759 if (mpath->flags & MESH_PATH_SN_VALID)
1760 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1761 if (mpath->flags & MESH_PATH_FIXED)
1762 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1763 if (mpath->flags & MESH_PATH_RESOLVED)
1764 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1767 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1768 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1771 struct ieee80211_sub_if_data *sdata;
1772 struct mesh_path *mpath;
1774 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1776 rcu_read_lock();
1777 mpath = mesh_path_lookup(sdata, dst);
1778 if (!mpath) {
1779 rcu_read_unlock();
1780 return -ENOENT;
1782 memcpy(dst, mpath->dst, ETH_ALEN);
1783 mpath_set_pinfo(mpath, next_hop, pinfo);
1784 rcu_read_unlock();
1785 return 0;
1788 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1789 int idx, u8 *dst, u8 *next_hop,
1790 struct mpath_info *pinfo)
1792 struct ieee80211_sub_if_data *sdata;
1793 struct mesh_path *mpath;
1795 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1797 rcu_read_lock();
1798 mpath = mesh_path_lookup_by_idx(sdata, idx);
1799 if (!mpath) {
1800 rcu_read_unlock();
1801 return -ENOENT;
1803 memcpy(dst, mpath->dst, ETH_ALEN);
1804 mpath_set_pinfo(mpath, next_hop, pinfo);
1805 rcu_read_unlock();
1806 return 0;
1809 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1810 struct mpath_info *pinfo)
1812 memset(pinfo, 0, sizeof(*pinfo));
1813 memcpy(mpp, mpath->mpp, ETH_ALEN);
1815 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
1818 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1819 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1822 struct ieee80211_sub_if_data *sdata;
1823 struct mesh_path *mpath;
1825 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1827 rcu_read_lock();
1828 mpath = mpp_path_lookup(sdata, dst);
1829 if (!mpath) {
1830 rcu_read_unlock();
1831 return -ENOENT;
1833 memcpy(dst, mpath->dst, ETH_ALEN);
1834 mpp_set_pinfo(mpath, mpp, pinfo);
1835 rcu_read_unlock();
1836 return 0;
1839 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1840 int idx, u8 *dst, u8 *mpp,
1841 struct mpath_info *pinfo)
1843 struct ieee80211_sub_if_data *sdata;
1844 struct mesh_path *mpath;
1846 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1848 rcu_read_lock();
1849 mpath = mpp_path_lookup_by_idx(sdata, idx);
1850 if (!mpath) {
1851 rcu_read_unlock();
1852 return -ENOENT;
1854 memcpy(dst, mpath->dst, ETH_ALEN);
1855 mpp_set_pinfo(mpath, mpp, pinfo);
1856 rcu_read_unlock();
1857 return 0;
1860 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1861 struct net_device *dev,
1862 struct mesh_config *conf)
1864 struct ieee80211_sub_if_data *sdata;
1865 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1867 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1868 return 0;
1871 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1873 return (mask >> (parm-1)) & 0x1;
1876 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1877 const struct mesh_setup *setup)
1879 u8 *new_ie;
1880 const u8 *old_ie;
1881 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1882 struct ieee80211_sub_if_data, u.mesh);
1884 /* allocate information elements */
1885 new_ie = NULL;
1886 old_ie = ifmsh->ie;
1888 if (setup->ie_len) {
1889 new_ie = kmemdup(setup->ie, setup->ie_len,
1890 GFP_KERNEL);
1891 if (!new_ie)
1892 return -ENOMEM;
1894 ifmsh->ie_len = setup->ie_len;
1895 ifmsh->ie = new_ie;
1896 kfree(old_ie);
1898 /* now copy the rest of the setup parameters */
1899 ifmsh->mesh_id_len = setup->mesh_id_len;
1900 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1901 ifmsh->mesh_sp_id = setup->sync_method;
1902 ifmsh->mesh_pp_id = setup->path_sel_proto;
1903 ifmsh->mesh_pm_id = setup->path_metric;
1904 ifmsh->user_mpm = setup->user_mpm;
1905 ifmsh->mesh_auth_id = setup->auth_id;
1906 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1907 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
1908 if (setup->is_authenticated)
1909 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1910 if (setup->is_secure)
1911 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1913 /* mcast rate setting in Mesh Node */
1914 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1915 sizeof(setup->mcast_rate));
1916 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
1918 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1919 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1921 return 0;
1924 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1925 struct net_device *dev, u32 mask,
1926 const struct mesh_config *nconf)
1928 struct mesh_config *conf;
1929 struct ieee80211_sub_if_data *sdata;
1930 struct ieee80211_if_mesh *ifmsh;
1932 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1933 ifmsh = &sdata->u.mesh;
1935 /* Set the config options which we are interested in setting */
1936 conf = &(sdata->u.mesh.mshcfg);
1937 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1938 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1939 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1940 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1941 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1942 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1943 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1944 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1945 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1946 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1947 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1948 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1949 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1950 conf->element_ttl = nconf->element_ttl;
1951 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1952 if (ifmsh->user_mpm)
1953 return -EBUSY;
1954 conf->auto_open_plinks = nconf->auto_open_plinks;
1956 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1957 conf->dot11MeshNbrOffsetMaxNeighbor =
1958 nconf->dot11MeshNbrOffsetMaxNeighbor;
1959 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1960 conf->dot11MeshHWMPmaxPREQretries =
1961 nconf->dot11MeshHWMPmaxPREQretries;
1962 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1963 conf->path_refresh_time = nconf->path_refresh_time;
1964 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1965 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1966 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1967 conf->dot11MeshHWMPactivePathTimeout =
1968 nconf->dot11MeshHWMPactivePathTimeout;
1969 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1970 conf->dot11MeshHWMPpreqMinInterval =
1971 nconf->dot11MeshHWMPpreqMinInterval;
1972 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1973 conf->dot11MeshHWMPperrMinInterval =
1974 nconf->dot11MeshHWMPperrMinInterval;
1975 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1976 mask))
1977 conf->dot11MeshHWMPnetDiameterTraversalTime =
1978 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1979 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1980 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1981 ieee80211_mesh_root_setup(ifmsh);
1983 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1984 /* our current gate announcement implementation rides on root
1985 * announcements, so require this ifmsh to also be a root node
1986 * */
1987 if (nconf->dot11MeshGateAnnouncementProtocol &&
1988 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1989 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
1990 ieee80211_mesh_root_setup(ifmsh);
1992 conf->dot11MeshGateAnnouncementProtocol =
1993 nconf->dot11MeshGateAnnouncementProtocol;
1995 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
1996 conf->dot11MeshHWMPRannInterval =
1997 nconf->dot11MeshHWMPRannInterval;
1998 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1999 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2000 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2001 /* our RSSI threshold implementation is supported only for
2002 * devices that report signal in dBm.
2004 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2005 return -ENOTSUPP;
2006 conf->rssi_threshold = nconf->rssi_threshold;
2008 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2009 conf->ht_opmode = nconf->ht_opmode;
2010 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2011 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
2013 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2014 conf->dot11MeshHWMPactivePathToRootTimeout =
2015 nconf->dot11MeshHWMPactivePathToRootTimeout;
2016 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2017 conf->dot11MeshHWMProotInterval =
2018 nconf->dot11MeshHWMProotInterval;
2019 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2020 conf->dot11MeshHWMPconfirmationInterval =
2021 nconf->dot11MeshHWMPconfirmationInterval;
2022 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2023 conf->power_mode = nconf->power_mode;
2024 ieee80211_mps_local_status_update(sdata);
2026 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2027 conf->dot11MeshAwakeWindowDuration =
2028 nconf->dot11MeshAwakeWindowDuration;
2029 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2030 conf->plink_timeout = nconf->plink_timeout;
2031 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2032 return 0;
2035 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2036 const struct mesh_config *conf,
2037 const struct mesh_setup *setup)
2039 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2040 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2041 int err;
2043 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2044 err = copy_mesh_setup(ifmsh, setup);
2045 if (err)
2046 return err;
2048 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2050 /* can mesh use other SMPS modes? */
2051 sdata->smps_mode = IEEE80211_SMPS_OFF;
2052 sdata->needed_rx_chains = sdata->local->rx_chains;
2054 mutex_lock(&sdata->local->mtx);
2055 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
2056 IEEE80211_CHANCTX_SHARED);
2057 mutex_unlock(&sdata->local->mtx);
2058 if (err)
2059 return err;
2061 return ieee80211_start_mesh(sdata);
2064 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2066 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2068 ieee80211_stop_mesh(sdata);
2069 mutex_lock(&sdata->local->mtx);
2070 ieee80211_vif_release_channel(sdata);
2071 mutex_unlock(&sdata->local->mtx);
2073 return 0;
2075 #endif
2077 static int ieee80211_change_bss(struct wiphy *wiphy,
2078 struct net_device *dev,
2079 struct bss_parameters *params)
2081 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2082 struct ieee80211_supported_band *sband;
2083 u32 changed = 0;
2085 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
2086 return -ENOENT;
2088 sband = ieee80211_get_sband(sdata);
2089 if (!sband)
2090 return -EINVAL;
2092 if (params->use_cts_prot >= 0) {
2093 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2094 changed |= BSS_CHANGED_ERP_CTS_PROT;
2096 if (params->use_short_preamble >= 0) {
2097 sdata->vif.bss_conf.use_short_preamble =
2098 params->use_short_preamble;
2099 changed |= BSS_CHANGED_ERP_PREAMBLE;
2102 if (!sdata->vif.bss_conf.use_short_slot &&
2103 sband->band == NL80211_BAND_5GHZ) {
2104 sdata->vif.bss_conf.use_short_slot = true;
2105 changed |= BSS_CHANGED_ERP_SLOT;
2108 if (params->use_short_slot_time >= 0) {
2109 sdata->vif.bss_conf.use_short_slot =
2110 params->use_short_slot_time;
2111 changed |= BSS_CHANGED_ERP_SLOT;
2114 if (params->basic_rates) {
2115 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2116 wiphy->bands[sband->band],
2117 params->basic_rates,
2118 params->basic_rates_len,
2119 &sdata->vif.bss_conf.basic_rates);
2120 changed |= BSS_CHANGED_BASIC_RATES;
2121 ieee80211_check_rate_mask(sdata);
2124 if (params->ap_isolate >= 0) {
2125 if (params->ap_isolate)
2126 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2127 else
2128 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2129 ieee80211_check_fast_rx_iface(sdata);
2132 if (params->ht_opmode >= 0) {
2133 sdata->vif.bss_conf.ht_operation_mode =
2134 (u16) params->ht_opmode;
2135 changed |= BSS_CHANGED_HT;
2138 if (params->p2p_ctwindow >= 0) {
2139 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2140 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2141 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2142 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2143 changed |= BSS_CHANGED_P2P_PS;
2146 if (params->p2p_opp_ps > 0) {
2147 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2148 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2149 changed |= BSS_CHANGED_P2P_PS;
2150 } else if (params->p2p_opp_ps == 0) {
2151 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2152 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2153 changed |= BSS_CHANGED_P2P_PS;
2156 ieee80211_bss_info_change_notify(sdata, changed);
2158 return 0;
2161 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2162 struct net_device *dev,
2163 struct ieee80211_txq_params *params)
2165 struct ieee80211_local *local = wiphy_priv(wiphy);
2166 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2167 struct ieee80211_tx_queue_params p;
2169 if (!local->ops->conf_tx)
2170 return -EOPNOTSUPP;
2172 if (local->hw.queues < IEEE80211_NUM_ACS)
2173 return -EOPNOTSUPP;
2175 memset(&p, 0, sizeof(p));
2176 p.aifs = params->aifs;
2177 p.cw_max = params->cwmax;
2178 p.cw_min = params->cwmin;
2179 p.txop = params->txop;
2182 * Setting tx queue params disables u-apsd because it's only
2183 * called in master mode.
2185 p.uapsd = false;
2187 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2189 sdata->tx_conf[params->ac] = p;
2190 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2191 wiphy_debug(local->hw.wiphy,
2192 "failed to set TX queue parameters for AC %d\n",
2193 params->ac);
2194 return -EINVAL;
2197 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2199 return 0;
2202 #ifdef CONFIG_PM
2203 static int ieee80211_suspend(struct wiphy *wiphy,
2204 struct cfg80211_wowlan *wowlan)
2206 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2209 static int ieee80211_resume(struct wiphy *wiphy)
2211 return __ieee80211_resume(wiphy_priv(wiphy));
2213 #else
2214 #define ieee80211_suspend NULL
2215 #define ieee80211_resume NULL
2216 #endif
2218 static int ieee80211_scan(struct wiphy *wiphy,
2219 struct cfg80211_scan_request *req)
2221 struct ieee80211_sub_if_data *sdata;
2223 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2225 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2226 case NL80211_IFTYPE_STATION:
2227 case NL80211_IFTYPE_ADHOC:
2228 case NL80211_IFTYPE_MESH_POINT:
2229 case NL80211_IFTYPE_P2P_CLIENT:
2230 case NL80211_IFTYPE_P2P_DEVICE:
2231 break;
2232 case NL80211_IFTYPE_P2P_GO:
2233 if (sdata->local->ops->hw_scan)
2234 break;
2236 * FIXME: implement NoA while scanning in software,
2237 * for now fall through to allow scanning only when
2238 * beaconing hasn't been configured yet
2240 /* fall through */
2241 case NL80211_IFTYPE_AP:
2243 * If the scan has been forced (and the driver supports
2244 * forcing), don't care about being beaconing already.
2245 * This will create problems to the attached stations (e.g. all
2246 * the frames sent while scanning on other channel will be
2247 * lost)
2249 if (sdata->u.ap.beacon &&
2250 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2251 !(req->flags & NL80211_SCAN_FLAG_AP)))
2252 return -EOPNOTSUPP;
2253 break;
2254 case NL80211_IFTYPE_NAN:
2255 default:
2256 return -EOPNOTSUPP;
2259 return ieee80211_request_scan(sdata, req);
2262 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2264 ieee80211_scan_cancel(wiphy_priv(wiphy));
2267 static int
2268 ieee80211_sched_scan_start(struct wiphy *wiphy,
2269 struct net_device *dev,
2270 struct cfg80211_sched_scan_request *req)
2272 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2274 if (!sdata->local->ops->sched_scan_start)
2275 return -EOPNOTSUPP;
2277 return ieee80211_request_sched_scan_start(sdata, req);
2280 static int
2281 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2282 u64 reqid)
2284 struct ieee80211_local *local = wiphy_priv(wiphy);
2286 if (!local->ops->sched_scan_stop)
2287 return -EOPNOTSUPP;
2289 return ieee80211_request_sched_scan_stop(local);
2292 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2293 struct cfg80211_auth_request *req)
2295 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2298 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2299 struct cfg80211_assoc_request *req)
2301 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2304 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2305 struct cfg80211_deauth_request *req)
2307 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2310 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2311 struct cfg80211_disassoc_request *req)
2313 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2316 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2317 struct cfg80211_ibss_params *params)
2319 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2322 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2324 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2327 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2328 struct ocb_setup *setup)
2330 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2333 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2335 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2338 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2339 int rate[NUM_NL80211_BANDS])
2341 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2343 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2344 sizeof(int) * NUM_NL80211_BANDS);
2346 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
2348 return 0;
2351 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2353 struct ieee80211_local *local = wiphy_priv(wiphy);
2354 int err;
2356 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2357 ieee80211_check_fast_xmit_all(local);
2359 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2361 if (err) {
2362 ieee80211_check_fast_xmit_all(local);
2363 return err;
2367 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2368 (changed & WIPHY_PARAM_DYN_ACK)) {
2369 s16 coverage_class;
2371 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2372 wiphy->coverage_class : -1;
2373 err = drv_set_coverage_class(local, coverage_class);
2375 if (err)
2376 return err;
2379 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2380 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2382 if (err)
2383 return err;
2386 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2387 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2388 return -EINVAL;
2389 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2391 if (changed & WIPHY_PARAM_RETRY_LONG) {
2392 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2393 return -EINVAL;
2394 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2396 if (changed &
2397 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2398 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2400 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2401 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2402 WIPHY_PARAM_TXQ_QUANTUM))
2403 ieee80211_txq_set_params(local);
2405 return 0;
2408 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2409 struct wireless_dev *wdev,
2410 enum nl80211_tx_power_setting type, int mbm)
2412 struct ieee80211_local *local = wiphy_priv(wiphy);
2413 struct ieee80211_sub_if_data *sdata;
2414 enum nl80211_tx_power_setting txp_type = type;
2415 bool update_txp_type = false;
2416 bool has_monitor = false;
2418 if (wdev) {
2419 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2421 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2422 sdata = rtnl_dereference(local->monitor_sdata);
2423 if (!sdata)
2424 return -EOPNOTSUPP;
2427 switch (type) {
2428 case NL80211_TX_POWER_AUTOMATIC:
2429 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2430 txp_type = NL80211_TX_POWER_LIMITED;
2431 break;
2432 case NL80211_TX_POWER_LIMITED:
2433 case NL80211_TX_POWER_FIXED:
2434 if (mbm < 0 || (mbm % 100))
2435 return -EOPNOTSUPP;
2436 sdata->user_power_level = MBM_TO_DBM(mbm);
2437 break;
2440 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2441 update_txp_type = true;
2442 sdata->vif.bss_conf.txpower_type = txp_type;
2445 ieee80211_recalc_txpower(sdata, update_txp_type);
2447 return 0;
2450 switch (type) {
2451 case NL80211_TX_POWER_AUTOMATIC:
2452 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2453 txp_type = NL80211_TX_POWER_LIMITED;
2454 break;
2455 case NL80211_TX_POWER_LIMITED:
2456 case NL80211_TX_POWER_FIXED:
2457 if (mbm < 0 || (mbm % 100))
2458 return -EOPNOTSUPP;
2459 local->user_power_level = MBM_TO_DBM(mbm);
2460 break;
2463 mutex_lock(&local->iflist_mtx);
2464 list_for_each_entry(sdata, &local->interfaces, list) {
2465 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2466 has_monitor = true;
2467 continue;
2469 sdata->user_power_level = local->user_power_level;
2470 if (txp_type != sdata->vif.bss_conf.txpower_type)
2471 update_txp_type = true;
2472 sdata->vif.bss_conf.txpower_type = txp_type;
2474 list_for_each_entry(sdata, &local->interfaces, list) {
2475 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2476 continue;
2477 ieee80211_recalc_txpower(sdata, update_txp_type);
2479 mutex_unlock(&local->iflist_mtx);
2481 if (has_monitor) {
2482 sdata = rtnl_dereference(local->monitor_sdata);
2483 if (sdata) {
2484 sdata->user_power_level = local->user_power_level;
2485 if (txp_type != sdata->vif.bss_conf.txpower_type)
2486 update_txp_type = true;
2487 sdata->vif.bss_conf.txpower_type = txp_type;
2489 ieee80211_recalc_txpower(sdata, update_txp_type);
2493 return 0;
2496 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2497 struct wireless_dev *wdev,
2498 int *dbm)
2500 struct ieee80211_local *local = wiphy_priv(wiphy);
2501 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2503 if (local->ops->get_txpower)
2504 return drv_get_txpower(local, sdata, dbm);
2506 if (!local->use_chanctx)
2507 *dbm = local->hw.conf.power_level;
2508 else
2509 *dbm = sdata->vif.bss_conf.txpower;
2511 return 0;
2514 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2515 const u8 *addr)
2517 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2519 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2521 return 0;
2524 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2526 struct ieee80211_local *local = wiphy_priv(wiphy);
2528 drv_rfkill_poll(local);
2531 #ifdef CONFIG_NL80211_TESTMODE
2532 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2533 struct wireless_dev *wdev,
2534 void *data, int len)
2536 struct ieee80211_local *local = wiphy_priv(wiphy);
2537 struct ieee80211_vif *vif = NULL;
2539 if (!local->ops->testmode_cmd)
2540 return -EOPNOTSUPP;
2542 if (wdev) {
2543 struct ieee80211_sub_if_data *sdata;
2545 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2546 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2547 vif = &sdata->vif;
2550 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2553 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2554 struct sk_buff *skb,
2555 struct netlink_callback *cb,
2556 void *data, int len)
2558 struct ieee80211_local *local = wiphy_priv(wiphy);
2560 if (!local->ops->testmode_dump)
2561 return -EOPNOTSUPP;
2563 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2565 #endif
2567 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2568 enum ieee80211_smps_mode smps_mode)
2570 struct sta_info *sta;
2571 enum ieee80211_smps_mode old_req;
2573 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2574 return -EINVAL;
2576 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2577 return 0;
2579 old_req = sdata->u.ap.req_smps;
2580 sdata->u.ap.req_smps = smps_mode;
2582 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2583 if (old_req == smps_mode ||
2584 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2585 return 0;
2587 ht_dbg(sdata,
2588 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
2589 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2591 mutex_lock(&sdata->local->sta_mtx);
2592 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2594 * Only stations associated to our AP and
2595 * associated VLANs
2597 if (sta->sdata->bss != &sdata->u.ap)
2598 continue;
2600 /* This station doesn't support MIMO - skip it */
2601 if (sta_info_tx_streams(sta) == 1)
2602 continue;
2605 * Don't wake up a STA just to send the action frame
2606 * unless we are getting more restrictive.
2608 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2609 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2610 smps_mode)) {
2611 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2612 sta->sta.addr);
2613 continue;
2617 * If the STA is not authorized, wait until it gets
2618 * authorized and the action frame will be sent then.
2620 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2621 continue;
2623 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2624 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2625 sdata->vif.bss_conf.bssid);
2627 mutex_unlock(&sdata->local->sta_mtx);
2629 sdata->smps_mode = smps_mode;
2630 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2632 return 0;
2635 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2636 enum ieee80211_smps_mode smps_mode)
2638 const u8 *ap;
2639 enum ieee80211_smps_mode old_req;
2640 int err;
2641 struct sta_info *sta;
2642 bool tdls_peer_found = false;
2644 lockdep_assert_held(&sdata->wdev.mtx);
2646 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2647 return -EINVAL;
2649 old_req = sdata->u.mgd.req_smps;
2650 sdata->u.mgd.req_smps = smps_mode;
2652 if (old_req == smps_mode &&
2653 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2654 return 0;
2657 * If not associated, or current association is not an HT
2658 * association, there's no need to do anything, just store
2659 * the new value until we associate.
2661 if (!sdata->u.mgd.associated ||
2662 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2663 return 0;
2665 ap = sdata->u.mgd.associated->bssid;
2667 rcu_read_lock();
2668 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2669 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2670 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2671 continue;
2673 tdls_peer_found = true;
2674 break;
2676 rcu_read_unlock();
2678 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2679 if (tdls_peer_found || !sdata->u.mgd.powersave)
2680 smps_mode = IEEE80211_SMPS_OFF;
2681 else
2682 smps_mode = IEEE80211_SMPS_DYNAMIC;
2685 /* send SM PS frame to AP */
2686 err = ieee80211_send_smps_action(sdata, smps_mode,
2687 ap, ap);
2688 if (err)
2689 sdata->u.mgd.req_smps = old_req;
2690 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2691 ieee80211_teardown_tdls_peers(sdata);
2693 return err;
2696 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2697 bool enabled, int timeout)
2699 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2700 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2702 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2703 return -EOPNOTSUPP;
2705 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
2706 return -EOPNOTSUPP;
2708 if (enabled == sdata->u.mgd.powersave &&
2709 timeout == local->dynamic_ps_forced_timeout)
2710 return 0;
2712 sdata->u.mgd.powersave = enabled;
2713 local->dynamic_ps_forced_timeout = timeout;
2715 /* no change, but if automatic follow powersave */
2716 sdata_lock(sdata);
2717 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2718 sdata_unlock(sdata);
2720 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
2721 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2723 ieee80211_recalc_ps(local);
2724 ieee80211_recalc_ps_vif(sdata);
2725 ieee80211_check_fast_rx_iface(sdata);
2727 return 0;
2730 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2731 struct net_device *dev,
2732 s32 rssi_thold, u32 rssi_hyst)
2734 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2735 struct ieee80211_vif *vif = &sdata->vif;
2736 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2738 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2739 rssi_hyst == bss_conf->cqm_rssi_hyst)
2740 return 0;
2742 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2743 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2744 return -EOPNOTSUPP;
2746 bss_conf->cqm_rssi_thold = rssi_thold;
2747 bss_conf->cqm_rssi_hyst = rssi_hyst;
2748 bss_conf->cqm_rssi_low = 0;
2749 bss_conf->cqm_rssi_high = 0;
2750 sdata->u.mgd.last_cqm_event_signal = 0;
2752 /* tell the driver upon association, unless already associated */
2753 if (sdata->u.mgd.associated &&
2754 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2755 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2757 return 0;
2760 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
2761 struct net_device *dev,
2762 s32 rssi_low, s32 rssi_high)
2764 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2765 struct ieee80211_vif *vif = &sdata->vif;
2766 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2768 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
2769 return -EOPNOTSUPP;
2771 bss_conf->cqm_rssi_low = rssi_low;
2772 bss_conf->cqm_rssi_high = rssi_high;
2773 bss_conf->cqm_rssi_thold = 0;
2774 bss_conf->cqm_rssi_hyst = 0;
2775 sdata->u.mgd.last_cqm_event_signal = 0;
2777 /* tell the driver upon association, unless already associated */
2778 if (sdata->u.mgd.associated &&
2779 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2780 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2782 return 0;
2785 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2786 struct net_device *dev,
2787 const u8 *addr,
2788 const struct cfg80211_bitrate_mask *mask)
2790 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2791 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2792 int i, ret;
2794 if (!ieee80211_sdata_running(sdata))
2795 return -ENETDOWN;
2798 * If active validate the setting and reject it if it doesn't leave
2799 * at least one basic rate usable, since we really have to be able
2800 * to send something, and if we're an AP we have to be able to do
2801 * so at a basic rate so that all clients can receive it.
2803 if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
2804 sdata->vif.bss_conf.chandef.chan) {
2805 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2806 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
2808 if (!(mask->control[band].legacy & basic_rates))
2809 return -EINVAL;
2812 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
2813 ret = drv_set_bitrate_mask(local, sdata, mask);
2814 if (ret)
2815 return ret;
2818 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2819 struct ieee80211_supported_band *sband = wiphy->bands[i];
2820 int j;
2822 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2823 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2824 sizeof(mask->control[i].ht_mcs));
2825 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
2826 mask->control[i].vht_mcs,
2827 sizeof(mask->control[i].vht_mcs));
2829 sdata->rc_has_mcs_mask[i] = false;
2830 sdata->rc_has_vht_mcs_mask[i] = false;
2831 if (!sband)
2832 continue;
2834 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
2835 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2836 sdata->rc_has_mcs_mask[i] = true;
2837 break;
2841 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
2842 if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
2843 sdata->rc_has_vht_mcs_mask[i] = true;
2844 break;
2849 return 0;
2852 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2853 struct net_device *dev,
2854 struct cfg80211_chan_def *chandef,
2855 u32 cac_time_ms)
2857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2858 struct ieee80211_local *local = sdata->local;
2859 int err;
2861 mutex_lock(&local->mtx);
2862 if (!list_empty(&local->roc_list) || local->scanning) {
2863 err = -EBUSY;
2864 goto out_unlock;
2867 /* whatever, but channel contexts should not complain about that one */
2868 sdata->smps_mode = IEEE80211_SMPS_OFF;
2869 sdata->needed_rx_chains = local->rx_chains;
2871 err = ieee80211_vif_use_channel(sdata, chandef,
2872 IEEE80211_CHANCTX_SHARED);
2873 if (err)
2874 goto out_unlock;
2876 ieee80211_queue_delayed_work(&sdata->local->hw,
2877 &sdata->dfs_cac_timer_work,
2878 msecs_to_jiffies(cac_time_ms));
2880 out_unlock:
2881 mutex_unlock(&local->mtx);
2882 return err;
2885 static struct cfg80211_beacon_data *
2886 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2888 struct cfg80211_beacon_data *new_beacon;
2889 u8 *pos;
2890 int len;
2892 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2893 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2894 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
2896 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2897 if (!new_beacon)
2898 return NULL;
2900 pos = (u8 *)(new_beacon + 1);
2901 if (beacon->head_len) {
2902 new_beacon->head_len = beacon->head_len;
2903 new_beacon->head = pos;
2904 memcpy(pos, beacon->head, beacon->head_len);
2905 pos += beacon->head_len;
2907 if (beacon->tail_len) {
2908 new_beacon->tail_len = beacon->tail_len;
2909 new_beacon->tail = pos;
2910 memcpy(pos, beacon->tail, beacon->tail_len);
2911 pos += beacon->tail_len;
2913 if (beacon->beacon_ies_len) {
2914 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2915 new_beacon->beacon_ies = pos;
2916 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2917 pos += beacon->beacon_ies_len;
2919 if (beacon->proberesp_ies_len) {
2920 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2921 new_beacon->proberesp_ies = pos;
2922 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2923 pos += beacon->proberesp_ies_len;
2925 if (beacon->assocresp_ies_len) {
2926 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2927 new_beacon->assocresp_ies = pos;
2928 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2929 pos += beacon->assocresp_ies_len;
2931 if (beacon->probe_resp_len) {
2932 new_beacon->probe_resp_len = beacon->probe_resp_len;
2933 new_beacon->probe_resp = pos;
2934 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2935 pos += beacon->probe_resp_len;
2938 /* might copy -1, meaning no changes requested */
2939 new_beacon->ftm_responder = beacon->ftm_responder;
2940 if (beacon->lci) {
2941 new_beacon->lci_len = beacon->lci_len;
2942 new_beacon->lci = pos;
2943 memcpy(pos, beacon->lci, beacon->lci_len);
2944 pos += beacon->lci_len;
2946 if (beacon->civicloc) {
2947 new_beacon->civicloc_len = beacon->civicloc_len;
2948 new_beacon->civicloc = pos;
2949 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
2950 pos += beacon->civicloc_len;
2953 return new_beacon;
2956 void ieee80211_csa_finish(struct ieee80211_vif *vif)
2958 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2960 ieee80211_queue_work(&sdata->local->hw,
2961 &sdata->csa_finalize_work);
2963 EXPORT_SYMBOL(ieee80211_csa_finish);
2965 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2966 u32 *changed)
2968 int err;
2970 switch (sdata->vif.type) {
2971 case NL80211_IFTYPE_AP:
2972 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2973 NULL);
2974 kfree(sdata->u.ap.next_beacon);
2975 sdata->u.ap.next_beacon = NULL;
2977 if (err < 0)
2978 return err;
2979 *changed |= err;
2980 break;
2981 case NL80211_IFTYPE_ADHOC:
2982 err = ieee80211_ibss_finish_csa(sdata);
2983 if (err < 0)
2984 return err;
2985 *changed |= err;
2986 break;
2987 #ifdef CONFIG_MAC80211_MESH
2988 case NL80211_IFTYPE_MESH_POINT:
2989 err = ieee80211_mesh_finish_csa(sdata);
2990 if (err < 0)
2991 return err;
2992 *changed |= err;
2993 break;
2994 #endif
2995 default:
2996 WARN_ON(1);
2997 return -EINVAL;
3000 return 0;
3003 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3005 struct ieee80211_local *local = sdata->local;
3006 u32 changed = 0;
3007 int err;
3009 sdata_assert_lock(sdata);
3010 lockdep_assert_held(&local->mtx);
3011 lockdep_assert_held(&local->chanctx_mtx);
3014 * using reservation isn't immediate as it may be deferred until later
3015 * with multi-vif. once reservation is complete it will re-schedule the
3016 * work with no reserved_chanctx so verify chandef to check if it
3017 * completed successfully
3020 if (sdata->reserved_chanctx) {
3022 * with multi-vif csa driver may call ieee80211_csa_finish()
3023 * many times while waiting for other interfaces to use their
3024 * reservations
3026 if (sdata->reserved_ready)
3027 return 0;
3029 return ieee80211_vif_use_reserved_context(sdata);
3032 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3033 &sdata->csa_chandef))
3034 return -EINVAL;
3036 sdata->vif.csa_active = false;
3038 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3039 if (err)
3040 return err;
3042 ieee80211_bss_info_change_notify(sdata, changed);
3044 if (sdata->csa_block_tx) {
3045 ieee80211_wake_vif_queues(local, sdata,
3046 IEEE80211_QUEUE_STOP_REASON_CSA);
3047 sdata->csa_block_tx = false;
3050 err = drv_post_channel_switch(sdata);
3051 if (err)
3052 return err;
3054 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3056 return 0;
3059 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3061 if (__ieee80211_csa_finalize(sdata)) {
3062 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3063 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3064 GFP_KERNEL);
3068 void ieee80211_csa_finalize_work(struct work_struct *work)
3070 struct ieee80211_sub_if_data *sdata =
3071 container_of(work, struct ieee80211_sub_if_data,
3072 csa_finalize_work);
3073 struct ieee80211_local *local = sdata->local;
3075 sdata_lock(sdata);
3076 mutex_lock(&local->mtx);
3077 mutex_lock(&local->chanctx_mtx);
3079 /* AP might have been stopped while waiting for the lock. */
3080 if (!sdata->vif.csa_active)
3081 goto unlock;
3083 if (!ieee80211_sdata_running(sdata))
3084 goto unlock;
3086 ieee80211_csa_finalize(sdata);
3088 unlock:
3089 mutex_unlock(&local->chanctx_mtx);
3090 mutex_unlock(&local->mtx);
3091 sdata_unlock(sdata);
3094 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3095 struct cfg80211_csa_settings *params,
3096 u32 *changed)
3098 struct ieee80211_csa_settings csa = {};
3099 int err;
3101 switch (sdata->vif.type) {
3102 case NL80211_IFTYPE_AP:
3103 sdata->u.ap.next_beacon =
3104 cfg80211_beacon_dup(&params->beacon_after);
3105 if (!sdata->u.ap.next_beacon)
3106 return -ENOMEM;
3109 * With a count of 0, we don't have to wait for any
3110 * TBTT before switching, so complete the CSA
3111 * immediately. In theory, with a count == 1 we
3112 * should delay the switch until just before the next
3113 * TBTT, but that would complicate things so we switch
3114 * immediately too. If we would delay the switch
3115 * until the next TBTT, we would have to set the probe
3116 * response here.
3118 * TODO: A channel switch with count <= 1 without
3119 * sending a CSA action frame is kind of useless,
3120 * because the clients won't know we're changing
3121 * channels. The action frame must be implemented
3122 * either here or in the userspace.
3124 if (params->count <= 1)
3125 break;
3127 if ((params->n_counter_offsets_beacon >
3128 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3129 (params->n_counter_offsets_presp >
3130 IEEE80211_MAX_CSA_COUNTERS_NUM))
3131 return -EINVAL;
3133 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3134 csa.counter_offsets_presp = params->counter_offsets_presp;
3135 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3136 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3137 csa.count = params->count;
3139 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
3140 if (err < 0) {
3141 kfree(sdata->u.ap.next_beacon);
3142 return err;
3144 *changed |= err;
3146 break;
3147 case NL80211_IFTYPE_ADHOC:
3148 if (!sdata->vif.bss_conf.ibss_joined)
3149 return -EINVAL;
3151 if (params->chandef.width != sdata->u.ibss.chandef.width)
3152 return -EINVAL;
3154 switch (params->chandef.width) {
3155 case NL80211_CHAN_WIDTH_40:
3156 if (cfg80211_get_chandef_type(&params->chandef) !=
3157 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3158 return -EINVAL;
3159 case NL80211_CHAN_WIDTH_5:
3160 case NL80211_CHAN_WIDTH_10:
3161 case NL80211_CHAN_WIDTH_20_NOHT:
3162 case NL80211_CHAN_WIDTH_20:
3163 break;
3164 default:
3165 return -EINVAL;
3168 /* changes into another band are not supported */
3169 if (sdata->u.ibss.chandef.chan->band !=
3170 params->chandef.chan->band)
3171 return -EINVAL;
3173 /* see comments in the NL80211_IFTYPE_AP block */
3174 if (params->count > 1) {
3175 err = ieee80211_ibss_csa_beacon(sdata, params);
3176 if (err < 0)
3177 return err;
3178 *changed |= err;
3181 ieee80211_send_action_csa(sdata, params);
3183 break;
3184 #ifdef CONFIG_MAC80211_MESH
3185 case NL80211_IFTYPE_MESH_POINT: {
3186 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3188 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3189 return -EINVAL;
3191 /* changes into another band are not supported */
3192 if (sdata->vif.bss_conf.chandef.chan->band !=
3193 params->chandef.chan->band)
3194 return -EINVAL;
3196 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3197 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3198 if (!ifmsh->pre_value)
3199 ifmsh->pre_value = 1;
3200 else
3201 ifmsh->pre_value++;
3204 /* see comments in the NL80211_IFTYPE_AP block */
3205 if (params->count > 1) {
3206 err = ieee80211_mesh_csa_beacon(sdata, params);
3207 if (err < 0) {
3208 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3209 return err;
3211 *changed |= err;
3214 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3215 ieee80211_send_action_csa(sdata, params);
3217 break;
3219 #endif
3220 default:
3221 return -EOPNOTSUPP;
3224 return 0;
3227 static int
3228 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3229 struct cfg80211_csa_settings *params)
3231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3232 struct ieee80211_local *local = sdata->local;
3233 struct ieee80211_channel_switch ch_switch;
3234 struct ieee80211_chanctx_conf *conf;
3235 struct ieee80211_chanctx *chanctx;
3236 u32 changed = 0;
3237 int err;
3239 sdata_assert_lock(sdata);
3240 lockdep_assert_held(&local->mtx);
3242 if (!list_empty(&local->roc_list) || local->scanning)
3243 return -EBUSY;
3245 if (sdata->wdev.cac_started)
3246 return -EBUSY;
3248 if (cfg80211_chandef_identical(&params->chandef,
3249 &sdata->vif.bss_conf.chandef))
3250 return -EINVAL;
3252 /* don't allow another channel switch if one is already active. */
3253 if (sdata->vif.csa_active)
3254 return -EBUSY;
3256 mutex_lock(&local->chanctx_mtx);
3257 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3258 lockdep_is_held(&local->chanctx_mtx));
3259 if (!conf) {
3260 err = -EBUSY;
3261 goto out;
3264 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3266 ch_switch.timestamp = 0;
3267 ch_switch.device_timestamp = 0;
3268 ch_switch.block_tx = params->block_tx;
3269 ch_switch.chandef = params->chandef;
3270 ch_switch.count = params->count;
3272 err = drv_pre_channel_switch(sdata, &ch_switch);
3273 if (err)
3274 goto out;
3276 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3277 chanctx->mode,
3278 params->radar_required);
3279 if (err)
3280 goto out;
3282 /* if reservation is invalid then this will fail */
3283 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3284 if (err) {
3285 ieee80211_vif_unreserve_chanctx(sdata);
3286 goto out;
3289 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3290 if (err) {
3291 ieee80211_vif_unreserve_chanctx(sdata);
3292 goto out;
3295 sdata->csa_chandef = params->chandef;
3296 sdata->csa_block_tx = params->block_tx;
3297 sdata->vif.csa_active = true;
3299 if (sdata->csa_block_tx)
3300 ieee80211_stop_vif_queues(local, sdata,
3301 IEEE80211_QUEUE_STOP_REASON_CSA);
3303 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3304 params->count);
3306 if (changed) {
3307 ieee80211_bss_info_change_notify(sdata, changed);
3308 drv_channel_switch_beacon(sdata, &params->chandef);
3309 } else {
3310 /* if the beacon didn't change, we can finalize immediately */
3311 ieee80211_csa_finalize(sdata);
3314 out:
3315 mutex_unlock(&local->chanctx_mtx);
3316 return err;
3319 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3320 struct cfg80211_csa_settings *params)
3322 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3323 struct ieee80211_local *local = sdata->local;
3324 int err;
3326 mutex_lock(&local->mtx);
3327 err = __ieee80211_channel_switch(wiphy, dev, params);
3328 mutex_unlock(&local->mtx);
3330 return err;
3333 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3335 lockdep_assert_held(&local->mtx);
3337 local->roc_cookie_counter++;
3339 /* wow, you wrapped 64 bits ... more likely a bug */
3340 if (WARN_ON(local->roc_cookie_counter == 0))
3341 local->roc_cookie_counter++;
3343 return local->roc_cookie_counter;
3346 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3347 u64 *cookie, gfp_t gfp)
3349 unsigned long spin_flags;
3350 struct sk_buff *ack_skb;
3351 int id;
3353 ack_skb = skb_copy(skb, gfp);
3354 if (!ack_skb)
3355 return -ENOMEM;
3357 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3358 id = idr_alloc(&local->ack_status_frames, ack_skb,
3359 1, 0x10000, GFP_ATOMIC);
3360 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3362 if (id < 0) {
3363 kfree_skb(ack_skb);
3364 return -ENOMEM;
3367 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3369 *cookie = ieee80211_mgmt_tx_cookie(local);
3370 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3372 return 0;
3375 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
3376 struct wireless_dev *wdev,
3377 u16 frame_type, bool reg)
3379 struct ieee80211_local *local = wiphy_priv(wiphy);
3380 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3382 switch (frame_type) {
3383 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3384 if (reg) {
3385 local->probe_req_reg++;
3386 sdata->vif.probe_req_reg++;
3387 } else {
3388 if (local->probe_req_reg)
3389 local->probe_req_reg--;
3391 if (sdata->vif.probe_req_reg)
3392 sdata->vif.probe_req_reg--;
3395 if (!local->open_count)
3396 break;
3398 if (sdata->vif.probe_req_reg == 1)
3399 drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
3400 FIF_PROBE_REQ);
3401 else if (sdata->vif.probe_req_reg == 0)
3402 drv_config_iface_filter(local, sdata, 0,
3403 FIF_PROBE_REQ);
3405 ieee80211_configure_filter(local);
3406 break;
3407 default:
3408 break;
3412 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3414 struct ieee80211_local *local = wiphy_priv(wiphy);
3416 if (local->started)
3417 return -EOPNOTSUPP;
3419 return drv_set_antenna(local, tx_ant, rx_ant);
3422 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3424 struct ieee80211_local *local = wiphy_priv(wiphy);
3426 return drv_get_antenna(local, tx_ant, rx_ant);
3429 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3430 struct net_device *dev,
3431 struct cfg80211_gtk_rekey_data *data)
3433 struct ieee80211_local *local = wiphy_priv(wiphy);
3434 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3436 if (!local->ops->set_rekey_data)
3437 return -EOPNOTSUPP;
3439 drv_set_rekey_data(local, sdata, data);
3441 return 0;
3444 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3445 const u8 *peer, u64 *cookie)
3447 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3448 struct ieee80211_local *local = sdata->local;
3449 struct ieee80211_qos_hdr *nullfunc;
3450 struct sk_buff *skb;
3451 int size = sizeof(*nullfunc);
3452 __le16 fc;
3453 bool qos;
3454 struct ieee80211_tx_info *info;
3455 struct sta_info *sta;
3456 struct ieee80211_chanctx_conf *chanctx_conf;
3457 enum nl80211_band band;
3458 int ret;
3460 /* the lock is needed to assign the cookie later */
3461 mutex_lock(&local->mtx);
3463 rcu_read_lock();
3464 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3465 if (WARN_ON(!chanctx_conf)) {
3466 ret = -EINVAL;
3467 goto unlock;
3469 band = chanctx_conf->def.chan->band;
3470 sta = sta_info_get_bss(sdata, peer);
3471 if (sta) {
3472 qos = sta->sta.wme;
3473 } else {
3474 ret = -ENOLINK;
3475 goto unlock;
3478 if (qos) {
3479 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3480 IEEE80211_STYPE_QOS_NULLFUNC |
3481 IEEE80211_FCTL_FROMDS);
3482 } else {
3483 size -= 2;
3484 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3485 IEEE80211_STYPE_NULLFUNC |
3486 IEEE80211_FCTL_FROMDS);
3489 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3490 if (!skb) {
3491 ret = -ENOMEM;
3492 goto unlock;
3495 skb->dev = dev;
3497 skb_reserve(skb, local->hw.extra_tx_headroom);
3499 nullfunc = skb_put(skb, size);
3500 nullfunc->frame_control = fc;
3501 nullfunc->duration_id = 0;
3502 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3503 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3504 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3505 nullfunc->seq_ctrl = 0;
3507 info = IEEE80211_SKB_CB(skb);
3509 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3510 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3511 info->band = band;
3513 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3514 skb->priority = 7;
3515 if (qos)
3516 nullfunc->qos_ctrl = cpu_to_le16(7);
3518 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3519 if (ret) {
3520 kfree_skb(skb);
3521 goto unlock;
3524 local_bh_disable();
3525 ieee80211_xmit(sdata, sta, skb, 0);
3526 local_bh_enable();
3528 ret = 0;
3529 unlock:
3530 rcu_read_unlock();
3531 mutex_unlock(&local->mtx);
3533 return ret;
3536 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3537 struct wireless_dev *wdev,
3538 struct cfg80211_chan_def *chandef)
3540 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3541 struct ieee80211_local *local = wiphy_priv(wiphy);
3542 struct ieee80211_chanctx_conf *chanctx_conf;
3543 int ret = -ENODATA;
3545 rcu_read_lock();
3546 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3547 if (chanctx_conf) {
3548 *chandef = sdata->vif.bss_conf.chandef;
3549 ret = 0;
3550 } else if (local->open_count > 0 &&
3551 local->open_count == local->monitors &&
3552 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3553 if (local->use_chanctx)
3554 *chandef = local->monitor_chandef;
3555 else
3556 *chandef = local->_oper_chandef;
3557 ret = 0;
3559 rcu_read_unlock();
3561 return ret;
3564 #ifdef CONFIG_PM
3565 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3567 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3569 #endif
3571 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3572 struct net_device *dev,
3573 struct cfg80211_qos_map *qos_map)
3575 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3576 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3578 if (qos_map) {
3579 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3580 if (!new_qos_map)
3581 return -ENOMEM;
3582 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3583 } else {
3584 /* A NULL qos_map was passed to disable QoS mapping */
3585 new_qos_map = NULL;
3588 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3589 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3590 if (old_qos_map)
3591 kfree_rcu(old_qos_map, rcu_head);
3593 return 0;
3596 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3597 struct net_device *dev,
3598 struct cfg80211_chan_def *chandef)
3600 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3601 int ret;
3602 u32 changed = 0;
3604 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3605 if (ret == 0)
3606 ieee80211_bss_info_change_notify(sdata, changed);
3608 return ret;
3611 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3612 u8 tsid, const u8 *peer, u8 up,
3613 u16 admitted_time)
3615 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3616 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3617 int ac = ieee802_1d_to_ac[up];
3619 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3620 return -EOPNOTSUPP;
3622 if (!(sdata->wmm_acm & BIT(up)))
3623 return -EINVAL;
3625 if (ifmgd->tx_tspec[ac].admitted_time)
3626 return -EBUSY;
3628 if (admitted_time) {
3629 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3630 ifmgd->tx_tspec[ac].tsid = tsid;
3631 ifmgd->tx_tspec[ac].up = up;
3634 return 0;
3637 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3638 u8 tsid, const u8 *peer)
3640 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3641 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3642 struct ieee80211_local *local = wiphy_priv(wiphy);
3643 int ac;
3645 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3646 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3648 /* skip unused entries */
3649 if (!tx_tspec->admitted_time)
3650 continue;
3652 if (tx_tspec->tsid != tsid)
3653 continue;
3655 /* due to this new packets will be reassigned to non-ACM ACs */
3656 tx_tspec->up = -1;
3658 /* Make sure that all packets have been sent to avoid to
3659 * restore the QoS params on packets that are still on the
3660 * queues.
3662 synchronize_net();
3663 ieee80211_flush_queues(local, sdata, false);
3665 /* restore the normal QoS parameters
3666 * (unconditionally to avoid races)
3668 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3669 tx_tspec->downgraded = false;
3670 ieee80211_sta_handle_tspec_ac_params(sdata);
3672 /* finally clear all the data */
3673 memset(tx_tspec, 0, sizeof(*tx_tspec));
3675 return 0;
3678 return -ENOENT;
3681 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
3682 u8 inst_id,
3683 enum nl80211_nan_func_term_reason reason,
3684 gfp_t gfp)
3686 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3687 struct cfg80211_nan_func *func;
3688 u64 cookie;
3690 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3691 return;
3693 spin_lock_bh(&sdata->u.nan.func_lock);
3695 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
3696 if (WARN_ON(!func)) {
3697 spin_unlock_bh(&sdata->u.nan.func_lock);
3698 return;
3701 cookie = func->cookie;
3702 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
3704 spin_unlock_bh(&sdata->u.nan.func_lock);
3706 cfg80211_free_nan_func(func);
3708 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
3709 reason, cookie, gfp);
3711 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
3713 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
3714 struct cfg80211_nan_match_params *match,
3715 gfp_t gfp)
3717 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3718 struct cfg80211_nan_func *func;
3720 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3721 return;
3723 spin_lock_bh(&sdata->u.nan.func_lock);
3725 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
3726 if (WARN_ON(!func)) {
3727 spin_unlock_bh(&sdata->u.nan.func_lock);
3728 return;
3730 match->cookie = func->cookie;
3732 spin_unlock_bh(&sdata->u.nan.func_lock);
3734 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
3736 EXPORT_SYMBOL(ieee80211_nan_func_match);
3738 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
3739 struct net_device *dev,
3740 const bool enabled)
3742 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3744 sdata->u.ap.multicast_to_unicast = enabled;
3746 return 0;
3749 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
3750 struct txq_info *txqi)
3752 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
3753 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
3754 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
3757 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
3758 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
3759 txqstats->backlog_packets = txqi->tin.backlog_packets;
3762 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
3763 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
3764 txqstats->flows = txqi->tin.flows;
3767 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
3768 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
3769 txqstats->drops = txqi->cstats.drop_count;
3772 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
3773 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
3774 txqstats->ecn_marks = txqi->cstats.ecn_mark;
3777 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
3778 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
3779 txqstats->overlimit = txqi->tin.overlimit;
3782 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
3783 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
3784 txqstats->collisions = txqi->tin.collisions;
3787 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
3788 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
3789 txqstats->tx_bytes = txqi->tin.tx_bytes;
3792 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
3793 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
3794 txqstats->tx_packets = txqi->tin.tx_packets;
3798 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
3799 struct wireless_dev *wdev,
3800 struct cfg80211_txq_stats *txqstats)
3802 struct ieee80211_local *local = wiphy_priv(wiphy);
3803 struct ieee80211_sub_if_data *sdata;
3804 int ret = 0;
3806 if (!local->ops->wake_tx_queue)
3807 return 1;
3809 spin_lock_bh(&local->fq.lock);
3810 rcu_read_lock();
3812 if (wdev) {
3813 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3814 if (!sdata->vif.txq) {
3815 ret = 1;
3816 goto out;
3818 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
3819 } else {
3820 /* phy stats */
3821 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
3822 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
3823 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
3824 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
3825 BIT(NL80211_TXQ_STATS_COLLISIONS) |
3826 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
3827 txqstats->backlog_packets = local->fq.backlog;
3828 txqstats->backlog_bytes = local->fq.memory_usage;
3829 txqstats->overlimit = local->fq.overlimit;
3830 txqstats->overmemory = local->fq.overmemory;
3831 txqstats->collisions = local->fq.collisions;
3832 txqstats->max_flows = local->fq.flows_cnt;
3835 out:
3836 rcu_read_unlock();
3837 spin_unlock_bh(&local->fq.lock);
3839 return ret;
3842 static int
3843 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
3844 struct net_device *dev,
3845 struct cfg80211_ftm_responder_stats *ftm_stats)
3847 struct ieee80211_local *local = wiphy_priv(wiphy);
3848 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3850 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
3853 const struct cfg80211_ops mac80211_config_ops = {
3854 .add_virtual_intf = ieee80211_add_iface,
3855 .del_virtual_intf = ieee80211_del_iface,
3856 .change_virtual_intf = ieee80211_change_iface,
3857 .start_p2p_device = ieee80211_start_p2p_device,
3858 .stop_p2p_device = ieee80211_stop_p2p_device,
3859 .add_key = ieee80211_add_key,
3860 .del_key = ieee80211_del_key,
3861 .get_key = ieee80211_get_key,
3862 .set_default_key = ieee80211_config_default_key,
3863 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3864 .start_ap = ieee80211_start_ap,
3865 .change_beacon = ieee80211_change_beacon,
3866 .stop_ap = ieee80211_stop_ap,
3867 .add_station = ieee80211_add_station,
3868 .del_station = ieee80211_del_station,
3869 .change_station = ieee80211_change_station,
3870 .get_station = ieee80211_get_station,
3871 .dump_station = ieee80211_dump_station,
3872 .dump_survey = ieee80211_dump_survey,
3873 #ifdef CONFIG_MAC80211_MESH
3874 .add_mpath = ieee80211_add_mpath,
3875 .del_mpath = ieee80211_del_mpath,
3876 .change_mpath = ieee80211_change_mpath,
3877 .get_mpath = ieee80211_get_mpath,
3878 .dump_mpath = ieee80211_dump_mpath,
3879 .get_mpp = ieee80211_get_mpp,
3880 .dump_mpp = ieee80211_dump_mpp,
3881 .update_mesh_config = ieee80211_update_mesh_config,
3882 .get_mesh_config = ieee80211_get_mesh_config,
3883 .join_mesh = ieee80211_join_mesh,
3884 .leave_mesh = ieee80211_leave_mesh,
3885 #endif
3886 .join_ocb = ieee80211_join_ocb,
3887 .leave_ocb = ieee80211_leave_ocb,
3888 .change_bss = ieee80211_change_bss,
3889 .set_txq_params = ieee80211_set_txq_params,
3890 .set_monitor_channel = ieee80211_set_monitor_channel,
3891 .suspend = ieee80211_suspend,
3892 .resume = ieee80211_resume,
3893 .scan = ieee80211_scan,
3894 .abort_scan = ieee80211_abort_scan,
3895 .sched_scan_start = ieee80211_sched_scan_start,
3896 .sched_scan_stop = ieee80211_sched_scan_stop,
3897 .auth = ieee80211_auth,
3898 .assoc = ieee80211_assoc,
3899 .deauth = ieee80211_deauth,
3900 .disassoc = ieee80211_disassoc,
3901 .join_ibss = ieee80211_join_ibss,
3902 .leave_ibss = ieee80211_leave_ibss,
3903 .set_mcast_rate = ieee80211_set_mcast_rate,
3904 .set_wiphy_params = ieee80211_set_wiphy_params,
3905 .set_tx_power = ieee80211_set_tx_power,
3906 .get_tx_power = ieee80211_get_tx_power,
3907 .set_wds_peer = ieee80211_set_wds_peer,
3908 .rfkill_poll = ieee80211_rfkill_poll,
3909 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3910 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3911 .set_power_mgmt = ieee80211_set_power_mgmt,
3912 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3913 .remain_on_channel = ieee80211_remain_on_channel,
3914 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3915 .mgmt_tx = ieee80211_mgmt_tx,
3916 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3917 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3918 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
3919 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3920 .set_antenna = ieee80211_set_antenna,
3921 .get_antenna = ieee80211_get_antenna,
3922 .set_rekey_data = ieee80211_set_rekey_data,
3923 .tdls_oper = ieee80211_tdls_oper,
3924 .tdls_mgmt = ieee80211_tdls_mgmt,
3925 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3926 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
3927 .probe_client = ieee80211_probe_client,
3928 .set_noack_map = ieee80211_set_noack_map,
3929 #ifdef CONFIG_PM
3930 .set_wakeup = ieee80211_set_wakeup,
3931 #endif
3932 .get_channel = ieee80211_cfg_get_channel,
3933 .start_radar_detection = ieee80211_start_radar_detection,
3934 .channel_switch = ieee80211_channel_switch,
3935 .set_qos_map = ieee80211_set_qos_map,
3936 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
3937 .add_tx_ts = ieee80211_add_tx_ts,
3938 .del_tx_ts = ieee80211_del_tx_ts,
3939 .start_nan = ieee80211_start_nan,
3940 .stop_nan = ieee80211_stop_nan,
3941 .nan_change_conf = ieee80211_nan_change_conf,
3942 .add_nan_func = ieee80211_add_nan_func,
3943 .del_nan_func = ieee80211_del_nan_func,
3944 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
3945 .tx_control_port = ieee80211_tx_control_port,
3946 .get_txq_stats = ieee80211_get_txq_stats,
3947 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,