aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/Kconfig2
-rw-r--r--net/mac80211/Makefile1
-rw-r--r--net/mac80211/aes_cmac.c18
-rw-r--r--net/mac80211/cfg.c398
-rw-r--r--net/mac80211/chan.c457
-rw-r--r--net/mac80211/debugfs.h6
-rw-r--r--net/mac80211/debugfs_netdev.c76
-rw-r--r--net/mac80211/driver-ops.h100
-rw-r--r--net/mac80211/ibss.c98
-rw-r--r--net/mac80211/ieee80211_i.h190
-rw-r--r--net/mac80211/iface.c99
-rw-r--r--net/mac80211/main.c136
-rw-r--r--net/mac80211/mesh.c52
-rw-r--r--net/mac80211/mesh.h4
-rw-r--r--net/mac80211/mesh_plink.c14
-rw-r--r--net/mac80211/mesh_sync.c55
-rw-r--r--net/mac80211/mlme.c361
-rw-r--r--net/mac80211/offchannel.c16
-rw-r--r--net/mac80211/pm.c6
-rw-r--r--net/mac80211/rate.h12
-rw-r--r--net/mac80211/rx.c147
-rw-r--r--net/mac80211/scan.c31
-rw-r--r--net/mac80211/sta_info.c74
-rw-r--r--net/mac80211/status.c169
-rw-r--r--net/mac80211/trace.h222
-rw-r--r--net/mac80211/tx.c291
-rw-r--r--net/mac80211/util.c230
-rw-r--r--net/mac80211/vht.c35
-rw-r--r--net/mac80211/wpa.c14
29 files changed, 2268 insertions, 1046 deletions
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index 63af25458fda..b4ecf267a34b 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -248,7 +248,7 @@ config MAC80211_MHWMP_DEBUG
248 Do not select this option. 248 Do not select this option.
249 249
250config MAC80211_MESH_SYNC_DEBUG 250config MAC80211_MESH_SYNC_DEBUG
251 bool "Verbose mesh mesh synchronization debugging" 251 bool "Verbose mesh synchronization debugging"
252 depends on MAC80211_DEBUG_MENU 252 depends on MAC80211_DEBUG_MENU
253 depends on MAC80211_MESH 253 depends on MAC80211_MESH
254 ---help--- 254 ---help---
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index a7dd110faafa..4911202334d9 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -8,6 +8,7 @@ mac80211-y := \
8 wpa.o \ 8 wpa.o \
9 scan.o offchannel.o \ 9 scan.o offchannel.o \
10 ht.o agg-tx.o agg-rx.o \ 10 ht.o agg-tx.o agg-rx.o \
11 vht.o \
11 ibss.o \ 12 ibss.o \
12 iface.o \ 13 iface.o \
13 rate.o \ 14 rate.o \
diff --git a/net/mac80211/aes_cmac.c b/net/mac80211/aes_cmac.c
index a04752e91023..537488cbf941 100644
--- a/net/mac80211/aes_cmac.c
+++ b/net/mac80211/aes_cmac.c
@@ -10,6 +10,7 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/crypto.h> 12#include <linux/crypto.h>
13#include <linux/export.h>
13#include <linux/err.h> 14#include <linux/err.h>
14#include <crypto/aes.h> 15#include <crypto/aes.h>
15 16
@@ -126,3 +127,20 @@ void ieee80211_aes_cmac_key_free(struct crypto_cipher *tfm)
126{ 127{
127 crypto_free_cipher(tfm); 128 crypto_free_cipher(tfm);
128} 129}
130
131void ieee80211_aes_cmac_calculate_k1_k2(struct ieee80211_key_conf *keyconf,
132 u8 *k1, u8 *k2)
133{
134 u8 l[AES_BLOCK_SIZE] = {};
135 struct ieee80211_key *key =
136 container_of(keyconf, struct ieee80211_key, conf);
137
138 crypto_cipher_encrypt_one(key->u.aes_cmac.tfm, l, l);
139
140 memcpy(k1, l, AES_BLOCK_SIZE);
141 gf_mulx(k1);
142
143 memcpy(k2, k1, AES_BLOCK_SIZE);
144 gf_mulx(k2);
145}
146EXPORT_SYMBOL(ieee80211_aes_cmac_calculate_k1_k2);
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 05f3a313db88..c46d4ee1c298 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -372,10 +372,11 @@ static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
372 372
373static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx) 373static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
374{ 374{
375 enum ieee80211_band band = ieee80211_get_sdata_band(sta->sdata);
376
375 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) { 377 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
376 struct ieee80211_supported_band *sband; 378 struct ieee80211_supported_band *sband;
377 sband = sta->local->hw.wiphy->bands[ 379 sband = sta->local->hw.wiphy->bands[band];
378 sta->local->oper_channel->band];
379 rate->legacy = sband->bitrates[idx].bitrate; 380 rate->legacy = sband->bitrates[idx].bitrate;
380 } else 381 } else
381 rate->mcs = idx; 382 rate->mcs = idx;
@@ -532,6 +533,8 @@ static void ieee80211_get_et_stats(struct wiphy *wiphy,
532 u64 *data) 533 u64 *data)
533{ 534{
534 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 535 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
536 struct ieee80211_chanctx_conf *chanctx_conf;
537 struct ieee80211_channel *channel;
535 struct sta_info *sta; 538 struct sta_info *sta;
536 struct ieee80211_local *local = sdata->local; 539 struct ieee80211_local *local = sdata->local;
537 struct station_info sinfo; 540 struct station_info sinfo;
@@ -607,19 +610,26 @@ static void ieee80211_get_et_stats(struct wiphy *wiphy,
607do_survey: 610do_survey:
608 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN; 611 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
609 /* Get survey stats for current channel */ 612 /* Get survey stats for current channel */
610 q = 0; 613 survey.filled = 0;
611 while (true) {
612 survey.filled = 0;
613 if (drv_get_survey(local, q, &survey) != 0) {
614 survey.filled = 0;
615 break;
616 }
617 614
618 if (survey.channel && 615 rcu_read_lock();
619 (local->oper_channel->center_freq == 616 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
620 survey.channel->center_freq)) 617 if (chanctx_conf)
621 break; 618 channel = chanctx_conf->channel;
622 q++; 619 else
620 channel = NULL;
621 rcu_read_unlock();
622
623 if (channel) {
624 q = 0;
625 do {
626 survey.filled = 0;
627 if (drv_get_survey(local, q, &survey) != 0) {
628 survey.filled = 0;
629 break;
630 }
631 q++;
632 } while (channel != survey.channel);
623 } 633 }
624 634
625 if (survey.filled) 635 if (survey.filled)
@@ -724,47 +734,42 @@ static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
724 return ret; 734 return ret;
725} 735}
726 736
727static int ieee80211_set_channel(struct wiphy *wiphy, 737static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
728 struct net_device *netdev, 738 struct ieee80211_channel *chan,
729 struct ieee80211_channel *chan, 739 enum nl80211_channel_type channel_type)
730 enum nl80211_channel_type channel_type)
731{ 740{
732 struct ieee80211_local *local = wiphy_priv(wiphy); 741 struct ieee80211_local *local = wiphy_priv(wiphy);
733 struct ieee80211_sub_if_data *sdata = NULL; 742 struct ieee80211_sub_if_data *sdata;
734 743 int ret = 0;
735 if (netdev)
736 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
737
738 switch (ieee80211_get_channel_mode(local, NULL)) {
739 case CHAN_MODE_HOPPING:
740 return -EBUSY;
741 case CHAN_MODE_FIXED:
742 if (local->oper_channel != chan ||
743 (!sdata && local->_oper_channel_type != channel_type))
744 return -EBUSY;
745 if (!sdata && local->_oper_channel_type == channel_type)
746 return 0;
747 break;
748 case CHAN_MODE_UNDEFINED:
749 break;
750 }
751
752 if (!ieee80211_set_channel_type(local, sdata, channel_type))
753 return -EBUSY;
754 744
755 local->oper_channel = chan; 745 if (local->monitor_channel == chan &&
746 local->monitor_channel_type == channel_type)
747 return 0;
756 748
757 /* auto-detects changes */ 749 mutex_lock(&local->iflist_mtx);
758 ieee80211_hw_config(local, 0); 750 if (local->use_chanctx) {
751 sdata = rcu_dereference_protected(
752 local->monitor_sdata,
753 lockdep_is_held(&local->iflist_mtx));
754 if (sdata) {
755 ieee80211_vif_release_channel(sdata);
756 ret = ieee80211_vif_use_channel(
757 sdata, chan, channel_type,
758 IEEE80211_CHANCTX_EXCLUSIVE);
759 }
760 } else if (local->open_count == local->monitors) {
761 local->_oper_channel = chan;
762 local->_oper_channel_type = channel_type;
763 ieee80211_hw_config(local, 0);
764 }
759 765
760 return 0; 766 if (ret == 0) {
761} 767 local->monitor_channel = chan;
768 local->monitor_channel_type = channel_type;
769 }
770 mutex_unlock(&local->iflist_mtx);
762 771
763static int ieee80211_set_monitor_channel(struct wiphy *wiphy, 772 return ret;
764 struct ieee80211_channel *chan,
765 enum nl80211_channel_type channel_type)
766{
767 return ieee80211_set_channel(wiphy, NULL, chan, channel_type);
768} 773}
769 774
770static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, 775static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
@@ -879,8 +884,13 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
879 if (old) 884 if (old)
880 return -EALREADY; 885 return -EALREADY;
881 886
882 err = ieee80211_set_channel(wiphy, dev, params->channel, 887 /* TODO: make hostapd tell us what it wants */
883 params->channel_type); 888 sdata->smps_mode = IEEE80211_SMPS_OFF;
889 sdata->needed_rx_chains = sdata->local->rx_chains;
890
891 err = ieee80211_vif_use_channel(sdata, params->channel,
892 params->channel_type,
893 IEEE80211_CHANCTX_SHARED);
884 if (err) 894 if (err)
885 return err; 895 return err;
886 896
@@ -912,6 +922,15 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
912 return err; 922 return err;
913 changed |= err; 923 changed |= err;
914 924
925 err = drv_start_ap(sdata->local, sdata);
926 if (err) {
927 old = rtnl_dereference(sdata->u.ap.beacon);
928 if (old)
929 kfree_rcu(old, rcu_head);
930 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
931 return err;
932 }
933
915 ieee80211_bss_info_change_notify(sdata, changed); 934 ieee80211_bss_info_change_notify(sdata, changed);
916 935
917 netif_carrier_on(dev); 936 netif_carrier_on(dev);
@@ -943,26 +962,40 @@ static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
943 962
944static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) 963static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
945{ 964{
946 struct ieee80211_sub_if_data *sdata, *vlan; 965 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
947 struct beacon_data *old; 966 struct ieee80211_sub_if_data *vlan;
948 967 struct ieee80211_local *local = sdata->local;
949 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 968 struct beacon_data *old_beacon;
969 struct probe_resp *old_probe_resp;
950 970
951 old = rtnl_dereference(sdata->u.ap.beacon); 971 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
952 if (!old) 972 if (!old_beacon)
953 return -ENOENT; 973 return -ENOENT;
974 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
954 975
976 /* turn off carrier for this interface and dependent VLANs */
955 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 977 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
956 netif_carrier_off(vlan->dev); 978 netif_carrier_off(vlan->dev);
957 netif_carrier_off(dev); 979 netif_carrier_off(dev);
958 980
981 /* remove beacon and probe response */
959 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); 982 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
983 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
984 kfree_rcu(old_beacon, rcu_head);
985 if (old_probe_resp)
986 kfree_rcu(old_probe_resp, rcu_head);
960 987
961 kfree_rcu(old, rcu_head); 988 sta_info_flush(local, sdata);
962
963 sta_info_flush(sdata->local, sdata);
964 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); 989 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
965 990
991 drv_stop_ap(sdata->local, sdata);
992
993 /* free all potentially still buffered bcast frames */
994 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
995 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
996
997 ieee80211_vif_release_channel(sdata);
998
966 return 0; 999 return 0;
967} 1000}
968 1001
@@ -1019,9 +1052,10 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1019 int i, j; 1052 int i, j;
1020 struct ieee80211_supported_band *sband; 1053 struct ieee80211_supported_band *sband;
1021 struct ieee80211_sub_if_data *sdata = sta->sdata; 1054 struct ieee80211_sub_if_data *sdata = sta->sdata;
1055 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
1022 u32 mask, set; 1056 u32 mask, set;
1023 1057
1024 sband = local->hw.wiphy->bands[local->oper_channel->band]; 1058 sband = local->hw.wiphy->bands[band];
1025 1059
1026 mask = params->sta_flags_mask; 1060 mask = params->sta_flags_mask;
1027 set = params->sta_flags_set; 1061 set = params->sta_flags_set;
@@ -1136,7 +1170,7 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1136 rates |= BIT(j); 1170 rates |= BIT(j);
1137 } 1171 }
1138 } 1172 }
1139 sta->sta.supp_rates[local->oper_channel->band] = rates; 1173 sta->sta.supp_rates[band] = rates;
1140 } 1174 }
1141 1175
1142 if (params->ht_capa) 1176 if (params->ht_capa)
@@ -1144,6 +1178,11 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1144 params->ht_capa, 1178 params->ht_capa,
1145 &sta->sta.ht_cap); 1179 &sta->sta.ht_cap);
1146 1180
1181 if (params->vht_capa)
1182 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1183 params->vht_capa,
1184 &sta->sta.vht_cap);
1185
1147 if (ieee80211_vif_is_mesh(&sdata->vif)) { 1186 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1148#ifdef CONFIG_MAC80211_MESH 1187#ifdef CONFIG_MAC80211_MESH
1149 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED) 1188 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
@@ -1664,8 +1703,13 @@ static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1664 if (err) 1703 if (err)
1665 return err; 1704 return err;
1666 1705
1667 err = ieee80211_set_channel(wiphy, dev, setup->channel, 1706 /* can mesh use other SMPS modes? */
1668 setup->channel_type); 1707 sdata->smps_mode = IEEE80211_SMPS_OFF;
1708 sdata->needed_rx_chains = sdata->local->rx_chains;
1709
1710 err = ieee80211_vif_use_channel(sdata, setup->channel,
1711 setup->channel_type,
1712 IEEE80211_CHANCTX_SHARED);
1669 if (err) 1713 if (err)
1670 return err; 1714 return err;
1671 1715
@@ -1679,6 +1723,7 @@ static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1679 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1723 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1680 1724
1681 ieee80211_stop_mesh(sdata); 1725 ieee80211_stop_mesh(sdata);
1726 ieee80211_vif_release_channel(sdata);
1682 1727
1683 return 0; 1728 return 0;
1684} 1729}
@@ -1688,10 +1733,14 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1688 struct net_device *dev, 1733 struct net_device *dev,
1689 struct bss_parameters *params) 1734 struct bss_parameters *params)
1690{ 1735{
1691 struct ieee80211_sub_if_data *sdata; 1736 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1737 enum ieee80211_band band;
1692 u32 changed = 0; 1738 u32 changed = 0;
1693 1739
1694 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1740 if (!rtnl_dereference(sdata->u.ap.beacon))
1741 return -ENOENT;
1742
1743 band = ieee80211_get_sdata_band(sdata);
1695 1744
1696 if (params->use_cts_prot >= 0) { 1745 if (params->use_cts_prot >= 0) {
1697 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; 1746 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
@@ -1704,7 +1753,7 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1704 } 1753 }
1705 1754
1706 if (!sdata->vif.bss_conf.use_short_slot && 1755 if (!sdata->vif.bss_conf.use_short_slot &&
1707 sdata->local->oper_channel->band == IEEE80211_BAND_5GHZ) { 1756 band == IEEE80211_BAND_5GHZ) {
1708 sdata->vif.bss_conf.use_short_slot = true; 1757 sdata->vif.bss_conf.use_short_slot = true;
1709 changed |= BSS_CHANGED_ERP_SLOT; 1758 changed |= BSS_CHANGED_ERP_SLOT;
1710 } 1759 }
@@ -1718,9 +1767,7 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1718 if (params->basic_rates) { 1767 if (params->basic_rates) {
1719 int i, j; 1768 int i, j;
1720 u32 rates = 0; 1769 u32 rates = 0;
1721 struct ieee80211_local *local = wiphy_priv(wiphy); 1770 struct ieee80211_supported_band *sband = wiphy->bands[band];
1722 struct ieee80211_supported_band *sband =
1723 wiphy->bands[local->oper_channel->band];
1724 1771
1725 for (i = 0; i < params->basic_rates_len; i++) { 1772 for (i = 0; i < params->basic_rates_len; i++) {
1726 int rate = (params->basic_rates[i] & 0x7f) * 5; 1773 int rate = (params->basic_rates[i] & 0x7f) * 5;
@@ -1829,7 +1876,16 @@ static int ieee80211_scan(struct wiphy *wiphy,
1829 * beaconing hasn't been configured yet 1876 * beaconing hasn't been configured yet
1830 */ 1877 */
1831 case NL80211_IFTYPE_AP: 1878 case NL80211_IFTYPE_AP:
1832 if (sdata->u.ap.beacon) 1879 /*
1880 * If the scan has been forced (and the driver supports
1881 * forcing), don't care about being beaconing already.
1882 * This will create problems to the attached stations (e.g. all
1883 * the frames sent while scanning on other channel will be
1884 * lost)
1885 */
1886 if (sdata->u.ap.beacon &&
1887 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1888 !(req->flags & NL80211_SCAN_FLAG_AP)))
1833 return -EOPNOTSUPP; 1889 return -EOPNOTSUPP;
1834 break; 1890 break;
1835 default: 1891 default:
@@ -1872,20 +1928,6 @@ static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1872static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, 1928static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1873 struct cfg80211_assoc_request *req) 1929 struct cfg80211_assoc_request *req)
1874{ 1930{
1875 struct ieee80211_local *local = wiphy_priv(wiphy);
1876 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1877
1878 switch (ieee80211_get_channel_mode(local, sdata)) {
1879 case CHAN_MODE_HOPPING:
1880 return -EBUSY;
1881 case CHAN_MODE_FIXED:
1882 if (local->oper_channel == req->bss->channel)
1883 break;
1884 return -EBUSY;
1885 case CHAN_MODE_UNDEFINED:
1886 break;
1887 }
1888
1889 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); 1931 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1890} 1932}
1891 1933
@@ -1904,30 +1946,22 @@ static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1904static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, 1946static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1905 struct cfg80211_ibss_params *params) 1947 struct cfg80211_ibss_params *params)
1906{ 1948{
1907 struct ieee80211_local *local = wiphy_priv(wiphy); 1949 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
1908 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1909
1910 switch (ieee80211_get_channel_mode(local, sdata)) {
1911 case CHAN_MODE_HOPPING:
1912 return -EBUSY;
1913 case CHAN_MODE_FIXED:
1914 if (!params->channel_fixed)
1915 return -EBUSY;
1916 if (local->oper_channel == params->channel)
1917 break;
1918 return -EBUSY;
1919 case CHAN_MODE_UNDEFINED:
1920 break;
1921 }
1922
1923 return ieee80211_ibss_join(sdata, params);
1924} 1950}
1925 1951
1926static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) 1952static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1927{ 1953{
1954 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
1955}
1956
1957static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
1958 int rate[IEEE80211_NUM_BANDS])
1959{
1928 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1960 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1929 1961
1930 return ieee80211_ibss_leave(sdata); 1962 memcpy(sdata->vif.bss_conf.mcast_rate, rate, sizeof(rate));
1963
1964 return 0;
1931} 1965}
1932 1966
1933static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) 1967static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
@@ -1968,41 +2002,65 @@ static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1968} 2002}
1969 2003
1970static int ieee80211_set_tx_power(struct wiphy *wiphy, 2004static int ieee80211_set_tx_power(struct wiphy *wiphy,
2005 struct wireless_dev *wdev,
1971 enum nl80211_tx_power_setting type, int mbm) 2006 enum nl80211_tx_power_setting type, int mbm)
1972{ 2007{
1973 struct ieee80211_local *local = wiphy_priv(wiphy); 2008 struct ieee80211_local *local = wiphy_priv(wiphy);
1974 struct ieee80211_channel *chan = local->oper_channel; 2009 struct ieee80211_sub_if_data *sdata;
1975 u32 changes = 0; 2010
2011 if (wdev) {
2012 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2013
2014 switch (type) {
2015 case NL80211_TX_POWER_AUTOMATIC:
2016 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2017 break;
2018 case NL80211_TX_POWER_LIMITED:
2019 case NL80211_TX_POWER_FIXED:
2020 if (mbm < 0 || (mbm % 100))
2021 return -EOPNOTSUPP;
2022 sdata->user_power_level = MBM_TO_DBM(mbm);
2023 break;
2024 }
2025
2026 ieee80211_recalc_txpower(sdata);
2027
2028 return 0;
2029 }
1976 2030
1977 switch (type) { 2031 switch (type) {
1978 case NL80211_TX_POWER_AUTOMATIC: 2032 case NL80211_TX_POWER_AUTOMATIC:
1979 local->user_power_level = -1; 2033 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
1980 break; 2034 break;
1981 case NL80211_TX_POWER_LIMITED: 2035 case NL80211_TX_POWER_LIMITED:
1982 if (mbm < 0 || (mbm % 100))
1983 return -EOPNOTSUPP;
1984 local->user_power_level = MBM_TO_DBM(mbm);
1985 break;
1986 case NL80211_TX_POWER_FIXED: 2036 case NL80211_TX_POWER_FIXED:
1987 if (mbm < 0 || (mbm % 100)) 2037 if (mbm < 0 || (mbm % 100))
1988 return -EOPNOTSUPP; 2038 return -EOPNOTSUPP;
1989 /* TODO: move to cfg80211 when it knows the channel */
1990 if (MBM_TO_DBM(mbm) > chan->max_power)
1991 return -EINVAL;
1992 local->user_power_level = MBM_TO_DBM(mbm); 2039 local->user_power_level = MBM_TO_DBM(mbm);
1993 break; 2040 break;
1994 } 2041 }
1995 2042
1996 ieee80211_hw_config(local, changes); 2043 mutex_lock(&local->iflist_mtx);
2044 list_for_each_entry(sdata, &local->interfaces, list)
2045 sdata->user_power_level = local->user_power_level;
2046 list_for_each_entry(sdata, &local->interfaces, list)
2047 ieee80211_recalc_txpower(sdata);
2048 mutex_unlock(&local->iflist_mtx);
1997 2049
1998 return 0; 2050 return 0;
1999} 2051}
2000 2052
2001static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm) 2053static int ieee80211_get_tx_power(struct wiphy *wiphy,
2054 struct wireless_dev *wdev,
2055 int *dbm)
2002{ 2056{
2003 struct ieee80211_local *local = wiphy_priv(wiphy); 2057 struct ieee80211_local *local = wiphy_priv(wiphy);
2058 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2004 2059
2005 *dbm = local->hw.conf.power_level; 2060 if (!local->use_chanctx)
2061 *dbm = local->hw.conf.power_level;
2062 else
2063 *dbm = sdata->vif.bss_conf.txpower;
2006 2064
2007 return 0; 2065 return 0;
2008} 2066}
@@ -2067,13 +2125,12 @@ int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2067 2125
2068 /* 2126 /*
2069 * If not associated, or current association is not an HT 2127 * If not associated, or current association is not an HT
2070 * association, there's no need to send an action frame. 2128 * association, there's no need to do anything, just store
2129 * the new value until we associate.
2071 */ 2130 */
2072 if (!sdata->u.mgd.associated || 2131 if (!sdata->u.mgd.associated ||
2073 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) { 2132 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT)
2074 ieee80211_recalc_smps(sdata->local);
2075 return 0; 2133 return 0;
2076 }
2077 2134
2078 ap = sdata->u.mgd.associated->bssid; 2135 ap = sdata->u.mgd.associated->bssid;
2079 2136
@@ -2189,6 +2246,9 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2189 2246
2190 lockdep_assert_held(&local->mtx); 2247 lockdep_assert_held(&local->mtx);
2191 2248
2249 if (local->use_chanctx && !local->ops->remain_on_channel)
2250 return -EOPNOTSUPP;
2251
2192 roc = kzalloc(sizeof(*roc), GFP_KERNEL); 2252 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2193 if (!roc) 2253 if (!roc)
2194 return -ENOMEM; 2254 return -ENOMEM;
@@ -2332,13 +2392,22 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2332 list_add_tail(&roc->list, &local->roc_list); 2392 list_add_tail(&roc->list, &local->roc_list);
2333 2393
2334 /* 2394 /*
2335 * cookie is either the roc (for normal roc) 2395 * cookie is either the roc cookie (for normal roc)
2336 * or the SKB (for mgmt TX) 2396 * or the SKB (for mgmt TX)
2337 */ 2397 */
2338 if (txskb) 2398 if (!txskb) {
2399 /* local->mtx protects this */
2400 local->roc_cookie_counter++;
2401 roc->cookie = local->roc_cookie_counter;
2402 /* wow, you wrapped 64 bits ... more likely a bug */
2403 if (WARN_ON(roc->cookie == 0)) {
2404 roc->cookie = 1;
2405 local->roc_cookie_counter++;
2406 }
2407 *cookie = roc->cookie;
2408 } else {
2339 *cookie = (unsigned long)txskb; 2409 *cookie = (unsigned long)txskb;
2340 else 2410 }
2341 *cookie = (unsigned long)roc;
2342 2411
2343 return 0; 2412 return 0;
2344} 2413}
@@ -2373,7 +2442,7 @@ static int ieee80211_cancel_roc(struct ieee80211_local *local,
2373 struct ieee80211_roc_work *dep, *tmp2; 2442 struct ieee80211_roc_work *dep, *tmp2;
2374 2443
2375 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) { 2444 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2376 if (!mgmt_tx && (unsigned long)dep != cookie) 2445 if (!mgmt_tx && dep->cookie != cookie)
2377 continue; 2446 continue;
2378 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie) 2447 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2379 continue; 2448 continue;
@@ -2385,7 +2454,7 @@ static int ieee80211_cancel_roc(struct ieee80211_local *local,
2385 return 0; 2454 return 0;
2386 } 2455 }
2387 2456
2388 if (!mgmt_tx && (unsigned long)roc != cookie) 2457 if (!mgmt_tx && roc->cookie != cookie)
2389 continue; 2458 continue;
2390 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie) 2459 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2391 continue; 2460 continue;
@@ -2515,10 +2584,20 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
2515 2584
2516 /* Check if the operating channel is the requested channel */ 2585 /* Check if the operating channel is the requested channel */
2517 if (!need_offchan) { 2586 if (!need_offchan) {
2518 need_offchan = chan != local->oper_channel; 2587 struct ieee80211_chanctx_conf *chanctx_conf;
2519 if (channel_type_valid && 2588
2520 channel_type != local->_oper_channel_type) 2589 rcu_read_lock();
2590 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2591
2592 if (chanctx_conf) {
2593 need_offchan = chan != chanctx_conf->channel;
2594 if (channel_type_valid &&
2595 channel_type != chanctx_conf->channel_type)
2596 need_offchan = true;
2597 } else {
2521 need_offchan = true; 2598 need_offchan = true;
2599 }
2600 rcu_read_unlock();
2522 } 2601 }
2523 2602
2524 if (need_offchan && !offchan) { 2603 if (need_offchan && !offchan) {
@@ -2594,6 +2673,9 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2594 else 2673 else
2595 local->probe_req_reg--; 2674 local->probe_req_reg--;
2596 2675
2676 if (!local->open_count)
2677 break;
2678
2597 ieee80211_queue_work(&local->hw, &local->reconfig_filter); 2679 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2598 break; 2680 break;
2599 default: 2681 default:
@@ -2667,7 +2749,7 @@ static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2667 u16 capab; 2749 u16 capab;
2668 2750
2669 capab = 0; 2751 capab = 0;
2670 if (local->oper_channel->band != IEEE80211_BAND_2GHZ) 2752 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
2671 return capab; 2753 return capab;
2672 2754
2673 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) 2755 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
@@ -2699,7 +2781,7 @@ ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2699 u16 status_code, struct sk_buff *skb) 2781 u16 status_code, struct sk_buff *skb)
2700{ 2782{
2701 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2783 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2702 struct ieee80211_local *local = sdata->local; 2784 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
2703 struct ieee80211_tdls_data *tf; 2785 struct ieee80211_tdls_data *tf;
2704 2786
2705 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u)); 2787 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
@@ -2719,10 +2801,8 @@ ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2719 tf->u.setup_req.capability = 2801 tf->u.setup_req.capability =
2720 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata)); 2802 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2721 2803
2722 ieee80211_add_srates_ie(sdata, skb, false, 2804 ieee80211_add_srates_ie(sdata, skb, false, band);
2723 local->oper_channel->band); 2805 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
2724 ieee80211_add_ext_srates_ie(sdata, skb, false,
2725 local->oper_channel->band);
2726 ieee80211_tdls_add_ext_capab(skb); 2806 ieee80211_tdls_add_ext_capab(skb);
2727 break; 2807 break;
2728 case WLAN_TDLS_SETUP_RESPONSE: 2808 case WLAN_TDLS_SETUP_RESPONSE:
@@ -2735,10 +2815,8 @@ ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2735 tf->u.setup_resp.capability = 2815 tf->u.setup_resp.capability =
2736 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata)); 2816 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2737 2817
2738 ieee80211_add_srates_ie(sdata, skb, false, 2818 ieee80211_add_srates_ie(sdata, skb, false, band);
2739 local->oper_channel->band); 2819 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
2740 ieee80211_add_ext_srates_ie(sdata, skb, false,
2741 local->oper_channel->band);
2742 ieee80211_tdls_add_ext_capab(skb); 2820 ieee80211_tdls_add_ext_capab(skb);
2743 break; 2821 break;
2744 case WLAN_TDLS_SETUP_CONFIRM: 2822 case WLAN_TDLS_SETUP_CONFIRM:
@@ -2776,7 +2854,7 @@ ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2776 u16 status_code, struct sk_buff *skb) 2854 u16 status_code, struct sk_buff *skb)
2777{ 2855{
2778 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2856 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2779 struct ieee80211_local *local = sdata->local; 2857 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
2780 struct ieee80211_mgmt *mgmt; 2858 struct ieee80211_mgmt *mgmt;
2781 2859
2782 mgmt = (void *)skb_put(skb, 24); 2860 mgmt = (void *)skb_put(skb, 24);
@@ -2799,10 +2877,8 @@ ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2799 mgmt->u.action.u.tdls_discover_resp.capability = 2877 mgmt->u.action.u.tdls_discover_resp.capability =
2800 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata)); 2878 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2801 2879
2802 ieee80211_add_srates_ie(sdata, skb, false, 2880 ieee80211_add_srates_ie(sdata, skb, false, band);
2803 local->oper_channel->band); 2881 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
2804 ieee80211_add_ext_srates_ie(sdata, skb, false,
2805 local->oper_channel->band);
2806 ieee80211_tdls_add_ext_capab(skb); 2882 ieee80211_tdls_add_ext_capab(skb);
2807 break; 2883 break;
2808 default: 2884 default:
@@ -2819,7 +2895,6 @@ static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2819{ 2895{
2820 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2896 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2821 struct ieee80211_local *local = sdata->local; 2897 struct ieee80211_local *local = sdata->local;
2822 struct ieee80211_tx_info *info;
2823 struct sk_buff *skb = NULL; 2898 struct sk_buff *skb = NULL;
2824 bool send_direct; 2899 bool send_direct;
2825 int ret; 2900 int ret;
@@ -2845,7 +2920,6 @@ static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2845 if (!skb) 2920 if (!skb)
2846 return -ENOMEM; 2921 return -ENOMEM;
2847 2922
2848 info = IEEE80211_SKB_CB(skb);
2849 skb_reserve(skb, local->hw.extra_tx_headroom); 2923 skb_reserve(skb, local->hw.extra_tx_headroom);
2850 2924
2851 switch (action_code) { 2925 switch (action_code) {
@@ -2982,12 +3056,19 @@ static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2982 bool qos; 3056 bool qos;
2983 struct ieee80211_tx_info *info; 3057 struct ieee80211_tx_info *info;
2984 struct sta_info *sta; 3058 struct sta_info *sta;
3059 struct ieee80211_chanctx_conf *chanctx_conf;
3060 enum ieee80211_band band;
2985 3061
2986 rcu_read_lock(); 3062 rcu_read_lock();
3063 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3064 if (WARN_ON(!chanctx_conf)) {
3065 rcu_read_unlock();
3066 return -EINVAL;
3067 }
3068 band = chanctx_conf->channel->band;
2987 sta = sta_info_get(sdata, peer); 3069 sta = sta_info_get(sdata, peer);
2988 if (sta) { 3070 if (sta) {
2989 qos = test_sta_flag(sta, WLAN_STA_WME); 3071 qos = test_sta_flag(sta, WLAN_STA_WME);
2990 rcu_read_unlock();
2991 } else { 3072 } else {
2992 rcu_read_unlock(); 3073 rcu_read_unlock();
2993 return -ENOLINK; 3074 return -ENOLINK;
@@ -3005,8 +3086,10 @@ static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3005 } 3086 }
3006 3087
3007 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); 3088 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3008 if (!skb) 3089 if (!skb) {
3090 rcu_read_unlock();
3009 return -ENOMEM; 3091 return -ENOMEM;
3092 }
3010 3093
3011 skb->dev = dev; 3094 skb->dev = dev;
3012 3095
@@ -3031,8 +3114,9 @@ static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3031 nullfunc->qos_ctrl = cpu_to_le16(7); 3114 nullfunc->qos_ctrl = cpu_to_le16(7);
3032 3115
3033 local_bh_disable(); 3116 local_bh_disable();
3034 ieee80211_xmit(sdata, skb); 3117 ieee80211_xmit(sdata, skb, band);
3035 local_bh_enable(); 3118 local_bh_enable();
3119 rcu_read_unlock();
3036 3120
3037 *cookie = (unsigned long) skb; 3121 *cookie = (unsigned long) skb;
3038 return 0; 3122 return 0;
@@ -3042,10 +3126,19 @@ static struct ieee80211_channel *
3042ieee80211_cfg_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev, 3126ieee80211_cfg_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
3043 enum nl80211_channel_type *type) 3127 enum nl80211_channel_type *type)
3044{ 3128{
3045 struct ieee80211_local *local = wiphy_priv(wiphy); 3129 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3130 struct ieee80211_chanctx_conf *chanctx_conf;
3131 struct ieee80211_channel *chan = NULL;
3132
3133 rcu_read_lock();
3134 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3135 if (chanctx_conf) {
3136 *type = chanctx_conf->channel_type;
3137 chan = chanctx_conf->channel;
3138 }
3139 rcu_read_unlock();
3046 3140
3047 *type = local->_oper_channel_type; 3141 return chan;
3048 return local->oper_channel;
3049} 3142}
3050 3143
3051#ifdef CONFIG_PM 3144#ifdef CONFIG_PM
@@ -3100,6 +3193,7 @@ struct cfg80211_ops mac80211_config_ops = {
3100 .disassoc = ieee80211_disassoc, 3193 .disassoc = ieee80211_disassoc,
3101 .join_ibss = ieee80211_join_ibss, 3194 .join_ibss = ieee80211_join_ibss,
3102 .leave_ibss = ieee80211_leave_ibss, 3195 .leave_ibss = ieee80211_leave_ibss,
3196 .set_mcast_rate = ieee80211_set_mcast_rate,
3103 .set_wiphy_params = ieee80211_set_wiphy_params, 3197 .set_wiphy_params = ieee80211_set_wiphy_params,
3104 .set_tx_power = ieee80211_set_tx_power, 3198 .set_tx_power = ieee80211_set_tx_power,
3105 .get_tx_power = ieee80211_get_tx_power, 3199 .get_tx_power = ieee80211_get_tx_power,
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index 0bfc914ddd15..a2b06d40aebf 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -3,108 +3,10 @@
3 */ 3 */
4 4
5#include <linux/nl80211.h> 5#include <linux/nl80211.h>
6#include <linux/export.h>
6#include <net/cfg80211.h> 7#include <net/cfg80211.h>
7#include "ieee80211_i.h" 8#include "ieee80211_i.h"
8 9#include "driver-ops.h"
9static enum ieee80211_chan_mode
10__ieee80211_get_channel_mode(struct ieee80211_local *local,
11 struct ieee80211_sub_if_data *ignore)
12{
13 struct ieee80211_sub_if_data *sdata;
14
15 lockdep_assert_held(&local->iflist_mtx);
16
17 list_for_each_entry(sdata, &local->interfaces, list) {
18 if (sdata == ignore)
19 continue;
20
21 if (!ieee80211_sdata_running(sdata))
22 continue;
23
24 switch (sdata->vif.type) {
25 case NL80211_IFTYPE_MONITOR:
26 continue;
27 case NL80211_IFTYPE_STATION:
28 if (!sdata->u.mgd.associated)
29 continue;
30 break;
31 case NL80211_IFTYPE_ADHOC:
32 if (!sdata->u.ibss.ssid_len)
33 continue;
34 if (!sdata->u.ibss.fixed_channel)
35 return CHAN_MODE_HOPPING;
36 break;
37 case NL80211_IFTYPE_AP_VLAN:
38 /* will also have _AP interface */
39 continue;
40 case NL80211_IFTYPE_AP:
41 if (!sdata->u.ap.beacon)
42 continue;
43 break;
44 case NL80211_IFTYPE_MESH_POINT:
45 if (!sdata->wdev.mesh_id_len)
46 continue;
47 break;
48 default:
49 break;
50 }
51
52 return CHAN_MODE_FIXED;
53 }
54
55 return CHAN_MODE_UNDEFINED;
56}
57
58enum ieee80211_chan_mode
59ieee80211_get_channel_mode(struct ieee80211_local *local,
60 struct ieee80211_sub_if_data *ignore)
61{
62 enum ieee80211_chan_mode mode;
63
64 mutex_lock(&local->iflist_mtx);
65 mode = __ieee80211_get_channel_mode(local, ignore);
66 mutex_unlock(&local->iflist_mtx);
67
68 return mode;
69}
70
71static enum nl80211_channel_type
72ieee80211_get_superchan(struct ieee80211_local *local,
73 struct ieee80211_sub_if_data *sdata)
74{
75 enum nl80211_channel_type superchan = NL80211_CHAN_NO_HT;
76 struct ieee80211_sub_if_data *tmp;
77
78 mutex_lock(&local->iflist_mtx);
79 list_for_each_entry(tmp, &local->interfaces, list) {
80 if (tmp == sdata)
81 continue;
82
83 if (!ieee80211_sdata_running(tmp))
84 continue;
85
86 switch (tmp->vif.bss_conf.channel_type) {
87 case NL80211_CHAN_NO_HT:
88 case NL80211_CHAN_HT20:
89 if (superchan > tmp->vif.bss_conf.channel_type)
90 break;
91
92 superchan = tmp->vif.bss_conf.channel_type;
93 break;
94 case NL80211_CHAN_HT40PLUS:
95 WARN_ON(superchan == NL80211_CHAN_HT40MINUS);
96 superchan = NL80211_CHAN_HT40PLUS;
97 break;
98 case NL80211_CHAN_HT40MINUS:
99 WARN_ON(superchan == NL80211_CHAN_HT40PLUS);
100 superchan = NL80211_CHAN_HT40MINUS;
101 break;
102 }
103 }
104 mutex_unlock(&local->iflist_mtx);
105
106 return superchan;
107}
108 10
109static bool 11static bool
110ieee80211_channel_types_are_compatible(enum nl80211_channel_type chantype1, 12ieee80211_channel_types_are_compatible(enum nl80211_channel_type chantype1,
@@ -148,23 +50,352 @@ ieee80211_channel_types_are_compatible(enum nl80211_channel_type chantype1,
148 return true; 50 return true;
149} 51}
150 52
151bool ieee80211_set_channel_type(struct ieee80211_local *local, 53static void ieee80211_change_chantype(struct ieee80211_local *local,
152 struct ieee80211_sub_if_data *sdata, 54 struct ieee80211_chanctx *ctx,
153 enum nl80211_channel_type chantype) 55 enum nl80211_channel_type chantype)
154{ 56{
155 enum nl80211_channel_type superchan; 57 if (chantype == ctx->conf.channel_type)
156 enum nl80211_channel_type compatchan; 58 return;
157 59
158 superchan = ieee80211_get_superchan(local, sdata); 60 ctx->conf.channel_type = chantype;
159 if (!ieee80211_channel_types_are_compatible(superchan, chantype, 61 drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_CHANNEL_TYPE);
160 &compatchan))
161 return false;
162 62
163 local->_oper_channel_type = compatchan; 63 if (!local->use_chanctx) {
64 local->_oper_channel_type = chantype;
65 ieee80211_hw_config(local, 0);
66 }
67}
164 68
165 if (sdata) 69static struct ieee80211_chanctx *
166 sdata->vif.bss_conf.channel_type = chantype; 70ieee80211_find_chanctx(struct ieee80211_local *local,
71 struct ieee80211_channel *channel,
72 enum nl80211_channel_type channel_type,
73 enum ieee80211_chanctx_mode mode)
74{
75 struct ieee80211_chanctx *ctx;
76 enum nl80211_channel_type compat_type;
167 77
168 return true; 78 lockdep_assert_held(&local->chanctx_mtx);
79
80 if (mode == IEEE80211_CHANCTX_EXCLUSIVE)
81 return NULL;
82 if (WARN_ON(!channel))
83 return NULL;
84
85 list_for_each_entry(ctx, &local->chanctx_list, list) {
86 compat_type = ctx->conf.channel_type;
87
88 if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE)
89 continue;
90 if (ctx->conf.channel != channel)
91 continue;
92 if (!ieee80211_channel_types_are_compatible(ctx->conf.channel_type,
93 channel_type,
94 &compat_type))
95 continue;
96
97 ieee80211_change_chantype(local, ctx, compat_type);
98
99 return ctx;
100 }
101
102 return NULL;
103}
104
105static struct ieee80211_chanctx *
106ieee80211_new_chanctx(struct ieee80211_local *local,
107 struct ieee80211_channel *channel,
108 enum nl80211_channel_type channel_type,
109 enum ieee80211_chanctx_mode mode)
110{
111 struct ieee80211_chanctx *ctx;
112 int err;
113
114 lockdep_assert_held(&local->chanctx_mtx);
115
116 ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL);
117 if (!ctx)
118 return ERR_PTR(-ENOMEM);
119
120 ctx->conf.channel = channel;
121 ctx->conf.channel_type = channel_type;
122 ctx->conf.rx_chains_static = 1;
123 ctx->conf.rx_chains_dynamic = 1;
124 ctx->mode = mode;
125
126 if (!local->use_chanctx) {
127 local->_oper_channel_type = channel_type;
128 local->_oper_channel = channel;
129 ieee80211_hw_config(local, 0);
130 } else {
131 err = drv_add_chanctx(local, ctx);
132 if (err) {
133 kfree(ctx);
134 return ERR_PTR(err);
135 }
136 }
137
138 list_add_rcu(&ctx->list, &local->chanctx_list);
139
140 return ctx;
141}
142
143static void ieee80211_free_chanctx(struct ieee80211_local *local,
144 struct ieee80211_chanctx *ctx)
145{
146 lockdep_assert_held(&local->chanctx_mtx);
147
148 WARN_ON_ONCE(ctx->refcount != 0);
149
150 if (!local->use_chanctx) {
151 local->_oper_channel_type = NL80211_CHAN_NO_HT;
152 ieee80211_hw_config(local, 0);
153 } else {
154 drv_remove_chanctx(local, ctx);
155 }
156
157 list_del_rcu(&ctx->list);
158 kfree_rcu(ctx, rcu_head);
159}
160
161static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata,
162 struct ieee80211_chanctx *ctx)
163{
164 struct ieee80211_local *local = sdata->local;
165 int ret;
166
167 lockdep_assert_held(&local->chanctx_mtx);
168
169 ret = drv_assign_vif_chanctx(local, sdata, ctx);
170 if (ret)
171 return ret;
172
173 rcu_assign_pointer(sdata->vif.chanctx_conf, &ctx->conf);
174 ctx->refcount++;
175
176 ieee80211_recalc_txpower(sdata);
177
178 return 0;
179}
180
181static enum nl80211_channel_type
182ieee80211_calc_chantype(struct ieee80211_local *local,
183 struct ieee80211_chanctx *ctx)
184{
185 struct ieee80211_chanctx_conf *conf = &ctx->conf;
186 struct ieee80211_sub_if_data *sdata;
187 enum nl80211_channel_type result = NL80211_CHAN_NO_HT;
188
189 lockdep_assert_held(&local->chanctx_mtx);
190
191 rcu_read_lock();
192 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
193 if (!ieee80211_sdata_running(sdata))
194 continue;
195 if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf)
196 continue;
197
198 WARN_ON_ONCE(!ieee80211_channel_types_are_compatible(
199 sdata->vif.bss_conf.channel_type,
200 result, &result));
201 }
202 rcu_read_unlock();
203
204 return result;
205}
206
207static void ieee80211_recalc_chanctx_chantype(struct ieee80211_local *local,
208 struct ieee80211_chanctx *ctx)
209{
210 enum nl80211_channel_type chantype;
211
212 lockdep_assert_held(&local->chanctx_mtx);
213
214 chantype = ieee80211_calc_chantype(local, ctx);
215 ieee80211_change_chantype(local, ctx, chantype);
216}
217
218static void ieee80211_unassign_vif_chanctx(struct ieee80211_sub_if_data *sdata,
219 struct ieee80211_chanctx *ctx)
220{
221 struct ieee80211_local *local = sdata->local;
222
223 lockdep_assert_held(&local->chanctx_mtx);
224
225 ctx->refcount--;
226 rcu_assign_pointer(sdata->vif.chanctx_conf, NULL);
227
228 drv_unassign_vif_chanctx(local, sdata, ctx);
229
230 if (ctx->refcount > 0) {
231 ieee80211_recalc_chanctx_chantype(sdata->local, ctx);
232 ieee80211_recalc_smps_chanctx(local, ctx);
233 }
234}
235
236static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
237{
238 struct ieee80211_local *local = sdata->local;
239 struct ieee80211_chanctx_conf *conf;
240 struct ieee80211_chanctx *ctx;
241
242 lockdep_assert_held(&local->chanctx_mtx);
243
244 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
245 lockdep_is_held(&local->chanctx_mtx));
246 if (!conf)
247 return;
248
249 ctx = container_of(conf, struct ieee80211_chanctx, conf);
250
251 ieee80211_unassign_vif_chanctx(sdata, ctx);
252 if (ctx->refcount == 0)
253 ieee80211_free_chanctx(local, ctx);
254}
255
256void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
257 struct ieee80211_chanctx *chanctx)
258{
259 struct ieee80211_sub_if_data *sdata;
260 u8 rx_chains_static, rx_chains_dynamic;
261
262 lockdep_assert_held(&local->chanctx_mtx);
263
264 rx_chains_static = 1;
265 rx_chains_dynamic = 1;
266
267 rcu_read_lock();
268 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
269 u8 needed_static, needed_dynamic;
270
271 if (!ieee80211_sdata_running(sdata))
272 continue;
273
274 if (rcu_access_pointer(sdata->vif.chanctx_conf) !=
275 &chanctx->conf)
276 continue;
277
278 switch (sdata->vif.type) {
279 case NL80211_IFTYPE_P2P_DEVICE:
280 continue;
281 case NL80211_IFTYPE_STATION:
282 if (!sdata->u.mgd.associated)
283 continue;
284 break;
285 case NL80211_IFTYPE_AP_VLAN:
286 continue;
287 case NL80211_IFTYPE_AP:
288 case NL80211_IFTYPE_ADHOC:
289 case NL80211_IFTYPE_WDS:
290 case NL80211_IFTYPE_MESH_POINT:
291 break;
292 default:
293 WARN_ON_ONCE(1);
294 }
295
296 switch (sdata->smps_mode) {
297 default:
298 WARN_ONCE(1, "Invalid SMPS mode %d\n",
299 sdata->smps_mode);
300 /* fall through */
301 case IEEE80211_SMPS_OFF:
302 needed_static = sdata->needed_rx_chains;
303 needed_dynamic = sdata->needed_rx_chains;
304 break;
305 case IEEE80211_SMPS_DYNAMIC:
306 needed_static = 1;
307 needed_dynamic = sdata->needed_rx_chains;
308 break;
309 case IEEE80211_SMPS_STATIC:
310 needed_static = 1;
311 needed_dynamic = 1;
312 break;
313 }
314
315 rx_chains_static = max(rx_chains_static, needed_static);
316 rx_chains_dynamic = max(rx_chains_dynamic, needed_dynamic);
317 }
318 rcu_read_unlock();
319
320 if (!local->use_chanctx) {
321 if (rx_chains_static > 1)
322 local->smps_mode = IEEE80211_SMPS_OFF;
323 else if (rx_chains_dynamic > 1)
324 local->smps_mode = IEEE80211_SMPS_DYNAMIC;
325 else
326 local->smps_mode = IEEE80211_SMPS_STATIC;
327 ieee80211_hw_config(local, 0);
328 }
329
330 if (rx_chains_static == chanctx->conf.rx_chains_static &&
331 rx_chains_dynamic == chanctx->conf.rx_chains_dynamic)
332 return;
333
334 chanctx->conf.rx_chains_static = rx_chains_static;
335 chanctx->conf.rx_chains_dynamic = rx_chains_dynamic;
336 drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RX_CHAINS);
337}
338
339int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
340 struct ieee80211_channel *channel,
341 enum nl80211_channel_type channel_type,
342 enum ieee80211_chanctx_mode mode)
343{
344 struct ieee80211_local *local = sdata->local;
345 struct ieee80211_chanctx *ctx;
346 int ret;
347
348 WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev));
349
350 mutex_lock(&local->chanctx_mtx);
351 __ieee80211_vif_release_channel(sdata);
352
353 ctx = ieee80211_find_chanctx(local, channel, channel_type, mode);
354 if (!ctx)
355 ctx = ieee80211_new_chanctx(local, channel, channel_type, mode);
356 if (IS_ERR(ctx)) {
357 ret = PTR_ERR(ctx);
358 goto out;
359 }
360
361 sdata->vif.bss_conf.channel_type = channel_type;
362
363 ret = ieee80211_assign_vif_chanctx(sdata, ctx);
364 if (ret) {
365 /* if assign fails refcount stays the same */
366 if (ctx->refcount == 0)
367 ieee80211_free_chanctx(local, ctx);
368 goto out;
369 }
370
371 ieee80211_recalc_smps_chanctx(local, ctx);
372 out:
373 mutex_unlock(&local->chanctx_mtx);
374 return ret;
375}
376
377void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
378{
379 WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev));
380
381 mutex_lock(&sdata->local->chanctx_mtx);
382 __ieee80211_vif_release_channel(sdata);
383 mutex_unlock(&sdata->local->chanctx_mtx);
384}
385
386void ieee80211_iter_chan_contexts_atomic(
387 struct ieee80211_hw *hw,
388 void (*iter)(struct ieee80211_hw *hw,
389 struct ieee80211_chanctx_conf *chanctx_conf,
390 void *data),
391 void *iter_data)
392{
393 struct ieee80211_local *local = hw_to_local(hw);
394 struct ieee80211_chanctx *ctx;
169 395
396 rcu_read_lock();
397 list_for_each_entry_rcu(ctx, &local->chanctx_list, list)
398 iter(hw, &ctx->conf, iter_data);
399 rcu_read_unlock();
170} 400}
401EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic);
diff --git a/net/mac80211/debugfs.h b/net/mac80211/debugfs.h
index 9be4e6d71d00..214ed4ecd739 100644
--- a/net/mac80211/debugfs.h
+++ b/net/mac80211/debugfs.h
@@ -2,9 +2,9 @@
2#define __MAC80211_DEBUGFS_H 2#define __MAC80211_DEBUGFS_H
3 3
4#ifdef CONFIG_MAC80211_DEBUGFS 4#ifdef CONFIG_MAC80211_DEBUGFS
5extern void debugfs_hw_add(struct ieee80211_local *local); 5void debugfs_hw_add(struct ieee80211_local *local);
6extern int mac80211_format_buffer(char __user *userbuf, size_t count, 6int __printf(4, 5) mac80211_format_buffer(char __user *userbuf, size_t count,
7 loff_t *ppos, char *fmt, ...); 7 loff_t *ppos, char *fmt, ...);
8#else 8#else
9static inline void debugfs_hw_add(struct ieee80211_local *local) 9static inline void debugfs_hw_add(struct ieee80211_local *local)
10{ 10{
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 6d5aec9418ee..ba9bd0ef119a 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -10,6 +10,7 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/if.h> 12#include <linux/if.h>
13#include <linux/if_ether.h>
13#include <linux/interrupt.h> 14#include <linux/interrupt.h>
14#include <linux/netdevice.h> 15#include <linux/netdevice.h>
15#include <linux/rtnetlink.h> 16#include <linux/rtnetlink.h>
@@ -168,6 +169,29 @@ IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
168IEEE80211_IF_FILE(flags, flags, HEX); 169IEEE80211_IF_FILE(flags, flags, HEX);
169IEEE80211_IF_FILE(state, state, LHEX); 170IEEE80211_IF_FILE(state, state, LHEX);
170IEEE80211_IF_FILE(channel_type, vif.bss_conf.channel_type, DEC); 171IEEE80211_IF_FILE(channel_type, vif.bss_conf.channel_type, DEC);
172IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC);
173IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC);
174IEEE80211_IF_FILE(user_power_level, user_power_level, DEC);
175
176static ssize_t
177ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata,
178 char *buf, int buflen)
179{
180 int len;
181
182 len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n",
183 sdata->vif.hw_queue[IEEE80211_AC_VO],
184 sdata->vif.hw_queue[IEEE80211_AC_VI],
185 sdata->vif.hw_queue[IEEE80211_AC_BE],
186 sdata->vif.hw_queue[IEEE80211_AC_BK]);
187
188 if (sdata->vif.type == NL80211_IFTYPE_AP)
189 len += scnprintf(buf + len, buflen - len, "cab queue: %d\n",
190 sdata->vif.cab_queue);
191
192 return len;
193}
194__IEEE80211_IF_FILE(hw_queues, NULL);
171 195
172/* STA attributes */ 196/* STA attributes */
173IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC); 197IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
@@ -217,7 +241,7 @@ static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
217 241
218 return snprintf(buf, buflen, "request: %s\nused: %s\n", 242 return snprintf(buf, buflen, "request: %s\nused: %s\n",
219 smps_modes[sdata->u.mgd.req_smps], 243 smps_modes[sdata->u.mgd.req_smps],
220 smps_modes[sdata->u.mgd.ap_smps]); 244 smps_modes[sdata->smps_mode]);
221} 245}
222 246
223static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata, 247static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
@@ -245,27 +269,6 @@ static ssize_t ieee80211_if_fmt_tkip_mic_test(
245 return -EOPNOTSUPP; 269 return -EOPNOTSUPP;
246} 270}
247 271
248static int hwaddr_aton(const char *txt, u8 *addr)
249{
250 int i;
251
252 for (i = 0; i < ETH_ALEN; i++) {
253 int a, b;
254
255 a = hex_to_bin(*txt++);
256 if (a < 0)
257 return -1;
258 b = hex_to_bin(*txt++);
259 if (b < 0)
260 return -1;
261 *addr++ = (a << 4) | b;
262 if (i < 5 && *txt++ != ':')
263 return -1;
264 }
265
266 return 0;
267}
268
269static ssize_t ieee80211_if_parse_tkip_mic_test( 272static ssize_t ieee80211_if_parse_tkip_mic_test(
270 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) 273 struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
271{ 274{
@@ -275,13 +278,7 @@ static ssize_t ieee80211_if_parse_tkip_mic_test(
275 struct ieee80211_hdr *hdr; 278 struct ieee80211_hdr *hdr;
276 __le16 fc; 279 __le16 fc;
277 280
278 /* 281 if (!mac_pton(buf, addr))
279 * Assume colon-delimited MAC address with possible white space
280 * following.
281 */
282 if (buflen < 3 * ETH_ALEN - 1)
283 return -EINVAL;
284 if (hwaddr_aton(buf, addr) < 0)
285 return -EINVAL; 282 return -EINVAL;
286 283
287 if (!ieee80211_sdata_running(sdata)) 284 if (!ieee80211_sdata_running(sdata))
@@ -307,13 +304,16 @@ static ssize_t ieee80211_if_parse_tkip_mic_test(
307 case NL80211_IFTYPE_STATION: 304 case NL80211_IFTYPE_STATION:
308 fc |= cpu_to_le16(IEEE80211_FCTL_TODS); 305 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
309 /* BSSID SA DA */ 306 /* BSSID SA DA */
310 if (sdata->vif.bss_conf.bssid == NULL) { 307 mutex_lock(&sdata->u.mgd.mtx);
308 if (!sdata->u.mgd.associated) {
309 mutex_unlock(&sdata->u.mgd.mtx);
311 dev_kfree_skb(skb); 310 dev_kfree_skb(skb);
312 return -ENOTCONN; 311 return -ENOTCONN;
313 } 312 }
314 memcpy(hdr->addr1, sdata->vif.bss_conf.bssid, ETH_ALEN); 313 memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
315 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); 314 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
316 memcpy(hdr->addr3, addr, ETH_ALEN); 315 memcpy(hdr->addr3, addr, ETH_ALEN);
316 mutex_unlock(&sdata->u.mgd.mtx);
317 break; 317 break;
318 default: 318 default:
319 dev_kfree_skb(skb); 319 dev_kfree_skb(skb);
@@ -395,14 +395,14 @@ __IEEE80211_IF_FILE_W(uapsd_max_sp_len);
395 395
396/* AP attributes */ 396/* AP attributes */
397IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC); 397IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
398IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC); 398IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
399IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC); 399IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
400 400
401static ssize_t ieee80211_if_fmt_num_buffered_multicast( 401static ssize_t ieee80211_if_fmt_num_buffered_multicast(
402 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) 402 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
403{ 403{
404 return scnprintf(buf, buflen, "%u\n", 404 return scnprintf(buf, buflen, "%u\n",
405 skb_queue_len(&sdata->u.ap.ps_bc_buf)); 405 skb_queue_len(&sdata->u.ap.ps.bc_buf));
406} 406}
407__IEEE80211_IF_FILE(num_buffered_multicast, NULL); 407__IEEE80211_IF_FILE(num_buffered_multicast, NULL);
408 408
@@ -443,7 +443,7 @@ static ssize_t ieee80211_if_parse_tsf(
443 } 443 }
444 ret = kstrtoull(buf, 10, &tsf); 444 ret = kstrtoull(buf, 10, &tsf);
445 if (ret < 0) 445 if (ret < 0)
446 return -EINVAL; 446 return ret;
447 if (tsf_is_delta) 447 if (tsf_is_delta)
448 tsf = drv_get_tsf(local, sdata) + tsf_is_delta * tsf; 448 tsf = drv_get_tsf(local, sdata) + tsf_is_delta * tsf;
449 if (local->ops->set_tsf) { 449 if (local->ops->set_tsf) {
@@ -471,7 +471,7 @@ IEEE80211_IF_FILE(dropped_frames_congestion,
471 u.mesh.mshstats.dropped_frames_congestion, DEC); 471 u.mesh.mshstats.dropped_frames_congestion, DEC);
472IEEE80211_IF_FILE(dropped_frames_no_route, 472IEEE80211_IF_FILE(dropped_frames_no_route,
473 u.mesh.mshstats.dropped_frames_no_route, DEC); 473 u.mesh.mshstats.dropped_frames_no_route, DEC);
474IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC); 474IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
475 475
476/* Mesh parameters */ 476/* Mesh parameters */
477IEEE80211_IF_FILE(dot11MeshMaxRetries, 477IEEE80211_IF_FILE(dot11MeshMaxRetries,
@@ -531,6 +531,7 @@ static void add_common_files(struct ieee80211_sub_if_data *sdata)
531 DEBUGFS_ADD(rc_rateidx_mask_5ghz); 531 DEBUGFS_ADD(rc_rateidx_mask_5ghz);
532 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz); 532 DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
533 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz); 533 DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
534 DEBUGFS_ADD(hw_queues);
534} 535}
535 536
536static void add_sta_files(struct ieee80211_sub_if_data *sdata) 537static void add_sta_files(struct ieee80211_sub_if_data *sdata)
@@ -632,6 +633,9 @@ static void add_files(struct ieee80211_sub_if_data *sdata)
632 DEBUGFS_ADD(flags); 633 DEBUGFS_ADD(flags);
633 DEBUGFS_ADD(state); 634 DEBUGFS_ADD(state);
634 DEBUGFS_ADD(channel_type); 635 DEBUGFS_ADD(channel_type);
636 DEBUGFS_ADD(txpower);
637 DEBUGFS_ADD(user_power_level);
638 DEBUGFS_ADD(ap_power_level);
635 639
636 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) 640 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
637 add_common_files(sdata); 641 add_common_files(sdata);
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index da9003b20004..4dc2577886ff 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -871,4 +871,104 @@ static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
871 local->ops->mgd_prepare_tx(&local->hw, &sdata->vif); 871 local->ops->mgd_prepare_tx(&local->hw, &sdata->vif);
872 trace_drv_return_void(local); 872 trace_drv_return_void(local);
873} 873}
874
875static inline int drv_add_chanctx(struct ieee80211_local *local,
876 struct ieee80211_chanctx *ctx)
877{
878 int ret = -EOPNOTSUPP;
879
880 trace_drv_add_chanctx(local, ctx);
881 if (local->ops->add_chanctx)
882 ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
883 trace_drv_return_int(local, ret);
884
885 return ret;
886}
887
888static inline void drv_remove_chanctx(struct ieee80211_local *local,
889 struct ieee80211_chanctx *ctx)
890{
891 trace_drv_remove_chanctx(local, ctx);
892 if (local->ops->remove_chanctx)
893 local->ops->remove_chanctx(&local->hw, &ctx->conf);
894 trace_drv_return_void(local);
895}
896
897static inline void drv_change_chanctx(struct ieee80211_local *local,
898 struct ieee80211_chanctx *ctx,
899 u32 changed)
900{
901 trace_drv_change_chanctx(local, ctx, changed);
902 if (local->ops->change_chanctx)
903 local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
904 trace_drv_return_void(local);
905}
906
907static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
908 struct ieee80211_sub_if_data *sdata,
909 struct ieee80211_chanctx *ctx)
910{
911 int ret = 0;
912
913 check_sdata_in_driver(sdata);
914
915 trace_drv_assign_vif_chanctx(local, sdata, ctx);
916 if (local->ops->assign_vif_chanctx)
917 ret = local->ops->assign_vif_chanctx(&local->hw,
918 &sdata->vif,
919 &ctx->conf);
920 trace_drv_return_int(local, ret);
921
922 return ret;
923}
924
925static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
926 struct ieee80211_sub_if_data *sdata,
927 struct ieee80211_chanctx *ctx)
928{
929 check_sdata_in_driver(sdata);
930
931 trace_drv_unassign_vif_chanctx(local, sdata, ctx);
932 if (local->ops->unassign_vif_chanctx)
933 local->ops->unassign_vif_chanctx(&local->hw,
934 &sdata->vif,
935 &ctx->conf);
936 trace_drv_return_void(local);
937}
938
939static inline int drv_start_ap(struct ieee80211_local *local,
940 struct ieee80211_sub_if_data *sdata)
941{
942 int ret = 0;
943
944 check_sdata_in_driver(sdata);
945
946 trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
947 if (local->ops->start_ap)
948 ret = local->ops->start_ap(&local->hw, &sdata->vif);
949 trace_drv_return_int(local, ret);
950 return ret;
951}
952
953static inline void drv_stop_ap(struct ieee80211_local *local,
954 struct ieee80211_sub_if_data *sdata)
955{
956 check_sdata_in_driver(sdata);
957
958 trace_drv_stop_ap(local, sdata);
959 if (local->ops->stop_ap)
960 local->ops->stop_ap(&local->hw, &sdata->vif);
961 trace_drv_return_void(local);
962}
963
964static inline void drv_restart_complete(struct ieee80211_local *local)
965{
966 might_sleep();
967
968 trace_drv_restart_complete(local);
969 if (local->ops->restart_complete)
970 local->ops->restart_complete(&local->hw);
971 trace_drv_return_void(local);
972}
973
874#endif /* __MAC80211_DRIVER_OPS */ 974#endif /* __MAC80211_DRIVER_OPS */
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 5f3620f0bc0a..67774b053535 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -26,7 +26,6 @@
26#include "rate.h" 26#include "rate.h"
27 27
28#define IEEE80211_SCAN_INTERVAL (2 * HZ) 28#define IEEE80211_SCAN_INTERVAL (2 * HZ)
29#define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
30#define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) 29#define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
31 30
32#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) 31#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
@@ -39,7 +38,8 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
39 const u8 *bssid, const int beacon_int, 38 const u8 *bssid, const int beacon_int,
40 struct ieee80211_channel *chan, 39 struct ieee80211_channel *chan,
41 const u32 basic_rates, 40 const u32 basic_rates,
42 const u16 capability, u64 tsf) 41 const u16 capability, u64 tsf,
42 bool creator)
43{ 43{
44 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 44 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
45 struct ieee80211_local *local = sdata->local; 45 struct ieee80211_local *local = sdata->local;
@@ -72,25 +72,27 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
72 /* if merging, indicate to driver that we leave the old IBSS */ 72 /* if merging, indicate to driver that we leave the old IBSS */
73 if (sdata->vif.bss_conf.ibss_joined) { 73 if (sdata->vif.bss_conf.ibss_joined) {
74 sdata->vif.bss_conf.ibss_joined = false; 74 sdata->vif.bss_conf.ibss_joined = false;
75 sdata->vif.bss_conf.ibss_creator = false;
75 netif_carrier_off(sdata->dev); 76 netif_carrier_off(sdata->dev);
76 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS); 77 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS);
77 } 78 }
78 79
79 memcpy(ifibss->bssid, bssid, ETH_ALEN);
80
81 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0; 80 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
82 81
83 local->oper_channel = chan;
84 channel_type = ifibss->channel_type; 82 channel_type = ifibss->channel_type;
85 if (!cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type)) 83 if (!cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
86 channel_type = NL80211_CHAN_HT20; 84 channel_type = NL80211_CHAN_HT20;
87 if (!ieee80211_set_channel_type(local, sdata, channel_type)) { 85
88 /* can only fail due to HT40+/- mismatch */ 86 ieee80211_vif_release_channel(sdata);
89 channel_type = NL80211_CHAN_HT20; 87 if (ieee80211_vif_use_channel(sdata, chan, channel_type,
90 WARN_ON(!ieee80211_set_channel_type(local, sdata, 88 ifibss->fixed_channel ?
91 NL80211_CHAN_HT20)); 89 IEEE80211_CHANCTX_SHARED :
90 IEEE80211_CHANCTX_EXCLUSIVE)) {
91 sdata_info(sdata, "Failed to join IBSS, no channel context\n");
92 return;
92 } 93 }
93 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); 94
95 memcpy(ifibss->bssid, bssid, ETH_ALEN);
94 96
95 sband = local->hw.wiphy->bands[chan->band]; 97 sband = local->hw.wiphy->bands[chan->band];
96 98
@@ -197,6 +199,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
197 bss_change |= BSS_CHANGED_HT; 199 bss_change |= BSS_CHANGED_HT;
198 bss_change |= BSS_CHANGED_IBSS; 200 bss_change |= BSS_CHANGED_IBSS;
199 sdata->vif.bss_conf.ibss_joined = true; 201 sdata->vif.bss_conf.ibss_joined = true;
202 sdata->vif.bss_conf.ibss_creator = creator;
200 ieee80211_bss_info_change_notify(sdata, bss_change); 203 ieee80211_bss_info_change_notify(sdata, bss_change);
201 204
202 ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates); 205 ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates);
@@ -249,7 +252,8 @@ static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
249 cbss->channel, 252 cbss->channel,
250 basic_rates, 253 basic_rates,
251 cbss->capability, 254 cbss->capability,
252 cbss->tsf); 255 cbss->tsf,
256 false);
253} 257}
254 258
255static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta, 259static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta,
@@ -279,7 +283,7 @@ static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta,
279 ibss_dbg(sdata, 283 ibss_dbg(sdata,
280 "TX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=1)\n", 284 "TX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=1)\n",
281 sdata->vif.addr, addr, sdata->u.ibss.bssid); 285 sdata->vif.addr, addr, sdata->u.ibss.bssid);
282 ieee80211_send_auth(sdata, 1, WLAN_AUTH_OPEN, NULL, 0, 286 ieee80211_send_auth(sdata, 1, WLAN_AUTH_OPEN, 0, NULL, 0,
283 addr, sdata->u.ibss.bssid, NULL, 0, 0); 287 addr, sdata->u.ibss.bssid, NULL, 0, 0);
284 } 288 }
285 return sta; 289 return sta;
@@ -294,7 +298,8 @@ ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
294 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 298 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
295 struct ieee80211_local *local = sdata->local; 299 struct ieee80211_local *local = sdata->local;
296 struct sta_info *sta; 300 struct sta_info *sta;
297 int band = local->oper_channel->band; 301 struct ieee80211_chanctx_conf *chanctx_conf;
302 int band;
298 303
299 /* 304 /*
300 * XXX: Consider removing the least recently used entry and 305 * XXX: Consider removing the least recently used entry and
@@ -317,6 +322,13 @@ ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
317 return NULL; 322 return NULL;
318 } 323 }
319 324
325 rcu_read_lock();
326 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
327 if (WARN_ON_ONCE(!chanctx_conf))
328 return NULL;
329 band = chanctx_conf->channel->band;
330 rcu_read_unlock();
331
320 sta = sta_info_alloc(sdata, addr, GFP_KERNEL); 332 sta = sta_info_alloc(sdata, addr, GFP_KERNEL);
321 if (!sta) { 333 if (!sta) {
322 rcu_read_lock(); 334 rcu_read_lock();
@@ -389,7 +401,7 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
389 * However, try to reply to authentication attempts if someone 401 * However, try to reply to authentication attempts if someone
390 * has actually implemented this. 402 * has actually implemented this.
391 */ 403 */
392 ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0, 404 ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, 0, NULL, 0,
393 mgmt->sa, sdata->u.ibss.bssid, NULL, 0, 0); 405 mgmt->sa, sdata->u.ibss.bssid, NULL, 0, 0);
394} 406}
395 407
@@ -517,7 +529,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
517 goto put_bss; 529 goto put_bss;
518 530
519 /* different channel */ 531 /* different channel */
520 if (cbss->channel != local->oper_channel) 532 if (sdata->u.ibss.fixed_channel &&
533 sdata->u.ibss.channel != cbss->channel)
521 goto put_bss; 534 goto put_bss;
522 535
523 /* different SSID */ 536 /* different SSID */
@@ -592,7 +605,8 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
592 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 605 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
593 struct ieee80211_local *local = sdata->local; 606 struct ieee80211_local *local = sdata->local;
594 struct sta_info *sta; 607 struct sta_info *sta;
595 int band = local->oper_channel->band; 608 struct ieee80211_chanctx_conf *chanctx_conf;
609 int band;
596 610
597 /* 611 /*
598 * XXX: Consider removing the least recently used entry and 612 * XXX: Consider removing the least recently used entry and
@@ -610,6 +624,15 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
610 if (!ether_addr_equal(bssid, sdata->u.ibss.bssid)) 624 if (!ether_addr_equal(bssid, sdata->u.ibss.bssid))
611 return; 625 return;
612 626
627 rcu_read_lock();
628 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
629 if (WARN_ON_ONCE(!chanctx_conf)) {
630 rcu_read_unlock();
631 return;
632 }
633 band = chanctx_conf->channel->band;
634 rcu_read_unlock();
635
613 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); 636 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
614 if (!sta) 637 if (!sta)
615 return; 638 return;
@@ -715,7 +738,7 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
715 738
716 __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int, 739 __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int,
717 ifibss->channel, ifibss->basic_rates, 740 ifibss->channel, ifibss->basic_rates,
718 capability, 0); 741 capability, 0, true);
719} 742}
720 743
721/* 744/*
@@ -784,18 +807,8 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
784 int interval = IEEE80211_SCAN_INTERVAL; 807 int interval = IEEE80211_SCAN_INTERVAL;
785 808
786 if (time_after(jiffies, ifibss->ibss_join_req + 809 if (time_after(jiffies, ifibss->ibss_join_req +
787 IEEE80211_IBSS_JOIN_TIMEOUT)) { 810 IEEE80211_IBSS_JOIN_TIMEOUT))
788 if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) { 811 ieee80211_sta_create_ibss(sdata);
789 ieee80211_sta_create_ibss(sdata);
790 return;
791 }
792 sdata_info(sdata, "IBSS not allowed on %d MHz\n",
793 local->oper_channel->center_freq);
794
795 /* No IBSS found - decrease scan interval and continue
796 * scanning. */
797 interval = IEEE80211_SCAN_INTERVAL_SLOW;
798 }
799 812
800 mod_timer(&ifibss->timer, 813 mod_timer(&ifibss->timer,
801 round_jiffies(jiffies + interval)); 814 round_jiffies(jiffies + interval));
@@ -1086,17 +1099,6 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1086 sdata->u.ibss.channel_type = params->channel_type; 1099 sdata->u.ibss.channel_type = params->channel_type;
1087 sdata->u.ibss.fixed_channel = params->channel_fixed; 1100 sdata->u.ibss.fixed_channel = params->channel_fixed;
1088 1101
1089 /* fix ourselves to that channel now already */
1090 if (params->channel_fixed) {
1091 sdata->local->oper_channel = params->channel;
1092 if (!ieee80211_set_channel_type(sdata->local, sdata,
1093 params->channel_type)) {
1094 mutex_unlock(&sdata->u.ibss.mtx);
1095 kfree_skb(skb);
1096 return -EINVAL;
1097 }
1098 }
1099
1100 if (params->ie) { 1102 if (params->ie) {
1101 sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len, 1103 sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len,
1102 GFP_KERNEL); 1104 GFP_KERNEL);
@@ -1108,7 +1110,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1108 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; 1110 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
1109 sdata->u.ibss.ibss_join_req = jiffies; 1111 sdata->u.ibss.ibss_join_req = jiffies;
1110 1112
1111 memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN); 1113 memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len);
1112 sdata->u.ibss.ssid_len = params->ssid_len; 1114 sdata->u.ibss.ssid_len = params->ssid_len;
1113 1115
1114 mutex_unlock(&sdata->u.ibss.mtx); 1116 mutex_unlock(&sdata->u.ibss.mtx);
@@ -1134,6 +1136,9 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1134 changed |= BSS_CHANGED_HT; 1136 changed |= BSS_CHANGED_HT;
1135 ieee80211_bss_info_change_notify(sdata, changed); 1137 ieee80211_bss_info_change_notify(sdata, changed);
1136 1138
1139 sdata->smps_mode = IEEE80211_SMPS_OFF;
1140 sdata->needed_rx_chains = sdata->local->rx_chains;
1141
1137 ieee80211_queue_work(&sdata->local->hw, &sdata->work); 1142 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1138 1143
1139 return 0; 1144 return 0;
@@ -1151,10 +1156,6 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1151 1156
1152 mutex_lock(&sdata->u.ibss.mtx); 1157 mutex_lock(&sdata->u.ibss.mtx);
1153 1158
1154 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
1155 memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
1156 sdata->u.ibss.ssid_len = 0;
1157
1158 active_ibss = ieee80211_sta_active_ibss(sdata); 1159 active_ibss = ieee80211_sta_active_ibss(sdata);
1159 1160
1160 if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) { 1161 if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) {
@@ -1175,6 +1176,10 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1175 } 1176 }
1176 } 1177 }
1177 1178
1179 ifibss->state = IEEE80211_IBSS_MLME_SEARCH;
1180 memset(ifibss->bssid, 0, ETH_ALEN);
1181 ifibss->ssid_len = 0;
1182
1178 sta_info_flush(sdata->local, sdata); 1183 sta_info_flush(sdata->local, sdata);
1179 1184
1180 spin_lock_bh(&ifibss->incomplete_lock); 1185 spin_lock_bh(&ifibss->incomplete_lock);
@@ -1197,6 +1202,7 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1197 lockdep_is_held(&sdata->u.ibss.mtx)); 1202 lockdep_is_held(&sdata->u.ibss.mtx));
1198 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL); 1203 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL);
1199 sdata->vif.bss_conf.ibss_joined = false; 1204 sdata->vif.bss_conf.ibss_joined = false;
1205 sdata->vif.bss_conf.ibss_creator = false;
1200 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | 1206 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
1201 BSS_CHANGED_IBSS); 1207 BSS_CHANGED_IBSS);
1202 synchronize_rcu(); 1208 synchronize_rcu();
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 8c804550465b..74748896d77b 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -56,6 +56,9 @@ struct ieee80211_local;
56#define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024)) 56#define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024))
57#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x)) 57#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x))
58 58
59/* power level hasn't been configured (or set to automatic) */
60#define IEEE80211_UNSET_POWER_LEVEL INT_MIN
61
59/* 62/*
60 * Some APs experience problems when working with U-APSD. Decrease the 63 * Some APs experience problems when working with U-APSD. Decrease the
61 * probability of that happening by using legacy mode for all ACs but VO. 64 * probability of that happening by using legacy mode for all ACs but VO.
@@ -280,23 +283,27 @@ struct probe_resp {
280 u8 data[0]; 283 u8 data[0];
281}; 284};
282 285
283struct ieee80211_if_ap { 286struct ps_data {
284 struct beacon_data __rcu *beacon;
285 struct probe_resp __rcu *probe_resp;
286
287 struct list_head vlans;
288
289 /* yes, this looks ugly, but guarantees that we can later use 287 /* yes, this looks ugly, but guarantees that we can later use
290 * bitmap_empty :) 288 * bitmap_empty :)
291 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */ 289 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */
292 u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)]; 290 u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
293 struct sk_buff_head ps_bc_buf; 291 struct sk_buff_head bc_buf;
294 atomic_t num_sta_ps; /* number of stations in PS mode */ 292 atomic_t num_sta_ps; /* number of stations in PS mode */
295 atomic_t num_mcast_sta; /* number of stations receiving multicast */
296 int dtim_count; 293 int dtim_count;
297 bool dtim_bc_mc; 294 bool dtim_bc_mc;
298}; 295};
299 296
297struct ieee80211_if_ap {
298 struct beacon_data __rcu *beacon;
299 struct probe_resp __rcu *probe_resp;
300
301 struct list_head vlans;
302
303 struct ps_data ps;
304 atomic_t num_mcast_sta; /* number of stations receiving multicast */
305};
306
300struct ieee80211_if_wds { 307struct ieee80211_if_wds {
301 struct sta_info *sta; 308 struct sta_info *sta;
302 u8 remote_addr[ETH_ALEN]; 309 u8 remote_addr[ETH_ALEN];
@@ -316,7 +323,6 @@ struct mesh_stats {
316 __u32 dropped_frames_ttl; /* Not transmitted since mesh_ttl == 0*/ 323 __u32 dropped_frames_ttl; /* Not transmitted since mesh_ttl == 0*/
317 __u32 dropped_frames_no_route; /* Not transmitted, no route found */ 324 __u32 dropped_frames_no_route; /* Not transmitted, no route found */
318 __u32 dropped_frames_congestion;/* Not forwarded due to congestion */ 325 __u32 dropped_frames_congestion;/* Not forwarded due to congestion */
319 atomic_t estab_plinks;
320}; 326};
321 327
322#define PREQ_Q_F_START 0x1 328#define PREQ_Q_F_START 0x1
@@ -350,7 +356,7 @@ struct ieee80211_roc_work {
350 356
351 u32 duration, req_duration; 357 u32 duration, req_duration;
352 struct sk_buff *frame; 358 struct sk_buff *frame;
353 u64 mgmt_tx_cookie; 359 u64 cookie, mgmt_tx_cookie;
354}; 360};
355 361
356/* flags used in struct ieee80211_if_managed.flags */ 362/* flags used in struct ieee80211_if_managed.flags */
@@ -378,8 +384,9 @@ struct ieee80211_mgd_auth_data {
378 u8 key_len, key_idx; 384 u8 key_len, key_idx;
379 bool done; 385 bool done;
380 386
381 size_t ie_len; 387 u16 sae_trans, sae_status;
382 u8 ie[]; 388 size_t data_len;
389 u8 data[];
383}; 390};
384 391
385struct ieee80211_mgd_assoc_data { 392struct ieee80211_mgd_assoc_data {
@@ -433,7 +440,6 @@ struct ieee80211_if_managed {
433 bool powersave; /* powersave requested for this iface */ 440 bool powersave; /* powersave requested for this iface */
434 bool broken_ap; /* AP is broken -- turn off powersave */ 441 bool broken_ap; /* AP is broken -- turn off powersave */
435 enum ieee80211_smps_mode req_smps, /* requested smps mode */ 442 enum ieee80211_smps_mode req_smps, /* requested smps mode */
436 ap_smps, /* smps mode AP thinks we're in */
437 driver_smps_mode; /* smps mode request */ 443 driver_smps_mode; /* smps mode request */
438 444
439 struct work_struct request_smps_work; 445 struct work_struct request_smps_work;
@@ -467,6 +473,8 @@ struct ieee80211_if_managed {
467 473
468 u8 use_4addr; 474 u8 use_4addr;
469 475
476 u8 p2p_noa_index;
477
470 /* Signal strength from the last Beacon frame in the current BSS. */ 478 /* Signal strength from the last Beacon frame in the current BSS. */
471 int last_beacon_signal; 479 int last_beacon_signal;
472 480
@@ -599,6 +607,7 @@ struct ieee80211_if_mesh {
599 int preq_queue_len; 607 int preq_queue_len;
600 struct mesh_stats mshstats; 608 struct mesh_stats mshstats;
601 struct mesh_config mshcfg; 609 struct mesh_config mshcfg;
610 atomic_t estab_plinks;
602 u32 mesh_seqnum; 611 u32 mesh_seqnum;
603 bool accepting_plinks; 612 bool accepting_plinks;
604 int num_gates; 613 int num_gates;
@@ -610,7 +619,7 @@ struct ieee80211_if_mesh {
610 IEEE80211_MESH_SEC_SECURED = 0x2, 619 IEEE80211_MESH_SEC_SECURED = 0x2,
611 } security; 620 } security;
612 /* Extensible Synchronization Framework */ 621 /* Extensible Synchronization Framework */
613 struct ieee80211_mesh_sync_ops *sync_ops; 622 const struct ieee80211_mesh_sync_ops *sync_ops;
614 s64 sync_offset_clockdrift_max; 623 s64 sync_offset_clockdrift_max;
615 spinlock_t sync_offset_lock; 624 spinlock_t sync_offset_lock;
616 bool adjusting_tbtt; 625 bool adjusting_tbtt;
@@ -658,6 +667,30 @@ enum ieee80211_sdata_state_bits {
658 SDATA_STATE_OFFCHANNEL, 667 SDATA_STATE_OFFCHANNEL,
659}; 668};
660 669
670/**
671 * enum ieee80211_chanctx_mode - channel context configuration mode
672 *
673 * @IEEE80211_CHANCTX_SHARED: channel context may be used by
674 * multiple interfaces
675 * @IEEE80211_CHANCTX_EXCLUSIVE: channel context can be used
676 * only by a single interface. This can be used for example for
677 * non-fixed channel IBSS.
678 */
679enum ieee80211_chanctx_mode {
680 IEEE80211_CHANCTX_SHARED,
681 IEEE80211_CHANCTX_EXCLUSIVE
682};
683
684struct ieee80211_chanctx {
685 struct list_head list;
686 struct rcu_head rcu_head;
687
688 enum ieee80211_chanctx_mode mode;
689 int refcount;
690
691 struct ieee80211_chanctx_conf conf;
692};
693
661struct ieee80211_sub_if_data { 694struct ieee80211_sub_if_data {
662 struct list_head list; 695 struct list_head list;
663 696
@@ -704,11 +737,20 @@ struct ieee80211_sub_if_data {
704 737
705 struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS]; 738 struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
706 739
740 /* used to reconfigure hardware SM PS */
741 struct work_struct recalc_smps;
742
707 struct work_struct work; 743 struct work_struct work;
708 struct sk_buff_head skb_queue; 744 struct sk_buff_head skb_queue;
709 745
710 bool arp_filter_state; 746 bool arp_filter_state;
711 747
748 u8 needed_rx_chains;
749 enum ieee80211_smps_mode smps_mode;
750
751 int user_power_level; /* in dBm */
752 int ap_power_level; /* in dBm */
753
712 /* 754 /*
713 * AP this belongs to: self in AP mode and 755 * AP this belongs to: self in AP mode and
714 * corresponding AP in VLAN mode, NULL for 756 * corresponding AP in VLAN mode, NULL for
@@ -749,6 +791,21 @@ struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p)
749 return container_of(p, struct ieee80211_sub_if_data, vif); 791 return container_of(p, struct ieee80211_sub_if_data, vif);
750} 792}
751 793
794static inline enum ieee80211_band
795ieee80211_get_sdata_band(struct ieee80211_sub_if_data *sdata)
796{
797 enum ieee80211_band band = IEEE80211_BAND_2GHZ;
798 struct ieee80211_chanctx_conf *chanctx_conf;
799
800 rcu_read_lock();
801 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
802 if (!WARN_ON(!chanctx_conf))
803 band = chanctx_conf->channel->band;
804 rcu_read_unlock();
805
806 return band;
807}
808
752enum sdata_queue_type { 809enum sdata_queue_type {
753 IEEE80211_SDATA_QUEUE_TYPE_FRAME = 0, 810 IEEE80211_SDATA_QUEUE_TYPE_FRAME = 0,
754 IEEE80211_SDATA_QUEUE_AGG_START = 1, 811 IEEE80211_SDATA_QUEUE_AGG_START = 1,
@@ -821,6 +878,7 @@ enum {
821 * @SCAN_SUSPEND: Suspend the scan and go back to operating channel to 878 * @SCAN_SUSPEND: Suspend the scan and go back to operating channel to
822 * send out data 879 * send out data
823 * @SCAN_RESUME: Resume the scan and scan the next channel 880 * @SCAN_RESUME: Resume the scan and scan the next channel
881 * @SCAN_ABORT: Abort the scan and go back to operating channel
824 */ 882 */
825enum mac80211_scan_state { 883enum mac80211_scan_state {
826 SCAN_DECISION, 884 SCAN_DECISION,
@@ -828,6 +886,7 @@ enum mac80211_scan_state {
828 SCAN_SEND_PROBE, 886 SCAN_SEND_PROBE,
829 SCAN_SUSPEND, 887 SCAN_SUSPEND,
830 SCAN_RESUME, 888 SCAN_RESUME,
889 SCAN_ABORT,
831}; 890};
832 891
833struct ieee80211_local { 892struct ieee80211_local {
@@ -858,15 +917,14 @@ struct ieee80211_local {
858 917
859 bool wiphy_ciphers_allocated; 918 bool wiphy_ciphers_allocated;
860 919
920 bool use_chanctx;
921
861 /* protects the aggregated multicast list and filter calls */ 922 /* protects the aggregated multicast list and filter calls */
862 spinlock_t filter_lock; 923 spinlock_t filter_lock;
863 924
864 /* used for uploading changed mc list */ 925 /* used for uploading changed mc list */
865 struct work_struct reconfig_filter; 926 struct work_struct reconfig_filter;
866 927
867 /* used to reconfigure hardware SM PS */
868 struct work_struct recalc_smps;
869
870 /* aggregated multicast list */ 928 /* aggregated multicast list */
871 struct netdev_hw_addr_list mc_list; 929 struct netdev_hw_addr_list mc_list;
872 930
@@ -903,6 +961,9 @@ struct ieee80211_local {
903 /* wowlan is enabled -- don't reconfig on resume */ 961 /* wowlan is enabled -- don't reconfig on resume */
904 bool wowlan; 962 bool wowlan;
905 963
964 /* number of RX chains the hardware has */
965 u8 rx_chains;
966
906 int tx_headroom; /* required headroom for hardware/radiotap */ 967 int tx_headroom; /* required headroom for hardware/radiotap */
907 968
908 /* Tasklet and skb queue to process calls from IRQ mode. All frames 969 /* Tasklet and skb queue to process calls from IRQ mode. All frames
@@ -980,13 +1041,19 @@ struct ieee80211_local {
980 enum mac80211_scan_state next_scan_state; 1041 enum mac80211_scan_state next_scan_state;
981 struct delayed_work scan_work; 1042 struct delayed_work scan_work;
982 struct ieee80211_sub_if_data __rcu *scan_sdata; 1043 struct ieee80211_sub_if_data __rcu *scan_sdata;
1044 struct ieee80211_channel *csa_channel;
1045 /* For backward compatibility only -- do not use */
1046 struct ieee80211_channel *_oper_channel;
983 enum nl80211_channel_type _oper_channel_type; 1047 enum nl80211_channel_type _oper_channel_type;
984 struct ieee80211_channel *oper_channel, *csa_channel;
985 1048
986 /* Temporary remain-on-channel for off-channel operations */ 1049 /* Temporary remain-on-channel for off-channel operations */
987 struct ieee80211_channel *tmp_channel; 1050 struct ieee80211_channel *tmp_channel;
988 enum nl80211_channel_type tmp_channel_type; 1051 enum nl80211_channel_type tmp_channel_type;
989 1052
1053 /* channel contexts */
1054 struct list_head chanctx_list;
1055 struct mutex chanctx_mtx;
1056
990 /* SNMP counters */ 1057 /* SNMP counters */
991 /* dot11CountersTable */ 1058 /* dot11CountersTable */
992 u32 dot11TransmittedFragmentCount; 1059 u32 dot11TransmittedFragmentCount;
@@ -1058,8 +1125,7 @@ struct ieee80211_local {
1058 int dynamic_ps_user_timeout; 1125 int dynamic_ps_user_timeout;
1059 bool disable_dynamic_ps; 1126 bool disable_dynamic_ps;
1060 1127
1061 int user_power_level; /* in dBm */ 1128 int user_power_level; /* in dBm, for all interfaces */
1062 int ap_power_level; /* in dBm */
1063 1129
1064 enum ieee80211_smps_mode smps_mode; 1130 enum ieee80211_smps_mode smps_mode;
1065 1131
@@ -1078,6 +1144,7 @@ struct ieee80211_local {
1078 struct list_head roc_list; 1144 struct list_head roc_list;
1079 struct work_struct hw_roc_start, hw_roc_done; 1145 struct work_struct hw_roc_start, hw_roc_done;
1080 unsigned long hw_roc_start_time; 1146 unsigned long hw_roc_start_time;
1147 u64 roc_cookie_counter;
1081 1148
1082 struct idr ack_status_frames; 1149 struct idr ack_status_frames;
1083 spinlock_t ack_status_lock; 1150 spinlock_t ack_status_lock;
@@ -1091,6 +1158,8 @@ struct ieee80211_local {
1091 1158
1092 /* virtual monitor interface */ 1159 /* virtual monitor interface */
1093 struct ieee80211_sub_if_data __rcu *monitor_sdata; 1160 struct ieee80211_sub_if_data __rcu *monitor_sdata;
1161 struct ieee80211_channel *monitor_channel;
1162 enum nl80211_channel_type monitor_channel_type;
1094}; 1163};
1095 1164
1096static inline struct ieee80211_sub_if_data * 1165static inline struct ieee80211_sub_if_data *
@@ -1133,6 +1202,8 @@ struct ieee802_11_elems {
1133 u8 *wmm_param; 1202 u8 *wmm_param;
1134 struct ieee80211_ht_cap *ht_cap_elem; 1203 struct ieee80211_ht_cap *ht_cap_elem;
1135 struct ieee80211_ht_operation *ht_operation; 1204 struct ieee80211_ht_operation *ht_operation;
1205 struct ieee80211_vht_cap *vht_cap_elem;
1206 struct ieee80211_vht_operation *vht_operation;
1136 struct ieee80211_meshconf_ie *mesh_config; 1207 struct ieee80211_meshconf_ie *mesh_config;
1137 u8 *mesh_id; 1208 u8 *mesh_id;
1138 u8 *peering; 1209 u8 *peering;
@@ -1302,6 +1373,9 @@ void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
1302int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up); 1373int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up);
1303void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata); 1374void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata);
1304 1375
1376bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
1377void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
1378
1305static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata) 1379static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata)
1306{ 1380{
1307 return test_bit(SDATA_STATE_RUNNING, &sdata->state); 1381 return test_bit(SDATA_STATE_RUNNING, &sdata->state);
@@ -1314,6 +1388,8 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1314 struct net_device *dev); 1388 struct net_device *dev);
1315netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, 1389netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1316 struct net_device *dev); 1390 struct net_device *dev);
1391void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
1392 struct sk_buff_head *skbs);
1317 1393
1318/* HT */ 1394/* HT */
1319void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata, 1395void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
@@ -1359,6 +1435,13 @@ void ieee80211_ba_session_work(struct work_struct *work);
1359void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid); 1435void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid);
1360void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid); 1436void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid);
1361 1437
1438u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs);
1439
1440/* VHT */
1441void ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
1442 struct ieee80211_supported_band *sband,
1443 struct ieee80211_vht_cap *vht_cap_ie,
1444 struct ieee80211_sta_vht_cap *vht_cap);
1362/* Spectrum management */ 1445/* Spectrum management */
1363void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata, 1446void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
1364 struct ieee80211_mgmt *mgmt, 1447 struct ieee80211_mgmt *mgmt,
@@ -1393,11 +1476,42 @@ void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int ke
1393 gfp_t gfp); 1476 gfp_t gfp);
1394void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata, 1477void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
1395 bool bss_notify); 1478 bool bss_notify);
1396void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb); 1479void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1480 enum ieee80211_band band);
1481
1482void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
1483 struct sk_buff *skb, int tid,
1484 enum ieee80211_band band);
1485
1486static inline void
1487ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
1488 struct sk_buff *skb, int tid,
1489 enum ieee80211_band band)
1490{
1491 rcu_read_lock();
1492 __ieee80211_tx_skb_tid_band(sdata, skb, tid, band);
1493 rcu_read_unlock();
1494}
1397 1495
1398void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, 1496static inline void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata,
1399 struct sk_buff *skb, int tid); 1497 struct sk_buff *skb, int tid)
1400static void inline ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, 1498{
1499 struct ieee80211_chanctx_conf *chanctx_conf;
1500
1501 rcu_read_lock();
1502 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1503 if (WARN_ON(!chanctx_conf)) {
1504 rcu_read_unlock();
1505 kfree_skb(skb);
1506 return;
1507 }
1508
1509 __ieee80211_tx_skb_tid_band(sdata, skb, tid,
1510 chanctx_conf->channel->band);
1511 rcu_read_unlock();
1512}
1513
1514static inline void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata,
1401 struct sk_buff *skb) 1515 struct sk_buff *skb)
1402{ 1516{
1403 /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */ 1517 /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */
@@ -1444,7 +1558,7 @@ static inline void ieee80211_add_pending_skbs(struct ieee80211_local *local,
1444} 1558}
1445 1559
1446void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 1560void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1447 u16 transaction, u16 auth_alg, 1561 u16 transaction, u16 auth_alg, u16 status,
1448 u8 *extra, size_t extra_len, const u8 *bssid, 1562 u8 *extra, size_t extra_len, const u8 *bssid,
1449 const u8 *da, const u8 *key, u8 key_len, u8 key_idx); 1563 const u8 *da, const u8 *key, u8 key_len, u8 key_idx);
1450void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, 1564void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
@@ -1464,7 +1578,7 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1464 const u8 *ssid, size_t ssid_len, 1578 const u8 *ssid, size_t ssid_len,
1465 const u8 *ie, size_t ie_len, 1579 const u8 *ie, size_t ie_len,
1466 u32 ratemask, bool directed, bool no_cck, 1580 u32 ratemask, bool directed, bool no_cck,
1467 struct ieee80211_channel *channel); 1581 struct ieee80211_channel *channel, bool scan);
1468 1582
1469void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 1583void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
1470 const size_t supp_rates_len, 1584 const size_t supp_rates_len,
@@ -1474,7 +1588,7 @@ u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
1474 enum ieee80211_band band, u32 *basic_rates); 1588 enum ieee80211_band band, u32 *basic_rates);
1475int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata, 1589int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1476 enum ieee80211_smps_mode smps_mode); 1590 enum ieee80211_smps_mode smps_mode);
1477void ieee80211_recalc_smps(struct ieee80211_local *local); 1591void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata);
1478 1592
1479size_t ieee80211_ie_split(const u8 *ies, size_t ielen, 1593size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
1480 const u8 *ids, int n_ids, size_t offset); 1594 const u8 *ids, int n_ids, size_t offset);
@@ -1495,21 +1609,19 @@ int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
1495 enum ieee80211_band band); 1609 enum ieee80211_band band);
1496 1610
1497/* channel management */ 1611/* channel management */
1498enum ieee80211_chan_mode {
1499 CHAN_MODE_UNDEFINED,
1500 CHAN_MODE_HOPPING,
1501 CHAN_MODE_FIXED,
1502};
1503
1504enum ieee80211_chan_mode
1505ieee80211_get_channel_mode(struct ieee80211_local *local,
1506 struct ieee80211_sub_if_data *ignore);
1507bool ieee80211_set_channel_type(struct ieee80211_local *local,
1508 struct ieee80211_sub_if_data *sdata,
1509 enum nl80211_channel_type chantype);
1510enum nl80211_channel_type 1612enum nl80211_channel_type
1511ieee80211_ht_oper_to_channel_type(struct ieee80211_ht_operation *ht_oper); 1613ieee80211_ht_oper_to_channel_type(struct ieee80211_ht_operation *ht_oper);
1512 1614
1615int __must_check
1616ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
1617 struct ieee80211_channel *channel,
1618 enum nl80211_channel_type channel_type,
1619 enum ieee80211_chanctx_mode mode);
1620void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
1621
1622void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
1623 struct ieee80211_chanctx *chanctx);
1624
1513#ifdef CONFIG_MAC80211_NOINLINE 1625#ifdef CONFIG_MAC80211_NOINLINE
1514#define debug_noinline noinline 1626#define debug_noinline noinline
1515#else 1627#else
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 6f8a73c64fb3..80ce90b29d9d 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -42,6 +42,41 @@
42 * by either the RTNL, the iflist_mtx or RCU. 42 * by either the RTNL, the iflist_mtx or RCU.
43 */ 43 */
44 44
45bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
46{
47 struct ieee80211_chanctx_conf *chanctx_conf;
48 int power;
49
50 rcu_read_lock();
51 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
52 if (!chanctx_conf) {
53 rcu_read_unlock();
54 return false;
55 }
56
57 power = chanctx_conf->channel->max_power;
58 rcu_read_unlock();
59
60 if (sdata->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
61 power = min(power, sdata->user_power_level);
62
63 if (sdata->ap_power_level != IEEE80211_UNSET_POWER_LEVEL)
64 power = min(power, sdata->ap_power_level);
65
66 if (power != sdata->vif.bss_conf.txpower) {
67 sdata->vif.bss_conf.txpower = power;
68 ieee80211_hw_config(sdata->local, 0);
69 return true;
70 }
71
72 return false;
73}
74
75void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
76{
77 if (__ieee80211_recalc_txpower(sdata))
78 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_TXPOWER);
79}
45 80
46static u32 ieee80211_idle_off(struct ieee80211_local *local, 81static u32 ieee80211_idle_off(struct ieee80211_local *local,
47 const char *reason) 82 const char *reason)
@@ -380,6 +415,15 @@ static int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
380 goto out_unlock; 415 goto out_unlock;
381 } 416 }
382 417
418 ret = ieee80211_vif_use_channel(sdata, local->monitor_channel,
419 local->monitor_channel_type,
420 IEEE80211_CHANCTX_EXCLUSIVE);
421 if (ret) {
422 drv_remove_interface(local, sdata);
423 kfree(sdata);
424 goto out_unlock;
425 }
426
383 rcu_assign_pointer(local->monitor_sdata, sdata); 427 rcu_assign_pointer(local->monitor_sdata, sdata);
384 out_unlock: 428 out_unlock:
385 mutex_unlock(&local->iflist_mtx); 429 mutex_unlock(&local->iflist_mtx);
@@ -403,6 +447,8 @@ static void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
403 rcu_assign_pointer(local->monitor_sdata, NULL); 447 rcu_assign_pointer(local->monitor_sdata, NULL);
404 synchronize_net(); 448 synchronize_net();
405 449
450 ieee80211_vif_release_channel(sdata);
451
406 drv_remove_interface(local, sdata); 452 drv_remove_interface(local, sdata);
407 453
408 kfree(sdata); 454 kfree(sdata);
@@ -665,7 +711,6 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
665 struct sk_buff *skb, *tmp; 711 struct sk_buff *skb, *tmp;
666 u32 hw_reconf_flags = 0; 712 u32 hw_reconf_flags = 0;
667 int i; 713 int i;
668 enum nl80211_channel_type orig_ct;
669 714
670 clear_bit(SDATA_STATE_RUNNING, &sdata->state); 715 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
671 716
@@ -729,34 +774,17 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
729 del_timer_sync(&local->dynamic_ps_timer); 774 del_timer_sync(&local->dynamic_ps_timer);
730 cancel_work_sync(&local->dynamic_ps_enable_work); 775 cancel_work_sync(&local->dynamic_ps_enable_work);
731 776
777 cancel_work_sync(&sdata->recalc_smps);
778
732 /* APs need special treatment */ 779 /* APs need special treatment */
733 if (sdata->vif.type == NL80211_IFTYPE_AP) { 780 if (sdata->vif.type == NL80211_IFTYPE_AP) {
734 struct ieee80211_sub_if_data *vlan, *tmpsdata; 781 struct ieee80211_sub_if_data *vlan, *tmpsdata;
735 struct beacon_data *old_beacon =
736 rtnl_dereference(sdata->u.ap.beacon);
737 struct probe_resp *old_probe_resp =
738 rtnl_dereference(sdata->u.ap.probe_resp);
739
740 /* sdata_running will return false, so this will disable */
741 ieee80211_bss_info_change_notify(sdata,
742 BSS_CHANGED_BEACON_ENABLED);
743
744 /* remove beacon and probe response */
745 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
746 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
747 synchronize_rcu();
748 kfree(old_beacon);
749 kfree(old_probe_resp);
750 782
751 /* down all dependent devices, that is VLANs */ 783 /* down all dependent devices, that is VLANs */
752 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans, 784 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
753 u.vlan.list) 785 u.vlan.list)
754 dev_close(vlan->dev); 786 dev_close(vlan->dev);
755 WARN_ON(!list_empty(&sdata->u.ap.vlans)); 787 WARN_ON(!list_empty(&sdata->u.ap.vlans));
756
757 /* free all potentially still buffered bcast frames */
758 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps_bc_buf);
759 skb_queue_purge(&sdata->u.ap.ps_bc_buf);
760 } else if (sdata->vif.type == NL80211_IFTYPE_STATION) { 788 } else if (sdata->vif.type == NL80211_IFTYPE_STATION) {
761 ieee80211_mgd_stop(sdata); 789 ieee80211_mgd_stop(sdata);
762 } 790 }
@@ -837,14 +865,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
837 hw_reconf_flags = 0; 865 hw_reconf_flags = 0;
838 } 866 }
839 867
840 /* Re-calculate channel-type, in case there are multiple vifs
841 * on different channel types.
842 */
843 orig_ct = local->_oper_channel_type;
844 ieee80211_set_channel_type(local, NULL, NL80211_CHAN_NO_HT);
845
846 /* do after stop to avoid reconfiguring when we stop anyway */ 868 /* do after stop to avoid reconfiguring when we stop anyway */
847 if (hw_reconf_flags || (orig_ct != local->_oper_channel_type)) 869 if (hw_reconf_flags)
848 ieee80211_hw_config(local, hw_reconf_flags); 870 ieee80211_hw_config(local, hw_reconf_flags);
849 871
850 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 872 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
@@ -853,7 +875,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
853 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 875 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
854 if (info->control.vif == &sdata->vif) { 876 if (info->control.vif == &sdata->vif) {
855 __skb_unlink(skb, &local->pending[i]); 877 __skb_unlink(skb, &local->pending[i]);
856 dev_kfree_skb_irq(skb); 878 ieee80211_free_txskb(&local->hw, skb);
857 } 879 }
858 } 880 }
859 } 881 }
@@ -1121,6 +1143,13 @@ static void ieee80211_iface_work(struct work_struct *work)
1121 } 1143 }
1122} 1144}
1123 1145
1146static void ieee80211_recalc_smps_work(struct work_struct *work)
1147{
1148 struct ieee80211_sub_if_data *sdata =
1149 container_of(work, struct ieee80211_sub_if_data, recalc_smps);
1150
1151 ieee80211_recalc_smps(sdata);
1152}
1124 1153
1125/* 1154/*
1126 * Helper function to initialise an interface to a specific type. 1155 * Helper function to initialise an interface to a specific type.
@@ -1149,6 +1178,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1149 1178
1150 skb_queue_head_init(&sdata->skb_queue); 1179 skb_queue_head_init(&sdata->skb_queue);
1151 INIT_WORK(&sdata->work, ieee80211_iface_work); 1180 INIT_WORK(&sdata->work, ieee80211_iface_work);
1181 INIT_WORK(&sdata->recalc_smps, ieee80211_recalc_smps_work);
1152 1182
1153 switch (type) { 1183 switch (type) {
1154 case NL80211_IFTYPE_P2P_GO: 1184 case NL80211_IFTYPE_P2P_GO:
@@ -1157,7 +1187,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1157 sdata->vif.p2p = true; 1187 sdata->vif.p2p = true;
1158 /* fall through */ 1188 /* fall through */
1159 case NL80211_IFTYPE_AP: 1189 case NL80211_IFTYPE_AP:
1160 skb_queue_head_init(&sdata->u.ap.ps_bc_buf); 1190 skb_queue_head_init(&sdata->u.ap.ps.bc_buf);
1161 INIT_LIST_HEAD(&sdata->u.ap.vlans); 1191 INIT_LIST_HEAD(&sdata->u.ap.vlans);
1162 break; 1192 break;
1163 case NL80211_IFTYPE_P2P_CLIENT: 1193 case NL80211_IFTYPE_P2P_CLIENT:
@@ -1282,11 +1312,6 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
1282 if (type == ieee80211_vif_type_p2p(&sdata->vif)) 1312 if (type == ieee80211_vif_type_p2p(&sdata->vif))
1283 return 0; 1313 return 0;
1284 1314
1285 /* Setting ad-hoc mode on non-IBSS channel is not supported. */
1286 if (sdata->local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS &&
1287 type == NL80211_IFTYPE_ADHOC)
1288 return -EOPNOTSUPP;
1289
1290 if (ieee80211_sdata_running(sdata)) { 1315 if (ieee80211_sdata_running(sdata)) {
1291 ret = ieee80211_runtime_change_iftype(sdata, type); 1316 ret = ieee80211_runtime_change_iftype(sdata, type);
1292 if (ret) 1317 if (ret)
@@ -1298,9 +1323,6 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
1298 } 1323 }
1299 1324
1300 /* reset some values that shouldn't be kept across type changes */ 1325 /* reset some values that shouldn't be kept across type changes */
1301 sdata->vif.bss_conf.basic_rates =
1302 ieee80211_mandatory_rates(sdata->local,
1303 sdata->local->oper_channel->band);
1304 sdata->drop_unencrypted = 0; 1326 sdata->drop_unencrypted = 0;
1305 if (type == NL80211_IFTYPE_STATION) 1327 if (type == NL80211_IFTYPE_STATION)
1306 sdata->u.mgd.use_4addr = false; 1328 sdata->u.mgd.use_4addr = false;
@@ -1523,6 +1545,9 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1523 1545
1524 ieee80211_set_default_queues(sdata); 1546 ieee80211_set_default_queues(sdata);
1525 1547
1548 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
1549 sdata->user_power_level = local->user_power_level;
1550
1526 /* setup type-dependent data */ 1551 /* setup type-dependent data */
1527 ieee80211_setup_sdata(sdata, type); 1552 ieee80211_setup_sdata(sdata, type);
1528 1553
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index c80c4490351c..da2f41610125 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -93,15 +93,15 @@ static void ieee80211_reconfig_filter(struct work_struct *work)
93 ieee80211_configure_filter(local); 93 ieee80211_configure_filter(local);
94} 94}
95 95
96int ieee80211_hw_config(struct ieee80211_local *local, u32 changed) 96static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
97{ 97{
98 struct ieee80211_sub_if_data *sdata;
98 struct ieee80211_channel *chan; 99 struct ieee80211_channel *chan;
99 int ret = 0; 100 u32 changed = 0;
100 int power; 101 int power;
101 enum nl80211_channel_type channel_type; 102 enum nl80211_channel_type channel_type;
102 u32 offchannel_flag; 103 u32 offchannel_flag;
103 104 bool scanning = false;
104 might_sleep();
105 105
106 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL; 106 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
107 if (local->scan_channel) { 107 if (local->scan_channel) {
@@ -109,7 +109,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
109 /* If scanning on oper channel, use whatever channel-type 109 /* If scanning on oper channel, use whatever channel-type
110 * is currently in use. 110 * is currently in use.
111 */ 111 */
112 if (chan == local->oper_channel) 112 if (chan == local->_oper_channel)
113 channel_type = local->_oper_channel_type; 113 channel_type = local->_oper_channel_type;
114 else 114 else
115 channel_type = NL80211_CHAN_NO_HT; 115 channel_type = NL80211_CHAN_NO_HT;
@@ -117,11 +117,11 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
117 chan = local->tmp_channel; 117 chan = local->tmp_channel;
118 channel_type = local->tmp_channel_type; 118 channel_type = local->tmp_channel_type;
119 } else { 119 } else {
120 chan = local->oper_channel; 120 chan = local->_oper_channel;
121 channel_type = local->_oper_channel_type; 121 channel_type = local->_oper_channel_type;
122 } 122 }
123 123
124 if (chan != local->oper_channel || 124 if (chan != local->_oper_channel ||
125 channel_type != local->_oper_channel_type) 125 channel_type != local->_oper_channel_type)
126 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL; 126 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
127 else 127 else
@@ -148,22 +148,39 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
148 changed |= IEEE80211_CONF_CHANGE_SMPS; 148 changed |= IEEE80211_CONF_CHANGE_SMPS;
149 } 149 }
150 150
151 if (test_bit(SCAN_SW_SCANNING, &local->scanning) || 151 scanning = test_bit(SCAN_SW_SCANNING, &local->scanning) ||
152 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning) || 152 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning) ||
153 test_bit(SCAN_HW_SCANNING, &local->scanning) || 153 test_bit(SCAN_HW_SCANNING, &local->scanning);
154 !local->ap_power_level) 154 power = chan->max_power;
155 power = chan->max_power;
156 else
157 power = min(chan->max_power, local->ap_power_level);
158 155
159 if (local->user_power_level >= 0) 156 rcu_read_lock();
160 power = min(power, local->user_power_level); 157 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
158 if (!rcu_access_pointer(sdata->vif.chanctx_conf))
159 continue;
160 power = min(power, sdata->vif.bss_conf.txpower);
161 }
162 rcu_read_unlock();
161 163
162 if (local->hw.conf.power_level != power) { 164 if (local->hw.conf.power_level != power) {
163 changed |= IEEE80211_CONF_CHANGE_POWER; 165 changed |= IEEE80211_CONF_CHANGE_POWER;
164 local->hw.conf.power_level = power; 166 local->hw.conf.power_level = power;
165 } 167 }
166 168
169 return changed;
170}
171
172int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
173{
174 int ret = 0;
175
176 might_sleep();
177
178 if (!local->use_chanctx)
179 changed |= ieee80211_hw_conf_chan(local);
180 else
181 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
182 IEEE80211_CONF_CHANGE_POWER);
183
167 if (changed && local->open_count) { 184 if (changed && local->open_count) {
168 ret = drv_config(local, changed); 185 ret = drv_config(local, changed);
169 /* 186 /*
@@ -359,14 +376,6 @@ void ieee80211_restart_hw(struct ieee80211_hw *hw)
359} 376}
360EXPORT_SYMBOL(ieee80211_restart_hw); 377EXPORT_SYMBOL(ieee80211_restart_hw);
361 378
362static void ieee80211_recalc_smps_work(struct work_struct *work)
363{
364 struct ieee80211_local *local =
365 container_of(work, struct ieee80211_local, recalc_smps);
366
367 ieee80211_recalc_smps(local);
368}
369
370#ifdef CONFIG_INET 379#ifdef CONFIG_INET
371static int ieee80211_ifa_changed(struct notifier_block *nb, 380static int ieee80211_ifa_changed(struct notifier_block *nb,
372 unsigned long data, void *arg) 381 unsigned long data, void *arg)
@@ -540,6 +549,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
540 struct ieee80211_local *local; 549 struct ieee80211_local *local;
541 int priv_size, i; 550 int priv_size, i;
542 struct wiphy *wiphy; 551 struct wiphy *wiphy;
552 bool use_chanctx;
543 553
544 if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config || 554 if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
545 !ops->add_interface || !ops->remove_interface || 555 !ops->add_interface || !ops->remove_interface ||
@@ -549,6 +559,14 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
549 if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove))) 559 if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
550 return NULL; 560 return NULL;
551 561
562 /* check all or no channel context operations exist */
563 i = !!ops->add_chanctx + !!ops->remove_chanctx +
564 !!ops->change_chanctx + !!ops->assign_vif_chanctx +
565 !!ops->unassign_vif_chanctx;
566 if (WARN_ON(i != 0 && i != 5))
567 return NULL;
568 use_chanctx = i == 5;
569
552 /* Ensure 32-byte alignment of our private data and hw private data. 570 /* Ensure 32-byte alignment of our private data and hw private data.
553 * We use the wiphy priv data for both our ieee80211_local and for 571 * We use the wiphy priv data for both our ieee80211_local and for
554 * the driver's private data 572 * the driver's private data
@@ -584,8 +602,15 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
584 if (ops->remain_on_channel) 602 if (ops->remain_on_channel)
585 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 603 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
586 604
587 wiphy->features = NL80211_FEATURE_SK_TX_STATUS | 605 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
588 NL80211_FEATURE_HT_IBSS; 606 NL80211_FEATURE_SAE |
607 NL80211_FEATURE_HT_IBSS |
608 NL80211_FEATURE_VIF_TXPOWER;
609
610 if (!ops->hw_scan)
611 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
612 NL80211_FEATURE_AP_SCAN;
613
589 614
590 if (!ops->set_key) 615 if (!ops->set_key)
591 wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 616 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
@@ -599,6 +624,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
599 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN); 624 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
600 625
601 local->ops = ops; 626 local->ops = ops;
627 local->use_chanctx = use_chanctx;
602 628
603 /* set up some defaults */ 629 /* set up some defaults */
604 local->hw.queues = 1; 630 local->hw.queues = 1;
@@ -612,7 +638,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
612 local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS | 638 local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
613 IEEE80211_RADIOTAP_MCS_HAVE_GI | 639 IEEE80211_RADIOTAP_MCS_HAVE_GI |
614 IEEE80211_RADIOTAP_MCS_HAVE_BW; 640 IEEE80211_RADIOTAP_MCS_HAVE_BW;
615 local->user_power_level = -1; 641 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
616 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask; 642 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
617 643
618 INIT_LIST_HEAD(&local->interfaces); 644 INIT_LIST_HEAD(&local->interfaces);
@@ -626,6 +652,9 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
626 spin_lock_init(&local->filter_lock); 652 spin_lock_init(&local->filter_lock);
627 spin_lock_init(&local->queue_stop_reason_lock); 653 spin_lock_init(&local->queue_stop_reason_lock);
628 654
655 INIT_LIST_HEAD(&local->chanctx_list);
656 mutex_init(&local->chanctx_mtx);
657
629 /* 658 /*
630 * The rx_skb_queue is only accessed from tasklets, 659 * The rx_skb_queue is only accessed from tasklets,
631 * but other SKB queues are used from within IRQ 660 * but other SKB queues are used from within IRQ
@@ -641,7 +670,6 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
641 INIT_WORK(&local->restart_work, ieee80211_restart_work); 670 INIT_WORK(&local->restart_work, ieee80211_restart_work);
642 671
643 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter); 672 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
644 INIT_WORK(&local->recalc_smps, ieee80211_recalc_smps_work);
645 local->smps_mode = IEEE80211_SMPS_OFF; 673 local->smps_mode = IEEE80211_SMPS_OFF;
646 674
647 INIT_WORK(&local->dynamic_ps_enable_work, 675 INIT_WORK(&local->dynamic_ps_enable_work,
@@ -719,6 +747,25 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
719 if ((hw->flags & IEEE80211_HW_SCAN_WHILE_IDLE) && !local->ops->hw_scan) 747 if ((hw->flags & IEEE80211_HW_SCAN_WHILE_IDLE) && !local->ops->hw_scan)
720 return -EINVAL; 748 return -EINVAL;
721 749
750 if (!local->use_chanctx) {
751 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
752 const struct ieee80211_iface_combination *comb;
753
754 comb = &local->hw.wiphy->iface_combinations[i];
755
756 if (comb->num_different_channels > 1)
757 return -EINVAL;
758 }
759 } else {
760 /*
761 * WDS is currently prohibited when channel contexts are used
762 * because there's no clear definition of which channel WDS
763 * type interfaces use
764 */
765 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
766 return -EINVAL;
767 }
768
722 /* Only HW csum features are currently compatible with mac80211 */ 769 /* Only HW csum features are currently compatible with mac80211 */
723 feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 770 feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
724 NETIF_F_HW_CSUM; 771 NETIF_F_HW_CSUM;
@@ -728,6 +775,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
728 if (hw->max_report_rates == 0) 775 if (hw->max_report_rates == 0)
729 hw->max_report_rates = hw->max_rates; 776 hw->max_report_rates = hw->max_rates;
730 777
778 local->rx_chains = 1;
779
731 /* 780 /*
732 * generic code guarantees at least one band, 781 * generic code guarantees at least one band,
733 * set this very early because much code assumes 782 * set this very early because much code assumes
@@ -743,18 +792,29 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
743 sband = local->hw.wiphy->bands[band]; 792 sband = local->hw.wiphy->bands[band];
744 if (!sband) 793 if (!sband)
745 continue; 794 continue;
746 if (!local->oper_channel) { 795 if (!local->use_chanctx && !local->_oper_channel) {
747 /* init channel we're on */ 796 /* init channel we're on */
748 local->hw.conf.channel = 797 local->hw.conf.channel =
749 local->oper_channel = &sband->channels[0]; 798 local->_oper_channel = &sband->channels[0];
750 local->hw.conf.channel_type = NL80211_CHAN_NO_HT; 799 local->hw.conf.channel_type = NL80211_CHAN_NO_HT;
751 } 800 }
801 if (!local->monitor_channel) {
802 local->monitor_channel = &sband->channels[0];
803 local->monitor_channel_type = NL80211_CHAN_NO_HT;
804 }
752 channels += sband->n_channels; 805 channels += sband->n_channels;
753 806
754 if (max_bitrates < sband->n_bitrates) 807 if (max_bitrates < sband->n_bitrates)
755 max_bitrates = sband->n_bitrates; 808 max_bitrates = sband->n_bitrates;
756 supp_ht = supp_ht || sband->ht_cap.ht_supported; 809 supp_ht = supp_ht || sband->ht_cap.ht_supported;
757 supp_vht = supp_vht || sband->vht_cap.vht_supported; 810 supp_vht = supp_vht || sband->vht_cap.vht_supported;
811
812 if (sband->ht_cap.ht_supported)
813 local->rx_chains =
814 max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
815 local->rx_chains);
816
817 /* TODO: consider VHT for RX chains, hopefully it's the same */
758 } 818 }
759 819
760 local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) + 820 local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
@@ -778,19 +838,13 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
778 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR); 838 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
779 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR); 839 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
780 840
781 /* 841 /* mac80211 doesn't support more than one IBSS interface right now */
782 * mac80211 doesn't support more than 1 channel, and also not more
783 * than one IBSS interface
784 */
785 for (i = 0; i < hw->wiphy->n_iface_combinations; i++) { 842 for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
786 const struct ieee80211_iface_combination *c; 843 const struct ieee80211_iface_combination *c;
787 int j; 844 int j;
788 845
789 c = &hw->wiphy->iface_combinations[i]; 846 c = &hw->wiphy->iface_combinations[i];
790 847
791 if (c->num_different_channels > 1)
792 return -EINVAL;
793
794 for (j = 0; j < c->n_limits; j++) 848 for (j = 0; j < c->n_limits; j++)
795 if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) && 849 if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
796 c->limits[j].max > 1) 850 c->limits[j].max > 1)
@@ -832,7 +886,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
832 886
833 if (supp_vht) 887 if (supp_vht)
834 local->scan_ies_len += 888 local->scan_ies_len +=
835 2 + sizeof(struct ieee80211_vht_capabilities); 889 2 + sizeof(struct ieee80211_vht_cap);
836 890
837 if (!local->ops->hw_scan) { 891 if (!local->ops->hw_scan) {
838 /* For hw_scan, driver needs to set these up. */ 892 /* For hw_scan, driver needs to set these up. */
@@ -871,8 +925,10 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
871 local->hw.wiphy->cipher_suites, 925 local->hw.wiphy->cipher_suites,
872 sizeof(u32) * local->hw.wiphy->n_cipher_suites, 926 sizeof(u32) * local->hw.wiphy->n_cipher_suites,
873 GFP_KERNEL); 927 GFP_KERNEL);
874 if (!suites) 928 if (!suites) {
875 return -ENOMEM; 929 result = -ENOMEM;
930 goto fail_wiphy_register;
931 }
876 for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) { 932 for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
877 u32 suite = local->hw.wiphy->cipher_suites[r]; 933 u32 suite = local->hw.wiphy->cipher_suites[r];
878 if (suite == WLAN_CIPHER_SUITE_WEP40 || 934 if (suite == WLAN_CIPHER_SUITE_WEP40 ||
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index ff0296c7bab8..a350cab4b339 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -97,7 +97,7 @@ bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
97 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))) 97 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth)))
98 goto mismatch; 98 goto mismatch;
99 99
100 ieee80211_sta_get_rates(local, ie, local->oper_channel->band, 100 ieee80211_sta_get_rates(local, ie, ieee80211_get_sdata_band(sdata),
101 &basic_rates); 101 &basic_rates);
102 102
103 if (sdata->vif.bss_conf.basic_rates != basic_rates) 103 if (sdata->vif.bss_conf.basic_rates != basic_rates)
@@ -264,7 +264,7 @@ mesh_add_meshconf_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
264 /* Authentication Protocol identifier */ 264 /* Authentication Protocol identifier */
265 *pos++ = ifmsh->mesh_auth_id; 265 *pos++ = ifmsh->mesh_auth_id;
266 /* Mesh Formation Info - number of neighbors */ 266 /* Mesh Formation Info - number of neighbors */
267 neighbors = atomic_read(&ifmsh->mshstats.estab_plinks); 267 neighbors = atomic_read(&ifmsh->estab_plinks);
268 /* Number of neighbor mesh STAs or 15 whichever is smaller */ 268 /* Number of neighbor mesh STAs or 15 whichever is smaller */
269 neighbors = (neighbors > 15) ? 15 : neighbors; 269 neighbors = (neighbors > 15) ? 15 : neighbors;
270 *pos++ = neighbors << 1; 270 *pos++ = neighbors << 1;
@@ -355,12 +355,22 @@ int mesh_add_ds_params_ie(struct sk_buff *skb,
355{ 355{
356 struct ieee80211_local *local = sdata->local; 356 struct ieee80211_local *local = sdata->local;
357 struct ieee80211_supported_band *sband; 357 struct ieee80211_supported_band *sband;
358 struct ieee80211_channel *chan = local->oper_channel; 358 struct ieee80211_chanctx_conf *chanctx_conf;
359 struct ieee80211_channel *chan;
359 u8 *pos; 360 u8 *pos;
360 361
361 if (skb_tailroom(skb) < 3) 362 if (skb_tailroom(skb) < 3)
362 return -ENOMEM; 363 return -ENOMEM;
363 364
365 rcu_read_lock();
366 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
367 if (WARN_ON(!chanctx_conf)) {
368 rcu_read_unlock();
369 return -EINVAL;
370 }
371 chan = chanctx_conf->channel;
372 rcu_read_unlock();
373
364 sband = local->hw.wiphy->bands[chan->band]; 374 sband = local->hw.wiphy->bands[chan->band];
365 if (sband->band == IEEE80211_BAND_2GHZ) { 375 if (sband->band == IEEE80211_BAND_2GHZ) {
366 pos = skb_put(skb, 2 + 1); 376 pos = skb_put(skb, 2 + 1);
@@ -376,10 +386,11 @@ int mesh_add_ht_cap_ie(struct sk_buff *skb,
376 struct ieee80211_sub_if_data *sdata) 386 struct ieee80211_sub_if_data *sdata)
377{ 387{
378 struct ieee80211_local *local = sdata->local; 388 struct ieee80211_local *local = sdata->local;
389 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
379 struct ieee80211_supported_band *sband; 390 struct ieee80211_supported_band *sband;
380 u8 *pos; 391 u8 *pos;
381 392
382 sband = local->hw.wiphy->bands[local->oper_channel->band]; 393 sband = local->hw.wiphy->bands[band];
383 if (!sband->ht_cap.ht_supported || 394 if (!sband->ht_cap.ht_supported ||
384 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) 395 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT)
385 return 0; 396 return 0;
@@ -397,14 +408,26 @@ int mesh_add_ht_oper_ie(struct sk_buff *skb,
397 struct ieee80211_sub_if_data *sdata) 408 struct ieee80211_sub_if_data *sdata)
398{ 409{
399 struct ieee80211_local *local = sdata->local; 410 struct ieee80211_local *local = sdata->local;
400 struct ieee80211_channel *channel = local->oper_channel; 411 struct ieee80211_chanctx_conf *chanctx_conf;
412 struct ieee80211_channel *channel;
401 enum nl80211_channel_type channel_type = 413 enum nl80211_channel_type channel_type =
402 sdata->vif.bss_conf.channel_type; 414 sdata->vif.bss_conf.channel_type;
403 struct ieee80211_supported_band *sband = 415 struct ieee80211_supported_band *sband;
404 local->hw.wiphy->bands[channel->band]; 416 struct ieee80211_sta_ht_cap *ht_cap;
405 struct ieee80211_sta_ht_cap *ht_cap = &sband->ht_cap;
406 u8 *pos; 417 u8 *pos;
407 418
419 rcu_read_lock();
420 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
421 if (WARN_ON(!chanctx_conf)) {
422 rcu_read_unlock();
423 return -EINVAL;
424 }
425 channel = chanctx_conf->channel;
426 rcu_read_unlock();
427
428 sband = local->hw.wiphy->bands[channel->band];
429 ht_cap = &sband->ht_cap;
430
408 if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT) 431 if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT)
409 return 0; 432 return 0;
410 433
@@ -610,7 +633,7 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
610 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL; 633 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
611 sdata->vif.bss_conf.basic_rates = 634 sdata->vif.bss_conf.basic_rates =
612 ieee80211_mandatory_rates(sdata->local, 635 ieee80211_mandatory_rates(sdata->local,
613 sdata->local->oper_channel->band); 636 ieee80211_get_sdata_band(sdata));
614 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON | 637 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
615 BSS_CHANGED_BEACON_ENABLED | 638 BSS_CHANGED_BEACON_ENABLED |
616 BSS_CHANGED_HT | 639 BSS_CHANGED_HT |
@@ -680,8 +703,10 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
680 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, 703 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
681 &elems); 704 &elems);
682 705
683 /* ignore beacons from secure mesh peers if our security is off */ 706 /* ignore non-mesh or secure / unsecure mismatch */
684 if (elems.rsn_len && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) 707 if ((!elems.mesh_id || !elems.mesh_config) ||
708 (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
709 (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
685 return; 710 return;
686 711
687 if (elems.ds_params && elems.ds_params_len == 1) 712 if (elems.ds_params && elems.ds_params_len == 1)
@@ -694,8 +719,7 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
694 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) 719 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
695 return; 720 return;
696 721
697 if (elems.mesh_id && elems.mesh_config && 722 if (mesh_matches_local(sdata, &elems))
698 mesh_matches_local(sdata, &elems))
699 mesh_neighbour_update(sdata, mgmt->sa, &elems); 723 mesh_neighbour_update(sdata, mgmt->sa, &elems);
700 724
701 if (ifmsh->sync_ops) 725 if (ifmsh->sync_ops)
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index 25d0f17dec71..9285f3f67e66 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -256,7 +256,7 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
256void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata); 256void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
257void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata); 257void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
258void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh); 258void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh);
259struct ieee80211_mesh_sync_ops *ieee80211_mesh_sync_ops_get(u8 method); 259const struct ieee80211_mesh_sync_ops *ieee80211_mesh_sync_ops_get(u8 method);
260 260
261/* Mesh paths */ 261/* Mesh paths */
262int mesh_nexthop_lookup(struct sk_buff *skb, 262int mesh_nexthop_lookup(struct sk_buff *skb,
@@ -324,7 +324,7 @@ extern int mesh_allocated;
324static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata) 324static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
325{ 325{
326 return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks - 326 return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks -
327 atomic_read(&sdata->u.mesh.mshstats.estab_plinks); 327 atomic_read(&sdata->u.mesh.estab_plinks);
328} 328}
329 329
330static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata) 330static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata)
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 3ab34d816897..234fe755968b 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -50,14 +50,14 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
50static inline 50static inline
51u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata) 51u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
52{ 52{
53 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks); 53 atomic_inc(&sdata->u.mesh.estab_plinks);
54 return mesh_accept_plinks_update(sdata); 54 return mesh_accept_plinks_update(sdata);
55} 55}
56 56
57static inline 57static inline
58u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata) 58u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
59{ 59{
60 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks); 60 atomic_dec(&sdata->u.mesh.estab_plinks);
61 return mesh_accept_plinks_update(sdata); 61 return mesh_accept_plinks_update(sdata);
62} 62}
63 63
@@ -252,6 +252,8 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
252 mgmt->u.action.u.self_prot.action_code = action; 252 mgmt->u.action.u.self_prot.action_code = action;
253 253
254 if (action != WLAN_SP_MESH_PEERING_CLOSE) { 254 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
255 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
256
255 /* capability info */ 257 /* capability info */
256 pos = skb_put(skb, 2); 258 pos = skb_put(skb, 2);
257 memset(pos, 0, 2); 259 memset(pos, 0, 2);
@@ -260,10 +262,8 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
260 pos = skb_put(skb, 2); 262 pos = skb_put(skb, 2);
261 memcpy(pos + 2, &plid, 2); 263 memcpy(pos + 2, &plid, 2);
262 } 264 }
263 if (ieee80211_add_srates_ie(sdata, skb, true, 265 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
264 local->oper_channel->band) || 266 ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
265 ieee80211_add_ext_srates_ie(sdata, skb, true,
266 local->oper_channel->band) ||
267 mesh_add_rsn_ie(skb, sdata) || 267 mesh_add_rsn_ie(skb, sdata) ||
268 mesh_add_meshid_ie(skb, sdata) || 268 mesh_add_meshid_ie(skb, sdata) ||
269 mesh_add_meshconf_ie(skb, sdata)) 269 mesh_add_meshconf_ie(skb, sdata))
@@ -343,7 +343,7 @@ static struct sta_info *mesh_peer_init(struct ieee80211_sub_if_data *sdata,
343 struct ieee802_11_elems *elems) 343 struct ieee802_11_elems *elems)
344{ 344{
345 struct ieee80211_local *local = sdata->local; 345 struct ieee80211_local *local = sdata->local;
346 enum ieee80211_band band = local->oper_channel->band; 346 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
347 struct ieee80211_supported_band *sband; 347 struct ieee80211_supported_band *sband;
348 u32 rates, basic_rates = 0; 348 u32 rates, basic_rates = 0;
349 struct sta_info *sta; 349 struct sta_info *sta;
diff --git a/net/mac80211/mesh_sync.c b/net/mac80211/mesh_sync.c
index a16b7b4b1e02..407c8705e10d 100644
--- a/net/mac80211/mesh_sync.c
+++ b/net/mac80211/mesh_sync.c
@@ -234,49 +234,7 @@ static void mesh_sync_offset_adjust_tbtt(struct ieee80211_sub_if_data *sdata)
234 spin_unlock_bh(&ifmsh->sync_offset_lock); 234 spin_unlock_bh(&ifmsh->sync_offset_lock);
235} 235}
236 236
237static const u8 *mesh_get_vendor_oui(struct ieee80211_sub_if_data *sdata) 237static const struct sync_method sync_methods[] = {
238{
239 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
240 u8 offset;
241
242 if (!ifmsh->ie || !ifmsh->ie_len)
243 return NULL;
244
245 offset = ieee80211_ie_split_vendor(ifmsh->ie,
246 ifmsh->ie_len, 0);
247
248 if (!offset)
249 return NULL;
250
251 return ifmsh->ie + offset + 2;
252}
253
254static void mesh_sync_vendor_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
255 u16 stype,
256 struct ieee80211_mgmt *mgmt,
257 struct ieee802_11_elems *elems,
258 struct ieee80211_rx_status *rx_status)
259{
260 const u8 *oui;
261
262 WARN_ON(sdata->u.mesh.mesh_sp_id != IEEE80211_SYNC_METHOD_VENDOR);
263 msync_dbg(sdata, "called mesh_sync_vendor_rx_bcn_presp\n");
264 oui = mesh_get_vendor_oui(sdata);
265 /* here you would implement the vendor offset tracking for this oui */
266}
267
268static void mesh_sync_vendor_adjust_tbtt(struct ieee80211_sub_if_data *sdata)
269{
270 const u8 *oui;
271
272 WARN_ON(sdata->u.mesh.mesh_sp_id != IEEE80211_SYNC_METHOD_VENDOR);
273 msync_dbg(sdata, "called mesh_sync_vendor_adjust_tbtt\n");
274 oui = mesh_get_vendor_oui(sdata);
275 /* here you would implement the vendor tsf adjustment for this oui */
276}
277
278/* global variable */
279static struct sync_method sync_methods[] = {
280 { 238 {
281 .method = IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET, 239 .method = IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET,
282 .ops = { 240 .ops = {
@@ -284,18 +242,11 @@ static struct sync_method sync_methods[] = {
284 .adjust_tbtt = &mesh_sync_offset_adjust_tbtt, 242 .adjust_tbtt = &mesh_sync_offset_adjust_tbtt,
285 } 243 }
286 }, 244 },
287 {
288 .method = IEEE80211_SYNC_METHOD_VENDOR,
289 .ops = {
290 .rx_bcn_presp = &mesh_sync_vendor_rx_bcn_presp,
291 .adjust_tbtt = &mesh_sync_vendor_adjust_tbtt,
292 }
293 },
294}; 245};
295 246
296struct ieee80211_mesh_sync_ops *ieee80211_mesh_sync_ops_get(u8 method) 247const struct ieee80211_mesh_sync_ops *ieee80211_mesh_sync_ops_get(u8 method)
297{ 248{
298 struct ieee80211_mesh_sync_ops *ops = NULL; 249 const struct ieee80211_mesh_sync_ops *ops = NULL;
299 u8 i; 250 u8 i;
300 251
301 for (i = 0 ; i < ARRAY_SIZE(sync_methods); ++i) { 252 for (i = 0 ; i < ARRAY_SIZE(sync_methods); ++i) {
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index e714ed8bb198..61614461e089 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -178,20 +178,30 @@ static u32 ieee80211_config_ht_tx(struct ieee80211_sub_if_data *sdata,
178{ 178{
179 struct ieee80211_local *local = sdata->local; 179 struct ieee80211_local *local = sdata->local;
180 struct ieee80211_supported_band *sband; 180 struct ieee80211_supported_band *sband;
181 struct ieee80211_chanctx_conf *chanctx_conf;
182 struct ieee80211_channel *chan;
181 struct sta_info *sta; 183 struct sta_info *sta;
182 u32 changed = 0; 184 u32 changed = 0;
183 u16 ht_opmode; 185 u16 ht_opmode;
184 bool disable_40 = false; 186 bool disable_40 = false;
185 187
186 sband = local->hw.wiphy->bands[local->oper_channel->band]; 188 rcu_read_lock();
189 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
190 if (WARN_ON(!chanctx_conf)) {
191 rcu_read_unlock();
192 return 0;
193 }
194 chan = chanctx_conf->channel;
195 rcu_read_unlock();
196 sband = local->hw.wiphy->bands[chan->band];
187 197
188 switch (sdata->vif.bss_conf.channel_type) { 198 switch (sdata->vif.bss_conf.channel_type) {
189 case NL80211_CHAN_HT40PLUS: 199 case NL80211_CHAN_HT40PLUS:
190 if (local->oper_channel->flags & IEEE80211_CHAN_NO_HT40PLUS) 200 if (chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
191 disable_40 = true; 201 disable_40 = true;
192 break; 202 break;
193 case NL80211_CHAN_HT40MINUS: 203 case NL80211_CHAN_HT40MINUS:
194 if (local->oper_channel->flags & IEEE80211_CHAN_NO_HT40MINUS) 204 if (chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
195 disable_40 = true; 205 disable_40 = true;
196 break; 206 break;
197 default: 207 default:
@@ -343,7 +353,7 @@ static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
343 cap = vht_cap.cap; 353 cap = vht_cap.cap;
344 354
345 /* reserve and fill IE */ 355 /* reserve and fill IE */
346 pos = skb_put(skb, sizeof(struct ieee80211_vht_capabilities) + 2); 356 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
347 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); 357 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
348} 358}
349 359
@@ -359,11 +369,21 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
359 int i, count, rates_len, supp_rates_len; 369 int i, count, rates_len, supp_rates_len;
360 u16 capab; 370 u16 capab;
361 struct ieee80211_supported_band *sband; 371 struct ieee80211_supported_band *sband;
372 struct ieee80211_chanctx_conf *chanctx_conf;
373 struct ieee80211_channel *chan;
362 u32 rates = 0; 374 u32 rates = 0;
363 375
364 lockdep_assert_held(&ifmgd->mtx); 376 lockdep_assert_held(&ifmgd->mtx);
365 377
366 sband = local->hw.wiphy->bands[local->oper_channel->band]; 378 rcu_read_lock();
379 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
380 if (WARN_ON(!chanctx_conf)) {
381 rcu_read_unlock();
382 return;
383 }
384 chan = chanctx_conf->channel;
385 rcu_read_unlock();
386 sband = local->hw.wiphy->bands[chan->band];
367 387
368 if (assoc_data->supp_rates_len) { 388 if (assoc_data->supp_rates_len) {
369 /* 389 /*
@@ -392,7 +412,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
392 4 + /* power capability */ 412 4 + /* power capability */
393 2 + 2 * sband->n_channels + /* supported channels */ 413 2 + 2 * sband->n_channels + /* supported channels */
394 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ 414 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
395 2 + sizeof(struct ieee80211_vht_capabilities) + /* VHT */ 415 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
396 assoc_data->ie_len + /* extra IEs */ 416 assoc_data->ie_len + /* extra IEs */
397 9, /* WMM */ 417 9, /* WMM */
398 GFP_KERNEL); 418 GFP_KERNEL);
@@ -485,7 +505,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
485 *pos++ = WLAN_EID_PWR_CAPABILITY; 505 *pos++ = WLAN_EID_PWR_CAPABILITY;
486 *pos++ = 2; 506 *pos++ = 2;
487 *pos++ = 0; /* min tx power */ 507 *pos++ = 0; /* min tx power */
488 *pos++ = local->oper_channel->max_power; /* max tx power */ 508 *pos++ = chan->max_power; /* max tx power */
489 509
490 /* 2. supported channels */ 510 /* 2. supported channels */
491 /* TODO: get this in reg domain format */ 511 /* TODO: get this in reg domain format */
@@ -523,7 +543,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
523 543
524 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) 544 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
525 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, 545 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
526 sband, local->oper_channel, ifmgd->ap_smps); 546 sband, chan, sdata->smps_mode);
527 547
528 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) 548 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
529 ieee80211_add_vht_ie(sdata, skb, sband); 549 ieee80211_add_vht_ie(sdata, skb, sband);
@@ -657,18 +677,18 @@ static void ieee80211_chswitch_work(struct work_struct *work)
657 if (!ifmgd->associated) 677 if (!ifmgd->associated)
658 goto out; 678 goto out;
659 679
660 sdata->local->oper_channel = sdata->local->csa_channel; 680 sdata->local->_oper_channel = sdata->local->csa_channel;
661 if (!sdata->local->ops->channel_switch) { 681 if (!sdata->local->ops->channel_switch) {
662 /* call "hw_config" only if doing sw channel switch */ 682 /* call "hw_config" only if doing sw channel switch */
663 ieee80211_hw_config(sdata->local, 683 ieee80211_hw_config(sdata->local,
664 IEEE80211_CONF_CHANGE_CHANNEL); 684 IEEE80211_CONF_CHANGE_CHANNEL);
665 } else { 685 } else {
666 /* update the device channel directly */ 686 /* update the device channel directly */
667 sdata->local->hw.conf.channel = sdata->local->oper_channel; 687 sdata->local->hw.conf.channel = sdata->local->_oper_channel;
668 } 688 }
669 689
670 /* XXX: shouldn't really modify cfg80211-owned data! */ 690 /* XXX: shouldn't really modify cfg80211-owned data! */
671 ifmgd->associated->channel = sdata->local->oper_channel; 691 ifmgd->associated->channel = sdata->local->_oper_channel;
672 692
673 /* XXX: wait for a beacon first? */ 693 /* XXX: wait for a beacon first? */
674 ieee80211_wake_queues_by_reason(&sdata->local->hw, 694 ieee80211_wake_queues_by_reason(&sdata->local->hw,
@@ -680,11 +700,8 @@ static void ieee80211_chswitch_work(struct work_struct *work)
680 700
681void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) 701void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
682{ 702{
683 struct ieee80211_sub_if_data *sdata; 703 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
684 struct ieee80211_if_managed *ifmgd; 704 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
685
686 sdata = vif_to_sdata(vif);
687 ifmgd = &sdata->u.mgd;
688 705
689 trace_api_chswitch_done(sdata, success); 706 trace_api_chswitch_done(sdata, success);
690 if (!success) { 707 if (!success) {
@@ -723,6 +740,7 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
723 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 740 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
724 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num, 741 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
725 cbss->channel->band); 742 cbss->channel->band);
743 struct ieee80211_chanctx *chanctx;
726 744
727 ASSERT_MGD_MTX(ifmgd); 745 ASSERT_MGD_MTX(ifmgd);
728 746
@@ -748,10 +766,34 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
748 return; 766 return;
749 } 767 }
750 768
751 sdata->local->csa_channel = new_ch;
752
753 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; 769 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
754 770
771 if (sdata->local->use_chanctx) {
772 sdata_info(sdata,
773 "not handling channel switch with channel contexts\n");
774 ieee80211_queue_work(&sdata->local->hw,
775 &ifmgd->csa_connection_drop_work);
776 }
777
778 mutex_lock(&sdata->local->chanctx_mtx);
779 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
780 mutex_unlock(&sdata->local->chanctx_mtx);
781 return;
782 }
783 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
784 struct ieee80211_chanctx, conf);
785 if (chanctx->refcount > 1) {
786 sdata_info(sdata,
787 "channel switch with multiple interfaces on the same channel, disconnecting\n");
788 ieee80211_queue_work(&sdata->local->hw,
789 &ifmgd->csa_connection_drop_work);
790 mutex_unlock(&sdata->local->chanctx_mtx);
791 return;
792 }
793 mutex_unlock(&sdata->local->chanctx_mtx);
794
795 sdata->local->csa_channel = new_ch;
796
755 if (sw_elem->mode) 797 if (sw_elem->mode)
756 ieee80211_stop_queues_by_reason(&sdata->local->hw, 798 ieee80211_stop_queues_by_reason(&sdata->local->hw,
757 IEEE80211_QUEUE_STOP_REASON_CSA); 799 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -778,10 +820,10 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
778 cbss->beacon_interval)); 820 cbss->beacon_interval));
779} 821}
780 822
781static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, 823static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
782 struct ieee80211_channel *channel, 824 struct ieee80211_channel *channel,
783 const u8 *country_ie, u8 country_ie_len, 825 const u8 *country_ie, u8 country_ie_len,
784 const u8 *pwr_constr_elem) 826 const u8 *pwr_constr_elem)
785{ 827{
786 struct ieee80211_country_ie_triplet *triplet; 828 struct ieee80211_country_ie_triplet *triplet;
787 int chan = ieee80211_frequency_to_channel(channel->center_freq); 829 int chan = ieee80211_frequency_to_channel(channel->center_freq);
@@ -790,7 +832,7 @@ static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
790 832
791 /* Invalid IE */ 833 /* Invalid IE */
792 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) 834 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
793 return; 835 return 0;
794 836
795 triplet = (void *)(country_ie + 3); 837 triplet = (void *)(country_ie + 3);
796 country_ie_len -= 3; 838 country_ie_len -= 3;
@@ -831,19 +873,21 @@ static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
831 } 873 }
832 874
833 if (!have_chan_pwr) 875 if (!have_chan_pwr)
834 return; 876 return 0;
835 877
836 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem); 878 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
837 879
838 if (sdata->local->ap_power_level == new_ap_level) 880 if (sdata->ap_power_level == new_ap_level)
839 return; 881 return 0;
840 882
841 sdata_info(sdata, 883 sdata_info(sdata,
842 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", 884 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
843 new_ap_level, chan_pwr, *pwr_constr_elem, 885 new_ap_level, chan_pwr, *pwr_constr_elem,
844 sdata->u.mgd.bssid); 886 sdata->u.mgd.bssid);
845 sdata->local->ap_power_level = new_ap_level; 887 sdata->ap_power_level = new_ap_level;
846 ieee80211_hw_config(sdata->local, 0); 888 if (__ieee80211_recalc_txpower(sdata))
889 return BSS_CHANGED_TXPOWER;
890 return 0;
847} 891}
848 892
849void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif) 893void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
@@ -1280,7 +1324,7 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1280 } 1324 }
1281 1325
1282 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 1326 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
1283 if (sdata->local->oper_channel->band == IEEE80211_BAND_5GHZ) 1327 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
1284 use_short_slot = true; 1328 use_short_slot = true;
1285 1329
1286 if (use_protection != bss_conf->use_cts_prot) { 1330 if (use_protection != bss_conf->use_cts_prot) {
@@ -1321,6 +1365,22 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1321 1365
1322 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; 1366 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1323 1367
1368 if (sdata->vif.p2p) {
1369 u8 noa[2];
1370 int ret;
1371
1372 ret = cfg80211_get_p2p_attr(cbss->information_elements,
1373 cbss->len_information_elements,
1374 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1375 noa, sizeof(noa));
1376 if (ret >= 2) {
1377 bss_conf->p2p_oppps = noa[1] & 0x80;
1378 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
1379 bss_info_changed |= BSS_CHANGED_P2P_PS;
1380 sdata->u.mgd.p2p_noa_index = noa[0];
1381 }
1382 }
1383
1324 /* just to be sure */ 1384 /* just to be sure */
1325 ieee80211_stop_poll(sdata); 1385 ieee80211_stop_poll(sdata);
1326 1386
@@ -1350,7 +1410,7 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1350 ieee80211_recalc_ps(local, -1); 1410 ieee80211_recalc_ps(local, -1);
1351 mutex_unlock(&local->iflist_mtx); 1411 mutex_unlock(&local->iflist_mtx);
1352 1412
1353 ieee80211_recalc_smps(local); 1413 ieee80211_recalc_smps(sdata);
1354 ieee80211_recalc_ps_vif(sdata); 1414 ieee80211_recalc_ps_vif(sdata);
1355 1415
1356 netif_tx_start_all_queues(sdata->dev); 1416 netif_tx_start_all_queues(sdata->dev);
@@ -1443,11 +1503,14 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1443 changed |= BSS_CHANGED_ASSOC; 1503 changed |= BSS_CHANGED_ASSOC;
1444 sdata->vif.bss_conf.assoc = false; 1504 sdata->vif.bss_conf.assoc = false;
1445 1505
1506 sdata->vif.bss_conf.p2p_ctwindow = 0;
1507 sdata->vif.bss_conf.p2p_oppps = false;
1508
1446 /* on the next assoc, re-program HT parameters */ 1509 /* on the next assoc, re-program HT parameters */
1447 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); 1510 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1448 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); 1511 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
1449 1512
1450 local->ap_power_level = 0; 1513 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
1451 1514
1452 del_timer_sync(&local->dynamic_ps_timer); 1515 del_timer_sync(&local->dynamic_ps_timer);
1453 cancel_work_sync(&local->dynamic_ps_enable_work); 1516 cancel_work_sync(&local->dynamic_ps_enable_work);
@@ -1465,9 +1528,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1465 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; 1528 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
1466 ieee80211_bss_info_change_notify(sdata, changed); 1529 ieee80211_bss_info_change_notify(sdata, changed);
1467 1530
1468 /* channel(_type) changes are handled by ieee80211_hw_config */ 1531 ieee80211_vif_release_channel(sdata);
1469 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
1470 ieee80211_hw_config(local, 0);
1471 1532
1472 /* disassociated - set to defaults now */ 1533 /* disassociated - set to defaults now */
1473 ieee80211_set_wmm_default(sdata, false); 1534 ieee80211_set_wmm_default(sdata, false);
@@ -1589,7 +1650,7 @@ static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1589 1650
1590 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL, 1651 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
1591 0, (u32) -1, true, false, 1652 0, (u32) -1, true, false,
1592 ifmgd->associated->channel); 1653 ifmgd->associated->channel, false);
1593 } 1654 }
1594 1655
1595 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); 1656 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
@@ -1692,8 +1753,7 @@ struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1692 ssid_len = ssid[1]; 1753 ssid_len = ssid[1];
1693 1754
1694 skb = ieee80211_build_probe_req(sdata, cbss->bssid, 1755 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
1695 (u32) -1, 1756 (u32) -1, cbss->channel,
1696 sdata->local->oper_channel,
1697 ssid + 2, ssid_len, 1757 ssid + 2, ssid_len,
1698 NULL, 0, true); 1758 NULL, 0, true);
1699 1759
@@ -1804,6 +1864,7 @@ static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
1804 1864
1805 memset(sdata->u.mgd.bssid, 0, ETH_ALEN); 1865 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
1806 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); 1866 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
1867 ieee80211_vif_release_channel(sdata);
1807 } 1868 }
1808 1869
1809 cfg80211_put_bss(auth_data->bss); 1870 cfg80211_put_bss(auth_data->bss);
@@ -1824,7 +1885,7 @@ static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1824 return; 1885 return;
1825 auth_data->expected_transaction = 4; 1886 auth_data->expected_transaction = 4;
1826 drv_mgd_prepare_tx(sdata->local, sdata); 1887 drv_mgd_prepare_tx(sdata->local, sdata);
1827 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 1888 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
1828 elems.challenge - 2, elems.challenge_len + 2, 1889 elems.challenge - 2, elems.challenge_len + 2,
1829 auth_data->bss->bssid, auth_data->bss->bssid, 1890 auth_data->bss->bssid, auth_data->bss->bssid,
1830 auth_data->key, auth_data->key_len, 1891 auth_data->key, auth_data->key_len,
@@ -1858,8 +1919,13 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1858 status_code = le16_to_cpu(mgmt->u.auth.status_code); 1919 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1859 1920
1860 if (auth_alg != ifmgd->auth_data->algorithm || 1921 if (auth_alg != ifmgd->auth_data->algorithm ||
1861 auth_transaction != ifmgd->auth_data->expected_transaction) 1922 auth_transaction != ifmgd->auth_data->expected_transaction) {
1923 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
1924 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
1925 auth_transaction,
1926 ifmgd->auth_data->expected_transaction);
1862 return RX_MGMT_NONE; 1927 return RX_MGMT_NONE;
1928 }
1863 1929
1864 if (status_code != WLAN_STATUS_SUCCESS) { 1930 if (status_code != WLAN_STATUS_SUCCESS) {
1865 sdata_info(sdata, "%pM denied authentication (status %d)\n", 1931 sdata_info(sdata, "%pM denied authentication (status %d)\n",
@@ -1872,6 +1938,7 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1872 case WLAN_AUTH_OPEN: 1938 case WLAN_AUTH_OPEN:
1873 case WLAN_AUTH_LEAP: 1939 case WLAN_AUTH_LEAP:
1874 case WLAN_AUTH_FT: 1940 case WLAN_AUTH_FT:
1941 case WLAN_AUTH_SAE:
1875 break; 1942 break;
1876 case WLAN_AUTH_SHARED_KEY: 1943 case WLAN_AUTH_SHARED_KEY:
1877 if (ifmgd->auth_data->expected_transaction != 4) { 1944 if (ifmgd->auth_data->expected_transaction != 4) {
@@ -1891,6 +1958,15 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1891 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; 1958 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
1892 run_again(ifmgd, ifmgd->auth_data->timeout); 1959 run_again(ifmgd, ifmgd->auth_data->timeout);
1893 1960
1961 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
1962 ifmgd->auth_data->expected_transaction != 2) {
1963 /*
1964 * Report auth frame to user space for processing since another
1965 * round of Authentication frames is still needed.
1966 */
1967 return RX_MGMT_CFG80211_RX_AUTH;
1968 }
1969
1894 /* move station state to auth */ 1970 /* move station state to auth */
1895 mutex_lock(&sdata->local->sta_mtx); 1971 mutex_lock(&sdata->local->sta_mtx);
1896 sta = sta_info_get(sdata, bssid); 1972 sta = sta_info_get(sdata, bssid);
@@ -2030,6 +2106,7 @@ static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2030 2106
2031 memset(sdata->u.mgd.bssid, 0, ETH_ALEN); 2107 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2032 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); 2108 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2109 ieee80211_vif_release_channel(sdata);
2033 } 2110 }
2034 2111
2035 kfree(assoc_data); 2112 kfree(assoc_data);
@@ -2091,7 +2168,7 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2091 return false; 2168 return false;
2092 } 2169 }
2093 2170
2094 sband = local->hw.wiphy->bands[local->oper_channel->band]; 2171 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
2095 2172
2096 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) 2173 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
2097 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, 2174 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
@@ -2100,6 +2177,11 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2100 sta->supports_40mhz = 2177 sta->supports_40mhz =
2101 sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; 2178 sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2102 2179
2180 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2181 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
2182 elems.vht_cap_elem,
2183 &sta->sta.vht_cap);
2184
2103 rate_control_rate_init(sta); 2185 rate_control_rate_init(sta);
2104 2186
2105 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) 2187 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
@@ -2369,8 +2451,10 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2369 size_t baselen; 2451 size_t baselen;
2370 struct ieee802_11_elems elems; 2452 struct ieee802_11_elems elems;
2371 struct ieee80211_local *local = sdata->local; 2453 struct ieee80211_local *local = sdata->local;
2454 struct ieee80211_chanctx_conf *chanctx_conf;
2455 struct ieee80211_channel *chan;
2372 u32 changed = 0; 2456 u32 changed = 0;
2373 bool erp_valid, directed_tim = false; 2457 bool erp_valid;
2374 u8 erp_value = 0; 2458 u8 erp_value = 0;
2375 u32 ncrc; 2459 u32 ncrc;
2376 u8 *bssid; 2460 u8 *bssid;
@@ -2382,8 +2466,19 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2382 if (baselen > len) 2466 if (baselen > len)
2383 return; 2467 return;
2384 2468
2385 if (rx_status->freq != local->oper_channel->center_freq) 2469 rcu_read_lock();
2470 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2471 if (!chanctx_conf) {
2472 rcu_read_unlock();
2386 return; 2473 return;
2474 }
2475
2476 if (rx_status->freq != chanctx_conf->channel->center_freq) {
2477 rcu_read_unlock();
2478 return;
2479 }
2480 chan = chanctx_conf->channel;
2481 rcu_read_unlock();
2387 2482
2388 if (ifmgd->assoc_data && !ifmgd->assoc_data->have_beacon && 2483 if (ifmgd->assoc_data && !ifmgd->assoc_data->have_beacon &&
2389 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { 2484 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
@@ -2490,11 +2585,10 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2490 len - baselen, &elems, 2585 len - baselen, &elems,
2491 care_about_ies, ncrc); 2586 care_about_ies, ncrc);
2492 2587
2493 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
2494 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
2495 ifmgd->aid);
2496
2497 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { 2588 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
2589 bool directed_tim = ieee80211_check_tim(elems.tim,
2590 elems.tim_len,
2591 ifmgd->aid);
2498 if (directed_tim) { 2592 if (directed_tim) {
2499 if (local->hw.conf.dynamic_ps_timeout > 0) { 2593 if (local->hw.conf.dynamic_ps_timeout > 0) {
2500 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 2594 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
@@ -2519,6 +2613,27 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2519 } 2613 }
2520 } 2614 }
2521 2615
2616 if (sdata->vif.p2p) {
2617 u8 noa[2];
2618 int ret;
2619
2620 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
2621 len - baselen,
2622 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2623 noa, sizeof(noa));
2624 if (ret >= 2 && sdata->u.mgd.p2p_noa_index != noa[0]) {
2625 bss_conf->p2p_oppps = noa[1] & 0x80;
2626 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
2627 changed |= BSS_CHANGED_P2P_PS;
2628 sdata->u.mgd.p2p_noa_index = noa[0];
2629 /*
2630 * make sure we update all information, the CRC
2631 * mechanism doesn't look at P2P attributes.
2632 */
2633 ifmgd->beacon_crc_valid = false;
2634 }
2635 }
2636
2522 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) 2637 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
2523 return; 2638 return;
2524 ifmgd->beacon_crc = ncrc; 2639 ifmgd->beacon_crc = ncrc;
@@ -2543,22 +2658,17 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2543 2658
2544 2659
2545 if (elems.ht_cap_elem && elems.ht_operation && elems.wmm_param && 2660 if (elems.ht_cap_elem && elems.ht_operation && elems.wmm_param &&
2546 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) { 2661 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
2547 struct ieee80211_supported_band *sband;
2548
2549 sband = local->hw.wiphy->bands[local->oper_channel->band];
2550
2551 changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation, 2662 changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation,
2552 bssid, true); 2663 bssid, true);
2553 }
2554 2664
2555 if (elems.country_elem && elems.pwr_constr_elem && 2665 if (elems.country_elem && elems.pwr_constr_elem &&
2556 mgmt->u.probe_resp.capab_info & 2666 mgmt->u.probe_resp.capab_info &
2557 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) 2667 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
2558 ieee80211_handle_pwr_constr(sdata, local->oper_channel, 2668 changed |= ieee80211_handle_pwr_constr(sdata, chan,
2559 elems.country_elem, 2669 elems.country_elem,
2560 elems.country_elem_len, 2670 elems.country_elem_len,
2561 elems.pwr_constr_elem); 2671 elems.pwr_constr_elem);
2562 2672
2563 ieee80211_bss_info_change_notify(sdata, changed); 2673 ieee80211_bss_info_change_notify(sdata, changed);
2564} 2674}
@@ -2703,13 +2813,23 @@ static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2703 drv_mgd_prepare_tx(local, sdata); 2813 drv_mgd_prepare_tx(local, sdata);
2704 2814
2705 if (auth_data->bss->proberesp_ies) { 2815 if (auth_data->bss->proberesp_ies) {
2816 u16 trans = 1;
2817 u16 status = 0;
2818
2706 sdata_info(sdata, "send auth to %pM (try %d/%d)\n", 2819 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
2707 auth_data->bss->bssid, auth_data->tries, 2820 auth_data->bss->bssid, auth_data->tries,
2708 IEEE80211_AUTH_MAX_TRIES); 2821 IEEE80211_AUTH_MAX_TRIES);
2709 2822
2710 auth_data->expected_transaction = 2; 2823 auth_data->expected_transaction = 2;
2711 ieee80211_send_auth(sdata, 1, auth_data->algorithm, 2824
2712 auth_data->ie, auth_data->ie_len, 2825 if (auth_data->algorithm == WLAN_AUTH_SAE) {
2826 trans = auth_data->sae_trans;
2827 status = auth_data->sae_status;
2828 auth_data->expected_transaction = trans;
2829 }
2830
2831 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
2832 auth_data->data, auth_data->data_len,
2713 auth_data->bss->bssid, 2833 auth_data->bss->bssid,
2714 auth_data->bss->bssid, NULL, 0, 0); 2834 auth_data->bss->bssid, NULL, 0, 0);
2715 } else { 2835 } else {
@@ -2728,7 +2848,7 @@ static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2728 */ 2848 */
2729 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1], 2849 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
2730 NULL, 0, (u32) -1, true, false, 2850 NULL, 0, (u32) -1, true, false,
2731 auth_data->bss->channel); 2851 auth_data->bss->channel, false);
2732 } 2852 }
2733 2853
2734 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; 2854 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
@@ -3099,39 +3219,57 @@ static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3099 ht_cfreq, ht_oper->primary_chan, 3219 ht_cfreq, ht_oper->primary_chan,
3100 cbss->channel->band); 3220 cbss->channel->band);
3101 ht_oper = NULL; 3221 ht_oper = NULL;
3222 } else {
3223 channel_type = NL80211_CHAN_HT20;
3102 } 3224 }
3103 } 3225 }
3104 3226
3105 if (ht_oper) { 3227 if (ht_oper && sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
3228 /*
3229 * cfg80211 already verified that the channel itself can
3230 * be used, but it didn't check that we can do the right
3231 * HT type, so do that here as well. If HT40 isn't allowed
3232 * on this channel, disable 40 MHz operation.
3233 */
3234 const u8 *ht_cap_ie;
3235 const struct ieee80211_ht_cap *ht_cap;
3236 u8 chains = 1;
3237
3106 channel_type = NL80211_CHAN_HT20; 3238 channel_type = NL80211_CHAN_HT20;
3107 3239
3108 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { 3240 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
3109 switch (ht_oper->ht_param & 3241 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
3110 IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { 3242 if (cbss->channel->flags & IEEE80211_CHAN_NO_HT40PLUS)
3111 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 3243 ifmgd->flags |= IEEE80211_STA_DISABLE_40MHZ;
3244 else
3112 channel_type = NL80211_CHAN_HT40PLUS; 3245 channel_type = NL80211_CHAN_HT40PLUS;
3113 break; 3246 break;
3114 case IEEE80211_HT_PARAM_CHA_SEC_BELOW: 3247 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
3248 if (cbss->channel->flags & IEEE80211_CHAN_NO_HT40MINUS)
3249 ifmgd->flags |= IEEE80211_STA_DISABLE_40MHZ;
3250 else
3115 channel_type = NL80211_CHAN_HT40MINUS; 3251 channel_type = NL80211_CHAN_HT40MINUS;
3116 break; 3252 break;
3117 }
3118 } 3253 }
3119 }
3120 3254
3121 if (!ieee80211_set_channel_type(local, sdata, channel_type)) { 3255 ht_cap_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY,
3122 /* can only fail due to HT40+/- mismatch */ 3256 cbss->information_elements,
3123 channel_type = NL80211_CHAN_HT20; 3257 cbss->len_information_elements);
3124 sdata_info(sdata, 3258 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3125 "disabling 40 MHz due to multi-vif mismatch\n"); 3259 ht_cap = (void *)(ht_cap_ie + 2);
3126 ifmgd->flags |= IEEE80211_STA_DISABLE_40MHZ; 3260 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3127 WARN_ON(!ieee80211_set_channel_type(local, sdata, 3261 }
3128 channel_type)); 3262 sdata->needed_rx_chains = min(chains, local->rx_chains);
3263 } else {
3264 sdata->needed_rx_chains = 1;
3129 } 3265 }
3130 3266
3131 local->oper_channel = cbss->channel; 3267 /* will change later if needed */
3132 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); 3268 sdata->smps_mode = IEEE80211_SMPS_OFF;
3133 3269
3134 return 0; 3270 ieee80211_vif_release_channel(sdata);
3271 return ieee80211_vif_use_channel(sdata, cbss->channel, channel_type,
3272 IEEE80211_CHANCTX_SHARED);
3135} 3273}
3136 3274
3137static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, 3275static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
@@ -3201,7 +3339,7 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3201 sdata->vif.bss_conf.basic_rates = basic_rates; 3339 sdata->vif.bss_conf.basic_rates = basic_rates;
3202 3340
3203 /* cf. IEEE 802.11 9.2.12 */ 3341 /* cf. IEEE 802.11 9.2.12 */
3204 if (local->oper_channel->band == IEEE80211_BAND_2GHZ && 3342 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
3205 have_higher_than_11mbit) 3343 have_higher_than_11mbit)
3206 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; 3344 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3207 else 3345 else
@@ -3263,19 +3401,33 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3263 case NL80211_AUTHTYPE_NETWORK_EAP: 3401 case NL80211_AUTHTYPE_NETWORK_EAP:
3264 auth_alg = WLAN_AUTH_LEAP; 3402 auth_alg = WLAN_AUTH_LEAP;
3265 break; 3403 break;
3404 case NL80211_AUTHTYPE_SAE:
3405 auth_alg = WLAN_AUTH_SAE;
3406 break;
3266 default: 3407 default:
3267 return -EOPNOTSUPP; 3408 return -EOPNOTSUPP;
3268 } 3409 }
3269 3410
3270 auth_data = kzalloc(sizeof(*auth_data) + req->ie_len, GFP_KERNEL); 3411 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
3412 req->ie_len, GFP_KERNEL);
3271 if (!auth_data) 3413 if (!auth_data)
3272 return -ENOMEM; 3414 return -ENOMEM;
3273 3415
3274 auth_data->bss = req->bss; 3416 auth_data->bss = req->bss;
3275 3417
3418 if (req->sae_data_len >= 4) {
3419 __le16 *pos = (__le16 *) req->sae_data;
3420 auth_data->sae_trans = le16_to_cpu(pos[0]);
3421 auth_data->sae_status = le16_to_cpu(pos[1]);
3422 memcpy(auth_data->data, req->sae_data + 4,
3423 req->sae_data_len - 4);
3424 auth_data->data_len += req->sae_data_len - 4;
3425 }
3426
3276 if (req->ie && req->ie_len) { 3427 if (req->ie && req->ie_len) {
3277 memcpy(auth_data->ie, req->ie, req->ie_len); 3428 memcpy(&auth_data->data[auth_data->data_len],
3278 auth_data->ie_len = req->ie_len; 3429 req->ie, req->ie_len);
3430 auth_data->data_len += req->ie_len;
3279 } 3431 }
3280 3432
3281 if (req->key && req->key_len) { 3433 if (req->key && req->key_len) {
@@ -3442,11 +3594,11 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3442 3594
3443 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { 3595 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
3444 if (ifmgd->powersave) 3596 if (ifmgd->powersave)
3445 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC; 3597 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
3446 else 3598 else
3447 ifmgd->ap_smps = IEEE80211_SMPS_OFF; 3599 sdata->smps_mode = IEEE80211_SMPS_OFF;
3448 } else 3600 } else
3449 ifmgd->ap_smps = ifmgd->req_smps; 3601 sdata->smps_mode = ifmgd->req_smps;
3450 3602
3451 assoc_data->capability = req->bss->capability; 3603 assoc_data->capability = req->bss->capability;
3452 assoc_data->wmm = bss->wmm_used && 3604 assoc_data->wmm = bss->wmm_used &&
@@ -3549,40 +3701,45 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
3549{ 3701{
3550 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3702 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3551 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 3703 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3704 bool tx = !req->local_state_change;
3705 bool sent_frame = false;
3552 3706
3553 mutex_lock(&ifmgd->mtx); 3707 mutex_lock(&ifmgd->mtx);
3554 3708
3555 if (ifmgd->auth_data) {
3556 ieee80211_destroy_auth_data(sdata, false);
3557 mutex_unlock(&ifmgd->mtx);
3558 return 0;
3559 }
3560
3561 sdata_info(sdata, 3709 sdata_info(sdata,
3562 "deauthenticating from %pM by local choice (reason=%d)\n", 3710 "deauthenticating from %pM by local choice (reason=%d)\n",
3563 req->bssid, req->reason_code); 3711 req->bssid, req->reason_code);
3564 3712
3565 if (ifmgd->associated && 3713 if (ifmgd->auth_data) {
3566 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
3567 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3568 req->reason_code, true, frame_buf);
3569 } else {
3570 drv_mgd_prepare_tx(sdata->local, sdata); 3714 drv_mgd_prepare_tx(sdata->local, sdata);
3571 ieee80211_send_deauth_disassoc(sdata, req->bssid, 3715 ieee80211_send_deauth_disassoc(sdata, req->bssid,
3572 IEEE80211_STYPE_DEAUTH, 3716 IEEE80211_STYPE_DEAUTH,
3573 req->reason_code, true, 3717 req->reason_code, tx,
3574 frame_buf); 3718 frame_buf);
3719 ieee80211_destroy_auth_data(sdata, false);
3720 mutex_unlock(&ifmgd->mtx);
3721
3722 sent_frame = tx;
3723 goto out;
3575 } 3724 }
3576 3725
3726 if (ifmgd->associated &&
3727 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
3728 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3729 req->reason_code, tx, frame_buf);
3730 sent_frame = tx;
3731 }
3577 mutex_unlock(&ifmgd->mtx); 3732 mutex_unlock(&ifmgd->mtx);
3578 3733
3579 __cfg80211_send_deauth(sdata->dev, frame_buf, 3734 out:
3580 IEEE80211_DEAUTH_FRAME_LEN);
3581
3582 mutex_lock(&sdata->local->mtx); 3735 mutex_lock(&sdata->local->mtx);
3583 ieee80211_recalc_idle(sdata->local); 3736 ieee80211_recalc_idle(sdata->local);
3584 mutex_unlock(&sdata->local->mtx); 3737 mutex_unlock(&sdata->local->mtx);
3585 3738
3739 if (sent_frame)
3740 __cfg80211_send_deauth(sdata->dev, frame_buf,
3741 IEEE80211_DEAUTH_FRAME_LEN);
3742
3586 return 0; 3743 return 0;
3587} 3744}
3588 3745
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
index 83608ac16780..0cd42d52880c 100644
--- a/net/mac80211/offchannel.c
+++ b/net/mac80211/offchannel.c
@@ -107,6 +107,9 @@ void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local,
107{ 107{
108 struct ieee80211_sub_if_data *sdata; 108 struct ieee80211_sub_if_data *sdata;
109 109
110 if (WARN_ON(local->use_chanctx))
111 return;
112
110 /* 113 /*
111 * notify the AP about us leaving the channel and stop all 114 * notify the AP about us leaving the channel and stop all
112 * STA interfaces. 115 * STA interfaces.
@@ -145,6 +148,9 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
145{ 148{
146 struct ieee80211_sub_if_data *sdata; 149 struct ieee80211_sub_if_data *sdata;
147 150
151 if (WARN_ON(local->use_chanctx))
152 return;
153
148 mutex_lock(&local->iflist_mtx); 154 mutex_lock(&local->iflist_mtx);
149 list_for_each_entry(sdata, &local->interfaces, list) { 155 list_for_each_entry(sdata, &local->interfaces, list) {
150 if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) 156 if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
@@ -193,11 +199,12 @@ void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc)
193 199
194 if (roc->mgmt_tx_cookie) { 200 if (roc->mgmt_tx_cookie) {
195 if (!WARN_ON(!roc->frame)) { 201 if (!WARN_ON(!roc->frame)) {
196 ieee80211_tx_skb(roc->sdata, roc->frame); 202 ieee80211_tx_skb_tid_band(roc->sdata, roc->frame, 7,
203 roc->chan->band);
197 roc->frame = NULL; 204 roc->frame = NULL;
198 } 205 }
199 } else { 206 } else {
200 cfg80211_ready_on_channel(&roc->sdata->wdev, (unsigned long)roc, 207 cfg80211_ready_on_channel(&roc->sdata->wdev, roc->cookie,
201 roc->chan, roc->chan_type, 208 roc->chan, roc->chan_type,
202 roc->req_duration, GFP_KERNEL); 209 roc->req_duration, GFP_KERNEL);
203 } 210 }
@@ -313,9 +320,8 @@ void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc)
313 320
314 if (!roc->mgmt_tx_cookie) 321 if (!roc->mgmt_tx_cookie)
315 cfg80211_remain_on_channel_expired(&roc->sdata->wdev, 322 cfg80211_remain_on_channel_expired(&roc->sdata->wdev,
316 (unsigned long)roc, 323 roc->cookie, roc->chan,
317 roc->chan, roc->chan_type, 324 roc->chan_type, GFP_KERNEL);
318 GFP_KERNEL);
319 325
320 list_for_each_entry_safe(dep, tmp, &roc->dependents, list) 326 list_for_each_entry_safe(dep, tmp, &roc->dependents, list)
321 ieee80211_roc_notify_destroy(dep); 327 ieee80211_roc_notify_destroy(dep);
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index 5c572e7a1a71..0f1c434638bc 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -135,6 +135,12 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
135 ieee80211_bss_info_change_notify(sdata, 135 ieee80211_bss_info_change_notify(sdata,
136 BSS_CHANGED_BEACON_ENABLED); 136 BSS_CHANGED_BEACON_ENABLED);
137 137
138 if (sdata->vif.type == NL80211_IFTYPE_AP &&
139 rcu_access_pointer(sdata->u.ap.beacon))
140 drv_stop_ap(local, sdata);
141
142 /* the interface is leaving the channel and is removed */
143 ieee80211_vif_release_channel(sdata);
138 drv_remove_interface(local, sdata); 144 drv_remove_interface(local, sdata);
139 } 145 }
140 146
diff --git a/net/mac80211/rate.h b/net/mac80211/rate.h
index 10de668eb9f6..ec198ef6aa8a 100644
--- a/net/mac80211/rate.h
+++ b/net/mac80211/rate.h
@@ -52,11 +52,21 @@ static inline void rate_control_rate_init(struct sta_info *sta)
52 struct ieee80211_sta *ista = &sta->sta; 52 struct ieee80211_sta *ista = &sta->sta;
53 void *priv_sta = sta->rate_ctrl_priv; 53 void *priv_sta = sta->rate_ctrl_priv;
54 struct ieee80211_supported_band *sband; 54 struct ieee80211_supported_band *sband;
55 struct ieee80211_chanctx_conf *chanctx_conf;
55 56
56 if (!ref) 57 if (!ref)
57 return; 58 return;
58 59
59 sband = local->hw.wiphy->bands[local->oper_channel->band]; 60 rcu_read_lock();
61
62 chanctx_conf = rcu_dereference(sta->sdata->vif.chanctx_conf);
63 if (WARN_ON(!chanctx_conf)) {
64 rcu_read_unlock();
65 return;
66 }
67
68 sband = local->hw.wiphy->bands[chanctx_conf->channel->band];
69 rcu_read_unlock();
60 70
61 ref->ops->rate_init(ref->priv, sband, ista, priv_sta); 71 ref->ops->rate_init(ref->priv, sband, ista, priv_sta);
62 set_sta_flag(sta, WLAN_STA_RATE_CONTROL); 72 set_sta_flag(sta, WLAN_STA_RATE_CONTROL);
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 61c621e9273f..6ad330341b71 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -54,8 +54,7 @@ static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
54 return skb; 54 return skb;
55} 55}
56 56
57static inline int should_drop_frame(struct sk_buff *skb, 57static inline int should_drop_frame(struct sk_buff *skb, int present_fcs_len)
58 int present_fcs_len)
59{ 58{
60 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 59 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
61 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 60 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
@@ -130,15 +129,14 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
130 (1 << IEEE80211_RADIOTAP_RX_FLAGS)); 129 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
131 rthdr->it_len = cpu_to_le16(rtap_len); 130 rthdr->it_len = cpu_to_le16(rtap_len);
132 131
133 pos = (unsigned char *)(rthdr+1); 132 pos = (unsigned char *)(rthdr + 1);
134 133
135 /* the order of the following fields is important */ 134 /* the order of the following fields is important */
136 135
137 /* IEEE80211_RADIOTAP_TSFT */ 136 /* IEEE80211_RADIOTAP_TSFT */
138 if (status->flag & RX_FLAG_MACTIME_MPDU) { 137 if (status->flag & RX_FLAG_MACTIME_MPDU) {
139 put_unaligned_le64(status->mactime, pos); 138 put_unaligned_le64(status->mactime, pos);
140 rthdr->it_present |= 139 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
141 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
142 pos += 8; 140 pos += 8;
143 } 141 }
144 142
@@ -374,7 +372,6 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
374 return origskb; 372 return origskb;
375} 373}
376 374
377
378static void ieee80211_parse_qos(struct ieee80211_rx_data *rx) 375static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
379{ 376{
380 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 377 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
@@ -481,8 +478,7 @@ static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
481 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data; 478 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
482 struct ieee80211_mmie *mmie; 479 struct ieee80211_mmie *mmie;
483 480
484 if (skb->len < 24 + sizeof(*mmie) || 481 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
485 !is_multicast_ether_addr(hdr->da))
486 return -1; 482 return -1;
487 483
488 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr)) 484 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
@@ -497,9 +493,7 @@ static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
497 return le16_to_cpu(mmie->key_id); 493 return le16_to_cpu(mmie->key_id);
498} 494}
499 495
500 496static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
501static ieee80211_rx_result
502ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
503{ 497{
504 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 498 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
505 char *dev_addr = rx->sdata->vif.addr; 499 char *dev_addr = rx->sdata->vif.addr;
@@ -507,7 +501,7 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
507 if (ieee80211_is_data(hdr->frame_control)) { 501 if (ieee80211_is_data(hdr->frame_control)) {
508 if (is_multicast_ether_addr(hdr->addr1)) { 502 if (is_multicast_ether_addr(hdr->addr1)) {
509 if (ieee80211_has_tods(hdr->frame_control) || 503 if (ieee80211_has_tods(hdr->frame_control) ||
510 !ieee80211_has_fromds(hdr->frame_control)) 504 !ieee80211_has_fromds(hdr->frame_control))
511 return RX_DROP_MONITOR; 505 return RX_DROP_MONITOR;
512 if (ether_addr_equal(hdr->addr3, dev_addr)) 506 if (ether_addr_equal(hdr->addr3, dev_addr))
513 return RX_DROP_MONITOR; 507 return RX_DROP_MONITOR;
@@ -531,10 +525,15 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
531 525
532 if (ieee80211_is_action(hdr->frame_control)) { 526 if (ieee80211_is_action(hdr->frame_control)) {
533 u8 category; 527 u8 category;
528
529 /* make sure category field is present */
530 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
531 return RX_DROP_MONITOR;
532
534 mgmt = (struct ieee80211_mgmt *)hdr; 533 mgmt = (struct ieee80211_mgmt *)hdr;
535 category = mgmt->u.action.category; 534 category = mgmt->u.action.category;
536 if (category != WLAN_CATEGORY_MESH_ACTION && 535 if (category != WLAN_CATEGORY_MESH_ACTION &&
537 category != WLAN_CATEGORY_SELF_PROTECTED) 536 category != WLAN_CATEGORY_SELF_PROTECTED)
538 return RX_DROP_MONITOR; 537 return RX_DROP_MONITOR;
539 return RX_CONTINUE; 538 return RX_CONTINUE;
540 } 539 }
@@ -546,7 +545,6 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
546 return RX_CONTINUE; 545 return RX_CONTINUE;
547 546
548 return RX_DROP_MONITOR; 547 return RX_DROP_MONITOR;
549
550 } 548 }
551 549
552 return RX_CONTINUE; 550 return RX_CONTINUE;
@@ -570,7 +568,6 @@ static inline u16 seq_sub(u16 sq1, u16 sq2)
570 return (sq1 - sq2) & SEQ_MASK; 568 return (sq1 - sq2) & SEQ_MASK;
571} 569}
572 570
573
574static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata, 571static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
575 struct tid_ampdu_rx *tid_agg_rx, 572 struct tid_ampdu_rx *tid_agg_rx,
576 int index) 573 int index)
@@ -883,14 +880,16 @@ ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
883 */ 880 */
884 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION && 881 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
885 ieee80211_is_data_present(hdr->frame_control)) { 882 ieee80211_is_data_present(hdr->frame_control)) {
886 u16 ethertype; 883 unsigned int hdrlen;
887 u8 *payload; 884 __be16 ethertype;
888 885
889 payload = rx->skb->data + 886 hdrlen = ieee80211_hdrlen(hdr->frame_control);
890 ieee80211_hdrlen(hdr->frame_control); 887
891 ethertype = (payload[6] << 8) | payload[7]; 888 if (rx->skb->len < hdrlen + 8)
892 if (cpu_to_be16(ethertype) == 889 return RX_DROP_MONITOR;
893 rx->sdata->control_port_protocol) 890
891 skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
892 if (ethertype == rx->sdata->control_port_protocol)
894 return RX_CONTINUE; 893 return RX_CONTINUE;
895 } 894 }
896 895
@@ -1141,12 +1140,19 @@ ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1141 return RX_CONTINUE; 1140 return RX_CONTINUE;
1142} 1141}
1143 1142
1144static void ap_sta_ps_start(struct sta_info *sta) 1143static void sta_ps_start(struct sta_info *sta)
1145{ 1144{
1146 struct ieee80211_sub_if_data *sdata = sta->sdata; 1145 struct ieee80211_sub_if_data *sdata = sta->sdata;
1147 struct ieee80211_local *local = sdata->local; 1146 struct ieee80211_local *local = sdata->local;
1147 struct ps_data *ps;
1148 1148
1149 atomic_inc(&sdata->bss->num_sta_ps); 1149 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1150 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1151 ps = &sdata->bss->ps;
1152 else
1153 return;
1154
1155 atomic_inc(&ps->num_sta_ps);
1150 set_sta_flag(sta, WLAN_STA_PS_STA); 1156 set_sta_flag(sta, WLAN_STA_PS_STA);
1151 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) 1157 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1152 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta); 1158 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
@@ -1154,7 +1160,7 @@ static void ap_sta_ps_start(struct sta_info *sta)
1154 sta->sta.addr, sta->sta.aid); 1160 sta->sta.addr, sta->sta.aid);
1155} 1161}
1156 1162
1157static void ap_sta_ps_end(struct sta_info *sta) 1163static void sta_ps_end(struct sta_info *sta)
1158{ 1164{
1159 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n", 1165 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1160 sta->sta.addr, sta->sta.aid); 1166 sta->sta.addr, sta->sta.aid);
@@ -1181,9 +1187,9 @@ int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1181 return -EINVAL; 1187 return -EINVAL;
1182 1188
1183 if (start) 1189 if (start)
1184 ap_sta_ps_start(sta_inf); 1190 sta_ps_start(sta_inf);
1185 else 1191 else
1186 ap_sta_ps_end(sta_inf); 1192 sta_ps_end(sta_inf);
1187 1193
1188 return 0; 1194 return 0;
1189} 1195}
@@ -1335,10 +1341,10 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1335 */ 1341 */
1336 if (ieee80211_is_data(hdr->frame_control) && 1342 if (ieee80211_is_data(hdr->frame_control) &&
1337 !ieee80211_has_pm(hdr->frame_control)) 1343 !ieee80211_has_pm(hdr->frame_control))
1338 ap_sta_ps_end(sta); 1344 sta_ps_end(sta);
1339 } else { 1345 } else {
1340 if (ieee80211_has_pm(hdr->frame_control)) 1346 if (ieee80211_has_pm(hdr->frame_control))
1341 ap_sta_ps_start(sta); 1347 sta_ps_start(sta);
1342 } 1348 }
1343 } 1349 }
1344 1350
@@ -1384,9 +1390,7 @@ ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1384 struct sk_buff **skb) 1390 struct sk_buff **skb)
1385{ 1391{
1386 struct ieee80211_fragment_entry *entry; 1392 struct ieee80211_fragment_entry *entry;
1387 int idx;
1388 1393
1389 idx = sdata->fragment_next;
1390 entry = &sdata->fragments[sdata->fragment_next++]; 1394 entry = &sdata->fragments[sdata->fragment_next++];
1391 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) 1395 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1392 sdata->fragment_next = 0; 1396 sdata->fragment_next = 0;
@@ -1462,11 +1466,14 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1462 1466
1463 hdr = (struct ieee80211_hdr *)rx->skb->data; 1467 hdr = (struct ieee80211_hdr *)rx->skb->data;
1464 fc = hdr->frame_control; 1468 fc = hdr->frame_control;
1469
1470 if (ieee80211_is_ctl(fc))
1471 return RX_CONTINUE;
1472
1465 sc = le16_to_cpu(hdr->seq_ctrl); 1473 sc = le16_to_cpu(hdr->seq_ctrl);
1466 frag = sc & IEEE80211_SCTL_FRAG; 1474 frag = sc & IEEE80211_SCTL_FRAG;
1467 1475
1468 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) || 1476 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
1469 (rx->skb)->len < 24 ||
1470 is_multicast_ether_addr(hdr->addr1))) { 1477 is_multicast_ether_addr(hdr->addr1))) {
1471 /* not fragmented */ 1478 /* not fragmented */
1472 goto out; 1479 goto out;
@@ -1570,18 +1577,15 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1570 return RX_CONTINUE; 1577 return RX_CONTINUE;
1571} 1578}
1572 1579
1573static int 1580static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1574ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1575{ 1581{
1576 if (unlikely(!rx->sta || 1582 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
1577 !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
1578 return -EACCES; 1583 return -EACCES;
1579 1584
1580 return 0; 1585 return 0;
1581} 1586}
1582 1587
1583static int 1588static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1584ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1585{ 1589{
1586 struct sk_buff *skb = rx->skb; 1590 struct sk_buff *skb = rx->skb;
1587 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 1591 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
@@ -1603,8 +1607,7 @@ ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1603 return 0; 1607 return 0;
1604} 1608}
1605 1609
1606static int 1610static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1607ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1608{ 1611{
1609 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; 1612 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1610 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); 1613 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
@@ -1889,6 +1892,20 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1889 1892
1890 hdr = (struct ieee80211_hdr *) skb->data; 1893 hdr = (struct ieee80211_hdr *) skb->data;
1891 hdrlen = ieee80211_hdrlen(hdr->frame_control); 1894 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1895
1896 /* make sure fixed part of mesh header is there, also checks skb len */
1897 if (!pskb_may_pull(rx->skb, hdrlen + 6))
1898 return RX_DROP_MONITOR;
1899
1900 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1901
1902 /* make sure full mesh header is there, also checks skb len */
1903 if (!pskb_may_pull(rx->skb,
1904 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
1905 return RX_DROP_MONITOR;
1906
1907 /* reload pointers */
1908 hdr = (struct ieee80211_hdr *) skb->data;
1892 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); 1909 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1893 1910
1894 /* frame is in RMC, don't forward */ 1911 /* frame is in RMC, don't forward */
@@ -1897,7 +1914,8 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1897 mesh_rmc_check(hdr->addr3, mesh_hdr, rx->sdata)) 1914 mesh_rmc_check(hdr->addr3, mesh_hdr, rx->sdata))
1898 return RX_DROP_MONITOR; 1915 return RX_DROP_MONITOR;
1899 1916
1900 if (!ieee80211_is_data(hdr->frame_control)) 1917 if (!ieee80211_is_data(hdr->frame_control) ||
1918 !(status->rx_flags & IEEE80211_RX_RA_MATCH))
1901 return RX_CONTINUE; 1919 return RX_CONTINUE;
1902 1920
1903 if (!mesh_hdr->ttl) 1921 if (!mesh_hdr->ttl)
@@ -1911,9 +1929,12 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1911 if (is_multicast_ether_addr(hdr->addr1)) { 1929 if (is_multicast_ether_addr(hdr->addr1)) {
1912 mpp_addr = hdr->addr3; 1930 mpp_addr = hdr->addr3;
1913 proxied_addr = mesh_hdr->eaddr1; 1931 proxied_addr = mesh_hdr->eaddr1;
1914 } else { 1932 } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
1933 /* has_a4 already checked in ieee80211_rx_mesh_check */
1915 mpp_addr = hdr->addr4; 1934 mpp_addr = hdr->addr4;
1916 proxied_addr = mesh_hdr->eaddr2; 1935 proxied_addr = mesh_hdr->eaddr2;
1936 } else {
1937 return RX_DROP_MONITOR;
1917 } 1938 }
1918 1939
1919 rcu_read_lock(); 1940 rcu_read_lock();
@@ -1941,12 +1962,9 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1941 } 1962 }
1942 skb_set_queue_mapping(skb, q); 1963 skb_set_queue_mapping(skb, q);
1943 1964
1944 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
1945 goto out;
1946
1947 if (!--mesh_hdr->ttl) { 1965 if (!--mesh_hdr->ttl) {
1948 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl); 1966 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
1949 return RX_DROP_MONITOR; 1967 goto out;
1950 } 1968 }
1951 1969
1952 if (!ifmsh->mshcfg.dot11MeshForwarding) 1970 if (!ifmsh->mshcfg.dot11MeshForwarding)
@@ -1973,7 +1991,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1973 } else { 1991 } else {
1974 /* unable to resolve next hop */ 1992 /* unable to resolve next hop */
1975 mesh_path_error_tx(ifmsh->mshcfg.element_ttl, fwd_hdr->addr3, 1993 mesh_path_error_tx(ifmsh->mshcfg.element_ttl, fwd_hdr->addr3,
1976 0, reason, fwd_hdr->addr2, sdata); 1994 0, reason, fwd_hdr->addr2, sdata);
1977 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route); 1995 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
1978 kfree_skb(fwd_skb); 1996 kfree_skb(fwd_skb);
1979 return RX_DROP_MONITOR; 1997 return RX_DROP_MONITOR;
@@ -2182,7 +2200,7 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2182 2200
2183 cfg80211_report_obss_beacon(rx->local->hw.wiphy, 2201 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2184 rx->skb->data, rx->skb->len, 2202 rx->skb->data, rx->skb->len,
2185 status->freq, sig, GFP_ATOMIC); 2203 status->freq, sig);
2186 rx->flags |= IEEE80211_RX_BEACON_REPORTED; 2204 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2187 } 2205 }
2188 2206
@@ -2353,6 +2371,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2353 } 2371 }
2354 break; 2372 break;
2355 case WLAN_CATEGORY_SELF_PROTECTED: 2373 case WLAN_CATEGORY_SELF_PROTECTED:
2374 if (len < (IEEE80211_MIN_ACTION_SIZE +
2375 sizeof(mgmt->u.action.u.self_prot.action_code)))
2376 break;
2377
2356 switch (mgmt->u.action.u.self_prot.action_code) { 2378 switch (mgmt->u.action.u.self_prot.action_code) {
2357 case WLAN_SP_MESH_PEERING_OPEN: 2379 case WLAN_SP_MESH_PEERING_OPEN:
2358 case WLAN_SP_MESH_PEERING_CLOSE: 2380 case WLAN_SP_MESH_PEERING_CLOSE:
@@ -2371,10 +2393,14 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2371 } 2393 }
2372 break; 2394 break;
2373 case WLAN_CATEGORY_MESH_ACTION: 2395 case WLAN_CATEGORY_MESH_ACTION:
2396 if (len < (IEEE80211_MIN_ACTION_SIZE +
2397 sizeof(mgmt->u.action.u.mesh_action.action_code)))
2398 break;
2399
2374 if (!ieee80211_vif_is_mesh(&sdata->vif)) 2400 if (!ieee80211_vif_is_mesh(&sdata->vif))
2375 break; 2401 break;
2376 if (mesh_action_is_path_sel(mgmt) && 2402 if (mesh_action_is_path_sel(mgmt) &&
2377 (!mesh_path_sel_is_hwmp(sdata))) 2403 !mesh_path_sel_is_hwmp(sdata))
2378 break; 2404 break;
2379 goto queue; 2405 goto queue;
2380 } 2406 }
@@ -2430,7 +2456,6 @@ ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2430 return RX_QUEUED; 2456 return RX_QUEUED;
2431 } 2457 }
2432 2458
2433
2434 return RX_CONTINUE; 2459 return RX_CONTINUE;
2435} 2460}
2436 2461
@@ -2913,10 +2938,15 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2913 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc)) 2938 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
2914 local->dot11ReceivedFragmentCount++; 2939 local->dot11ReceivedFragmentCount++;
2915 2940
2916 if (ieee80211_is_mgmt(fc)) 2941 if (ieee80211_is_mgmt(fc)) {
2917 err = skb_linearize(skb); 2942 /* drop frame if too short for header */
2918 else 2943 if (skb->len < ieee80211_hdrlen(fc))
2944 err = -ENOBUFS;
2945 else
2946 err = skb_linearize(skb);
2947 } else {
2919 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc)); 2948 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
2949 }
2920 2950
2921 if (err) { 2951 if (err) {
2922 dev_kfree_skb(skb); 2952 dev_kfree_skb(skb);
@@ -3010,8 +3040,7 @@ void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
3010 3040
3011 WARN_ON_ONCE(softirq_count() == 0); 3041 WARN_ON_ONCE(softirq_count() == 0);
3012 3042
3013 if (WARN_ON(status->band < 0 || 3043 if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
3014 status->band >= IEEE80211_NUM_BANDS))
3015 goto drop; 3044 goto drop;
3016 3045
3017 sband = local->hw.wiphy->bands[status->band]; 3046 sband = local->hw.wiphy->bands[status->band];
@@ -3056,8 +3085,7 @@ void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
3056 * hardware error. The driver should catch hardware 3085 * hardware error. The driver should catch hardware
3057 * errors. 3086 * errors.
3058 */ 3087 */
3059 if (WARN((status->rate_idx < 0 || 3088 if (WARN(status->rate_idx > 76,
3060 status->rate_idx > 76),
3061 "Rate marked as an HT rate but passed " 3089 "Rate marked as an HT rate but passed "
3062 "status->rate_idx is not " 3090 "status->rate_idx is not "
3063 "an MCS index [0-76]: %d (0x%02x)\n", 3091 "an MCS index [0-76]: %d (0x%02x)\n",
@@ -3065,8 +3093,7 @@ void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
3065 status->rate_idx)) 3093 status->rate_idx))
3066 goto drop; 3094 goto drop;
3067 } else { 3095 } else {
3068 if (WARN_ON(status->rate_idx < 0 || 3096 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
3069 status->rate_idx >= sband->n_bitrates))
3070 goto drop; 3097 goto drop;
3071 rate = &sband->bitrates[status->rate_idx]; 3098 rate = &sband->bitrates[status->rate_idx];
3072 } 3099 }
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index c4cdbde24fd3..8e9bb168b73b 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -336,6 +336,10 @@ EXPORT_SYMBOL(ieee80211_scan_completed);
336 336
337static int ieee80211_start_sw_scan(struct ieee80211_local *local) 337static int ieee80211_start_sw_scan(struct ieee80211_local *local)
338{ 338{
339 /* Software scan is not supported in multi-channel cases */
340 if (local->use_chanctx)
341 return -EOPNOTSUPP;
342
339 /* 343 /*
340 * Hardware/driver doesn't support hw_scan, so use software 344 * Hardware/driver doesn't support hw_scan, so use software
341 * scanning instead. First send a nullfunc frame with power save 345 * scanning instead. First send a nullfunc frame with power save
@@ -417,7 +421,7 @@ static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
417 local->scan_req->ie, local->scan_req->ie_len, 421 local->scan_req->ie, local->scan_req->ie_len,
418 local->scan_req->rates[band], false, 422 local->scan_req->rates[band], false,
419 local->scan_req->no_cck, 423 local->scan_req->no_cck,
420 local->hw.conf.channel); 424 local->hw.conf.channel, true);
421 425
422 /* 426 /*
423 * After sending probe requests, wait for probe responses 427 * After sending probe requests, wait for probe responses
@@ -462,6 +466,7 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
462 sizeof(*local->hw_scan_req) + 466 sizeof(*local->hw_scan_req) +
463 req->n_channels * sizeof(req->channels[0]); 467 req->n_channels * sizeof(req->channels[0]);
464 local->hw_scan_req->ie = ies; 468 local->hw_scan_req->ie = ies;
469 local->hw_scan_req->flags = req->flags;
465 470
466 local->hw_scan_band = 0; 471 local->hw_scan_band = 0;
467 472
@@ -480,7 +485,7 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
480 if (local->ops->hw_scan) { 485 if (local->ops->hw_scan) {
481 __set_bit(SCAN_HW_SCANNING, &local->scanning); 486 __set_bit(SCAN_HW_SCANNING, &local->scanning);
482 } else if ((req->n_channels == 1) && 487 } else if ((req->n_channels == 1) &&
483 (req->channels[0] == local->oper_channel)) { 488 (req->channels[0] == local->_oper_channel)) {
484 /* 489 /*
485 * If we are scanning only on the operating channel 490 * If we are scanning only on the operating channel
486 * then we do not need to stop normal activities 491 * then we do not need to stop normal activities
@@ -562,6 +567,7 @@ static void ieee80211_scan_state_decision(struct ieee80211_local *local,
562 unsigned long min_beacon_int = 0; 567 unsigned long min_beacon_int = 0;
563 struct ieee80211_sub_if_data *sdata; 568 struct ieee80211_sub_if_data *sdata;
564 struct ieee80211_channel *next_chan; 569 struct ieee80211_channel *next_chan;
570 enum mac80211_scan_state next_scan_state;
565 571
566 /* 572 /*
567 * check if at least one STA interface is associated, 573 * check if at least one STA interface is associated,
@@ -620,10 +626,18 @@ static void ieee80211_scan_state_decision(struct ieee80211_local *local,
620 usecs_to_jiffies(min_beacon_int * 1024) * 626 usecs_to_jiffies(min_beacon_int * 1024) *
621 local->hw.conf.listen_interval); 627 local->hw.conf.listen_interval);
622 628
623 if (associated && (!tx_empty || bad_latency || listen_int_exceeded)) 629 if (associated && !tx_empty) {
624 local->next_scan_state = SCAN_SUSPEND; 630 if (local->scan_req->flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
625 else 631 next_scan_state = SCAN_ABORT;
626 local->next_scan_state = SCAN_SET_CHANNEL; 632 else
633 next_scan_state = SCAN_SUSPEND;
634 } else if (associated && (bad_latency || listen_int_exceeded)) {
635 next_scan_state = SCAN_SUSPEND;
636 } else {
637 next_scan_state = SCAN_SET_CHANNEL;
638 }
639
640 local->next_scan_state = next_scan_state;
627 641
628 *next_delay = 0; 642 *next_delay = 0;
629} 643}
@@ -794,6 +808,9 @@ void ieee80211_scan_work(struct work_struct *work)
794 case SCAN_RESUME: 808 case SCAN_RESUME:
795 ieee80211_scan_state_resume(local, &next_delay); 809 ieee80211_scan_state_resume(local, &next_delay);
796 break; 810 break;
811 case SCAN_ABORT:
812 aborted = true;
813 goto out_complete;
797 } 814 }
798 } while (next_delay == 0); 815 } while (next_delay == 0);
799 816
@@ -917,7 +934,7 @@ int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
917 struct cfg80211_sched_scan_request *req) 934 struct cfg80211_sched_scan_request *req)
918{ 935{
919 struct ieee80211_local *local = sdata->local; 936 struct ieee80211_local *local = sdata->local;
920 struct ieee80211_sched_scan_ies sched_scan_ies; 937 struct ieee80211_sched_scan_ies sched_scan_ies = {};
921 int ret, i; 938 int ret, i;
922 939
923 mutex_lock(&local->mtx); 940 mutex_lock(&local->mtx);
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 797dd36a220d..e9d57689c05f 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -98,6 +98,7 @@ static void free_sta_work(struct work_struct *wk)
98 struct tid_ampdu_tx *tid_tx; 98 struct tid_ampdu_tx *tid_tx;
99 struct ieee80211_sub_if_data *sdata = sta->sdata; 99 struct ieee80211_sub_if_data *sdata = sta->sdata;
100 struct ieee80211_local *local = sdata->local; 100 struct ieee80211_local *local = sdata->local;
101 struct ps_data *ps;
101 102
102 /* 103 /*
103 * At this point, when being called as call_rcu callback, 104 * At this point, when being called as call_rcu callback,
@@ -107,18 +108,22 @@ static void free_sta_work(struct work_struct *wk)
107 */ 108 */
108 109
109 if (test_sta_flag(sta, WLAN_STA_PS_STA)) { 110 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
110 BUG_ON(!sdata->bss); 111 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
112 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
113 ps = &sdata->bss->ps;
114 else
115 return;
111 116
112 clear_sta_flag(sta, WLAN_STA_PS_STA); 117 clear_sta_flag(sta, WLAN_STA_PS_STA);
113 118
114 atomic_dec(&sdata->bss->num_sta_ps); 119 atomic_dec(&ps->num_sta_ps);
115 sta_info_recalc_tim(sta); 120 sta_info_recalc_tim(sta);
116 } 121 }
117 122
118 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 123 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
119 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]); 124 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
120 __skb_queue_purge(&sta->ps_tx_buf[ac]); 125 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
121 __skb_queue_purge(&sta->tx_filtered[ac]); 126 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
122 } 127 }
123 128
124#ifdef CONFIG_MAC80211_MESH 129#ifdef CONFIG_MAC80211_MESH
@@ -141,7 +146,7 @@ static void free_sta_work(struct work_struct *wk)
141 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]); 146 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
142 if (!tid_tx) 147 if (!tid_tx)
143 continue; 148 continue;
144 __skb_queue_purge(&tid_tx->pending); 149 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
145 kfree(tid_tx); 150 kfree(tid_tx);
146 } 151 }
147 152
@@ -502,22 +507,22 @@ int sta_info_insert(struct sta_info *sta)
502 return err; 507 return err;
503} 508}
504 509
505static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) 510static inline void __bss_tim_set(u8 *tim, u16 id)
506{ 511{
507 /* 512 /*
508 * This format has been mandated by the IEEE specifications, 513 * This format has been mandated by the IEEE specifications,
509 * so this line may not be changed to use the __set_bit() format. 514 * so this line may not be changed to use the __set_bit() format.
510 */ 515 */
511 bss->tim[aid / 8] |= (1 << (aid % 8)); 516 tim[id / 8] |= (1 << (id % 8));
512} 517}
513 518
514static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) 519static inline void __bss_tim_clear(u8 *tim, u16 id)
515{ 520{
516 /* 521 /*
517 * This format has been mandated by the IEEE specifications, 522 * This format has been mandated by the IEEE specifications,
518 * so this line may not be changed to use the __clear_bit() format. 523 * so this line may not be changed to use the __clear_bit() format.
519 */ 524 */
520 bss->tim[aid / 8] &= ~(1 << (aid % 8)); 525 tim[id / 8] &= ~(1 << (id % 8));
521} 526}
522 527
523static unsigned long ieee80211_tids_for_ac(int ac) 528static unsigned long ieee80211_tids_for_ac(int ac)
@@ -541,14 +546,23 @@ static unsigned long ieee80211_tids_for_ac(int ac)
541void sta_info_recalc_tim(struct sta_info *sta) 546void sta_info_recalc_tim(struct sta_info *sta)
542{ 547{
543 struct ieee80211_local *local = sta->local; 548 struct ieee80211_local *local = sta->local;
544 struct ieee80211_if_ap *bss = sta->sdata->bss; 549 struct ps_data *ps;
545 unsigned long flags; 550 unsigned long flags;
546 bool indicate_tim = false; 551 bool indicate_tim = false;
547 u8 ignore_for_tim = sta->sta.uapsd_queues; 552 u8 ignore_for_tim = sta->sta.uapsd_queues;
548 int ac; 553 int ac;
554 u16 id;
555
556 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
557 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
558 if (WARN_ON_ONCE(!sta->sdata->bss))
559 return;
549 560
550 if (WARN_ON_ONCE(!sta->sdata->bss)) 561 ps = &sta->sdata->bss->ps;
562 id = sta->sta.aid;
563 } else {
551 return; 564 return;
565 }
552 566
553 /* No need to do anything if the driver does all */ 567 /* No need to do anything if the driver does all */
554 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) 568 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
@@ -587,9 +601,9 @@ void sta_info_recalc_tim(struct sta_info *sta)
587 spin_lock_irqsave(&local->tim_lock, flags); 601 spin_lock_irqsave(&local->tim_lock, flags);
588 602
589 if (indicate_tim) 603 if (indicate_tim)
590 __bss_tim_set(bss, sta->sta.aid); 604 __bss_tim_set(ps->tim, id);
591 else 605 else
592 __bss_tim_clear(bss, sta->sta.aid); 606 __bss_tim_clear(ps->tim, id);
593 607
594 if (local->ops->set_tim) { 608 if (local->ops->set_tim) {
595 local->tim_in_locked_section = true; 609 local->tim_in_locked_section = true;
@@ -650,7 +664,7 @@ static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
650 */ 664 */
651 if (!skb) 665 if (!skb)
652 break; 666 break;
653 dev_kfree_skb(skb); 667 ieee80211_free_txskb(&local->hw, skb);
654 } 668 }
655 669
656 /* 670 /*
@@ -679,7 +693,7 @@ static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
679 local->total_ps_buffered--; 693 local->total_ps_buffered--;
680 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n", 694 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
681 sta->sta.addr); 695 sta->sta.addr);
682 dev_kfree_skb(skb); 696 ieee80211_free_txskb(&local->hw, skb);
683 } 697 }
684 698
685 /* 699 /*
@@ -893,8 +907,8 @@ void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
893 continue; 907 continue;
894 908
895 if (time_after(jiffies, sta->last_rx + exp_time)) { 909 if (time_after(jiffies, sta->last_rx + exp_time)) {
896 ibss_dbg(sdata, "expiring inactive STA %pM\n", 910 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
897 sta->sta.addr); 911 sta->sta.addr);
898 WARN_ON(__sta_info_destroy(sta)); 912 WARN_ON(__sta_info_destroy(sta));
899 } 913 }
900 } 914 }
@@ -948,10 +962,17 @@ static void clear_sta_ps_flags(void *_sta)
948{ 962{
949 struct sta_info *sta = _sta; 963 struct sta_info *sta = _sta;
950 struct ieee80211_sub_if_data *sdata = sta->sdata; 964 struct ieee80211_sub_if_data *sdata = sta->sdata;
965 struct ps_data *ps;
966
967 if (sdata->vif.type == NL80211_IFTYPE_AP ||
968 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
969 ps = &sdata->bss->ps;
970 else
971 return;
951 972
952 clear_sta_flag(sta, WLAN_STA_PS_DRIVER); 973 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
953 if (test_and_clear_sta_flag(sta, WLAN_STA_PS_STA)) 974 if (test_and_clear_sta_flag(sta, WLAN_STA_PS_STA))
954 atomic_dec(&sdata->bss->num_sta_ps); 975 atomic_dec(&ps->num_sta_ps);
955} 976}
956 977
957/* powersave support code */ 978/* powersave support code */
@@ -961,6 +982,7 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
961 struct ieee80211_local *local = sdata->local; 982 struct ieee80211_local *local = sdata->local;
962 struct sk_buff_head pending; 983 struct sk_buff_head pending;
963 int filtered = 0, buffered = 0, ac; 984 int filtered = 0, buffered = 0, ac;
985 unsigned long flags;
964 986
965 clear_sta_flag(sta, WLAN_STA_SP); 987 clear_sta_flag(sta, WLAN_STA_SP);
966 988
@@ -976,12 +998,16 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
976 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 998 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
977 int count = skb_queue_len(&pending), tmp; 999 int count = skb_queue_len(&pending), tmp;
978 1000
1001 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
979 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending); 1002 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
1003 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
980 tmp = skb_queue_len(&pending); 1004 tmp = skb_queue_len(&pending);
981 filtered += tmp - count; 1005 filtered += tmp - count;
982 count = tmp; 1006 count = tmp;
983 1007
1008 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
984 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending); 1009 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
1010 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
985 tmp = skb_queue_len(&pending); 1011 tmp = skb_queue_len(&pending);
986 buffered += tmp - count; 1012 buffered += tmp - count;
987 } 1013 }
@@ -1008,6 +1034,7 @@ static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
1008 __le16 fc; 1034 __le16 fc;
1009 bool qos = test_sta_flag(sta, WLAN_STA_WME); 1035 bool qos = test_sta_flag(sta, WLAN_STA_WME);
1010 struct ieee80211_tx_info *info; 1036 struct ieee80211_tx_info *info;
1037 struct ieee80211_chanctx_conf *chanctx_conf;
1011 1038
1012 if (qos) { 1039 if (qos) {
1013 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | 1040 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
@@ -1057,7 +1084,16 @@ static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
1057 1084
1058 drv_allow_buffered_frames(local, sta, BIT(tid), 1, reason, false); 1085 drv_allow_buffered_frames(local, sta, BIT(tid), 1, reason, false);
1059 1086
1060 ieee80211_xmit(sdata, skb); 1087 rcu_read_lock();
1088 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1089 if (WARN_ON(!chanctx_conf)) {
1090 rcu_read_unlock();
1091 kfree_skb(skb);
1092 return;
1093 }
1094
1095 ieee80211_xmit(sdata, skb, chanctx_conf->channel->band);
1096 rcu_read_unlock();
1061} 1097}
1062 1098
1063static void 1099static void
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index 3af0cc4130f1..ab63237107c8 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -189,30 +189,31 @@ static void ieee80211_frame_acked(struct sta_info *sta, struct sk_buff *skb)
189 } 189 }
190 190
191 if (ieee80211_is_action(mgmt->frame_control) && 191 if (ieee80211_is_action(mgmt->frame_control) &&
192 sdata->vif.type == NL80211_IFTYPE_STATION &&
193 mgmt->u.action.category == WLAN_CATEGORY_HT && 192 mgmt->u.action.category == WLAN_CATEGORY_HT &&
194 mgmt->u.action.u.ht_smps.action == WLAN_HT_ACTION_SMPS) { 193 mgmt->u.action.u.ht_smps.action == WLAN_HT_ACTION_SMPS &&
194 sdata->vif.type == NL80211_IFTYPE_STATION &&
195 ieee80211_sdata_running(sdata)) {
195 /* 196 /*
196 * This update looks racy, but isn't -- if we come 197 * This update looks racy, but isn't -- if we come
197 * here we've definitely got a station that we're 198 * here we've definitely got a station that we're
198 * talking to, and on a managed interface that can 199 * talking to, and on a managed interface that can
199 * only be the AP. And the only other place updating 200 * only be the AP. And the only other place updating
200 * this variable is before we're associated. 201 * this variable in managed mode is before association.
201 */ 202 */
202 switch (mgmt->u.action.u.ht_smps.smps_control) { 203 switch (mgmt->u.action.u.ht_smps.smps_control) {
203 case WLAN_HT_SMPS_CONTROL_DYNAMIC: 204 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
204 sta->sdata->u.mgd.ap_smps = IEEE80211_SMPS_DYNAMIC; 205 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
205 break; 206 break;
206 case WLAN_HT_SMPS_CONTROL_STATIC: 207 case WLAN_HT_SMPS_CONTROL_STATIC:
207 sta->sdata->u.mgd.ap_smps = IEEE80211_SMPS_STATIC; 208 sdata->smps_mode = IEEE80211_SMPS_STATIC;
208 break; 209 break;
209 case WLAN_HT_SMPS_CONTROL_DISABLED: 210 case WLAN_HT_SMPS_CONTROL_DISABLED:
210 default: /* shouldn't happen since we don't send that */ 211 default: /* shouldn't happen since we don't send that */
211 sta->sdata->u.mgd.ap_smps = IEEE80211_SMPS_OFF; 212 sdata->smps_mode = IEEE80211_SMPS_OFF;
212 break; 213 break;
213 } 214 }
214 215
215 ieee80211_queue_work(&local->hw, &local->recalc_smps); 216 ieee80211_queue_work(&local->hw, &sdata->recalc_smps);
216 } 217 }
217} 218}
218 219
@@ -324,6 +325,75 @@ static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band
324 325
325} 326}
326 327
328static void ieee80211_report_used_skb(struct ieee80211_local *local,
329 struct sk_buff *skb, bool dropped)
330{
331 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
332 struct ieee80211_hdr *hdr = (void *)skb->data;
333 bool acked = info->flags & IEEE80211_TX_STAT_ACK;
334
335 if (dropped)
336 acked = false;
337
338 if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) {
339 struct ieee80211_sub_if_data *sdata = NULL;
340 struct ieee80211_sub_if_data *iter_sdata;
341 u64 cookie = (unsigned long)skb;
342
343 rcu_read_lock();
344
345 if (skb->dev) {
346 list_for_each_entry_rcu(iter_sdata, &local->interfaces,
347 list) {
348 if (!iter_sdata->dev)
349 continue;
350
351 if (skb->dev == iter_sdata->dev) {
352 sdata = iter_sdata;
353 break;
354 }
355 }
356 } else {
357 sdata = rcu_dereference(local->p2p_sdata);
358 }
359
360 if (!sdata)
361 skb->dev = NULL;
362 else if (ieee80211_is_nullfunc(hdr->frame_control) ||
363 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
364 cfg80211_probe_status(sdata->dev, hdr->addr1,
365 cookie, acked, GFP_ATOMIC);
366 } else {
367 cfg80211_mgmt_tx_status(&sdata->wdev, cookie, skb->data,
368 skb->len, acked, GFP_ATOMIC);
369 }
370
371 rcu_read_unlock();
372 }
373
374 if (unlikely(info->ack_frame_id)) {
375 struct sk_buff *ack_skb;
376 unsigned long flags;
377
378 spin_lock_irqsave(&local->ack_status_lock, flags);
379 ack_skb = idr_find(&local->ack_status_frames,
380 info->ack_frame_id);
381 if (ack_skb)
382 idr_remove(&local->ack_status_frames,
383 info->ack_frame_id);
384 spin_unlock_irqrestore(&local->ack_status_lock, flags);
385
386 if (ack_skb) {
387 if (!dropped) {
388 /* consumes ack_skb */
389 skb_complete_wifi_ack(ack_skb, acked);
390 } else {
391 dev_kfree_skb_any(ack_skb);
392 }
393 }
394 }
395}
396
327/* 397/*
328 * Use a static threshold for now, best value to be determined 398 * Use a static threshold for now, best value to be determined
329 * by testing ... 399 * by testing ...
@@ -515,62 +585,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
515 msecs_to_jiffies(10)); 585 msecs_to_jiffies(10));
516 } 586 }
517 587
518 if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) { 588 ieee80211_report_used_skb(local, skb, false);
519 u64 cookie = (unsigned long)skb;
520 bool found = false;
521
522 acked = info->flags & IEEE80211_TX_STAT_ACK;
523
524 rcu_read_lock();
525
526 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
527 if (!sdata->dev)
528 continue;
529
530 if (skb->dev != sdata->dev)
531 continue;
532
533 found = true;
534 break;
535 }
536
537 if (!skb->dev) {
538 sdata = rcu_dereference(local->p2p_sdata);
539 if (sdata)
540 found = true;
541 }
542
543 if (!found)
544 skb->dev = NULL;
545 else if (ieee80211_is_nullfunc(hdr->frame_control) ||
546 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
547 cfg80211_probe_status(sdata->dev, hdr->addr1,
548 cookie, acked, GFP_ATOMIC);
549 } else {
550 cfg80211_mgmt_tx_status(&sdata->wdev, cookie, skb->data,
551 skb->len, acked, GFP_ATOMIC);
552 }
553
554 rcu_read_unlock();
555 }
556
557 if (unlikely(info->ack_frame_id)) {
558 struct sk_buff *ack_skb;
559 unsigned long flags;
560
561 spin_lock_irqsave(&local->ack_status_lock, flags);
562 ack_skb = idr_find(&local->ack_status_frames,
563 info->ack_frame_id);
564 if (ack_skb)
565 idr_remove(&local->ack_status_frames,
566 info->ack_frame_id);
567 spin_unlock_irqrestore(&local->ack_status_lock, flags);
568
569 /* consumes ack_skb */
570 if (ack_skb)
571 skb_complete_wifi_ack(ack_skb,
572 info->flags & IEEE80211_TX_STAT_ACK);
573 }
574 589
575 /* this was a transmitted frame, but now we want to reuse it */ 590 /* this was a transmitted frame, but now we want to reuse it */
576 skb_orphan(skb); 591 skb_orphan(skb);
@@ -646,25 +661,17 @@ EXPORT_SYMBOL(ieee80211_report_low_ack);
646void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb) 661void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb)
647{ 662{
648 struct ieee80211_local *local = hw_to_local(hw); 663 struct ieee80211_local *local = hw_to_local(hw);
649 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
650
651 if (unlikely(info->ack_frame_id)) {
652 struct sk_buff *ack_skb;
653 unsigned long flags;
654
655 spin_lock_irqsave(&local->ack_status_lock, flags);
656 ack_skb = idr_find(&local->ack_status_frames,
657 info->ack_frame_id);
658 if (ack_skb)
659 idr_remove(&local->ack_status_frames,
660 info->ack_frame_id);
661 spin_unlock_irqrestore(&local->ack_status_lock, flags);
662
663 /* consumes ack_skb */
664 if (ack_skb)
665 dev_kfree_skb_any(ack_skb);
666 }
667 664
665 ieee80211_report_used_skb(local, skb, true);
668 dev_kfree_skb_any(skb); 666 dev_kfree_skb_any(skb);
669} 667}
670EXPORT_SYMBOL(ieee80211_free_txskb); 668EXPORT_SYMBOL(ieee80211_free_txskb);
669
670void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
671 struct sk_buff_head *skbs)
672{
673 struct sk_buff *skb;
674
675 while ((skb = __skb_dequeue(skbs)))
676 ieee80211_free_txskb(hw, skb);
677}
diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index 18d9c8a52e9e..758836c85a80 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -28,6 +28,20 @@
28#define VIF_PR_FMT " vif:%s(%d%s)" 28#define VIF_PR_FMT " vif:%s(%d%s)"
29#define VIF_PR_ARG __get_str(vif_name), __entry->vif_type, __entry->p2p ? "/p2p" : "" 29#define VIF_PR_ARG __get_str(vif_name), __entry->vif_type, __entry->p2p ? "/p2p" : ""
30 30
31#define CHANCTX_ENTRY __field(int, freq) \
32 __field(int, chantype) \
33 __field(u8, rx_chains_static) \
34 __field(u8, rx_chains_dynamic)
35#define CHANCTX_ASSIGN __entry->freq = ctx->conf.channel->center_freq; \
36 __entry->chantype = ctx->conf.channel_type; \
37 __entry->rx_chains_static = ctx->conf.rx_chains_static; \
38 __entry->rx_chains_dynamic = ctx->conf.rx_chains_dynamic
39#define CHANCTX_PR_FMT " freq:%d MHz chantype:%d chains:%d/%d"
40#define CHANCTX_PR_ARG __entry->freq, __entry->chantype, \
41 __entry->rx_chains_static, __entry->rx_chains_dynamic
42
43
44
31/* 45/*
32 * Tracing for driver callbacks. 46 * Tracing for driver callbacks.
33 */ 47 */
@@ -301,20 +315,36 @@ TRACE_EVENT(drv_bss_info_changed,
301 TP_STRUCT__entry( 315 TP_STRUCT__entry(
302 LOCAL_ENTRY 316 LOCAL_ENTRY
303 VIF_ENTRY 317 VIF_ENTRY
318 __field(u32, changed)
304 __field(bool, assoc) 319 __field(bool, assoc)
320 __field(bool, ibss_joined)
321 __field(bool, ibss_creator)
305 __field(u16, aid) 322 __field(u16, aid)
306 __field(bool, cts) 323 __field(bool, cts)
307 __field(bool, shortpre) 324 __field(bool, shortpre)
308 __field(bool, shortslot) 325 __field(bool, shortslot)
326 __field(bool, enable_beacon)
309 __field(u8, dtimper) 327 __field(u8, dtimper)
310 __field(u16, bcnint) 328 __field(u16, bcnint)
311 __field(u16, assoc_cap) 329 __field(u16, assoc_cap)
312 __field(u64, sync_tsf) 330 __field(u64, sync_tsf)
313 __field(u32, sync_device_ts) 331 __field(u32, sync_device_ts)
314 __field(u32, basic_rates) 332 __field(u32, basic_rates)
315 __field(u32, changed) 333 __array(int, mcast_rate, IEEE80211_NUM_BANDS)
316 __field(bool, enable_beacon)
317 __field(u16, ht_operation_mode) 334 __field(u16, ht_operation_mode)
335 __field(s32, cqm_rssi_thold);
336 __field(s32, cqm_rssi_hyst);
337 __field(u32, channel_type);
338 __dynamic_array(u32, arp_addr_list, info->arp_addr_cnt);
339 __field(bool, arp_filter_enabled);
340 __field(bool, qos);
341 __field(bool, idle);
342 __field(bool, ps);
343 __dynamic_array(u8, ssid, info->ssid_len);
344 __field(bool, hidden_ssid);
345 __field(int, txpower)
346 __field(u8, p2p_ctwindow)
347 __field(bool, p2p_oppps)
318 ), 348 ),
319 349
320 TP_fast_assign( 350 TP_fast_assign(
@@ -323,17 +353,35 @@ TRACE_EVENT(drv_bss_info_changed,
323 __entry->changed = changed; 353 __entry->changed = changed;
324 __entry->aid = info->aid; 354 __entry->aid = info->aid;
325 __entry->assoc = info->assoc; 355 __entry->assoc = info->assoc;
356 __entry->ibss_joined = info->ibss_joined;
357 __entry->ibss_creator = info->ibss_creator;
326 __entry->shortpre = info->use_short_preamble; 358 __entry->shortpre = info->use_short_preamble;
327 __entry->cts = info->use_cts_prot; 359 __entry->cts = info->use_cts_prot;
328 __entry->shortslot = info->use_short_slot; 360 __entry->shortslot = info->use_short_slot;
361 __entry->enable_beacon = info->enable_beacon;
329 __entry->dtimper = info->dtim_period; 362 __entry->dtimper = info->dtim_period;
330 __entry->bcnint = info->beacon_int; 363 __entry->bcnint = info->beacon_int;
331 __entry->assoc_cap = info->assoc_capability; 364 __entry->assoc_cap = info->assoc_capability;
332 __entry->sync_tsf = info->sync_tsf; 365 __entry->sync_tsf = info->sync_tsf;
333 __entry->sync_device_ts = info->sync_device_ts; 366 __entry->sync_device_ts = info->sync_device_ts;
334 __entry->basic_rates = info->basic_rates; 367 __entry->basic_rates = info->basic_rates;
335 __entry->enable_beacon = info->enable_beacon; 368 memcpy(__entry->mcast_rate, info->mcast_rate,
369 sizeof(__entry->mcast_rate));
336 __entry->ht_operation_mode = info->ht_operation_mode; 370 __entry->ht_operation_mode = info->ht_operation_mode;
371 __entry->cqm_rssi_thold = info->cqm_rssi_thold;
372 __entry->cqm_rssi_hyst = info->cqm_rssi_hyst;
373 __entry->channel_type = info->channel_type;
374 memcpy(__get_dynamic_array(arp_addr_list), info->arp_addr_list,
375 sizeof(u32) * info->arp_addr_cnt);
376 __entry->arp_filter_enabled = info->arp_filter_enabled;
377 __entry->qos = info->qos;
378 __entry->idle = info->idle;
379 __entry->ps = info->ps;
380 memcpy(__get_dynamic_array(ssid), info->ssid, info->ssid_len);
381 __entry->hidden_ssid = info->hidden_ssid;
382 __entry->txpower = info->txpower;
383 __entry->p2p_ctwindow = info->p2p_ctwindow;
384 __entry->p2p_oppps = info->p2p_oppps;
337 ), 385 ),
338 386
339 TP_printk( 387 TP_printk(
@@ -1001,34 +1049,6 @@ DEFINE_EVENT(local_only_evt, drv_cancel_remain_on_channel,
1001 TP_ARGS(local) 1049 TP_ARGS(local)
1002); 1050);
1003 1051
1004TRACE_EVENT(drv_offchannel_tx,
1005 TP_PROTO(struct ieee80211_local *local, struct sk_buff *skb,
1006 struct ieee80211_channel *chan,
1007 enum nl80211_channel_type channel_type,
1008 unsigned int wait),
1009
1010 TP_ARGS(local, skb, chan, channel_type, wait),
1011
1012 TP_STRUCT__entry(
1013 LOCAL_ENTRY
1014 __field(int, center_freq)
1015 __field(int, channel_type)
1016 __field(unsigned int, wait)
1017 ),
1018
1019 TP_fast_assign(
1020 LOCAL_ASSIGN;
1021 __entry->center_freq = chan->center_freq;
1022 __entry->channel_type = channel_type;
1023 __entry->wait = wait;
1024 ),
1025
1026 TP_printk(
1027 LOCAL_PR_FMT " freq:%dMHz, wait:%dms",
1028 LOCAL_PR_ARG, __entry->center_freq, __entry->wait
1029 )
1030);
1031
1032TRACE_EVENT(drv_set_ringparam, 1052TRACE_EVENT(drv_set_ringparam,
1033 TP_PROTO(struct ieee80211_local *local, u32 tx, u32 rx), 1053 TP_PROTO(struct ieee80211_local *local, u32 tx, u32 rx),
1034 1054
@@ -1256,6 +1276,146 @@ DEFINE_EVENT(local_sdata_evt, drv_mgd_prepare_tx,
1256 TP_ARGS(local, sdata) 1276 TP_ARGS(local, sdata)
1257); 1277);
1258 1278
1279DECLARE_EVENT_CLASS(local_chanctx,
1280 TP_PROTO(struct ieee80211_local *local,
1281 struct ieee80211_chanctx *ctx),
1282
1283 TP_ARGS(local, ctx),
1284
1285 TP_STRUCT__entry(
1286 LOCAL_ENTRY
1287 CHANCTX_ENTRY
1288 ),
1289
1290 TP_fast_assign(
1291 LOCAL_ASSIGN;
1292 CHANCTX_ASSIGN;
1293 ),
1294
1295 TP_printk(
1296 LOCAL_PR_FMT CHANCTX_PR_FMT,
1297 LOCAL_PR_ARG, CHANCTX_PR_ARG
1298 )
1299);
1300
1301DEFINE_EVENT(local_chanctx, drv_add_chanctx,
1302 TP_PROTO(struct ieee80211_local *local,
1303 struct ieee80211_chanctx *ctx),
1304 TP_ARGS(local, ctx)
1305);
1306
1307DEFINE_EVENT(local_chanctx, drv_remove_chanctx,
1308 TP_PROTO(struct ieee80211_local *local,
1309 struct ieee80211_chanctx *ctx),
1310 TP_ARGS(local, ctx)
1311);
1312
1313TRACE_EVENT(drv_change_chanctx,
1314 TP_PROTO(struct ieee80211_local *local,
1315 struct ieee80211_chanctx *ctx,
1316 u32 changed),
1317
1318 TP_ARGS(local, ctx, changed),
1319
1320 TP_STRUCT__entry(
1321 LOCAL_ENTRY
1322 CHANCTX_ENTRY
1323 __field(u32, changed)
1324 ),
1325
1326 TP_fast_assign(
1327 LOCAL_ASSIGN;
1328 CHANCTX_ASSIGN;
1329 __entry->changed = changed;
1330 ),
1331
1332 TP_printk(
1333 LOCAL_PR_FMT CHANCTX_PR_FMT " changed:%#x",
1334 LOCAL_PR_ARG, CHANCTX_PR_ARG, __entry->changed
1335 )
1336);
1337
1338DECLARE_EVENT_CLASS(local_sdata_chanctx,
1339 TP_PROTO(struct ieee80211_local *local,
1340 struct ieee80211_sub_if_data *sdata,
1341 struct ieee80211_chanctx *ctx),
1342
1343 TP_ARGS(local, sdata, ctx),
1344
1345 TP_STRUCT__entry(
1346 LOCAL_ENTRY
1347 VIF_ENTRY
1348 CHANCTX_ENTRY
1349 ),
1350
1351 TP_fast_assign(
1352 LOCAL_ASSIGN;
1353 VIF_ASSIGN;
1354 CHANCTX_ASSIGN;
1355 ),
1356
1357 TP_printk(
1358 LOCAL_PR_FMT VIF_PR_FMT CHANCTX_PR_FMT,
1359 LOCAL_PR_ARG, VIF_PR_ARG, CHANCTX_PR_ARG
1360 )
1361);
1362
1363DEFINE_EVENT(local_sdata_chanctx, drv_assign_vif_chanctx,
1364 TP_PROTO(struct ieee80211_local *local,
1365 struct ieee80211_sub_if_data *sdata,
1366 struct ieee80211_chanctx *ctx),
1367 TP_ARGS(local, sdata, ctx)
1368);
1369
1370DEFINE_EVENT(local_sdata_chanctx, drv_unassign_vif_chanctx,
1371 TP_PROTO(struct ieee80211_local *local,
1372 struct ieee80211_sub_if_data *sdata,
1373 struct ieee80211_chanctx *ctx),
1374 TP_ARGS(local, sdata, ctx)
1375);
1376
1377TRACE_EVENT(drv_start_ap,
1378 TP_PROTO(struct ieee80211_local *local,
1379 struct ieee80211_sub_if_data *sdata,
1380 struct ieee80211_bss_conf *info),
1381
1382 TP_ARGS(local, sdata, info),
1383
1384 TP_STRUCT__entry(
1385 LOCAL_ENTRY
1386 VIF_ENTRY
1387 __field(u8, dtimper)
1388 __field(u16, bcnint)
1389 __dynamic_array(u8, ssid, info->ssid_len);
1390 __field(bool, hidden_ssid);
1391 ),
1392
1393 TP_fast_assign(
1394 LOCAL_ASSIGN;
1395 VIF_ASSIGN;
1396 __entry->dtimper = info->dtim_period;
1397 __entry->bcnint = info->beacon_int;
1398 memcpy(__get_dynamic_array(ssid), info->ssid, info->ssid_len);
1399 __entry->hidden_ssid = info->hidden_ssid;
1400 ),
1401
1402 TP_printk(
1403 LOCAL_PR_FMT VIF_PR_FMT,
1404 LOCAL_PR_ARG, VIF_PR_ARG
1405 )
1406);
1407
1408DEFINE_EVENT(local_sdata_evt, drv_stop_ap,
1409 TP_PROTO(struct ieee80211_local *local,
1410 struct ieee80211_sub_if_data *sdata),
1411 TP_ARGS(local, sdata)
1412);
1413
1414DEFINE_EVENT(local_only_evt, drv_restart_complete,
1415 TP_PROTO(struct ieee80211_local *local),
1416 TP_ARGS(local)
1417);
1418
1259/* 1419/*
1260 * Tracing for API calls that drivers call. 1420 * Tracing for API calls that drivers call.
1261 */ 1421 */
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index c9bf83f36657..04076250264b 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -324,22 +324,20 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
324 struct ieee80211_sub_if_data *sdata; 324 struct ieee80211_sub_if_data *sdata;
325 struct sta_info *sta; 325 struct sta_info *sta;
326 326
327 /*
328 * virtual interfaces are protected by RCU
329 */
330 rcu_read_lock();
331
332 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 327 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
333 struct ieee80211_if_ap *ap; 328 struct ps_data *ps;
334 if (sdata->vif.type != NL80211_IFTYPE_AP) 329
330 if (sdata->vif.type == NL80211_IFTYPE_AP)
331 ps = &sdata->u.ap.ps;
332 else
335 continue; 333 continue;
336 ap = &sdata->u.ap; 334
337 skb = skb_dequeue(&ap->ps_bc_buf); 335 skb = skb_dequeue(&ps->bc_buf);
338 if (skb) { 336 if (skb) {
339 purged++; 337 purged++;
340 dev_kfree_skb(skb); 338 dev_kfree_skb(skb);
341 } 339 }
342 total += skb_queue_len(&ap->ps_bc_buf); 340 total += skb_queue_len(&ps->bc_buf);
343 } 341 }
344 342
345 /* 343 /*
@@ -360,8 +358,6 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
360 } 358 }
361 } 359 }
362 360
363 rcu_read_unlock();
364
365 local->total_ps_buffered = total; 361 local->total_ps_buffered = total;
366 ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged); 362 ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged);
367} 363}
@@ -371,6 +367,7 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
371{ 367{
372 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 368 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
373 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 369 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
370 struct ps_data *ps;
374 371
375 /* 372 /*
376 * broadcast/multicast frame 373 * broadcast/multicast frame
@@ -380,16 +377,24 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
380 * This is done either by the hardware or us. 377 * This is done either by the hardware or us.
381 */ 378 */
382 379
383 /* powersaving STAs only in AP/VLAN mode */ 380 /* powersaving STAs currently only in AP/VLAN mode */
384 if (!tx->sdata->bss) 381 if (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
382 tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
383 if (!tx->sdata->bss)
384 return TX_CONTINUE;
385
386 ps = &tx->sdata->bss->ps;
387 } else {
385 return TX_CONTINUE; 388 return TX_CONTINUE;
389 }
390
386 391
387 /* no buffering for ordered frames */ 392 /* no buffering for ordered frames */
388 if (ieee80211_has_order(hdr->frame_control)) 393 if (ieee80211_has_order(hdr->frame_control))
389 return TX_CONTINUE; 394 return TX_CONTINUE;
390 395
391 /* no stations in PS mode */ 396 /* no stations in PS mode */
392 if (!atomic_read(&tx->sdata->bss->num_sta_ps)) 397 if (!atomic_read(&ps->num_sta_ps))
393 return TX_CONTINUE; 398 return TX_CONTINUE;
394 399
395 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM; 400 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
@@ -404,14 +409,14 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
404 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 409 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
405 purge_old_ps_buffers(tx->local); 410 purge_old_ps_buffers(tx->local);
406 411
407 if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >= AP_MAX_BC_BUFFER) { 412 if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) {
408 ps_dbg(tx->sdata, 413 ps_dbg(tx->sdata,
409 "BC TX buffer full - dropping the oldest frame\n"); 414 "BC TX buffer full - dropping the oldest frame\n");
410 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf)); 415 dev_kfree_skb(skb_dequeue(&ps->bc_buf));
411 } else 416 } else
412 tx->local->total_ps_buffered++; 417 tx->local->total_ps_buffered++;
413 418
414 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb); 419 skb_queue_tail(&ps->bc_buf, tx->skb);
415 420
416 return TX_QUEUED; 421 return TX_QUEUED;
417} 422}
@@ -951,7 +956,6 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
951 fragnum = 0; 956 fragnum = 0;
952 957
953 skb_queue_walk(&tx->skbs, skb) { 958 skb_queue_walk(&tx->skbs, skb) {
954 int next_len;
955 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); 959 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
956 960
957 hdr = (void *)skb->data; 961 hdr = (void *)skb->data;
@@ -970,7 +974,6 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
970 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; 974 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
971 } else { 975 } else {
972 hdr->frame_control &= ~morefrags; 976 hdr->frame_control &= ~morefrags;
973 next_len = 0;
974 } 977 }
975 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG); 978 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
976 fragnum++; 979 fragnum++;
@@ -1358,7 +1361,7 @@ static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1358 if (tx->skb) 1361 if (tx->skb)
1359 ieee80211_free_txskb(&tx->local->hw, tx->skb); 1362 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1360 else 1363 else
1361 __skb_queue_purge(&tx->skbs); 1364 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1362 return -1; 1365 return -1;
1363 } else if (unlikely(res == TX_QUEUED)) { 1366 } else if (unlikely(res == TX_QUEUED)) {
1364 I802_DEBUG_INC(tx->local->tx_handlers_queued); 1367 I802_DEBUG_INC(tx->local->tx_handlers_queued);
@@ -1372,7 +1375,8 @@ static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1372 * Returns false if the frame couldn't be transmitted but was queued instead. 1375 * Returns false if the frame couldn't be transmitted but was queued instead.
1373 */ 1376 */
1374static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, 1377static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1375 struct sk_buff *skb, bool txpending) 1378 struct sk_buff *skb, bool txpending,
1379 enum ieee80211_band band)
1376{ 1380{
1377 struct ieee80211_local *local = sdata->local; 1381 struct ieee80211_local *local = sdata->local;
1378 struct ieee80211_tx_data tx; 1382 struct ieee80211_tx_data tx;
@@ -1386,20 +1390,18 @@ static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1386 return true; 1390 return true;
1387 } 1391 }
1388 1392
1389 rcu_read_lock();
1390
1391 /* initialises tx */ 1393 /* initialises tx */
1392 led_len = skb->len; 1394 led_len = skb->len;
1393 res_prepare = ieee80211_tx_prepare(sdata, &tx, skb); 1395 res_prepare = ieee80211_tx_prepare(sdata, &tx, skb);
1394 1396
1395 if (unlikely(res_prepare == TX_DROP)) { 1397 if (unlikely(res_prepare == TX_DROP)) {
1396 ieee80211_free_txskb(&local->hw, skb); 1398 ieee80211_free_txskb(&local->hw, skb);
1397 goto out; 1399 return true;
1398 } else if (unlikely(res_prepare == TX_QUEUED)) { 1400 } else if (unlikely(res_prepare == TX_QUEUED)) {
1399 goto out; 1401 return true;
1400 } 1402 }
1401 1403
1402 info->band = local->hw.conf.channel->band; 1404 info->band = band;
1403 1405
1404 /* set up hw_queue value early */ 1406 /* set up hw_queue value early */
1405 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) || 1407 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
@@ -1410,8 +1412,7 @@ static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1410 if (!invoke_tx_handlers(&tx)) 1412 if (!invoke_tx_handlers(&tx))
1411 result = __ieee80211_tx(local, &tx.skbs, led_len, 1413 result = __ieee80211_tx(local, &tx.skbs, led_len,
1412 tx.sta, txpending); 1414 tx.sta, txpending);
1413 out: 1415
1414 rcu_read_unlock();
1415 return result; 1416 return result;
1416} 1417}
1417 1418
@@ -1446,7 +1447,8 @@ static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
1446 return 0; 1447 return 0;
1447} 1448}
1448 1449
1449void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) 1450void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1451 enum ieee80211_band band)
1450{ 1452{
1451 struct ieee80211_local *local = sdata->local; 1453 struct ieee80211_local *local = sdata->local;
1452 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1454 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
@@ -1454,8 +1456,6 @@ void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
1454 int headroom; 1456 int headroom;
1455 bool may_encrypt; 1457 bool may_encrypt;
1456 1458
1457 rcu_read_lock();
1458
1459 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT); 1459 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
1460 1460
1461 headroom = local->tx_headroom; 1461 headroom = local->tx_headroom;
@@ -1466,7 +1466,6 @@ void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
1466 1466
1467 if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) { 1467 if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
1468 ieee80211_free_txskb(&local->hw, skb); 1468 ieee80211_free_txskb(&local->hw, skb);
1469 rcu_read_unlock();
1470 return; 1469 return;
1471 } 1470 }
1472 1471
@@ -1478,13 +1477,11 @@ void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
1478 !is_multicast_ether_addr(hdr->addr1) && 1477 !is_multicast_ether_addr(hdr->addr1) &&
1479 mesh_nexthop_resolve(skb, sdata)) { 1478 mesh_nexthop_resolve(skb, sdata)) {
1480 /* skb queued: don't free */ 1479 /* skb queued: don't free */
1481 rcu_read_unlock();
1482 return; 1480 return;
1483 } 1481 }
1484 1482
1485 ieee80211_set_qos_hdr(sdata, skb); 1483 ieee80211_set_qos_hdr(sdata, skb);
1486 ieee80211_tx(sdata, skb, false); 1484 ieee80211_tx(sdata, skb, false, band);
1487 rcu_read_unlock();
1488} 1485}
1489 1486
1490static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb) 1487static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
@@ -1574,7 +1571,8 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1574 struct net_device *dev) 1571 struct net_device *dev)
1575{ 1572{
1576 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1573 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1577 struct ieee80211_channel *chan = local->hw.conf.channel; 1574 struct ieee80211_chanctx_conf *chanctx_conf;
1575 struct ieee80211_channel *chan;
1578 struct ieee80211_radiotap_header *prthdr = 1576 struct ieee80211_radiotap_header *prthdr =
1579 (struct ieee80211_radiotap_header *)skb->data; 1577 (struct ieee80211_radiotap_header *)skb->data;
1580 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1578 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
@@ -1583,26 +1581,6 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1583 u16 len_rthdr; 1581 u16 len_rthdr;
1584 int hdrlen; 1582 int hdrlen;
1585 1583
1586 /*
1587 * Frame injection is not allowed if beaconing is not allowed
1588 * or if we need radar detection. Beaconing is usually not allowed when
1589 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
1590 * Passive scan is also used in world regulatory domains where
1591 * your country is not known and as such it should be treated as
1592 * NO TX unless the channel is explicitly allowed in which case
1593 * your current regulatory domain would not have the passive scan
1594 * flag.
1595 *
1596 * Since AP mode uses monitor interfaces to inject/TX management
1597 * frames we can make AP mode the exception to this rule once it
1598 * supports radar detection as its implementation can deal with
1599 * radar detection by itself. We can do that later by adding a
1600 * monitor flag interfaces used for AP support.
1601 */
1602 if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
1603 IEEE80211_CHAN_PASSIVE_SCAN)))
1604 goto fail;
1605
1606 /* check for not even having the fixed radiotap header part */ 1584 /* check for not even having the fixed radiotap header part */
1607 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) 1585 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
1608 goto fail; /* too short to be possibly valid */ 1586 goto fail; /* too short to be possibly valid */
@@ -1688,11 +1666,45 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1688 } 1666 }
1689 } 1667 }
1690 1668
1691 ieee80211_xmit(sdata, skb); 1669 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1670 if (!chanctx_conf) {
1671 tmp_sdata = rcu_dereference(local->monitor_sdata);
1672 if (tmp_sdata)
1673 chanctx_conf =
1674 rcu_dereference(tmp_sdata->vif.chanctx_conf);
1675 }
1676 if (!chanctx_conf)
1677 goto fail_rcu;
1678
1679 chan = chanctx_conf->channel;
1680
1681 /*
1682 * Frame injection is not allowed if beaconing is not allowed
1683 * or if we need radar detection. Beaconing is usually not allowed when
1684 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
1685 * Passive scan is also used in world regulatory domains where
1686 * your country is not known and as such it should be treated as
1687 * NO TX unless the channel is explicitly allowed in which case
1688 * your current regulatory domain would not have the passive scan
1689 * flag.
1690 *
1691 * Since AP mode uses monitor interfaces to inject/TX management
1692 * frames we can make AP mode the exception to this rule once it
1693 * supports radar detection as its implementation can deal with
1694 * radar detection by itself. We can do that later by adding a
1695 * monitor flag interfaces used for AP support.
1696 */
1697 if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
1698 IEEE80211_CHAN_PASSIVE_SCAN)))
1699 goto fail_rcu;
1700
1701 ieee80211_xmit(sdata, skb, chan->band);
1692 rcu_read_unlock(); 1702 rcu_read_unlock();
1693 1703
1694 return NETDEV_TX_OK; 1704 return NETDEV_TX_OK;
1695 1705
1706fail_rcu:
1707 rcu_read_unlock();
1696fail: 1708fail:
1697 dev_kfree_skb(skb); 1709 dev_kfree_skb(skb);
1698 return NETDEV_TX_OK; /* meaning, we dealt with the skb */ 1710 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
@@ -1734,6 +1746,9 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1734 bool multicast; 1746 bool multicast;
1735 u32 info_flags = 0; 1747 u32 info_flags = 0;
1736 u16 info_id = 0; 1748 u16 info_id = 0;
1749 struct ieee80211_chanctx_conf *chanctx_conf;
1750 struct ieee80211_sub_if_data *ap_sdata;
1751 enum ieee80211_band band;
1737 1752
1738 if (unlikely(skb->len < ETH_HLEN)) 1753 if (unlikely(skb->len < ETH_HLEN))
1739 goto fail; 1754 goto fail;
@@ -1743,9 +1758,10 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1743 ethertype = (skb->data[12] << 8) | skb->data[13]; 1758 ethertype = (skb->data[12] << 8) | skb->data[13];
1744 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); 1759 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
1745 1760
1761 rcu_read_lock();
1762
1746 switch (sdata->vif.type) { 1763 switch (sdata->vif.type) {
1747 case NL80211_IFTYPE_AP_VLAN: 1764 case NL80211_IFTYPE_AP_VLAN:
1748 rcu_read_lock();
1749 sta = rcu_dereference(sdata->u.vlan.sta); 1765 sta = rcu_dereference(sdata->u.vlan.sta);
1750 if (sta) { 1766 if (sta) {
1751 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1767 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
@@ -1758,7 +1774,12 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1758 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 1774 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1759 wme_sta = test_sta_flag(sta, WLAN_STA_WME); 1775 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
1760 } 1776 }
1761 rcu_read_unlock(); 1777 ap_sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1778 u.ap);
1779 chanctx_conf = rcu_dereference(ap_sdata->vif.chanctx_conf);
1780 if (!chanctx_conf)
1781 goto fail_rcu;
1782 band = chanctx_conf->channel->band;
1762 if (sta) 1783 if (sta)
1763 break; 1784 break;
1764 /* fall through */ 1785 /* fall through */
@@ -1769,6 +1790,11 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1769 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 1790 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1770 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); 1791 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
1771 hdrlen = 24; 1792 hdrlen = 24;
1793 if (sdata->vif.type == NL80211_IFTYPE_AP)
1794 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1795 if (!chanctx_conf)
1796 goto fail_rcu;
1797 band = chanctx_conf->channel->band;
1772 break; 1798 break;
1773 case NL80211_IFTYPE_WDS: 1799 case NL80211_IFTYPE_WDS:
1774 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1800 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
@@ -1778,15 +1804,20 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1778 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1804 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1779 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 1805 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1780 hdrlen = 30; 1806 hdrlen = 30;
1807 /*
1808 * This is the exception! WDS style interfaces are prohibited
1809 * when channel contexts are in used so this must be valid
1810 */
1811 band = local->hw.conf.channel->band;
1781 break; 1812 break;
1782#ifdef CONFIG_MAC80211_MESH 1813#ifdef CONFIG_MAC80211_MESH
1783 case NL80211_IFTYPE_MESH_POINT: 1814 case NL80211_IFTYPE_MESH_POINT:
1784 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) { 1815 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
1785 /* Do not send frames with mesh_ttl == 0 */ 1816 /* Do not send frames with mesh_ttl == 0 */
1786 sdata->u.mesh.mshstats.dropped_frames_ttl++; 1817 sdata->u.mesh.mshstats.dropped_frames_ttl++;
1787 goto fail; 1818 goto fail_rcu;
1788 } 1819 }
1789 rcu_read_lock(); 1820
1790 if (!is_multicast_ether_addr(skb->data)) { 1821 if (!is_multicast_ether_addr(skb->data)) {
1791 mpath = mesh_path_lookup(skb->data, sdata); 1822 mpath = mesh_path_lookup(skb->data, sdata);
1792 if (!mpath) 1823 if (!mpath)
@@ -1803,7 +1834,6 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1803 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) { 1834 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
1804 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 1835 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1805 skb->data, skb->data + ETH_ALEN); 1836 skb->data, skb->data + ETH_ALEN);
1806 rcu_read_unlock();
1807 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr, 1837 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
1808 sdata, NULL, NULL); 1838 sdata, NULL, NULL);
1809 } else { 1839 } else {
@@ -1819,7 +1849,6 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1819 mesh_da = mppath->mpp; 1849 mesh_da = mppath->mpp;
1820 else if (mpath) 1850 else if (mpath)
1821 mesh_da = mpath->dst; 1851 mesh_da = mpath->dst;
1822 rcu_read_unlock();
1823 1852
1824 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 1853 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1825 mesh_da, sdata->vif.addr); 1854 mesh_da, sdata->vif.addr);
@@ -1839,13 +1868,16 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1839 skb->data + ETH_ALEN); 1868 skb->data + ETH_ALEN);
1840 1869
1841 } 1870 }
1871 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1872 if (!chanctx_conf)
1873 goto fail_rcu;
1874 band = chanctx_conf->channel->band;
1842 break; 1875 break;
1843#endif 1876#endif
1844 case NL80211_IFTYPE_STATION: 1877 case NL80211_IFTYPE_STATION:
1845 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) { 1878 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1846 bool tdls_peer = false; 1879 bool tdls_peer = false;
1847 1880
1848 rcu_read_lock();
1849 sta = sta_info_get(sdata, skb->data); 1881 sta = sta_info_get(sdata, skb->data);
1850 if (sta) { 1882 if (sta) {
1851 authorized = test_sta_flag(sta, 1883 authorized = test_sta_flag(sta,
@@ -1856,7 +1888,6 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1856 tdls_auth = test_sta_flag(sta, 1888 tdls_auth = test_sta_flag(sta,
1857 WLAN_STA_TDLS_PEER_AUTH); 1889 WLAN_STA_TDLS_PEER_AUTH);
1858 } 1890 }
1859 rcu_read_unlock();
1860 1891
1861 /* 1892 /*
1862 * If the TDLS link is enabled, send everything 1893 * If the TDLS link is enabled, send everything
@@ -1871,7 +1902,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1871 if (tdls_direct) { 1902 if (tdls_direct) {
1872 /* link during setup - throw out frames to peer */ 1903 /* link during setup - throw out frames to peer */
1873 if (!tdls_auth) 1904 if (!tdls_auth)
1874 goto fail; 1905 goto fail_rcu;
1875 1906
1876 /* DA SA BSSID */ 1907 /* DA SA BSSID */
1877 memcpy(hdr.addr1, skb->data, ETH_ALEN); 1908 memcpy(hdr.addr1, skb->data, ETH_ALEN);
@@ -1896,6 +1927,10 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1896 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1927 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1897 hdrlen = 24; 1928 hdrlen = 24;
1898 } 1929 }
1930 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1931 if (!chanctx_conf)
1932 goto fail_rcu;
1933 band = chanctx_conf->channel->band;
1899 break; 1934 break;
1900 case NL80211_IFTYPE_ADHOC: 1935 case NL80211_IFTYPE_ADHOC:
1901 /* DA SA BSSID */ 1936 /* DA SA BSSID */
@@ -1903,9 +1938,13 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1903 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 1938 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1904 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN); 1939 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
1905 hdrlen = 24; 1940 hdrlen = 24;
1941 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1942 if (!chanctx_conf)
1943 goto fail_rcu;
1944 band = chanctx_conf->channel->band;
1906 break; 1945 break;
1907 default: 1946 default:
1908 goto fail; 1947 goto fail_rcu;
1909 } 1948 }
1910 1949
1911 /* 1950 /*
@@ -1915,13 +1954,11 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1915 */ 1954 */
1916 multicast = is_multicast_ether_addr(hdr.addr1); 1955 multicast = is_multicast_ether_addr(hdr.addr1);
1917 if (!multicast) { 1956 if (!multicast) {
1918 rcu_read_lock();
1919 sta = sta_info_get(sdata, hdr.addr1); 1957 sta = sta_info_get(sdata, hdr.addr1);
1920 if (sta) { 1958 if (sta) {
1921 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 1959 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1922 wme_sta = test_sta_flag(sta, WLAN_STA_WME); 1960 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
1923 } 1961 }
1924 rcu_read_unlock();
1925 } 1962 }
1926 1963
1927 /* For mesh, the use of the QoS header is mandatory */ 1964 /* For mesh, the use of the QoS header is mandatory */
@@ -1949,7 +1986,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1949 1986
1950 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); 1987 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
1951 1988
1952 goto fail; 1989 goto fail_rcu;
1953 } 1990 }
1954 1991
1955 if (unlikely(!multicast && skb->sk && 1992 if (unlikely(!multicast && skb->sk &&
@@ -2004,7 +2041,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
2004 kfree_skb(tmp_skb); 2041 kfree_skb(tmp_skb);
2005 2042
2006 if (!skb) 2043 if (!skb)
2007 goto fail; 2044 goto fail_rcu;
2008 } 2045 }
2009 2046
2010 hdr.frame_control = fc; 2047 hdr.frame_control = fc;
@@ -2052,7 +2089,8 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
2052 head_need = max_t(int, 0, head_need); 2089 head_need = max_t(int, 0, head_need);
2053 if (ieee80211_skb_resize(sdata, skb, head_need, true)) { 2090 if (ieee80211_skb_resize(sdata, skb, head_need, true)) {
2054 ieee80211_free_txskb(&local->hw, skb); 2091 ieee80211_free_txskb(&local->hw, skb);
2055 return NETDEV_TX_OK; 2092 skb = NULL;
2093 goto fail_rcu;
2056 } 2094 }
2057 } 2095 }
2058 2096
@@ -2104,10 +2142,13 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
2104 info->flags = info_flags; 2142 info->flags = info_flags;
2105 info->ack_frame_id = info_id; 2143 info->ack_frame_id = info_id;
2106 2144
2107 ieee80211_xmit(sdata, skb); 2145 ieee80211_xmit(sdata, skb, band);
2146 rcu_read_unlock();
2108 2147
2109 return NETDEV_TX_OK; 2148 return NETDEV_TX_OK;
2110 2149
2150 fail_rcu:
2151 rcu_read_unlock();
2111 fail: 2152 fail:
2112 dev_kfree_skb(skb); 2153 dev_kfree_skb(skb);
2113 return NETDEV_TX_OK; 2154 return NETDEV_TX_OK;
@@ -2120,10 +2161,13 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
2120 */ 2161 */
2121void ieee80211_clear_tx_pending(struct ieee80211_local *local) 2162void ieee80211_clear_tx_pending(struct ieee80211_local *local)
2122{ 2163{
2164 struct sk_buff *skb;
2123 int i; 2165 int i;
2124 2166
2125 for (i = 0; i < local->hw.queues; i++) 2167 for (i = 0; i < local->hw.queues; i++) {
2126 skb_queue_purge(&local->pending[i]); 2168 while ((skb = skb_dequeue(&local->pending[i])) != NULL)
2169 ieee80211_free_txskb(&local->hw, skb);
2170 }
2127} 2171}
2128 2172
2129/* 2173/*
@@ -2139,11 +2183,18 @@ static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
2139 struct sta_info *sta; 2183 struct sta_info *sta;
2140 struct ieee80211_hdr *hdr; 2184 struct ieee80211_hdr *hdr;
2141 bool result; 2185 bool result;
2186 struct ieee80211_chanctx_conf *chanctx_conf;
2142 2187
2143 sdata = vif_to_sdata(info->control.vif); 2188 sdata = vif_to_sdata(info->control.vif);
2144 2189
2145 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) { 2190 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
2146 result = ieee80211_tx(sdata, skb, true); 2191 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2192 if (unlikely(!chanctx_conf)) {
2193 dev_kfree_skb(skb);
2194 return true;
2195 }
2196 result = ieee80211_tx(sdata, skb, true,
2197 chanctx_conf->channel->band);
2147 } else { 2198 } else {
2148 struct sk_buff_head skbs; 2199 struct sk_buff_head skbs;
2149 2200
@@ -2211,9 +2262,8 @@ void ieee80211_tx_pending(unsigned long data)
2211/* functions for drivers to get certain frames */ 2262/* functions for drivers to get certain frames */
2212 2263
2213static void ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, 2264static void ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2214 struct ieee80211_if_ap *bss, 2265 struct ps_data *ps,
2215 struct sk_buff *skb, 2266 struct sk_buff *skb)
2216 struct beacon_data *beacon)
2217{ 2267{
2218 u8 *pos, *tim; 2268 u8 *pos, *tim;
2219 int aid0 = 0; 2269 int aid0 = 0;
@@ -2221,27 +2271,27 @@ static void ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2221 2271
2222 /* Generate bitmap for TIM only if there are any STAs in power save 2272 /* Generate bitmap for TIM only if there are any STAs in power save
2223 * mode. */ 2273 * mode. */
2224 if (atomic_read(&bss->num_sta_ps) > 0) 2274 if (atomic_read(&ps->num_sta_ps) > 0)
2225 /* in the hope that this is faster than 2275 /* in the hope that this is faster than
2226 * checking byte-for-byte */ 2276 * checking byte-for-byte */
2227 have_bits = !bitmap_empty((unsigned long*)bss->tim, 2277 have_bits = !bitmap_empty((unsigned long*)ps->tim,
2228 IEEE80211_MAX_AID+1); 2278 IEEE80211_MAX_AID+1);
2229 2279
2230 if (bss->dtim_count == 0) 2280 if (ps->dtim_count == 0)
2231 bss->dtim_count = sdata->vif.bss_conf.dtim_period - 1; 2281 ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1;
2232 else 2282 else
2233 bss->dtim_count--; 2283 ps->dtim_count--;
2234 2284
2235 tim = pos = (u8 *) skb_put(skb, 6); 2285 tim = pos = (u8 *) skb_put(skb, 6);
2236 *pos++ = WLAN_EID_TIM; 2286 *pos++ = WLAN_EID_TIM;
2237 *pos++ = 4; 2287 *pos++ = 4;
2238 *pos++ = bss->dtim_count; 2288 *pos++ = ps->dtim_count;
2239 *pos++ = sdata->vif.bss_conf.dtim_period; 2289 *pos++ = sdata->vif.bss_conf.dtim_period;
2240 2290
2241 if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf)) 2291 if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
2242 aid0 = 1; 2292 aid0 = 1;
2243 2293
2244 bss->dtim_bc_mc = aid0 == 1; 2294 ps->dtim_bc_mc = aid0 == 1;
2245 2295
2246 if (have_bits) { 2296 if (have_bits) {
2247 /* Find largest even number N1 so that bits numbered 1 through 2297 /* Find largest even number N1 so that bits numbered 1 through
@@ -2249,14 +2299,14 @@ static void ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2249 * (N2 + 1) x 8 through 2007 are 0. */ 2299 * (N2 + 1) x 8 through 2007 are 0. */
2250 n1 = 0; 2300 n1 = 0;
2251 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) { 2301 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
2252 if (bss->tim[i]) { 2302 if (ps->tim[i]) {
2253 n1 = i & 0xfe; 2303 n1 = i & 0xfe;
2254 break; 2304 break;
2255 } 2305 }
2256 } 2306 }
2257 n2 = n1; 2307 n2 = n1;
2258 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) { 2308 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
2259 if (bss->tim[i]) { 2309 if (ps->tim[i]) {
2260 n2 = i; 2310 n2 = i;
2261 break; 2311 break;
2262 } 2312 }
@@ -2266,7 +2316,7 @@ static void ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2266 *pos++ = n1 | aid0; 2316 *pos++ = n1 | aid0;
2267 /* Part Virt Bitmap */ 2317 /* Part Virt Bitmap */
2268 skb_put(skb, n2 - n1); 2318 skb_put(skb, n2 - n1);
2269 memcpy(pos, bss->tim + n1, n2 - n1 + 1); 2319 memcpy(pos, ps->tim + n1, n2 - n1 + 1);
2270 2320
2271 tim[1] = n2 - n1 + 4; 2321 tim[1] = n2 - n1 + 4;
2272 } else { 2322 } else {
@@ -2283,16 +2333,16 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2283 struct sk_buff *skb = NULL; 2333 struct sk_buff *skb = NULL;
2284 struct ieee80211_tx_info *info; 2334 struct ieee80211_tx_info *info;
2285 struct ieee80211_sub_if_data *sdata = NULL; 2335 struct ieee80211_sub_if_data *sdata = NULL;
2286 struct ieee80211_if_ap *ap = NULL; 2336 enum ieee80211_band band;
2287 struct beacon_data *beacon;
2288 enum ieee80211_band band = local->oper_channel->band;
2289 struct ieee80211_tx_rate_control txrc; 2337 struct ieee80211_tx_rate_control txrc;
2338 struct ieee80211_chanctx_conf *chanctx_conf;
2290 2339
2291 rcu_read_lock(); 2340 rcu_read_lock();
2292 2341
2293 sdata = vif_to_sdata(vif); 2342 sdata = vif_to_sdata(vif);
2343 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2294 2344
2295 if (!ieee80211_sdata_running(sdata)) 2345 if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
2296 goto out; 2346 goto out;
2297 2347
2298 if (tim_offset) 2348 if (tim_offset)
@@ -2301,8 +2351,9 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2301 *tim_length = 0; 2351 *tim_length = 0;
2302 2352
2303 if (sdata->vif.type == NL80211_IFTYPE_AP) { 2353 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2304 ap = &sdata->u.ap; 2354 struct ieee80211_if_ap *ap = &sdata->u.ap;
2305 beacon = rcu_dereference(ap->beacon); 2355 struct beacon_data *beacon = rcu_dereference(ap->beacon);
2356
2306 if (beacon) { 2357 if (beacon) {
2307 /* 2358 /*
2308 * headroom, head length, 2359 * headroom, head length,
@@ -2326,14 +2377,12 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2326 * of the tim bitmap in mac80211 and the driver. 2377 * of the tim bitmap in mac80211 and the driver.
2327 */ 2378 */
2328 if (local->tim_in_locked_section) { 2379 if (local->tim_in_locked_section) {
2329 ieee80211_beacon_add_tim(sdata, ap, skb, 2380 ieee80211_beacon_add_tim(sdata, &ap->ps, skb);
2330 beacon);
2331 } else { 2381 } else {
2332 unsigned long flags; 2382 unsigned long flags;
2333 2383
2334 spin_lock_irqsave(&local->tim_lock, flags); 2384 spin_lock_irqsave(&local->tim_lock, flags);
2335 ieee80211_beacon_add_tim(sdata, ap, skb, 2385 ieee80211_beacon_add_tim(sdata, &ap->ps, skb);
2336 beacon);
2337 spin_unlock_irqrestore(&local->tim_lock, flags); 2386 spin_unlock_irqrestore(&local->tim_lock, flags);
2338 } 2387 }
2339 2388
@@ -2409,6 +2458,8 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2409 *pos++ = WLAN_EID_SSID; 2458 *pos++ = WLAN_EID_SSID;
2410 *pos++ = 0x0; 2459 *pos++ = 0x0;
2411 2460
2461 band = chanctx_conf->channel->band;
2462
2412 if (ieee80211_add_srates_ie(sdata, skb, true, band) || 2463 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
2413 mesh_add_ds_params_ie(skb, sdata) || 2464 mesh_add_ds_params_ie(skb, sdata) ||
2414 ieee80211_add_ext_srates_ie(sdata, skb, true, band) || 2465 ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
@@ -2426,6 +2477,8 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2426 goto out; 2477 goto out;
2427 } 2478 }
2428 2479
2480 band = chanctx_conf->channel->band;
2481
2429 info = IEEE80211_SKB_CB(skb); 2482 info = IEEE80211_SKB_CB(skb);
2430 2483
2431 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 2484 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
@@ -2653,29 +2706,40 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2653 struct sk_buff *skb = NULL; 2706 struct sk_buff *skb = NULL;
2654 struct ieee80211_tx_data tx; 2707 struct ieee80211_tx_data tx;
2655 struct ieee80211_sub_if_data *sdata; 2708 struct ieee80211_sub_if_data *sdata;
2656 struct ieee80211_if_ap *bss = NULL; 2709 struct ps_data *ps;
2657 struct beacon_data *beacon;
2658 struct ieee80211_tx_info *info; 2710 struct ieee80211_tx_info *info;
2711 struct ieee80211_chanctx_conf *chanctx_conf;
2659 2712
2660 sdata = vif_to_sdata(vif); 2713 sdata = vif_to_sdata(vif);
2661 bss = &sdata->u.ap;
2662 2714
2663 rcu_read_lock(); 2715 rcu_read_lock();
2664 beacon = rcu_dereference(bss->beacon); 2716 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2717
2718 if (!chanctx_conf)
2719 goto out;
2665 2720
2666 if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head) 2721 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2722 struct beacon_data *beacon =
2723 rcu_dereference(sdata->u.ap.beacon);
2724
2725 if (!beacon || !beacon->head)
2726 goto out;
2727
2728 ps = &sdata->u.ap.ps;
2729 } else {
2667 goto out; 2730 goto out;
2731 }
2668 2732
2669 if (bss->dtim_count != 0 || !bss->dtim_bc_mc) 2733 if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
2670 goto out; /* send buffered bc/mc only after DTIM beacon */ 2734 goto out; /* send buffered bc/mc only after DTIM beacon */
2671 2735
2672 while (1) { 2736 while (1) {
2673 skb = skb_dequeue(&bss->ps_bc_buf); 2737 skb = skb_dequeue(&ps->bc_buf);
2674 if (!skb) 2738 if (!skb)
2675 goto out; 2739 goto out;
2676 local->total_ps_buffered--; 2740 local->total_ps_buffered--;
2677 2741
2678 if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) { 2742 if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
2679 struct ieee80211_hdr *hdr = 2743 struct ieee80211_hdr *hdr =
2680 (struct ieee80211_hdr *) skb->data; 2744 (struct ieee80211_hdr *) skb->data;
2681 /* more buffered multicast/broadcast frames ==> set 2745 /* more buffered multicast/broadcast frames ==> set
@@ -2693,7 +2757,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2693 info = IEEE80211_SKB_CB(skb); 2757 info = IEEE80211_SKB_CB(skb);
2694 2758
2695 tx.flags |= IEEE80211_TX_PS_BUFFERED; 2759 tx.flags |= IEEE80211_TX_PS_BUFFERED;
2696 info->band = local->oper_channel->band; 2760 info->band = chanctx_conf->channel->band;
2697 2761
2698 if (invoke_tx_handlers(&tx)) 2762 if (invoke_tx_handlers(&tx))
2699 skb = NULL; 2763 skb = NULL;
@@ -2704,8 +2768,9 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2704} 2768}
2705EXPORT_SYMBOL(ieee80211_get_buffered_bc); 2769EXPORT_SYMBOL(ieee80211_get_buffered_bc);
2706 2770
2707void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, 2771void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
2708 struct sk_buff *skb, int tid) 2772 struct sk_buff *skb, int tid,
2773 enum ieee80211_band band)
2709{ 2774{
2710 int ac = ieee802_1d_to_ac[tid & 7]; 2775 int ac = ieee802_1d_to_ac[tid & 7];
2711 2776
@@ -2722,6 +2787,6 @@ void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata,
2722 * requirements are that we do not come into tx with bhs on. 2787 * requirements are that we do not come into tx with bhs on.
2723 */ 2788 */
2724 local_bh_disable(); 2789 local_bh_disable();
2725 ieee80211_xmit(sdata, skb); 2790 ieee80211_xmit(sdata, skb, band);
2726 local_bh_enable(); 2791 local_bh_enable();
2727} 2792}
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 22ca35054dd0..c4a60bfb9f14 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -406,7 +406,7 @@ void ieee80211_add_pending_skb(struct ieee80211_local *local,
406 int queue = info->hw_queue; 406 int queue = info->hw_queue;
407 407
408 if (WARN_ON(!info->control.vif)) { 408 if (WARN_ON(!info->control.vif)) {
409 kfree_skb(skb); 409 ieee80211_free_txskb(&local->hw, skb);
410 return; 410 return;
411 } 411 }
412 412
@@ -431,7 +431,7 @@ void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
431 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 431 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
432 432
433 if (WARN_ON(!info->control.vif)) { 433 if (WARN_ON(!info->control.vif)) {
434 kfree_skb(skb); 434 ieee80211_free_txskb(&local->hw, skb);
435 continue; 435 continue;
436 } 436 }
437 437
@@ -512,7 +512,7 @@ void ieee80211_wake_queues(struct ieee80211_hw *hw)
512EXPORT_SYMBOL(ieee80211_wake_queues); 512EXPORT_SYMBOL(ieee80211_wake_queues);
513 513
514void ieee80211_iterate_active_interfaces( 514void ieee80211_iterate_active_interfaces(
515 struct ieee80211_hw *hw, 515 struct ieee80211_hw *hw, u32 iter_flags,
516 void (*iterator)(void *data, u8 *mac, 516 void (*iterator)(void *data, u8 *mac,
517 struct ieee80211_vif *vif), 517 struct ieee80211_vif *vif),
518 void *data) 518 void *data)
@@ -530,6 +530,9 @@ void ieee80211_iterate_active_interfaces(
530 default: 530 default:
531 break; 531 break;
532 } 532 }
533 if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) &&
534 !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
535 continue;
533 if (ieee80211_sdata_running(sdata)) 536 if (ieee80211_sdata_running(sdata))
534 iterator(data, sdata->vif.addr, 537 iterator(data, sdata->vif.addr,
535 &sdata->vif); 538 &sdata->vif);
@@ -537,7 +540,9 @@ void ieee80211_iterate_active_interfaces(
537 540
538 sdata = rcu_dereference_protected(local->monitor_sdata, 541 sdata = rcu_dereference_protected(local->monitor_sdata,
539 lockdep_is_held(&local->iflist_mtx)); 542 lockdep_is_held(&local->iflist_mtx));
540 if (sdata) 543 if (sdata &&
544 (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL ||
545 sdata->flags & IEEE80211_SDATA_IN_DRIVER))
541 iterator(data, sdata->vif.addr, &sdata->vif); 546 iterator(data, sdata->vif.addr, &sdata->vif);
542 547
543 mutex_unlock(&local->iflist_mtx); 548 mutex_unlock(&local->iflist_mtx);
@@ -545,7 +550,7 @@ void ieee80211_iterate_active_interfaces(
545EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); 550EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
546 551
547void ieee80211_iterate_active_interfaces_atomic( 552void ieee80211_iterate_active_interfaces_atomic(
548 struct ieee80211_hw *hw, 553 struct ieee80211_hw *hw, u32 iter_flags,
549 void (*iterator)(void *data, u8 *mac, 554 void (*iterator)(void *data, u8 *mac,
550 struct ieee80211_vif *vif), 555 struct ieee80211_vif *vif),
551 void *data) 556 void *data)
@@ -563,13 +568,18 @@ void ieee80211_iterate_active_interfaces_atomic(
563 default: 568 default:
564 break; 569 break;
565 } 570 }
571 if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) &&
572 !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
573 continue;
566 if (ieee80211_sdata_running(sdata)) 574 if (ieee80211_sdata_running(sdata))
567 iterator(data, sdata->vif.addr, 575 iterator(data, sdata->vif.addr,
568 &sdata->vif); 576 &sdata->vif);
569 } 577 }
570 578
571 sdata = rcu_dereference(local->monitor_sdata); 579 sdata = rcu_dereference(local->monitor_sdata);
572 if (sdata) 580 if (sdata &&
581 (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL ||
582 sdata->flags & IEEE80211_SDATA_IN_DRIVER))
573 iterator(data, sdata->vif.addr, &sdata->vif); 583 iterator(data, sdata->vif.addr, &sdata->vif);
574 584
575 rcu_read_unlock(); 585 rcu_read_unlock();
@@ -643,13 +653,41 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
643 break; 653 break;
644 } 654 }
645 655
646 if (id != WLAN_EID_VENDOR_SPECIFIC && 656 switch (id) {
647 id != WLAN_EID_QUIET && 657 case WLAN_EID_SSID:
648 test_bit(id, seen_elems)) { 658 case WLAN_EID_SUPP_RATES:
649 elems->parse_error = true; 659 case WLAN_EID_FH_PARAMS:
650 left -= elen; 660 case WLAN_EID_DS_PARAMS:
651 pos += elen; 661 case WLAN_EID_CF_PARAMS:
652 continue; 662 case WLAN_EID_TIM:
663 case WLAN_EID_IBSS_PARAMS:
664 case WLAN_EID_CHALLENGE:
665 case WLAN_EID_RSN:
666 case WLAN_EID_ERP_INFO:
667 case WLAN_EID_EXT_SUPP_RATES:
668 case WLAN_EID_HT_CAPABILITY:
669 case WLAN_EID_HT_OPERATION:
670 case WLAN_EID_VHT_CAPABILITY:
671 case WLAN_EID_VHT_OPERATION:
672 case WLAN_EID_MESH_ID:
673 case WLAN_EID_MESH_CONFIG:
674 case WLAN_EID_PEER_MGMT:
675 case WLAN_EID_PREQ:
676 case WLAN_EID_PREP:
677 case WLAN_EID_PERR:
678 case WLAN_EID_RANN:
679 case WLAN_EID_CHANNEL_SWITCH:
680 case WLAN_EID_EXT_CHANSWITCH_ANN:
681 case WLAN_EID_COUNTRY:
682 case WLAN_EID_PWR_CONSTRAINT:
683 case WLAN_EID_TIMEOUT_INTERVAL:
684 if (test_bit(id, seen_elems)) {
685 elems->parse_error = true;
686 left -= elen;
687 pos += elen;
688 continue;
689 }
690 break;
653 } 691 }
654 692
655 if (calc_crc && id < 64 && (filter & (1ULL << id))) 693 if (calc_crc && id < 64 && (filter & (1ULL << id)))
@@ -741,6 +779,18 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
741 else 779 else
742 elem_parse_failed = true; 780 elem_parse_failed = true;
743 break; 781 break;
782 case WLAN_EID_VHT_CAPABILITY:
783 if (elen >= sizeof(struct ieee80211_vht_cap))
784 elems->vht_cap_elem = (void *)pos;
785 else
786 elem_parse_failed = true;
787 break;
788 case WLAN_EID_VHT_OPERATION:
789 if (elen >= sizeof(struct ieee80211_vht_operation))
790 elems->vht_operation = (void *)pos;
791 else
792 elem_parse_failed = true;
793 break;
744 case WLAN_EID_MESH_ID: 794 case WLAN_EID_MESH_ID:
745 elems->mesh_id = pos; 795 elems->mesh_id = pos;
746 elems->mesh_id_len = elen; 796 elems->mesh_id_len = elen;
@@ -809,7 +859,7 @@ u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
809 if (elem_parse_failed) 859 if (elem_parse_failed)
810 elems->parse_error = true; 860 elems->parse_error = true;
811 else 861 else
812 set_bit(id, seen_elems); 862 __set_bit(id, seen_elems);
813 863
814 left -= elen; 864 left -= elen;
815 pos += elen; 865 pos += elen;
@@ -832,6 +882,7 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
832{ 882{
833 struct ieee80211_local *local = sdata->local; 883 struct ieee80211_local *local = sdata->local;
834 struct ieee80211_tx_queue_params qparam; 884 struct ieee80211_tx_queue_params qparam;
885 struct ieee80211_chanctx_conf *chanctx_conf;
835 int ac; 886 int ac;
836 bool use_11b, enable_qos; 887 bool use_11b, enable_qos;
837 int aCWmin, aCWmax; 888 int aCWmin, aCWmax;
@@ -844,8 +895,12 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
844 895
845 memset(&qparam, 0, sizeof(qparam)); 896 memset(&qparam, 0, sizeof(qparam));
846 897
847 use_11b = (local->oper_channel->band == IEEE80211_BAND_2GHZ) && 898 rcu_read_lock();
899 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
900 use_11b = (chanctx_conf &&
901 chanctx_conf->channel->band == IEEE80211_BAND_2GHZ) &&
848 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE); 902 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
903 rcu_read_unlock();
849 904
850 /* 905 /*
851 * By default disable QoS in STA mode for old access points, which do 906 * By default disable QoS in STA mode for old access points, which do
@@ -924,7 +979,7 @@ void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
924 const size_t supp_rates_len, 979 const size_t supp_rates_len,
925 const u8 *supp_rates) 980 const u8 *supp_rates)
926{ 981{
927 struct ieee80211_local *local = sdata->local; 982 struct ieee80211_chanctx_conf *chanctx_conf;
928 int i, have_higher_than_11mbit = 0; 983 int i, have_higher_than_11mbit = 0;
929 984
930 /* cf. IEEE 802.11 9.2.12 */ 985 /* cf. IEEE 802.11 9.2.12 */
@@ -932,11 +987,16 @@ void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
932 if ((supp_rates[i] & 0x7f) * 5 > 110) 987 if ((supp_rates[i] & 0x7f) * 5 > 110)
933 have_higher_than_11mbit = 1; 988 have_higher_than_11mbit = 1;
934 989
935 if (local->oper_channel->band == IEEE80211_BAND_2GHZ && 990 rcu_read_lock();
991 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
992
993 if (chanctx_conf &&
994 chanctx_conf->channel->band == IEEE80211_BAND_2GHZ &&
936 have_higher_than_11mbit) 995 have_higher_than_11mbit)
937 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; 996 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
938 else 997 else
939 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; 998 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
999 rcu_read_unlock();
940 1000
941 ieee80211_set_wmm_default(sdata, true); 1001 ieee80211_set_wmm_default(sdata, true);
942} 1002}
@@ -968,7 +1028,7 @@ u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
968} 1028}
969 1029
970void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 1030void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
971 u16 transaction, u16 auth_alg, 1031 u16 transaction, u16 auth_alg, u16 status,
972 u8 *extra, size_t extra_len, const u8 *da, 1032 u8 *extra, size_t extra_len, const u8 *da,
973 const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx) 1033 const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx)
974{ 1034{
@@ -993,7 +1053,7 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
993 memcpy(mgmt->bssid, bssid, ETH_ALEN); 1053 memcpy(mgmt->bssid, bssid, ETH_ALEN);
994 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); 1054 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
995 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); 1055 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
996 mgmt->u.auth.status_code = cpu_to_le16(0); 1056 mgmt->u.auth.status_code = cpu_to_le16(status);
997 if (extra) 1057 if (extra)
998 memcpy(skb_put(skb, extra_len), extra, extra_len); 1058 memcpy(skb_put(skb, extra_len), extra, extra_len);
999 1059
@@ -1206,7 +1266,7 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1206 const u8 *ssid, size_t ssid_len, 1266 const u8 *ssid, size_t ssid_len,
1207 const u8 *ie, size_t ie_len, 1267 const u8 *ie, size_t ie_len,
1208 u32 ratemask, bool directed, bool no_cck, 1268 u32 ratemask, bool directed, bool no_cck,
1209 struct ieee80211_channel *channel) 1269 struct ieee80211_channel *channel, bool scan)
1210{ 1270{
1211 struct sk_buff *skb; 1271 struct sk_buff *skb;
1212 1272
@@ -1217,7 +1277,10 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1217 if (no_cck) 1277 if (no_cck)
1218 IEEE80211_SKB_CB(skb)->flags |= 1278 IEEE80211_SKB_CB(skb)->flags |=
1219 IEEE80211_TX_CTL_NO_CCK_RATE; 1279 IEEE80211_TX_CTL_NO_CCK_RATE;
1220 ieee80211_tx_skb(sdata, skb); 1280 if (scan)
1281 ieee80211_tx_skb_tid_band(sdata, skb, 7, channel->band);
1282 else
1283 ieee80211_tx_skb(sdata, skb);
1221 } 1284 }
1222} 1285}
1223 1286
@@ -1280,6 +1343,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1280{ 1343{
1281 struct ieee80211_hw *hw = &local->hw; 1344 struct ieee80211_hw *hw = &local->hw;
1282 struct ieee80211_sub_if_data *sdata; 1345 struct ieee80211_sub_if_data *sdata;
1346 struct ieee80211_chanctx *ctx;
1283 struct sta_info *sta; 1347 struct sta_info *sta;
1284 int res, i; 1348 int res, i;
1285 1349
@@ -1352,6 +1416,29 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1352 res = drv_add_interface(local, sdata); 1416 res = drv_add_interface(local, sdata);
1353 } 1417 }
1354 1418
1419 /* add channel contexts */
1420 mutex_lock(&local->chanctx_mtx);
1421 list_for_each_entry(ctx, &local->chanctx_list, list)
1422 WARN_ON(drv_add_chanctx(local, ctx));
1423 mutex_unlock(&local->chanctx_mtx);
1424
1425 list_for_each_entry(sdata, &local->interfaces, list) {
1426 struct ieee80211_chanctx_conf *ctx_conf;
1427
1428 if (!ieee80211_sdata_running(sdata))
1429 continue;
1430
1431 mutex_lock(&local->chanctx_mtx);
1432 ctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1433 lockdep_is_held(&local->chanctx_mtx));
1434 if (ctx_conf) {
1435 ctx = container_of(ctx_conf, struct ieee80211_chanctx,
1436 conf);
1437 drv_assign_vif_chanctx(local, sdata, ctx);
1438 }
1439 mutex_unlock(&local->chanctx_mtx);
1440 }
1441
1355 /* add STAs back */ 1442 /* add STAs back */
1356 mutex_lock(&local->sta_mtx); 1443 mutex_lock(&local->sta_mtx);
1357 list_for_each_entry(sta, &local->sta_list, list) { 1444 list_for_each_entry(sta, &local->sta_list, list) {
@@ -1407,7 +1494,8 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1407 BSS_CHANGED_BSSID | 1494 BSS_CHANGED_BSSID |
1408 BSS_CHANGED_CQM | 1495 BSS_CHANGED_CQM |
1409 BSS_CHANGED_QOS | 1496 BSS_CHANGED_QOS |
1410 BSS_CHANGED_IDLE; 1497 BSS_CHANGED_IDLE |
1498 BSS_CHANGED_TXPOWER;
1411 1499
1412 switch (sdata->vif.type) { 1500 switch (sdata->vif.type) {
1413 case NL80211_IFTYPE_STATION: 1501 case NL80211_IFTYPE_STATION:
@@ -1424,9 +1512,13 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1424 case NL80211_IFTYPE_AP: 1512 case NL80211_IFTYPE_AP:
1425 changed |= BSS_CHANGED_SSID; 1513 changed |= BSS_CHANGED_SSID;
1426 1514
1427 if (sdata->vif.type == NL80211_IFTYPE_AP) 1515 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1428 changed |= BSS_CHANGED_AP_PROBE_RESP; 1516 changed |= BSS_CHANGED_AP_PROBE_RESP;
1429 1517
1518 if (rcu_access_pointer(sdata->u.ap.beacon))
1519 drv_start_ap(local, sdata);
1520 }
1521
1430 /* fall through */ 1522 /* fall through */
1431 case NL80211_IFTYPE_MESH_POINT: 1523 case NL80211_IFTYPE_MESH_POINT:
1432 changed |= BSS_CHANGED_BEACON | 1524 changed |= BSS_CHANGED_BEACON |
@@ -1463,6 +1555,8 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1463 list_for_each_entry(sdata, &local->interfaces, list) { 1555 list_for_each_entry(sdata, &local->interfaces, list) {
1464 if (sdata->vif.type != NL80211_IFTYPE_STATION) 1556 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1465 continue; 1557 continue;
1558 if (!sdata->u.mgd.associated)
1559 continue;
1466 1560
1467 ieee80211_send_nullfunc(local, sdata, 0); 1561 ieee80211_send_nullfunc(local, sdata, 0);
1468 } 1562 }
@@ -1523,8 +1617,10 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1523 * If this is for hw restart things are still running. 1617 * If this is for hw restart things are still running.
1524 * We may want to change that later, however. 1618 * We may want to change that later, however.
1525 */ 1619 */
1526 if (!local->suspended) 1620 if (!local->suspended) {
1621 drv_restart_complete(local);
1527 return 0; 1622 return 0;
1623 }
1528 1624
1529#ifdef CONFIG_PM 1625#ifdef CONFIG_PM
1530 /* first set suspended false, then resuming */ 1626 /* first set suspended false, then resuming */
@@ -1587,68 +1683,24 @@ void ieee80211_resume_disconnect(struct ieee80211_vif *vif)
1587} 1683}
1588EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect); 1684EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect);
1589 1685
1590static int check_mgd_smps(struct ieee80211_if_managed *ifmgd, 1686void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata)
1591 enum ieee80211_smps_mode *smps_mode)
1592{
1593 if (ifmgd->associated) {
1594 *smps_mode = ifmgd->ap_smps;
1595
1596 if (*smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1597 if (ifmgd->powersave)
1598 *smps_mode = IEEE80211_SMPS_DYNAMIC;
1599 else
1600 *smps_mode = IEEE80211_SMPS_OFF;
1601 }
1602
1603 return 1;
1604 }
1605
1606 return 0;
1607}
1608
1609void ieee80211_recalc_smps(struct ieee80211_local *local)
1610{ 1687{
1611 struct ieee80211_sub_if_data *sdata; 1688 struct ieee80211_local *local = sdata->local;
1612 enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_OFF; 1689 struct ieee80211_chanctx_conf *chanctx_conf;
1613 int count = 0; 1690 struct ieee80211_chanctx *chanctx;
1614
1615 mutex_lock(&local->iflist_mtx);
1616
1617 /*
1618 * This function could be improved to handle multiple
1619 * interfaces better, but right now it makes any
1620 * non-station interfaces force SM PS to be turned
1621 * off. If there are multiple station interfaces it
1622 * could also use the best possible mode, e.g. if
1623 * one is in static and the other in dynamic then
1624 * dynamic is ok.
1625 */
1626
1627 list_for_each_entry(sdata, &local->interfaces, list) {
1628 if (!ieee80211_sdata_running(sdata))
1629 continue;
1630 if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
1631 continue;
1632 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1633 goto set;
1634 1691
1635 count += check_mgd_smps(&sdata->u.mgd, &smps_mode); 1692 mutex_lock(&local->chanctx_mtx);
1636 1693
1637 if (count > 1) { 1694 chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1638 smps_mode = IEEE80211_SMPS_OFF; 1695 lockdep_is_held(&local->chanctx_mtx));
1639 break;
1640 }
1641 }
1642 1696
1643 if (smps_mode == local->smps_mode) 1697 if (WARN_ON_ONCE(!chanctx_conf))
1644 goto unlock; 1698 goto unlock;
1645 1699
1646 set: 1700 chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
1647 local->smps_mode = smps_mode; 1701 ieee80211_recalc_smps_chanctx(local, chanctx);
1648 /* changed flag is auto-detected for this */
1649 ieee80211_hw_config(local, 0);
1650 unlock: 1702 unlock:
1651 mutex_unlock(&local->iflist_mtx); 1703 mutex_unlock(&local->chanctx_mtx);
1652} 1704}
1653 1705
1654static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id) 1706static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
@@ -1788,8 +1840,8 @@ u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
1788 __le32 tmp; 1840 __le32 tmp;
1789 1841
1790 *pos++ = WLAN_EID_VHT_CAPABILITY; 1842 *pos++ = WLAN_EID_VHT_CAPABILITY;
1791 *pos++ = sizeof(struct ieee80211_vht_capabilities); 1843 *pos++ = sizeof(struct ieee80211_vht_cap);
1792 memset(pos, 0, sizeof(struct ieee80211_vht_capabilities)); 1844 memset(pos, 0, sizeof(struct ieee80211_vht_cap));
1793 1845
1794 /* capability flags */ 1846 /* capability flags */
1795 tmp = cpu_to_le32(cap); 1847 tmp = cpu_to_le32(cap);
@@ -1947,3 +1999,19 @@ int ieee80211_ave_rssi(struct ieee80211_vif *vif)
1947 return ifmgd->ave_beacon_signal; 1999 return ifmgd->ave_beacon_signal;
1948} 2000}
1949EXPORT_SYMBOL_GPL(ieee80211_ave_rssi); 2001EXPORT_SYMBOL_GPL(ieee80211_ave_rssi);
2002
2003u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs)
2004{
2005 if (!mcs)
2006 return 1;
2007
2008 /* TODO: consider rx_highest */
2009
2010 if (mcs->rx_mask[3])
2011 return 4;
2012 if (mcs->rx_mask[2])
2013 return 3;
2014 if (mcs->rx_mask[1])
2015 return 2;
2016 return 1;
2017}
diff --git a/net/mac80211/vht.c b/net/mac80211/vht.c
new file mode 100644
index 000000000000..f311388aeedf
--- /dev/null
+++ b/net/mac80211/vht.c
@@ -0,0 +1,35 @@
1/*
2 * VHT handling
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/ieee80211.h>
10#include <linux/export.h>
11#include <net/mac80211.h>
12#include "ieee80211_i.h"
13
14
15void ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
16 struct ieee80211_supported_band *sband,
17 struct ieee80211_vht_cap *vht_cap_ie,
18 struct ieee80211_sta_vht_cap *vht_cap)
19{
20 if (WARN_ON_ONCE(!vht_cap))
21 return;
22
23 memset(vht_cap, 0, sizeof(*vht_cap));
24
25 if (!vht_cap_ie || !sband->vht_cap.vht_supported)
26 return;
27
28 vht_cap->vht_supported = true;
29
30 vht_cap->cap = le32_to_cpu(vht_cap_ie->vht_cap_info);
31
32 /* Copy peer MCS info, the driver might need them. */
33 memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
34 sizeof(struct ieee80211_vht_mcs_info));
35}
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index bdb53aba888e..8bd2f5c6a56e 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -106,7 +106,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
106 if (status->flag & RX_FLAG_MMIC_ERROR) 106 if (status->flag & RX_FLAG_MMIC_ERROR)
107 goto mic_fail; 107 goto mic_fail;
108 108
109 if (!(status->flag & RX_FLAG_IV_STRIPPED) && rx->key) 109 if (!(status->flag & RX_FLAG_IV_STRIPPED) && rx->key &&
110 rx->key->conf.cipher == WLAN_CIPHER_SUITE_TKIP)
110 goto update_iv; 111 goto update_iv;
111 112
112 return RX_CONTINUE; 113 return RX_CONTINUE;
@@ -545,14 +546,19 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
545 546
546static void bip_aad(struct sk_buff *skb, u8 *aad) 547static void bip_aad(struct sk_buff *skb, u8 *aad)
547{ 548{
549 __le16 mask_fc;
550 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
551
548 /* BIP AAD: FC(masked) || A1 || A2 || A3 */ 552 /* BIP AAD: FC(masked) || A1 || A2 || A3 */
549 553
550 /* FC type/subtype */ 554 /* FC type/subtype */
551 aad[0] = skb->data[0];
552 /* Mask FC Retry, PwrMgt, MoreData flags to zero */ 555 /* Mask FC Retry, PwrMgt, MoreData flags to zero */
553 aad[1] = skb->data[1] & ~(BIT(4) | BIT(5) | BIT(6)); 556 mask_fc = hdr->frame_control;
557 mask_fc &= ~cpu_to_le16(IEEE80211_FCTL_RETRY | IEEE80211_FCTL_PM |
558 IEEE80211_FCTL_MOREDATA);
559 put_unaligned(mask_fc, (__le16 *) &aad[0]);
554 /* A1 || A2 || A3 */ 560 /* A1 || A2 || A3 */
555 memcpy(aad + 2, skb->data + 4, 3 * ETH_ALEN); 561 memcpy(aad + 2, &hdr->addr1, 3 * ETH_ALEN);
556} 562}
557 563
558 564