From 67d0eb5ad402fbdfe0961727181a21d7d1e55b0b Mon Sep 17 00:00:00 2001 From: Milind Ramesh Murhekar Date: Mon, 3 Jul 2017 10:25:32 +0530 Subject: [PATCH] Add Support for bssid scan feature. Description: This patch adds the bssid scan feature to get the bss info from wpa_supplicant Change-Id: I64679d4f9b5177b66e40d8e9a3ba11d2a7da4629 Signed-off-by: Milind Ramesh Murhekar --- include/network_dbus.h | 2 +- include/network_interface.h | 6 +- include/network_internal.h | 4 +- include/wifi_internal.h | 6 ++ src/network_dbus.c | 14 ++--- src/network_interface.c | 14 ++--- src/network_internal.c | 2 +- src/network_signal.c | 22 ++++---- src/wifi_internal.c | 133 ++++++++++++++++++++++++++++++++++++++++++++ src/wifi_manager.c | 25 +++++++++ test/wifi_manager_test.c | 76 ++++++++++++++++++++++++- 11 files changed, 271 insertions(+), 33 deletions(-) diff --git a/include/network_dbus.h b/include/network_dbus.h index d6e7722..c78be3e 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -105,7 +105,7 @@ int _net_invoke_dbus_method_nonblock(const char *dest, const char *path, int _net_dbus_load_wifi_driver(gboolean wifi_picker_test); int _net_dbus_remove_wifi_driver(void); int _net_dbus_specific_scan_request(const char *ssid); -int _net_dbus_wps_scan_request(void); +int _net_dbus_bssid_scan_request(void); int _net_dbus_get_passpoint(int *enabled); int _net_dbus_set_passpoint(int enable); diff --git a/include/network_interface.h b/include/network_interface.h index 8264c1e..ec2c24c 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -62,7 +62,7 @@ typedef enum { NET_EVENT_WIFI_SPECIFIC_SCAN_IND, NET_EVENT_WIFI_WPS_RSP, NET_EVENT_WIFI_SCANNING_IND, - NET_EVENT_WIFI_WPS_SCAN_IND, + NET_EVENT_WIFI_BSSID_SCAN_IND, NET_EVENT_WIFI_TDLS_DISCOVERED_IND, NET_EVENT_WIFI_TDLS_CONNECTED_IND, NET_EVENT_WIFI_TDLS_DISCONNECTED_IND, @@ -183,7 +183,7 @@ typedef struct { char bssid[NET_WLAN_BSSID_LEN + 1]; int rssi; int mode; -} net_wps_scan_bss_info_s; +} net_bssid_scan_bss_info_s; typedef struct { net_event_e Event; /** CM Asynchronous event */ @@ -232,7 +232,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_wps_scan_wifi(void); +int net_bssid_scan_wifi(void); 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/include/network_internal.h b/include/network_internal.h index e21e695..86d5082 100755 --- a/include/network_internal.h +++ b/include/network_internal.h @@ -95,7 +95,7 @@ extern "C" { #define NETCONFIG_SIGNAL_POWERON_COMPLETED "PowerOnCompleted" #define NETCONFIG_SIGNAL_POWEROFF_COMPLETED "PowerOffCompleted" #define NETCONFIG_SIGNAL_SPECIFIC_SCAN_DONE "SpecificScanCompleted" -#define NETCONFIG_SIGNAL_WPS_SCAN_DONE "WpsScanCompleted" +#define NETCONFIG_SIGNAL_BSSID_SCAN_DONE "BssidScanCompleted" #define NETCONFIG_SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound" #define NETCONFIG_SIGNAL_TDLS_CONNECTED "TDLSConnect" #define NETCONFIG_SIGNAL_TDLS_DISCONNECTED "TDLSDisconnect" @@ -114,7 +114,7 @@ typedef enum { NETWORK_REQUEST_TYPE_WIFI_POWER, NETWORK_REQUEST_TYPE_ENROLL_WPS, NETWORK_REQUEST_TYPE_SPECIFIC_SCAN, - NETWORK_REQUEST_TYPE_WPS_SCAN, + NETWORK_REQUEST_TYPE_BSSID_SCAN, NETWORK_REQUEST_TYPE_SET_DEFAULT, NETWORK_REQUEST_TYPE_RESET_DEFAULT, NETWORK_REQUEST_TYPE_TDLS_DISCOVERY, diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 1b2b452..709ca49 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -92,6 +92,7 @@ typedef enum { WIFI_SCAN_REQUEST_CB, WIFI_SCAN_CHANGED_CB, WIFI_SPECIFIC_SCAN_CB, + WIFI_BSSID_SCAN_CB, WIFI_MANAGER_CONNECTION_STATE_CB, WIFI_ACTIVATED_CB, WIFI_DEACTIVATED_CB, @@ -148,6 +149,8 @@ typedef struct { void *scan_changed_user_data; wifi_manager_scan_finished_cb specific_scan_cb; void *specific_scan_user_data; + wifi_manager_bssid_scan_finished_cb bssid_scan_cb; + void *bssid_scan_user_data; wifi_manager_connection_state_changed_cb connection_state_cb; void *connection_state_user_data; wifi_manager_activated_cb activated_cb; @@ -209,6 +212,7 @@ int _wifi_get_hidden_aps(wifi_manager_h wifi, const char* essid, int _wifi_get_connected_profile(wifi_manager_ap_h *ap); int _wifi_foreach_found_ap(wifi_manager_found_ap_cb callback, void *user_data); int _wifi_foreach_found_specific_ap(wifi_manager_found_ap_cb callback, void *user_data); +int _wifi_foreach_found_bssid_ap(wifi_manager_found_ap_cb callback, void *user_data); int _wifi_open_profile(wifi_manager_h wifi, wifi_manager_ap_h ap_h, wifi_manager_connected_cb callback, void *user_data); @@ -229,6 +233,8 @@ int _wifi_connect_with_wps_pbc_without_ssid(wifi_manager_h wifi, int _wifi_connect_with_wps_pin_without_ssid(wifi_manager_h wifi, const char *pin, wifi_manager_connected_cb callback, void* user_data); int _wifi_cancel_wps(void); +int _wifi_bssid_scan_request(wifi_manager_h wifi, + wifi_manager_bssid_scan_finished_cb callback, void *user_data); /* WIFI Configuration */ bool _wifi_check_config_validity(wifi_manager_config_h config_h); diff --git a/src/network_dbus.c b/src/network_dbus.c index b5e5a42..16619cc 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -496,7 +496,7 @@ static void __net_specific_scan_wifi_reply(GObject *source_object, GAsyncResult __NETWORK_FUNC_EXIT__; } -static void __net_wps_scan_wifi_reply(GObject *source_object, GAsyncResult *res, gpointer user_data) +static void __net_bssid_scan_wifi_reply(GObject *source_object, GAsyncResult *res, gpointer user_data) { __NETWORK_FUNC_ENTER__; @@ -515,11 +515,11 @@ static void __net_wps_scan_wifi_reply(GObject *source_object, GAsyncResult *res, if (Error != NET_ERR_NONE) { WIFI_LOG(WIFI_ERROR, "WPS scan failed[%d]", Error); - if (request_table[NETWORK_REQUEST_TYPE_WPS_SCAN].flag == TRUE) { - memset(&request_table[NETWORK_REQUEST_TYPE_WPS_SCAN], + if (request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE) { + memset(&request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN], 0, sizeof(network_request_table_s)); - event_data.Event = NET_EVENT_WIFI_WPS_SCAN_IND; + event_data.Event = NET_EVENT_WIFI_BSSID_SCAN_IND; event_data.Datalength = 0; event_data.Data = NULL; event_data.Error = Error; @@ -1757,15 +1757,15 @@ int _net_dbus_specific_scan_request(const char *ssid) } //LCOV_EXCL_START -int _net_dbus_wps_scan_request(void) +int _net_dbus_bssid_scan_request(void) { __NETWORK_FUNC_ENTER__; net_err_e Error = NET_ERR_NONE; Error = _net_invoke_dbus_method_nonblock(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, - "RequestWpsScan", NULL, 6 * DBUS_REPLY_TIMEOUT, - __net_wps_scan_wifi_reply); + "RequestBssidScan", NULL, 6 * DBUS_REPLY_TIMEOUT, + __net_bssid_scan_wifi_reply); __NETWORK_FUNC_EXIT__; return Error; diff --git a/src/network_interface.c b/src/network_interface.c index 6bea83b..2d832fd 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -1406,7 +1406,7 @@ int net_specific_scan_wifi(const char *ssid) } //LCOV_EXCL_START -int net_wps_scan_wifi(void) +int net_bssid_scan_wifi(void) { __NETWORK_FUNC_ENTER__; @@ -1424,15 +1424,15 @@ int net_wps_scan_wifi(void) return NET_ERR_INVALID_OPERATION; } - request_table[NETWORK_REQUEST_TYPE_WPS_SCAN].flag = TRUE; + request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag = TRUE; - Error = _net_dbus_wps_scan_request(); + Error = _net_dbus_bssid_scan_request(); if (Error != NET_ERR_NONE) { WIFI_LOG(WIFI_ERROR, - "_net_dbus_wps_scan_request() failed. Error [%s]", + "_net_dbus_bssid_scan_request() failed. Error [%s]", _net_print_error(Error)); - memset(&request_table[NETWORK_REQUEST_TYPE_WPS_SCAN], 0, + memset(&request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN], 0, sizeof(network_request_table_s)); } @@ -1712,10 +1712,10 @@ int net_wifi_power_off(void) 0, sizeof(network_request_table_s)); } - if (request_table[NETWORK_REQUEST_TYPE_WPS_SCAN].flag == TRUE) { + if (request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE) { _net_dbus_pending_call_unref(); - memset(&request_table[NETWORK_REQUEST_TYPE_WPS_SCAN], + memset(&request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN], 0, sizeof(network_request_table_s)); } diff --git a/src/network_internal.c b/src/network_internal.c index 0e893d0..6e50744 100755 --- a/src/network_internal.c +++ b/src/network_internal.c @@ -365,7 +365,7 @@ void _net_client_callback(net_event_info_s *event_data) memcpy(client, event_data, sizeof(net_event_info_s)); if (event_data->Datalength > 0) { if (event_data->Event == NET_EVENT_WIFI_SPECIFIC_SCAN_IND || - event_data->Event == NET_EVENT_WIFI_WPS_SCAN_IND) { + event_data->Event == NET_EVENT_WIFI_BSSID_SCAN_IND) { client->Data = g_try_malloc0(sizeof(GSList)); if (client->Data == NULL) { g_free(client); diff --git a/src/network_signal.c b/src/network_signal.c index dab5e7f..cbc9e6d 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -251,15 +251,15 @@ static int __net_handle_wifi_specific_scan_rsp(GVariant *param) return NET_ERR_NONE; } -static int __net_handle_wps_scan_resp(GSList *bss_info_list) +static int __net_handle_bssid_scan_resp(GSList *bss_info_list) { __NETWORK_FUNC_ENTER__; int count = 0;; net_event_info_s event_data = { 0, }; - if (request_table[NETWORK_REQUEST_TYPE_WPS_SCAN].flag == TRUE) { - memset(&request_table[NETWORK_REQUEST_TYPE_WPS_SCAN], + if (request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE) { + memset(&request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN], 0, sizeof(network_request_table_s)); _net_dbus_pending_call_unref(); @@ -267,10 +267,10 @@ static int __net_handle_wps_scan_resp(GSList *bss_info_list) count = (int)g_slist_length(bss_info_list); WIFI_LOG(WIFI_INFO, "Received the signal: %s with total bss count = %d", - NETCONFIG_SIGNAL_WPS_SCAN_DONE, + NETCONFIG_SIGNAL_BSSID_SCAN_DONE, count); - event_data.Event = NET_EVENT_WIFI_WPS_SCAN_IND; + event_data.Event = NET_EVENT_WIFI_BSSID_SCAN_IND; event_data.Datalength = count; event_data.Data = bss_info_list; @@ -282,7 +282,7 @@ static int __net_handle_wps_scan_resp(GSList *bss_info_list) return NET_ERR_NONE; } -static int __net_handle_wifi_wps_scan_rsp(GVariant *param) +static int __net_handle_wifi_bssid_scan_rsp(GVariant *param) { GVariantIter *iter = NULL; GVariant *value = NULL; @@ -317,8 +317,8 @@ static int __net_handle_wifi_wps_scan_rsp(GVariant *param) if (ssid_found == TRUE && bssid_found == TRUE && rssi_found == TRUE && mode_found == TRUE) { - net_wps_scan_bss_info_s *bss = NULL; - bss = g_try_new0(net_wps_scan_bss_info_s, 1); + net_bssid_scan_bss_info_s *bss = NULL; + bss = g_try_new0(net_bssid_scan_bss_info_s, 1); if (bss == NULL) { WIFI_LOG(WIFI_ERROR, "Memory allocation error"); @@ -340,7 +340,7 @@ static int __net_handle_wifi_wps_scan_rsp(GVariant *param) } g_variant_iter_free(iter); - __net_handle_wps_scan_resp(bss_info_list); + __net_handle_bssid_scan_resp(bss_info_list); return NET_ERR_NONE; } @@ -1049,8 +1049,8 @@ static void __net_netconfig_signal_filter(GDBusConnection *conn, __net_handle_wifi_power_rsp(FALSE); else if (g_strcmp0(sig, NETCONFIG_SIGNAL_SPECIFIC_SCAN_DONE) == 0) __net_handle_wifi_specific_scan_rsp(param); - else if (g_strcmp0(sig, NETCONFIG_SIGNAL_WPS_SCAN_DONE) == 0) - __net_handle_wifi_wps_scan_rsp(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_BSSID_SCAN_DONE) == 0) + __net_handle_wifi_bssid_scan_rsp(param); else if (g_strcmp0(sig, NETCONFIG_SIGNAL_TDLS_PEER_FOUND) == 0) __net_handle_wifi_tdls_discover_event(param); else if (g_strcmp0(sig, NETCONFIG_SIGNAL_TDLS_CONNECTED) == 0) diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 8697bec..1bb65a1 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -37,6 +37,7 @@ static __thread GSList *config_handle_list = NULL; static __thread GSList *profile_iterator = NULL; static __thread GSList *specific_profile_iterator = NULL; +static __thread GSList *bss_profile_iterator = NULL; static __thread GSList *config_iterator = NULL; static __thread char specific_profile_essid[NET_WLAN_ESSID_LEN + 1] = { 0, }; static __thread bool wifi_is_feature_checked[WIFI_SUPPORTED_FEATURE_MAX] = {0, }; @@ -326,6 +327,47 @@ static void __update_specific_iterator(GSList *bss_list) } } +static void __update_bss_profile_iterator(GSList *bss_list) +{ + int count = 0; + GSList *list = bss_list; + + count = (int)g_slist_length(list); + if (count == 0) { + WIFI_LOG(WIFI_INFO, "No AP found !!"); + return; + } + + for (list = bss_list; list; list = list->next) { + + net_bssid_scan_bss_info_s *ap = (net_bssid_scan_bss_info_s *)list->data; + net_profile_info_s *profile = g_try_malloc0(sizeof(net_profile_info_s)); + if (profile == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to alloc profile"); + return; + } + + if (net_init_profile_info(profile) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed to init profile"); + g_free(profile); + return; + } + + g_strlcpy(profile->essid, (char *)ap->ssid, NET_WLAN_ESSID_LEN+1); + g_strlcpy(profile->bssid, ap->bssid, NET_MAX_MAC_ADDR_LEN+1); + + profile->wlan_mode = ap->mode; + profile->Strength = ap->rssi; + + /* we receive the negative value of RSSI from the wpa supplicant. + * so modify the rssi value in same manner as done in connman. */ + profile->Strength = 120 + ap->rssi; + + bss_profile_iterator = g_slist_append(bss_profile_iterator, + (net_profile_info_s *)profile); + } +} + static void __convert_profile_info_to_wifi_info(net_wifi_connection_info_s *wifi_info, net_profile_info_s *ap_info) { @@ -482,6 +524,7 @@ static void __power_on_off_cb(net_event_info_s *event_cb, bool is_requested) state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED; __clear_profile_list(&profile_iterator); __clear_profile_list(&specific_profile_iterator); + __clear_profile_list(&bss_profile_iterator); } else { WIFI_LOG(WIFI_ERROR, "Error Wi-Fi state %d", *wifi_state); error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED; @@ -551,6 +594,17 @@ static void __set_specific_scan_cb(wifi_manager_h wifi, } } +static void __set_bssid_scan_cb(wifi_manager_h wifi, + wifi_manager_bssid_scan_finished_cb user_cb, void *user_data) +{ + wifi_manager_handle_s *local_handle = (wifi_manager_handle_s *)wifi; + + if (user_cb) { + local_handle->bssid_scan_cb = user_cb; + local_handle->bssid_scan_user_data = user_data; + } +} + static void __scan_cb(net_event_info_s *event_cb, bool is_requested) { GSList *list; @@ -636,6 +690,35 @@ static void __specific_scan_cb(net_event_info_s *event_cb) } } +static void __bssid_scan_cb(net_event_info_s *event_cb) +{ + GSList *list; + wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE; + + __clear_profile_list(&bss_profile_iterator); + + if (event_cb->Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "BSSID scan failed!, Error [%d]\n", + event_cb->Error); + error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED; + } else if (event_cb->Data) { + __update_bss_profile_iterator((GSList *)event_cb->Data); + WIFI_LOG(WIFI_INFO, "BSS AP count : %d\n", + (int)g_slist_length(bss_profile_iterator)); + } + + if (_wifi_get_callback_count_from_handle_list(WIFI_BSSID_SCAN_CB)) { + for (list = wifi_manager_handle_list; list; list = list->next) { + wifi_manager_handle_s *local_handle = (wifi_manager_handle_s *)list->data; + if (local_handle->bssid_scan_cb) + local_handle->bssid_scan_cb(error_code, local_handle->bssid_scan_user_data); + + local_handle->bssid_scan_cb = NULL; + local_handle->bssid_scan_user_data = NULL; + } + } +} + static void __set_connected_cb(wifi_manager_h wifi, wifi_manager_connected_cb user_cb, void *user_data) { @@ -916,6 +999,10 @@ static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data) WIFI_LOG(WIFI_INFO, "Got Wi-Fi specific scan IND\n"); __specific_scan_cb(event_cb); break; + case NET_EVENT_WIFI_BSSID_SCAN_IND: + WIFI_LOG(WIFI_INFO, "Got BSSID scan done IND\n"); + __bssid_scan_cb(event_cb); + break; case NET_EVENT_WIFI_SCAN_CHANGED: WIFI_LOG(WIFI_INFO, "Got Wi-Fi ScanChanged event\n"); wifi_manager_scan_state_e *scan_state = (wifi_manager_scan_state_e *)event_cb->Data; @@ -1058,6 +1145,10 @@ int _wifi_get_callback_count_from_handle_list(wifi_manager_handle_cb_e e) if (local_handle->tdls_discovered_cb) ++count; break; + case WIFI_BSSID_SCAN_CB: + if (local_handle->bssid_scan_cb) + ++count; + break; default: break; } @@ -1074,6 +1165,7 @@ bool _wifi_deinit(void) __clear_profile_list(&profile_iterator); __clear_profile_list(&specific_profile_iterator); + __clear_profile_list(&bss_profile_iterator); g_slist_free_full(ap_handle_list, g_free); ap_handle_list = NULL; @@ -1152,6 +1244,9 @@ bool _wifi_check_ap_validity(wifi_manager_ap_h ap_h) for (list = specific_profile_iterator; list; list = list->next) if (ap_h == list->data) return true; + for (list = bss_profile_iterator; list; list = list->next) + if (ap_h == list->data) return true; + return false; } @@ -1419,6 +1514,25 @@ int _wifi_get_hidden_aps(wifi_manager_h wifi, const char *essid, return _wifi_open_profile(wifi, profile_info, callback, user_data); } +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(); + + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv == NET_ERR_INVALID_OPERATION) { + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + } else if (rv == NET_ERR_NONE) { + __set_bssid_scan_cb(wifi, callback, user_data); + return WIFI_MANAGER_ERROR_NONE; + } + + WIFI_LOG(WIFI_ERROR, "Operation Failed"); + return WIFI_MANAGER_ERROR_OPERATION_FAILED; +} int _wifi_get_connected_profile(wifi_manager_ap_h *ap) { @@ -1524,6 +1638,25 @@ int _wifi_foreach_found_specific_ap(wifi_manager_found_ap_cb callback, void *use return WIFI_MANAGER_ERROR_NONE; } +int _wifi_foreach_found_bssid_ap(wifi_manager_found_ap_cb callback, void *user_data) +{ + 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); + if (rv == false) break; + } + + return WIFI_MANAGER_ERROR_NONE; +} + int _wifi_open_profile(wifi_manager_h wifi, wifi_manager_ap_h ap_h, wifi_manager_connected_cb callback, void *user_data) { diff --git a/src/wifi_manager.c b/src/wifi_manager.c index e447074..92607fa 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -497,6 +497,19 @@ EXPORT_API int wifi_manager_foreach_found_specific_ap(wifi_manager_h wifi, return _wifi_foreach_found_specific_ap(callback, user_data); } +EXPORT_API int wifi_manager_foreach_found_bssid_ap(wifi_manager_h wifi, + wifi_manager_found_ap_cb callback, void *user_data) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (callback == NULL || !(__wifi_check_handle_validity(wifi))) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + return _wifi_foreach_found_bssid_ap(callback, user_data); +} + EXPORT_API int wifi_manager_connect(wifi_manager_h wifi, wifi_manager_ap_h ap, wifi_manager_connected_cb callback, void *user_data) { @@ -932,3 +945,15 @@ EXPORT_API int wifi_manager_get_module_state(wifi_manager_h wifi, } +EXPORT_API int wifi_manager_bssid_scan(wifi_manager_h wifi, + wifi_manager_bssid_scan_finished_cb callback, void *user_data) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (callback == NULL || !(__wifi_check_handle_validity(wifi))) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + return _wifi_bssid_scan_request(wifi, callback, user_data); +} diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index b8ca0b9..cc397e9 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -42,6 +42,7 @@ wifi_manager_h wifi = NULL; wifi_manager_h wifi2 = NULL; gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data); +int test_wifi_manager_foreach_bssid_scan(void); static const char *__test_convert_error_to_string(wifi_manager_error_e err_type) { @@ -131,6 +132,15 @@ static void __test_scan_request_callback(wifi_manager_error_e error_code, void* __test_convert_error_to_string(error_code)); } +static void __test_bssid_scan_request_callback(wifi_manager_error_e error_code, void *user_data) +{ + printf("BSSID Scan Completed, error code : %s\n", + __test_convert_error_to_string(error_code)); + + if (error_code == WIFI_MANAGER_ERROR_NONE) + test_wifi_manager_foreach_bssid_scan(); +} + static void __test_connection_state_callback(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void* user_data) { int rv = 0; @@ -2191,6 +2201,66 @@ int test_wifi_manager_get_autoscan_mode(void) return 1; } +static bool __test_get_bssid_scan_list(wifi_manager_ap_h ap, void *user_data) +{ + char *bssid; + char *essid; + int rssi; + + if (wifi_manager_ap_get_bssid(ap, &bssid) != WIFI_MANAGER_ERROR_NONE) { + printf("Failed to get bssid for ap\n"); + return false; + } + + if (wifi_manager_ap_get_essid(ap, &essid) != WIFI_MANAGER_ERROR_NONE) { + printf("Failed to get essid for ap\n"); + g_free(bssid); + return false; + } + + if (wifi_manager_ap_get_rssi(ap, &rssi) != WIFI_MANAGER_ERROR_NONE) { + printf("Failed to get rssi for ap\n"); + g_free(bssid); + g_free(essid); + return false; + } + + printf("bssid : %s, essid : %s, rssi : %d\n", + bssid, essid, rssi); + + g_free(bssid); + g_free(essid); + return true; +} + +int test_wifi_manager_foreach_bssid_scan(void) +{ + int rv; + + rv = wifi_manager_foreach_found_bssid_ap(wifi, + __test_get_bssid_scan_list, NULL); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Failed to get wps scan list [%s]\n", + __test_convert_error_to_string(rv)); + return -1; + } + + return 1; +} + +int test_wifi_manager_bssid_scan(void) +{ + int rv = 0; + rv = wifi_manager_bssid_scan(wifi, __test_bssid_scan_request_callback, NULL); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Fail to request bssid scan [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("BSSID Scan request succeeded\n"); + return 1; +} + int test_wifi_manager_get_scan_state(void) { int rv = 0; @@ -2287,7 +2357,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("A - Get Auto Scan Mode\n"); printf("B - Enable TDLS Channel Switch Request\n"); printf("C - Disable TDLS Channel Switch Request\n"); - printf("D - Get Wi-Fi Module State\\n"); + printf("D - Get Wi-Fi Module State\n"); + printf("E - BSSID Scan\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); @@ -2413,6 +2484,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'D': rv = test_wifi_manager_get_module_state(); break; + case 'E': + rv = test_wifi_manager_bssid_scan(); + break; default: break; } -- 2.7.4