Skip to content

Commit 2103dec

Browse files
Simon Wunderlichjmberg-intel
authored andcommitted
mac80211: select and adjust bitrates according to channel mode
The various components accessing the bitrates table must use consider the used channel bandwidth to select only available rates or calculate the bitrate correctly. There are some rates in reduced bandwidth modes which can't be represented as multiples of 500kbps, like 2.25 MBit/s in 5 MHz mode. The standard suggests to round up to the next multiple of 500kbps, just do that in mac80211 as well. Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de> Signed-off-by: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de> [make rate unsigned in ieee80211_add_tx_radiotap_header(), squash fix] Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
1 parent a5e7069 commit 2103dec

12 files changed

Lines changed: 352 additions & 159 deletions

File tree

‎net/mac80211/cfg.c‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,13 @@ void sta_set_rate_info_tx(struct sta_info *sta,
395395
rinfo->nss = ieee80211_rate_get_vht_nss(rate);
396396
} else {
397397
struct ieee80211_supported_band *sband;
398+
int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
399+
u16 brate;
400+
398401
sband = sta->local->hw.wiphy->bands[
399402
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);
401405
}
402406
if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
403407
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)
422426
rinfo->mcs = sta->last_rx_rate_idx;
423427
} else {
424428
struct ieee80211_supported_band *sband;
429+
int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
430+
u16 brate;
425431

426432
sband = sta->local->hw.wiphy->bands[
427433
ieee80211_get_sdata_band(sta->sdata)];
428-
rinfo->legacy =
429-
sband->bitrates[sta->last_rx_rate_idx].bitrate;
434+
brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
435+
rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
430436
}
431437

432438
if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
@@ -1190,8 +1196,6 @@ static int sta_apply_parameters(struct ieee80211_local *local,
11901196
struct station_parameters *params)
11911197
{
11921198
int ret = 0;
1193-
u32 rates;
1194-
int i, j;
11951199
struct ieee80211_supported_band *sband;
11961200
struct ieee80211_sub_if_data *sdata = sta->sdata;
11971201
enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
@@ -1284,16 +1288,10 @@ static int sta_apply_parameters(struct ieee80211_local *local,
12841288
sta->listen_interval = params->listen_interval;
12851289

12861290
if (params->supported_rates) {
1287-
rates = 0;
1288-
1289-
for (i = 0; i < params->supported_rates_len; i++) {
1290-
int rate = (params->supported_rates[i] & 0x7f) * 5;
1291-
for (j = 0; j < sband->n_bitrates; j++) {
1292-
if (sband->bitrates[j].bitrate == rate)
1293-
rates |= BIT(j);
1294-
}
1295-
}
1296-
sta->sta.supp_rates[band] = rates;
1291+
ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1292+
sband, params->supported_rates,
1293+
params->supported_rates_len,
1294+
&sta->sta.supp_rates[band]);
12971295
}
12981296

12991297
if (params->ht_capa)
@@ -1956,18 +1954,11 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
19561954
}
19571955

19581956
if (params->basic_rates) {
1959-
int i, j;
1960-
u32 rates = 0;
1961-
struct ieee80211_supported_band *sband = wiphy->bands[band];
1962-
1963-
for (i = 0; i < params->basic_rates_len; i++) {
1964-
int rate = (params->basic_rates[i] & 0x7f) * 5;
1965-
for (j = 0; j < sband->n_bitrates; j++) {
1966-
if (sband->bitrates[j].bitrate == rate)
1967-
rates |= BIT(j);
1968-
}
1969-
}
1970-
sdata->vif.bss_conf.basic_rates = rates;
1957+
ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1958+
wiphy->bands[band],
1959+
params->basic_rates,
1960+
params->basic_rates_len,
1961+
&sdata->vif.bss_conf.basic_rates);
19711962
changed |= BSS_CHANGED_BASIC_RATES;
19721963
}
19731964

