@@ -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
0 commit comments