Add API to add device 93/260593/2
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 18 Jan 2021 04:12:49 +0000 (09:42 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 1 Jul 2021 08:53:45 +0000 (14:23 +0530)
Change-Id: I03c26bdb3efb0872ae71df9d2d8ead83c390d588
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/wifi-location-plugin-util.h
include/wifi-location-plugin.h
src/wifi-location-plugin-scan.c
src/wifi-location-plugin-util.c
src/wifi-location-plugin.c

index f695156..ce6787e 100644 (file)
@@ -58,6 +58,17 @@ extern "C" {
                } \
        } while (0)
 
+
+uas_wifi_location_info_t *_wifi_location_plugin_util_get_wifi_location_info_from_dev_info(
+               uas_device_info_t *dev_info);
+
+uas_device_info_t *_wifi_location_plugin_util_get_dev_info_from_wifi_location_info(
+                                       uas_wifi_location_info_t *wifi_location_info);
+
+void _wifi_location_plugin_util_uas_device_info_free(uas_device_info_t *device);
+
+unsigned long long _wifi_location_plugin_util_get_curr_time(void);
+
 #ifdef __cplusplus
 }
 #endif
index 011408b..900ce78 100755 (executable)
@@ -30,11 +30,27 @@ extern "C" {
 #endif
 
 #define PLUGIN_ID UAS_PLUGIN_ID_WIFI_LOCATION
+#define UAS_DEVICE_ID_MAX_LEN 50
+#define MAC_ADDRESS_MAX_LEN 18
+
+typedef struct {
+       int user_id; /**< User id */
+       int os; /**< OS type */
+       char device_id[UAS_DEVICE_ID_MAX_LEN]; /**< Mobile ID */
+       char mac_addr[MAC_ADDRESS_MAX_LEN]; /**< Mac address */
+       gboolean presence_reported; /**< Presence reported or not */
+       gboolean discriminant; /**< Weather to check or not */
+} uas_wifi_location_info_t;
+
+gboolean _wifi_location_plugin_add_device(gpointer data);
 
 int _wifi_location_plugin_start_scan(int scan_mode);
 
 int _wifi_location_plugin_stop_scan(void);
 
+void _wifi_location_plugin_handle_device_added(int status,
+               uas_wifi_location_info_t *wifi_location_info);
+
 #ifdef __cplusplus
 }
 #endif
index f61872b..869cebd 100755 (executable)
 #include "wifi-location-plugin.h"
 #include "wifi-location-plugin-util.h"
 
+gboolean _wifi_location_plugin_add_device(gpointer data)
+{
+       FUNC_ENTER;
+       uas_wifi_location_info_t *dev = data;
+       int status = UAS_STATUS_SUCCESS;
+
+       retv_if(NULL == dev, FALSE);
+
+       /* TODO: Add device */
+
+       _wifi_location_plugin_handle_device_added(status, dev);
+       g_free(dev);
+       FUNC_EXIT;
+       return FALSE;
+}
+
 int _wifi_location_plugin_start_scan(int scan_mode) {
        FUNC_ENTER;
        int ret = UAS_STATUS_SUCCESS;
index 78d4c4c..f92f641 100644 (file)
 
 #include "wifi-location-plugin.h"
 #include "wifi-location-plugin-util.h"
+
+uas_wifi_location_info_t *_wifi_location_plugin_util_get_wifi_location_info_from_dev_info(
+               uas_device_info_t *dev_info)
+{
+       FUNC_ENTER;
+       uas_wifi_location_info_t *wifi_location_info;
+       int i;
+
+       retv_if(NULL == dev_info, NULL);
+       retv_if(NULL == dev_info->device_id, NULL);
+
+       wifi_location_info = g_new0(uas_wifi_location_info_t, 1);
+       wifi_location_info->user_id = dev_info->user_id;
+       wifi_location_info->os = dev_info->os;
+       wifi_location_info->discriminant = dev_info->discriminant;
+       g_strlcpy(wifi_location_info->device_id,
+                       dev_info->device_id, UAS_DEVICE_ID_MAX_LEN);
+
+       for (i = 0; i < dev_info->num_addr; i++) {
+               if (UAS_ADDR_TYPE_WIFI ==
+                               dev_info->addr_list[i].type) {
+                       g_strlcpy(wifi_location_info->mac_addr,
+                                       dev_info->addr_list[i].address,
+                                       MAC_ADDRESS_MAX_LEN);
+                       break;
+               }
+       }
+
+       UA_WIFI_LOCATION_DBG("User Id: [0x%X], OS: [0x%X], Device Id: [%s], " \
+               "WIFI_LOCATION Addr: [%s], Discriminant [%d] ",
+               wifi_location_info->user_id, wifi_location_info->os,
+               wifi_location_info->device_id, wifi_location_info->mac_addr,
+               wifi_location_info->discriminant);
+
+
+       FUNC_EXIT;
+       return wifi_location_info;
+}
+
+
+uas_device_info_t *_wifi_location_plugin_util_get_dev_info_from_wifi_location_info(
+                                       uas_wifi_location_info_t *wifi_location_info)
+{
+       FUNC_ENTER;
+       uas_device_info_t *dev_info;
+
+       retv_if(NULL == wifi_location_info, NULL);
+
+       dev_info = g_new0(uas_device_info_t, 1);
+       dev_info->user_id = wifi_location_info->user_id;
+       dev_info->os = wifi_location_info->os;
+       dev_info->discriminant = wifi_location_info->discriminant;
+       dev_info->device_id = g_strdup(wifi_location_info->device_id);
+       dev_info->num_addr = 1;
+       dev_info->addr_list = g_new0(uas_address_info_t, 1);
+       dev_info->addr_list[0].type = UAS_ADDR_TYPE_WIFI;
+       dev_info->addr_list[0].address = g_strdup(wifi_location_info->mac_addr);
+
+       UA_WIFI_LOCATION_DBG("User Id: [0x%X], OS: [0x%X], Device Id: [%s], " \
+                       "WIFI_LOCATION Addr: [%s] Discriminant [%d],",
+                       dev_info->user_id, dev_info->os, dev_info->device_id,
+                       dev_info->addr_list[0].address, dev_info->discriminant);
+
+       FUNC_EXIT;
+       return dev_info;
+}
+
+void _wifi_location_plugin_util_uas_device_info_free(uas_device_info_t *device)
+{
+       FUNC_ENTER;
+       int i;
+
+       ret_if(NULL == device);
+
+       g_free(device->device_id);
+
+       for (i = 0; i < device->num_addr; i++)
+               g_free(device->addr_list[i].address);
+
+       g_free(device->addr_list);
+       g_free(device);
+
+       FUNC_EXIT;
+}
+
+unsigned long long _wifi_location_plugin_util_get_curr_time(void)
+{
+       int ret;
+       struct timespec t;
+
+       ret = clock_gettime(CLOCK_REALTIME, &t);
+       if (-1 == ret) {
+               UA_WIFI_LOCATION_ERR("Failed to call clock_gettime [%d]", errno);
+               return 0;
+       }
+       return ((unsigned long long)(t.tv_sec) * 1000000000LL + t.tv_nsec) / 1000000;
+}
index 15823c4..c818c17 100755 (executable)
@@ -192,6 +192,25 @@ static int get_capability(uas_capability_e *capability)
        return UAS_STATUS_SUCCESS;
 }
 
