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_DPM_ENABLE
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 dpm_result_t _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 DPM_RESULT_SUCCESS;
110 dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void)
112 BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
114 return policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
117 dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
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;
123 policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value = value;
125 return DPM_RESULT_SUCCESS;
128 dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void)
130 BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
132 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
133 return DPM_RESTRICTED;
135 return policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
138 dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
140 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
141 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
142 return DPM_RESULT_ACCESS_DENIED;
144 policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value = value;
146 return DPM_RESULT_SUCCESS;
149 dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void)
151 BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
153 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
154 return DPM_RESTRICTED;
156 return policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
159 dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr)
161 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
162 char *dev_addr = NULL;
164 BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
166 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
167 return DPM_RESULT_ACCESS_DENIED;
169 BT_CHECK_PARAMETER(bd_addr, return);
171 _bt_convert_addr_type_to_string(device_address,
172 (unsigned char *)bd_addr->addr);
174 dev_addr = g_strdup(device_address);
176 return DPM_RESULT_FAIL;
177 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
179 return DPM_RESULT_SUCCESS;
182 dpm_result_t _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
184 dpm_result_t ret = DPM_RESULT_FAIL;
185 bt_dpm_device_list_t device_list;
186 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
189 BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
191 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
195 ret = DPM_RESULT_SUCCESS;
196 for (; list; list = list->next, i++) {
197 memset(device_list.addresses[i].addr, 0, BT_ADDRESS_STRING_SIZE);
198 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
200 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
201 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
203 ret = DPM_RESULT_SUCCESS;
204 device_list.count = 0;
205 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
210 dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
212 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
213 char *dev_addr = NULL;
215 BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
217 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
218 return DPM_RESULT_ACCESS_DENIED;
220 BT_CHECK_PARAMETER(bd_addr, return);
222 _bt_convert_addr_type_to_string(device_address,
223 (unsigned char *)bd_addr->addr);
225 dev_addr = g_strdup(device_address);
227 return DPM_RESULT_FAIL;
228 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
229 return DPM_RESULT_SUCCESS;
232 dpm_result_t _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
234 dpm_result_t ret = DPM_RESULT_FAIL;
235 bt_dpm_device_list_t device_list;
236 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
239 BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
241 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
245 ret = DPM_RESULT_SUCCESS;
246 for (; list; list = list->next, i++) {
247 memset(device_list.addresses[i].addr, 0, BT_ADDRESS_STRING_SIZE);
248 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
251 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
252 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
254 ret = DPM_RESULT_SUCCESS;
255 device_list.count = 0;
256 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
261 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
264 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
266 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
267 return DPM_RESULT_ACCESS_DENIED;
269 l_uuid = g_strdup(uuid);
271 return DPM_RESULT_FAIL;
272 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
273 return DPM_RESULT_SUCCESS;
276 dpm_result_t _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
278 dpm_result_t ret = DPM_RESULT_FAIL;
279 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
280 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
283 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
285 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
289 ret = DPM_RESULT_SUCCESS;
290 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
291 for (; list; list = list->next, i++) {
292 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
293 g_strlcpy(uuids_list.uuids[i], list->data,
294 BLUETOOTH_UUID_STRING_MAX);
296 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
298 ret = DPM_RESULT_SUCCESS;
299 uuids_list.count = 0;
300 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
306 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
309 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
311 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
312 return DPM_RESULT_ACCESS_DENIED;
314 l_uuid = g_strdup(uuid);
316 return DPM_RESULT_FAIL;
317 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
318 return DPM_RESULT_SUCCESS;
322 dpm_result_t _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
324 dpm_result_t ret = DPM_RESULT_FAIL;
325 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
326 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
329 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
331 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
335 ret = DPM_RESULT_SUCCESS;
336 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
337 for (; list; list = list->next, i++) {
338 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
339 g_strlcpy(uuids_list.uuids[i], list->data,
340 BLUETOOTH_UUID_STRING_MAX);
342 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
344 ret = DPM_RESULT_SUCCESS;
345 uuids_list.count = 0;
346 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
353 dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
355 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
356 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
357 return DPM_RESULT_ACCESS_DENIED;
359 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
361 return DPM_RESULT_SUCCESS;
364 dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void)
366 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
368 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
369 return DPM_RESTRICTED;
371 return policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
374 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
377 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
379 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
380 return DPM_RESULT_ACCESS_DENIED;
382 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
383 char *address = l->data;
385 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
389 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
390 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
391 return DPM_RESULT_SUCCESS;
394 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
397 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
399 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
400 return DPM_RESULT_ACCESS_DENIED;
402 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
403 char *address = l->data;
405 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
409 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
410 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
411 return DPM_RESULT_SUCCESS;
414 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
417 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
419 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
420 return DPM_RESULT_ACCESS_DENIED;
422 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
423 char *l_uuid = l->data;
425 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
428 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
429 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
430 return DPM_RESULT_SUCCESS;
433 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
436 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
438 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
439 return DPM_RESULT_ACCESS_DENIED;
441 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
442 char *l_uuid = l->data;
444 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
448 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
449 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
450 return DPM_RESULT_SUCCESS;
453 dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
455 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
457 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
458 return DPM_RESTRICTED;
460 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
462 return DPM_RESULT_SUCCESS;
465 dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void)
467 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
469 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
470 return DPM_RESTRICTED;
472 return policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
475 dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
477 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
479 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
480 return DPM_RESTRICTED;
482 dpm_profile_state[profile].value = value;
484 return DPM_RESULT_SUCCESS;
487 dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile)
489 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
491 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
492 return DPM_RESTRICTED;
494 return dpm_profile_state[profile].value;
497 dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
499 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
501 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
502 return DPM_RESTRICTED;
504 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
506 return DPM_RESULT_SUCCESS;
509 dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void)
511 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
513 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
514 return DPM_RESTRICTED;
516 return policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
519 dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
521 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
523 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
524 return DPM_RESTRICTED;
526 if (value == DPM_RESTRICTED) {
527 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
528 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
531 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
533 return DPM_RESULT_SUCCESS;
536 dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void)
538 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
540 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
541 return DPM_RESTRICTED;
543 return policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
546 dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
548 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
550 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
551 return DPM_RESTRICTED;
553 if (value == DPM_RESTRICTED) {
554 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
555 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
558 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
560 return DPM_RESULT_SUCCESS;
563 dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void)
565 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
567 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
568 return DPM_RESTRICTED;
570 return policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
573 dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
575 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
577 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
578 return DPM_RESTRICTED;
580 return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
583 dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(void)
585 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
587 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
588 return DPM_RESTRICTED;
590 return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
593 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
596 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
597 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
599 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
600 return DPM_RESULT_ACCESS_DENIED;
602 _bt_convert_addr_type_to_string(bd_addr,
603 (unsigned char *)device_address->addr);
605 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
606 return DPM_RESULT_ACCESS_DENIED;
608 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
609 char *l_device = l->data;
610 if (l_device && g_strcmp0(l_device, bd_addr)) {
611 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
615 return DPM_RESULT_SUCCESS;
618 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
621 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
623 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
625 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
626 return DPM_RESULT_ACCESS_DENIED;
628 _bt_convert_addr_type_to_string(bd_addr,
629 (unsigned char *)device_address->addr);
631 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
632 char *l_device = l->data;
633 if (l_device && g_strcmp0(l_device, bd_addr)) {
634 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
639 return DPM_RESULT_SUCCESS;
642 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
645 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
647 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
648 return DPM_RESULT_ACCESS_DENIED;
649 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
650 char *l_uuid = l->data;
651 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
652 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
656 return DPM_RESULT_SUCCESS;
659 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
662 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
664 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
665 return DPM_RESULT_ACCESS_DENIED;
667 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
668 char *l_uuid = l->data;
669 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
670 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
674 return DPM_RESULT_SUCCESS;
677 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void)
679 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
680 dpm_result_t err = DPM_RESULT_FAIL;
682 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
683 return DPM_RESULT_ACCESS_DENIED;
685 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
687 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
692 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void)
694 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
695 dpm_result_t err = DPM_RESULT_FAIL;
697 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
698 return DPM_RESULT_ACCESS_DENIED;
700 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
702 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
706 #endif /* #ifdef TIZEN_DPM_ENABLE */