EVENT(UAM_EVENT_SENSOR_STATE_NOT_READY) \
EVENT(UAM_EVENT_DETECTION_STARTED) \
EVENT(UAM_EVENT_DETECTION_STOPPED) \
+ EVENT(UAM_EVENT_DEVICE_FOUND) \
+ EVENT(UAM_EVENT_SCAN_COMPLETED) \
EVENT(UAM_EVENT_MAX)
#define GENERATE_EVENT_ENUM(ENUM) ENUM,
int _uam_stop_absence_detection(unsigned int bitmask);
+int _uam_start_search_active_devices(unsigned int bitmask, int detection_period);
+
+int _uam_stop_search_active_devices(unsigned int bitmask);
+
typedef enum {
UAM_PRESENCE_STATE_INVALID = 0x00,
UAM_PRESENCE_STATE_PRESENT,
REQUEST(UAM_REQUEST_SET_LOW_POWER_MODE) \
REQUEST(UAM_REQUEST_GET_DETECTION_PARAMS) \
REQUEST(UAM_REQUEST_SET_DETECTION_PARAMS) \
+ REQUEST(UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES) \
+ REQUEST(UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES) \
REQUEST(UAM_REQUEST_MAX)
#define GENERATE_REQUEST_ENUM(ENUM) ENUM,
#define UAM_SIGNAL_SENSOR_STATE_NOT_READY "SensorNotReady"
#define UAM_SIGNAL_DETECTION_STARTED "DetectionStarted"
#define UAM_SIGNAL_DETECTION_STOPPED "DetectionStopped"
+#define UAM_SIGNAL_DEVICE_FOUND "DeviceFound"
+#define UAM_SIGNAL_SCAN_COMPLETED "ScanCompleted"
#ifdef __cplusplus
}
FUNC_EXIT;
return ret;
}
+
+UAM_EXPORT_API int _uam_start_search_active_devices(unsigned int bitmask, int detection_period)
+{
+ FUNC_ENTRY;
+ int ret;
+
+ UAM_INIT_PARAMS();
+ UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ g_array_append_vals(in_param1, &bitmask, sizeof(unsigned int));
+ g_array_append_vals(in_param2, &detection_period, sizeof(int));
+ ret = _uam_sync_request(UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ FUNC_EXIT;
+ return ret;
+}
+
+UAM_EXPORT_API int _uam_stop_search_active_devices(unsigned int bitmask)
+{
+ FUNC_ENTRY;
+ int ret;
+
+ UAM_INIT_PARAMS();
+ UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ g_array_append_vals(in_param1, &bitmask, sizeof(unsigned int));
+ ret = _uam_sync_request(UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ FUNC_EXIT;
+ return ret;
+}
strlen(UAM_SIGNAL_DETECTION_STOPPED))) {
__uam_send_event(UAM_EVENT_DETECTION_STOPPED, result, NULL,
event_info->cb, event_info->user_data);
+ } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_DEVICE_FOUND,
+ strlen(UAM_SIGNAL_DEVICE_FOUND))) {
+ uam_device_info_t dev_info;
+ int os, type;
+ char *mac = NULL;
+ char *ipv4_addr = NULL;
+ char *device_id = NULL;
+
+ g_variant_get(parameters, "(iii&s&s&s)", &result,
+ &os, &type, &mac, &ipv4_addr, &device_id);
+
+ dev_info.operating_system = os;
+ dev_info.type = type;
+ g_strlcpy(dev_info.mac,
+ mac, UAM_MAC_ADDRESS_STRING_LEN);
+ g_strlcpy(dev_info.ipv4_addr,
+ ipv4_addr, UAM_IP_ADDRESS_MAX_STRING_LEN);
+ g_strlcpy(dev_info.device_id,
+ device_id, UAM_DEVICE_ID_MAX_STRING_LEN);
+
+ event = UAM_EVENT_DEVICE_FOUND;
+ __uam_send_event(event, result, &dev_info,
+ event_info->cb, event_info->user_data);
+ } else if (0 == strncasecmp(signal_name, UAM_SIGNAL_SCAN_COMPLETED,
+ strlen(UAM_SIGNAL_SCAN_COMPLETED))) {
+
+ event = UAM_EVENT_SCAN_COMPLETED;
+ __uam_send_event(event, result, NULL,
+ event_info->cb, event_info->user_data);
} else {
UAM_WARN("Unknown signal recieved: %s", signal_name);
}
// long long int timestamp;
} uam_db_user_info_t;
+
+typedef enum {
+ UAM_ACTIVE_DEVICE_FOUND = 0x01,
+ UAM_ACTIVE_SCAN_COMPLETED = 0x02
+} uam_active_scan_event_e;
+
int _uam_core_add_user(const char *account, const char *name);
int _uam_core_remove_user(const char *account);
void _uam_core_handle_detection_stopped(unsigned int sensor);
+int _uam_core_start_search_active_devices(char *sender, unsigned int sensors, int detection_period);
+
+int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors);
+
+void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int sensor, const uam_device_info_t *dev_info);
+
#ifdef __cplusplus
}
#endif
int _uam_pm_set_detection_threshold(unsigned int sensor,
int presence_threshold, int absence_threshold);
+int _uam_pm_start_search_active_devices(unsigned int* bitmask, int detection_period);
+
+int _uam_pm_stop_search_active_devices(unsigned int bitmask);
+
#ifdef __cplusplus
}
#endif
FUNC_EXIT;
return UAM_ERROR_NONE;
}
+
+int _uam_pm_start_search_active_devices(unsigned int* bitmask, int detection_period)
+{
+ FUNC_ENTRY;
+ int id;
+ int status;
+ int ret = UAM_ERROR_INTERNAL;
+
+ unsigned int scanning_sensor = 0;
+
+ for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
+ uam_sensor_plugin_info_t *plugin = plugins[id];
+ unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id);
+
+ if (!(sensor & (*bitmask)))
+ continue;
+
+ if (!plugin || !plugin->api || !plugin->api->scan_active_devices)
+ continue;
+
+ status = plugin->api->scan_active_devices(detection_period);
+
+ if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
+ UAM_ERR("plugin->search_active_devices(%d) failed for %d", detection_period, id);
+ continue;
+ }
+
+ scanning_sensor |= sensor;
+ /* Result success if scanning started for atleast 1 of the sensor */
+ ret = UAM_ERROR_NONE;
+ }
+
+ (*bitmask) &= scanning_sensor;
+
+ FUNC_EXIT;
+ return ret;
+}
+
+int _uam_pm_stop_search_active_devices(unsigned int bitmask)
+{
+ FUNC_ENTRY;
+ int id;
+ int status;
+ int ret = UAM_ERROR_INTERNAL;
+
+ for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
+ uam_sensor_plugin_info_t *plugin = plugins[id];
+ unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id);
+
+ if (!(sensor & bitmask))
+ continue;
+
+ if (!plugin || !plugin->api || !plugin->api->cancel_active_device_scan)
+ continue;
+
+ status = plugin->api->cancel_active_device_scan();
+
+ if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
+ UAM_ERR("plugin->stop_search_active_devices() failed for %d", id);
+ continue;
+ }
+
+ ret = UAM_ERROR_NONE;
+ }
+
+ FUNC_EXIT;
+ return ret;
+}
FUNC_EXIT;
return device;
}
+
+uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_scan_event_e event)
+{
+ switch (event) {
+ case UAS_ACTIVE_DEVICE_FOUND :
+ return UAM_ACTIVE_DEVICE_FOUND;
+ case UAS_ACTIVE_SCAN_COMPLETED :
+ return UAM_ACTIVE_SCAN_COMPLETED;
+ default:
+ UAM_WARN("Unknown event 0x%8.8X", event);
+ return 0;
+ }
+}
const char *_pm_util_uas_status_to_str(int status);
+uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_scan_event_e event);
+
#ifdef __cplusplus
}
#endif
const uas_device_info_t *device)
{
FUNC_ENTRY;
+ uam_device_info_t *dev_info = NULL;
+ uam_active_scan_event_e event_info;
+ if(UAS_ACTIVE_DEVICE_FOUND == event){
+ ret_if(NULL == device);
+
+ dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device);
+ ret_if(NULL == dev_info);
+
+ dev_info->type = UAM_TECH_TYPE_WIFI;
+ }
+
+ event_info = _pm_util_uas_scan_event_to_uam_scan_event(event);
+
+ _uam_core_handle_active_device(event_info, UAM_SENSOR_BITMASK_WIFI, dev_info);
+
+ g_free(dev_info);
FUNC_EXIT;
}
GSList *monitors; /* List of monitoring apps - uam_monitor_info_t */
GSList *users; /* List of users - uam_db_user_info_t */
GSList *devices; /* List of devices - uam_db_device_info_t */
+GSList *scanners; /* List of scanning apps - uam_monitor_info_t*/
static gboolean user_id_list[UAM_MAX_USERS];
static int next_user_id = 1;
FUNC_EXIT;
}
+
+static uam_monitor_info_t *__uam_find_scanner(const char *name)
+{
+// FUNC_ENTRY;
+ GSList *l;
+
+ retv_if(NULL == name, NULL);
+
+ for (l = scanners; NULL != l; l = g_slist_next(l)) {
+ uam_monitor_info_t *scanner = l->data;
+
+ if (!scanner || !scanner->name)
+ continue;
+
+ if (0 == g_strcmp0(scanner->name, name)) {
+ UAM_DBG("Scanning application found in list");
+ return scanner;
+ }
+ }
+
+// FUNC_EXIT;
+ return NULL;
+}
+
+int _uam_core_start_search_active_devices(char *sender, unsigned int sensors, int detection_period)
+{
+ FUNC_ENTRY;
+ int ret;
+ uam_monitor_info_t *scanner;
+ GSList *l;
+
+ retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM);
+
+ scanner = __uam_find_scanner(sender);
+ if (scanner) {
+ ret = UAM_ERROR_NOW_IN_PROGRESS;
+ UAM_ERR("Failed with error: %s (0x%4.4X)",
+ _uam_manager_error_to_str(ret), ret);
+ return ret;
+ }
+
+ for (l = scanners; NULL != l; l = g_slist_next(l)) {
+ uam_monitor_info_t *scanner_data = l->data;
+
+ if (!scanner_data || !scanner_data->name)
+ continue;
+ sensors &= ~(scanner_data->sensors);
+ }
+
+ ret = _uam_pm_start_search_active_devices(&sensors, detection_period);
+
+ if (UAM_ERROR_NONE != ret) {
+ UAM_ERR("Failed with error: %s (0x%4.4X)",
+ _uam_manager_error_to_str(ret), ret);
+ return ret;
+ }
+
+ scanner = g_malloc0(sizeof(uam_monitor_info_t));
+ scanner->name = g_strdup(sender);
+ scanner->sensors |= sensors;
+ scanners = g_slist_append(scanners, scanner);
+
+ FUNC_EXIT;
+ return UAM_ERROR_NONE;
+}
+
+int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors)
+{
+ FUNC_ENTRY;
+ int ret;
+
+ GSList *l;
+ retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM);
+
+ for (l = scanners; NULL != l; l = g_slist_next(l)) {
+ uam_monitor_info_t *scanner = l->data;
+
+ if (!scanner || !scanner->name)
+ continue;
+
+ if (scanner->sensors & sensors){
+ ret = _uam_pm_stop_search_active_devices(sensors);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_ERR("Failed with error: %s (0x%4.4X)",
+ _uam_manager_error_to_str(ret), ret);
+ return ret;
+ }
+ scanners = g_slist_remove(scanners,scanner);
+ g_free(scanner->name);
+ g_free(scanner);
+ }
+ }
+
+ FUNC_EXIT;
+ return UAM_ERROR_NONE;
+}
+
+void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int sensor, const uam_device_info_t *dev_info)
+{
+ FUNC_ENTRY;
+
+ GVariant *param = NULL;
+ GSList *l;
+ int done = 0;
+ char* name = NULL;
+
+ for (l = scanners; NULL != l; l = g_slist_next(l)) {
+ uam_monitor_info_t *scanner = (uam_monitor_info_t *)l->data;
+
+ if (!scanner || !scanner->name)
+ continue;
+
+ if (scanner->sensors & sensor){
+
+ name = g_strdup(scanner->name);
+ if(event == UAM_ACTIVE_SCAN_COMPLETED){
+ scanner->sensors &= ~(sensor);
+ if(scanner->sensors == 0){
+ done = 1;
+ scanners = g_slist_remove(scanners, scanner);
+ g_free(scanner->name);
+ g_free(scanner);
+ }
+ }
+ break;
+ }
+ }
+
+ if(event == UAM_ACTIVE_DEVICE_FOUND){
+ param = g_variant_new("(iiisss)",
+ UAM_ERROR_NONE,
+ dev_info->operating_system,
+ dev_info->type,
+ dev_info->mac,
+ dev_info->ipv4_addr,
+ dev_info->device_id);
+ UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_DEVICE_FOUND));
+ /* Send device event to application */
+ if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_DEVICE_FOUND, param))
+ UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event));
+ }
+ else if(done == 1 && event == UAM_ACTIVE_SCAN_COMPLETED){
+ UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_SCAN_COMPLETED));
+ /* Send device event to application */
+ if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_SCAN_COMPLETED, param))
+ UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event));
+ }
+
+ if (name != NULL)
+ g_free(name);
+
+ FUNC_EXIT;
+}
case UAM_EVENT_DETECTION_STOPPED:
signal = UAM_SIGNAL_DETECTION_STOPPED;
break;
+ case UAM_EVENT_DEVICE_FOUND:
+ signal = UAM_SIGNAL_DEVICE_FOUND;
+ break;
+ case UAM_EVENT_SCAN_COMPLETED:
+ signal = UAM_SIGNAL_SCAN_COMPLETED;
+ break;
default:
UAM_ERR("Unhandled event");
return UAM_ERROR_INTERNAL;
detection_param.period, detection_param.retries);
break;
}
+ case UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES: {
+ unsigned int sensors;
+ int detection_period;
+
+ __uam_manager_copy_params(in_param1,
+ &sensors, sizeof(unsigned int));
+
+ __uam_manager_copy_params(in_param2,
+ &detection_period, sizeof(int));
+
+ result = _uam_core_start_search_active_devices(sender, sensors, detection_period);
+ break;
+ }
+ case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES: {
+ unsigned int sensors;
+
+ __uam_manager_copy_params(in_param1,
+ &sensors, sizeof(unsigned int));
+
+ result = _uam_core_stop_search_active_devices(sender, sensors);
+ break;
+ }
default:
UAM_WARN("UnSupported function [%s(0x%4.4X)]",
_uam_manager_request_to_str(function), function);
case UAM_REQUEST_SET_LOW_POWER_MODE:
case UAM_REQUEST_GET_DETECTION_PARAMS:
case UAM_REQUEST_SET_DETECTION_PARAMS:
+ case UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES:
+ case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES:
return TRUE;
default:
return FALSE;