Besides channel number the secondary channel for HT40 and center idx0
and idx1 gives full understanding about real channel position and width
on the spectra. So grab it via nl80211 and make it available in both C
and LUA APIs, and show detailed channel information on CLI scan results.

Signed-off-by: Yury Shvedov <yshve...@wimarksystems.com>
---
 include/iwinfo.h | 19 +++++++++++++++++++
 iwinfo_cli.c     | 10 ++++++++++
 iwinfo_lua.c     | 11 +++++++++++
 iwinfo_nl80211.c | 32 ++++++++++++++++++++++++++++++--
 4 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/include/iwinfo.h b/include/iwinfo.h
index b3f5470..1559837 100644
--- a/include/iwinfo.h
+++ b/include/iwinfo.h
@@ -145,6 +145,24 @@ struct iwinfo_crypto_entry {
        uint8_t auth_suites;
        uint8_t auth_algs;
 };
+struct iwinfo_channel_info_entry {
+       /**
+        * sec_channel_offset - Secondary channel offset for HT40
+        *
+        * 0 = HT40 disabled,
+        * -1 = HT40 enabled, secondary channel below primary,
+        * 1 = HT40 enabled, secondary channel above primary
+        */
+       int8_t sec_channel_offset;
+       /**
+        * Center channel for VHT80
+        */
+       uint8_t center_idx0;
+       /**
+        * Center channel for VHT160
+        */
+       uint8_t center_idx1;
+};
 
 struct iwinfo_scanlist_entry {
        uint8_t mac[6];
@@ -156,6 +174,7 @@ struct iwinfo_scanlist_entry {
        uint8_t quality_max;
     uint16_t htmodelist;
        struct iwinfo_crypto_entry crypto;
+       struct iwinfo_channel_info_entry channel_info;
 };
 
 struct iwinfo_country_entry {
diff --git a/iwinfo_cli.c b/iwinfo_cli.c
index 0429fbc..7bd2da2 100644
--- a/iwinfo_cli.c
+++ b/iwinfo_cli.c
@@ -612,6 +612,16 @@ static void print_scanlist(const struct iwinfo_ops *iw, 
const char *ifname)
                                if (e->htmodelist & (1 << h))
                                        printf("%s ", IWINFO_HTMODE_NAMES[h]);
                        printf("\n");
+                       if (e->channel_info.sec_channel_offset)
+                               printf("              HT secondary channel is 
%s\n",
+                                               
e->channel_info.sec_channel_offset < 0 ? "below" :
+                                                       "above");
+                       if (e->channel_info.center_idx0)
+                               printf("              VHT Center IDX0: %d\n",
+                                               e->channel_info.center_idx0);
+                       if (e->channel_info.center_idx1)
+                               printf("              VHT Center IDX1: %d\n",
+                                               e->channel_info.center_idx1);
                }
                printf("\n");
        }
diff --git a/iwinfo_lua.c b/iwinfo_lua.c
index 303fd08..9f95017 100644
--- a/iwinfo_lua.c
+++ b/iwinfo_lua.c
@@ -444,6 +444,17 @@ static int iwinfo_L_scanlist(lua_State *L, int 
(*func)(const char *, char *, int
                 lua_setfield(L, -2, "htmodelist");
                        }
 
+                       lua_pushinteger(L, e->channel_info.sec_channel_offset);
+                       lua_setfield(L, -2, "sec_channel_offset");
+                       if (e->channel_info.center_idx0) {
+                               lua_pushinteger(L, e->channel_info.center_idx0);
+                               lua_setfield(L, -2, "center_idx0");
+                       }
+                       if (e->channel_info.center_idx1) {
+                               lua_pushinteger(L, e->channel_info.center_idx1);
+                               lua_setfield(L, -2, "center_idx1");
+                       }
+
                        lua_rawseti(L, -2, x);
                }
        }
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index 542ac7d..fb137b2 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -1996,6 +1996,27 @@ static void nl80211_parse_ht_capa(struct 
iwinfo_scanlist_entry *e,
                        e->htmodelist |= IWINFO_HTMODE_VHT40;
        }
 }
+static void nl80211_parse_ht_oper(struct iwinfo_scanlist_entry *e,
+                                                                 unsigned char 
*ie,
+                                                                 int len)
+{
+       uint8_t oper_info;
+
+       if (len < 6)
+               return;
+       oper_info = ie[1];
+       switch (oper_info & 3) {
+       case 0:
+               e->channel_info.sec_channel_offset = 0;
+               break;
+       case 1:
+               e->channel_info.sec_channel_offset = 1;
+               break;
+       case 3:
+               e->channel_info.sec_channel_offset = -1;
+               break;
+       }
+}
 static void nl80211_parse_vht_capa(struct iwinfo_scanlist_entry *e,
                                                                   unsigned 
char *ie,
                                                                   int len)
@@ -2024,7 +2045,7 @@ static void nl80211_parse_vht_oper(struct 
iwinfo_scanlist_entry *e,
                                                                   int len)
 {
        int chanwidth;
-       if (len < 1)
+       if (len < 3)
                return;
        chanwidth = ie[0];
 
@@ -2036,6 +2057,7 @@ static void nl80211_parse_vht_oper(struct 
iwinfo_scanlist_entry *e,
        /*case 0: 20 or 40 MHz */
        case 1:
                e->htmodelist |= IWINFO_HTMODE_VHT80;
+               e->channel_info.center_idx0 = ie[1];
                break;
        case 2:
                e->htmodelist |= IWINFO_HTMODE_VHT160;
@@ -2044,10 +2066,12 @@ static void nl80211_parse_vht_oper(struct 
iwinfo_scanlist_entry *e,
                e->htmodelist |= IWINFO_HTMODE_VHT80_80;
                break;
        }
+       e->channel_info.center_idx0 = ie[1];
+       e->channel_info.center_idx1 = ie[2];
 }
 
 static void nl80211_get_scanlist_ie(struct nlattr **bss,
-                                    struct iwinfo_scanlist_entry *e)
+                                                                       struct 
iwinfo_scanlist_entry *e)
 {
        int ielen = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
        unsigned char *ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
@@ -2073,6 +2097,10 @@ static void nl80211_get_scanlist_ie(struct nlattr **bss,
                                         IWINFO_CIPHER_CCMP, 
IWINFO_KMGMT_8021x);
                        break;
 
+               case 61: /* HT Operation */
+                       nl80211_parse_ht_oper(e, ie + 2, ie[1]);
+                       break;
+
                case 191: /* VHT Capabilities */
                        nl80211_parse_vht_capa(e, ie + 2, ie[1]);
                        break;
-- 
2.17.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to