From ba9d968cfdfc95218646ba7b6d46f631482f1d80 Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Fri, 4 Jan 2019 12:23:57 +0530 Subject: [PATCH] Added parsing of netlink scan results for WEP encryption. Change-Id: I23adcb76555af77891728d70e7a513763928a75c Signed-off-by: Niraj Kumar Goit --- include/wifi-netlink-scan.h | 3 +++ src/wifi-netlink-scan.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/wifi-netlink-scan.h b/include/wifi-netlink-scan.h index 2dc4c92..c790392 100755 --- a/include/wifi-netlink-scan.h +++ b/include/wifi-netlink-scan.h @@ -37,6 +37,7 @@ extern "C" { #define NL80211_CMD_NEW_SCAN_RESULTS 34 #define NL80211_BSS_BSSID 1 #define NL80211_BSS_FREQUENCY 2 +#define NL80211_BSS_CAPABILITY 5 #define NL80211_BSS_INFORMATION_ELEMENTS 6 #define NL80211_BSS_SIGNAL_MBM 7 #define NL80211_BSS_MAX 15 @@ -46,6 +47,8 @@ extern "C" { #define NL80211_ATTR_SCAN_SSIDS 45 #define NL80211_ATTR_MAX 221 +#define WLAN_CAPABILITY_PRIVACY (1<<4) + struct bss_scan_info_t { char bssid[NETCONFIG_BSSID_LEN+1]; char ssid[NETCONFIG_SSID_LEN+1]; diff --git a/src/wifi-netlink-scan.c b/src/wifi-netlink-scan.c index 38098f1..97fb74c 100755 --- a/src/wifi-netlink-scan.c +++ b/src/wifi-netlink-scan.c @@ -472,12 +472,14 @@ static int __netconfig_netlink_scan_cb(struct nl_msg *msg, void *user_data) char ssid[NETCONFIG_SSID_LEN+1] = {0, }; wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE; wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_TYPE_NONE; + int wep_check = 0; GSList *vsie = NULL; struct nlattr *tb[NL80211_ATTR_MAX + 1]; struct nlattr *bss[NL80211_BSS_MAX + 1]; struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { [NL80211_BSS_FREQUENCY] = {.type = NLA_U32}, [NL80211_BSS_BSSID] = { }, + [NL80211_BSS_CAPABILITY] = {.type = NLA_U16}, [NL80211_BSS_INFORMATION_ELEMENTS] = { }, [NL80211_BSS_SIGNAL_MBM] = {.type = NLA_U32}, }; @@ -499,9 +501,21 @@ static int __netconfig_netlink_scan_cb(struct nl_msg *msg, void *user_data) __netconfig_macaddress_str(bssid, nla_data(bss[NL80211_BSS_BSSID])); __netconfig_found_ap(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]), nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), ssid); __netconfig_get_vsie(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]), nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), &vsie); + + if (bss[NL80211_BSS_CAPABILITY]) { + __u16 capa = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); + if (capa & WLAN_CAPABILITY_PRIVACY) { + wep_check = 1; + } + } __netconfig_get_security(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]), nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), &sec_type, &enc_type); + if (wep_check && sec_type == WIFI_SECURITY_TYPE_NONE) { + sec_type = WIFI_SECURITY_TYPE_WEP; + enc_type = WIFI_ENCRYPTION_TYPE_WEP; + } + if (sec_type == WIFI_SECURITY_TYPE_EAP) { g_slist_free_full(vsie, g_free); return NL_SKIP; -- 2.34.1