From 15be3fab3c586e9c4d743c39e82a3371f340b76b Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Tue, 1 Nov 2022 12:30:29 +0900 Subject: [PATCH] DA: Fix netlink scan logic 1. Modify the wrong routine for netlink scan 2. Fix the nl_recvmsg error case. 3. Add pmf_required field Change-Id: I5ef5e5892e0bd0fa4d5af9c61df90ec356cfc8ff Signed-off-by: Jaehyun Kim --- include/wifi-netlink-scan.h | 1 + src/wifi-netlink-scan.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/wifi-netlink-scan.h b/include/wifi-netlink-scan.h index a926dd2..d4e281b 100755 --- a/include/wifi-netlink-scan.h +++ b/include/wifi-netlink-scan.h @@ -58,6 +58,7 @@ struct bss_scan_info_t { int signal; int security_type; int encryption_type; + int pmf_required; }; struct netconfig_netlink_scan_results { diff --git a/src/wifi-netlink-scan.c b/src/wifi-netlink-scan.c index 409534a..a02c9a7 100755 --- a/src/wifi-netlink-scan.c +++ b/src/wifi-netlink-scan.c @@ -61,6 +61,7 @@ void __netconfig_notify_netlink_scan_done(const char *interface_name) const char *prop_vsie_list = "vsie_list"; const char *prop_sec = "security"; const char *prop_enc = "encryption"; + const char *prop_pmf = "pmf"; bss_info_list = g_slist_sort(bss_info_list, __netconfig_compare_bss_by_rssi); @@ -76,6 +77,7 @@ void __netconfig_notify_netlink_scan_done(const char *interface_name) int signal = (int)bss_info->signal; int sec_type = (int)bss_info->security_type; int enc_type = (int)bss_info->encryption_type; + int pmf_required = (int)bss_info->pmf_required; g_variant_builder_add(builder, "{sv}", prop_ssid, g_variant_new_string(ssid)); g_variant_builder_add(builder, "{sv}", prop_bssid, g_variant_new_string(bssid)); @@ -108,6 +110,7 @@ void __netconfig_notify_netlink_scan_done(const char *interface_name) g_variant_builder_add(builder, "{sv}", prop_sec, g_variant_new_int32(sec_type)); g_variant_builder_add(builder, "{sv}", prop_enc, g_variant_new_int32(enc_type)); + g_variant_builder_add(builder, "{sv}", prop_pmf, g_variant_new_int32(pmf_required)); } } @@ -136,6 +139,8 @@ static int finish_handler(struct nl_msg *msg, void *user_data) { int *ret = user_data; *ret = 0; + + DBG(""); return NL_SKIP; } @@ -144,7 +149,9 @@ static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, { int *ret = user_data; *ret = err->error; - return NL_SKIP; + + DBG(""); + return NL_STOP; } static int no_seq_check(struct nl_msg *msg, void *user_data) @@ -268,7 +275,8 @@ typedef enum { static unsigned char ms_oui[3] = { 0x00, 0x50, 0xf2 }; static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac }; -static void __netconfig_get_security(unsigned char *bss_element, int length, wifi_security_type_e *sec_type, wifi_encryption_type_e *enc_type) +static void __netconfig_get_security(unsigned char *bss_element, int length, + wifi_security_type_e *sec_type, wifi_encryption_type_e *enc_type, int *pmf_required) { int i; unsigned char *data; @@ -349,6 +357,8 @@ static void __netconfig_get_security(unsigned char *bss_element, int length, wif if (t_data[3] == 1 || t_data[3] == 3 || t_data[3] == 5) { // 1 : IEEE 802.1X, 3 : FT/IEEE 802.1X, 5 : IEEE 802.1X/SHA-256 *sec_type = WIFI_SECURITY_TYPE_EAP; } else if (t_data[3] == 2 || t_data[3] == 4 || t_data[3] == 6) { // 2 : PSK, 4 : FT/PSK, 6 : PSK/SHA-256 + if (t_data[3] == 6) + *pmf_required = 1; if (*sec_type != WIFI_SECURITY_TYPE_WPA2_PSK) *sec_type = WIFI_SECURITY_TYPE_WPA_PSK; } @@ -418,6 +428,8 @@ static void __netconfig_get_security(unsigned char *bss_element, int length, wif if (t_data[3] == 1 || t_data[3] == 3 || t_data[3] == 5) { // 1 : IEEE 802.1X, 3 : FT/IEEE 802.1X, 5 : IEEE 802.1X/SHA-256 *sec_type = WIFI_SECURITY_TYPE_EAP; } else if (t_data[3] == 2 || t_data[3] == 4 || t_data[3] == 6) { // 2 : PSK, 4 : FT/PSK, 6 : PSK/SHA-256 + if (t_data[3] == 6) + *pmf_required = 1; *sec_type = WIFI_SECURITY_TYPE_WPA2_PSK; ieee80211_psk = true; } else if (t_data[3] == 8) { // Add SAE security type for netlink scan @@ -507,6 +519,8 @@ static int __netconfig_netlink_scan_cb(struct nl_msg *msg, void *user_data) [NL80211_BSS_SIGNAL_MBM] = {.type = NLA_U32}, }; + int pmf_needed = 0; + /** Parse nl message and check error. */ nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (!tb[NL80211_ATTR_BSS]) { @@ -532,7 +546,7 @@ static int __netconfig_netlink_scan_cb(struct nl_msg *msg, void *user_data) } } __netconfig_get_security(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]), - nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), &sec_type, &enc_type); + nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), &sec_type, &enc_type, &pmf_needed); if (wep_check && sec_type == WIFI_SECURITY_TYPE_NONE) { sec_type = WIFI_SECURITY_TYPE_WEP; @@ -576,9 +590,10 @@ static int __netconfig_netlink_scan_cb(struct nl_msg *msg, void *user_data) bss_info->security_type = sec_type; bss_info->encryption_type = enc_type; - DBG("%s %d %d %s %d %d ", bss_info->bssid, bss_info->freq, + bss_info->pmf_required = pmf_needed; + SECURE_LOGD("%s %d %d %s %d %d %d ", bss_info->bssid, bss_info->freq, bss_info->signal, bss_info->ssid, bss_info->security_type, - bss_info->encryption_type); + bss_info->encryption_type, bss_info->pmf_required); if (bss_info->ssid[0] == '\0') g_free(bss_info); @@ -723,6 +738,12 @@ static int __netconfig_trigger_netlink_scan(struct nl_sock *socket, } } + if (err < 0) { + DBG("error code = %d", err); + ret = -1; + goto out; + } + while (!results.done) { ret = nl_recvmsgs(socket, cb); #if !defined TIZEN_WEARABLE -- 2.34.1