commit 712a92cc4c43428f04a252d42f5c6e1d860d1a6a
parent 5bfbdd5a01ad05eef54ac41dcdc2104d93ab4bf8
Author: Denis Kenzior <denkenz@gmail.com>
Date: Thu, 15 Nov 2018 11:37:20 -0600
network: Simplify is_rsn logic
In the current version SECURITY_PSK was handled inside the is_rsn block
while the SECURITY_8021X was off in its own block. This was weird and a
bit misleading. Simplify the code flow through the use of a goto and
decrease the nesting level.
Also optimize out unnecessary use of scan_bss_get_rsn_info
Diffstat:
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/src/network.c b/src/network.c
@@ -512,6 +512,7 @@ int network_autoconnect(struct network *network, struct scan_bss *bss)
struct station *station = network->station;
struct wiphy *wiphy = station_get_wiphy(station);
enum security security = network_get_security(network);
+ struct ie_rsn_info rsn;
bool is_autoconnectable;
bool is_rsn;
int ret;
@@ -544,27 +545,24 @@ int network_autoconnect(struct network *network, struct scan_bss *bss)
if (!is_autoconnectable)
goto close_settings;
- if (is_rsn) {
- struct ie_rsn_info rsn;
-
- memset(&rsn, 0, sizeof(rsn));
- scan_bss_get_rsn_info(bss, &rsn);
+ if (!is_rsn)
+ goto done;
- if (!wiphy_select_cipher(wiphy, rsn.pairwise_ciphers) ||
- !wiphy_select_cipher(wiphy, rsn.group_cipher)) {
- l_debug("Cipher mis-match");
- ret = -ENETUNREACH;
- goto close_settings;
- }
+ memset(&rsn, 0, sizeof(rsn));
+ scan_bss_get_rsn_info(bss, &rsn);
- if (security == SECURITY_PSK) {
- ret = network_load_psk(network, bss_is_sae(bss));
- if (ret < 0)
- goto close_settings;
- }
+ if (!wiphy_select_cipher(wiphy, rsn.pairwise_ciphers) ||
+ !wiphy_select_cipher(wiphy, rsn.group_cipher)) {
+ l_debug("Cipher mis-match");
+ ret = -ENETUNREACH;
+ goto close_settings;
}
- if (security == SECURITY_8021X) {
+ if (security == SECURITY_PSK) {
+ ret = network_load_psk(network, __bss_is_sae(bss, &rsn));
+ if (ret < 0)
+ goto close_settings;
+ } else if (security == SECURITY_8021X) {
struct l_queue *missing_secrets = NULL;
ret = eap_check_settings(network->settings, network->secrets,
@@ -582,6 +580,7 @@ int network_autoconnect(struct network *network, struct scan_bss *bss)
goto close_settings;
}
+done:
return __station_connect_network(station, network, bss);
close_settings: