From cc76a7199d2ae8e014720d90d06bf90e6d0535b3 Mon Sep 17 00:00:00 2001 From: Jakob Olsson <jakob.olsson@iopsys.eu> Date: Tue, 14 Feb 2023 17:40:00 +0100 Subject: [PATCH] use bitshift macro to handle correct auth types --- src/cntlr_tlv.c | 24 ++++++++++++------------ src/config.c | 30 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cntlr_tlv.c b/src/cntlr_tlv.c index 2e8565e5..974a47d9 100644 --- a/src/cntlr_tlv.c +++ b/src/cntlr_tlv.c @@ -57,31 +57,31 @@ uint16_t wifi_sec_to_auth_types(enum wifi_security sec) { uint16_t auth_type = 0; - if (sec >= WIFI_SECURITY_WPA) { - if (sec == WIFI_SECURITY_WPA2) { + if (sec >= BIT(WIFI_SECURITY_WPA)) { + if (sec == BIT(WIFI_SECURITY_WPA2)) { auth_type = WPS_AUTH_WPA; - } else if (sec == WIFI_SECURITY_WPA) { + } else if (sec == BIT(WIFI_SECURITY_WPA)) { auth_type = WPS_AUTH_WPA; - } else if ((sec & WIFI_SECURITY_WPA) && (sec & WIFI_SECURITY_WPA2)) { + } else if ((sec & BIT(WIFI_SECURITY_WPA)) && (sec & BIT(WIFI_SECURITY_WPA2))) { auth_type |= WPS_AUTH_WPA; auth_type |= WPS_AUTH_WPA2; } - } else if (sec >= WIFI_SECURITY_WPAPSK) { - if (sec == WIFI_SECURITY_WPA3PSK) { + } else if (sec >= BIT(WIFI_SECURITY_WPAPSK)) { + if (sec == BIT(WIFI_SECURITY_WPA3PSK)) { auth_type = WPS_AUTH_SAE; - } else if (sec == WIFI_SECURITY_WPA3PSK_T) { + } else if (sec == BIT(WIFI_SECURITY_WPA3PSK_T)) { auth_type = WPS_AUTH_WPA3_T; - } else if ((sec & WIFI_SECURITY_WPA3PSK) && (sec & WIFI_SECURITY_WPA3PSK_T)) { + } else if ((sec & BIT(WIFI_SECURITY_WPA3PSK)) && (sec & BIT(WIFI_SECURITY_WPA3PSK_T))) { auth_type = WPS_AUTH_WPA3_T; - } else if (sec == WIFI_SECURITY_WPA2PSK) { + } else if (sec == BIT(WIFI_SECURITY_WPA2PSK)) { auth_type = WPS_AUTH_WPA2PSK; - } else if (sec == WIFI_SECURITY_WPAPSK) { + } else if (sec == BIT(WIFI_SECURITY_WPAPSK)) { auth_type = WPS_AUTH_WPAPSK; - } else if ((sec & WIFI_SECURITY_WPAPSK) && (sec & WIFI_SECURITY_WPA2PSK)) { + } else if ((sec & BIT(WIFI_SECURITY_WPAPSK)) && (sec & BIT(WIFI_SECURITY_WPA2PSK))) { auth_type |= WPS_AUTH_WPAPSK; auth_type |= WPS_AUTH_WPA2PSK; } - } else if (sec == WIFI_SECURITY_NONE) + } else if (sec == BIT(WIFI_SECURITY_NONE)) auth_type = WPS_AUTH_OPEN; //TODO: ciphers (if any) diff --git a/src/config.c b/src/config.c index e218a3cc..cd758540 100644 --- a/src/config.c +++ b/src/config.c @@ -1033,28 +1033,28 @@ static int cntlr_config_get_credentials(struct controller_config *c, const char *sec = tb[CRED_SEC]->v.string; if (!strncmp(sec, "sae-mixed", 9)) { - cred->sec |= WIFI_SECURITY_WPA3PSK; - cred->sec |= WIFI_SECURITY_WPA3PSK_T; + cred->sec |= BIT(WIFI_SECURITY_WPA3PSK); + cred->sec |= BIT(WIFI_SECURITY_WPA3PSK_T); } else if (!strncmp(sec, "sae", 3)) { - cred->sec |= WIFI_SECURITY_WPA3PSK; + cred->sec |= BIT(WIFI_SECURITY_WPA3PSK); } else if (!strncmp(sec, "psk-mixed", 9)) { - cred->sec |= WIFI_SECURITY_WPAPSK; - cred->sec |= WIFI_SECURITY_WPA2PSK; + cred->sec |= BIT(WIFI_SECURITY_WPAPSK); + cred->sec |= BIT(WIFI_SECURITY_WPA2PSK); } else if (!strncmp(sec, "psk2", 4)) { - cred->sec |= WIFI_SECURITY_WPA2PSK; + cred->sec |= BIT(WIFI_SECURITY_WPA2PSK); } else if (!strncmp(sec, "psk", 3)) { - cred->sec |= WIFI_SECURITY_WPAPSK; + cred->sec |= BIT(WIFI_SECURITY_WPAPSK); } else if (!strncmp(sec, "wpa-mixed", 9)) { - cred->sec |= WIFI_SECURITY_WPA; - cred->sec |= WIFI_SECURITY_WPA2; + cred->sec |= BIT(WIFI_SECURITY_WPA); + cred->sec |= BIT(WIFI_SECURITY_WPA2); } else if (!strncmp(sec, "wpa2", 4)) { - cred->sec |= WIFI_SECURITY_WPA2; + cred->sec |= BIT(WIFI_SECURITY_WPA2); } else if (!strncmp(sec, "wpa", 3)) { - cred->sec |= WIFI_SECURITY_WPA; + cred->sec |= BIT(WIFI_SECURITY_WPA); } else if (!strncmp(sec, "none", 4)) { - cred->sec |= WIFI_SECURITY_NONE; + cred->sec |= BIT(WIFI_SECURITY_NONE); } else if (!strncmp(sec, "open", 4)) { - cred->sec |= WIFI_SECURITY_NONE; + cred->sec |= BIT(WIFI_SECURITY_NONE); } else { free(cred); return -1; @@ -1093,9 +1093,9 @@ static int cntlr_config_get_credentials(struct controller_config *c, } if (use_default_security) { - cred->sec |= WIFI_SECURITY_WPA3PSK; + cred->sec |= BIT(WIFI_SECURITY_WPA3PSK); if (!!(cred->multi_ap & 2)) - cred->sec |= WIFI_SECURITY_WPA3PSK_T; + cred->sec |= BIT(WIFI_SECURITY_WPA3PSK_T); } if (tb[CRED_D_BSTA]) { -- GitLab