From patchwork Tue May 14 14:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13664194 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62B24139589 for ; Tue, 14 May 2024 14:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715696373; cv=none; b=IqRxOQFC4hS71eAT0QDf8KAB1OOrS7nwADvn+/QY1BGcLFMn83j9RpzGJwrh3zOzXoKeRYB5XzijK9YkIG1BcFvf1f/K6MR2bSDapdOLeMm31XDRmvfE3DkV+twB3uPwmz3ktiOpQm1/8S4Olt1yv4ucewIoWI9ReBwuJOHEIk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715696373; c=relaxed/simple; bh=LQTK71j74/BzISZNk9MAR2Jasf7z9BFxfLCQpRl9QxU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qCqSvuUuaYyMF3nRAEV/yHbUTfWwjWqdzLq4dYDDGeCzArT9vG2yV7GigMLwgEK/eEJqwkbG+SuwX4VVY5UVk3KVi8jOAHsF6QnjrKEV3C544bZIfpIfsXZNSOoDFswbE7L66KXdYbRPcvHzRUc90LKkxfa5MRDcMrYsGW9uKgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SO2XFv08; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SO2XFv08" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41fe54cb0e3so36103425e9.2 for ; Tue, 14 May 2024 07:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715696369; x=1716301169; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=V4519cry0Iw6LkbE+i6nxT0awlm0XMxXWFbxF1HDBDk=; b=SO2XFv08qEJD8yKFDVxSs/gXT5FJlreaxBiNs3s+OUrCOW1IPrMjejp0garLW+gMD5 jgn3nCmWSMfWYQKfSlxS/Zi6DJLvkPEVkQ9tcmA9J1lzZ3osK7R0W9UicOzW37BCVrGV vqFeQKbAvcdZ00BK9pEPVaBzL3N0vsFQ2lwNxRuOrOt7Z1BhXw5iub1drO6M10dR4lBJ GC+0635+svz7owdZQIwvJP5D4cW4HfTqqXmPUd5GUV/uJKArUxdbfCHpDaipalGCkOoi vQ/spC73btb4FCEUiszE9fvOcUY28ay2iJnqqIOOLhxGBBqlTqBwOuBz6b7/eD5fgOwJ TL2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715696369; x=1716301169; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=V4519cry0Iw6LkbE+i6nxT0awlm0XMxXWFbxF1HDBDk=; b=TGmzOSez95LcLJOPTM1OCktiOElQVtSMuRtAbX+BqTP9rlGHyLG64OzvsqlCDMfJz8 IpshBpc5ZxZlcChMAmimjO6IpYWoNuiZLhQVrEmkA9yHSwdH385zPeilkR+S5NK3+Rhp QNNEfh8xhJxiZHZwS19zWpDTE4SsKcGtaZ5NwLjfLX4JddcHsA6eqX9WSbVo/0hx5yvv 9Da49Kx8++TajIkTR9o2v4cKMhzol7HzPuc5AxNmBTDs7KlEniJxCqvVktFsK3h7QcH/ 2X0yBZ/+VpgH7hI1VEjn2atO0KeEZVSTV2gYZB/f0FpX5YKCCvzQcOGoXQ4n6+DecjwS 1sbw== X-Gm-Message-State: AOJu0YzNzSUtSFbBh0mgsA1hUt3ZeGmI82V/4xArOffUa2OBla9MXfak 07D/iSxt9NpqeRGS74XdaEniIExuayint3h/qLNTvEkleiXvXpp9IeRNrY3D X-Google-Smtp-Source: AGHT+IHsvEv/KSPY+PbeiDEt+PncJDQsZEYWxCE405f9gDFc2uggvg0NJJpmKDenf5mpcI9c18utRA== X-Received: by 2002:a05:600c:4e0b:b0:420:12af:c759 with SMTP id 5b1f17b1804b1-42012afc9bfmr58172715e9.9.1715696369273; Tue, 14 May 2024 07:19:29 -0700 (PDT) Received: from LOCLAP699.dhl-toledo.locus ([195.55.200.178]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f9ffe26acsm153448085e9.1.2024.05.14.07.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 07:19:28 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 1/2] band: support band lookup fallback for buggy APs Date: Tue, 14 May 2024 07:19:22 -0700 Message-Id: <20240514141923.291148-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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) { From patchwork Tue May 14 14:19:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13664195 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A709139589 for ; Tue, 14 May 2024 14:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715696375; cv=none; b=TQXKGkLL++eM5+LKbanvoY2QQrV81f8bcv3a4Dol0zfp2xU7rDZlToQAiGodqDL1hZ5CakYvCT7+BKWT6R9IfZOEAIDGJNDtm8G+zPhiU0bEE61Z2b0bQsByJ8+qrgUbBCW5l/HKvG0SgcADjAgE0zLiC/ymo181AnV8/ASRprQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715696375; c=relaxed/simple; bh=EaxKL/84g4ULI7CfYTO8RQgeXcTOii58NZ1/LIMHcs0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jmfZN/Q3YlHX8z0K69tpZ45eOEQY8JsdVQ16JZ3agE/vYVgASB0ZzkOxYo4P1PYZE8g7M/oYny7tPeqLet1fLW9WF0ydqF8MI2acrcDaC4zdpK1OrUIrPwWgzaTouMxeo/0ELmkUG4Q8yccEUx9Oe/ahktiwRT+EJhLc4BRlVdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZJp4gPiL; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZJp4gPiL" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-420160f8f52so14878495e9.0 for ; Tue, 14 May 2024 07:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715696371; x=1716301171; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lrkOXJ7QoRpfEOxioFQtxI1IVrPOFesRvqJ1x7s4b6c=; b=ZJp4gPiLsrCMcAaDrdrE3NditScpEEAYLnae9rlaTK9BxUvnTLL7tMVu5T4x7FRpK7 RkyLGz5/GlsKAxVmj+Rdryn4fgq+3Lz3gaCIYcFCyrpogtSGJ+mJwQiSiYi9/6Z1Wxwg 6R4COBqYVf9X1RAyYJ9TR9yIqghDKsfcfZsLh9ylMk5y1+ntGCP9iRJ2p92X6ZlEjpCY jaz0lxsTSO3fIyybN//W2VRWc2g/gQxXvqLZk9T+5AJrmu2VvWKfDr2yNDwKbsQjOuua yoA5hWd2hhQzOjCEJTtpFxwuN+Hxdiieux+9udEMv8ax35GNiQ/VGWKTByMl9UoOOGG+ X1nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715696371; x=1716301171; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lrkOXJ7QoRpfEOxioFQtxI1IVrPOFesRvqJ1x7s4b6c=; b=Xv73qJFzLLVknWrIuWxYuaQr31g3KvfzKPts1HPawHN/Bvta9yNpHITbElTgjJB52Z I6sRcdL7MrNBAhsYh0HyanePf+VcdH+QVrcQP9fsXnKFf5AUBL/YeZdzwrtttVGxVhLg PQ+tRLULd2It/BK2nhDpdzrR+W9hEZpICm/DdEur+1xbW8+EDPUe4oy4CHyXeVdT1saY C1L/U2mwMUT/6JgUhSoj8FY/5and5/USNgxpDQ99cA6DvVB6i5dcDRnDfF8WBxzaqzUl oUIi7XMzTbn4Q+GHarDFbEcHopmLme8NGWnc56zO7AZopLl148jGoZ1eDLFL8zZdD1Fg RUig== X-Gm-Message-State: AOJu0YzKoFAYcvy+rvWQfD3djzMV2lI7U79T23MpHdt66HUQH/QGiVpl Z7Ix3aS9qkMyLZUxdkDkNyXAvfWUYrXhUiDMzQARitbazVI4XgDmXOD3XaTR X-Google-Smtp-Source: AGHT+IEEmkzB4tqVvjHwCBHgeU+3JjzIBawqaPkf4BQSOau9NuIrmN2AFPUinLdvoqOUEc5tC+KbLA== X-Received: by 2002:a05:600c:3594:b0:41b:f41a:c67e with SMTP id 5b1f17b1804b1-41fead6ae4dmr87651295e9.33.1715696371218; Tue, 14 May 2024 07:19:31 -0700 (PDT) Received: from LOCLAP699.dhl-toledo.locus ([195.55.200.178]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f9ffe26acsm153448085e9.1.2024.05.14.07.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 07:19:30 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 2/2] unit: add test for band fallback Date: Tue, 14 May 2024 07:19:23 -0700 Message-Id: <20240514141923.291148-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240514141923.291148-1-prestwoj@gmail.com> References: <20240514141923.291148-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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(+) diff --git a/unit/test-band.c b/unit/test-band.c index 855fb67f..606bb854 100644 --- a/unit/test-band.c +++ b/unit/test-band.c @@ -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(); }