From 99e58db1520b2427683aa4cc6e25da602f9b1bea Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Fri, 20 Jan 2017 06:49:40 +0100 Subject: [PATCH] wiphy: Add utility to check if bss ciphers compatible Move the BSS's supported ciphers checks from network_bss_select to a new function in wiphy.c so we can reuse it in device.c. --- src/network.c | 17 +++++------------ src/wiphy.c | 24 ++++++++++++++++++++++++ src/wiphy.h | 2 ++ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/network.c b/src/network.c index 4b084cca..ed947a2f 100644 --- a/src/network.c +++ b/src/network.c @@ -483,22 +483,15 @@ struct scan_bss *network_bss_select(struct network *network) case SECURITY_PSK: case SECURITY_8021X: - /* Pick the first bss that advertises any cipher we support. */ + /* + * Pick the first bss that advertises ciphers compatible with + * the wiphy. + */ for (bss_entry = l_queue_get_entries(bss_list); bss_entry; bss_entry = bss_entry->next) { struct scan_bss *bss = bss_entry->data; - struct ie_rsn_info rsn; - memset(&rsn, 0, sizeof(rsn)); - scan_bss_get_rsn_info(bss, &rsn); - - if (rsn.mfpr && !wiphy_select_cipher(wiphy, - rsn.group_management_cipher)) - continue; - - if (wiphy_select_cipher(wiphy, rsn.pairwise_ciphers) && - wiphy_select_cipher(wiphy, - rsn.group_cipher)) + if (wiphy_can_connect(wiphy, bss)) return bss; } diff --git a/src/wiphy.c b/src/wiphy.c index cd546504..9eaab8fb 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -120,6 +120,30 @@ uint32_t wiphy_get_supported_bands(struct wiphy *wiphy) return scan_freq_set_get_bands(wiphy->supported_freqs); } +bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss) +{ + struct ie_rsn_info rsn_info; + int r; + + memset(&rsn_info, 0, sizeof(rsn_info)); + r = scan_bss_get_rsn_info(bss, &rsn_info); + + if (r == 0) { + if (!wiphy_select_cipher(wiphy, rsn_info.pairwise_ciphers)) + return false; + + if (!wiphy_select_cipher(wiphy, rsn_info.group_cipher)) + return false; + + if (rsn_info.mfpr && !wiphy_select_cipher(wiphy, + rsn_info.group_management_cipher)) + return false; + } else if (r != -ENOENT) + return false; + + return true; +} + static void wiphy_print_basic_info(struct wiphy *wiphy) { uint32_t bands; diff --git a/src/wiphy.h b/src/wiphy.h index 961e6e43..d3297097 100644 --- a/src/wiphy.h +++ b/src/wiphy.h @@ -24,6 +24,7 @@ #include struct wiphy; +struct scan_bss; enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, uint16_t mask); @@ -32,6 +33,7 @@ struct wiphy *wiphy_find(int wiphy_id); const char *wiphy_get_path(struct wiphy *wiphy); uint32_t wiphy_get_supported_bands(struct wiphy *wiphy); +bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss); bool wiphy_init(struct l_genl_family *in); bool wiphy_exit(void);