Request Bssid scan only when wifi is deactivated 02/147802/1
authorAbhishek Sansanwal <abhishek.s94@samsung.com>
Thu, 31 Aug 2017 07:04:24 +0000 (12:34 +0530)
committertaesub kim <taesub.kim@samsung.com>
Tue, 5 Sep 2017 23:49:32 +0000 (08:49 +0900)
Description: When wifi is in activated state perform a
normal scan. In case of deactivated wifi state, perform
a bssid scan.

Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Change-Id: Iebb4a37fe1e63eb7491a4b770a2993c5407949d9

include/network_error.h
include/network_interface.h
src/network_dbus.c
src/network_interface.c
src/network_signal.c
src/wifi_internal.c

index 447b3a7d0b46554ea8044fa08cf47fa1d80ca7a0..56e437b3d512c1171babae65d81e12519c4597a2 100755 (executable)
@@ -67,6 +67,7 @@ typedef enum {
        NET_ERR_FAIL_TDLS_DISCOVER = -697,
        NET_ERR_FAIL_TDLS_DISCONNECT = -696,
        NET_ERR_FAIL_TDLS_CONNECT = -695,
+       NET_ERR_FAIL_DEVICE_BUSY = -694,
 } net_err_e;
 
 #ifdef __cplusplus
index 7db48fe185d0e6ccde4b0ddf93e0b669e4e1d165..0a818e4d4b0e5ca7a4e99d61c459423b88f895df 100755 (executable)
@@ -246,7 +246,7 @@ int net_get_wifi_state(net_wifi_state_e *current_state);
 int net_init_profile_info(net_profile_info_s *ProfInfo);
 int net_specific_scan_wifi(const char *ssid);
 int net_get_wps_pin(char **wps_pin);
-int net_bssid_scan_wifi(void);
+int net_bssid_scan_wifi(int activated);
 int net_wifi_get_passpoint(int *enable);
 int net_wifi_set_passpoint(int enable);
 int net_wifi_get_scan_state(int *scan_state);
index 959d9f44e3c165042beba691f06fb298f4a46e92..1aa88bb90865bda36813c5bdcc8673e1dcebd9f2 100755 (executable)
@@ -38,6 +38,8 @@ static int __net_error_string_to_enum(const char *error)
 
        if (NULL != strstr(error, "NoReply"))
                return NET_ERR_TIME_OUT;
+       else if (NULL != strstr(error, "Device or resource busy"))
+               return NET_ERR_FAIL_DEVICE_BUSY;
        else if (NULL != strstr(error, "Failed"))
                return NET_ERR_UNKNOWN;
        else if (NULL != strstr(error, "UnknownMethod"))
@@ -341,6 +343,60 @@ done:
        __NETWORK_FUNC_EXIT__;
 }
 
+static void __net_bssid_scan_reply(GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       WIFI_LOG(WIFI_INFO, "__net_bssid_scan_reply() called");
+
+       net_event_info_s event_data = { 0, };
+       network_request_table_s *bssid_scan_info =
+                       &request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN];
+
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       net_err_e Error = NET_ERR_NONE;
+
+       conn = G_DBUS_CONNECTION(source_object);
+       g_dbus_connection_call_finish(conn, res, &error);
+       if (error != NULL) {
+               Error = __net_error_string_to_enum(error->message);
+               g_error_free(error);
+       }
+
+       if (Error == NET_ERR_NONE)
+               goto done;
+
+       WIFI_LOG(WIFI_ERROR, "Bssid scan failed[%d]", Error);
+
+       /* Show scan list even if device is in association state */
+       if (bssid_scan_info->flag == TRUE && Error == NET_ERR_FAIL_DEVICE_BUSY) {
+               memset(&request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN],
+                               0, sizeof(network_request_table_s));
+
+
+               event_data.Event = NET_EVENT_WIFI_BSSID_SCAN_IND;
+               WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_WIFI_BSSID_SCAN_IND[%s]",
+                               _net_print_error(event_data.Error));
+               event_data.Error = NET_ERR_NONE;
+               event_data.Datalength = 0;
+               event_data.Data = NULL;
+
+               _net_client_callback(&event_data);
+       } else {
+               _net_dbus_pending_call_unref();
+
+               __NETWORK_FUNC_EXIT__;
+               return;
+       }
+
+done:
+       _net_dbus_pending_call_unref();
+
+
+       __NETWORK_FUNC_EXIT__;
+}
+
 static void __net_close_connection_reply(GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
        __NETWORK_FUNC_ENTER__;
@@ -716,7 +772,7 @@ int _net_dbus_scan_request(void)
        Error = _net_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
                        CONNMAN_WIFI_TECHNOLOGY_PREFIX,
                        CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL,
-                       DBUS_REPLY_TIMEOUT, NULL);
+                       DBUS_REPLY_TIMEOUT, __net_bssid_scan_reply);
 
        if (Error == NET_ERR_IN_PROGRESS)
                Error = NET_ERR_NONE; //LCOV_EXCL_LINE
