42dee1009ba13286ca7963f7177cc12b6f90e708
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-emul / 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 #ifdef TIZEN_FEATURE_BT_DPM
18
19 #include <glib.h>
20 #include <gio/gio.h>
21 #include <dlog.h>
22 #include <string.h>
23 #include <bundle_internal.h>
24 #include <vconf.h>
25
26 #include "bluetooth-api.h"
27 #include "bt-internal-types.h"
28
29 #include "bt-service-common.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-dpm.h"
32
33 static dpm_policy_t policy_table[DPM_POLICY_END] = {
34         [DPM_POLICY_ALLOW_BLUETOOTH] = { {DPM_BT_ERROR} },
35         [DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION] = { {DPM_STATUS_ERROR} },
36         [DPM_POLICY_BLUETOOTH_UUID_RESTRICTION] = { {DPM_STATUS_ERROR} },
37         [DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST] = { {NULL} },
38         [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = { {NULL} },
39         [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = { {NULL} },
40         [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = { {NULL} },
41         [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = { {DPM_STATUS_ERROR} },
42         [DPM_POLICY_BLUETOOTH_PAIRING_STATE] = { {DPM_STATUS_ERROR} },
43         [DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE] = { {DPM_STATUS_ERROR} },
44         [DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
45         [DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
46         [DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE] = { {DPM_STATUS_ERROR} },
47 };
48
49
50 /**
51  * @brief DPM profile state
52  * @see
53  */
54 static dpm_profile_state_t dpm_profile_state[DPM_PROFILE_NONE]  = {
55         [DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE] = {DPM_STATUS_ERROR},
56         [DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE] = {DPM_STATUS_ERROR},
57         [DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
58         [DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE] = {DPM_STATUS_ERROR},
59         [DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE] = {DPM_STATUS_ERROR},
60         [DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE] = {DPM_STATUS_ERROR},
61         [DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE] = {DPM_STATUS_ERROR},
62         [DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
63         [DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
64         [DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
65 };
66
67 dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
68 {
69         BT_INFO("_bt_dpm_set_allow_bluetooth_mode");
70
71 #if 0
72         if (value == DPM_BT_ALLOWED && value == DPM_BT_HANDSFREE_ONLY) {
73                 /* Update Bluetooth DPM Status to notify other modules */
74                 if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, value) != 0)
75                         BT_ERR("Set vconf failed\n");
76                         return DPM_RESULT_FAIL;
77         } else {
78                 /* Update Bluetooth DPM Status to notify other modules */
79                 if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, VCONFKEY_BT_DPM_STATUS_RESTRICTED) != 0)
80                         BT_ERR("Set vconf failed\n");
81                         return DPM_RESULT_FAIL;
82         }
83 #endif
84         policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value  = value;
85
86         return DPM_RESULT_SUCCESS;
87 }
88
89 dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void)
90 {
91         BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
92
93         return policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
94 }
95
96 dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
97 {
98         BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
99         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
100                 return DPM_RESULT_ACCESS_DENIED;
101
102         policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value  = value;
103
104         return DPM_RESULT_SUCCESS;
105 }
106
107 dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void)
108 {
109         BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
110
111         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
112                 return DPM_RESTRICTED;
113
114         return policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
115 }
116
117 dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
118 {
119         BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
120         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
121                 return DPM_RESULT_ACCESS_DENIED;
122
123         policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value  = value;
124
125         return DPM_RESULT_SUCCESS;
126 }
127
128 dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void)
129 {
130         BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
131
132         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
133                 return DPM_RESTRICTED;
134
135         return policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
136 }
137
138 dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr)
139 {
140         char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
141         char *dev_addr = NULL;
142
143         BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
144
145         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
146                 return DPM_RESULT_ACCESS_DENIED;
147
148         BT_CHECK_PARAMETER(bd_addr, return);
149
150         _bt_convert_addr_type_to_string(device_address,
151                         (unsigned char *)bd_addr->addr);
152
153         dev_addr = g_strdup(device_address);
154         if (!dev_addr)
155                 return DPM_RESULT_FAIL;
156         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
157
158         return DPM_RESULT_SUCCESS;
159 }
160
161 dpm_result_t _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
162 {
163         dpm_result_t ret = DPM_RESULT_FAIL;
164         bt_dpm_device_list_t device_list;
165         GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
166         int i = 0;
167
168         BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
169
170         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
171                 return ret;
172
173         if (list) {
174                 ret = DPM_RESULT_SUCCESS;
175                 for (; list; list = list->next, i++) {
176                         memset(device_list.addresses[i].addr, 0, BT_ADDRESS_STRING_SIZE);
177                         _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
178                 }
179                 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
180                 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
181         } else {
182                 ret = DPM_RESULT_SUCCESS;
183                 device_list.count = 0;
184                 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
185         }
186         return ret;
187 }
188
189 dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
190 {
191         char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
192         char *dev_addr = NULL;
193
194         BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
195
196         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
197                 return DPM_RESULT_ACCESS_DENIED;
198
199         BT_CHECK_PARAMETER(bd_addr, return);
200
201         _bt_convert_addr_type_to_string(device_address,
202                         (unsigned char *)bd_addr->addr);
203
204         dev_addr = g_strdup(device_address);
205         if (!dev_addr)
206                 return DPM_RESULT_FAIL;
207         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
208         return DPM_RESULT_SUCCESS;
209 }
210
211 dpm_result_t _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
212 {
213         dpm_result_t ret = DPM_RESULT_FAIL;
214         bt_dpm_device_list_t device_list;
215         GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
216         int i = 0;
217
218         BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
219
220         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
221                 return ret;
222
223         if (list) {
224                 ret = DPM_RESULT_SUCCESS;
225                 for (; list; list = list->next, i++) {
226                         memset(device_list.addresses[i].addr, 0, BT_ADDRESS_STRING_SIZE);
227                         _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
228
229                 }
230                 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
231                 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
232         } else {
233                 ret = DPM_RESULT_SUCCESS;
234                 device_list.count = 0;
235                 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
236         }
237         return ret;
238 }
239
240 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
241 {
242         char *l_uuid;
243         BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
244
245         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
246                 return DPM_RESULT_ACCESS_DENIED;
247
248         l_uuid = g_strdup(uuid);
249         if (!l_uuid)
250                 return DPM_RESULT_FAIL;
251         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
252         return DPM_RESULT_SUCCESS;
253 }
254
255 dpm_result_t _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
256 {
257         dpm_result_t ret = DPM_RESULT_FAIL;
258         bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
259         GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
260         int i = 0;
261
262         BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
263
264         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
265                 return ret;
266
267         if (list) {
268                 ret = DPM_RESULT_SUCCESS;
269                 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
270                 for (; list; list = list->next, i++) {
271                         memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
272                         g_strlcpy(uuids_list.uuids[i], list->data,
273                                 BLUETOOTH_UUID_STRING_MAX);
274                 }
275                 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
276         } else {
277                 ret = DPM_RESULT_SUCCESS;
278                 uuids_list.count = 0;
279                 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
280         }
281
282         return ret;
283 }
284
285 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
286 {
287         char *l_uuid;
288         BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
289
290         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
291                 return DPM_RESULT_ACCESS_DENIED;
292
293         l_uuid = g_strdup(uuid);
294         if (!l_uuid)
295                 return DPM_RESULT_FAIL;
296         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
297         return DPM_RESULT_SUCCESS;
298 }
299
300
301 dpm_result_t _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
302 {
303         dpm_result_t ret = DPM_RESULT_FAIL;
304         bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
305         GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
306         int i = 0;
307
308         BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
309
310         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
311                 return ret;
312
313         if (list) {
314                 ret = DPM_RESULT_SUCCESS;
315                 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
316                 for (; list; list = list->next, i++) {
317                         memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
318                         g_strlcpy(uuids_list.uuids[i], list->data,
319                                 BLUETOOTH_UUID_STRING_MAX);
320                 }
321                 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
322         } else {
323                 ret = DPM_RESULT_SUCCESS;
324                 uuids_list.count = 0;
325                 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
326         }
327
328         return ret;
329
330 }
331
332 dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
333 {
334         BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
335         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
336                 return DPM_RESULT_ACCESS_DENIED;
337
338         policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value  = value;
339
340         return DPM_RESULT_SUCCESS;
341 }
342
343 dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void)
344 {
345         BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
346
347         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
348                 return DPM_RESTRICTED;
349
350         return policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
351 }
352
353 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
354 {
355         GSList *l = NULL;
356         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
357
358         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
359                 return DPM_RESULT_ACCESS_DENIED;
360
361         for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
362                 char *address = l->data;
363                 if (address) {
364                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
365                         g_free(address);
366                 }
367         }
368         g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
369         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
370         return DPM_RESULT_SUCCESS;
371 }
372
373 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
374 {
375         GSList *l = NULL;
376         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
377
378         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
379                 return DPM_RESULT_ACCESS_DENIED;
380
381         for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
382                 char *address = l->data;
383                 if (address) {
384                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
385                         g_free(address);
386                 }
387         }
388         g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
389         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
390         return DPM_RESULT_SUCCESS;
391 }
392
393 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
394 {
395         GSList *l = NULL;
396         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
397
398         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
399                 return DPM_RESULT_ACCESS_DENIED;
400
401         for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
402                 char *l_uuid = l->data;
403                 if (l_uuid)
404                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
405                         g_free(l_uuid);
406         }
407         g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
408         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
409         return DPM_RESULT_SUCCESS;
410 }
411
412 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
413 {
414         GSList *l = NULL;
415         BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
416
417         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
418                 return DPM_RESULT_ACCESS_DENIED;
419
420         for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
421                 char *l_uuid = l->data;
422                 if (l_uuid) {
423                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
424                         g_free(l_uuid);
425                 }
426         }
427         g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
428         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
429         return DPM_RESULT_SUCCESS;
430 }
431
432 dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
433 {
434         BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
435
436         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
437                 return DPM_RESTRICTED;
438
439         policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
440
441         return DPM_RESULT_SUCCESS;
442 }
443
444 dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void)
445 {
446         BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
447
448         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
449                 return DPM_RESTRICTED;
450
451         return policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
452 }
453
454 dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
455 {
456         BT_INFO("_bt_dpm_set_bluetooth_profile_state");
457
458         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
459                 return DPM_RESTRICTED;
460
461         dpm_profile_state[profile].value = value;
462
463         return DPM_RESULT_SUCCESS;
464 }
465
466 dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile)
467 {
468         BT_INFO("_bt_dpm_get_bluetooth_profile_state");
469
470         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
471                 return DPM_RESTRICTED;
472
473         return dpm_profile_state[profile].value;
474 }
475
476 dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
477 {
478         BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
479
480         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
481                 return DPM_RESTRICTED;
482
483         policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
484
485         return DPM_RESULT_SUCCESS;
486 }
487
488 dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void)
489 {
490         BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
491
492         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
493                 return DPM_RESTRICTED;
494
495         return policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
496 }
497
498 dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
499 {
500         BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
501
502         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
503                 return DPM_RESTRICTED;
504
505         if (value == DPM_RESTRICTED) {
506                 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
507                 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
508         }
509
510         policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
511
512         return DPM_RESULT_SUCCESS;
513 }
514
515 dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void)
516 {
517         BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
518
519         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
520                 return DPM_RESTRICTED;
521
522         return policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
523 }
524
525 dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
526 {
527         BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
528
529         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
530                 return DPM_RESTRICTED;
531
532         if (value == DPM_RESTRICTED) {
533                 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
534                 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
535         }
536
537         policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
538
539         return DPM_RESULT_SUCCESS;
540 }
541
542 dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void)
543 {
544         BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
545
546         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
547                 return DPM_RESTRICTED;
548
549         return policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
550 }
551
552 dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
553 {
554         BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
555
556         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
557                 return DPM_RESTRICTED;
558
559         return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
560 }
561
562 dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(void)
563 {
564         BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
565
566         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
567                 return DPM_RESTRICTED;
568
569         return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
570 }
571
572 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
573 {
574         GSList *l = NULL;
575         char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
576         BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
577
578         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
579                 return DPM_RESULT_ACCESS_DENIED;
580
581         _bt_convert_addr_type_to_string(bd_addr,
582                         (unsigned char *)device_address->addr);
583
584         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
585                 return DPM_RESULT_ACCESS_DENIED;
586
587         for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
588                 char *l_device = l->data;
589                 if (l_device && g_strcmp0(l_device, bd_addr)) {
590                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
591                         g_free(l_device);
592                 }
593         }
594         return DPM_RESULT_SUCCESS;
595 }
596
597 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
598 {
599         GSList *l = NULL;
600         char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
601
602         BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
603
604         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
605                 return DPM_RESULT_ACCESS_DENIED;
606
607         _bt_convert_addr_type_to_string(bd_addr,
608                         (unsigned char *)device_address->addr);
609
610         for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
611                 char *l_device = l->data;
612                 if (l_device && g_strcmp0(l_device, bd_addr)) {
613                         policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
614                         g_free(l_device);
615                 }
616         }
617
618         return DPM_RESULT_SUCCESS;
619 }
620
621 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
622 {
623         GSList *l = NULL;
624         BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
625
626         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
627                 return DPM_RESULT_ACCESS_DENIED;
628         for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
629                 char *l_uuid = l->data;
630                 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
631                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
632                         g_free(l_uuid);
633                 }
634         }
635         return DPM_RESULT_SUCCESS;
636 }
637
638 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
639 {
640         GSList *l = NULL;
641         BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
642
643         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
644                 return DPM_RESULT_ACCESS_DENIED;
645
646         for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
647                 char *l_uuid = l->data;
648                 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
649                         policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
650                         g_free(l_uuid);
651                 }
652         }
653         return DPM_RESULT_SUCCESS;
654 }
655
656 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void)
657 {
658         BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
659         dpm_result_t err = DPM_RESULT_FAIL;
660
661         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
662                 return DPM_RESULT_ACCESS_DENIED;
663
664         err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
665         if (!err)
666                 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
667
668         return err;
669 }
670
671 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void)
672 {
673         BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
674         dpm_result_t err = DPM_RESULT_FAIL;
675
676         if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
677                 return DPM_RESULT_ACCESS_DENIED;
678
679         err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
680         if (!err)
681                 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
682
683         return err;
684 }
685 #endif /* #ifdef TIZEN_FEATURE_BT_DPM */