cli: fix reporting of mixed WPA2/WPA3 versions
authorJo-Philipp Wich <jo@mein.io>
Fri, 20 Sep 2019 06:55:37 +0000 (08:55 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 20 Sep 2019 11:12:56 +0000 (13:12 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
iwinfo_cli.c

index acfeb759fb6124b03188a547aef2f5a591cf962c..0332bc2b90fd7821f7232bc2f00fdf5b5830916e 100644 (file)
@@ -203,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)
        {
@@ -234,31 +236,25 @@ static char * format_encryption(struct iwinfo_crypto_entry *c)
                /* WPA */
                else if (c->wpa_version)
                {
-                       switch (c->wpa_version) {
-                               case 4:
-                                       snprintf(buf, sizeof(buf), "WPA3 %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 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;
+                       if (n > 1)
+                               pos += sprintf(pos, "mixed ");
 
-                               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;
+                       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/");
 
-                               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;
-                       }
+                       pos--;
+
+                       sprintf(pos, " %s (%s)",
+                               format_enc_suites(c->auth_suites),
+                               format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
                }
                else
                {