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 <bundle_internal.h>
26 #include "bluetooth-api.h"
27 #include "bt-internal-types.h"
29 #include "bt-service-common.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-dpm.h"
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} },
51 * @brief DPM profile state
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},
67 dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
69 BT_INFO("_bt_dpm_set_allow_bluetooth_mode");
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;
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;
84 policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value = value;
86 return DPM_RESULT_SUCCESS;
89 dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void)
91 BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
93 return policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
96 dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
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;
102 policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value = value;
104 return DPM_RESULT_SUCCESS;
107 dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void)
109 BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
111 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
112 return DPM_RESTRICTED;
114 return policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
117 dpm_result_t _bt_dpm_activate_bluetoooth_uuid_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_UUID_RESTRICTION].value = value;
125 return DPM_RESULT_SUCCESS;
128 dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void)
130 BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
132 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
133 return DPM_RESTRICTED;
135 return policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
138 dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr)
140 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
141 char *dev_addr = NULL;
143 BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
145 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
146 return DPM_RESULT_ACCESS_DENIED;
148 BT_CHECK_PARAMETER(bd_addr, return);
150 _bt_convert_addr_type_to_string(device_address,
151 (unsigned char *)bd_addr->addr);
153 dev_addr = g_strdup(device_address);
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);
158 return DPM_RESULT_SUCCESS;
161 dpm_result_t _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
163 dpm_result_t ret = DPM_RESULT_FAIL;
164 bt_dpm_device_list_t device_list = { 0, };
165 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
168 BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
170 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
174 ret = DPM_RESULT_SUCCESS;
175 for (; list; list = list->next, i++) {
176 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
177 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
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));
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));
189 dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
191 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
192 char *dev_addr = NULL;
194 BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
196 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
197 return DPM_RESULT_ACCESS_DENIED;
199 BT_CHECK_PARAMETER(bd_addr, return);
201 _bt_convert_addr_type_to_string(device_address,
202 (unsigned char *)bd_addr->addr);
204 dev_addr = g_strdup(device_address);
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;
211 dpm_result_t _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
213 dpm_result_t ret = DPM_RESULT_FAIL;
214 bt_dpm_device_list_t device_list = { 0, };
215 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
218 BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
220 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
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);
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));
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));
240 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
243 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
245 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
246 return DPM_RESULT_ACCESS_DENIED;
248 l_uuid = g_strdup(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;
255 dpm_result_t _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
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;
262 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
264 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
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);
275 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
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));
285 dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
288 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
290 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
291 return DPM_RESULT_ACCESS_DENIED;
293 l_uuid = g_strdup(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;
301 dpm_result_t _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
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;
308 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
310 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
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);
321 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
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));
332 dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
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;
338 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
340 return DPM_RESULT_SUCCESS;
343 dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void)
345 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
347 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
348 return DPM_RESTRICTED;
350 return policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
353 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
356 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
358 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
359 return DPM_RESULT_ACCESS_DENIED;
361 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
362 char *address = l->data;
364 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
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;
373 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
376 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
378 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
379 return DPM_RESULT_ACCESS_DENIED;
381 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
382 char *address = l->data;
384 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
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;
393 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
396 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
398 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
399 return DPM_RESULT_ACCESS_DENIED;
401 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
402 char *l_uuid = l->data;
404 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
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;
412 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
415 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
417 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
418 return DPM_RESULT_ACCESS_DENIED;
420 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
421 char *l_uuid = l->data;
423 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
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;
432 dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
434 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
436 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
437 return DPM_RESTRICTED;
439 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
441 return DPM_RESULT_SUCCESS;
444 dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void)
446 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
448 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
449 return DPM_RESTRICTED;
451 return policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
454 dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
456 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
458 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
459 return DPM_RESTRICTED;
461 dpm_profile_state[profile].value = value;
463 return DPM_RESULT_SUCCESS;
466 dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile)
468 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
470 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
471 return DPM_RESTRICTED;
473 return dpm_profile_state[profile].value;
476 dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
478 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
480 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
481 return DPM_RESTRICTED;
483 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
485 return DPM_RESULT_SUCCESS;
488 dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void)
490 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
492 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
493 return DPM_RESTRICTED;
495 return policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
498 dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
500 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
502 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
503 return DPM_RESTRICTED;
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);
510 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
512 return DPM_RESULT_SUCCESS;
515 dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void)
517 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
519 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
520 return DPM_RESTRICTED;
522 return policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
525 dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
527 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
529 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
530 return DPM_RESTRICTED;
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);
537 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
539 return DPM_RESULT_SUCCESS;
542 dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void)
544 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
546 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
547 return DPM_RESTRICTED;
549 return policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
552 dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
554 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
556 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
557 return DPM_RESTRICTED;
559 return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
562 dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(void)
564 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
566 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
567 return DPM_RESTRICTED;
569 return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
572 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
575 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
576 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
578 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
579 return DPM_RESULT_ACCESS_DENIED;
581 _bt_convert_addr_type_to_string(bd_addr,
582 (unsigned char *)device_address->addr);
584 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
585 return DPM_RESULT_ACCESS_DENIED;
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);
594 return DPM_RESULT_SUCCESS;
597 dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
600 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
602 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
604 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
605 return DPM_RESULT_ACCESS_DENIED;
607 _bt_convert_addr_type_to_string(bd_addr,
608 (unsigned char *)device_address->addr);
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);
618 return DPM_RESULT_SUCCESS;
621 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
624 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
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);
635 return DPM_RESULT_SUCCESS;
638 dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
641 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
643 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
644 return DPM_RESULT_ACCESS_DENIED;
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);
653 return DPM_RESULT_SUCCESS;
656 dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void)
658 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
659 dpm_result_t err = DPM_RESULT_FAIL;
661 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
662 return DPM_RESULT_ACCESS_DENIED;
664 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
666 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
671 dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void)
673 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
674 dpm_result_t err = DPM_RESULT_FAIL;
676 if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
677 return DPM_RESULT_ACCESS_DENIED;
679 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
681 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
685 #endif /* #ifdef TIZEN_FEATURE_BT_DPM */