cli: fix printing the scan channel width
authorAndre Heider <a.heider@gmail.com>
Mon, 21 Nov 2022 17:56:38 +0000 (18:56 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 15 Dec 2022 23:09:07 +0000 (00:09 +0100)
The "chan_width" var contains an index, not a value.

While at it, make the 40 and 2040 description shorter and clearer.

Signed-off-by: Andre Heider <a.heider@gmail.com>
iwinfo_cli.c

index 6ed60f2b86f9522b956e799d7d137b9d7687729e..c8436a47f1802981a2c9b4ec714ff98662406abd 100644 (file)
@@ -340,16 +340,21 @@ static char * format_assocrate(struct iwinfo_rate_entry *r)
        return buf;
 }
 
-static const char* format_chan_width(uint16_t width)
-{
-       switch (width) {
-               case 20: return "20 MHz";
-               case 2040: return "40 MHz and upper or 20 MHz with intolerant bit";
-               case 40: return "40 MHz or lower";
-               case 80: return "80 MHz";
-               case 8080: return "80+80 MHz";
-               case 160: return "160 MHz";
-       }
+static const char* format_chan_width(bool vht, uint8_t width)
+{
+       if (!vht && width < ARRAY_SIZE(ht_chan_width))
+               switch (ht_chan_width[width]) {
+                       case 20: return "20 MHz";
+                       case 2040: return "40 MHz or higher";
+               }
+
+       if (vht && width < ARRAY_SIZE(vht_chan_width))
+               switch (vht_chan_width[width]) {
+                       case 40: return "20 or 40 MHz";
+                       case 80: return "80 MHz";
+                       case 8080: return "80+80 MHz";
+                       case 160: return "160 MHz";
+               }
 
        return "unknown";
 }
@@ -674,16 +679,16 @@ static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
                printf("                    Secondary Channel Offset: %s\n",
                        ht_secondary_offset[e->ht_chan_info.secondary_chan_off]);
                printf("                    Channel Width: %s\n",
-                       format_chan_width(e->ht_chan_info.chan_width));
+                       format_chan_width(false, e->ht_chan_info.chan_width));
 
                if (e->vht_chan_info.center_chan_1) {
                        printf("          VHT Operation:\n");
-                       printf("                    Channel Width: %s\n",
-                               format_chan_width(e->vht_chan_info.chan_width));
                        printf("                    Center Frequency 1: %d\n",
                                 e->vht_chan_info.center_chan_1);
                        printf("                    Center Frequency 2: %d\n",
                                 e->vht_chan_info.center_chan_2);
+                       printf("                    Channel Width: %s\n",
+                               format_chan_width(true, e->vht_chan_info.chan_width));
                }
 
                printf("\n");