From 02112f9b105752fa05fd1314092347e60c1aeaf7 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 20 Sep 2019 08:55:37 +0200 Subject: cli: fix reporting of mixed WPA2/WPA3 versions Signed-off-by: Jo-Philipp Wich --- iwinfo_cli.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'iwinfo_cli.c') diff --git a/iwinfo_cli.c b/iwinfo_cli.c index acfeb75..0332bc2 100644 --- a/iwinfo_cli.c +++ b/iwinfo_cli.c @@ -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 { -- cgit v1.2.1