From: Abhishek Sansanwal Date: Thu, 31 Aug 2017 07:04:24 +0000 (+0530) Subject: Request Bssid scan only when wifi is deactivated X-Git-Tag: submit/tizen_4.0/20170906.010245~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa9eb40df24f5530129424c069d2b9dfa886b532;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Request Bssid scan only when wifi is deactivated 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 Change-Id: Iebb4a37fe1e63eb7491a4b770a2993c5407949d9 --- diff --git a/include/network_error.h b/include/network_error.h index 447b3a7..56e437b 100755 --- a/include/network_error.h +++ b/include/network_error.h @@ -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 diff --git a/include/network_interface.h b/include/network_interface.h index 7db48fe..0a818e4 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -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); diff --git a/src/network_dbus.c b/src/network_dbus.c index 959d9f4..1aa88bb 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -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 diff --git a/src/network_interface.c b/src/network_interface.c index 84b2f4e..c39c0c8 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -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]", diff --git a/src/network_signal.c b/src/network_signal.c index 62339c1..e556a60 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -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__; diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 828c890..d78b669 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -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);