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 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/if_ether.h>
18 #include <net/cfg80211.h>
19 #include "ieee80211_i.h"
20 #include "driver-ops.h"
25 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
26 struct vif_params *params)
28 bool mu_mimo_groups = false;
29 bool mu_mimo_follow = false;
31 if (params->vht_mumimo_groups) {
34 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
36 memcpy(sdata->vif.bss_conf.mu_group.membership,
37 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
38 memcpy(sdata->vif.bss_conf.mu_group.position,
39 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
40 WLAN_USER_POSITION_LEN);
41 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
42 /* don't care about endianness - just check for 0 */
43 memcpy(&membership, params->vht_mumimo_groups,
45 mu_mimo_groups = membership != 0;
48 if (params->vht_mumimo_follow_addr) {
50 is_valid_ether_addr(params->vht_mumimo_follow_addr);
51 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
52 params->vht_mumimo_follow_addr);
55 sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
58 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
59 struct vif_params *params)
61 struct ieee80211_local *local = sdata->local;
62 struct ieee80211_sub_if_data *monitor_sdata;
64 /* check flags first */
65 if (params->flags && ieee80211_sdata_running(sdata)) {
66 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
69 * Prohibit MONITOR_FLAG_COOK_FRAMES and
70 * MONITOR_FLAG_ACTIVE to be changed while the
72 * Else we would need to add a lot of cruft
73 * to update everything:
74 * cooked_mntrs, monitor and all fif_* counters
75 * reconfigure hardware
77 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
81 /* also validate MU-MIMO change */
82 monitor_sdata = rtnl_dereference(local->monitor_sdata);
85 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
88 /* apply all changes now - no failures allowed */
91 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
94 if (ieee80211_sdata_running(sdata)) {
95 ieee80211_adjust_monitor_flags(sdata, -1);
96 sdata->u.mntr.flags = params->flags;
97 ieee80211_adjust_monitor_flags(sdata, 1);
99 ieee80211_configure_filter(local);
102 * Because the interface is down, ieee80211_do_stop
103 * and ieee80211_do_open take care of "everything"
104 * mentioned in the comment above.
106 sdata->u.mntr.flags = params->flags;
113 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
115 unsigned char name_assign_type,
116 enum nl80211_iftype type,
117 struct vif_params *params)
119 struct ieee80211_local *local = wiphy_priv(wiphy);
120 struct wireless_dev *wdev;
121 struct ieee80211_sub_if_data *sdata;
124 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
128 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
130 if (type == NL80211_IFTYPE_MONITOR) {
131 err = ieee80211_set_mon_options(sdata, params);
133 ieee80211_if_remove(sdata);
141 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
143 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
148 static int ieee80211_change_iface(struct wiphy *wiphy,
149 struct net_device *dev,
150 enum nl80211_iftype type,
151 struct vif_params *params)
153 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
156 ret = ieee80211_if_change_type(sdata, type);
160 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
161 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
162 ieee80211_check_fast_rx_iface(sdata);
163 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
164 sdata->u.mgd.use_4addr = params->use_4addr;
167 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
168 ret = ieee80211_set_mon_options(sdata, params);
176 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
177 struct wireless_dev *wdev)
179 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
182 mutex_lock(&sdata->local->chanctx_mtx);
183 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
184 mutex_unlock(&sdata->local->chanctx_mtx);
188 return ieee80211_do_open(wdev, true);
191 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
192 struct wireless_dev *wdev)
194 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
197 static int ieee80211_start_nan(struct wiphy *wiphy,
198 struct wireless_dev *wdev,
199 struct cfg80211_nan_conf *conf)
201 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
204 mutex_lock(&sdata->local->chanctx_mtx);
205 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
206 mutex_unlock(&sdata->local->chanctx_mtx);
210 ret = ieee80211_do_open(wdev, true);
214 ret = drv_start_nan(sdata->local, sdata, conf);
216 ieee80211_sdata_stop(sdata);
218 sdata->u.nan.conf = *conf;
223 static void ieee80211_stop_nan(struct wiphy *wiphy,
224 struct wireless_dev *wdev)
226 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
228 drv_stop_nan(sdata->local, sdata);
229 ieee80211_sdata_stop(sdata);
232 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
233 struct wireless_dev *wdev,
234 struct cfg80211_nan_conf *conf,
237 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
238 struct cfg80211_nan_conf new_conf;
241 if (sdata->vif.type != NL80211_IFTYPE_NAN)
244 if (!ieee80211_sdata_running(sdata))
247 new_conf = sdata->u.nan.conf;
249 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
250 new_conf.master_pref = conf->master_pref;
252 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
253 new_conf.bands = conf->bands;
255 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
257 sdata->u.nan.conf = new_conf;
262 static int ieee80211_add_nan_func(struct wiphy *wiphy,
263 struct wireless_dev *wdev,
264 struct cfg80211_nan_func *nan_func)
266 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
269 if (sdata->vif.type != NL80211_IFTYPE_NAN)
272 if (!ieee80211_sdata_running(sdata))
275 spin_lock_bh(&sdata->u.nan.func_lock);
277 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
278 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
280 spin_unlock_bh(&sdata->u.nan.func_lock);
285 nan_func->instance_id = ret;
287 WARN_ON(nan_func->instance_id == 0);
289 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
291 spin_lock_bh(&sdata->u.nan.func_lock);
292 idr_remove(&sdata->u.nan.function_inst_ids,
293 nan_func->instance_id);
294 spin_unlock_bh(&sdata->u.nan.func_lock);
300 static struct cfg80211_nan_func *
301 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
304 struct cfg80211_nan_func *func;
307 lockdep_assert_held(&sdata->u.nan.func_lock);
309 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
310 if (func->cookie == cookie)
317 static void ieee80211_del_nan_func(struct wiphy *wiphy,
318 struct wireless_dev *wdev, u64 cookie)
320 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
321 struct cfg80211_nan_func *func;
324 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
325 !ieee80211_sdata_running(sdata))
328 spin_lock_bh(&sdata->u.nan.func_lock);
330 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
332 instance_id = func->instance_id;
334 spin_unlock_bh(&sdata->u.nan.func_lock);
337 drv_del_nan_func(sdata->local, sdata, instance_id);
340 static int ieee80211_set_noack_map(struct wiphy *wiphy,
341 struct net_device *dev,
344 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
346 sdata->noack_map = noack_map;
348 ieee80211_check_fast_xmit_iface(sdata);
353 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
354 const u8 *mac_addr, u8 key_idx)
356 struct ieee80211_local *local = sdata->local;
357 struct ieee80211_key *key;
358 struct sta_info *sta;
361 if (!wiphy_ext_feature_isset(local->hw.wiphy,
362 NL80211_EXT_FEATURE_EXT_KEY_ID))
365 sta = sta_info_get_bss(sdata, mac_addr);
370 if (sta->ptk_idx == key_idx)
373 mutex_lock(&local->key_mtx);
374 key = key_mtx_dereference(local, sta->ptk[key_idx]);
376 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
377 ret = ieee80211_set_tx_key(key);
379 mutex_unlock(&local->key_mtx);
383 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
384 u8 key_idx, bool pairwise, const u8 *mac_addr,
385 struct key_params *params)
387 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
388 struct ieee80211_local *local = sdata->local;
389 struct sta_info *sta = NULL;
390 const struct ieee80211_cipher_scheme *cs = NULL;
391 struct ieee80211_key *key;
394 if (!ieee80211_sdata_running(sdata))
397 if (pairwise && params->mode == NL80211_KEY_SET_TX)
398 return ieee80211_set_tx(sdata, mac_addr, key_idx);
400 /* reject WEP and TKIP keys if WEP failed to initialize */
401 switch (params->cipher) {
402 case WLAN_CIPHER_SUITE_WEP40:
403 case WLAN_CIPHER_SUITE_TKIP:
404 case WLAN_CIPHER_SUITE_WEP104:
405 if (IS_ERR(local->wep_tx_tfm))
408 case WLAN_CIPHER_SUITE_CCMP:
409 case WLAN_CIPHER_SUITE_CCMP_256:
410 case WLAN_CIPHER_SUITE_AES_CMAC:
411 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
412 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
413 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
414 case WLAN_CIPHER_SUITE_GCMP:
415 case WLAN_CIPHER_SUITE_GCMP_256:
418 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
422 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
423 params->key, params->seq_len, params->seq,
429 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
431 if (params->mode == NL80211_KEY_NO_TX)
432 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
434 mutex_lock(&local->sta_mtx);
437 sta = sta_info_get_bss(sdata, mac_addr);
439 * The ASSOC test makes sure the driver is ready to
440 * receive the key. When wpa_supplicant has roamed
441 * using FT, it attempts to set the key before
442 * association has completed, this rejects that attempt
443 * so it will set the key again after association.
445 * TODO: accept the key if we have a station entry and
446 * add it to the device after the station.
448 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
449 ieee80211_key_free_unused(key);
455 switch (sdata->vif.type) {
456 case NL80211_IFTYPE_STATION:
457 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
458 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
460 case NL80211_IFTYPE_AP:
461 case NL80211_IFTYPE_AP_VLAN:
462 /* Keys without a station are used for TX only */
463 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
464 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
466 case NL80211_IFTYPE_ADHOC:
469 case NL80211_IFTYPE_MESH_POINT:
470 #ifdef CONFIG_MAC80211_MESH
471 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
472 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
475 case NL80211_IFTYPE_WDS:
476 case NL80211_IFTYPE_MONITOR:
477 case NL80211_IFTYPE_P2P_DEVICE:
478 case NL80211_IFTYPE_NAN:
479 case NL80211_IFTYPE_UNSPECIFIED:
480 case NUM_NL80211_IFTYPES:
481 case NL80211_IFTYPE_P2P_CLIENT:
482 case NL80211_IFTYPE_P2P_GO:
483 case NL80211_IFTYPE_OCB:
484 /* shouldn't happen */
490 sta->cipher_scheme = cs;
492 err = ieee80211_key_link(key, sdata, sta);
495 mutex_unlock(&local->sta_mtx);
500 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
501 u8 key_idx, bool pairwise, const u8 *mac_addr)
503 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
504 struct ieee80211_local *local = sdata->local;
505 struct sta_info *sta;
506 struct ieee80211_key *key = NULL;
509 mutex_lock(&local->sta_mtx);
510 mutex_lock(&local->key_mtx);
515 sta = sta_info_get_bss(sdata, mac_addr);
520 key = key_mtx_dereference(local, sta->ptk[key_idx]);
522 key = key_mtx_dereference(local, sta->gtk[key_idx]);
524 key = key_mtx_dereference(local, sdata->keys[key_idx]);
531 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
535 mutex_unlock(&local->key_mtx);
536 mutex_unlock(&local->sta_mtx);
541 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
542 u8 key_idx, bool pairwise, const u8 *mac_addr,
544 void (*callback)(void *cookie,
545 struct key_params *params))
547 struct ieee80211_sub_if_data *sdata;
548 struct sta_info *sta = NULL;
550 struct key_params params;
551 struct ieee80211_key *key = NULL;
556 struct ieee80211_key_seq kseq = {};
558 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
563 sta = sta_info_get_bss(sdata, mac_addr);
567 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
568 key = rcu_dereference(sta->ptk[key_idx]);
569 else if (!pairwise &&
570 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
571 key = rcu_dereference(sta->gtk[key_idx]);
573 key = rcu_dereference(sdata->keys[key_idx]);
578 memset(¶ms, 0, sizeof(params));
580 params.cipher = key->conf.cipher;
582 switch (key->conf.cipher) {
583 case WLAN_CIPHER_SUITE_TKIP:
584 pn64 = atomic64_read(&key->conf.tx_pn);
585 iv32 = TKIP_PN_TO_IV32(pn64);
586 iv16 = TKIP_PN_TO_IV16(pn64);
588 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
589 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
590 drv_get_key_seq(sdata->local, key, &kseq);
591 iv32 = kseq.tkip.iv32;
592 iv16 = kseq.tkip.iv16;
595 seq[0] = iv16 & 0xff;
596 seq[1] = (iv16 >> 8) & 0xff;
597 seq[2] = iv32 & 0xff;
598 seq[3] = (iv32 >> 8) & 0xff;
599 seq[4] = (iv32 >> 16) & 0xff;
600 seq[5] = (iv32 >> 24) & 0xff;
604 case WLAN_CIPHER_SUITE_CCMP:
605 case WLAN_CIPHER_SUITE_CCMP_256:
606 case WLAN_CIPHER_SUITE_AES_CMAC:
607 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
608 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
609 offsetof(typeof(kseq), aes_cmac));
611 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
612 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
613 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
614 offsetof(typeof(kseq), aes_gmac));
616 case WLAN_CIPHER_SUITE_GCMP:
617 case WLAN_CIPHER_SUITE_GCMP_256:
618 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
619 offsetof(typeof(kseq), gcmp));
621 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
622 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
623 drv_get_key_seq(sdata->local, key, &kseq);
624 memcpy(seq, kseq.ccmp.pn, 6);
626 pn64 = atomic64_read(&key->conf.tx_pn);
638 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
640 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
642 drv_get_key_seq(sdata->local, key, &kseq);
643 params.seq = kseq.hw.seq;
644 params.seq_len = kseq.hw.seq_len;
648 params.key = key->conf.key;
649 params.key_len = key->conf.keylen;
651 callback(cookie, ¶ms);
659 static int ieee80211_config_default_key(struct wiphy *wiphy,
660 struct net_device *dev,
661 u8 key_idx, bool uni,
664 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
666 ieee80211_set_default_key(sdata, key_idx, uni, multi);
671 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
672 struct net_device *dev,
675 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
677 ieee80211_set_default_mgmt_key(sdata, key_idx);
682 void sta_set_rate_info_tx(struct sta_info *sta,
683 const struct ieee80211_tx_rate *rate,
684 struct rate_info *rinfo)
687 if (rate->flags & IEEE80211_TX_RC_MCS) {
688 rinfo->flags |= RATE_INFO_FLAGS_MCS;
689 rinfo->mcs = rate->idx;
690 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
691 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
692 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
693 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
695 struct ieee80211_supported_band *sband;
696 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
699 sband = ieee80211_get_sband(sta->sdata);
701 brate = sband->bitrates[rate->idx].bitrate;
702 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
705 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
706 rinfo->bw = RATE_INFO_BW_40;
707 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
708 rinfo->bw = RATE_INFO_BW_80;
709 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
710 rinfo->bw = RATE_INFO_BW_160;
712 rinfo->bw = RATE_INFO_BW_20;
713 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
714 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
717 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
718 int idx, u8 *mac, struct station_info *sinfo)
720 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
721 struct ieee80211_local *local = sdata->local;
722 struct sta_info *sta;
725 mutex_lock(&local->sta_mtx);
727 sta = sta_info_get_by_idx(sdata, idx);
730 memcpy(mac, sta->sta.addr, ETH_ALEN);
731 sta_set_sinfo(sta, sinfo, true);
734 mutex_unlock(&local->sta_mtx);
739 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
740 int idx, struct survey_info *survey)
742 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
744 return drv_get_survey(local, idx, survey);
747 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
748 const u8 *mac, struct station_info *sinfo)
750 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
751 struct ieee80211_local *local = sdata->local;
752 struct sta_info *sta;
755 mutex_lock(&local->sta_mtx);
757 sta = sta_info_get_bss(sdata, mac);
760 sta_set_sinfo(sta, sinfo, true);
763 mutex_unlock(&local->sta_mtx);
768 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
769 struct cfg80211_chan_def *chandef)
771 struct ieee80211_local *local = wiphy_priv(wiphy);
772 struct ieee80211_sub_if_data *sdata;
775 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
778 mutex_lock(&local->mtx);
779 if (local->use_chanctx) {
780 sdata = rtnl_dereference(local->monitor_sdata);
782 ieee80211_vif_release_channel(sdata);
783 ret = ieee80211_vif_use_channel(sdata, chandef,
784 IEEE80211_CHANCTX_EXCLUSIVE);
786 } else if (local->open_count == local->monitors) {
787 local->_oper_chandef = *chandef;
788 ieee80211_hw_config(local, 0);
792 local->monitor_chandef = *chandef;
793 mutex_unlock(&local->mtx);
798 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
799 const u8 *resp, size_t resp_len,
800 const struct ieee80211_csa_settings *csa)
802 struct probe_resp *new, *old;
804 if (!resp || !resp_len)
807 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
809 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
814 memcpy(new->data, resp, resp_len);
817 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
818 csa->n_counter_offsets_presp *
819 sizeof(new->csa_counter_offsets[0]));
821 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
823 kfree_rcu(old, rcu_head);
828 static int ieee80211_set_ftm_responder_params(
829 struct ieee80211_sub_if_data *sdata,
830 const u8 *lci, size_t lci_len,
831 const u8 *civicloc, size_t civicloc_len)
833 struct ieee80211_ftm_responder_params *new, *old;
834 struct ieee80211_bss_conf *bss_conf;
838 if (!lci_len && !civicloc_len)
841 bss_conf = &sdata->vif.bss_conf;
842 old = bss_conf->ftmr_params;
843 len = lci_len + civicloc_len;
845 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
849 pos = (u8 *)(new + 1);
851 new->lci_len = lci_len;
853 memcpy(pos, lci, lci_len);
858 new->civicloc_len = civicloc_len;
860 memcpy(pos, civicloc, civicloc_len);
864 bss_conf->ftmr_params = new;
870 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
871 struct cfg80211_beacon_data *params,
872 const struct ieee80211_csa_settings *csa)
874 struct beacon_data *new, *old;
875 int new_head_len, new_tail_len;
877 u32 changed = BSS_CHANGED_BEACON;
879 old = sdata_dereference(sdata->u.ap.beacon, sdata);
882 /* Need to have a beacon head if we don't have one yet */
883 if (!params->head && !old)
886 /* new or old head? */
888 new_head_len = params->head_len;
890 new_head_len = old->head_len;
892 /* new or old tail? */
893 if (params->tail || !old)
894 /* params->tail_len will be zero for !params->tail */
895 new_tail_len = params->tail_len;
897 new_tail_len = old->tail_len;
899 size = sizeof(*new) + new_head_len + new_tail_len;
901 new = kzalloc(size, GFP_KERNEL);
905 /* start filling the new info now */
908 * pointers go into the block we allocated,
909 * memory is | beacon_data | head | tail |
911 new->head = ((u8 *) new) + sizeof(*new);
912 new->tail = new->head + new_head_len;
913 new->head_len = new_head_len;
914 new->tail_len = new_tail_len;
917 new->csa_current_counter = csa->count;
918 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
919 csa->n_counter_offsets_beacon *
920 sizeof(new->csa_counter_offsets[0]));
925 memcpy(new->head, params->head, new_head_len);
927 memcpy(new->head, old->head, new_head_len);
929 /* copy in optional tail */
931 memcpy(new->tail, params->tail, new_tail_len);
934 memcpy(new->tail, old->tail, new_tail_len);
936 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
937 params->probe_resp_len, csa);
941 changed |= BSS_CHANGED_AP_PROBE_RESP;
943 if (params->ftm_responder != -1) {
944 sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
945 err = ieee80211_set_ftm_responder_params(sdata,
949 params->civicloc_len);
954 changed |= BSS_CHANGED_FTM_RESPONDER;
957 rcu_assign_pointer(sdata->u.ap.beacon, new);
960 kfree_rcu(old, rcu_head);
965 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
966 struct cfg80211_ap_settings *params)
968 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
969 struct ieee80211_local *local = sdata->local;
970 struct beacon_data *old;
971 struct ieee80211_sub_if_data *vlan;
972 u32 changed = BSS_CHANGED_BEACON_INT |
973 BSS_CHANGED_BEACON_ENABLED |
981 old = sdata_dereference(sdata->u.ap.beacon, sdata);
985 switch (params->smps_mode) {
986 case NL80211_SMPS_OFF:
987 sdata->smps_mode = IEEE80211_SMPS_OFF;
989 case NL80211_SMPS_STATIC:
990 sdata->smps_mode = IEEE80211_SMPS_STATIC;
992 case NL80211_SMPS_DYNAMIC:
993 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
998 sdata->u.ap.req_smps = sdata->smps_mode;
1000 sdata->needed_rx_chains = sdata->local->rx_chains;
1002 prev_beacon_int = sdata->vif.bss_conf.beacon_int;
1003 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
1006 sdata->vif.bss_conf.he_support = true;
1008 mutex_lock(&local->mtx);
1009 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
1010 IEEE80211_CHANCTX_SHARED);
1012 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
1013 mutex_unlock(&local->mtx);
1015 sdata->vif.bss_conf.beacon_int = prev_beacon_int;
1020 * Apply control port protocol, this allows us to
1021 * not encrypt dynamic WEP control frames.
1023 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1024 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1025 sdata->control_port_over_nl80211 =
1026 params->crypto.control_port_over_nl80211;
1027 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
1031 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1032 vlan->control_port_protocol =
1033 params->crypto.control_port_ethertype;
1034 vlan->control_port_no_encrypt =
1035 params->crypto.control_port_no_encrypt;
1036 vlan->control_port_over_nl80211 =
1037 params->crypto.control_port_over_nl80211;
1038 vlan->encrypt_headroom =
1039 ieee80211_cs_headroom(sdata->local,
1044 sdata->vif.bss_conf.dtim_period = params->dtim_period;
1045 sdata->vif.bss_conf.enable_beacon = true;
1046 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
1048 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1049 if (params->ssid_len)
1050 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1052 sdata->vif.bss_conf.hidden_ssid =
1053 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1055 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1056 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1057 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1058 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1059 if (params->p2p_opp_ps)
1060 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1061 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1063 err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL);
1065 ieee80211_vif_release_channel(sdata);
1070 err = drv_start_ap(sdata->local, sdata);
1072 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1075 kfree_rcu(old, rcu_head);
1076 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1077 ieee80211_vif_release_channel(sdata);
1081 ieee80211_recalc_dtim(local, sdata);
1082 ieee80211_bss_info_change_notify(sdata, changed);
1084 netif_carrier_on(dev);
1085 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1086 netif_carrier_on(vlan->dev);
1091 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1092 struct cfg80211_beacon_data *params)
1094 struct ieee80211_sub_if_data *sdata;
1095 struct beacon_data *old;
1098 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1099 sdata_assert_lock(sdata);
1101 /* don't allow changing the beacon while CSA is in place - offset
1102 * of channel switch counter may change
1104 if (sdata->vif.csa_active)
1107 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1111 err = ieee80211_assign_beacon(sdata, params, NULL);
1114 ieee80211_bss_info_change_notify(sdata, err);
1118 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1120 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1121 struct ieee80211_sub_if_data *vlan;
1122 struct ieee80211_local *local = sdata->local;
1123 struct beacon_data *old_beacon;
1124 struct probe_resp *old_probe_resp;
1125 struct cfg80211_chan_def chandef;
1127 sdata_assert_lock(sdata);
1129 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
1132 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
1134 /* abort any running channel switch */
1135 mutex_lock(&local->mtx);
1136 sdata->vif.csa_active = false;
1137 if (sdata->csa_block_tx) {
1138 ieee80211_wake_vif_queues(local, sdata,
1139 IEEE80211_QUEUE_STOP_REASON_CSA);
1140 sdata->csa_block_tx = false;
1143 mutex_unlock(&local->mtx);
1145 kfree(sdata->u.ap.next_beacon);
1146 sdata->u.ap.next_beacon = NULL;
1148 /* turn off carrier for this interface and dependent VLANs */
1149 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1150 netif_carrier_off(vlan->dev);
1151 netif_carrier_off(dev);
1153 /* remove beacon and probe response */
1154 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1155 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1156 kfree_rcu(old_beacon, rcu_head);
1158 kfree_rcu(old_probe_resp, rcu_head);
1159 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
1161 kfree(sdata->vif.bss_conf.ftmr_params);
1162 sdata->vif.bss_conf.ftmr_params = NULL;
1164 __sta_info_flush(sdata, true);
1165 ieee80211_free_keys(sdata, true);
1167 sdata->vif.bss_conf.enable_beacon = false;
1168 sdata->vif.bss_conf.ssid_len = 0;
1169 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1170 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1172 if (sdata->wdev.cac_started) {
1173 chandef = sdata->vif.bss_conf.chandef;
1174 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1175 cfg80211_cac_event(sdata->dev, &chandef,
1176 NL80211_RADAR_CAC_ABORTED,
1180 drv_stop_ap(sdata->local, sdata);
1182 /* free all potentially still buffered bcast frames */
1183 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1184 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1186 mutex_lock(&local->mtx);
1187 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
1188 ieee80211_vif_release_channel(sdata);
1189 mutex_unlock(&local->mtx);
1194 static int sta_apply_auth_flags(struct ieee80211_local *local,
1195 struct sta_info *sta,
1200 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1201 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1202 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1203 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1208 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1209 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1210 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1212 * When peer becomes associated, init rate control as
1213 * well. Some drivers require rate control initialized
1214 * before drv_sta_state() is called.
1216 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1217 rate_control_rate_init(sta);
1219 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1224 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1225 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1226 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1227 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1228 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1235 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1236 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1237 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1238 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1243 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1244 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1245 test_sta_flag(sta, WLAN_STA_AUTH)) {
1246 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1254 static void sta_apply_mesh_params(struct ieee80211_local *local,
1255 struct sta_info *sta,
1256 struct station_parameters *params)
1258 #ifdef CONFIG_MAC80211_MESH
1259 struct ieee80211_sub_if_data *sdata = sta->sdata;
1262 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1263 switch (params->plink_state) {
1264 case NL80211_PLINK_ESTAB:
1265 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1266 changed = mesh_plink_inc_estab_count(sdata);
1267 sta->mesh->plink_state = params->plink_state;
1268 sta->mesh->aid = params->peer_aid;
1270 ieee80211_mps_sta_status_update(sta);
1271 changed |= ieee80211_mps_set_sta_local_pm(sta,
1272 sdata->u.mesh.mshcfg.power_mode);
1274 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1275 /* init at low value */
1276 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1279 case NL80211_PLINK_LISTEN:
1280 case NL80211_PLINK_BLOCKED:
1281 case NL80211_PLINK_OPN_SNT:
1282 case NL80211_PLINK_OPN_RCVD:
1283 case NL80211_PLINK_CNF_RCVD:
1284 case NL80211_PLINK_HOLDING:
1285 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1286 changed = mesh_plink_dec_estab_count(sdata);
1287 sta->mesh->plink_state = params->plink_state;
1289 ieee80211_mps_sta_status_update(sta);
1290 changed |= ieee80211_mps_set_sta_local_pm(sta,
1291 NL80211_MESH_POWER_UNKNOWN);
1299 switch (params->plink_action) {
1300 case NL80211_PLINK_ACTION_NO_ACTION:
1303 case NL80211_PLINK_ACTION_OPEN:
1304 changed |= mesh_plink_open(sta);
1306 case NL80211_PLINK_ACTION_BLOCK:
1307 changed |= mesh_plink_block(sta);
1311 if (params->local_pm)
1312 changed |= ieee80211_mps_set_sta_local_pm(sta,
1315 ieee80211_mbss_info_change_notify(sdata, changed);
1319 static int sta_apply_parameters(struct ieee80211_local *local,
1320 struct sta_info *sta,
1321 struct station_parameters *params)
1324 struct ieee80211_supported_band *sband;
1325 struct ieee80211_sub_if_data *sdata = sta->sdata;
1328 sband = ieee80211_get_sband(sdata);
1332 mask = params->sta_flags_mask;
1333 set = params->sta_flags_set;
1335 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1337 * In mesh mode, ASSOCIATED isn't part of the nl80211
1338 * API but must follow AUTHENTICATED for driver state.
1340 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1341 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1342 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1343 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1344 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1346 * TDLS -- everything follows authorized, but
1347 * only becoming authorized is possible, not
1350 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1351 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1352 BIT(NL80211_STA_FLAG_ASSOCIATED);
1353 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1354 BIT(NL80211_STA_FLAG_ASSOCIATED);
1358 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1359 local->hw.queues >= IEEE80211_NUM_ACS)
1360 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1362 /* auth flags will be set later for TDLS,
1363 * and for unassociated stations that move to assocaited */
1364 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1365 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1366 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1367 ret = sta_apply_auth_flags(local, sta, mask, set);
1372 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1373 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1374 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1376 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1379 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1380 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1381 if (set & BIT(NL80211_STA_FLAG_MFP))
1382 set_sta_flag(sta, WLAN_STA_MFP);
1384 clear_sta_flag(sta, WLAN_STA_MFP);
1387 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1388 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1389 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1391 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1394 /* mark TDLS channel switch support, if the AP allows it */
1395 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1396 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1397 params->ext_capab_len >= 4 &&
1398 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1399 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1401 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1402 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1403 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1404 params->ext_capab_len >= 8 &&
1405 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1406 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1408 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1409 sta->sta.uapsd_queues = params->uapsd_queues;
1410 sta->sta.max_sp = params->max_sp;
1413 /* The sender might not have sent the last bit, consider it to be 0 */
1414 if (params->ext_capab_len >= 8) {
1415 u8 val = (params->ext_capab[7] &
1416 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1418 /* we did get all the bits, take the MSB as well */
1419 if (params->ext_capab_len >= 9) {
1420 u8 val_msb = params->ext_capab[8] &
1421 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1428 sta->sta.max_amsdu_subframes = 32;
1431 sta->sta.max_amsdu_subframes = 16;
1434 sta->sta.max_amsdu_subframes = 8;
1437 sta->sta.max_amsdu_subframes = 0;
1442 * cfg80211 validates this (1-2007) and allows setting the AID
1443 * only when creating a new station entry
1446 sta->sta.aid = params->aid;
1449 * Some of the following updates would be racy if called on an
1450 * existing station, via ieee80211_change_station(). However,
1451 * all such changes are rejected by cfg80211 except for updates
1452 * changing the supported rates on an existing but not yet used
1456 if (params->listen_interval >= 0)
1457 sta->listen_interval = params->listen_interval;
1459 if (params->sta_modify_mask & STATION_PARAM_APPLY_STA_TXPOWER) {
1460 sta->sta.txpwr.type = params->txpwr.type;
1461 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1462 sta->sta.txpwr.power = params->txpwr.power;
1463 ret = drv_sta_set_txpwr(local, sdata, sta);
1468 if (params->supported_rates) {
1469 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1470 sband, params->supported_rates,
1471 params->supported_rates_len,
1472 &sta->sta.supp_rates[sband->band]);
1475 if (params->ht_capa)
1476 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1477 params->ht_capa, sta);
1479 /* VHT can override some HT caps such as the A-MSDU max length */
1480 if (params->vht_capa)
1481 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1482 params->vht_capa, sta);
1484 if (params->he_capa)
1485 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1486 (void *)params->he_capa,
1487 params->he_capa_len, sta);
1489 if (params->opmode_notif_used) {
1490 /* returned value is only needed for rc update, but the
1491 * rc isn't initialized here yet, so ignore it
1493 __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
1497 if (params->support_p2p_ps >= 0)
1498 sta->sta.support_p2p_ps = params->support_p2p_ps;
1500 if (ieee80211_vif_is_mesh(&sdata->vif))
1501 sta_apply_mesh_params(local, sta, params);
1503 if (params->airtime_weight)
1504 sta->airtime_weight = params->airtime_weight;
1506 /* set the STA state after all sta info from usermode has been set */
1507 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1508 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1509 ret = sta_apply_auth_flags(local, sta, mask, set);
1517 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1519 struct station_parameters *params)
1521 struct ieee80211_local *local = wiphy_priv(wiphy);
1522 struct sta_info *sta;
1523 struct ieee80211_sub_if_data *sdata;
1528 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1530 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1531 sdata->vif.type != NL80211_IFTYPE_AP)
1534 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1536 if (ether_addr_equal(mac, sdata->vif.addr))
1539 if (is_multicast_ether_addr(mac))
1542 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1546 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1547 sta->sta.tdls = true;
1549 if (sta->sta.tdls && sdata->vif.type == NL80211_IFTYPE_STATION &&
1550 !sdata->u.mgd.associated)
1553 err = sta_apply_parameters(local, sta, params);
1555 sta_info_free(local, sta);
1560 * for TDLS and for unassociated station, rate control should be
1561 * initialized only when rates are known and station is marked
1562 * authorized/associated
1564 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1565 test_sta_flag(sta, WLAN_STA_ASSOC))
1566 rate_control_rate_init(sta);
1568 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1569 sdata->vif.type == NL80211_IFTYPE_AP;
1571 err = sta_info_insert_rcu(sta);
1578 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
1585 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1586 struct station_del_parameters *params)
1588 struct ieee80211_sub_if_data *sdata;
1590 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1593 return sta_info_destroy_addr_bss(sdata, params->mac);
1595 sta_info_flush(sdata);
1599 static int ieee80211_change_station(struct wiphy *wiphy,
1600 struct net_device *dev, const u8 *mac,
1601 struct station_parameters *params)
1603 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1604 struct ieee80211_local *local = wiphy_priv(wiphy);
1605 struct sta_info *sta;
1606 struct ieee80211_sub_if_data *vlansdata;
1607 enum cfg80211_station_type statype;
1610 mutex_lock(&local->sta_mtx);
1612 sta = sta_info_get_bss(sdata, mac);
1618 switch (sdata->vif.type) {
1619 case NL80211_IFTYPE_MESH_POINT:
1620 if (sdata->u.mesh.user_mpm)
1621 statype = CFG80211_STA_MESH_PEER_USER;
1623 statype = CFG80211_STA_MESH_PEER_KERNEL;
1625 case NL80211_IFTYPE_ADHOC:
1626 statype = CFG80211_STA_IBSS;
1628 case NL80211_IFTYPE_STATION:
1629 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1630 statype = CFG80211_STA_AP_STA;
1633 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1634 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1636 statype = CFG80211_STA_TDLS_PEER_SETUP;
1638 case NL80211_IFTYPE_AP:
1639 case NL80211_IFTYPE_AP_VLAN:
1640 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1641 statype = CFG80211_STA_AP_CLIENT;
1643 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1650 err = cfg80211_check_station_change(wiphy, params, statype);
1654 if (params->vlan && params->vlan != sta->sdata->dev) {
1655 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1657 if (params->vlan->ieee80211_ptr->use_4addr) {
1658 if (vlansdata->u.vlan.sta) {
1663 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1664 __ieee80211_check_fast_rx_iface(vlansdata);
1667 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1668 sta->sdata->u.vlan.sta)
1669 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1671 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1672 ieee80211_vif_dec_num_mcast(sta->sdata);
1674 sta->sdata = vlansdata;
1675 ieee80211_check_fast_xmit(sta);
1677 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1678 ieee80211_vif_inc_num_mcast(sta->sdata);
1680 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
1683 err = sta_apply_parameters(local, sta, params);
1687 mutex_unlock(&local->sta_mtx);
1689 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1690 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1691 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1692 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1693 sta_info_tx_streams(sta) != 1) {
1695 "%pM just authorized and MIMO capable - update SMPS\n",
1697 ieee80211_send_smps_action(sta->sdata,
1698 sta->sdata->bss->req_smps,
1700 sta->sdata->vif.bss_conf.bssid);
1703 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1704 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1705 ieee80211_recalc_ps(local);
1706 ieee80211_recalc_ps_vif(sdata);
1711 mutex_unlock(&local->sta_mtx);
1715 #ifdef CONFIG_MAC80211_MESH
1716 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1717 const u8 *dst, const u8 *next_hop)
1719 struct ieee80211_sub_if_data *sdata;
1720 struct mesh_path *mpath;
1721 struct sta_info *sta;
1723 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1726 sta = sta_info_get(sdata, next_hop);
1732 mpath = mesh_path_add(sdata, dst);
1733 if (IS_ERR(mpath)) {
1735 return PTR_ERR(mpath);
1738 mesh_path_fix_nexthop(mpath, sta);
1744 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1747 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1750 return mesh_path_del(sdata, dst);
1752 mesh_path_flush_by_iface(sdata);
1756 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1757 const u8 *dst, const u8 *next_hop)
1759 struct ieee80211_sub_if_data *sdata;
1760 struct mesh_path *mpath;
1761 struct sta_info *sta;
1763 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1767 sta = sta_info_get(sdata, next_hop);
1773 mpath = mesh_path_lookup(sdata, dst);
1779 mesh_path_fix_nexthop(mpath, sta);
1785 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1786 struct mpath_info *pinfo)
1788 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1791 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1793 eth_zero_addr(next_hop);
1795 memset(pinfo, 0, sizeof(*pinfo));
1797 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
1799 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1802 MPATH_INFO_EXPTIME |
1803 MPATH_INFO_DISCOVERY_TIMEOUT |
1804 MPATH_INFO_DISCOVERY_RETRIES |
1806 MPATH_INFO_HOP_COUNT |
1807 MPATH_INFO_PATH_CHANGE;
1809 pinfo->frame_qlen = mpath->frame_queue.qlen;
1810 pinfo->sn = mpath->sn;
1811 pinfo->metric = mpath->metric;
1812 if (time_before(jiffies, mpath->exp_time))
1813 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1814 pinfo->discovery_timeout =
1815 jiffies_to_msecs(mpath->discovery_timeout);
1816 pinfo->discovery_retries = mpath->discovery_retries;
1817 if (mpath->flags & MESH_PATH_ACTIVE)
1818 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1819 if (mpath->flags & MESH_PATH_RESOLVING)
1820 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1821 if (mpath->flags & MESH_PATH_SN_VALID)
1822 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1823 if (mpath->flags & MESH_PATH_FIXED)
1824 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1825 if (mpath->flags & MESH_PATH_RESOLVED)
1826 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1827 pinfo->hop_count = mpath->hop_count;
1828 pinfo->path_change_count = mpath->path_change_count;
1831 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1832 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1835 struct ieee80211_sub_if_data *sdata;
1836 struct mesh_path *mpath;
1838 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1841 mpath = mesh_path_lookup(sdata, dst);
1846 memcpy(dst, mpath->dst, ETH_ALEN);
1847 mpath_set_pinfo(mpath, next_hop, pinfo);
1852 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1853 int idx, u8 *dst, u8 *next_hop,
1854 struct mpath_info *pinfo)
1856 struct ieee80211_sub_if_data *sdata;
1857 struct mesh_path *mpath;
1859 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1862 mpath = mesh_path_lookup_by_idx(sdata, idx);
1867 memcpy(dst, mpath->dst, ETH_ALEN);
1868 mpath_set_pinfo(mpath, next_hop, pinfo);
1873 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1874 struct mpath_info *pinfo)
1876 memset(pinfo, 0, sizeof(*pinfo));
1877 memcpy(mpp, mpath->mpp, ETH_ALEN);
1879 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
1882 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1883 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1886 struct ieee80211_sub_if_data *sdata;
1887 struct mesh_path *mpath;
1889 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1892 mpath = mpp_path_lookup(sdata, dst);
1897 memcpy(dst, mpath->dst, ETH_ALEN);
1898 mpp_set_pinfo(mpath, mpp, pinfo);
1903 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1904 int idx, u8 *dst, u8 *mpp,
1905 struct mpath_info *pinfo)
1907 struct ieee80211_sub_if_data *sdata;
1908 struct mesh_path *mpath;
1910 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1913 mpath = mpp_path_lookup_by_idx(sdata, idx);
1918 memcpy(dst, mpath->dst, ETH_ALEN);
1919 mpp_set_pinfo(mpath, mpp, pinfo);
1924 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1925 struct net_device *dev,
1926 struct mesh_config *conf)
1928 struct ieee80211_sub_if_data *sdata;
1929 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1931 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1935 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1937 return (mask >> (parm-1)) & 0x1;
1940 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1941 const struct mesh_setup *setup)
1945 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1946 struct ieee80211_sub_if_data, u.mesh);
1948 /* allocate information elements */
1952 if (setup->ie_len) {
1953 new_ie = kmemdup(setup->ie, setup->ie_len,
1958 ifmsh->ie_len = setup->ie_len;
1962 /* now copy the rest of the setup parameters */
1963 ifmsh->mesh_id_len = setup->mesh_id_len;
1964 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1965 ifmsh->mesh_sp_id = setup->sync_method;
1966 ifmsh->mesh_pp_id = setup->path_sel_proto;
1967 ifmsh->mesh_pm_id = setup->path_metric;
1968 ifmsh->user_mpm = setup->user_mpm;
1969 ifmsh->mesh_auth_id = setup->auth_id;
1970 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1971 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
1972 if (setup->is_authenticated)
1973 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1974 if (setup->is_secure)
1975 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1977 /* mcast rate setting in Mesh Node */
1978 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1979 sizeof(setup->mcast_rate));
1980 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
1982 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1983 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1988 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1989 struct net_device *dev, u32 mask,
1990 const struct mesh_config *nconf)
1992 struct mesh_config *conf;
1993 struct ieee80211_sub_if_data *sdata;
1994 struct ieee80211_if_mesh *ifmsh;
1996 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1997 ifmsh = &sdata->u.mesh;
1999 /* Set the config options which we are interested in setting */
2000 conf = &(sdata->u.mesh.mshcfg);
2001 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2002 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2003 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2004 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2005 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2006 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2007 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2008 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2009 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2010 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2011 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2012 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2013 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2014 conf->element_ttl = nconf->element_ttl;
2015 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2016 if (ifmsh->user_mpm)
2018 conf->auto_open_plinks = nconf->auto_open_plinks;
2020 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2021 conf->dot11MeshNbrOffsetMaxNeighbor =
2022 nconf->dot11MeshNbrOffsetMaxNeighbor;
2023 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2024 conf->dot11MeshHWMPmaxPREQretries =
2025 nconf->dot11MeshHWMPmaxPREQretries;
2026 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2027 conf->path_refresh_time = nconf->path_refresh_time;
2028 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2029 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2030 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2031 conf->dot11MeshHWMPactivePathTimeout =
2032 nconf->dot11MeshHWMPactivePathTimeout;
2033 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2034 conf->dot11MeshHWMPpreqMinInterval =
2035 nconf->dot11MeshHWMPpreqMinInterval;
2036 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2037 conf->dot11MeshHWMPperrMinInterval =
2038 nconf->dot11MeshHWMPperrMinInterval;
2039 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2041 conf->dot11MeshHWMPnetDiameterTraversalTime =
2042 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2043 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2044 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2045 ieee80211_mesh_root_setup(ifmsh);
2047 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2048 /* our current gate announcement implementation rides on root
2049 * announcements, so require this ifmsh to also be a root node
2051 if (nconf->dot11MeshGateAnnouncementProtocol &&
2052 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2053 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2054 ieee80211_mesh_root_setup(ifmsh);
2056 conf->dot11MeshGateAnnouncementProtocol =
2057 nconf->dot11MeshGateAnnouncementProtocol;
2059 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2060 conf->dot11MeshHWMPRannInterval =
2061 nconf->dot11MeshHWMPRannInterval;
2062 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2063 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2064 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2065 /* our RSSI threshold implementation is supported only for
2066 * devices that report signal in dBm.
2068 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2070 conf->rssi_threshold = nconf->rssi_threshold;
2072 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2073 conf->ht_opmode = nconf->ht_opmode;
2074 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2075 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
2077 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2078 conf->dot11MeshHWMPactivePathToRootTimeout =
2079 nconf->dot11MeshHWMPactivePathToRootTimeout;
2080 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2081 conf->dot11MeshHWMProotInterval =
2082 nconf->dot11MeshHWMProotInterval;
2083 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2084 conf->dot11MeshHWMPconfirmationInterval =
2085 nconf->dot11MeshHWMPconfirmationInterval;
2086 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2087 conf->power_mode = nconf->power_mode;
2088 ieee80211_mps_local_status_update(sdata);
2090 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2091 conf->dot11MeshAwakeWindowDuration =
2092 nconf->dot11MeshAwakeWindowDuration;
2093 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2094 conf->plink_timeout = nconf->plink_timeout;
2095 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2096 conf->dot11MeshConnectedToMeshGate =
2097 nconf->dot11MeshConnectedToMeshGate;
2098 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2102 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2103 const struct mesh_config *conf,
2104 const struct mesh_setup *setup)
2106 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2107 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2110 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2111 err = copy_mesh_setup(ifmsh, setup);
2115 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2117 /* can mesh use other SMPS modes? */
2118 sdata->smps_mode = IEEE80211_SMPS_OFF;
2119 sdata->needed_rx_chains = sdata->local->rx_chains;
2121 mutex_lock(&sdata->local->mtx);
2122 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
2123 IEEE80211_CHANCTX_SHARED);
2124 mutex_unlock(&sdata->local->mtx);
2128 return ieee80211_start_mesh(sdata);
2131 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2133 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2135 ieee80211_stop_mesh(sdata);
2136 mutex_lock(&sdata->local->mtx);
2137 ieee80211_vif_release_channel(sdata);
2138 mutex_unlock(&sdata->local->mtx);
2144 static int ieee80211_change_bss(struct wiphy *wiphy,
2145 struct net_device *dev,
2146 struct bss_parameters *params)
2148 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2149 struct ieee80211_supported_band *sband;
2152 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
2155 sband = ieee80211_get_sband(sdata);
2159 if (params->use_cts_prot >= 0) {
2160 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2161 changed |= BSS_CHANGED_ERP_CTS_PROT;
2163 if (params->use_short_preamble >= 0) {
2164 sdata->vif.bss_conf.use_short_preamble =
2165 params->use_short_preamble;
2166 changed |= BSS_CHANGED_ERP_PREAMBLE;
2169 if (!sdata->vif.bss_conf.use_short_slot &&
2170 sband->band == NL80211_BAND_5GHZ) {
2171 sdata->vif.bss_conf.use_short_slot = true;
2172 changed |= BSS_CHANGED_ERP_SLOT;
2175 if (params->use_short_slot_time >= 0) {
2176 sdata->vif.bss_conf.use_short_slot =
2177 params->use_short_slot_time;
2178 changed |= BSS_CHANGED_ERP_SLOT;
2181 if (params->basic_rates) {
2182 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2183 wiphy->bands[sband->band],
2184 params->basic_rates,
2185 params->basic_rates_len,
2186 &sdata->vif.bss_conf.basic_rates);
2187 changed |= BSS_CHANGED_BASIC_RATES;
2188 ieee80211_check_rate_mask(sdata);
2191 if (params->ap_isolate >= 0) {
2192 if (params->ap_isolate)
2193 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2195 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2196 ieee80211_check_fast_rx_iface(sdata);
2199 if (params->ht_opmode >= 0) {
2200 sdata->vif.bss_conf.ht_operation_mode =
2201 (u16) params->ht_opmode;
2202 changed |= BSS_CHANGED_HT;
2205 if (params->p2p_ctwindow >= 0) {
2206 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2207 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2208 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2209 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2210 changed |= BSS_CHANGED_P2P_PS;
2213 if (params->p2p_opp_ps > 0) {
2214 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2215 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2216 changed |= BSS_CHANGED_P2P_PS;
2217 } else if (params->p2p_opp_ps == 0) {
2218 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2219 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2220 changed |= BSS_CHANGED_P2P_PS;
2223 ieee80211_bss_info_change_notify(sdata, changed);
2228 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2229 struct net_device *dev,
2230 struct ieee80211_txq_params *params)
2232 struct ieee80211_local *local = wiphy_priv(wiphy);
2233 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2234 struct ieee80211_tx_queue_params p;
2236 if (!local->ops->conf_tx)
2239 if (local->hw.queues < IEEE80211_NUM_ACS)
2242 memset(&p, 0, sizeof(p));
2243 p.aifs = params->aifs;
2244 p.cw_max = params->cwmax;
2245 p.cw_min = params->cwmin;
2246 p.txop = params->txop;
2249 * Setting tx queue params disables u-apsd because it's only
2250 * called in master mode.
2254 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2256 sdata->tx_conf[params->ac] = p;
2257 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2258 wiphy_debug(local->hw.wiphy,
2259 "failed to set TX queue parameters for AC %d\n",
2264 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2270 static int ieee80211_suspend(struct wiphy *wiphy,
2271 struct cfg80211_wowlan *wowlan)
2273 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2276 static int ieee80211_resume(struct wiphy *wiphy)
2278 return __ieee80211_resume(wiphy_priv(wiphy));
2281 #define ieee80211_suspend NULL
2282 #define ieee80211_resume NULL
2285 static int ieee80211_scan(struct wiphy *wiphy,
2286 struct cfg80211_scan_request *req)
2288 struct ieee80211_sub_if_data *sdata;
2290 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2292 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2293 case NL80211_IFTYPE_STATION:
2294 case NL80211_IFTYPE_ADHOC:
2295 case NL80211_IFTYPE_MESH_POINT:
2296 case NL80211_IFTYPE_P2P_CLIENT:
2297 case NL80211_IFTYPE_P2P_DEVICE:
2299 case NL80211_IFTYPE_P2P_GO:
2300 if (sdata->local->ops->hw_scan)
2303 * FIXME: implement NoA while scanning in software,
2304 * for now fall through to allow scanning only when
2305 * beaconing hasn't been configured yet
2308 case NL80211_IFTYPE_AP:
2310 * If the scan has been forced (and the driver supports
2311 * forcing), don't care about being beaconing already.
2312 * This will create problems to the attached stations (e.g. all
2313 * the frames sent while scanning on other channel will be
2316 if (sdata->u.ap.beacon &&
2317 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2318 !(req->flags & NL80211_SCAN_FLAG_AP)))
2321 case NL80211_IFTYPE_NAN:
2326 return ieee80211_request_scan(sdata, req);
2329 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2331 ieee80211_scan_cancel(wiphy_priv(wiphy));
2335 ieee80211_sched_scan_start(struct wiphy *wiphy,
2336 struct net_device *dev,
2337 struct cfg80211_sched_scan_request *req)
2339 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2341 if (!sdata->local->ops->sched_scan_start)
2344 return ieee80211_request_sched_scan_start(sdata, req);
2348 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2351 struct ieee80211_local *local = wiphy_priv(wiphy);
2353 if (!local->ops->sched_scan_stop)
2356 return ieee80211_request_sched_scan_stop(local);
2359 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2360 struct cfg80211_auth_request *req)
2362 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2365 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2366 struct cfg80211_assoc_request *req)
2368 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2371 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2372 struct cfg80211_deauth_request *req)
2374 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2377 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2378 struct cfg80211_disassoc_request *req)
2380 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2383 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2384 struct cfg80211_ibss_params *params)
2386 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2389 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2391 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2394 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2395 struct ocb_setup *setup)
2397 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2400 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2402 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2405 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2406 int rate[NUM_NL80211_BANDS])
2408 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2410 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2411 sizeof(int) * NUM_NL80211_BANDS);
2413 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
2418 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2420 struct ieee80211_local *local = wiphy_priv(wiphy);
2423 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2424 ieee80211_check_fast_xmit_all(local);
2426 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2429 ieee80211_check_fast_xmit_all(local);
2434 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2435 (changed & WIPHY_PARAM_DYN_ACK)) {
2438 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2439 wiphy->coverage_class : -1;
2440 err = drv_set_coverage_class(local, coverage_class);
2446 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2447 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2453 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2454 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2456 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2458 if (changed & WIPHY_PARAM_RETRY_LONG) {
2459 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2461 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2464 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2465 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2467 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2468 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2469 WIPHY_PARAM_TXQ_QUANTUM))
2470 ieee80211_txq_set_params(local);
2475 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2476 struct wireless_dev *wdev,
2477 enum nl80211_tx_power_setting type, int mbm)
2479 struct ieee80211_local *local = wiphy_priv(wiphy);
2480 struct ieee80211_sub_if_data *sdata;
2481 enum nl80211_tx_power_setting txp_type = type;
2482 bool update_txp_type = false;
2483 bool has_monitor = false;
2486 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2488 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2489 sdata = rtnl_dereference(local->monitor_sdata);
2495 case NL80211_TX_POWER_AUTOMATIC:
2496 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2497 txp_type = NL80211_TX_POWER_LIMITED;
2499 case NL80211_TX_POWER_LIMITED:
2500 case NL80211_TX_POWER_FIXED:
2501 if (mbm < 0 || (mbm % 100))
2503 sdata->user_power_level = MBM_TO_DBM(mbm);
2507 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2508 update_txp_type = true;
2509 sdata->vif.bss_conf.txpower_type = txp_type;
2512 ieee80211_recalc_txpower(sdata, update_txp_type);
2518 case NL80211_TX_POWER_AUTOMATIC:
2519 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2520 txp_type = NL80211_TX_POWER_LIMITED;
2522 case NL80211_TX_POWER_LIMITED:
2523 case NL80211_TX_POWER_FIXED:
2524 if (mbm < 0 || (mbm % 100))
2526 local->user_power_level = MBM_TO_DBM(mbm);
2530 mutex_lock(&local->iflist_mtx);
2531 list_for_each_entry(sdata, &local->interfaces, list) {
2532 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2536 sdata->user_power_level = local->user_power_level;
2537 if (txp_type != sdata->vif.bss_conf.txpower_type)
2538 update_txp_type = true;
2539 sdata->vif.bss_conf.txpower_type = txp_type;
2541 list_for_each_entry(sdata, &local->interfaces, list) {
2542 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2544 ieee80211_recalc_txpower(sdata, update_txp_type);
2546 mutex_unlock(&local->iflist_mtx);
2549 sdata = rtnl_dereference(local->monitor_sdata);
2551 sdata->user_power_level = local->user_power_level;
2552 if (txp_type != sdata->vif.bss_conf.txpower_type)
2553 update_txp_type = true;
2554 sdata->vif.bss_conf.txpower_type = txp_type;
2556 ieee80211_recalc_txpower(sdata, update_txp_type);
2563 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2564 struct wireless_dev *wdev,
2567 struct ieee80211_local *local = wiphy_priv(wiphy);
2568 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2570 if (local->ops->get_txpower)
2571 return drv_get_txpower(local, sdata, dbm);
2573 if (!local->use_chanctx)
2574 *dbm = local->hw.conf.power_level;
2576 *dbm = sdata->vif.bss_conf.txpower;
2581 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2584 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2586 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2591 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2593 struct ieee80211_local *local = wiphy_priv(wiphy);
2595 drv_rfkill_poll(local);
2598 #ifdef CONFIG_NL80211_TESTMODE
2599 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2600 struct wireless_dev *wdev,
2601 void *data, int len)
2603 struct ieee80211_local *local = wiphy_priv(wiphy);
2604 struct ieee80211_vif *vif = NULL;
2606 if (!local->ops->testmode_cmd)
2610 struct ieee80211_sub_if_data *sdata;
2612 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2613 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2617 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2620 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2621 struct sk_buff *skb,
2622 struct netlink_callback *cb,
2623 void *data, int len)
2625 struct ieee80211_local *local = wiphy_priv(wiphy);
2627 if (!local->ops->testmode_dump)
2630 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2634 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2635 enum ieee80211_smps_mode smps_mode)
2637 struct sta_info *sta;
2638 enum ieee80211_smps_mode old_req;
2640 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2643 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2646 old_req = sdata->u.ap.req_smps;
2647 sdata->u.ap.req_smps = smps_mode;
2649 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2650 if (old_req == smps_mode ||
2651 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2655 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
2656 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2658 mutex_lock(&sdata->local->sta_mtx);
2659 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2661 * Only stations associated to our AP and
2664 if (sta->sdata->bss != &sdata->u.ap)
2667 /* This station doesn't support MIMO - skip it */
2668 if (sta_info_tx_streams(sta) == 1)
2672 * Don't wake up a STA just to send the action frame
2673 * unless we are getting more restrictive.
2675 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2676 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2678 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2684 * If the STA is not authorized, wait until it gets
2685 * authorized and the action frame will be sent then.
2687 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2690 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2691 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2692 sdata->vif.bss_conf.bssid);
2694 mutex_unlock(&sdata->local->sta_mtx);
2696 sdata->smps_mode = smps_mode;
2697 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2702 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2703 enum ieee80211_smps_mode smps_mode)
2706 enum ieee80211_smps_mode old_req;
2708 struct sta_info *sta;
2709 bool tdls_peer_found = false;
2711 lockdep_assert_held(&sdata->wdev.mtx);
2713 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2716 old_req = sdata->u.mgd.req_smps;
2717 sdata->u.mgd.req_smps = smps_mode;
2719 if (old_req == smps_mode &&
2720 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2724 * If not associated, or current association is not an HT
2725 * association, there's no need to do anything, just store
2726 * the new value until we associate.
2728 if (!sdata->u.mgd.associated ||
2729 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2732 ap = sdata->u.mgd.associated->bssid;
2735 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2736 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2737 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2740 tdls_peer_found = true;
2745 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2746 if (tdls_peer_found || !sdata->u.mgd.powersave)
2747 smps_mode = IEEE80211_SMPS_OFF;
2749 smps_mode = IEEE80211_SMPS_DYNAMIC;
2752 /* send SM PS frame to AP */
2753 err = ieee80211_send_smps_action(sdata, smps_mode,
2756 sdata->u.mgd.req_smps = old_req;
2757 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2758 ieee80211_teardown_tdls_peers(sdata);
2763 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2764 bool enabled, int timeout)
2766 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2767 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2769 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2772 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
2775 if (enabled == sdata->u.mgd.powersave &&
2776 timeout == local->dynamic_ps_forced_timeout)
2779 sdata->u.mgd.powersave = enabled;
2780 local->dynamic_ps_forced_timeout = timeout;
2782 /* no change, but if automatic follow powersave */
2784 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2785 sdata_unlock(sdata);
2787 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
2788 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2790 ieee80211_recalc_ps(local);
2791 ieee80211_recalc_ps_vif(sdata);
2792 ieee80211_check_fast_rx_iface(sdata);
2797 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2798 struct net_device *dev,
2799 s32 rssi_thold, u32 rssi_hyst)
2801 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2802 struct ieee80211_vif *vif = &sdata->vif;
2803 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2805 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2806 rssi_hyst == bss_conf->cqm_rssi_hyst)
2809 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2810 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2813 bss_conf->cqm_rssi_thold = rssi_thold;
2814 bss_conf->cqm_rssi_hyst = rssi_hyst;
2815 bss_conf->cqm_rssi_low = 0;
2816 bss_conf->cqm_rssi_high = 0;
2817 sdata->u.mgd.last_cqm_event_signal = 0;
2819 /* tell the driver upon association, unless already associated */
2820 if (sdata->u.mgd.associated &&
2821 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2822 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2827 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
2828 struct net_device *dev,
2829 s32 rssi_low, s32 rssi_high)
2831 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2832 struct ieee80211_vif *vif = &sdata->vif;
2833 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2835 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
2838 bss_conf->cqm_rssi_low = rssi_low;
2839 bss_conf->cqm_rssi_high = rssi_high;
2840 bss_conf->cqm_rssi_thold = 0;
2841 bss_conf->cqm_rssi_hyst = 0;
2842 sdata->u.mgd.last_cqm_event_signal = 0;
2844 /* tell the driver upon association, unless already associated */
2845 if (sdata->u.mgd.associated &&
2846 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2847 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2852 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2853 struct net_device *dev,
2855 const struct cfg80211_bitrate_mask *mask)
2857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2858 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2861 if (!ieee80211_sdata_running(sdata))
2865 * If active validate the setting and reject it if it doesn't leave
2866 * at least one basic rate usable, since we really have to be able
2867 * to send something, and if we're an AP we have to be able to do
2868 * so at a basic rate so that all clients can receive it.
2870 if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
2871 sdata->vif.bss_conf.chandef.chan) {
2872 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2873 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
2875 if (!(mask->control[band].legacy & basic_rates))
2879 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
2880 ret = drv_set_bitrate_mask(local, sdata, mask);
2885 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2886 struct ieee80211_supported_band *sband = wiphy->bands[i];
2889 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2890 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2891 sizeof(mask->control[i].ht_mcs));
2892 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
2893 mask->control[i].vht_mcs,
2894 sizeof(mask->control[i].vht_mcs));
2896 sdata->rc_has_mcs_mask[i] = false;
2897 sdata->rc_has_vht_mcs_mask[i] = false;
2901 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
2902 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2903 sdata->rc_has_mcs_mask[i] = true;
2908 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
2909 if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
2910 sdata->rc_has_vht_mcs_mask[i] = true;
2919 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2920 struct net_device *dev,
2921 struct cfg80211_chan_def *chandef,
2924 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2925 struct ieee80211_local *local = sdata->local;
2928 mutex_lock(&local->mtx);
2929 if (!list_empty(&local->roc_list) || local->scanning) {
2934 /* whatever, but channel contexts should not complain about that one */
2935 sdata->smps_mode = IEEE80211_SMPS_OFF;
2936 sdata->needed_rx_chains = local->rx_chains;
2938 err = ieee80211_vif_use_channel(sdata, chandef,
2939 IEEE80211_CHANCTX_SHARED);
2943 ieee80211_queue_delayed_work(&sdata->local->hw,
2944 &sdata->dfs_cac_timer_work,
2945 msecs_to_jiffies(cac_time_ms));
2948 mutex_unlock(&local->mtx);
2952 static struct cfg80211_beacon_data *
2953 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2955 struct cfg80211_beacon_data *new_beacon;
2959 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2960 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2961 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
2963 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2967 pos = (u8 *)(new_beacon + 1);
2968 if (beacon->head_len) {
2969 new_beacon->head_len = beacon->head_len;
2970 new_beacon->head = pos;
2971 memcpy(pos, beacon->head, beacon->head_len);
2972 pos += beacon->head_len;
2974 if (beacon->tail_len) {
2975 new_beacon->tail_len = beacon->tail_len;
2976 new_beacon->tail = pos;
2977 memcpy(pos, beacon->tail, beacon->tail_len);
2978 pos += beacon->tail_len;
2980 if (beacon->beacon_ies_len) {
2981 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2982 new_beacon->beacon_ies = pos;
2983 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2984 pos += beacon->beacon_ies_len;
2986 if (beacon->proberesp_ies_len) {
2987 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2988 new_beacon->proberesp_ies = pos;
2989 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2990 pos += beacon->proberesp_ies_len;
2992 if (beacon->assocresp_ies_len) {
2993 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2994 new_beacon->assocresp_ies = pos;
2995 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2996 pos += beacon->assocresp_ies_len;
2998 if (beacon->probe_resp_len) {
2999 new_beacon->probe_resp_len = beacon->probe_resp_len;
3000 new_beacon->probe_resp = pos;
3001 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3002 pos += beacon->probe_resp_len;
3005 /* might copy -1, meaning no changes requested */
3006 new_beacon->ftm_responder = beacon->ftm_responder;
3008 new_beacon->lci_len = beacon->lci_len;
3009 new_beacon->lci = pos;
3010 memcpy(pos, beacon->lci, beacon->lci_len);
3011 pos += beacon->lci_len;
3013 if (beacon->civicloc) {
3014 new_beacon->civicloc_len = beacon->civicloc_len;
3015 new_beacon->civicloc = pos;
3016 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3017 pos += beacon->civicloc_len;
3023 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3025 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3027 ieee80211_queue_work(&sdata->local->hw,
3028 &sdata->csa_finalize_work);
3030 EXPORT_SYMBOL(ieee80211_csa_finish);
3032 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3037 switch (sdata->vif.type) {
3038 case NL80211_IFTYPE_AP:
3039 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
3041 kfree(sdata->u.ap.next_beacon);
3042 sdata->u.ap.next_beacon = NULL;
3048 case NL80211_IFTYPE_ADHOC:
3049 err = ieee80211_ibss_finish_csa(sdata);
3054 #ifdef CONFIG_MAC80211_MESH
3055 case NL80211_IFTYPE_MESH_POINT:
3056 err = ieee80211_mesh_finish_csa(sdata);
3070 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3072 struct ieee80211_local *local = sdata->local;
3076 sdata_assert_lock(sdata);
3077 lockdep_assert_held(&local->mtx);
3078 lockdep_assert_held(&local->chanctx_mtx);
3081 * using reservation isn't immediate as it may be deferred until later
3082 * with multi-vif. once reservation is complete it will re-schedule the
3083 * work with no reserved_chanctx so verify chandef to check if it
3084 * completed successfully
3087 if (sdata->reserved_chanctx) {
3089 * with multi-vif csa driver may call ieee80211_csa_finish()
3090 * many times while waiting for other interfaces to use their
3093 if (sdata->reserved_ready)
3096 return ieee80211_vif_use_reserved_context(sdata);
3099 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3100 &sdata->csa_chandef))
3103 sdata->vif.csa_active = false;
3105 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3109 ieee80211_bss_info_change_notify(sdata, changed);
3111 if (sdata->csa_block_tx) {
3112 ieee80211_wake_vif_queues(local, sdata,
3113 IEEE80211_QUEUE_STOP_REASON_CSA);
3114 sdata->csa_block_tx = false;
3117 err = drv_post_channel_switch(sdata);
3121 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3126 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3128 if (__ieee80211_csa_finalize(sdata)) {
3129 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3130 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3135 void ieee80211_csa_finalize_work(struct work_struct *work)
3137 struct ieee80211_sub_if_data *sdata =
3138 container_of(work, struct ieee80211_sub_if_data,
3140 struct ieee80211_local *local = sdata->local;
3143 mutex_lock(&local->mtx);
3144 mutex_lock(&local->chanctx_mtx);
3146 /* AP might have been stopped while waiting for the lock. */
3147 if (!sdata->vif.csa_active)
3150 if (!ieee80211_sdata_running(sdata))
3153 ieee80211_csa_finalize(sdata);
3156 mutex_unlock(&local->chanctx_mtx);
3157 mutex_unlock(&local->mtx);
3158 sdata_unlock(sdata);
3161 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3162 struct cfg80211_csa_settings *params,
3165 struct ieee80211_csa_settings csa = {};
3168 switch (sdata->vif.type) {
3169 case NL80211_IFTYPE_AP:
3170 sdata->u.ap.next_beacon =
3171 cfg80211_beacon_dup(¶ms->beacon_after);
3172 if (!sdata->u.ap.next_beacon)
3176 * With a count of 0, we don't have to wait for any
3177 * TBTT before switching, so complete the CSA
3178 * immediately. In theory, with a count == 1 we
3179 * should delay the switch until just before the next
3180 * TBTT, but that would complicate things so we switch
3181 * immediately too. If we would delay the switch
3182 * until the next TBTT, we would have to set the probe
3185 * TODO: A channel switch with count <= 1 without
3186 * sending a CSA action frame is kind of useless,
3187 * because the clients won't know we're changing
3188 * channels. The action frame must be implemented
3189 * either here or in the userspace.
3191 if (params->count <= 1)
3194 if ((params->n_counter_offsets_beacon >
3195 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3196 (params->n_counter_offsets_presp >
3197 IEEE80211_MAX_CSA_COUNTERS_NUM))
3200 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3201 csa.counter_offsets_presp = params->counter_offsets_presp;
3202 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3203 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3204 csa.count = params->count;
3206 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa);
3208 kfree(sdata->u.ap.next_beacon);
3214 case NL80211_IFTYPE_ADHOC:
3215 if (!sdata->vif.bss_conf.ibss_joined)
3218 if (params->chandef.width != sdata->u.ibss.chandef.width)
3221 switch (params->chandef.width) {
3222 case NL80211_CHAN_WIDTH_40:
3223 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3224 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3226 case NL80211_CHAN_WIDTH_5:
3227 case NL80211_CHAN_WIDTH_10:
3228 case NL80211_CHAN_WIDTH_20_NOHT:
3229 case NL80211_CHAN_WIDTH_20:
3235 /* changes into another band are not supported */
3236 if (sdata->u.ibss.chandef.chan->band !=
3237 params->chandef.chan->band)
3240 /* see comments in the NL80211_IFTYPE_AP block */
3241 if (params->count > 1) {
3242 err = ieee80211_ibss_csa_beacon(sdata, params);
3248 ieee80211_send_action_csa(sdata, params);
3251 #ifdef CONFIG_MAC80211_MESH
3252 case NL80211_IFTYPE_MESH_POINT: {
3253 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3255 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3258 /* changes into another band are not supported */
3259 if (sdata->vif.bss_conf.chandef.chan->band !=
3260 params->chandef.chan->band)
3263 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3264 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3265 if (!ifmsh->pre_value)
3266 ifmsh->pre_value = 1;
3271 /* see comments in the NL80211_IFTYPE_AP block */
3272 if (params->count > 1) {
3273 err = ieee80211_mesh_csa_beacon(sdata, params);
3275 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3281 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3282 ieee80211_send_action_csa(sdata, params);
3295 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3296 struct cfg80211_csa_settings *params)
3298 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3299 struct ieee80211_local *local = sdata->local;
3300 struct ieee80211_channel_switch ch_switch;
3301 struct ieee80211_chanctx_conf *conf;
3302 struct ieee80211_chanctx *chanctx;
3306 sdata_assert_lock(sdata);
3307 lockdep_assert_held(&local->mtx);
3309 if (!list_empty(&local->roc_list) || local->scanning)
3312 if (sdata->wdev.cac_started)
3315 if (cfg80211_chandef_identical(¶ms->chandef,
3316 &sdata->vif.bss_conf.chandef))
3319 /* don't allow another channel switch if one is already active. */
3320 if (sdata->vif.csa_active)
3323 mutex_lock(&local->chanctx_mtx);
3324 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3325 lockdep_is_held(&local->chanctx_mtx));
3331 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3333 ch_switch.timestamp = 0;
3334 ch_switch.device_timestamp = 0;
3335 ch_switch.block_tx = params->block_tx;
3336 ch_switch.chandef = params->chandef;
3337 ch_switch.count = params->count;
3339 err = drv_pre_channel_switch(sdata, &ch_switch);
3343 err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef,
3345 params->radar_required);
3349 /* if reservation is invalid then this will fail */
3350 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3352 ieee80211_vif_unreserve_chanctx(sdata);
3356 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3358 ieee80211_vif_unreserve_chanctx(sdata);
3362 sdata->csa_chandef = params->chandef;
3363 sdata->csa_block_tx = params->block_tx;
3364 sdata->vif.csa_active = true;
3366 if (sdata->csa_block_tx)
3367 ieee80211_stop_vif_queues(local, sdata,
3368 IEEE80211_QUEUE_STOP_REASON_CSA);
3370 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3374 ieee80211_bss_info_change_notify(sdata, changed);
3375 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3377 /* if the beacon didn't change, we can finalize immediately */
3378 ieee80211_csa_finalize(sdata);
3382 mutex_unlock(&local->chanctx_mtx);
3386 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3387 struct cfg80211_csa_settings *params)
3389 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3390 struct ieee80211_local *local = sdata->local;
3393 mutex_lock(&local->mtx);
3394 err = __ieee80211_channel_switch(wiphy, dev, params);
3395 mutex_unlock(&local->mtx);
3400 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3402 lockdep_assert_held(&local->mtx);
3404 local->roc_cookie_counter++;
3406 /* wow, you wrapped 64 bits ... more likely a bug */
3407 if (WARN_ON(local->roc_cookie_counter == 0))
3408 local->roc_cookie_counter++;
3410 return local->roc_cookie_counter;
3413 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3414 u64 *cookie, gfp_t gfp)
3416 unsigned long spin_flags;
3417 struct sk_buff *ack_skb;
3420 ack_skb = skb_copy(skb, gfp);
3424 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3425 id = idr_alloc(&local->ack_status_frames, ack_skb,
3426 1, 0x10000, GFP_ATOMIC);
3427 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3434 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3436 *cookie = ieee80211_mgmt_tx_cookie(local);
3437 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3442 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
3443 struct wireless_dev *wdev,
3444 u16 frame_type, bool reg)
3446 struct ieee80211_local *local = wiphy_priv(wiphy);
3447 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3449 switch (frame_type) {
3450 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3452 local->probe_req_reg++;
3453 sdata->vif.probe_req_reg++;
3455 if (local->probe_req_reg)
3456 local->probe_req_reg--;
3458 if (sdata->vif.probe_req_reg)
3459 sdata->vif.probe_req_reg--;
3462 if (!local->open_count)
3465 if (sdata->vif.probe_req_reg == 1)
3466 drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
3468 else if (sdata->vif.probe_req_reg == 0)
3469 drv_config_iface_filter(local, sdata, 0,
3472 ieee80211_configure_filter(local);
3479 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3481 struct ieee80211_local *local = wiphy_priv(wiphy);
3486 return drv_set_antenna(local, tx_ant, rx_ant);
3489 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3491 struct ieee80211_local *local = wiphy_priv(wiphy);
3493 return drv_get_antenna(local, tx_ant, rx_ant);
3496 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3497 struct net_device *dev,
3498 struct cfg80211_gtk_rekey_data *data)
3500 struct ieee80211_local *local = wiphy_priv(wiphy);
3501 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3503 if (!local->ops->set_rekey_data)
3506 drv_set_rekey_data(local, sdata, data);
3511 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3512 const u8 *peer, u64 *cookie)
3514 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3515 struct ieee80211_local *local = sdata->local;
3516 struct ieee80211_qos_hdr *nullfunc;
3517 struct sk_buff *skb;
3518 int size = sizeof(*nullfunc);
3521 struct ieee80211_tx_info *info;
3522 struct sta_info *sta;
3523 struct ieee80211_chanctx_conf *chanctx_conf;
3524 enum nl80211_band band;
3527 /* the lock is needed to assign the cookie later */
3528 mutex_lock(&local->mtx);
3531 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3532 if (WARN_ON(!chanctx_conf)) {
3536 band = chanctx_conf->def.chan->band;
3537 sta = sta_info_get_bss(sdata, peer);
3546 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3547 IEEE80211_STYPE_QOS_NULLFUNC |
3548 IEEE80211_FCTL_FROMDS);
3551 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3552 IEEE80211_STYPE_NULLFUNC |
3553 IEEE80211_FCTL_FROMDS);
3556 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3564 skb_reserve(skb, local->hw.extra_tx_headroom);
3566 nullfunc = skb_put(skb, size);
3567 nullfunc->frame_control = fc;
3568 nullfunc->duration_id = 0;
3569 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3570 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3571 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3572 nullfunc->seq_ctrl = 0;
3574 info = IEEE80211_SKB_CB(skb);
3576 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3577 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3580 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3583 nullfunc->qos_ctrl = cpu_to_le16(7);
3585 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3592 ieee80211_xmit(sdata, sta, skb, 0);
3598 mutex_unlock(&local->mtx);
3603 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3604 struct wireless_dev *wdev,
3605 struct cfg80211_chan_def *chandef)
3607 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3608 struct ieee80211_local *local = wiphy_priv(wiphy);
3609 struct ieee80211_chanctx_conf *chanctx_conf;
3613 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3615 *chandef = sdata->vif.bss_conf.chandef;
3617 } else if (local->open_count > 0 &&
3618 local->open_count == local->monitors &&
3619 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3620 if (local->use_chanctx)
3621 *chandef = local->monitor_chandef;
3623 *chandef = local->_oper_chandef;
3632 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3634 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3638 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3639 struct net_device *dev,
3640 struct cfg80211_qos_map *qos_map)
3642 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3643 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3646 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3649 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3651 /* A NULL qos_map was passed to disable QoS mapping */
3655 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3656 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3658 kfree_rcu(old_qos_map, rcu_head);
3663 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3664 struct net_device *dev,
3665 struct cfg80211_chan_def *chandef)
3667 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3671 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3673 ieee80211_bss_info_change_notify(sdata, changed);
3678 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3679 u8 tsid, const u8 *peer, u8 up,
3682 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3683 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3684 int ac = ieee802_1d_to_ac[up];
3686 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3689 if (!(sdata->wmm_acm & BIT(up)))
3692 if (ifmgd->tx_tspec[ac].admitted_time)
3695 if (admitted_time) {
3696 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3697 ifmgd->tx_tspec[ac].tsid = tsid;
3698 ifmgd->tx_tspec[ac].up = up;
3704 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3705 u8 tsid, const u8 *peer)
3707 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3708 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3709 struct ieee80211_local *local = wiphy_priv(wiphy);
3712 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3713 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3715 /* skip unused entries */
3716 if (!tx_tspec->admitted_time)
3719 if (tx_tspec->tsid != tsid)
3722 /* due to this new packets will be reassigned to non-ACM ACs */
3725 /* Make sure that all packets have been sent to avoid to
3726 * restore the QoS params on packets that are still on the
3730 ieee80211_flush_queues(local, sdata, false);
3732 /* restore the normal QoS parameters
3733 * (unconditionally to avoid races)
3735 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3736 tx_tspec->downgraded = false;
3737 ieee80211_sta_handle_tspec_ac_params(sdata);
3739 /* finally clear all the data */
3740 memset(tx_tspec, 0, sizeof(*tx_tspec));
3748 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
3750 enum nl80211_nan_func_term_reason reason,
3753 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3754 struct cfg80211_nan_func *func;
3757 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3760 spin_lock_bh(&sdata->u.nan.func_lock);
3762 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
3763 if (WARN_ON(!func)) {
3764 spin_unlock_bh(&sdata->u.nan.func_lock);
3768 cookie = func->cookie;
3769 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
3771 spin_unlock_bh(&sdata->u.nan.func_lock);
3773 cfg80211_free_nan_func(func);
3775 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
3776 reason, cookie, gfp);
3778 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
3780 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
3781 struct cfg80211_nan_match_params *match,
3784 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3785 struct cfg80211_nan_func *func;
3787 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3790 spin_lock_bh(&sdata->u.nan.func_lock);
3792 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
3793 if (WARN_ON(!func)) {
3794 spin_unlock_bh(&sdata->u.nan.func_lock);
3797 match->cookie = func->cookie;
3799 spin_unlock_bh(&sdata->u.nan.func_lock);
3801 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
3803 EXPORT_SYMBOL(ieee80211_nan_func_match);
3805 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
3806 struct net_device *dev,
3809 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3811 sdata->u.ap.multicast_to_unicast = enabled;
3816 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
3817 struct txq_info *txqi)
3819 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
3820 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
3821 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
3824 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
3825 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
3826 txqstats->backlog_packets = txqi->tin.backlog_packets;
3829 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
3830 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
3831 txqstats->flows = txqi->tin.flows;
3834 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
3835 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
3836 txqstats->drops = txqi->cstats.drop_count;
3839 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
3840 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
3841 txqstats->ecn_marks = txqi->cstats.ecn_mark;
3844 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
3845 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
3846 txqstats->overlimit = txqi->tin.overlimit;
3849 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
3850 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
3851 txqstats->collisions = txqi->tin.collisions;
3854 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
3855 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
3856 txqstats->tx_bytes = txqi->tin.tx_bytes;
3859 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
3860 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
3861 txqstats->tx_packets = txqi->tin.tx_packets;
3865 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
3866 struct wireless_dev *wdev,
3867 struct cfg80211_txq_stats *txqstats)
3869 struct ieee80211_local *local = wiphy_priv(wiphy);
3870 struct ieee80211_sub_if_data *sdata;
3873 if (!local->ops->wake_tx_queue)
3876 spin_lock_bh(&local->fq.lock);
3880 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3881 if (!sdata->vif.txq) {
3885 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
3888 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
3889 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
3890 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
3891 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
3892 BIT(NL80211_TXQ_STATS_COLLISIONS) |
3893 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
3894 txqstats->backlog_packets = local->fq.backlog;
3895 txqstats->backlog_bytes = local->fq.memory_usage;
3896 txqstats->overlimit = local->fq.overlimit;
3897 txqstats->overmemory = local->fq.overmemory;
3898 txqstats->collisions = local->fq.collisions;
3899 txqstats->max_flows = local->fq.flows_cnt;
3904 spin_unlock_bh(&local->fq.lock);
3910 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
3911 struct net_device *dev,
3912 struct cfg80211_ftm_responder_stats *ftm_stats)
3914 struct ieee80211_local *local = wiphy_priv(wiphy);
3915 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3917 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
3921 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
3922 struct cfg80211_pmsr_request *request)
3924 struct ieee80211_local *local = wiphy_priv(wiphy);
3925 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
3927 return drv_start_pmsr(local, sdata, request);
3931 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
3932 struct cfg80211_pmsr_request *request)
3934 struct ieee80211_local *local = wiphy_priv(wiphy);
3935 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
3937 return drv_abort_pmsr(local, sdata, request);
3940 const struct cfg80211_ops mac80211_config_ops = {
3941 .add_virtual_intf = ieee80211_add_iface,
3942 .del_virtual_intf = ieee80211_del_iface,
3943 .change_virtual_intf = ieee80211_change_iface,
3944 .start_p2p_device = ieee80211_start_p2p_device,
3945 .stop_p2p_device = ieee80211_stop_p2p_device,
3946 .add_key = ieee80211_add_key,
3947 .del_key = ieee80211_del_key,
3948 .get_key = ieee80211_get_key,
3949 .set_default_key = ieee80211_config_default_key,
3950 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3951 .start_ap = ieee80211_start_ap,
3952 .change_beacon = ieee80211_change_beacon,
3953 .stop_ap = ieee80211_stop_ap,
3954 .add_station = ieee80211_add_station,
3955 .del_station = ieee80211_del_station,
3956 .change_station = ieee80211_change_station,
3957 .get_station = ieee80211_get_station,
3958 .dump_station = ieee80211_dump_station,
3959 .dump_survey = ieee80211_dump_survey,
3960 #ifdef CONFIG_MAC80211_MESH
3961 .add_mpath = ieee80211_add_mpath,
3962 .del_mpath = ieee80211_del_mpath,
3963 .change_mpath = ieee80211_change_mpath,
3964 .get_mpath = ieee80211_get_mpath,
3965 .dump_mpath = ieee80211_dump_mpath,
3966 .get_mpp = ieee80211_get_mpp,
3967 .dump_mpp = ieee80211_dump_mpp,
3968 .update_mesh_config = ieee80211_update_mesh_config,
3969 .get_mesh_config = ieee80211_get_mesh_config,
3970 .join_mesh = ieee80211_join_mesh,
3971 .leave_mesh = ieee80211_leave_mesh,
3973 .join_ocb = ieee80211_join_ocb,
3974 .leave_ocb = ieee80211_leave_ocb,
3975 .change_bss = ieee80211_change_bss,
3976 .set_txq_params = ieee80211_set_txq_params,
3977 .set_monitor_channel = ieee80211_set_monitor_channel,
3978 .suspend = ieee80211_suspend,
3979 .resume = ieee80211_resume,
3980 .scan = ieee80211_scan,
3981 .abort_scan = ieee80211_abort_scan,
3982 .sched_scan_start = ieee80211_sched_scan_start,
3983 .sched_scan_stop = ieee80211_sched_scan_stop,
3984 .auth = ieee80211_auth,
3985 .assoc = ieee80211_assoc,
3986 .deauth = ieee80211_deauth,
3987 .disassoc = ieee80211_disassoc,
3988 .join_ibss = ieee80211_join_ibss,
3989 .leave_ibss = ieee80211_leave_ibss,
3990 .set_mcast_rate = ieee80211_set_mcast_rate,
3991 .set_wiphy_params = ieee80211_set_wiphy_params,
3992 .set_tx_power = ieee80211_set_tx_power,
3993 .get_tx_power = ieee80211_get_tx_power,
3994 .set_wds_peer = ieee80211_set_wds_peer,
3995 .rfkill_poll = ieee80211_rfkill_poll,
3996 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3997 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3998 .set_power_mgmt = ieee80211_set_power_mgmt,
3999 .set_bitrate_mask = ieee80211_set_bitrate_mask,
4000 .remain_on_channel = ieee80211_remain_on_channel,
4001 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4002 .mgmt_tx = ieee80211_mgmt_tx,
4003 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4004 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4005 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4006 .mgmt_frame_register = ieee80211_mgmt_frame_register,
4007 .set_antenna = ieee80211_set_antenna,
4008 .get_antenna = ieee80211_get_antenna,
4009 .set_rekey_data = ieee80211_set_rekey_data,
4010 .tdls_oper = ieee80211_tdls_oper,
4011 .tdls_mgmt = ieee80211_tdls_mgmt,
4012 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4013 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4014 .probe_client = ieee80211_probe_client,
4015 .set_noack_map = ieee80211_set_noack_map,
4017 .set_wakeup = ieee80211_set_wakeup,
4019 .get_channel = ieee80211_cfg_get_channel,
4020 .start_radar_detection = ieee80211_start_radar_detection,
4021 .channel_switch = ieee80211_channel_switch,
4022 .set_qos_map = ieee80211_set_qos_map,
4023 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4024 .add_tx_ts = ieee80211_add_tx_ts,
4025 .del_tx_ts = ieee80211_del_tx_ts,
4026 .start_nan = ieee80211_start_nan,
4027 .stop_nan = ieee80211_stop_nan,
4028 .nan_change_conf = ieee80211_nan_change_conf,
4029 .add_nan_func = ieee80211_add_nan_func,
4030 .del_nan_func = ieee80211_del_nan_func,
4031 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4032 .tx_control_port = ieee80211_tx_control_port,
4033 .get_txq_stats = ieee80211_get_txq_stats,
4034 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4035 .start_pmsr = ieee80211_start_pmsr,
4036 .abort_pmsr = ieee80211_abort_pmsr,
4037 .probe_mesh_link = ieee80211_probe_mesh_link,