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)
661 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
662 /* Get survey stats for current channel */
666 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
668 channel = chanctx_conf->def.chan;
677 if (drv_get_survey(local, q, &survey) != 0) {
682 } while (channel != survey.channel);
686 data[i++] = survey.channel->center_freq;
689 if (survey.filled & SURVEY_INFO_NOISE_DBM)
690 data[i++] = (u8)survey.noise;
693 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
694 data[i++] = survey.channel_time;
697 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
698 data[i++] = survey.channel_time_busy;
701 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
702 data[i++] = survey.channel_time_ext_busy;
705 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
706 data[i++] = survey.channel_time_rx;
709 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
710 data[i++] = survey.channel_time_tx;
714 mutex_unlock(&local->sta_mtx);
716 if (WARN_ON(i != STA_STATS_LEN))
719 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
722 static void ieee80211_get_et_strings(struct wiphy *wiphy,
723 struct net_device *dev,
726 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
727 int sz_sta_stats = 0;
729 if (sset == ETH_SS_STATS) {
730 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
731 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
733 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
736 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
737 int idx, u8 *mac, struct station_info *sinfo)
739 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
740 struct ieee80211_local *local = sdata->local;
741 struct sta_info *sta;
744 mutex_lock(&local->sta_mtx);
746 sta = sta_info_get_by_idx(sdata, idx);
749 memcpy(mac, sta->sta.addr, ETH_ALEN);
750 sta_set_sinfo(sta, sinfo);
753 mutex_unlock(&local->sta_mtx);
758 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
759 int idx, struct survey_info *survey)
761 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
763 return drv_get_survey(local, idx, survey);
766 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
767 u8 *mac, struct station_info *sinfo)
769 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
770 struct ieee80211_local *local = sdata->local;
771 struct sta_info *sta;
774 mutex_lock(&local->sta_mtx);
776 sta = sta_info_get_bss(sdata, mac);
779 sta_set_sinfo(sta, sinfo);
782 mutex_unlock(&local->sta_mtx);
787 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
788 struct cfg80211_chan_def *chandef)
790 struct ieee80211_local *local = wiphy_priv(wiphy);
791 struct ieee80211_sub_if_data *sdata;
794 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
797 mutex_lock(&local->iflist_mtx);
798 if (local->use_chanctx) {
799 sdata = rcu_dereference_protected(
800 local->monitor_sdata,
801 lockdep_is_held(&local->iflist_mtx));
803 ieee80211_vif_release_channel(sdata);
804 ret = ieee80211_vif_use_channel(sdata, chandef,
805 IEEE80211_CHANCTX_EXCLUSIVE);
807 } else if (local->open_count == local->monitors) {
808 local->_oper_channel = chandef->chan;
809 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
810 ieee80211_hw_config(local, 0);
814 local->monitor_chandef = *chandef;
815 mutex_unlock(&local->iflist_mtx);
820 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
821 const u8 *resp, size_t resp_len)
823 struct probe_resp *new, *old;
825 if (!resp || !resp_len)
828 old = rtnl_dereference(sdata->u.ap.probe_resp);
830 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
835 memcpy(new->data, resp, resp_len);
837 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
839 kfree_rcu(old, rcu_head);
844 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
845 struct cfg80211_beacon_data *params)
847 struct beacon_data *new, *old;
848 int new_head_len, new_tail_len;
850 u32 changed = BSS_CHANGED_BEACON;
852 old = rtnl_dereference(sdata->u.ap.beacon);
854 /* Need to have a beacon head if we don't have one yet */
855 if (!params->head && !old)
858 /* new or old head? */
860 new_head_len = params->head_len;
862 new_head_len = old->head_len;
864 /* new or old tail? */
865 if (params->tail || !old)
866 /* params->tail_len will be zero for !params->tail */
867 new_tail_len = params->tail_len;
869 new_tail_len = old->tail_len;
871 size = sizeof(*new) + new_head_len + new_tail_len;
873 new = kzalloc(size, GFP_KERNEL);
877 /* start filling the new info now */
880 * pointers go into the block we allocated,
881 * memory is | beacon_data | head | tail |
883 new->head = ((u8 *) new) + sizeof(*new);
884 new->tail = new->head + new_head_len;
885 new->head_len = new_head_len;
886 new->tail_len = new_tail_len;
890 memcpy(new->head, params->head, new_head_len);
892 memcpy(new->head, old->head, new_head_len);
894 /* copy in optional tail */
896 memcpy(new->tail, params->tail, new_tail_len);
899 memcpy(new->tail, old->tail, new_tail_len);
901 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
902 params->probe_resp_len);
906 changed |= BSS_CHANGED_AP_PROBE_RESP;
908 rcu_assign_pointer(sdata->u.ap.beacon, new);
911 kfree_rcu(old, rcu_head);
916 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
917 struct cfg80211_ap_settings *params)
919 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
920 struct beacon_data *old;
921 struct ieee80211_sub_if_data *vlan;
922 u32 changed = BSS_CHANGED_BEACON_INT |
923 BSS_CHANGED_BEACON_ENABLED |
929 old = rtnl_dereference(sdata->u.ap.beacon);
933 /* TODO: make hostapd tell us what it wants */
934 sdata->smps_mode = IEEE80211_SMPS_OFF;
935 sdata->needed_rx_chains = sdata->local->rx_chains;
936 sdata->radar_required = params->radar_required;
938 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
939 IEEE80211_CHANCTX_SHARED);
942 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
945 * Apply control port protocol, this allows us to
946 * not encrypt dynamic WEP control frames.
948 sdata->control_port_protocol = params->crypto.control_port_ethertype;
949 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
950 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
951 vlan->control_port_protocol =
952 params->crypto.control_port_ethertype;
953 vlan->control_port_no_encrypt =
954 params->crypto.control_port_no_encrypt;
957 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
958 sdata->vif.bss_conf.dtim_period = params->dtim_period;
959 sdata->vif.bss_conf.enable_beacon = true;
961 sdata->vif.bss_conf.ssid_len = params->ssid_len;
962 if (params->ssid_len)
963 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
965 sdata->vif.bss_conf.hidden_ssid =
966 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
968 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
969 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
970 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
971 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
972 if (params->p2p_opp_ps)
973 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
974 IEEE80211_P2P_OPPPS_ENABLE_BIT;
976 err = ieee80211_assign_beacon(sdata, ¶ms->beacon);
981 err = drv_start_ap(sdata->local, sdata);
983 old = rtnl_dereference(sdata->u.ap.beacon);
985 kfree_rcu(old, rcu_head);
986 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
990 ieee80211_bss_info_change_notify(sdata, changed);
992 netif_carrier_on(dev);
993 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
994 netif_carrier_on(vlan->dev);
999 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1000 struct cfg80211_beacon_data *params)
1002 struct ieee80211_sub_if_data *sdata;
1003 struct beacon_data *old;
1006 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1008 old = rtnl_dereference(sdata->u.ap.beacon);
1012 err = ieee80211_assign_beacon(sdata, params);
1015 ieee80211_bss_info_change_notify(sdata, err);
1019 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1021 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1022 struct ieee80211_sub_if_data *vlan;
1023 struct ieee80211_local *local = sdata->local;
1024 struct beacon_data *old_beacon;
1025 struct probe_resp *old_probe_resp;
1027 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1030 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
1032 /* turn off carrier for this interface and dependent VLANs */
1033 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1034 netif_carrier_off(vlan->dev);
1035 netif_carrier_off(dev);
1037 /* remove beacon and probe response */
1038 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1039 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1040 kfree_rcu(old_beacon, rcu_head);
1042 kfree_rcu(old_probe_resp, rcu_head);
1044 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1045 sta_info_flush_defer(vlan);
1046 sta_info_flush_defer(sdata);
1048 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1049 sta_info_flush_cleanup(vlan);
1050 ieee80211_free_keys(vlan);
1052 sta_info_flush_cleanup(sdata);
1053 ieee80211_free_keys(sdata);
1055 sdata->vif.bss_conf.enable_beacon = false;
1056 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1057 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1059 drv_stop_ap(sdata->local, sdata);
1061 /* free all potentially still buffered bcast frames */
1062 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1063 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1065 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
1066 ieee80211_vif_release_channel(sdata);
1071 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1072 struct iapp_layer2_update {
1073 u8 da[ETH_ALEN]; /* broadcast */
1074 u8 sa[ETH_ALEN]; /* STA addr */
1082 static void ieee80211_send_layer2_update(struct sta_info *sta)
1084 struct iapp_layer2_update *msg;
1085 struct sk_buff *skb;
1087 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1090 skb = dev_alloc_skb(sizeof(*msg));
1093 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1095 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1096 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1098 eth_broadcast_addr(msg->da);
1099 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
1100 msg->len = htons(6);
1102 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1103 msg->control = 0xaf; /* XID response lsb.1111F101.
1104 * F=0 (no poll command; unsolicited frame) */
1105 msg->xid_info[0] = 0x81; /* XID format identifier */
1106 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1107 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1109 skb->dev = sta->sdata->dev;
1110 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
1111 memset(skb->cb, 0, sizeof(skb->cb));
1115 static int sta_apply_auth_flags(struct ieee80211_local *local,
1116 struct sta_info *sta,
1121 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1122 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1123 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1124 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1129 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1130 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1131 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1132 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1137 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1138 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1139 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1140 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1141 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1148 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1149 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1150 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1151 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1156 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1157 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1158 test_sta_flag(sta, WLAN_STA_AUTH)) {
1159 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1167 static int sta_apply_parameters(struct ieee80211_local *local,
1168 struct sta_info *sta,
1169 struct station_parameters *params)
1174 struct ieee80211_supported_band *sband;
1175 struct ieee80211_sub_if_data *sdata = sta->sdata;
1176 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
1179 sband = local->hw.wiphy->bands[band];
1181 mask = params->sta_flags_mask;
1182 set = params->sta_flags_set;
1184 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1186 * In mesh mode, ASSOCIATED isn't part of the nl80211
1187 * API but must follow AUTHENTICATED for driver state.
1189 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1190 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1191 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1192 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1193 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1195 * TDLS -- everything follows authorized, but
1196 * only becoming authorized is possible, not
1199 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1200 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1201 BIT(NL80211_STA_FLAG_ASSOCIATED);
1202 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1203 BIT(NL80211_STA_FLAG_ASSOCIATED);
1207 ret = sta_apply_auth_flags(local, sta, mask, set);
1211 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1212 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1213 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1215 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1218 if (mask & BIT(NL80211_STA_FLAG_WME)) {
1219 if (set & BIT(NL80211_STA_FLAG_WME)) {
1220 set_sta_flag(sta, WLAN_STA_WME);
1221 sta->sta.wme = true;
1223 clear_sta_flag(sta, WLAN_STA_WME);
1224 sta->sta.wme = false;
1228 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1229 if (set & BIT(NL80211_STA_FLAG_MFP))
1230 set_sta_flag(sta, WLAN_STA_MFP);
1232 clear_sta_flag(sta, WLAN_STA_MFP);
1235 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1236 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1237 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1239 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1242 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1243 sta->sta.uapsd_queues = params->uapsd_queues;
1244 sta->sta.max_sp = params->max_sp;
1248 * cfg80211 validates this (1-2007) and allows setting the AID
1249 * only when creating a new station entry
1252 sta->sta.aid = params->aid;
1255 * Some of the following updates would be racy if called on an
1256 * existing station, via ieee80211_change_station(). However,
1257 * all such changes are rejected by cfg80211 except for updates
1258 * changing the supported rates on an existing but not yet used
1262 if (params->listen_interval >= 0)
1263 sta->listen_interval = params->listen_interval;
1265 if (params->supported_rates) {
1268 for (i = 0; i < params->supported_rates_len; i++) {
1269 int rate = (params->supported_rates[i] & 0x7f) * 5;
1270 for (j = 0; j < sband->n_bitrates; j++) {
1271 if (sband->bitrates[j].bitrate == rate)
1275 sta->sta.supp_rates[band] = rates;
1278 if (params->ht_capa)
1279 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1280 params->ht_capa, sta);
1282 if (params->vht_capa)
1283 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1284 params->vht_capa, sta);
1286 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1287 #ifdef CONFIG_MAC80211_MESH
1290 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1291 switch (params->plink_state) {
1292 case NL80211_PLINK_ESTAB:
1293 if (sta->plink_state != NL80211_PLINK_ESTAB)
1294 changed = mesh_plink_inc_estab_count(
1296 sta->plink_state = params->plink_state;
1298 ieee80211_mps_sta_status_update(sta);
1299 changed |= ieee80211_mps_set_sta_local_pm(sta,
1300 sdata->u.mesh.mshcfg.power_mode);
1302 case NL80211_PLINK_LISTEN:
1303 case NL80211_PLINK_BLOCKED:
1304 case NL80211_PLINK_OPN_SNT:
1305 case NL80211_PLINK_OPN_RCVD:
1306 case NL80211_PLINK_CNF_RCVD:
1307 case NL80211_PLINK_HOLDING:
1308 if (sta->plink_state == NL80211_PLINK_ESTAB)
1309 changed = mesh_plink_dec_estab_count(
1311 sta->plink_state = params->plink_state;
1313 ieee80211_mps_sta_status_update(sta);
1315 ieee80211_mps_local_status_update(sdata);
1323 switch (params->plink_action) {
1324 case NL80211_PLINK_ACTION_NO_ACTION:
1327 case NL80211_PLINK_ACTION_OPEN:
1328 changed |= mesh_plink_open(sta);
1330 case NL80211_PLINK_ACTION_BLOCK:
1331 changed |= mesh_plink_block(sta);
1335 if (params->local_pm)
1337 ieee80211_mps_set_sta_local_pm(sta,
1339 ieee80211_bss_info_change_notify(sdata, changed);
1346 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1347 u8 *mac, struct station_parameters *params)
1349 struct ieee80211_local *local = wiphy_priv(wiphy);
1350 struct sta_info *sta;
1351 struct ieee80211_sub_if_data *sdata;
1356 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1358 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1359 sdata->vif.type != NL80211_IFTYPE_AP)
1362 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1364 if (ether_addr_equal(mac, sdata->vif.addr))
1367 if (is_multicast_ether_addr(mac))
1370 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1375 * defaults -- if userspace wants something else we'll
1376 * change it accordingly in sta_apply_parameters()
1378 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1379 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1380 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1383 err = sta_apply_parameters(local, sta, params);
1385 sta_info_free(local, sta);
1390 * for TDLS, rate control should be initialized only when
1391 * rates are known and station is marked authorized
1393 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1394 rate_control_rate_init(sta);
1396 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1397 sdata->vif.type == NL80211_IFTYPE_AP;
1399 err = sta_info_insert_rcu(sta);
1406 ieee80211_send_layer2_update(sta);
1413 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1416 struct ieee80211_sub_if_data *sdata;
1418 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1421 return sta_info_destroy_addr_bss(sdata, mac);
1423 sta_info_flush(sdata);
1427 static int ieee80211_change_station(struct wiphy *wiphy,
1428 struct net_device *dev, u8 *mac,
1429 struct station_parameters *params)
1431 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1432 struct ieee80211_local *local = wiphy_priv(wiphy);
1433 struct sta_info *sta;
1434 struct ieee80211_sub_if_data *vlansdata;
1435 enum cfg80211_station_type statype;
1438 mutex_lock(&local->sta_mtx);
1440 sta = sta_info_get_bss(sdata, mac);
1446 switch (sdata->vif.type) {
1447 case NL80211_IFTYPE_MESH_POINT:
1448 if (sdata->u.mesh.user_mpm)
1449 statype = CFG80211_STA_MESH_PEER_USER;
1451 statype = CFG80211_STA_MESH_PEER_KERNEL;
1453 case NL80211_IFTYPE_ADHOC:
1454 statype = CFG80211_STA_IBSS;
1456 case NL80211_IFTYPE_STATION:
1457 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1458 statype = CFG80211_STA_AP_STA;
1461 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1462 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1464 statype = CFG80211_STA_TDLS_PEER_SETUP;
1466 case NL80211_IFTYPE_AP:
1467 case NL80211_IFTYPE_AP_VLAN:
1468 statype = CFG80211_STA_AP_CLIENT;
1475 err = cfg80211_check_station_change(wiphy, params, statype);
1479 if (params->vlan && params->vlan != sta->sdata->dev) {
1480 bool prev_4addr = false;
1481 bool new_4addr = false;
1483 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1485 if (params->vlan->ieee80211_ptr->use_4addr) {
1486 if (vlansdata->u.vlan.sta) {
1491 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1495 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1496 sta->sdata->u.vlan.sta) {
1497 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1501 sta->sdata = vlansdata;
1503 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1504 prev_4addr != new_4addr) {
1506 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1508 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1511 ieee80211_send_layer2_update(sta);
1514 err = sta_apply_parameters(local, sta, params);
1518 /* When peer becomes authorized, init rate control as well */
1519 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1520 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1521 rate_control_rate_init(sta);
1523 mutex_unlock(&local->sta_mtx);
1525 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1526 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1527 ieee80211_recalc_ps(local, -1);
1528 ieee80211_recalc_ps_vif(sdata);
1533 mutex_unlock(&local->sta_mtx);
1537 #ifdef CONFIG_MAC80211_MESH
1538 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1539 u8 *dst, u8 *next_hop)
1541 struct ieee80211_sub_if_data *sdata;
1542 struct mesh_path *mpath;
1543 struct sta_info *sta;
1546 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1549 sta = sta_info_get(sdata, next_hop);
1555 err = mesh_path_add(sdata, dst);
1561 mpath = mesh_path_lookup(sdata, dst);
1566 mesh_path_fix_nexthop(mpath, sta);
1572 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1575 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1578 return mesh_path_del(sdata, dst);
1580 mesh_path_flush_by_iface(sdata);
1584 static int ieee80211_change_mpath(struct wiphy *wiphy,
1585 struct net_device *dev,
1586 u8 *dst, u8 *next_hop)
1588 struct ieee80211_sub_if_data *sdata;
1589 struct mesh_path *mpath;
1590 struct sta_info *sta;
1592 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1596 sta = sta_info_get(sdata, next_hop);
1602 mpath = mesh_path_lookup(sdata, dst);
1608 mesh_path_fix_nexthop(mpath, sta);
1614 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1615 struct mpath_info *pinfo)
1617 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1620 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1622 memset(next_hop, 0, ETH_ALEN);
1624 memset(pinfo, 0, sizeof(*pinfo));
1626 pinfo->generation = mesh_paths_generation;
1628 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1631 MPATH_INFO_EXPTIME |
1632 MPATH_INFO_DISCOVERY_TIMEOUT |
1633 MPATH_INFO_DISCOVERY_RETRIES |
1636 pinfo->frame_qlen = mpath->frame_queue.qlen;
1637 pinfo->sn = mpath->sn;
1638 pinfo->metric = mpath->metric;
1639 if (time_before(jiffies, mpath->exp_time))
1640 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1641 pinfo->discovery_timeout =
1642 jiffies_to_msecs(mpath->discovery_timeout);
1643 pinfo->discovery_retries = mpath->discovery_retries;
1644 if (mpath->flags & MESH_PATH_ACTIVE)
1645 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1646 if (mpath->flags & MESH_PATH_RESOLVING)
1647 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1648 if (mpath->flags & MESH_PATH_SN_VALID)
1649 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1650 if (mpath->flags & MESH_PATH_FIXED)
1651 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1652 if (mpath->flags & MESH_PATH_RESOLVED)
1653 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1656 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1657 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1660 struct ieee80211_sub_if_data *sdata;
1661 struct mesh_path *mpath;
1663 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1666 mpath = mesh_path_lookup(sdata, dst);
1671 memcpy(dst, mpath->dst, ETH_ALEN);
1672 mpath_set_pinfo(mpath, next_hop, pinfo);
1677 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1678 int idx, u8 *dst, u8 *next_hop,
1679 struct mpath_info *pinfo)
1681 struct ieee80211_sub_if_data *sdata;
1682 struct mesh_path *mpath;
1684 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1687 mpath = mesh_path_lookup_by_idx(sdata, idx);
1692 memcpy(dst, mpath->dst, ETH_ALEN);
1693 mpath_set_pinfo(mpath, next_hop, pinfo);
1698 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1699 struct net_device *dev,
1700 struct mesh_config *conf)
1702 struct ieee80211_sub_if_data *sdata;
1703 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1705 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1709 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1711 return (mask >> (parm-1)) & 0x1;
1714 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1715 const struct mesh_setup *setup)
1719 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1720 struct ieee80211_sub_if_data, u.mesh);
1722 /* allocate information elements */
1726 if (setup->ie_len) {
1727 new_ie = kmemdup(setup->ie, setup->ie_len,
1732 ifmsh->ie_len = setup->ie_len;
1736 /* now copy the rest of the setup parameters */
1737 ifmsh->mesh_id_len = setup->mesh_id_len;
1738 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1739 ifmsh->mesh_sp_id = setup->sync_method;
1740 ifmsh->mesh_pp_id = setup->path_sel_proto;
1741 ifmsh->mesh_pm_id = setup->path_metric;
1742 ifmsh->user_mpm = setup->user_mpm;
1743 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1744 if (setup->is_authenticated)
1745 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1746 if (setup->is_secure)
1747 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1749 /* mcast rate setting in Mesh Node */
1750 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1751 sizeof(setup->mcast_rate));
1753 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1754 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1759 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1760 struct net_device *dev, u32 mask,
1761 const struct mesh_config *nconf)
1763 struct mesh_config *conf;
1764 struct ieee80211_sub_if_data *sdata;
1765 struct ieee80211_if_mesh *ifmsh;
1767 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1768 ifmsh = &sdata->u.mesh;
1770 /* Set the config options which we are interested in setting */
1771 conf = &(sdata->u.mesh.mshcfg);
1772 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1773 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1774 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1775 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1776 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1777 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1778 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1779 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1780 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1781 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1782 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1783 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1784 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1785 conf->element_ttl = nconf->element_ttl;
1786 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1787 if (ifmsh->user_mpm)
1789 conf->auto_open_plinks = nconf->auto_open_plinks;
1791 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1792 conf->dot11MeshNbrOffsetMaxNeighbor =
1793 nconf->dot11MeshNbrOffsetMaxNeighbor;
1794 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1795 conf->dot11MeshHWMPmaxPREQretries =
1796 nconf->dot11MeshHWMPmaxPREQretries;
1797 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1798 conf->path_refresh_time = nconf->path_refresh_time;
1799 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1800 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1801 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1802 conf->dot11MeshHWMPactivePathTimeout =
1803 nconf->dot11MeshHWMPactivePathTimeout;
1804 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1805 conf->dot11MeshHWMPpreqMinInterval =
1806 nconf->dot11MeshHWMPpreqMinInterval;
1807 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1808 conf->dot11MeshHWMPperrMinInterval =
1809 nconf->dot11MeshHWMPperrMinInterval;
1810 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1812 conf->dot11MeshHWMPnetDiameterTraversalTime =
1813 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1814 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1815 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1816 ieee80211_mesh_root_setup(ifmsh);
1818 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1819 /* our current gate announcement implementation rides on root
1820 * announcements, so require this ifmsh to also be a root node
1822 if (nconf->dot11MeshGateAnnouncementProtocol &&
1823 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1824 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
1825 ieee80211_mesh_root_setup(ifmsh);
1827 conf->dot11MeshGateAnnouncementProtocol =
1828 nconf->dot11MeshGateAnnouncementProtocol;
1830 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
1831 conf->dot11MeshHWMPRannInterval =
1832 nconf->dot11MeshHWMPRannInterval;
1833 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1834 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1835 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1836 /* our RSSI threshold implementation is supported only for
1837 * devices that report signal in dBm.
1839 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1841 conf->rssi_threshold = nconf->rssi_threshold;
1843 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1844 conf->ht_opmode = nconf->ht_opmode;
1845 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1846 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1848 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1849 conf->dot11MeshHWMPactivePathToRootTimeout =
1850 nconf->dot11MeshHWMPactivePathToRootTimeout;
1851 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1852 conf->dot11MeshHWMProotInterval =
1853 nconf->dot11MeshHWMProotInterval;
1854 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1855 conf->dot11MeshHWMPconfirmationInterval =
1856 nconf->dot11MeshHWMPconfirmationInterval;
1857 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1858 conf->power_mode = nconf->power_mode;
1859 ieee80211_mps_local_status_update(sdata);
1861 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
1862 conf->dot11MeshAwakeWindowDuration =
1863 nconf->dot11MeshAwakeWindowDuration;
1864 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
1868 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1869 const struct mesh_config *conf,
1870 const struct mesh_setup *setup)
1872 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1873 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1876 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1877 err = copy_mesh_setup(ifmsh, setup);
1881 /* can mesh use other SMPS modes? */
1882 sdata->smps_mode = IEEE80211_SMPS_OFF;
1883 sdata->needed_rx_chains = sdata->local->rx_chains;
1885 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
1886 IEEE80211_CHANCTX_SHARED);
1890 return ieee80211_start_mesh(sdata);
1893 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1895 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1897 ieee80211_stop_mesh(sdata);
1898 ieee80211_vif_release_channel(sdata);
1904 static int ieee80211_change_bss(struct wiphy *wiphy,
1905 struct net_device *dev,
1906 struct bss_parameters *params)
1908 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1909 enum ieee80211_band band;
1912 if (!rtnl_dereference(sdata->u.ap.beacon))
1915 band = ieee80211_get_sdata_band(sdata);
1917 if (params->use_cts_prot >= 0) {
1918 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1919 changed |= BSS_CHANGED_ERP_CTS_PROT;
1921 if (params->use_short_preamble >= 0) {
1922 sdata->vif.bss_conf.use_short_preamble =
1923 params->use_short_preamble;
1924 changed |= BSS_CHANGED_ERP_PREAMBLE;
1927 if (!sdata->vif.bss_conf.use_short_slot &&
1928 band == IEEE80211_BAND_5GHZ) {
1929 sdata->vif.bss_conf.use_short_slot = true;
1930 changed |= BSS_CHANGED_ERP_SLOT;
1933 if (params->use_short_slot_time >= 0) {
1934 sdata->vif.bss_conf.use_short_slot =
1935 params->use_short_slot_time;
1936 changed |= BSS_CHANGED_ERP_SLOT;
1939 if (params->basic_rates) {
1942 struct ieee80211_supported_band *sband = wiphy->bands[band];
1944 for (i = 0; i < params->basic_rates_len; i++) {
1945 int rate = (params->basic_rates[i] & 0x7f) * 5;
1946 for (j = 0; j < sband->n_bitrates; j++) {
1947 if (sband->bitrates[j].bitrate == rate)
1951 sdata->vif.bss_conf.basic_rates = rates;
1952 changed |= BSS_CHANGED_BASIC_RATES;
1955 if (params->ap_isolate >= 0) {
1956 if (params->ap_isolate)
1957 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1959 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1962 if (params->ht_opmode >= 0) {
1963 sdata->vif.bss_conf.ht_operation_mode =
1964 (u16) params->ht_opmode;
1965 changed |= BSS_CHANGED_HT;
1968 if (params->p2p_ctwindow >= 0) {
1969 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1970 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1971 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1972 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1973 changed |= BSS_CHANGED_P2P_PS;
1976 if (params->p2p_opp_ps > 0) {
1977 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1978 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1979 changed |= BSS_CHANGED_P2P_PS;
1980 } else if (params->p2p_opp_ps == 0) {
1981 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1982 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
1983 changed |= BSS_CHANGED_P2P_PS;
1986 ieee80211_bss_info_change_notify(sdata, changed);
1991 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1992 struct net_device *dev,
1993 struct ieee80211_txq_params *params)
1995 struct ieee80211_local *local = wiphy_priv(wiphy);
1996 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1997 struct ieee80211_tx_queue_params p;
1999 if (!local->ops->conf_tx)
2002 if (local->hw.queues < IEEE80211_NUM_ACS)
2005 memset(&p, 0, sizeof(p));
2006 p.aifs = params->aifs;
2007 p.cw_max = params->cwmax;
2008 p.cw_min = params->cwmin;
2009 p.txop = params->txop;
2012 * Setting tx queue params disables u-apsd because it's only
2013 * called in master mode.
2017 sdata->tx_conf[params->ac] = p;
2018 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2019 wiphy_debug(local->hw.wiphy,
2020 "failed to set TX queue parameters for AC %d\n",
2025 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2031 static int ieee80211_suspend(struct wiphy *wiphy,
2032 struct cfg80211_wowlan *wowlan)
2034 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2037 static int ieee80211_resume(struct wiphy *wiphy)
2039 return __ieee80211_resume(wiphy_priv(wiphy));
2042 #define ieee80211_suspend NULL
2043 #define ieee80211_resume NULL
2046 static int ieee80211_scan(struct wiphy *wiphy,
2047 struct cfg80211_scan_request *req)
2049 struct ieee80211_sub_if_data *sdata;
2051 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2053 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2054 case NL80211_IFTYPE_STATION:
2055 case NL80211_IFTYPE_ADHOC:
2056 case NL80211_IFTYPE_MESH_POINT:
2057 case NL80211_IFTYPE_P2P_CLIENT:
2058 case NL80211_IFTYPE_P2P_DEVICE:
2060 case NL80211_IFTYPE_P2P_GO:
2061 if (sdata->local->ops->hw_scan)
2064 * FIXME: implement NoA while scanning in software,
2065 * for now fall through to allow scanning only when
2066 * beaconing hasn't been configured yet
2068 case NL80211_IFTYPE_AP:
2070 * If the scan has been forced (and the driver supports
2071 * forcing), don't care about being beaconing already.
2072 * This will create problems to the attached stations (e.g. all
2073 * the frames sent while scanning on other channel will be
2076 if (sdata->u.ap.beacon &&
2077 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2078 !(req->flags & NL80211_SCAN_FLAG_AP)))
2085 return ieee80211_request_scan(sdata, req);
2089 ieee80211_sched_scan_start(struct wiphy *wiphy,
2090 struct net_device *dev,
2091 struct cfg80211_sched_scan_request *req)
2093 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2095 if (!sdata->local->ops->sched_scan_start)
2098 return ieee80211_request_sched_scan_start(sdata, req);
2102 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
2104 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2106 if (!sdata->local->ops->sched_scan_stop)
2109 return ieee80211_request_sched_scan_stop(sdata);
2112 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2113 struct cfg80211_auth_request *req)
2115 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2118 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2119 struct cfg80211_assoc_request *req)
2121 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2124 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2125 struct cfg80211_deauth_request *req)
2127 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2130 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2131 struct cfg80211_disassoc_request *req)
2133 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2136 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2137 struct cfg80211_ibss_params *params)
2139 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2142 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2144 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2147 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2148 int rate[IEEE80211_NUM_BANDS])
2150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2152 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2153 sizeof(int) * IEEE80211_NUM_BANDS);
2158 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2160 struct ieee80211_local *local = wiphy_priv(wiphy);
2163 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2164 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2170 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2171 err = drv_set_coverage_class(local, wiphy->coverage_class);
2177 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2178 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2184 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2185 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2187 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2189 if (changed & WIPHY_PARAM_RETRY_LONG) {
2190 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2192 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2195 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2196 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2201 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2202 struct wireless_dev *wdev,
2203 enum nl80211_tx_power_setting type, int mbm)
2205 struct ieee80211_local *local = wiphy_priv(wiphy);
2206 struct ieee80211_sub_if_data *sdata;
2209 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2212 case NL80211_TX_POWER_AUTOMATIC:
2213 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2215 case NL80211_TX_POWER_LIMITED:
2216 case NL80211_TX_POWER_FIXED:
2217 if (mbm < 0 || (mbm % 100))
2219 sdata->user_power_level = MBM_TO_DBM(mbm);
2223 ieee80211_recalc_txpower(sdata);
2229 case NL80211_TX_POWER_AUTOMATIC:
2230 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2232 case NL80211_TX_POWER_LIMITED:
2233 case NL80211_TX_POWER_FIXED:
2234 if (mbm < 0 || (mbm % 100))
2236 local->user_power_level = MBM_TO_DBM(mbm);
2240 mutex_lock(&local->iflist_mtx);
2241 list_for_each_entry(sdata, &local->interfaces, list)
2242 sdata->user_power_level = local->user_power_level;
2243 list_for_each_entry(sdata, &local->interfaces, list)
2244 ieee80211_recalc_txpower(sdata);
2245 mutex_unlock(&local->iflist_mtx);
2250 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2251 struct wireless_dev *wdev,
2254 struct ieee80211_local *local = wiphy_priv(wiphy);
2255 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2257 if (!local->use_chanctx)
2258 *dbm = local->hw.conf.power_level;
2260 *dbm = sdata->vif.bss_conf.txpower;
2265 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2268 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2270 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2275 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2277 struct ieee80211_local *local = wiphy_priv(wiphy);
2279 drv_rfkill_poll(local);
2282 #ifdef CONFIG_NL80211_TESTMODE
2283 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
2285 struct ieee80211_local *local = wiphy_priv(wiphy);
2287 if (!local->ops->testmode_cmd)
2290 return local->ops->testmode_cmd(&local->hw, data, len);
2293 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2294 struct sk_buff *skb,
2295 struct netlink_callback *cb,
2296 void *data, int len)
2298 struct ieee80211_local *local = wiphy_priv(wiphy);
2300 if (!local->ops->testmode_dump)
2303 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2307 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2308 enum ieee80211_smps_mode smps_mode)
2311 enum ieee80211_smps_mode old_req;
2314 lockdep_assert_held(&sdata->u.mgd.mtx);
2316 old_req = sdata->u.mgd.req_smps;
2317 sdata->u.mgd.req_smps = smps_mode;
2319 if (old_req == smps_mode &&
2320 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2324 * If not associated, or current association is not an HT
2325 * association, there's no need to do anything, just store
2326 * the new value until we associate.
2328 if (!sdata->u.mgd.associated ||
2329 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2332 ap = sdata->u.mgd.associated->bssid;
2334 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2335 if (sdata->u.mgd.powersave)
2336 smps_mode = IEEE80211_SMPS_DYNAMIC;
2338 smps_mode = IEEE80211_SMPS_OFF;
2341 /* send SM PS frame to AP */
2342 err = ieee80211_send_smps_action(sdata, smps_mode,
2345 sdata->u.mgd.req_smps = old_req;
2350 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2351 bool enabled, int timeout)
2353 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2354 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2356 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2357 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
2360 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2363 if (enabled == sdata->u.mgd.powersave &&
2364 timeout == local->dynamic_ps_forced_timeout)
2367 sdata->u.mgd.powersave = enabled;
2368 local->dynamic_ps_forced_timeout = timeout;
2370 /* no change, but if automatic follow powersave */
2371 mutex_lock(&sdata->u.mgd.mtx);
2372 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2373 mutex_unlock(&sdata->u.mgd.mtx);
2375 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2376 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2378 ieee80211_recalc_ps(local, -1);
2379 ieee80211_recalc_ps_vif(sdata);
2384 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2385 struct net_device *dev,
2386 s32 rssi_thold, u32 rssi_hyst)
2388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2389 struct ieee80211_vif *vif = &sdata->vif;
2390 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2392 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2393 rssi_hyst == bss_conf->cqm_rssi_hyst)
2396 bss_conf->cqm_rssi_thold = rssi_thold;
2397 bss_conf->cqm_rssi_hyst = rssi_hyst;
2399 /* tell the driver upon association, unless already associated */
2400 if (sdata->u.mgd.associated &&
2401 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2402 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2407 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2408 struct net_device *dev,
2410 const struct cfg80211_bitrate_mask *mask)
2412 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2413 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2416 if (!ieee80211_sdata_running(sdata))
2419 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2420 ret = drv_set_bitrate_mask(local, sdata, mask);
2425 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
2426 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2427 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2428 sizeof(mask->control[i].mcs));
2434 static int ieee80211_start_roc_work(struct ieee80211_local *local,
2435 struct ieee80211_sub_if_data *sdata,
2436 struct ieee80211_channel *channel,
2437 unsigned int duration, u64 *cookie,
2438 struct sk_buff *txskb,
2439 enum ieee80211_roc_type type)
2441 struct ieee80211_roc_work *roc, *tmp;
2442 bool queued = false;
2445 lockdep_assert_held(&local->mtx);
2447 if (local->use_chanctx && !local->ops->remain_on_channel)
2450 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2454 roc->chan = channel;
2455 roc->duration = duration;
2456 roc->req_duration = duration;
2459 roc->mgmt_tx_cookie = (unsigned long)txskb;
2461 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2462 INIT_LIST_HEAD(&roc->dependents);
2464 /* if there's one pending or we're scanning, queue this one */
2465 if (!list_empty(&local->roc_list) ||
2466 local->scanning || local->radar_detect_enabled)
2467 goto out_check_combine;
2469 /* if not HW assist, just queue & schedule work */
2470 if (!local->ops->remain_on_channel) {
2471 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2475 /* otherwise actually kick it off here (for error handling) */
2478 * If the duration is zero, then the driver
2479 * wouldn't actually do anything. Set it to
2482 * TODO: cancel the off-channel operation
2483 * when we get the SKB's TX status and
2484 * the wait time was zero before.
2489 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
2495 roc->started = true;
2499 list_for_each_entry(tmp, &local->roc_list, list) {
2500 if (tmp->chan != channel || tmp->sdata != sdata)
2504 * Extend this ROC if possible:
2506 * If it hasn't started yet, just increase the duration
2507 * and add the new one to the list of dependents.
2508 * If the type of the new ROC has higher priority, modify the
2509 * type of the previous one to match that of the new one.
2511 if (!tmp->started) {
2512 list_add_tail(&roc->list, &tmp->dependents);
2513 tmp->duration = max(tmp->duration, roc->duration);
2514 tmp->type = max(tmp->type, roc->type);
2519 /* If it has already started, it's more difficult ... */
2520 if (local->ops->remain_on_channel) {
2521 unsigned long j = jiffies;
2524 * In the offloaded ROC case, if it hasn't begun, add
2525 * this new one to the dependent list to be handled
2526 * when the master one begins. If it has begun,
2527 * check that there's still a minimum time left and
2528 * if so, start this one, transmitting the frame, but
2529 * add it to the list directly after this one with
2530 * a reduced time so we'll ask the driver to execute
2531 * it right after finishing the previous one, in the
2532 * hope that it'll also be executed right afterwards,
2533 * effectively extending the old one.
2534 * If there's no minimum time left, just add it to the
2536 * TODO: the ROC type is ignored here, assuming that it
2537 * is better to immediately use the current ROC.
2539 if (!tmp->hw_begun) {
2540 list_add_tail(&roc->list, &tmp->dependents);
2545 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2546 tmp->hw_start_time +
2547 msecs_to_jiffies(tmp->duration))) {
2550 ieee80211_handle_roc_started(roc);
2552 new_dur = roc->duration -
2553 jiffies_to_msecs(tmp->hw_start_time +
2559 /* add right after tmp */
2560 list_add(&roc->list, &tmp->list);
2562 list_add_tail(&roc->list,
2567 } else if (del_timer_sync(&tmp->work.timer)) {
2568 unsigned long new_end;
2571 * In the software ROC case, cancel the timer, if
2572 * that fails then the finish work is already
2573 * queued/pending and thus we queue the new ROC
2574 * normally, if that succeeds then we can extend
2575 * the timer duration and TX the frame (if any.)
2578 list_add_tail(&roc->list, &tmp->dependents);
2581 new_end = jiffies + msecs_to_jiffies(roc->duration);
2583 /* ok, it was started & we canceled timer */
2584 if (time_after(new_end, tmp->work.timer.expires))
2585 mod_timer(&tmp->work.timer, new_end);
2587 add_timer(&tmp->work.timer);
2589 ieee80211_handle_roc_started(roc);
2596 list_add_tail(&roc->list, &local->roc_list);
2599 * cookie is either the roc cookie (for normal roc)
2600 * or the SKB (for mgmt TX)
2603 /* local->mtx protects this */
2604 local->roc_cookie_counter++;
2605 roc->cookie = local->roc_cookie_counter;
2606 /* wow, you wrapped 64 bits ... more likely a bug */
2607 if (WARN_ON(roc->cookie == 0)) {
2609 local->roc_cookie_counter++;
2611 *cookie = roc->cookie;
2613 *cookie = (unsigned long)txskb;
2619 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
2620 struct wireless_dev *wdev,
2621 struct ieee80211_channel *chan,
2622 unsigned int duration,
2625 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2626 struct ieee80211_local *local = sdata->local;
2629 mutex_lock(&local->mtx);
2630 ret = ieee80211_start_roc_work(local, sdata, chan,
2631 duration, cookie, NULL,
2632 IEEE80211_ROC_TYPE_NORMAL);
2633 mutex_unlock(&local->mtx);
2638 static int ieee80211_cancel_roc(struct ieee80211_local *local,
2639 u64 cookie, bool mgmt_tx)
2641 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2644 mutex_lock(&local->mtx);
2645 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
2646 struct ieee80211_roc_work *dep, *tmp2;
2648 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2649 if (!mgmt_tx && dep->cookie != cookie)
2651 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2653 /* found dependent item -- just remove it */
2654 list_del(&dep->list);
2655 mutex_unlock(&local->mtx);
2657 ieee80211_roc_notify_destroy(dep);
2661 if (!mgmt_tx && roc->cookie != cookie)
2663 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2671 mutex_unlock(&local->mtx);
2676 * We found the item to cancel, so do that. Note that it
2677 * may have dependents, which we also cancel (and send
2678 * the expired signal for.) Not doing so would be quite
2679 * tricky here, but we may need to fix it later.
2682 if (local->ops->remain_on_channel) {
2683 if (found->started) {
2684 ret = drv_cancel_remain_on_channel(local);
2685 if (WARN_ON_ONCE(ret)) {
2686 mutex_unlock(&local->mtx);
2691 list_del(&found->list);
2694 ieee80211_start_next_roc(local);
2695 mutex_unlock(&local->mtx);
2697 ieee80211_roc_notify_destroy(found);
2699 /* work may be pending so use it all the time */
2700 found->abort = true;
2701 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2703 mutex_unlock(&local->mtx);
2705 /* work will clean up etc */
2706 flush_delayed_work(&found->work);
2712 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
2713 struct wireless_dev *wdev,
2716 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2717 struct ieee80211_local *local = sdata->local;
2719 return ieee80211_cancel_roc(local, cookie, false);
2722 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2723 struct net_device *dev,
2724 struct cfg80211_chan_def *chandef)
2726 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2727 struct ieee80211_local *local = sdata->local;
2728 unsigned long timeout;
2731 if (!list_empty(&local->roc_list) || local->scanning)
2734 /* whatever, but channel contexts should not complain about that one */
2735 sdata->smps_mode = IEEE80211_SMPS_OFF;
2736 sdata->needed_rx_chains = local->rx_chains;
2737 sdata->radar_required = true;
2739 mutex_lock(&local->iflist_mtx);
2740 err = ieee80211_vif_use_channel(sdata, chandef,
2741 IEEE80211_CHANCTX_SHARED);
2742 mutex_unlock(&local->iflist_mtx);
2746 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2747 ieee80211_queue_delayed_work(&sdata->local->hw,
2748 &sdata->dfs_cac_timer_work, timeout);
2753 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
2754 struct ieee80211_channel *chan, bool offchan,
2755 unsigned int wait, const u8 *buf, size_t len,
2756 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
2758 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2759 struct ieee80211_local *local = sdata->local;
2760 struct sk_buff *skb;
2761 struct sta_info *sta;
2762 const struct ieee80211_mgmt *mgmt = (void *)buf;
2763 bool need_offchan = false;
2767 if (dont_wait_for_ack)
2768 flags = IEEE80211_TX_CTL_NO_ACK;
2770 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2771 IEEE80211_TX_CTL_REQ_TX_STATUS;
2774 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2776 switch (sdata->vif.type) {
2777 case NL80211_IFTYPE_ADHOC:
2778 if (!sdata->vif.bss_conf.ibss_joined)
2779 need_offchan = true;
2781 #ifdef CONFIG_MAC80211_MESH
2782 case NL80211_IFTYPE_MESH_POINT:
2783 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2784 !sdata->u.mesh.mesh_id_len)
2785 need_offchan = true;
2788 case NL80211_IFTYPE_AP:
2789 case NL80211_IFTYPE_AP_VLAN:
2790 case NL80211_IFTYPE_P2P_GO:
2791 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2792 !ieee80211_vif_is_mesh(&sdata->vif) &&
2793 !rcu_access_pointer(sdata->bss->beacon))
2794 need_offchan = true;
2795 if (!ieee80211_is_action(mgmt->frame_control) ||
2796 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2799 sta = sta_info_get(sdata, mgmt->da);
2804 case NL80211_IFTYPE_STATION:
2805 case NL80211_IFTYPE_P2P_CLIENT:
2806 if (!sdata->u.mgd.associated)
2807 need_offchan = true;
2809 case NL80211_IFTYPE_P2P_DEVICE:
2810 need_offchan = true;
2816 mutex_lock(&local->mtx);
2818 /* Check if the operating channel is the requested channel */
2819 if (!need_offchan) {
2820 struct ieee80211_chanctx_conf *chanctx_conf;
2823 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2826 need_offchan = chan != chanctx_conf->def.chan;
2828 need_offchan = true;
2832 if (need_offchan && !offchan) {
2837 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2842 skb_reserve(skb, local->hw.extra_tx_headroom);
2844 memcpy(skb_put(skb, len), buf, len);
2846 IEEE80211_SKB_CB(skb)->flags = flags;
2848 skb->dev = sdata->dev;
2850 if (!need_offchan) {
2851 *cookie = (unsigned long) skb;
2852 ieee80211_tx_skb(sdata, skb);
2857 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
2858 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
2859 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
2860 IEEE80211_SKB_CB(skb)->hw_queue =
2861 local->hw.offchannel_tx_hw_queue;
2863 /* This will handle all kinds of coalescing and immediate TX */
2864 ret = ieee80211_start_roc_work(local, sdata, chan,
2866 IEEE80211_ROC_TYPE_MGMT_TX);
2870 mutex_unlock(&local->mtx);
2874 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2875 struct wireless_dev *wdev,
2878 struct ieee80211_local *local = wiphy_priv(wiphy);
2880 return ieee80211_cancel_roc(local, cookie, true);
2883 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2884 struct wireless_dev *wdev,
2885 u16 frame_type, bool reg)
2887 struct ieee80211_local *local = wiphy_priv(wiphy);
2888 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2890 switch (frame_type) {
2891 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2892 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2893 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2896 ifibss->auth_frame_registrations++;
2898 ifibss->auth_frame_registrations--;
2901 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2903 local->probe_req_reg++;
2905 local->probe_req_reg--;
2907 if (!local->open_count)
2910 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2917 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2919 struct ieee80211_local *local = wiphy_priv(wiphy);
2924 return drv_set_antenna(local, tx_ant, rx_ant);
2927 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2929 struct ieee80211_local *local = wiphy_priv(wiphy);
2931 return drv_get_antenna(local, tx_ant, rx_ant);
2934 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2936 struct ieee80211_local *local = wiphy_priv(wiphy);
2938 return drv_set_ringparam(local, tx, rx);
2941 static void ieee80211_get_ringparam(struct wiphy *wiphy,
2942 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2944 struct ieee80211_local *local = wiphy_priv(wiphy);
2946 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2949 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2950 struct net_device *dev,
2951 struct cfg80211_gtk_rekey_data *data)
2953 struct ieee80211_local *local = wiphy_priv(wiphy);
2954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2956 if (!local->ops->set_rekey_data)
2959 drv_set_rekey_data(local, sdata, data);
2964 static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2966 u8 *pos = (void *)skb_put(skb, 7);
2968 *pos++ = WLAN_EID_EXT_CAPABILITY;
2969 *pos++ = 5; /* len */
2974 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2977 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2979 struct ieee80211_local *local = sdata->local;
2983 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
2986 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2987 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2988 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2989 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2994 static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2995 u8 *peer, u8 *bssid)
2997 struct ieee80211_tdls_lnkie *lnkid;
2999 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3001 lnkid->ie_type = WLAN_EID_LINK_ID;
3002 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3004 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3005 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3006 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3010 ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3011 u8 *peer, u8 action_code, u8 dialog_token,
3012 u16 status_code, struct sk_buff *skb)
3014 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3015 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
3016 struct ieee80211_tdls_data *tf;
3018 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3020 memcpy(tf->da, peer, ETH_ALEN);
3021 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3022 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3023 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3025 switch (action_code) {
3026 case WLAN_TDLS_SETUP_REQUEST:
3027 tf->category = WLAN_CATEGORY_TDLS;
3028 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3030 skb_put(skb, sizeof(tf->u.setup_req));
3031 tf->u.setup_req.dialog_token = dialog_token;
3032 tf->u.setup_req.capability =
3033 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3035 ieee80211_add_srates_ie(sdata, skb, false, band);
3036 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3037 ieee80211_tdls_add_ext_capab(skb);
3039 case WLAN_TDLS_SETUP_RESPONSE:
3040 tf->category = WLAN_CATEGORY_TDLS;
3041 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3043 skb_put(skb, sizeof(tf->u.setup_resp));
3044 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3045 tf->u.setup_resp.dialog_token = dialog_token;
3046 tf->u.setup_resp.capability =
3047 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3049 ieee80211_add_srates_ie(sdata, skb, false, band);
3050 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3051 ieee80211_tdls_add_ext_capab(skb);
3053 case WLAN_TDLS_SETUP_CONFIRM:
3054 tf->category = WLAN_CATEGORY_TDLS;
3055 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3057 skb_put(skb, sizeof(tf->u.setup_cfm));
3058 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3059 tf->u.setup_cfm.dialog_token = dialog_token;
3061 case WLAN_TDLS_TEARDOWN:
3062 tf->category = WLAN_CATEGORY_TDLS;
3063 tf->action_code = WLAN_TDLS_TEARDOWN;
3065 skb_put(skb, sizeof(tf->u.teardown));
3066 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3068 case WLAN_TDLS_DISCOVERY_REQUEST:
3069 tf->category = WLAN_CATEGORY_TDLS;
3070 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3072 skb_put(skb, sizeof(tf->u.discover_req));
3073 tf->u.discover_req.dialog_token = dialog_token;
3083 ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3084 u8 *peer, u8 action_code, u8 dialog_token,
3085 u16 status_code, struct sk_buff *skb)
3087 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3088 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
3089 struct ieee80211_mgmt *mgmt;
3091 mgmt = (void *)skb_put(skb, 24);
3092 memset(mgmt, 0, 24);
3093 memcpy(mgmt->da, peer, ETH_ALEN);
3094 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3095 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3097 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3098 IEEE80211_STYPE_ACTION);
3100 switch (action_code) {
3101 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3102 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3103 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3104 mgmt->u.action.u.tdls_discover_resp.action_code =
3105 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3106 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3108 mgmt->u.action.u.tdls_discover_resp.capability =
3109 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3111 ieee80211_add_srates_ie(sdata, skb, false, band);
3112 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3113 ieee80211_tdls_add_ext_capab(skb);
3122 static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3123 u8 *peer, u8 action_code, u8 dialog_token,
3124 u16 status_code, const u8 *extra_ies,
3125 size_t extra_ies_len)
3127 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3128 struct ieee80211_local *local = sdata->local;
3129 struct sk_buff *skb = NULL;
3133 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3136 /* make sure we are in managed mode, and associated */
3137 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3138 !sdata->u.mgd.associated)
3141 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3144 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3145 max(sizeof(struct ieee80211_mgmt),
3146 sizeof(struct ieee80211_tdls_data)) +
3147 50 + /* supported rates */
3150 sizeof(struct ieee80211_tdls_lnkie));
3154 skb_reserve(skb, local->hw.extra_tx_headroom);
3156 switch (action_code) {
3157 case WLAN_TDLS_SETUP_REQUEST:
3158 case WLAN_TDLS_SETUP_RESPONSE:
3159 case WLAN_TDLS_SETUP_CONFIRM:
3160 case WLAN_TDLS_TEARDOWN:
3161 case WLAN_TDLS_DISCOVERY_REQUEST:
3162 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3163 action_code, dialog_token,
3165 send_direct = false;
3167 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3168 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3169 dialog_token, status_code,
3182 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3184 /* the TDLS link IE is always added last */
3185 switch (action_code) {
3186 case WLAN_TDLS_SETUP_REQUEST:
3187 case WLAN_TDLS_SETUP_CONFIRM:
3188 case WLAN_TDLS_TEARDOWN:
3189 case WLAN_TDLS_DISCOVERY_REQUEST:
3190 /* we are the initiator */
3191 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3192 sdata->u.mgd.bssid);
3194 case WLAN_TDLS_SETUP_RESPONSE:
3195 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3196 /* we are the responder */
3197 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3198 sdata->u.mgd.bssid);
3206 ieee80211_tx_skb(sdata, skb);
3211 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3212 * we should default to AC_VI.
3214 switch (action_code) {
3215 case WLAN_TDLS_SETUP_REQUEST:
3216 case WLAN_TDLS_SETUP_RESPONSE:
3217 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3221 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3226 /* disable bottom halves when entering the Tx path */
3228 ret = ieee80211_subif_start_xmit(skb, dev);
3238 static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3239 u8 *peer, enum nl80211_tdls_operation oper)
3241 struct sta_info *sta;
3242 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3244 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3247 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3250 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
3253 case NL80211_TDLS_ENABLE_LINK:
3255 sta = sta_info_get(sdata, peer);
3261 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
3264 case NL80211_TDLS_DISABLE_LINK:
3265 return sta_info_destroy_addr(sdata, peer);
3266 case NL80211_TDLS_TEARDOWN:
3267 case NL80211_TDLS_SETUP:
3268 case NL80211_TDLS_DISCOVERY_REQ:
3269 /* We don't support in-driver setup/teardown/discovery */
3278 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3279 const u8 *peer, u64 *cookie)
3281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3282 struct ieee80211_local *local = sdata->local;
3283 struct ieee80211_qos_hdr *nullfunc;
3284 struct sk_buff *skb;
3285 int size = sizeof(*nullfunc);
3288 struct ieee80211_tx_info *info;
3289 struct sta_info *sta;
3290 struct ieee80211_chanctx_conf *chanctx_conf;
3291 enum ieee80211_band band;
3294 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3295 if (WARN_ON(!chanctx_conf)) {
3299 band = chanctx_conf->def.chan->band;
3300 sta = sta_info_get(sdata, peer);
3302 qos = test_sta_flag(sta, WLAN_STA_WME);
3309 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3310 IEEE80211_STYPE_QOS_NULLFUNC |
3311 IEEE80211_FCTL_FROMDS);
3314 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3315 IEEE80211_STYPE_NULLFUNC |
3316 IEEE80211_FCTL_FROMDS);
3319 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3327 skb_reserve(skb, local->hw.extra_tx_headroom);
3329 nullfunc = (void *) skb_put(skb, size);
3330 nullfunc->frame_control = fc;
3331 nullfunc->duration_id = 0;
3332 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3333 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3334 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3335 nullfunc->seq_ctrl = 0;
3337 info = IEEE80211_SKB_CB(skb);
3339 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3340 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3342 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3345 nullfunc->qos_ctrl = cpu_to_le16(7);
3348 ieee80211_xmit(sdata, skb, band);
3352 *cookie = (unsigned long) skb;
3356 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3357 struct wireless_dev *wdev,
3358 struct cfg80211_chan_def *chandef)
3360 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3361 struct ieee80211_local *local = wiphy_priv(wiphy);
3362 struct ieee80211_chanctx_conf *chanctx_conf;
3366 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3368 *chandef = chanctx_conf->def;
3370 } else if (local->open_count > 0 &&
3371 local->open_count == local->monitors &&
3372 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3373 if (local->use_chanctx)
3374 *chandef = local->monitor_chandef;
3376 cfg80211_chandef_create(chandef,
3377 local->_oper_channel,
3378 local->_oper_channel_type);
3387 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3389 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3393 struct cfg80211_ops mac80211_config_ops = {
3394 .add_virtual_intf = ieee80211_add_iface,
3395 .del_virtual_intf = ieee80211_del_iface,
3396 .change_virtual_intf = ieee80211_change_iface,
3397 .start_p2p_device = ieee80211_start_p2p_device,
3398 .stop_p2p_device = ieee80211_stop_p2p_device,
3399 .add_key = ieee80211_add_key,
3400 .del_key = ieee80211_del_key,
3401 .get_key = ieee80211_get_key,
3402 .set_default_key = ieee80211_config_default_key,
3403 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3404 .start_ap = ieee80211_start_ap,
3405 .change_beacon = ieee80211_change_beacon,
3406 .stop_ap = ieee80211_stop_ap,
3407 .add_station = ieee80211_add_station,
3408 .del_station = ieee80211_del_station,
3409 .change_station = ieee80211_change_station,
3410 .get_station = ieee80211_get_station,
3411 .dump_station = ieee80211_dump_station,
3412 .dump_survey = ieee80211_dump_survey,
3413 #ifdef CONFIG_MAC80211_MESH
3414 .add_mpath = ieee80211_add_mpath,
3415 .del_mpath = ieee80211_del_mpath,
3416 .change_mpath = ieee80211_change_mpath,
3417 .get_mpath = ieee80211_get_mpath,
3418 .dump_mpath = ieee80211_dump_mpath,
3419 .update_mesh_config = ieee80211_update_mesh_config,
3420 .get_mesh_config = ieee80211_get_mesh_config,
3421 .join_mesh = ieee80211_join_mesh,
3422 .leave_mesh = ieee80211_leave_mesh,
3424 .change_bss = ieee80211_change_bss,
3425 .set_txq_params = ieee80211_set_txq_params,
3426 .set_monitor_channel = ieee80211_set_monitor_channel,
3427 .suspend = ieee80211_suspend,
3428 .resume = ieee80211_resume,
3429 .scan = ieee80211_scan,
3430 .sched_scan_start = ieee80211_sched_scan_start,
3431 .sched_scan_stop = ieee80211_sched_scan_stop,
3432 .auth = ieee80211_auth,
3433 .assoc = ieee80211_assoc,
3434 .deauth = ieee80211_deauth,
3435 .disassoc = ieee80211_disassoc,
3436 .join_ibss = ieee80211_join_ibss,
3437 .leave_ibss = ieee80211_leave_ibss,
3438 .set_mcast_rate = ieee80211_set_mcast_rate,
3439 .set_wiphy_params = ieee80211_set_wiphy_params,
3440 .set_tx_power = ieee80211_set_tx_power,
3441 .get_tx_power = ieee80211_get_tx_power,
3442 .set_wds_peer = ieee80211_set_wds_peer,
3443 .rfkill_poll = ieee80211_rfkill_poll,
3444 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3445 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3446 .set_power_mgmt = ieee80211_set_power_mgmt,
3447 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3448 .remain_on_channel = ieee80211_remain_on_channel,
3449 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3450 .mgmt_tx = ieee80211_mgmt_tx,
3451 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3452 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3453 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3454 .set_antenna = ieee80211_set_antenna,
3455 .get_antenna = ieee80211_get_antenna,
3456 .set_ringparam = ieee80211_set_ringparam,
3457 .get_ringparam = ieee80211_get_ringparam,
3458 .set_rekey_data = ieee80211_set_rekey_data,
3459 .tdls_oper = ieee80211_tdls_oper,
3460 .tdls_mgmt = ieee80211_tdls_mgmt,
3461 .probe_client = ieee80211_probe_client,
3462 .set_noack_map = ieee80211_set_noack_map,
3464 .set_wakeup = ieee80211_set_wakeup,
3466 .get_et_sset_count = ieee80211_get_et_sset_count,
3467 .get_et_stats = ieee80211_get_et_stats,
3468 .get_et_strings = ieee80211_get_et_strings,
3469 .get_channel = ieee80211_cfg_get_channel,
3470 .start_radar_detection = ieee80211_start_radar_detection,