($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 1/2] band: support band lookup fallback for buggy APs
Date: Tue, 14 May 2024 07:19:22 -0700	[thread overview]
Message-ID: <20240514141923.291148-1-prestwoj@gmail.com> (raw)

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(-)

diff --git a/src/band.c b/src/band.c
index 906d6197..6891d06c 100644
--- a/src/band.c
+++ b/src/band.c
@@ -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) {
-- 
2.34.1


             reply	other threads:[~2024-05-14 14:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 14:19 James Prestwood [this message]
2024-05-14 14:19 ` [PATCH 2/2] unit: add test for band fallback James Prestwood
2024-05-14 15:33 ` [PATCH 1/2] band: support band lookup fallback for buggy APs Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240514141923.291148-1-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).