index 84b2f4ea2873ed72b4ea5af177d58211b4d3db26..c39c0c895489862e69706be3d1281c6a95beaf24 100755 (executable)
@@ -1410,7 +1410,7 @@ int net_specific_scan_wifi(const char *ssid)
 }
 
 //LCOV_EXCL_START
-int net_bssid_scan_wifi(void)
+int net_bssid_scan_wifi(int activated)
 {
        __NETWORK_FUNC_ENTER__;
 
@@ -1423,6 +1423,9 @@ int net_bssid_scan_wifi(void)
        }
 
        if (_net_dbus_is_pending_call_used() == TRUE) {
+               if (request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE)
+                       return NET_ERR_IN_PROGRESS;
+
                WIFI_LOG(WIFI_ERROR, "pending call in progress");
                __NETWORK_FUNC_EXIT__;
                return NET_ERR_INVALID_OPERATION;
@@ -1430,7 +1433,11 @@ int net_bssid_scan_wifi(void)
 
        request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag = TRUE;
 
-       Error = _net_dbus_bssid_scan_request();
+       if (activated == 0)
+               Error = _net_dbus_bssid_scan_request();
+       else
+               Error = _net_dbus_scan_request();
+
        if (Error != NET_ERR_NONE) {
                WIFI_LOG(WIFI_ERROR,
                                "_net_dbus_bssid_scan_request() failed. Error [%s]",
index 62339c1489f4e7d67e5e25287fb0ec32d58113e4..e556a60998ed4da34269ca9f04dbbaea2e055446 100755 (executable)
@@ -41,6 +41,8 @@ static __thread guint gdbus_conn_subscribe_id_netconfig = 0;
 static __thread int net_dpm_wifi_state = -1;
 static __thread int net_dpm_wifi_profile_state = -1;
 
+static int __net_dbus_get_bssid_list();
+
 //LCOV_EXCL_START
 static int string2state(const char *state)
 {
@@ -738,6 +740,13 @@ static int __net_handle_scan_done(GVariant *param)
                _net_dbus_pending_call_unref();
                event_data.Event = NET_EVENT_WIFI_MULTI_SCAN_IND;
 
+       } else if (request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE) {
+
+               _net_dbus_pending_call_unref();
+               WIFI_LOG(WIFI_INFO, "BSSID Scan Completed");
+               __net_dbus_get_bssid_list();
+               return NET_ERR_NONE;
+
        } else if (request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE) {
                memset(&request_table[NETWORK_REQUEST_TYPE_SCAN], 0,
                                sizeof(network_request_table_s));
@@ -1168,6 +1177,28 @@ static int __net_get_tech_states(GVariant *msg, net_state_type_e *state_table)
        return Error;
 }
 
+static int __net_dbus_get_bssid_list()
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+
+       message = _net_invoke_dbus_method(NETCONFIG_SERVICE,
+                       NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
+                       "GetBssidList", NULL, &Error);
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get bssid list");
+               goto done;
+       }
+
+       g_variant_unref(message);
+
+done:
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 static int __net_dbus_get_technology_states(net_state_type_e *state_table)
 {
        __NETWORK_FUNC_ENTER__;
index 828c8902516283498f95007ff78e339fd68df729..d78b669b40c5ca805bb07a4bf11b3c8c690701b1 100755 (executable)
@@ -1569,7 +1569,19 @@ int _wifi_bssid_scan_request(wifi_manager_h wifi,
                wifi_manager_bssid_scan_finished_cb callback, void *user_data)
 {
        int rv;
-       rv = net_bssid_scan_wifi();
+       wifi_manager_device_state_e device_state;
+       int activated = -1;
+
+       rv = _wifi_get_wifi_device_state(&device_state);
+       if (rv == WIFI_MANAGER_ERROR_NONE) {
+               if (WIFI_MANAGER_DEVICE_STATE_DEACTIVATED == device_state)
+                       activated = 0;
+               else
+                       activated = 1;
+       }
+
+       WIFI_LOG(WIFI_INFO, "Activated: %d", activated);
+       rv = net_bssid_scan_wifi(activated);
 
        if (rv == NET_ERR_ACCESS_DENIED) {
                WIFI_LOG(WIFI_ERROR, "Access denied");
@@ -1851,11 +1863,6 @@ int _wifi_foreach_found_bssid_ap(wifi_manager_found_ap_cb callback, void *user_d
        int rv;
        GSList *list;
 
-       if ((int)g_slist_length(bss_profile_iterator) == 0) {
-               WIFI_LOG(WIFI_WARN, "No AP found with bss info !");
-               return WIFI_MANAGER_ERROR_OPERATION_FAILED;
-       }
-
        for (list = bss_profile_iterator; list; list = list->next) {
                net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
                rv = callback((wifi_manager_ap_h)prof_info, user_data);