iwinfo: nl80211: fix hwmode parsing for multi-band NICs openwrt-21.02
authorDavid Bauer <mail@david-bauer.net>
Sun, 24 Apr 2022 22:52:22 +0000 (00:52 +0200)
committerDavid Bauer <mail@david-bauer.net>
Tue, 26 Apr 2022 00:03:00 +0000 (02:03 +0200)
In case a NIC supports multiple frequency bands, the supported
hw-modelist might not contain all valid hwmodes, as B/G/AD hwmodes are
only included based on the last parsed supported frequency.

In case a radio supports multiple bands, this might result in these
hwmodes not being flagged as supported.

Circumvent this by tracking all seen frequency bands using a bitmask
which later determined which HW modes are listed as supported.

Signed-off-by: David Bauer <mail@david-bauer.net>
package/network/utils/iwinfo/Makefile
package/network/utils/iwinfo/patches/0002-iwinfo-nl80211-fix-hwmode-parsing-for-multi-band-NIC.patch [new file with mode: 0644]
package/network/utils/iwinfo/patches/0003-iwinfo-nl80211-omit-A-hwmode-on-non-5GHz-hardware.patch [new file with mode: 0644]

index 815c477988b51e1855c3319bc2670f7673d86609..3a63b0d153633c8c87e2b6473bbaffb112f40d0c 100644 (file)
@@ -7,7 +7,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=libiwinfo
-PKG_RELEASE:=2.1
+PKG_RELEASE:=3
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/iwinfo.git
diff --git a/package/network/utils/iwinfo/patches/0002-iwinfo-nl80211-fix-hwmode-parsing-for-multi-band-NIC.patch b/package/network/utils/iwinfo/patches/0002-iwinfo-nl80211-fix-hwmode-parsing-for-multi-band-NIC.patch
new file mode 100644 (file)
index 0000000..bb57079
--- /dev/null
@@ -0,0 +1,120 @@
+From 562d01532616b7be095b9e14a407351e71c0a06c Mon Sep 17 00:00:00 2001
+From: David Bauer <mail@david-bauer.net>
+Date: Fri, 22 Apr 2022 23:56:35 +0200
+Subject: [PATCH 1/2] iwinfo: nl80211: fix hwmode parsing for multi-band NICs
+
+In case a NIC supports multiple frequency bands, the supported
+hw-modelist might not contain all valid hwmodes, as B/G/AD hwmodes are
+only included based on the last parsed supported frequency.
+
+In case a radio supports multiple bands, this might result in these
+hwmodes not being flagged as supported.
+
+Circumvent this by tracking all seen frequency bands using a bitmask
+which later determined which HW modes are listed as supported.
+
+Signed-off-by: David Bauer <mail@david-bauer.net>
+---
+ include/iwinfo.h |  5 +++++
+ iwinfo_nl80211.c | 34 ++++++++++++++++++++++++++++------
+ 2 files changed, 33 insertions(+), 6 deletions(-)
+
+diff --git a/include/iwinfo.h b/include/iwinfo.h
+index 8469ee7..e9b7451 100644
+--- a/include/iwinfo.h
++++ b/include/iwinfo.h
+@@ -31,6 +31,11 @@
+ #define IWINFO_80211_AD      (1 << 5)
+ #define IWINFO_80211_AX      (1 << 6)
++#define IWINFO_BAND_24       (1 << 0)
++#define IWINFO_BAND_5        (1 << 1)
++#define IWINFO_BAND_6        (1 << 2)
++#define IWINFO_BAND_60       (1 << 3)
++
+ #define IWINFO_CIPHER_NONE   (1 << 0)
+ #define IWINFO_CIPHER_WEP40  (1 << 1)
+ #define IWINFO_CIPHER_TKIP   (1 << 2)
+diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
+index c4b0ee2..5b5deec 100644
+--- a/iwinfo_nl80211.c
++++ b/iwinfo_nl80211.c
+@@ -3012,7 +3012,8 @@ struct nl80211_modes
+       uint32_t hw;
+       uint32_t ht;
+-      uint32_t nl_freq;
++      uint8_t bands;
++
+       uint16_t nl_ht;
+       uint32_t nl_vht;
+       uint16_t he_phy_cap[6];
+@@ -3044,12 +3045,13 @@ static int nl80211_eval_modelist(struct nl80211_modes *m)
+                       m->ht |= IWINFO_HTMODE_HE160 | IWINFO_HTMODE_HE80_80;
+       }
+-      if (m->nl_freq < 2485)
++      if (m->bands & IWINFO_BAND_24)
+       {
+               m->hw |= IWINFO_80211_B;
+               m->hw |= IWINFO_80211_G;
+       }
+-      else if (m->nl_vht)
++
++      if (m->nl_vht)
+       {
+               /* Treat any nonzero capability as 11ac */
+               if (m->nl_vht > 0)
+@@ -3068,11 +3070,13 @@ static int nl80211_eval_modelist(struct nl80211_modes *m)
+                       }
+               }
+       }
+-      else if (m->nl_freq >= 56160)
++
++      if (m->bands & IWINFO_BAND_60)
+       {
+               m->hw |= IWINFO_80211_AD;
+       }
+-      else if (!(m->hw & IWINFO_80211_AC))
++
++      if (!(m->hw & IWINFO_80211_AC))
+       {
+               m->hw |= IWINFO_80211_A;
+       }
+@@ -3088,6 +3092,7 @@ static int nl80211_get_modelist_cb(struct nl_msg *msg, void *arg)
+       struct nlattr *bands[NL80211_BAND_ATTR_MAX + 1];
+       struct nlattr *freqs[NL80211_FREQUENCY_ATTR_MAX + 1];
+       struct nlattr *band, *freq;
++      uint32_t freq_mhz;
+       if (attr[NL80211_ATTR_WIPHY_BANDS])
+       {
+@@ -3133,7 +3138,24 @@ static int nl80211_get_modelist_cb(struct nl_msg *msg, void *arg)
+                                       if (!freqs[NL80211_FREQUENCY_ATTR_FREQ])
+                                               continue;
+-                                      m->nl_freq = nla_get_u32(freqs[NL80211_FREQUENCY_ATTR_FREQ]);
++                                      freq_mhz = nla_get_u32(freqs[NL80211_FREQUENCY_ATTR_FREQ]);
++
++                                      if (freq_mhz > 2400 && freq_mhz < 2485)
++                                      {
++                                              m->bands |= IWINFO_BAND_24;
++                                      }
++                                      else if (freq_mhz > 5000 && freq_mhz < 5850)
++                                      {
++                                              m->bands |= IWINFO_BAND_5;
++                                      }
++                                      else if (freq_mhz > 6000 && freq_mhz < 7120)
++                                      {
++                                              m->bands |= IWINFO_BAND_6;
++                                      }
++                                      else if (freq_mhz >= 56160)
++                                      {
++                                              m->bands |= IWINFO_BAND_60;
++                                      }
+                               }
+                       }
+               }
+-- 
+2.36.0
+
diff --git a/package/network/utils/iwinfo/patches/0003-iwinfo-nl80211-omit-A-hwmode-on-non-5GHz-hardware.patch b/package/network/utils/iwinfo/patches/0003-iwinfo-nl80211-omit-A-hwmode-on-non-5GHz-hardware.patch
new file mode 100644 (file)
index 0000000..3999e44
--- /dev/null
@@ -0,0 +1,54 @@
+From 20e1b873b6871dfe7b2d5e0f9ab590bf5f87941e Mon Sep 17 00:00:00 2001
+From: David Bauer <mail@david-bauer.net>
+Date: Tue, 26 Apr 2022 01:53:51 +0200
+Subject: [PATCH] iwinfo: nl80211: omit A-hwmode on non-5GHz hardware
+
+Don't add the hwmode A for radios which do not support 5GHz operation.
+Before, this hwmode was added to all non-VHT radios regardless of their
+supported bands.
+
+Fixes commit 562d01532616 ("iwinfo: nl80211: fix hwmode parsing for multi-band NICs")
+
+Signed-off-by: David Bauer <mail@david-bauer.net>
+---
+ iwinfo_nl80211.c | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
+index 5b5deec..adb8c45 100644
+--- a/iwinfo_nl80211.c
++++ b/iwinfo_nl80211.c
+@@ -3051,7 +3051,7 @@ static int nl80211_eval_modelist(struct nl80211_modes *m)
+               m->hw |= IWINFO_80211_G;
+       }
+-      if (m->nl_vht)
++      if (m->bands & IWINFO_BAND_5)
+       {
+               /* Treat any nonzero capability as 11ac */
+               if (m->nl_vht > 0)
+@@ -3069,6 +3069,10 @@ static int nl80211_eval_modelist(struct nl80211_modes *m)
+                               m->ht |= IWINFO_HTMODE_VHT160;
+                       }
+               }
++              else
++              {
++                      m->hw |= IWINFO_80211_A;
++              }
+       }
+       if (m->bands & IWINFO_BAND_60)
+@@ -3076,10 +3080,6 @@ static int nl80211_eval_modelist(struct nl80211_modes *m)
+               m->hw |= IWINFO_80211_AD;
+       }
+-      if (!(m->hw & IWINFO_80211_AC))
+-      {
+-              m->hw |= IWINFO_80211_A;
+-      }
+ }
+ static int nl80211_get_modelist_cb(struct nl_msg *msg, void *arg)
+-- 
+2.36.0
+