+static int add_device(uas_device_info_t *device)
+{
+       FUNC_ENTER;
+       uas_wifi_location_info_t *wifi_location_info;
+
+       retv_if(NULL == device, UAS_STATUS_FAIL);
+       retv_if(NULL == uas_cbs, UAS_STATUS_NOT_READY);
+
+       wifi_location_info =
+               _wifi_location_plugin_util_get_wifi_location_info_from_dev_info(device);
+       retv_if_with_log(NULL == wifi_location_info, UAS_STATUS_FAIL,
+               "_wifi_location_plugin_util_get_wifi_location_info_from_dev_info");
+
+       g_idle_add(_wifi_location_plugin_add_device, wifi_location_info);
+
+       FUNC_EXIT;
+       return UAS_STATUS_SUCCESS;
+}
+
 static int start_detection(unsigned int detection_type, int scan_mode)
 {
        FUNC_ENTER;
@@ -267,7 +286,7 @@ static uas_api_t wifi_location_api = {
        .get_state = get_state,
        .get_capability = get_capability,
        .set_registered_devices = NULL,
-       .add_device = NULL,
+       .add_device = add_device,
        .remove_device = NULL,
        .start_detection = start_detection,
        .stop_detection = stop_detection,
@@ -298,3 +317,42 @@ static int module_deinit(void)
 }
 
 UAS_MODULE_ADD(UAS_PLUGIN_ID_WIFI_LOCATION, NAME, AUTHOR, VERSION, module_init, module_deinit);
+
+void _wifi_location_plugin_handle_device_added(int status,
+               uas_wifi_location_info_t *wifi_location_info)
+{
+       FUNC_ENTER;
+       uas_device_info_t *dev_info;
+
+       ret_if(NULL == wifi_location_info);
+
+       dev_info = _wifi_location_plugin_util_get_dev_info_from_wifi_location_info(
+                                                               wifi_location_info);
+       if (NULL == dev_info) {
+               /* Device Addition failed */
+               UA_WIFI_LOCATION_ERR(
+               "_wifi_location_plugin_util_get_dev_info_from_wifi_location_info failed");
+               if (uas_cbs && uas_cbs->device_added_cb)
+                       uas_cbs->device_added_cb(PLUGIN_ID, UAS_STATUS_FAIL, NULL);
+               FUNC_EXIT;
+               return;
+       }
+
+       if (UAS_STATUS_SUCCESS == status) {
+               dev_list = g_slist_prepend(dev_list,
+                               g_memdup(wifi_location_info,
+                               sizeof(uas_wifi_location_info_t)));
+       }
+       /* Save current time */
+       dev_info->last_seen = _wifi_location_plugin_util_get_curr_time();
+
+       /* Send device Addition callback */
+       if (uas_cbs && uas_cbs->device_added_cb) {
+               uas_cbs->device_added_cb(PLUGIN_ID, status, dev_info);
+       } else {
+               UA_WIFI_LOCATION_ERR("uas_cbs not ready");
+       }
+
+       _wifi_location_plugin_util_uas_device_info_free(dev_info);
+       FUNC_EXIT;
+}