2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2015 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 unsigned char name_assign_type,
27 enum nl80211_iftype type,
29 struct vif_params *params)
31 struct ieee80211_local *local = wiphy_priv(wiphy);
32 struct wireless_dev *wdev;
33 struct ieee80211_sub_if_data *sdata;
36 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
40 if (type == NL80211_IFTYPE_MONITOR && flags) {
41 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
42 sdata->u.mntr.flags = *flags;
48 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
50 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
55 static int ieee80211_change_iface(struct wiphy *wiphy,
56 struct net_device *dev,
57 enum nl80211_iftype type, u32 *flags,
58 struct vif_params *params)
60 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
63 ret = ieee80211_if_change_type(sdata, type);
67 if (type == NL80211_IFTYPE_AP_VLAN &&
68 params && params->use_4addr == 0) {
69 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
70 ieee80211_check_fast_rx_iface(sdata);
71 } else if (type == NL80211_IFTYPE_STATION &&
72 params && params->use_4addr >= 0) {
73 sdata->u.mgd.use_4addr = params->use_4addr;
76 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
77 struct ieee80211_local *local = sdata->local;
78 struct ieee80211_sub_if_data *monitor_sdata;
79 u32 mu_mntr_cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
81 monitor_sdata = rtnl_dereference(local->monitor_sdata);
83 wiphy_ext_feature_isset(wiphy, mu_mntr_cap_flag)) {
84 memcpy(monitor_sdata->vif.bss_conf.mu_group.membership,
85 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
86 memcpy(monitor_sdata->vif.bss_conf.mu_group.position,
87 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
88 WLAN_USER_POSITION_LEN);
89 monitor_sdata->vif.mu_mimo_owner = true;
90 ieee80211_bss_info_change_notify(monitor_sdata,
91 BSS_CHANGED_MU_GROUPS);
93 ether_addr_copy(monitor_sdata->u.mntr.mu_follow_addr,
100 if (ieee80211_sdata_running(sdata)) {
101 u32 mask = MONITOR_FLAG_COOK_FRAMES |
105 * Prohibit MONITOR_FLAG_COOK_FRAMES and
106 * MONITOR_FLAG_ACTIVE to be changed while the
108 * Else we would need to add a lot of cruft
109 * to update everything:
110 * cooked_mntrs, monitor and all fif_* counters
111 * reconfigure hardware
113 if ((*flags & mask) != (sdata->u.mntr.flags & mask))
116 ieee80211_adjust_monitor_flags(sdata, -1);
117 sdata->u.mntr.flags = *flags;
118 ieee80211_adjust_monitor_flags(sdata, 1);
120 ieee80211_configure_filter(local);
123 * Because the interface is down, ieee80211_do_stop
124 * and ieee80211_do_open take care of "everything"
125 * mentioned in the comment above.
127 sdata->u.mntr.flags = *flags;
134 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
135 struct wireless_dev *wdev)
137 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
140 mutex_lock(&sdata->local->chanctx_mtx);
141 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
142 mutex_unlock(&sdata->local->chanctx_mtx);
146 return ieee80211_do_open(wdev, true);
149 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
150 struct wireless_dev *wdev)
152 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
155 static int ieee80211_set_noack_map(struct wiphy *wiphy,
156 struct net_device *dev,
159 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
161 sdata->noack_map = noack_map;
163 ieee80211_check_fast_xmit_iface(sdata);
168 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
169 u8 key_idx, bool pairwise, const u8 *mac_addr,
170 struct key_params *params)
172 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
173 struct ieee80211_local *local = sdata->local;
174 struct sta_info *sta = NULL;
175 const struct ieee80211_cipher_scheme *cs = NULL;
176 struct ieee80211_key *key;
179 if (!ieee80211_sdata_running(sdata))
182 /* reject WEP and TKIP keys if WEP failed to initialize */
183 switch (params->cipher) {
184 case WLAN_CIPHER_SUITE_WEP40:
185 case WLAN_CIPHER_SUITE_TKIP:
186 case WLAN_CIPHER_SUITE_WEP104:
187 if (IS_ERR(local->wep_tx_tfm))
190 case WLAN_CIPHER_SUITE_CCMP:
191 case WLAN_CIPHER_SUITE_CCMP_256:
192 case WLAN_CIPHER_SUITE_AES_CMAC:
193 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
194 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
195 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
196 case WLAN_CIPHER_SUITE_GCMP:
197 case WLAN_CIPHER_SUITE_GCMP_256:
200 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
204 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
205 params->key, params->seq_len, params->seq,
211 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
213 mutex_lock(&local->sta_mtx);
216 if (ieee80211_vif_is_mesh(&sdata->vif))
217 sta = sta_info_get(sdata, mac_addr);
219 sta = sta_info_get_bss(sdata, mac_addr);
221 * The ASSOC test makes sure the driver is ready to
222 * receive the key. When wpa_supplicant has roamed
223 * using FT, it attempts to set the key before
224 * association has completed, this rejects that attempt
225 * so it will set the key again after association.
227 * TODO: accept the key if we have a station entry and
228 * add it to the device after the station.
230 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
231 ieee80211_key_free_unused(key);
237 switch (sdata->vif.type) {
238 case NL80211_IFTYPE_STATION:
239 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
240 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
242 case NL80211_IFTYPE_AP:
243 case NL80211_IFTYPE_AP_VLAN:
244 /* Keys without a station are used for TX only */
245 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
246 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
248 case NL80211_IFTYPE_ADHOC:
251 case NL80211_IFTYPE_MESH_POINT:
252 #ifdef CONFIG_MAC80211_MESH
253 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
254 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
257 case NL80211_IFTYPE_WDS:
258 case NL80211_IFTYPE_MONITOR:
259 case NL80211_IFTYPE_P2P_DEVICE:
260 case NL80211_IFTYPE_NAN:
261 case NL80211_IFTYPE_UNSPECIFIED:
262 case NUM_NL80211_IFTYPES:
263 case NL80211_IFTYPE_P2P_CLIENT:
264 case NL80211_IFTYPE_P2P_GO:
265 case NL80211_IFTYPE_OCB:
266 /* shouldn't happen */
272 sta->cipher_scheme = cs;
274 err = ieee80211_key_link(key, sdata, sta);
277 mutex_unlock(&local->sta_mtx);
282 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
283 u8 key_idx, bool pairwise, const u8 *mac_addr)
285 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
286 struct ieee80211_local *local = sdata->local;
287 struct sta_info *sta;
288 struct ieee80211_key *key = NULL;
291 mutex_lock(&local->sta_mtx);
292 mutex_lock(&local->key_mtx);
297 sta = sta_info_get_bss(sdata, mac_addr);
302 key = key_mtx_dereference(local, sta->ptk[key_idx]);
304 key = key_mtx_dereference(local, sta->gtk[key_idx]);
306 key = key_mtx_dereference(local, sdata->keys[key_idx]);
313 ieee80211_key_free(key, true);
317 mutex_unlock(&local->key_mtx);
318 mutex_unlock(&local->sta_mtx);
323 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
324 u8 key_idx, bool pairwise, const u8 *mac_addr,
326 void (*callback)(void *cookie,
327 struct key_params *params))
329 struct ieee80211_sub_if_data *sdata;
330 struct sta_info *sta = NULL;
332 struct key_params params;
333 struct ieee80211_key *key = NULL;
338 struct ieee80211_key_seq kseq = {};
340 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
345 sta = sta_info_get_bss(sdata, mac_addr);
349 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
350 key = rcu_dereference(sta->ptk[key_idx]);
351 else if (!pairwise &&
352 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
353 key = rcu_dereference(sta->gtk[key_idx]);
355 key = rcu_dereference(sdata->keys[key_idx]);
360 memset(¶ms, 0, sizeof(params));
362 params.cipher = key->conf.cipher;
364 switch (key->conf.cipher) {
365 case WLAN_CIPHER_SUITE_TKIP:
366 pn64 = atomic64_read(&key->conf.tx_pn);
367 iv32 = TKIP_PN_TO_IV32(pn64);
368 iv16 = TKIP_PN_TO_IV16(pn64);
370 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
371 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
372 drv_get_key_seq(sdata->local, key, &kseq);
373 iv32 = kseq.tkip.iv32;
374 iv16 = kseq.tkip.iv16;
377 seq[0] = iv16 & 0xff;
378 seq[1] = (iv16 >> 8) & 0xff;
379 seq[2] = iv32 & 0xff;
380 seq[3] = (iv32 >> 8) & 0xff;
381 seq[4] = (iv32 >> 16) & 0xff;
382 seq[5] = (iv32 >> 24) & 0xff;
386 case WLAN_CIPHER_SUITE_CCMP:
387 case WLAN_CIPHER_SUITE_CCMP_256:
388 case WLAN_CIPHER_SUITE_AES_CMAC:
389 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
390 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
391 offsetof(typeof(kseq), aes_cmac));
392 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
393 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
394 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
395 offsetof(typeof(kseq), aes_gmac));
396 case WLAN_CIPHER_SUITE_GCMP:
397 case WLAN_CIPHER_SUITE_GCMP_256:
398 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
399 offsetof(typeof(kseq), gcmp));
401 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
402 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
403 drv_get_key_seq(sdata->local, key, &kseq);
404 memcpy(seq, kseq.ccmp.pn, 6);
406 pn64 = atomic64_read(&key->conf.tx_pn);
418 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
420 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
422 drv_get_key_seq(sdata->local, key, &kseq);
423 params.seq = kseq.hw.seq;
424 params.seq_len = kseq.hw.seq_len;
428 params.key = key->conf.key;
429 params.key_len = key->conf.keylen;
431 callback(cookie, ¶ms);
439 static int ieee80211_config_default_key(struct wiphy *wiphy,
440 struct net_device *dev,
441 u8 key_idx, bool uni,
444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
446 ieee80211_set_default_key(sdata, key_idx, uni, multi);
451 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
452 struct net_device *dev,
455 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
457 ieee80211_set_default_mgmt_key(sdata, key_idx);
462 void sta_set_rate_info_tx(struct sta_info *sta,
463 const struct ieee80211_tx_rate *rate,
464 struct rate_info *rinfo)
467 if (rate->flags & IEEE80211_TX_RC_MCS) {
468 rinfo->flags |= RATE_INFO_FLAGS_MCS;
469 rinfo->mcs = rate->idx;
470 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
471 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
472 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
473 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
475 struct ieee80211_supported_band *sband;
476 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
479 sband = sta->local->hw.wiphy->bands[
480 ieee80211_get_sdata_band(sta->sdata)];
481 brate = sband->bitrates[rate->idx].bitrate;
482 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
484 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
485 rinfo->bw = RATE_INFO_BW_40;
486 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
487 rinfo->bw = RATE_INFO_BW_80;
488 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
489 rinfo->bw = RATE_INFO_BW_160;
491 rinfo->bw = RATE_INFO_BW_20;
492 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
493 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
496 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
497 int idx, u8 *mac, struct station_info *sinfo)
499 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
500 struct ieee80211_local *local = sdata->local;
501 struct sta_info *sta;
504 mutex_lock(&local->sta_mtx);
506 sta = sta_info_get_by_idx(sdata, idx);
509 memcpy(mac, sta->sta.addr, ETH_ALEN);
510 sta_set_sinfo(sta, sinfo);
513 mutex_unlock(&local->sta_mtx);
518 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
519 int idx, struct survey_info *survey)
521 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
523 return drv_get_survey(local, idx, survey);
526 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
527 const u8 *mac, struct station_info *sinfo)
529 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
530 struct ieee80211_local *local = sdata->local;
531 struct sta_info *sta;
534 mutex_lock(&local->sta_mtx);
536 sta = sta_info_get_bss(sdata, mac);
539 sta_set_sinfo(sta, sinfo);
542 mutex_unlock(&local->sta_mtx);
547 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
548 struct cfg80211_chan_def *chandef)
550 struct ieee80211_local *local = wiphy_priv(wiphy);
551 struct ieee80211_sub_if_data *sdata;
554 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
557 mutex_lock(&local->mtx);
558 mutex_lock(&local->iflist_mtx);
559 if (local->use_chanctx) {
560 sdata = rcu_dereference_protected(
561 local->monitor_sdata,
562 lockdep_is_held(&local->iflist_mtx));
564 ieee80211_vif_release_channel(sdata);
565 ret = ieee80211_vif_use_channel(sdata, chandef,
566 IEEE80211_CHANCTX_EXCLUSIVE);
568 } else if (local->open_count == local->monitors) {
569 local->_oper_chandef = *chandef;
570 ieee80211_hw_config(local, 0);
574 local->monitor_chandef = *chandef;
575 mutex_unlock(&local->iflist_mtx);
576 mutex_unlock(&local->mtx);
581 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
582 const u8 *resp, size_t resp_len,
583 const struct ieee80211_csa_settings *csa)
585 struct probe_resp *new, *old;
587 if (!resp || !resp_len)
590 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
592 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
597 memcpy(new->data, resp, resp_len);
600 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
601 csa->n_counter_offsets_presp *
602 sizeof(new->csa_counter_offsets[0]));
604 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
606 kfree_rcu(old, rcu_head);
611 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
612 struct cfg80211_beacon_data *params,
613 const struct ieee80211_csa_settings *csa)
615 struct beacon_data *new, *old;
616 int new_head_len, new_tail_len;
618 u32 changed = BSS_CHANGED_BEACON;
620 old = sdata_dereference(sdata->u.ap.beacon, sdata);
623 /* Need to have a beacon head if we don't have one yet */
624 if (!params->head && !old)
627 /* new or old head? */
629 new_head_len = params->head_len;
631 new_head_len = old->head_len;
633 /* new or old tail? */
634 if (params->tail || !old)
635 /* params->tail_len will be zero for !params->tail */
636 new_tail_len = params->tail_len;
638 new_tail_len = old->tail_len;
640 size = sizeof(*new) + new_head_len + new_tail_len;
642 new = kzalloc(size, GFP_KERNEL);
646 /* start filling the new info now */
649 * pointers go into the block we allocated,
650 * memory is | beacon_data | head | tail |
652 new->head = ((u8 *) new) + sizeof(*new);
653 new->tail = new->head + new_head_len;
654 new->head_len = new_head_len;
655 new->tail_len = new_tail_len;
658 new->csa_current_counter = csa->count;
659 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
660 csa->n_counter_offsets_beacon *
661 sizeof(new->csa_counter_offsets[0]));
666 memcpy(new->head, params->head, new_head_len);
668 memcpy(new->head, old->head, new_head_len);
670 /* copy in optional tail */
672 memcpy(new->tail, params->tail, new_tail_len);
675 memcpy(new->tail, old->tail, new_tail_len);
677 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
678 params->probe_resp_len, csa);
682 changed |= BSS_CHANGED_AP_PROBE_RESP;
684 rcu_assign_pointer(sdata->u.ap.beacon, new);
687 kfree_rcu(old, rcu_head);
692 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
693 struct cfg80211_ap_settings *params)
695 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
696 struct ieee80211_local *local = sdata->local;
697 struct beacon_data *old;
698 struct ieee80211_sub_if_data *vlan;
699 u32 changed = BSS_CHANGED_BEACON_INT |
700 BSS_CHANGED_BEACON_ENABLED |
707 old = sdata_dereference(sdata->u.ap.beacon, sdata);
711 switch (params->smps_mode) {
712 case NL80211_SMPS_OFF:
713 sdata->smps_mode = IEEE80211_SMPS_OFF;
715 case NL80211_SMPS_STATIC:
716 sdata->smps_mode = IEEE80211_SMPS_STATIC;
718 case NL80211_SMPS_DYNAMIC:
719 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
724 sdata->needed_rx_chains = sdata->local->rx_chains;
726 mutex_lock(&local->mtx);
727 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
728 IEEE80211_CHANCTX_SHARED);
730 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
731 mutex_unlock(&local->mtx);
736 * Apply control port protocol, this allows us to
737 * not encrypt dynamic WEP control frames.
739 sdata->control_port_protocol = params->crypto.control_port_ethertype;
740 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
741 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
745 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
746 vlan->control_port_protocol =
747 params->crypto.control_port_ethertype;
748 vlan->control_port_no_encrypt =
749 params->crypto.control_port_no_encrypt;
750 vlan->encrypt_headroom =
751 ieee80211_cs_headroom(sdata->local,
756 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
757 sdata->vif.bss_conf.dtim_period = params->dtim_period;
758 sdata->vif.bss_conf.enable_beacon = true;
759 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
761 sdata->vif.bss_conf.ssid_len = params->ssid_len;
762 if (params->ssid_len)
763 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
765 sdata->vif.bss_conf.hidden_ssid =
766 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
768 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
769 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
770 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
771 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
772 if (params->p2p_opp_ps)
773 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
774 IEEE80211_P2P_OPPPS_ENABLE_BIT;
776 err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL);
778 ieee80211_vif_release_channel(sdata);
783 err = drv_start_ap(sdata->local, sdata);
785 old = sdata_dereference(sdata->u.ap.beacon, sdata);
788 kfree_rcu(old, rcu_head);
789 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
790 ieee80211_vif_release_channel(sdata);
794 ieee80211_recalc_dtim(local, sdata);
795 ieee80211_bss_info_change_notify(sdata, changed);
797 netif_carrier_on(dev);
798 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
799 netif_carrier_on(vlan->dev);
804 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
805 struct cfg80211_beacon_data *params)
807 struct ieee80211_sub_if_data *sdata;
808 struct beacon_data *old;
811 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
812 sdata_assert_lock(sdata);
814 /* don't allow changing the beacon while CSA is in place - offset
815 * of channel switch counter may change
817 if (sdata->vif.csa_active)
820 old = sdata_dereference(sdata->u.ap.beacon, sdata);
824 err = ieee80211_assign_beacon(sdata, params, NULL);
827 ieee80211_bss_info_change_notify(sdata, err);
831 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
833 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
834 struct ieee80211_sub_if_data *vlan;
835 struct ieee80211_local *local = sdata->local;
836 struct beacon_data *old_beacon;
837 struct probe_resp *old_probe_resp;
838 struct cfg80211_chan_def chandef;
840 sdata_assert_lock(sdata);
842 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
845 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
847 /* abort any running channel switch */
848 mutex_lock(&local->mtx);
849 sdata->vif.csa_active = false;
850 if (sdata->csa_block_tx) {
851 ieee80211_wake_vif_queues(local, sdata,
852 IEEE80211_QUEUE_STOP_REASON_CSA);
853 sdata->csa_block_tx = false;
856 mutex_unlock(&local->mtx);
858 kfree(sdata->u.ap.next_beacon);
859 sdata->u.ap.next_beacon = NULL;
861 /* turn off carrier for this interface and dependent VLANs */
862 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
863 netif_carrier_off(vlan->dev);
864 netif_carrier_off(dev);
866 /* remove beacon and probe response */
867 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
868 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
869 kfree_rcu(old_beacon, rcu_head);
871 kfree_rcu(old_probe_resp, rcu_head);
872 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
874 __sta_info_flush(sdata, true);
875 ieee80211_free_keys(sdata, true);
877 sdata->vif.bss_conf.enable_beacon = false;
878 sdata->vif.bss_conf.ssid_len = 0;
879 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
880 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
882 if (sdata->wdev.cac_started) {
883 chandef = sdata->vif.bss_conf.chandef;
884 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
885 cfg80211_cac_event(sdata->dev, &chandef,
886 NL80211_RADAR_CAC_ABORTED,
890 drv_stop_ap(sdata->local, sdata);
892 /* free all potentially still buffered bcast frames */
893 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
894 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
896 mutex_lock(&local->mtx);
897 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
898 ieee80211_vif_release_channel(sdata);
899 mutex_unlock(&local->mtx);
904 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
905 struct iapp_layer2_update {
906 u8 da[ETH_ALEN]; /* broadcast */
907 u8 sa[ETH_ALEN]; /* STA addr */
915 static void ieee80211_send_layer2_update(struct sta_info *sta)
917 struct iapp_layer2_update *msg;
920 /* Send Level 2 Update Frame to update forwarding tables in layer 2
923 skb = dev_alloc_skb(sizeof(*msg));
926 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
928 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
929 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
931 eth_broadcast_addr(msg->da);
932 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
935 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
936 msg->control = 0xaf; /* XID response lsb.1111F101.
937 * F=0 (no poll command; unsolicited frame) */
938 msg->xid_info[0] = 0x81; /* XID format identifier */
939 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
940 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
942 skb->dev = sta->sdata->dev;
943 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
944 memset(skb->cb, 0, sizeof(skb->cb));
948 static int sta_apply_auth_flags(struct ieee80211_local *local,
949 struct sta_info *sta,
954 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
955 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
956 !test_sta_flag(sta, WLAN_STA_AUTH)) {
957 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
962 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
963 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
964 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
966 * When peer becomes associated, init rate control as
967 * well. Some drivers require rate control initialized
968 * before drv_sta_state() is called.
970 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
971 rate_control_rate_init(sta);
973 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
978 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
979 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
980 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
981 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
982 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
989 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
990 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
991 test_sta_flag(sta, WLAN_STA_ASSOC)) {
992 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
997 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
998 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
999 test_sta_flag(sta, WLAN_STA_AUTH)) {
1000 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1008 static void sta_apply_mesh_params(struct ieee80211_local *local,
1009 struct sta_info *sta,
1010 struct station_parameters *params)
1012 #ifdef CONFIG_MAC80211_MESH
1013 struct ieee80211_sub_if_data *sdata = sta->sdata;
1016 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1017 switch (params->plink_state) {
1018 case NL80211_PLINK_ESTAB:
1019 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1020 changed = mesh_plink_inc_estab_count(sdata);
1021 sta->mesh->plink_state = params->plink_state;
1022 sta->mesh->aid = params->peer_aid;
1024 ieee80211_mps_sta_status_update(sta);
1025 changed |= ieee80211_mps_set_sta_local_pm(sta,
1026 sdata->u.mesh.mshcfg.power_mode);
1028 case NL80211_PLINK_LISTEN:
1029 case NL80211_PLINK_BLOCKED:
1030 case NL80211_PLINK_OPN_SNT:
1031 case NL80211_PLINK_OPN_RCVD:
1032 case NL80211_PLINK_CNF_RCVD:
1033 case NL80211_PLINK_HOLDING:
1034 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1035 changed = mesh_plink_dec_estab_count(sdata);
1036 sta->mesh->plink_state = params->plink_state;
1038 ieee80211_mps_sta_status_update(sta);
1039 changed |= ieee80211_mps_set_sta_local_pm(sta,
1040 NL80211_MESH_POWER_UNKNOWN);
1048 switch (params->plink_action) {
1049 case NL80211_PLINK_ACTION_NO_ACTION:
1052 case NL80211_PLINK_ACTION_OPEN:
1053 changed |= mesh_plink_open(sta);
1055 case NL80211_PLINK_ACTION_BLOCK:
1056 changed |= mesh_plink_block(sta);
1060 if (params->local_pm)
1061 changed |= ieee80211_mps_set_sta_local_pm(sta,
1064 ieee80211_mbss_info_change_notify(sdata, changed);
1068 static int sta_apply_parameters(struct ieee80211_local *local,
1069 struct sta_info *sta,
1070 struct station_parameters *params)
1073 struct ieee80211_supported_band *sband;
1074 struct ieee80211_sub_if_data *sdata = sta->sdata;
1075 enum nl80211_band band = ieee80211_get_sdata_band(sdata);
1078 sband = local->hw.wiphy->bands[band];
1080 mask = params->sta_flags_mask;
1081 set = params->sta_flags_set;
1083 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1085 * In mesh mode, ASSOCIATED isn't part of the nl80211
1086 * API but must follow AUTHENTICATED for driver state.
1088 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1089 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1090 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1091 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1092 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1094 * TDLS -- everything follows authorized, but
1095 * only becoming authorized is possible, not
1098 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1099 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1100 BIT(NL80211_STA_FLAG_ASSOCIATED);
1101 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1102 BIT(NL80211_STA_FLAG_ASSOCIATED);
1106 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1107 local->hw.queues >= IEEE80211_NUM_ACS)
1108 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1110 /* auth flags will be set later for TDLS,
1111 * and for unassociated stations that move to assocaited */
1112 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1113 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1114 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1115 ret = sta_apply_auth_flags(local, sta, mask, set);
1120 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1121 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1122 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1124 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1127 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1128 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1129 if (set & BIT(NL80211_STA_FLAG_MFP))
1130 set_sta_flag(sta, WLAN_STA_MFP);
1132 clear_sta_flag(sta, WLAN_STA_MFP);
1135 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1136 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1137 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1139 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1142 /* mark TDLS channel switch support, if the AP allows it */
1143 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1144 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1145 params->ext_capab_len >= 4 &&
1146 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1147 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1149 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1150 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1151 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1152 params->ext_capab_len >= 8 &&
1153 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1154 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1156 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1157 sta->sta.uapsd_queues = params->uapsd_queues;
1158 sta->sta.max_sp = params->max_sp;
1161 /* The sender might not have sent the last bit, consider it to be 0 */
1162 if (params->ext_capab_len >= 8) {
1163 u8 val = (params->ext_capab[7] &
1164 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1166 /* we did get all the bits, take the MSB as well */
1167 if (params->ext_capab_len >= 9) {
1168 u8 val_msb = params->ext_capab[8] &
1169 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1176 sta->sta.max_amsdu_subframes = 32;
1179 sta->sta.max_amsdu_subframes = 16;
1182 sta->sta.max_amsdu_subframes = 8;
1185 sta->sta.max_amsdu_subframes = 0;
1190 * cfg80211 validates this (1-2007) and allows setting the AID
1191 * only when creating a new station entry
1194 sta->sta.aid = params->aid;
1197 * Some of the following updates would be racy if called on an
1198 * existing station, via ieee80211_change_station(). However,
1199 * all such changes are rejected by cfg80211 except for updates
1200 * changing the supported rates on an existing but not yet used
1204 if (params->listen_interval >= 0)
1205 sta->listen_interval = params->listen_interval;
1207 if (params->supported_rates) {
1208 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1209 sband, params->supported_rates,
1210 params->supported_rates_len,
1211 &sta->sta.supp_rates[band]);
1214 if (params->ht_capa)
1215 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1216 params->ht_capa, sta);
1218 /* VHT can override some HT caps such as the A-MSDU max length */
1219 if (params->vht_capa)
1220 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1221 params->vht_capa, sta);
1223 if (params->opmode_notif_used) {
1224 /* returned value is only needed for rc update, but the
1225 * rc isn't initialized here yet, so ignore it
1227 __ieee80211_vht_handle_opmode(sdata, sta,
1228 params->opmode_notif, band);
1231 if (params->support_p2p_ps >= 0)
1232 sta->sta.support_p2p_ps = params->support_p2p_ps;
1234 if (ieee80211_vif_is_mesh(&sdata->vif))
1235 sta_apply_mesh_params(local, sta, params);
1237 /* set the STA state after all sta info from usermode has been set */
1238 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1239 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1240 ret = sta_apply_auth_flags(local, sta, mask, set);
1248 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1250 struct station_parameters *params)
1252 struct ieee80211_local *local = wiphy_priv(wiphy);
1253 struct sta_info *sta;
1254 struct ieee80211_sub_if_data *sdata;
1259 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1261 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1262 sdata->vif.type != NL80211_IFTYPE_AP)
1265 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1267 if (ether_addr_equal(mac, sdata->vif.addr))
1270 if (is_multicast_ether_addr(mac))
1273 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1277 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1278 sta->sta.tdls = true;
1280 err = sta_apply_parameters(local, sta, params);
1282 sta_info_free(local, sta);
1287 * for TDLS and for unassociated station, rate control should be
1288 * initialized only when rates are known and station is marked
1289 * authorized/associated
1291 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1292 test_sta_flag(sta, WLAN_STA_ASSOC))
1293 rate_control_rate_init(sta);
1295 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1296 sdata->vif.type == NL80211_IFTYPE_AP;
1298 err = sta_info_insert_rcu(sta);
1305 ieee80211_send_layer2_update(sta);
1312 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1313 struct station_del_parameters *params)
1315 struct ieee80211_sub_if_data *sdata;
1317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1320 return sta_info_destroy_addr_bss(sdata, params->mac);
1322 sta_info_flush(sdata);
1326 static int ieee80211_change_station(struct wiphy *wiphy,
1327 struct net_device *dev, const u8 *mac,
1328 struct station_parameters *params)
1330 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1331 struct ieee80211_local *local = wiphy_priv(wiphy);
1332 struct sta_info *sta;
1333 struct ieee80211_sub_if_data *vlansdata;
1334 enum cfg80211_station_type statype;
1337 mutex_lock(&local->sta_mtx);
1339 sta = sta_info_get_bss(sdata, mac);
1345 switch (sdata->vif.type) {
1346 case NL80211_IFTYPE_MESH_POINT:
1347 if (sdata->u.mesh.user_mpm)
1348 statype = CFG80211_STA_MESH_PEER_USER;
1350 statype = CFG80211_STA_MESH_PEER_KERNEL;
1352 case NL80211_IFTYPE_ADHOC:
1353 statype = CFG80211_STA_IBSS;
1355 case NL80211_IFTYPE_STATION:
1356 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1357 statype = CFG80211_STA_AP_STA;
1360 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1361 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1363 statype = CFG80211_STA_TDLS_PEER_SETUP;
1365 case NL80211_IFTYPE_AP:
1366 case NL80211_IFTYPE_AP_VLAN:
1367 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1368 statype = CFG80211_STA_AP_CLIENT;
1370 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1377 err = cfg80211_check_station_change(wiphy, params, statype);
1381 if (params->vlan && params->vlan != sta->sdata->dev) {
1382 bool prev_4addr = false;
1383 bool new_4addr = false;
1385 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1387 if (params->vlan->ieee80211_ptr->use_4addr) {
1388 if (vlansdata->u.vlan.sta) {
1393 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1395 __ieee80211_check_fast_rx_iface(vlansdata);
1398 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1399 sta->sdata->u.vlan.sta) {
1400 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1404 sta->sdata = vlansdata;
1405 ieee80211_check_fast_xmit(sta);
1407 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1408 prev_4addr != new_4addr) {
1410 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1412 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1415 ieee80211_send_layer2_update(sta);
1418 err = sta_apply_parameters(local, sta, params);
1422 mutex_unlock(&local->sta_mtx);
1424 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1425 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1426 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1427 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1428 sta_info_tx_streams(sta) != 1) {
1430 "%pM just authorized and MIMO capable - update SMPS\n",
1432 ieee80211_send_smps_action(sta->sdata,
1433 sta->sdata->bss->req_smps,
1435 sta->sdata->vif.bss_conf.bssid);
1438 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1439 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1440 ieee80211_recalc_ps(local);
1441 ieee80211_recalc_ps_vif(sdata);
1446 mutex_unlock(&local->sta_mtx);
1450 #ifdef CONFIG_MAC80211_MESH
1451 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1452 const u8 *dst, const u8 *next_hop)
1454 struct ieee80211_sub_if_data *sdata;
1455 struct mesh_path *mpath;
1456 struct sta_info *sta;
1458 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1461 sta = sta_info_get(sdata, next_hop);
1467 mpath = mesh_path_add(sdata, dst);
1468 if (IS_ERR(mpath)) {
1470 return PTR_ERR(mpath);
1473 mesh_path_fix_nexthop(mpath, sta);
1479 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1482 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1485 return mesh_path_del(sdata, dst);
1487 mesh_path_flush_by_iface(sdata);
1491 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1492 const u8 *dst, const u8 *next_hop)
1494 struct ieee80211_sub_if_data *sdata;
1495 struct mesh_path *mpath;
1496 struct sta_info *sta;
1498 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1502 sta = sta_info_get(sdata, next_hop);
1508 mpath = mesh_path_lookup(sdata, dst);
1514 mesh_path_fix_nexthop(mpath, sta);
1520 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1521 struct mpath_info *pinfo)
1523 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1526 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1528 eth_zero_addr(next_hop);
1530 memset(pinfo, 0, sizeof(*pinfo));
1532 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
1534 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1537 MPATH_INFO_EXPTIME |
1538 MPATH_INFO_DISCOVERY_TIMEOUT |
1539 MPATH_INFO_DISCOVERY_RETRIES |
1542 pinfo->frame_qlen = mpath->frame_queue.qlen;
1543 pinfo->sn = mpath->sn;
1544 pinfo->metric = mpath->metric;
1545 if (time_before(jiffies, mpath->exp_time))
1546 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1547 pinfo->discovery_timeout =
1548 jiffies_to_msecs(mpath->discovery_timeout);
1549 pinfo->discovery_retries = mpath->discovery_retries;
1550 if (mpath->flags & MESH_PATH_ACTIVE)
1551 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1552 if (mpath->flags & MESH_PATH_RESOLVING)
1553 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1554 if (mpath->flags & MESH_PATH_SN_VALID)
1555 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1556 if (mpath->flags & MESH_PATH_FIXED)
1557 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1558 if (mpath->flags & MESH_PATH_RESOLVED)
1559 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1562 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1563 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1566 struct ieee80211_sub_if_data *sdata;
1567 struct mesh_path *mpath;
1569 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1572 mpath = mesh_path_lookup(sdata, dst);
1577 memcpy(dst, mpath->dst, ETH_ALEN);
1578 mpath_set_pinfo(mpath, next_hop, pinfo);
1583 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1584 int idx, u8 *dst, u8 *next_hop,
1585 struct mpath_info *pinfo)
1587 struct ieee80211_sub_if_data *sdata;
1588 struct mesh_path *mpath;
1590 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1593 mpath = mesh_path_lookup_by_idx(sdata, idx);
1598 memcpy(dst, mpath->dst, ETH_ALEN);
1599 mpath_set_pinfo(mpath, next_hop, pinfo);
1604 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1605 struct mpath_info *pinfo)
1607 memset(pinfo, 0, sizeof(*pinfo));
1608 memcpy(mpp, mpath->mpp, ETH_ALEN);
1610 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
1613 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1614 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1617 struct ieee80211_sub_if_data *sdata;
1618 struct mesh_path *mpath;
1620 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1623 mpath = mpp_path_lookup(sdata, dst);
1628 memcpy(dst, mpath->dst, ETH_ALEN);
1629 mpp_set_pinfo(mpath, mpp, pinfo);
1634 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1635 int idx, u8 *dst, u8 *mpp,
1636 struct mpath_info *pinfo)
1638 struct ieee80211_sub_if_data *sdata;
1639 struct mesh_path *mpath;
1641 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1644 mpath = mpp_path_lookup_by_idx(sdata, idx);
1649 memcpy(dst, mpath->dst, ETH_ALEN);
1650 mpp_set_pinfo(mpath, mpp, pinfo);
1655 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1656 struct net_device *dev,
1657 struct mesh_config *conf)
1659 struct ieee80211_sub_if_data *sdata;
1660 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1662 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1666 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1668 return (mask >> (parm-1)) & 0x1;
1671 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1672 const struct mesh_setup *setup)
1676 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1677 struct ieee80211_sub_if_data, u.mesh);
1679 /* allocate information elements */
1683 if (setup->ie_len) {
1684 new_ie = kmemdup(setup->ie, setup->ie_len,
1689 ifmsh->ie_len = setup->ie_len;
1693 /* now copy the rest of the setup parameters */
1694 ifmsh->mesh_id_len = setup->mesh_id_len;
1695 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1696 ifmsh->mesh_sp_id = setup->sync_method;
1697 ifmsh->mesh_pp_id = setup->path_sel_proto;
1698 ifmsh->mesh_pm_id = setup->path_metric;
1699 ifmsh->user_mpm = setup->user_mpm;
1700 ifmsh->mesh_auth_id = setup->auth_id;
1701 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1702 if (setup->is_authenticated)
1703 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1704 if (setup->is_secure)
1705 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1707 /* mcast rate setting in Mesh Node */
1708 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1709 sizeof(setup->mcast_rate));
1710 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
1712 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1713 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1718 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1719 struct net_device *dev, u32 mask,
1720 const struct mesh_config *nconf)
1722 struct mesh_config *conf;
1723 struct ieee80211_sub_if_data *sdata;
1724 struct ieee80211_if_mesh *ifmsh;
1726 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1727 ifmsh = &sdata->u.mesh;
1729 /* Set the config options which we are interested in setting */
1730 conf = &(sdata->u.mesh.mshcfg);
1731 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1732 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1733 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1734 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1735 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1736 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1737 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1738 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1739 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1740 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1741 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1742 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1743 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1744 conf->element_ttl = nconf->element_ttl;
1745 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1746 if (ifmsh->user_mpm)
1748 conf->auto_open_plinks = nconf->auto_open_plinks;
1750 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1751 conf->dot11MeshNbrOffsetMaxNeighbor =
1752 nconf->dot11MeshNbrOffsetMaxNeighbor;
1753 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1754 conf->dot11MeshHWMPmaxPREQretries =
1755 nconf->dot11MeshHWMPmaxPREQretries;
1756 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1757 conf->path_refresh_time = nconf->path_refresh_time;
1758 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1759 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1760 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1761 conf->dot11MeshHWMPactivePathTimeout =
1762 nconf->dot11MeshHWMPactivePathTimeout;
1763 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1764 conf->dot11MeshHWMPpreqMinInterval =
1765 nconf->dot11MeshHWMPpreqMinInterval;
1766 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1767 conf->dot11MeshHWMPperrMinInterval =
1768 nconf->dot11MeshHWMPperrMinInterval;
1769 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1771 conf->dot11MeshHWMPnetDiameterTraversalTime =
1772 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1773 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1774 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1775 ieee80211_mesh_root_setup(ifmsh);
1777 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1778 /* our current gate announcement implementation rides on root
1779 * announcements, so require this ifmsh to also be a root node
1781 if (nconf->dot11MeshGateAnnouncementProtocol &&
1782 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1783 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
1784 ieee80211_mesh_root_setup(ifmsh);
1786 conf->dot11MeshGateAnnouncementProtocol =
1787 nconf->dot11MeshGateAnnouncementProtocol;
1789 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
1790 conf->dot11MeshHWMPRannInterval =
1791 nconf->dot11MeshHWMPRannInterval;
1792 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1793 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1794 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1795 /* our RSSI threshold implementation is supported only for
1796 * devices that report signal in dBm.
1798 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
1800 conf->rssi_threshold = nconf->rssi_threshold;
1802 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1803 conf->ht_opmode = nconf->ht_opmode;
1804 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1805 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1807 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1808 conf->dot11MeshHWMPactivePathToRootTimeout =
1809 nconf->dot11MeshHWMPactivePathToRootTimeout;
1810 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1811 conf->dot11MeshHWMProotInterval =
1812 nconf->dot11MeshHWMProotInterval;
1813 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1814 conf->dot11MeshHWMPconfirmationInterval =
1815 nconf->dot11MeshHWMPconfirmationInterval;
1816 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1817 conf->power_mode = nconf->power_mode;
1818 ieee80211_mps_local_status_update(sdata);
1820 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
1821 conf->dot11MeshAwakeWindowDuration =
1822 nconf->dot11MeshAwakeWindowDuration;
1823 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1824 conf->plink_timeout = nconf->plink_timeout;
1825 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
1829 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1830 const struct mesh_config *conf,
1831 const struct mesh_setup *setup)
1833 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1834 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1837 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1838 err = copy_mesh_setup(ifmsh, setup);
1842 /* can mesh use other SMPS modes? */
1843 sdata->smps_mode = IEEE80211_SMPS_OFF;
1844 sdata->needed_rx_chains = sdata->local->rx_chains;
1846 mutex_lock(&sdata->local->mtx);
1847 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
1848 IEEE80211_CHANCTX_SHARED);
1849 mutex_unlock(&sdata->local->mtx);
1853 return ieee80211_start_mesh(sdata);
1856 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1858 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1860 ieee80211_stop_mesh(sdata);
1861 mutex_lock(&sdata->local->mtx);
1862 ieee80211_vif_release_channel(sdata);
1863 mutex_unlock(&sdata->local->mtx);
1869 static int ieee80211_change_bss(struct wiphy *wiphy,
1870 struct net_device *dev,
1871 struct bss_parameters *params)
1873 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1874 enum nl80211_band band;
1877 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
1880 band = ieee80211_get_sdata_band(sdata);
1882 if (params->use_cts_prot >= 0) {
1883 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1884 changed |= BSS_CHANGED_ERP_CTS_PROT;
1886 if (params->use_short_preamble >= 0) {
1887 sdata->vif.bss_conf.use_short_preamble =
1888 params->use_short_preamble;
1889 changed |= BSS_CHANGED_ERP_PREAMBLE;
1892 if (!sdata->vif.bss_conf.use_short_slot &&
1893 band == NL80211_BAND_5GHZ) {
1894 sdata->vif.bss_conf.use_short_slot = true;
1895 changed |= BSS_CHANGED_ERP_SLOT;
1898 if (params->use_short_slot_time >= 0) {
1899 sdata->vif.bss_conf.use_short_slot =
1900 params->use_short_slot_time;
1901 changed |= BSS_CHANGED_ERP_SLOT;
1904 if (params->basic_rates) {
1905 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1907 params->basic_rates,
1908 params->basic_rates_len,
1909 &sdata->vif.bss_conf.basic_rates);
1910 changed |= BSS_CHANGED_BASIC_RATES;
1913 if (params->ap_isolate >= 0) {
1914 if (params->ap_isolate)
1915 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1917 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1918 ieee80211_check_fast_rx_iface(sdata);
1921 if (params->ht_opmode >= 0) {
1922 sdata->vif.bss_conf.ht_operation_mode =
1923 (u16) params->ht_opmode;
1924 changed |= BSS_CHANGED_HT;
1927 if (params->p2p_ctwindow >= 0) {
1928 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1929 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1930 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1931 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1932 changed |= BSS_CHANGED_P2P_PS;
1935 if (params->p2p_opp_ps > 0) {
1936 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1937 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1938 changed |= BSS_CHANGED_P2P_PS;
1939 } else if (params->p2p_opp_ps == 0) {
1940 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1941 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
1942 changed |= BSS_CHANGED_P2P_PS;
1945 ieee80211_bss_info_change_notify(sdata, changed);
1950 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1951 struct net_device *dev,
1952 struct ieee80211_txq_params *params)
1954 struct ieee80211_local *local = wiphy_priv(wiphy);
1955 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1956 struct ieee80211_tx_queue_params p;
1958 if (!local->ops->conf_tx)
1961 if (local->hw.queues < IEEE80211_NUM_ACS)
1964 memset(&p, 0, sizeof(p));
1965 p.aifs = params->aifs;
1966 p.cw_max = params->cwmax;
1967 p.cw_min = params->cwmin;
1968 p.txop = params->txop;
1971 * Setting tx queue params disables u-apsd because it's only
1972 * called in master mode.
1976 sdata->tx_conf[params->ac] = p;
1977 if (drv_conf_tx(local, sdata, params->ac, &p)) {
1978 wiphy_debug(local->hw.wiphy,
1979 "failed to set TX queue parameters for AC %d\n",
1984 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1990 static int ieee80211_suspend(struct wiphy *wiphy,
1991 struct cfg80211_wowlan *wowlan)
1993 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1996 static int ieee80211_resume(struct wiphy *wiphy)
1998 return __ieee80211_resume(wiphy_priv(wiphy));
2001 #define ieee80211_suspend NULL
2002 #define ieee80211_resume NULL
2005 static int ieee80211_scan(struct wiphy *wiphy,
2006 struct cfg80211_scan_request *req)
2008 struct ieee80211_sub_if_data *sdata;
2010 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2012 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2013 case NL80211_IFTYPE_STATION:
2014 case NL80211_IFTYPE_ADHOC:
2015 case NL80211_IFTYPE_MESH_POINT:
2016 case NL80211_IFTYPE_P2P_CLIENT:
2017 case NL80211_IFTYPE_P2P_DEVICE:
2019 case NL80211_IFTYPE_P2P_GO:
2020 if (sdata->local->ops->hw_scan)
2023 * FIXME: implement NoA while scanning in software,
2024 * for now fall through to allow scanning only when
2025 * beaconing hasn't been configured yet
2027 case NL80211_IFTYPE_AP:
2029 * If the scan has been forced (and the driver supports
2030 * forcing), don't care about being beaconing already.
2031 * This will create problems to the attached stations (e.g. all
2032 * the frames sent while scanning on other channel will be
2035 if (sdata->u.ap.beacon &&
2036 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2037 !(req->flags & NL80211_SCAN_FLAG_AP)))
2040 case NL80211_IFTYPE_NAN:
2045 return ieee80211_request_scan(sdata, req);
2048 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2050 ieee80211_scan_cancel(wiphy_priv(wiphy));
2054 ieee80211_sched_scan_start(struct wiphy *wiphy,
2055 struct net_device *dev,
2056 struct cfg80211_sched_scan_request *req)
2058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2060 if (!sdata->local->ops->sched_scan_start)
2063 return ieee80211_request_sched_scan_start(sdata, req);
2067 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
2069 struct ieee80211_local *local = wiphy_priv(wiphy);
2071 if (!local->ops->sched_scan_stop)
2074 return ieee80211_request_sched_scan_stop(local);
2077 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2078 struct cfg80211_auth_request *req)
2080 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2083 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2084 struct cfg80211_assoc_request *req)
2086 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2089 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2090 struct cfg80211_deauth_request *req)
2092 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2095 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2096 struct cfg80211_disassoc_request *req)
2098 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2101 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2102 struct cfg80211_ibss_params *params)
2104 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2107 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2109 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2112 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2113 struct ocb_setup *setup)
2115 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2118 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2120 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2123 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2124 int rate[NUM_NL80211_BANDS])
2126 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2128 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2129 sizeof(int) * NUM_NL80211_BANDS);
2134 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2136 struct ieee80211_local *local = wiphy_priv(wiphy);
2139 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2140 ieee80211_check_fast_xmit_all(local);
2142 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2145 ieee80211_check_fast_xmit_all(local);
2150 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2151 (changed & WIPHY_PARAM_DYN_ACK)) {
2154 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2155 wiphy->coverage_class : -1;
2156 err = drv_set_coverage_class(local, coverage_class);
2162 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2163 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2169 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2170 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2172 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2174 if (changed & WIPHY_PARAM_RETRY_LONG) {
2175 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2177 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2180 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2181 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2186 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2187 struct wireless_dev *wdev,
2188 enum nl80211_tx_power_setting type, int mbm)
2190 struct ieee80211_local *local = wiphy_priv(wiphy);
2191 struct ieee80211_sub_if_data *sdata;
2192 enum nl80211_tx_power_setting txp_type = type;
2193 bool update_txp_type = false;
2196 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2199 case NL80211_TX_POWER_AUTOMATIC:
2200 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2201 txp_type = NL80211_TX_POWER_LIMITED;
2203 case NL80211_TX_POWER_LIMITED:
2204 case NL80211_TX_POWER_FIXED:
2205 if (mbm < 0 || (mbm % 100))
2207 sdata->user_power_level = MBM_TO_DBM(mbm);
2211 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2212 update_txp_type = true;
2213 sdata->vif.bss_conf.txpower_type = txp_type;
2216 ieee80211_recalc_txpower(sdata, update_txp_type);
2222 case NL80211_TX_POWER_AUTOMATIC:
2223 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2224 txp_type = NL80211_TX_POWER_LIMITED;
2226 case NL80211_TX_POWER_LIMITED:
2227 case NL80211_TX_POWER_FIXED:
2228 if (mbm < 0 || (mbm % 100))
2230 local->user_power_level = MBM_TO_DBM(mbm);
2234 mutex_lock(&local->iflist_mtx);
2235 list_for_each_entry(sdata, &local->interfaces, list) {
2236 sdata->user_power_level = local->user_power_level;
2237 if (txp_type != sdata->vif.bss_conf.txpower_type)
2238 update_txp_type = true;
2239 sdata->vif.bss_conf.txpower_type = txp_type;
2241 list_for_each_entry(sdata, &local->interfaces, list)
2242 ieee80211_recalc_txpower(sdata, update_txp_type);
2243 mutex_unlock(&local->iflist_mtx);
2248 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2249 struct wireless_dev *wdev,
2252 struct ieee80211_local *local = wiphy_priv(wiphy);
2253 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2255 if (local->ops->get_txpower)
2256 return drv_get_txpower(local, sdata, dbm);
2258 if (!local->use_chanctx)
2259 *dbm = local->hw.conf.power_level;
2261 *dbm = sdata->vif.bss_conf.txpower;
2266 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2269 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2271 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2276 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2278 struct ieee80211_local *local = wiphy_priv(wiphy);
2280 drv_rfkill_poll(local);
2283 #ifdef CONFIG_NL80211_TESTMODE
2284 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2285 struct wireless_dev *wdev,
2286 void *data, int len)
2288 struct ieee80211_local *local = wiphy_priv(wiphy);
2289 struct ieee80211_vif *vif = NULL;
2291 if (!local->ops->testmode_cmd)
2295 struct ieee80211_sub_if_data *sdata;
2297 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2298 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2302 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2305 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2306 struct sk_buff *skb,
2307 struct netlink_callback *cb,
2308 void *data, int len)
2310 struct ieee80211_local *local = wiphy_priv(wiphy);
2312 if (!local->ops->testmode_dump)
2315 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2319 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2320 enum ieee80211_smps_mode smps_mode)
2322 struct sta_info *sta;
2323 enum ieee80211_smps_mode old_req;
2325 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2328 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2331 old_req = sdata->u.ap.req_smps;
2332 sdata->u.ap.req_smps = smps_mode;
2334 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2335 if (old_req == smps_mode ||
2336 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2339 /* If no associated stations, there's no need to do anything */
2340 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2341 sdata->smps_mode = smps_mode;
2342 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2347 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
2348 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2350 mutex_lock(&sdata->local->sta_mtx);
2351 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2353 * Only stations associated to our AP and
2356 if (sta->sdata->bss != &sdata->u.ap)
2359 /* This station doesn't support MIMO - skip it */
2360 if (sta_info_tx_streams(sta) == 1)
2364 * Don't wake up a STA just to send the action frame
2365 * unless we are getting more restrictive.
2367 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2368 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2370 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2376 * If the STA is not authorized, wait until it gets
2377 * authorized and the action frame will be sent then.
2379 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2382 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2383 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2384 sdata->vif.bss_conf.bssid);
2386 mutex_unlock(&sdata->local->sta_mtx);
2388 sdata->smps_mode = smps_mode;
2389 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2394 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2395 enum ieee80211_smps_mode smps_mode)
2398 enum ieee80211_smps_mode old_req;
2400 struct sta_info *sta;
2401 bool tdls_peer_found = false;
2403 lockdep_assert_held(&sdata->wdev.mtx);
2405 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2408 old_req = sdata->u.mgd.req_smps;
2409 sdata->u.mgd.req_smps = smps_mode;
2411 if (old_req == smps_mode &&
2412 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2416 * If not associated, or current association is not an HT
2417 * association, there's no need to do anything, just store
2418 * the new value until we associate.
2420 if (!sdata->u.mgd.associated ||
2421 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2424 ap = sdata->u.mgd.associated->bssid;
2427 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2428 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2429 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2432 tdls_peer_found = true;
2437 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2438 if (tdls_peer_found || !sdata->u.mgd.powersave)
2439 smps_mode = IEEE80211_SMPS_OFF;
2441 smps_mode = IEEE80211_SMPS_DYNAMIC;
2444 /* send SM PS frame to AP */
2445 err = ieee80211_send_smps_action(sdata, smps_mode,
2448 sdata->u.mgd.req_smps = old_req;
2449 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2450 ieee80211_teardown_tdls_peers(sdata);
2455 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2456 bool enabled, int timeout)
2458 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2459 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2461 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2464 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
2467 if (enabled == sdata->u.mgd.powersave &&
2468 timeout == local->dynamic_ps_forced_timeout)
2471 sdata->u.mgd.powersave = enabled;
2472 local->dynamic_ps_forced_timeout = timeout;
2474 /* no change, but if automatic follow powersave */
2476 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2477 sdata_unlock(sdata);
2479 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
2480 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2482 ieee80211_recalc_ps(local);
2483 ieee80211_recalc_ps_vif(sdata);
2488 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2489 struct net_device *dev,
2490 s32 rssi_thold, u32 rssi_hyst)
2492 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2493 struct ieee80211_vif *vif = &sdata->vif;
2494 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2496 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2497 rssi_hyst == bss_conf->cqm_rssi_hyst)
2500 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2501 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2504 bss_conf->cqm_rssi_thold = rssi_thold;
2505 bss_conf->cqm_rssi_hyst = rssi_hyst;
2506 sdata->u.mgd.last_cqm_event_signal = 0;
2508 /* tell the driver upon association, unless already associated */
2509 if (sdata->u.mgd.associated &&
2510 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2511 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2516 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2517 struct net_device *dev,
2519 const struct cfg80211_bitrate_mask *mask)
2521 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2522 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2525 if (!ieee80211_sdata_running(sdata))
2528 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
2529 ret = drv_set_bitrate_mask(local, sdata, mask);
2534 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2535 struct ieee80211_supported_band *sband = wiphy->bands[i];
2538 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2539 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2540 sizeof(mask->control[i].ht_mcs));
2541 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
2542 mask->control[i].vht_mcs,
2543 sizeof(mask->control[i].vht_mcs));
2545 sdata->rc_has_mcs_mask[i] = false;
2546 sdata->rc_has_vht_mcs_mask[i] = false;
2550 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
2551 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2552 sdata->rc_has_mcs_mask[i] = true;
2557 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
2558 if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
2559 sdata->rc_has_vht_mcs_mask[i] = true;
2568 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2569 struct net_device *dev,
2570 struct cfg80211_chan_def *chandef,
2573 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2574 struct ieee80211_local *local = sdata->local;
2577 mutex_lock(&local->mtx);
2578 if (!list_empty(&local->roc_list) || local->scanning) {
2583 /* whatever, but channel contexts should not complain about that one */
2584 sdata->smps_mode = IEEE80211_SMPS_OFF;
2585 sdata->needed_rx_chains = local->rx_chains;
2587 err = ieee80211_vif_use_channel(sdata, chandef,
2588 IEEE80211_CHANCTX_SHARED);
2592 ieee80211_queue_delayed_work(&sdata->local->hw,
2593 &sdata->dfs_cac_timer_work,
2594 msecs_to_jiffies(cac_time_ms));
2597 mutex_unlock(&local->mtx);
2601 static struct cfg80211_beacon_data *
2602 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2604 struct cfg80211_beacon_data *new_beacon;
2608 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2609 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2610 beacon->probe_resp_len;
2612 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2616 pos = (u8 *)(new_beacon + 1);
2617 if (beacon->head_len) {
2618 new_beacon->head_len = beacon->head_len;
2619 new_beacon->head = pos;
2620 memcpy(pos, beacon->head, beacon->head_len);
2621 pos += beacon->head_len;
2623 if (beacon->tail_len) {
2624 new_beacon->tail_len = beacon->tail_len;
2625 new_beacon->tail = pos;
2626 memcpy(pos, beacon->tail, beacon->tail_len);
2627 pos += beacon->tail_len;
2629 if (beacon->beacon_ies_len) {
2630 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2631 new_beacon->beacon_ies = pos;
2632 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2633 pos += beacon->beacon_ies_len;
2635 if (beacon->proberesp_ies_len) {
2636 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2637 new_beacon->proberesp_ies = pos;
2638 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2639 pos += beacon->proberesp_ies_len;
2641 if (beacon->assocresp_ies_len) {
2642 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2643 new_beacon->assocresp_ies = pos;
2644 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2645 pos += beacon->assocresp_ies_len;
2647 if (beacon->probe_resp_len) {
2648 new_beacon->probe_resp_len = beacon->probe_resp_len;
2649 beacon->probe_resp = pos;
2650 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2651 pos += beacon->probe_resp_len;
2657 void ieee80211_csa_finish(struct ieee80211_vif *vif)
2659 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2661 ieee80211_queue_work(&sdata->local->hw,
2662 &sdata->csa_finalize_work);
2664 EXPORT_SYMBOL(ieee80211_csa_finish);
2666 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2671 switch (sdata->vif.type) {
2672 case NL80211_IFTYPE_AP:
2673 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2675 kfree(sdata->u.ap.next_beacon);
2676 sdata->u.ap.next_beacon = NULL;
2682 case NL80211_IFTYPE_ADHOC:
2683 err = ieee80211_ibss_finish_csa(sdata);
2688 #ifdef CONFIG_MAC80211_MESH
2689 case NL80211_IFTYPE_MESH_POINT:
2690 err = ieee80211_mesh_finish_csa(sdata);
2704 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2706 struct ieee80211_local *local = sdata->local;
2710 sdata_assert_lock(sdata);
2711 lockdep_assert_held(&local->mtx);
2712 lockdep_assert_held(&local->chanctx_mtx);
2715 * using reservation isn't immediate as it may be deferred until later
2716 * with multi-vif. once reservation is complete it will re-schedule the
2717 * work with no reserved_chanctx so verify chandef to check if it
2718 * completed successfully
2721 if (sdata->reserved_chanctx) {
2723 * with multi-vif csa driver may call ieee80211_csa_finish()
2724 * many times while waiting for other interfaces to use their
2727 if (sdata->reserved_ready)
2730 return ieee80211_vif_use_reserved_context(sdata);
2733 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2734 &sdata->csa_chandef))
2737 sdata->vif.csa_active = false;
2739 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2743 ieee80211_bss_info_change_notify(sdata, changed);
2745 if (sdata->csa_block_tx) {
2746 ieee80211_wake_vif_queues(local, sdata,
2747 IEEE80211_QUEUE_STOP_REASON_CSA);
2748 sdata->csa_block_tx = false;
2751 err = drv_post_channel_switch(sdata);
2755 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2760 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2762 if (__ieee80211_csa_finalize(sdata)) {
2763 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2764 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2769 void ieee80211_csa_finalize_work(struct work_struct *work)
2771 struct ieee80211_sub_if_data *sdata =
2772 container_of(work, struct ieee80211_sub_if_data,
2774 struct ieee80211_local *local = sdata->local;
2777 mutex_lock(&local->mtx);
2778 mutex_lock(&local->chanctx_mtx);
2780 /* AP might have been stopped while waiting for the lock. */
2781 if (!sdata->vif.csa_active)
2784 if (!ieee80211_sdata_running(sdata))
2787 ieee80211_csa_finalize(sdata);
2790 mutex_unlock(&local->chanctx_mtx);
2791 mutex_unlock(&local->mtx);
2792 sdata_unlock(sdata);
2795 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
2796 struct cfg80211_csa_settings *params,
2799 struct ieee80211_csa_settings csa = {};
2802 switch (sdata->vif.type) {
2803 case NL80211_IFTYPE_AP:
2804 sdata->u.ap.next_beacon =
2805 cfg80211_beacon_dup(¶ms->beacon_after);
2806 if (!sdata->u.ap.next_beacon)
2810 * With a count of 0, we don't have to wait for any
2811 * TBTT before switching, so complete the CSA
2812 * immediately. In theory, with a count == 1 we
2813 * should delay the switch until just before the next
2814 * TBTT, but that would complicate things so we switch
2815 * immediately too. If we would delay the switch
2816 * until the next TBTT, we would have to set the probe
2819 * TODO: A channel switch with count <= 1 without
2820 * sending a CSA action frame is kind of useless,
2821 * because the clients won't know we're changing
2822 * channels. The action frame must be implemented
2823 * either here or in the userspace.
2825 if (params->count <= 1)
2828 if ((params->n_counter_offsets_beacon >
2829 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
2830 (params->n_counter_offsets_presp >
2831 IEEE80211_MAX_CSA_COUNTERS_NUM))
2834 csa.counter_offsets_beacon = params->counter_offsets_beacon;
2835 csa.counter_offsets_presp = params->counter_offsets_presp;
2836 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
2837 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
2838 csa.count = params->count;
2840 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa);
2842 kfree(sdata->u.ap.next_beacon);
2848 case NL80211_IFTYPE_ADHOC:
2849 if (!sdata->vif.bss_conf.ibss_joined)
2852 if (params->chandef.width != sdata->u.ibss.chandef.width)
2855 switch (params->chandef.width) {
2856 case NL80211_CHAN_WIDTH_40:
2857 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2858 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
2860 case NL80211_CHAN_WIDTH_5:
2861 case NL80211_CHAN_WIDTH_10:
2862 case NL80211_CHAN_WIDTH_20_NOHT:
2863 case NL80211_CHAN_WIDTH_20:
2869 /* changes into another band are not supported */
2870 if (sdata->u.ibss.chandef.chan->band !=
2871 params->chandef.chan->band)
2874 /* see comments in the NL80211_IFTYPE_AP block */
2875 if (params->count > 1) {
2876 err = ieee80211_ibss_csa_beacon(sdata, params);
2882 ieee80211_send_action_csa(sdata, params);
2885 #ifdef CONFIG_MAC80211_MESH
2886 case NL80211_IFTYPE_MESH_POINT: {
2887 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2889 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
2892 /* changes into another band are not supported */
2893 if (sdata->vif.bss_conf.chandef.chan->band !=
2894 params->chandef.chan->band)
2897 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
2898 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
2899 if (!ifmsh->pre_value)
2900 ifmsh->pre_value = 1;
2905 /* see comments in the NL80211_IFTYPE_AP block */
2906 if (params->count > 1) {
2907 err = ieee80211_mesh_csa_beacon(sdata, params);
2909 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
2915 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
2916 ieee80211_send_action_csa(sdata, params);
2929 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
2930 struct cfg80211_csa_settings *params)
2932 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2933 struct ieee80211_local *local = sdata->local;
2934 struct ieee80211_channel_switch ch_switch;
2935 struct ieee80211_chanctx_conf *conf;
2936 struct ieee80211_chanctx *chanctx;
2940 sdata_assert_lock(sdata);
2941 lockdep_assert_held(&local->mtx);
2943 if (!list_empty(&local->roc_list) || local->scanning)
2946 if (sdata->wdev.cac_started)
2949 if (cfg80211_chandef_identical(¶ms->chandef,
2950 &sdata->vif.bss_conf.chandef))
2953 /* don't allow another channel switch if one is already active. */
2954 if (sdata->vif.csa_active)
2957 mutex_lock(&local->chanctx_mtx);
2958 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
2959 lockdep_is_held(&local->chanctx_mtx));
2965 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
2967 ch_switch.timestamp = 0;
2968 ch_switch.device_timestamp = 0;
2969 ch_switch.block_tx = params->block_tx;
2970 ch_switch.chandef = params->chandef;
2971 ch_switch.count = params->count;
2973 err = drv_pre_channel_switch(sdata, &ch_switch);
2977 err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef,
2979 params->radar_required);
2983 /* if reservation is invalid then this will fail */
2984 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
2986 ieee80211_vif_unreserve_chanctx(sdata);
2990 err = ieee80211_set_csa_beacon(sdata, params, &changed);
2992 ieee80211_vif_unreserve_chanctx(sdata);
2996 sdata->csa_chandef = params->chandef;
2997 sdata->csa_block_tx = params->block_tx;
2998 sdata->vif.csa_active = true;
3000 if (sdata->csa_block_tx)
3001 ieee80211_stop_vif_queues(local, sdata,
3002 IEEE80211_QUEUE_STOP_REASON_CSA);
3004 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3008 ieee80211_bss_info_change_notify(sdata, changed);
3009 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3011 /* if the beacon didn't change, we can finalize immediately */
3012 ieee80211_csa_finalize(sdata);
3016 mutex_unlock(&local->chanctx_mtx);
3020 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3021 struct cfg80211_csa_settings *params)
3023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3024 struct ieee80211_local *local = sdata->local;
3027 mutex_lock(&local->mtx);
3028 err = __ieee80211_channel_switch(wiphy, dev, params);
3029 mutex_unlock(&local->mtx);
3034 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3036 lockdep_assert_held(&local->mtx);
3038 local->roc_cookie_counter++;
3040 /* wow, you wrapped 64 bits ... more likely a bug */
3041 if (WARN_ON(local->roc_cookie_counter == 0))
3042 local->roc_cookie_counter++;
3044 return local->roc_cookie_counter;
3047 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3048 u64 *cookie, gfp_t gfp)
3050 unsigned long spin_flags;
3051 struct sk_buff *ack_skb;
3054 ack_skb = skb_copy(skb, gfp);
3058 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3059 id = idr_alloc(&local->ack_status_frames, ack_skb,
3060 1, 0x10000, GFP_ATOMIC);
3061 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3068 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3070 *cookie = ieee80211_mgmt_tx_cookie(local);
3071 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3076 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
3077 struct wireless_dev *wdev,
3078 u16 frame_type, bool reg)
3080 struct ieee80211_local *local = wiphy_priv(wiphy);
3081 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3083 switch (frame_type) {
3084 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3086 local->probe_req_reg++;
3087 sdata->vif.probe_req_reg++;
3089 if (local->probe_req_reg)
3090 local->probe_req_reg--;
3092 if (sdata->vif.probe_req_reg)
3093 sdata->vif.probe_req_reg--;
3096 if (!local->open_count)
3099 if (sdata->vif.probe_req_reg == 1)
3100 drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
3102 else if (sdata->vif.probe_req_reg == 0)
3103 drv_config_iface_filter(local, sdata, 0,
3106 ieee80211_configure_filter(local);
3113 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3115 struct ieee80211_local *local = wiphy_priv(wiphy);
3120 return drv_set_antenna(local, tx_ant, rx_ant);
3123 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3125 struct ieee80211_local *local = wiphy_priv(wiphy);
3127 return drv_get_antenna(local, tx_ant, rx_ant);
3130 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3131 struct net_device *dev,
3132 struct cfg80211_gtk_rekey_data *data)
3134 struct ieee80211_local *local = wiphy_priv(wiphy);
3135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3137 if (!local->ops->set_rekey_data)
3140 drv_set_rekey_data(local, sdata, data);
3145 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3146 const u8 *peer, u64 *cookie)
3148 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3149 struct ieee80211_local *local = sdata->local;
3150 struct ieee80211_qos_hdr *nullfunc;
3151 struct sk_buff *skb;
3152 int size = sizeof(*nullfunc);
3155 struct ieee80211_tx_info *info;
3156 struct sta_info *sta;
3157 struct ieee80211_chanctx_conf *chanctx_conf;
3158 enum nl80211_band band;
3161 /* the lock is needed to assign the cookie later */
3162 mutex_lock(&local->mtx);
3165 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3166 if (WARN_ON(!chanctx_conf)) {
3170 band = chanctx_conf->def.chan->band;
3171 sta = sta_info_get_bss(sdata, peer);
3180 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3181 IEEE80211_STYPE_QOS_NULLFUNC |
3182 IEEE80211_FCTL_FROMDS);
3185 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3186 IEEE80211_STYPE_NULLFUNC |
3187 IEEE80211_FCTL_FROMDS);
3190 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3198 skb_reserve(skb, local->hw.extra_tx_headroom);
3200 nullfunc = (void *) skb_put(skb, size);
3201 nullfunc->frame_control = fc;
3202 nullfunc->duration_id = 0;
3203 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3204 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3205 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3206 nullfunc->seq_ctrl = 0;
3208 info = IEEE80211_SKB_CB(skb);
3210 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3211 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3214 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3217 nullfunc->qos_ctrl = cpu_to_le16(7);
3219 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3226 ieee80211_xmit(sdata, sta, skb);
3232 mutex_unlock(&local->mtx);
3237 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3238 struct wireless_dev *wdev,
3239 struct cfg80211_chan_def *chandef)
3241 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3242 struct ieee80211_local *local = wiphy_priv(wiphy);
3243 struct ieee80211_chanctx_conf *chanctx_conf;
3247 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3249 *chandef = sdata->vif.bss_conf.chandef;
3251 } else if (local->open_count > 0 &&
3252 local->open_count == local->monitors &&
3253 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3254 if (local->use_chanctx)
3255 *chandef = local->monitor_chandef;
3257 *chandef = local->_oper_chandef;
3266 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3268 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3272 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3273 struct net_device *dev,
3274 struct cfg80211_qos_map *qos_map)
3276 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3277 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3280 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3283 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3285 /* A NULL qos_map was passed to disable QoS mapping */
3289 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3290 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3292 kfree_rcu(old_qos_map, rcu_head);
3297 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3298 struct net_device *dev,
3299 struct cfg80211_chan_def *chandef)
3301 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3305 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3307 ieee80211_bss_info_change_notify(sdata, changed);
3312 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3313 u8 tsid, const u8 *peer, u8 up,
3316 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3317 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3318 int ac = ieee802_1d_to_ac[up];
3320 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3323 if (!(sdata->wmm_acm & BIT(up)))
3326 if (ifmgd->tx_tspec[ac].admitted_time)
3329 if (admitted_time) {
3330 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3331 ifmgd->tx_tspec[ac].tsid = tsid;
3332 ifmgd->tx_tspec[ac].up = up;
3338 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3339 u8 tsid, const u8 *peer)
3341 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3342 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3343 struct ieee80211_local *local = wiphy_priv(wiphy);
3346 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3347 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3349 /* skip unused entries */
3350 if (!tx_tspec->admitted_time)
3353 if (tx_tspec->tsid != tsid)
3356 /* due to this new packets will be reassigned to non-ACM ACs */
3359 /* Make sure that all packets have been sent to avoid to
3360 * restore the QoS params on packets that are still on the
3364 ieee80211_flush_queues(local, sdata, false);
3366 /* restore the normal QoS parameters
3367 * (unconditionally to avoid races)
3369 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3370 tx_tspec->downgraded = false;
3371 ieee80211_sta_handle_tspec_ac_params(sdata);
3373 /* finally clear all the data */
3374 memset(tx_tspec, 0, sizeof(*tx_tspec));
3382 const struct cfg80211_ops mac80211_config_ops = {
3383 .add_virtual_intf = ieee80211_add_iface,
3384 .del_virtual_intf = ieee80211_del_iface,
3385 .change_virtual_intf = ieee80211_change_iface,
3386 .start_p2p_device = ieee80211_start_p2p_device,
3387 .stop_p2p_device = ieee80211_stop_p2p_device,
3388 .add_key = ieee80211_add_key,
3389 .del_key = ieee80211_del_key,
3390 .get_key = ieee80211_get_key,
3391 .set_default_key = ieee80211_config_default_key,
3392 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3393 .start_ap = ieee80211_start_ap,
3394 .change_beacon = ieee80211_change_beacon,
3395 .stop_ap = ieee80211_stop_ap,
3396 .add_station = ieee80211_add_station,
3397 .del_station = ieee80211_del_station,
3398 .change_station = ieee80211_change_station,
3399 .get_station = ieee80211_get_station,
3400 .dump_station = ieee80211_dump_station,
3401 .dump_survey = ieee80211_dump_survey,
3402 #ifdef CONFIG_MAC80211_MESH
3403 .add_mpath = ieee80211_add_mpath,
3404 .del_mpath = ieee80211_del_mpath,
3405 .change_mpath = ieee80211_change_mpath,
3406 .get_mpath = ieee80211_get_mpath,
3407 .dump_mpath = ieee80211_dump_mpath,
3408 .get_mpp = ieee80211_get_mpp,
3409 .dump_mpp = ieee80211_dump_mpp,
3410 .update_mesh_config = ieee80211_update_mesh_config,
3411 .get_mesh_config = ieee80211_get_mesh_config,
3412 .join_mesh = ieee80211_join_mesh,
3413 .leave_mesh = ieee80211_leave_mesh,
3415 .join_ocb = ieee80211_join_ocb,
3416 .leave_ocb = ieee80211_leave_ocb,
3417 .change_bss = ieee80211_change_bss,
3418 .set_txq_params = ieee80211_set_txq_params,
3419 .set_monitor_channel = ieee80211_set_monitor_channel,
3420 .suspend = ieee80211_suspend,
3421 .resume = ieee80211_resume,
3422 .scan = ieee80211_scan,
3423 .abort_scan = ieee80211_abort_scan,
3424 .sched_scan_start = ieee80211_sched_scan_start,
3425 .sched_scan_stop = ieee80211_sched_scan_stop,
3426 .auth = ieee80211_auth,
3427 .assoc = ieee80211_assoc,
3428 .deauth = ieee80211_deauth,
3429 .disassoc = ieee80211_disassoc,
3430 .join_ibss = ieee80211_join_ibss,
3431 .leave_ibss = ieee80211_leave_ibss,
3432 .set_mcast_rate = ieee80211_set_mcast_rate,
3433 .set_wiphy_params = ieee80211_set_wiphy_params,
3434 .set_tx_power = ieee80211_set_tx_power,
3435 .get_tx_power = ieee80211_get_tx_power,
3436 .set_wds_peer = ieee80211_set_wds_peer,
3437 .rfkill_poll = ieee80211_rfkill_poll,
3438 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3439 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3440 .set_power_mgmt = ieee80211_set_power_mgmt,
3441 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3442 .remain_on_channel = ieee80211_remain_on_channel,
3443 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3444 .mgmt_tx = ieee80211_mgmt_tx,
3445 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3446 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3447 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3448 .set_antenna = ieee80211_set_antenna,
3449 .get_antenna = ieee80211_get_antenna,
3450 .set_rekey_data = ieee80211_set_rekey_data,
3451 .tdls_oper = ieee80211_tdls_oper,
3452 .tdls_mgmt = ieee80211_tdls_mgmt,
3453 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3454 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
3455 .probe_client = ieee80211_probe_client,
3456 .set_noack_map = ieee80211_set_noack_map,
3458 .set_wakeup = ieee80211_set_wakeup,
3460 .get_channel = ieee80211_cfg_get_channel,
3461 .start_radar_detection = ieee80211_start_radar_detection,
3462 .channel_switch = ieee80211_channel_switch,
3463 .set_qos_map = ieee80211_set_qos_map,
3464 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
3465 .add_tx_ts = ieee80211_add_tx_ts,
3466 .del_tx_ts = ieee80211_del_tx_ts,