band: support band lookup fallback for buggy APs
PATCH 1/2 band: support band lookup fallback for buggy APs
Its been seen that some vendors incorrectly set the 3rd byte of the country code which causes the band lookup to fail with the provided operating class. This isn't compliant with the spec, but its been seen out in the wild and it causes IWD to behave poorly, specifically with roaming since it cannot parse neighbor reports. This then requires IWD to do a full scan on each roam.
Instead of a hard rejection, IWD can instead attempt to determine the band by ignoring that 3rd byte and only use the alpha2 string. This makes IWD slightly less strict but at the advantage of not being crippled when exposed to poor AP configurations.
--- src/band.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-)
src/band.c +55 -3
@@ -1485,15 +1485,48 @@ static const uint8_t oper_class_cn_to_global[] = {/* 128 - 130 is a 1 to 1 mapping */ }; -enum band_freq band_oper_class_to_band (const uint8_t *country, -uint8_t oper_class) +/* +* Annex C describes the country string encoding. +* +* If it is a country, the first two octets of this string is the two character +* country code as described in document ISO 3166-1. The third octet is one of +* the following: +* 1. an ASCII space character, if the regulations under which the station is +* operating encompass all environments for the current frequency band in +* the country, +* 2. an ASCII 'O' character, if the regulations under which the station is +* operating are for an outdoor environment only, or +* 3. an ASCII 'I' character, if the regulations under which the station is +* operating are for an indoor environment only. +* 4. an ASCII 'X' character, if the station is operating under a noncountry +* entity. The first two octets of the noncountry entity is two ASCII 'XX' +* characters. +* 5. the hexadecimal representation of the Operating Class table number +* currently in use, from the set of tables defined in Annex E, e.g., +* Table E-1 is represented as x'01'. +*/ +static enum band_freq oper_class_to_band (const uint8_t *country, +uint8_t oper_class, +bool ignore_country3) {unsigned int i;int table =0 ; -if (country && country[2 ] >=1 && country[2 ] <=5 ) +/* +* If a country is set, and the 3rd byte maps to some E-* table in the +* spec use that (case 5). Only caveat here is some APs erroneously set +* this 3rd byte. To work around we can fall back to case 1, where only +* the first two characters are used to lookup the table. +*/ +if (!ignore_country3 && country && country[2 ] >=1 && country[2 ] <=5 ) table = country[2 ];else if (country) { +/* +* Assuming case 1, although its unlikely you would handle +* cases 2 (O) or 3 (I) any differently. Case 4 (X) is unlikely +* and we really wouldn't have enough information to correctly +* determine the band in some obscure non-country domain. +*/ for (i =0 ; i <L_ARRAY_SIZE (oper_class_us_codes); i++)if (!memcmp (oper_class_us_codes[i], country,2 )) {/* Use table E-1 */
@@ -1542,6 +1575,25 @@ enum band_freq band_oper_class_to_band(const uint8_t *country,return 0 ; } +enum band_freq band_oper_class_to_band (const uint8_t *country, +uint8_t oper_class) +{ +enum band_freq band =oper_class_to_band (country, oper_class, false); +if (!band) { +/* Fallback with no country string won't change anything */ +if (!country) +return 0 ; + +l_warn ("Failed to find band with country string '%c%c %u' and " +"oper class %u, trying fallback" , + country[0 ], country[1 ], country[2 ], oper_class); + +return oper_class_to_band (country, oper_class, true); + } + +return band; +} +const char *band_chandef_width_to_string (enum band_chandef_width width) {switch (width) {
Signature · 1 line
2.34.1
PATCH 2/2 unit: add test for band fallback
This test uses the same country/country3 values seen by an AP vendor which causes issues with IWD. The alpha2 is ES (Spain) and the 3rd byte is 4, indicating to use the E-4. The issue then comes when the neighbor report claims the BSS is under operating class 3 which is not part of E-4.
With the fallback implemented, this test will pass since it will try and lookup only on ES (the EU table) which operating class 3 is part of.
--- unit/test-band.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
unit/test-band.c +14 -0
@@ -670,6 +670,19 @@ static void test_conversions(const void *data)assert (!band_channel_to_freq (192 ,BAND_FREQ_5_GHZ )); } +static void test_conversion_fallback (const void *data) +{ +enum band_freq band; +const uint8_t cc[] = {'E' ,'S' ,0x04 }; + +/* +* Without a fallback, this would fail. There is no operclass 3 in the +* global operating table (E-4) +*/ + band =band_oper_class_to_band (cc,3 ); +assert (band ==BAND_FREQ_5_GHZ ); +} +int main (int argc,char *argv[]) {l_test_init (&argc, &argv);
@@ -736,6 +749,7 @@ int main(int argc, char *argv[])l_test_add ("/band/6ghz/freq" , test_6ghz_freqs,NULL );l_test_add ("/band/conversions" , test_conversions,NULL ); +l_test_add ("/band/conversion fallback" , test_conversion_fallback,NULL );return l_test_run (); }
Signature · 1 line
2.34.1
Hi James,
Quoted 7 lines · James Prestwood
Its been seen that some vendors incorrectly set the 3rd byte of the country code which causes the band lookup to fail with the provided operating class. This isn't compliant with the spec, but its been seen out in the wild and it causes IWD to behave poorly, specifically with roaming since it cannot parse neighbor reports. This then requires IWD to do a full scan on each roam.
Quoted 8 lines
Instead of a hard rejection, IWD can instead attempt to determine the band by ignoring that 3rd byte and only use the alpha2 string. This makes IWD slightly less strict but at the advantage of not being crippled when exposed to poor AP configurations.
--- src/band.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-)
Both applied, thanks.
Regards,
-Denis