1 // SPDX-License-Identifier: GPL-2.0-only
3 * mac80211 configuration hooks for cfg80211
5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2015 Intel Mobile Communications GmbH
7 * Copyright (C) 2015-2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2021 Intel Corporation
11 #include <linux/ieee80211.h>
12 #include <linux/nl80211.h>
13 #include <linux/rtnetlink.h>
14 #include <linux/slab.h>
15 #include <net/net_namespace.h>
16 #include <linux/rcupdate.h>
17 #include <linux/fips.h>
18 #include <linux/if_ether.h>
19 #include <net/cfg80211.h>
20 #include "ieee80211_i.h"
21 #include "driver-ops.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) {
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,
46 mu_mimo_groups = membership != 0;
49 if (params->vht_mumimo_follow_addr) {
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
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))
82 /* also validate MU-MIMO change */
83 monitor_sdata = wiphy_dereference(local->hw.wiphy,
84 local->monitor_sdata);
87 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
90 /* apply all changes now - no failures allowed */
93 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
96 if (ieee80211_sdata_running(sdata)) {
97 ieee80211_adjust_monitor_flags(sdata, -1);
98 sdata->u.mntr.flags = params->flags;
99 ieee80211_adjust_monitor_flags(sdata, 1);
101 ieee80211_configure_filter(local);
104 * Because the interface is down, ieee80211_do_stop
105 * and ieee80211_do_open take care of "everything"
106 * mentioned in the comment above.
108 sdata->u.mntr.flags = params->flags;
115 static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
116 struct cfg80211_mbssid_config params)
118 struct ieee80211_sub_if_data *tx_sdata;
120 sdata->vif.mbssid_tx_vif = NULL;
121 sdata->vif.bss_conf.bssid_index = 0;
122 sdata->vif.bss_conf.nontransmitted = false;
123 sdata->vif.bss_conf.ema_ap = false;
125 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
128 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
132 if (tx_sdata == sdata) {
133 sdata->vif.mbssid_tx_vif = &sdata->vif;
135 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
136 sdata->vif.bss_conf.nontransmitted = true;
137 sdata->vif.bss_conf.bssid_index = params.index;
140 sdata->vif.bss_conf.ema_ap = true;
145 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
147 unsigned char name_assign_type,
148 enum nl80211_iftype type,
149 struct vif_params *params)
151 struct ieee80211_local *local = wiphy_priv(wiphy);
152 struct wireless_dev *wdev;
153 struct ieee80211_sub_if_data *sdata;
156 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
160 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
162 if (type == NL80211_IFTYPE_MONITOR) {
163 err = ieee80211_set_mon_options(sdata, params);
165 ieee80211_if_remove(sdata);
173 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
175 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
180 static int ieee80211_change_iface(struct wiphy *wiphy,
181 struct net_device *dev,
182 enum nl80211_iftype type,
183 struct vif_params *params)
185 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
186 struct ieee80211_local *local = sdata->local;
187 struct sta_info *sta;
190 ret = ieee80211_if_change_type(sdata, type);
194 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
195 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
196 ieee80211_check_fast_rx_iface(sdata);
197 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
198 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
200 if (params->use_4addr == ifmgd->use_4addr)
203 sdata->u.mgd.use_4addr = params->use_4addr;
204 if (!ifmgd->associated)
207 mutex_lock(&local->sta_mtx);
208 sta = sta_info_get(sdata, ifmgd->bssid);
210 drv_sta_set_4addr(local, sdata, &sta->sta,
212 mutex_unlock(&local->sta_mtx);
214 if (params->use_4addr)
215 ieee80211_send_4addr_nullfunc(local, sdata);
218 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
219 ret = ieee80211_set_mon_options(sdata, params);
227 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
228 struct wireless_dev *wdev)
230 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
233 mutex_lock(&sdata->local->chanctx_mtx);
234 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
235 mutex_unlock(&sdata->local->chanctx_mtx);
239 return ieee80211_do_open(wdev, true);
242 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
243 struct wireless_dev *wdev)
245 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
248 static int ieee80211_start_nan(struct wiphy *wiphy,
249 struct wireless_dev *wdev,
250 struct cfg80211_nan_conf *conf)
252 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
255 mutex_lock(&sdata->local->chanctx_mtx);
256 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
257 mutex_unlock(&sdata->local->chanctx_mtx);
261 ret = ieee80211_do_open(wdev, true);
265 ret = drv_start_nan(sdata->local, sdata, conf);
267 ieee80211_sdata_stop(sdata);
269 sdata->u.nan.conf = *conf;
274 static void ieee80211_stop_nan(struct wiphy *wiphy,
275 struct wireless_dev *wdev)
277 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
279 drv_stop_nan(sdata->local, sdata);
280 ieee80211_sdata_stop(sdata);
283 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
284 struct wireless_dev *wdev,
285 struct cfg80211_nan_conf *conf,
288 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
289 struct cfg80211_nan_conf new_conf;
292 if (sdata->vif.type != NL80211_IFTYPE_NAN)
295 if (!ieee80211_sdata_running(sdata))
298 new_conf = sdata->u.nan.conf;
300 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
301 new_conf.master_pref = conf->master_pref;
303 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
304 new_conf.bands = conf->bands;
306 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
308 sdata->u.nan.conf = new_conf;
313 static int ieee80211_add_nan_func(struct wiphy *wiphy,
314 struct wireless_dev *wdev,
315 struct cfg80211_nan_func *nan_func)
317 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
320 if (sdata->vif.type != NL80211_IFTYPE_NAN)
323 if (!ieee80211_sdata_running(sdata))
326 spin_lock_bh(&sdata->u.nan.func_lock);
328 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
329 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
331 spin_unlock_bh(&sdata->u.nan.func_lock);
336 nan_func->instance_id = ret;
338 WARN_ON(nan_func->instance_id == 0);
340 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
342 spin_lock_bh(&sdata->u.nan.func_lock);
343 idr_remove(&sdata->u.nan.function_inst_ids,
344 nan_func->instance_id);
345 spin_unlock_bh(&sdata->u.nan.func_lock);
351 static struct cfg80211_nan_func *
352 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
355 struct cfg80211_nan_func *func;
358 lockdep_assert_held(&sdata->u.nan.func_lock);
360 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
361 if (func->cookie == cookie)
368 static void ieee80211_del_nan_func(struct wiphy *wiphy,
369 struct wireless_dev *wdev, u64 cookie)
371 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
372 struct cfg80211_nan_func *func;
375 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
376 !ieee80211_sdata_running(sdata))
379 spin_lock_bh(&sdata->u.nan.func_lock);
381 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
383 instance_id = func->instance_id;
385 spin_unlock_bh(&sdata->u.nan.func_lock);
388 drv_del_nan_func(sdata->local, sdata, instance_id);
391 static int ieee80211_set_noack_map(struct wiphy *wiphy,
392 struct net_device *dev,
395 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
397 sdata->noack_map = noack_map;
399 ieee80211_check_fast_xmit_iface(sdata);
404 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
405 const u8 *mac_addr, u8 key_idx)
407 struct ieee80211_local *local = sdata->local;
408 struct ieee80211_key *key;
409 struct sta_info *sta;
412 if (!wiphy_ext_feature_isset(local->hw.wiphy,
413 NL80211_EXT_FEATURE_EXT_KEY_ID))
416 sta = sta_info_get_bss(sdata, mac_addr);
421 if (sta->ptk_idx == key_idx)
424 mutex_lock(&local->key_mtx);
425 key = key_mtx_dereference(local, sta->ptk[key_idx]);
427 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
428 ret = ieee80211_set_tx_key(key);
430 mutex_unlock(&local->key_mtx);
434 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
435 u8 key_idx, bool pairwise, const u8 *mac_addr,
436 struct key_params *params)
438 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
439 struct ieee80211_local *local = sdata->local;
440 struct sta_info *sta = NULL;
441 const struct ieee80211_cipher_scheme *cs = NULL;
442 struct ieee80211_key *key;
445 if (!ieee80211_sdata_running(sdata))
448 if (pairwise && params->mode == NL80211_KEY_SET_TX)
449 return ieee80211_set_tx(sdata, mac_addr, key_idx);
451 /* reject WEP and TKIP keys if WEP failed to initialize */
452 switch (params->cipher) {
453 case WLAN_CIPHER_SUITE_WEP40:
454 case WLAN_CIPHER_SUITE_TKIP:
455 case WLAN_CIPHER_SUITE_WEP104:
456 if (WARN_ON_ONCE(fips_enabled))
459 case WLAN_CIPHER_SUITE_CCMP:
460 case WLAN_CIPHER_SUITE_CCMP_256:
461 case WLAN_CIPHER_SUITE_AES_CMAC:
462 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
463 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
464 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
465 case WLAN_CIPHER_SUITE_GCMP:
466 case WLAN_CIPHER_SUITE_GCMP_256:
469 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
473 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
474 params->key, params->seq_len, params->seq,
480 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
482 if (params->mode == NL80211_KEY_NO_TX)
483 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
485 mutex_lock(&local->sta_mtx);
488 sta = sta_info_get_bss(sdata, mac_addr);
490 * The ASSOC test makes sure the driver is ready to
491 * receive the key. When wpa_supplicant has roamed
492 * using FT, it attempts to set the key before
493 * association has completed, this rejects that attempt
494 * so it will set the key again after association.
496 * TODO: accept the key if we have a station entry and
497 * add it to the device after the station.
499 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
500 ieee80211_key_free_unused(key);
506 switch (sdata->vif.type) {
507 case NL80211_IFTYPE_STATION:
508 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
509 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
511 case NL80211_IFTYPE_AP:
512 case NL80211_IFTYPE_AP_VLAN:
513 /* Keys without a station are used for TX only */
514 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
515 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
517 case NL80211_IFTYPE_ADHOC:
520 case NL80211_IFTYPE_MESH_POINT:
521 #ifdef CONFIG_MAC80211_MESH
522 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
523 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
526 case NL80211_IFTYPE_WDS:
527 case NL80211_IFTYPE_MONITOR:
528 case NL80211_IFTYPE_P2P_DEVICE:
529 case NL80211_IFTYPE_NAN:
530 case NL80211_IFTYPE_UNSPECIFIED:
531 case NUM_NL80211_IFTYPES:
532 case NL80211_IFTYPE_P2P_CLIENT:
533 case NL80211_IFTYPE_P2P_GO:
534 case NL80211_IFTYPE_OCB:
535 /* shouldn't happen */
541 sta->cipher_scheme = cs;
543 err = ieee80211_key_link(key, sdata, sta);
546 mutex_unlock(&local->sta_mtx);
551 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
552 u8 key_idx, bool pairwise, const u8 *mac_addr)
554 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555 struct ieee80211_local *local = sdata->local;
556 struct sta_info *sta;
557 struct ieee80211_key *key = NULL;
560 mutex_lock(&local->sta_mtx);
561 mutex_lock(&local->key_mtx);
566 sta = sta_info_get_bss(sdata, mac_addr);
571 key = key_mtx_dereference(local, sta->ptk[key_idx]);
573 key = key_mtx_dereference(local,
574 sta->deflink.gtk[key_idx]);
576 key = key_mtx_dereference(local, sdata->keys[key_idx]);
583 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
587 mutex_unlock(&local->key_mtx);
588 mutex_unlock(&local->sta_mtx);
593 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
594 u8 key_idx, bool pairwise, const u8 *mac_addr,
596 void (*callback)(void *cookie,
597 struct key_params *params))
599 struct ieee80211_sub_if_data *sdata;
600 struct sta_info *sta = NULL;
602 struct key_params params;
603 struct ieee80211_key *key = NULL;
608 struct ieee80211_key_seq kseq = {};
610 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
615 sta = sta_info_get_bss(sdata, mac_addr);
619 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
620 key = rcu_dereference(sta->ptk[key_idx]);
621 else if (!pairwise &&
622 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
623 NUM_DEFAULT_BEACON_KEYS)
624 key = rcu_dereference(sta->deflink.gtk[key_idx]);
626 key = rcu_dereference(sdata->keys[key_idx]);
631 memset(¶ms, 0, sizeof(params));
633 params.cipher = key->conf.cipher;
635 switch (key->conf.cipher) {
636 case WLAN_CIPHER_SUITE_TKIP:
637 pn64 = atomic64_read(&key->conf.tx_pn);
638 iv32 = TKIP_PN_TO_IV32(pn64);
639 iv16 = TKIP_PN_TO_IV16(pn64);
641 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
642 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
643 drv_get_key_seq(sdata->local, key, &kseq);
644 iv32 = kseq.tkip.iv32;
645 iv16 = kseq.tkip.iv16;
648 seq[0] = iv16 & 0xff;
649 seq[1] = (iv16 >> 8) & 0xff;
650 seq[2] = iv32 & 0xff;
651 seq[3] = (iv32 >> 8) & 0xff;
652 seq[4] = (iv32 >> 16) & 0xff;
653 seq[5] = (iv32 >> 24) & 0xff;
657 case WLAN_CIPHER_SUITE_CCMP:
658 case WLAN_CIPHER_SUITE_CCMP_256:
659 case WLAN_CIPHER_SUITE_AES_CMAC:
660 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
661 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
662 offsetof(typeof(kseq), aes_cmac));
664 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
665 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
666 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
667 offsetof(typeof(kseq), aes_gmac));
669 case WLAN_CIPHER_SUITE_GCMP:
670 case WLAN_CIPHER_SUITE_GCMP_256:
671 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
672 offsetof(typeof(kseq), gcmp));
674 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
675 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
676 drv_get_key_seq(sdata->local, key, &kseq);
677 memcpy(seq, kseq.ccmp.pn, 6);
679 pn64 = atomic64_read(&key->conf.tx_pn);
691 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
693 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
695 drv_get_key_seq(sdata->local, key, &kseq);
696 params.seq = kseq.hw.seq;
697 params.seq_len = kseq.hw.seq_len;
701 params.key = key->conf.key;
702 params.key_len = key->conf.keylen;
704 callback(cookie, ¶ms);
712 static int ieee80211_config_default_key(struct wiphy *wiphy,
713 struct net_device *dev,
714 u8 key_idx, bool uni,
717 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
719 ieee80211_set_default_key(sdata, key_idx, uni, multi);
724 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
725 struct net_device *dev,
728 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
730 ieee80211_set_default_mgmt_key(sdata, key_idx);
735 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
736 struct net_device *dev,
739 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
741 ieee80211_set_default_beacon_key(sdata, key_idx);
746 void sta_set_rate_info_tx(struct sta_info *sta,
747 const struct ieee80211_tx_rate *rate,
748 struct rate_info *rinfo)
751 if (rate->flags & IEEE80211_TX_RC_MCS) {
752 rinfo->flags |= RATE_INFO_FLAGS_MCS;
753 rinfo->mcs = rate->idx;
754 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
755 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
756 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
757 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
759 struct ieee80211_supported_band *sband;
760 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
763 sband = ieee80211_get_sband(sta->sdata);
764 WARN_ON_ONCE(sband && !sband->bitrates);
765 if (sband && sband->bitrates) {
766 brate = sband->bitrates[rate->idx].bitrate;
767 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
770 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
771 rinfo->bw = RATE_INFO_BW_40;
772 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
773 rinfo->bw = RATE_INFO_BW_80;
774 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
775 rinfo->bw = RATE_INFO_BW_160;
777 rinfo->bw = RATE_INFO_BW_20;
778 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
779 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
782 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
783 int idx, u8 *mac, struct station_info *sinfo)
785 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
786 struct ieee80211_local *local = sdata->local;
787 struct sta_info *sta;
790 mutex_lock(&local->sta_mtx);
792 sta = sta_info_get_by_idx(sdata, idx);
795 memcpy(mac, sta->sta.addr, ETH_ALEN);
796 sta_set_sinfo(sta, sinfo, true);
799 mutex_unlock(&local->sta_mtx);
804 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
805 int idx, struct survey_info *survey)
807 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
809 return drv_get_survey(local, idx, survey);
812 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
813 const u8 *mac, struct station_info *sinfo)
815 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
816 struct ieee80211_local *local = sdata->local;
817 struct sta_info *sta;
820 mutex_lock(&local->sta_mtx);
822 sta = sta_info_get_bss(sdata, mac);
825 sta_set_sinfo(sta, sinfo, true);
828 mutex_unlock(&local->sta_mtx);
833 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
834 struct cfg80211_chan_def *chandef)
836 struct ieee80211_local *local = wiphy_priv(wiphy);
837 struct ieee80211_sub_if_data *sdata;
840 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
843 mutex_lock(&local->mtx);
844 if (local->use_chanctx) {
845 sdata = wiphy_dereference(local->hw.wiphy,
846 local->monitor_sdata);
848 ieee80211_vif_release_channel(sdata);
849 ret = ieee80211_vif_use_channel(sdata, chandef,
850 IEEE80211_CHANCTX_EXCLUSIVE);
852 } else if (local->open_count == local->monitors) {
853 local->_oper_chandef = *chandef;
854 ieee80211_hw_config(local, 0);
858 local->monitor_chandef = *chandef;
859 mutex_unlock(&local->mtx);
865 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
866 const u8 *resp, size_t resp_len,
867 const struct ieee80211_csa_settings *csa,
868 const struct ieee80211_color_change_settings *cca)
870 struct probe_resp *new, *old;
872 if (!resp || !resp_len)
875 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
877 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
882 memcpy(new->data, resp, resp_len);
885 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
886 csa->n_counter_offsets_presp *
887 sizeof(new->cntdwn_counter_offsets[0]));
889 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
891 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
893 kfree_rcu(old, rcu_head);
898 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
899 struct cfg80211_fils_discovery *params)
901 struct fils_discovery_data *new, *old = NULL;
902 struct ieee80211_fils_discovery *fd;
904 if (!params->tmpl || !params->tmpl_len)
907 fd = &sdata->vif.bss_conf.fils_discovery;
908 fd->min_interval = params->min_interval;
909 fd->max_interval = params->max_interval;
911 old = sdata_dereference(sdata->u.ap.fils_discovery, sdata);
912 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
915 new->len = params->tmpl_len;
916 memcpy(new->data, params->tmpl, params->tmpl_len);
917 rcu_assign_pointer(sdata->u.ap.fils_discovery, new);
920 kfree_rcu(old, rcu_head);
926 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
927 struct cfg80211_unsol_bcast_probe_resp *params)
929 struct unsol_bcast_probe_resp_data *new, *old = NULL;
931 if (!params->tmpl || !params->tmpl_len)
934 old = sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp, sdata);
935 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
938 new->len = params->tmpl_len;
939 memcpy(new->data, params->tmpl, params->tmpl_len);
940 rcu_assign_pointer(sdata->u.ap.unsol_bcast_probe_resp, new);
943 kfree_rcu(old, rcu_head);
945 sdata->vif.bss_conf.unsol_bcast_probe_resp_interval =
951 static int ieee80211_set_ftm_responder_params(
952 struct ieee80211_sub_if_data *sdata,
953 const u8 *lci, size_t lci_len,
954 const u8 *civicloc, size_t civicloc_len)
956 struct ieee80211_ftm_responder_params *new, *old;
957 struct ieee80211_bss_conf *bss_conf;
961 if (!lci_len && !civicloc_len)
964 bss_conf = &sdata->vif.bss_conf;
965 old = bss_conf->ftmr_params;
966 len = lci_len + civicloc_len;
968 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
972 pos = (u8 *)(new + 1);
974 new->lci_len = lci_len;
976 memcpy(pos, lci, lci_len);
981 new->civicloc_len = civicloc_len;
983 memcpy(pos, civicloc, civicloc_len);
987 bss_conf->ftmr_params = new;
994 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
995 struct cfg80211_mbssid_elems *src)
999 for (i = 0; i < src->cnt; i++) {
1000 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1001 dst->elem[i].len = src->elem[i].len;
1002 dst->elem[i].data = pos + offset;
1003 offset += dst->elem[i].len;
1005 dst->cnt = src->cnt;
1010 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1011 struct cfg80211_beacon_data *params,
1012 const struct ieee80211_csa_settings *csa,
1013 const struct ieee80211_color_change_settings *cca)
1015 struct cfg80211_mbssid_elems *mbssid = NULL;
1016 struct beacon_data *new, *old;
1017 int new_head_len, new_tail_len;
1019 u32 changed = BSS_CHANGED_BEACON;
1021 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1024 /* Need to have a beacon head if we don't have one yet */
1025 if (!params->head && !old)
1028 /* new or old head? */
1030 new_head_len = params->head_len;
1032 new_head_len = old->head_len;
1034 /* new or old tail? */
1035 if (params->tail || !old)
1036 /* params->tail_len will be zero for !params->tail */
1037 new_tail_len = params->tail_len;
1039 new_tail_len = old->tail_len;
1041 size = sizeof(*new) + new_head_len + new_tail_len;
1043 /* new or old multiple BSSID elements? */
1044 if (params->mbssid_ies) {
1045 mbssid = params->mbssid_ies;
1046 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1047 size += ieee80211_get_mbssid_beacon_len(mbssid);
1048 } else if (old && old->mbssid_ies) {
1049 mbssid = old->mbssid_ies;
1050 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1051 size += ieee80211_get_mbssid_beacon_len(mbssid);
1054 new = kzalloc(size, GFP_KERNEL);
1058 /* start filling the new info now */
1061 * pointers go into the block we allocated,
1062 * memory is | beacon_data | head | tail | mbssid_ies
1064 new->head = ((u8 *) new) + sizeof(*new);
1065 new->tail = new->head + new_head_len;
1066 new->head_len = new_head_len;
1067 new->tail_len = new_tail_len;
1068 /* copy in optional mbssid_ies */
1070 u8 *pos = new->tail + new->tail_len;
1072 new->mbssid_ies = (void *)pos;
1073 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1074 ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid);
1075 /* update bssid_indicator */
1076 sdata->vif.bss_conf.bssid_indicator =
1077 ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
1081 new->cntdwn_current_counter = csa->count;
1082 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1083 csa->n_counter_offsets_beacon *
1084 sizeof(new->cntdwn_counter_offsets[0]));
1086 new->cntdwn_current_counter = cca->count;
1087 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1092 memcpy(new->head, params->head, new_head_len);
1094 memcpy(new->head, old->head, new_head_len);
1096 /* copy in optional tail */
1098 memcpy(new->tail, params->tail, new_tail_len);
1101 memcpy(new->tail, old->tail, new_tail_len);
1103 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1104 params->probe_resp_len, csa, cca);
1110 changed |= BSS_CHANGED_AP_PROBE_RESP;
1112 if (params->ftm_responder != -1) {
1113 sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
1114 err = ieee80211_set_ftm_responder_params(sdata,
1118 params->civicloc_len);
1125 changed |= BSS_CHANGED_FTM_RESPONDER;
1128 rcu_assign_pointer(sdata->u.ap.beacon, new);
1131 kfree_rcu(old, rcu_head);
1136 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1137 struct cfg80211_ap_settings *params)
1139 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1140 struct ieee80211_local *local = sdata->local;
1141 struct beacon_data *old;
1142 struct ieee80211_sub_if_data *vlan;
1143 u32 changed = BSS_CHANGED_BEACON_INT |
1144 BSS_CHANGED_BEACON_ENABLED |
1145 BSS_CHANGED_BEACON |
1147 BSS_CHANGED_P2P_PS |
1148 BSS_CHANGED_TXPOWER |
1151 int prev_beacon_int;
1153 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1157 if (params->smps_mode != NL80211_SMPS_OFF)
1160 sdata->smps_mode = IEEE80211_SMPS_OFF;
1162 sdata->needed_rx_chains = sdata->local->rx_chains;
1164 prev_beacon_int = sdata->vif.bss_conf.beacon_int;
1165 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
1167 if (params->he_cap && params->he_oper) {
1168 sdata->vif.bss_conf.he_support = true;
1169 sdata->vif.bss_conf.htc_trig_based_pkt_ext =
1170 le32_get_bits(params->he_oper->he_oper_params,
1171 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1172 sdata->vif.bss_conf.frame_time_rts_th =
1173 le32_get_bits(params->he_oper->he_oper_params,
1174 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1175 changed |= BSS_CHANGED_HE_OBSS_PD;
1177 if (params->beacon.he_bss_color.enabled)
1178 changed |= BSS_CHANGED_HE_BSS_COLOR;
1181 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1182 params->mbssid_config.tx_wdev) {
1183 err = ieee80211_set_ap_mbssid_options(sdata,
1184 params->mbssid_config);
1189 mutex_lock(&local->mtx);
1190 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
1191 IEEE80211_CHANCTX_SHARED);
1193 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
1194 mutex_unlock(&local->mtx);
1196 sdata->vif.bss_conf.beacon_int = prev_beacon_int;
1201 * Apply control port protocol, this allows us to
1202 * not encrypt dynamic WEP control frames.
1204 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1205 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1206 sdata->control_port_over_nl80211 =
1207 params->crypto.control_port_over_nl80211;
1208 sdata->control_port_no_preauth =
1209 params->crypto.control_port_no_preauth;
1210 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
1214 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1215 vlan->control_port_protocol =
1216 params->crypto.control_port_ethertype;
1217 vlan->control_port_no_encrypt =
1218 params->crypto.control_port_no_encrypt;
1219 vlan->control_port_over_nl80211 =
1220 params->crypto.control_port_over_nl80211;
1221 vlan->control_port_no_preauth =
1222 params->crypto.control_port_no_preauth;
1223 vlan->encrypt_headroom =
1224 ieee80211_cs_headroom(sdata->local,
1229 sdata->vif.bss_conf.dtim_period = params->dtim_period;
1230 sdata->vif.bss_conf.enable_beacon = true;
1231 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
1232 sdata->vif.bss_conf.twt_responder = params->twt_responder;
1233 sdata->vif.bss_conf.he_obss_pd = params->he_obss_pd;
1234 sdata->vif.bss_conf.he_bss_color = params->beacon.he_bss_color;
1235 sdata->vif.bss_conf.s1g = params->chandef.chan->band ==
1238 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1239 if (params->ssid_len)
1240 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1242 sdata->vif.bss_conf.hidden_ssid =
1243 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1245 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1246 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1247 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1248 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1249 if (params->p2p_opp_ps)
1250 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1251 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1253 sdata->beacon_rate_set = false;
1254 if (wiphy_ext_feature_isset(local->hw.wiphy,
1255 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1256 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1257 sdata->beacon_rateidx_mask[i] =
1258 params->beacon_rate.control[i].legacy;
1259 if (sdata->beacon_rateidx_mask[i])
1260 sdata->beacon_rate_set = true;
1264 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1265 sdata->vif.bss_conf.beacon_tx_rate = params->beacon_rate;
1267 err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL, NULL);
1272 if (params->fils_discovery.max_interval) {
1273 err = ieee80211_set_fils_discovery(sdata,
1274 ¶ms->fils_discovery);
1277 changed |= BSS_CHANGED_FILS_DISCOVERY;
1280 if (params->unsol_bcast_probe_resp.interval) {
1281 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1282 ¶ms->unsol_bcast_probe_resp);
1285 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1288 err = drv_start_ap(sdata->local, sdata);
1290 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1293 kfree_rcu(old, rcu_head);
1294 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1298 ieee80211_recalc_dtim(local, sdata);
1299 ieee80211_bss_info_change_notify(sdata, changed);
1301 netif_carrier_on(dev);
1302 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1303 netif_carrier_on(vlan->dev);
1308 mutex_lock(&local->mtx);
1309 ieee80211_vif_release_channel(sdata);
1310 mutex_unlock(&local->mtx);
1315 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1316 struct cfg80211_beacon_data *params)
1318 struct ieee80211_sub_if_data *sdata;
1319 struct ieee80211_bss_conf *bss_conf;
1320 struct beacon_data *old;
1323 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1324 sdata_assert_lock(sdata);
1326 /* don't allow changing the beacon while a countdown is in place - offset
1327 * of channel switch counter may change
1329 if (sdata->vif.csa_active || sdata->vif.color_change_active)
1332 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1336 err = ieee80211_assign_beacon(sdata, params, NULL, NULL);
1340 bss_conf = &sdata->vif.bss_conf;
1341 if (params->he_bss_color_valid &&
1342 params->he_bss_color.enabled != bss_conf->he_bss_color.enabled) {
1343 bss_conf->he_bss_color.enabled = params->he_bss_color.enabled;
1344 err |= BSS_CHANGED_HE_BSS_COLOR;
1347 ieee80211_bss_info_change_notify(sdata, err);
1351 static void ieee80211_free_next_beacon(struct ieee80211_sub_if_data *sdata)
1353 if (!sdata->u.ap.next_beacon)
1356 kfree(sdata->u.ap.next_beacon->mbssid_ies);
1357 kfree(sdata->u.ap.next_beacon);
1358 sdata->u.ap.next_beacon = NULL;
1361 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1364 struct ieee80211_sub_if_data *vlan;
1365 struct ieee80211_local *local = sdata->local;
1366 struct beacon_data *old_beacon;
1367 struct probe_resp *old_probe_resp;
1368 struct fils_discovery_data *old_fils_discovery;
1369 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1370 struct cfg80211_chan_def chandef;
1372 sdata_assert_lock(sdata);
1374 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
1377 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
1378 old_fils_discovery = sdata_dereference(sdata->u.ap.fils_discovery,
1380 old_unsol_bcast_probe_resp =
1381 sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp,
1384 /* abort any running channel switch */
1385 mutex_lock(&local->mtx);
1386 sdata->vif.csa_active = false;
1387 if (sdata->csa_block_tx) {
1388 ieee80211_wake_vif_queues(local, sdata,
1389 IEEE80211_QUEUE_STOP_REASON_CSA);
1390 sdata->csa_block_tx = false;
1393 mutex_unlock(&local->mtx);
1395 ieee80211_free_next_beacon(sdata);
1397 /* turn off carrier for this interface and dependent VLANs */
1398 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1399 netif_carrier_off(vlan->dev);
1400 netif_carrier_off(dev);
1402 /* remove beacon and probe response */
1403 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1404 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1405 RCU_INIT_POINTER(sdata->u.ap.fils_discovery, NULL);
1406 RCU_INIT_POINTER(sdata->u.ap.unsol_bcast_probe_resp, NULL);
1407 kfree_rcu(old_beacon, rcu_head);
1409 kfree_rcu(old_probe_resp, rcu_head);
1410 if (old_fils_discovery)
1411 kfree_rcu(old_fils_discovery, rcu_head);
1412 if (old_unsol_bcast_probe_resp)
1413 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1415 kfree(sdata->vif.bss_conf.ftmr_params);
1416 sdata->vif.bss_conf.ftmr_params = NULL;
1418 __sta_info_flush(sdata, true);
1419 ieee80211_free_keys(sdata, true);
1421 sdata->vif.bss_conf.enable_beacon = false;
1422 sdata->beacon_rate_set = false;
1423 sdata->vif.bss_conf.ssid_len = 0;
1424 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1425 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1427 if (sdata->wdev.cac_started) {
1428 chandef = sdata->vif.bss_conf.chandef;
1429 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1430 cfg80211_cac_event(sdata->dev, &chandef,
1431 NL80211_RADAR_CAC_ABORTED,
1435 drv_stop_ap(sdata->local, sdata);
1437 /* free all potentially still buffered bcast frames */
1438 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1439 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1441 mutex_lock(&local->mtx);
1442 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
1443 ieee80211_vif_release_channel(sdata);
1444 mutex_unlock(&local->mtx);
1449 static int sta_apply_auth_flags(struct ieee80211_local *local,
1450 struct sta_info *sta,
1455 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1456 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1457 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1458 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1463 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1464 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1465 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1467 * When peer becomes associated, init rate control as
1468 * well. Some drivers require rate control initialized
1469 * before drv_sta_state() is called.
1471 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1472 rate_control_rate_init(sta);
1474 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1479 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1480 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1481 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1482 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1483 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1490 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1491 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1492 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1493 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1498 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1499 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1500 test_sta_flag(sta, WLAN_STA_AUTH)) {
1501 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1509 static void sta_apply_mesh_params(struct ieee80211_local *local,
1510 struct sta_info *sta,
1511 struct station_parameters *params)
1513 #ifdef CONFIG_MAC80211_MESH
1514 struct ieee80211_sub_if_data *sdata = sta->sdata;
1517 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1518 switch (params->plink_state) {
1519 case NL80211_PLINK_ESTAB:
1520 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1521 changed = mesh_plink_inc_estab_count(sdata);
1522 sta->mesh->plink_state = params->plink_state;
1523 sta->mesh->aid = params->peer_aid;
1525 ieee80211_mps_sta_status_update(sta);
1526 changed |= ieee80211_mps_set_sta_local_pm(sta,
1527 sdata->u.mesh.mshcfg.power_mode);
1529 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1530 /* init at low value */
1531 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1534 case NL80211_PLINK_LISTEN:
1535 case NL80211_PLINK_BLOCKED:
1536 case NL80211_PLINK_OPN_SNT:
1537 case NL80211_PLINK_OPN_RCVD:
1538 case NL80211_PLINK_CNF_RCVD:
1539 case NL80211_PLINK_HOLDING:
1540 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1541 changed = mesh_plink_dec_estab_count(sdata);
1542 sta->mesh->plink_state = params->plink_state;
1544 ieee80211_mps_sta_status_update(sta);
1545 changed |= ieee80211_mps_set_sta_local_pm(sta,
1546 NL80211_MESH_POWER_UNKNOWN);
1554 switch (params->plink_action) {
1555 case NL80211_PLINK_ACTION_NO_ACTION:
1558 case NL80211_PLINK_ACTION_OPEN:
1559 changed |= mesh_plink_open(sta);
1561 case NL80211_PLINK_ACTION_BLOCK:
1562 changed |= mesh_plink_block(sta);
1566 if (params->local_pm)
1567 changed |= ieee80211_mps_set_sta_local_pm(sta,
1570 ieee80211_mbss_info_change_notify(sdata, changed);
1574 static void sta_apply_airtime_params(struct ieee80211_local *local,
1575 struct sta_info *sta,
1576 struct station_parameters *params)
1580 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1581 struct airtime_sched_info *air_sched = &local->airtime[ac];
1582 struct airtime_info *air_info = &sta->airtime[ac];
1583 struct txq_info *txqi;
1586 spin_lock_bh(&air_sched->lock);
1587 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
1588 if (air_info->weight == params->airtime_weight ||
1589 !sta->sta.txq[tid] ||
1590 ac != ieee80211_ac_from_tid(tid))
1593 airtime_weight_set(air_info, params->airtime_weight);
1595 txqi = to_txq_info(sta->sta.txq[tid]);
1596 if (RB_EMPTY_NODE(&txqi->schedule_order))
1599 ieee80211_update_airtime_weight(local, air_sched,
1602 spin_unlock_bh(&air_sched->lock);
1606 static int sta_apply_parameters(struct ieee80211_local *local,
1607 struct sta_info *sta,
1608 struct station_parameters *params)
1611 struct ieee80211_supported_band *sband;
1612 struct ieee80211_sub_if_data *sdata = sta->sdata;
1615 sband = ieee80211_get_sband(sdata);
1619 mask = params->sta_flags_mask;
1620 set = params->sta_flags_set;
1622 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1624 * In mesh mode, ASSOCIATED isn't part of the nl80211
1625 * API but must follow AUTHENTICATED for driver state.
1627 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1628 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1629 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1630 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1631 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1633 * TDLS -- everything follows authorized, but
1634 * only becoming authorized is possible, not
1637 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1638 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1639 BIT(NL80211_STA_FLAG_ASSOCIATED);
1640 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1641 BIT(NL80211_STA_FLAG_ASSOCIATED);
1645 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1646 local->hw.queues >= IEEE80211_NUM_ACS)
1647 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1649 /* auth flags will be set later for TDLS,
1650 * and for unassociated stations that move to associated */
1651 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1652 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1653 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1654 ret = sta_apply_auth_flags(local, sta, mask, set);
1659 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1660 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1661 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1663 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1666 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1667 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1668 if (set & BIT(NL80211_STA_FLAG_MFP))
1669 set_sta_flag(sta, WLAN_STA_MFP);
1671 clear_sta_flag(sta, WLAN_STA_MFP);
1674 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1675 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1676 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1678 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1681 /* mark TDLS channel switch support, if the AP allows it */
1682 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1683 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1684 params->ext_capab_len >= 4 &&
1685 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1686 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1688 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1689 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1690 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1691 params->ext_capab_len >= 8 &&
1692 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1693 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1695 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1696 sta->sta.uapsd_queues = params->uapsd_queues;
1697 sta->sta.max_sp = params->max_sp;
1700 /* The sender might not have sent the last bit, consider it to be 0 */
1701 if (params->ext_capab_len >= 8) {
1702 u8 val = (params->ext_capab[7] &
1703 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1705 /* we did get all the bits, take the MSB as well */
1706 if (params->ext_capab_len >= 9) {
1707 u8 val_msb = params->ext_capab[8] &
1708 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1715 sta->sta.max_amsdu_subframes = 32;
1718 sta->sta.max_amsdu_subframes = 16;
1721 sta->sta.max_amsdu_subframes = 8;
1724 sta->sta.max_amsdu_subframes = 0;
1729 * cfg80211 validates this (1-2007) and allows setting the AID
1730 * only when creating a new station entry
1733 sta->sta.aid = params->aid;
1736 * Some of the following updates would be racy if called on an
1737 * existing station, via ieee80211_change_station(). However,
1738 * all such changes are rejected by cfg80211 except for updates
1739 * changing the supported rates on an existing but not yet used
1743 if (params->listen_interval >= 0)
1744 sta->listen_interval = params->listen_interval;
1746 if (params->sta_modify_mask & STATION_PARAM_APPLY_STA_TXPOWER) {
1747 sta->sta.deflink.txpwr.type = params->txpwr.type;
1748 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1749 sta->sta.deflink.txpwr.power = params->txpwr.power;
1750 ret = drv_sta_set_txpwr(local, sdata, sta);
1755 if (params->supported_rates && params->supported_rates_len) {
1756 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1757 sband, params->supported_rates,
1758 params->supported_rates_len,
1759 &sta->sta.deflink.supp_rates[sband->band]);
1762 if (params->ht_capa)
1763 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1764 params->ht_capa, sta);
1766 /* VHT can override some HT caps such as the A-MSDU max length */
1767 if (params->vht_capa)
1768 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1769 params->vht_capa, sta);
1771 if (params->he_capa)
1772 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1773 (void *)params->he_capa,
1774 params->he_capa_len,
1775 (void *)params->he_6ghz_capa,
1778 if (params->eht_capa)
1779 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1780 (u8 *)params->he_capa,
1781 params->he_capa_len,
1783 params->eht_capa_len,
1786 if (params->opmode_notif_used) {
1787 /* returned value is only needed for rc update, but the
1788 * rc isn't initialized here yet, so ignore it
1790 __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
1794 if (params->support_p2p_ps >= 0)
1795 sta->sta.support_p2p_ps = params->support_p2p_ps;
1797 if (ieee80211_vif_is_mesh(&sdata->vif))
1798 sta_apply_mesh_params(local, sta, params);
1800 if (params->airtime_weight)
1801 sta_apply_airtime_params(local, sta, params);
1804 /* set the STA state after all sta info from usermode has been set */
1805 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1806 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1807 ret = sta_apply_auth_flags(local, sta, mask, set);
1815 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1817 struct station_parameters *params)
1819 struct ieee80211_local *local = wiphy_priv(wiphy);
1820 struct sta_info *sta;
1821 struct ieee80211_sub_if_data *sdata;
1825 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1827 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1828 sdata->vif.type != NL80211_IFTYPE_AP)
1831 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1833 if (ether_addr_equal(mac, sdata->vif.addr))
1836 if (!is_valid_ether_addr(mac))
1839 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
1840 sdata->vif.type == NL80211_IFTYPE_STATION &&
1841 !sdata->u.mgd.associated)
1844 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1848 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1849 sta->sta.tdls = true;
1851 err = sta_apply_parameters(local, sta, params);
1853 sta_info_free(local, sta);
1858 * for TDLS and for unassociated station, rate control should be
1859 * initialized only when rates are known and station is marked
1860 * authorized/associated
1862 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1863 test_sta_flag(sta, WLAN_STA_ASSOC))
1864 rate_control_rate_init(sta);
1866 return sta_info_insert(sta);
1869 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1870 struct station_del_parameters *params)
1872 struct ieee80211_sub_if_data *sdata;
1874 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1877 return sta_info_destroy_addr_bss(sdata, params->mac);
1879 sta_info_flush(sdata);
1883 static int ieee80211_change_station(struct wiphy *wiphy,
1884 struct net_device *dev, const u8 *mac,
1885 struct station_parameters *params)
1887 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1888 struct ieee80211_local *local = wiphy_priv(wiphy);
1889 struct sta_info *sta;
1890 struct ieee80211_sub_if_data *vlansdata;
1891 enum cfg80211_station_type statype;
1894 mutex_lock(&local->sta_mtx);
1896 sta = sta_info_get_bss(sdata, mac);
1902 switch (sdata->vif.type) {
1903 case NL80211_IFTYPE_MESH_POINT:
1904 if (sdata->u.mesh.user_mpm)
1905 statype = CFG80211_STA_MESH_PEER_USER;
1907 statype = CFG80211_STA_MESH_PEER_KERNEL;
1909 case NL80211_IFTYPE_ADHOC:
1910 statype = CFG80211_STA_IBSS;
1912 case NL80211_IFTYPE_STATION:
1913 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1914 statype = CFG80211_STA_AP_STA;
1917 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1918 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1920 statype = CFG80211_STA_TDLS_PEER_SETUP;
1922 case NL80211_IFTYPE_AP:
1923 case NL80211_IFTYPE_AP_VLAN:
1924 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1925 statype = CFG80211_STA_AP_CLIENT;
1927 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1934 err = cfg80211_check_station_change(wiphy, params, statype);
1938 if (params->vlan && params->vlan != sta->sdata->dev) {
1939 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1941 if (params->vlan->ieee80211_ptr->use_4addr) {
1942 if (vlansdata->u.vlan.sta) {
1947 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1948 __ieee80211_check_fast_rx_iface(vlansdata);
1949 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
1952 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1953 sta->sdata->u.vlan.sta) {
1954 ieee80211_clear_fast_rx(sta);
1955 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1958 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1959 ieee80211_vif_dec_num_mcast(sta->sdata);
1961 sta->sdata = vlansdata;
1962 ieee80211_check_fast_xmit(sta);
1964 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1965 ieee80211_vif_inc_num_mcast(sta->sdata);
1966 cfg80211_send_layer2_update(sta->sdata->dev,
1971 err = sta_apply_parameters(local, sta, params);
1975 mutex_unlock(&local->sta_mtx);
1977 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1978 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1979 ieee80211_recalc_ps(local);
1980 ieee80211_recalc_ps_vif(sdata);
1985 mutex_unlock(&local->sta_mtx);
1989 #ifdef CONFIG_MAC80211_MESH
1990 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1991 const u8 *dst, const u8 *next_hop)
1993 struct ieee80211_sub_if_data *sdata;
1994 struct mesh_path *mpath;
1995 struct sta_info *sta;
1997 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2000 sta = sta_info_get(sdata, next_hop);
2006 mpath = mesh_path_add(sdata, dst);
2007 if (IS_ERR(mpath)) {
2009 return PTR_ERR(mpath);
2012 mesh_path_fix_nexthop(mpath, sta);
2018 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2021 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2024 return mesh_path_del(sdata, dst);
2026 mesh_path_flush_by_iface(sdata);
2030 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2031 const u8 *dst, const u8 *next_hop)
2033 struct ieee80211_sub_if_data *sdata;
2034 struct mesh_path *mpath;
2035 struct sta_info *sta;
2037 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2041 sta = sta_info_get(sdata, next_hop);
2047 mpath = mesh_path_lookup(sdata, dst);
2053 mesh_path_fix_nexthop(mpath, sta);
2059 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2060 struct mpath_info *pinfo)
2062 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2065 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2067 eth_zero_addr(next_hop);
2069 memset(pinfo, 0, sizeof(*pinfo));
2071 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2073 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2076 MPATH_INFO_EXPTIME |
2077 MPATH_INFO_DISCOVERY_TIMEOUT |
2078 MPATH_INFO_DISCOVERY_RETRIES |
2080 MPATH_INFO_HOP_COUNT |
2081 MPATH_INFO_PATH_CHANGE;
2083 pinfo->frame_qlen = mpath->frame_queue.qlen;
2084 pinfo->sn = mpath->sn;
2085 pinfo->metric = mpath->metric;
2086 if (time_before(jiffies, mpath->exp_time))
2087 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2088 pinfo->discovery_timeout =
2089 jiffies_to_msecs(mpath->discovery_timeout);
2090 pinfo->discovery_retries = mpath->discovery_retries;
2091 if (mpath->flags & MESH_PATH_ACTIVE)
2092 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2093 if (mpath->flags & MESH_PATH_RESOLVING)
2094 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2095 if (mpath->flags & MESH_PATH_SN_VALID)
2096 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2097 if (mpath->flags & MESH_PATH_FIXED)
2098 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2099 if (mpath->flags & MESH_PATH_RESOLVED)
2100 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2101 pinfo->hop_count = mpath->hop_count;
2102 pinfo->path_change_count = mpath->path_change_count;
2105 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2106 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2109 struct ieee80211_sub_if_data *sdata;
2110 struct mesh_path *mpath;
2112 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2115 mpath = mesh_path_lookup(sdata, dst);
2120 memcpy(dst, mpath->dst, ETH_ALEN);
2121 mpath_set_pinfo(mpath, next_hop, pinfo);
2126 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2127 int idx, u8 *dst, u8 *next_hop,
2128 struct mpath_info *pinfo)
2130 struct ieee80211_sub_if_data *sdata;
2131 struct mesh_path *mpath;
2133 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2136 mpath = mesh_path_lookup_by_idx(sdata, idx);
2141 memcpy(dst, mpath->dst, ETH_ALEN);
2142 mpath_set_pinfo(mpath, next_hop, pinfo);
2147 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2148 struct mpath_info *pinfo)
2150 memset(pinfo, 0, sizeof(*pinfo));
2151 memcpy(mpp, mpath->mpp, ETH_ALEN);
2153 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2156 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2157 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2160 struct ieee80211_sub_if_data *sdata;
2161 struct mesh_path *mpath;
2163 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2166 mpath = mpp_path_lookup(sdata, dst);
2171 memcpy(dst, mpath->dst, ETH_ALEN);
2172 mpp_set_pinfo(mpath, mpp, pinfo);
2177 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2178 int idx, u8 *dst, u8 *mpp,
2179 struct mpath_info *pinfo)
2181 struct ieee80211_sub_if_data *sdata;
2182 struct mesh_path *mpath;
2184 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2187 mpath = mpp_path_lookup_by_idx(sdata, idx);
2192 memcpy(dst, mpath->dst, ETH_ALEN);
2193 mpp_set_pinfo(mpath, mpp, pinfo);
2198 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2199 struct net_device *dev,
2200 struct mesh_config *conf)
2202 struct ieee80211_sub_if_data *sdata;
2203 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2205 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2209 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2211 return (mask >> (parm-1)) & 0x1;
2214 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2215 const struct mesh_setup *setup)
2218 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2219 struct ieee80211_sub_if_data, u.mesh);
2222 /* allocate information elements */
2225 if (setup->ie_len) {
2226 new_ie = kmemdup(setup->ie, setup->ie_len,
2231 ifmsh->ie_len = setup->ie_len;
2234 /* now copy the rest of the setup parameters */
2235 ifmsh->mesh_id_len = setup->mesh_id_len;
2236 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2237 ifmsh->mesh_sp_id = setup->sync_method;
2238 ifmsh->mesh_pp_id = setup->path_sel_proto;
2239 ifmsh->mesh_pm_id = setup->path_metric;
2240 ifmsh->user_mpm = setup->user_mpm;
2241 ifmsh->mesh_auth_id = setup->auth_id;
2242 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2243 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2244 if (setup->is_authenticated)
2245 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2246 if (setup->is_secure)
2247 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2249 /* mcast rate setting in Mesh Node */
2250 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2251 sizeof(setup->mcast_rate));
2252 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2254 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2255 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2257 sdata->beacon_rate_set = false;
2258 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2259 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2260 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2261 sdata->beacon_rateidx_mask[i] =
2262 setup->beacon_rate.control[i].legacy;
2263 if (sdata->beacon_rateidx_mask[i])
2264 sdata->beacon_rate_set = true;
2271 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2272 struct net_device *dev, u32 mask,
2273 const struct mesh_config *nconf)
2275 struct mesh_config *conf;
2276 struct ieee80211_sub_if_data *sdata;
2277 struct ieee80211_if_mesh *ifmsh;
2279 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2280 ifmsh = &sdata->u.mesh;
2282 /* Set the config options which we are interested in setting */
2283 conf = &(sdata->u.mesh.mshcfg);
2284 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2285 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2286 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2287 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2288 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2289 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2290 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2291 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2292 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2293 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2294 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2295 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2296 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2297 conf->element_ttl = nconf->element_ttl;
2298 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2299 if (ifmsh->user_mpm)
2301 conf->auto_open_plinks = nconf->auto_open_plinks;
2303 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2304 conf->dot11MeshNbrOffsetMaxNeighbor =
2305 nconf->dot11MeshNbrOffsetMaxNeighbor;
2306 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2307 conf->dot11MeshHWMPmaxPREQretries =
2308 nconf->dot11MeshHWMPmaxPREQretries;
2309 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2310 conf->path_refresh_time = nconf->path_refresh_time;
2311 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2312 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2313 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2314 conf->dot11MeshHWMPactivePathTimeout =
2315 nconf->dot11MeshHWMPactivePathTimeout;
2316 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2317 conf->dot11MeshHWMPpreqMinInterval =
2318 nconf->dot11MeshHWMPpreqMinInterval;
2319 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2320 conf->dot11MeshHWMPperrMinInterval =
2321 nconf->dot11MeshHWMPperrMinInterval;
2322 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2324 conf->dot11MeshHWMPnetDiameterTraversalTime =
2325 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2326 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2327 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2328 ieee80211_mesh_root_setup(ifmsh);
2330 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2331 /* our current gate announcement implementation rides on root
2332 * announcements, so require this ifmsh to also be a root node
2334 if (nconf->dot11MeshGateAnnouncementProtocol &&
2335 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2336 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2337 ieee80211_mesh_root_setup(ifmsh);
2339 conf->dot11MeshGateAnnouncementProtocol =
2340 nconf->dot11MeshGateAnnouncementProtocol;
2342 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2343 conf->dot11MeshHWMPRannInterval =
2344 nconf->dot11MeshHWMPRannInterval;
2345 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2346 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2347 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2348 /* our RSSI threshold implementation is supported only for
2349 * devices that report signal in dBm.
2351 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2353 conf->rssi_threshold = nconf->rssi_threshold;
2355 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2356 conf->ht_opmode = nconf->ht_opmode;
2357 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2358 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
2360 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2361 conf->dot11MeshHWMPactivePathToRootTimeout =
2362 nconf->dot11MeshHWMPactivePathToRootTimeout;
2363 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2364 conf->dot11MeshHWMProotInterval =
2365 nconf->dot11MeshHWMProotInterval;
2366 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2367 conf->dot11MeshHWMPconfirmationInterval =
2368 nconf->dot11MeshHWMPconfirmationInterval;
2369 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2370 conf->power_mode = nconf->power_mode;
2371 ieee80211_mps_local_status_update(sdata);
2373 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2374 conf->dot11MeshAwakeWindowDuration =
2375 nconf->dot11MeshAwakeWindowDuration;
2376 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2377 conf->plink_timeout = nconf->plink_timeout;
2378 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2379 conf->dot11MeshConnectedToMeshGate =
2380 nconf->dot11MeshConnectedToMeshGate;
2381 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2382 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2383 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2384 conf->dot11MeshConnectedToAuthServer =
2385 nconf->dot11MeshConnectedToAuthServer;
2386 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2390 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2391 const struct mesh_config *conf,
2392 const struct mesh_setup *setup)
2394 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2395 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2398 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2399 err = copy_mesh_setup(ifmsh, setup);
2403 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2405 /* can mesh use other SMPS modes? */
2406 sdata->smps_mode = IEEE80211_SMPS_OFF;
2407 sdata->needed_rx_chains = sdata->local->rx_chains;
2409 mutex_lock(&sdata->local->mtx);
2410 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
2411 IEEE80211_CHANCTX_SHARED);
2412 mutex_unlock(&sdata->local->mtx);
2416 return ieee80211_start_mesh(sdata);
2419 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2421 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2423 ieee80211_stop_mesh(sdata);
2424 mutex_lock(&sdata->local->mtx);
2425 ieee80211_vif_release_channel(sdata);
2426 kfree(sdata->u.mesh.ie);
2427 mutex_unlock(&sdata->local->mtx);
2433 static int ieee80211_change_bss(struct wiphy *wiphy,
2434 struct net_device *dev,
2435 struct bss_parameters *params)
2437 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2438 struct ieee80211_supported_band *sband;
2441 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
2444 sband = ieee80211_get_sband(sdata);
2448 if (params->use_cts_prot >= 0) {
2449 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2450 changed |= BSS_CHANGED_ERP_CTS_PROT;
2452 if (params->use_short_preamble >= 0) {
2453 sdata->vif.bss_conf.use_short_preamble =
2454 params->use_short_preamble;
2455 changed |= BSS_CHANGED_ERP_PREAMBLE;
2458 if (!sdata->vif.bss_conf.use_short_slot &&
2459 (sband->band == NL80211_BAND_5GHZ ||
2460 sband->band == NL80211_BAND_6GHZ)) {
2461 sdata->vif.bss_conf.use_short_slot = true;
2462 changed |= BSS_CHANGED_ERP_SLOT;
2465 if (params->use_short_slot_time >= 0) {
2466 sdata->vif.bss_conf.use_short_slot =
2467 params->use_short_slot_time;
2468 changed |= BSS_CHANGED_ERP_SLOT;
2471 if (params->basic_rates) {
2472 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2473 wiphy->bands[sband->band],
2474 params->basic_rates,
2475 params->basic_rates_len,
2476 &sdata->vif.bss_conf.basic_rates);
2477 changed |= BSS_CHANGED_BASIC_RATES;
2478 ieee80211_check_rate_mask(sdata);
2481 if (params->ap_isolate >= 0) {
2482 if (params->ap_isolate)
2483 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2485 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2486 ieee80211_check_fast_rx_iface(sdata);
2489 if (params->ht_opmode >= 0) {
2490 sdata->vif.bss_conf.ht_operation_mode =
2491 (u16) params->ht_opmode;
2492 changed |= BSS_CHANGED_HT;
2495 if (params->p2p_ctwindow >= 0) {
2496 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2497 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2498 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2499 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2500 changed |= BSS_CHANGED_P2P_PS;
2503 if (params->p2p_opp_ps > 0) {
2504 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2505 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2506 changed |= BSS_CHANGED_P2P_PS;
2507 } else if (params->p2p_opp_ps == 0) {
2508 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2509 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2510 changed |= BSS_CHANGED_P2P_PS;
2513 ieee80211_bss_info_change_notify(sdata, changed);
2518 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2519 struct net_device *dev,
2520 struct ieee80211_txq_params *params)
2522 struct ieee80211_local *local = wiphy_priv(wiphy);
2523 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2524 struct ieee80211_tx_queue_params p;
2526 if (!local->ops->conf_tx)
2529 if (local->hw.queues < IEEE80211_NUM_ACS)
2532 memset(&p, 0, sizeof(p));
2533 p.aifs = params->aifs;
2534 p.cw_max = params->cwmax;
2535 p.cw_min = params->cwmin;
2536 p.txop = params->txop;
2539 * Setting tx queue params disables u-apsd because it's only
2540 * called in master mode.
2544 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2546 sdata->tx_conf[params->ac] = p;
2547 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2548 wiphy_debug(local->hw.wiphy,
2549 "failed to set TX queue parameters for AC %d\n",
2554 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2560 static int ieee80211_suspend(struct wiphy *wiphy,
2561 struct cfg80211_wowlan *wowlan)
2563 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2566 static int ieee80211_resume(struct wiphy *wiphy)
2568 return __ieee80211_resume(wiphy_priv(wiphy));
2571 #define ieee80211_suspend NULL
2572 #define ieee80211_resume NULL
2575 static int ieee80211_scan(struct wiphy *wiphy,
2576 struct cfg80211_scan_request *req)
2578 struct ieee80211_sub_if_data *sdata;
2580 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2582 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2583 case NL80211_IFTYPE_STATION:
2584 case NL80211_IFTYPE_ADHOC:
2585 case NL80211_IFTYPE_MESH_POINT:
2586 case NL80211_IFTYPE_P2P_CLIENT:
2587 case NL80211_IFTYPE_P2P_DEVICE:
2589 case NL80211_IFTYPE_P2P_GO:
2590 if (sdata->local->ops->hw_scan)
2593 * FIXME: implement NoA while scanning in software,
2594 * for now fall through to allow scanning only when
2595 * beaconing hasn't been configured yet
2598 case NL80211_IFTYPE_AP:
2600 * If the scan has been forced (and the driver supports
2601 * forcing), don't care about being beaconing already.
2602 * This will create problems to the attached stations (e.g. all
2603 * the frames sent while scanning on other channel will be
2606 if (sdata->u.ap.beacon &&
2607 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2608 !(req->flags & NL80211_SCAN_FLAG_AP)))
2611 case NL80211_IFTYPE_NAN:
2616 return ieee80211_request_scan(sdata, req);
2619 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2621 ieee80211_scan_cancel(wiphy_priv(wiphy));
2625 ieee80211_sched_scan_start(struct wiphy *wiphy,
2626 struct net_device *dev,
2627 struct cfg80211_sched_scan_request *req)
2629 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2631 if (!sdata->local->ops->sched_scan_start)
2634 return ieee80211_request_sched_scan_start(sdata, req);
2638 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2641 struct ieee80211_local *local = wiphy_priv(wiphy);
2643 if (!local->ops->sched_scan_stop)
2646 return ieee80211_request_sched_scan_stop(local);
2649 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2650 struct cfg80211_auth_request *req)
2652 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2655 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2656 struct cfg80211_assoc_request *req)
2658 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2661 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2662 struct cfg80211_deauth_request *req)
2664 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2667 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2668 struct cfg80211_disassoc_request *req)
2670 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2673 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2674 struct cfg80211_ibss_params *params)
2676 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2679 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2681 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2684 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2685 struct ocb_setup *setup)
2687 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2690 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2692 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2695 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2696 int rate[NUM_NL80211_BANDS])
2698 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2700 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2701 sizeof(int) * NUM_NL80211_BANDS);
2703 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
2708 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2710 struct ieee80211_local *local = wiphy_priv(wiphy);
2713 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2714 ieee80211_check_fast_xmit_all(local);
2716 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2719 ieee80211_check_fast_xmit_all(local);
2724 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2725 (changed & WIPHY_PARAM_DYN_ACK)) {
2728 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2729 wiphy->coverage_class : -1;
2730 err = drv_set_coverage_class(local, coverage_class);
2736 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2737 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2743 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2744 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2746 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2748 if (changed & WIPHY_PARAM_RETRY_LONG) {
2749 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2751 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2754 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2755 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2757 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2758 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2759 WIPHY_PARAM_TXQ_QUANTUM))
2760 ieee80211_txq_set_params(local);
2765 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2766 struct wireless_dev *wdev,
2767 enum nl80211_tx_power_setting type, int mbm)
2769 struct ieee80211_local *local = wiphy_priv(wiphy);
2770 struct ieee80211_sub_if_data *sdata;
2771 enum nl80211_tx_power_setting txp_type = type;
2772 bool update_txp_type = false;
2773 bool has_monitor = false;
2776 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2778 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2779 sdata = wiphy_dereference(local->hw.wiphy,
2780 local->monitor_sdata);
2786 case NL80211_TX_POWER_AUTOMATIC:
2787 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2788 txp_type = NL80211_TX_POWER_LIMITED;
2790 case NL80211_TX_POWER_LIMITED:
2791 case NL80211_TX_POWER_FIXED:
2792 if (mbm < 0 || (mbm % 100))
2794 sdata->user_power_level = MBM_TO_DBM(mbm);
2798 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2799 update_txp_type = true;
2800 sdata->vif.bss_conf.txpower_type = txp_type;
2803 ieee80211_recalc_txpower(sdata, update_txp_type);
2809 case NL80211_TX_POWER_AUTOMATIC:
2810 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2811 txp_type = NL80211_TX_POWER_LIMITED;
2813 case NL80211_TX_POWER_LIMITED:
2814 case NL80211_TX_POWER_FIXED:
2815 if (mbm < 0 || (mbm % 100))
2817 local->user_power_level = MBM_TO_DBM(mbm);
2821 mutex_lock(&local->iflist_mtx);
2822 list_for_each_entry(sdata, &local->interfaces, list) {
2823 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2827 sdata->user_power_level = local->user_power_level;
2828 if (txp_type != sdata->vif.bss_conf.txpower_type)
2829 update_txp_type = true;
2830 sdata->vif.bss_conf.txpower_type = txp_type;
2832 list_for_each_entry(sdata, &local->interfaces, list) {
2833 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2835 ieee80211_recalc_txpower(sdata, update_txp_type);
2837 mutex_unlock(&local->iflist_mtx);
2840 sdata = wiphy_dereference(local->hw.wiphy,
2841 local->monitor_sdata);
2843 sdata->user_power_level = local->user_power_level;
2844 if (txp_type != sdata->vif.bss_conf.txpower_type)
2845 update_txp_type = true;
2846 sdata->vif.bss_conf.txpower_type = txp_type;
2848 ieee80211_recalc_txpower(sdata, update_txp_type);
2855 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2856 struct wireless_dev *wdev,
2859 struct ieee80211_local *local = wiphy_priv(wiphy);
2860 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2862 if (local->ops->get_txpower)
2863 return drv_get_txpower(local, sdata, dbm);
2865 if (!local->use_chanctx)
2866 *dbm = local->hw.conf.power_level;
2868 *dbm = sdata->vif.bss_conf.txpower;
2873 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2875 struct ieee80211_local *local = wiphy_priv(wiphy);
2877 drv_rfkill_poll(local);
2880 #ifdef CONFIG_NL80211_TESTMODE
2881 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2882 struct wireless_dev *wdev,
2883 void *data, int len)
2885 struct ieee80211_local *local = wiphy_priv(wiphy);
2886 struct ieee80211_vif *vif = NULL;
2888 if (!local->ops->testmode_cmd)
2892 struct ieee80211_sub_if_data *sdata;
2894 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2895 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2899 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2902 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2903 struct sk_buff *skb,
2904 struct netlink_callback *cb,
2905 void *data, int len)
2907 struct ieee80211_local *local = wiphy_priv(wiphy);
2909 if (!local->ops->testmode_dump)
2912 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2916 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2917 enum ieee80211_smps_mode smps_mode)
2920 enum ieee80211_smps_mode old_req;
2922 struct sta_info *sta;
2923 bool tdls_peer_found = false;
2925 lockdep_assert_held(&sdata->wdev.mtx);
2927 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2930 old_req = sdata->u.mgd.req_smps;
2931 sdata->u.mgd.req_smps = smps_mode;
2933 if (old_req == smps_mode &&
2934 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2938 * If not associated, or current association is not an HT
2939 * association, there's no need to do anything, just store
2940 * the new value until we associate.
2942 if (!sdata->u.mgd.associated ||
2943 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2946 ap = sdata->u.mgd.bssid;
2949 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2950 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2951 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2954 tdls_peer_found = true;
2959 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2960 if (tdls_peer_found || !sdata->u.mgd.powersave)
2961 smps_mode = IEEE80211_SMPS_OFF;
2963 smps_mode = IEEE80211_SMPS_DYNAMIC;
2966 /* send SM PS frame to AP */
2967 err = ieee80211_send_smps_action(sdata, smps_mode,
2970 sdata->u.mgd.req_smps = old_req;
2971 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2972 ieee80211_teardown_tdls_peers(sdata);
2977 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2978 bool enabled, int timeout)
2980 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2981 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2983 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2986 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
2989 if (enabled == sdata->u.mgd.powersave &&
2990 timeout == local->dynamic_ps_forced_timeout)
2993 sdata->u.mgd.powersave = enabled;
2994 local->dynamic_ps_forced_timeout = timeout;
2996 /* no change, but if automatic follow powersave */
2998 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2999 sdata_unlock(sdata);
3001 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3002 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3004 ieee80211_recalc_ps(local);
3005 ieee80211_recalc_ps_vif(sdata);
3006 ieee80211_check_fast_rx_iface(sdata);
3011 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3012 struct net_device *dev,
3013 s32 rssi_thold, u32 rssi_hyst)
3015 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3016 struct ieee80211_vif *vif = &sdata->vif;
3017 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3019 if (rssi_thold == bss_conf->cqm_rssi_thold &&
3020 rssi_hyst == bss_conf->cqm_rssi_hyst)
3023 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3024 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3027 bss_conf->cqm_rssi_thold = rssi_thold;
3028 bss_conf->cqm_rssi_hyst = rssi_hyst;
3029 bss_conf->cqm_rssi_low = 0;
3030 bss_conf->cqm_rssi_high = 0;
3031 sdata->u.mgd.last_cqm_event_signal = 0;
3033 /* tell the driver upon association, unless already associated */
3034 if (sdata->u.mgd.associated &&
3035 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3036 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
3041 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3042 struct net_device *dev,
3043 s32 rssi_low, s32 rssi_high)
3045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3046 struct ieee80211_vif *vif = &sdata->vif;
3047 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3049 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
3052 bss_conf->cqm_rssi_low = rssi_low;
3053 bss_conf->cqm_rssi_high = rssi_high;
3054 bss_conf->cqm_rssi_thold = 0;
3055 bss_conf->cqm_rssi_hyst = 0;
3056 sdata->u.mgd.last_cqm_event_signal = 0;
3058 /* tell the driver upon association, unless already associated */
3059 if (sdata->u.mgd.associated &&
3060 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3061 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
3066 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3067 struct net_device *dev,
3069 const struct cfg80211_bitrate_mask *mask)
3071 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3072 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3075 if (!ieee80211_sdata_running(sdata))
3079 * If active validate the setting and reject it if it doesn't leave
3080 * at least one basic rate usable, since we really have to be able
3081 * to send something, and if we're an AP we have to be able to do
3082 * so at a basic rate so that all clients can receive it.
3084 if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
3085 sdata->vif.bss_conf.chandef.chan) {
3086 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3087 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3089 if (!(mask->control[band].legacy & basic_rates))
3093 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3094 ret = drv_set_bitrate_mask(local, sdata, mask);
3099 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3100 struct ieee80211_supported_band *sband = wiphy->bands[i];
3103 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3104 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3105 sizeof(mask->control[i].ht_mcs));
3106 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3107 mask->control[i].vht_mcs,
3108 sizeof(mask->control[i].vht_mcs));
3110 sdata->rc_has_mcs_mask[i] = false;
3111 sdata->rc_has_vht_mcs_mask[i] = false;
3115 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3116 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3117 sdata->rc_has_mcs_mask[i] = true;
3122 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3123 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3124 sdata->rc_has_vht_mcs_mask[i] = true;
3133 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3134 struct net_device *dev,
3135 struct cfg80211_chan_def *chandef,
3138 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3139 struct ieee80211_local *local = sdata->local;
3142 mutex_lock(&local->mtx);
3143 if (!list_empty(&local->roc_list) || local->scanning) {
3148 /* whatever, but channel contexts should not complain about that one */
3149 sdata->smps_mode = IEEE80211_SMPS_OFF;
3150 sdata->needed_rx_chains = local->rx_chains;
3152 err = ieee80211_vif_use_channel(sdata, chandef,
3153 IEEE80211_CHANCTX_SHARED);
3157 ieee80211_queue_delayed_work(&sdata->local->hw,
3158 &sdata->dfs_cac_timer_work,
3159 msecs_to_jiffies(cac_time_ms));
3162 mutex_unlock(&local->mtx);
3166 static void ieee80211_end_cac(struct wiphy *wiphy,
3167 struct net_device *dev)
3169 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3170 struct ieee80211_local *local = sdata->local;
3172 mutex_lock(&local->mtx);
3173 list_for_each_entry(sdata, &local->interfaces, list) {
3174 /* it might be waiting for the local->mtx, but then
3175 * by the time it gets it, sdata->wdev.cac_started
3176 * will no longer be true
3178 cancel_delayed_work(&sdata->dfs_cac_timer_work);
3180 if (sdata->wdev.cac_started) {
3181 ieee80211_vif_release_channel(sdata);
3182 sdata->wdev.cac_started = false;
3185 mutex_unlock(&local->mtx);
3188 static struct cfg80211_beacon_data *
3189 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3191 struct cfg80211_beacon_data *new_beacon;
3195 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3196 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3197 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len +
3198 ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies);
3200 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3204 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3205 new_beacon->mbssid_ies =
3206 kzalloc(struct_size(new_beacon->mbssid_ies,
3207 elem, beacon->mbssid_ies->cnt),
3209 if (!new_beacon->mbssid_ies) {
3215 pos = (u8 *)(new_beacon + 1);
3216 if (beacon->head_len) {
3217 new_beacon->head_len = beacon->head_len;
3218 new_beacon->head = pos;
3219 memcpy(pos, beacon->head, beacon->head_len);
3220 pos += beacon->head_len;
3222 if (beacon->tail_len) {
3223 new_beacon->tail_len = beacon->tail_len;
3224 new_beacon->tail = pos;
3225 memcpy(pos, beacon->tail, beacon->tail_len);
3226 pos += beacon->tail_len;
3228 if (beacon->beacon_ies_len) {
3229 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3230 new_beacon->beacon_ies = pos;
3231 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3232 pos += beacon->beacon_ies_len;
3234 if (beacon->proberesp_ies_len) {
3235 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3236 new_beacon->proberesp_ies = pos;
3237 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3238 pos += beacon->proberesp_ies_len;
3240 if (beacon->assocresp_ies_len) {
3241 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3242 new_beacon->assocresp_ies = pos;
3243 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3244 pos += beacon->assocresp_ies_len;
3246 if (beacon->probe_resp_len) {
3247 new_beacon->probe_resp_len = beacon->probe_resp_len;
3248 new_beacon->probe_resp = pos;
3249 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3250 pos += beacon->probe_resp_len;
3252 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt)
3253 pos += ieee80211_copy_mbssid_beacon(pos,
3254 new_beacon->mbssid_ies,
3255 beacon->mbssid_ies);
3257 /* might copy -1, meaning no changes requested */
3258 new_beacon->ftm_responder = beacon->ftm_responder;
3260 new_beacon->lci_len = beacon->lci_len;
3261 new_beacon->lci = pos;
3262 memcpy(pos, beacon->lci, beacon->lci_len);
3263 pos += beacon->lci_len;
3265 if (beacon->civicloc) {
3266 new_beacon->civicloc_len = beacon->civicloc_len;
3267 new_beacon->civicloc = pos;
3268 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3269 pos += beacon->civicloc_len;
3275 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3277 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3278 struct ieee80211_local *local = sdata->local;
3282 if (vif->mbssid_tx_vif == vif) {
3283 /* Trigger ieee80211_csa_finish() on the non-transmitting
3284 * interfaces when channel switch is received on
3285 * transmitting interface
3287 struct ieee80211_sub_if_data *iter;
3289 list_for_each_entry_rcu(iter, &local->interfaces, list) {
3290 if (!ieee80211_sdata_running(iter))
3293 if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3296 ieee80211_queue_work(&iter->local->hw,
3297 &iter->csa_finalize_work);
3300 ieee80211_queue_work(&local->hw, &sdata->csa_finalize_work);
3304 EXPORT_SYMBOL(ieee80211_csa_finish);
3306 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3308 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3309 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3310 struct ieee80211_local *local = sdata->local;
3312 sdata->csa_block_tx = block_tx;
3313 sdata_info(sdata, "channel switch failed, disconnecting\n");
3314 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
3316 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3318 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3323 switch (sdata->vif.type) {
3324 case NL80211_IFTYPE_AP:
3325 if (!sdata->u.ap.next_beacon)
3328 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
3330 ieee80211_free_next_beacon(sdata);
3336 case NL80211_IFTYPE_ADHOC:
3337 err = ieee80211_ibss_finish_csa(sdata);
3342 #ifdef CONFIG_MAC80211_MESH
3343 case NL80211_IFTYPE_MESH_POINT:
3344 err = ieee80211_mesh_finish_csa(sdata);
3358 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3360 struct ieee80211_local *local = sdata->local;
3364 sdata_assert_lock(sdata);
3365 lockdep_assert_held(&local->mtx);
3366 lockdep_assert_held(&local->chanctx_mtx);
3369 * using reservation isn't immediate as it may be deferred until later
3370 * with multi-vif. once reservation is complete it will re-schedule the
3371 * work with no reserved_chanctx so verify chandef to check if it
3372 * completed successfully
3375 if (sdata->reserved_chanctx) {
3377 * with multi-vif csa driver may call ieee80211_csa_finish()
3378 * many times while waiting for other interfaces to use their
3381 if (sdata->reserved_ready)
3384 return ieee80211_vif_use_reserved_context(sdata);
3387 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3388 &sdata->csa_chandef))
3391 sdata->vif.csa_active = false;
3393 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3397 ieee80211_bss_info_change_notify(sdata, changed);
3399 if (sdata->csa_block_tx) {
3400 ieee80211_wake_vif_queues(local, sdata,
3401 IEEE80211_QUEUE_STOP_REASON_CSA);
3402 sdata->csa_block_tx = false;
3405 err = drv_post_channel_switch(sdata);
3409 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3414 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3416 if (__ieee80211_csa_finalize(sdata)) {
3417 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3418 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3423 void ieee80211_csa_finalize_work(struct work_struct *work)
3425 struct ieee80211_sub_if_data *sdata =
3426 container_of(work, struct ieee80211_sub_if_data,
3428 struct ieee80211_local *local = sdata->local;
3431 mutex_lock(&local->mtx);
3432 mutex_lock(&local->chanctx_mtx);
3434 /* AP might have been stopped while waiting for the lock. */
3435 if (!sdata->vif.csa_active)
3438 if (!ieee80211_sdata_running(sdata))
3441 ieee80211_csa_finalize(sdata);
3444 mutex_unlock(&local->chanctx_mtx);
3445 mutex_unlock(&local->mtx);
3446 sdata_unlock(sdata);
3449 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3450 struct cfg80211_csa_settings *params,
3453 struct ieee80211_csa_settings csa = {};
3456 switch (sdata->vif.type) {
3457 case NL80211_IFTYPE_AP:
3458 sdata->u.ap.next_beacon =
3459 cfg80211_beacon_dup(¶ms->beacon_after);
3460 if (!sdata->u.ap.next_beacon)
3464 * With a count of 0, we don't have to wait for any
3465 * TBTT before switching, so complete the CSA
3466 * immediately. In theory, with a count == 1 we
3467 * should delay the switch until just before the next
3468 * TBTT, but that would complicate things so we switch
3469 * immediately too. If we would delay the switch
3470 * until the next TBTT, we would have to set the probe
3473 * TODO: A channel switch with count <= 1 without
3474 * sending a CSA action frame is kind of useless,
3475 * because the clients won't know we're changing
3476 * channels. The action frame must be implemented
3477 * either here or in the userspace.
3479 if (params->count <= 1)
3482 if ((params->n_counter_offsets_beacon >
3483 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3484 (params->n_counter_offsets_presp >
3485 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3486 ieee80211_free_next_beacon(sdata);
3490 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3491 csa.counter_offsets_presp = params->counter_offsets_presp;
3492 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3493 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3494 csa.count = params->count;
3496 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa, NULL);
3498 ieee80211_free_next_beacon(sdata);
3504 case NL80211_IFTYPE_ADHOC:
3505 if (!sdata->vif.bss_conf.ibss_joined)
3508 if (params->chandef.width != sdata->u.ibss.chandef.width)
3511 switch (params->chandef.width) {
3512 case NL80211_CHAN_WIDTH_40:
3513 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3514 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3517 case NL80211_CHAN_WIDTH_5:
3518 case NL80211_CHAN_WIDTH_10:
3519 case NL80211_CHAN_WIDTH_20_NOHT:
3520 case NL80211_CHAN_WIDTH_20:
3526 /* changes into another band are not supported */
3527 if (sdata->u.ibss.chandef.chan->band !=
3528 params->chandef.chan->band)
3531 /* see comments in the NL80211_IFTYPE_AP block */
3532 if (params->count > 1) {
3533 err = ieee80211_ibss_csa_beacon(sdata, params);
3539 ieee80211_send_action_csa(sdata, params);
3542 #ifdef CONFIG_MAC80211_MESH
3543 case NL80211_IFTYPE_MESH_POINT: {
3544 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3546 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3549 /* changes into another band are not supported */
3550 if (sdata->vif.bss_conf.chandef.chan->band !=
3551 params->chandef.chan->band)
3554 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3555 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3556 if (!ifmsh->pre_value)
3557 ifmsh->pre_value = 1;
3562 /* see comments in the NL80211_IFTYPE_AP block */
3563 if (params->count > 1) {
3564 err = ieee80211_mesh_csa_beacon(sdata, params);
3566 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3572 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3573 ieee80211_send_action_csa(sdata, params);
3585 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3587 sdata->vif.color_change_active = false;
3589 ieee80211_free_next_beacon(sdata);
3591 cfg80211_color_change_aborted_notify(sdata->dev);
3595 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3596 struct cfg80211_csa_settings *params)
3598 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3599 struct ieee80211_local *local = sdata->local;
3600 struct ieee80211_channel_switch ch_switch;
3601 struct ieee80211_chanctx_conf *conf;
3602 struct ieee80211_chanctx *chanctx;
3606 sdata_assert_lock(sdata);
3607 lockdep_assert_held(&local->mtx);
3609 if (!list_empty(&local->roc_list) || local->scanning)
3612 if (sdata->wdev.cac_started)
3615 if (cfg80211_chandef_identical(¶ms->chandef,
3616 &sdata->vif.bss_conf.chandef))
3619 /* don't allow another channel switch if one is already active. */
3620 if (sdata->vif.csa_active)
3623 mutex_lock(&local->chanctx_mtx);
3624 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3625 lockdep_is_held(&local->chanctx_mtx));
3631 if (params->chandef.chan->freq_offset) {
3632 /* this may work, but is untested */
3637 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3639 ch_switch.timestamp = 0;
3640 ch_switch.device_timestamp = 0;
3641 ch_switch.block_tx = params->block_tx;
3642 ch_switch.chandef = params->chandef;
3643 ch_switch.count = params->count;
3645 err = drv_pre_channel_switch(sdata, &ch_switch);
3649 err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef,
3651 params->radar_required);
3655 /* if reservation is invalid then this will fail */
3656 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3658 ieee80211_vif_unreserve_chanctx(sdata);
3662 /* if there is a color change in progress, abort it */
3663 if (sdata->vif.color_change_active)
3664 ieee80211_color_change_abort(sdata);
3666 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3668 ieee80211_vif_unreserve_chanctx(sdata);
3672 sdata->csa_chandef = params->chandef;
3673 sdata->csa_block_tx = params->block_tx;
3674 sdata->vif.csa_active = true;
3676 if (sdata->csa_block_tx)
3677 ieee80211_stop_vif_queues(local, sdata,
3678 IEEE80211_QUEUE_STOP_REASON_CSA);
3680 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3681 params->count, params->block_tx);
3684 ieee80211_bss_info_change_notify(sdata, changed);
3685 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3687 /* if the beacon didn't change, we can finalize immediately */
3688 ieee80211_csa_finalize(sdata);
3692 mutex_unlock(&local->chanctx_mtx);
3696 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3697 struct cfg80211_csa_settings *params)
3699 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3700 struct ieee80211_local *local = sdata->local;
3703 mutex_lock(&local->mtx);
3704 err = __ieee80211_channel_switch(wiphy, dev, params);
3705 mutex_unlock(&local->mtx);
3710 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3712 lockdep_assert_held(&local->mtx);
3714 local->roc_cookie_counter++;
3716 /* wow, you wrapped 64 bits ... more likely a bug */
3717 if (WARN_ON(local->roc_cookie_counter == 0))
3718 local->roc_cookie_counter++;
3720 return local->roc_cookie_counter;
3723 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3724 u64 *cookie, gfp_t gfp)
3726 unsigned long spin_flags;
3727 struct sk_buff *ack_skb;
3730 ack_skb = skb_copy(skb, gfp);
3734 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3735 id = idr_alloc(&local->ack_status_frames, ack_skb,
3736 1, 0x2000, GFP_ATOMIC);
3737 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3744 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3746 *cookie = ieee80211_mgmt_tx_cookie(local);
3747 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3753 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
3754 struct wireless_dev *wdev,
3755 struct mgmt_frame_regs *upd)
3757 struct ieee80211_local *local = wiphy_priv(wiphy);
3758 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3759 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
3760 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
3761 bool global_change, intf_change;
3764 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3765 (local->rx_mcast_action_reg !=
3766 !!(upd->global_mcast_stypes & action_mask));
3767 local->probe_req_reg = upd->global_stypes & preq_mask;
3768 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
3770 intf_change = (sdata->vif.probe_req_reg !=
3771 !!(upd->interface_stypes & preq_mask)) ||
3772 (sdata->vif.rx_mcast_action_reg !=
3773 !!(upd->interface_mcast_stypes & action_mask));
3774 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
3775 sdata->vif.rx_mcast_action_reg =
3776 upd->interface_mcast_stypes & action_mask;
3778 if (!local->open_count)
3781 if (intf_change && ieee80211_sdata_running(sdata))
3782 drv_config_iface_filter(local, sdata,
3783 sdata->vif.probe_req_reg ?
3788 ieee80211_configure_filter(local);
3791 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3793 struct ieee80211_local *local = wiphy_priv(wiphy);
3798 return drv_set_antenna(local, tx_ant, rx_ant);
3801 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3803 struct ieee80211_local *local = wiphy_priv(wiphy);
3805 return drv_get_antenna(local, tx_ant, rx_ant);
3808 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3809 struct net_device *dev,
3810 struct cfg80211_gtk_rekey_data *data)
3812 struct ieee80211_local *local = wiphy_priv(wiphy);
3813 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3815 if (!local->ops->set_rekey_data)
3818 drv_set_rekey_data(local, sdata, data);
3823 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3824 const u8 *peer, u64 *cookie)
3826 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3827 struct ieee80211_local *local = sdata->local;
3828 struct ieee80211_qos_hdr *nullfunc;
3829 struct sk_buff *skb;
3830 int size = sizeof(*nullfunc);
3833 struct ieee80211_tx_info *info;
3834 struct sta_info *sta;
3835 struct ieee80211_chanctx_conf *chanctx_conf;
3836 enum nl80211_band band;
3839 /* the lock is needed to assign the cookie later */
3840 mutex_lock(&local->mtx);
3843 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3844 if (WARN_ON(!chanctx_conf)) {
3848 band = chanctx_conf->def.chan->band;
3849 sta = sta_info_get_bss(sdata, peer);
3858 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3859 IEEE80211_STYPE_QOS_NULLFUNC |
3860 IEEE80211_FCTL_FROMDS);
3863 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3864 IEEE80211_STYPE_NULLFUNC |
3865 IEEE80211_FCTL_FROMDS);
3868 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3876 skb_reserve(skb, local->hw.extra_tx_headroom);
3878 nullfunc = skb_put(skb, size);
3879 nullfunc->frame_control = fc;
3880 nullfunc->duration_id = 0;
3881 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3882 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3883 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3884 nullfunc->seq_ctrl = 0;
3886 info = IEEE80211_SKB_CB(skb);
3888 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3889 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3892 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3895 nullfunc->qos_ctrl = cpu_to_le16(7);
3897 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3904 ieee80211_xmit(sdata, sta, skb);
3910 mutex_unlock(&local->mtx);
3915 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3916 struct wireless_dev *wdev,
3917 struct cfg80211_chan_def *chandef)
3919 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3920 struct ieee80211_local *local = wiphy_priv(wiphy);
3921 struct ieee80211_chanctx_conf *chanctx_conf;
3925 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3927 *chandef = sdata->vif.bss_conf.chandef;
3929 } else if (local->open_count > 0 &&
3930 local->open_count == local->monitors &&
3931 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3932 if (local->use_chanctx)
3933 *chandef = local->monitor_chandef;
3935 *chandef = local->_oper_chandef;
3944 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3946 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3950 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3951 struct net_device *dev,
3952 struct cfg80211_qos_map *qos_map)
3954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3955 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3958 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3961 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3963 /* A NULL qos_map was passed to disable QoS mapping */
3967 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3968 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3970 kfree_rcu(old_qos_map, rcu_head);
3975 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3976 struct net_device *dev,
3977 struct cfg80211_chan_def *chandef)
3979 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3983 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3985 ieee80211_bss_info_change_notify(sdata, changed);
3990 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3991 u8 tsid, const u8 *peer, u8 up,
3994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3995 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3996 int ac = ieee802_1d_to_ac[up];
3998 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4001 if (!(sdata->wmm_acm & BIT(up)))
4004 if (ifmgd->tx_tspec[ac].admitted_time)
4007 if (admitted_time) {
4008 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4009 ifmgd->tx_tspec[ac].tsid = tsid;
4010 ifmgd->tx_tspec[ac].up = up;
4016 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4017 u8 tsid, const u8 *peer)
4019 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4020 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4021 struct ieee80211_local *local = wiphy_priv(wiphy);
4024 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4025 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4027 /* skip unused entries */
4028 if (!tx_tspec->admitted_time)
4031 if (tx_tspec->tsid != tsid)
4034 /* due to this new packets will be reassigned to non-ACM ACs */
4037 /* Make sure that all packets have been sent to avoid to
4038 * restore the QoS params on packets that are still on the
4042 ieee80211_flush_queues(local, sdata, false);
4044 /* restore the normal QoS parameters
4045 * (unconditionally to avoid races)
4047 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4048 tx_tspec->downgraded = false;
4049 ieee80211_sta_handle_tspec_ac_params(sdata);
4051 /* finally clear all the data */
4052 memset(tx_tspec, 0, sizeof(*tx_tspec));
4060 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4062 enum nl80211_nan_func_term_reason reason,
4065 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4066 struct cfg80211_nan_func *func;
4069 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4072 spin_lock_bh(&sdata->u.nan.func_lock);
4074 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4075 if (WARN_ON(!func)) {
4076 spin_unlock_bh(&sdata->u.nan.func_lock);
4080 cookie = func->cookie;
4081 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4083 spin_unlock_bh(&sdata->u.nan.func_lock);
4085 cfg80211_free_nan_func(func);
4087 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4088 reason, cookie, gfp);
4090 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4092 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4093 struct cfg80211_nan_match_params *match,
4096 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4097 struct cfg80211_nan_func *func;
4099 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4102 spin_lock_bh(&sdata->u.nan.func_lock);
4104 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4105 if (WARN_ON(!func)) {
4106 spin_unlock_bh(&sdata->u.nan.func_lock);
4109 match->cookie = func->cookie;
4111 spin_unlock_bh(&sdata->u.nan.func_lock);
4113 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4115 EXPORT_SYMBOL(ieee80211_nan_func_match);
4117 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4118 struct net_device *dev,
4121 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4123 sdata->u.ap.multicast_to_unicast = enabled;
4128 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4129 struct txq_info *txqi)
4131 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4132 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4133 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4136 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4137 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4138 txqstats->backlog_packets = txqi->tin.backlog_packets;
4141 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4142 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4143 txqstats->flows = txqi->tin.flows;
4146 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4147 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4148 txqstats->drops = txqi->cstats.drop_count;
4151 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4152 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4153 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4156 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4157 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4158 txqstats->overlimit = txqi->tin.overlimit;
4161 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4162 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4163 txqstats->collisions = txqi->tin.collisions;
4166 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4167 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4168 txqstats->tx_bytes = txqi->tin.tx_bytes;
4171 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4172 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4173 txqstats->tx_packets = txqi->tin.tx_packets;
4177 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4178 struct wireless_dev *wdev,
4179 struct cfg80211_txq_stats *txqstats)
4181 struct ieee80211_local *local = wiphy_priv(wiphy);
4182 struct ieee80211_sub_if_data *sdata;
4185 if (!local->ops->wake_tx_queue)
4188 spin_lock_bh(&local->fq.lock);
4192 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4193 if (!sdata->vif.txq) {
4197 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4200 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4201 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4202 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4203 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4204 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4205 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4206 txqstats->backlog_packets = local->fq.backlog;
4207 txqstats->backlog_bytes = local->fq.memory_usage;
4208 txqstats->overlimit = local->fq.overlimit;
4209 txqstats->overmemory = local->fq.overmemory;
4210 txqstats->collisions = local->fq.collisions;
4211 txqstats->max_flows = local->fq.flows_cnt;
4216 spin_unlock_bh(&local->fq.lock);
4222 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4223 struct net_device *dev,
4224 struct cfg80211_ftm_responder_stats *ftm_stats)
4226 struct ieee80211_local *local = wiphy_priv(wiphy);
4227 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4229 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4233 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4234 struct cfg80211_pmsr_request *request)
4236 struct ieee80211_local *local = wiphy_priv(wiphy);
4237 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4239 return drv_start_pmsr(local, sdata, request);
4243 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4244 struct cfg80211_pmsr_request *request)
4246 struct ieee80211_local *local = wiphy_priv(wiphy);
4247 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4249 return drv_abort_pmsr(local, sdata, request);
4252 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4253 struct net_device *dev,
4254 struct cfg80211_tid_config *tid_conf)
4256 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4257 struct sta_info *sta;
4260 if (!sdata->local->ops->set_tid_config)
4263 if (!tid_conf->peer)
4264 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4266 mutex_lock(&sdata->local->sta_mtx);
4267 sta = sta_info_get_bss(sdata, tid_conf->peer);
4269 mutex_unlock(&sdata->local->sta_mtx);
4273 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4274 mutex_unlock(&sdata->local->sta_mtx);
4279 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4280 struct net_device *dev,
4281 const u8 *peer, u8 tids)
4283 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4284 struct sta_info *sta;
4287 if (!sdata->local->ops->reset_tid_config)
4291 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4293 mutex_lock(&sdata->local->sta_mtx);
4294 sta = sta_info_get_bss(sdata, peer);
4296 mutex_unlock(&sdata->local->sta_mtx);
4300 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4301 mutex_unlock(&sdata->local->sta_mtx);
4306 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4307 struct cfg80211_sar_specs *sar)
4309 struct ieee80211_local *local = wiphy_priv(wiphy);
4311 if (!local->ops->set_sar_specs)
4314 return local->ops->set_sar_specs(&local->hw, sar);
4318 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4321 switch (sdata->vif.type) {
4322 case NL80211_IFTYPE_AP: {
4325 if (!sdata->u.ap.next_beacon)
4328 ret = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
4330 ieee80211_free_next_beacon(sdata);
4347 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4348 struct cfg80211_color_change_settings *params,
4351 struct ieee80211_color_change_settings color_change = {};
4354 switch (sdata->vif.type) {
4355 case NL80211_IFTYPE_AP:
4356 sdata->u.ap.next_beacon =
4357 cfg80211_beacon_dup(¶ms->beacon_next);
4358 if (!sdata->u.ap.next_beacon)
4361 if (params->count <= 1)
4364 color_change.counter_offset_beacon =
4365 params->counter_offset_beacon;
4366 color_change.counter_offset_presp =
4367 params->counter_offset_presp;
4368 color_change.count = params->count;
4370 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_color_change,
4371 NULL, &color_change);
4373 ieee80211_free_next_beacon(sdata);
4386 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4387 u8 color, int enable, u32 changed)
4389 sdata->vif.bss_conf.he_bss_color.color = color;
4390 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4391 changed |= BSS_CHANGED_HE_BSS_COLOR;
4393 ieee80211_bss_info_change_notify(sdata, changed);
4395 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4396 struct ieee80211_sub_if_data *child;
4398 mutex_lock(&sdata->local->iflist_mtx);
4399 list_for_each_entry(child, &sdata->local->interfaces, list) {
4400 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4401 child->vif.bss_conf.he_bss_color.color = color;
4402 child->vif.bss_conf.he_bss_color.enabled = enable;
4403 ieee80211_bss_info_change_notify(child,
4404 BSS_CHANGED_HE_BSS_COLOR);
4407 mutex_unlock(&sdata->local->iflist_mtx);
4411 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4413 struct ieee80211_local *local = sdata->local;
4417 sdata_assert_lock(sdata);
4418 lockdep_assert_held(&local->mtx);
4420 sdata->vif.color_change_active = false;
4422 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4424 cfg80211_color_change_aborted_notify(sdata->dev);
4428 ieee80211_color_change_bss_config_notify(sdata,
4429 sdata->vif.color_change_color,
4431 cfg80211_color_change_notify(sdata->dev);
4436 void ieee80211_color_change_finalize_work(struct work_struct *work)
4438 struct ieee80211_sub_if_data *sdata =
4439 container_of(work, struct ieee80211_sub_if_data,
4440 color_change_finalize_work);
4441 struct ieee80211_local *local = sdata->local;
4444 mutex_lock(&local->mtx);
4446 /* AP might have been stopped while waiting for the lock. */
4447 if (!sdata->vif.color_change_active)
4450 if (!ieee80211_sdata_running(sdata))
4453 ieee80211_color_change_finalize(sdata);
4456 mutex_unlock(&local->mtx);
4457 sdata_unlock(sdata);
4460 void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4462 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4464 ieee80211_queue_work(&sdata->local->hw,
4465 &sdata->color_change_finalize_work);
4467 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4470 ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4471 u64 color_bitmap, gfp_t gfp)
4473 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4475 if (sdata->vif.color_change_active || sdata->vif.csa_active)
4478 cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap, gfp);
4480 EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4483 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4484 struct cfg80211_color_change_settings *params)
4486 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4487 struct ieee80211_local *local = sdata->local;
4491 sdata_assert_lock(sdata);
4493 if (sdata->vif.bss_conf.nontransmitted)
4496 mutex_lock(&local->mtx);
4498 /* don't allow another color change if one is already active or if csa
4501 if (sdata->vif.color_change_active || sdata->vif.csa_active) {
4506 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4510 sdata->vif.color_change_active = true;
4511 sdata->vif.color_change_color = params->color;
4513 cfg80211_color_change_started_notify(sdata->dev, params->count);
4516 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4518 /* if the beacon didn't change, we can finalize immediately */
4519 ieee80211_color_change_finalize(sdata);
4522 mutex_unlock(&local->mtx);
4528 ieee80211_set_radar_background(struct wiphy *wiphy,
4529 struct cfg80211_chan_def *chandef)
4531 struct ieee80211_local *local = wiphy_priv(wiphy);
4533 if (!local->ops->set_radar_background)
4536 return local->ops->set_radar_background(&local->hw, chandef);
4539 const struct cfg80211_ops mac80211_config_ops = {
4540 .add_virtual_intf = ieee80211_add_iface,
4541 .del_virtual_intf = ieee80211_del_iface,
4542 .change_virtual_intf = ieee80211_change_iface,
4543 .start_p2p_device = ieee80211_start_p2p_device,
4544 .stop_p2p_device = ieee80211_stop_p2p_device,
4545 .add_key = ieee80211_add_key,
4546 .del_key = ieee80211_del_key,
4547 .get_key = ieee80211_get_key,
4548 .set_default_key = ieee80211_config_default_key,
4549 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
4550 .set_default_beacon_key = ieee80211_config_default_beacon_key,
4551 .start_ap = ieee80211_start_ap,
4552 .change_beacon = ieee80211_change_beacon,
4553 .stop_ap = ieee80211_stop_ap,
4554 .add_station = ieee80211_add_station,
4555 .del_station = ieee80211_del_station,
4556 .change_station = ieee80211_change_station,
4557 .get_station = ieee80211_get_station,
4558 .dump_station = ieee80211_dump_station,
4559 .dump_survey = ieee80211_dump_survey,
4560 #ifdef CONFIG_MAC80211_MESH
4561 .add_mpath = ieee80211_add_mpath,
4562 .del_mpath = ieee80211_del_mpath,
4563 .change_mpath = ieee80211_change_mpath,
4564 .get_mpath = ieee80211_get_mpath,
4565 .dump_mpath = ieee80211_dump_mpath,
4566 .get_mpp = ieee80211_get_mpp,
4567 .dump_mpp = ieee80211_dump_mpp,
4568 .update_mesh_config = ieee80211_update_mesh_config,
4569 .get_mesh_config = ieee80211_get_mesh_config,
4570 .join_mesh = ieee80211_join_mesh,
4571 .leave_mesh = ieee80211_leave_mesh,
4573 .join_ocb = ieee80211_join_ocb,
4574 .leave_ocb = ieee80211_leave_ocb,
4575 .change_bss = ieee80211_change_bss,
4576 .set_txq_params = ieee80211_set_txq_params,
4577 .set_monitor_channel = ieee80211_set_monitor_channel,
4578 .suspend = ieee80211_suspend,
4579 .resume = ieee80211_resume,
4580 .scan = ieee80211_scan,
4581 .abort_scan = ieee80211_abort_scan,
4582 .sched_scan_start = ieee80211_sched_scan_start,
4583 .sched_scan_stop = ieee80211_sched_scan_stop,
4584 .auth = ieee80211_auth,
4585 .assoc = ieee80211_assoc,
4586 .deauth = ieee80211_deauth,
4587 .disassoc = ieee80211_disassoc,
4588 .join_ibss = ieee80211_join_ibss,
4589 .leave_ibss = ieee80211_leave_ibss,
4590 .set_mcast_rate = ieee80211_set_mcast_rate,
4591 .set_wiphy_params = ieee80211_set_wiphy_params,
4592 .set_tx_power = ieee80211_set_tx_power,
4593 .get_tx_power = ieee80211_get_tx_power,
4594 .rfkill_poll = ieee80211_rfkill_poll,
4595 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
4596 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
4597 .set_power_mgmt = ieee80211_set_power_mgmt,
4598 .set_bitrate_mask = ieee80211_set_bitrate_mask,
4599 .remain_on_channel = ieee80211_remain_on_channel,
4600 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4601 .mgmt_tx = ieee80211_mgmt_tx,
4602 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4603 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4604 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4605 .update_mgmt_frame_registrations =
4606 ieee80211_update_mgmt_frame_registrations,
4607 .set_antenna = ieee80211_set_antenna,
4608 .get_antenna = ieee80211_get_antenna,
4609 .set_rekey_data = ieee80211_set_rekey_data,
4610 .tdls_oper = ieee80211_tdls_oper,
4611 .tdls_mgmt = ieee80211_tdls_mgmt,
4612 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4613 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4614 .probe_client = ieee80211_probe_client,
4615 .set_noack_map = ieee80211_set_noack_map,
4617 .set_wakeup = ieee80211_set_wakeup,
4619 .get_channel = ieee80211_cfg_get_channel,
4620 .start_radar_detection = ieee80211_start_radar_detection,
4621 .end_cac = ieee80211_end_cac,
4622 .channel_switch = ieee80211_channel_switch,
4623 .set_qos_map = ieee80211_set_qos_map,
4624 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4625 .add_tx_ts = ieee80211_add_tx_ts,
4626 .del_tx_ts = ieee80211_del_tx_ts,
4627 .start_nan = ieee80211_start_nan,
4628 .stop_nan = ieee80211_stop_nan,
4629 .nan_change_conf = ieee80211_nan_change_conf,
4630 .add_nan_func = ieee80211_add_nan_func,
4631 .del_nan_func = ieee80211_del_nan_func,
4632 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4633 .tx_control_port = ieee80211_tx_control_port,
4634 .get_txq_stats = ieee80211_get_txq_stats,
4635 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4636 .start_pmsr = ieee80211_start_pmsr,
4637 .abort_pmsr = ieee80211_abort_pmsr,
4638 .probe_mesh_link = ieee80211_probe_mesh_link,
4639 .set_tid_config = ieee80211_set_tid_config,
4640 .reset_tid_config = ieee80211_reset_tid_config,
4641 .set_sar_specs = ieee80211_set_sar_specs,
4642 .color_change = ieee80211_color_change,
4643 .set_radar_background = ieee80211_set_radar_background,