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] = { { } },
38 [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = { { } },
39 [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = { { } },
40 [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = { { } },
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 int _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 BLUETOOTH_ERROR_NONE;
89 int _bt_dpm_get_allow_bluetooth_mode(int *value)
91 BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
93 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
95 return BLUETOOTH_ERROR_NONE;
98 int _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
100 int allow_bt = DPM_BT_ERROR;
101 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
103 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
104 if (allow_bt == DPM_BT_RESTRICTED)
105 return BLUETOOTH_ERROR_PERMISSION_DEINED;
107 policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value = value;
109 return BLUETOOTH_ERROR_NONE;
112 int _bt_dpm_is_bluetooth_device_restriction_active(int *value)
114 int allow_bt = DPM_BT_ERROR;
116 BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
118 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
119 if (allow_bt == DPM_BT_RESTRICTED)
120 return BLUETOOTH_ERROR_PERMISSION_DEINED;
122 *value = policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
124 return BLUETOOTH_ERROR_NONE;
127 dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
129 int allow_bt = DPM_BT_ERROR;
131 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
133 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
134 if (allow_bt == DPM_BT_RESTRICTED)
135 return BLUETOOTH_ERROR_PERMISSION_DEINED;
137 policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value = value;
139 return BLUETOOTH_ERROR_NONE;
142 dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(int *value)
144 int allow_bt = DPM_BT_ERROR;
146 BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
148 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
149 if (allow_bt == DPM_BT_RESTRICTED)
150 return BLUETOOTH_ERROR_PERMISSION_DEINED;
152 *value = policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
154 return BLUETOOTH_ERROR_NONE;
157 dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr)
159 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
160 char *dev_addr = NULL;
161 int allow_bt = DPM_BT_ERROR;
163 BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
165 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
166 if (allow_bt == DPM_BT_RESTRICTED)
167 return BLUETOOTH_ERROR_PERMISSION_DEINED;
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 BLUETOOTH_ERROR_MEMORY_ALLOCATION;
178 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
180 return BLUETOOTH_ERROR_NONE;
183 int _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
185 int ret = BLUETOOTH_ERROR_INTERNAL;
186 int allow_bt = DPM_BT_ERROR;
187 bt_dpm_device_list_t device_list;
188 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
191 BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
193 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
194 if (allow_bt == DPM_BT_RESTRICTED)
195 return BLUETOOTH_ERROR_PERMISSION_DEINED;
198 ret = BLUETOOTH_ERROR_NONE;
199 for (; list; list = list->next, i++) {
200 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
201 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
203 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
204 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
206 ret = BLUETOOTH_ERROR_NONE;
207 device_list.count = 0;
208 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
213 int _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
215 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
216 char *dev_addr = NULL;
217 int allow_bt = DPM_BT_ERROR;
219 BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
221 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
222 if (allow_bt == DPM_BT_RESTRICTED)
223 return BLUETOOTH_ERROR_PERMISSION_DEINED;
225 BT_CHECK_PARAMETER(bd_addr, return);
227 _bt_convert_addr_type_to_string(device_address,
228 (unsigned char *)bd_addr->addr);
230 dev_addr = g_strdup(device_address);
232 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
233 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
234 return BLUETOOTH_ERROR_NONE;
237 int _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
239 dpm_result_t ret = BLUETOOTH_ERROR_INTERNAL;
240 int allow_bt = DPM_BT_ERROR;
241 bt_dpm_device_list_t device_list;
242 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
245 BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
247 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
248 if (allow_bt == DPM_BT_RESTRICTED)
249 return BLUETOOTH_ERROR_PERMISSION_DEINED;
252 ret = BLUETOOTH_ERROR_NONE;
253 for (; list; list = list->next, i++) {
254 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
255 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
258 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
259 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
261 ret = BLUETOOTH_ERROR_NONE;
262 device_list.count = 0;
263 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
268 int _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
271 int allow_bt = DPM_BT_ERROR;
273 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
275 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
276 if (allow_bt == DPM_BT_RESTRICTED)
277 return BLUETOOTH_ERROR_PERMISSION_DEINED;
279 l_uuid = g_strdup(uuid);
281 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
283 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
284 return BLUETOOTH_ERROR_NONE;
287 int _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
289 int ret = BLUETOOTH_ERROR_INTERNAL;
290 int allow_bt = DPM_BT_ERROR;
291 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
292 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
295 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
297 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
298 if (allow_bt == DPM_BT_RESTRICTED)
299 return BLUETOOTH_ERROR_PERMISSION_DEINED;
302 ret = BLUETOOTH_ERROR_NONE;
303 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
304 for (; list; list = list->next, i++) {
305 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
306 g_strlcpy(uuids_list.uuids[i], list->data,
307 BLUETOOTH_UUID_STRING_MAX);
309 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
311 ret = BLUETOOTH_ERROR_NONE;
312 uuids_list.count = 0;
313 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
319 int _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
322 int allow_bt = DPM_BT_ERROR;
324 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
326 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
327 if (allow_bt == DPM_BT_RESTRICTED)
328 return BLUETOOTH_ERROR_PERMISSION_DEINED;
330 l_uuid = g_strdup(uuid);
332 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
334 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
335 return BLUETOOTH_ERROR_NONE;
339 int _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
341 int ret = BLUETOOTH_ERROR_INTERNAL;
342 int allow_bt = DPM_BT_ERROR;
343 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
344 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
347 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
349 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
350 if (allow_bt == DPM_BT_RESTRICTED)
351 return BLUETOOTH_ERROR_PERMISSION_DEINED;
354 ret = BLUETOOTH_ERROR_NONE;
355 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
356 for (; list; list = list->next, i++) {
357 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
358 g_strlcpy(uuids_list.uuids[i], list->data,
359 BLUETOOTH_UUID_STRING_MAX);
361 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
363 ret = BLUETOOTH_ERROR_NONE;
364 uuids_list.count = 0;
365 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
372 int _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
374 int allow_bt = DPM_BT_ERROR;
376 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
378 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
379 if (allow_bt == DPM_BT_RESTRICTED)
380 return BLUETOOTH_ERROR_PERMISSION_DEINED;
382 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
384 return BLUETOOTH_ERROR_NONE;
387 int _bt_dpm_get_allow_bluetooth_outgoing_call(int *value)
389 int allow_bt = DPM_BT_ERROR;
391 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
393 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
394 if (allow_bt == DPM_BT_RESTRICTED)
395 return BLUETOOTH_ERROR_PERMISSION_DEINED;
397 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
399 return BLUETOOTH_ERROR_NONE;
402 int _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
405 int allow_bt = DPM_BT_ERROR;
407 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
409 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
410 if (allow_bt == DPM_BT_RESTRICTED)
411 return BLUETOOTH_ERROR_PERMISSION_DEINED;
413 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
414 char *address = l->data;
416 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
420 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
421 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
423 return BLUETOOTH_ERROR_NONE;
426 int _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
429 int allow_bt = DPM_BT_ERROR;
431 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
433 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
434 if (allow_bt == DPM_BT_RESTRICTED)
435 return BLUETOOTH_ERROR_PERMISSION_DEINED;
437 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
438 char *address = l->data;
440 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
444 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
445 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
447 return BLUETOOTH_ERROR_NONE;
450 int _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
453 int allow_bt = DPM_BT_ERROR;
455 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
457 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
458 if (allow_bt == DPM_BT_RESTRICTED)
459 return BLUETOOTH_ERROR_PERMISSION_DEINED;
461 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
462 char *l_uuid = l->data;
464 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
468 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
469 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
471 return BLUETOOTH_ERROR_NONE;
474 int _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
477 int allow_bt = DPM_BT_ERROR;
479 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
481 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
482 if (allow_bt == DPM_BT_RESTRICTED)
483 return BLUETOOTH_ERROR_PERMISSION_DEINED;
485 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
486 char *l_uuid = l->data;
488 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
492 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
493 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
495 return BLUETOOTH_ERROR_NONE;
498 int _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
500 int allow_bt = DPM_BT_ERROR;
502 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
504 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
505 if (allow_bt == DPM_BT_RESTRICTED)
506 return BLUETOOTH_ERROR_PERMISSION_DEINED;
508 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
510 return BLUETOOTH_ERROR_NONE;
513 int _bt_dpm_get_bluetooth_pairing_state(int *value)
515 int allow_bt = DPM_BT_ERROR;
517 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
519 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
520 if (allow_bt == DPM_BT_RESTRICTED)
521 return BLUETOOTH_ERROR_PERMISSION_DEINED;
523 *value = policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
525 return BLUETOOTH_ERROR_NONE;
528 int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
530 int allow_bt = DPM_BT_ERROR;
532 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
534 if (profile >= DPM_PROFILE_NONE)
535 return BLUETOOTH_ERROR_INTERNAL;
537 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
538 if (allow_bt == DPM_BT_RESTRICTED)
539 return BLUETOOTH_ERROR_PERMISSION_DEINED;
541 dpm_profile_state[profile].value = value;
543 return BLUETOOTH_ERROR_NONE;
546 int _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile, int *value)
548 int allow_bt = DPM_BT_ERROR;
550 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
552 if (profile >= DPM_PROFILE_NONE)
553 return BLUETOOTH_ERROR_INTERNAL;
555 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
556 if (allow_bt == DPM_BT_RESTRICTED)
557 return BLUETOOTH_ERROR_PERMISSION_DEINED;
559 *value = dpm_profile_state[profile].value;
561 return BLUETOOTH_ERROR_NONE;
564 int _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
566 int allow_bt = DPM_BT_ERROR;
568 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
570 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
571 if (allow_bt == DPM_BT_RESTRICTED)
572 return BLUETOOTH_ERROR_PERMISSION_DEINED;
574 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
576 return BLUETOOTH_ERROR_NONE;
579 int _bt_dpm_get_bluetooth_desktop_connectivity_state(int *value)
581 int allow_bt = DPM_BT_ERROR;
583 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
585 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
586 if (allow_bt == DPM_BT_RESTRICTED)
587 return BLUETOOTH_ERROR_PERMISSION_DEINED;
589 *value = policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
591 return BLUETOOTH_ERROR_NONE;
594 int _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
596 int allow_bt = DPM_BT_ERROR;
598 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
600 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
601 if (allow_bt == DPM_BT_RESTRICTED)
602 return BLUETOOTH_ERROR_PERMISSION_DEINED;
604 if (value == DPM_RESTRICTED) {
605 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
606 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
609 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
611 return BLUETOOTH_ERROR_NONE;
614 int _bt_dpm_get_bluetooth_discoverable_state(int *value)
616 int allow_bt = DPM_BT_ERROR;
618 BT_INFO("_bt_dpm_get_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 *value = policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
626 return BLUETOOTH_ERROR_NONE;
629 int _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
631 int allow_bt = DPM_BT_ERROR;
633 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
635 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
636 if (allow_bt == DPM_BT_RESTRICTED)
637 return BLUETOOTH_ERROR_PERMISSION_DEINED;
639 if (value == DPM_RESTRICTED) {
640 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
641 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
644 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
646 return BLUETOOTH_ERROR_NONE;
649 int _bt_dpm_get_bluetooth_limited_discoverable_state(int *value)
651 int allow_bt = DPM_BT_ERROR;
653 BT_INFO("_bt_dpm_get_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 *value = policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
661 return BLUETOOTH_ERROR_NONE;
664 int _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
666 int allow_bt = DPM_BT_ERROR;
668 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
670 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
671 if (allow_bt == DPM_BT_RESTRICTED)
672 return BLUETOOTH_ERROR_PERMISSION_DEINED;
674 policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
675 return BLUETOOTH_ERROR_NONE;
678 int _bt_dpm_get_allow_bluetooth_data_transfer_state(int *value)
680 int allow_bt = DPM_BT_ERROR;
682 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
684 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
685 if (allow_bt == DPM_BT_RESTRICTED)
686 return BLUETOOTH_ERROR_PERMISSION_DEINED;
688 *value = policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
690 return BLUETOOTH_ERROR_NONE;
693 int _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
696 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
697 int allow_bt = DPM_BT_ERROR;
699 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
701 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
702 if (allow_bt == DPM_BT_RESTRICTED)
703 return BLUETOOTH_ERROR_PERMISSION_DEINED;
705 _bt_convert_addr_type_to_string(bd_addr,
706 (unsigned char *)device_address->addr);
708 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
709 char *l_device = l->data;
710 if (l_device && g_strcmp0(l_device, bd_addr)) {
711 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
715 return BLUETOOTH_ERROR_NONE;
718 int _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
721 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
722 int allow_bt = DPM_BT_ERROR;
724 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
726 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
727 if (allow_bt == DPM_BT_RESTRICTED)
728 return BLUETOOTH_ERROR_PERMISSION_DEINED;
730 _bt_convert_addr_type_to_string(bd_addr,
731 (unsigned char *)device_address->addr);
733 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
734 char *l_device = l->data;
735 if (l_device && g_strcmp0(l_device, bd_addr)) {
736 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
741 return BLUETOOTH_ERROR_NONE;
744 int _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
747 int allow_bt = DPM_BT_ERROR;
749 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
751 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
752 if (allow_bt == DPM_BT_RESTRICTED)
753 return BLUETOOTH_ERROR_PERMISSION_DEINED;
755 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
756 char *l_uuid = l->data;
757 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
758 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
762 return BLUETOOTH_ERROR_NONE;
765 int _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
768 int allow_bt = DPM_BT_ERROR;
770 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
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_BLACKLIST].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_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
783 return BLUETOOTH_ERROR_NONE;
786 int _bt_dpm_clear_bluetooth_uuids_from_list(void)
788 int allow_bt = DPM_BT_ERROR;
789 int err = BLUETOOTH_ERROR_INTERNAL;
791 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
793 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
794 if (allow_bt == DPM_BT_RESTRICTED)
795 return BLUETOOTH_ERROR_PERMISSION_DEINED;
797 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
799 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
804 int _bt_dpm_clear_bluetooth_devices_from_list(void)
806 int allow_bt = DPM_BT_ERROR;
807 int err = BLUETOOTH_ERROR_INTERNAL;
809 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
811 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
812 if (allow_bt == DPM_BT_RESTRICTED)
813 return BLUETOOTH_ERROR_PERMISSION_DEINED;
815 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
817 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
821 #endif /* #ifdef TIZEN_FEATURE_BT_DPM */