} \
} 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
#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
#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;
#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;
+}
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;
.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,
}
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;
+}