a38d59c5333e721704ae0c00f10fc2e97534b7d1
[platform/core/connectivity/ua-manager.git] / ua-daemon / src / pm / ua-plugin-manager.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <dlfcn.h>
21 #include <ua-plugin.h>
22 #include <ua-plugin-manager.h>
23 #include <tzplatform_config.h>
24
25 #include "ua-pm-util.h"
26
27 static unsigned int available_sensors = 0;
28
29 extern const uas_callbacks_t ble_cbs;
30 extern const uas_callbacks_t wifi_cbs;
31 extern const uas_callbacks_t light_cbs;
32 extern const uas_callbacks_t motion_cbs;
33
34 static int ble_detection_type = 0;
35 static int wifi_detection_type = 0;
36
37 typedef struct {
38         void *handle;
39         uas_module_t *module;
40         uas_api_t *api;
41         uas_capability_e capability;
42 } uam_sensor_plugin_info_t;
43
44 uam_sensor_plugin_info_t* plugins[UAS_PLUGIN_ID_MAX];
45
46 static gboolean __add_plugin(void *handle, uas_module_t *module)
47 {
48         FUNC_ENTRY;
49         uas_api_t *api = NULL;
50         uam_sensor_plugin_info_t *plugin;
51
52         UAM_DBG("Plugin [id: %d, name: %s, version: %s]",
53                         module->id, module->name, module->version);
54
55         if (UAS_PLUGIN_ID_MAX <= module->id ||
56                         UAS_PLUGIN_ID_BLE > module->id) {
57                 UAM_ERR("Unknown Id %d for %s", module->id, module->name);
58                 return FALSE;
59         }
60
61         if (NULL != plugins[module->id]) {
62                 UAM_ERR("Plugin %s already added",
63                                 plugins[module->id]->module->name);
64                 return FALSE;
65         }
66
67         if (g_str_equal(module->version, UAM_VERSION) == FALSE) {
68                 UAM_ERR("Version (%s) mismatch for %s",
69                                 module->version, module->name);
70                 return FALSE;
71         }
72
73         plugin = g_try_new0(uam_sensor_plugin_info_t, 1);
74         if (NULL == plugin) {
75                 UAM_ERR("Memory allocation failed");
76                 return FALSE;
77         }
78         if (NULL == module->init) {
79                 UAM_ERR("module->init is NULL");
80                 g_free(plugin);
81                 return FALSE;
82         }
83
84         module->init(&api);
85         if (NULL == api) {
86                 UAM_ERR("API returned is NULL");
87                 g_free(plugin);
88                 return FALSE;
89         }
90
91         plugin->handle = handle;
92         plugin->module = module;
93         plugin->api = api;
94
95         plugins[module->id] = plugin;
96
97         FUNC_EXIT;
98         return TRUE;
99 }
100
101 static int __load_plugin(const char *path, const char *name, const char *symbol)
102 {
103         FUNC_ENTRY;
104         char *filename;
105         void *handle;
106         uas_module_t *module;
107
108         retv_if(NULL == path, UAM_ERROR_INVALID_PARAMETER);
109         retv_if(NULL == name, UAM_ERROR_INVALID_PARAMETER);
110         retv_if(NULL == symbol, UAM_ERROR_INVALID_PARAMETER);
111
112         filename = g_build_filename(path, name, NULL);
113         UAM_DBG("Loading [%s]", filename);
114
115         handle = dlopen(filename, RTLD_NOW);
116         g_free(filename);
117         if (handle == NULL) {
118                 UAM_ERR("Can't load plugin %s", dlerror());
119                 return UAM_ERROR_INTERNAL;
120         }
121
122         module = (uas_module_t *)dlsym(handle, symbol);
123         if (module == NULL) {
124                 UAM_ERR("Can't load plugin module: %s", dlerror());
125                 dlclose(handle);
126                 return UAM_ERROR_INTERNAL;
127         }
128
129         retv_if(FALSE == __add_plugin(handle, module), UAM_ERROR_INTERNAL);
130
131         FUNC_EXIT;
132         return UAM_ERROR_NONE;
133 }
134
135 static int __load_sensor_plugins(void)
136 {
137         FUNC_ENTRY;
138
139         GDir *dir;
140         const char *filename;
141         int ret = UAM_ERROR_INTERNAL;
142
143         retv_if(0 == strlen(SENSOR_PLUGIN_DIR), UAM_ERROR_INVALID_PARAMETER);
144
145         UAM_DBG("Loading plugins from %s", SENSOR_PLUGIN_DIR);
146
147         dir = g_dir_open(SENSOR_PLUGIN_DIR, 0, NULL);
148         if (!dir) {
149                 UAM_ERR("Unable to open directory");
150                 return UAM_ERROR_INTERNAL;
151         }
152
153         while ((filename = g_dir_read_name(dir)) != NULL) {
154
155                 if (g_str_has_suffix(filename, ".so") == FALSE)
156                         continue;
157
158                 /* If atleast one plugin is loaded, return value is UAM_ERROR_NONE */
159                 if (UAM_ERROR_NONE == __load_plugin(
160                                         SENSOR_PLUGIN_DIR, filename, "uas_module"))
161                         ret = UAM_ERROR_NONE;
162
163         }
164
165         g_dir_close(dir);
166
167         FUNC_EXIT;
168         return ret;
169 }
170
171 static int __init_sensor_plugins(void)
172 {
173         FUNC_ENTRY;
174         int ret = UAM_ERROR_INTERNAL;
175         int id;
176
177         retv_if(UAM_ERROR_NONE != __load_sensor_plugins(), UAM_ERROR_INTERNAL);
178
179         /* Initialize loaded sensor plugins */
180         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
181                 uam_sensor_plugin_info_t *plugin = plugins[id];
182                 int status;
183
184                 if (!plugin || !plugin->api) {
185                         UAM_WARN("Plugin with ID: %s is NULL", _uam_get_sensor_str(id));
186                         continue;
187                 }
188
189                 switch (id) {
190                 case UAS_PLUGIN_ID_BLE:
191                         status = plugin->api->init(&ble_cbs);
192                         if (UAS_STATUS_SUCCESS != status) {
193                                 /* Deinit plugin */
194                                 continue;
195                         }
196
197                         plugin->capability = UAS_NOT_SUPPORT_USER;
198                         if (UAS_STATUS_SUCCESS != plugin->api->get_capability(
199                                                 &plugin->capability))
200                                 plugin->capability = UAS_NOT_SUPPORT_USER;
201
202                         available_sensors |= UAM_SENSOR_BITMASK_BLE;
203                         break;
204                 case UAS_PLUGIN_ID_WIFI:
205                         status = plugin->api->init(&wifi_cbs);
206                         if (UAS_STATUS_SUCCESS != status) {
207                                 /* Deinit plugin */
208                                 continue;
209                         }
210
211                         plugin->capability = UAS_NOT_SUPPORT_USER;
212                         if (UAS_STATUS_SUCCESS != plugin->api->get_capability(
213                                                 &plugin->capability))
214                                 plugin->capability = UAS_NOT_SUPPORT_USER;
215
216                         available_sensors |= UAM_SENSOR_BITMASK_WIFI;
217                         break;
218
219                 case UAS_PLUGIN_ID_LIGHT:
220                         status = plugin->api->init(&light_cbs);
221                         if (UAS_STATUS_SUCCESS != status) {
222                                 /* Deinit plugin */
223                                 continue;
224                         }
225
226                         available_sensors |= UAM_SENSOR_BITMASK_LIGHT;
227                         break;
228                 case UAS_PLUGIN_ID_MOTION:
229                         status = plugin->api->init(&motion_cbs);
230                         if (UAS_STATUS_SUCCESS != status) {
231                                 /* Deinit plugin */
232                                 continue;
233                         }
234
235                         available_sensors |= UAM_SENSOR_BITMASK_MOTION;
236                         break;
237                 }
238
239                 /* If atleast one sensor init is success, return success */
240                 ret = UAM_ERROR_NONE;
241         }
242
243         FUNC_EXIT;
244         return ret;
245 }
246
247 static void __deinit_sensor_plugins(void)
248 {
249         FUNC_ENTRY;
250         int id;
251
252         /* Deinitialize and unload sensor plugins */
253         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
254                 uam_sensor_plugin_info_t *plugin = plugins[id];
255
256                 if (!plugin)
257                         continue;
258
259                 if (plugin->api && plugin->api->deinit)
260                         plugin->api->deinit();
261
262                 if (plugin->module && plugin->module->deinit)
263                         plugin->module->deinit();
264
265                 if (plugin->handle)
266                         dlclose(plugin->handle);
267
268                 g_free(plugin);
269                 plugin = NULL;
270         }
271
272         available_sensors = 0;
273         FUNC_EXIT;
274 }
275
276 static void __uas_device_list_free(int count, uas_device_info_t *devices)
277 {
278         FUNC_ENTRY;
279         int i;
280         int j;
281
282         for (i = 0; i < count; i++) {
283                 uas_device_info_t *device = &(devices[i]);
284
285                 g_free(device->device_id);
286
287                 for (j = 0; j < device->num_addr; j++)
288                         g_free(device->addr_list[j].address);
289
290                 g_free(device->addr_list);
291         }
292
293         g_free(devices);
294
295         FUNC_EXIT;
296 }
297
298 static uas_device_info_t *__get_uas_device_list(int id, GSList *devices, int *num_devices)
299 {
300         FUNC_ENTRY;
301         uas_device_info_t *dev_list;
302         GSList *l;
303         int len;
304         int count = 0;
305         unsigned int tech_type;
306
307         retv_if(NULL == devices, NULL);
308
309         tech_type = _pm_util_uas_plugin_id_to_tech_type(id);
310         retv_if(UAM_TECH_TYPE_NONE == tech_type, NULL);
311
312         len = g_slist_length(devices);
313         dev_list = g_new0(uas_device_info_t, len);
314
315         for (l = devices; NULL != l; l = g_slist_next(l)) {
316                 uam_db_device_info_t *dev = l->data;
317                 uas_device_info_t *device = &(dev_list[count]);
318
319                 if (!dev)
320                         continue;
321
322                 if (dev->supported_techs & tech_type) {
323                         _pm_util_uam_db_dev_to_uas_dev(tech_type, dev, &device);
324                         device->supported_techs = dev->supported_techs;
325                         count++;
326                 }
327         }
328
329         *num_devices = count;
330         FUNC_EXIT;
331
332         return dev_list;
333 }
334
335 int _uam_pm_init(void)
336 {
337         FUNC_ENTRY;
338         int ret;
339
340         ret = __init_sensor_plugins();
341         if (UAM_ERROR_NONE != ret)
342                 return ret;
343
344         FUNC_EXIT;
345         return UAM_ERROR_NONE;
346 }
347
348 void _uam_pm_deinit(void)
349 {
350         FUNC_ENTRY;
351
352         __deinit_sensor_plugins();
353
354         FUNC_EXIT;
355 }
356
357 unsigned int _uam_pm_get_avaliable_sensors(void)
358 {
359         FUNC_ENTRY;
360
361         UAM_DBG("Available sensors: 0x%8.8X", available_sensors);
362
363         FUNC_EXIT;
364         return available_sensors;
365 }
366
367 gboolean _uam_pm_is_sensor_ready(unsigned int sensor_bitmask)
368 {
369         FUNC_ENTRY;
370         int id;
371         int state;
372         uam_sensor_plugin_info_t *plugin;
373
374         id = _pm_util_sensor_bitmask_to_plugin_id(sensor_bitmask);
375         retv_if(UAS_PLUGIN_ID_MAX <= id, FALSE);
376
377         plugin = plugins[id];
378         retv_if(!plugin || !plugin->api, FALSE);
379
380         if (UAS_STATUS_SUCCESS != plugin->api->get_state(&state))
381                 state = UAS_STATE_NOT_READY;
382
383         UAM_DBG("Sensor: 0x%8.8X, State: %d", sensor_bitmask, state);
384
385         FUNC_EXIT;
386         return (UAS_STATE_READY == state ? TRUE : FALSE);
387 }
388
389 int _uam_pm_register_device(int user_id, const uam_device_info_s *dev)
390 {
391         FUNC_ENTRY;
392         int id;
393         uam_sensor_plugin_info_t *plugin;
394         uas_device_info_t *device = NULL;
395
396         retv_if(NULL == dev, UAM_ERROR_INVALID_PARAMETER);
397
398         id = _pm_util_uam_tech_type_to_plugin_id(dev->type);
399         retv_if(UAS_PLUGIN_ID_MAX <= id, UAM_ERROR_INVALID_PARAMETER);
400
401         plugin = plugins[id];
402         retv_if(!plugin || !plugin->api, UAM_ERROR_NOT_SUPPORTED);
403         retv_if(UAS_SUPPORT_USER != plugin->capability, UAM_ERROR_NOT_SUPPORTED);
404
405         device = _pm_util_uam_dev_info_to_uas_dev_info(dev);
406         retv_if(NULL == device, UAM_ERROR_INTERNAL);
407
408         device->user_id = user_id;
409         if (UAS_STATUS_SUCCESS != plugin->api->add_device(device)) {
410                 UAM_ERR("plugin->add_device() failed");
411                 return UAM_ERROR_INTERNAL;
412         }
413         _pm_util_uas_device_info_free(device);
414
415         FUNC_EXIT;
416         return UAM_ERROR_NONE;
417 }
418
419 int _uam_pm_unregister_device(int user_id, const uam_device_info_s *dev)
420 {
421         FUNC_ENTRY;
422         int id;
423         uam_sensor_plugin_info_t *plugin;
424         uas_device_info_t *device = NULL;
425         int ret;
426
427         retv_if(NULL == dev, UAM_ERROR_INVALID_PARAMETER);
428
429         id = _pm_util_uam_tech_type_to_plugin_id(dev->type);
430         retv_if(UAS_PLUGIN_ID_MAX <= id, UAM_ERROR_INVALID_PARAMETER);
431
432         plugin = plugins[id];
433         retv_if(!plugin || !plugin->api, UAM_ERROR_NOT_SUPPORTED);
434         retv_if(UAS_SUPPORT_USER != plugin->capability, UAM_ERROR_NOT_SUPPORTED);
435
436         device = _pm_util_uam_dev_info_to_uas_dev_info(dev);
437         retv_if(NULL == device, UAM_ERROR_INTERNAL);
438         device->user_id = user_id;
439
440         ret = plugin->api->remove_device(device);
441         if (UAS_STATUS_SUCCESS != ret && UAS_STATUS_ALREADY_DONE != ret) {
442                 UAM_ERR("plugin->remove_device() failed");
443         }
444
445         _pm_util_uas_device_info_free(device);
446
447         FUNC_EXIT;
448         return UAM_ERROR_NONE;
449 }
450
451 int _uam_pm_set_registered_devices(GSList *devices)
452 {
453         FUNC_ENTRY;
454         int id;
455         uas_device_info_t *dev_list = NULL;
456         int num_devices = 0;
457
458         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
459                 uam_sensor_plugin_info_t *plugin = plugins[id];
460
461                 if (!plugin || !plugin->api)
462                         continue;
463
464                 if (UAS_SUPPORT_USER != plugin->capability)
465                         continue;
466
467                 dev_list = __get_uas_device_list(id, devices, &num_devices);
468                 if (!dev_list)
469                         UAM_INFO("No devices for Plugin %d", id);
470
471                 if (UAS_STATUS_SUCCESS != plugin->api->set_registered_devices(
472                                         num_devices, dev_list))
473                         UAM_ERR("plugin->set_registered_devices() failed for %d", id);
474
475                 __uas_device_list_free(num_devices, dev_list);
476         }
477
478         FUNC_EXIT;
479         return UAM_ERROR_NONE;
480 }
481
482 int _uam_pm_start_detection(unsigned int detection_mode, unsigned int bitmask)
483 {
484         FUNC_ENTRY;
485         int id;
486         int status;
487         int ret = UAM_ERROR_INTERNAL;
488         uas_detection_type_e type;
489
490         switch (detection_mode) {
491         case UAM_DETECT_PRESENCE:
492                 type = UAS_PRESENCE;
493                 break;
494         case UAM_DETECT_ABSENCE:
495                 type = UAS_ABSENCE;
496                 break;
497         default:
498                 type = UAS_PRESENCE | UAS_ABSENCE;
499         }
500
501         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
502                 uam_sensor_plugin_info_t *plugin = plugins[id];
503                 unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id);
504
505                 if (!(sensor & bitmask))
506                         continue;
507
508                 if (!plugin || !plugin->api)
509                         continue;
510
511                 /*
512                  * For User/device detection capable plugins, need to start both, PRESENCE
513                  * as well as ABSENCE detection, to keep UA database updated.
514                  */
515                 if (UAS_PLUGIN_ID_BLE == id || UAS_PLUGIN_ID_WIFI == id)
516                         status = plugin->api->start_detection(UAS_PRESENCE | UAS_ABSENCE);
517                 else
518                         status = plugin->api->start_detection(type);
519
520                 if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
521                         UAM_ERR("plugin->start_detection(%d) failed for %d", type, id);
522                         continue;
523                 }
524
525                 if (UAS_PLUGIN_ID_BLE == id)
526                         ble_detection_type |= type;
527                 if (UAS_PLUGIN_ID_WIFI == id)
528                         wifi_detection_type |= type;
529
530                 /* Result success if detection started for atleast 1 of the sensor */
531                 ret = UAM_ERROR_NONE;
532         }
533
534         FUNC_EXIT;
535         return ret;
536 }
537
538 int _uam_pm_stop_detection(unsigned int detection_mode, unsigned int bitmask)
539 {
540         FUNC_ENTRY;
541         int id;
542         int status;
543         int ret = UAM_ERROR_INTERNAL;
544         uas_detection_type_e type;
545
546         switch (detection_mode) {
547         case UAM_DETECT_PRESENCE:
548                 type = UAS_PRESENCE;
549                 break;
550         case UAM_DETECT_ABSENCE:
551                 type = UAS_ABSENCE;
552                 break;
553         default:
554                 type = UAS_PRESENCE | UAS_ABSENCE;
555         }
556
557         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
558                 uam_sensor_plugin_info_t *plugin = plugins[id];
559                 unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id);
560
561                 if (!(sensor & bitmask))
562                         continue;
563
564                 if (!plugin || !plugin->api)
565                         continue;
566
567                 if (UAS_PLUGIN_ID_BLE == id) {
568                         ble_detection_type &= ~type;
569                         ret = UAM_ERROR_NONE;
570                         if (0 != ble_detection_type)
571                                 continue;
572                 }
573
574                 if (UAS_PLUGIN_ID_WIFI == id) {
575                         wifi_detection_type &= ~type;
576                         ret = UAM_ERROR_NONE;
577                         if (0 != wifi_detection_type)
578                                 continue;
579                 }
580
581                 if (UAS_PLUGIN_ID_BLE == id || UAS_PLUGIN_ID_WIFI == id)
582                         status = plugin->api->stop_detection(UAS_PRESENCE | UAS_ABSENCE);
583                 else
584                         status = plugin->api->stop_detection(type);
585
586                 if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
587                         UAM_ERR("plugin->stop_detection(%d) failed for %d", type, id);
588                         continue;
589                 }
590
591                 /* Result success if detection stopped for atleast 1 of the sensor */
592                 ret = UAM_ERROR_NONE;
593         }
594
595         FUNC_EXIT;
596         return ret;
597 }
598
599 int _uam_pm_set_low_power_mode(unsigned int bitmask, gboolean mode)
600 {
601         FUNC_ENTRY;
602         int id;
603
604         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
605                 uam_sensor_plugin_info_t *plugin = plugins[id];
606                 unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id);
607
608                 if (!(sensor & bitmask))
609                         continue;
610
611                 if (!plugin || !plugin->api || !plugin->api->set_low_power_mode)
612                         continue;
613
614                 if (UAS_STATUS_SUCCESS !=
615                                 plugin->api->set_low_power_mode(mode ? 1 : 0))
616                         UAM_ERR("plugin->set_low_power_mode() failed for %d", id);
617         }
618
619         FUNC_EXIT;
620         return UAM_ERROR_NONE;
621 }
622
623 int _uam_pm_set_detection_window(unsigned int detection_window)
624 {
625         FUNC_ENTRY;
626         int id;
627         int ret = UAM_ERROR_INTERNAL;
628
629         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
630                 uam_sensor_plugin_info_t *plugin = plugins[id];
631
632                 if (!plugin || !plugin->api || !plugin->api->set_detection_window)
633                         continue;
634
635                 if (UAS_STATUS_SUCCESS != plugin->api->set_detection_window(detection_window)) {
636                         UAM_ERR("plugin->set_detection_window() failed");
637                         continue;
638                 }
639
640                 /* Result success if detection params set for atleast 1 of the sensors */
641                 ret = UAM_ERROR_NONE;
642         }
643
644         FUNC_EXIT;
645         return ret;
646 }
647
648 int _uam_pm_set_detection_threshold(unsigned int sensor,
649                 int presence_threshold, int absence_threshold)
650 {
651         FUNC_ENTRY;
652         int id;
653         uam_sensor_plugin_info_t *plugin;
654
655         id = _pm_util_sensor_bitmask_to_plugin_id(sensor);
656         retv_if(UAS_PLUGIN_ID_MAX <= id, UAM_ERROR_INVALID_PARAMETER);
657
658         plugin = plugins[id];
659         retv_if(!plugin || !plugin->api, UAM_ERROR_NOT_SUPPORTED);
660
661         if (UAS_STATUS_SUCCESS != plugin->api->set_detection_threshold(
662                                 presence_threshold, absence_threshold)) {
663                 UAM_ERR("plugin->set_detection_threshold() failed");
664                 return UAM_ERROR_INTERNAL;
665         }
666
667         FUNC_EXIT;
668         return UAM_ERROR_NONE;
669 }
670
671 int _uam_pm_start_active_device_scan(unsigned int* bitmask, int detection_period)
672 {
673         FUNC_ENTRY;
674         int id;
675         int status;
676         int ret = UAM_ERROR_INTERNAL;
677
678         unsigned int scanning_sensor = 0;
679
680         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
681                 uam_sensor_plugin_info_t *plugin = plugins[id];
682                 unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id);
683
684                 if (!(sensor & (*bitmask)))
685                         continue;
686
687                 if (!plugin || !plugin->api || !plugin->api->scan_active_devices)
688                         continue;
689
690                 status = plugin->api->scan_active_devices(detection_period);
691
692                 if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
693                         UAM_ERR("plugin->search_active_devices(%d) failed for %d", detection_period, id);
694                         continue;
695                 }
696
697                 scanning_sensor |= sensor;
698                 /* Result success if scanning started for atleast 1 of the sensor */
699                 ret = UAM_ERROR_NONE;
700         }
701
702         (*bitmask) &= scanning_sensor;
703
704         FUNC_EXIT;
705         return ret;
706 }
707
708 int _uam_pm_stop_active_device_scan(unsigned int bitmask)
709 {
710         FUNC_ENTRY;
711         int id;
712         int status;
713         int ret = UAM_ERROR_INTERNAL;
714
715         for (id = UAS_PLUGIN_ID_BLE; id < UAS_PLUGIN_ID_MAX; id++) {
716                 uam_sensor_plugin_info_t *plugin = plugins[id];
717                 unsigned int sensor = _pm_util_uas_plugin_id_to_sensor_bitmask(id);
718
719                 if (!(sensor & bitmask))
720                         continue;
721
722                 if (!plugin || !plugin->api || !plugin->api->cancel_active_device_scan)
723                         continue;
724
725                 status = plugin->api->cancel_active_device_scan();
726
727                 if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
728                         UAM_ERR("plugin->stop_search_active_devices() failed for %d", id);
729                         continue;
730                 }
731
732                 ret = UAM_ERROR_NONE;
733         }
734
735         FUNC_EXIT;
736         return ret;
737 }
738
739 int _uam_pm_add_ibeacon_adv(unsigned int adv_len, const char *iadv)
740 {
741         FUNC_ENTRY;
742         int id;
743         int status;
744         int ret = UAM_ERROR_INTERNAL;
745
746         id = UAS_PLUGIN_ID_BLE;
747         uam_sensor_plugin_info_t *plugin = plugins[id];
748
749         if (!plugin || !plugin->api || !plugin->api->add_ibeacon_adv) {
750                 ret = UAM_ERROR_NOT_SUPPORTED;
751                 goto done;
752         }
753
754         status = plugin->api->add_ibeacon_adv(adv_len, iadv);
755         if (UAS_STATUS_SUCCESS != status && UAS_STATUS_ALREADY_DONE != status) {
756                 UAM_ERR("plugin->add_ibeacon_adv failed for %d", id);
757                 goto done;
758         }
759         ret = UAM_ERROR_NONE;
760
761 done:
762         FUNC_EXIT;
763         return ret;
764 }