2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * This file is GPLv2 as found in COPYING.
10 #include <linux/ieee80211.h>
11 #include <linux/nl80211.h>
12 #include <linux/rtnetlink.h>
13 #include <linux/slab.h>
14 #include <net/net_namespace.h>
15 #include <linux/rcupdate.h>
16 #include <linux/if_ether.h>
17 #include <net/cfg80211.h>
18 #include "ieee80211_i.h"
19 #include "driver-ops.h"
24 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
26 enum nl80211_iftype type,
28 struct vif_params *params)
30 struct ieee80211_local *local = wiphy_priv(wiphy);
31 struct wireless_dev *wdev;
32 struct ieee80211_sub_if_data *sdata;
35 err = ieee80211_if_add(local, name, &wdev, type, params);
39 if (type == NL80211_IFTYPE_MONITOR && flags) {
40 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
41 sdata->u.mntr_flags = *flags;
47 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
49 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
54 static int ieee80211_change_iface(struct wiphy *wiphy,
55 struct net_device *dev,
56 enum nl80211_iftype type, u32 *flags,
57 struct vif_params *params)
59 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
62 ret = ieee80211_if_change_type(sdata, type);
66 if (type == NL80211_IFTYPE_AP_VLAN &&
67 params && params->use_4addr == 0)
68 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
69 else if (type == NL80211_IFTYPE_STATION &&
70 params && params->use_4addr >= 0)
71 sdata->u.mgd.use_4addr = params->use_4addr;
73 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
74 struct ieee80211_local *local = sdata->local;
76 if (ieee80211_sdata_running(sdata)) {
77 u32 mask = MONITOR_FLAG_COOK_FRAMES |
81 * Prohibit MONITOR_FLAG_COOK_FRAMES and
82 * MONITOR_FLAG_ACTIVE to be changed while the
84 * Else we would need to add a lot of cruft
85 * to update everything:
86 * cooked_mntrs, monitor and all fif_* counters
87 * reconfigure hardware
89 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
92 ieee80211_adjust_monitor_flags(sdata, -1);
93 sdata->u.mntr_flags = *flags;
94 ieee80211_adjust_monitor_flags(sdata, 1);
96 ieee80211_configure_filter(local);
99 * Because the interface is down, ieee80211_do_stop
100 * and ieee80211_do_open take care of "everything"
101 * mentioned in the comment above.
103 sdata->u.mntr_flags = *flags;
110 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
111 struct wireless_dev *wdev)
113 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
116 mutex_lock(&sdata->local->chanctx_mtx);
117 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
118 mutex_unlock(&sdata->local->chanctx_mtx);
122 return ieee80211_do_open(wdev, true);
125 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
126 struct wireless_dev *wdev)
128 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
131 static int ieee80211_set_noack_map(struct wiphy *wiphy,
132 struct net_device *dev,
135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
137 sdata->noack_map = noack_map;
141 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
142 u8 key_idx, bool pairwise, const u8 *mac_addr,
143 struct key_params *params)
145 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
146 struct ieee80211_local *local = sdata->local;
147 struct sta_info *sta = NULL;
148 const struct ieee80211_cipher_scheme *cs = NULL;
149 struct ieee80211_key *key;
152 if (!ieee80211_sdata_running(sdata))
155 /* reject WEP and TKIP keys if WEP failed to initialize */
156 switch (params->cipher) {
157 case WLAN_CIPHER_SUITE_WEP40:
158 case WLAN_CIPHER_SUITE_TKIP:
159 case WLAN_CIPHER_SUITE_WEP104:
160 if (IS_ERR(local->wep_tx_tfm))
163 case WLAN_CIPHER_SUITE_CCMP:
164 case WLAN_CIPHER_SUITE_AES_CMAC:
165 case WLAN_CIPHER_SUITE_GCMP:
168 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
172 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
173 params->key, params->seq_len, params->seq,
179 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
181 mutex_lock(&local->sta_mtx);
184 if (ieee80211_vif_is_mesh(&sdata->vif))
185 sta = sta_info_get(sdata, mac_addr);
187 sta = sta_info_get_bss(sdata, mac_addr);
189 * The ASSOC test makes sure the driver is ready to
190 * receive the key. When wpa_supplicant has roamed
191 * using FT, it attempts to set the key before
192 * association has completed, this rejects that attempt
193 * so it will set the key again after assocation.
195 * TODO: accept the key if we have a station entry and
196 * add it to the device after the station.
198 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
199 ieee80211_key_free_unused(key);
205 switch (sdata->vif.type) {
206 case NL80211_IFTYPE_STATION:
207 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
208 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
210 case NL80211_IFTYPE_AP:
211 case NL80211_IFTYPE_AP_VLAN:
212 /* Keys without a station are used for TX only */
213 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
214 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
216 case NL80211_IFTYPE_ADHOC:
219 case NL80211_IFTYPE_MESH_POINT:
220 #ifdef CONFIG_MAC80211_MESH
221 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
222 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
225 case NL80211_IFTYPE_WDS:
226 case NL80211_IFTYPE_MONITOR:
227 case NL80211_IFTYPE_P2P_DEVICE:
228 case NL80211_IFTYPE_UNSPECIFIED:
229 case NUM_NL80211_IFTYPES:
230 case NL80211_IFTYPE_P2P_CLIENT:
231 case NL80211_IFTYPE_P2P_GO:
232 /* shouldn't happen */
238 sta->cipher_scheme = cs;
240 err = ieee80211_key_link(key, sdata, sta);
243 mutex_unlock(&local->sta_mtx);
248 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
249 u8 key_idx, bool pairwise, const u8 *mac_addr)
251 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
252 struct ieee80211_local *local = sdata->local;
253 struct sta_info *sta;
254 struct ieee80211_key *key = NULL;
257 mutex_lock(&local->sta_mtx);
258 mutex_lock(&local->key_mtx);
263 sta = sta_info_get_bss(sdata, mac_addr);
268 key = key_mtx_dereference(local, sta->ptk[key_idx]);
270 key = key_mtx_dereference(local, sta->gtk[key_idx]);
272 key = key_mtx_dereference(local, sdata->keys[key_idx]);
279 ieee80211_key_free(key, true);
283 mutex_unlock(&local->key_mtx);
284 mutex_unlock(&local->sta_mtx);
289 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
290 u8 key_idx, bool pairwise, const u8 *mac_addr,
292 void (*callback)(void *cookie,
293 struct key_params *params))
295 struct ieee80211_sub_if_data *sdata;
296 struct sta_info *sta = NULL;
298 struct key_params params;
299 struct ieee80211_key *key = NULL;
305 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
310 sta = sta_info_get_bss(sdata, mac_addr);
314 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
315 key = rcu_dereference(sta->ptk[key_idx]);
316 else if (!pairwise &&
317 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
318 key = rcu_dereference(sta->gtk[key_idx]);
320 key = rcu_dereference(sdata->keys[key_idx]);
325 memset(¶ms, 0, sizeof(params));
327 params.cipher = key->conf.cipher;
329 switch (key->conf.cipher) {
330 case WLAN_CIPHER_SUITE_TKIP:
331 iv32 = key->u.tkip.tx.iv32;
332 iv16 = key->u.tkip.tx.iv16;
334 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
335 drv_get_tkip_seq(sdata->local,
336 key->conf.hw_key_idx,
339 seq[0] = iv16 & 0xff;
340 seq[1] = (iv16 >> 8) & 0xff;
341 seq[2] = iv32 & 0xff;
342 seq[3] = (iv32 >> 8) & 0xff;
343 seq[4] = (iv32 >> 16) & 0xff;
344 seq[5] = (iv32 >> 24) & 0xff;
348 case WLAN_CIPHER_SUITE_CCMP:
349 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
359 case WLAN_CIPHER_SUITE_AES_CMAC:
360 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
372 params.key = key->conf.key;
373 params.key_len = key->conf.keylen;
375 callback(cookie, ¶ms);
383 static int ieee80211_config_default_key(struct wiphy *wiphy,
384 struct net_device *dev,
385 u8 key_idx, bool uni,
388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
390 ieee80211_set_default_key(sdata, key_idx, uni, multi);
395 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
396 struct net_device *dev,
399 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
401 ieee80211_set_default_mgmt_key(sdata, key_idx);
406 void sta_set_rate_info_tx(struct sta_info *sta,
407 const struct ieee80211_tx_rate *rate,
408 struct rate_info *rinfo)
411 if (rate->flags & IEEE80211_TX_RC_MCS) {
412 rinfo->flags |= RATE_INFO_FLAGS_MCS;
413 rinfo->mcs = rate->idx;
414 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
415 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
416 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
417 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
419 struct ieee80211_supported_band *sband;
420 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
423 sband = sta->local->hw.wiphy->bands[
424 ieee80211_get_sdata_band(sta->sdata)];
425 brate = sband->bitrates[rate->idx].bitrate;
426 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
428 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
429 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
430 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
431 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
432 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
433 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
434 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
435 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
438 void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
442 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
443 rinfo->flags |= RATE_INFO_FLAGS_MCS;
444 rinfo->mcs = sta->last_rx_rate_idx;
445 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
446 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
447 rinfo->nss = sta->last_rx_rate_vht_nss;
448 rinfo->mcs = sta->last_rx_rate_idx;
450 struct ieee80211_supported_band *sband;
451 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
454 sband = sta->local->hw.wiphy->bands[
455 ieee80211_get_sdata_band(sta->sdata)];
456 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
457 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
460 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
461 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
462 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
463 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
464 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
465 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
466 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80P80MHZ)
467 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
468 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
469 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
472 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
473 int idx, u8 *mac, struct station_info *sinfo)
475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
476 struct ieee80211_local *local = sdata->local;
477 struct sta_info *sta;
480 mutex_lock(&local->sta_mtx);
482 sta = sta_info_get_by_idx(sdata, idx);
485 memcpy(mac, sta->sta.addr, ETH_ALEN);
486 sta_set_sinfo(sta, sinfo);
489 mutex_unlock(&local->sta_mtx);
494 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
495 int idx, struct survey_info *survey)
497 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
499 return drv_get_survey(local, idx, survey);
502 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
503 const u8 *mac, struct station_info *sinfo)
505 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
506 struct ieee80211_local *local = sdata->local;
507 struct sta_info *sta;
510 mutex_lock(&local->sta_mtx);
512 sta = sta_info_get_bss(sdata, mac);
515 sta_set_sinfo(sta, sinfo);
518 mutex_unlock(&local->sta_mtx);
523 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
524 struct cfg80211_chan_def *chandef)
526 struct ieee80211_local *local = wiphy_priv(wiphy);
527 struct ieee80211_sub_if_data *sdata;
530 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
533 mutex_lock(&local->mtx);
534 mutex_lock(&local->iflist_mtx);
535 if (local->use_chanctx) {
536 sdata = rcu_dereference_protected(
537 local->monitor_sdata,
538 lockdep_is_held(&local->iflist_mtx));
540 ieee80211_vif_release_channel(sdata);
541 ret = ieee80211_vif_use_channel(sdata, chandef,
542 IEEE80211_CHANCTX_EXCLUSIVE);
544 } else if (local->open_count == local->monitors) {
545 local->_oper_chandef = *chandef;
546 ieee80211_hw_config(local, 0);
550 local->monitor_chandef = *chandef;
551 mutex_unlock(&local->iflist_mtx);
552 mutex_unlock(&local->mtx);
557 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
558 const u8 *resp, size_t resp_len,
559 const struct ieee80211_csa_settings *csa)
561 struct probe_resp *new, *old;
563 if (!resp || !resp_len)
566 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
568 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
573 memcpy(new->data, resp, resp_len);
576 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
577 csa->n_counter_offsets_presp *
578 sizeof(new->csa_counter_offsets[0]));
580 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
582 kfree_rcu(old, rcu_head);
587 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
588 struct cfg80211_beacon_data *params,
589 const struct ieee80211_csa_settings *csa)
591 struct beacon_data *new, *old;
592 int new_head_len, new_tail_len;
594 u32 changed = BSS_CHANGED_BEACON;
596 old = sdata_dereference(sdata->u.ap.beacon, sdata);
599 /* Need to have a beacon head if we don't have one yet */
600 if (!params->head && !old)
603 /* new or old head? */
605 new_head_len = params->head_len;
607 new_head_len = old->head_len;
609 /* new or old tail? */
610 if (params->tail || !old)
611 /* params->tail_len will be zero for !params->tail */
612 new_tail_len = params->tail_len;
614 new_tail_len = old->tail_len;
616 size = sizeof(*new) + new_head_len + new_tail_len;
618 new = kzalloc(size, GFP_KERNEL);
622 /* start filling the new info now */
625 * pointers go into the block we allocated,
626 * memory is | beacon_data | head | tail |
628 new->head = ((u8 *) new) + sizeof(*new);
629 new->tail = new->head + new_head_len;
630 new->head_len = new_head_len;
631 new->tail_len = new_tail_len;
634 new->csa_current_counter = csa->count;
635 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
636 csa->n_counter_offsets_beacon *
637 sizeof(new->csa_counter_offsets[0]));
642 memcpy(new->head, params->head, new_head_len);
644 memcpy(new->head, old->head, new_head_len);
646 /* copy in optional tail */
648 memcpy(new->tail, params->tail, new_tail_len);
651 memcpy(new->tail, old->tail, new_tail_len);
653 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
654 params->probe_resp_len, csa);
658 changed |= BSS_CHANGED_AP_PROBE_RESP;
660 rcu_assign_pointer(sdata->u.ap.beacon, new);
663 kfree_rcu(old, rcu_head);
668 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
669 struct cfg80211_ap_settings *params)
671 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
672 struct ieee80211_local *local = sdata->local;
673 struct beacon_data *old;
674 struct ieee80211_sub_if_data *vlan;
675 u32 changed = BSS_CHANGED_BEACON_INT |
676 BSS_CHANGED_BEACON_ENABLED |
682 old = sdata_dereference(sdata->u.ap.beacon, sdata);
686 /* TODO: make hostapd tell us what it wants */
687 sdata->smps_mode = IEEE80211_SMPS_OFF;
688 sdata->needed_rx_chains = sdata->local->rx_chains;
690 mutex_lock(&local->mtx);
691 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
692 IEEE80211_CHANCTX_SHARED);
694 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
695 mutex_unlock(&local->mtx);
700 * Apply control port protocol, this allows us to
701 * not encrypt dynamic WEP control frames.
703 sdata->control_port_protocol = params->crypto.control_port_ethertype;
704 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
705 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
709 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
710 vlan->control_port_protocol =
711 params->crypto.control_port_ethertype;
712 vlan->control_port_no_encrypt =
713 params->crypto.control_port_no_encrypt;
714 vlan->encrypt_headroom =
715 ieee80211_cs_headroom(sdata->local,
720 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
721 sdata->vif.bss_conf.dtim_period = params->dtim_period;
722 sdata->vif.bss_conf.enable_beacon = true;
724 sdata->vif.bss_conf.ssid_len = params->ssid_len;
725 if (params->ssid_len)
726 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
728 sdata->vif.bss_conf.hidden_ssid =
729 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
731 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
732 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
733 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
734 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
735 if (params->p2p_opp_ps)
736 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
737 IEEE80211_P2P_OPPPS_ENABLE_BIT;
739 err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL);
741 ieee80211_vif_release_channel(sdata);
746 err = drv_start_ap(sdata->local, sdata);
748 old = sdata_dereference(sdata->u.ap.beacon, sdata);
751 kfree_rcu(old, rcu_head);
752 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
753 ieee80211_vif_release_channel(sdata);
757 ieee80211_recalc_dtim(local, sdata);
758 ieee80211_bss_info_change_notify(sdata, changed);
760 netif_carrier_on(dev);
761 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
762 netif_carrier_on(vlan->dev);
767 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
768 struct cfg80211_beacon_data *params)
770 struct ieee80211_sub_if_data *sdata;
771 struct beacon_data *old;
774 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
775 sdata_assert_lock(sdata);
777 /* don't allow changing the beacon while CSA is in place - offset
778 * of channel switch counter may change
780 if (sdata->vif.csa_active)
783 old = sdata_dereference(sdata->u.ap.beacon, sdata);
787 err = ieee80211_assign_beacon(sdata, params, NULL);
790 ieee80211_bss_info_change_notify(sdata, err);
794 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
796 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
797 struct ieee80211_sub_if_data *vlan;
798 struct ieee80211_local *local = sdata->local;
799 struct beacon_data *old_beacon;
800 struct probe_resp *old_probe_resp;
801 struct cfg80211_chan_def chandef;
803 sdata_assert_lock(sdata);
805 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
808 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
810 /* abort any running channel switch */
811 mutex_lock(&local->mtx);
812 sdata->vif.csa_active = false;
813 if (sdata->csa_block_tx) {
814 ieee80211_wake_vif_queues(local, sdata,
815 IEEE80211_QUEUE_STOP_REASON_CSA);
816 sdata->csa_block_tx = false;
819 mutex_unlock(&local->mtx);
821 kfree(sdata->u.ap.next_beacon);
822 sdata->u.ap.next_beacon = NULL;
824 /* turn off carrier for this interface and dependent VLANs */
825 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
826 netif_carrier_off(vlan->dev);
827 netif_carrier_off(dev);
829 /* remove beacon and probe response */
830 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
831 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
832 kfree_rcu(old_beacon, rcu_head);
834 kfree_rcu(old_probe_resp, rcu_head);
835 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
837 __sta_info_flush(sdata, true);
838 ieee80211_free_keys(sdata, true);
840 sdata->vif.bss_conf.enable_beacon = false;
841 sdata->vif.bss_conf.ssid_len = 0;
842 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
843 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
845 if (sdata->wdev.cac_started) {
846 chandef = sdata->vif.bss_conf.chandef;
847 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
848 cfg80211_cac_event(sdata->dev, &chandef,
849 NL80211_RADAR_CAC_ABORTED,
853 drv_stop_ap(sdata->local, sdata);
855 /* free all potentially still buffered bcast frames */
856 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
857 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
859 mutex_lock(&local->mtx);
860 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
861 ieee80211_vif_release_channel(sdata);
862 mutex_unlock(&local->mtx);
867 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
868 struct iapp_layer2_update {
869 u8 da[ETH_ALEN]; /* broadcast */
870 u8 sa[ETH_ALEN]; /* STA addr */
878 static void ieee80211_send_layer2_update(struct sta_info *sta)
880 struct iapp_layer2_update *msg;
883 /* Send Level 2 Update Frame to update forwarding tables in layer 2
886 skb = dev_alloc_skb(sizeof(*msg));
889 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
891 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
892 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
894 eth_broadcast_addr(msg->da);
895 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
898 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
899 msg->control = 0xaf; /* XID response lsb.1111F101.
900 * F=0 (no poll command; unsolicited frame) */
901 msg->xid_info[0] = 0x81; /* XID format identifier */
902 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
903 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
905 skb->dev = sta->sdata->dev;
906 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
907 memset(skb->cb, 0, sizeof(skb->cb));
911 static int sta_apply_auth_flags(struct ieee80211_local *local,
912 struct sta_info *sta,
917 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
918 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
919 !test_sta_flag(sta, WLAN_STA_AUTH)) {
920 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
925 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
926 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
927 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
928 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
933 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
934 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
935 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
936 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
937 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
944 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
945 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
946 test_sta_flag(sta, WLAN_STA_ASSOC)) {
947 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
952 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
953 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
954 test_sta_flag(sta, WLAN_STA_AUTH)) {
955 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
963 static int sta_apply_parameters(struct ieee80211_local *local,
964 struct sta_info *sta,
965 struct station_parameters *params)
968 struct ieee80211_supported_band *sband;
969 struct ieee80211_sub_if_data *sdata = sta->sdata;
970 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
973 sband = local->hw.wiphy->bands[band];
975 mask = params->sta_flags_mask;
976 set = params->sta_flags_set;
978 if (ieee80211_vif_is_mesh(&sdata->vif)) {
980 * In mesh mode, ASSOCIATED isn't part of the nl80211
981 * API but must follow AUTHENTICATED for driver state.
983 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
984 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
985 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
986 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
987 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
989 * TDLS -- everything follows authorized, but
990 * only becoming authorized is possible, not
993 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
994 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
995 BIT(NL80211_STA_FLAG_ASSOCIATED);
996 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
997 BIT(NL80211_STA_FLAG_ASSOCIATED);
1001 /* auth flags will be set later for TDLS stations */
1002 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1003 ret = sta_apply_auth_flags(local, sta, mask, set);
1008 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1009 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1010 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1012 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1015 if (mask & BIT(NL80211_STA_FLAG_WME))
1016 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1018 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1019 if (set & BIT(NL80211_STA_FLAG_MFP))
1020 set_sta_flag(sta, WLAN_STA_MFP);
1022 clear_sta_flag(sta, WLAN_STA_MFP);
1025 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1026 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1027 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1029 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1032 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1033 sta->sta.uapsd_queues = params->uapsd_queues;
1034 sta->sta.max_sp = params->max_sp;
1038 * cfg80211 validates this (1-2007) and allows setting the AID
1039 * only when creating a new station entry
1042 sta->sta.aid = params->aid;
1045 * Some of the following updates would be racy if called on an
1046 * existing station, via ieee80211_change_station(). However,
1047 * all such changes are rejected by cfg80211 except for updates
1048 * changing the supported rates on an existing but not yet used
1052 if (params->listen_interval >= 0)
1053 sta->listen_interval = params->listen_interval;
1055 if (params->supported_rates) {
1056 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1057 sband, params->supported_rates,
1058 params->supported_rates_len,
1059 &sta->sta.supp_rates[band]);
1062 if (params->ht_capa)
1063 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1064 params->ht_capa, sta);
1066 if (params->vht_capa)
1067 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1068 params->vht_capa, sta);
1070 if (params->opmode_notif_used) {
1071 /* returned value is only needed for rc update, but the
1072 * rc isn't initialized here yet, so ignore it
1074 __ieee80211_vht_handle_opmode(sdata, sta,
1075 params->opmode_notif,
1079 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1080 #ifdef CONFIG_MAC80211_MESH
1083 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1084 switch (params->plink_state) {
1085 case NL80211_PLINK_ESTAB:
1086 if (sta->plink_state != NL80211_PLINK_ESTAB)
1087 changed = mesh_plink_inc_estab_count(
1089 sta->plink_state = params->plink_state;
1091 ieee80211_mps_sta_status_update(sta);
1092 changed |= ieee80211_mps_set_sta_local_pm(sta,
1093 sdata->u.mesh.mshcfg.power_mode);
1095 case NL80211_PLINK_LISTEN:
1096 case NL80211_PLINK_BLOCKED:
1097 case NL80211_PLINK_OPN_SNT:
1098 case NL80211_PLINK_OPN_RCVD:
1099 case NL80211_PLINK_CNF_RCVD:
1100 case NL80211_PLINK_HOLDING:
1101 if (sta->plink_state == NL80211_PLINK_ESTAB)
1102 changed = mesh_plink_dec_estab_count(
1104 sta->plink_state = params->plink_state;
1106 ieee80211_mps_sta_status_update(sta);
1107 changed |= ieee80211_mps_set_sta_local_pm(sta,
1108 NL80211_MESH_POWER_UNKNOWN);
1116 switch (params->plink_action) {
1117 case NL80211_PLINK_ACTION_NO_ACTION:
1120 case NL80211_PLINK_ACTION_OPEN:
1121 changed |= mesh_plink_open(sta);
1123 case NL80211_PLINK_ACTION_BLOCK:
1124 changed |= mesh_plink_block(sta);
1128 if (params->local_pm)
1130 ieee80211_mps_set_sta_local_pm(sta,
1132 ieee80211_mbss_info_change_notify(sdata, changed);
1136 /* set the STA state after all sta info from usermode has been set */
1137 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1138 ret = sta_apply_auth_flags(local, sta, mask, set);
1146 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1148 struct station_parameters *params)
1150 struct ieee80211_local *local = wiphy_priv(wiphy);
1151 struct sta_info *sta;
1152 struct ieee80211_sub_if_data *sdata;
1157 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1159 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1160 sdata->vif.type != NL80211_IFTYPE_AP)
1163 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1165 if (ether_addr_equal(mac, sdata->vif.addr))
1168 if (is_multicast_ether_addr(mac))
1171 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1176 * defaults -- if userspace wants something else we'll
1177 * change it accordingly in sta_apply_parameters()
1179 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1180 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1181 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1183 sta->sta.tdls = true;
1186 err = sta_apply_parameters(local, sta, params);
1188 sta_info_free(local, sta);
1193 * for TDLS, rate control should be initialized only when
1194 * rates are known and station is marked authorized
1196 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1197 rate_control_rate_init(sta);
1199 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1200 sdata->vif.type == NL80211_IFTYPE_AP;
1202 err = sta_info_insert_rcu(sta);
1209 ieee80211_send_layer2_update(sta);
1216 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1219 struct ieee80211_sub_if_data *sdata;
1221 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1224 return sta_info_destroy_addr_bss(sdata, mac);
1226 sta_info_flush(sdata);
1230 static int ieee80211_change_station(struct wiphy *wiphy,
1231 struct net_device *dev, const u8 *mac,
1232 struct station_parameters *params)
1234 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1235 struct ieee80211_local *local = wiphy_priv(wiphy);
1236 struct sta_info *sta;
1237 struct ieee80211_sub_if_data *vlansdata;
1238 enum cfg80211_station_type statype;
1241 mutex_lock(&local->sta_mtx);
1243 sta = sta_info_get_bss(sdata, mac);
1249 switch (sdata->vif.type) {
1250 case NL80211_IFTYPE_MESH_POINT:
1251 if (sdata->u.mesh.user_mpm)
1252 statype = CFG80211_STA_MESH_PEER_USER;
1254 statype = CFG80211_STA_MESH_PEER_KERNEL;
1256 case NL80211_IFTYPE_ADHOC:
1257 statype = CFG80211_STA_IBSS;
1259 case NL80211_IFTYPE_STATION:
1260 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1261 statype = CFG80211_STA_AP_STA;
1264 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1265 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1267 statype = CFG80211_STA_TDLS_PEER_SETUP;
1269 case NL80211_IFTYPE_AP:
1270 case NL80211_IFTYPE_AP_VLAN:
1271 statype = CFG80211_STA_AP_CLIENT;
1278 err = cfg80211_check_station_change(wiphy, params, statype);
1282 if (params->vlan && params->vlan != sta->sdata->dev) {
1283 bool prev_4addr = false;
1284 bool new_4addr = false;
1286 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1288 if (params->vlan->ieee80211_ptr->use_4addr) {
1289 if (vlansdata->u.vlan.sta) {
1294 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1298 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1299 sta->sdata->u.vlan.sta) {
1300 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1304 sta->sdata = vlansdata;
1306 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1307 prev_4addr != new_4addr) {
1309 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1311 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1314 ieee80211_send_layer2_update(sta);
1317 err = sta_apply_parameters(local, sta, params);
1321 /* When peer becomes authorized, init rate control as well */
1322 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1323 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1324 rate_control_rate_init(sta);
1326 mutex_unlock(&local->sta_mtx);
1328 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1329 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1330 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1331 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1332 sta_info_tx_streams(sta) != 1) {
1334 "%pM just authorized and MIMO capable - update SMPS\n",
1336 ieee80211_send_smps_action(sta->sdata,
1337 sta->sdata->bss->req_smps,
1339 sta->sdata->vif.bss_conf.bssid);
1342 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1343 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1344 ieee80211_recalc_ps(local, -1);
1345 ieee80211_recalc_ps_vif(sdata);
1350 mutex_unlock(&local->sta_mtx);
1354 #ifdef CONFIG_MAC80211_MESH
1355 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1356 const u8 *dst, const u8 *next_hop)
1358 struct ieee80211_sub_if_data *sdata;
1359 struct mesh_path *mpath;
1360 struct sta_info *sta;
1362 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1365 sta = sta_info_get(sdata, next_hop);
1371 mpath = mesh_path_add(sdata, dst);
1372 if (IS_ERR(mpath)) {
1374 return PTR_ERR(mpath);
1377 mesh_path_fix_nexthop(mpath, sta);
1383 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1389 return mesh_path_del(sdata, dst);
1391 mesh_path_flush_by_iface(sdata);
1395 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1396 const u8 *dst, const u8 *next_hop)
1398 struct ieee80211_sub_if_data *sdata;
1399 struct mesh_path *mpath;
1400 struct sta_info *sta;
1402 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1406 sta = sta_info_get(sdata, next_hop);
1412 mpath = mesh_path_lookup(sdata, dst);
1418 mesh_path_fix_nexthop(mpath, sta);
1424 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1425 struct mpath_info *pinfo)
1427 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1430 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1432 memset(next_hop, 0, ETH_ALEN);
1434 memset(pinfo, 0, sizeof(*pinfo));
1436 pinfo->generation = mesh_paths_generation;
1438 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1441 MPATH_INFO_EXPTIME |
1442 MPATH_INFO_DISCOVERY_TIMEOUT |
1443 MPATH_INFO_DISCOVERY_RETRIES |
1446 pinfo->frame_qlen = mpath->frame_queue.qlen;
1447 pinfo->sn = mpath->sn;
1448 pinfo->metric = mpath->metric;
1449 if (time_before(jiffies, mpath->exp_time))
1450 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1451 pinfo->discovery_timeout =
1452 jiffies_to_msecs(mpath->discovery_timeout);
1453 pinfo->discovery_retries = mpath->discovery_retries;
1454 if (mpath->flags & MESH_PATH_ACTIVE)
1455 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1456 if (mpath->flags & MESH_PATH_RESOLVING)
1457 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1458 if (mpath->flags & MESH_PATH_SN_VALID)
1459 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1460 if (mpath->flags & MESH_PATH_FIXED)
1461 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1462 if (mpath->flags & MESH_PATH_RESOLVED)
1463 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1466 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1467 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1470 struct ieee80211_sub_if_data *sdata;
1471 struct mesh_path *mpath;
1473 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1476 mpath = mesh_path_lookup(sdata, dst);
1481 memcpy(dst, mpath->dst, ETH_ALEN);
1482 mpath_set_pinfo(mpath, next_hop, pinfo);
1487 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1488 int idx, u8 *dst, u8 *next_hop,
1489 struct mpath_info *pinfo)
1491 struct ieee80211_sub_if_data *sdata;
1492 struct mesh_path *mpath;
1494 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1497 mpath = mesh_path_lookup_by_idx(sdata, idx);
1502 memcpy(dst, mpath->dst, ETH_ALEN);
1503 mpath_set_pinfo(mpath, next_hop, pinfo);
1508 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1509 struct net_device *dev,
1510 struct mesh_config *conf)
1512 struct ieee80211_sub_if_data *sdata;
1513 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1515 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1519 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1521 return (mask >> (parm-1)) & 0x1;
1524 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1525 const struct mesh_setup *setup)
1529 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1530 struct ieee80211_sub_if_data, u.mesh);
1532 /* allocate information elements */
1536 if (setup->ie_len) {
1537 new_ie = kmemdup(setup->ie, setup->ie_len,
1542 ifmsh->ie_len = setup->ie_len;
1546 /* now copy the rest of the setup parameters */
1547 ifmsh->mesh_id_len = setup->mesh_id_len;
1548 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1549 ifmsh->mesh_sp_id = setup->sync_method;
1550 ifmsh->mesh_pp_id = setup->path_sel_proto;
1551 ifmsh->mesh_pm_id = setup->path_metric;
1552 ifmsh->user_mpm = setup->user_mpm;
1553 ifmsh->mesh_auth_id = setup->auth_id;
1554 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1555 if (setup->is_authenticated)
1556 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1557 if (setup->is_secure)
1558 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1560 /* mcast rate setting in Mesh Node */
1561 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1562 sizeof(setup->mcast_rate));
1563 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
1565 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1566 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1571 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1572 struct net_device *dev, u32 mask,
1573 const struct mesh_config *nconf)
1575 struct mesh_config *conf;
1576 struct ieee80211_sub_if_data *sdata;
1577 struct ieee80211_if_mesh *ifmsh;
1579 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1580 ifmsh = &sdata->u.mesh;
1582 /* Set the config options which we are interested in setting */
1583 conf = &(sdata->u.mesh.mshcfg);
1584 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1585 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1586 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1587 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1588 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1589 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1590 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1591 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1592 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1593 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1594 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1595 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1596 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1597 conf->element_ttl = nconf->element_ttl;
1598 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1599 if (ifmsh->user_mpm)
1601 conf->auto_open_plinks = nconf->auto_open_plinks;
1603 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1604 conf->dot11MeshNbrOffsetMaxNeighbor =
1605 nconf->dot11MeshNbrOffsetMaxNeighbor;
1606 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1607 conf->dot11MeshHWMPmaxPREQretries =
1608 nconf->dot11MeshHWMPmaxPREQretries;
1609 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1610 conf->path_refresh_time = nconf->path_refresh_time;
1611 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1612 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1613 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1614 conf->dot11MeshHWMPactivePathTimeout =
1615 nconf->dot11MeshHWMPactivePathTimeout;
1616 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1617 conf->dot11MeshHWMPpreqMinInterval =
1618 nconf->dot11MeshHWMPpreqMinInterval;
1619 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1620 conf->dot11MeshHWMPperrMinInterval =
1621 nconf->dot11MeshHWMPperrMinInterval;
1622 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1624 conf->dot11MeshHWMPnetDiameterTraversalTime =
1625 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1626 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1627 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1628 ieee80211_mesh_root_setup(ifmsh);
1630 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1631 /* our current gate announcement implementation rides on root
1632 * announcements, so require this ifmsh to also be a root node
1634 if (nconf->dot11MeshGateAnnouncementProtocol &&
1635 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1636 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
1637 ieee80211_mesh_root_setup(ifmsh);
1639 conf->dot11MeshGateAnnouncementProtocol =
1640 nconf->dot11MeshGateAnnouncementProtocol;
1642 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
1643 conf->dot11MeshHWMPRannInterval =
1644 nconf->dot11MeshHWMPRannInterval;
1645 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1646 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1647 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1648 /* our RSSI threshold implementation is supported only for
1649 * devices that report signal in dBm.
1651 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1653 conf->rssi_threshold = nconf->rssi_threshold;
1655 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1656 conf->ht_opmode = nconf->ht_opmode;
1657 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1658 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1660 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1661 conf->dot11MeshHWMPactivePathToRootTimeout =
1662 nconf->dot11MeshHWMPactivePathToRootTimeout;
1663 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1664 conf->dot11MeshHWMProotInterval =
1665 nconf->dot11MeshHWMProotInterval;
1666 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1667 conf->dot11MeshHWMPconfirmationInterval =
1668 nconf->dot11MeshHWMPconfirmationInterval;
1669 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1670 conf->power_mode = nconf->power_mode;
1671 ieee80211_mps_local_status_update(sdata);
1673 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
1674 conf->dot11MeshAwakeWindowDuration =
1675 nconf->dot11MeshAwakeWindowDuration;
1676 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1677 conf->plink_timeout = nconf->plink_timeout;
1678 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
1682 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1683 const struct mesh_config *conf,
1684 const struct mesh_setup *setup)
1686 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1687 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1690 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1691 err = copy_mesh_setup(ifmsh, setup);
1695 /* can mesh use other SMPS modes? */
1696 sdata->smps_mode = IEEE80211_SMPS_OFF;
1697 sdata->needed_rx_chains = sdata->local->rx_chains;
1699 mutex_lock(&sdata->local->mtx);
1700 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
1701 IEEE80211_CHANCTX_SHARED);
1702 mutex_unlock(&sdata->local->mtx);
1706 return ieee80211_start_mesh(sdata);
1709 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1711 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1713 ieee80211_stop_mesh(sdata);
1714 mutex_lock(&sdata->local->mtx);
1715 ieee80211_vif_release_channel(sdata);
1716 mutex_unlock(&sdata->local->mtx);
1722 static int ieee80211_change_bss(struct wiphy *wiphy,
1723 struct net_device *dev,
1724 struct bss_parameters *params)
1726 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1727 enum ieee80211_band band;
1730 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
1733 band = ieee80211_get_sdata_band(sdata);
1735 if (params->use_cts_prot >= 0) {
1736 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1737 changed |= BSS_CHANGED_ERP_CTS_PROT;
1739 if (params->use_short_preamble >= 0) {
1740 sdata->vif.bss_conf.use_short_preamble =
1741 params->use_short_preamble;
1742 changed |= BSS_CHANGED_ERP_PREAMBLE;
1745 if (!sdata->vif.bss_conf.use_short_slot &&
1746 band == IEEE80211_BAND_5GHZ) {
1747 sdata->vif.bss_conf.use_short_slot = true;
1748 changed |= BSS_CHANGED_ERP_SLOT;
1751 if (params->use_short_slot_time >= 0) {
1752 sdata->vif.bss_conf.use_short_slot =
1753 params->use_short_slot_time;
1754 changed |= BSS_CHANGED_ERP_SLOT;
1757 if (params->basic_rates) {
1758 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1760 params->basic_rates,
1761 params->basic_rates_len,
1762 &sdata->vif.bss_conf.basic_rates);
1763 changed |= BSS_CHANGED_BASIC_RATES;
1766 if (params->ap_isolate >= 0) {
1767 if (params->ap_isolate)
1768 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1770 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1773 if (params->ht_opmode >= 0) {
1774 sdata->vif.bss_conf.ht_operation_mode =
1775 (u16) params->ht_opmode;
1776 changed |= BSS_CHANGED_HT;
1779 if (params->p2p_ctwindow >= 0) {
1780 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1781 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1782 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1783 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1784 changed |= BSS_CHANGED_P2P_PS;
1787 if (params->p2p_opp_ps > 0) {
1788 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1789 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1790 changed |= BSS_CHANGED_P2P_PS;
1791 } else if (params->p2p_opp_ps == 0) {
1792 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1793 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
1794 changed |= BSS_CHANGED_P2P_PS;
1797 ieee80211_bss_info_change_notify(sdata, changed);
1802 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1803 struct net_device *dev,
1804 struct ieee80211_txq_params *params)
1806 struct ieee80211_local *local = wiphy_priv(wiphy);
1807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1808 struct ieee80211_tx_queue_params p;
1810 if (!local->ops->conf_tx)
1813 if (local->hw.queues < IEEE80211_NUM_ACS)
1816 memset(&p, 0, sizeof(p));
1817 p.aifs = params->aifs;
1818 p.cw_max = params->cwmax;
1819 p.cw_min = params->cwmin;
1820 p.txop = params->txop;
1823 * Setting tx queue params disables u-apsd because it's only
1824 * called in master mode.
1828 sdata->tx_conf[params->ac] = p;
1829 if (drv_conf_tx(local, sdata, params->ac, &p)) {
1830 wiphy_debug(local->hw.wiphy,
1831 "failed to set TX queue parameters for AC %d\n",
1836 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1842 static int ieee80211_suspend(struct wiphy *wiphy,
1843 struct cfg80211_wowlan *wowlan)
1845 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1848 static int ieee80211_resume(struct wiphy *wiphy)
1850 return __ieee80211_resume(wiphy_priv(wiphy));
1853 #define ieee80211_suspend NULL
1854 #define ieee80211_resume NULL
1857 static int ieee80211_scan(struct wiphy *wiphy,
1858 struct cfg80211_scan_request *req)
1860 struct ieee80211_sub_if_data *sdata;
1862 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
1864 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1865 case NL80211_IFTYPE_STATION:
1866 case NL80211_IFTYPE_ADHOC:
1867 case NL80211_IFTYPE_MESH_POINT:
1868 case NL80211_IFTYPE_P2P_CLIENT:
1869 case NL80211_IFTYPE_P2P_DEVICE:
1871 case NL80211_IFTYPE_P2P_GO:
1872 if (sdata->local->ops->hw_scan)
1875 * FIXME: implement NoA while scanning in software,
1876 * for now fall through to allow scanning only when
1877 * beaconing hasn't been configured yet
1879 case NL80211_IFTYPE_AP:
1881 * If the scan has been forced (and the driver supports
1882 * forcing), don't care about being beaconing already.
1883 * This will create problems to the attached stations (e.g. all
1884 * the frames sent while scanning on other channel will be
1887 if (sdata->u.ap.beacon &&
1888 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1889 !(req->flags & NL80211_SCAN_FLAG_AP)))
1896 return ieee80211_request_scan(sdata, req);
1900 ieee80211_sched_scan_start(struct wiphy *wiphy,
1901 struct net_device *dev,
1902 struct cfg80211_sched_scan_request *req)
1904 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1906 if (!sdata->local->ops->sched_scan_start)
1909 return ieee80211_request_sched_scan_start(sdata, req);
1913 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
1915 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1917 if (!sdata->local->ops->sched_scan_stop)
1920 return ieee80211_request_sched_scan_stop(sdata);
1923 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1924 struct cfg80211_auth_request *req)
1926 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1929 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1930 struct cfg80211_assoc_request *req)
1932 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1935 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1936 struct cfg80211_deauth_request *req)
1938 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1941 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1942 struct cfg80211_disassoc_request *req)
1944 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1947 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1948 struct cfg80211_ibss_params *params)
1950 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
1953 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1955 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
1958 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
1959 int rate[IEEE80211_NUM_BANDS])
1961 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1963 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
1964 sizeof(int) * IEEE80211_NUM_BANDS);
1969 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1971 struct ieee80211_local *local = wiphy_priv(wiphy);
1974 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1975 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1981 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
1982 (changed & WIPHY_PARAM_DYN_ACK)) {
1985 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
1986 wiphy->coverage_class : -1;
1987 err = drv_set_coverage_class(local, coverage_class);
1993 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1994 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2000 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2001 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2003 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2005 if (changed & WIPHY_PARAM_RETRY_LONG) {
2006 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2008 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2011 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2012 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2017 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2018 struct wireless_dev *wdev,
2019 enum nl80211_tx_power_setting type, int mbm)
2021 struct ieee80211_local *local = wiphy_priv(wiphy);
2022 struct ieee80211_sub_if_data *sdata;
2025 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2028 case NL80211_TX_POWER_AUTOMATIC:
2029 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2031 case NL80211_TX_POWER_LIMITED:
2032 case NL80211_TX_POWER_FIXED:
2033 if (mbm < 0 || (mbm % 100))
2035 sdata->user_power_level = MBM_TO_DBM(mbm);
2039 ieee80211_recalc_txpower(sdata);
2045 case NL80211_TX_POWER_AUTOMATIC:
2046 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2048 case NL80211_TX_POWER_LIMITED:
2049 case NL80211_TX_POWER_FIXED:
2050 if (mbm < 0 || (mbm % 100))
2052 local->user_power_level = MBM_TO_DBM(mbm);
2056 mutex_lock(&local->iflist_mtx);
2057 list_for_each_entry(sdata, &local->interfaces, list)
2058 sdata->user_power_level = local->user_power_level;
2059 list_for_each_entry(sdata, &local->interfaces, list)
2060 ieee80211_recalc_txpower(sdata);
2061 mutex_unlock(&local->iflist_mtx);
2066 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2067 struct wireless_dev *wdev,
2070 struct ieee80211_local *local = wiphy_priv(wiphy);
2071 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2073 if (!local->use_chanctx)
2074 *dbm = local->hw.conf.power_level;
2076 *dbm = sdata->vif.bss_conf.txpower;
2081 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2084 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2086 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2091 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2093 struct ieee80211_local *local = wiphy_priv(wiphy);
2095 drv_rfkill_poll(local);
2098 #ifdef CONFIG_NL80211_TESTMODE
2099 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2100 struct wireless_dev *wdev,
2101 void *data, int len)
2103 struct ieee80211_local *local = wiphy_priv(wiphy);
2104 struct ieee80211_vif *vif = NULL;
2106 if (!local->ops->testmode_cmd)
2110 struct ieee80211_sub_if_data *sdata;
2112 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2113 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2117 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2120 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2121 struct sk_buff *skb,
2122 struct netlink_callback *cb,
2123 void *data, int len)
2125 struct ieee80211_local *local = wiphy_priv(wiphy);
2127 if (!local->ops->testmode_dump)
2130 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2134 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2135 enum ieee80211_smps_mode smps_mode)
2137 struct sta_info *sta;
2138 enum ieee80211_smps_mode old_req;
2141 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2144 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2147 old_req = sdata->u.ap.req_smps;
2148 sdata->u.ap.req_smps = smps_mode;
2150 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2151 if (old_req == smps_mode ||
2152 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2155 /* If no associated stations, there's no need to do anything */
2156 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2157 sdata->smps_mode = smps_mode;
2158 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2163 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2164 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2166 mutex_lock(&sdata->local->sta_mtx);
2167 for (i = 0; i < STA_HASH_SIZE; i++) {
2168 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2169 lockdep_is_held(&sdata->local->sta_mtx));
2171 sta = rcu_dereference_protected(sta->hnext,
2172 lockdep_is_held(&sdata->local->sta_mtx))) {
2174 * Only stations associated to our AP and
2177 if (sta->sdata->bss != &sdata->u.ap)
2180 /* This station doesn't support MIMO - skip it */
2181 if (sta_info_tx_streams(sta) == 1)
2185 * Don't wake up a STA just to send the action frame
2186 * unless we are getting more restrictive.
2188 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2189 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2192 "Won't send SMPS to sleeping STA %pM\n",
2198 * If the STA is not authorized, wait until it gets
2199 * authorized and the action frame will be sent then.
2201 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2204 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2205 ieee80211_send_smps_action(sdata, smps_mode,
2207 sdata->vif.bss_conf.bssid);
2210 mutex_unlock(&sdata->local->sta_mtx);
2212 sdata->smps_mode = smps_mode;
2213 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2218 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2219 enum ieee80211_smps_mode smps_mode)
2222 enum ieee80211_smps_mode old_req;
2225 lockdep_assert_held(&sdata->wdev.mtx);
2227 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2230 old_req = sdata->u.mgd.req_smps;
2231 sdata->u.mgd.req_smps = smps_mode;
2233 if (old_req == smps_mode &&
2234 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2238 * If not associated, or current association is not an HT
2239 * association, there's no need to do anything, just store
2240 * the new value until we associate.
2242 if (!sdata->u.mgd.associated ||
2243 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2246 ap = sdata->u.mgd.associated->bssid;
2248 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2249 if (sdata->u.mgd.powersave)
2250 smps_mode = IEEE80211_SMPS_DYNAMIC;
2252 smps_mode = IEEE80211_SMPS_OFF;
2255 /* send SM PS frame to AP */
2256 err = ieee80211_send_smps_action(sdata, smps_mode,
2259 sdata->u.mgd.req_smps = old_req;
2264 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2265 bool enabled, int timeout)
2267 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2268 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2270 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2273 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2276 if (enabled == sdata->u.mgd.powersave &&
2277 timeout == local->dynamic_ps_forced_timeout)
2280 sdata->u.mgd.powersave = enabled;
2281 local->dynamic_ps_forced_timeout = timeout;
2283 /* no change, but if automatic follow powersave */
2285 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2286 sdata_unlock(sdata);
2288 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2289 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2291 ieee80211_recalc_ps(local, -1);
2292 ieee80211_recalc_ps_vif(sdata);
2297 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2298 struct net_device *dev,
2299 s32 rssi_thold, u32 rssi_hyst)
2301 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2302 struct ieee80211_vif *vif = &sdata->vif;
2303 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2305 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2306 rssi_hyst == bss_conf->cqm_rssi_hyst)
2309 bss_conf->cqm_rssi_thold = rssi_thold;
2310 bss_conf->cqm_rssi_hyst = rssi_hyst;
2312 /* tell the driver upon association, unless already associated */
2313 if (sdata->u.mgd.associated &&
2314 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2315 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2320 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2321 struct net_device *dev,
2323 const struct cfg80211_bitrate_mask *mask)
2325 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2326 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2329 if (!ieee80211_sdata_running(sdata))
2332 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2333 ret = drv_set_bitrate_mask(local, sdata, mask);
2338 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
2339 struct ieee80211_supported_band *sband = wiphy->bands[i];
2342 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2343 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2344 sizeof(mask->control[i].ht_mcs));
2346 sdata->rc_has_mcs_mask[i] = false;
2350 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2351 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2352 sdata->rc_has_mcs_mask[i] = true;
2360 static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2361 struct ieee80211_roc_work *new_roc,
2362 struct ieee80211_roc_work *cur_roc)
2364 unsigned long j = jiffies;
2365 unsigned long cur_roc_end = cur_roc->hw_start_time +
2366 msecs_to_jiffies(cur_roc->duration);
2367 struct ieee80211_roc_work *next_roc;
2370 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2373 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2376 ieee80211_handle_roc_started(new_roc);
2378 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2380 /* cur_roc is long enough - add new_roc to the dependents list. */
2382 list_add_tail(&new_roc->list, &cur_roc->dependents);
2386 new_roc->duration = new_dur;
2389 * if cur_roc was already coalesced before, we might
2390 * want to extend the next roc instead of adding
2393 next_roc = list_entry(cur_roc->list.next,
2394 struct ieee80211_roc_work, list);
2395 if (&next_roc->list != &local->roc_list &&
2396 next_roc->chan == new_roc->chan &&
2397 next_roc->sdata == new_roc->sdata &&
2398 !WARN_ON(next_roc->started)) {
2399 list_add_tail(&new_roc->list, &next_roc->dependents);
2400 next_roc->duration = max(next_roc->duration,
2402 next_roc->type = max(next_roc->type, new_roc->type);
2406 /* add right after cur_roc */
2407 list_add(&new_roc->list, &cur_roc->list);
2412 static int ieee80211_start_roc_work(struct ieee80211_local *local,
2413 struct ieee80211_sub_if_data *sdata,
2414 struct ieee80211_channel *channel,
2415 unsigned int duration, u64 *cookie,
2416 struct sk_buff *txskb,
2417 enum ieee80211_roc_type type)
2419 struct ieee80211_roc_work *roc, *tmp;
2420 bool queued = false;
2423 lockdep_assert_held(&local->mtx);
2425 if (local->use_chanctx && !local->ops->remain_on_channel)
2428 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2433 * If the duration is zero, then the driver
2434 * wouldn't actually do anything. Set it to
2437 * TODO: cancel the off-channel operation
2438 * when we get the SKB's TX status and
2439 * the wait time was zero before.
2444 roc->chan = channel;
2445 roc->duration = duration;
2446 roc->req_duration = duration;
2449 roc->mgmt_tx_cookie = (unsigned long)txskb;
2451 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2452 INIT_LIST_HEAD(&roc->dependents);
2455 * cookie is either the roc cookie (for normal roc)
2456 * or the SKB (for mgmt TX)
2459 /* local->mtx protects this */
2460 local->roc_cookie_counter++;
2461 roc->cookie = local->roc_cookie_counter;
2462 /* wow, you wrapped 64 bits ... more likely a bug */
2463 if (WARN_ON(roc->cookie == 0)) {
2465 local->roc_cookie_counter++;
2467 *cookie = roc->cookie;
2469 *cookie = (unsigned long)txskb;
2472 /* if there's one pending or we're scanning, queue this one */
2473 if (!list_empty(&local->roc_list) ||
2474 local->scanning || local->radar_detect_enabled)
2475 goto out_check_combine;
2477 /* if not HW assist, just queue & schedule work */
2478 if (!local->ops->remain_on_channel) {
2479 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2483 /* otherwise actually kick it off here (for error handling) */
2485 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
2491 roc->started = true;
2495 list_for_each_entry(tmp, &local->roc_list, list) {
2496 if (tmp->chan != channel || tmp->sdata != sdata)
2500 * Extend this ROC if possible:
2502 * If it hasn't started yet, just increase the duration
2503 * and add the new one to the list of dependents.
2504 * If the type of the new ROC has higher priority, modify the
2505 * type of the previous one to match that of the new one.
2507 if (!tmp->started) {
2508 list_add_tail(&roc->list, &tmp->dependents);
2509 tmp->duration = max(tmp->duration, roc->duration);
2510 tmp->type = max(tmp->type, roc->type);
2515 /* If it has already started, it's more difficult ... */
2516 if (local->ops->remain_on_channel) {
2518 * In the offloaded ROC case, if it hasn't begun, add
2519 * this new one to the dependent list to be handled
2520 * when the master one begins. If it has begun,
2521 * check that there's still a minimum time left and
2522 * if so, start this one, transmitting the frame, but
2523 * add it to the list directly after this one with
2524 * a reduced time so we'll ask the driver to execute
2525 * it right after finishing the previous one, in the
2526 * hope that it'll also be executed right afterwards,
2527 * effectively extending the old one.
2528 * If there's no minimum time left, just add it to the
2530 * TODO: the ROC type is ignored here, assuming that it
2531 * is better to immediately use the current ROC.
2533 if (!tmp->hw_begun) {
2534 list_add_tail(&roc->list, &tmp->dependents);
2539 if (ieee80211_coalesce_started_roc(local, roc, tmp))
2541 } else if (del_timer_sync(&tmp->work.timer)) {
2542 unsigned long new_end;
2545 * In the software ROC case, cancel the timer, if
2546 * that fails then the finish work is already
2547 * queued/pending and thus we queue the new ROC
2548 * normally, if that succeeds then we can extend
2549 * the timer duration and TX the frame (if any.)
2552 list_add_tail(&roc->list, &tmp->dependents);
2555 new_end = jiffies + msecs_to_jiffies(roc->duration);
2557 /* ok, it was started & we canceled timer */
2558 if (time_after(new_end, tmp->work.timer.expires))
2559 mod_timer(&tmp->work.timer, new_end);
2561 add_timer(&tmp->work.timer);
2563 ieee80211_handle_roc_started(roc);
2570 list_add_tail(&roc->list, &local->roc_list);
2575 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
2576 struct wireless_dev *wdev,
2577 struct ieee80211_channel *chan,
2578 unsigned int duration,
2581 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2582 struct ieee80211_local *local = sdata->local;
2585 mutex_lock(&local->mtx);
2586 ret = ieee80211_start_roc_work(local, sdata, chan,
2587 duration, cookie, NULL,
2588 IEEE80211_ROC_TYPE_NORMAL);
2589 mutex_unlock(&local->mtx);
2594 static int ieee80211_cancel_roc(struct ieee80211_local *local,
2595 u64 cookie, bool mgmt_tx)
2597 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2600 mutex_lock(&local->mtx);
2601 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
2602 struct ieee80211_roc_work *dep, *tmp2;
2604 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2605 if (!mgmt_tx && dep->cookie != cookie)
2607 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2609 /* found dependent item -- just remove it */
2610 list_del(&dep->list);
2611 mutex_unlock(&local->mtx);
2613 ieee80211_roc_notify_destroy(dep, true);
2617 if (!mgmt_tx && roc->cookie != cookie)
2619 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2627 mutex_unlock(&local->mtx);
2632 * We found the item to cancel, so do that. Note that it
2633 * may have dependents, which we also cancel (and send
2634 * the expired signal for.) Not doing so would be quite
2635 * tricky here, but we may need to fix it later.
2638 if (local->ops->remain_on_channel) {
2639 if (found->started) {
2640 ret = drv_cancel_remain_on_channel(local);
2641 if (WARN_ON_ONCE(ret)) {
2642 mutex_unlock(&local->mtx);
2647 list_del(&found->list);
2650 ieee80211_start_next_roc(local);
2651 mutex_unlock(&local->mtx);
2653 ieee80211_roc_notify_destroy(found, true);
2655 /* work may be pending so use it all the time */
2656 found->abort = true;
2657 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2659 mutex_unlock(&local->mtx);
2661 /* work will clean up etc */
2662 flush_delayed_work(&found->work);
2663 WARN_ON(!found->to_be_freed);
2670 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
2671 struct wireless_dev *wdev,
2674 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2675 struct ieee80211_local *local = sdata->local;
2677 return ieee80211_cancel_roc(local, cookie, false);
2680 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2681 struct net_device *dev,
2682 struct cfg80211_chan_def *chandef,
2685 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2686 struct ieee80211_local *local = sdata->local;
2689 mutex_lock(&local->mtx);
2690 if (!list_empty(&local->roc_list) || local->scanning) {
2695 /* whatever, but channel contexts should not complain about that one */
2696 sdata->smps_mode = IEEE80211_SMPS_OFF;
2697 sdata->needed_rx_chains = local->rx_chains;
2699 err = ieee80211_vif_use_channel(sdata, chandef,
2700 IEEE80211_CHANCTX_SHARED);
2704 ieee80211_queue_delayed_work(&sdata->local->hw,
2705 &sdata->dfs_cac_timer_work,
2706 msecs_to_jiffies(cac_time_ms));
2709 mutex_unlock(&local->mtx);
2713 static struct cfg80211_beacon_data *
2714 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2716 struct cfg80211_beacon_data *new_beacon;
2720 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2721 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2722 beacon->probe_resp_len;
2724 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2728 pos = (u8 *)(new_beacon + 1);
2729 if (beacon->head_len) {
2730 new_beacon->head_len = beacon->head_len;
2731 new_beacon->head = pos;
2732 memcpy(pos, beacon->head, beacon->head_len);
2733 pos += beacon->head_len;
2735 if (beacon->tail_len) {
2736 new_beacon->tail_len = beacon->tail_len;
2737 new_beacon->tail = pos;
2738 memcpy(pos, beacon->tail, beacon->tail_len);
2739 pos += beacon->tail_len;
2741 if (beacon->beacon_ies_len) {
2742 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2743 new_beacon->beacon_ies = pos;
2744 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2745 pos += beacon->beacon_ies_len;
2747 if (beacon->proberesp_ies_len) {
2748 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2749 new_beacon->proberesp_ies = pos;
2750 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2751 pos += beacon->proberesp_ies_len;
2753 if (beacon->assocresp_ies_len) {
2754 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2755 new_beacon->assocresp_ies = pos;
2756 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2757 pos += beacon->assocresp_ies_len;
2759 if (beacon->probe_resp_len) {
2760 new_beacon->probe_resp_len = beacon->probe_resp_len;
2761 beacon->probe_resp = pos;
2762 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2763 pos += beacon->probe_resp_len;
2769 void ieee80211_csa_finish(struct ieee80211_vif *vif)
2771 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2773 ieee80211_queue_work(&sdata->local->hw,
2774 &sdata->csa_finalize_work);
2776 EXPORT_SYMBOL(ieee80211_csa_finish);
2778 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2783 switch (sdata->vif.type) {
2784 case NL80211_IFTYPE_AP:
2785 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2787 kfree(sdata->u.ap.next_beacon);
2788 sdata->u.ap.next_beacon = NULL;
2794 case NL80211_IFTYPE_ADHOC:
2795 err = ieee80211_ibss_finish_csa(sdata);
2800 #ifdef CONFIG_MAC80211_MESH
2801 case NL80211_IFTYPE_MESH_POINT:
2802 err = ieee80211_mesh_finish_csa(sdata);
2816 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2818 struct ieee80211_local *local = sdata->local;
2822 sdata_assert_lock(sdata);
2823 lockdep_assert_held(&local->mtx);
2824 lockdep_assert_held(&local->chanctx_mtx);
2827 * using reservation isn't immediate as it may be deferred until later
2828 * with multi-vif. once reservation is complete it will re-schedule the
2829 * work with no reserved_chanctx so verify chandef to check if it
2830 * completed successfully
2833 if (sdata->reserved_chanctx) {
2835 * with multi-vif csa driver may call ieee80211_csa_finish()
2836 * many times while waiting for other interfaces to use their
2839 if (sdata->reserved_ready)
2842 err = ieee80211_vif_use_reserved_context(sdata);
2849 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2850 &sdata->csa_chandef))
2853 sdata->vif.csa_active = false;
2855 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2859 ieee80211_bss_info_change_notify(sdata, changed);
2860 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2862 if (sdata->csa_block_tx) {
2863 ieee80211_wake_vif_queues(local, sdata,
2864 IEEE80211_QUEUE_STOP_REASON_CSA);
2865 sdata->csa_block_tx = false;
2871 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2873 if (__ieee80211_csa_finalize(sdata)) {
2874 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2875 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2880 void ieee80211_csa_finalize_work(struct work_struct *work)
2882 struct ieee80211_sub_if_data *sdata =
2883 container_of(work, struct ieee80211_sub_if_data,
2885 struct ieee80211_local *local = sdata->local;
2888 mutex_lock(&local->mtx);
2889 mutex_lock(&local->chanctx_mtx);
2891 /* AP might have been stopped while waiting for the lock. */
2892 if (!sdata->vif.csa_active)
2895 if (!ieee80211_sdata_running(sdata))
2898 ieee80211_csa_finalize(sdata);
2901 mutex_unlock(&local->chanctx_mtx);
2902 mutex_unlock(&local->mtx);
2903 sdata_unlock(sdata);
2906 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
2907 struct cfg80211_csa_settings *params,
2910 struct ieee80211_csa_settings csa = {};
2913 switch (sdata->vif.type) {
2914 case NL80211_IFTYPE_AP:
2915 sdata->u.ap.next_beacon =
2916 cfg80211_beacon_dup(¶ms->beacon_after);
2917 if (!sdata->u.ap.next_beacon)
2921 * With a count of 0, we don't have to wait for any
2922 * TBTT before switching, so complete the CSA
2923 * immediately. In theory, with a count == 1 we
2924 * should delay the switch until just before the next
2925 * TBTT, but that would complicate things so we switch
2926 * immediately too. If we would delay the switch
2927 * until the next TBTT, we would have to set the probe
2930 * TODO: A channel switch with count <= 1 without
2931 * sending a CSA action frame is kind of useless,
2932 * because the clients won't know we're changing
2933 * channels. The action frame must be implemented
2934 * either here or in the userspace.
2936 if (params->count <= 1)
2939 if ((params->n_counter_offsets_beacon >
2940 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
2941 (params->n_counter_offsets_presp >
2942 IEEE80211_MAX_CSA_COUNTERS_NUM))
2945 csa.counter_offsets_beacon = params->counter_offsets_beacon;
2946 csa.counter_offsets_presp = params->counter_offsets_presp;
2947 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
2948 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
2949 csa.count = params->count;
2951 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa);
2953 kfree(sdata->u.ap.next_beacon);
2959 case NL80211_IFTYPE_ADHOC:
2960 if (!sdata->vif.bss_conf.ibss_joined)
2963 if (params->chandef.width != sdata->u.ibss.chandef.width)
2966 switch (params->chandef.width) {
2967 case NL80211_CHAN_WIDTH_40:
2968 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2969 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
2971 case NL80211_CHAN_WIDTH_5:
2972 case NL80211_CHAN_WIDTH_10:
2973 case NL80211_CHAN_WIDTH_20_NOHT:
2974 case NL80211_CHAN_WIDTH_20:
2980 /* changes into another band are not supported */
2981 if (sdata->u.ibss.chandef.chan->band !=
2982 params->chandef.chan->band)
2985 /* see comments in the NL80211_IFTYPE_AP block */
2986 if (params->count > 1) {
2987 err = ieee80211_ibss_csa_beacon(sdata, params);
2993 ieee80211_send_action_csa(sdata, params);
2996 #ifdef CONFIG_MAC80211_MESH
2997 case NL80211_IFTYPE_MESH_POINT: {
2998 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3000 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3003 /* changes into another band are not supported */
3004 if (sdata->vif.bss_conf.chandef.chan->band !=
3005 params->chandef.chan->band)
3008 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3009 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3010 if (!ifmsh->pre_value)
3011 ifmsh->pre_value = 1;
3016 /* see comments in the NL80211_IFTYPE_AP block */
3017 if (params->count > 1) {
3018 err = ieee80211_mesh_csa_beacon(sdata, params);
3020 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3026 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3027 ieee80211_send_action_csa(sdata, params);
3040 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3041 struct cfg80211_csa_settings *params)
3043 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3044 struct ieee80211_local *local = sdata->local;
3045 struct ieee80211_chanctx_conf *conf;
3046 struct ieee80211_chanctx *chanctx;
3047 int err, changed = 0;
3049 sdata_assert_lock(sdata);
3050 lockdep_assert_held(&local->mtx);
3052 if (!list_empty(&local->roc_list) || local->scanning)
3055 if (sdata->wdev.cac_started)
3058 if (cfg80211_chandef_identical(¶ms->chandef,
3059 &sdata->vif.bss_conf.chandef))
3062 /* don't allow another channel switch if one is already active. */
3063 if (sdata->vif.csa_active)
3066 mutex_lock(&local->chanctx_mtx);
3067 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3068 lockdep_is_held(&local->chanctx_mtx));
3074 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3080 err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef,
3082 params->radar_required);
3086 /* if reservation is invalid then this will fail */
3087 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3089 ieee80211_vif_unreserve_chanctx(sdata);
3093 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3095 ieee80211_vif_unreserve_chanctx(sdata);
3099 sdata->csa_chandef = params->chandef;
3100 sdata->csa_block_tx = params->block_tx;
3101 sdata->vif.csa_active = true;
3103 if (sdata->csa_block_tx)
3104 ieee80211_stop_vif_queues(local, sdata,
3105 IEEE80211_QUEUE_STOP_REASON_CSA);
3108 ieee80211_bss_info_change_notify(sdata, changed);
3109 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3111 /* if the beacon didn't change, we can finalize immediately */
3112 ieee80211_csa_finalize(sdata);
3116 mutex_unlock(&local->chanctx_mtx);
3120 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3121 struct cfg80211_csa_settings *params)
3123 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3124 struct ieee80211_local *local = sdata->local;
3127 mutex_lock(&local->mtx);
3128 err = __ieee80211_channel_switch(wiphy, dev, params);
3129 mutex_unlock(&local->mtx);
3134 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
3135 struct cfg80211_mgmt_tx_params *params,
3138 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3139 struct ieee80211_local *local = sdata->local;
3140 struct sk_buff *skb;
3141 struct sta_info *sta;
3142 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
3143 bool need_offchan = false;
3148 if (params->dont_wait_for_ack)
3149 flags = IEEE80211_TX_CTL_NO_ACK;
3151 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3152 IEEE80211_TX_CTL_REQ_TX_STATUS;
3155 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3157 switch (sdata->vif.type) {
3158 case NL80211_IFTYPE_ADHOC:
3159 if (!sdata->vif.bss_conf.ibss_joined)
3160 need_offchan = true;
3162 #ifdef CONFIG_MAC80211_MESH
3163 case NL80211_IFTYPE_MESH_POINT:
3164 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3165 !sdata->u.mesh.mesh_id_len)
3166 need_offchan = true;
3169 case NL80211_IFTYPE_AP:
3170 case NL80211_IFTYPE_AP_VLAN:
3171 case NL80211_IFTYPE_P2P_GO:
3172 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3173 !ieee80211_vif_is_mesh(&sdata->vif) &&
3174 !rcu_access_pointer(sdata->bss->beacon))
3175 need_offchan = true;
3176 if (!ieee80211_is_action(mgmt->frame_control) ||
3177 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
3178 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3179 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
3182 sta = sta_info_get(sdata, mgmt->da);
3187 case NL80211_IFTYPE_STATION:
3188 case NL80211_IFTYPE_P2P_CLIENT:
3189 if (!sdata->u.mgd.associated)
3190 need_offchan = true;
3192 case NL80211_IFTYPE_P2P_DEVICE:
3193 need_offchan = true;
3199 /* configurations requiring offchan cannot work if no channel has been
3202 if (need_offchan && !params->chan)
3205 mutex_lock(&local->mtx);
3207 /* Check if the operating channel is the requested channel */
3208 if (!need_offchan) {
3209 struct ieee80211_chanctx_conf *chanctx_conf;
3212 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3215 need_offchan = params->chan &&
3217 chanctx_conf->def.chan);
3218 } else if (!params->chan) {
3223 need_offchan = true;
3228 if (need_offchan && !params->offchan) {
3233 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
3238 skb_reserve(skb, local->hw.extra_tx_headroom);
3240 data = skb_put(skb, params->len);
3241 memcpy(data, params->buf, params->len);
3243 /* Update CSA counters */
3244 if (sdata->vif.csa_active &&
3245 (sdata->vif.type == NL80211_IFTYPE_AP ||
3246 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3247 params->n_csa_offsets) {
3249 struct beacon_data *beacon = NULL;
3253 if (sdata->vif.type == NL80211_IFTYPE_AP)
3254 beacon = rcu_dereference(sdata->u.ap.beacon);
3255 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3256 beacon = rcu_dereference(sdata->u.ibss.presp);
3257 else if (ieee80211_vif_is_mesh(&sdata->vif))
3258 beacon = rcu_dereference(sdata->u.mesh.beacon);
3261 for (i = 0; i < params->n_csa_offsets; i++)
3262 data[params->csa_offsets[i]] =
3263 beacon->csa_current_counter;
3268 IEEE80211_SKB_CB(skb)->flags = flags;
3270 skb->dev = sdata->dev;
3272 if (!need_offchan) {
3273 *cookie = (unsigned long) skb;
3274 ieee80211_tx_skb(sdata, skb);
3279 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3280 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
3281 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
3282 IEEE80211_SKB_CB(skb)->hw_queue =
3283 local->hw.offchannel_tx_hw_queue;
3285 /* This will handle all kinds of coalescing and immediate TX */
3286 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3287 params->wait, cookie, skb,
3288 IEEE80211_ROC_TYPE_MGMT_TX);
3292 mutex_unlock(&local->mtx);
3296 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
3297 struct wireless_dev *wdev,
3300 struct ieee80211_local *local = wiphy_priv(wiphy);
3302 return ieee80211_cancel_roc(local, cookie, true);
3305 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
3306 struct wireless_dev *wdev,
3307 u16 frame_type, bool reg)
3309 struct ieee80211_local *local = wiphy_priv(wiphy);
3311 switch (frame_type) {
3312 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3314 local->probe_req_reg++;
3316 local->probe_req_reg--;
3318 if (!local->open_count)
3321 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3328 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3330 struct ieee80211_local *local = wiphy_priv(wiphy);
3335 return drv_set_antenna(local, tx_ant, rx_ant);
3338 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3340 struct ieee80211_local *local = wiphy_priv(wiphy);
3342 return drv_get_antenna(local, tx_ant, rx_ant);
3345 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3346 struct net_device *dev,
3347 struct cfg80211_gtk_rekey_data *data)
3349 struct ieee80211_local *local = wiphy_priv(wiphy);
3350 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3352 if (!local->ops->set_rekey_data)
3355 drv_set_rekey_data(local, sdata, data);
3360 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3361 const u8 *peer, u64 *cookie)
3363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3364 struct ieee80211_local *local = sdata->local;
3365 struct ieee80211_qos_hdr *nullfunc;
3366 struct sk_buff *skb;
3367 int size = sizeof(*nullfunc);
3370 struct ieee80211_tx_info *info;
3371 struct sta_info *sta;
3372 struct ieee80211_chanctx_conf *chanctx_conf;
3373 enum ieee80211_band band;
3376 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3377 if (WARN_ON(!chanctx_conf)) {
3381 band = chanctx_conf->def.chan->band;
3382 sta = sta_info_get_bss(sdata, peer);
3391 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3392 IEEE80211_STYPE_QOS_NULLFUNC |
3393 IEEE80211_FCTL_FROMDS);
3396 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3397 IEEE80211_STYPE_NULLFUNC |
3398 IEEE80211_FCTL_FROMDS);
3401 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3409 skb_reserve(skb, local->hw.extra_tx_headroom);
3411 nullfunc = (void *) skb_put(skb, size);
3412 nullfunc->frame_control = fc;
3413 nullfunc->duration_id = 0;
3414 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3415 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3416 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3417 nullfunc->seq_ctrl = 0;
3419 info = IEEE80211_SKB_CB(skb);
3421 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3422 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3424 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3427 nullfunc->qos_ctrl = cpu_to_le16(7);
3430 ieee80211_xmit(sdata, skb, band);
3434 *cookie = (unsigned long) skb;
3438 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3439 struct wireless_dev *wdev,
3440 struct cfg80211_chan_def *chandef)
3442 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3443 struct ieee80211_local *local = wiphy_priv(wiphy);
3444 struct ieee80211_chanctx_conf *chanctx_conf;
3448 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3450 *chandef = chanctx_conf->def;
3452 } else if (local->open_count > 0 &&
3453 local->open_count == local->monitors &&
3454 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3455 if (local->use_chanctx)
3456 *chandef = local->monitor_chandef;
3458 *chandef = local->_oper_chandef;
3467 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3469 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3473 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3474 struct net_device *dev,
3475 struct cfg80211_qos_map *qos_map)
3477 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3478 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3481 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3484 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3486 /* A NULL qos_map was passed to disable QoS mapping */
3490 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3491 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3493 kfree_rcu(old_qos_map, rcu_head);
3498 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3499 struct net_device *dev,
3500 struct cfg80211_chan_def *chandef)
3502 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3506 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3508 ieee80211_bss_info_change_notify(sdata, changed);
3513 const struct cfg80211_ops mac80211_config_ops = {
3514 .add_virtual_intf = ieee80211_add_iface,
3515 .del_virtual_intf = ieee80211_del_iface,
3516 .change_virtual_intf = ieee80211_change_iface,
3517 .start_p2p_device = ieee80211_start_p2p_device,
3518 .stop_p2p_device = ieee80211_stop_p2p_device,
3519 .add_key = ieee80211_add_key,
3520 .del_key = ieee80211_del_key,
3521 .get_key = ieee80211_get_key,
3522 .set_default_key = ieee80211_config_default_key,
3523 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3524 .start_ap = ieee80211_start_ap,
3525 .change_beacon = ieee80211_change_beacon,
3526 .stop_ap = ieee80211_stop_ap,
3527 .add_station = ieee80211_add_station,
3528 .del_station = ieee80211_del_station,
3529 .change_station = ieee80211_change_station,
3530 .get_station = ieee80211_get_station,
3531 .dump_station = ieee80211_dump_station,
3532 .dump_survey = ieee80211_dump_survey,
3533 #ifdef CONFIG_MAC80211_MESH
3534 .add_mpath = ieee80211_add_mpath,
3535 .del_mpath = ieee80211_del_mpath,
3536 .change_mpath = ieee80211_change_mpath,
3537 .get_mpath = ieee80211_get_mpath,
3538 .dump_mpath = ieee80211_dump_mpath,
3539 .update_mesh_config = ieee80211_update_mesh_config,
3540 .get_mesh_config = ieee80211_get_mesh_config,
3541 .join_mesh = ieee80211_join_mesh,
3542 .leave_mesh = ieee80211_leave_mesh,
3544 .change_bss = ieee80211_change_bss,
3545 .set_txq_params = ieee80211_set_txq_params,
3546 .set_monitor_channel = ieee80211_set_monitor_channel,
3547 .suspend = ieee80211_suspend,
3548 .resume = ieee80211_resume,
3549 .scan = ieee80211_scan,
3550 .sched_scan_start = ieee80211_sched_scan_start,
3551 .sched_scan_stop = ieee80211_sched_scan_stop,
3552 .auth = ieee80211_auth,
3553 .assoc = ieee80211_assoc,
3554 .deauth = ieee80211_deauth,
3555 .disassoc = ieee80211_disassoc,
3556 .join_ibss = ieee80211_join_ibss,
3557 .leave_ibss = ieee80211_leave_ibss,
3558 .set_mcast_rate = ieee80211_set_mcast_rate,
3559 .set_wiphy_params = ieee80211_set_wiphy_params,
3560 .set_tx_power = ieee80211_set_tx_power,
3561 .get_tx_power = ieee80211_get_tx_power,
3562 .set_wds_peer = ieee80211_set_wds_peer,
3563 .rfkill_poll = ieee80211_rfkill_poll,
3564 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3565 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3566 .set_power_mgmt = ieee80211_set_power_mgmt,
3567 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3568 .remain_on_channel = ieee80211_remain_on_channel,
3569 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3570 .mgmt_tx = ieee80211_mgmt_tx,
3571 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3572 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3573 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3574 .set_antenna = ieee80211_set_antenna,
3575 .get_antenna = ieee80211_get_antenna,
3576 .set_rekey_data = ieee80211_set_rekey_data,
3577 .tdls_oper = ieee80211_tdls_oper,
3578 .tdls_mgmt = ieee80211_tdls_mgmt,
3579 .probe_client = ieee80211_probe_client,
3580 .set_noack_map = ieee80211_set_noack_map,
3582 .set_wakeup = ieee80211_set_wakeup,
3584 .get_channel = ieee80211_cfg_get_channel,
3585 .start_radar_detection = ieee80211_start_radar_detection,
3586 .channel_switch = ieee80211_channel_switch,
3587 .set_qos_map = ieee80211_set_qos_map,
3588 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,