iwinfo: add device id for Mikrotik R11e-5HacD miniPCIe card
[oweals/iwinfo.git] / iwinfo_cli.c
index d9a59e281749a34661c43114ae34b490ebcfbab7..0332bc2b90fd7821f7232bc2f00fdf5b5830916e 100644 (file)
@@ -130,7 +130,7 @@ static char * format_noise(int noise)
 
 static char * format_rate(int rate)
 {
-       static char buf[14];
+       static char buf[18];
 
        if (rate <= 0)
                snprintf(buf, sizeof(buf), "unknown");
@@ -186,6 +186,12 @@ static char * format_enc_suites(int suites)
        if (suites & IWINFO_KMGMT_8021x)
                pos += sprintf(pos, "802.1X/");
 
+       if (suites & IWINFO_KMGMT_SAE)
+               pos += sprintf(pos, "SAE/");
+
+       if (suites & IWINFO_KMGMT_OWE)
+               pos += sprintf(pos, "OWE/");
+
        if (!suites || (suites & IWINFO_KMGMT_NONE))
                pos += sprintf(pos, "NONE/");
 
@@ -197,6 +203,8 @@ static char * format_enc_suites(int suites)
 static char * format_encryption(struct iwinfo_crypto_entry *c)
 {
        static char buf[512];
+       char *pos = buf;
+       int i, n;
 
        if (!c)
        {
@@ -228,25 +236,25 @@ static char * format_encryption(struct iwinfo_crypto_entry *c)
                /* WPA */
                else if (c->wpa_version)
                {
-                       switch (c->wpa_version) {
-                               case 3:
-                                       snprintf(buf, sizeof(buf), "mixed WPA/WPA2 %s (%s)",
-                                               format_enc_suites(c->auth_suites),
-                                               format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
-                                       break;
+                       for (i = 0, n = 0; i < 3; i++)
+                               if (c->wpa_version & (1 << i))
+                                       n++;
 
-                               case 2:
-                                       snprintf(buf, sizeof(buf), "WPA2 %s (%s)",
-                                               format_enc_suites(c->auth_suites),
-                                               format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
-                                       break;
+                       if (n > 1)
+                               pos += sprintf(pos, "mixed ");
 
-                               case 1:
-                                       snprintf(buf, sizeof(buf), "WPA %s (%s)",
-                                               format_enc_suites(c->auth_suites),
-                                               format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
-                                       break;
-                       }
+                       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--;
+
+                       sprintf(pos, " %s (%s)",
+                               format_enc_suites(c->auth_suites),
+                               format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
                }
                else
                {
@@ -263,24 +271,25 @@ static char * format_encryption(struct iwinfo_crypto_entry *c)
 
 static char * format_hwmodes(int modes)
 {
-       static char buf[12];
+       static char buf[15];
 
        if (modes <= 0)
                snprintf(buf, sizeof(buf), "unknown");
        else
-               snprintf(buf, sizeof(buf), "802.11%s%s%s%s%s",
+               snprintf(buf, sizeof(buf), "802.11%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_AC) ? "ac" : "",
+                       (modes & IWINFO_80211_AD) ? "ad" : "");
 
        return buf;
 }
 
 static char * format_assocrate(struct iwinfo_rate_entry *r)
 {
-       static char buf[40];
+       static char buf[80];
        char *p = buf;
        int l = sizeof(buf);
 
@@ -293,13 +302,21 @@ static char * format_assocrate(struct iwinfo_rate_entry *r)
                p += snprintf(p, l, "%s", format_rate(r->rate));
                l = sizeof(buf) - (p - buf);
 
-               if (r->mcs >= 0)
+               if (r->is_ht)
                {
-                       p += snprintf(p, l, ", MCS %d, %dMHz", r->mcs, 20 + r->is_40mhz*20);
+                       p += snprintf(p, l, ", MCS %d, %dMHz", r->mcs, r->mhz);
+                       l = sizeof(buf) - (p - buf);
+               }
+               else if (r->is_vht)
+               {
+                       p += snprintf(p, l, ", VHT-MCS %d, %dMHz", r->mcs, r->mhz);
                        l = sizeof(buf) - (p - buf);
 
-                       if (r->is_short_gi)
-                               p += snprintf(p, l, ", short GI");
+                       if (r->nss)
+                       {
+                               p += snprintf(p, l, ", VHT-NSS %d", r->nss);
+                               l = sizeof(buf) - (p - buf);
+                       }
                }
        }
 
@@ -692,10 +709,13 @@ static void print_assoclist(const struct iwinfo_ops *iw, const char *ifname)
                        e->rx_packets
                );
 
-               printf("        TX: %-38s  %8d Pkts.\n\n",
+               printf("        TX: %-38s  %8d Pkts.\n",
                        format_assocrate(&e->tx_rate),
                        e->tx_packets
                );
+
+               printf("        expected throughput: %s\n\n",
+                       format_rate(e->thr));
        }
 }
 
@@ -744,6 +764,23 @@ static void print_countrylist(const struct iwinfo_ops *iw, const char *ifname)
        }
 }
 
+static void print_htmodelist(const struct iwinfo_ops *iw, const char *ifname)
+{
+       int i, htmodes = 0;
+
+       if (iw->htmodelist(ifname, &htmodes))
+       {
+               printf("No HT mode information available\n");
+               return;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
+               if (htmodes & (1 << i))
+                       printf("%s ", IWINFO_HTMODE_NAMES[i]);
+
+       printf("\n");
+}
+
 static void lookup_phy(const struct iwinfo_ops *iw, const char *section)
 {
        char buf[IWINFO_BUFSIZE];
@@ -781,6 +818,7 @@ int main(int argc, char **argv)
                        "       iwinfo <device> freqlist\n"
                        "       iwinfo <device> assoclist\n"
                        "       iwinfo <device> countrylist\n"
+                       "       iwinfo <device> htmodelist\n"
                        "       iwinfo <backend> phyname <section>\n"
                );
 
@@ -873,6 +911,10 @@ int main(int argc, char **argv)
                                        print_countrylist(iw, argv[1]);
                                        break;
 
+                               case 'h':
+                                       print_htmodelist(iw, argv[1]);
+                                       break;
+
                                default:
                                        fprintf(stderr, "Unknown command: %s\n", argv[i]);
                                        rv = 1;
@@ -881,7 +923,6 @@ int main(int argc, char **argv)
                }
        }
 
-out:
        iwinfo_finish();
 
        return rv;