#define DETECTION_WINDOW_DEFAULT 55 /* 55 seconds */
+#define DETECTION_STARTED 1
+#define DETECTION_STOPPED 0
+
+static unsigned int wifi_location_detection_window = DETECTION_WINDOW_DEFAULT;
static const uas_callbacks_t *uas_cbs = NULL;
static GSList *dev_list = NULL;
+static int wifi_location_detection_type = 0;
+static guint stop_scan_timer = 0;
+
+static void __report_absence(gpointer data, gpointer user_data)
+{
+ FUNC_ENTER;
+
+ /* TODO: Implement this function */
+
+ FUNC_EXIT;
+}
+
+static void __reset_devices(gpointer data, gpointer user_data)
+{
+ /* TODO: Implement this function */
+ return;
+}
+
+static int __stop_scan()
+{
+ FUNC_ENTER;
+ int ret = UAS_STATUS_SUCCESS;
+
+ g_slist_foreach(dev_list, __reset_devices, NULL);
+
+ /* TODO: stop scan */
+ if (UAS_STATUS_SUCCESS != ret) {
+ UA_WIFI_LOCATION_ERR("Fail to stop wifi_location scan [%d]", ret);
+ return ret;
+ }
+
+ /* Send detection stopped */
+ if (uas_cbs && uas_cbs->detection_state_cb) {
+ uas_cbs->detection_state_cb(PLUGIN_ID, DETECTION_STOPPED);
+ } else {
+ UA_WIFI_LOCATION_ERR("uas_cbs not ready");
+ }
+
+ /* Reset detection flags */
+ wifi_location_detection_type = 0;
+
+ FUNC_EXIT;
+ return ret;
+}
+
+static gboolean __stop_scan_expired_timer_cb(gpointer user_data)
+{
+ int ret = UAS_STATUS_SUCCESS;
+
+ stop_scan_timer = 0;
+
+ /* Report absence for undetected devices */
+ g_slist_foreach(dev_list, __report_absence, NULL);
+
+ /* Stop detection */
+ ret = __stop_scan();
+ retv_if_with_log(UAS_STATUS_SUCCESS != ret, FALSE, "return %d", ret);
+
+ return FALSE;
+}
+
+static int __start_scan(gpointer user_data, int scan_mode)
+{
+ FUNC_ENTER;
+ int ret = UAS_STATUS_SUCCESS;
+
+ ret = _wifi_location_plugin_start_scan(scan_mode);
+ retv_if_with_log(UAS_STATUS_SUCCESS != ret, ret, "return %d", ret);
+
+ if (0 < stop_scan_timer)
+ g_source_remove(stop_scan_timer);
+ stop_scan_timer = g_timeout_add_seconds(wifi_location_detection_window,
+ __stop_scan_expired_timer_cb, NULL);
+
+ /* Send detection started */
+ if (uas_cbs && uas_cbs->detection_state_cb) {
+ uas_cbs->detection_state_cb(PLUGIN_ID, DETECTION_STARTED);
+ } else {
+ UA_WIFI_LOCATION_ERR("uas_cbs not ready");
+ ret = UAS_STATUS_FAIL;
+ }
+
+ FUNC_EXIT;
+ return ret;
+}
static int init(const uas_callbacks_t *callbacks)
{
return UAS_STATUS_SUCCESS;
}
+static int start_detection(unsigned int detection_type, int scan_mode)
+{
+ FUNC_ENTER;
+
+ int ret = UAS_STATUS_SUCCESS;
+
+ retv_if(NULL == uas_cbs, UAS_STATUS_NOT_READY);
+ retv_if(detection_type == (wifi_location_detection_type & detection_type),
+ UAS_STATUS_ALREADY_DONE);
+
+ /* Check if detection already in progress */
+ if (0 != wifi_location_detection_type)
+ goto done;
+
+ /* Start detection */
+ ret = __start_scan(NULL, scan_mode);
+ retv_if_with_log(UAS_STATUS_SUCCESS != ret, ret, "return %d", ret);
+
+done:
+ wifi_location_detection_type |= detection_type;
+ UA_WIFI_LOCATION_INFO_C("wifi_location_detection_type = 0x%8.8X", wifi_location_detection_type);
+
+ FUNC_EXIT;
+ return ret;
+}
+
static uas_api_t wifi_location_api = {
.init = init,
.deinit = deinit,
.set_registered_devices = NULL,
.add_device = NULL,
.remove_device = NULL,
- .start_detection = NULL,
+ .start_detection = start_detection,
.stop_detection = NULL,
.set_low_power_mode = NULL,
.set_detection_window = NULL,