2 * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifdef TIZEN_FEATURE_BT_DPM
23 #include <syspopup_caller.h>
24 #include <bundle_internal.h>
27 #include "bluetooth-api.h"
28 #include "bt-internal-types.h"
30 #include "bt-service-common.h"
31 #include "bt-service-adapter.h"
32 #include "bt-service-dpm.h"
34 static dpm_policy_t policy_table[DPM_POLICY_END] = {
35 [DPM_POLICY_ALLOW_BLUETOOTH] = { {DPM_BT_ERROR} },
36 [DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION] = { {DPM_STATUS_ERROR} },
37 [DPM_POLICY_BLUETOOTH_UUID_RESTRICTION] = { {DPM_STATUS_ERROR} },
38 [DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST] = { {NULL} },
39 [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = { {NULL} },
40 [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = { {NULL} },
41 [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = { {NULL} },
42 [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = { {DPM_STATUS_ERROR} },
43 [DPM_POLICY_BLUETOOTH_PAIRING_STATE] = { {DPM_STATUS_ERROR} },
44 [DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE] = { {DPM_STATUS_ERROR} },
45 [DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
46 [DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
47 [DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE] = { {DPM_STATUS_ERROR} },
52 * @brief DPM profile state
55 static dpm_profile_state_t dpm_profile_state[DPM_PROFILE_NONE] = {
56 [DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE] = {DPM_STATUS_ERROR},
57 [DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE] = {DPM_STATUS_ERROR},
58 [DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
59 [DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE] = {DPM_STATUS_ERROR},
60 [DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE] = {DPM_STATUS_ERROR},
61 [DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE] = {DPM_STATUS_ERROR},
62 [DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE] = {DPM_STATUS_ERROR},
63 [DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
64 [DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
65 [DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
68 int _bt_launch_dpm_popup(char *mode)
74 retv_if(b == NULL, BLUETOOTH_ERROR_INTERNAL);
76 bundle_add(b, "mode", mode);
78 ret = syspopup_launch(BT_DPM_SYSPOPUP, b);
81 BT_ERR("Popup launch failed: %d\n", ret);
88 int _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
90 BT_INFO("_bt_dpm_set_allow_bluetooth_mode");
93 if (value == DPM_BT_ALLOWED && value == DPM_BT_HANDSFREE_ONLY) {
94 /* Update Bluetooth DPM Status to notify other modules */
95 if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, value) != 0)
96 BT_ERR("Set vconf failed\n");
97 return DPM_RESULT_FAIL;
99 /* Update Bluetooth DPM Status to notify other modules */
100 if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, VCONFKEY_BT_DPM_STATUS_RESTRICTED) != 0)
101 BT_ERR("Set vconf failed\n");
102 return DPM_RESULT_FAIL;
105 policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value = value;
107 return BLUETOOTH_ERROR_NONE;
110 int _bt_dpm_get_allow_bluetooth_mode(int *value)
112 BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
114 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
116 return BLUETOOTH_ERROR_NONE;
119 int _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
121 int allow_bt = DPM_BT_ERROR;
122 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
124 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
125 if (allow_bt == DPM_BT_RESTRICTED)
126 return BLUETOOTH_ERROR_PERMISSION_DEINED;
128 policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value = value;
130 return BLUETOOTH_ERROR_NONE;
133 int _bt_dpm_is_bluetooth_device_restriction_active(int *value)
135 int allow_bt = DPM_BT_ERROR;
137 BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
139 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
140 if (allow_bt == DPM_BT_RESTRICTED)
141 return BLUETOOTH_ERROR_PERMISSION_DEINED;
143 *value = policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
145 return BLUETOOTH_ERROR_NONE;
148 dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
150 int allow_bt = DPM_BT_ERROR;
152 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
154 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
155 if (allow_bt == DPM_BT_RESTRICTED)
156 return BLUETOOTH_ERROR_PERMISSION_DEINED;
158 policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value = value;
160 return BLUETOOTH_ERROR_NONE;
163 dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(int *value)
165 int allow_bt = DPM_BT_ERROR;
167 BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
169 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
170 if (allow_bt == DPM_BT_RESTRICTED)
171 return BLUETOOTH_ERROR_PERMISSION_DEINED;
173 *value = policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
175 return BLUETOOTH_ERROR_NONE;
178 dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr)
180 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
181 char *dev_addr = NULL;
182 int allow_bt = DPM_BT_ERROR;
184 BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
186 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
187 if (allow_bt == DPM_BT_RESTRICTED)
188 return BLUETOOTH_ERROR_PERMISSION_DEINED;
190 BT_CHECK_PARAMETER(bd_addr, return);
192 _bt_convert_addr_type_to_string(device_address,
193 (unsigned char *)bd_addr->addr);
195 dev_addr = g_strdup(device_address);
197 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
199 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
201 return BLUETOOTH_ERROR_NONE;
204 int _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
206 int ret = BLUETOOTH_ERROR_INTERNAL;
207 int allow_bt = DPM_BT_ERROR;
208 bt_dpm_device_list_t device_list;
209 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
212 BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
214 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
215 if (allow_bt == DPM_BT_RESTRICTED)
216 return BLUETOOTH_ERROR_PERMISSION_DEINED;
219 ret = BLUETOOTH_ERROR_NONE;
220 for (; list; list = list->next, i++) {
221 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
222 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
224 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
225 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
227 ret = BLUETOOTH_ERROR_NONE;
228 device_list.count = 0;
229 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
234 int _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
236 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
237 char *dev_addr = NULL;
238 int allow_bt = DPM_BT_ERROR;
240 BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
242 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
243 if (allow_bt == DPM_BT_RESTRICTED)
244 return BLUETOOTH_ERROR_PERMISSION_DEINED;
246 BT_CHECK_PARAMETER(bd_addr, return);
248 _bt_convert_addr_type_to_string(device_address,
249 (unsigned char *)bd_addr->addr);
251 dev_addr = g_strdup(device_address);
253 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
254 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
255 return BLUETOOTH_ERROR_NONE;
258 int _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
260 dpm_result_t ret = BLUETOOTH_ERROR_INTERNAL;
261 int allow_bt = DPM_BT_ERROR;
262 bt_dpm_device_list_t device_list;
263 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
266 BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
268 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
269 if (allow_bt == DPM_BT_RESTRICTED)
270 return BLUETOOTH_ERROR_PERMISSION_DEINED;
273 ret = BLUETOOTH_ERROR_NONE;
274 for (; list; list = list->next, i++) {
275 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
276 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
279 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
280 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
282 ret = BLUETOOTH_ERROR_NONE;
283 device_list.count = 0;
284 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
289 int _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
292 int allow_bt = DPM_BT_ERROR;
294 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
296 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
297 if (allow_bt == DPM_BT_RESTRICTED)
298 return BLUETOOTH_ERROR_PERMISSION_DEINED;
300 l_uuid = g_strdup(uuid);
302 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
304 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
305 return BLUETOOTH_ERROR_NONE;
308 int _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
310 int ret = BLUETOOTH_ERROR_INTERNAL;
311 int allow_bt = DPM_BT_ERROR;
312 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
313 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
316 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
318 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
319 if (allow_bt == DPM_BT_RESTRICTED)
320 return BLUETOOTH_ERROR_PERMISSION_DEINED;
323 ret = BLUETOOTH_ERROR_NONE;
324 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
325 for (; list; list = list->next, i++) {
326 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
327 g_strlcpy(uuids_list.uuids[i], list->data,
328 BLUETOOTH_UUID_STRING_MAX);
330 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
332 ret = BLUETOOTH_ERROR_NONE;
333 uuids_list.count = 0;
334 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
340 int _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
343 int allow_bt = DPM_BT_ERROR;
345 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
347 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
348 if (allow_bt == DPM_BT_RESTRICTED)
349 return BLUETOOTH_ERROR_PERMISSION_DEINED;
351 l_uuid = g_strdup(uuid);
353 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
355 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
356 return BLUETOOTH_ERROR_NONE;
360 int _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
362 int ret = BLUETOOTH_ERROR_INTERNAL;
363 int allow_bt = DPM_BT_ERROR;
364 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
365 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
368 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
370 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
371 if (allow_bt == DPM_BT_RESTRICTED)
372 return BLUETOOTH_ERROR_PERMISSION_DEINED;
375 ret = BLUETOOTH_ERROR_NONE;
376 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
377 for (; list; list = list->next, i++) {
378 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
379 g_strlcpy(uuids_list.uuids[i], list->data,
380 BLUETOOTH_UUID_STRING_MAX);
382 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
384 ret = BLUETOOTH_ERROR_NONE;
385 uuids_list.count = 0;
386 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
393 int _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
395 int allow_bt = DPM_BT_ERROR;
397 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
399 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
400 if (allow_bt == DPM_BT_RESTRICTED)
401 return BLUETOOTH_ERROR_PERMISSION_DEINED;
403 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
405 return BLUETOOTH_ERROR_NONE;
408 int _bt_dpm_get_allow_bluetooth_outgoing_call(int *value)
410 int allow_bt = DPM_BT_ERROR;
412 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
414 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
415 if (allow_bt == DPM_BT_RESTRICTED)
416 return BLUETOOTH_ERROR_PERMISSION_DEINED;
418 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
420 return BLUETOOTH_ERROR_NONE;
423 int _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
426 int allow_bt = DPM_BT_ERROR;
428 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
430 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
431 if (allow_bt == DPM_BT_RESTRICTED)
432 return BLUETOOTH_ERROR_PERMISSION_DEINED;
434 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
435 char *address = l->data;
437 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
441 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
442 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
444 return BLUETOOTH_ERROR_NONE;
447 int _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
450 int allow_bt = DPM_BT_ERROR;
452 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
454 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
455 if (allow_bt == DPM_BT_RESTRICTED)
456 return BLUETOOTH_ERROR_PERMISSION_DEINED;
458 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
459 char *address = l->data;
461 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
465 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
466 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
468 return BLUETOOTH_ERROR_NONE;
471 int _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
474 int allow_bt = DPM_BT_ERROR;
476 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
478 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
479 if (allow_bt == DPM_BT_RESTRICTED)
480 return BLUETOOTH_ERROR_PERMISSION_DEINED;
482 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
483 char *l_uuid = l->data;
485 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
488 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
489 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
491 return BLUETOOTH_ERROR_NONE;
494 int _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
497 int allow_bt = DPM_BT_ERROR;
499 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
501 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
502 if (allow_bt == DPM_BT_RESTRICTED)
503 return BLUETOOTH_ERROR_PERMISSION_DEINED;
505 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
506 char *l_uuid = l->data;
508 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
512 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
513 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
515 return BLUETOOTH_ERROR_NONE;
518 int _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
520 int allow_bt = DPM_BT_ERROR;
522 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
524 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
525 if (allow_bt == DPM_BT_RESTRICTED)
526 return BLUETOOTH_ERROR_PERMISSION_DEINED;
528 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
530 return BLUETOOTH_ERROR_NONE;
533 int _bt_dpm_get_bluetooth_pairing_state(int *value)
535 int allow_bt = DPM_BT_ERROR;
537 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
539 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
540 if (allow_bt == DPM_BT_RESTRICTED)
541 return BLUETOOTH_ERROR_PERMISSION_DEINED;
543 *value = policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
545 return BLUETOOTH_ERROR_NONE;
548 int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
550 int allow_bt = DPM_BT_ERROR;
552 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
554 if (profile >= DPM_PROFILE_NONE)
555 return BLUETOOTH_ERROR_INTERNAL;
557 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
558 if (allow_bt == DPM_BT_RESTRICTED)
559 return BLUETOOTH_ERROR_PERMISSION_DEINED;
561 dpm_profile_state[profile].value = value;
563 return BLUETOOTH_ERROR_NONE;
566 int _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile, int *value)
568 int allow_bt = DPM_BT_ERROR;
570 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
572 if (profile >= DPM_PROFILE_NONE)
573 return BLUETOOTH_ERROR_INTERNAL;
575 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
576 if (allow_bt == DPM_BT_RESTRICTED)
577 return BLUETOOTH_ERROR_PERMISSION_DEINED;
579 *value = dpm_profile_state[profile].value;
581 return BLUETOOTH_ERROR_NONE;
584 int _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
586 int allow_bt = DPM_BT_ERROR;
588 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
590 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
591 if (allow_bt == DPM_BT_RESTRICTED)
592 return BLUETOOTH_ERROR_PERMISSION_DEINED;
594 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
596 return BLUETOOTH_ERROR_NONE;
599 int _bt_dpm_get_bluetooth_desktop_connectivity_state(int *value)
601 int allow_bt = DPM_BT_ERROR;
603 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
605 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
606 if (allow_bt == DPM_BT_RESTRICTED)
607 return BLUETOOTH_ERROR_PERMISSION_DEINED;
609 *value = policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
611 return BLUETOOTH_ERROR_NONE;
614 int _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
616 int allow_bt = DPM_BT_ERROR;
618 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
620 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
621 if (allow_bt == DPM_BT_RESTRICTED)
622 return BLUETOOTH_ERROR_PERMISSION_DEINED;
624 if (value == DPM_RESTRICTED) {
625 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
626 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
629 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
631 return BLUETOOTH_ERROR_NONE;
634 int _bt_dpm_get_bluetooth_discoverable_state(int *value)
636 int allow_bt = DPM_BT_ERROR;
638 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
640 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
641 if (allow_bt == DPM_BT_RESTRICTED)
642 return BLUETOOTH_ERROR_PERMISSION_DEINED;
644 *value = policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
646 return BLUETOOTH_ERROR_NONE;
649 int _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
651 int allow_bt = DPM_BT_ERROR;
653 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
655 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
656 if (allow_bt == DPM_BT_RESTRICTED)
657 return BLUETOOTH_ERROR_PERMISSION_DEINED;
659 if (value == DPM_RESTRICTED) {
660 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
661 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
664 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
666 return BLUETOOTH_ERROR_NONE;
669 int _bt_dpm_get_bluetooth_limited_discoverable_state(int *value)
671 int allow_bt = DPM_BT_ERROR;
673 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
675 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
676 if (allow_bt == DPM_BT_RESTRICTED)
677 return BLUETOOTH_ERROR_PERMISSION_DEINED;
679 *value = policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
681 return BLUETOOTH_ERROR_NONE;
684 int _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
686 int allow_bt = DPM_BT_ERROR;
688 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
690 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
691 if (allow_bt == DPM_BT_RESTRICTED)
692 return BLUETOOTH_ERROR_PERMISSION_DEINED;
694 policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
695 return BLUETOOTH_ERROR_NONE;
698 int _bt_dpm_get_allow_bluetooth_data_transfer_state(int *value)
700 int allow_bt = DPM_BT_ERROR;
702 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
704 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
705 if (allow_bt == DPM_BT_RESTRICTED)
706 return BLUETOOTH_ERROR_PERMISSION_DEINED;
708 *value = policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
710 return BLUETOOTH_ERROR_NONE;
713 int _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
716 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
717 int allow_bt = DPM_BT_ERROR;
719 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
721 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
722 if (allow_bt == DPM_BT_RESTRICTED)
723 return BLUETOOTH_ERROR_PERMISSION_DEINED;
725 _bt_convert_addr_type_to_string(bd_addr,
726 (unsigned char *)device_address->addr);
728 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
729 char *l_device = l->data;
730 if (l_device && g_strcmp0(l_device, bd_addr)) {
731 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
735 return BLUETOOTH_ERROR_NONE;
738 int _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
741 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
742 int allow_bt = DPM_BT_ERROR;
744 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
746 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
747 if (allow_bt == DPM_BT_RESTRICTED)
748 return BLUETOOTH_ERROR_PERMISSION_DEINED;
750 _bt_convert_addr_type_to_string(bd_addr,
751 (unsigned char *)device_address->addr);
753 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
754 char *l_device = l->data;
755 if (l_device && g_strcmp0(l_device, bd_addr)) {
756 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
761 return BLUETOOTH_ERROR_NONE;
764 int _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
767 int allow_bt = DPM_BT_ERROR;
769 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
771 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
772 if (allow_bt == DPM_BT_RESTRICTED)
773 return BLUETOOTH_ERROR_PERMISSION_DEINED;
775 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
776 char *l_uuid = l->data;
777 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
778 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
782 return BLUETOOTH_ERROR_NONE;
785 int _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
788 int allow_bt = DPM_BT_ERROR;
790 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
792 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
793 if (allow_bt == DPM_BT_RESTRICTED)
794 return BLUETOOTH_ERROR_PERMISSION_DEINED;
796 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
797 char *l_uuid = l->data;
798 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
799 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
803 return BLUETOOTH_ERROR_NONE;
806 int _bt_dpm_clear_bluetooth_uuids_from_list(void)
808 int allow_bt = DPM_BT_ERROR;
809 int err = BLUETOOTH_ERROR_INTERNAL;
811 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
813 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
814 if (allow_bt == DPM_BT_RESTRICTED)
815 return BLUETOOTH_ERROR_PERMISSION_DEINED;
817 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
819 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
824 int _bt_dpm_clear_bluetooth_devices_from_list(void)
826 int allow_bt = DPM_BT_ERROR;
827 int err = BLUETOOTH_ERROR_INTERNAL;
829 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
831 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
832 if (allow_bt == DPM_BT_RESTRICTED)
833 return BLUETOOTH_ERROR_PERMISSION_DEINED;
835 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
837 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
841 #endif /* #ifdef TIZEN_FEATURE_BT_DPM */