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)) {
77 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
78 * changed while the interface is up.
79 * Else we would need to add a lot of cruft
80 * to update everything:
81 * cooked_mntrs, monitor and all fif_* counters
82 * reconfigure hardware
84 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
85 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
88 ieee80211_adjust_monitor_flags(sdata, -1);
89 sdata->u.mntr_flags = *flags;
90 ieee80211_adjust_monitor_flags(sdata, 1);
92 ieee80211_configure_filter(local);
95 * Because the interface is down, ieee80211_do_stop
96 * and ieee80211_do_open take care of "everything"
97 * mentioned in the comment above.
99 sdata->u.mntr_flags = *flags;
106 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
107 struct wireless_dev *wdev)
109 return ieee80211_do_open(wdev, true);
112 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
113 struct wireless_dev *wdev)
115 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
118 static int ieee80211_set_noack_map(struct wiphy *wiphy,
119 struct net_device *dev,
122 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
124 sdata->noack_map = noack_map;
128 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
129 u8 key_idx, bool pairwise, const u8 *mac_addr,
130 struct key_params *params)
132 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
133 struct sta_info *sta = NULL;
134 struct ieee80211_key *key;
137 if (!ieee80211_sdata_running(sdata))
140 /* reject WEP and TKIP keys if WEP failed to initialize */
141 switch (params->cipher) {
142 case WLAN_CIPHER_SUITE_WEP40:
143 case WLAN_CIPHER_SUITE_TKIP:
144 case WLAN_CIPHER_SUITE_WEP104:
145 if (IS_ERR(sdata->local->wep_tx_tfm))
152 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
153 params->key, params->seq_len, params->seq);
158 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
160 mutex_lock(&sdata->local->sta_mtx);
163 if (ieee80211_vif_is_mesh(&sdata->vif))
164 sta = sta_info_get(sdata, mac_addr);
166 sta = sta_info_get_bss(sdata, mac_addr);
168 * The ASSOC test makes sure the driver is ready to
169 * receive the key. When wpa_supplicant has roamed
170 * using FT, it attempts to set the key before
171 * association has completed, this rejects that attempt
172 * so it will set the key again after assocation.
174 * TODO: accept the key if we have a station entry and
175 * add it to the device after the station.
177 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
178 ieee80211_key_free_unused(key);
184 switch (sdata->vif.type) {
185 case NL80211_IFTYPE_STATION:
186 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
187 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
189 case NL80211_IFTYPE_AP:
190 case NL80211_IFTYPE_AP_VLAN:
191 /* Keys without a station are used for TX only */
192 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
193 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
195 case NL80211_IFTYPE_ADHOC:
198 case NL80211_IFTYPE_MESH_POINT:
199 #ifdef CONFIG_MAC80211_MESH
200 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
201 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
204 case NL80211_IFTYPE_WDS:
205 case NL80211_IFTYPE_MONITOR:
206 case NL80211_IFTYPE_P2P_DEVICE:
207 case NL80211_IFTYPE_UNSPECIFIED:
208 case NUM_NL80211_IFTYPES:
209 case NL80211_IFTYPE_P2P_CLIENT:
210 case NL80211_IFTYPE_P2P_GO:
211 /* shouldn't happen */
216 err = ieee80211_key_link(key, sdata, sta);
219 mutex_unlock(&sdata->local->sta_mtx);
224 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
225 u8 key_idx, bool pairwise, const u8 *mac_addr)
227 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
228 struct ieee80211_local *local = sdata->local;
229 struct sta_info *sta;
230 struct ieee80211_key *key = NULL;
233 mutex_lock(&local->sta_mtx);
234 mutex_lock(&local->key_mtx);
239 sta = sta_info_get_bss(sdata, mac_addr);
244 key = key_mtx_dereference(local, sta->ptk);
246 key = key_mtx_dereference(local, sta->gtk[key_idx]);
248 key = key_mtx_dereference(local, sdata->keys[key_idx]);
255 ieee80211_key_free(key, true);
259 mutex_unlock(&local->key_mtx);
260 mutex_unlock(&local->sta_mtx);
265 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
266 u8 key_idx, bool pairwise, const u8 *mac_addr,
268 void (*callback)(void *cookie,
269 struct key_params *params))
271 struct ieee80211_sub_if_data *sdata;
272 struct sta_info *sta = NULL;
274 struct key_params params;
275 struct ieee80211_key *key = NULL;
281 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
286 sta = sta_info_get_bss(sdata, mac_addr);
291 key = rcu_dereference(sta->ptk);
292 else if (key_idx < NUM_DEFAULT_KEYS)
293 key = rcu_dereference(sta->gtk[key_idx]);
295 key = rcu_dereference(sdata->keys[key_idx]);
300 memset(¶ms, 0, sizeof(params));
302 params.cipher = key->conf.cipher;
304 switch (key->conf.cipher) {
305 case WLAN_CIPHER_SUITE_TKIP:
306 iv32 = key->u.tkip.tx.iv32;
307 iv16 = key->u.tkip.tx.iv16;
309 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
310 drv_get_tkip_seq(sdata->local,
311 key->conf.hw_key_idx,
314 seq[0] = iv16 & 0xff;
315 seq[1] = (iv16 >> 8) & 0xff;
316 seq[2] = iv32 & 0xff;
317 seq[3] = (iv32 >> 8) & 0xff;
318 seq[4] = (iv32 >> 16) & 0xff;
319 seq[5] = (iv32 >> 24) & 0xff;
323 case WLAN_CIPHER_SUITE_CCMP:
324 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
334 case WLAN_CIPHER_SUITE_AES_CMAC:
335 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
347 params.key = key->conf.key;
348 params.key_len = key->conf.keylen;
350 callback(cookie, ¶ms);
358 static int ieee80211_config_default_key(struct wiphy *wiphy,
359 struct net_device *dev,
360 u8 key_idx, bool uni,
363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
365 ieee80211_set_default_key(sdata, key_idx, uni, multi);
370 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
371 struct net_device *dev,
374 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
376 ieee80211_set_default_mgmt_key(sdata, key_idx);
381 void sta_set_rate_info_tx(struct sta_info *sta,
382 const struct ieee80211_tx_rate *rate,
383 struct rate_info *rinfo)
386 if (rate->flags & IEEE80211_TX_RC_MCS) {
387 rinfo->flags |= RATE_INFO_FLAGS_MCS;
388 rinfo->mcs = rate->idx;
389 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
390 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
391 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
392 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
394 struct ieee80211_supported_band *sband;
395 sband = sta->local->hw.wiphy->bands[
396 ieee80211_get_sdata_band(sta->sdata)];
397 rinfo->legacy = sband->bitrates[rate->idx].bitrate;
399 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
400 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
401 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
402 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
403 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
404 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
405 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
406 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
409 void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
413 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
414 rinfo->flags |= RATE_INFO_FLAGS_MCS;
415 rinfo->mcs = sta->last_rx_rate_idx;
416 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
417 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
418 rinfo->nss = sta->last_rx_rate_vht_nss;
419 rinfo->mcs = sta->last_rx_rate_idx;
421 struct ieee80211_supported_band *sband;
423 sband = sta->local->hw.wiphy->bands[
424 ieee80211_get_sdata_band(sta->sdata)];
426 sband->bitrates[sta->last_rx_rate_idx].bitrate;
429 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
430 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
431 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
432 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
433 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
434 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
435 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
436 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
437 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
438 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
441 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
443 struct ieee80211_sub_if_data *sdata = sta->sdata;
444 struct ieee80211_local *local = sdata->local;
445 struct timespec uptime;
449 sinfo->generation = sdata->local->sta_generation;
451 sinfo->filled = STATION_INFO_INACTIVE_TIME |
452 STATION_INFO_RX_BYTES64 |
453 STATION_INFO_TX_BYTES64 |
454 STATION_INFO_RX_PACKETS |
455 STATION_INFO_TX_PACKETS |
456 STATION_INFO_TX_RETRIES |
457 STATION_INFO_TX_FAILED |
458 STATION_INFO_TX_BITRATE |
459 STATION_INFO_RX_BITRATE |
460 STATION_INFO_RX_DROP_MISC |
461 STATION_INFO_BSS_PARAM |
462 STATION_INFO_CONNECTED_TIME |
463 STATION_INFO_STA_FLAGS |
464 STATION_INFO_BEACON_LOSS_COUNT;
466 do_posix_clock_monotonic_gettime(&uptime);
467 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
469 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
471 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
472 sinfo->tx_bytes += sta->tx_bytes[ac];
473 packets += sta->tx_packets[ac];
475 sinfo->tx_packets = packets;
476 sinfo->rx_bytes = sta->rx_bytes;
477 sinfo->rx_packets = sta->rx_packets;
478 sinfo->tx_retries = sta->tx_retry_count;
479 sinfo->tx_failed = sta->tx_retry_failed;
480 sinfo->rx_dropped_misc = sta->rx_dropped;
481 sinfo->beacon_loss_count = sta->beacon_loss_count;
483 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
484 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
485 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
486 if (!local->ops->get_rssi ||
487 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
488 sinfo->signal = (s8)sta->last_signal;
489 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
492 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
493 sta_set_rate_info_rx(sta, &sinfo->rxrate);
495 if (ieee80211_vif_is_mesh(&sdata->vif)) {
496 #ifdef CONFIG_MAC80211_MESH
497 sinfo->filled |= STATION_INFO_LLID |
499 STATION_INFO_PLINK_STATE |
500 STATION_INFO_LOCAL_PM |
501 STATION_INFO_PEER_PM |
502 STATION_INFO_NONPEER_PM;
504 sinfo->llid = le16_to_cpu(sta->llid);
505 sinfo->plid = le16_to_cpu(sta->plid);
506 sinfo->plink_state = sta->plink_state;
507 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
508 sinfo->filled |= STATION_INFO_T_OFFSET;
509 sinfo->t_offset = sta->t_offset;
511 sinfo->local_pm = sta->local_pm;
512 sinfo->peer_pm = sta->peer_pm;
513 sinfo->nonpeer_pm = sta->nonpeer_pm;
517 sinfo->bss_param.flags = 0;
518 if (sdata->vif.bss_conf.use_cts_prot)
519 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
520 if (sdata->vif.bss_conf.use_short_preamble)
521 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
522 if (sdata->vif.bss_conf.use_short_slot)
523 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
524 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
525 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
527 sinfo->sta_flags.set = 0;
528 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
529 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
530 BIT(NL80211_STA_FLAG_WME) |
531 BIT(NL80211_STA_FLAG_MFP) |
532 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
533 BIT(NL80211_STA_FLAG_ASSOCIATED) |
534 BIT(NL80211_STA_FLAG_TDLS_PEER);
535 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
536 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
537 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
538 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
539 if (test_sta_flag(sta, WLAN_STA_WME))
540 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
541 if (test_sta_flag(sta, WLAN_STA_MFP))
542 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
543 if (test_sta_flag(sta, WLAN_STA_AUTH))
544 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
545 if (test_sta_flag(sta, WLAN_STA_ASSOC))
546 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
547 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
548 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
551 static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
552 "rx_packets", "rx_bytes", "wep_weak_iv_count",
553 "rx_duplicates", "rx_fragments", "rx_dropped",
554 "tx_packets", "tx_bytes", "tx_fragments",
555 "tx_filtered", "tx_retry_failed", "tx_retries",
556 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
557 "channel", "noise", "ch_time", "ch_time_busy",
558 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
560 #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
562 static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
563 struct net_device *dev,
566 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
569 if (sset == ETH_SS_STATS)
572 rv += drv_get_et_sset_count(sdata, sset);
579 static void ieee80211_get_et_stats(struct wiphy *wiphy,
580 struct net_device *dev,
581 struct ethtool_stats *stats,
584 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
585 struct ieee80211_chanctx_conf *chanctx_conf;
586 struct ieee80211_channel *channel;
587 struct sta_info *sta;
588 struct ieee80211_local *local = sdata->local;
589 struct station_info sinfo;
590 struct survey_info survey;
592 #define STA_STATS_SURVEY_LEN 7
594 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
596 #define ADD_STA_STATS(sta) \
598 data[i++] += sta->rx_packets; \
599 data[i++] += sta->rx_bytes; \
600 data[i++] += sta->wep_weak_iv_count; \
601 data[i++] += sta->num_duplicates; \
602 data[i++] += sta->rx_fragments; \
603 data[i++] += sta->rx_dropped; \
605 data[i++] += sinfo.tx_packets; \
606 data[i++] += sinfo.tx_bytes; \
607 data[i++] += sta->tx_fragments; \
608 data[i++] += sta->tx_filtered_count; \
609 data[i++] += sta->tx_retry_failed; \
610 data[i++] += sta->tx_retry_count; \
611 data[i++] += sta->beacon_loss_count; \
614 /* For Managed stations, find the single station based on BSSID
615 * and use that. For interface types, iterate through all available
616 * stations and add stats for any station that is assigned to this
620 mutex_lock(&local->sta_mtx);
622 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
623 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
625 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
629 sta_set_sinfo(sta, &sinfo);
634 data[i++] = sta->sta_state;
637 if (sinfo.filled & STATION_INFO_TX_BITRATE)
639 cfg80211_calculate_bitrate(&sinfo.txrate);
641 if (sinfo.filled & STATION_INFO_RX_BITRATE)
643 cfg80211_calculate_bitrate(&sinfo.rxrate);
646 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
647 data[i] = (u8)sinfo.signal_avg;
650 list_for_each_entry(sta, &local->sta_list, list) {
651 /* Make sure this station belongs to the proper dev */
652 if (sta->sdata->dev != dev)
656 sta_set_sinfo(sta, &sinfo);
663 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
664 /* Get survey stats for current channel */
668 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
670 channel = chanctx_conf->def.chan;
679 if (drv_get_survey(local, q, &survey) != 0) {
684 } while (channel != survey.channel);
688 data[i++] = survey.channel->center_freq;
691 if (survey.filled & SURVEY_INFO_NOISE_DBM)
692 data[i++] = (u8)survey.noise;
695 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
696 data[i++] = survey.channel_time;
699 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
700 data[i++] = survey.channel_time_busy;
703 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
704 data[i++] = survey.channel_time_ext_busy;
707 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
708 data[i++] = survey.channel_time_rx;
711 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
712 data[i++] = survey.channel_time_tx;
716 mutex_unlock(&local->sta_mtx);
718 if (WARN_ON(i != STA_STATS_LEN))
721 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
724 static void ieee80211_get_et_strings(struct wiphy *wiphy,
725 struct net_device *dev,
728 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
729 int sz_sta_stats = 0;
731 if (sset == ETH_SS_STATS) {
732 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
733 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
735 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
738 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
739 int idx, u8 *mac, struct station_info *sinfo)
741 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
742 struct ieee80211_local *local = sdata->local;
743 struct sta_info *sta;
746 mutex_lock(&local->sta_mtx);
748 sta = sta_info_get_by_idx(sdata, idx);
751 memcpy(mac, sta->sta.addr, ETH_ALEN);
752 sta_set_sinfo(sta, sinfo);
755 mutex_unlock(&local->sta_mtx);
760 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
761 int idx, struct survey_info *survey)
763 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
765 return drv_get_survey(local, idx, survey);
768 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
769 u8 *mac, struct station_info *sinfo)
771 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
772 struct ieee80211_local *local = sdata->local;
773 struct sta_info *sta;
776 mutex_lock(&local->sta_mtx);
778 sta = sta_info_get_bss(sdata, mac);
781 sta_set_sinfo(sta, sinfo);
784 mutex_unlock(&local->sta_mtx);
789 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
790 struct cfg80211_chan_def *chandef)
792 struct ieee80211_local *local = wiphy_priv(wiphy);
793 struct ieee80211_sub_if_data *sdata;
796 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
799 mutex_lock(&local->iflist_mtx);
800 if (local->use_chanctx) {
801 sdata = rcu_dereference_protected(
802 local->monitor_sdata,
803 lockdep_is_held(&local->iflist_mtx));
805 ieee80211_vif_release_channel(sdata);
806 ret = ieee80211_vif_use_channel(sdata, chandef,
807 IEEE80211_CHANCTX_EXCLUSIVE);
809 } else if (local->open_count == local->monitors) {
810 local->_oper_chandef = *chandef;
811 ieee80211_hw_config(local, 0);
815 local->monitor_chandef = *chandef;
816 mutex_unlock(&local->iflist_mtx);
821 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
822 const u8 *resp, size_t resp_len)
824 struct probe_resp *new, *old;
826 if (!resp || !resp_len)
829 old = rtnl_dereference(sdata->u.ap.probe_resp);
831 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
836 memcpy(new->data, resp, resp_len);
838 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
840 kfree_rcu(old, rcu_head);
845 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
846 struct cfg80211_beacon_data *params)
848 struct beacon_data *new, *old;
849 int new_head_len, new_tail_len;
851 u32 changed = BSS_CHANGED_BEACON;
853 old = rtnl_dereference(sdata->u.ap.beacon);
855 /* Need to have a beacon head if we don't have one yet */
856 if (!params->head && !old)
859 /* new or old head? */
861 new_head_len = params->head_len;
863 new_head_len = old->head_len;
865 /* new or old tail? */
866 if (params->tail || !old)
867 /* params->tail_len will be zero for !params->tail */
868 new_tail_len = params->tail_len;
870 new_tail_len = old->tail_len;
872 size = sizeof(*new) + new_head_len + new_tail_len;
874 new = kzalloc(size, GFP_KERNEL);
878 /* start filling the new info now */
881 * pointers go into the block we allocated,
882 * memory is | beacon_data | head | tail |
884 new->head = ((u8 *) new) + sizeof(*new);
885 new->tail = new->head + new_head_len;
886 new->head_len = new_head_len;
887 new->tail_len = new_tail_len;
891 memcpy(new->head, params->head, new_head_len);
893 memcpy(new->head, old->head, new_head_len);
895 /* copy in optional tail */
897 memcpy(new->tail, params->tail, new_tail_len);
900 memcpy(new->tail, old->tail, new_tail_len);
902 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
903 params->probe_resp_len);
907 changed |= BSS_CHANGED_AP_PROBE_RESP;
909 rcu_assign_pointer(sdata->u.ap.beacon, new);
912 kfree_rcu(old, rcu_head);
917 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
918 struct cfg80211_ap_settings *params)
920 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
921 struct beacon_data *old;
922 struct ieee80211_sub_if_data *vlan;
923 u32 changed = BSS_CHANGED_BEACON_INT |
924 BSS_CHANGED_BEACON_ENABLED |
930 old = rtnl_dereference(sdata->u.ap.beacon);
934 /* TODO: make hostapd tell us what it wants */
935 sdata->smps_mode = IEEE80211_SMPS_OFF;
936 sdata->needed_rx_chains = sdata->local->rx_chains;
937 sdata->radar_required = params->radar_required;
939 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
940 IEEE80211_CHANCTX_SHARED);
943 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
946 * Apply control port protocol, this allows us to
947 * not encrypt dynamic WEP control frames.
949 sdata->control_port_protocol = params->crypto.control_port_ethertype;
950 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
951 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
952 vlan->control_port_protocol =
953 params->crypto.control_port_ethertype;
954 vlan->control_port_no_encrypt =
955 params->crypto.control_port_no_encrypt;
958 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
959 sdata->vif.bss_conf.dtim_period = params->dtim_period;
960 sdata->vif.bss_conf.enable_beacon = true;
962 sdata->vif.bss_conf.ssid_len = params->ssid_len;
963 if (params->ssid_len)
964 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
966 sdata->vif.bss_conf.hidden_ssid =
967 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
969 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
970 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
971 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
972 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
973 if (params->p2p_opp_ps)
974 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
975 IEEE80211_P2P_OPPPS_ENABLE_BIT;
977 err = ieee80211_assign_beacon(sdata, ¶ms->beacon);
979 ieee80211_vif_release_channel(sdata);
984 err = drv_start_ap(sdata->local, sdata);
986 old = rtnl_dereference(sdata->u.ap.beacon);
988 kfree_rcu(old, rcu_head);
989 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
990 ieee80211_vif_release_channel(sdata);
994 ieee80211_bss_info_change_notify(sdata, changed);
996 netif_carrier_on(dev);
997 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
998 netif_carrier_on(vlan->dev);
1003 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1004 struct cfg80211_beacon_data *params)
1006 struct ieee80211_sub_if_data *sdata;
1007 struct beacon_data *old;
1010 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1012 old = rtnl_dereference(sdata->u.ap.beacon);
1016 err = ieee80211_assign_beacon(sdata, params);
1019 ieee80211_bss_info_change_notify(sdata, err);
1023 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1025 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1026 struct ieee80211_sub_if_data *vlan;
1027 struct ieee80211_local *local = sdata->local;
1028 struct beacon_data *old_beacon;
1029 struct probe_resp *old_probe_resp;
1031 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1034 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
1036 /* turn off carrier for this interface and dependent VLANs */
1037 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1038 netif_carrier_off(vlan->dev);
1039 netif_carrier_off(dev);
1041 /* remove beacon and probe response */
1042 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1043 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1044 kfree_rcu(old_beacon, rcu_head);
1046 kfree_rcu(old_probe_resp, rcu_head);
1048 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1049 sta_info_flush_defer(vlan);
1050 sta_info_flush_defer(sdata);
1053 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1054 sta_info_flush_cleanup(vlan);
1055 ieee80211_free_keys(vlan);
1057 sta_info_flush_cleanup(sdata);
1058 ieee80211_free_keys(sdata);
1060 sdata->vif.bss_conf.enable_beacon = false;
1061 sdata->vif.bss_conf.ssid_len = 0;
1062 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1063 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1065 if (sdata->wdev.cac_started) {
1066 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1067 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
1071 drv_stop_ap(sdata->local, sdata);
1073 /* free all potentially still buffered bcast frames */
1074 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1075 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1077 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
1078 ieee80211_vif_release_channel(sdata);
1083 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1084 struct iapp_layer2_update {
1085 u8 da[ETH_ALEN]; /* broadcast */
1086 u8 sa[ETH_ALEN]; /* STA addr */
1094 static void ieee80211_send_layer2_update(struct sta_info *sta)
1096 struct iapp_layer2_update *msg;
1097 struct sk_buff *skb;
1099 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1102 skb = dev_alloc_skb(sizeof(*msg));
1105 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1107 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1108 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1110 eth_broadcast_addr(msg->da);
1111 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
1112 msg->len = htons(6);
1114 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1115 msg->control = 0xaf; /* XID response lsb.1111F101.
1116 * F=0 (no poll command; unsolicited frame) */
1117 msg->xid_info[0] = 0x81; /* XID format identifier */
1118 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1119 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1121 skb->dev = sta->sdata->dev;
1122 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
1123 memset(skb->cb, 0, sizeof(skb->cb));
1127 static int sta_apply_auth_flags(struct ieee80211_local *local,
1128 struct sta_info *sta,
1133 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1134 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1135 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1136 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1141 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1142 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1143 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1144 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1149 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1150 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1151 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1152 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1153 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1160 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1161 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1162 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1163 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1168 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1169 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1170 test_sta_flag(sta, WLAN_STA_AUTH)) {
1171 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1179 static int sta_apply_parameters(struct ieee80211_local *local,
1180 struct sta_info *sta,
1181 struct station_parameters *params)
1186 struct ieee80211_supported_band *sband;
1187 struct ieee80211_sub_if_data *sdata = sta->sdata;
1188 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
1191 sband = local->hw.wiphy->bands[band];
1193 mask = params->sta_flags_mask;
1194 set = params->sta_flags_set;
1196 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1198 * In mesh mode, ASSOCIATED isn't part of the nl80211
1199 * API but must follow AUTHENTICATED for driver state.
1201 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1202 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1203 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1204 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1205 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1207 * TDLS -- everything follows authorized, but
1208 * only becoming authorized is possible, not
1211 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1212 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1213 BIT(NL80211_STA_FLAG_ASSOCIATED);
1214 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1215 BIT(NL80211_STA_FLAG_ASSOCIATED);
1219 ret = sta_apply_auth_flags(local, sta, mask, set);
1223 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1224 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1225 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1227 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1230 if (mask & BIT(NL80211_STA_FLAG_WME)) {
1231 if (set & BIT(NL80211_STA_FLAG_WME)) {
1232 set_sta_flag(sta, WLAN_STA_WME);
1233 sta->sta.wme = true;
1235 clear_sta_flag(sta, WLAN_STA_WME);
1236 sta->sta.wme = false;
1240 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1241 if (set & BIT(NL80211_STA_FLAG_MFP))
1242 set_sta_flag(sta, WLAN_STA_MFP);
1244 clear_sta_flag(sta, WLAN_STA_MFP);
1247 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1248 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1249 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1251 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1254 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1255 sta->sta.uapsd_queues = params->uapsd_queues;
1256 sta->sta.max_sp = params->max_sp;
1260 * cfg80211 validates this (1-2007) and allows setting the AID
1261 * only when creating a new station entry
1264 sta->sta.aid = params->aid;
1267 * Some of the following updates would be racy if called on an
1268 * existing station, via ieee80211_change_station(). However,
1269 * all such changes are rejected by cfg80211 except for updates
1270 * changing the supported rates on an existing but not yet used
1274 if (params->listen_interval >= 0)
1275 sta->listen_interval = params->listen_interval;
1277 if (params->supported_rates) {
1280 for (i = 0; i < params->supported_rates_len; i++) {
1281 int rate = (params->supported_rates[i] & 0x7f) * 5;
1282 for (j = 0; j < sband->n_bitrates; j++) {
1283 if (sband->bitrates[j].bitrate == rate)
1287 sta->sta.supp_rates[band] = rates;
1290 if (params->ht_capa)
1291 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1292 params->ht_capa, sta);
1294 if (params->vht_capa)
1295 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1296 params->vht_capa, sta);
1298 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1299 #ifdef CONFIG_MAC80211_MESH
1302 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1303 switch (params->plink_state) {
1304 case NL80211_PLINK_ESTAB:
1305 if (sta->plink_state != NL80211_PLINK_ESTAB)
1306 changed = mesh_plink_inc_estab_count(
1308 sta->plink_state = params->plink_state;
1310 ieee80211_mps_sta_status_update(sta);
1311 changed |= ieee80211_mps_set_sta_local_pm(sta,
1312 sdata->u.mesh.mshcfg.power_mode);
1314 case NL80211_PLINK_LISTEN:
1315 case NL80211_PLINK_BLOCKED:
1316 case NL80211_PLINK_OPN_SNT:
1317 case NL80211_PLINK_OPN_RCVD:
1318 case NL80211_PLINK_CNF_RCVD:
1319 case NL80211_PLINK_HOLDING:
1320 if (sta->plink_state == NL80211_PLINK_ESTAB)
1321 changed = mesh_plink_dec_estab_count(
1323 sta->plink_state = params->plink_state;
1325 ieee80211_mps_sta_status_update(sta);
1327 ieee80211_mps_local_status_update(sdata);
1335 switch (params->plink_action) {
1336 case NL80211_PLINK_ACTION_NO_ACTION:
1339 case NL80211_PLINK_ACTION_OPEN:
1340 changed |= mesh_plink_open(sta);
1342 case NL80211_PLINK_ACTION_BLOCK:
1343 changed |= mesh_plink_block(sta);
1347 if (params->local_pm)
1349 ieee80211_mps_set_sta_local_pm(sta,
1351 ieee80211_bss_info_change_notify(sdata, changed);
1358 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1359 u8 *mac, struct station_parameters *params)
1361 struct ieee80211_local *local = wiphy_priv(wiphy);
1362 struct sta_info *sta;
1363 struct ieee80211_sub_if_data *sdata;
1368 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1370 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1371 sdata->vif.type != NL80211_IFTYPE_AP)
1374 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1376 if (ether_addr_equal(mac, sdata->vif.addr))
1379 if (is_multicast_ether_addr(mac))
1382 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1387 * defaults -- if userspace wants something else we'll
1388 * change it accordingly in sta_apply_parameters()
1390 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1391 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1392 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1395 err = sta_apply_parameters(local, sta, params);
1397 sta_info_free(local, sta);
1402 * for TDLS, rate control should be initialized only when
1403 * rates are known and station is marked authorized
1405 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1406 rate_control_rate_init(sta);
1408 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1409 sdata->vif.type == NL80211_IFTYPE_AP;
1411 err = sta_info_insert_rcu(sta);
1418 ieee80211_send_layer2_update(sta);
1425 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1428 struct ieee80211_sub_if_data *sdata;
1430 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1433 return sta_info_destroy_addr_bss(sdata, mac);
1435 sta_info_flush(sdata);
1439 static int ieee80211_change_station(struct wiphy *wiphy,
1440 struct net_device *dev, u8 *mac,
1441 struct station_parameters *params)
1443 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1444 struct ieee80211_local *local = wiphy_priv(wiphy);
1445 struct sta_info *sta;
1446 struct ieee80211_sub_if_data *vlansdata;
1447 enum cfg80211_station_type statype;
1450 mutex_lock(&local->sta_mtx);
1452 sta = sta_info_get_bss(sdata, mac);
1458 switch (sdata->vif.type) {
1459 case NL80211_IFTYPE_MESH_POINT:
1460 if (sdata->u.mesh.user_mpm)
1461 statype = CFG80211_STA_MESH_PEER_USER;
1463 statype = CFG80211_STA_MESH_PEER_KERNEL;
1465 case NL80211_IFTYPE_ADHOC:
1466 statype = CFG80211_STA_IBSS;
1468 case NL80211_IFTYPE_STATION:
1469 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1470 statype = CFG80211_STA_AP_STA;
1473 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1474 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1476 statype = CFG80211_STA_TDLS_PEER_SETUP;
1478 case NL80211_IFTYPE_AP:
1479 case NL80211_IFTYPE_AP_VLAN:
1480 statype = CFG80211_STA_AP_CLIENT;
1487 err = cfg80211_check_station_change(wiphy, params, statype);
1491 if (params->vlan && params->vlan != sta->sdata->dev) {
1492 bool prev_4addr = false;
1493 bool new_4addr = false;
1495 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1497 if (params->vlan->ieee80211_ptr->use_4addr) {
1498 if (vlansdata->u.vlan.sta) {
1503 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1507 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1508 sta->sdata->u.vlan.sta) {
1509 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1513 sta->sdata = vlansdata;
1515 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1516 prev_4addr != new_4addr) {
1518 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1520 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1523 ieee80211_send_layer2_update(sta);
1526 err = sta_apply_parameters(local, sta, params);
1530 /* When peer becomes authorized, init rate control as well */
1531 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1532 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1533 rate_control_rate_init(sta);
1535 mutex_unlock(&local->sta_mtx);
1537 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1538 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1539 ieee80211_recalc_ps(local, -1);
1540 ieee80211_recalc_ps_vif(sdata);
1545 mutex_unlock(&local->sta_mtx);
1549 #ifdef CONFIG_MAC80211_MESH
1550 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1551 u8 *dst, u8 *next_hop)
1553 struct ieee80211_sub_if_data *sdata;
1554 struct mesh_path *mpath;
1555 struct sta_info *sta;
1557 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1560 sta = sta_info_get(sdata, next_hop);
1566 mpath = mesh_path_add(sdata, dst);
1567 if (IS_ERR(mpath)) {
1569 return PTR_ERR(mpath);
1572 mesh_path_fix_nexthop(mpath, sta);
1578 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1581 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1584 return mesh_path_del(sdata, dst);
1586 mesh_path_flush_by_iface(sdata);
1590 static int ieee80211_change_mpath(struct wiphy *wiphy,
1591 struct net_device *dev,
1592 u8 *dst, u8 *next_hop)
1594 struct ieee80211_sub_if_data *sdata;
1595 struct mesh_path *mpath;
1596 struct sta_info *sta;
1598 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1602 sta = sta_info_get(sdata, next_hop);
1608 mpath = mesh_path_lookup(sdata, dst);
1614 mesh_path_fix_nexthop(mpath, sta);
1620 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1621 struct mpath_info *pinfo)
1623 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1626 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1628 memset(next_hop, 0, ETH_ALEN);
1630 memset(pinfo, 0, sizeof(*pinfo));
1632 pinfo->generation = mesh_paths_generation;
1634 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1637 MPATH_INFO_EXPTIME |
1638 MPATH_INFO_DISCOVERY_TIMEOUT |
1639 MPATH_INFO_DISCOVERY_RETRIES |
1642 pinfo->frame_qlen = mpath->frame_queue.qlen;
1643 pinfo->sn = mpath->sn;
1644 pinfo->metric = mpath->metric;
1645 if (time_before(jiffies, mpath->exp_time))
1646 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1647 pinfo->discovery_timeout =
1648 jiffies_to_msecs(mpath->discovery_timeout);
1649 pinfo->discovery_retries = mpath->discovery_retries;
1650 if (mpath->flags & MESH_PATH_ACTIVE)
1651 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1652 if (mpath->flags & MESH_PATH_RESOLVING)
1653 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1654 if (mpath->flags & MESH_PATH_SN_VALID)
1655 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1656 if (mpath->flags & MESH_PATH_FIXED)
1657 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1658 if (mpath->flags & MESH_PATH_RESOLVED)
1659 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1662 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1663 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1666 struct ieee80211_sub_if_data *sdata;
1667 struct mesh_path *mpath;
1669 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1672 mpath = mesh_path_lookup(sdata, dst);
1677 memcpy(dst, mpath->dst, ETH_ALEN);
1678 mpath_set_pinfo(mpath, next_hop, pinfo);
1683 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1684 int idx, u8 *dst, u8 *next_hop,
1685 struct mpath_info *pinfo)
1687 struct ieee80211_sub_if_data *sdata;
1688 struct mesh_path *mpath;
1690 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1693 mpath = mesh_path_lookup_by_idx(sdata, idx);
1698 memcpy(dst, mpath->dst, ETH_ALEN);
1699 mpath_set_pinfo(mpath, next_hop, pinfo);
1704 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1705 struct net_device *dev,
1706 struct mesh_config *conf)
1708 struct ieee80211_sub_if_data *sdata;
1709 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1711 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1715 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1717 return (mask >> (parm-1)) & 0x1;
1720 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1721 const struct mesh_setup *setup)
1725 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1726 struct ieee80211_sub_if_data, u.mesh);
1728 /* allocate information elements */
1732 if (setup->ie_len) {
1733 new_ie = kmemdup(setup->ie, setup->ie_len,
1738 ifmsh->ie_len = setup->ie_len;
1742 /* now copy the rest of the setup parameters */
1743 ifmsh->mesh_id_len = setup->mesh_id_len;
1744 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1745 ifmsh->mesh_sp_id = setup->sync_method;
1746 ifmsh->mesh_pp_id = setup->path_sel_proto;
1747 ifmsh->mesh_pm_id = setup->path_metric;
1748 ifmsh->user_mpm = setup->user_mpm;
1749 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1750 if (setup->is_authenticated)
1751 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1752 if (setup->is_secure)
1753 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1755 /* mcast rate setting in Mesh Node */
1756 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1757 sizeof(setup->mcast_rate));
1759 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1760 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1765 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1766 struct net_device *dev, u32 mask,
1767 const struct mesh_config *nconf)
1769 struct mesh_config *conf;
1770 struct ieee80211_sub_if_data *sdata;
1771 struct ieee80211_if_mesh *ifmsh;
1773 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1774 ifmsh = &sdata->u.mesh;
1776 /* Set the config options which we are interested in setting */
1777 conf = &(sdata->u.mesh.mshcfg);
1778 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1779 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1780 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1781 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1782 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1783 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1784 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1785 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1786 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1787 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1788 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1789 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1790 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1791 conf->element_ttl = nconf->element_ttl;
1792 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1793 if (ifmsh->user_mpm)
1795 conf->auto_open_plinks = nconf->auto_open_plinks;
1797 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1798 conf->dot11MeshNbrOffsetMaxNeighbor =
1799 nconf->dot11MeshNbrOffsetMaxNeighbor;
1800 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1801 conf->dot11MeshHWMPmaxPREQretries =
1802 nconf->dot11MeshHWMPmaxPREQretries;
1803 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1804 conf->path_refresh_time = nconf->path_refresh_time;
1805 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1806 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1807 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1808 conf->dot11MeshHWMPactivePathTimeout =
1809 nconf->dot11MeshHWMPactivePathTimeout;
1810 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1811 conf->dot11MeshHWMPpreqMinInterval =
1812 nconf->dot11MeshHWMPpreqMinInterval;
1813 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1814 conf->dot11MeshHWMPperrMinInterval =
1815 nconf->dot11MeshHWMPperrMinInterval;
1816 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1818 conf->dot11MeshHWMPnetDiameterTraversalTime =
1819 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1820 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1821 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1822 ieee80211_mesh_root_setup(ifmsh);
1824 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1825 /* our current gate announcement implementation rides on root
1826 * announcements, so require this ifmsh to also be a root node
1828 if (nconf->dot11MeshGateAnnouncementProtocol &&
1829 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1830 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
1831 ieee80211_mesh_root_setup(ifmsh);
1833 conf->dot11MeshGateAnnouncementProtocol =
1834 nconf->dot11MeshGateAnnouncementProtocol;
1836 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
1837 conf->dot11MeshHWMPRannInterval =
1838 nconf->dot11MeshHWMPRannInterval;
1839 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1840 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1841 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1842 /* our RSSI threshold implementation is supported only for
1843 * devices that report signal in dBm.
1845 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1847 conf->rssi_threshold = nconf->rssi_threshold;
1849 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1850 conf->ht_opmode = nconf->ht_opmode;
1851 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1852 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1854 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1855 conf->dot11MeshHWMPactivePathToRootTimeout =
1856 nconf->dot11MeshHWMPactivePathToRootTimeout;
1857 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1858 conf->dot11MeshHWMProotInterval =
1859 nconf->dot11MeshHWMProotInterval;
1860 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1861 conf->dot11MeshHWMPconfirmationInterval =
1862 nconf->dot11MeshHWMPconfirmationInterval;
1863 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1864 conf->power_mode = nconf->power_mode;
1865 ieee80211_mps_local_status_update(sdata);
1867 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
1868 conf->dot11MeshAwakeWindowDuration =
1869 nconf->dot11MeshAwakeWindowDuration;
1870 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
1874 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1875 const struct mesh_config *conf,
1876 const struct mesh_setup *setup)
1878 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1879 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1882 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1883 err = copy_mesh_setup(ifmsh, setup);
1887 /* can mesh use other SMPS modes? */
1888 sdata->smps_mode = IEEE80211_SMPS_OFF;
1889 sdata->needed_rx_chains = sdata->local->rx_chains;
1891 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
1892 IEEE80211_CHANCTX_SHARED);
1896 return ieee80211_start_mesh(sdata);
1899 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1901 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1903 ieee80211_stop_mesh(sdata);
1904 ieee80211_vif_release_channel(sdata);
1910 static int ieee80211_change_bss(struct wiphy *wiphy,
1911 struct net_device *dev,
1912 struct bss_parameters *params)
1914 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1915 enum ieee80211_band band;
1918 if (!rtnl_dereference(sdata->u.ap.beacon))
1921 band = ieee80211_get_sdata_band(sdata);
1923 if (params->use_cts_prot >= 0) {
1924 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1925 changed |= BSS_CHANGED_ERP_CTS_PROT;
1927 if (params->use_short_preamble >= 0) {
1928 sdata->vif.bss_conf.use_short_preamble =
1929 params->use_short_preamble;
1930 changed |= BSS_CHANGED_ERP_PREAMBLE;
1933 if (!sdata->vif.bss_conf.use_short_slot &&
1934 band == IEEE80211_BAND_5GHZ) {
1935 sdata->vif.bss_conf.use_short_slot = true;
1936 changed |= BSS_CHANGED_ERP_SLOT;
1939 if (params->use_short_slot_time >= 0) {
1940 sdata->vif.bss_conf.use_short_slot =
1941 params->use_short_slot_time;
1942 changed |= BSS_CHANGED_ERP_SLOT;
1945 if (params->basic_rates) {
1948 struct ieee80211_supported_band *sband = wiphy->bands[band];
1950 for (i = 0; i < params->basic_rates_len; i++) {
1951 int rate = (params->basic_rates[i] & 0x7f) * 5;
1952 for (j = 0; j < sband->n_bitrates; j++) {
1953 if (sband->bitrates[j].bitrate == rate)
1957 sdata->vif.bss_conf.basic_rates = rates;
1958 changed |= BSS_CHANGED_BASIC_RATES;
1961 if (params->ap_isolate >= 0) {
1962 if (params->ap_isolate)
1963 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1965 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1968 if (params->ht_opmode >= 0) {
1969 sdata->vif.bss_conf.ht_operation_mode =
1970 (u16) params->ht_opmode;
1971 changed |= BSS_CHANGED_HT;
1974 if (params->p2p_ctwindow >= 0) {
1975 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1976 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1977 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1978 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1979 changed |= BSS_CHANGED_P2P_PS;
1982 if (params->p2p_opp_ps > 0) {
1983 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1984 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1985 changed |= BSS_CHANGED_P2P_PS;
1986 } else if (params->p2p_opp_ps == 0) {
1987 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1988 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
1989 changed |= BSS_CHANGED_P2P_PS;
1992 ieee80211_bss_info_change_notify(sdata, changed);
1997 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1998 struct net_device *dev,
1999 struct ieee80211_txq_params *params)
2001 struct ieee80211_local *local = wiphy_priv(wiphy);
2002 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2003 struct ieee80211_tx_queue_params p;
2005 if (!local->ops->conf_tx)
2008 if (local->hw.queues < IEEE80211_NUM_ACS)
2011 memset(&p, 0, sizeof(p));
2012 p.aifs = params->aifs;
2013 p.cw_max = params->cwmax;
2014 p.cw_min = params->cwmin;
2015 p.txop = params->txop;
2018 * Setting tx queue params disables u-apsd because it's only
2019 * called in master mode.
2023 sdata->tx_conf[params->ac] = p;
2024 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2025 wiphy_debug(local->hw.wiphy,
2026 "failed to set TX queue parameters for AC %d\n",
2031 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2037 static int ieee80211_suspend(struct wiphy *wiphy,
2038 struct cfg80211_wowlan *wowlan)
2040 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2043 static int ieee80211_resume(struct wiphy *wiphy)
2045 return __ieee80211_resume(wiphy_priv(wiphy));
2048 #define ieee80211_suspend NULL
2049 #define ieee80211_resume NULL
2052 static int ieee80211_scan(struct wiphy *wiphy,
2053 struct cfg80211_scan_request *req)
2055 struct ieee80211_sub_if_data *sdata;
2057 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2059 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2060 case NL80211_IFTYPE_STATION:
2061 case NL80211_IFTYPE_ADHOC:
2062 case NL80211_IFTYPE_MESH_POINT:
2063 case NL80211_IFTYPE_P2P_CLIENT:
2064 case NL80211_IFTYPE_P2P_DEVICE:
2066 case NL80211_IFTYPE_P2P_GO:
2067 if (sdata->local->ops->hw_scan)
2070 * FIXME: implement NoA while scanning in software,
2071 * for now fall through to allow scanning only when
2072 * beaconing hasn't been configured yet
2074 case NL80211_IFTYPE_AP:
2076 * If the scan has been forced (and the driver supports
2077 * forcing), don't care about being beaconing already.
2078 * This will create problems to the attached stations (e.g. all
2079 * the frames sent while scanning on other channel will be
2082 if (sdata->u.ap.beacon &&
2083 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2084 !(req->flags & NL80211_SCAN_FLAG_AP)))
2091 return ieee80211_request_scan(sdata, req);
2095 ieee80211_sched_scan_start(struct wiphy *wiphy,
2096 struct net_device *dev,
2097 struct cfg80211_sched_scan_request *req)
2099 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2101 if (!sdata->local->ops->sched_scan_start)
2104 return ieee80211_request_sched_scan_start(sdata, req);
2108 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
2110 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2112 if (!sdata->local->ops->sched_scan_stop)
2115 return ieee80211_request_sched_scan_stop(sdata);
2118 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2119 struct cfg80211_auth_request *req)
2121 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2124 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2125 struct cfg80211_assoc_request *req)
2127 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2130 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2131 struct cfg80211_deauth_request *req)
2133 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2136 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2137 struct cfg80211_disassoc_request *req)
2139 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2142 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2143 struct cfg80211_ibss_params *params)
2145 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2148 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2150 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2153 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2154 int rate[IEEE80211_NUM_BANDS])
2156 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2158 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2159 sizeof(int) * IEEE80211_NUM_BANDS);
2164 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2166 struct ieee80211_local *local = wiphy_priv(wiphy);
2169 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2170 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2176 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2177 err = drv_set_coverage_class(local, wiphy->coverage_class);
2183 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2184 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2190 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2191 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2193 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2195 if (changed & WIPHY_PARAM_RETRY_LONG) {
2196 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2198 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2201 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2202 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2207 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2208 struct wireless_dev *wdev,
2209 enum nl80211_tx_power_setting type, int mbm)
2211 struct ieee80211_local *local = wiphy_priv(wiphy);
2212 struct ieee80211_sub_if_data *sdata;
2215 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2218 case NL80211_TX_POWER_AUTOMATIC:
2219 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2221 case NL80211_TX_POWER_LIMITED:
2222 case NL80211_TX_POWER_FIXED:
2223 if (mbm < 0 || (mbm % 100))
2225 sdata->user_power_level = MBM_TO_DBM(mbm);
2229 ieee80211_recalc_txpower(sdata);
2235 case NL80211_TX_POWER_AUTOMATIC:
2236 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2238 case NL80211_TX_POWER_LIMITED:
2239 case NL80211_TX_POWER_FIXED:
2240 if (mbm < 0 || (mbm % 100))
2242 local->user_power_level = MBM_TO_DBM(mbm);
2246 mutex_lock(&local->iflist_mtx);
2247 list_for_each_entry(sdata, &local->interfaces, list)
2248 sdata->user_power_level = local->user_power_level;
2249 list_for_each_entry(sdata, &local->interfaces, list)
2250 ieee80211_recalc_txpower(sdata);
2251 mutex_unlock(&local->iflist_mtx);
2256 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2257 struct wireless_dev *wdev,
2260 struct ieee80211_local *local = wiphy_priv(wiphy);
2261 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2263 if (!local->use_chanctx)
2264 *dbm = local->hw.conf.power_level;
2266 *dbm = sdata->vif.bss_conf.txpower;
2271 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2274 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2276 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2281 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2283 struct ieee80211_local *local = wiphy_priv(wiphy);
2285 drv_rfkill_poll(local);
2288 #ifdef CONFIG_NL80211_TESTMODE
2289 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
2291 struct ieee80211_local *local = wiphy_priv(wiphy);
2293 if (!local->ops->testmode_cmd)
2296 return local->ops->testmode_cmd(&local->hw, data, len);
2299 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2300 struct sk_buff *skb,
2301 struct netlink_callback *cb,
2302 void *data, int len)
2304 struct ieee80211_local *local = wiphy_priv(wiphy);
2306 if (!local->ops->testmode_dump)
2309 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2313 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2314 enum ieee80211_smps_mode smps_mode)
2317 enum ieee80211_smps_mode old_req;
2320 lockdep_assert_held(&sdata->u.mgd.mtx);
2322 old_req = sdata->u.mgd.req_smps;
2323 sdata->u.mgd.req_smps = smps_mode;
2325 if (old_req == smps_mode &&
2326 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2330 * If not associated, or current association is not an HT
2331 * association, there's no need to do anything, just store
2332 * the new value until we associate.
2334 if (!sdata->u.mgd.associated ||
2335 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2338 ap = sdata->u.mgd.associated->bssid;
2340 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2341 if (sdata->u.mgd.powersave)
2342 smps_mode = IEEE80211_SMPS_DYNAMIC;
2344 smps_mode = IEEE80211_SMPS_OFF;
2347 /* send SM PS frame to AP */
2348 err = ieee80211_send_smps_action(sdata, smps_mode,
2351 sdata->u.mgd.req_smps = old_req;
2356 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2357 bool enabled, int timeout)
2359 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2360 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2362 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2365 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2368 if (enabled == sdata->u.mgd.powersave &&
2369 timeout == local->dynamic_ps_forced_timeout)
2372 sdata->u.mgd.powersave = enabled;
2373 local->dynamic_ps_forced_timeout = timeout;
2375 /* no change, but if automatic follow powersave */
2376 mutex_lock(&sdata->u.mgd.mtx);
2377 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2378 mutex_unlock(&sdata->u.mgd.mtx);
2380 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2381 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2383 ieee80211_recalc_ps(local, -1);
2384 ieee80211_recalc_ps_vif(sdata);
2389 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2390 struct net_device *dev,
2391 s32 rssi_thold, u32 rssi_hyst)
2393 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2394 struct ieee80211_vif *vif = &sdata->vif;
2395 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2397 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2398 rssi_hyst == bss_conf->cqm_rssi_hyst)
2401 bss_conf->cqm_rssi_thold = rssi_thold;
2402 bss_conf->cqm_rssi_hyst = rssi_hyst;
2404 /* tell the driver upon association, unless already associated */
2405 if (sdata->u.mgd.associated &&
2406 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2407 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2412 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2413 struct net_device *dev,
2415 const struct cfg80211_bitrate_mask *mask)
2417 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2418 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2421 if (!ieee80211_sdata_running(sdata))
2424 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2425 ret = drv_set_bitrate_mask(local, sdata, mask);
2430 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
2431 struct ieee80211_supported_band *sband = wiphy->bands[i];
2434 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2435 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2436 sizeof(mask->control[i].mcs));
2438 sdata->rc_has_mcs_mask[i] = false;
2442 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2443 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2444 sdata->rc_has_mcs_mask[i] = true;
2452 static int ieee80211_start_roc_work(struct ieee80211_local *local,
2453 struct ieee80211_sub_if_data *sdata,
2454 struct ieee80211_channel *channel,
2455 unsigned int duration, u64 *cookie,
2456 struct sk_buff *txskb,
2457 enum ieee80211_roc_type type)
2459 struct ieee80211_roc_work *roc, *tmp;
2460 bool queued = false;
2463 lockdep_assert_held(&local->mtx);
2465 if (local->use_chanctx && !local->ops->remain_on_channel)
2468 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2472 roc->chan = channel;
2473 roc->duration = duration;
2474 roc->req_duration = duration;
2477 roc->mgmt_tx_cookie = (unsigned long)txskb;
2479 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2480 INIT_LIST_HEAD(&roc->dependents);
2483 * cookie is either the roc cookie (for normal roc)
2484 * or the SKB (for mgmt TX)
2487 /* local->mtx protects this */
2488 local->roc_cookie_counter++;
2489 roc->cookie = local->roc_cookie_counter;
2490 /* wow, you wrapped 64 bits ... more likely a bug */
2491 if (WARN_ON(roc->cookie == 0)) {
2493 local->roc_cookie_counter++;
2495 *cookie = roc->cookie;
2497 *cookie = (unsigned long)txskb;
2500 /* if there's one pending or we're scanning, queue this one */
2501 if (!list_empty(&local->roc_list) ||
2502 local->scanning || local->radar_detect_enabled)
2503 goto out_check_combine;
2505 /* if not HW assist, just queue & schedule work */
2506 if (!local->ops->remain_on_channel) {
2507 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2511 /* otherwise actually kick it off here (for error handling) */
2514 * If the duration is zero, then the driver
2515 * wouldn't actually do anything. Set it to
2518 * TODO: cancel the off-channel operation
2519 * when we get the SKB's TX status and
2520 * the wait time was zero before.
2525 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
2531 roc->started = true;
2535 list_for_each_entry(tmp, &local->roc_list, list) {
2536 if (tmp->chan != channel || tmp->sdata != sdata)
2540 * Extend this ROC if possible:
2542 * If it hasn't started yet, just increase the duration
2543 * and add the new one to the list of dependents.
2544 * If the type of the new ROC has higher priority, modify the
2545 * type of the previous one to match that of the new one.
2547 if (!tmp->started) {
2548 list_add_tail(&roc->list, &tmp->dependents);
2549 tmp->duration = max(tmp->duration, roc->duration);
2550 tmp->type = max(tmp->type, roc->type);
2555 /* If it has already started, it's more difficult ... */
2556 if (local->ops->remain_on_channel) {
2557 unsigned long j = jiffies;
2560 * In the offloaded ROC case, if it hasn't begun, add
2561 * this new one to the dependent list to be handled
2562 * when the master one begins. If it has begun,
2563 * check that there's still a minimum time left and
2564 * if so, start this one, transmitting the frame, but
2565 * add it to the list directly after this one with
2566 * a reduced time so we'll ask the driver to execute
2567 * it right after finishing the previous one, in the
2568 * hope that it'll also be executed right afterwards,
2569 * effectively extending the old one.
2570 * If there's no minimum time left, just add it to the
2572 * TODO: the ROC type is ignored here, assuming that it
2573 * is better to immediately use the current ROC.
2575 if (!tmp->hw_begun) {
2576 list_add_tail(&roc->list, &tmp->dependents);
2581 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2582 tmp->hw_start_time +
2583 msecs_to_jiffies(tmp->duration))) {
2586 ieee80211_handle_roc_started(roc);
2588 new_dur = roc->duration -
2589 jiffies_to_msecs(tmp->hw_start_time +
2595 /* add right after tmp */
2596 list_add(&roc->list, &tmp->list);
2598 list_add_tail(&roc->list,
2603 } else if (del_timer_sync(&tmp->work.timer)) {
2604 unsigned long new_end;
2607 * In the software ROC case, cancel the timer, if
2608 * that fails then the finish work is already
2609 * queued/pending and thus we queue the new ROC
2610 * normally, if that succeeds then we can extend
2611 * the timer duration and TX the frame (if any.)
2614 list_add_tail(&roc->list, &tmp->dependents);
2617 new_end = jiffies + msecs_to_jiffies(roc->duration);
2619 /* ok, it was started & we canceled timer */
2620 if (time_after(new_end, tmp->work.timer.expires))
2621 mod_timer(&tmp->work.timer, new_end);
2623 add_timer(&tmp->work.timer);
2625 ieee80211_handle_roc_started(roc);
2632 list_add_tail(&roc->list, &local->roc_list);
2637 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
2638 struct wireless_dev *wdev,
2639 struct ieee80211_channel *chan,
2640 unsigned int duration,
2643 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2644 struct ieee80211_local *local = sdata->local;
2647 mutex_lock(&local->mtx);
2648 ret = ieee80211_start_roc_work(local, sdata, chan,
2649 duration, cookie, NULL,
2650 IEEE80211_ROC_TYPE_NORMAL);
2651 mutex_unlock(&local->mtx);
2656 static int ieee80211_cancel_roc(struct ieee80211_local *local,
2657 u64 cookie, bool mgmt_tx)
2659 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2662 mutex_lock(&local->mtx);
2663 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
2664 struct ieee80211_roc_work *dep, *tmp2;
2666 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2667 if (!mgmt_tx && dep->cookie != cookie)
2669 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2671 /* found dependent item -- just remove it */
2672 list_del(&dep->list);
2673 mutex_unlock(&local->mtx);
2675 ieee80211_roc_notify_destroy(dep, true);
2679 if (!mgmt_tx && roc->cookie != cookie)
2681 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2689 mutex_unlock(&local->mtx);
2694 * We found the item to cancel, so do that. Note that it
2695 * may have dependents, which we also cancel (and send
2696 * the expired signal for.) Not doing so would be quite
2697 * tricky here, but we may need to fix it later.
2700 if (local->ops->remain_on_channel) {
2701 if (found->started) {
2702 ret = drv_cancel_remain_on_channel(local);
2703 if (WARN_ON_ONCE(ret)) {
2704 mutex_unlock(&local->mtx);
2709 list_del(&found->list);
2712 ieee80211_start_next_roc(local);
2713 mutex_unlock(&local->mtx);
2715 ieee80211_roc_notify_destroy(found, true);
2717 /* work may be pending so use it all the time */
2718 found->abort = true;
2719 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2721 mutex_unlock(&local->mtx);
2723 /* work will clean up etc */
2724 flush_delayed_work(&found->work);
2725 WARN_ON(!found->to_be_freed);
2732 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
2733 struct wireless_dev *wdev,
2736 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2737 struct ieee80211_local *local = sdata->local;
2739 return ieee80211_cancel_roc(local, cookie, false);
2742 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2743 struct net_device *dev,
2744 struct cfg80211_chan_def *chandef)
2746 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2747 struct ieee80211_local *local = sdata->local;
2748 unsigned long timeout;
2751 if (!list_empty(&local->roc_list) || local->scanning)
2754 /* whatever, but channel contexts should not complain about that one */
2755 sdata->smps_mode = IEEE80211_SMPS_OFF;
2756 sdata->needed_rx_chains = local->rx_chains;
2757 sdata->radar_required = true;
2759 mutex_lock(&local->iflist_mtx);
2760 err = ieee80211_vif_use_channel(sdata, chandef,
2761 IEEE80211_CHANCTX_SHARED);
2762 mutex_unlock(&local->iflist_mtx);
2766 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2767 ieee80211_queue_delayed_work(&sdata->local->hw,
2768 &sdata->dfs_cac_timer_work, timeout);
2773 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
2774 struct ieee80211_channel *chan, bool offchan,
2775 unsigned int wait, const u8 *buf, size_t len,
2776 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
2778 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2779 struct ieee80211_local *local = sdata->local;
2780 struct sk_buff *skb;
2781 struct sta_info *sta;
2782 const struct ieee80211_mgmt *mgmt = (void *)buf;
2783 bool need_offchan = false;
2787 if (dont_wait_for_ack)
2788 flags = IEEE80211_TX_CTL_NO_ACK;
2790 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2791 IEEE80211_TX_CTL_REQ_TX_STATUS;
2794 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2796 switch (sdata->vif.type) {
2797 case NL80211_IFTYPE_ADHOC:
2798 if (!sdata->vif.bss_conf.ibss_joined)
2799 need_offchan = true;
2801 #ifdef CONFIG_MAC80211_MESH
2802 case NL80211_IFTYPE_MESH_POINT:
2803 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2804 !sdata->u.mesh.mesh_id_len)
2805 need_offchan = true;
2808 case NL80211_IFTYPE_AP:
2809 case NL80211_IFTYPE_AP_VLAN:
2810 case NL80211_IFTYPE_P2P_GO:
2811 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2812 !ieee80211_vif_is_mesh(&sdata->vif) &&
2813 !rcu_access_pointer(sdata->bss->beacon))
2814 need_offchan = true;
2815 if (!ieee80211_is_action(mgmt->frame_control) ||
2816 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2819 sta = sta_info_get(sdata, mgmt->da);
2824 case NL80211_IFTYPE_STATION:
2825 case NL80211_IFTYPE_P2P_CLIENT:
2826 if (!sdata->u.mgd.associated)
2827 need_offchan = true;
2829 case NL80211_IFTYPE_P2P_DEVICE:
2830 need_offchan = true;
2836 mutex_lock(&local->mtx);
2838 /* Check if the operating channel is the requested channel */
2839 if (!need_offchan) {
2840 struct ieee80211_chanctx_conf *chanctx_conf;
2843 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2846 need_offchan = chan != chanctx_conf->def.chan;
2848 need_offchan = true;
2852 if (need_offchan && !offchan) {
2857 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2862 skb_reserve(skb, local->hw.extra_tx_headroom);
2864 memcpy(skb_put(skb, len), buf, len);
2866 IEEE80211_SKB_CB(skb)->flags = flags;
2868 skb->dev = sdata->dev;
2870 if (!need_offchan) {
2871 *cookie = (unsigned long) skb;
2872 ieee80211_tx_skb(sdata, skb);
2877 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
2878 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
2879 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
2880 IEEE80211_SKB_CB(skb)->hw_queue =
2881 local->hw.offchannel_tx_hw_queue;
2883 /* This will handle all kinds of coalescing and immediate TX */
2884 ret = ieee80211_start_roc_work(local, sdata, chan,
2886 IEEE80211_ROC_TYPE_MGMT_TX);
2890 mutex_unlock(&local->mtx);
2894 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2895 struct wireless_dev *wdev,
2898 struct ieee80211_local *local = wiphy_priv(wiphy);
2900 return ieee80211_cancel_roc(local, cookie, true);
2903 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2904 struct wireless_dev *wdev,
2905 u16 frame_type, bool reg)
2907 struct ieee80211_local *local = wiphy_priv(wiphy);
2908 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2910 switch (frame_type) {
2911 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2912 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2913 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2916 ifibss->auth_frame_registrations++;
2918 ifibss->auth_frame_registrations--;
2921 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2923 local->probe_req_reg++;
2925 local->probe_req_reg--;
2927 if (!local->open_count)
2930 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2937 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2939 struct ieee80211_local *local = wiphy_priv(wiphy);
2944 return drv_set_antenna(local, tx_ant, rx_ant);
2947 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2949 struct ieee80211_local *local = wiphy_priv(wiphy);
2951 return drv_get_antenna(local, tx_ant, rx_ant);
2954 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2956 struct ieee80211_local *local = wiphy_priv(wiphy);
2958 return drv_set_ringparam(local, tx, rx);
2961 static void ieee80211_get_ringparam(struct wiphy *wiphy,
2962 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2964 struct ieee80211_local *local = wiphy_priv(wiphy);
2966 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2969 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2970 struct net_device *dev,
2971 struct cfg80211_gtk_rekey_data *data)
2973 struct ieee80211_local *local = wiphy_priv(wiphy);
2974 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2976 if (!local->ops->set_rekey_data)
2979 drv_set_rekey_data(local, sdata, data);
2984 static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2986 u8 *pos = (void *)skb_put(skb, 7);
2988 *pos++ = WLAN_EID_EXT_CAPABILITY;
2989 *pos++ = 5; /* len */
2994 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2997 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2999 struct ieee80211_local *local = sdata->local;
3003 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
3006 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3007 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3008 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3009 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3014 static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3015 u8 *peer, u8 *bssid)
3017 struct ieee80211_tdls_lnkie *lnkid;
3019 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3021 lnkid->ie_type = WLAN_EID_LINK_ID;
3022 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3024 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3025 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3026 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3030 ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3031 u8 *peer, u8 action_code, u8 dialog_token,
3032 u16 status_code, struct sk_buff *skb)
3034 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3035 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
3036 struct ieee80211_tdls_data *tf;
3038 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3040 memcpy(tf->da, peer, ETH_ALEN);
3041 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3042 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3043 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3045 switch (action_code) {
3046 case WLAN_TDLS_SETUP_REQUEST:
3047 tf->category = WLAN_CATEGORY_TDLS;
3048 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3050 skb_put(skb, sizeof(tf->u.setup_req));
3051 tf->u.setup_req.dialog_token = dialog_token;
3052 tf->u.setup_req.capability =
3053 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3055 ieee80211_add_srates_ie(sdata, skb, false, band);
3056 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3057 ieee80211_tdls_add_ext_capab(skb);
3059 case WLAN_TDLS_SETUP_RESPONSE:
3060 tf->category = WLAN_CATEGORY_TDLS;
3061 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3063 skb_put(skb, sizeof(tf->u.setup_resp));
3064 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3065 tf->u.setup_resp.dialog_token = dialog_token;
3066 tf->u.setup_resp.capability =
3067 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3069 ieee80211_add_srates_ie(sdata, skb, false, band);
3070 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3071 ieee80211_tdls_add_ext_capab(skb);
3073 case WLAN_TDLS_SETUP_CONFIRM:
3074 tf->category = WLAN_CATEGORY_TDLS;
3075 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3077 skb_put(skb, sizeof(tf->u.setup_cfm));
3078 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3079 tf->u.setup_cfm.dialog_token = dialog_token;
3081 case WLAN_TDLS_TEARDOWN:
3082 tf->category = WLAN_CATEGORY_TDLS;
3083 tf->action_code = WLAN_TDLS_TEARDOWN;
3085 skb_put(skb, sizeof(tf->u.teardown));
3086 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3088 case WLAN_TDLS_DISCOVERY_REQUEST:
3089 tf->category = WLAN_CATEGORY_TDLS;
3090 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3092 skb_put(skb, sizeof(tf->u.discover_req));
3093 tf->u.discover_req.dialog_token = dialog_token;
3103 ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3104 u8 *peer, u8 action_code, u8 dialog_token,
3105 u16 status_code, struct sk_buff *skb)
3107 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3108 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
3109 struct ieee80211_mgmt *mgmt;
3111 mgmt = (void *)skb_put(skb, 24);
3112 memset(mgmt, 0, 24);
3113 memcpy(mgmt->da, peer, ETH_ALEN);
3114 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3115 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3117 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3118 IEEE80211_STYPE_ACTION);
3120 switch (action_code) {
3121 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3122 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3123 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3124 mgmt->u.action.u.tdls_discover_resp.action_code =
3125 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3126 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3128 mgmt->u.action.u.tdls_discover_resp.capability =
3129 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3131 ieee80211_add_srates_ie(sdata, skb, false, band);
3132 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3133 ieee80211_tdls_add_ext_capab(skb);
3142 static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3143 u8 *peer, u8 action_code, u8 dialog_token,
3144 u16 status_code, const u8 *extra_ies,
3145 size_t extra_ies_len)
3147 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3148 struct ieee80211_local *local = sdata->local;
3149 struct sk_buff *skb = NULL;
3153 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3156 /* make sure we are in managed mode, and associated */
3157 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3158 !sdata->u.mgd.associated)
3161 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3164 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3165 max(sizeof(struct ieee80211_mgmt),
3166 sizeof(struct ieee80211_tdls_data)) +
3167 50 + /* supported rates */
3170 sizeof(struct ieee80211_tdls_lnkie));
3174 skb_reserve(skb, local->hw.extra_tx_headroom);
3176 switch (action_code) {
3177 case WLAN_TDLS_SETUP_REQUEST:
3178 case WLAN_TDLS_SETUP_RESPONSE:
3179 case WLAN_TDLS_SETUP_CONFIRM:
3180 case WLAN_TDLS_TEARDOWN:
3181 case WLAN_TDLS_DISCOVERY_REQUEST:
3182 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3183 action_code, dialog_token,
3185 send_direct = false;
3187 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3188 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3189 dialog_token, status_code,
3202 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3204 /* the TDLS link IE is always added last */
3205 switch (action_code) {
3206 case WLAN_TDLS_SETUP_REQUEST:
3207 case WLAN_TDLS_SETUP_CONFIRM:
3208 case WLAN_TDLS_TEARDOWN:
3209 case WLAN_TDLS_DISCOVERY_REQUEST:
3210 /* we are the initiator */
3211 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3212 sdata->u.mgd.bssid);
3214 case WLAN_TDLS_SETUP_RESPONSE:
3215 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3216 /* we are the responder */
3217 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3218 sdata->u.mgd.bssid);
3226 ieee80211_tx_skb(sdata, skb);
3231 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3232 * we should default to AC_VI.
3234 switch (action_code) {
3235 case WLAN_TDLS_SETUP_REQUEST:
3236 case WLAN_TDLS_SETUP_RESPONSE:
3237 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3241 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3246 /* disable bottom halves when entering the Tx path */
3248 ret = ieee80211_subif_start_xmit(skb, dev);
3258 static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3259 u8 *peer, enum nl80211_tdls_operation oper)
3261 struct sta_info *sta;
3262 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3264 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3267 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3270 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
3273 case NL80211_TDLS_ENABLE_LINK:
3275 sta = sta_info_get(sdata, peer);
3281 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
3284 case NL80211_TDLS_DISABLE_LINK:
3285 return sta_info_destroy_addr(sdata, peer);
3286 case NL80211_TDLS_TEARDOWN:
3287 case NL80211_TDLS_SETUP:
3288 case NL80211_TDLS_DISCOVERY_REQ:
3289 /* We don't support in-driver setup/teardown/discovery */
3298 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3299 const u8 *peer, u64 *cookie)
3301 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3302 struct ieee80211_local *local = sdata->local;
3303 struct ieee80211_qos_hdr *nullfunc;
3304 struct sk_buff *skb;
3305 int size = sizeof(*nullfunc);
3308 struct ieee80211_tx_info *info;
3309 struct sta_info *sta;
3310 struct ieee80211_chanctx_conf *chanctx_conf;
3311 enum ieee80211_band band;
3314 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3315 if (WARN_ON(!chanctx_conf)) {
3319 band = chanctx_conf->def.chan->band;
3320 sta = sta_info_get_bss(sdata, peer);
3322 qos = test_sta_flag(sta, WLAN_STA_WME);
3329 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3330 IEEE80211_STYPE_QOS_NULLFUNC |
3331 IEEE80211_FCTL_FROMDS);
3334 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3335 IEEE80211_STYPE_NULLFUNC |
3336 IEEE80211_FCTL_FROMDS);
3339 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3347 skb_reserve(skb, local->hw.extra_tx_headroom);
3349 nullfunc = (void *) skb_put(skb, size);
3350 nullfunc->frame_control = fc;
3351 nullfunc->duration_id = 0;
3352 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3353 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3354 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3355 nullfunc->seq_ctrl = 0;
3357 info = IEEE80211_SKB_CB(skb);
3359 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3360 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3362 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3365 nullfunc->qos_ctrl = cpu_to_le16(7);
3368 ieee80211_xmit(sdata, skb, band);
3372 *cookie = (unsigned long) skb;
3376 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3377 struct wireless_dev *wdev,
3378 struct cfg80211_chan_def *chandef)
3380 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3381 struct ieee80211_local *local = wiphy_priv(wiphy);
3382 struct ieee80211_chanctx_conf *chanctx_conf;
3386 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3388 *chandef = chanctx_conf->def;
3390 } else if (local->open_count > 0 &&
3391 local->open_count == local->monitors &&
3392 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3393 if (local->use_chanctx)
3394 *chandef = local->monitor_chandef;
3396 *chandef = local->_oper_chandef;
3405 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3407 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3411 struct cfg80211_ops mac80211_config_ops = {
3412 .add_virtual_intf = ieee80211_add_iface,
3413 .del_virtual_intf = ieee80211_del_iface,
3414 .change_virtual_intf = ieee80211_change_iface,
3415 .start_p2p_device = ieee80211_start_p2p_device,
3416 .stop_p2p_device = ieee80211_stop_p2p_device,
3417 .add_key = ieee80211_add_key,
3418 .del_key = ieee80211_del_key,
3419 .get_key = ieee80211_get_key,
3420 .set_default_key = ieee80211_config_default_key,
3421 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3422 .start_ap = ieee80211_start_ap,
3423 .change_beacon = ieee80211_change_beacon,
3424 .stop_ap = ieee80211_stop_ap,
3425 .add_station = ieee80211_add_station,
3426 .del_station = ieee80211_del_station,
3427 .change_station = ieee80211_change_station,
3428 .get_station = ieee80211_get_station,
3429 .dump_station = ieee80211_dump_station,
3430 .dump_survey = ieee80211_dump_survey,
3431 #ifdef CONFIG_MAC80211_MESH
3432 .add_mpath = ieee80211_add_mpath,
3433 .del_mpath = ieee80211_del_mpath,
3434 .change_mpath = ieee80211_change_mpath,
3435 .get_mpath = ieee80211_get_mpath,
3436 .dump_mpath = ieee80211_dump_mpath,
3437 .update_mesh_config = ieee80211_update_mesh_config,
3438 .get_mesh_config = ieee80211_get_mesh_config,
3439 .join_mesh = ieee80211_join_mesh,
3440 .leave_mesh = ieee80211_leave_mesh,
3442 .change_bss = ieee80211_change_bss,
3443 .set_txq_params = ieee80211_set_txq_params,
3444 .set_monitor_channel = ieee80211_set_monitor_channel,
3445 .suspend = ieee80211_suspend,
3446 .resume = ieee80211_resume,
3447 .scan = ieee80211_scan,
3448 .sched_scan_start = ieee80211_sched_scan_start,
3449 .sched_scan_stop = ieee80211_sched_scan_stop,
3450 .auth = ieee80211_auth,
3451 .assoc = ieee80211_assoc,
3452 .deauth = ieee80211_deauth,
3453 .disassoc = ieee80211_disassoc,
3454 .join_ibss = ieee80211_join_ibss,
3455 .leave_ibss = ieee80211_leave_ibss,
3456 .set_mcast_rate = ieee80211_set_mcast_rate,
3457 .set_wiphy_params = ieee80211_set_wiphy_params,
3458 .set_tx_power = ieee80211_set_tx_power,
3459 .get_tx_power = ieee80211_get_tx_power,
3460 .set_wds_peer = ieee80211_set_wds_peer,
3461 .rfkill_poll = ieee80211_rfkill_poll,
3462 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3463 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3464 .set_power_mgmt = ieee80211_set_power_mgmt,
3465 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3466 .remain_on_channel = ieee80211_remain_on_channel,
3467 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3468 .mgmt_tx = ieee80211_mgmt_tx,
3469 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3470 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3471 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3472 .set_antenna = ieee80211_set_antenna,
3473 .get_antenna = ieee80211_get_antenna,
3474 .set_ringparam = ieee80211_set_ringparam,
3475 .get_ringparam = ieee80211_get_ringparam,
3476 .set_rekey_data = ieee80211_set_rekey_data,
3477 .tdls_oper = ieee80211_tdls_oper,
3478 .tdls_mgmt = ieee80211_tdls_mgmt,
3479 .probe_client = ieee80211_probe_client,
3480 .set_noack_map = ieee80211_set_noack_map,
3482 .set_wakeup = ieee80211_set_wakeup,
3484 .get_et_sset_count = ieee80211_get_et_sset_count,
3485 .get_et_stats = ieee80211_get_et_stats,
3486 .get_et_strings = ieee80211_get_et_strings,
3487 .get_channel = ieee80211_cfg_get_channel,
3488 .start_radar_detection = ieee80211_start_radar_detection,