summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-01-02 15:03:39 +0100
committerThomas Haller <thaller@redhat.com>2020-01-07 22:01:01 +0100
commit303d549f4f23f45011e2b6534fd42e411776d5e7 (patch)
treea5aa82b55b0e4ab5b30d78839b0ad6a5fc8f63d3
parent4ecad2dda792db1a7a41ce71fc407f6af1deb3b5 (diff)
downloadNetworkManager-303d549f4f23f45011e2b6534fd42e411776d5e7.tar.gz
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.
-rw-r--r--libnm-core/nm-utils.c27
1 files 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;