From 303d549f4f23f45011e2b6534fd42e411776d5e7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 2 Jan 2020 15:03:39 +0100 Subject: libnm: cleanup conditions by moving pre-check in nm_utils_security_valid() Do the switch based on the type on the top level, don't split the conditions to first handle some cases, and some later. --- libnm-core/nm-utils.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 7d6e159b84..f5da87b7c5 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -1166,21 +1166,10 @@ nm_utils_security_valid (NMUtilsSecurityType type, NM80211ApSecurityFlags ap_wpa, NM80211ApSecurityFlags ap_rsn) { - if (!have_ap) { - if (type == NMU_SEC_NONE) - return TRUE; - if ( (type == NMU_SEC_STATIC_WEP) - || ((type == NMU_SEC_DYNAMIC_WEP) && !adhoc) - || ((type == NMU_SEC_LEAP) && !adhoc)) { - if (wifi_caps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104)) - return TRUE; - return FALSE; - } - } - switch (type) { case NMU_SEC_NONE: - g_assert (have_ap); + if (!have_ap) + return TRUE; if (ap_flags & NM_802_11_AP_FLAGS_PRIVACY) return FALSE; if ( ap_wpa @@ -1192,7 +1181,11 @@ nm_utils_security_valid (NMUtilsSecurityType type, return FALSE; /* fall through */ case NMU_SEC_STATIC_WEP: - g_assert (have_ap); + if (!have_ap) { + if (wifi_caps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104)) + return TRUE; + return FALSE; + } if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) return FALSE; if ( ap_wpa @@ -1206,7 +1199,11 @@ nm_utils_security_valid (NMUtilsSecurityType type, case NMU_SEC_DYNAMIC_WEP: if (adhoc) return FALSE; - g_assert (have_ap); + if (!have_ap) { + if (wifi_caps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104)) + return TRUE; + return FALSE; + } if ( ap_rsn || !(ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) return FALSE; -- cgit v1.2.1