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] = { { } },
39 [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = { { } },
40 [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = { { } },
41 [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = { { } },
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);
489 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
490 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
492 return BLUETOOTH_ERROR_NONE;
495 int _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
498 int allow_bt = DPM_BT_ERROR;
500 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
502 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
503 if (allow_bt == DPM_BT_RESTRICTED)
504 return BLUETOOTH_ERROR_PERMISSION_DEINED;
506 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
507 char *l_uuid = l->data;
509 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
513 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
514 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
516 return BLUETOOTH_ERROR_NONE;
519 int _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
521 int allow_bt = DPM_BT_ERROR;
523 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
525 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
526 if (allow_bt == DPM_BT_RESTRICTED)
527 return BLUETOOTH_ERROR_PERMISSION_DEINED;
529 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
531 return BLUETOOTH_ERROR_NONE;
534 int _bt_dpm_get_bluetooth_pairing_state(int *value)
536 int allow_bt = DPM_BT_ERROR;
538 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
540 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
541 if (allow_bt == DPM_BT_RESTRICTED)
542 return BLUETOOTH_ERROR_PERMISSION_DEINED;
544 *value = policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
546 return BLUETOOTH_ERROR_NONE;
549 int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
551 int allow_bt = DPM_BT_ERROR;
553 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
555 if (profile >= DPM_PROFILE_NONE)
556 return BLUETOOTH_ERROR_INTERNAL;
558 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
559 if (allow_bt == DPM_BT_RESTRICTED)
560 return BLUETOOTH_ERROR_PERMISSION_DEINED;
562 dpm_profile_state[profile].value = value;
564 return BLUETOOTH_ERROR_NONE;
567 int _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile, int *value)
569 int allow_bt = DPM_BT_ERROR;
571 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
573 if (profile >= DPM_PROFILE_NONE)
574 return BLUETOOTH_ERROR_INTERNAL;
576 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
577 if (allow_bt == DPM_BT_RESTRICTED)
578 return BLUETOOTH_ERROR_PERMISSION_DEINED;
580 *value = dpm_profile_state[profile].value;
582 return BLUETOOTH_ERROR_NONE;
585 int _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
587 int allow_bt = DPM_BT_ERROR;
589 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
591 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
592 if (allow_bt == DPM_BT_RESTRICTED)
593 return BLUETOOTH_ERROR_PERMISSION_DEINED;
595 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
597 return BLUETOOTH_ERROR_NONE;
600 int _bt_dpm_get_bluetooth_desktop_connectivity_state(int *value)
602 int allow_bt = DPM_BT_ERROR;
604 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
606 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
607 if (allow_bt == DPM_BT_RESTRICTED)
608 return BLUETOOTH_ERROR_PERMISSION_DEINED;
610 *value = policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
612 return BLUETOOTH_ERROR_NONE;
615 int _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
617 int allow_bt = DPM_BT_ERROR;
619 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
621 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
622 if (allow_bt == DPM_BT_RESTRICTED)
623 return BLUETOOTH_ERROR_PERMISSION_DEINED;
625 if (value == DPM_RESTRICTED) {
626 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
627 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
630 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
632 return BLUETOOTH_ERROR_NONE;
635 int _bt_dpm_get_bluetooth_discoverable_state(int *value)
637 int allow_bt = DPM_BT_ERROR;
639 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
641 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
642 if (allow_bt == DPM_BT_RESTRICTED)
643 return BLUETOOTH_ERROR_PERMISSION_DEINED;
645 *value = policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
647 return BLUETOOTH_ERROR_NONE;
650 int _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
652 int allow_bt = DPM_BT_ERROR;
654 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
656 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
657 if (allow_bt == DPM_BT_RESTRICTED)
658 return BLUETOOTH_ERROR_PERMISSION_DEINED;
660 if (value == DPM_RESTRICTED) {
661 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
662 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
665 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
667 return BLUETOOTH_ERROR_NONE;
670 int _bt_dpm_get_bluetooth_limited_discoverable_state(int *value)
672 int allow_bt = DPM_BT_ERROR;
674 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
676 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
677 if (allow_bt == DPM_BT_RESTRICTED)
678 return BLUETOOTH_ERROR_PERMISSION_DEINED;
680 *value = policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
682 return BLUETOOTH_ERROR_NONE;
685 int _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
687 int allow_bt = DPM_BT_ERROR;
689 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
691 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
692 if (allow_bt == DPM_BT_RESTRICTED)
693 return BLUETOOTH_ERROR_PERMISSION_DEINED;
695 policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
696 return BLUETOOTH_ERROR_NONE;
699 int _bt_dpm_get_allow_bluetooth_data_transfer_state(int *value)
701 int allow_bt = DPM_BT_ERROR;
703 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
705 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
706 if (allow_bt == DPM_BT_RESTRICTED)
707 return BLUETOOTH_ERROR_PERMISSION_DEINED;
709 *value = policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
711 return BLUETOOTH_ERROR_NONE;
714 int _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
717 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
718 int allow_bt = DPM_BT_ERROR;
720 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
722 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
723 if (allow_bt == DPM_BT_RESTRICTED)
724 return BLUETOOTH_ERROR_PERMISSION_DEINED;
726 _bt_convert_addr_type_to_string(bd_addr,
727 (unsigned char *)device_address->addr);
729 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
730 char *l_device = l->data;
731 if (l_device && g_strcmp0(l_device, bd_addr)) {
732 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
736 return BLUETOOTH_ERROR_NONE;
739 int _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
742 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
743 int allow_bt = DPM_BT_ERROR;
745 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
747 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
748 if (allow_bt == DPM_BT_RESTRICTED)
749 return BLUETOOTH_ERROR_PERMISSION_DEINED;
751 _bt_convert_addr_type_to_string(bd_addr,
752 (unsigned char *)device_address->addr);
754 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
755 char *l_device = l->data;
756 if (l_device && g_strcmp0(l_device, bd_addr)) {
757 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
762 return BLUETOOTH_ERROR_NONE;
765 int _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
768 int allow_bt = DPM_BT_ERROR;
770 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
772 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
773 if (allow_bt == DPM_BT_RESTRICTED)
774 return BLUETOOTH_ERROR_PERMISSION_DEINED;
776 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
777 char *l_uuid = l->data;
778 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
779 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
783 return BLUETOOTH_ERROR_NONE;
786 int _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
789 int allow_bt = DPM_BT_ERROR;
791 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
793 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
794 if (allow_bt == DPM_BT_RESTRICTED)
795 return BLUETOOTH_ERROR_PERMISSION_DEINED;
797 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
798 char *l_uuid = l->data;
799 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
800 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
804 return BLUETOOTH_ERROR_NONE;
807 int _bt_dpm_clear_bluetooth_uuids_from_list(void)
809 int allow_bt = DPM_BT_ERROR;
810 int err = BLUETOOTH_ERROR_INTERNAL;
812 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
814 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
815 if (allow_bt == DPM_BT_RESTRICTED)
816 return BLUETOOTH_ERROR_PERMISSION_DEINED;
818 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
820 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
825 int _bt_dpm_clear_bluetooth_devices_from_list(void)
827 int allow_bt = DPM_BT_ERROR;
828 int err = BLUETOOTH_ERROR_INTERNAL;
830 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
832 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
833 if (allow_bt == DPM_BT_RESTRICTED)
834 return BLUETOOTH_ERROR_PERMISSION_DEINED;
836 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
838 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
842 #endif /* #ifdef TIZEN_FEATURE_BT_DPM */