From fdb73a8c00e44af522cadb2c93a68ba8df5d8ddb Mon Sep 17 00:00:00 2001 From: Mayank Haarit Date: Wed, 16 May 2018 21:34:10 +0530 Subject: [PATCH] wifi-manager: To get vsie list of APs This patch add the funtionality : 1) To get the vsie list of APs during netlink scan results. 2) Added common function to clear internal GSList of net_profile_info_s. Change-Id: Iac37300311cb8069a6b459107a9f8afd729ae250 Signed-off-by: Mayank Haarit --- include/network_interface.h | 2 +- src/network_signal.c | 47 +++++++++++++++++++++++++++++++++++++-------- src/wifi_ap.c | 4 ---- src/wifi_internal.c | 41 +++++++++++++++++++++++++++++++++++++++ test/wifi_manager_test.c | 3 +++ 5 files changed, 84 insertions(+), 13 deletions(-) diff --git a/include/network_interface.h b/include/network_interface.h index ad86ba8..8acf82e 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -215,7 +215,7 @@ typedef struct { typedef struct { char ssid[NET_WLAN_ESSID_LEN + 1]; char bssid[NET_WLAN_BSSID_LEN + 1]; - char vsie[NET_WLAN_MAX_VSIE_LEN + 1]; + GSList *vsie_list; int freq; int rssi; int security_type; diff --git a/src/network_signal.c b/src/network_signal.c index b4c3faf..2078a40 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -426,7 +426,7 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param) GSList *bss_info_list = NULL; const gchar *ssid = NULL; const gchar *bssid = NULL; - const gchar *vsie = NULL; + GSList *vsie_list = NULL; int freq = 0; int rssi = 0; int sec_type = 0; @@ -460,8 +460,31 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param) } else if (g_strcmp0(key, "encryption") == 0) { enc_type = g_variant_get_int32(value); encryption_found = TRUE; - } else if (g_strcmp0(key, "vsie") == 0) { - vsie = g_variant_get_string(value, NULL); + } else if (g_strcmp0(key, "vsie_list") == 0) { + GVariantIter *iter_sub = NULL; + const unsigned char *vsie_bytes = NULL; + unsigned char *vsie = NULL; + GVariant *value_sub; + gchar *key_sub = NULL; + gsize size; + g_variant_get(value, "a{sv}", &iter_sub); + vsie_list = NULL; + + while (g_variant_iter_loop(iter_sub, "{sv}", &key_sub, &value_sub)) { + vsie_bytes = g_variant_get_fixed_array(value_sub, &size, sizeof(guchar)); + + if (vsie_bytes) { + vsie = (unsigned char *)g_try_malloc0(size); + + if (vsie) { + memcpy(vsie, vsie_bytes, size); + vsie_list = g_slist_append(vsie_list, vsie); + } else + WIFI_LOG(WIFI_ERROR, "Failed to allocate memory."); + } + } + + g_variant_iter_free(iter_sub); vsie_found = TRUE; } @@ -470,8 +493,20 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param) freq_found == TRUE && rssi_found == TRUE && vsie_found == TRUE) { net_netlink_scan_bss_info_s *bss = NULL; bss = g_try_new0(net_netlink_scan_bss_info_s, 1); + if (bss == NULL) { WIFI_LOG(WIFI_ERROR, "Memory allocation error"); + GSList *list_sub = bss_info_list; + g_slist_free_full(vsie_list, g_free); + + for (list_sub = bss_info_list; list_sub; list_sub = list_sub->next) { + net_netlink_scan_bss_info_s *ap_sub = (net_netlink_scan_bss_info_s *)list_sub->data; + + if (ap_sub->vsie_list) { + g_slist_free_full(ap_sub->vsie_list, g_free); + ap_sub->vsie_list = NULL; + } + } g_slist_free_full(bss_info_list, g_free); g_variant_unref(value); @@ -491,11 +526,7 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param) "Security type : %d, Encryption type: %d", bssid, freq, rssi, ssid, sec_type, enc_type); - if (strncmp(vsie, "dd", 2) == 0) { - WIFI_LOG(WIFI_INFO, "vsie: %s", vsie); - g_strlcpy(bss->vsie, vsie, strlen(vsie)+1); - } - + bss->vsie_list = vsie_list; bss_info_list = g_slist_append(bss_info_list, bss); ssid_found = bssid_found = freq_found = rssi_found = vsie_found = FALSE; diff --git a/src/wifi_ap.c b/src/wifi_ap.c index 0761873..7aea86f 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -580,8 +580,6 @@ EXPORT_API int wifi_manager_ap_foreach_vsie(wifi_manager_ap_h ap, if (rv == false) break; } - g_slist_free_full(profile_info->vsie_list, g_free); - profile_info->vsie_list = NULL; __NETWORK_CAPI_FUNC_EXIT__; return WIFI_MANAGER_ERROR_NONE; @@ -1606,8 +1604,6 @@ EXPORT_API int wifi_manager_foreach_found_bssid(wifi_manager_ap_h ap, if (rv == false) break; } - g_slist_free_full(profile_info->bssid_list, g_free); - profile_info->bssid_list = NULL; __NETWORK_CAPI_FUNC_EXIT__; return WIFI_MANAGER_ERROR_NONE; diff --git a/src/wifi_internal.c b/src/wifi_internal.c index a1a07c2..85c0e94 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -279,12 +279,33 @@ gchar *_wifi_eap_auth_type_to_string(wifi_manager_eap_auth_type_e eap_auth_type) } return type; } + +static void __clear_profile_internal_list(GSList **iterator) +{ + GSList *list; + + for (list = *iterator; list; list = list->next) { + net_profile_info_s *prof_info = (net_profile_info_s *)list->data; + + if (prof_info->vsie_list) { + g_slist_free_full(prof_info->vsie_list, g_free); + prof_info->vsie_list = NULL; + } + + if (prof_info->bssid_list) { + g_slist_free_full(prof_info->bssid_list, g_free); + prof_info->bssid_list = NULL; + } + } +} + //LCOV_EXCL_STOP static void __clear_profile_list(GSList **iterator) { if (*iterator) { *iterator = g_slist_nth(*iterator, 0); + __clear_profile_internal_list(iterator); g_slist_free_full(*iterator, g_free); *iterator = NULL; } @@ -408,6 +429,26 @@ static void __update_netlink_scan_profile_iterator(GSList *bss_list) g_strlcpy(profile->essid, ap->ssid, NET_WLAN_ESSID_LEN+1); g_strlcpy(profile->bssid, ap->bssid, NET_MAX_MAC_ADDR_LEN+1); + + if (ap->vsie_list) { + GSList *list; + + for (list = ap->vsie_list; list; list = list->next) { + unsigned char *str = (unsigned char *)list->data; + unsigned char *vsie; + vsie = g_try_malloc0(str[1]+2); + + if (vsie) { + memcpy(vsie, str, str[1]+2); + profile->vsie_list = g_slist_append(profile->vsie_list, vsie); + } else + WIFI_LOG(WIFI_ERROR, "Failed to allocate memory."); + } + + g_slist_free_full(ap->vsie_list, g_free); + ap->vsie_list = NULL; + } + profile->frequency = (unsigned int)ap->freq; profile->Strength = 120 + ap->rssi; diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index fdb42f8..0252d6e 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -2682,6 +2682,9 @@ static bool __test_get_netlink_scan_list(wifi_manager_ap_h ap, void *user_data) break; } + if (wifi_manager_ap_foreach_vsie(ap, __test_vendor_specific_callback, NULL) != WIFI_MANAGER_ERROR_NONE) + printf("Fail to get vsie\n"); + g_free(bssid); g_free(essid); return true; -- 2.7.4