From: Mayank Haarit Date: Fri, 20 Apr 2018 15:41:15 +0000 (+0530) Subject: wifi-manager: Add support for returning APs information X-Git-Tag: accepted/tizen/unified/20180425.062306~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F176677%2F3;p=platform%2Fcore%2Fapi%2Fwifi-manager.git wifi-manager: Add support for returning APs information This patch provides list of bssid, signal strength and frequency of APs having same SSID and security type. Change-Id: I1545a9e8818ee4956c5062f86cd99ffcc5dbf9b6 Signed-off-by: Mayank Haarit --- diff --git a/include/network_interface.h b/include/network_interface.h index a0a3fd0..ad86ba8 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -148,6 +148,12 @@ typedef enum { } net_vsie_frames_e; typedef struct { + char bssid[18]; + int strength; + int frequency; +} net_profile_bssid_list_s; + +typedef struct { char ProfileName[NET_PROFILE_NAME_LEN_MAX+1]; /** Profile name */ net_state_type_e ProfileState; /** Service state */ char essid[NET_WLAN_ESSID_LEN+1]; /** ESSID */ @@ -171,6 +177,7 @@ typedef struct { GSList *vsie_list; /** List of Vendor Specific Information Element of AP*/ int assoc_status_code; /** Supplicant WiFi Association Status Code */ char country_code[NET_WLAN_COUNTRY_CODE_LEN]; /** Country code received from AP */ + GSList *bssid_list; /** List if BSSID, strength and frequency of AP **/ } net_profile_info_s; typedef struct { diff --git a/src/network_interface.c b/src/network_interface.c index 1fbbf8b..8b04e6b 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -1062,6 +1062,34 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof if (value != NULL) g_strlcpy(ProfInfo->country_code, value, NET_WLAN_COUNTRY_CODE_LEN); + } else if (g_strcmp0(key, "BSSID.List") == 0) { + GVariantIter *iter_sub = NULL; + net_profile_bssid_list_s *bssid_list = NULL; + g_variant_get(var, "a{sv}", &iter_sub); + + while (g_variant_iter_loop(iter_sub, "{sv}", &value, &var)) { + if (g_strcmp0(value, "BSSID") == 0) { + bssid_list = (net_profile_bssid_list_s *)g_try_malloc0(sizeof(net_profile_bssid_list_s)); + + if (bssid_list) { + value = g_variant_get_string(var, NULL); + + if (value != NULL) + g_strlcpy(bssid_list->bssid, value, 18); + else + WIFI_LOG(WIFI_ERROR, "Value is empty"); + } else { + WIFI_LOG(WIFI_ERROR, "Failed to allocate memory."); + break; + } + } else if (bssid_list && g_strcmp0(value, "Strength") == 0) { + bssid_list->strength = (int)g_variant_get_uint16(var); + } else if (bssid_list && g_strcmp0(value, "Frequency") == 0) { + bssid_list->frequency = (int)g_variant_get_uint16(var); + ProfInfo->bssid_list = g_slist_append(ProfInfo->bssid_list, bssid_list); + } + } + g_variant_iter_free(iter_sub); } else Error = __net_extract_common_info(key, var, ProfInfo); } diff --git a/src/wifi_ap.c b/src/wifi_ap.c index 198fed4..0761873 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -1582,6 +1582,37 @@ EXPORT_API int wifi_manager_ap_get_countrycode(wifi_manager_ap_h ap, return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_foreach_found_bssid(wifi_manager_ap_h ap, + wifi_manager_found_bssid_cb callback, void *user_data) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (_wifi_check_ap_validity(ap) == false || callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter\n"); + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + net_profile_info_s *profile_info = ap; + + bool rv; + GSList *list; + for (list = profile_info->bssid_list; list; list = list->next) { + net_profile_bssid_list_s *bssid_list = (net_profile_bssid_list_s *)list->data; + + rv = callback((const char *)bssid_list->bssid, (bssid_list->strength - 120), bssid_list->frequency, user_data); + 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; +} + /* Wi-Fi security information ************************************************/ EXPORT_API int wifi_manager_ap_get_security_type(wifi_manager_ap_h ap, wifi_manager_security_type_e *type) diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index 0d824ac..fdb42f8 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -1037,6 +1037,12 @@ static bool __test_vendor_specific_callback(unsigned char *vsie_bytes, int vsie_ return true; } +static bool __test_found_bssid_list_callback(const char *bssid, int rssi, int freq, void *user_data) +{ + printf("-> BSSID : %s, RSSI : %d, Frequency : %d\n", bssid, rssi, freq); + return true; +} + static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user_data) { int rv, address_type = 0; @@ -1074,6 +1080,9 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user } else printf("Fail to get BSSID\n"); + if (wifi_manager_foreach_found_bssid(ap, __test_found_bssid_list_callback, NULL) != WIFI_MANAGER_ERROR_NONE) + printf("Fail to get BSSID list data\n"); + if (wifi_manager_ap_get_rssi(ap, &int_value) == WIFI_MANAGER_ERROR_NONE) printf("RSSI : %d\n", int_value); else