wifi-manager: Add support for returning APs information 77/176677/3
authorMayank Haarit <mayank.h@samsung.com>
Fri, 20 Apr 2018 15:41:15 +0000 (21:11 +0530)
committerMayank Haarit <mayank.h@samsung.com>
Fri, 20 Apr 2018 16:44:52 +0000 (22:14 +0530)
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 <mayank.h@samsung.com>
include/network_interface.h
src/network_interface.c
src/wifi_ap.c
test/wifi_manager_test.c

index a0a3fd0..ad86ba8 100755 (executable)
@@ -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 {
index 1fbbf8b..8b04e6b 100755 (executable)
@@ -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);
        }
index 198fed4..0761873 100755 (executable)
@@ -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)
index 0d824ac..fdb42f8 100755 (executable)
@@ -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