2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * This file is GPLv2 as found in COPYING.
9 #include <linux/ieee80211.h>
10 #include <linux/nl80211.h>
11 #include <linux/rtnetlink.h>
12 #include <linux/slab.h>
13 #include <net/net_namespace.h>
14 #include <linux/rcupdate.h>
15 #include <linux/if_ether.h>
16 #include <net/cfg80211.h>
17 #include "ieee80211_i.h"
18 #include "driver-ops.h"
23 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
25 enum nl80211_iftype type,
27 struct vif_params *params)
29 struct ieee80211_local *local = wiphy_priv(wiphy);
30 struct wireless_dev *wdev;
31 struct ieee80211_sub_if_data *sdata;
34 err = ieee80211_if_add(local, name, &wdev, type, params);
38 if (type == NL80211_IFTYPE_MONITOR && flags) {
39 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
40 sdata->u.mntr_flags = *flags;
46 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
48 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
53 static int ieee80211_change_iface(struct wiphy *wiphy,
54 struct net_device *dev,
55 enum nl80211_iftype type, u32 *flags,
56 struct vif_params *params)
58 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
61 ret = ieee80211_if_change_type(sdata, type);
65 if (type == NL80211_IFTYPE_AP_VLAN &&
66 params && params->use_4addr == 0)
67 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
68 else if (type == NL80211_IFTYPE_STATION &&
69 params && params->use_4addr >= 0)
70 sdata->u.mgd.use_4addr = params->use_4addr;
72 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
73 struct ieee80211_local *local = sdata->local;
75 if (ieee80211_sdata_running(sdata)) {
76 u32 mask = MONITOR_FLAG_COOK_FRAMES |
80 * Prohibit MONITOR_FLAG_COOK_FRAMES and
81 * MONITOR_FLAG_ACTIVE to be changed while the
83 * Else we would need to add a lot of cruft
84 * to update everything:
85 * cooked_mntrs, monitor and all fif_* counters
86 * reconfigure hardware
88 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
91 ieee80211_adjust_monitor_flags(sdata, -1);
92 sdata->u.mntr_flags = *flags;
93 ieee80211_adjust_monitor_flags(sdata, 1);
95 ieee80211_configure_filter(local);
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
102 sdata->u.mntr_flags = *flags;
109 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
110 struct wireless_dev *wdev)
112 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
115 mutex_lock(&sdata->local->chanctx_mtx);
116 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
117 mutex_unlock(&sdata->local->chanctx_mtx);
121 return ieee80211_do_open(wdev, true);
124 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
125 struct wireless_dev *wdev)
127 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
130 static int ieee80211_set_noack_map(struct wiphy *wiphy,
131 struct net_device *dev,
134 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
136 sdata->noack_map = noack_map;
140 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
141 u8 key_idx, bool pairwise, const u8 *mac_addr,
142 struct key_params *params)
144 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
145 struct ieee80211_local *local = sdata->local;
146 struct sta_info *sta = NULL;
147 const struct ieee80211_cipher_scheme *cs = NULL;
148 struct ieee80211_key *key;
151 if (!ieee80211_sdata_running(sdata))
154 /* reject WEP and TKIP keys if WEP failed to initialize */
155 switch (params->cipher) {
156 case WLAN_CIPHER_SUITE_WEP40:
157 case WLAN_CIPHER_SUITE_TKIP:
158 case WLAN_CIPHER_SUITE_WEP104:
159 if (IS_ERR(local->wep_tx_tfm))
162 case WLAN_CIPHER_SUITE_CCMP:
163 case WLAN_CIPHER_SUITE_AES_CMAC:
164 case WLAN_CIPHER_SUITE_GCMP:
167 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
171 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
172 params->key, params->seq_len, params->seq,
178 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
180 mutex_lock(&local->sta_mtx);
183 if (ieee80211_vif_is_mesh(&sdata->vif))
184 sta = sta_info_get(sdata, mac_addr);
186 sta = sta_info_get_bss(sdata, mac_addr);
188 * The ASSOC test makes sure the driver is ready to
189 * receive the key. When wpa_supplicant has roamed
190 * using FT, it attempts to set the key before
191 * association has completed, this rejects that attempt
192 * so it will set the key again after assocation.
194 * TODO: accept the key if we have a station entry and
195 * add it to the device after the station.
197 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
198 ieee80211_key_free_unused(key);
204 switch (sdata->vif.type) {
205 case NL80211_IFTYPE_STATION:
206 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
207 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
209 case NL80211_IFTYPE_AP:
210 case NL80211_IFTYPE_AP_VLAN:
211 /* Keys without a station are used for TX only */
212 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
213 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
215 case NL80211_IFTYPE_ADHOC:
218 case NL80211_IFTYPE_MESH_POINT:
219 #ifdef CONFIG_MAC80211_MESH
220 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
221 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
224 case NL80211_IFTYPE_WDS:
225 case NL80211_IFTYPE_MONITOR:
226 case NL80211_IFTYPE_P2P_DEVICE:
227 case NL80211_IFTYPE_UNSPECIFIED:
228 case NUM_NL80211_IFTYPES:
229 case NL80211_IFTYPE_P2P_CLIENT:
230 case NL80211_IFTYPE_P2P_GO:
231 /* shouldn't happen */
237 sta->cipher_scheme = cs;
239 err = ieee80211_key_link(key, sdata, sta);
242 mutex_unlock(&local->sta_mtx);
247 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
248 u8 key_idx, bool pairwise, const u8 *mac_addr)
250 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
251 struct ieee80211_local *local = sdata->local;
252 struct sta_info *sta;
253 struct ieee80211_key *key = NULL;
256 mutex_lock(&local->sta_mtx);
257 mutex_lock(&local->key_mtx);
262 sta = sta_info_get_bss(sdata, mac_addr);
267 key = key_mtx_dereference(local, sta->ptk[key_idx]);
269 key = key_mtx_dereference(local, sta->gtk[key_idx]);
271 key = key_mtx_dereference(local, sdata->keys[key_idx]);
278 ieee80211_key_free(key, true);
282 mutex_unlock(&local->key_mtx);
283 mutex_unlock(&local->sta_mtx);
288 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
289 u8 key_idx, bool pairwise, const u8 *mac_addr,
291 void (*callback)(void *cookie,
292 struct key_params *params))
294 struct ieee80211_sub_if_data *sdata;
295 struct sta_info *sta = NULL;
297 struct key_params params;
298 struct ieee80211_key *key = NULL;
304 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
309 sta = sta_info_get_bss(sdata, mac_addr);
313 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
314 key = rcu_dereference(sta->ptk[key_idx]);
315 else if (!pairwise &&
316 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
317 key = rcu_dereference(sta->gtk[key_idx]);
319 key = rcu_dereference(sdata->keys[key_idx]);
324 memset(¶ms, 0, sizeof(params));
326 params.cipher = key->conf.cipher;
328 switch (key->conf.cipher) {
329 case WLAN_CIPHER_SUITE_TKIP:
330 iv32 = key->u.tkip.tx.iv32;
331 iv16 = key->u.tkip.tx.iv16;
333 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
334 drv_get_tkip_seq(sdata->local,
335 key->conf.hw_key_idx,
338 seq[0] = iv16 & 0xff;
339 seq[1] = (iv16 >> 8) & 0xff;
340 seq[2] = iv32 & 0xff;
341 seq[3] = (iv32 >> 8) & 0xff;
342 seq[4] = (iv32 >> 16) & 0xff;
343 seq[5] = (iv32 >> 24) & 0xff;
347 case WLAN_CIPHER_SUITE_CCMP:
348 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
358 case WLAN_CIPHER_SUITE_AES_CMAC:
359 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
371 params.key = key->conf.key;
372 params.key_len = key->conf.keylen;
374 callback(cookie, ¶ms);
382 static int ieee80211_config_default_key(struct wiphy *wiphy,
383 struct net_device *dev,
384 u8 key_idx, bool uni,
387 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
389 ieee80211_set_default_key(sdata, key_idx, uni, multi);
394 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
395 struct net_device *dev,
398 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
400 ieee80211_set_default_mgmt_key(sdata, key_idx);
405 void sta_set_rate_info_tx(struct sta_info *sta,
406 const struct ieee80211_tx_rate *rate,
407 struct rate_info *rinfo)
410 if (rate->flags & IEEE80211_TX_RC_MCS) {
411 rinfo->flags |= RATE_INFO_FLAGS_MCS;
412 rinfo->mcs = rate->idx;
413 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
414 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
415 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
416 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
418 struct ieee80211_supported_band *sband;
419 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
422 sband = sta->local->hw.wiphy->bands[
423 ieee80211_get_sdata_band(sta->sdata)];
424 brate = sband->bitrates[rate->idx].bitrate;
425 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
427 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
428 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
429 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
430 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
431 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
432 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
433 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
434 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
437 void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
441 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
442 rinfo->flags |= RATE_INFO_FLAGS_MCS;
443 rinfo->mcs = sta->last_rx_rate_idx;
444 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
445 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
446 rinfo->nss = sta->last_rx_rate_vht_nss;
447 rinfo->mcs = sta->last_rx_rate_idx;
449 struct ieee80211_supported_band *sband;
450 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
453 sband = sta->local->hw.wiphy->bands[
454 ieee80211_get_sdata_band(sta->sdata)];
455 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
456 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
459 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
460 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
461 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
462 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
463 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
464 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
465 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80P80MHZ)
466 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
467 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
468 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
471 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
473 struct ieee80211_sub_if_data *sdata = sta->sdata;
474 struct ieee80211_local *local = sdata->local;
475 struct rate_control_ref *ref = NULL;
476 struct timespec uptime;
481 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
482 ref = local->rate_ctrl;
484 sinfo->generation = sdata->local->sta_generation;
486 sinfo->filled = STATION_INFO_INACTIVE_TIME |
487 STATION_INFO_RX_BYTES64 |
488 STATION_INFO_TX_BYTES64 |
489 STATION_INFO_RX_PACKETS |
490 STATION_INFO_TX_PACKETS |
491 STATION_INFO_TX_RETRIES |
492 STATION_INFO_TX_FAILED |
493 STATION_INFO_TX_BITRATE |
494 STATION_INFO_RX_BITRATE |
495 STATION_INFO_RX_DROP_MISC |
496 STATION_INFO_BSS_PARAM |
497 STATION_INFO_CONNECTED_TIME |
498 STATION_INFO_STA_FLAGS |
499 STATION_INFO_BEACON_LOSS_COUNT;
501 do_posix_clock_monotonic_gettime(&uptime);
502 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
504 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
506 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
507 sinfo->tx_bytes += sta->tx_bytes[ac];
508 packets += sta->tx_packets[ac];
510 sinfo->tx_packets = packets;
511 sinfo->rx_bytes = sta->rx_bytes;
512 sinfo->rx_packets = sta->rx_packets;
513 sinfo->tx_retries = sta->tx_retry_count;
514 sinfo->tx_failed = sta->tx_retry_failed;
515 sinfo->rx_dropped_misc = sta->rx_dropped;
516 sinfo->beacon_loss_count = sta->beacon_loss_count;
518 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
519 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
520 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
521 if (!local->ops->get_rssi ||
522 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
523 sinfo->signal = (s8)sta->last_signal;
524 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
527 sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
528 STATION_INFO_CHAIN_SIGNAL_AVG;
530 sinfo->chains = sta->chains;
531 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
532 sinfo->chain_signal[i] = sta->chain_signal_last[i];
533 sinfo->chain_signal_avg[i] =
534 (s8) -ewma_read(&sta->chain_signal_avg[i]);
538 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
539 sta_set_rate_info_rx(sta, &sinfo->rxrate);
541 if (ieee80211_vif_is_mesh(&sdata->vif)) {
542 #ifdef CONFIG_MAC80211_MESH
543 sinfo->filled |= STATION_INFO_LLID |
545 STATION_INFO_PLINK_STATE |
546 STATION_INFO_LOCAL_PM |
547 STATION_INFO_PEER_PM |
548 STATION_INFO_NONPEER_PM;
550 sinfo->llid = sta->llid;
551 sinfo->plid = sta->plid;
552 sinfo->plink_state = sta->plink_state;
553 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
554 sinfo->filled |= STATION_INFO_T_OFFSET;
555 sinfo->t_offset = sta->t_offset;
557 sinfo->local_pm = sta->local_pm;
558 sinfo->peer_pm = sta->peer_pm;
559 sinfo->nonpeer_pm = sta->nonpeer_pm;
563 sinfo->bss_param.flags = 0;
564 if (sdata->vif.bss_conf.use_cts_prot)
565 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
566 if (sdata->vif.bss_conf.use_short_preamble)
567 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
568 if (sdata->vif.bss_conf.use_short_slot)
569 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
570 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
571 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
573 sinfo->sta_flags.set = 0;
574 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
575 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
576 BIT(NL80211_STA_FLAG_WME) |
577 BIT(NL80211_STA_FLAG_MFP) |
578 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
579 BIT(NL80211_STA_FLAG_ASSOCIATED) |
580 BIT(NL80211_STA_FLAG_TDLS_PEER);
581 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
582 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
583 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
584 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
585 if (test_sta_flag(sta, WLAN_STA_WME))
586 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
587 if (test_sta_flag(sta, WLAN_STA_MFP))
588 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
589 if (test_sta_flag(sta, WLAN_STA_AUTH))
590 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
591 if (test_sta_flag(sta, WLAN_STA_ASSOC))
592 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
593 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
594 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
596 /* check if the driver has a SW RC implementation */
597 if (ref && ref->ops->get_expected_throughput)
598 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
600 thr = drv_get_expected_throughput(local, &sta->sta);
603 sinfo->filled |= STATION_INFO_EXPECTED_THROUGHPUT;
604 sinfo->expected_throughput = thr;
608 static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
609 "rx_packets", "rx_bytes", "wep_weak_iv_count",
610 "rx_duplicates", "rx_fragments", "rx_dropped",
611 "tx_packets", "tx_bytes", "tx_fragments",
612 "tx_filtered", "tx_retry_failed", "tx_retries",
613 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
614 "channel", "noise", "ch_time", "ch_time_busy",
615 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
617 #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
619 static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
620 struct net_device *dev,
623 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
626 if (sset == ETH_SS_STATS)
629 rv += drv_get_et_sset_count(sdata, sset);
636 static void ieee80211_get_et_stats(struct wiphy *wiphy,
637 struct net_device *dev,
638 struct ethtool_stats *stats,
641 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
642 struct ieee80211_chanctx_conf *chanctx_conf;
643 struct ieee80211_channel *channel;
644 struct sta_info *sta;
645 struct ieee80211_local *local = sdata->local;
646 struct station_info sinfo;
647 struct survey_info survey;
649 #define STA_STATS_SURVEY_LEN 7
651 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
653 #define ADD_STA_STATS(sta) \
655 data[i++] += sta->rx_packets; \
656 data[i++] += sta->rx_bytes; \
657 data[i++] += sta->wep_weak_iv_count; \
658 data[i++] += sta->num_duplicates; \
659 data[i++] += sta->rx_fragments; \
660 data[i++] += sta->rx_dropped; \
662 data[i++] += sinfo.tx_packets; \
663 data[i++] += sinfo.tx_bytes; \
664 data[i++] += sta->tx_fragments; \
665 data[i++] += sta->tx_filtered_count; \
666 data[i++] += sta->tx_retry_failed; \
667 data[i++] += sta->tx_retry_count; \
668 data[i++] += sta->beacon_loss_count; \
671 /* For Managed stations, find the single station based on BSSID
672 * and use that. For interface types, iterate through all available
673 * stations and add stats for any station that is assigned to this
677 mutex_lock(&local->sta_mtx);
679 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
680 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
682 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
686 sta_set_sinfo(sta, &sinfo);
691 data[i++] = sta->sta_state;
694 if (sinfo.filled & STATION_INFO_TX_BITRATE)
696 cfg80211_calculate_bitrate(&sinfo.txrate);
698 if (sinfo.filled & STATION_INFO_RX_BITRATE)
700 cfg80211_calculate_bitrate(&sinfo.rxrate);
703 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
704 data[i] = (u8)sinfo.signal_avg;
707 list_for_each_entry(sta, &local->sta_list, list) {
708 /* Make sure this station belongs to the proper dev */
709 if (sta->sdata->dev != dev)
713 sta_set_sinfo(sta, &sinfo);
720 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
721 /* Get survey stats for current channel */
725 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
727 channel = chanctx_conf->def.chan;
736 if (drv_get_survey(local, q, &survey) != 0) {
741 } while (channel != survey.channel);
745 data[i++] = survey.channel->center_freq;
748 if (survey.filled & SURVEY_INFO_NOISE_DBM)
749 data[i++] = (u8)survey.noise;
752 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
753 data[i++] = survey.channel_time;
756 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
757 data[i++] = survey.channel_time_busy;
760 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
761 data[i++] = survey.channel_time_ext_busy;
764 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
765 data[i++] = survey.channel_time_rx;
768 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
769 data[i++] = survey.channel_time_tx;
773 mutex_unlock(&local->sta_mtx);
775 if (WARN_ON(i != STA_STATS_LEN))
778 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
781 static void ieee80211_get_et_strings(struct wiphy *wiphy,
782 struct net_device *dev,
785 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
786 int sz_sta_stats = 0;
788 if (sset == ETH_SS_STATS) {
789 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
790 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
792 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
795 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
796 int idx, u8 *mac, struct station_info *sinfo)
798 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
799 struct ieee80211_local *local = sdata->local;
800 struct sta_info *sta;
803 mutex_lock(&local->sta_mtx);
805 sta = sta_info_get_by_idx(sdata, idx);
808 memcpy(mac, sta->sta.addr, ETH_ALEN);
809 sta_set_sinfo(sta, sinfo);
812 mutex_unlock(&local->sta_mtx);
817 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
818 int idx, struct survey_info *survey)
820 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
822 return drv_get_survey(local, idx, survey);
825 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
826 const u8 *mac, struct station_info *sinfo)
828 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
829 struct ieee80211_local *local = sdata->local;
830 struct sta_info *sta;
833 mutex_lock(&local->sta_mtx);
835 sta = sta_info_get_bss(sdata, mac);
838 sta_set_sinfo(sta, sinfo);
841 mutex_unlock(&local->sta_mtx);
846 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
847 struct cfg80211_chan_def *chandef)
849 struct ieee80211_local *local = wiphy_priv(wiphy);
850 struct ieee80211_sub_if_data *sdata;
853 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
856 mutex_lock(&local->mtx);
857 mutex_lock(&local->iflist_mtx);
858 if (local->use_chanctx) {
859 sdata = rcu_dereference_protected(
860 local->monitor_sdata,
861 lockdep_is_held(&local->iflist_mtx));
863 ieee80211_vif_release_channel(sdata);
864 ret = ieee80211_vif_use_channel(sdata, chandef,
865 IEEE80211_CHANCTX_EXCLUSIVE);
867 } else if (local->open_count == local->monitors) {
868 local->_oper_chandef = *chandef;
869 ieee80211_hw_config(local, 0);
873 local->monitor_chandef = *chandef;
874 mutex_unlock(&local->iflist_mtx);
875 mutex_unlock(&local->mtx);
880 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
881 const u8 *resp, size_t resp_len)
883 struct probe_resp *new, *old;
885 if (!resp || !resp_len)
888 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
890 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
895 memcpy(new->data, resp, resp_len);
897 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
899 kfree_rcu(old, rcu_head);
904 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
905 struct cfg80211_beacon_data *params)
907 struct beacon_data *new, *old;
908 int new_head_len, new_tail_len;
910 u32 changed = BSS_CHANGED_BEACON;
912 old = sdata_dereference(sdata->u.ap.beacon, sdata);
915 /* Need to have a beacon head if we don't have one yet */
916 if (!params->head && !old)
919 /* new or old head? */
921 new_head_len = params->head_len;
923 new_head_len = old->head_len;
925 /* new or old tail? */
926 if (params->tail || !old)
927 /* params->tail_len will be zero for !params->tail */
928 new_tail_len = params->tail_len;
930 new_tail_len = old->tail_len;
932 size = sizeof(*new) + new_head_len + new_tail_len;
934 new = kzalloc(size, GFP_KERNEL);
938 /* start filling the new info now */
941 * pointers go into the block we allocated,
942 * memory is | beacon_data | head | tail |
944 new->head = ((u8 *) new) + sizeof(*new);
945 new->tail = new->head + new_head_len;
946 new->head_len = new_head_len;
947 new->tail_len = new_tail_len;
951 memcpy(new->head, params->head, new_head_len);
953 memcpy(new->head, old->head, new_head_len);
955 /* copy in optional tail */
957 memcpy(new->tail, params->tail, new_tail_len);
960 memcpy(new->tail, old->tail, new_tail_len);
962 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
963 params->probe_resp_len);
967 changed |= BSS_CHANGED_AP_PROBE_RESP;
969 rcu_assign_pointer(sdata->u.ap.beacon, new);
972 kfree_rcu(old, rcu_head);
977 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
978 struct cfg80211_ap_settings *params)
980 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
981 struct ieee80211_local *local = sdata->local;
982 struct beacon_data *old;
983 struct ieee80211_sub_if_data *vlan;
984 u32 changed = BSS_CHANGED_BEACON_INT |
985 BSS_CHANGED_BEACON_ENABLED |
991 old = sdata_dereference(sdata->u.ap.beacon, sdata);
995 /* TODO: make hostapd tell us what it wants */
996 sdata->smps_mode = IEEE80211_SMPS_OFF;
997 sdata->needed_rx_chains = sdata->local->rx_chains;
999 mutex_lock(&local->mtx);
1000 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
1001 IEEE80211_CHANCTX_SHARED);
1003 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
1004 mutex_unlock(&local->mtx);
1009 * Apply control port protocol, this allows us to
1010 * not encrypt dynamic WEP control frames.
1012 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1013 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1014 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
1018 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1019 vlan->control_port_protocol =
1020 params->crypto.control_port_ethertype;
1021 vlan->control_port_no_encrypt =
1022 params->crypto.control_port_no_encrypt;
1023 vlan->encrypt_headroom =
1024 ieee80211_cs_headroom(sdata->local,
1029 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
1030 sdata->vif.bss_conf.dtim_period = params->dtim_period;
1031 sdata->vif.bss_conf.enable_beacon = true;
1033 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1034 if (params->ssid_len)
1035 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1037 sdata->vif.bss_conf.hidden_ssid =
1038 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1040 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1041 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1042 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1043 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1044 if (params->p2p_opp_ps)
1045 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1046 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1048 err = ieee80211_assign_beacon(sdata, ¶ms->beacon);
1050 ieee80211_vif_release_channel(sdata);
1055 err = drv_start_ap(sdata->local, sdata);
1057 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1060 kfree_rcu(old, rcu_head);
1061 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1062 ieee80211_vif_release_channel(sdata);
1066 ieee80211_recalc_dtim(local, sdata);
1067 ieee80211_bss_info_change_notify(sdata, changed);
1069 netif_carrier_on(dev);
1070 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1071 netif_carrier_on(vlan->dev);
1076 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1077 struct cfg80211_beacon_data *params)
1079 struct ieee80211_sub_if_data *sdata;
1080 struct beacon_data *old;
1083 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1084 sdata_assert_lock(sdata);
1086 /* don't allow changing the beacon while CSA is in place - offset
1087 * of channel switch counter may change
1089 if (sdata->vif.csa_active)
1092 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1096 err = ieee80211_assign_beacon(sdata, params);
1099 ieee80211_bss_info_change_notify(sdata, err);
1103 bool ieee80211_csa_needs_block_tx(struct ieee80211_local *local)
1105 struct ieee80211_sub_if_data *sdata;
1107 lockdep_assert_held(&local->mtx);
1110 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1111 if (!ieee80211_sdata_running(sdata))
1114 if (!sdata->vif.csa_active)
1117 if (!sdata->csa_block_tx)
1128 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1130 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1131 struct ieee80211_sub_if_data *vlan;
1132 struct ieee80211_local *local = sdata->local;
1133 struct beacon_data *old_beacon;
1134 struct probe_resp *old_probe_resp;
1135 struct cfg80211_chan_def chandef;
1137 sdata_assert_lock(sdata);
1139 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
1142 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
1144 /* abort any running channel switch */
1145 mutex_lock(&local->mtx);
1146 sdata->vif.csa_active = false;
1147 if (!ieee80211_csa_needs_block_tx(local))
1148 ieee80211_wake_queues_by_reason(&local->hw,
1149 IEEE80211_MAX_QUEUE_MAP,
1150 IEEE80211_QUEUE_STOP_REASON_CSA);
1151 mutex_unlock(&local->mtx);
1153 kfree(sdata->u.ap.next_beacon);
1154 sdata->u.ap.next_beacon = NULL;
1156 /* turn off carrier for this interface and dependent VLANs */
1157 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1158 netif_carrier_off(vlan->dev);
1159 netif_carrier_off(dev);
1161 /* remove beacon and probe response */
1162 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1163 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1164 kfree_rcu(old_beacon, rcu_head);
1166 kfree_rcu(old_probe_resp, rcu_head);
1167 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
1169 __sta_info_flush(sdata, true);
1170 ieee80211_free_keys(sdata, true);
1172 sdata->vif.bss_conf.enable_beacon = false;
1173 sdata->vif.bss_conf.ssid_len = 0;
1174 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1175 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1177 if (sdata->wdev.cac_started) {
1178 chandef = sdata->vif.bss_conf.chandef;
1179 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1180 cfg80211_cac_event(sdata->dev, &chandef,
1181 NL80211_RADAR_CAC_ABORTED,
1185 drv_stop_ap(sdata->local, sdata);
1187 /* free all potentially still buffered bcast frames */
1188 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1189 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1191 mutex_lock(&local->mtx);
1192 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
1193 ieee80211_vif_release_channel(sdata);
1194 mutex_unlock(&local->mtx);
1199 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1200 struct iapp_layer2_update {
1201 u8 da[ETH_ALEN]; /* broadcast */
1202 u8 sa[ETH_ALEN]; /* STA addr */
1210 static void ieee80211_send_layer2_update(struct sta_info *sta)
1212 struct iapp_layer2_update *msg;
1213 struct sk_buff *skb;
1215 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1218 skb = dev_alloc_skb(sizeof(*msg));
1221 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1223 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1224 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1226 eth_broadcast_addr(msg->da);
1227 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
1228 msg->len = htons(6);
1230 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1231 msg->control = 0xaf; /* XID response lsb.1111F101.
1232 * F=0 (no poll command; unsolicited frame) */
1233 msg->xid_info[0] = 0x81; /* XID format identifier */
1234 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1235 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1237 skb->dev = sta->sdata->dev;
1238 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
1239 memset(skb->cb, 0, sizeof(skb->cb));
1243 static int sta_apply_auth_flags(struct ieee80211_local *local,
1244 struct sta_info *sta,
1249 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1250 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1251 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1252 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1257 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1258 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1259 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1260 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1265 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1266 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1267 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1268 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1269 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1276 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1277 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1278 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1279 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1284 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1285 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1286 test_sta_flag(sta, WLAN_STA_AUTH)) {
1287 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1295 static int sta_apply_parameters(struct ieee80211_local *local,
1296 struct sta_info *sta,
1297 struct station_parameters *params)
1300 struct ieee80211_supported_band *sband;
1301 struct ieee80211_sub_if_data *sdata = sta->sdata;
1302 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
1305 sband = local->hw.wiphy->bands[band];
1307 mask = params->sta_flags_mask;
1308 set = params->sta_flags_set;
1310 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1312 * In mesh mode, ASSOCIATED isn't part of the nl80211
1313 * API but must follow AUTHENTICATED for driver state.
1315 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1316 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1317 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1318 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1319 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1321 * TDLS -- everything follows authorized, but
1322 * only becoming authorized is possible, not
1325 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1326 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1327 BIT(NL80211_STA_FLAG_ASSOCIATED);
1328 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1329 BIT(NL80211_STA_FLAG_ASSOCIATED);
1333 ret = sta_apply_auth_flags(local, sta, mask, set);
1337 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1338 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1339 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1341 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1344 if (mask & BIT(NL80211_STA_FLAG_WME)) {
1345 if (set & BIT(NL80211_STA_FLAG_WME)) {
1346 set_sta_flag(sta, WLAN_STA_WME);
1347 sta->sta.wme = true;
1349 clear_sta_flag(sta, WLAN_STA_WME);
1350 sta->sta.wme = false;
1354 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1355 if (set & BIT(NL80211_STA_FLAG_MFP))
1356 set_sta_flag(sta, WLAN_STA_MFP);
1358 clear_sta_flag(sta, WLAN_STA_MFP);
1361 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1362 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1363 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1365 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1368 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1369 sta->sta.uapsd_queues = params->uapsd_queues;
1370 sta->sta.max_sp = params->max_sp;
1374 * cfg80211 validates this (1-2007) and allows setting the AID
1375 * only when creating a new station entry
1378 sta->sta.aid = params->aid;
1381 * Some of the following updates would be racy if called on an
1382 * existing station, via ieee80211_change_station(). However,
1383 * all such changes are rejected by cfg80211 except for updates
1384 * changing the supported rates on an existing but not yet used
1388 if (params->listen_interval >= 0)
1389 sta->listen_interval = params->listen_interval;
1391 if (params->supported_rates) {
1392 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1393 sband, params->supported_rates,
1394 params->supported_rates_len,
1395 &sta->sta.supp_rates[band]);
1398 if (params->ht_capa)
1399 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1400 params->ht_capa, sta);
1402 if (params->vht_capa)
1403 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1404 params->vht_capa, sta);
1406 if (params->opmode_notif_used) {
1407 /* returned value is only needed for rc update, but the
1408 * rc isn't initialized here yet, so ignore it
1410 __ieee80211_vht_handle_opmode(sdata, sta,
1411 params->opmode_notif,
1415 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1416 #ifdef CONFIG_MAC80211_MESH
1419 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1420 switch (params->plink_state) {
1421 case NL80211_PLINK_ESTAB:
1422 if (sta->plink_state != NL80211_PLINK_ESTAB)
1423 changed = mesh_plink_inc_estab_count(
1425 sta->plink_state = params->plink_state;
1427 ieee80211_mps_sta_status_update(sta);
1428 changed |= ieee80211_mps_set_sta_local_pm(sta,
1429 sdata->u.mesh.mshcfg.power_mode);
1431 case NL80211_PLINK_LISTEN:
1432 case NL80211_PLINK_BLOCKED:
1433 case NL80211_PLINK_OPN_SNT:
1434 case NL80211_PLINK_OPN_RCVD:
1435 case NL80211_PLINK_CNF_RCVD:
1436 case NL80211_PLINK_HOLDING:
1437 if (sta->plink_state == NL80211_PLINK_ESTAB)
1438 changed = mesh_plink_dec_estab_count(
1440 sta->plink_state = params->plink_state;
1442 ieee80211_mps_sta_status_update(sta);
1443 changed |= ieee80211_mps_set_sta_local_pm(sta,
1444 NL80211_MESH_POWER_UNKNOWN);
1452 switch (params->plink_action) {
1453 case NL80211_PLINK_ACTION_NO_ACTION:
1456 case NL80211_PLINK_ACTION_OPEN:
1457 changed |= mesh_plink_open(sta);
1459 case NL80211_PLINK_ACTION_BLOCK:
1460 changed |= mesh_plink_block(sta);
1464 if (params->local_pm)
1466 ieee80211_mps_set_sta_local_pm(sta,
1468 ieee80211_mbss_info_change_notify(sdata, changed);
1475 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1477 struct station_parameters *params)
1479 struct ieee80211_local *local = wiphy_priv(wiphy);
1480 struct sta_info *sta;
1481 struct ieee80211_sub_if_data *sdata;
1486 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1488 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1489 sdata->vif.type != NL80211_IFTYPE_AP)
1492 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1494 if (ether_addr_equal(mac, sdata->vif.addr))
1497 if (is_multicast_ether_addr(mac))
1500 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1505 * defaults -- if userspace wants something else we'll
1506 * change it accordingly in sta_apply_parameters()
1508 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1509 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1510 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1512 sta->sta.tdls = true;
1515 err = sta_apply_parameters(local, sta, params);
1517 sta_info_free(local, sta);
1522 * for TDLS, rate control should be initialized only when
1523 * rates are known and station is marked authorized
1525 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1526 rate_control_rate_init(sta);
1528 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1529 sdata->vif.type == NL80211_IFTYPE_AP;
1531 err = sta_info_insert_rcu(sta);
1538 ieee80211_send_layer2_update(sta);
1545 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1548 struct ieee80211_sub_if_data *sdata;
1550 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1553 return sta_info_destroy_addr_bss(sdata, mac);
1555 sta_info_flush(sdata);
1559 static int ieee80211_change_station(struct wiphy *wiphy,
1560 struct net_device *dev, const u8 *mac,
1561 struct station_parameters *params)
1563 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1564 struct ieee80211_local *local = wiphy_priv(wiphy);
1565 struct sta_info *sta;
1566 struct ieee80211_sub_if_data *vlansdata;
1567 enum cfg80211_station_type statype;
1570 mutex_lock(&local->sta_mtx);
1572 sta = sta_info_get_bss(sdata, mac);
1578 switch (sdata->vif.type) {
1579 case NL80211_IFTYPE_MESH_POINT:
1580 if (sdata->u.mesh.user_mpm)
1581 statype = CFG80211_STA_MESH_PEER_USER;
1583 statype = CFG80211_STA_MESH_PEER_KERNEL;
1585 case NL80211_IFTYPE_ADHOC:
1586 statype = CFG80211_STA_IBSS;
1588 case NL80211_IFTYPE_STATION:
1589 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1590 statype = CFG80211_STA_AP_STA;
1593 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1594 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1596 statype = CFG80211_STA_TDLS_PEER_SETUP;
1598 case NL80211_IFTYPE_AP:
1599 case NL80211_IFTYPE_AP_VLAN:
1600 statype = CFG80211_STA_AP_CLIENT;
1607 err = cfg80211_check_station_change(wiphy, params, statype);
1611 if (params->vlan && params->vlan != sta->sdata->dev) {
1612 bool prev_4addr = false;
1613 bool new_4addr = false;
1615 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1617 if (params->vlan->ieee80211_ptr->use_4addr) {
1618 if (vlansdata->u.vlan.sta) {
1623 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1627 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1628 sta->sdata->u.vlan.sta) {
1629 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1633 sta->sdata = vlansdata;
1635 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1636 prev_4addr != new_4addr) {
1638 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1640 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1643 ieee80211_send_layer2_update(sta);
1646 err = sta_apply_parameters(local, sta, params);
1650 /* When peer becomes authorized, init rate control as well */
1651 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1652 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1653 rate_control_rate_init(sta);
1655 mutex_unlock(&local->sta_mtx);
1657 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1658 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1659 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1660 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1661 sta_info_tx_streams(sta) != 1) {
1663 "%pM just authorized and MIMO capable - update SMPS\n",
1665 ieee80211_send_smps_action(sta->sdata,
1666 sta->sdata->bss->req_smps,
1668 sta->sdata->vif.bss_conf.bssid);
1671 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1672 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1673 ieee80211_recalc_ps(local, -1);
1674 ieee80211_recalc_ps_vif(sdata);
1679 mutex_unlock(&local->sta_mtx);
1683 #ifdef CONFIG_MAC80211_MESH
1684 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1685 const u8 *dst, const u8 *next_hop)
1687 struct ieee80211_sub_if_data *sdata;
1688 struct mesh_path *mpath;
1689 struct sta_info *sta;
1691 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1694 sta = sta_info_get(sdata, next_hop);
1700 mpath = mesh_path_add(sdata, dst);
1701 if (IS_ERR(mpath)) {
1703 return PTR_ERR(mpath);
1706 mesh_path_fix_nexthop(mpath, sta);
1712 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1718 return mesh_path_del(sdata, dst);
1720 mesh_path_flush_by_iface(sdata);
1724 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1725 const u8 *dst, const u8 *next_hop)
1727 struct ieee80211_sub_if_data *sdata;
1728 struct mesh_path *mpath;
1729 struct sta_info *sta;
1731 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1735 sta = sta_info_get(sdata, next_hop);
1741 mpath = mesh_path_lookup(sdata, dst);
1747 mesh_path_fix_nexthop(mpath, sta);
1753 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1754 struct mpath_info *pinfo)
1756 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1759 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1761 memset(next_hop, 0, ETH_ALEN);
1763 memset(pinfo, 0, sizeof(*pinfo));
1765 pinfo->generation = mesh_paths_generation;
1767 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1770 MPATH_INFO_EXPTIME |
1771 MPATH_INFO_DISCOVERY_TIMEOUT |
1772 MPATH_INFO_DISCOVERY_RETRIES |
1775 pinfo->frame_qlen = mpath->frame_queue.qlen;
1776 pinfo->sn = mpath->sn;
1777 pinfo->metric = mpath->metric;
1778 if (time_before(jiffies, mpath->exp_time))
1779 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1780 pinfo->discovery_timeout =
1781 jiffies_to_msecs(mpath->discovery_timeout);
1782 pinfo->discovery_retries = mpath->discovery_retries;
1783 if (mpath->flags & MESH_PATH_ACTIVE)
1784 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1785 if (mpath->flags & MESH_PATH_RESOLVING)
1786 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1787 if (mpath->flags & MESH_PATH_SN_VALID)
1788 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1789 if (mpath->flags & MESH_PATH_FIXED)
1790 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1791 if (mpath->flags & MESH_PATH_RESOLVED)
1792 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1795 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1796 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1799 struct ieee80211_sub_if_data *sdata;
1800 struct mesh_path *mpath;
1802 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1805 mpath = mesh_path_lookup(sdata, dst);
1810 memcpy(dst, mpath->dst, ETH_ALEN);
1811 mpath_set_pinfo(mpath, next_hop, pinfo);
1816 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1817 int idx, u8 *dst, u8 *next_hop,
1818 struct mpath_info *pinfo)
1820 struct ieee80211_sub_if_data *sdata;
1821 struct mesh_path *mpath;
1823 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1826 mpath = mesh_path_lookup_by_idx(sdata, idx);
1831 memcpy(dst, mpath->dst, ETH_ALEN);
1832 mpath_set_pinfo(mpath, next_hop, pinfo);
1837 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1838 struct net_device *dev,
1839 struct mesh_config *conf)
1841 struct ieee80211_sub_if_data *sdata;
1842 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1844 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1848 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1850 return (mask >> (parm-1)) & 0x1;
1853 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1854 const struct mesh_setup *setup)
1858 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1859 struct ieee80211_sub_if_data, u.mesh);
1861 /* allocate information elements */
1865 if (setup->ie_len) {
1866 new_ie = kmemdup(setup->ie, setup->ie_len,
1871 ifmsh->ie_len = setup->ie_len;
1875 /* now copy the rest of the setup parameters */
1876 ifmsh->mesh_id_len = setup->mesh_id_len;
1877 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1878 ifmsh->mesh_sp_id = setup->sync_method;
1879 ifmsh->mesh_pp_id = setup->path_sel_proto;
1880 ifmsh->mesh_pm_id = setup->path_metric;
1881 ifmsh->user_mpm = setup->user_mpm;
1882 ifmsh->mesh_auth_id = setup->auth_id;
1883 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1884 if (setup->is_authenticated)
1885 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1886 if (setup->is_secure)
1887 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1889 /* mcast rate setting in Mesh Node */
1890 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1891 sizeof(setup->mcast_rate));
1892 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
1894 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1895 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1900 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1901 struct net_device *dev, u32 mask,
1902 const struct mesh_config *nconf)
1904 struct mesh_config *conf;
1905 struct ieee80211_sub_if_data *sdata;
1906 struct ieee80211_if_mesh *ifmsh;
1908 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1909 ifmsh = &sdata->u.mesh;
1911 /* Set the config options which we are interested in setting */
1912 conf = &(sdata->u.mesh.mshcfg);
1913 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1914 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1915 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1916 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1917 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1918 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1919 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1920 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1921 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1922 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1923 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1924 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1925 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1926 conf->element_ttl = nconf->element_ttl;
1927 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1928 if (ifmsh->user_mpm)
1930 conf->auto_open_plinks = nconf->auto_open_plinks;
1932 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1933 conf->dot11MeshNbrOffsetMaxNeighbor =
1934 nconf->dot11MeshNbrOffsetMaxNeighbor;
1935 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1936 conf->dot11MeshHWMPmaxPREQretries =
1937 nconf->dot11MeshHWMPmaxPREQretries;
1938 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1939 conf->path_refresh_time = nconf->path_refresh_time;
1940 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1941 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1942 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1943 conf->dot11MeshHWMPactivePathTimeout =
1944 nconf->dot11MeshHWMPactivePathTimeout;
1945 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1946 conf->dot11MeshHWMPpreqMinInterval =
1947 nconf->dot11MeshHWMPpreqMinInterval;
1948 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1949 conf->dot11MeshHWMPperrMinInterval =
1950 nconf->dot11MeshHWMPperrMinInterval;
1951 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1953 conf->dot11MeshHWMPnetDiameterTraversalTime =
1954 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1955 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1956 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1957 ieee80211_mesh_root_setup(ifmsh);
1959 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1960 /* our current gate announcement implementation rides on root
1961 * announcements, so require this ifmsh to also be a root node
1963 if (nconf->dot11MeshGateAnnouncementProtocol &&
1964 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1965 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
1966 ieee80211_mesh_root_setup(ifmsh);
1968 conf->dot11MeshGateAnnouncementProtocol =
1969 nconf->dot11MeshGateAnnouncementProtocol;
1971 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
1972 conf->dot11MeshHWMPRannInterval =
1973 nconf->dot11MeshHWMPRannInterval;
1974 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1975 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1976 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1977 /* our RSSI threshold implementation is supported only for
1978 * devices that report signal in dBm.
1980 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1982 conf->rssi_threshold = nconf->rssi_threshold;
1984 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1985 conf->ht_opmode = nconf->ht_opmode;
1986 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1987 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1989 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1990 conf->dot11MeshHWMPactivePathToRootTimeout =
1991 nconf->dot11MeshHWMPactivePathToRootTimeout;
1992 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1993 conf->dot11MeshHWMProotInterval =
1994 nconf->dot11MeshHWMProotInterval;
1995 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1996 conf->dot11MeshHWMPconfirmationInterval =
1997 nconf->dot11MeshHWMPconfirmationInterval;
1998 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1999 conf->power_mode = nconf->power_mode;
2000 ieee80211_mps_local_status_update(sdata);
2002 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2003 conf->dot11MeshAwakeWindowDuration =
2004 nconf->dot11MeshAwakeWindowDuration;
2005 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2006 conf->plink_timeout = nconf->plink_timeout;
2007 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2011 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2012 const struct mesh_config *conf,
2013 const struct mesh_setup *setup)
2015 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2016 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2019 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2020 err = copy_mesh_setup(ifmsh, setup);
2024 /* can mesh use other SMPS modes? */
2025 sdata->smps_mode = IEEE80211_SMPS_OFF;
2026 sdata->needed_rx_chains = sdata->local->rx_chains;
2028 mutex_lock(&sdata->local->mtx);
2029 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
2030 IEEE80211_CHANCTX_SHARED);
2031 mutex_unlock(&sdata->local->mtx);
2035 return ieee80211_start_mesh(sdata);
2038 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2040 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2042 ieee80211_stop_mesh(sdata);
2043 mutex_lock(&sdata->local->mtx);
2044 ieee80211_vif_release_channel(sdata);
2045 mutex_unlock(&sdata->local->mtx);
2051 static int ieee80211_change_bss(struct wiphy *wiphy,
2052 struct net_device *dev,
2053 struct bss_parameters *params)
2055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2056 enum ieee80211_band band;
2059 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
2062 band = ieee80211_get_sdata_band(sdata);
2064 if (params->use_cts_prot >= 0) {
2065 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2066 changed |= BSS_CHANGED_ERP_CTS_PROT;
2068 if (params->use_short_preamble >= 0) {
2069 sdata->vif.bss_conf.use_short_preamble =
2070 params->use_short_preamble;
2071 changed |= BSS_CHANGED_ERP_PREAMBLE;
2074 if (!sdata->vif.bss_conf.use_short_slot &&
2075 band == IEEE80211_BAND_5GHZ) {
2076 sdata->vif.bss_conf.use_short_slot = true;
2077 changed |= BSS_CHANGED_ERP_SLOT;
2080 if (params->use_short_slot_time >= 0) {
2081 sdata->vif.bss_conf.use_short_slot =
2082 params->use_short_slot_time;
2083 changed |= BSS_CHANGED_ERP_SLOT;
2086 if (params->basic_rates) {
2087 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2089 params->basic_rates,
2090 params->basic_rates_len,
2091 &sdata->vif.bss_conf.basic_rates);
2092 changed |= BSS_CHANGED_BASIC_RATES;
2095 if (params->ap_isolate >= 0) {
2096 if (params->ap_isolate)
2097 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2099 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2102 if (params->ht_opmode >= 0) {
2103 sdata->vif.bss_conf.ht_operation_mode =
2104 (u16) params->ht_opmode;
2105 changed |= BSS_CHANGED_HT;
2108 if (params->p2p_ctwindow >= 0) {
2109 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2110 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2111 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2112 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2113 changed |= BSS_CHANGED_P2P_PS;
2116 if (params->p2p_opp_ps > 0) {
2117 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2118 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2119 changed |= BSS_CHANGED_P2P_PS;
2120 } else if (params->p2p_opp_ps == 0) {
2121 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2122 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2123 changed |= BSS_CHANGED_P2P_PS;
2126 ieee80211_bss_info_change_notify(sdata, changed);
2131 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2132 struct net_device *dev,
2133 struct ieee80211_txq_params *params)
2135 struct ieee80211_local *local = wiphy_priv(wiphy);
2136 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2137 struct ieee80211_tx_queue_params p;
2139 if (!local->ops->conf_tx)
2142 if (local->hw.queues < IEEE80211_NUM_ACS)
2145 memset(&p, 0, sizeof(p));
2146 p.aifs = params->aifs;
2147 p.cw_max = params->cwmax;
2148 p.cw_min = params->cwmin;
2149 p.txop = params->txop;
2152 * Setting tx queue params disables u-apsd because it's only
2153 * called in master mode.
2157 sdata->tx_conf[params->ac] = p;
2158 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2159 wiphy_debug(local->hw.wiphy,
2160 "failed to set TX queue parameters for AC %d\n",
2165 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2171 static int ieee80211_suspend(struct wiphy *wiphy,
2172 struct cfg80211_wowlan *wowlan)
2174 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2177 static int ieee80211_resume(struct wiphy *wiphy)
2179 return __ieee80211_resume(wiphy_priv(wiphy));
2182 #define ieee80211_suspend NULL
2183 #define ieee80211_resume NULL
2186 static int ieee80211_scan(struct wiphy *wiphy,
2187 struct cfg80211_scan_request *req)
2189 struct ieee80211_sub_if_data *sdata;
2191 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2193 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2194 case NL80211_IFTYPE_STATION:
2195 case NL80211_IFTYPE_ADHOC:
2196 case NL80211_IFTYPE_MESH_POINT:
2197 case NL80211_IFTYPE_P2P_CLIENT:
2198 case NL80211_IFTYPE_P2P_DEVICE:
2200 case NL80211_IFTYPE_P2P_GO:
2201 if (sdata->local->ops->hw_scan)
2204 * FIXME: implement NoA while scanning in software,
2205 * for now fall through to allow scanning only when
2206 * beaconing hasn't been configured yet
2208 case NL80211_IFTYPE_AP:
2210 * If the scan has been forced (and the driver supports
2211 * forcing), don't care about being beaconing already.
2212 * This will create problems to the attached stations (e.g. all
2213 * the frames sent while scanning on other channel will be
2216 if (sdata->u.ap.beacon &&
2217 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2218 !(req->flags & NL80211_SCAN_FLAG_AP)))
2225 return ieee80211_request_scan(sdata, req);
2229 ieee80211_sched_scan_start(struct wiphy *wiphy,
2230 struct net_device *dev,
2231 struct cfg80211_sched_scan_request *req)
2233 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2235 if (!sdata->local->ops->sched_scan_start)
2238 return ieee80211_request_sched_scan_start(sdata, req);
2242 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
2244 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2246 if (!sdata->local->ops->sched_scan_stop)
2249 return ieee80211_request_sched_scan_stop(sdata);
2252 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2253 struct cfg80211_auth_request *req)
2255 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2258 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2259 struct cfg80211_assoc_request *req)
2261 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2264 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2265 struct cfg80211_deauth_request *req)
2267 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2270 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2271 struct cfg80211_disassoc_request *req)
2273 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2276 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2277 struct cfg80211_ibss_params *params)
2279 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2282 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2284 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2287 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2288 int rate[IEEE80211_NUM_BANDS])
2290 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2292 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2293 sizeof(int) * IEEE80211_NUM_BANDS);
2298 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2300 struct ieee80211_local *local = wiphy_priv(wiphy);
2303 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2304 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2310 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2311 err = drv_set_coverage_class(local, wiphy->coverage_class);
2317 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2318 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2324 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2325 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2327 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2329 if (changed & WIPHY_PARAM_RETRY_LONG) {
2330 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2332 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2335 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2336 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2341 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2342 struct wireless_dev *wdev,
2343 enum nl80211_tx_power_setting type, int mbm)
2345 struct ieee80211_local *local = wiphy_priv(wiphy);
2346 struct ieee80211_sub_if_data *sdata;
2349 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2352 case NL80211_TX_POWER_AUTOMATIC:
2353 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2355 case NL80211_TX_POWER_LIMITED:
2356 case NL80211_TX_POWER_FIXED:
2357 if (mbm < 0 || (mbm % 100))
2359 sdata->user_power_level = MBM_TO_DBM(mbm);
2363 ieee80211_recalc_txpower(sdata);
2369 case NL80211_TX_POWER_AUTOMATIC:
2370 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2372 case NL80211_TX_POWER_LIMITED:
2373 case NL80211_TX_POWER_FIXED:
2374 if (mbm < 0 || (mbm % 100))
2376 local->user_power_level = MBM_TO_DBM(mbm);
2380 mutex_lock(&local->iflist_mtx);
2381 list_for_each_entry(sdata, &local->interfaces, list)
2382 sdata->user_power_level = local->user_power_level;
2383 list_for_each_entry(sdata, &local->interfaces, list)
2384 ieee80211_recalc_txpower(sdata);
2385 mutex_unlock(&local->iflist_mtx);
2390 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2391 struct wireless_dev *wdev,
2394 struct ieee80211_local *local = wiphy_priv(wiphy);
2395 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2397 if (!local->use_chanctx)
2398 *dbm = local->hw.conf.power_level;
2400 *dbm = sdata->vif.bss_conf.txpower;
2405 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2408 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2410 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2415 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2417 struct ieee80211_local *local = wiphy_priv(wiphy);
2419 drv_rfkill_poll(local);
2422 #ifdef CONFIG_NL80211_TESTMODE
2423 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2424 struct wireless_dev *wdev,
2425 void *data, int len)
2427 struct ieee80211_local *local = wiphy_priv(wiphy);
2428 struct ieee80211_vif *vif = NULL;
2430 if (!local->ops->testmode_cmd)
2434 struct ieee80211_sub_if_data *sdata;
2436 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2437 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2441 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2444 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2445 struct sk_buff *skb,
2446 struct netlink_callback *cb,
2447 void *data, int len)
2449 struct ieee80211_local *local = wiphy_priv(wiphy);
2451 if (!local->ops->testmode_dump)
2454 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2458 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2459 enum ieee80211_smps_mode smps_mode)
2461 struct sta_info *sta;
2462 enum ieee80211_smps_mode old_req;
2465 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2468 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2471 old_req = sdata->u.ap.req_smps;
2472 sdata->u.ap.req_smps = smps_mode;
2474 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2475 if (old_req == smps_mode ||
2476 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2479 /* If no associated stations, there's no need to do anything */
2480 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2481 sdata->smps_mode = smps_mode;
2482 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2487 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2488 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2490 mutex_lock(&sdata->local->sta_mtx);
2491 for (i = 0; i < STA_HASH_SIZE; i++) {
2492 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2493 lockdep_is_held(&sdata->local->sta_mtx));
2495 sta = rcu_dereference_protected(sta->hnext,
2496 lockdep_is_held(&sdata->local->sta_mtx))) {
2498 * Only stations associated to our AP and
2501 if (sta->sdata->bss != &sdata->u.ap)
2504 /* This station doesn't support MIMO - skip it */
2505 if (sta_info_tx_streams(sta) == 1)
2509 * Don't wake up a STA just to send the action frame
2510 * unless we are getting more restrictive.
2512 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2513 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2516 "Won't send SMPS to sleeping STA %pM\n",
2522 * If the STA is not authorized, wait until it gets
2523 * authorized and the action frame will be sent then.
2525 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2528 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2529 ieee80211_send_smps_action(sdata, smps_mode,
2531 sdata->vif.bss_conf.bssid);
2534 mutex_unlock(&sdata->local->sta_mtx);
2536 sdata->smps_mode = smps_mode;
2537 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2542 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2543 enum ieee80211_smps_mode smps_mode)
2546 enum ieee80211_smps_mode old_req;
2549 lockdep_assert_held(&sdata->wdev.mtx);
2551 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2554 old_req = sdata->u.mgd.req_smps;
2555 sdata->u.mgd.req_smps = smps_mode;
2557 if (old_req == smps_mode &&
2558 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2562 * If not associated, or current association is not an HT
2563 * association, there's no need to do anything, just store
2564 * the new value until we associate.
2566 if (!sdata->u.mgd.associated ||
2567 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2570 ap = sdata->u.mgd.associated->bssid;
2572 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2573 if (sdata->u.mgd.powersave)
2574 smps_mode = IEEE80211_SMPS_DYNAMIC;
2576 smps_mode = IEEE80211_SMPS_OFF;
2579 /* send SM PS frame to AP */
2580 err = ieee80211_send_smps_action(sdata, smps_mode,
2583 sdata->u.mgd.req_smps = old_req;
2588 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2589 bool enabled, int timeout)
2591 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2592 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2594 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2597 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2600 if (enabled == sdata->u.mgd.powersave &&
2601 timeout == local->dynamic_ps_forced_timeout)
2604 sdata->u.mgd.powersave = enabled;
2605 local->dynamic_ps_forced_timeout = timeout;
2607 /* no change, but if automatic follow powersave */
2609 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2610 sdata_unlock(sdata);
2612 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2613 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2615 ieee80211_recalc_ps(local, -1);
2616 ieee80211_recalc_ps_vif(sdata);
2621 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2622 struct net_device *dev,
2623 s32 rssi_thold, u32 rssi_hyst)
2625 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2626 struct ieee80211_vif *vif = &sdata->vif;
2627 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2629 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2630 rssi_hyst == bss_conf->cqm_rssi_hyst)
2633 bss_conf->cqm_rssi_thold = rssi_thold;
2634 bss_conf->cqm_rssi_hyst = rssi_hyst;
2636 /* tell the driver upon association, unless already associated */
2637 if (sdata->u.mgd.associated &&
2638 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2639 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2644 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2645 struct net_device *dev,
2647 const struct cfg80211_bitrate_mask *mask)
2649 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2650 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2653 if (!ieee80211_sdata_running(sdata))
2656 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2657 ret = drv_set_bitrate_mask(local, sdata, mask);
2662 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
2663 struct ieee80211_supported_band *sband = wiphy->bands[i];
2666 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2667 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2668 sizeof(mask->control[i].ht_mcs));
2670 sdata->rc_has_mcs_mask[i] = false;
2674 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2675 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2676 sdata->rc_has_mcs_mask[i] = true;
2684 static int ieee80211_start_roc_work(struct ieee80211_local *local,
2685 struct ieee80211_sub_if_data *sdata,
2686 struct ieee80211_channel *channel,
2687 unsigned int duration, u64 *cookie,
2688 struct sk_buff *txskb,
2689 enum ieee80211_roc_type type)
2691 struct ieee80211_roc_work *roc, *tmp;
2692 bool queued = false;
2695 lockdep_assert_held(&local->mtx);
2697 if (local->use_chanctx && !local->ops->remain_on_channel)
2700 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2705 * If the duration is zero, then the driver
2706 * wouldn't actually do anything. Set it to
2709 * TODO: cancel the off-channel operation
2710 * when we get the SKB's TX status and
2711 * the wait time was zero before.
2716 roc->chan = channel;
2717 roc->duration = duration;
2718 roc->req_duration = duration;
2721 roc->mgmt_tx_cookie = (unsigned long)txskb;
2723 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2724 INIT_LIST_HEAD(&roc->dependents);
2727 * cookie is either the roc cookie (for normal roc)
2728 * or the SKB (for mgmt TX)
2731 /* local->mtx protects this */
2732 local->roc_cookie_counter++;
2733 roc->cookie = local->roc_cookie_counter;
2734 /* wow, you wrapped 64 bits ... more likely a bug */
2735 if (WARN_ON(roc->cookie == 0)) {
2737 local->roc_cookie_counter++;
2739 *cookie = roc->cookie;
2741 *cookie = (unsigned long)txskb;
2744 /* if there's one pending or we're scanning, queue this one */
2745 if (!list_empty(&local->roc_list) ||
2746 local->scanning || local->radar_detect_enabled)
2747 goto out_check_combine;
2749 /* if not HW assist, just queue & schedule work */
2750 if (!local->ops->remain_on_channel) {
2751 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2755 /* otherwise actually kick it off here (for error handling) */
2757 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
2763 roc->started = true;
2767 list_for_each_entry(tmp, &local->roc_list, list) {
2768 if (tmp->chan != channel || tmp->sdata != sdata)
2772 * Extend this ROC if possible:
2774 * If it hasn't started yet, just increase the duration
2775 * and add the new one to the list of dependents.
2776 * If the type of the new ROC has higher priority, modify the
2777 * type of the previous one to match that of the new one.
2779 if (!tmp->started) {
2780 list_add_tail(&roc->list, &tmp->dependents);
2781 tmp->duration = max(tmp->duration, roc->duration);
2782 tmp->type = max(tmp->type, roc->type);
2787 /* If it has already started, it's more difficult ... */
2788 if (local->ops->remain_on_channel) {
2789 unsigned long j = jiffies;
2792 * In the offloaded ROC case, if it hasn't begun, add
2793 * this new one to the dependent list to be handled
2794 * when the master one begins. If it has begun,
2795 * check that there's still a minimum time left and
2796 * if so, start this one, transmitting the frame, but
2797 * add it to the list directly after this one with
2798 * a reduced time so we'll ask the driver to execute
2799 * it right after finishing the previous one, in the
2800 * hope that it'll also be executed right afterwards,
2801 * effectively extending the old one.
2802 * If there's no minimum time left, just add it to the
2804 * TODO: the ROC type is ignored here, assuming that it
2805 * is better to immediately use the current ROC.
2807 if (!tmp->hw_begun) {
2808 list_add_tail(&roc->list, &tmp->dependents);
2813 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2814 tmp->hw_start_time +
2815 msecs_to_jiffies(tmp->duration))) {
2818 ieee80211_handle_roc_started(roc);
2820 new_dur = roc->duration -
2821 jiffies_to_msecs(tmp->hw_start_time +
2827 /* add right after tmp */
2828 list_add(&roc->list, &tmp->list);
2830 list_add_tail(&roc->list,
2835 } else if (del_timer_sync(&tmp->work.timer)) {
2836 unsigned long new_end;
2839 * In the software ROC case, cancel the timer, if
2840 * that fails then the finish work is already
2841 * queued/pending and thus we queue the new ROC
2842 * normally, if that succeeds then we can extend
2843 * the timer duration and TX the frame (if any.)
2846 list_add_tail(&roc->list, &tmp->dependents);
2849 new_end = jiffies + msecs_to_jiffies(roc->duration);
2851 /* ok, it was started & we canceled timer */
2852 if (time_after(new_end, tmp->work.timer.expires))
2853 mod_timer(&tmp->work.timer, new_end);
2855 add_timer(&tmp->work.timer);
2857 ieee80211_handle_roc_started(roc);
2864 list_add_tail(&roc->list, &local->roc_list);
2869 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
2870 struct wireless_dev *wdev,
2871 struct ieee80211_channel *chan,
2872 unsigned int duration,
2875 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2876 struct ieee80211_local *local = sdata->local;
2879 mutex_lock(&local->mtx);
2880 ret = ieee80211_start_roc_work(local, sdata, chan,
2881 duration, cookie, NULL,
2882 IEEE80211_ROC_TYPE_NORMAL);
2883 mutex_unlock(&local->mtx);
2888 static int ieee80211_cancel_roc(struct ieee80211_local *local,
2889 u64 cookie, bool mgmt_tx)
2891 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2894 mutex_lock(&local->mtx);
2895 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
2896 struct ieee80211_roc_work *dep, *tmp2;
2898 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2899 if (!mgmt_tx && dep->cookie != cookie)
2901 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2903 /* found dependent item -- just remove it */
2904 list_del(&dep->list);
2905 mutex_unlock(&local->mtx);
2907 ieee80211_roc_notify_destroy(dep, true);
2911 if (!mgmt_tx && roc->cookie != cookie)
2913 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2921 mutex_unlock(&local->mtx);
2926 * We found the item to cancel, so do that. Note that it
2927 * may have dependents, which we also cancel (and send
2928 * the expired signal for.) Not doing so would be quite
2929 * tricky here, but we may need to fix it later.
2932 if (local->ops->remain_on_channel) {
2933 if (found->started) {
2934 ret = drv_cancel_remain_on_channel(local);
2935 if (WARN_ON_ONCE(ret)) {
2936 mutex_unlock(&local->mtx);
2941 list_del(&found->list);
2944 ieee80211_start_next_roc(local);
2945 mutex_unlock(&local->mtx);
2947 ieee80211_roc_notify_destroy(found, true);
2949 /* work may be pending so use it all the time */
2950 found->abort = true;
2951 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2953 mutex_unlock(&local->mtx);
2955 /* work will clean up etc */
2956 flush_delayed_work(&found->work);
2957 WARN_ON(!found->to_be_freed);
2964 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
2965 struct wireless_dev *wdev,
2968 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2969 struct ieee80211_local *local = sdata->local;
2971 return ieee80211_cancel_roc(local, cookie, false);
2974 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2975 struct net_device *dev,
2976 struct cfg80211_chan_def *chandef,
2979 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2980 struct ieee80211_local *local = sdata->local;
2983 mutex_lock(&local->mtx);
2984 if (!list_empty(&local->roc_list) || local->scanning) {
2989 /* whatever, but channel contexts should not complain about that one */
2990 sdata->smps_mode = IEEE80211_SMPS_OFF;
2991 sdata->needed_rx_chains = local->rx_chains;
2993 err = ieee80211_vif_use_channel(sdata, chandef,
2994 IEEE80211_CHANCTX_SHARED);
2998 ieee80211_queue_delayed_work(&sdata->local->hw,
2999 &sdata->dfs_cac_timer_work,
3000 msecs_to_jiffies(cac_time_ms));
3003 mutex_unlock(&local->mtx);
3007 static struct cfg80211_beacon_data *
3008 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3010 struct cfg80211_beacon_data *new_beacon;
3014 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3015 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3016 beacon->probe_resp_len;
3018 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3022 pos = (u8 *)(new_beacon + 1);
3023 if (beacon->head_len) {
3024 new_beacon->head_len = beacon->head_len;
3025 new_beacon->head = pos;
3026 memcpy(pos, beacon->head, beacon->head_len);
3027 pos += beacon->head_len;
3029 if (beacon->tail_len) {
3030 new_beacon->tail_len = beacon->tail_len;
3031 new_beacon->tail = pos;
3032 memcpy(pos, beacon->tail, beacon->tail_len);
3033 pos += beacon->tail_len;
3035 if (beacon->beacon_ies_len) {
3036 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3037 new_beacon->beacon_ies = pos;
3038 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3039 pos += beacon->beacon_ies_len;
3041 if (beacon->proberesp_ies_len) {
3042 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3043 new_beacon->proberesp_ies = pos;
3044 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3045 pos += beacon->proberesp_ies_len;
3047 if (beacon->assocresp_ies_len) {
3048 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3049 new_beacon->assocresp_ies = pos;
3050 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3051 pos += beacon->assocresp_ies_len;
3053 if (beacon->probe_resp_len) {
3054 new_beacon->probe_resp_len = beacon->probe_resp_len;
3055 beacon->probe_resp = pos;
3056 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3057 pos += beacon->probe_resp_len;
3063 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3065 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3067 ieee80211_queue_work(&sdata->local->hw,
3068 &sdata->csa_finalize_work);
3070 EXPORT_SYMBOL(ieee80211_csa_finish);
3072 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3077 switch (sdata->vif.type) {
3078 case NL80211_IFTYPE_AP:
3079 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
3080 kfree(sdata->u.ap.next_beacon);
3081 sdata->u.ap.next_beacon = NULL;
3087 case NL80211_IFTYPE_ADHOC:
3088 err = ieee80211_ibss_finish_csa(sdata);
3093 #ifdef CONFIG_MAC80211_MESH
3094 case NL80211_IFTYPE_MESH_POINT:
3095 err = ieee80211_mesh_finish_csa(sdata);
3109 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3111 struct ieee80211_local *local = sdata->local;
3115 sdata_assert_lock(sdata);
3116 lockdep_assert_held(&local->mtx);
3118 sdata->radar_required = sdata->csa_radar_required;
3119 err = ieee80211_vif_change_channel(sdata, &changed);
3123 if (!local->use_chanctx) {
3124 local->_oper_chandef = sdata->csa_chandef;
3125 ieee80211_hw_config(local, 0);
3128 sdata->vif.csa_active = false;
3130 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3134 ieee80211_bss_info_change_notify(sdata, changed);
3135 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3137 if (!ieee80211_csa_needs_block_tx(local))
3138 ieee80211_wake_queues_by_reason(&local->hw,
3139 IEEE80211_MAX_QUEUE_MAP,
3140 IEEE80211_QUEUE_STOP_REASON_CSA);
3145 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3147 if (__ieee80211_csa_finalize(sdata)) {
3148 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3149 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3154 void ieee80211_csa_finalize_work(struct work_struct *work)
3156 struct ieee80211_sub_if_data *sdata =
3157 container_of(work, struct ieee80211_sub_if_data,
3159 struct ieee80211_local *local = sdata->local;
3162 mutex_lock(&local->mtx);
3164 /* AP might have been stopped while waiting for the lock. */
3165 if (!sdata->vif.csa_active)
3168 if (!ieee80211_sdata_running(sdata))
3171 ieee80211_csa_finalize(sdata);
3174 mutex_unlock(&local->mtx);
3175 sdata_unlock(sdata);
3178 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3179 struct cfg80211_csa_settings *params,
3184 switch (sdata->vif.type) {
3185 case NL80211_IFTYPE_AP:
3186 sdata->u.ap.next_beacon =
3187 cfg80211_beacon_dup(¶ms->beacon_after);
3188 if (!sdata->u.ap.next_beacon)
3192 * With a count of 0, we don't have to wait for any
3193 * TBTT before switching, so complete the CSA
3194 * immediately. In theory, with a count == 1 we
3195 * should delay the switch until just before the next
3196 * TBTT, but that would complicate things so we switch
3197 * immediately too. If we would delay the switch
3198 * until the next TBTT, we would have to set the probe
3201 * TODO: A channel switch with count <= 1 without
3202 * sending a CSA action frame is kind of useless,
3203 * because the clients won't know we're changing
3204 * channels. The action frame must be implemented
3205 * either here or in the userspace.
3207 if (params->count <= 1)
3210 if ((params->n_counter_offsets_beacon >
3211 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3212 (params->n_counter_offsets_presp >
3213 IEEE80211_MAX_CSA_COUNTERS_NUM))
3216 /* make sure we don't have garbage in other counters */
3217 memset(sdata->csa_counter_offset_beacon, 0,
3218 sizeof(sdata->csa_counter_offset_beacon));
3219 memset(sdata->csa_counter_offset_presp, 0,
3220 sizeof(sdata->csa_counter_offset_presp));
3222 memcpy(sdata->csa_counter_offset_beacon,
3223 params->counter_offsets_beacon,
3224 params->n_counter_offsets_beacon * sizeof(u16));
3225 memcpy(sdata->csa_counter_offset_presp,
3226 params->counter_offsets_presp,
3227 params->n_counter_offsets_presp * sizeof(u16));
3229 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa);
3231 kfree(sdata->u.ap.next_beacon);
3237 case NL80211_IFTYPE_ADHOC:
3238 if (!sdata->vif.bss_conf.ibss_joined)
3241 if (params->chandef.width != sdata->u.ibss.chandef.width)
3244 switch (params->chandef.width) {
3245 case NL80211_CHAN_WIDTH_40:
3246 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3247 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3249 case NL80211_CHAN_WIDTH_5:
3250 case NL80211_CHAN_WIDTH_10:
3251 case NL80211_CHAN_WIDTH_20_NOHT:
3252 case NL80211_CHAN_WIDTH_20:
3258 /* changes into another band are not supported */
3259 if (sdata->u.ibss.chandef.chan->band !=
3260 params->chandef.chan->band)
3263 /* see comments in the NL80211_IFTYPE_AP block */
3264 if (params->count > 1) {
3265 err = ieee80211_ibss_csa_beacon(sdata, params);
3271 ieee80211_send_action_csa(sdata, params);
3274 #ifdef CONFIG_MAC80211_MESH
3275 case NL80211_IFTYPE_MESH_POINT: {
3276 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3278 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3281 /* changes into another band are not supported */
3282 if (sdata->vif.bss_conf.chandef.chan->band !=
3283 params->chandef.chan->band)
3286 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3287 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3288 if (!ifmsh->pre_value)
3289 ifmsh->pre_value = 1;
3294 /* see comments in the NL80211_IFTYPE_AP block */
3295 if (params->count > 1) {
3296 err = ieee80211_mesh_csa_beacon(sdata, params);
3298 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3304 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3305 ieee80211_send_action_csa(sdata, params);
3318 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3319 struct cfg80211_csa_settings *params)
3321 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3322 struct ieee80211_local *local = sdata->local;
3323 struct ieee80211_chanctx_conf *conf;
3324 struct ieee80211_chanctx *chanctx;
3325 int err, num_chanctx, changed = 0;
3327 sdata_assert_lock(sdata);
3328 lockdep_assert_held(&local->mtx);
3330 if (!list_empty(&local->roc_list) || local->scanning)
3333 if (sdata->wdev.cac_started)
3336 if (cfg80211_chandef_identical(¶ms->chandef,
3337 &sdata->vif.bss_conf.chandef))
3340 mutex_lock(&local->chanctx_mtx);
3341 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3342 lockdep_is_held(&local->chanctx_mtx));
3344 mutex_unlock(&local->chanctx_mtx);
3348 /* don't handle for multi-VIF cases */
3349 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3350 if (ieee80211_chanctx_refcount(local, chanctx) > 1) {
3351 mutex_unlock(&local->chanctx_mtx);
3355 list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
3357 mutex_unlock(&local->chanctx_mtx);
3359 if (num_chanctx > 1)
3362 /* don't allow another channel switch if one is already active. */
3363 if (sdata->vif.csa_active)
3366 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3370 sdata->csa_radar_required = params->radar_required;
3371 sdata->csa_chandef = params->chandef;
3372 sdata->csa_block_tx = params->block_tx;
3373 sdata->csa_current_counter = params->count;
3374 sdata->vif.csa_active = true;
3376 if (sdata->csa_block_tx)
3377 ieee80211_stop_queues_by_reason(&local->hw,
3378 IEEE80211_MAX_QUEUE_MAP,
3379 IEEE80211_QUEUE_STOP_REASON_CSA);
3382 ieee80211_bss_info_change_notify(sdata, changed);
3383 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3385 /* if the beacon didn't change, we can finalize immediately */
3386 ieee80211_csa_finalize(sdata);
3392 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3393 struct cfg80211_csa_settings *params)
3395 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3396 struct ieee80211_local *local = sdata->local;
3399 mutex_lock(&local->mtx);
3400 err = __ieee80211_channel_switch(wiphy, dev, params);
3401 mutex_unlock(&local->mtx);
3406 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
3407 struct cfg80211_mgmt_tx_params *params,
3410 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3411 struct ieee80211_local *local = sdata->local;
3412 struct sk_buff *skb;
3413 struct sta_info *sta;
3414 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
3415 bool need_offchan = false;
3420 if (params->dont_wait_for_ack)
3421 flags = IEEE80211_TX_CTL_NO_ACK;
3423 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3424 IEEE80211_TX_CTL_REQ_TX_STATUS;
3427 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3429 switch (sdata->vif.type) {
3430 case NL80211_IFTYPE_ADHOC:
3431 if (!sdata->vif.bss_conf.ibss_joined)
3432 need_offchan = true;
3434 #ifdef CONFIG_MAC80211_MESH
3435 case NL80211_IFTYPE_MESH_POINT:
3436 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3437 !sdata->u.mesh.mesh_id_len)
3438 need_offchan = true;
3441 case NL80211_IFTYPE_AP:
3442 case NL80211_IFTYPE_AP_VLAN:
3443 case NL80211_IFTYPE_P2P_GO:
3444 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3445 !ieee80211_vif_is_mesh(&sdata->vif) &&
3446 !rcu_access_pointer(sdata->bss->beacon))
3447 need_offchan = true;
3448 if (!ieee80211_is_action(mgmt->frame_control) ||
3449 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
3450 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3451 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
3454 sta = sta_info_get(sdata, mgmt->da);
3459 case NL80211_IFTYPE_STATION:
3460 case NL80211_IFTYPE_P2P_CLIENT:
3461 if (!sdata->u.mgd.associated)
3462 need_offchan = true;
3464 case NL80211_IFTYPE_P2P_DEVICE:
3465 need_offchan = true;
3471 /* configurations requiring offchan cannot work if no channel has been
3474 if (need_offchan && !params->chan)
3477 mutex_lock(&local->mtx);
3479 /* Check if the operating channel is the requested channel */
3480 if (!need_offchan) {
3481 struct ieee80211_chanctx_conf *chanctx_conf;
3484 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3487 need_offchan = params->chan &&
3489 chanctx_conf->def.chan);
3490 } else if (!params->chan) {
3495 need_offchan = true;
3500 if (need_offchan && !params->offchan) {
3505 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
3510 skb_reserve(skb, local->hw.extra_tx_headroom);
3512 data = skb_put(skb, params->len);
3513 memcpy(data, params->buf, params->len);
3515 /* Update CSA counters */
3516 if (sdata->vif.csa_active &&
3517 (sdata->vif.type == NL80211_IFTYPE_AP ||
3518 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3519 params->n_csa_offsets) {
3521 u8 c = sdata->csa_current_counter;
3523 for (i = 0; i < params->n_csa_offsets; i++)
3524 data[params->csa_offsets[i]] = c;
3527 IEEE80211_SKB_CB(skb)->flags = flags;
3529 skb->dev = sdata->dev;
3531 if (!need_offchan) {
3532 *cookie = (unsigned long) skb;
3533 ieee80211_tx_skb(sdata, skb);
3538 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3539 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
3540 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
3541 IEEE80211_SKB_CB(skb)->hw_queue =
3542 local->hw.offchannel_tx_hw_queue;
3544 /* This will handle all kinds of coalescing and immediate TX */
3545 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3546 params->wait, cookie, skb,
3547 IEEE80211_ROC_TYPE_MGMT_TX);
3551 mutex_unlock(&local->mtx);
3555 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
3556 struct wireless_dev *wdev,
3559 struct ieee80211_local *local = wiphy_priv(wiphy);
3561 return ieee80211_cancel_roc(local, cookie, true);
3564 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
3565 struct wireless_dev *wdev,
3566 u16 frame_type, bool reg)
3568 struct ieee80211_local *local = wiphy_priv(wiphy);
3570 switch (frame_type) {
3571 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3573 local->probe_req_reg++;
3575 local->probe_req_reg--;
3577 if (!local->open_count)
3580 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3587 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3589 struct ieee80211_local *local = wiphy_priv(wiphy);
3594 return drv_set_antenna(local, tx_ant, rx_ant);
3597 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3599 struct ieee80211_local *local = wiphy_priv(wiphy);
3601 return drv_get_antenna(local, tx_ant, rx_ant);
3604 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
3606 struct ieee80211_local *local = wiphy_priv(wiphy);
3608 return drv_set_ringparam(local, tx, rx);
3611 static void ieee80211_get_ringparam(struct wiphy *wiphy,
3612 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
3614 struct ieee80211_local *local = wiphy_priv(wiphy);
3616 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
3619 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3620 struct net_device *dev,
3621 struct cfg80211_gtk_rekey_data *data)
3623 struct ieee80211_local *local = wiphy_priv(wiphy);
3624 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3626 if (!local->ops->set_rekey_data)
3629 drv_set_rekey_data(local, sdata, data);
3634 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3635 const u8 *peer, u64 *cookie)
3637 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3638 struct ieee80211_local *local = sdata->local;
3639 struct ieee80211_qos_hdr *nullfunc;
3640 struct sk_buff *skb;
3641 int size = sizeof(*nullfunc);
3644 struct ieee80211_tx_info *info;
3645 struct sta_info *sta;
3646 struct ieee80211_chanctx_conf *chanctx_conf;
3647 enum ieee80211_band band;
3650 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3651 if (WARN_ON(!chanctx_conf)) {
3655 band = chanctx_conf->def.chan->band;
3656 sta = sta_info_get_bss(sdata, peer);
3658 qos = test_sta_flag(sta, WLAN_STA_WME);
3665 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3666 IEEE80211_STYPE_QOS_NULLFUNC |
3667 IEEE80211_FCTL_FROMDS);
3670 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3671 IEEE80211_STYPE_NULLFUNC |
3672 IEEE80211_FCTL_FROMDS);
3675 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3683 skb_reserve(skb, local->hw.extra_tx_headroom);
3685 nullfunc = (void *) skb_put(skb, size);
3686 nullfunc->frame_control = fc;
3687 nullfunc->duration_id = 0;
3688 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3689 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3690 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3691 nullfunc->seq_ctrl = 0;
3693 info = IEEE80211_SKB_CB(skb);
3695 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3696 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3698 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3701 nullfunc->qos_ctrl = cpu_to_le16(7);
3704 ieee80211_xmit(sdata, skb, band);
3708 *cookie = (unsigned long) skb;
3712 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3713 struct wireless_dev *wdev,
3714 struct cfg80211_chan_def *chandef)
3716 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3717 struct ieee80211_local *local = wiphy_priv(wiphy);
3718 struct ieee80211_chanctx_conf *chanctx_conf;
3722 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3724 *chandef = chanctx_conf->def;
3726 } else if (local->open_count > 0 &&
3727 local->open_count == local->monitors &&
3728 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3729 if (local->use_chanctx)
3730 *chandef = local->monitor_chandef;
3732 *chandef = local->_oper_chandef;
3741 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3743 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3747 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3748 struct net_device *dev,
3749 struct cfg80211_qos_map *qos_map)
3751 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3752 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3755 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3758 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3760 /* A NULL qos_map was passed to disable QoS mapping */
3764 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3765 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3767 kfree_rcu(old_qos_map, rcu_head);
3772 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3773 struct net_device *dev,
3774 struct cfg80211_chan_def *chandef)
3776 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3780 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3782 ieee80211_bss_info_change_notify(sdata, changed);
3787 const struct cfg80211_ops mac80211_config_ops = {
3788 .add_virtual_intf = ieee80211_add_iface,
3789 .del_virtual_intf = ieee80211_del_iface,
3790 .change_virtual_intf = ieee80211_change_iface,
3791 .start_p2p_device = ieee80211_start_p2p_device,
3792 .stop_p2p_device = ieee80211_stop_p2p_device,
3793 .add_key = ieee80211_add_key,
3794 .del_key = ieee80211_del_key,
3795 .get_key = ieee80211_get_key,
3796 .set_default_key = ieee80211_config_default_key,
3797 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3798 .start_ap = ieee80211_start_ap,
3799 .change_beacon = ieee80211_change_beacon,
3800 .stop_ap = ieee80211_stop_ap,
3801 .add_station = ieee80211_add_station,
3802 .del_station = ieee80211_del_station,
3803 .change_station = ieee80211_change_station,
3804 .get_station = ieee80211_get_station,
3805 .dump_station = ieee80211_dump_station,
3806 .dump_survey = ieee80211_dump_survey,
3807 #ifdef CONFIG_MAC80211_MESH
3808 .add_mpath = ieee80211_add_mpath,
3809 .del_mpath = ieee80211_del_mpath,
3810 .change_mpath = ieee80211_change_mpath,
3811 .get_mpath = ieee80211_get_mpath,
3812 .dump_mpath = ieee80211_dump_mpath,
3813 .update_mesh_config = ieee80211_update_mesh_config,
3814 .get_mesh_config = ieee80211_get_mesh_config,
3815 .join_mesh = ieee80211_join_mesh,
3816 .leave_mesh = ieee80211_leave_mesh,
3818 .change_bss = ieee80211_change_bss,
3819 .set_txq_params = ieee80211_set_txq_params,
3820 .set_monitor_channel = ieee80211_set_monitor_channel,
3821 .suspend = ieee80211_suspend,
3822 .resume = ieee80211_resume,
3823 .scan = ieee80211_scan,
3824 .sched_scan_start = ieee80211_sched_scan_start,
3825 .sched_scan_stop = ieee80211_sched_scan_stop,
3826 .auth = ieee80211_auth,
3827 .assoc = ieee80211_assoc,
3828 .deauth = ieee80211_deauth,
3829 .disassoc = ieee80211_disassoc,
3830 .join_ibss = ieee80211_join_ibss,
3831 .leave_ibss = ieee80211_leave_ibss,
3832 .set_mcast_rate = ieee80211_set_mcast_rate,
3833 .set_wiphy_params = ieee80211_set_wiphy_params,
3834 .set_tx_power = ieee80211_set_tx_power,
3835 .get_tx_power = ieee80211_get_tx_power,
3836 .set_wds_peer = ieee80211_set_wds_peer,
3837 .rfkill_poll = ieee80211_rfkill_poll,
3838 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3839 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3840 .set_power_mgmt = ieee80211_set_power_mgmt,
3841 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3842 .remain_on_channel = ieee80211_remain_on_channel,
3843 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3844 .mgmt_tx = ieee80211_mgmt_tx,
3845 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3846 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3847 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3848 .set_antenna = ieee80211_set_antenna,
3849 .get_antenna = ieee80211_get_antenna,
3850 .set_ringparam = ieee80211_set_ringparam,
3851 .get_ringparam = ieee80211_get_ringparam,
3852 .set_rekey_data = ieee80211_set_rekey_data,
3853 .tdls_oper = ieee80211_tdls_oper,
3854 .tdls_mgmt = ieee80211_tdls_mgmt,
3855 .probe_client = ieee80211_probe_client,
3856 .set_noack_map = ieee80211_set_noack_map,
3858 .set_wakeup = ieee80211_set_wakeup,
3860 .get_et_sset_count = ieee80211_get_et_sset_count,
3861 .get_et_stats = ieee80211_get_et_stats,
3862 .get_et_strings = ieee80211_get_et_strings,
3863 .get_channel = ieee80211_cfg_get_channel,
3864 .start_radar_detection = ieee80211_start_radar_detection,
3865 .channel_switch = ieee80211_channel_switch,
3866 .set_qos_map = ieee80211_set_qos_map,
3867 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,