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-2022 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_link_info_change_notify(sdata, 0,
43 BSS_CHANGED_MU_GROUPS);
44 /* don't care about endianness - just check for 0 */
45 memcpy(&membership, params->vht_mumimo_groups,
47 mu_mimo_groups = membership != 0;
50 if (params->vht_mumimo_follow_addr) {
52 is_valid_ether_addr(params->vht_mumimo_follow_addr);
53 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
54 params->vht_mumimo_follow_addr);
57 sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
60 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
61 struct vif_params *params)
63 struct ieee80211_local *local = sdata->local;
64 struct ieee80211_sub_if_data *monitor_sdata;
66 /* check flags first */
67 if (params->flags && ieee80211_sdata_running(sdata)) {
68 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
71 * Prohibit MONITOR_FLAG_COOK_FRAMES and
72 * MONITOR_FLAG_ACTIVE to be changed while the
74 * Else we would need to add a lot of cruft
75 * to update everything:
76 * cooked_mntrs, monitor and all fif_* counters
77 * reconfigure hardware
79 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
83 /* also validate MU-MIMO change */
84 monitor_sdata = wiphy_dereference(local->hw.wiphy,
85 local->monitor_sdata);
88 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
91 /* apply all changes now - no failures allowed */
94 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
97 if (ieee80211_sdata_running(sdata)) {
98 ieee80211_adjust_monitor_flags(sdata, -1);
99 sdata->u.mntr.flags = params->flags;
100 ieee80211_adjust_monitor_flags(sdata, 1);
102 ieee80211_configure_filter(local);
105 * Because the interface is down, ieee80211_do_stop
106 * and ieee80211_do_open take care of "everything"
107 * mentioned in the comment above.
109 sdata->u.mntr.flags = params->flags;
116 static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
117 struct cfg80211_mbssid_config params,
118 struct ieee80211_bss_conf *link_conf)
120 struct ieee80211_sub_if_data *tx_sdata;
122 sdata->vif.mbssid_tx_vif = NULL;
123 link_conf->bssid_index = 0;
124 link_conf->nontransmitted = false;
125 link_conf->ema_ap = false;
127 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
130 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
134 if (tx_sdata == sdata) {
135 sdata->vif.mbssid_tx_vif = &sdata->vif;
137 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
138 link_conf->nontransmitted = true;
139 link_conf->bssid_index = params.index;
142 link_conf->ema_ap = true;
147 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
149 unsigned char name_assign_type,
150 enum nl80211_iftype type,
151 struct vif_params *params)
153 struct ieee80211_local *local = wiphy_priv(wiphy);
154 struct wireless_dev *wdev;
155 struct ieee80211_sub_if_data *sdata;
158 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
162 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
164 if (type == NL80211_IFTYPE_MONITOR) {
165 err = ieee80211_set_mon_options(sdata, params);
167 ieee80211_if_remove(sdata);
175 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
177 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
182 static int ieee80211_change_iface(struct wiphy *wiphy,
183 struct net_device *dev,
184 enum nl80211_iftype type,
185 struct vif_params *params)
187 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
188 struct ieee80211_local *local = sdata->local;
189 struct sta_info *sta;
192 ret = ieee80211_if_change_type(sdata, type);
196 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
197 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
198 ieee80211_check_fast_rx_iface(sdata);
199 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
200 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
202 if (params->use_4addr == ifmgd->use_4addr)
205 sdata->u.mgd.use_4addr = params->use_4addr;
206 if (!ifmgd->associated)
209 mutex_lock(&local->sta_mtx);
210 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
212 drv_sta_set_4addr(local, sdata, &sta->sta,
214 mutex_unlock(&local->sta_mtx);
216 if (params->use_4addr)
217 ieee80211_send_4addr_nullfunc(local, sdata);
220 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
221 ret = ieee80211_set_mon_options(sdata, params);
229 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
230 struct wireless_dev *wdev)
232 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
235 mutex_lock(&sdata->local->chanctx_mtx);
236 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
237 mutex_unlock(&sdata->local->chanctx_mtx);
241 return ieee80211_do_open(wdev, true);
244 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
245 struct wireless_dev *wdev)
247 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
250 static int ieee80211_start_nan(struct wiphy *wiphy,
251 struct wireless_dev *wdev,
252 struct cfg80211_nan_conf *conf)
254 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
257 mutex_lock(&sdata->local->chanctx_mtx);
258 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
259 mutex_unlock(&sdata->local->chanctx_mtx);
263 ret = ieee80211_do_open(wdev, true);
267 ret = drv_start_nan(sdata->local, sdata, conf);
269 ieee80211_sdata_stop(sdata);
271 sdata->u.nan.conf = *conf;
276 static void ieee80211_stop_nan(struct wiphy *wiphy,
277 struct wireless_dev *wdev)
279 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
281 drv_stop_nan(sdata->local, sdata);
282 ieee80211_sdata_stop(sdata);
285 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
286 struct wireless_dev *wdev,
287 struct cfg80211_nan_conf *conf,
290 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
291 struct cfg80211_nan_conf new_conf;
294 if (sdata->vif.type != NL80211_IFTYPE_NAN)
297 if (!ieee80211_sdata_running(sdata))
300 new_conf = sdata->u.nan.conf;
302 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
303 new_conf.master_pref = conf->master_pref;
305 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
306 new_conf.bands = conf->bands;
308 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
310 sdata->u.nan.conf = new_conf;
315 static int ieee80211_add_nan_func(struct wiphy *wiphy,
316 struct wireless_dev *wdev,
317 struct cfg80211_nan_func *nan_func)
319 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
322 if (sdata->vif.type != NL80211_IFTYPE_NAN)
325 if (!ieee80211_sdata_running(sdata))
328 spin_lock_bh(&sdata->u.nan.func_lock);
330 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
331 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
333 spin_unlock_bh(&sdata->u.nan.func_lock);
338 nan_func->instance_id = ret;
340 WARN_ON(nan_func->instance_id == 0);
342 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
344 spin_lock_bh(&sdata->u.nan.func_lock);
345 idr_remove(&sdata->u.nan.function_inst_ids,
346 nan_func->instance_id);
347 spin_unlock_bh(&sdata->u.nan.func_lock);
353 static struct cfg80211_nan_func *
354 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
357 struct cfg80211_nan_func *func;
360 lockdep_assert_held(&sdata->u.nan.func_lock);
362 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
363 if (func->cookie == cookie)
370 static void ieee80211_del_nan_func(struct wiphy *wiphy,
371 struct wireless_dev *wdev, u64 cookie)
373 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
374 struct cfg80211_nan_func *func;
377 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
378 !ieee80211_sdata_running(sdata))
381 spin_lock_bh(&sdata->u.nan.func_lock);
383 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
385 instance_id = func->instance_id;
387 spin_unlock_bh(&sdata->u.nan.func_lock);
390 drv_del_nan_func(sdata->local, sdata, instance_id);
393 static int ieee80211_set_noack_map(struct wiphy *wiphy,
394 struct net_device *dev,
397 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
399 sdata->noack_map = noack_map;
401 ieee80211_check_fast_xmit_iface(sdata);
406 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
407 const u8 *mac_addr, u8 key_idx)
409 struct ieee80211_local *local = sdata->local;
410 struct ieee80211_key *key;
411 struct sta_info *sta;
414 if (!wiphy_ext_feature_isset(local->hw.wiphy,
415 NL80211_EXT_FEATURE_EXT_KEY_ID))
418 sta = sta_info_get_bss(sdata, mac_addr);
423 if (sta->ptk_idx == key_idx)
426 mutex_lock(&local->key_mtx);
427 key = key_mtx_dereference(local, sta->ptk[key_idx]);
429 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
430 ret = ieee80211_set_tx_key(key);
432 mutex_unlock(&local->key_mtx);
436 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
437 u8 key_idx, bool pairwise, const u8 *mac_addr,
438 struct key_params *params)
440 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
441 struct ieee80211_local *local = sdata->local;
442 struct sta_info *sta = NULL;
443 struct ieee80211_key *key;
446 if (!ieee80211_sdata_running(sdata))
449 if (pairwise && params->mode == NL80211_KEY_SET_TX)
450 return ieee80211_set_tx(sdata, mac_addr, key_idx);
452 /* reject WEP and TKIP keys if WEP failed to initialize */
453 switch (params->cipher) {
454 case WLAN_CIPHER_SUITE_WEP40:
455 case WLAN_CIPHER_SUITE_TKIP:
456 case WLAN_CIPHER_SUITE_WEP104:
457 if (WARN_ON_ONCE(fips_enabled))
464 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
465 params->key, params->seq_len, params->seq);
470 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
472 if (params->mode == NL80211_KEY_NO_TX)
473 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
475 mutex_lock(&local->sta_mtx);
478 sta = sta_info_get_bss(sdata, mac_addr);
480 * The ASSOC test makes sure the driver is ready to
481 * receive the key. When wpa_supplicant has roamed
482 * using FT, it attempts to set the key before
483 * association has completed, this rejects that attempt
484 * so it will set the key again after association.
486 * TODO: accept the key if we have a station entry and
487 * add it to the device after the station.
489 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
490 ieee80211_key_free_unused(key);
496 switch (sdata->vif.type) {
497 case NL80211_IFTYPE_STATION:
498 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
499 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
501 case NL80211_IFTYPE_AP:
502 case NL80211_IFTYPE_AP_VLAN:
503 /* Keys without a station are used for TX only */
504 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
505 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
507 case NL80211_IFTYPE_ADHOC:
510 case NL80211_IFTYPE_MESH_POINT:
511 #ifdef CONFIG_MAC80211_MESH
512 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
513 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
516 case NL80211_IFTYPE_WDS:
517 case NL80211_IFTYPE_MONITOR:
518 case NL80211_IFTYPE_P2P_DEVICE:
519 case NL80211_IFTYPE_NAN:
520 case NL80211_IFTYPE_UNSPECIFIED:
521 case NUM_NL80211_IFTYPES:
522 case NL80211_IFTYPE_P2P_CLIENT:
523 case NL80211_IFTYPE_P2P_GO:
524 case NL80211_IFTYPE_OCB:
525 /* shouldn't happen */
530 err = ieee80211_key_link(key, sdata, sta);
533 mutex_unlock(&local->sta_mtx);
538 static struct ieee80211_key *
539 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata,
540 u8 key_idx, bool pairwise, const u8 *mac_addr)
542 struct ieee80211_local *local = sdata->local;
543 struct ieee80211_key *key;
544 struct sta_info *sta;
547 sta = sta_info_get_bss(sdata, mac_addr);
551 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
552 return rcu_dereference_check_key_mtx(local,
556 key_idx < NUM_DEFAULT_KEYS +
557 NUM_DEFAULT_MGMT_KEYS +
558 NUM_DEFAULT_BEACON_KEYS)
559 return rcu_dereference_check_key_mtx(local,
560 sta->deflink.gtk[key_idx]);
565 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
566 return rcu_dereference_check_key_mtx(local,
567 sdata->keys[key_idx]);
569 key = rcu_dereference_check_key_mtx(local, sdata->deflink.gtk[key_idx]);
576 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
577 u8 key_idx, bool pairwise, const u8 *mac_addr)
579 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
580 struct ieee80211_local *local = sdata->local;
581 struct ieee80211_key *key;
584 mutex_lock(&local->sta_mtx);
585 mutex_lock(&local->key_mtx);
587 key = ieee80211_lookup_key(sdata, key_idx, pairwise, mac_addr);
593 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
597 mutex_unlock(&local->key_mtx);
598 mutex_unlock(&local->sta_mtx);
603 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
604 u8 key_idx, bool pairwise, const u8 *mac_addr,
606 void (*callback)(void *cookie,
607 struct key_params *params))
609 struct ieee80211_sub_if_data *sdata;
611 struct key_params params;
612 struct ieee80211_key *key;
617 struct ieee80211_key_seq kseq = {};
619 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
623 key = ieee80211_lookup_key(sdata, key_idx, pairwise, mac_addr);
627 memset(¶ms, 0, sizeof(params));
629 params.cipher = key->conf.cipher;
631 switch (key->conf.cipher) {
632 case WLAN_CIPHER_SUITE_TKIP:
633 pn64 = atomic64_read(&key->conf.tx_pn);
634 iv32 = TKIP_PN_TO_IV32(pn64);
635 iv16 = TKIP_PN_TO_IV16(pn64);
637 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
638 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
639 drv_get_key_seq(sdata->local, key, &kseq);
640 iv32 = kseq.tkip.iv32;
641 iv16 = kseq.tkip.iv16;
644 seq[0] = iv16 & 0xff;
645 seq[1] = (iv16 >> 8) & 0xff;
646 seq[2] = iv32 & 0xff;
647 seq[3] = (iv32 >> 8) & 0xff;
648 seq[4] = (iv32 >> 16) & 0xff;
649 seq[5] = (iv32 >> 24) & 0xff;
653 case WLAN_CIPHER_SUITE_CCMP:
654 case WLAN_CIPHER_SUITE_CCMP_256:
655 case WLAN_CIPHER_SUITE_AES_CMAC:
656 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
657 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
658 offsetof(typeof(kseq), aes_cmac));
660 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
661 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
662 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
663 offsetof(typeof(kseq), aes_gmac));
665 case WLAN_CIPHER_SUITE_GCMP:
666 case WLAN_CIPHER_SUITE_GCMP_256:
667 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
668 offsetof(typeof(kseq), gcmp));
670 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
671 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
672 drv_get_key_seq(sdata->local, key, &kseq);
673 memcpy(seq, kseq.ccmp.pn, 6);
675 pn64 = atomic64_read(&key->conf.tx_pn);
687 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
689 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
691 drv_get_key_seq(sdata->local, key, &kseq);
692 params.seq = kseq.hw.seq;
693 params.seq_len = kseq.hw.seq_len;
697 params.key = key->conf.key;
698 params.key_len = key->conf.keylen;
700 callback(cookie, ¶ms);
708 static int ieee80211_config_default_key(struct wiphy *wiphy,
709 struct net_device *dev,
710 u8 key_idx, bool uni,
713 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
715 ieee80211_set_default_key(sdata, key_idx, uni, multi);
720 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
721 struct net_device *dev,
724 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
726 ieee80211_set_default_mgmt_key(sdata, key_idx);
731 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
732 struct net_device *dev,
735 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
737 ieee80211_set_default_beacon_key(sdata, key_idx);
742 void sta_set_rate_info_tx(struct sta_info *sta,
743 const struct ieee80211_tx_rate *rate,
744 struct rate_info *rinfo)
747 if (rate->flags & IEEE80211_TX_RC_MCS) {
748 rinfo->flags |= RATE_INFO_FLAGS_MCS;
749 rinfo->mcs = rate->idx;
750 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
751 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
752 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
753 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
755 struct ieee80211_supported_band *sband;
756 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
759 sband = ieee80211_get_sband(sta->sdata);
760 WARN_ON_ONCE(sband && !sband->bitrates);
761 if (sband && sband->bitrates) {
762 brate = sband->bitrates[rate->idx].bitrate;
763 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
766 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
767 rinfo->bw = RATE_INFO_BW_40;
768 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
769 rinfo->bw = RATE_INFO_BW_80;
770 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
771 rinfo->bw = RATE_INFO_BW_160;
773 rinfo->bw = RATE_INFO_BW_20;
774 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
775 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
778 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
779 int idx, u8 *mac, struct station_info *sinfo)
781 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
782 struct ieee80211_local *local = sdata->local;
783 struct sta_info *sta;
786 mutex_lock(&local->sta_mtx);
788 sta = sta_info_get_by_idx(sdata, idx);
791 memcpy(mac, sta->sta.addr, ETH_ALEN);
792 sta_set_sinfo(sta, sinfo, true);
795 mutex_unlock(&local->sta_mtx);
800 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
801 int idx, struct survey_info *survey)
803 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
805 return drv_get_survey(local, idx, survey);
808 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
809 const u8 *mac, struct station_info *sinfo)
811 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
812 struct ieee80211_local *local = sdata->local;
813 struct sta_info *sta;
816 mutex_lock(&local->sta_mtx);
818 sta = sta_info_get_bss(sdata, mac);
821 sta_set_sinfo(sta, sinfo, true);
824 mutex_unlock(&local->sta_mtx);
829 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
830 struct cfg80211_chan_def *chandef)
832 struct ieee80211_local *local = wiphy_priv(wiphy);
833 struct ieee80211_sub_if_data *sdata;
836 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
839 mutex_lock(&local->mtx);
840 if (local->use_chanctx) {
841 sdata = wiphy_dereference(local->hw.wiphy,
842 local->monitor_sdata);
844 ieee80211_link_release_channel(sdata->link[0]);
845 ret = ieee80211_link_use_channel(sdata->link[0],
847 IEEE80211_CHANCTX_EXCLUSIVE);
849 } else if (local->open_count == local->monitors) {
850 local->_oper_chandef = *chandef;
851 ieee80211_hw_config(local, 0);
855 local->monitor_chandef = *chandef;
856 mutex_unlock(&local->mtx);
862 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
863 const u8 *resp, size_t resp_len,
864 const struct ieee80211_csa_settings *csa,
865 const struct ieee80211_color_change_settings *cca,
866 struct ieee80211_link_data *link)
868 struct probe_resp *new, *old;
870 if (!resp || !resp_len)
873 old = sdata_dereference(link->u.ap.probe_resp, sdata);
875 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
880 memcpy(new->data, resp, resp_len);
883 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
884 csa->n_counter_offsets_presp *
885 sizeof(new->cntdwn_counter_offsets[0]));
887 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
889 rcu_assign_pointer(link->u.ap.probe_resp, new);
891 kfree_rcu(old, rcu_head);
896 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
897 struct cfg80211_fils_discovery *params,
898 struct ieee80211_link_data *link,
899 struct ieee80211_bss_conf *link_conf)
901 struct fils_discovery_data *new, *old = NULL;
902 struct ieee80211_fils_discovery *fd;
904 if (!params->tmpl || !params->tmpl_len)
907 fd = &link_conf->fils_discovery;
908 fd->min_interval = params->min_interval;
909 fd->max_interval = params->max_interval;
911 old = sdata_dereference(link->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(link->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,
928 struct ieee80211_link_data *link,
929 struct ieee80211_bss_conf *link_conf)
931 struct unsol_bcast_probe_resp_data *new, *old = NULL;
933 if (!params->tmpl || !params->tmpl_len)
936 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
937 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
940 new->len = params->tmpl_len;
941 memcpy(new->data, params->tmpl, params->tmpl_len);
942 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
945 kfree_rcu(old, rcu_head);
947 link_conf->unsol_bcast_probe_resp_interval = params->interval;
952 static int ieee80211_set_ftm_responder_params(
953 struct ieee80211_sub_if_data *sdata,
954 const u8 *lci, size_t lci_len,
955 const u8 *civicloc, size_t civicloc_len,
956 struct ieee80211_bss_conf *link_conf)
958 struct ieee80211_ftm_responder_params *new, *old;
962 if (!lci_len && !civicloc_len)
965 old = link_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 link_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;
1020 struct ieee80211_link_data *link = sdata->link[params->link_id];
1021 struct ieee80211_bss_conf *link_conf =
1022 sdata->vif.link_conf[params->link_id];
1024 old = sdata_dereference(link->u.ap.beacon, sdata);
1026 /* Need to have a beacon head if we don't have one yet */
1027 if (!params->head && !old)
1030 /* new or old head? */
1032 new_head_len = params->head_len;
1034 new_head_len = old->head_len;
1036 /* new or old tail? */
1037 if (params->tail || !old)
1038 /* params->tail_len will be zero for !params->tail */
1039 new_tail_len = params->tail_len;
1041 new_tail_len = old->tail_len;
1043 size = sizeof(*new) + new_head_len + new_tail_len;
1045 /* new or old multiple BSSID elements? */
1046 if (params->mbssid_ies) {
1047 mbssid = params->mbssid_ies;
1048 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1049 size += ieee80211_get_mbssid_beacon_len(mbssid);
1050 } else if (old && old->mbssid_ies) {
1051 mbssid = old->mbssid_ies;
1052 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1053 size += ieee80211_get_mbssid_beacon_len(mbssid);
1056 new = kzalloc(size, GFP_KERNEL);
1060 /* start filling the new info now */
1063 * pointers go into the block we allocated,
1064 * memory is | beacon_data | head | tail | mbssid_ies
1066 new->head = ((u8 *) new) + sizeof(*new);
1067 new->tail = new->head + new_head_len;
1068 new->head_len = new_head_len;
1069 new->tail_len = new_tail_len;
1070 /* copy in optional mbssid_ies */
1072 u8 *pos = new->tail + new->tail_len;
1074 new->mbssid_ies = (void *)pos;
1075 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1076 ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid);
1077 /* update bssid_indicator */
1078 link_conf->bssid_indicator =
1079 ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
1083 new->cntdwn_current_counter = csa->count;
1084 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1085 csa->n_counter_offsets_beacon *
1086 sizeof(new->cntdwn_counter_offsets[0]));
1088 new->cntdwn_current_counter = cca->count;
1089 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1094 memcpy(new->head, params->head, new_head_len);
1096 memcpy(new->head, old->head, new_head_len);
1098 /* copy in optional tail */
1100 memcpy(new->tail, params->tail, new_tail_len);
1103 memcpy(new->tail, old->tail, new_tail_len);
1105 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1106 params->probe_resp_len, csa, cca, link);
1112 changed |= BSS_CHANGED_AP_PROBE_RESP;
1114 if (params->ftm_responder != -1) {
1115 link_conf->ftm_responder = params->ftm_responder;
1116 err = ieee80211_set_ftm_responder_params(sdata,
1120 params->civicloc_len,
1128 changed |= BSS_CHANGED_FTM_RESPONDER;
1131 rcu_assign_pointer(link->u.ap.beacon, new);
1132 sdata->u.ap.active = true;
1135 kfree_rcu(old, rcu_head);
1140 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1141 struct cfg80211_ap_settings *params)
1143 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1144 struct ieee80211_local *local = sdata->local;
1145 struct beacon_data *old;
1146 struct ieee80211_sub_if_data *vlan;
1147 u32 changed = BSS_CHANGED_BEACON_INT |
1148 BSS_CHANGED_BEACON_ENABLED |
1149 BSS_CHANGED_BEACON |
1150 BSS_CHANGED_P2P_PS |
1151 BSS_CHANGED_TXPOWER |
1154 int prev_beacon_int;
1155 unsigned int link_id = params->beacon.link_id;
1156 struct ieee80211_link_data *link = sdata->link[link_id];
1157 struct ieee80211_bss_conf *link_conf = sdata->vif.link_conf[link_id];
1159 old = sdata_dereference(link->u.ap.beacon, sdata);
1163 if (params->smps_mode != NL80211_SMPS_OFF)
1166 link->smps_mode = IEEE80211_SMPS_OFF;
1168 link->needed_rx_chains = sdata->local->rx_chains;
1170 prev_beacon_int = link_conf->beacon_int;
1171 link_conf->beacon_int = params->beacon_interval;
1173 if (params->he_cap && params->he_oper) {
1174 link_conf->he_support = true;
1175 link_conf->htc_trig_based_pkt_ext =
1176 le32_get_bits(params->he_oper->he_oper_params,
1177 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1178 link_conf->frame_time_rts_th =
1179 le32_get_bits(params->he_oper->he_oper_params,
1180 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1181 changed |= BSS_CHANGED_HE_OBSS_PD;
1183 if (params->beacon.he_bss_color.enabled)
1184 changed |= BSS_CHANGED_HE_BSS_COLOR;
1187 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1188 params->mbssid_config.tx_wdev) {
1189 err = ieee80211_set_ap_mbssid_options(sdata,
1190 params->mbssid_config,
1196 mutex_lock(&local->mtx);
1197 err = ieee80211_link_use_channel(link, ¶ms->chandef,
1198 IEEE80211_CHANCTX_SHARED);
1200 ieee80211_link_copy_chanctx_to_vlans(link, false);
1201 mutex_unlock(&local->mtx);
1203 link_conf->beacon_int = prev_beacon_int;
1208 * Apply control port protocol, this allows us to
1209 * not encrypt dynamic WEP control frames.
1211 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1212 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1213 sdata->control_port_over_nl80211 =
1214 params->crypto.control_port_over_nl80211;
1215 sdata->control_port_no_preauth =
1216 params->crypto.control_port_no_preauth;
1218 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1219 vlan->control_port_protocol =
1220 params->crypto.control_port_ethertype;
1221 vlan->control_port_no_encrypt =
1222 params->crypto.control_port_no_encrypt;
1223 vlan->control_port_over_nl80211 =
1224 params->crypto.control_port_over_nl80211;
1225 vlan->control_port_no_preauth =
1226 params->crypto.control_port_no_preauth;
1229 link_conf->dtim_period = params->dtim_period;
1230 link_conf->enable_beacon = true;
1231 link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1232 link_conf->twt_responder = params->twt_responder;
1233 link_conf->he_obss_pd = params->he_obss_pd;
1234 link_conf->he_bss_color = params->beacon.he_bss_color;
1235 sdata->vif.cfg.s1g = params->chandef.chan->band ==
1238 sdata->vif.cfg.ssid_len = params->ssid_len;
1239 if (params->ssid_len)
1240 memcpy(sdata->vif.cfg.ssid, params->ssid,
1242 link_conf->hidden_ssid =
1243 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1245 memset(&link_conf->p2p_noa_attr, 0,
1246 sizeof(link_conf->p2p_noa_attr));
1247 link_conf->p2p_noa_attr.oppps_ctwindow =
1248 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1249 if (params->p2p_opp_ps)
1250 link_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 link_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,
1278 changed |= BSS_CHANGED_FILS_DISCOVERY;
1281 if (params->unsol_bcast_probe_resp.interval) {
1282 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1283 ¶ms->unsol_bcast_probe_resp,
1287 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1290 err = drv_start_ap(sdata->local, sdata, link_id);
1292 old = sdata_dereference(link->u.ap.beacon, sdata);
1295 kfree_rcu(old, rcu_head);
1296 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1297 sdata->u.ap.active = false;
1301 ieee80211_recalc_dtim(local, sdata);
1302 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
1303 ieee80211_link_info_change_notify(sdata, link_id, changed);
1305 netif_carrier_on(dev);
1306 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1307 netif_carrier_on(vlan->dev);
1312 mutex_lock(&local->mtx);
1313 ieee80211_link_release_channel(link);
1314 mutex_unlock(&local->mtx);
1319 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1320 struct cfg80211_beacon_data *params)
1322 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1323 struct beacon_data *old;
1325 struct ieee80211_bss_conf *link_conf =
1326 sdata->vif.link_conf[params->link_id];
1328 sdata_assert_lock(sdata);
1330 /* don't allow changing the beacon while a countdown is in place - offset
1331 * of channel switch counter may change
1333 if (link_conf->csa_active || link_conf->color_change_active)
1336 old = sdata_dereference(sdata->link[params->link_id]->u.ap.beacon,
1341 err = ieee80211_assign_beacon(sdata, params, NULL, NULL);
1345 if (params->he_bss_color_valid &&
1346 params->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1347 link_conf->he_bss_color.enabled = params->he_bss_color.enabled;
1348 err |= BSS_CHANGED_HE_BSS_COLOR;
1351 ieee80211_link_info_change_notify(sdata, params->link_id, err);
1355 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
1357 if (!link->u.ap.next_beacon)
1360 kfree(link->u.ap.next_beacon->mbssid_ies);
1361 kfree(link->u.ap.next_beacon);
1362 link->u.ap.next_beacon = NULL;
1365 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1366 unsigned int link_id)
1368 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1369 struct ieee80211_sub_if_data *vlan;
1370 struct ieee80211_local *local = sdata->local;
1371 struct beacon_data *old_beacon;
1372 struct probe_resp *old_probe_resp;
1373 struct fils_discovery_data *old_fils_discovery;
1374 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1375 struct cfg80211_chan_def chandef;
1376 struct ieee80211_link_data *link = sdata->link[link_id];
1377 struct ieee80211_bss_conf *link_conf = sdata->vif.link_conf[link_id];
1379 sdata_assert_lock(sdata);
1381 old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
1384 old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
1386 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
1388 old_unsol_bcast_probe_resp =
1389 sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
1392 /* abort any running channel switch */
1393 mutex_lock(&local->mtx);
1394 link_conf->csa_active = false;
1395 if (link->csa_block_tx) {
1396 ieee80211_wake_vif_queues(local, sdata,
1397 IEEE80211_QUEUE_STOP_REASON_CSA);
1398 link->csa_block_tx = false;
1401 mutex_unlock(&local->mtx);
1403 ieee80211_free_next_beacon(link);
1405 /* turn off carrier for this interface and dependent VLANs */
1406 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1407 netif_carrier_off(vlan->dev);
1408 netif_carrier_off(dev);
1410 /* remove beacon and probe response */
1411 sdata->u.ap.active = false;
1412 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1413 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1414 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1415 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1416 kfree_rcu(old_beacon, rcu_head);
1418 kfree_rcu(old_probe_resp, rcu_head);
1419 if (old_fils_discovery)
1420 kfree_rcu(old_fils_discovery, rcu_head);
1421 if (old_unsol_bcast_probe_resp)
1422 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1424 kfree(link_conf->ftmr_params);
1425 link_conf->ftmr_params = NULL;
1427 __sta_info_flush(sdata, true);
1428 ieee80211_free_keys(sdata, true);
1430 link_conf->enable_beacon = false;
1431 sdata->beacon_rate_set = false;
1432 sdata->vif.cfg.ssid_len = 0;
1433 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1434 ieee80211_link_info_change_notify(sdata, link_id,
1435 BSS_CHANGED_BEACON_ENABLED);
1437 if (sdata->wdev.cac_started) {
1438 chandef = link_conf->chandef;
1439 cancel_delayed_work_sync(&link->dfs_cac_timer_work);
1440 cfg80211_cac_event(sdata->dev, &chandef,
1441 NL80211_RADAR_CAC_ABORTED,
1445 drv_stop_ap(sdata->local, sdata, link_id);
1447 /* free all potentially still buffered bcast frames */
1448 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1449 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1451 mutex_lock(&local->mtx);
1452 ieee80211_link_copy_chanctx_to_vlans(link, true);
1453 ieee80211_link_release_channel(link);
1454 mutex_unlock(&local->mtx);
1459 static int sta_apply_auth_flags(struct ieee80211_local *local,
1460 struct sta_info *sta,
1465 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1466 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1467 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1468 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1473 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1474 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1475 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1477 * When peer becomes associated, init rate control as
1478 * well. Some drivers require rate control initialized
1479 * before drv_sta_state() is called.
1481 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1482 rate_control_rate_init(sta);
1484 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1489 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1490 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1491 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1492 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1493 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1500 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1501 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1502 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1503 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1508 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1509 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1510 test_sta_flag(sta, WLAN_STA_AUTH)) {
1511 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1519 static void sta_apply_mesh_params(struct ieee80211_local *local,
1520 struct sta_info *sta,
1521 struct station_parameters *params)
1523 #ifdef CONFIG_MAC80211_MESH
1524 struct ieee80211_sub_if_data *sdata = sta->sdata;
1527 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1528 switch (params->plink_state) {
1529 case NL80211_PLINK_ESTAB:
1530 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1531 changed = mesh_plink_inc_estab_count(sdata);
1532 sta->mesh->plink_state = params->plink_state;
1533 sta->mesh->aid = params->peer_aid;
1535 ieee80211_mps_sta_status_update(sta);
1536 changed |= ieee80211_mps_set_sta_local_pm(sta,
1537 sdata->u.mesh.mshcfg.power_mode);
1539 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1540 /* init at low value */
1541 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1544 case NL80211_PLINK_LISTEN:
1545 case NL80211_PLINK_BLOCKED:
1546 case NL80211_PLINK_OPN_SNT:
1547 case NL80211_PLINK_OPN_RCVD:
1548 case NL80211_PLINK_CNF_RCVD:
1549 case NL80211_PLINK_HOLDING:
1550 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1551 changed = mesh_plink_dec_estab_count(sdata);
1552 sta->mesh->plink_state = params->plink_state;
1554 ieee80211_mps_sta_status_update(sta);
1555 changed |= ieee80211_mps_set_sta_local_pm(sta,
1556 NL80211_MESH_POWER_UNKNOWN);
1564 switch (params->plink_action) {
1565 case NL80211_PLINK_ACTION_NO_ACTION:
1568 case NL80211_PLINK_ACTION_OPEN:
1569 changed |= mesh_plink_open(sta);
1571 case NL80211_PLINK_ACTION_BLOCK:
1572 changed |= mesh_plink_block(sta);
1576 if (params->local_pm)
1577 changed |= ieee80211_mps_set_sta_local_pm(sta,
1580 ieee80211_mbss_info_change_notify(sdata, changed);
1584 static int sta_link_apply_parameters(struct ieee80211_local *local,
1585 struct sta_info *sta,
1586 struct link_station_parameters *params)
1589 struct ieee80211_supported_band *sband;
1590 struct ieee80211_sub_if_data *sdata = sta->sdata;
1591 u32 link_id = params->link_id < 0 ? 0 : params->link_id;
1592 struct link_sta_info *link_sta =
1593 rcu_dereference_protected(sta->link[link_id],
1594 lockdep_is_held(&local->sta_mtx));
1599 sband = ieee80211_get_link_sband(sdata, link_id);
1603 if (params->link_mac) {
1604 memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
1605 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
1608 if (params->txpwr_set) {
1609 link_sta->pub->txpwr.type = params->txpwr.type;
1610 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1611 link_sta->pub->txpwr.power = params->txpwr.power;
1612 ret = drv_sta_set_txpwr(local, sdata, sta);
1617 if (params->supported_rates &&
1618 params->supported_rates_len) {
1619 ieee80211_parse_bitrates(&sdata->vif.link_conf[link_id]->chandef,
1620 sband, params->supported_rates,
1621 params->supported_rates_len,
1622 &link_sta->pub->supp_rates[sband->band]);
1625 if (params->ht_capa)
1626 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1627 params->ht_capa, link_sta);
1629 /* VHT can override some HT caps such as the A-MSDU max length */
1630 if (params->vht_capa)
1631 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1632 params->vht_capa, link_sta);
1634 if (params->he_capa)
1635 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1636 (void *)params->he_capa,
1637 params->he_capa_len,
1638 (void *)params->he_6ghz_capa,
1641 if (params->eht_capa)
1642 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1643 (u8 *)params->he_capa,
1644 params->he_capa_len,
1646 params->eht_capa_len,
1649 if (params->opmode_notif_used) {
1650 /* returned value is only needed for rc update, but the
1651 * rc isn't initialized here yet, so ignore it
1653 __ieee80211_vht_handle_opmode(sdata, link_sta,
1654 params->opmode_notif,
1661 static int sta_apply_parameters(struct ieee80211_local *local,
1662 struct sta_info *sta,
1663 struct station_parameters *params)
1666 struct ieee80211_supported_band *sband;
1667 struct ieee80211_sub_if_data *sdata = sta->sdata;
1668 u32 link_id = params->link_sta_params.link_id < 0 ?
1669 0 : params->link_sta_params.link_id;
1672 sband = ieee80211_get_link_sband(sdata, link_id);
1676 mask = params->sta_flags_mask;
1677 set = params->sta_flags_set;
1679 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1681 * In mesh mode, ASSOCIATED isn't part of the nl80211
1682 * API but must follow AUTHENTICATED for driver state.
1684 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1685 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1686 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1687 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1688 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1690 * TDLS -- everything follows authorized, but
1691 * only becoming authorized is possible, not
1694 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1695 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1696 BIT(NL80211_STA_FLAG_ASSOCIATED);
1697 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1698 BIT(NL80211_STA_FLAG_ASSOCIATED);
1702 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1703 local->hw.queues >= IEEE80211_NUM_ACS)
1704 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1706 /* auth flags will be set later for TDLS,
1707 * and for unassociated stations that move to associated */
1708 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1709 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1710 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1711 ret = sta_apply_auth_flags(local, sta, mask, set);
1716 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1717 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1718 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1720 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1723 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1724 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1725 if (set & BIT(NL80211_STA_FLAG_MFP))
1726 set_sta_flag(sta, WLAN_STA_MFP);
1728 clear_sta_flag(sta, WLAN_STA_MFP);
1731 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1732 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1733 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1735 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1738 /* mark TDLS channel switch support, if the AP allows it */
1739 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1740 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1741 params->ext_capab_len >= 4 &&
1742 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1743 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1745 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1746 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1747 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1748 params->ext_capab_len >= 8 &&
1749 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1750 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1752 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1753 sta->sta.uapsd_queues = params->uapsd_queues;
1754 sta->sta.max_sp = params->max_sp;
1757 /* The sender might not have sent the last bit, consider it to be 0 */
1758 if (params->ext_capab_len >= 8) {
1759 u8 val = (params->ext_capab[7] &
1760 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1762 /* we did get all the bits, take the MSB as well */
1763 if (params->ext_capab_len >= 9) {
1764 u8 val_msb = params->ext_capab[8] &
1765 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1772 sta->sta.max_amsdu_subframes = 32;
1775 sta->sta.max_amsdu_subframes = 16;
1778 sta->sta.max_amsdu_subframes = 8;
1781 sta->sta.max_amsdu_subframes = 0;
1786 * cfg80211 validates this (1-2007) and allows setting the AID
1787 * only when creating a new station entry
1790 sta->sta.aid = params->aid;
1793 * Some of the following updates would be racy if called on an
1794 * existing station, via ieee80211_change_station(). However,
1795 * all such changes are rejected by cfg80211 except for updates
1796 * changing the supported rates on an existing but not yet used
1800 if (params->listen_interval >= 0)
1801 sta->listen_interval = params->listen_interval;
1803 ret = sta_link_apply_parameters(local, sta, ¶ms->link_sta_params);
1807 if (params->support_p2p_ps >= 0)
1808 sta->sta.support_p2p_ps = params->support_p2p_ps;
1810 if (ieee80211_vif_is_mesh(&sdata->vif))
1811 sta_apply_mesh_params(local, sta, params);
1813 if (params->airtime_weight)
1814 sta->airtime_weight = params->airtime_weight;
1816 /* set the STA state after all sta info from usermode has been set */
1817 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1818 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1819 ret = sta_apply_auth_flags(local, sta, mask, set);
1827 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1829 struct station_parameters *params)
1831 struct ieee80211_local *local = wiphy_priv(wiphy);
1832 struct sta_info *sta;
1833 struct ieee80211_sub_if_data *sdata;
1837 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1839 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1840 sdata->vif.type != NL80211_IFTYPE_AP)
1843 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1845 if (ether_addr_equal(mac, sdata->vif.addr))
1848 if (!is_valid_ether_addr(mac))
1851 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
1852 sdata->vif.type == NL80211_IFTYPE_STATION &&
1853 !sdata->u.mgd.associated)
1856 sta = sta_info_alloc(sdata, mac, params->link_sta_params.link_id,
1861 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1862 sta->sta.tdls = true;
1864 /* Though the mutex is not needed here (since the station is not
1865 * visible yet), sta_apply_parameters (and inner functions) require
1866 * the mutex due to other paths.
1868 mutex_lock(&local->sta_mtx);
1869 err = sta_apply_parameters(local, sta, params);
1870 mutex_unlock(&local->sta_mtx);
1872 sta_info_free(local, sta);
1877 * for TDLS and for unassociated station, rate control should be
1878 * initialized only when rates are known and station is marked
1879 * authorized/associated
1881 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1882 test_sta_flag(sta, WLAN_STA_ASSOC))
1883 rate_control_rate_init(sta);
1885 return sta_info_insert(sta);
1888 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1889 struct station_del_parameters *params)
1891 struct ieee80211_sub_if_data *sdata;
1893 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1896 return sta_info_destroy_addr_bss(sdata, params->mac);
1898 sta_info_flush(sdata);
1902 static int ieee80211_change_station(struct wiphy *wiphy,
1903 struct net_device *dev, const u8 *mac,
1904 struct station_parameters *params)
1906 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1907 struct ieee80211_local *local = wiphy_priv(wiphy);
1908 struct sta_info *sta;
1909 struct ieee80211_sub_if_data *vlansdata;
1910 enum cfg80211_station_type statype;
1913 mutex_lock(&local->sta_mtx);
1915 sta = sta_info_get_bss(sdata, mac);
1921 switch (sdata->vif.type) {
1922 case NL80211_IFTYPE_MESH_POINT:
1923 if (sdata->u.mesh.user_mpm)
1924 statype = CFG80211_STA_MESH_PEER_USER;
1926 statype = CFG80211_STA_MESH_PEER_KERNEL;
1928 case NL80211_IFTYPE_ADHOC:
1929 statype = CFG80211_STA_IBSS;
1931 case NL80211_IFTYPE_STATION:
1932 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1933 statype = CFG80211_STA_AP_STA;
1936 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1937 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1939 statype = CFG80211_STA_TDLS_PEER_SETUP;
1941 case NL80211_IFTYPE_AP:
1942 case NL80211_IFTYPE_AP_VLAN:
1943 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1944 statype = CFG80211_STA_AP_CLIENT;
1946 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1953 err = cfg80211_check_station_change(wiphy, params, statype);
1957 if (params->vlan && params->vlan != sta->sdata->dev) {
1958 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1960 if (params->vlan->ieee80211_ptr->use_4addr) {
1961 if (vlansdata->u.vlan.sta) {
1966 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1967 __ieee80211_check_fast_rx_iface(vlansdata);
1968 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
1971 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1972 sta->sdata->u.vlan.sta) {
1973 ieee80211_clear_fast_rx(sta);
1974 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1977 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1978 ieee80211_vif_dec_num_mcast(sta->sdata);
1980 sta->sdata = vlansdata;
1981 ieee80211_check_fast_xmit(sta);
1983 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1984 ieee80211_vif_inc_num_mcast(sta->sdata);
1985 cfg80211_send_layer2_update(sta->sdata->dev,
1990 err = sta_apply_parameters(local, sta, params);
1994 mutex_unlock(&local->sta_mtx);
1996 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1997 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1998 ieee80211_recalc_ps(local);
1999 ieee80211_recalc_ps_vif(sdata);
2004 mutex_unlock(&local->sta_mtx);
2008 #ifdef CONFIG_MAC80211_MESH
2009 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2010 const u8 *dst, const u8 *next_hop)
2012 struct ieee80211_sub_if_data *sdata;
2013 struct mesh_path *mpath;
2014 struct sta_info *sta;
2016 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2019 sta = sta_info_get(sdata, next_hop);
2025 mpath = mesh_path_add(sdata, dst);
2026 if (IS_ERR(mpath)) {
2028 return PTR_ERR(mpath);
2031 mesh_path_fix_nexthop(mpath, sta);
2037 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2040 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2043 return mesh_path_del(sdata, dst);
2045 mesh_path_flush_by_iface(sdata);
2049 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2050 const u8 *dst, const u8 *next_hop)
2052 struct ieee80211_sub_if_data *sdata;
2053 struct mesh_path *mpath;
2054 struct sta_info *sta;
2056 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2060 sta = sta_info_get(sdata, next_hop);
2066 mpath = mesh_path_lookup(sdata, dst);
2072 mesh_path_fix_nexthop(mpath, sta);
2078 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2079 struct mpath_info *pinfo)
2081 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2084 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2086 eth_zero_addr(next_hop);
2088 memset(pinfo, 0, sizeof(*pinfo));
2090 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2092 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2095 MPATH_INFO_EXPTIME |
2096 MPATH_INFO_DISCOVERY_TIMEOUT |
2097 MPATH_INFO_DISCOVERY_RETRIES |
2099 MPATH_INFO_HOP_COUNT |
2100 MPATH_INFO_PATH_CHANGE;
2102 pinfo->frame_qlen = mpath->frame_queue.qlen;
2103 pinfo->sn = mpath->sn;
2104 pinfo->metric = mpath->metric;
2105 if (time_before(jiffies, mpath->exp_time))
2106 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2107 pinfo->discovery_timeout =
2108 jiffies_to_msecs(mpath->discovery_timeout);
2109 pinfo->discovery_retries = mpath->discovery_retries;
2110 if (mpath->flags & MESH_PATH_ACTIVE)
2111 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2112 if (mpath->flags & MESH_PATH_RESOLVING)
2113 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2114 if (mpath->flags & MESH_PATH_SN_VALID)
2115 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2116 if (mpath->flags & MESH_PATH_FIXED)
2117 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2118 if (mpath->flags & MESH_PATH_RESOLVED)
2119 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2120 pinfo->hop_count = mpath->hop_count;
2121 pinfo->path_change_count = mpath->path_change_count;
2124 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2125 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2128 struct ieee80211_sub_if_data *sdata;
2129 struct mesh_path *mpath;
2131 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2134 mpath = mesh_path_lookup(sdata, dst);
2139 memcpy(dst, mpath->dst, ETH_ALEN);
2140 mpath_set_pinfo(mpath, next_hop, pinfo);
2145 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2146 int idx, u8 *dst, u8 *next_hop,
2147 struct mpath_info *pinfo)
2149 struct ieee80211_sub_if_data *sdata;
2150 struct mesh_path *mpath;
2152 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2155 mpath = mesh_path_lookup_by_idx(sdata, idx);
2160 memcpy(dst, mpath->dst, ETH_ALEN);
2161 mpath_set_pinfo(mpath, next_hop, pinfo);
2166 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2167 struct mpath_info *pinfo)
2169 memset(pinfo, 0, sizeof(*pinfo));
2170 memcpy(mpp, mpath->mpp, ETH_ALEN);
2172 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2175 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2176 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2179 struct ieee80211_sub_if_data *sdata;
2180 struct mesh_path *mpath;
2182 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2185 mpath = mpp_path_lookup(sdata, dst);
2190 memcpy(dst, mpath->dst, ETH_ALEN);
2191 mpp_set_pinfo(mpath, mpp, pinfo);
2196 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2197 int idx, u8 *dst, u8 *mpp,
2198 struct mpath_info *pinfo)
2200 struct ieee80211_sub_if_data *sdata;
2201 struct mesh_path *mpath;
2203 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2206 mpath = mpp_path_lookup_by_idx(sdata, idx);
2211 memcpy(dst, mpath->dst, ETH_ALEN);
2212 mpp_set_pinfo(mpath, mpp, pinfo);
2217 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2218 struct net_device *dev,
2219 struct mesh_config *conf)
2221 struct ieee80211_sub_if_data *sdata;
2222 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2224 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2228 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2230 return (mask >> (parm-1)) & 0x1;
2233 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2234 const struct mesh_setup *setup)
2237 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2238 struct ieee80211_sub_if_data, u.mesh);
2241 /* allocate information elements */
2244 if (setup->ie_len) {
2245 new_ie = kmemdup(setup->ie, setup->ie_len,
2250 ifmsh->ie_len = setup->ie_len;
2253 /* now copy the rest of the setup parameters */
2254 ifmsh->mesh_id_len = setup->mesh_id_len;
2255 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2256 ifmsh->mesh_sp_id = setup->sync_method;
2257 ifmsh->mesh_pp_id = setup->path_sel_proto;
2258 ifmsh->mesh_pm_id = setup->path_metric;
2259 ifmsh->user_mpm = setup->user_mpm;
2260 ifmsh->mesh_auth_id = setup->auth_id;
2261 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2262 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2263 if (setup->is_authenticated)
2264 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2265 if (setup->is_secure)
2266 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2268 /* mcast rate setting in Mesh Node */
2269 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2270 sizeof(setup->mcast_rate));
2271 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2273 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2274 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2276 sdata->beacon_rate_set = false;
2277 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2278 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2279 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2280 sdata->beacon_rateidx_mask[i] =
2281 setup->beacon_rate.control[i].legacy;
2282 if (sdata->beacon_rateidx_mask[i])
2283 sdata->beacon_rate_set = true;
2290 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2291 struct net_device *dev, u32 mask,
2292 const struct mesh_config *nconf)
2294 struct mesh_config *conf;
2295 struct ieee80211_sub_if_data *sdata;
2296 struct ieee80211_if_mesh *ifmsh;
2298 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2299 ifmsh = &sdata->u.mesh;
2301 /* Set the config options which we are interested in setting */
2302 conf = &(sdata->u.mesh.mshcfg);
2303 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2304 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2305 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2306 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2307 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2308 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2309 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2310 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2311 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2312 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2313 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2314 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2315 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2316 conf->element_ttl = nconf->element_ttl;
2317 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2318 if (ifmsh->user_mpm)
2320 conf->auto_open_plinks = nconf->auto_open_plinks;
2322 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2323 conf->dot11MeshNbrOffsetMaxNeighbor =
2324 nconf->dot11MeshNbrOffsetMaxNeighbor;
2325 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2326 conf->dot11MeshHWMPmaxPREQretries =
2327 nconf->dot11MeshHWMPmaxPREQretries;
2328 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2329 conf->path_refresh_time = nconf->path_refresh_time;
2330 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2331 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2332 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2333 conf->dot11MeshHWMPactivePathTimeout =
2334 nconf->dot11MeshHWMPactivePathTimeout;
2335 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2336 conf->dot11MeshHWMPpreqMinInterval =
2337 nconf->dot11MeshHWMPpreqMinInterval;
2338 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2339 conf->dot11MeshHWMPperrMinInterval =
2340 nconf->dot11MeshHWMPperrMinInterval;
2341 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2343 conf->dot11MeshHWMPnetDiameterTraversalTime =
2344 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2345 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2346 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2347 ieee80211_mesh_root_setup(ifmsh);
2349 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2350 /* our current gate announcement implementation rides on root
2351 * announcements, so require this ifmsh to also be a root node
2353 if (nconf->dot11MeshGateAnnouncementProtocol &&
2354 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2355 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2356 ieee80211_mesh_root_setup(ifmsh);
2358 conf->dot11MeshGateAnnouncementProtocol =
2359 nconf->dot11MeshGateAnnouncementProtocol;
2361 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2362 conf->dot11MeshHWMPRannInterval =
2363 nconf->dot11MeshHWMPRannInterval;
2364 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2365 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2366 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2367 /* our RSSI threshold implementation is supported only for
2368 * devices that report signal in dBm.
2370 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2372 conf->rssi_threshold = nconf->rssi_threshold;
2374 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2375 conf->ht_opmode = nconf->ht_opmode;
2376 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2377 ieee80211_link_info_change_notify(sdata, 0, BSS_CHANGED_HT);
2379 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2380 conf->dot11MeshHWMPactivePathToRootTimeout =
2381 nconf->dot11MeshHWMPactivePathToRootTimeout;
2382 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2383 conf->dot11MeshHWMProotInterval =
2384 nconf->dot11MeshHWMProotInterval;
2385 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2386 conf->dot11MeshHWMPconfirmationInterval =
2387 nconf->dot11MeshHWMPconfirmationInterval;
2388 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2389 conf->power_mode = nconf->power_mode;
2390 ieee80211_mps_local_status_update(sdata);
2392 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2393 conf->dot11MeshAwakeWindowDuration =
2394 nconf->dot11MeshAwakeWindowDuration;
2395 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2396 conf->plink_timeout = nconf->plink_timeout;
2397 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2398 conf->dot11MeshConnectedToMeshGate =
2399 nconf->dot11MeshConnectedToMeshGate;
2400 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2401 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2402 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2403 conf->dot11MeshConnectedToAuthServer =
2404 nconf->dot11MeshConnectedToAuthServer;
2405 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2409 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2410 const struct mesh_config *conf,
2411 const struct mesh_setup *setup)
2413 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2414 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2417 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2418 err = copy_mesh_setup(ifmsh, setup);
2422 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2424 /* can mesh use other SMPS modes? */
2425 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2426 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
2428 mutex_lock(&sdata->local->mtx);
2429 err = ieee80211_link_use_channel(sdata->link[0], &setup->chandef,
2430 IEEE80211_CHANCTX_SHARED);
2431 mutex_unlock(&sdata->local->mtx);
2435 return ieee80211_start_mesh(sdata);
2438 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2440 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2442 ieee80211_stop_mesh(sdata);
2443 mutex_lock(&sdata->local->mtx);
2444 ieee80211_link_release_channel(sdata->link[0]);
2445 kfree(sdata->u.mesh.ie);
2446 mutex_unlock(&sdata->local->mtx);
2452 static int ieee80211_change_bss(struct wiphy *wiphy,
2453 struct net_device *dev,
2454 struct bss_parameters *params)
2456 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2457 struct ieee80211_supported_band *sband;
2460 if (!sdata_dereference(sdata->deflink.u.ap.beacon, sdata))
2463 sband = ieee80211_get_sband(sdata);
2467 if (params->use_cts_prot >= 0) {
2468 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2469 changed |= BSS_CHANGED_ERP_CTS_PROT;
2471 if (params->use_short_preamble >= 0) {
2472 sdata->vif.bss_conf.use_short_preamble =
2473 params->use_short_preamble;
2474 changed |= BSS_CHANGED_ERP_PREAMBLE;
2477 if (!sdata->vif.bss_conf.use_short_slot &&
2478 (sband->band == NL80211_BAND_5GHZ ||
2479 sband->band == NL80211_BAND_6GHZ)) {
2480 sdata->vif.bss_conf.use_short_slot = true;
2481 changed |= BSS_CHANGED_ERP_SLOT;
2484 if (params->use_short_slot_time >= 0) {
2485 sdata->vif.bss_conf.use_short_slot =
2486 params->use_short_slot_time;
2487 changed |= BSS_CHANGED_ERP_SLOT;
2490 if (params->basic_rates) {
2491 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2492 wiphy->bands[sband->band],
2493 params->basic_rates,
2494 params->basic_rates_len,
2495 &sdata->vif.bss_conf.basic_rates);
2496 changed |= BSS_CHANGED_BASIC_RATES;
2497 ieee80211_check_rate_mask(sdata);
2500 if (params->ap_isolate >= 0) {
2501 if (params->ap_isolate)
2502 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2504 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2505 ieee80211_check_fast_rx_iface(sdata);
2508 if (params->ht_opmode >= 0) {
2509 sdata->vif.bss_conf.ht_operation_mode =
2510 (u16) params->ht_opmode;
2511 changed |= BSS_CHANGED_HT;
2514 if (params->p2p_ctwindow >= 0) {
2515 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2516 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2517 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2518 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2519 changed |= BSS_CHANGED_P2P_PS;
2522 if (params->p2p_opp_ps > 0) {
2523 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2524 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2525 changed |= BSS_CHANGED_P2P_PS;
2526 } else if (params->p2p_opp_ps == 0) {
2527 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2528 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2529 changed |= BSS_CHANGED_P2P_PS;
2532 ieee80211_link_info_change_notify(sdata, 0, changed);
2537 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2538 struct net_device *dev,
2539 struct ieee80211_txq_params *params)
2541 struct ieee80211_local *local = wiphy_priv(wiphy);
2542 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2543 struct ieee80211_tx_queue_params p;
2545 if (!local->ops->conf_tx)
2548 if (local->hw.queues < IEEE80211_NUM_ACS)
2551 memset(&p, 0, sizeof(p));
2552 p.aifs = params->aifs;
2553 p.cw_max = params->cwmax;
2554 p.cw_min = params->cwmin;
2555 p.txop = params->txop;
2558 * Setting tx queue params disables u-apsd because it's only
2559 * called in master mode.
2563 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2565 sdata->tx_conf[params->ac] = p;
2566 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2567 wiphy_debug(local->hw.wiphy,
2568 "failed to set TX queue parameters for AC %d\n",
2573 ieee80211_link_info_change_notify(sdata, 0, BSS_CHANGED_QOS);
2579 static int ieee80211_suspend(struct wiphy *wiphy,
2580 struct cfg80211_wowlan *wowlan)
2582 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2585 static int ieee80211_resume(struct wiphy *wiphy)
2587 return __ieee80211_resume(wiphy_priv(wiphy));
2590 #define ieee80211_suspend NULL
2591 #define ieee80211_resume NULL
2594 static int ieee80211_scan(struct wiphy *wiphy,
2595 struct cfg80211_scan_request *req)
2597 struct ieee80211_sub_if_data *sdata;
2599 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2601 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2602 case NL80211_IFTYPE_STATION:
2603 case NL80211_IFTYPE_ADHOC:
2604 case NL80211_IFTYPE_MESH_POINT:
2605 case NL80211_IFTYPE_P2P_CLIENT:
2606 case NL80211_IFTYPE_P2P_DEVICE:
2608 case NL80211_IFTYPE_P2P_GO:
2609 if (sdata->local->ops->hw_scan)
2612 * FIXME: implement NoA while scanning in software,
2613 * for now fall through to allow scanning only when
2614 * beaconing hasn't been configured yet
2617 case NL80211_IFTYPE_AP:
2619 * If the scan has been forced (and the driver supports
2620 * forcing), don't care about being beaconing already.
2621 * This will create problems to the attached stations (e.g. all
2622 * the frames sent while scanning on other channel will be
2625 if (sdata->deflink.u.ap.beacon &&
2626 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2627 !(req->flags & NL80211_SCAN_FLAG_AP)))
2630 case NL80211_IFTYPE_NAN:
2635 return ieee80211_request_scan(sdata, req);
2638 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2640 ieee80211_scan_cancel(wiphy_priv(wiphy));
2644 ieee80211_sched_scan_start(struct wiphy *wiphy,
2645 struct net_device *dev,
2646 struct cfg80211_sched_scan_request *req)
2648 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2650 if (!sdata->local->ops->sched_scan_start)
2653 return ieee80211_request_sched_scan_start(sdata, req);
2657 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2660 struct ieee80211_local *local = wiphy_priv(wiphy);
2662 if (!local->ops->sched_scan_stop)
2665 return ieee80211_request_sched_scan_stop(local);
2668 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2669 struct cfg80211_auth_request *req)
2671 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2674 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2675 struct cfg80211_assoc_request *req)
2677 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2680 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2681 struct cfg80211_deauth_request *req)
2683 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2686 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2687 struct cfg80211_disassoc_request *req)
2689 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2692 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2693 struct cfg80211_ibss_params *params)
2695 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2698 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2700 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2703 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2704 struct ocb_setup *setup)
2706 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2709 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2711 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2714 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2715 int rate[NUM_NL80211_BANDS])
2717 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2719 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2720 sizeof(int) * NUM_NL80211_BANDS);
2722 ieee80211_link_info_change_notify(sdata, 0, BSS_CHANGED_MCAST_RATE);
2727 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2729 struct ieee80211_local *local = wiphy_priv(wiphy);
2732 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2733 ieee80211_check_fast_xmit_all(local);
2735 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2738 ieee80211_check_fast_xmit_all(local);
2743 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2744 (changed & WIPHY_PARAM_DYN_ACK)) {
2747 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2748 wiphy->coverage_class : -1;
2749 err = drv_set_coverage_class(local, coverage_class);
2755 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2756 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2762 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2763 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2765 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2767 if (changed & WIPHY_PARAM_RETRY_LONG) {
2768 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2770 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2773 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2774 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2776 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2777 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2778 WIPHY_PARAM_TXQ_QUANTUM))
2779 ieee80211_txq_set_params(local);
2784 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2785 struct wireless_dev *wdev,
2786 enum nl80211_tx_power_setting type, int mbm)
2788 struct ieee80211_local *local = wiphy_priv(wiphy);
2789 struct ieee80211_sub_if_data *sdata;
2790 enum nl80211_tx_power_setting txp_type = type;
2791 bool update_txp_type = false;
2792 bool has_monitor = false;
2795 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2797 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2798 sdata = wiphy_dereference(local->hw.wiphy,
2799 local->monitor_sdata);
2805 case NL80211_TX_POWER_AUTOMATIC:
2806 sdata->deflink.user_power_level =
2807 IEEE80211_UNSET_POWER_LEVEL;
2808 txp_type = NL80211_TX_POWER_LIMITED;
2810 case NL80211_TX_POWER_LIMITED:
2811 case NL80211_TX_POWER_FIXED:
2812 if (mbm < 0 || (mbm % 100))
2814 sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
2818 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2819 update_txp_type = true;
2820 sdata->vif.bss_conf.txpower_type = txp_type;
2823 ieee80211_recalc_txpower(sdata, update_txp_type);
2829 case NL80211_TX_POWER_AUTOMATIC:
2830 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2831 txp_type = NL80211_TX_POWER_LIMITED;
2833 case NL80211_TX_POWER_LIMITED:
2834 case NL80211_TX_POWER_FIXED:
2835 if (mbm < 0 || (mbm % 100))
2837 local->user_power_level = MBM_TO_DBM(mbm);
2841 mutex_lock(&local->iflist_mtx);
2842 list_for_each_entry(sdata, &local->interfaces, list) {
2843 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2847 sdata->deflink.user_power_level = local->user_power_level;
2848 if (txp_type != sdata->vif.bss_conf.txpower_type)
2849 update_txp_type = true;
2850 sdata->vif.bss_conf.txpower_type = txp_type;
2852 list_for_each_entry(sdata, &local->interfaces, list) {
2853 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2855 ieee80211_recalc_txpower(sdata, update_txp_type);
2857 mutex_unlock(&local->iflist_mtx);
2860 sdata = wiphy_dereference(local->hw.wiphy,
2861 local->monitor_sdata);
2863 sdata->deflink.user_power_level = local->user_power_level;
2864 if (txp_type != sdata->vif.bss_conf.txpower_type)
2865 update_txp_type = true;
2866 sdata->vif.bss_conf.txpower_type = txp_type;
2868 ieee80211_recalc_txpower(sdata, update_txp_type);
2875 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2876 struct wireless_dev *wdev,
2879 struct ieee80211_local *local = wiphy_priv(wiphy);
2880 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2882 if (local->ops->get_txpower)
2883 return drv_get_txpower(local, sdata, dbm);
2885 if (!local->use_chanctx)
2886 *dbm = local->hw.conf.power_level;
2888 *dbm = sdata->vif.bss_conf.txpower;
2893 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2895 struct ieee80211_local *local = wiphy_priv(wiphy);
2897 drv_rfkill_poll(local);
2900 #ifdef CONFIG_NL80211_TESTMODE
2901 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2902 struct wireless_dev *wdev,
2903 void *data, int len)
2905 struct ieee80211_local *local = wiphy_priv(wiphy);
2906 struct ieee80211_vif *vif = NULL;
2908 if (!local->ops->testmode_cmd)
2912 struct ieee80211_sub_if_data *sdata;
2914 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2915 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2919 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2922 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2923 struct sk_buff *skb,
2924 struct netlink_callback *cb,
2925 void *data, int len)
2927 struct ieee80211_local *local = wiphy_priv(wiphy);
2929 if (!local->ops->testmode_dump)
2932 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2936 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2937 unsigned int link_id,
2938 enum ieee80211_smps_mode smps_mode)
2941 enum ieee80211_smps_mode old_req;
2943 struct sta_info *sta;
2944 bool tdls_peer_found = false;
2946 lockdep_assert_held(&sdata->wdev.mtx);
2948 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2951 old_req = sdata->link[link_id]->u.mgd.req_smps;
2952 sdata->link[link_id]->u.mgd.req_smps = smps_mode;
2954 if (old_req == smps_mode &&
2955 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2959 * If not associated, or current association is not an HT
2960 * association, there's no need to do anything, just store
2961 * the new value until we associate.
2963 if (!sdata->u.mgd.associated ||
2964 sdata->vif.link_conf[link_id]->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2967 ap = sdata->link[link_id]->u.mgd.bssid;
2970 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2971 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2972 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2975 tdls_peer_found = true;
2980 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2981 if (tdls_peer_found || !sdata->u.mgd.powersave)
2982 smps_mode = IEEE80211_SMPS_OFF;
2984 smps_mode = IEEE80211_SMPS_DYNAMIC;
2987 /* send SM PS frame to AP */
2988 err = ieee80211_send_smps_action(sdata, smps_mode,
2991 sdata->link[link_id]->u.mgd.req_smps = old_req;
2992 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2993 ieee80211_teardown_tdls_peers(sdata);
2998 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2999 bool enabled, int timeout)
3001 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3002 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3003 unsigned int link_id;
3005 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3008 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3011 if (enabled == sdata->u.mgd.powersave &&
3012 timeout == local->dynamic_ps_forced_timeout)
3015 sdata->u.mgd.powersave = enabled;
3016 local->dynamic_ps_forced_timeout = timeout;
3018 /* no change, but if automatic follow powersave */
3020 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3021 if (!sdata->link[link_id])
3023 __ieee80211_request_smps_mgd(sdata, link_id,
3024 sdata->link[link_id]->u.mgd.req_smps);
3026 sdata_unlock(sdata);
3028 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3029 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3031 ieee80211_recalc_ps(local);
3032 ieee80211_recalc_ps_vif(sdata);
3033 ieee80211_check_fast_rx_iface(sdata);
3038 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3039 struct net_device *dev,
3040 s32 rssi_thold, u32 rssi_hyst)
3042 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3043 struct ieee80211_vif *vif = &sdata->vif;
3044 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3046 if (rssi_thold == bss_conf->cqm_rssi_thold &&
3047 rssi_hyst == bss_conf->cqm_rssi_hyst)
3050 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3051 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3054 bss_conf->cqm_rssi_thold = rssi_thold;
3055 bss_conf->cqm_rssi_hyst = rssi_hyst;
3056 bss_conf->cqm_rssi_low = 0;
3057 bss_conf->cqm_rssi_high = 0;
3058 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3060 /* tell the driver upon association, unless already associated */
3061 if (sdata->u.mgd.associated &&
3062 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3063 ieee80211_link_info_change_notify(sdata, 0, BSS_CHANGED_CQM);
3068 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3069 struct net_device *dev,
3070 s32 rssi_low, s32 rssi_high)
3072 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3073 struct ieee80211_vif *vif = &sdata->vif;
3074 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3076 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
3079 bss_conf->cqm_rssi_low = rssi_low;
3080 bss_conf->cqm_rssi_high = rssi_high;
3081 bss_conf->cqm_rssi_thold = 0;
3082 bss_conf->cqm_rssi_hyst = 0;
3083 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3085 /* tell the driver upon association, unless already associated */
3086 if (sdata->u.mgd.associated &&
3087 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3088 ieee80211_link_info_change_notify(sdata, 0, BSS_CHANGED_CQM);
3093 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3094 struct net_device *dev,
3095 unsigned int link_id,
3097 const struct cfg80211_bitrate_mask *mask)
3099 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3100 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3103 if (!ieee80211_sdata_running(sdata))
3107 * If active validate the setting and reject it if it doesn't leave
3108 * at least one basic rate usable, since we really have to be able
3109 * to send something, and if we're an AP we have to be able to do
3110 * so at a basic rate so that all clients can receive it.
3112 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3113 sdata->vif.bss_conf.chandef.chan) {
3114 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3115 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3117 if (!(mask->control[band].legacy & basic_rates))
3121 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3122 ret = drv_set_bitrate_mask(local, sdata, mask);
3127 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3128 struct ieee80211_supported_band *sband = wiphy->bands[i];
3131 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3132 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3133 sizeof(mask->control[i].ht_mcs));
3134 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3135 mask->control[i].vht_mcs,
3136 sizeof(mask->control[i].vht_mcs));
3138 sdata->rc_has_mcs_mask[i] = false;
3139 sdata->rc_has_vht_mcs_mask[i] = false;
3143 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3144 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3145 sdata->rc_has_mcs_mask[i] = true;
3150 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3151 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3152 sdata->rc_has_vht_mcs_mask[i] = true;
3161 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3162 struct net_device *dev,
3163 struct cfg80211_chan_def *chandef,
3166 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3167 struct ieee80211_local *local = sdata->local;
3170 mutex_lock(&local->mtx);
3171 if (!list_empty(&local->roc_list) || local->scanning) {
3176 /* whatever, but channel contexts should not complain about that one */
3177 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3178 sdata->deflink.needed_rx_chains = local->rx_chains;
3180 err = ieee80211_link_use_channel(sdata->link[0], chandef,
3181 IEEE80211_CHANCTX_SHARED);
3185 ieee80211_queue_delayed_work(&sdata->local->hw,
3186 &sdata->deflink.dfs_cac_timer_work,
3187 msecs_to_jiffies(cac_time_ms));
3190 mutex_unlock(&local->mtx);
3194 static void ieee80211_end_cac(struct wiphy *wiphy,
3195 struct net_device *dev)
3197 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3198 struct ieee80211_local *local = sdata->local;
3200 mutex_lock(&local->mtx);
3201 list_for_each_entry(sdata, &local->interfaces, list) {
3202 /* it might be waiting for the local->mtx, but then
3203 * by the time it gets it, sdata->wdev.cac_started
3204 * will no longer be true
3206 cancel_delayed_work(&sdata->deflink.dfs_cac_timer_work);
3208 if (sdata->wdev.cac_started) {
3209 ieee80211_link_release_channel(sdata->link[0]);
3210 sdata->wdev.cac_started = false;
3213 mutex_unlock(&local->mtx);
3216 static struct cfg80211_beacon_data *
3217 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3219 struct cfg80211_beacon_data *new_beacon;
3223 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3224 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3225 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len +
3226 ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies);
3228 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3232 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3233 new_beacon->mbssid_ies =
3234 kzalloc(struct_size(new_beacon->mbssid_ies,
3235 elem, beacon->mbssid_ies->cnt),
3237 if (!new_beacon->mbssid_ies) {
3243 pos = (u8 *)(new_beacon + 1);
3244 if (beacon->head_len) {
3245 new_beacon->head_len = beacon->head_len;
3246 new_beacon->head = pos;
3247 memcpy(pos, beacon->head, beacon->head_len);
3248 pos += beacon->head_len;
3250 if (beacon->tail_len) {
3251 new_beacon->tail_len = beacon->tail_len;
3252 new_beacon->tail = pos;
3253 memcpy(pos, beacon->tail, beacon->tail_len);
3254 pos += beacon->tail_len;
3256 if (beacon->beacon_ies_len) {
3257 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3258 new_beacon->beacon_ies = pos;
3259 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3260 pos += beacon->beacon_ies_len;
3262 if (beacon->proberesp_ies_len) {
3263 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3264 new_beacon->proberesp_ies = pos;
3265 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3266 pos += beacon->proberesp_ies_len;
3268 if (beacon->assocresp_ies_len) {
3269 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3270 new_beacon->assocresp_ies = pos;
3271 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3272 pos += beacon->assocresp_ies_len;
3274 if (beacon->probe_resp_len) {
3275 new_beacon->probe_resp_len = beacon->probe_resp_len;
3276 new_beacon->probe_resp = pos;
3277 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3278 pos += beacon->probe_resp_len;
3280 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt)
3281 pos += ieee80211_copy_mbssid_beacon(pos,
3282 new_beacon->mbssid_ies,
3283 beacon->mbssid_ies);
3285 /* might copy -1, meaning no changes requested */
3286 new_beacon->ftm_responder = beacon->ftm_responder;
3288 new_beacon->lci_len = beacon->lci_len;
3289 new_beacon->lci = pos;
3290 memcpy(pos, beacon->lci, beacon->lci_len);
3291 pos += beacon->lci_len;
3293 if (beacon->civicloc) {
3294 new_beacon->civicloc_len = beacon->civicloc_len;
3295 new_beacon->civicloc = pos;
3296 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3297 pos += beacon->civicloc_len;
3303 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3305 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3306 struct ieee80211_local *local = sdata->local;
3310 if (vif->mbssid_tx_vif == vif) {
3311 /* Trigger ieee80211_csa_finish() on the non-transmitting
3312 * interfaces when channel switch is received on
3313 * transmitting interface
3315 struct ieee80211_sub_if_data *iter;
3317 list_for_each_entry_rcu(iter, &local->interfaces, list) {
3318 if (!ieee80211_sdata_running(iter))
3321 if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3324 ieee80211_queue_work(&iter->local->hw,
3325 &iter->deflink.csa_finalize_work);
3328 ieee80211_queue_work(&local->hw, &sdata->deflink.csa_finalize_work);
3332 EXPORT_SYMBOL(ieee80211_csa_finish);
3334 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3336 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3337 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3338 struct ieee80211_local *local = sdata->local;
3340 sdata->deflink.csa_block_tx = block_tx;
3341 sdata_info(sdata, "channel switch failed, disconnecting\n");
3342 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
3344 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3346 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3351 switch (sdata->vif.type) {
3352 case NL80211_IFTYPE_AP:
3353 if (!sdata->deflink.u.ap.next_beacon)
3356 err = ieee80211_assign_beacon(sdata,
3357 sdata->deflink.u.ap.next_beacon,
3359 ieee80211_free_next_beacon(&sdata->deflink);
3365 case NL80211_IFTYPE_ADHOC:
3366 err = ieee80211_ibss_finish_csa(sdata);
3371 #ifdef CONFIG_MAC80211_MESH
3372 case NL80211_IFTYPE_MESH_POINT:
3373 err = ieee80211_mesh_finish_csa(sdata);
3387 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3389 struct ieee80211_local *local = sdata->local;
3393 sdata_assert_lock(sdata);
3394 lockdep_assert_held(&local->mtx);
3395 lockdep_assert_held(&local->chanctx_mtx);
3398 * using reservation isn't immediate as it may be deferred until later
3399 * with multi-vif. once reservation is complete it will re-schedule the
3400 * work with no reserved_chanctx so verify chandef to check if it
3401 * completed successfully
3404 if (sdata->deflink.reserved_chanctx) {
3406 * with multi-vif csa driver may call ieee80211_csa_finish()
3407 * many times while waiting for other interfaces to use their
3410 if (sdata->deflink.reserved_ready)
3413 return ieee80211_link_use_reserved_context(sdata->link[0]);
3416 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3417 &sdata->deflink.csa_chandef))
3420 sdata->vif.bss_conf.csa_active = false;
3422 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3426 ieee80211_link_info_change_notify(sdata, 0, changed);
3428 if (sdata->deflink.csa_block_tx) {
3429 ieee80211_wake_vif_queues(local, sdata,
3430 IEEE80211_QUEUE_STOP_REASON_CSA);
3431 sdata->deflink.csa_block_tx = false;
3434 err = drv_post_channel_switch(sdata);
3438 cfg80211_ch_switch_notify(sdata->dev, &sdata->deflink.csa_chandef, 0);
3443 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3445 if (__ieee80211_csa_finalize(sdata)) {
3446 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3447 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3452 void ieee80211_csa_finalize_work(struct work_struct *work)
3454 struct ieee80211_sub_if_data *sdata =
3455 container_of(work, struct ieee80211_sub_if_data,
3456 deflink.csa_finalize_work);
3457 struct ieee80211_local *local = sdata->local;
3460 mutex_lock(&local->mtx);
3461 mutex_lock(&local->chanctx_mtx);
3463 /* AP might have been stopped while waiting for the lock. */
3464 if (!sdata->vif.bss_conf.csa_active)
3467 if (!ieee80211_sdata_running(sdata))
3470 ieee80211_csa_finalize(sdata);
3473 mutex_unlock(&local->chanctx_mtx);
3474 mutex_unlock(&local->mtx);
3475 sdata_unlock(sdata);
3478 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3479 struct cfg80211_csa_settings *params,
3482 struct ieee80211_csa_settings csa = {};
3485 switch (sdata->vif.type) {
3486 case NL80211_IFTYPE_AP:
3487 sdata->deflink.u.ap.next_beacon =
3488 cfg80211_beacon_dup(¶ms->beacon_after);
3489 if (!sdata->deflink.u.ap.next_beacon)
3493 * With a count of 0, we don't have to wait for any
3494 * TBTT before switching, so complete the CSA
3495 * immediately. In theory, with a count == 1 we
3496 * should delay the switch until just before the next
3497 * TBTT, but that would complicate things so we switch
3498 * immediately too. If we would delay the switch
3499 * until the next TBTT, we would have to set the probe
3502 * TODO: A channel switch with count <= 1 without
3503 * sending a CSA action frame is kind of useless,
3504 * because the clients won't know we're changing
3505 * channels. The action frame must be implemented
3506 * either here or in the userspace.
3508 if (params->count <= 1)
3511 if ((params->n_counter_offsets_beacon >
3512 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3513 (params->n_counter_offsets_presp >
3514 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3515 ieee80211_free_next_beacon(&sdata->deflink);
3519 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3520 csa.counter_offsets_presp = params->counter_offsets_presp;
3521 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3522 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3523 csa.count = params->count;
3525 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa, NULL);
3527 ieee80211_free_next_beacon(&sdata->deflink);
3533 case NL80211_IFTYPE_ADHOC:
3534 if (!sdata->vif.cfg.ibss_joined)
3537 if (params->chandef.width != sdata->u.ibss.chandef.width)
3540 switch (params->chandef.width) {
3541 case NL80211_CHAN_WIDTH_40:
3542 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3543 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3546 case NL80211_CHAN_WIDTH_5:
3547 case NL80211_CHAN_WIDTH_10:
3548 case NL80211_CHAN_WIDTH_20_NOHT:
3549 case NL80211_CHAN_WIDTH_20:
3555 /* changes into another band are not supported */
3556 if (sdata->u.ibss.chandef.chan->band !=
3557 params->chandef.chan->band)
3560 /* see comments in the NL80211_IFTYPE_AP block */
3561 if (params->count > 1) {
3562 err = ieee80211_ibss_csa_beacon(sdata, params);
3568 ieee80211_send_action_csa(sdata, params);
3571 #ifdef CONFIG_MAC80211_MESH
3572 case NL80211_IFTYPE_MESH_POINT: {
3573 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3575 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3578 /* changes into another band are not supported */
3579 if (sdata->vif.bss_conf.chandef.chan->band !=
3580 params->chandef.chan->band)
3583 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3584 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3585 if (!ifmsh->pre_value)
3586 ifmsh->pre_value = 1;
3591 /* see comments in the NL80211_IFTYPE_AP block */
3592 if (params->count > 1) {
3593 err = ieee80211_mesh_csa_beacon(sdata, params);
3595 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3601 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3602 ieee80211_send_action_csa(sdata, params);
3614 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3616 sdata->vif.bss_conf.color_change_active = false;
3618 ieee80211_free_next_beacon(&sdata->deflink);
3620 cfg80211_color_change_aborted_notify(sdata->dev);
3624 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3625 struct cfg80211_csa_settings *params)
3627 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3628 struct ieee80211_local *local = sdata->local;
3629 struct ieee80211_channel_switch ch_switch;
3630 struct ieee80211_chanctx_conf *conf;
3631 struct ieee80211_chanctx *chanctx;
3635 sdata_assert_lock(sdata);
3636 lockdep_assert_held(&local->mtx);
3638 if (!list_empty(&local->roc_list) || local->scanning)
3641 if (sdata->wdev.cac_started)
3644 if (cfg80211_chandef_identical(¶ms->chandef,
3645 &sdata->vif.bss_conf.chandef))
3648 /* don't allow another channel switch if one is already active. */
3649 if (sdata->vif.bss_conf.csa_active)
3652 mutex_lock(&local->chanctx_mtx);
3653 conf = rcu_dereference_protected(sdata->vif.bss_conf.chanctx_conf,
3654 lockdep_is_held(&local->chanctx_mtx));
3660 if (params->chandef.chan->freq_offset) {
3661 /* this may work, but is untested */
3666 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3668 ch_switch.timestamp = 0;
3669 ch_switch.device_timestamp = 0;
3670 ch_switch.block_tx = params->block_tx;
3671 ch_switch.chandef = params->chandef;
3672 ch_switch.count = params->count;
3674 err = drv_pre_channel_switch(sdata, &ch_switch);
3678 err = ieee80211_link_reserve_chanctx(sdata->link[0], ¶ms->chandef,
3680 params->radar_required);
3684 /* if reservation is invalid then this will fail */
3685 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3687 ieee80211_link_unreserve_chanctx(sdata->link[0]);
3691 /* if there is a color change in progress, abort it */
3692 if (sdata->vif.bss_conf.color_change_active)
3693 ieee80211_color_change_abort(sdata);
3695 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3697 ieee80211_link_unreserve_chanctx(sdata->link[0]);
3701 sdata->deflink.csa_chandef = params->chandef;
3702 sdata->deflink.csa_block_tx = params->block_tx;
3703 sdata->vif.bss_conf.csa_active = true;
3705 if (sdata->deflink.csa_block_tx)
3706 ieee80211_stop_vif_queues(local, sdata,
3707 IEEE80211_QUEUE_STOP_REASON_CSA);
3709 cfg80211_ch_switch_started_notify(sdata->dev,
3710 &sdata->deflink.csa_chandef,
3711 params->count, params->block_tx);
3714 ieee80211_link_info_change_notify(sdata, 0, changed);
3715 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3717 /* if the beacon didn't change, we can finalize immediately */
3718 ieee80211_csa_finalize(sdata);
3722 mutex_unlock(&local->chanctx_mtx);
3726 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3727 struct cfg80211_csa_settings *params)
3729 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3730 struct ieee80211_local *local = sdata->local;
3733 mutex_lock(&local->mtx);
3734 err = __ieee80211_channel_switch(wiphy, dev, params);
3735 mutex_unlock(&local->mtx);
3740 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3742 lockdep_assert_held(&local->mtx);
3744 local->roc_cookie_counter++;
3746 /* wow, you wrapped 64 bits ... more likely a bug */
3747 if (WARN_ON(local->roc_cookie_counter == 0))
3748 local->roc_cookie_counter++;
3750 return local->roc_cookie_counter;
3753 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3754 u64 *cookie, gfp_t gfp)
3756 unsigned long spin_flags;
3757 struct sk_buff *ack_skb;
3760 ack_skb = skb_copy(skb, gfp);
3764 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3765 id = idr_alloc(&local->ack_status_frames, ack_skb,
3766 1, 0x2000, GFP_ATOMIC);
3767 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3774 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3776 *cookie = ieee80211_mgmt_tx_cookie(local);
3777 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3783 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
3784 struct wireless_dev *wdev,
3785 struct mgmt_frame_regs *upd)
3787 struct ieee80211_local *local = wiphy_priv(wiphy);
3788 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3789 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
3790 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
3791 bool global_change, intf_change;
3794 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3795 (local->rx_mcast_action_reg !=
3796 !!(upd->global_mcast_stypes & action_mask));
3797 local->probe_req_reg = upd->global_stypes & preq_mask;
3798 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
3800 intf_change = (sdata->vif.probe_req_reg !=
3801 !!(upd->interface_stypes & preq_mask)) ||
3802 (sdata->vif.rx_mcast_action_reg !=
3803 !!(upd->interface_mcast_stypes & action_mask));
3804 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
3805 sdata->vif.rx_mcast_action_reg =
3806 upd->interface_mcast_stypes & action_mask;
3808 if (!local->open_count)
3811 if (intf_change && ieee80211_sdata_running(sdata))
3812 drv_config_iface_filter(local, sdata,
3813 sdata->vif.probe_req_reg ?
3818 ieee80211_configure_filter(local);
3821 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3823 struct ieee80211_local *local = wiphy_priv(wiphy);
3828 return drv_set_antenna(local, tx_ant, rx_ant);
3831 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3833 struct ieee80211_local *local = wiphy_priv(wiphy);
3835 return drv_get_antenna(local, tx_ant, rx_ant);
3838 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3839 struct net_device *dev,
3840 struct cfg80211_gtk_rekey_data *data)
3842 struct ieee80211_local *local = wiphy_priv(wiphy);
3843 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3845 if (!local->ops->set_rekey_data)
3848 drv_set_rekey_data(local, sdata, data);
3853 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3854 const u8 *peer, u64 *cookie)
3856 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3857 struct ieee80211_local *local = sdata->local;
3858 struct ieee80211_qos_hdr *nullfunc;
3859 struct sk_buff *skb;
3860 int size = sizeof(*nullfunc);
3863 struct ieee80211_tx_info *info;
3864 struct sta_info *sta;
3865 struct ieee80211_chanctx_conf *chanctx_conf;
3866 enum nl80211_band band;
3869 /* the lock is needed to assign the cookie later */
3870 mutex_lock(&local->mtx);
3873 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3874 if (WARN_ON(!chanctx_conf)) {
3878 band = chanctx_conf->def.chan->band;
3879 sta = sta_info_get_bss(sdata, peer);
3888 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3889 IEEE80211_STYPE_QOS_NULLFUNC |
3890 IEEE80211_FCTL_FROMDS);
3893 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3894 IEEE80211_STYPE_NULLFUNC |
3895 IEEE80211_FCTL_FROMDS);
3898 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3906 skb_reserve(skb, local->hw.extra_tx_headroom);
3908 nullfunc = skb_put(skb, size);
3909 nullfunc->frame_control = fc;
3910 nullfunc->duration_id = 0;
3911 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3912 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3913 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3914 nullfunc->seq_ctrl = 0;
3916 info = IEEE80211_SKB_CB(skb);
3918 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3919 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3922 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3925 nullfunc->qos_ctrl = cpu_to_le16(7);
3927 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3934 ieee80211_xmit(sdata, sta, skb);
3940 mutex_unlock(&local->mtx);
3945 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3946 struct wireless_dev *wdev,
3947 unsigned int link_id,
3948 struct cfg80211_chan_def *chandef)
3950 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3951 struct ieee80211_local *local = wiphy_priv(wiphy);
3952 struct ieee80211_chanctx_conf *chanctx_conf;
3956 chanctx_conf = rcu_dereference(sdata->vif.link_conf[link_id]->chanctx_conf);
3958 *chandef = sdata->vif.link_conf[link_id]->chandef;
3960 } else if (local->open_count > 0 &&
3961 local->open_count == local->monitors &&
3962 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3963 if (local->use_chanctx)
3964 *chandef = local->monitor_chandef;
3966 *chandef = local->_oper_chandef;
3975 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3977 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3981 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3982 struct net_device *dev,
3983 struct cfg80211_qos_map *qos_map)
3985 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3986 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3989 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3992 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3994 /* A NULL qos_map was passed to disable QoS mapping */
3998 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3999 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4001 kfree_rcu(old_qos_map, rcu_head);
4006 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4007 struct net_device *dev,
4008 unsigned int link_id,
4009 struct cfg80211_chan_def *chandef)
4011 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4015 ret = ieee80211_link_change_bandwidth(sdata->link[link_id], chandef,
4018 ieee80211_link_info_change_notify(sdata, link_id, changed);
4023 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4024 u8 tsid, const u8 *peer, u8 up,
4027 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4028 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4029 int ac = ieee802_1d_to_ac[up];
4031 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4034 if (!(sdata->wmm_acm & BIT(up)))
4037 if (ifmgd->tx_tspec[ac].admitted_time)
4040 if (admitted_time) {
4041 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4042 ifmgd->tx_tspec[ac].tsid = tsid;
4043 ifmgd->tx_tspec[ac].up = up;
4049 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4050 u8 tsid, const u8 *peer)
4052 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4053 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4054 struct ieee80211_local *local = wiphy_priv(wiphy);
4057 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4058 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4060 /* skip unused entries */
4061 if (!tx_tspec->admitted_time)
4064 if (tx_tspec->tsid != tsid)
4067 /* due to this new packets will be reassigned to non-ACM ACs */
4070 /* Make sure that all packets have been sent to avoid to
4071 * restore the QoS params on packets that are still on the
4075 ieee80211_flush_queues(local, sdata, false);
4077 /* restore the normal QoS parameters
4078 * (unconditionally to avoid races)
4080 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4081 tx_tspec->downgraded = false;
4082 ieee80211_sta_handle_tspec_ac_params(sdata);
4084 /* finally clear all the data */
4085 memset(tx_tspec, 0, sizeof(*tx_tspec));
4093 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4095 enum nl80211_nan_func_term_reason reason,
4098 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4099 struct cfg80211_nan_func *func;
4102 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4105 spin_lock_bh(&sdata->u.nan.func_lock);
4107 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4108 if (WARN_ON(!func)) {
4109 spin_unlock_bh(&sdata->u.nan.func_lock);
4113 cookie = func->cookie;
4114 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4116 spin_unlock_bh(&sdata->u.nan.func_lock);
4118 cfg80211_free_nan_func(func);
4120 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4121 reason, cookie, gfp);
4123 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4125 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4126 struct cfg80211_nan_match_params *match,
4129 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4130 struct cfg80211_nan_func *func;
4132 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4135 spin_lock_bh(&sdata->u.nan.func_lock);
4137 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4138 if (WARN_ON(!func)) {
4139 spin_unlock_bh(&sdata->u.nan.func_lock);
4142 match->cookie = func->cookie;
4144 spin_unlock_bh(&sdata->u.nan.func_lock);
4146 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4148 EXPORT_SYMBOL(ieee80211_nan_func_match);
4150 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4151 struct net_device *dev,
4154 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4156 sdata->u.ap.multicast_to_unicast = enabled;
4161 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4162 struct txq_info *txqi)
4164 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4165 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4166 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4169 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4170 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4171 txqstats->backlog_packets = txqi->tin.backlog_packets;
4174 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4175 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4176 txqstats->flows = txqi->tin.flows;
4179 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4180 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4181 txqstats->drops = txqi->cstats.drop_count;
4184 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4185 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4186 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4189 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4190 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4191 txqstats->overlimit = txqi->tin.overlimit;
4194 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4195 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4196 txqstats->collisions = txqi->tin.collisions;
4199 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4200 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4201 txqstats->tx_bytes = txqi->tin.tx_bytes;
4204 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4205 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4206 txqstats->tx_packets = txqi->tin.tx_packets;
4210 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4211 struct wireless_dev *wdev,
4212 struct cfg80211_txq_stats *txqstats)
4214 struct ieee80211_local *local = wiphy_priv(wiphy);
4215 struct ieee80211_sub_if_data *sdata;
4218 if (!local->ops->wake_tx_queue)
4221 spin_lock_bh(&local->fq.lock);
4225 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4226 if (!sdata->vif.txq) {
4230 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4233 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4234 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4235 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4236 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4237 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4238 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4239 txqstats->backlog_packets = local->fq.backlog;
4240 txqstats->backlog_bytes = local->fq.memory_usage;
4241 txqstats->overlimit = local->fq.overlimit;
4242 txqstats->overmemory = local->fq.overmemory;
4243 txqstats->collisions = local->fq.collisions;
4244 txqstats->max_flows = local->fq.flows_cnt;
4249 spin_unlock_bh(&local->fq.lock);
4255 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4256 struct net_device *dev,
4257 struct cfg80211_ftm_responder_stats *ftm_stats)
4259 struct ieee80211_local *local = wiphy_priv(wiphy);
4260 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4262 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4266 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4267 struct cfg80211_pmsr_request *request)
4269 struct ieee80211_local *local = wiphy_priv(wiphy);
4270 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4272 return drv_start_pmsr(local, sdata, request);
4276 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4277 struct cfg80211_pmsr_request *request)
4279 struct ieee80211_local *local = wiphy_priv(wiphy);
4280 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4282 return drv_abort_pmsr(local, sdata, request);
4285 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4286 struct net_device *dev,
4287 struct cfg80211_tid_config *tid_conf)
4289 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4290 struct sta_info *sta;
4293 if (!sdata->local->ops->set_tid_config)
4296 if (!tid_conf->peer)
4297 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4299 mutex_lock(&sdata->local->sta_mtx);
4300 sta = sta_info_get_bss(sdata, tid_conf->peer);
4302 mutex_unlock(&sdata->local->sta_mtx);
4306 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4307 mutex_unlock(&sdata->local->sta_mtx);
4312 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4313 struct net_device *dev,
4314 const u8 *peer, u8 tids)
4316 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4317 struct sta_info *sta;
4320 if (!sdata->local->ops->reset_tid_config)
4324 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4326 mutex_lock(&sdata->local->sta_mtx);
4327 sta = sta_info_get_bss(sdata, peer);
4329 mutex_unlock(&sdata->local->sta_mtx);
4333 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4334 mutex_unlock(&sdata->local->sta_mtx);
4339 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4340 struct cfg80211_sar_specs *sar)
4342 struct ieee80211_local *local = wiphy_priv(wiphy);
4344 if (!local->ops->set_sar_specs)
4347 return local->ops->set_sar_specs(&local->hw, sar);
4351 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4354 switch (sdata->vif.type) {
4355 case NL80211_IFTYPE_AP: {
4358 if (!sdata->deflink.u.ap.next_beacon)
4361 ret = ieee80211_assign_beacon(sdata,
4362 sdata->deflink.u.ap.next_beacon,
4364 ieee80211_free_next_beacon(&sdata->deflink);
4381 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4382 struct cfg80211_color_change_settings *params,
4385 struct ieee80211_color_change_settings color_change = {};
4388 switch (sdata->vif.type) {
4389 case NL80211_IFTYPE_AP:
4390 sdata->deflink.u.ap.next_beacon =
4391 cfg80211_beacon_dup(¶ms->beacon_next);
4392 if (!sdata->deflink.u.ap.next_beacon)
4395 if (params->count <= 1)
4398 color_change.counter_offset_beacon =
4399 params->counter_offset_beacon;
4400 color_change.counter_offset_presp =
4401 params->counter_offset_presp;
4402 color_change.count = params->count;
4404 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_color_change,
4405 NULL, &color_change);
4407 ieee80211_free_next_beacon(&sdata->deflink);
4420 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4421 u8 color, int enable, u32 changed)
4423 sdata->vif.bss_conf.he_bss_color.color = color;
4424 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4425 changed |= BSS_CHANGED_HE_BSS_COLOR;
4427 ieee80211_link_info_change_notify(sdata, 0, changed);
4429 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4430 struct ieee80211_sub_if_data *child;
4432 mutex_lock(&sdata->local->iflist_mtx);
4433 list_for_each_entry(child, &sdata->local->interfaces, list) {
4434 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4435 child->vif.bss_conf.he_bss_color.color = color;
4436 child->vif.bss_conf.he_bss_color.enabled = enable;
4437 ieee80211_link_info_change_notify(child, 0,
4438 BSS_CHANGED_HE_BSS_COLOR);
4441 mutex_unlock(&sdata->local->iflist_mtx);
4445 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4447 struct ieee80211_local *local = sdata->local;
4451 sdata_assert_lock(sdata);
4452 lockdep_assert_held(&local->mtx);
4454 sdata->vif.bss_conf.color_change_active = false;
4456 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4458 cfg80211_color_change_aborted_notify(sdata->dev);
4462 ieee80211_color_change_bss_config_notify(sdata,
4463 sdata->vif.bss_conf.color_change_color,
4465 cfg80211_color_change_notify(sdata->dev);
4470 void ieee80211_color_change_finalize_work(struct work_struct *work)
4472 struct ieee80211_sub_if_data *sdata =
4473 container_of(work, struct ieee80211_sub_if_data,
4474 deflink.color_change_finalize_work);
4475 struct ieee80211_local *local = sdata->local;
4478 mutex_lock(&local->mtx);
4480 /* AP might have been stopped while waiting for the lock. */
4481 if (!sdata->vif.bss_conf.color_change_active)
4484 if (!ieee80211_sdata_running(sdata))
4487 ieee80211_color_change_finalize(sdata);
4490 mutex_unlock(&local->mtx);
4491 sdata_unlock(sdata);
4494 void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4496 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4498 ieee80211_queue_work(&sdata->local->hw,
4499 &sdata->deflink.color_change_finalize_work);
4501 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4504 ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4505 u64 color_bitmap, gfp_t gfp)
4507 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4509 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active)
4512 cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap, gfp);
4514 EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4517 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4518 struct cfg80211_color_change_settings *params)
4520 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4521 struct ieee80211_local *local = sdata->local;
4525 sdata_assert_lock(sdata);
4527 if (sdata->vif.bss_conf.nontransmitted)
4530 mutex_lock(&local->mtx);
4532 /* don't allow another color change if one is already active or if csa
4535 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) {
4540 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4544 sdata->vif.bss_conf.color_change_active = true;
4545 sdata->vif.bss_conf.color_change_color = params->color;
4547 cfg80211_color_change_started_notify(sdata->dev, params->count);
4550 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4552 /* if the beacon didn't change, we can finalize immediately */
4553 ieee80211_color_change_finalize(sdata);
4556 mutex_unlock(&local->mtx);
4562 ieee80211_set_radar_background(struct wiphy *wiphy,
4563 struct cfg80211_chan_def *chandef)
4565 struct ieee80211_local *local = wiphy_priv(wiphy);
4567 if (!local->ops->set_radar_background)
4570 return local->ops->set_radar_background(&local->hw, chandef);
4573 static int ieee80211_add_intf_link(struct wiphy *wiphy,
4574 struct wireless_dev *wdev,
4575 unsigned int link_id)
4577 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4579 return ieee80211_vif_set_links(sdata, wdev->valid_links);
4582 static void ieee80211_del_intf_link(struct wiphy *wiphy,
4583 struct wireless_dev *wdev,
4584 unsigned int link_id)
4586 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4588 ieee80211_vif_set_links(sdata, wdev->valid_links);
4591 const struct cfg80211_ops mac80211_config_ops = {
4592 .add_virtual_intf = ieee80211_add_iface,
4593 .del_virtual_intf = ieee80211_del_iface,
4594 .change_virtual_intf = ieee80211_change_iface,
4595 .start_p2p_device = ieee80211_start_p2p_device,
4596 .stop_p2p_device = ieee80211_stop_p2p_device,
4597 .add_key = ieee80211_add_key,
4598 .del_key = ieee80211_del_key,
4599 .get_key = ieee80211_get_key,
4600 .set_default_key = ieee80211_config_default_key,
4601 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
4602 .set_default_beacon_key = ieee80211_config_default_beacon_key,
4603 .start_ap = ieee80211_start_ap,
4604 .change_beacon = ieee80211_change_beacon,
4605 .stop_ap = ieee80211_stop_ap,
4606 .add_station = ieee80211_add_station,
4607 .del_station = ieee80211_del_station,
4608 .change_station = ieee80211_change_station,
4609 .get_station = ieee80211_get_station,
4610 .dump_station = ieee80211_dump_station,
4611 .dump_survey = ieee80211_dump_survey,
4612 #ifdef CONFIG_MAC80211_MESH
4613 .add_mpath = ieee80211_add_mpath,
4614 .del_mpath = ieee80211_del_mpath,
4615 .change_mpath = ieee80211_change_mpath,
4616 .get_mpath = ieee80211_get_mpath,
4617 .dump_mpath = ieee80211_dump_mpath,
4618 .get_mpp = ieee80211_get_mpp,
4619 .dump_mpp = ieee80211_dump_mpp,
4620 .update_mesh_config = ieee80211_update_mesh_config,
4621 .get_mesh_config = ieee80211_get_mesh_config,
4622 .join_mesh = ieee80211_join_mesh,
4623 .leave_mesh = ieee80211_leave_mesh,
4625 .join_ocb = ieee80211_join_ocb,
4626 .leave_ocb = ieee80211_leave_ocb,
4627 .change_bss = ieee80211_change_bss,
4628 .set_txq_params = ieee80211_set_txq_params,
4629 .set_monitor_channel = ieee80211_set_monitor_channel,
4630 .suspend = ieee80211_suspend,
4631 .resume = ieee80211_resume,
4632 .scan = ieee80211_scan,
4633 .abort_scan = ieee80211_abort_scan,
4634 .sched_scan_start = ieee80211_sched_scan_start,
4635 .sched_scan_stop = ieee80211_sched_scan_stop,
4636 .auth = ieee80211_auth,
4637 .assoc = ieee80211_assoc,
4638 .deauth = ieee80211_deauth,
4639 .disassoc = ieee80211_disassoc,
4640 .join_ibss = ieee80211_join_ibss,
4641 .leave_ibss = ieee80211_leave_ibss,
4642 .set_mcast_rate = ieee80211_set_mcast_rate,
4643 .set_wiphy_params = ieee80211_set_wiphy_params,
4644 .set_tx_power = ieee80211_set_tx_power,
4645 .get_tx_power = ieee80211_get_tx_power,
4646 .rfkill_poll = ieee80211_rfkill_poll,
4647 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
4648 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
4649 .set_power_mgmt = ieee80211_set_power_mgmt,
4650 .set_bitrate_mask = ieee80211_set_bitrate_mask,
4651 .remain_on_channel = ieee80211_remain_on_channel,
4652 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4653 .mgmt_tx = ieee80211_mgmt_tx,
4654 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4655 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4656 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4657 .update_mgmt_frame_registrations =
4658 ieee80211_update_mgmt_frame_registrations,
4659 .set_antenna = ieee80211_set_antenna,
4660 .get_antenna = ieee80211_get_antenna,
4661 .set_rekey_data = ieee80211_set_rekey_data,
4662 .tdls_oper = ieee80211_tdls_oper,
4663 .tdls_mgmt = ieee80211_tdls_mgmt,
4664 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4665 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4666 .probe_client = ieee80211_probe_client,
4667 .set_noack_map = ieee80211_set_noack_map,
4669 .set_wakeup = ieee80211_set_wakeup,
4671 .get_channel = ieee80211_cfg_get_channel,
4672 .start_radar_detection = ieee80211_start_radar_detection,
4673 .end_cac = ieee80211_end_cac,
4674 .channel_switch = ieee80211_channel_switch,
4675 .set_qos_map = ieee80211_set_qos_map,
4676 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4677 .add_tx_ts = ieee80211_add_tx_ts,
4678 .del_tx_ts = ieee80211_del_tx_ts,
4679 .start_nan = ieee80211_start_nan,
4680 .stop_nan = ieee80211_stop_nan,
4681 .nan_change_conf = ieee80211_nan_change_conf,
4682 .add_nan_func = ieee80211_add_nan_func,
4683 .del_nan_func = ieee80211_del_nan_func,
4684 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4685 .tx_control_port = ieee80211_tx_control_port,
4686 .get_txq_stats = ieee80211_get_txq_stats,
4687 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4688 .start_pmsr = ieee80211_start_pmsr,
4689 .abort_pmsr = ieee80211_abort_pmsr,
4690 .probe_mesh_link = ieee80211_probe_mesh_link,
4691 .set_tid_config = ieee80211_set_tid_config,
4692 .reset_tid_config = ieee80211_reset_tid_config,
4693 .set_sar_specs = ieee80211_set_sar_specs,
4694 .color_change = ieee80211_color_change,
4695 .set_radar_background = ieee80211_set_radar_background,
4696 .add_intf_link = ieee80211_add_intf_link,
4697 .del_intf_link = ieee80211_del_intf_link,