cli: fix printing the scan channel width
[project/iwinfo.git] / iwinfo_cli.c
index 1ca899909d736b8acb96bb5ca81095fe766f6c19..c8436a47f1802981a2c9b4ec714ff98662406abd 100644 (file)
@@ -254,10 +254,12 @@ static char * format_encryption(struct iwinfo_crypto_entry *c)
 
                        for (i = 0; i < 3; i++)
                                if (c->wpa_version & (1 << i))
+                               {
                                        if (i)
                                                pos += sprintf(pos, "WPA%d/", i + 1);
                                        else
                                                pos += sprintf(pos, "WPA/");
+                               }
 
                        pos--;
 
@@ -280,19 +282,10 @@ static char * format_encryption(struct iwinfo_crypto_entry *c)
 
 static char * format_hwmodes(int modes)
 {
-       static char buf[17];
+       static char buf[32] = "802.11";
 
-       if (modes <= 0)
+       if (iwinfo_format_hwmodes(modes, buf + 6, sizeof(buf) - 6) < 1)
                snprintf(buf, sizeof(buf), "unknown");
-       else
-               snprintf(buf, sizeof(buf), "802.11%s%s%s%s%s%s%s",
-                       (modes & IWINFO_80211_A) ? "a" : "",
-                       (modes & IWINFO_80211_B) ? "b" : "",
-                       (modes & IWINFO_80211_G) ? "g" : "",
-                       (modes & IWINFO_80211_N) ? "n" : "",
-                       (modes & IWINFO_80211_AC) ? "ac" : "",
-                       (modes & IWINFO_80211_AD) ? "ad" : "",
-                       (modes & IWINFO_80211_AX) ? "ax" : "");
 
        return buf;
 }
@@ -347,16 +340,21 @@ static char * format_assocrate(struct iwinfo_rate_entry *r)
        return buf;
 }
 
-static const char* format_chan_width(uint16_t width)
+static const char* format_chan_width(bool vht, uint8_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";
-       }
+       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";
 }
@@ -681,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");
@@ -730,7 +728,7 @@ static void print_txpwrlist(const struct iwinfo_ops *iw, const char *ifname)
 
 static void print_freqlist(const struct iwinfo_ops *iw, const char *ifname)
 {
-       int i, len, ch;
+       int i, len, freq;
        char buf[IWINFO_BUFSIZE];
        struct iwinfo_freqlist_entry *e;
 
@@ -740,15 +738,15 @@ static void print_freqlist(const struct iwinfo_ops *iw, const char *ifname)
                return;
        }
 
-       if (iw->channel(ifname, &ch))
-               ch = -1;
+       if (iw->frequency(ifname, &freq))
+               freq = -1;
 
        for (i = 0; i < len; i += sizeof(struct iwinfo_freqlist_entry))
        {
                e = (struct iwinfo_freqlist_entry *) &buf[i];
 
                printf("%s %s (Channel %s)%s\n",
-                       (ch == e->channel) ? "*" : " ",
+                       (freq == e->mhz) ? "*" : " ",
                        format_frequency(e->mhz),
                        format_channel(e->channel),
                        e->restricted ? " [restricted]" : "");