fix -Wdangling-else warnings
[project/iwinfo.git] / iwinfo_cli.c
index 5949004965bbe4f0f622aa68766921c97f8aea71..b533ffe96fefa36ae2b8b1548a9b71c661971a3f 100644 (file)
@@ -46,7 +46,7 @@ static char * format_ssid(char *ssid)
 
 static char * format_channel(int ch)
 {
-       static char buf[8];
+       static char buf[16];
 
        if (ch <= 0)
                snprintf(buf, sizeof(buf), "unknown");
@@ -58,7 +58,7 @@ static char * format_channel(int ch)
 
 static char * format_frequency(int freq)
 {
-       static char buf[10];
+       static char buf[11];
 
        if (freq <= 0)
                snprintf(buf, sizeof(buf), "unknown");
@@ -70,7 +70,7 @@ static char * format_frequency(int freq)
 
 static char * format_txpower(int pwr)
 {
-       static char buf[10];
+       static char buf[16];
 
        if (pwr < 0)
                snprintf(buf, sizeof(buf), "unknown");
@@ -82,7 +82,7 @@ static char * format_txpower(int pwr)
 
 static char * format_quality(int qual)
 {
-       static char buf[8];
+       static char buf[16];
 
        if (qual < 0)
                snprintf(buf, sizeof(buf), "unknown");
@@ -94,7 +94,7 @@ static char * format_quality(int qual)
 
 static char * format_quality_max(int qmax)
 {
-       static char buf[8];
+       static char buf[16];
 
        if (qmax < 0)
                snprintf(buf, sizeof(buf), "unknown");
@@ -158,6 +158,15 @@ static char * format_enc_ciphers(int ciphers)
        if (ciphers & IWINFO_CIPHER_CCMP)
                pos += sprintf(pos, "CCMP, ");
 
+       if (ciphers & IWINFO_CIPHER_CCMP256)
+               pos += sprintf(pos, "CCMP-256, ");
+
+       if (ciphers & IWINFO_CIPHER_GCMP)
+               pos += sprintf(pos, "GCMP, ");
+
+       if (ciphers & IWINFO_CIPHER_GCMP256)
+               pos += sprintf(pos, "GCMP-256, ");
+
        if (ciphers & IWINFO_CIPHER_WRAP)
                pos += sprintf(pos, "WRAP, ");
 
@@ -245,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--;
 
@@ -271,18 +282,19 @@ static char * format_encryption(struct iwinfo_crypto_entry *c)
 
 static char * format_hwmodes(int modes)
 {
-       static char buf[15];
+       static char buf[17];
 
        if (modes <= 0)
                snprintf(buf, sizeof(buf), "unknown");
        else
-               snprintf(buf, sizeof(buf), "802.11%s%s%s%s%s%s",
+               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_AD) ? "ad" : "",
+                       (modes & IWINFO_80211_AX) ? "ax" : "");
 
        return buf;
 }
@@ -318,11 +330,39 @@ static char * format_assocrate(struct iwinfo_rate_entry *r)
                                l = sizeof(buf) - (p - buf);
                        }
                }
+               else if (r->is_he)
+               {
+                       p += snprintf(p, l, ", HE-MCS %d, %dMHz", r->mcs, r->mhz);
+                       l = sizeof(buf) - (p - buf);
+
+                       p += snprintf(p, l, ", HE-NSS %d", r->nss);
+                       l = sizeof(buf) - (p - buf);
+
+                       p += snprintf(p, l, ", HE-GI %d", r->he_gi);
+                       l = sizeof(buf) - (p - buf);
+
+                       p += snprintf(p, l, ", HE-DCM %d", r->he_dcm);
+                       l = sizeof(buf) - (p - buf);
+               }
        }
 
        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";
+       }
+
+       return "unknown";
+}
+
 
 static const char * print_type(const struct iwinfo_ops *iw, const char *ifname)
 {
@@ -431,6 +471,24 @@ static char * print_channel(const struct iwinfo_ops *iw, const char *ifname)
        return format_channel(ch);
 }
 
+static char * print_center_chan1(const struct iwinfo_ops *iw, const char *ifname)
+{
+       int ch;
+       if (iw->center_chan1(ifname, &ch))
+               ch = -1;
+
+       return format_channel(ch);
+}
+
+static char * print_center_chan2(const struct iwinfo_ops *iw, const char *ifname)
+{
+       int ch;
+       if (iw->center_chan2(ifname, &ch))
+               ch = -1;
+
+       return format_channel(ch);
+}
+
 static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname)
 {
        int freq;
@@ -552,6 +610,11 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname)
                print_mode(iw, ifname),
                print_channel(iw, ifname),
                print_frequency(iw, ifname));
+       if (iw->center_chan1 != NULL) {
+               printf("          Center Channel 1: %s",
+                       print_center_chan1(iw, ifname));
+               printf(" 2: %s\n", print_center_chan2(iw, ifname));
+       }
        printf("          Tx-Power: %s  Link Quality: %s/%s\n",
                print_txpower(iw, ifname),
                print_quality(iw, ifname),
@@ -614,14 +677,24 @@ static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
                        format_quality_max(e->quality_max));
                printf("          Encryption: %s\n",
                        format_encryption(&e->crypto));
-               if (e->has_bss_load) {
-                       printf("          Station count: %u\n",
-                               e->station_count);
-                       printf("          Channel utilization: %u/255\n",
-                               e->channel_utilization);
-                       printf("          Available admission capacity: %u (*32us)\n",
-                               e->admission_capacity);
+               printf("          HT Operation:\n");
+               printf("                    Primary Channel: %d\n",
+                       e->ht_chan_info.primary_chan);
+               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));
+
+               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("\n");
        }
 }
@@ -810,6 +883,16 @@ static void lookup_phy(const struct iwinfo_ops *iw, const char *section)
 }
 
 
+static void lookup_path(const struct iwinfo_ops *iw, const char *phy)
+{
+       const char *path;
+
+       if (!iw->phy_path || iw->phy_path(phy, &path) || !path)
+               return;
+
+       printf("%s\n", path);
+}
+
 int main(int argc, char **argv)
 {
        int i, rv = 0;
@@ -869,6 +952,10 @@ int main(int argc, char **argv)
                }
                else
                {
+                       if (!strcmp(argv[2], "path")) {
+                               lookup_path(iw, argv[3]);
+                               return 0;
+                       }
                        switch (argv[2][0])
                        {
                        case 'p':