‎net/mac80211/ibss.c‎

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
4343
{
4444
struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
4545
struct ieee80211_local *local = sdata->local;
46-
int rates, i;
46+
int rates_n = 0, i, ri;
4747
struct ieee80211_mgmt *mgmt;
4848
u8 *pos;
4949
struct ieee80211_supported_band *sband;
5050
struct cfg80211_bss *bss;
51-
u32 bss_change;
51+
u32 bss_change, rate_flags, rates = 0, rates_added = 0;
5252
u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
5353
struct cfg80211_chan_def chandef;
5454
struct beacon_data *presp;
5555
int frame_len;
56+
int shift;
5657

5758
sdata_assert_lock(sdata);
5859

@@ -99,6 +100,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
99100
memcpy(ifibss->bssid, bssid, ETH_ALEN);
100101

101102
sband = local->hw.wiphy->bands[chan->band];
103+
shift = ieee80211_vif_get_shift(&sdata->vif);
102104

103105
/* Build IBSS probe response */
104106
frame_len = sizeof(struct ieee80211_hdr_3addr) +
@@ -134,15 +136,29 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
134136
memcpy(pos, ifibss->ssid, ifibss->ssid_len);
135137
pos += ifibss->ssid_len;
136138

137-
rates = min_t(int, 8, sband->n_bitrates);
139+
rate_flags = ieee80211_chandef_rate_flags(&chandef);
140+
for (i = 0; i < sband->n_bitrates; i++) {
141+
if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
142+
continue;
143+
144+
rates |= BIT(i);
145+
rates_n++;
146+
}
147+
138148
*pos++ = WLAN_EID_SUPP_RATES;
139-
*pos++ = rates;
140-
for (i = 0; i < rates; i++) {
141-
int rate = sband->bitrates[i].bitrate;
149+
*pos++ = min_t(int, 8, rates_n);
150+
for (ri = 0; ri < sband->n_bitrates; ri++) {
151+
int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate,
152+
5 * (1 << shift));
142153
u8 basic = 0;
143-
if (basic_rates & BIT(i))
154+
if (!(rates & BIT(ri)))
155+
continue;
156+
157+
if (basic_rates & BIT(ri))
144158
basic = 0x80;
145-
*pos++ = basic | (u8) (rate / 5);
159+
*pos++ = basic | (u8) rate;
160+
if (++rates_added == 8)
161+
break;
146162
}
147163

148164
if (sband->band == IEEE80211_BAND_2GHZ) {
@@ -157,15 +173,20 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
157173
*pos++ = 0;
158174
*pos++ = 0;
159175

160-
if (sband->n_bitrates > 8) {
176+
/* put the remaining rates in WLAN_EID_EXT_SUPP_RATES */
177+
if (rates_n > 8) {
161178
*pos++ = WLAN_EID_EXT_SUPP_RATES;
162-
*pos++ = sband->n_bitrates - 8;
163-
for (i = 8; i < sband->n_bitrates; i++) {
164-
int rate = sband->bitrates[i].bitrate;
179+
*pos++ = rates_n - 8;
180+
for (; ri < sband->n_bitrates; ri++) {
181+
int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate,
182+
5 * (1 << shift));
165183
u8 basic = 0;
166-
if (basic_rates & BIT(i))
184+
if (!(rates & BIT(ri)))
185+
continue;
186+
187+
if (basic_rates & BIT(ri))
167188
basic = 0x80;
168-
*pos++ = basic | (u8) (rate / 5);
189+
*pos++ = basic | (u8) rate;
169190
}
170191
}
171192

@@ -244,7 +265,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
244265
sdata->vif.bss_conf.ibss_creator = creator;
245266
ieee80211_bss_info_change_notify(sdata, bss_change);
246267

247-
ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates);
268+
ieee80211_sta_def_wmm_params(sdata, rates, supp_rates);
248269

249270
ifibss->state = IEEE80211_IBSS_MLME_JOINED;
250271
mod_timer(&ifibss->timer,
@@ -268,22 +289,33 @@ static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
268289
u16 beacon_int = cbss->beacon_interval;
269290
const struct cfg80211_bss_ies *ies;
270291
u64 tsf;
292+
u32 rate_flags;
293+
int shift;
271294

272295
sdata_assert_lock(sdata);
273296

274297
if (beacon_int < 10)
275298
beacon_int = 10;
276299

277300
sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
301+
rate_flags = ieee80211_chandef_rate_flags(&sdata->u.ibss.chandef);
302+
shift = ieee80211_vif_get_shift(&sdata->vif);
278303

279304
basic_rates = 0;
280305

281306
for (i = 0; i < bss->supp_rates_len; i++) {
282-
int rate = (bss->supp_rates[i] & 0x7f) * 5;
307+
int rate = bss->supp_rates[i] & 0x7f;
283308
bool is_basic = !!(bss->supp_rates[i] & 0x80);
284309

285310
for (j = 0; j < sband->n_bitrates; j++) {
286-
if (sband->bitrates[j].bitrate == rate) {
311+
int brate;
312+
if ((rate_flags & sband->bitrates[j].flags)
313+
!= rate_flags)
314+
continue;
315+
316+
brate = DIV_ROUND_UP(sband->bitrates[j].bitrate,
317+
5 * (1 << shift));
318+
if (brate == rate) {
287319
if (is_basic)
288320
basic_rates |= BIT(j);
289321
break;
@@ -465,7 +497,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
465497
sta = sta_info_get(sdata, mgmt->sa);
466498

467499
if (elems->supp_rates) {
468-
supp_rates = ieee80211_sta_get_rates(local, elems,
500+
supp_rates = ieee80211_sta_get_rates(sdata, elems,
469501
band, NULL);
470502
if (sta) {
471503
u32 prev_rates;
@@ -589,7 +621,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
589621
"beacon TSF higher than local TSF - IBSS merge with BSSID %pM\n",
590622
mgmt->bssid);
591623
ieee80211_sta_join_ibss(sdata, bss);
592-
supp_rates = ieee80211_sta_get_rates(local, elems, band, NULL);
624+
supp_rates = ieee80211_sta_get_rates(sdata, elems, band, NULL);
593625
ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa,
594626
supp_rates);
595627
rcu_read_unlock();
@@ -1024,6 +1056,9 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
10241056
struct cfg80211_ibss_params *params)
10251057
{
10261058
u32 changed = 0;
1059+
u32 rate_flags;
1060+
struct ieee80211_supported_band *sband;
1061+
int i;
10271062

10281063
if (params->bssid) {
10291064
memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
@@ -1034,6 +1069,14 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
10341069
sdata->u.ibss.privacy = params->privacy;
10351070
sdata->u.ibss.control_port = params->control_port;
10361071
sdata->u.ibss.basic_rates = params->basic_rates;
1072+
1073+
/* fix basic_rates if channel does not support these rates */
1074+
rate_flags = ieee80211_chandef_rate_flags(&params->chandef);
1075+
sband = sdata->local->hw.wiphy->bands[params->chandef.chan->band];
1076+
for (i = 0; i < sband->n_bitrates; i++) {
1077+
if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
1078+
sdata->u.ibss.basic_rates &= ~BIT(i);
1079+
}
10371080
memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate,
10381081
sizeof(params->mcast_rate));
10391082

‎net/mac80211/ieee80211_i.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
16011601
int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
16021602
size_t buffer_len, const u8 *ie, size_t ie_len,
16031603
enum ieee80211_band band, u32 rate_mask,
1604-
u8 channel);
1604+
struct cfg80211_chan_def *chandef);
16051605
struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
16061606
u8 *dst, u32 ratemask,
16071607
struct ieee80211_channel *chan,
@@ -1617,7 +1617,7 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
16171617
void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
16181618
const size_t supp_rates_len,
16191619
const u8 *supp_rates);
1620-
u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
1620+
u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
16211621
struct ieee802_11_elems *elems,
16221622
enum ieee80211_band band, u32 *basic_rates);
16231623
int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
@@ -1634,6 +1634,9 @@ u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
16341634
u16 prot_mode);
16351635
u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
16361636
u32 cap);
1637+
int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef,
1638+
const struct ieee80211_supported_band *sband,
1639+
const u8 *srates, int srates_len, u32 *rates);
16371640
int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
16381641
struct sk_buff *skb, bool need_basic,
16391642
enum ieee80211_band band);

‎net/mac80211/mesh.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
6262
struct ieee802_11_elems *ie)
6363
{
6464
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
65-
struct ieee80211_local *local = sdata->local;
6665
u32 basic_rates = 0;
6766
struct cfg80211_chan_def sta_chan_def;
6867

@@ -85,7 +84,7 @@ bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
8584
(ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth)))
8685
return false;
8786

88-
ieee80211_sta_get_rates(local, ie, ieee80211_get_sdata_band(sdata),
87+
ieee80211_sta_get_rates(sdata, ie, ieee80211_get_sdata_band(sdata),
8988
&basic_rates);
9089

9190
if (sdata->vif.bss_conf.basic_rates != basic_rates)

‎net/mac80211/mesh_plink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
379379
u32 rates, basic_rates = 0, changed = 0;
380380

381381
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);
383383

384384
spin_lock_bh(&sta->lock);
385385
sta->last_rx = jiffies;

0 commit comments

Comments
 (0)