cli: fix marking the active channel
[project/iwinfo.git] / iwinfo_cli.c
index 456c67a2a5812015636b35b589385f4fa2219cb3..6ed60f2b86f9522b956e799d7d137b9d7687729e 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");
@@ -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,9 +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, ");
 
@@ -248,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--;
 
@@ -274,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;
 }
@@ -724,7 +723,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;
 
@@ -734,15 +733,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]" : "");