[warnings] Fix build warnings
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-dpm.c
1 /*
2  * Copyright (c) 2011 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
18 #include <glib.h>
19 #include <gio/gio.h>
20 #include <dlog.h>
21 #include <string.h>
22 #include <syspopup_caller.h>
23 #include <bundle_internal.h>
24
25 #include "bluetooth-api.h"
26 #include "bt-internal-types.h"
27
28 #include "bt-service-common.h"
29 #include "bt-service-dpm.h"
30
31 static dpm_policy_t policy_table[DPM_POLICY_END] = {
32         /* policy-group : BLUETOOTH */
33         [DPM_POLICY_ALLOW_BLUETOOTH] = {DPM_BT_ERROR},
34         [DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION] = {DPM_STATUS_ERROR},
35         [DPM_POLICY_BLUETOOTH_UUID_RESTRICTION] = {DPM_STATUS_ERROR},
36         [DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST] = {NULL},
37         [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = {NULL},
38         [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = {NULL},
39         [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = {NULL},
40         [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = {DPM_STATUS_ERROR},
41         [DPM_POLICY_BLUETOOTH_PAIRING_STATE] = {DPM_STATUS_ERROR},
42         [DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE] = {DPM_STATUS_ERROR},
43         [DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE] = {DPM_STATUS_ERROR},
44         [DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE] = {DPM_STATUS_ERROR},
45         [DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE] = {DPM_STATUS_ERROR},
46 };
47
48
49 /**
50  * @brief DPM profile state
51  * @see
52  */
53 static dpm_profile_state_t dpm_profile_state[DPM_PROFILE_NONE]  = {
54         [DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE] = {DPM_STATUS_ERROR},
55         [DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE] = {DPM_STATUS_ERROR},
56         [DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
57         [DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE] = {DPM_STATUS_ERROR},
58         [DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE] = {DPM_STATUS_ERROR},
59         [DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE] = {DPM_STATUS_ERROR},
60         [DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE] = {DPM_STATUS_ERROR},
61         [DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
62         [DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
63         [DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
64 };
65
66 dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
67 {
68         BT_INFO("_bt_dpm_set_allow_bluetooth_mode");
69         policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value  = value;
70
71         return DPM_RESULT_SUCCESS;
72 }
73
74 dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void)
75 {
76         BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
77         return policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
78 }
79
80 dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
81 {
82         BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
83         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
84                 return DPM_RESULT_ACCESS_DENIED;
85
86         policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value  = value;
87
88         return DPM_RESULT_SUCCESS;
89 }
90
91 dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void)
92 {
93         BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
94
95         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
96                 return DPM_RESTRICTED;
97
98         return policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
99 }
100
101 dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
102 {
103         BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
104         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
105                 return DPM_RESULT_ACCESS_DENIED;
106
107         policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value  = value;
108
109         return DPM_RESULT_SUCCESS;
110 }
111
112 dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void)
113 {
114         BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
115
116         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
117                 return DPM_RESTRICTED;
118
119         return policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
120 }
121
122 dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(char *device_address)
123 {
124         char *dev_addr;
125         BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
126
127         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
128                 return DPM_RESULT_ACCESS_DENIED;
129
130         dev_addr = g_strdup(device_address);
131         if (!dev_addr)
132                 return DPM_RESULT_FAIL;
133         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
134         return DPM_RESULT_SUCCESS;
135 }
136
137 GSList *_bt_dpm_get_bluetooth_devices_from_blacklist(void)
138 {
139         BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
140
141         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
142                 return NULL;
143
144         return policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
145 }
146
147 dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(char *device_address)
148 {
149         char *dev_addr;
150         BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
151
152         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
153                 return DPM_RESULT_ACCESS_DENIED;
154
155         dev_addr = g_strdup(device_address);
156         if (!dev_addr)
157                 return DPM_RESULT_FAIL;
158         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
159         return DPM_RESULT_SUCCESS;
160 }
161
162 GSList *_bt_dpm_get_bluetooth_devices_from_whitelist(void)
163 {
164         BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
165
166         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
167                 return NULL;
168
169         return policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
170 }
171
172 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(char *uuid)
173 {
174         char *l_uuid;
175         BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
176
177         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
178                 return DPM_RESULT_ACCESS_DENIED;
179
180         l_uuid = g_strdup(uuid);
181         if (!l_uuid)
182                 return DPM_RESULT_FAIL;
183         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
184         return DPM_RESULT_SUCCESS;
185 }
186
187 GSList *_bt_dpm_get_bluetooth_uuids_from_blacklist(void)
188 {
189         BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
190
191         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
192                 return NULL;
193
194         return policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
195 }
196
197 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(char *uuid)
198 {
199         char *l_uuid;
200         BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
201
202         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
203                 return DPM_RESULT_ACCESS_DENIED;
204
205         l_uuid = g_strdup(uuid);
206         if (!l_uuid)
207                 return DPM_RESULT_FAIL;
208         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
209         return DPM_RESULT_SUCCESS;
210 }
211
212
213 GSList *_bt_dpm_get_bluetooth_uuids_from_whitelist(void)
214 {
215         BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
216
217         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
218                 return NULL;
219
220         return policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
221 }
222
223 dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
224 {
225         BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
226         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
227                 return DPM_RESULT_ACCESS_DENIED;
228
229         policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value  = value;
230
231         return DPM_RESULT_SUCCESS;
232 }
233
234 dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void)
235 {
236         BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
237
238         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
239                 return DPM_RESTRICTED;
240
241         return policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
242 }
243
244 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
245 {
246         GSList *l = NULL;
247         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
248
249         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
250                 return DPM_RESULT_ACCESS_DENIED;
251
252         for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
253                 char *address = l->data;
254                 if (address) {
255                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
256                         g_free(address);
257                 }
258         }
259         return DPM_RESULT_SUCCESS;
260 }
261
262 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
263 {
264         GSList *l = NULL;
265         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
266
267         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
268                 return DPM_RESULT_ACCESS_DENIED;
269
270         for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
271                 char *address = l->data;
272                 if (address) {
273                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
274                         g_free(address);
275                 }
276         }
277         return DPM_RESULT_SUCCESS;
278 }
279
280 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
281 {
282         GSList *l = NULL;
283         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
284
285         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
286                 return DPM_RESULT_ACCESS_DENIED;
287
288         for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
289                 char *l_uuid = l->data;
290                 if (l_uuid)
291                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
292                         g_free(l_uuid);
293         }
294         return DPM_RESULT_SUCCESS;
295 }
296
297 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
298 {
299         GSList *l = NULL;
300         BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
301
302         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
303                 return DPM_RESULT_ACCESS_DENIED;
304
305         for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
306                 char *l_uuid = l->data;
307                 if (l_uuid) {
308                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
309                         g_free(l_uuid);
310                 }
311         }
312         return DPM_RESULT_SUCCESS;
313 }
314
315 dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
316 {
317         BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
318
319         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
320                 return DPM_RESTRICTED;
321
322         policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
323
324         return DPM_RESULT_SUCCESS;
325 }
326
327 dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void)
328 {
329         BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
330
331         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
332                 return DPM_RESTRICTED;
333
334         return policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
335 }
336
337 dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
338 {
339         BT_INFO("_bt_dpm_set_bluetooth_profile_state");
340
341         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
342                 return DPM_RESTRICTED;
343
344         dpm_profile_state[profile].value = value;
345
346         return DPM_RESULT_SUCCESS;
347 }
348
349 dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile)
350 {
351         BT_INFO("_bt_dpm_get_bluetooth_profile_state");
352
353         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
354                 return DPM_RESTRICTED;
355
356         return dpm_profile_state[profile].value;
357 }
358
359 dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
360 {
361         BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
362
363         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
364                 return DPM_RESTRICTED;
365
366         policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
367
368         return DPM_RESULT_SUCCESS;
369 }
370
371 dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void)
372 {
373         BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
374
375         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
376                 return DPM_RESTRICTED;
377
378         return policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
379 }
380
381 dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
382 {
383         BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
384
385         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
386                 return DPM_RESTRICTED;
387
388         policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
389
390         return DPM_RESULT_SUCCESS;
391 }
392
393 dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void)
394 {
395         BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
396
397         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
398                 return DPM_RESTRICTED;
399
400         return policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
401 }
402
403 dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
404 {
405         BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
406
407         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
408                 return DPM_RESTRICTED;
409
410         policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
411
412         return DPM_RESULT_SUCCESS;
413 }
414
415 dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void)
416 {
417         BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
418
419         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
420                 return DPM_RESTRICTED;
421
422         return policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
423 }
424
425 dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
426 {
427         BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
428
429         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
430                 return DPM_RESTRICTED;
431
432         return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
433 }
434
435 dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(dpm_status_t value)
436 {
437         BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
438
439         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
440                 return DPM_RESTRICTED;
441
442         return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
443 }
444
445 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(GSList *device_addresses)
446 {
447         GSList *l = NULL;
448         GSList *device_list = NULL;
449         BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
450
451         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
452                 return DPM_RESULT_ACCESS_DENIED;
453
454         for (device_list = device_addresses; device_list; device_list = g_slist_next(device_list)) {
455                 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
456                         if (l->data == device_list->data) {
457                                 char *addr = device_list->data;
458                                 if (addr) {
459                                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list =
460                                                 g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, addr);
461                                         g_free(addr);
462                                         break;
463                                 }
464                         }
465                 }
466         }
467         return DPM_RESULT_SUCCESS;
468 }
469
470 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(GSList *device_addresses)
471 {
472         GSList *l = NULL;
473         GSList *device_list = NULL;
474         BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
475
476         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
477                 return DPM_RESULT_ACCESS_DENIED;
478
479         for (device_list = device_addresses; device_list; device_list = g_slist_next(device_list)) {
480                 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
481                         if (l->data == device_list->data) {
482                                 char *addr = device_list->data;
483                                 if (addr) {
484                                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list =
485                                                 g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, addr);
486                                         g_free(addr);
487                                         break;
488                                 }
489                         }
490                 }
491         }
492         return DPM_RESULT_SUCCESS;
493 }
494
495 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(GSList *uuids)
496 {
497         GSList *l = NULL;
498         GSList *uuids_list = NULL;
499         BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
500
501         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
502                 return DPM_RESULT_ACCESS_DENIED;
503
504         for (uuids_list = uuids; uuids_list; uuids_list = g_slist_next(uuids_list)) {
505                 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
506                         if (l->data == uuids_list->data) {
507                                 char *uuid = uuids_list->data;
508                                 if (uuid) {
509                                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list =
510                                                 g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, uuid);
511                                         g_free(uuid);
512                                         break;
513                                 }
514                         }
515                 }
516         }
517         return DPM_RESULT_SUCCESS;
518 }
519
520 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(GSList *uuids)
521 {
522         GSList *l = NULL;
523         GSList *uuids_list = NULL;
524         BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
525
526         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
527                 return DPM_RESULT_ACCESS_DENIED;
528
529         for (uuids_list = uuids; uuids_list; uuids_list = g_slist_next(uuids_list)) {
530                 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
531                         if (l->data == uuids_list->data) {
532                                 char *uuid = uuids_list->data;
533                                 if (uuid) {
534                                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list =
535                                                 g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, uuid);
536                                         g_free(uuid);
537                                         break;
538                                 }
539                         }
540                 }
541         }
542         return DPM_RESULT_SUCCESS;
543 }
544
545 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void)
546 {
547         BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
548         dpm_result_t err = DPM_RESULT_FAIL;
549
550         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
551                 return DPM_RESULT_ACCESS_DENIED;
552
553         err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
554         if (!err){
555                 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
556         }
557
558         return err;
559 }
560
561 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void)
562 {
563         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
564         dpm_result_t err = DPM_RESULT_FAIL;
565
566         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
567                 return DPM_RESULT_ACCESS_DENIED;
568
569         err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
570         if (!err){
571                 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
572         }
573
574         return err;
575 }