aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2013-08-01 15:26:52 -0400
committerJohn W. Linville <linville@tuxdriver.com>2013-08-01 15:26:52 -0400
commit7546ff95499781306e8fd7d84ae38b84be961364 (patch)
tree58416d00380ad1122acee71b594b26ab9a201e48 /net/mac80211
parent2cdf359a521bb72286b6714478dfdbcd2691f3fe (diff)
parentc82b5a74cc739385db6e4275fe504a0e9469bf01 (diff)
Merge branch 'for-john' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/cfg.c45
-rw-r--r--net/mac80211/ht.c53
-rw-r--r--net/mac80211/ibss.c154
-rw-r--r--net/mac80211/ieee80211_i.h49
-rw-r--r--net/mac80211/iface.c2
-rw-r--r--net/mac80211/main.c15
-rw-r--r--net/mac80211/mesh.c7
-rw-r--r--net/mac80211/mesh_plink.c2
-rw-r--r--net/mac80211/mlme.c98
-rw-r--r--net/mac80211/rate.c46
-rw-r--r--net/mac80211/rate.h22
-rw-r--r--net/mac80211/rc80211_minstrel.c33
-rw-r--r--net/mac80211/rc80211_minstrel_ht.c15
-rw-r--r--net/mac80211/rc80211_pid_algo.c1
-rw-r--r--net/mac80211/rx.c97
-rw-r--r--net/mac80211/scan.c72
-rw-r--r--net/mac80211/status.c18
-rw-r--r--net/mac80211/tx.c29
-rw-r--r--net/mac80211/util.c216
19 files changed, 684 insertions, 290 deletions
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 43dd7525bfcb..973594b229f4 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -395,9 +395,13 @@ void sta_set_rate_info_tx(struct sta_info *sta,
395 rinfo->nss = ieee80211_rate_get_vht_nss(rate); 395 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
396 } else { 396 } else {
397 struct ieee80211_supported_band *sband; 397 struct ieee80211_supported_band *sband;
398 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
399 u16 brate;
400
398 sband = sta->local->hw.wiphy->bands[ 401 sband = sta->local->hw.wiphy->bands[
399 ieee80211_get_sdata_band(sta->sdata)]; 402 ieee80211_get_sdata_band(sta->sdata)];
400 rinfo->legacy = sband->bitrates[rate->idx].bitrate; 403 brate = sband->bitrates[rate->idx].bitrate;
404 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
401 } 405 }
402 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) 406 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
403 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; 407 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
@@ -422,11 +426,13 @@ void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
422 rinfo->mcs = sta->last_rx_rate_idx; 426 rinfo->mcs = sta->last_rx_rate_idx;
423 } else { 427 } else {
424 struct ieee80211_supported_band *sband; 428 struct ieee80211_supported_band *sband;
429 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
430 u16 brate;
425 431
426 sband = sta->local->hw.wiphy->bands[ 432 sband = sta->local->hw.wiphy->bands[
427 ieee80211_get_sdata_band(sta->sdata)]; 433 ieee80211_get_sdata_band(sta->sdata)];
428 rinfo->legacy = 434 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
429 sband->bitrates[sta->last_rx_rate_idx].bitrate; 435 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
430 } 436 }
431 437
432 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ) 438 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
@@ -1192,8 +1198,6 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1192 struct station_parameters *params) 1198 struct station_parameters *params)
1193{ 1199{
1194 int ret = 0; 1200 int ret = 0;
1195 u32 rates;
1196 int i, j;
1197 struct ieee80211_supported_band *sband; 1201 struct ieee80211_supported_band *sband;
1198 struct ieee80211_sub_if_data *sdata = sta->sdata; 1202 struct ieee80211_sub_if_data *sdata = sta->sdata;
1199 enum ieee80211_band band = ieee80211_get_sdata_band(sdata); 1203 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
@@ -1286,16 +1290,10 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1286 sta->listen_interval = params->listen_interval; 1290 sta->listen_interval = params->listen_interval;
1287 1291
1288 if (params->supported_rates) { 1292 if (params->supported_rates) {
1289 rates = 0; 1293 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1290 1294 sband, params->supported_rates,
1291 for (i = 0; i < params->supported_rates_len; i++) { 1295 params->supported_rates_len,
1292 int rate = (params->supported_rates[i] & 0x7f) * 5; 1296 &sta->sta.supp_rates[band]);
1293 for (j = 0; j < sband->n_bitrates; j++) {
1294 if (sband->bitrates[j].bitrate == rate)
1295 rates |= BIT(j);
1296 }
1297 }
1298 sta->sta.supp_rates[band] = rates;
1299 } 1297 }
1300 1298
1301 if (params->ht_capa) 1299 if (params->ht_capa)
@@ -1958,18 +1956,11 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1958 } 1956 }
1959 1957
1960 if (params->basic_rates) { 1958 if (params->basic_rates) {
1961 int i, j; 1959 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1962 u32 rates = 0; 1960 wiphy->bands[band],
1963 struct ieee80211_supported_band *sband = wiphy->bands[band]; 1961 params->basic_rates,
1964 1962 params->basic_rates_len,
1965 for (i = 0; i < params->basic_rates_len; i++) { 1963 &sdata->vif.bss_conf.basic_rates);
1966 int rate = (params->basic_rates[i] & 0x7f) * 5;
1967 for (j = 0; j < sband->n_bitrates; j++) {
1968 if (sband->bitrates[j].bitrate == rate)
1969 rates |= BIT(j);
1970 }
1971 }
1972 sdata->vif.bss_conf.basic_rates = rates;
1973 changed |= BSS_CHANGED_BASIC_RATES; 1964 changed |= BSS_CHANGED_BASIC_RATES;
1974 } 1965 }
1975 1966
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index f83534f6a2ee..529bf58bc145 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -19,13 +19,14 @@
19#include "ieee80211_i.h" 19#include "ieee80211_i.h"
20#include "rate.h" 20#include "rate.h"
21 21
22static void __check_htcap_disable(struct ieee80211_sub_if_data *sdata, 22static void __check_htcap_disable(struct ieee80211_ht_cap *ht_capa,
23 struct ieee80211_ht_cap *ht_capa_mask,
23 struct ieee80211_sta_ht_cap *ht_cap, 24 struct ieee80211_sta_ht_cap *ht_cap,
24 u16 flag) 25 u16 flag)
25{ 26{
26 __le16 le_flag = cpu_to_le16(flag); 27 __le16 le_flag = cpu_to_le16(flag);
27 if (sdata->u.mgd.ht_capa_mask.cap_info & le_flag) { 28 if (ht_capa_mask->cap_info & le_flag) {
28 if (!(sdata->u.mgd.ht_capa.cap_info & le_flag)) 29 if (!(ht_capa->cap_info & le_flag))
29 ht_cap->cap &= ~flag; 30 ht_cap->cap &= ~flag;
30 } 31 }
31} 32}
@@ -33,13 +34,30 @@ static void __check_htcap_disable(struct ieee80211_sub_if_data *sdata,
33void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata, 34void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
34 struct ieee80211_sta_ht_cap *ht_cap) 35 struct ieee80211_sta_ht_cap *ht_cap)
35{ 36{
36 u8 *scaps = (u8 *)(&sdata->u.mgd.ht_capa.mcs.rx_mask); 37 struct ieee80211_ht_cap *ht_capa, *ht_capa_mask;
37 u8 *smask = (u8 *)(&sdata->u.mgd.ht_capa_mask.mcs.rx_mask); 38 u8 *scaps, *smask;
38 int i; 39 int i;
39 40
40 if (!ht_cap->ht_supported) 41 if (!ht_cap->ht_supported)
41 return; 42 return;
42 43
44 switch (sdata->vif.type) {
45 case NL80211_IFTYPE_STATION:
46 ht_capa = &sdata->u.mgd.ht_capa;
47 ht_capa_mask = &sdata->u.mgd.ht_capa_mask;
48 break;
49 case NL80211_IFTYPE_ADHOC:
50 ht_capa = &sdata->u.ibss.ht_capa;
51 ht_capa_mask = &sdata->u.ibss.ht_capa_mask;
52 break;
53 default:
54 WARN_ON_ONCE(1);
55 return;
56 }
57
58 scaps = (u8 *)(&ht_capa->mcs.rx_mask);
59 smask = (u8 *)(&ht_capa_mask->mcs.rx_mask);
60
43 /* NOTE: If you add more over-rides here, update register_hw 61 /* NOTE: If you add more over-rides here, update register_hw
44 * ht_capa_mod_msk logic in main.c as well. 62 * ht_capa_mod_msk logic in main.c as well.
45 * And, if this method can ever change ht_cap.ht_supported, fix 63 * And, if this method can ever change ht_cap.ht_supported, fix
@@ -55,28 +73,32 @@ void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
55 } 73 }
56 74
57 /* Force removal of HT-40 capabilities? */ 75 /* Force removal of HT-40 capabilities? */
58 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SUP_WIDTH_20_40); 76 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
59 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SGI_40); 77 IEEE80211_HT_CAP_SUP_WIDTH_20_40);
78 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
79 IEEE80211_HT_CAP_SGI_40);
60 80
61 /* Allow user to disable SGI-20 (SGI-40 is handled above) */ 81 /* Allow user to disable SGI-20 (SGI-40 is handled above) */
62 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SGI_20); 82 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
83 IEEE80211_HT_CAP_SGI_20);
63 84
64 /* Allow user to disable the max-AMSDU bit. */ 85 /* Allow user to disable the max-AMSDU bit. */
65 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_MAX_AMSDU); 86 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
87 IEEE80211_HT_CAP_MAX_AMSDU);
66 88
67 /* Allow user to decrease AMPDU factor */ 89 /* Allow user to decrease AMPDU factor */
68 if (sdata->u.mgd.ht_capa_mask.ampdu_params_info & 90 if (ht_capa_mask->ampdu_params_info &
69 IEEE80211_HT_AMPDU_PARM_FACTOR) { 91 IEEE80211_HT_AMPDU_PARM_FACTOR) {
70 u8 n = sdata->u.mgd.ht_capa.ampdu_params_info 92 u8 n = ht_capa->ampdu_params_info &
71 & IEEE80211_HT_AMPDU_PARM_FACTOR; 93 IEEE80211_HT_AMPDU_PARM_FACTOR;
72 if (n < ht_cap->ampdu_factor) 94 if (n < ht_cap->ampdu_factor)
73 ht_cap->ampdu_factor = n; 95 ht_cap->ampdu_factor = n;
74 } 96 }
75 97
76 /* Allow the user to increase AMPDU density. */ 98 /* Allow the user to increase AMPDU density. */
77 if (sdata->u.mgd.ht_capa_mask.ampdu_params_info & 99 if (ht_capa_mask->ampdu_params_info &
78 IEEE80211_HT_AMPDU_PARM_DENSITY) { 100 IEEE80211_HT_AMPDU_PARM_DENSITY) {
79 u8 n = (sdata->u.mgd.ht_capa.ampdu_params_info & 101 u8 n = (ht_capa->ampdu_params_info &
80 IEEE80211_HT_AMPDU_PARM_DENSITY) 102 IEEE80211_HT_AMPDU_PARM_DENSITY)
81 >> IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT; 103 >> IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT;
82 if (n > ht_cap->ampdu_density) 104 if (n > ht_cap->ampdu_density)
@@ -112,7 +134,8 @@ bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
112 * we advertised a restricted capability set to. Override 134 * we advertised a restricted capability set to. Override
113 * our own capabilities and then use those below. 135 * our own capabilities and then use those below.
114 */ 136 */
115 if (sdata->vif.type == NL80211_IFTYPE_STATION && 137 if ((sdata->vif.type == NL80211_IFTYPE_STATION ||
138 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
116 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) 139 !test_sta_flag(sta, WLAN_STA_TDLS_PEER))
117 ieee80211_apply_htcap_overrides(sdata, &own_cap); 140 ieee80211_apply_htcap_overrides(sdata, &own_cap);
118 141
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index ea7b9c2c7e66..5e6836c3aa4c 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -43,16 +43,18 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
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;
46 int rates, i; 46 int rates_n = 0, i, ri;
47 struct ieee80211_mgmt *mgmt; 47 struct ieee80211_mgmt *mgmt;
48 u8 *pos; 48 u8 *pos;
49 struct ieee80211_supported_band *sband; 49 struct ieee80211_supported_band *sband;
50 struct cfg80211_bss *bss; 50 struct cfg80211_bss *bss;
51 u32 bss_change; 51 u32 bss_change, rate_flags, rates = 0, rates_added = 0;
52 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
53 struct cfg80211_chan_def chandef; 52 struct cfg80211_chan_def chandef;
53 enum nl80211_bss_scan_width scan_width;
54 bool have_higher_than_11mbit = false;
54 struct beacon_data *presp; 55 struct beacon_data *presp;
55 int frame_len; 56 int frame_len;
57 int shift;
56 58
57 sdata_assert_lock(sdata); 59 sdata_assert_lock(sdata);
58 60
@@ -83,6 +85,14 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
83 85
84 chandef = ifibss->chandef; 86 chandef = ifibss->chandef;
85 if (!cfg80211_reg_can_beacon(local->hw.wiphy, &chandef)) { 87 if (!cfg80211_reg_can_beacon(local->hw.wiphy, &chandef)) {
88 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
89 chandef.width == NL80211_CHAN_WIDTH_10 ||
90 chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
91 chandef.width == NL80211_CHAN_WIDTH_20) {
92 sdata_info(sdata,
93 "Failed to join IBSS, beacons forbidden\n");
94 return;
95 }
86 chandef.width = NL80211_CHAN_WIDTH_20; 96 chandef.width = NL80211_CHAN_WIDTH_20;
87 chandef.center_freq1 = chan->center_freq; 97 chandef.center_freq1 = chan->center_freq;
88 } 98 }
@@ -99,6 +109,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
99 memcpy(ifibss->bssid, bssid, ETH_ALEN); 109 memcpy(ifibss->bssid, bssid, ETH_ALEN);
100 110
101 sband = local->hw.wiphy->bands[chan->band]; 111 sband = local->hw.wiphy->bands[chan->band];
112 shift = ieee80211_vif_get_shift(&sdata->vif);
102 113
103 /* Build IBSS probe response */ 114 /* Build IBSS probe response */
104 frame_len = sizeof(struct ieee80211_hdr_3addr) + 115 frame_len = sizeof(struct ieee80211_hdr_3addr) +
@@ -134,15 +145,33 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
134 memcpy(pos, ifibss->ssid, ifibss->ssid_len); 145 memcpy(pos, ifibss->ssid, ifibss->ssid_len);
135 pos += ifibss->ssid_len; 146 pos += ifibss->ssid_len;
136 147
137 rates = min_t(int, 8, sband->n_bitrates); 148 rate_flags = ieee80211_chandef_rate_flags(&chandef);
149 for (i = 0; i < sband->n_bitrates; i++) {
150 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
151 continue;
152 if (sband->bitrates[i].bitrate > 110)
153 have_higher_than_11mbit = true;
154
155 rates |= BIT(i);
156 rates_n++;
157 }
158
138 *pos++ = WLAN_EID_SUPP_RATES; 159 *pos++ = WLAN_EID_SUPP_RATES;
139 *pos++ = rates; 160 *pos++ = min_t(int, 8, rates_n);
140 for (i = 0; i < rates; i++) { 161 for (ri = 0; ri < sband->n_bitrates; ri++) {
141 int rate = sband->bitrates[i].bitrate; 162 int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate,
163 5 * (1 << shift));
142 u8 basic = 0; 164 u8 basic = 0;
143 if (basic_rates & BIT(i)) 165 if (!(rates & BIT(ri)))
166 continue;
167
168 if (basic_rates & BIT(ri))
144 basic = 0x80; 169 basic = 0x80;
145 *pos++ = basic | (u8) (rate / 5); 170 *pos++ = basic | (u8) rate;
171 if (++rates_added == 8) {
172 ri++; /* continue at next rate for EXT_SUPP_RATES */
173 break;
174 }
146 } 175 }
147 176
148 if (sband->band == IEEE80211_BAND_2GHZ) { 177 if (sband->band == IEEE80211_BAND_2GHZ) {
@@ -157,15 +186,20 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
157 *pos++ = 0; 186 *pos++ = 0;
158 *pos++ = 0; 187 *pos++ = 0;
159 188
160 if (sband->n_bitrates > 8) { 189 /* put the remaining rates in WLAN_EID_EXT_SUPP_RATES */
190 if (rates_n > 8) {
161 *pos++ = WLAN_EID_EXT_SUPP_RATES; 191 *pos++ = WLAN_EID_EXT_SUPP_RATES;
162 *pos++ = sband->n_bitrates - 8; 192 *pos++ = rates_n - 8;
163 for (i = 8; i < sband->n_bitrates; i++) { 193 for (; ri < sband->n_bitrates; ri++) {
164 int rate = sband->bitrates[i].bitrate; 194 int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate,
195 5 * (1 << shift));
165 u8 basic = 0; 196 u8 basic = 0;
166 if (basic_rates & BIT(i)) 197 if (!(rates & BIT(ri)))
198 continue;
199
200 if (basic_rates & BIT(ri))
167 basic = 0x80; 201 basic = 0x80;
168 *pos++ = basic | (u8) (rate / 5); 202 *pos++ = basic | (u8) rate;
169 } 203 }
170 } 204 }
171 205
@@ -179,8 +213,12 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
179 chandef.width != NL80211_CHAN_WIDTH_5 && 213 chandef.width != NL80211_CHAN_WIDTH_5 &&
180 chandef.width != NL80211_CHAN_WIDTH_10 && 214 chandef.width != NL80211_CHAN_WIDTH_10 &&
181 sband->ht_cap.ht_supported) { 215 sband->ht_cap.ht_supported) {
182 pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, 216 struct ieee80211_sta_ht_cap ht_cap;
183 sband->ht_cap.cap); 217
218 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
219 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
220
221 pos = ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap);
184 /* 222 /*
185 * Note: According to 802.11n-2009 9.13.3.1, HT Protection 223 * Note: According to 802.11n-2009 9.13.3.1, HT Protection
186 * field and RIFS Mode are reserved in IBSS mode, therefore 224 * field and RIFS Mode are reserved in IBSS mode, therefore
@@ -236,18 +274,26 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
236 sdata->vif.bss_conf.use_short_slot = chan->band == IEEE80211_BAND_5GHZ; 274 sdata->vif.bss_conf.use_short_slot = chan->band == IEEE80211_BAND_5GHZ;
237 bss_change |= BSS_CHANGED_ERP_SLOT; 275 bss_change |= BSS_CHANGED_ERP_SLOT;
238 276
277 /* cf. IEEE 802.11 9.2.12 */
278 if (chan->band == IEEE80211_BAND_2GHZ && have_higher_than_11mbit)
279 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
280 else
281 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
282
239 sdata->vif.bss_conf.ibss_joined = true; 283 sdata->vif.bss_conf.ibss_joined = true;
240 sdata->vif.bss_conf.ibss_creator = creator; 284 sdata->vif.bss_conf.ibss_creator = creator;
241 ieee80211_bss_info_change_notify(sdata, bss_change); 285 ieee80211_bss_info_change_notify(sdata, bss_change);
242 286
243 ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates); 287 ieee80211_set_wmm_default(sdata, true);
244 288
245 ifibss->state = IEEE80211_IBSS_MLME_JOINED; 289 ifibss->state = IEEE80211_IBSS_MLME_JOINED;
246 mod_timer(&ifibss->timer, 290 mod_timer(&ifibss->timer,
247 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); 291 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
248 292
249 bss = cfg80211_inform_bss_frame(local->hw.wiphy, chan, 293 scan_width = cfg80211_chandef_to_scan_width(&chandef);
250 mgmt, presp->head_len, 0, GFP_KERNEL); 294 bss = cfg80211_inform_bss_width_frame(local->hw.wiphy, chan,
295 scan_width, mgmt,
296 presp->head_len, 0, GFP_KERNEL);
251 cfg80211_put_bss(local->hw.wiphy, bss); 297 cfg80211_put_bss(local->hw.wiphy, bss);
252 netif_carrier_on(sdata->dev); 298 netif_carrier_on(sdata->dev);
253 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL); 299 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
@@ -264,6 +310,8 @@ static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
264 u16 beacon_int = cbss->beacon_interval; 310 u16 beacon_int = cbss->beacon_interval;
265 const struct cfg80211_bss_ies *ies; 311 const struct cfg80211_bss_ies *ies;
266 u64 tsf; 312 u64 tsf;
313 u32 rate_flags;
314 int shift;
267 315
268 sdata_assert_lock(sdata); 316 sdata_assert_lock(sdata);
269 317
@@ -271,15 +319,24 @@ static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
271 beacon_int = 10; 319 beacon_int = 10;
272 320
273 sband = sdata->local->hw.wiphy->bands[cbss->channel->band]; 321 sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
322 rate_flags = ieee80211_chandef_rate_flags(&sdata->u.ibss.chandef);
323 shift = ieee80211_vif_get_shift(&sdata->vif);
274 324
275 basic_rates = 0; 325 basic_rates = 0;
276 326
277 for (i = 0; i < bss->supp_rates_len; i++) { 327 for (i = 0; i < bss->supp_rates_len; i++) {
278 int rate = (bss->supp_rates[i] & 0x7f) * 5; 328 int rate = bss->supp_rates[i] & 0x7f;
279 bool is_basic = !!(bss->supp_rates[i] & 0x80); 329 bool is_basic = !!(bss->supp_rates[i] & 0x80);
280 330
281 for (j = 0; j < sband->n_bitrates; j++) { 331 for (j = 0; j < sband->n_bitrates; j++) {
282 if (sband->bitrates[j].bitrate == rate) { 332 int brate;
333 if ((rate_flags & sband->bitrates[j].flags)
334 != rate_flags)
335 continue;
336
337 brate = DIV_ROUND_UP(sband->bitrates[j].bitrate,
338 5 * (1 << shift));
339 if (brate == rate) {
283 if (is_basic) 340 if (is_basic)
284 basic_rates |= BIT(j); 341 basic_rates |= BIT(j);
285 break; 342 break;
@@ -335,6 +392,7 @@ ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, const u8 *bssid,
335 struct sta_info *sta; 392 struct sta_info *sta;
336 struct ieee80211_chanctx_conf *chanctx_conf; 393 struct ieee80211_chanctx_conf *chanctx_conf;
337 struct ieee80211_supported_band *sband; 394 struct ieee80211_supported_band *sband;
395 enum nl80211_bss_scan_width scan_width;
338 int band; 396 int band;
339 397
340 /* 398 /*
@@ -363,6 +421,7 @@ ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, const u8 *bssid,
363 if (WARN_ON_ONCE(!chanctx_conf)) 421 if (WARN_ON_ONCE(!chanctx_conf))
364 return NULL; 422 return NULL;
365 band = chanctx_conf->def.chan->band; 423 band = chanctx_conf->def.chan->band;
424 scan_width = cfg80211_chandef_to_scan_width(&chanctx_conf->def);
366 rcu_read_unlock(); 425 rcu_read_unlock();
367 426
368 sta = sta_info_alloc(sdata, addr, GFP_KERNEL); 427 sta = sta_info_alloc(sdata, addr, GFP_KERNEL);
@@ -376,7 +435,7 @@ ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, const u8 *bssid,
376 /* make sure mandatory rates are always added */ 435 /* make sure mandatory rates are always added */
377 sband = local->hw.wiphy->bands[band]; 436 sband = local->hw.wiphy->bands[band];
378 sta->sta.supp_rates[band] = supp_rates | 437 sta->sta.supp_rates[band] = supp_rates |
379 ieee80211_mandatory_rates(sband); 438 ieee80211_mandatory_rates(sband, scan_width);
380 439
381 return ieee80211_ibss_finish_sta(sta); 440 return ieee80211_ibss_finish_sta(sta);
382} 441}
@@ -440,6 +499,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
440 u64 beacon_timestamp, rx_timestamp; 499 u64 beacon_timestamp, rx_timestamp;
441 u32 supp_rates = 0; 500 u32 supp_rates = 0;
442 enum ieee80211_band band = rx_status->band; 501 enum ieee80211_band band = rx_status->band;
502 enum nl80211_bss_scan_width scan_width;
443 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band]; 503 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
444 bool rates_updated = false; 504 bool rates_updated = false;
445 505
@@ -461,16 +521,22 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
461 sta = sta_info_get(sdata, mgmt->sa); 521 sta = sta_info_get(sdata, mgmt->sa);
462 522
463 if (elems->supp_rates) { 523 if (elems->supp_rates) {
464 supp_rates = ieee80211_sta_get_rates(local, elems, 524 supp_rates = ieee80211_sta_get_rates(sdata, elems,
465 band, NULL); 525 band, NULL);
466 if (sta) { 526 if (sta) {
467 u32 prev_rates; 527 u32 prev_rates;
468 528
469 prev_rates = sta->sta.supp_rates[band]; 529 prev_rates = sta->sta.supp_rates[band];
470 /* make sure mandatory rates are always added */ 530 /* make sure mandatory rates are always added */
471 sta->sta.supp_rates[band] = supp_rates | 531 scan_width = NL80211_BSS_CHAN_WIDTH_20;
472 ieee80211_mandatory_rates(sband); 532 if (rx_status->flag & RX_FLAG_5MHZ)
533 scan_width = NL80211_BSS_CHAN_WIDTH_5;
534 if (rx_status->flag & RX_FLAG_10MHZ)
535 scan_width = NL80211_BSS_CHAN_WIDTH_10;
473 536
537 sta->sta.supp_rates[band] = supp_rates |
538 ieee80211_mandatory_rates(sband,
539 scan_width);
474 if (sta->sta.supp_rates[band] != prev_rates) { 540 if (sta->sta.supp_rates[band] != prev_rates) {
475 ibss_dbg(sdata, 541 ibss_dbg(sdata,
476 "updated supp_rates set for %pM based on beacon/probe_resp (0x%x -> 0x%x)\n", 542 "updated supp_rates set for %pM based on beacon/probe_resp (0x%x -> 0x%x)\n",
@@ -585,7 +651,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
585 "beacon TSF higher than local TSF - IBSS merge with BSSID %pM\n", 651 "beacon TSF higher than local TSF - IBSS merge with BSSID %pM\n",
586 mgmt->bssid); 652 mgmt->bssid);
587 ieee80211_sta_join_ibss(sdata, bss); 653 ieee80211_sta_join_ibss(sdata, bss);
588 supp_rates = ieee80211_sta_get_rates(local, elems, band, NULL); 654 supp_rates = ieee80211_sta_get_rates(sdata, elems, band, NULL);
589 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, 655 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa,
590 supp_rates); 656 supp_rates);
591 rcu_read_unlock(); 657 rcu_read_unlock();
@@ -604,6 +670,7 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
604 struct sta_info *sta; 670 struct sta_info *sta;
605 struct ieee80211_chanctx_conf *chanctx_conf; 671 struct ieee80211_chanctx_conf *chanctx_conf;
606 struct ieee80211_supported_band *sband; 672 struct ieee80211_supported_band *sband;
673 enum nl80211_bss_scan_width scan_width;
607 int band; 674 int band;
608 675
609 /* 676 /*
@@ -629,6 +696,7 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
629 return; 696 return;
630 } 697 }
631 band = chanctx_conf->def.chan->band; 698 band = chanctx_conf->def.chan->band;
699 scan_width = cfg80211_chandef_to_scan_width(&chanctx_conf->def);
632 rcu_read_unlock(); 700 rcu_read_unlock();
633 701
634 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); 702 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
@@ -640,7 +708,7 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
640 /* make sure mandatory rates are always added */ 708 /* make sure mandatory rates are always added */
641 sband = local->hw.wiphy->bands[band]; 709 sband = local->hw.wiphy->bands[band];
642 sta->sta.supp_rates[band] = supp_rates | 710 sta->sta.supp_rates[band] = supp_rates |
643 ieee80211_mandatory_rates(sband); 711 ieee80211_mandatory_rates(sband, scan_width);
644 712
645 spin_lock(&ifibss->incomplete_lock); 713 spin_lock(&ifibss->incomplete_lock);
646 list_add(&sta->list, &ifibss->incomplete_stations); 714 list_add(&sta->list, &ifibss->incomplete_stations);
@@ -679,6 +747,7 @@ static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
679static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) 747static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
680{ 748{
681 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 749 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
750 enum nl80211_bss_scan_width scan_width;
682 751
683 sdata_assert_lock(sdata); 752 sdata_assert_lock(sdata);
684 753
@@ -700,8 +769,9 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
700 sdata_info(sdata, 769 sdata_info(sdata,
701 "No active IBSS STAs - trying to scan for other IBSS networks with same SSID (merge)\n"); 770 "No active IBSS STAs - trying to scan for other IBSS networks with same SSID (merge)\n");
702 771
772 scan_width = cfg80211_chandef_to_scan_width(&ifibss->chandef);
703 ieee80211_request_ibss_scan(sdata, ifibss->ssid, ifibss->ssid_len, 773 ieee80211_request_ibss_scan(sdata, ifibss->ssid, ifibss->ssid_len,
704 NULL); 774 NULL, scan_width);
705} 775}
706 776
707static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) 777static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
@@ -751,6 +821,7 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
751 struct cfg80211_bss *cbss; 821 struct cfg80211_bss *cbss;
752 struct ieee80211_channel *chan = NULL; 822 struct ieee80211_channel *chan = NULL;
753 const u8 *bssid = NULL; 823 const u8 *bssid = NULL;
824 enum nl80211_bss_scan_width scan_width;
754 int active_ibss; 825 int active_ibss;
755 u16 capability; 826 u16 capability;
756 827
@@ -799,8 +870,10 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
799 IEEE80211_SCAN_INTERVAL)) { 870 IEEE80211_SCAN_INTERVAL)) {
800 sdata_info(sdata, "Trigger new scan to find an IBSS to join\n"); 871 sdata_info(sdata, "Trigger new scan to find an IBSS to join\n");
801 872
873 scan_width = cfg80211_chandef_to_scan_width(&ifibss->chandef);
802 ieee80211_request_ibss_scan(sdata, ifibss->ssid, 874 ieee80211_request_ibss_scan(sdata, ifibss->ssid,
803 ifibss->ssid_len, chan); 875 ifibss->ssid_len, chan,
876 scan_width);
804 } else { 877 } else {
805 int interval = IEEE80211_SCAN_INTERVAL; 878 int interval = IEEE80211_SCAN_INTERVAL;
806 879
@@ -1020,6 +1093,9 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1020 struct cfg80211_ibss_params *params) 1093 struct cfg80211_ibss_params *params)
1021{ 1094{
1022 u32 changed = 0; 1095 u32 changed = 0;
1096 u32 rate_flags;
1097 struct ieee80211_supported_band *sband;
1098 int i;
1023 1099
1024 if (params->bssid) { 1100 if (params->bssid) {
1025 memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN); 1101 memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
@@ -1030,6 +1106,14 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1030 sdata->u.ibss.privacy = params->privacy; 1106 sdata->u.ibss.privacy = params->privacy;
1031 sdata->u.ibss.control_port = params->control_port; 1107 sdata->u.ibss.control_port = params->control_port;
1032 sdata->u.ibss.basic_rates = params->basic_rates; 1108 sdata->u.ibss.basic_rates = params->basic_rates;
1109
1110 /* fix basic_rates if channel does not support these rates */
1111 rate_flags = ieee80211_chandef_rate_flags(&params->chandef);
1112 sband = sdata->local->hw.wiphy->bands[params->chandef.chan->band];
1113 for (i = 0; i < sband->n_bitrates; i++) {
1114 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
1115 sdata->u.ibss.basic_rates &= ~BIT(i);
1116 }
1033 memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate, 1117 memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate,
1034 sizeof(params->mcast_rate)); 1118 sizeof(params->mcast_rate));
1035 1119
@@ -1051,6 +1135,11 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1051 memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len); 1135 memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len);
1052 sdata->u.ibss.ssid_len = params->ssid_len; 1136 sdata->u.ibss.ssid_len = params->ssid_len;
1053 1137
1138 memcpy(&sdata->u.ibss.ht_capa, &params->ht_capa,
1139 sizeof(sdata->u.ibss.ht_capa));
1140 memcpy(&sdata->u.ibss.ht_capa_mask, &params->ht_capa_mask,
1141 sizeof(sdata->u.ibss.ht_capa_mask));
1142
1054 /* 1143 /*
1055 * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is 1144 * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is
1056 * reserved, but an HT STA shall protect HT transmissions as though 1145 * reserved, but an HT STA shall protect HT transmissions as though
@@ -1131,6 +1220,11 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1131 presp = rcu_dereference_protected(ifibss->presp, 1220 presp = rcu_dereference_protected(ifibss->presp,
1132 lockdep_is_held(&sdata->wdev.mtx)); 1221 lockdep_is_held(&sdata->wdev.mtx));
1133 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL); 1222 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL);
1223
1224 /* on the next join, re-program HT parameters */
1225 memset(&ifibss->ht_capa, 0, sizeof(ifibss->ht_capa));
1226 memset(&ifibss->ht_capa_mask, 0, sizeof(ifibss->ht_capa_mask));
1227
1134 sdata->vif.bss_conf.ibss_joined = false; 1228 sdata->vif.bss_conf.ibss_joined = false;
1135 sdata->vif.bss_conf.ibss_creator = false; 1229 sdata->vif.bss_conf.ibss_creator = false;
1136 sdata->vif.bss_conf.enable_beacon = false; 1230 sdata->vif.bss_conf.enable_beacon = false;
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 8412a303993a..3d32df1fbc6d 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -509,6 +509,9 @@ struct ieee80211_if_ibss {
509 /* probe response/beacon for IBSS */ 509 /* probe response/beacon for IBSS */
510 struct beacon_data __rcu *presp; 510 struct beacon_data __rcu *presp;
511 511
512 struct ieee80211_ht_cap ht_capa; /* configured ht-cap over-rides */
513 struct ieee80211_ht_cap ht_capa_mask; /* Valid parts of ht_capa */
514
512 spinlock_t incomplete_lock; 515 spinlock_t incomplete_lock;
513 struct list_head incomplete_stations; 516 struct list_head incomplete_stations;
514 517
@@ -809,6 +812,34 @@ ieee80211_get_sdata_band(struct ieee80211_sub_if_data *sdata)
809 return band; 812 return band;
810} 813}
811 814
815static inline int
816ieee80211_chandef_get_shift(struct cfg80211_chan_def *chandef)
817{
818 switch (chandef->width) {
819 case NL80211_CHAN_WIDTH_5:
820 return 2;
821 case NL80211_CHAN_WIDTH_10:
822 return 1;
823 default:
824 return 0;
825 }
826}
827
828static inline int
829ieee80211_vif_get_shift(struct ieee80211_vif *vif)
830{
831 struct ieee80211_chanctx_conf *chanctx_conf;
832 int shift = 0;
833
834 rcu_read_lock();
835 chanctx_conf = rcu_dereference(vif->chanctx_conf);
836 if (chanctx_conf)
837 shift = ieee80211_chandef_get_shift(&chanctx_conf->def);
838 rcu_read_unlock();
839
840 return shift;
841}
842
812enum sdata_queue_type { 843enum sdata_queue_type {
813 IEEE80211_SDATA_QUEUE_TYPE_FRAME = 0, 844 IEEE80211_SDATA_QUEUE_TYPE_FRAME = 0,
814 IEEE80211_SDATA_QUEUE_AGG_START = 1, 845 IEEE80211_SDATA_QUEUE_AGG_START = 1,
@@ -1026,7 +1057,7 @@ struct ieee80211_local {
1026 struct cfg80211_ssid scan_ssid; 1057 struct cfg80211_ssid scan_ssid;
1027 struct cfg80211_scan_request *int_scan_req; 1058 struct cfg80211_scan_request *int_scan_req;
1028 struct cfg80211_scan_request *scan_req, *hw_scan_req; 1059 struct cfg80211_scan_request *scan_req, *hw_scan_req;
1029 struct ieee80211_channel *scan_channel; 1060 struct cfg80211_chan_def scan_chandef;
1030 enum ieee80211_band hw_scan_band; 1061 enum ieee80211_band hw_scan_band;
1031 int scan_channel_idx; 1062 int scan_channel_idx;
1032 int scan_ies_len; 1063 int scan_ies_len;
@@ -1306,7 +1337,8 @@ void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1306void ieee80211_scan_work(struct work_struct *work); 1337void ieee80211_scan_work(struct work_struct *work);
1307int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata, 1338int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata,
1308 const u8 *ssid, u8 ssid_len, 1339 const u8 *ssid, u8 ssid_len,
1309 struct ieee80211_channel *chan); 1340 struct ieee80211_channel *chan,
1341 enum nl80211_bss_scan_width scan_width);
1310int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, 1342int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
1311 struct cfg80211_scan_request *req); 1343 struct cfg80211_scan_request *req);
1312void ieee80211_scan_cancel(struct ieee80211_local *local); 1344void ieee80211_scan_cancel(struct ieee80211_local *local);
@@ -1465,7 +1497,8 @@ extern void *mac80211_wiphy_privid; /* for wiphy privid */
1465u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, 1497u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
1466 enum nl80211_iftype type); 1498 enum nl80211_iftype type);
1467int ieee80211_frame_duration(enum ieee80211_band band, size_t len, 1499int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
1468 int rate, int erp, int short_preamble); 1500 int rate, int erp, int short_preamble,
1501 int shift);
1469void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 1502void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
1470 struct ieee80211_hdr *hdr, const u8 *tsc, 1503 struct ieee80211_hdr *hdr, const u8 *tsc,
1471 gfp_t gfp); 1504 gfp_t gfp);
@@ -1569,7 +1602,7 @@ void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
1569int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, 1602int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1570 size_t buffer_len, const u8 *ie, size_t ie_len, 1603 size_t buffer_len, const u8 *ie, size_t ie_len,
1571 enum ieee80211_band band, u32 rate_mask, 1604 enum ieee80211_band band, u32 rate_mask,
1572 u8 channel); 1605 struct cfg80211_chan_def *chandef);
1573struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata, 1606struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
1574 u8 *dst, u32 ratemask, 1607 u8 *dst, u32 ratemask,
1575 struct ieee80211_channel *chan, 1608 struct ieee80211_channel *chan,
@@ -1582,10 +1615,7 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1582 u32 ratemask, bool directed, u32 tx_flags, 1615 u32 ratemask, bool directed, u32 tx_flags,
1583 struct ieee80211_channel *channel, bool scan); 1616 struct ieee80211_channel *channel, bool scan);
1584 1617
1585void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 1618u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
1586 const size_t supp_rates_len,
1587 const u8 *supp_rates);
1588u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
1589 struct ieee802_11_elems *elems, 1619 struct ieee802_11_elems *elems,
1590 enum ieee80211_band band, u32 *basic_rates); 1620 enum ieee80211_band band, u32 *basic_rates);
1591int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata, 1621int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
@@ -1602,6 +1632,9 @@ u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
1602 u16 prot_mode); 1632 u16 prot_mode);
1603u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap, 1633u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
1604 u32 cap); 1634 u32 cap);
1635int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef,
1636 const struct ieee80211_supported_band *sband,
1637 const u8 *srates, int srates_len, u32 *rates);
1605int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata, 1638int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
1606 struct sk_buff *skb, bool need_basic, 1639 struct sk_buff *skb, bool need_basic,
1607 enum ieee80211_band band); 1640 enum ieee80211_band band);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index cc117591f678..4c41c11958c8 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -54,7 +54,7 @@ bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
54 return false; 54 return false;
55 } 55 }
56 56
57 power = chanctx_conf->def.chan->max_power; 57 power = ieee80211_chandef_max_power(&chanctx_conf->def);
58 rcu_read_unlock(); 58 rcu_read_unlock();
59 59
60 if (sdata->user_power_level != IEEE80211_UNSET_POWER_LEVEL) 60 if (sdata->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 091088ac7890..25eb35b01938 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -102,17 +102,8 @@ static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
102 102
103 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL; 103 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
104 104
105 if (local->scan_channel) { 105 if (local->scan_chandef.chan) {
106 chandef.chan = local->scan_channel; 106 chandef = local->scan_chandef;
107 /* If scanning on oper channel, use whatever channel-type
108 * is currently in use.
109 */
110 if (chandef.chan == local->_oper_chandef.chan) {
111 chandef = local->_oper_chandef;
112 } else {
113 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
114 chandef.center_freq1 = chandef.chan->center_freq;
115 }
116 } else if (local->tmp_channel) { 107 } else if (local->tmp_channel) {
117 chandef.chan = local->tmp_channel; 108 chandef.chan = local->tmp_channel;
118 chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 109 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
@@ -151,7 +142,7 @@ static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
151 changed |= IEEE80211_CONF_CHANGE_SMPS; 142 changed |= IEEE80211_CONF_CHANGE_SMPS;
152 } 143 }
153 144
154 power = chandef.chan->max_power; 145 power = ieee80211_chandef_max_power(&chandef);
155 146
156 rcu_read_lock(); 147 rcu_read_lock();
157 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 148 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 447f41bbe744..885a5f6e2c21 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -62,7 +62,6 @@ bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
62 struct ieee802_11_elems *ie) 62 struct ieee802_11_elems *ie)
63{ 63{
64 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 64 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
65 struct ieee80211_local *local = sdata->local;
66 u32 basic_rates = 0; 65 u32 basic_rates = 0;
67 struct cfg80211_chan_def sta_chan_def; 66 struct cfg80211_chan_def sta_chan_def;
68 67
@@ -85,7 +84,7 @@ bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
85 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))) 84 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth)))
86 return false; 85 return false;
87 86
88 ieee80211_sta_get_rates(local, ie, ieee80211_get_sdata_band(sdata), 87 ieee80211_sta_get_rates(sdata, ie, ieee80211_get_sdata_band(sdata),
89 &basic_rates); 88 &basic_rates);
90 89
91 if (sdata->vif.bss_conf.basic_rates != basic_rates) 90 if (sdata->vif.bss_conf.basic_rates != basic_rates)
@@ -274,7 +273,9 @@ int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
274 neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS); 273 neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS);
275 *pos++ = neighbors << 1; 274 *pos++ = neighbors << 1;
276 /* Mesh capability */ 275 /* Mesh capability */
277 *pos = IEEE80211_MESHCONF_CAPAB_FORWARDING; 276 *pos = 0x00;
277 *pos |= ifmsh->mshcfg.dot11MeshForwarding ?
278 IEEE80211_MESHCONF_CAPAB_FORWARDING : 0x00;
278 *pos |= ifmsh->accepting_plinks ? 279 *pos |= ifmsh->accepting_plinks ?
279 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00; 280 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
280 /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */ 281 /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 02c05fa15c20..6b65d5055f5b 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -379,7 +379,7 @@ static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
379 u32 rates, basic_rates = 0, changed = 0; 379 u32 rates, basic_rates = 0, changed = 0;
380 380
381 sband = local->hw.wiphy->bands[band]; 381 sband = local->hw.wiphy->bands[band];
382 rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates); 382 rates = ieee80211_sta_get_rates(sdata, elems, band, &basic_rates);
383 383
384 spin_lock_bh(&sta->lock); 384 spin_lock_bh(&sta->lock);
385 sta->last_rx = jiffies; 385 sta->last_rx = jiffies;
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index ae31968d42d3..211246b46819 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -478,27 +478,6 @@ static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
478 478
479/* frame sending functions */ 479/* frame sending functions */
480 480
481static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
482 struct ieee80211_supported_band *sband,
483 u32 *rates)
484{
485 int i, j, count;
486 *rates = 0;
487 count = 0;
488 for (i = 0; i < supp_rates_len; i++) {
489 int rate = (supp_rates[i] & 0x7F) * 5;
490
491 for (j = 0; j < sband->n_bitrates; j++)
492 if (sband->bitrates[j].bitrate == rate) {
493 *rates |= BIT(j);
494 count++;
495 break;
496 }
497 }
498
499 return count;
500}
501
502static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, 481static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
503 struct sk_buff *skb, u8 ap_ht_param, 482 struct sk_buff *skb, u8 ap_ht_param,
504 struct ieee80211_supported_band *sband, 483 struct ieee80211_supported_band *sband,
@@ -617,12 +596,12 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
617 struct ieee80211_mgmt *mgmt; 596 struct ieee80211_mgmt *mgmt;
618 u8 *pos, qos_info; 597 u8 *pos, qos_info;
619 size_t offset = 0, noffset; 598 size_t offset = 0, noffset;
620 int i, count, rates_len, supp_rates_len; 599 int i, count, rates_len, supp_rates_len, shift;
621 u16 capab; 600 u16 capab;
622 struct ieee80211_supported_band *sband; 601 struct ieee80211_supported_band *sband;
623 struct ieee80211_chanctx_conf *chanctx_conf; 602 struct ieee80211_chanctx_conf *chanctx_conf;
624 struct ieee80211_channel *chan; 603 struct ieee80211_channel *chan;
625 u32 rates = 0; 604 u32 rate_flags, rates = 0;
626 605
627 sdata_assert_lock(sdata); 606 sdata_assert_lock(sdata);
628 607
@@ -633,8 +612,10 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
633 return; 612 return;
634 } 613 }
635 chan = chanctx_conf->def.chan; 614 chan = chanctx_conf->def.chan;
615 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
636 rcu_read_unlock(); 616 rcu_read_unlock();
637 sband = local->hw.wiphy->bands[chan->band]; 617 sband = local->hw.wiphy->bands[chan->band];
618 shift = ieee80211_vif_get_shift(&sdata->vif);
638 619
639 if (assoc_data->supp_rates_len) { 620 if (assoc_data->supp_rates_len) {
640 /* 621 /*
@@ -643,17 +624,24 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
643 * in the association request (e.g. D-Link DAP 1353 in 624 * in the association request (e.g. D-Link DAP 1353 in
644 * b-only mode)... 625 * b-only mode)...
645 */ 626 */
646 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates, 627 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
647 assoc_data->supp_rates_len, 628 assoc_data->supp_rates,
648 sband, &rates); 629 assoc_data->supp_rates_len,
630 &rates);
649 } else { 631 } else {
650 /* 632 /*
651 * In case AP not provide any supported rates information 633 * In case AP not provide any supported rates information
652 * before association, we send information element(s) with 634 * before association, we send information element(s) with
653 * all rates that we support. 635 * all rates that we support.
654 */ 636 */
655 rates = ~0; 637 rates_len = 0;
656 rates_len = sband->n_bitrates; 638 for (i = 0; i < sband->n_bitrates; i++) {
639 if ((rate_flags & sband->bitrates[i].flags)
640 != rate_flags)
641 continue;
642 rates |= BIT(i);
643 rates_len++;
644 }
657 } 645 }
658 646
659 skb = alloc_skb(local->hw.extra_tx_headroom + 647 skb = alloc_skb(local->hw.extra_tx_headroom +
@@ -730,8 +718,9 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
730 count = 0; 718 count = 0;
731 for (i = 0; i < sband->n_bitrates; i++) { 719 for (i = 0; i < sband->n_bitrates; i++) {
732 if (BIT(i) & rates) { 720 if (BIT(i) & rates) {
733 int rate = sband->bitrates[i].bitrate; 721 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
734 *pos++ = (u8) (rate / 5); 722 5 * (1 << shift));
723 *pos++ = (u8) rate;
735 if (++count == 8) 724 if (++count == 8)
736 break; 725 break;
737 } 726 }
@@ -744,8 +733,10 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
744 733
745 for (i++; i < sband->n_bitrates; i++) { 734 for (i++; i < sband->n_bitrates; i++) {
746 if (BIT(i) & rates) { 735 if (BIT(i) & rates) {
747 int rate = sband->bitrates[i].bitrate; 736 int rate;
748 *pos++ = (u8) (rate / 5); 737 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
738 5 * (1 << shift));
739 *pos++ = (u8) rate;
749 } 740 }
750 } 741 }
751 } 742 }
@@ -756,7 +747,8 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
756 *pos++ = WLAN_EID_PWR_CAPABILITY; 747 *pos++ = WLAN_EID_PWR_CAPABILITY;
757 *pos++ = 2; 748 *pos++ = 2;
758 *pos++ = 0; /* min tx power */ 749 *pos++ = 0; /* min tx power */
759 *pos++ = chan->max_power; /* max tx power */ 750 /* max tx power */
751 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
760 752
761 /* 2. supported channels */ 753 /* 2. supported channels */
762 /* TODO: get this in reg domain format */ 754 /* TODO: get this in reg domain format */
@@ -2432,15 +2424,16 @@ static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2432 u8 *supp_rates, unsigned int supp_rates_len, 2424 u8 *supp_rates, unsigned int supp_rates_len,
2433 u32 *rates, u32 *basic_rates, 2425 u32 *rates, u32 *basic_rates,
2434 bool *have_higher_than_11mbit, 2426 bool *have_higher_than_11mbit,
2435 int *min_rate, int *min_rate_index) 2427 int *min_rate, int *min_rate_index,
2428 int shift, u32 rate_flags)
2436{ 2429{
2437 int i, j; 2430 int i, j;
2438 2431
2439 for (i = 0; i < supp_rates_len; i++) { 2432 for (i = 0; i < supp_rates_len; i++) {
2440 int rate = (supp_rates[i] & 0x7f) * 5; 2433 int rate = supp_rates[i] & 0x7f;
2441 bool is_basic = !!(supp_rates[i] & 0x80); 2434 bool is_basic = !!(supp_rates[i] & 0x80);
2442 2435
2443 if (rate > 110) 2436 if ((rate * 5 * (1 << shift)) > 110)
2444 *have_higher_than_11mbit = true; 2437 *have_higher_than_11mbit = true;
2445 2438
2446 /* 2439 /*
@@ -2456,12 +2449,20 @@ static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2456 continue; 2449 continue;
2457 2450
2458 for (j = 0; j < sband->n_bitrates; j++) { 2451 for (j = 0; j < sband->n_bitrates; j++) {
2459 if (sband->bitrates[j].bitrate == rate) { 2452 struct ieee80211_rate *br;
2453 int brate;
2454
2455 br = &sband->bitrates[j];
2456 if ((rate_flags & br->flags) != rate_flags)
2457 continue;
2458
2459 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
2460 if (brate == rate) {
2460 *rates |= BIT(j); 2461 *rates |= BIT(j);
2461 if (is_basic) 2462 if (is_basic)
2462 *basic_rates |= BIT(j); 2463 *basic_rates |= BIT(j);
2463 if (rate < *min_rate) { 2464 if ((rate * 5) < *min_rate) {
2464 *min_rate = rate; 2465 *min_rate = rate * 5;
2465 *min_rate_index = j; 2466 *min_rate_index = j;
2466 } 2467 }
2467 break; 2468 break;
@@ -3884,27 +3885,40 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3884 if (!new_sta) 3885 if (!new_sta)
3885 return -ENOMEM; 3886 return -ENOMEM;
3886 } 3887 }
3887
3888 if (new_sta) { 3888 if (new_sta) {
3889 u32 rates = 0, basic_rates = 0; 3889 u32 rates = 0, basic_rates = 0;
3890 bool have_higher_than_11mbit; 3890 bool have_higher_than_11mbit;
3891 int min_rate = INT_MAX, min_rate_index = -1; 3891 int min_rate = INT_MAX, min_rate_index = -1;
3892 struct ieee80211_chanctx_conf *chanctx_conf;
3892 struct ieee80211_supported_band *sband; 3893 struct ieee80211_supported_band *sband;
3893 const struct cfg80211_bss_ies *ies; 3894 const struct cfg80211_bss_ies *ies;
3895 int shift;
3896 u32 rate_flags;
3894 3897
3895 sband = local->hw.wiphy->bands[cbss->channel->band]; 3898 sband = local->hw.wiphy->bands[cbss->channel->band];
3896 3899
3897 err = ieee80211_prep_channel(sdata, cbss); 3900 err = ieee80211_prep_channel(sdata, cbss);
3898 if (err) { 3901 if (err) {
3899 sta_info_free(local, new_sta); 3902 sta_info_free(local, new_sta);
3900 return err; 3903 return -EINVAL;
3901 } 3904 }
3905 shift = ieee80211_vif_get_shift(&sdata->vif);
3906
3907 rcu_read_lock();
3908 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3909 if (WARN_ON(!chanctx_conf)) {
3910 rcu_read_unlock();
3911 return -EINVAL;
3912 }
3913 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
3914 rcu_read_unlock();
3902 3915
3903 ieee80211_get_rates(sband, bss->supp_rates, 3916 ieee80211_get_rates(sband, bss->supp_rates,
3904 bss->supp_rates_len, 3917 bss->supp_rates_len,
3905 &rates, &basic_rates, 3918 &rates, &basic_rates,
3906 &have_higher_than_11mbit, 3919 &have_higher_than_11mbit,
3907 &min_rate, &min_rate_index); 3920 &min_rate, &min_rate_index,
3921 shift, rate_flags);
3908 3922
3909 /* 3923 /*
3910 * This used to be a workaround for basic rates missing 3924 * This used to be a workaround for basic rates missing
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index 30d58d2d13e2..ba63ac851c2b 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -232,37 +232,28 @@ static void rc_send_low_broadcast(s8 *idx, u32 basic_rates,
232 /* could not find a basic rate; use original selection */ 232 /* could not find a basic rate; use original selection */
233} 233}
234 234
235static inline s8 235static void __rate_control_send_low(struct ieee80211_hw *hw,
236rate_lowest_non_cck_index(struct ieee80211_supported_band *sband, 236 struct ieee80211_supported_band *sband,
237 struct ieee80211_sta *sta) 237 struct ieee80211_sta *sta,
238 struct ieee80211_tx_info *info)
238{ 239{
239 int i; 240 int i;
241 u32 rate_flags =
242 ieee80211_chandef_rate_flags(&hw->conf.chandef);
240 243
244 if ((sband->band == IEEE80211_BAND_2GHZ) &&
245 (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
246 rate_flags |= IEEE80211_RATE_ERP_G;
247
248 info->control.rates[0].idx = 0;
241 for (i = 0; i < sband->n_bitrates; i++) { 249 for (i = 0; i < sband->n_bitrates; i++) {
242 struct ieee80211_rate *srate = &sband->bitrates[i]; 250 if (!rate_supported(sta, sband->band, i))
243 if ((srate->bitrate == 10) || (srate->bitrate == 20) ||
244 (srate->bitrate == 55) || (srate->bitrate == 110))
245 continue; 251 continue;
246 252
247 if (rate_supported(sta, sband->band, i)) 253 info->control.rates[0].idx = i;
248 return i; 254 break;
249 } 255 }
250 256 WARN_ON_ONCE(i == sband->n_bitrates);
251 /* No matching rate found */
252 return 0;
253}
254
255static void __rate_control_send_low(struct ieee80211_hw *hw,
256 struct ieee80211_supported_band *sband,
257 struct ieee80211_sta *sta,
258 struct ieee80211_tx_info *info)
259{
260 if ((sband->band != IEEE80211_BAND_2GHZ) ||
261 !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
262 info->control.rates[0].idx = rate_lowest_index(sband, sta);
263 else
264 info->control.rates[0].idx =
265 rate_lowest_non_cck_index(sband, sta);
266 257
267 info->control.rates[0].count = 258 info->control.rates[0].count =
268 (info->flags & IEEE80211_TX_CTL_NO_ACK) ? 259 (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
@@ -585,6 +576,7 @@ static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata,
585 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]; 576 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
586 bool has_mcs_mask; 577 bool has_mcs_mask;
587 u32 mask; 578 u32 mask;
579 u32 rate_flags;
588 int i; 580 int i;
589 581
590 /* 582 /*
@@ -594,6 +586,12 @@ static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata,
594 */ 586 */
595 mask = sdata->rc_rateidx_mask[info->band]; 587 mask = sdata->rc_rateidx_mask[info->band];
596 has_mcs_mask = sdata->rc_has_mcs_mask[info->band]; 588 has_mcs_mask = sdata->rc_has_mcs_mask[info->band];
589 rate_flags =
590 ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
591 for (i = 0; i < sband->n_bitrates; i++)
592 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
593 mask &= ~BIT(i);
594
597 if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask) 595 if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask)
598 return; 596 return;
599 597
diff --git a/net/mac80211/rate.h b/net/mac80211/rate.h
index d35a5dd3fb13..5dedc56c94db 100644
--- a/net/mac80211/rate.h
+++ b/net/mac80211/rate.h
@@ -66,11 +66,12 @@ static inline void rate_control_rate_init(struct sta_info *sta)
66 } 66 }
67 67
68 sband = local->hw.wiphy->bands[chanctx_conf->def.chan->band]; 68 sband = local->hw.wiphy->bands[chanctx_conf->def.chan->band];
69 rcu_read_unlock();
70 69
71 ieee80211_sta_set_rx_nss(sta); 70 ieee80211_sta_set_rx_nss(sta);
72 71
73 ref->ops->rate_init(ref->priv, sband, ista, priv_sta); 72 ref->ops->rate_init(ref->priv, sband, &chanctx_conf->def, ista,
73 priv_sta);
74 rcu_read_unlock();
74 set_sta_flag(sta, WLAN_STA_RATE_CONTROL); 75 set_sta_flag(sta, WLAN_STA_RATE_CONTROL);
75} 76}
76 77
@@ -81,10 +82,21 @@ static inline void rate_control_rate_update(struct ieee80211_local *local,
81 struct rate_control_ref *ref = local->rate_ctrl; 82 struct rate_control_ref *ref = local->rate_ctrl;
82 struct ieee80211_sta *ista = &sta->sta; 83 struct ieee80211_sta *ista = &sta->sta;
83 void *priv_sta = sta->rate_ctrl_priv; 84 void *priv_sta = sta->rate_ctrl_priv;
85 struct ieee80211_chanctx_conf *chanctx_conf;
86
87 if (ref && ref->ops->rate_update) {
88 rcu_read_lock();
84 89
85 if (ref && ref->ops->rate_update) 90 chanctx_conf = rcu_dereference(sta->sdata->vif.chanctx_conf);
86 ref->ops->rate_update(ref->priv, sband, ista, 91 if (WARN_ON(!chanctx_conf)) {
87 priv_sta, changed); 92 rcu_read_unlock();
93 return;
94 }
95
96 ref->ops->rate_update(ref->priv, sband, &chanctx_conf->def,
97 ista, priv_sta, changed);
98 rcu_read_unlock();
99 }
88 drv_sta_rc_update(local, sta->sdata, &sta->sta, changed); 100 drv_sta_rc_update(local, sta->sdata, &sta->sta, changed);
89} 101}
90 102
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index e6512e2ffd20..8b5f7ef7c0c9 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -383,14 +383,18 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
383static void 383static void
384calc_rate_durations(enum ieee80211_band band, 384calc_rate_durations(enum ieee80211_band band,
385 struct minstrel_rate *d, 385 struct minstrel_rate *d,
386 struct ieee80211_rate *rate) 386 struct ieee80211_rate *rate,
387 struct cfg80211_chan_def *chandef)
387{ 388{
388 int erp = !!(rate->flags & IEEE80211_RATE_ERP_G); 389 int erp = !!(rate->flags & IEEE80211_RATE_ERP_G);
390 int shift = ieee80211_chandef_get_shift(chandef);
389 391
390 d->perfect_tx_time = ieee80211_frame_duration(band, 1200, 392 d->perfect_tx_time = ieee80211_frame_duration(band, 1200,
391 rate->bitrate, erp, 1); 393 DIV_ROUND_UP(rate->bitrate, 1 << shift), erp, 1,
394 shift);
392 d->ack_time = ieee80211_frame_duration(band, 10, 395 d->ack_time = ieee80211_frame_duration(band, 10,
393 rate->bitrate, erp, 1); 396 DIV_ROUND_UP(rate->bitrate, 1 << shift), erp, 1,
397 shift);
394} 398}
395 399
396static void 400static void
@@ -418,21 +422,25 @@ init_sample_table(struct minstrel_sta_info *mi)
418 422
419static void 423static void
420minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband, 424minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
421 struct ieee80211_sta *sta, void *priv_sta) 425 struct cfg80211_chan_def *chandef,
426 struct ieee80211_sta *sta, void *priv_sta)
422{ 427{
423 struct minstrel_sta_info *mi = priv_sta; 428 struct minstrel_sta_info *mi = priv_sta;
424 struct minstrel_priv *mp = priv; 429 struct minstrel_priv *mp = priv;
425 struct ieee80211_rate *ctl_rate; 430 struct ieee80211_rate *ctl_rate;
426 unsigned int i, n = 0; 431 unsigned int i, n = 0;
427 unsigned int t_slot = 9; /* FIXME: get real slot time */ 432 unsigned int t_slot = 9; /* FIXME: get real slot time */
433 u32 rate_flags;
428 434
429 mi->sta = sta; 435 mi->sta = sta;
430 mi->lowest_rix = rate_lowest_index(sband, sta); 436 mi->lowest_rix = rate_lowest_index(sband, sta);
431 ctl_rate = &sband->bitrates[mi->lowest_rix]; 437 ctl_rate = &sband->bitrates[mi->lowest_rix];
432 mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10, 438 mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
433 ctl_rate->bitrate, 439 ctl_rate->bitrate,
434 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1); 440 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1,
441 ieee80211_chandef_get_shift(chandef));
435 442
443 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
436 memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate)); 444 memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
437 mi->max_prob_rate = 0; 445 mi->max_prob_rate = 0;
438 446
@@ -441,15 +449,22 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
441 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0; 449 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
442 unsigned int tx_time_single; 450 unsigned int tx_time_single;
443 unsigned int cw = mp->cw_min; 451 unsigned int cw = mp->cw_min;
452 int shift;
444 453
445 if (!rate_supported(sta, sband->band, i)) 454 if (!rate_supported(sta, sband->band, i))
446 continue; 455 continue;
456 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
457 continue;
458
447 n++; 459 n++;
448 memset(mr, 0, sizeof(*mr)); 460 memset(mr, 0, sizeof(*mr));
449 461
450 mr->rix = i; 462 mr->rix = i;
451 mr->bitrate = sband->bitrates[i].bitrate / 5; 463 shift = ieee80211_chandef_get_shift(chandef);
452 calc_rate_durations(sband->band, mr, &sband->bitrates[i]); 464 mr->bitrate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
465 (1 << shift) * 5);
466 calc_rate_durations(sband->band, mr, &sband->bitrates[i],
467 chandef);
453 468
454 /* calculate maximum number of retransmissions before 469 /* calculate maximum number of retransmissions before
455 * fallback (based on maximum segment size) */ 470 * fallback (based on maximum segment size) */
@@ -547,6 +562,7 @@ minstrel_init_cck_rates(struct minstrel_priv *mp)
547{ 562{
548 static const int bitrates[4] = { 10, 20, 55, 110 }; 563 static const int bitrates[4] = { 10, 20, 55, 110 };
549 struct ieee80211_supported_band *sband; 564 struct ieee80211_supported_band *sband;
565 u32 rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
550 int i, j; 566 int i, j;
551 567
552 sband = mp->hw->wiphy->bands[IEEE80211_BAND_2GHZ]; 568 sband = mp->hw->wiphy->bands[IEEE80211_BAND_2GHZ];
@@ -559,6 +575,9 @@ minstrel_init_cck_rates(struct minstrel_priv *mp)
559 if (rate->flags & IEEE80211_RATE_ERP_G) 575 if (rate->flags & IEEE80211_RATE_ERP_G)
560 continue; 576 continue;
561 577
578 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
579 continue;
580
562 for (j = 0; j < ARRAY_SIZE(bitrates); j++) { 581 for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
563 if (rate->bitrate != bitrates[j]) 582 if (rate->bitrate != bitrates[j])
564 continue; 583 continue;
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index f5aed963b22e..61569425b723 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -844,6 +844,7 @@ minstrel_ht_update_cck(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
844 844
845static void 845static void
846minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband, 846minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
847 struct cfg80211_chan_def *chandef,
847 struct ieee80211_sta *sta, void *priv_sta) 848 struct ieee80211_sta *sta, void *priv_sta)
848{ 849{
849 struct minstrel_priv *mp = priv; 850 struct minstrel_priv *mp = priv;
@@ -869,8 +870,9 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
869 mi->sta = sta; 870 mi->sta = sta;
870 mi->stats_update = jiffies; 871 mi->stats_update = jiffies;
871 872
872 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1); 873 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1, 0);
873 mi->overhead = ieee80211_frame_duration(sband->band, 0, 60, 1, 1) + ack_dur; 874 mi->overhead = ieee80211_frame_duration(sband->band, 0, 60, 1, 1, 0);
875 mi->overhead += ack_dur;
874 mi->overhead_rtscts = mi->overhead + 2 * ack_dur; 876 mi->overhead_rtscts = mi->overhead + 2 * ack_dur;
875 877
876 mi->avg_ampdu_len = MINSTREL_FRAC(1, 1); 878 mi->avg_ampdu_len = MINSTREL_FRAC(1, 1);
@@ -939,22 +941,25 @@ use_legacy:
939 memset(&msp->legacy, 0, sizeof(msp->legacy)); 941 memset(&msp->legacy, 0, sizeof(msp->legacy));
940 msp->legacy.r = msp->ratelist; 942 msp->legacy.r = msp->ratelist;
941 msp->legacy.sample_table = msp->sample_table; 943 msp->legacy.sample_table = msp->sample_table;
942 return mac80211_minstrel.rate_init(priv, sband, sta, &msp->legacy); 944 return mac80211_minstrel.rate_init(priv, sband, chandef, sta,
945 &msp->legacy);
943} 946}
944 947
945static void 948static void
946minstrel_ht_rate_init(void *priv, struct ieee80211_supported_band *sband, 949minstrel_ht_rate_init(void *priv, struct ieee80211_supported_band *sband,
950 struct cfg80211_chan_def *chandef,
947 struct ieee80211_sta *sta, void *priv_sta) 951 struct ieee80211_sta *sta, void *priv_sta)
948{ 952{
949 minstrel_ht_update_caps(priv, sband, sta, priv_sta); 953 minstrel_ht_update_caps(priv, sband, chandef, sta, priv_sta);
950} 954}
951 955
952static void 956static void
953minstrel_ht_rate_update(void *priv, struct ieee80211_supported_band *sband, 957minstrel_ht_rate_update(void *priv, struct ieee80211_supported_band *sband,
958 struct cfg80211_chan_def *chandef,
954 struct ieee80211_sta *sta, void *priv_sta, 959 struct ieee80211_sta *sta, void *priv_sta,
955 u32 changed) 960 u32 changed)
956{ 961{
957 minstrel_ht_update_caps(priv, sband, sta, priv_sta); 962 minstrel_ht_update_caps(priv, sband, chandef, sta, priv_sta);
958} 963}
959 964
960static void * 965static void *
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 502d3ecc4a79..958fad07b54c 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -293,6 +293,7 @@ rate_control_pid_get_rate(void *priv, struct ieee80211_sta *sta,
293 293
294static void 294static void
295rate_control_pid_rate_init(void *priv, struct ieee80211_supported_band *sband, 295rate_control_pid_rate_init(void *priv, struct ieee80211_supported_band *sband,
296 struct cfg80211_chan_def *chandef,
296 struct ieee80211_sta *sta, void *priv_sta) 297 struct ieee80211_sta *sta, void *priv_sta)
297{ 298{
298 struct rc_pid_sta_info *spinfo = priv_sta; 299 struct rc_pid_sta_info *spinfo = priv_sta;
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 2c5a79bd3777..6b85f95b9ba1 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -87,11 +87,13 @@ ieee80211_rx_radiotap_space(struct ieee80211_local *local,
87 int len; 87 int len;
88 88
89 /* always present fields */ 89 /* always present fields */
90 len = sizeof(struct ieee80211_radiotap_header) + 9; 90 len = sizeof(struct ieee80211_radiotap_header) + 8;
91 91
92 /* allocate extra bitmap */ 92 /* allocate extra bitmaps */
93 if (status->vendor_radiotap_len) 93 if (status->vendor_radiotap_len)
94 len += 4; 94 len += 4;
95 if (status->chains)
96 len += 4 * hweight8(status->chains);
95 97
96 if (ieee80211_have_rx_timestamp(status)) { 98 if (ieee80211_have_rx_timestamp(status)) {
97 len = ALIGN(len, 8); 99 len = ALIGN(len, 8);
@@ -100,6 +102,10 @@ ieee80211_rx_radiotap_space(struct ieee80211_local *local,
100 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) 102 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
101 len += 1; 103 len += 1;
102 104
105 /* antenna field, if we don't have per-chain info */
106 if (!status->chains)
107 len += 1;
108
103 /* padding for RX_FLAGS if necessary */ 109 /* padding for RX_FLAGS if necessary */
104 len = ALIGN(len, 2); 110 len = ALIGN(len, 2);
105 111
@@ -116,6 +122,11 @@ ieee80211_rx_radiotap_space(struct ieee80211_local *local,
116 len += 12; 122 len += 12;
117 } 123 }
118 124
125 if (status->chains) {
126 /* antenna and antenna signal fields */
127 len += 2 * hweight8(status->chains);
128 }
129
119 if (status->vendor_radiotap_len) { 130 if (status->vendor_radiotap_len) {
120 if (WARN_ON_ONCE(status->vendor_radiotap_align == 0)) 131 if (WARN_ON_ONCE(status->vendor_radiotap_align == 0))
121 status->vendor_radiotap_align = 1; 132 status->vendor_radiotap_align = 1;
@@ -145,8 +156,12 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
145 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 156 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
146 struct ieee80211_radiotap_header *rthdr; 157 struct ieee80211_radiotap_header *rthdr;
147 unsigned char *pos; 158 unsigned char *pos;
159 __le32 *it_present;
160 u32 it_present_val;
148 u16 rx_flags = 0; 161 u16 rx_flags = 0;
149 int mpdulen; 162 u16 channel_flags = 0;
163 int mpdulen, chain;
164 unsigned long chains = status->chains;
150 165
151 mpdulen = skb->len; 166 mpdulen = skb->len;
152 if (!(has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))) 167 if (!(has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)))
@@ -154,25 +169,39 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
154 169
155 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len); 170 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
156 memset(rthdr, 0, rtap_len); 171 memset(rthdr, 0, rtap_len);
172 it_present = &rthdr->it_present;
157 173
158 /* radiotap header, set always present flags */ 174 /* radiotap header, set always present flags */
159 rthdr->it_present =
160 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
161 (1 << IEEE80211_RADIOTAP_CHANNEL) |
162 (1 << IEEE80211_RADIOTAP_ANTENNA) |
163 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
164 rthdr->it_len = cpu_to_le16(rtap_len + status->vendor_radiotap_len); 175 rthdr->it_len = cpu_to_le16(rtap_len + status->vendor_radiotap_len);
176 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
177 BIT(IEEE80211_RADIOTAP_CHANNEL) |
178 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
165 179
166 pos = (unsigned char *)(rthdr + 1); 180 if (!status->chains)
181 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
182
183 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
184 it_present_val |=
185 BIT(IEEE80211_RADIOTAP_EXT) |
186 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
187 put_unaligned_le32(it_present_val, it_present);
188 it_present++;
189 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
190 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
191 }
167 192
168 if (status->vendor_radiotap_len) { 193 if (status->vendor_radiotap_len) {
169 rthdr->it_present |= 194 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
170 cpu_to_le32(BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE)) | 195 BIT(IEEE80211_RADIOTAP_EXT);
171 cpu_to_le32(BIT(IEEE80211_RADIOTAP_EXT)); 196 put_unaligned_le32(it_present_val, it_present);
172 put_unaligned_le32(status->vendor_radiotap_bitmap, pos); 197 it_present++;
173 pos += 4; 198 it_present_val = status->vendor_radiotap_bitmap;
174 } 199 }
175 200
201 put_unaligned_le32(it_present_val, it_present);
202
203 pos = (void *)(it_present + 1);
204
176 /* the order of the following fields is important */ 205 /* the order of the following fields is important */
177 206
178 /* IEEE80211_RADIOTAP_TSFT */ 207 /* IEEE80211_RADIOTAP_TSFT */
@@ -207,28 +236,35 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
207 */ 236 */
208 *pos = 0; 237 *pos = 0;
209 } else { 238 } else {
239 int shift = 0;
210 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE); 240 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
211 *pos = rate->bitrate / 5; 241 if (status->flag & RX_FLAG_10MHZ)
242 shift = 1;
243 else if (status->flag & RX_FLAG_5MHZ)
244 shift = 2;
245 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
212 } 246 }
213 pos++; 247 pos++;
214 248
215 /* IEEE80211_RADIOTAP_CHANNEL */ 249 /* IEEE80211_RADIOTAP_CHANNEL */
216 put_unaligned_le16(status->freq, pos); 250 put_unaligned_le16(status->freq, pos);
217 pos += 2; 251 pos += 2;
252 if (status->flag & RX_FLAG_10MHZ)
253 channel_flags |= IEEE80211_CHAN_HALF;
254 else if (status->flag & RX_FLAG_5MHZ)
255 channel_flags |= IEEE80211_CHAN_QUARTER;
256
218 if (status->band == IEEE80211_BAND_5GHZ) 257 if (status->band == IEEE80211_BAND_5GHZ)
219 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ, 258 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
220 pos);
221 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) 259 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
222 put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ, 260 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
223 pos);
224 else if (rate && rate->flags & IEEE80211_RATE_ERP_G) 261 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
225 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ, 262 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
226 pos);
227 else if (rate) 263 else if (rate)
228 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ, 264 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
229 pos);
230 else 265 else
231 put_unaligned_le16(IEEE80211_CHAN_2GHZ, pos); 266 channel_flags |= IEEE80211_CHAN_2GHZ;
267 put_unaligned_le16(channel_flags, pos);
232 pos += 2; 268 pos += 2;
233 269
234 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */ 270 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
@@ -242,9 +278,11 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
242 278
243 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */ 279 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
244 280
245 /* IEEE80211_RADIOTAP_ANTENNA */ 281 if (!status->chains) {
246 *pos = status->antenna; 282 /* IEEE80211_RADIOTAP_ANTENNA */
247 pos++; 283 *pos = status->antenna;
284 pos++;
285 }
248 286
249 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */ 287 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
250 288
@@ -341,6 +379,11 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
341 pos += 2; 379 pos += 2;
342 } 380 }
343 381
382 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
383 *pos++ = status->chain_signal[chain];
384 *pos++ = chain;
385 }
386
344 if (status->vendor_radiotap_len) { 387 if (status->vendor_radiotap_len) {
345 /* ensure 2 byte alignment for the vendor field as required */ 388 /* ensure 2 byte alignment for the vendor field as required */
346 if ((pos - (u8 *)rthdr) & 1) 389 if ((pos - (u8 *)rthdr) & 1)
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 1b122a79b0d8..08afe74b98f4 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -66,6 +66,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
66 struct cfg80211_bss *cbss; 66 struct cfg80211_bss *cbss;
67 struct ieee80211_bss *bss; 67 struct ieee80211_bss *bss;
68 int clen, srlen; 68 int clen, srlen;
69 enum nl80211_bss_scan_width scan_width;
69 s32 signal = 0; 70 s32 signal = 0;
70 71
71 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) 72 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
@@ -73,8 +74,15 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
73 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) 74 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
74 signal = (rx_status->signal * 100) / local->hw.max_signal; 75 signal = (rx_status->signal * 100) / local->hw.max_signal;
75 76
76 cbss = cfg80211_inform_bss_frame(local->hw.wiphy, channel, 77 scan_width = NL80211_BSS_CHAN_WIDTH_20;
77 mgmt, len, signal, GFP_ATOMIC); 78 if (rx_status->flag & RX_FLAG_5MHZ)
79 scan_width = NL80211_BSS_CHAN_WIDTH_5;
80 if (rx_status->flag & RX_FLAG_10MHZ)
81 scan_width = NL80211_BSS_CHAN_WIDTH_10;
82
83 cbss = cfg80211_inform_bss_width_frame(local->hw.wiphy, channel,
84 scan_width, mgmt, len, signal,
85 GFP_ATOMIC);
78 if (!cbss) 86 if (!cbss)
79 return NULL; 87 return NULL;
80 88
@@ -204,10 +212,29 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
204 ieee80211_rx_bss_put(local, bss); 212 ieee80211_rx_bss_put(local, bss);
205} 213}
206 214
215static void
216ieee80211_prepare_scan_chandef(struct cfg80211_chan_def *chandef,
217 enum nl80211_bss_scan_width scan_width)
218{
219 memset(chandef, 0, sizeof(*chandef));
220 switch (scan_width) {
221 case NL80211_BSS_CHAN_WIDTH_5:
222 chandef->width = NL80211_CHAN_WIDTH_5;
223 break;
224 case NL80211_BSS_CHAN_WIDTH_10:
225 chandef->width = NL80211_CHAN_WIDTH_10;
226 break;
227 default:
228 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
229 break;
230 }
231}
232
207/* return false if no more work */ 233/* return false if no more work */
208static bool ieee80211_prep_hw_scan(struct ieee80211_local *local) 234static bool ieee80211_prep_hw_scan(struct ieee80211_local *local)
209{ 235{
210 struct cfg80211_scan_request *req = local->scan_req; 236 struct cfg80211_scan_request *req = local->scan_req;
237 struct cfg80211_chan_def chandef;
211 enum ieee80211_band band; 238 enum ieee80211_band band;
212 int i, ielen, n_chans; 239 int i, ielen, n_chans;
213 240
@@ -229,11 +256,12 @@ static bool ieee80211_prep_hw_scan(struct ieee80211_local *local)
229 } while (!n_chans); 256 } while (!n_chans);
230 257
231 local->hw_scan_req->n_channels = n_chans; 258 local->hw_scan_req->n_channels = n_chans;
259 ieee80211_prepare_scan_chandef(&chandef, req->scan_width);
232 260
233 ielen = ieee80211_build_preq_ies(local, (u8 *)local->hw_scan_req->ie, 261 ielen = ieee80211_build_preq_ies(local, (u8 *)local->hw_scan_req->ie,
234 local->hw_scan_ies_bufsize, 262 local->hw_scan_ies_bufsize,
235 req->ie, req->ie_len, band, 263 req->ie, req->ie_len, band,
236 req->rates[band], 0); 264 req->rates[band], &chandef);
237 local->hw_scan_req->ie_len = ielen; 265 local->hw_scan_req->ie_len = ielen;
238 local->hw_scan_req->no_cck = req->no_cck; 266 local->hw_scan_req->no_cck = req->no_cck;
239 267
@@ -280,7 +308,7 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted,
280 rcu_assign_pointer(local->scan_sdata, NULL); 308 rcu_assign_pointer(local->scan_sdata, NULL);
281 309
282 local->scanning = 0; 310 local->scanning = 0;
283 local->scan_channel = NULL; 311 local->scan_chandef.chan = NULL;
284 312
285 /* Set power back to normal operating levels. */ 313 /* Set power back to normal operating levels. */
286 ieee80211_hw_config(local, 0); 314 ieee80211_hw_config(local, 0);
@@ -615,11 +643,34 @@ static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
615{ 643{
616 int skip; 644 int skip;
617 struct ieee80211_channel *chan; 645 struct ieee80211_channel *chan;
646 enum nl80211_bss_scan_width oper_scan_width;
618 647
619 skip = 0; 648 skip = 0;
620 chan = local->scan_req->channels[local->scan_channel_idx]; 649 chan = local->scan_req->channels[local->scan_channel_idx];
621 650
622 local->scan_channel = chan; 651 local->scan_chandef.chan = chan;
652 local->scan_chandef.center_freq1 = chan->center_freq;
653 local->scan_chandef.center_freq2 = 0;
654 switch (local->scan_req->scan_width) {
655 case NL80211_BSS_CHAN_WIDTH_5:
656 local->scan_chandef.width = NL80211_CHAN_WIDTH_5;
657 break;
658 case NL80211_BSS_CHAN_WIDTH_10:
659 local->scan_chandef.width = NL80211_CHAN_WIDTH_10;
660 break;
661 case NL80211_BSS_CHAN_WIDTH_20:
662 /* If scanning on oper channel, use whatever channel-type
663 * is currently in use.
664 */
665 oper_scan_width = cfg80211_chandef_to_scan_width(
666 &local->_oper_chandef);
667 if (chan == local->_oper_chandef.chan &&
668 oper_scan_width == local->scan_req->scan_width)
669 local->scan_chandef = local->_oper_chandef;
670 else
671 local->scan_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
672 break;
673 }
623 674
624 if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL)) 675 if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
625 skip = 1; 676 skip = 1;
@@ -659,7 +710,7 @@ static void ieee80211_scan_state_suspend(struct ieee80211_local *local,
659 unsigned long *next_delay) 710 unsigned long *next_delay)
660{ 711{
661 /* switch back to the operating channel */ 712 /* switch back to the operating channel */
662 local->scan_channel = NULL; 713 local->scan_chandef.chan = NULL;
663 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); 714 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
664 715
665 /* disable PS */ 716 /* disable PS */
@@ -801,7 +852,8 @@ int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
801 852
802int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata, 853int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata,
803 const u8 *ssid, u8 ssid_len, 854 const u8 *ssid, u8 ssid_len,
804 struct ieee80211_channel *chan) 855 struct ieee80211_channel *chan,
856 enum nl80211_bss_scan_width scan_width)
805{ 857{
806 struct ieee80211_local *local = sdata->local; 858 struct ieee80211_local *local = sdata->local;
807 int ret = -EBUSY; 859 int ret = -EBUSY;
@@ -851,6 +903,7 @@ int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata,
851 903
852 local->int_scan_req->ssids = &local->scan_ssid; 904 local->int_scan_req->ssids = &local->scan_ssid;
853 local->int_scan_req->n_ssids = 1; 905 local->int_scan_req->n_ssids = 1;
906 local->int_scan_req->scan_width = scan_width;
854 memcpy(local->int_scan_req->ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN); 907 memcpy(local->int_scan_req->ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
855 local->int_scan_req->ssids[0].ssid_len = ssid_len; 908 local->int_scan_req->ssids[0].ssid_len = ssid_len;
856 909
@@ -912,6 +965,7 @@ int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
912{ 965{
913 struct ieee80211_local *local = sdata->local; 966 struct ieee80211_local *local = sdata->local;
914 struct ieee80211_sched_scan_ies sched_scan_ies = {}; 967 struct ieee80211_sched_scan_ies sched_scan_ies = {};
968 struct cfg80211_chan_def chandef;
915 int ret, i, iebufsz; 969 int ret, i, iebufsz;
916 970
917 iebufsz = 2 + IEEE80211_MAX_SSID_LEN + 971 iebufsz = 2 + IEEE80211_MAX_SSID_LEN +
@@ -939,10 +993,12 @@ int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
939 goto out_free; 993 goto out_free;
940 } 994 }
941 995
996 ieee80211_prepare_scan_chandef(&chandef, req->scan_width);
997
942 sched_scan_ies.len[i] = 998 sched_scan_ies.len[i] =
943 ieee80211_build_preq_ies(local, sched_scan_ies.ie[i], 999 ieee80211_build_preq_ies(local, sched_scan_ies.ie[i],
944 iebufsz, req->ie, req->ie_len, 1000 iebufsz, req->ie, req->ie_len,
945 i, (u32) -1, 0); 1001 i, (u32) -1, &chandef);
946 } 1002 }
947 1003
948 ret = drv_sched_scan_start(local, sdata, req, &sched_scan_ies); 1004 ret = drv_sched_scan_start(local, sdata, req, &sched_scan_ies);
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index 43439203f4e4..6ad4c14385ef 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -252,9 +252,10 @@ static int ieee80211_tx_radiotap_len(struct ieee80211_tx_info *info)
252 return len; 252 return len;
253} 253}
254 254
255static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band 255static void
256 *sband, struct sk_buff *skb, 256ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band *sband,
257 int retry_count, int rtap_len) 257 struct sk_buff *skb, int retry_count,
258 int rtap_len, int shift)
258{ 259{
259 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 260 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
260 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 261 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -280,8 +281,11 @@ static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band
280 /* IEEE80211_RADIOTAP_RATE */ 281 /* IEEE80211_RADIOTAP_RATE */
281 if (info->status.rates[0].idx >= 0 && 282 if (info->status.rates[0].idx >= 0 &&
282 !(info->status.rates[0].flags & IEEE80211_TX_RC_MCS)) { 283 !(info->status.rates[0].flags & IEEE80211_TX_RC_MCS)) {
284 u16 rate;
285
283 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE); 286 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
284 *pos = sband->bitrates[info->status.rates[0].idx].bitrate / 5; 287 rate = sband->bitrates[info->status.rates[0].idx].bitrate;
288 *pos = DIV_ROUND_UP(rate, 5 * (1 << shift));
285 /* padding for tx flags */ 289 /* padding for tx flags */
286 pos += 2; 290 pos += 2;
287 } 291 }
@@ -424,6 +428,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
424 bool acked; 428 bool acked;
425 struct ieee80211_bar *bar; 429 struct ieee80211_bar *bar;
426 int rtap_len; 430 int rtap_len;
431 int shift = 0;
427 432
428 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { 433 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
429 if ((info->flags & IEEE80211_TX_CTL_AMPDU) && 434 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
@@ -458,6 +463,8 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
458 if (!ether_addr_equal(hdr->addr2, sta->sdata->vif.addr)) 463 if (!ether_addr_equal(hdr->addr2, sta->sdata->vif.addr))
459 continue; 464 continue;
460 465
466 shift = ieee80211_vif_get_shift(&sta->sdata->vif);
467
461 if (info->flags & IEEE80211_TX_STATUS_EOSP) 468 if (info->flags & IEEE80211_TX_STATUS_EOSP)
462 clear_sta_flag(sta, WLAN_STA_SP); 469 clear_sta_flag(sta, WLAN_STA_SP);
463 470
@@ -624,7 +631,8 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
624 dev_kfree_skb(skb); 631 dev_kfree_skb(skb);
625 return; 632 return;
626 } 633 }
627 ieee80211_add_tx_radiotap_header(sband, skb, retry_count, rtap_len); 634 ieee80211_add_tx_radiotap_header(sband, skb, retry_count, rtap_len,
635 shift);
628 636
629 /* XXX: is this sufficient for BPF? */ 637 /* XXX: is this sufficient for BPF? */
630 skb_set_mac_header(skb, 0); 638 skb_set_mac_header(skb, 0);
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 4105d0ca963e..be4d3caf4879 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -40,12 +40,22 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
40 struct sk_buff *skb, int group_addr, 40 struct sk_buff *skb, int group_addr,
41 int next_frag_len) 41 int next_frag_len)
42{ 42{
43 int rate, mrate, erp, dur, i; 43 int rate, mrate, erp, dur, i, shift = 0;
44 struct ieee80211_rate *txrate; 44 struct ieee80211_rate *txrate;
45 struct ieee80211_local *local = tx->local; 45 struct ieee80211_local *local = tx->local;
46 struct ieee80211_supported_band *sband; 46 struct ieee80211_supported_band *sband;
47 struct ieee80211_hdr *hdr; 47 struct ieee80211_hdr *hdr;
48 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 48 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
49 struct ieee80211_chanctx_conf *chanctx_conf;
50 u32 rate_flags = 0;
51
52 rcu_read_lock();
53 chanctx_conf = rcu_dereference(tx->sdata->vif.chanctx_conf);
54 if (chanctx_conf) {
55 shift = ieee80211_chandef_get_shift(&chanctx_conf->def);
56 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
57 }
58 rcu_read_unlock();
49 59
50 /* assume HW handles this */ 60 /* assume HW handles this */
51 if (tx->rate.flags & IEEE80211_TX_RC_MCS) 61 if (tx->rate.flags & IEEE80211_TX_RC_MCS)
@@ -122,8 +132,11 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
122 if (r->bitrate > txrate->bitrate) 132 if (r->bitrate > txrate->bitrate)
123 break; 133 break;
124 134
135 if ((rate_flags & r->flags) != rate_flags)
136 continue;
137
125 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i)) 138 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
126 rate = r->bitrate; 139 rate = DIV_ROUND_UP(r->bitrate, 1 << shift);
127 140
128 switch (sband->band) { 141 switch (sband->band) {
129 case IEEE80211_BAND_2GHZ: { 142 case IEEE80211_BAND_2GHZ: {
@@ -150,7 +163,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
150 if (rate == -1) { 163 if (rate == -1) {
151 /* No matching basic rate found; use highest suitable mandatory 164 /* No matching basic rate found; use highest suitable mandatory
152 * PHY rate */ 165 * PHY rate */
153 rate = mrate; 166 rate = DIV_ROUND_UP(mrate, 1 << shift);
154 } 167 }
155 168
156 /* Don't calculate ACKs for QoS Frames with NoAck Policy set */ 169 /* Don't calculate ACKs for QoS Frames with NoAck Policy set */
@@ -162,7 +175,8 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
162 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up 175 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
163 * to closest integer */ 176 * to closest integer */
164 dur = ieee80211_frame_duration(sband->band, 10, rate, erp, 177 dur = ieee80211_frame_duration(sband->band, 10, rate, erp,
165 tx->sdata->vif.bss_conf.use_short_preamble); 178 tx->sdata->vif.bss_conf.use_short_preamble,
179 shift);
166 180
167 if (next_frag_len) { 181 if (next_frag_len) {
168 /* Frame is fragmented: duration increases with time needed to 182 /* Frame is fragmented: duration increases with time needed to
@@ -171,7 +185,8 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
171 /* next fragment */ 185 /* next fragment */
172 dur += ieee80211_frame_duration(sband->band, next_frag_len, 186 dur += ieee80211_frame_duration(sband->band, next_frag_len,
173 txrate->bitrate, erp, 187 txrate->bitrate, erp,
174 tx->sdata->vif.bss_conf.use_short_preamble); 188 tx->sdata->vif.bss_conf.use_short_preamble,
189 shift);
175 } 190 }
176 191
177 return cpu_to_le16(dur); 192 return cpu_to_le16(dur);
@@ -1257,6 +1272,10 @@ static bool __ieee80211_tx(struct ieee80211_local *local,
1257 1272
1258 switch (sdata->vif.type) { 1273 switch (sdata->vif.type) {
1259 case NL80211_IFTYPE_MONITOR: 1274 case NL80211_IFTYPE_MONITOR:
1275 if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) {
1276 vif = &sdata->vif;
1277 break;
1278 }
1260 sdata = rcu_dereference(local->monitor_sdata); 1279 sdata = rcu_dereference(local->monitor_sdata);
1261 if (sdata) { 1280 if (sdata) {
1262 vif = &sdata->vif; 1281 vif = &sdata->vif;
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 22654452a561..d23c5a705a68 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -107,7 +107,8 @@ void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
107} 107}
108 108
109int ieee80211_frame_duration(enum ieee80211_band band, size_t len, 109int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
110 int rate, int erp, int short_preamble) 110 int rate, int erp, int short_preamble,
111 int shift)
111{ 112{
112 int dur; 113 int dur;
113 114
@@ -118,6 +119,9 @@ int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
118 * 119 *
119 * rate is in 100 kbps, so divident is multiplied by 10 in the 120 * rate is in 100 kbps, so divident is multiplied by 10 in the
120 * DIV_ROUND_UP() operations. 121 * DIV_ROUND_UP() operations.
122 *
123 * shift may be 2 for 5 MHz channels or 1 for 10 MHz channels, and
124 * is assumed to be 0 otherwise.
121 */ 125 */
122 126
123 if (band == IEEE80211_BAND_5GHZ || erp) { 127 if (band == IEEE80211_BAND_5GHZ || erp) {
@@ -130,13 +134,23 @@ int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
130 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext 134 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
131 * 135 *
132 * T_SYM = 4 usec 136 * T_SYM = 4 usec
133 * 802.11a - 17.5.2: aSIFSTime = 16 usec 137 * 802.11a - 18.5.2: aSIFSTime = 16 usec
134 * 802.11g - 19.8.4: aSIFSTime = 10 usec + 138 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
135 * signal ext = 6 usec 139 * signal ext = 6 usec
136 */ 140 */
137 dur = 16; /* SIFS + signal ext */ 141 dur = 16; /* SIFS + signal ext */
138 dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */ 142 dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */
139 dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */ 143 dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */
144
145 /* IEEE 802.11-2012 18.3.2.4: all values above are:
146 * * times 4 for 5 MHz
147 * * times 2 for 10 MHz
148 */
149 dur *= 1 << shift;
150
151 /* rates should already consider the channel bandwidth,
152 * don't apply divisor again.
153 */
140 dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, 154 dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
141 4 * rate); /* T_SYM x N_SYM */ 155 4 * rate); /* T_SYM x N_SYM */
142 } else { 156 } else {
@@ -168,7 +182,7 @@ __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
168{ 182{
169 struct ieee80211_sub_if_data *sdata; 183 struct ieee80211_sub_if_data *sdata;
170 u16 dur; 184 u16 dur;
171 int erp; 185 int erp, shift = 0;
172 bool short_preamble = false; 186 bool short_preamble = false;
173 187
174 erp = 0; 188 erp = 0;
@@ -177,10 +191,11 @@ __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
177 short_preamble = sdata->vif.bss_conf.use_short_preamble; 191 short_preamble = sdata->vif.bss_conf.use_short_preamble;
178 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 192 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
179 erp = rate->flags & IEEE80211_RATE_ERP_G; 193 erp = rate->flags & IEEE80211_RATE_ERP_G;
194 shift = ieee80211_vif_get_shift(vif);
180 } 195 }
181 196
182 dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp, 197 dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
183 short_preamble); 198 short_preamble, shift);
184 199
185 return cpu_to_le16(dur); 200 return cpu_to_le16(dur);
186} 201}
@@ -194,7 +209,7 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
194 struct ieee80211_rate *rate; 209 struct ieee80211_rate *rate;
195 struct ieee80211_sub_if_data *sdata; 210 struct ieee80211_sub_if_data *sdata;
196 bool short_preamble; 211 bool short_preamble;
197 int erp; 212 int erp, shift = 0, bitrate;
198 u16 dur; 213 u16 dur;
199 struct ieee80211_supported_band *sband; 214 struct ieee80211_supported_band *sband;
200 215
@@ -210,17 +225,20 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
210 short_preamble = sdata->vif.bss_conf.use_short_preamble; 225 short_preamble = sdata->vif.bss_conf.use_short_preamble;
211 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 226 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
212 erp = rate->flags & IEEE80211_RATE_ERP_G; 227 erp = rate->flags & IEEE80211_RATE_ERP_G;
228 shift = ieee80211_vif_get_shift(vif);
213 } 229 }
214 230
231 bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
232
215 /* CTS duration */ 233 /* CTS duration */
216 dur = ieee80211_frame_duration(sband->band, 10, rate->bitrate, 234 dur = ieee80211_frame_duration(sband->band, 10, bitrate,
217 erp, short_preamble); 235 erp, short_preamble, shift);
218 /* Data frame duration */ 236 /* Data frame duration */
219 dur += ieee80211_frame_duration(sband->band, frame_len, rate->bitrate, 237 dur += ieee80211_frame_duration(sband->band, frame_len, bitrate,
220 erp, short_preamble); 238 erp, short_preamble, shift);
221 /* ACK duration */ 239 /* ACK duration */
222 dur += ieee80211_frame_duration(sband->band, 10, rate->bitrate, 240 dur += ieee80211_frame_duration(sband->band, 10, bitrate,
223 erp, short_preamble); 241 erp, short_preamble, shift);
224 242
225 return cpu_to_le16(dur); 243 return cpu_to_le16(dur);
226} 244}
@@ -235,7 +253,7 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
235 struct ieee80211_rate *rate; 253 struct ieee80211_rate *rate;
236 struct ieee80211_sub_if_data *sdata; 254 struct ieee80211_sub_if_data *sdata;
237 bool short_preamble; 255 bool short_preamble;
238 int erp; 256 int erp, shift = 0, bitrate;
239 u16 dur; 257 u16 dur;
240 struct ieee80211_supported_band *sband; 258 struct ieee80211_supported_band *sband;
241 259
@@ -250,15 +268,18 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
250 short_preamble = sdata->vif.bss_conf.use_short_preamble; 268 short_preamble = sdata->vif.bss_conf.use_short_preamble;
251 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 269 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
252 erp = rate->flags & IEEE80211_RATE_ERP_G; 270 erp = rate->flags & IEEE80211_RATE_ERP_G;
271 shift = ieee80211_vif_get_shift(vif);
253 } 272 }
254 273
274 bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
275
255 /* Data frame duration */ 276 /* Data frame duration */
256 dur = ieee80211_frame_duration(sband->band, frame_len, rate->bitrate, 277 dur = ieee80211_frame_duration(sband->band, frame_len, bitrate,
257 erp, short_preamble); 278 erp, short_preamble, shift);
258 if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { 279 if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
259 /* ACK duration */ 280 /* ACK duration */
260 dur += ieee80211_frame_duration(sband->band, 10, rate->bitrate, 281 dur += ieee80211_frame_duration(sband->band, 10, bitrate,
261 erp, short_preamble); 282 erp, short_preamble, shift);
262 } 283 }
263 284
264 return cpu_to_le16(dur); 285 return cpu_to_le16(dur);
@@ -1052,32 +1073,6 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
1052 } 1073 }
1053} 1074}
1054 1075
1055void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
1056 const size_t supp_rates_len,
1057 const u8 *supp_rates)
1058{
1059 struct ieee80211_chanctx_conf *chanctx_conf;
1060 int i, have_higher_than_11mbit = 0;
1061
1062 /* cf. IEEE 802.11 9.2.12 */
1063 for (i = 0; i < supp_rates_len; i++)
1064 if ((supp_rates[i] & 0x7f) * 5 > 110)
1065 have_higher_than_11mbit = 1;
1066
1067 rcu_read_lock();
1068 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1069
1070 if (chanctx_conf &&
1071 chanctx_conf->def.chan->band == IEEE80211_BAND_2GHZ &&
1072 have_higher_than_11mbit)
1073 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1074 else
1075 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1076 rcu_read_unlock();
1077
1078 ieee80211_set_wmm_default(sdata, true);
1079}
1080
1081void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 1076void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1082 u16 transaction, u16 auth_alg, u16 status, 1077 u16 transaction, u16 auth_alg, u16 status,
1083 const u8 *extra, size_t extra_len, const u8 *da, 1078 const u8 *extra, size_t extra_len, const u8 *da,
@@ -1162,7 +1157,7 @@ void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
1162int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, 1157int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1163 size_t buffer_len, const u8 *ie, size_t ie_len, 1158 size_t buffer_len, const u8 *ie, size_t ie_len,
1164 enum ieee80211_band band, u32 rate_mask, 1159 enum ieee80211_band band, u32 rate_mask,
1165 u8 channel) 1160 struct cfg80211_chan_def *chandef)
1166{ 1161{
1167 struct ieee80211_supported_band *sband; 1162 struct ieee80211_supported_band *sband;
1168 u8 *pos = buffer, *end = buffer + buffer_len; 1163 u8 *pos = buffer, *end = buffer + buffer_len;
@@ -1171,16 +1166,26 @@ int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1171 u8 rates[32]; 1166 u8 rates[32];
1172 int num_rates; 1167 int num_rates;
1173 int ext_rates_len; 1168 int ext_rates_len;
1169 int shift;
1170 u32 rate_flags;
1174 1171
1175 sband = local->hw.wiphy->bands[band]; 1172 sband = local->hw.wiphy->bands[band];
1176 if (WARN_ON_ONCE(!sband)) 1173 if (WARN_ON_ONCE(!sband))
1177 return 0; 1174 return 0;
1178 1175
1176 rate_flags = ieee80211_chandef_rate_flags(chandef);
1177 shift = ieee80211_chandef_get_shift(chandef);
1178
1179 num_rates = 0; 1179 num_rates = 0;
1180 for (i = 0; i < sband->n_bitrates; i++) { 1180 for (i = 0; i < sband->n_bitrates; i++) {
1181 if ((BIT(i) & rate_mask) == 0) 1181 if ((BIT(i) & rate_mask) == 0)
1182 continue; /* skip rate */ 1182 continue; /* skip rate */
1183 rates[num_rates++] = (u8) (sband->bitrates[i].bitrate / 5); 1183 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
1184 continue;
1185
1186 rates[num_rates++] =
1187 (u8) DIV_ROUND_UP(sband->bitrates[i].bitrate,
1188 (1 << shift) * 5);
1184 } 1189 }
1185 1190
1186 supp_rates_len = min_t(int, num_rates, 8); 1191 supp_rates_len = min_t(int, num_rates, 8);
@@ -1220,12 +1225,13 @@ int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1220 pos += ext_rates_len; 1225 pos += ext_rates_len;
1221 } 1226 }
1222 1227
1223 if (channel && sband->band == IEEE80211_BAND_2GHZ) { 1228 if (chandef->chan && sband->band == IEEE80211_BAND_2GHZ) {
1224 if (end - pos < 3) 1229 if (end - pos < 3)
1225 goto out_err; 1230 goto out_err;
1226 *pos++ = WLAN_EID_DS_PARAMS; 1231 *pos++ = WLAN_EID_DS_PARAMS;
1227 *pos++ = 1; 1232 *pos++ = 1;
1228 *pos++ = channel; 1233 *pos++ = ieee80211_frequency_to_channel(
1234 chandef->chan->center_freq);
1229 } 1235 }
1230 1236
1231 /* insert custom IEs that go before HT */ 1237 /* insert custom IEs that go before HT */
@@ -1290,9 +1296,9 @@ struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
1290 bool directed) 1296 bool directed)
1291{ 1297{
1292 struct ieee80211_local *local = sdata->local; 1298 struct ieee80211_local *local = sdata->local;
1299 struct cfg80211_chan_def chandef;
1293 struct sk_buff *skb; 1300 struct sk_buff *skb;
1294 struct ieee80211_mgmt *mgmt; 1301 struct ieee80211_mgmt *mgmt;
1295 u8 chan_no;
1296 int ies_len; 1302 int ies_len;
1297 1303
1298 /* 1304 /*
@@ -1300,10 +1306,11 @@ struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
1300 * in order to maximize the chance that we get a response. Some 1306 * in order to maximize the chance that we get a response. Some
1301 * badly-behaved APs don't respond when this parameter is included. 1307 * badly-behaved APs don't respond when this parameter is included.
1302 */ 1308 */
1309 chandef.width = sdata->vif.bss_conf.chandef.width;
1303 if (directed) 1310 if (directed)
1304 chan_no = 0; 1311 chandef.chan = NULL;
1305 else 1312 else
1306 chan_no = ieee80211_frequency_to_channel(chan->center_freq); 1313 chandef.chan = chan;
1307 1314
1308 skb = ieee80211_probereq_get(&local->hw, &sdata->vif, 1315 skb = ieee80211_probereq_get(&local->hw, &sdata->vif,
1309 ssid, ssid_len, 100 + ie_len); 1316 ssid, ssid_len, 100 + ie_len);
@@ -1313,7 +1320,7 @@ struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
1313 ies_len = ieee80211_build_preq_ies(local, skb_tail_pointer(skb), 1320 ies_len = ieee80211_build_preq_ies(local, skb_tail_pointer(skb),
1314 skb_tailroom(skb), 1321 skb_tailroom(skb),
1315 ie, ie_len, chan->band, 1322 ie, ie_len, chan->band,
1316 ratemask, chan_no); 1323 ratemask, &chandef);
1317 skb_put(skb, ies_len); 1324 skb_put(skb, ies_len);
1318 1325
1319 if (dst) { 1326 if (dst) {
@@ -1347,16 +1354,19 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1347 } 1354 }
1348} 1355}
1349 1356
1350u32 ieee80211_sta_get_rates(struct ieee80211_local *local, 1357u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
1351 struct ieee802_11_elems *elems, 1358 struct ieee802_11_elems *elems,
1352 enum ieee80211_band band, u32 *basic_rates) 1359 enum ieee80211_band band, u32 *basic_rates)
1353{ 1360{
1354 struct ieee80211_supported_band *sband; 1361 struct ieee80211_supported_band *sband;
1355 struct ieee80211_rate *bitrates; 1362 struct ieee80211_rate *bitrates;
1356 size_t num_rates; 1363 size_t num_rates;
1357 u32 supp_rates; 1364 u32 supp_rates, rate_flags;
1358 int i, j; 1365 int i, j, shift;
1359 sband = local->hw.wiphy->bands[band]; 1366 sband = sdata->local->hw.wiphy->bands[band];
1367
1368 rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
1369 shift = ieee80211_vif_get_shift(&sdata->vif);
1360 1370
1361 if (WARN_ON(!sband)) 1371 if (WARN_ON(!sband))
1362 return 1; 1372 return 1;
@@ -1381,7 +1391,15 @@ u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
1381 continue; 1391 continue;
1382 1392
1383 for (j = 0; j < num_rates; j++) { 1393 for (j = 0; j < num_rates; j++) {
1384 if (bitrates[j].bitrate == own_rate) { 1394 int brate;
1395 if ((rate_flags & sband->bitrates[j].flags)
1396 != rate_flags)
1397 continue;
1398
1399 brate = DIV_ROUND_UP(sband->bitrates[j].bitrate,
1400 1 << shift);
1401
1402 if (brate == own_rate) {
1385 supp_rates |= BIT(j); 1403 supp_rates |= BIT(j);
1386 if (basic_rates && is_basic) 1404 if (basic_rates && is_basic)
1387 *basic_rates |= BIT(j); 1405 *basic_rates |= BIT(j);
@@ -2004,18 +2022,56 @@ void ieee80211_ht_oper_to_chandef(struct ieee80211_channel *control_chan,
2004 cfg80211_chandef_create(chandef, control_chan, channel_type); 2022 cfg80211_chandef_create(chandef, control_chan, channel_type);
2005} 2023}
2006 2024
2025int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef,
2026 const struct ieee80211_supported_band *sband,
2027 const u8 *srates, int srates_len, u32 *rates)
2028{
2029 u32 rate_flags = ieee80211_chandef_rate_flags(chandef);
2030 int shift = ieee80211_chandef_get_shift(chandef);
2031 struct ieee80211_rate *br;
2032 int brate, rate, i, j, count = 0;
2033
2034 *rates = 0;
2035
2036 for (i = 0; i < srates_len; i++) {
2037 rate = srates[i] & 0x7f;
2038
2039 for (j = 0; j < sband->n_bitrates; j++) {
2040 br = &sband->bitrates[j];
2041 if ((rate_flags & br->flags) != rate_flags)
2042 continue;
2043
2044 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
2045 if (brate == rate) {
2046 *rates |= BIT(j);
2047 count++;
2048 break;
2049 }
2050 }
2051 }
2052 return count;
2053}
2054
2007int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata, 2055int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
2008 struct sk_buff *skb, bool need_basic, 2056 struct sk_buff *skb, bool need_basic,
2009 enum ieee80211_band band) 2057 enum ieee80211_band band)
2010{ 2058{
2011 struct ieee80211_local *local = sdata->local; 2059 struct ieee80211_local *local = sdata->local;
2012 struct ieee80211_supported_band *sband; 2060 struct ieee80211_supported_band *sband;
2013 int rate; 2061 int rate, shift;
2014 u8 i, rates, *pos; 2062 u8 i, rates, *pos;
2015 u32 basic_rates = sdata->vif.bss_conf.basic_rates; 2063 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2064 u32 rate_flags;
2016 2065
2066 shift = ieee80211_vif_get_shift(&sdata->vif);
2067 rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
2017 sband = local->hw.wiphy->bands[band]; 2068 sband = local->hw.wiphy->bands[band];
2018 rates = sband->n_bitrates; 2069 rates = 0;
2070 for (i = 0; i < sband->n_bitrates; i++) {
2071 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
2072 continue;
2073 rates++;
2074 }
2019 if (rates > 8) 2075 if (rates > 8)
2020 rates = 8; 2076 rates = 8;
2021 2077
@@ -2027,10 +2083,15 @@ int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
2027 *pos++ = rates; 2083 *pos++ = rates;
2028 for (i = 0; i < rates; i++) { 2084 for (i = 0; i < rates; i++) {
2029 u8 basic = 0; 2085 u8 basic = 0;
2086 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
2087 continue;
2088
2030 if (need_basic && basic_rates & BIT(i)) 2089 if (need_basic && basic_rates & BIT(i))
2031 basic = 0x80; 2090 basic = 0x80;
2032 rate = sband->bitrates[i].bitrate; 2091 rate = sband->bitrates[i].bitrate;
2033 *pos++ = basic | (u8) (rate / 5); 2092 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
2093 5 * (1 << shift));
2094 *pos++ = basic | (u8) rate;
2034 } 2095 }
2035 2096
2036 return 0; 2097 return 0;
@@ -2042,12 +2103,22 @@ int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
2042{ 2103{
2043 struct ieee80211_local *local = sdata->local; 2104 struct ieee80211_local *local = sdata->local;
2044 struct ieee80211_supported_band *sband; 2105 struct ieee80211_supported_band *sband;
2045 int rate; 2106 int rate, skip, shift;
2046 u8 i, exrates, *pos; 2107 u8 i, exrates, *pos;
2047 u32 basic_rates = sdata->vif.bss_conf.basic_rates; 2108 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2109 u32 rate_flags;
2110
2111 rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
2112 shift = ieee80211_vif_get_shift(&sdata->vif);
2048 2113
2049 sband = local->hw.wiphy->bands[band]; 2114 sband = local->hw.wiphy->bands[band];
2050 exrates = sband->n_bitrates; 2115 exrates = 0;
2116 for (i = 0; i < sband->n_bitrates; i++) {
2117 if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
2118 continue;
2119 exrates++;
2120 }
2121
2051 if (exrates > 8) 2122 if (exrates > 8)
2052 exrates -= 8; 2123 exrates -= 8;
2053 else 2124 else
@@ -2060,12 +2131,19 @@ int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
2060 pos = skb_put(skb, exrates + 2); 2131 pos = skb_put(skb, exrates + 2);
2061 *pos++ = WLAN_EID_EXT_SUPP_RATES; 2132 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2062 *pos++ = exrates; 2133 *pos++ = exrates;
2134 skip = 0;
2063 for (i = 8; i < sband->n_bitrates; i++) { 2135 for (i = 8; i < sband->n_bitrates; i++) {
2064 u8 basic = 0; 2136 u8 basic = 0;
2137 if ((rate_flags & sband->bitrates[i].flags)
2138 != rate_flags)
2139 continue;
2140 if (skip++ < 8)
2141 continue;
2065 if (need_basic && basic_rates & BIT(i)) 2142 if (need_basic && basic_rates & BIT(i))
2066 basic = 0x80; 2143 basic = 0x80;
2067 rate = sband->bitrates[i].bitrate; 2144 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
2068 *pos++ = basic | (u8) (rate / 5); 2145 5 * (1 << shift));
2146 *pos++ = basic | (u8) rate;
2069 } 2147 }
2070 } 2148 }
2071 return 0; 2149 return 0;
@@ -2149,9 +2227,17 @@ u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
2149 ri.flags |= RATE_INFO_FLAGS_SHORT_GI; 2227 ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
2150 } else { 2228 } else {
2151 struct ieee80211_supported_band *sband; 2229 struct ieee80211_supported_band *sband;
2230 int shift = 0;
2231 int bitrate;
2232
2233 if (status->flag & RX_FLAG_10MHZ)
2234 shift = 1;
2235 if (status->flag & RX_FLAG_5MHZ)
2236 shift = 2;
2152 2237
2153 sband = local->hw.wiphy->bands[status->band]; 2238 sband = local->hw.wiphy->bands[status->band];
2154 ri.legacy = sband->bitrates[status->rate_idx].bitrate; 2239 bitrate = sband->bitrates[status->rate_idx].bitrate;
2240 ri.legacy = DIV_ROUND_UP(bitrate, (1 << shift));
2155 } 2241 }
2156 2242
2157 rate = cfg80211_calculate_bitrate(&ri); 2243 rate = cfg80211_calculate_bitrate(&ri);