From: Abhay Agarwal Date: Mon, 21 Jun 2021 09:20:24 +0000 (+0530) Subject: Fix issues in add device and scan operation X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72d894feed0c20d5729db8ed342937cc490e107c;p=platform%2Fcore%2Fconnectivity%2Fua-plugin-wifi-location.git Fix issues in add device and scan operation This patch handles following - Fix mac address format to be used on call of add device - Fix mac address format handling on receiving location callback - Handle registered device addition on reboot Change-Id: I30c4245a27b1687fcd789fbb93469273b9db9538 Signed-off-by: Abhay Agarwal --- diff --git a/include/wifi-location-plugin.h b/include/wifi-location-plugin.h index aeb3d84..1cf47c8 100755 --- a/include/wifi-location-plugin.h +++ b/include/wifi-location-plugin.h @@ -32,6 +32,7 @@ extern "C" { #define PLUGIN_ID UAS_PLUGIN_ID_WIFI_LOCATION #define UAS_DEVICE_ID_MAX_LEN 50 #define MAC_ADDRESS_MAX_LEN 18 +#define MAC_ADDRESS_ARRAY_SIZE 6 typedef struct { int user_id; /**< User id */ diff --git a/src/wifi-location-plugin-scan.c b/src/wifi-location-plugin-scan.c index 81ce28d..f3e2aa8 100755 --- a/src/wifi-location-plugin-scan.c +++ b/src/wifi-location-plugin-scan.c @@ -55,6 +55,7 @@ int _wifi_location_plugin_deinitialize(void) UA_WIFI_LOCATION_ERR( "wifi_location_request_destroy failed"); } + g_request = NULL; ret = wifi_location_deinitialize(); retv_if_with_log(WIFI_LOCATION_ERROR_NONE != ret, @@ -80,7 +81,7 @@ wifi_location_request_h _wifi_location_plugin_get_request(void) return g_request; } -int _wifi_location_plugin_add_registered_device(gpointer data) +int _wifi_location_plugin_add_dev(gpointer data) { FUNC_ENTER; uas_wifi_location_info_t *dev = data; @@ -88,6 +89,7 @@ int _wifi_location_plugin_add_registered_device(gpointer data) int ret = WIFI_LOCATION_ERROR_NONE; wifi_location_peer_type_e peer_type = WIFI_LOCATION_PEER_TYPE_WIFI_AWARE; + unsigned char mac[6] = {0, }; retv_if(NULL == dev, UAS_STATUS_FAIL); @@ -98,9 +100,11 @@ int _wifi_location_plugin_add_registered_device(gpointer data) return status; } + sscanf(dev->mac_addr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); + /* Add device */ - ret = wifi_location_request_add_peer(g_request, - (unsigned char*)dev->mac_addr, peer_type); + ret = wifi_location_request_add_peer(g_request, mac, peer_type); if (WIFI_LOCATION_ERROR_NONE == ret) status = UAS_STATUS_SUCCESS; else @@ -110,6 +114,22 @@ int _wifi_location_plugin_add_registered_device(gpointer data) return status; } +gboolean _wifi_location_plugin_add_registered_device(gpointer data) +{ + FUNC_ENTER; + uas_wifi_location_info_t *dev = data; + int status = UAS_STATUS_FAIL; + retv_if(NULL == dev, FALSE); + + status = _wifi_location_plugin_add_dev(data); + if (UAS_STATUS_SUCCESS != status) + UA_WIFI_LOCATION_ERR( + "_wifi_location_plugin_add_registered_device failed"); + + FUNC_EXIT; + return FALSE; +} + gboolean _wifi_location_plugin_add_device(gpointer data) { FUNC_ENTER; @@ -117,7 +137,7 @@ gboolean _wifi_location_plugin_add_device(gpointer data) int status = UAS_STATUS_FAIL; retv_if(NULL == dev, FALSE); - status = _wifi_location_plugin_add_registered_device(data); + status = _wifi_location_plugin_add_dev(data); _wifi_location_plugin_handle_device_added(status, dev); g_free(dev); @@ -132,9 +152,11 @@ static void __wifi_location_result_received_cb( void *user_data) { FUNC_ENTER; - unsigned char *mac = NULL; + unsigned char *mac = (unsigned char *)g_new0(unsigned char*, + MAC_ADDRESS_ARRAY_SIZE); + char mac_string[MAC_ADDRESS_MAX_LEN] = {""}; int distance_mm = 0; - int ret; + int ret = WIFI_LOCATION_ERROR_NONE; if(WIFI_LOCATION_ERROR_NONE != error) { UA_WIFI_LOCATION_ERR("failed error %d", error); @@ -147,11 +169,19 @@ static void __wifi_location_result_received_cb( } ret = wifi_location_result_get_mac(result, &mac); - if(WIFI_LOCATION_ERROR_NONE != ret) + if (WIFI_LOCATION_ERROR_NONE != ret) { UA_WIFI_LOCATION_ERR("wifi_location_result_get_mac " \ "failed error %d", ret); - else - UA_WIFI_LOCATION_DBG("Result received for mac %s", mac); + } else { + UA_WIFI_LOCATION_DBG("Result received for mac " + "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + } + + snprintf(mac_string, MAC_ADDRESS_MAX_LEN, + "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + UA_WIFI_LOCATION_DBG("Result received for mac %s", mac_string); ret = wifi_location_result_get_distance_mm(result, &distance_mm); if(WIFI_LOCATION_ERROR_NONE != ret) @@ -160,7 +190,8 @@ static void __wifi_location_result_received_cb( else UA_WIFI_LOCATION_DBG("Result distance(mm) %d", distance_mm); - _wifi_location_plugin_handle_device_found((const char*)mac, distance_mm); + _wifi_location_plugin_handle_device_found( + (const char*)mac_string, distance_mm); FUNC_EXIT; }