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-core-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 /* Disconnect if connected blacklist device is existing */
181 // TODO: need to implement disconnect logic
183 return BLUETOOTH_ERROR_NONE;
186 int _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
188 int ret = BLUETOOTH_ERROR_INTERNAL;
189 int allow_bt = DPM_BT_ERROR;
190 bt_dpm_device_list_t device_list = { 0, };
191 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
194 BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
196 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
197 if (allow_bt == DPM_BT_RESTRICTED)
198 return BLUETOOTH_ERROR_PERMISSION_DEINED;
201 ret = BLUETOOTH_ERROR_NONE;
202 for (; list; list = list->next, i++) {
203 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
204 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
206 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
207 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
209 ret = BLUETOOTH_ERROR_NONE;
210 device_list.count = 0;
211 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
216 int _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
218 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
219 char *dev_addr = NULL;
220 int allow_bt = DPM_BT_ERROR;
222 BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
224 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
225 if (allow_bt == DPM_BT_RESTRICTED)
226 return BLUETOOTH_ERROR_PERMISSION_DEINED;
228 BT_CHECK_PARAMETER(bd_addr, return);
230 _bt_convert_addr_type_to_string(device_address,
231 (unsigned char *)bd_addr->addr);
233 dev_addr = g_strdup(device_address);
235 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
236 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
237 return BLUETOOTH_ERROR_NONE;
240 int _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
242 dpm_result_t ret = BLUETOOTH_ERROR_INTERNAL;
243 int allow_bt = DPM_BT_ERROR;
244 bt_dpm_device_list_t device_list = { 0, };
245 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
248 BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
250 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
251 if (allow_bt == DPM_BT_RESTRICTED)
252 return BLUETOOTH_ERROR_PERMISSION_DEINED;
255 ret = BLUETOOTH_ERROR_NONE;
256 for (; list; list = list->next, i++) {
257 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
258 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
261 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
262 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
264 ret = BLUETOOTH_ERROR_NONE;
265 device_list.count = 0;
266 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
271 int _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
274 int allow_bt = DPM_BT_ERROR;
275 GArray *addr_list = NULL;
278 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
280 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
281 if (allow_bt == DPM_BT_RESTRICTED)
282 return BLUETOOTH_ERROR_PERMISSION_DEINED;
284 l_uuid = g_strdup(uuid);
286 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
288 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
290 /* Disconnect if connected blacklist uuid is existing */
291 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
292 _bt_get_profile_connected_devices((char *)uuid, &addr_list);
293 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
294 char address[BT_ADDRESS_STRING_SIZE];
296 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
297 _bt_convert_addr_type_to_string(address, addr->addr);
298 BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
299 // TODO: need to implement disconnect logic
301 g_array_free(addr_list, TRUE);
303 return BLUETOOTH_ERROR_NONE;
306 int _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
308 int ret = BLUETOOTH_ERROR_INTERNAL;
309 int allow_bt = DPM_BT_ERROR;
310 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
311 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
314 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
316 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
317 if (allow_bt == DPM_BT_RESTRICTED)
318 return BLUETOOTH_ERROR_PERMISSION_DEINED;
321 ret = BLUETOOTH_ERROR_NONE;
322 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
323 for (; list; list = list->next, i++) {
324 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
325 g_strlcpy(uuids_list.uuids[i], list->data,
326 BLUETOOTH_UUID_STRING_MAX);
328 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
330 ret = BLUETOOTH_ERROR_NONE;
331 uuids_list.count = 0;
332 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
338 int _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
341 int allow_bt = DPM_BT_ERROR;
343 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
345 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
346 if (allow_bt == DPM_BT_RESTRICTED)
347 return BLUETOOTH_ERROR_PERMISSION_DEINED;
349 l_uuid = g_strdup(uuid);
351 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
353 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
354 return BLUETOOTH_ERROR_NONE;
358 int _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
360 int ret = BLUETOOTH_ERROR_INTERNAL;
361 int allow_bt = DPM_BT_ERROR;
362 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
363 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
366 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
368 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
369 if (allow_bt == DPM_BT_RESTRICTED)
370 return BLUETOOTH_ERROR_PERMISSION_DEINED;
373 ret = BLUETOOTH_ERROR_NONE;
374 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
375 for (; list; list = list->next, i++) {
376 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
377 g_strlcpy(uuids_list.uuids[i], list->data,
378 BLUETOOTH_UUID_STRING_MAX);
380 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
382 ret = BLUETOOTH_ERROR_NONE;
383 uuids_list.count = 0;
384 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
391 int _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
393 int allow_bt = DPM_BT_ERROR;
395 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
397 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
398 if (allow_bt == DPM_BT_RESTRICTED)
399 return BLUETOOTH_ERROR_PERMISSION_DEINED;
401 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
403 return BLUETOOTH_ERROR_NONE;
406 int _bt_dpm_get_allow_bluetooth_outgoing_call(int *value)
408 int allow_bt = DPM_BT_ERROR;
410 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
412 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
413 if (allow_bt == DPM_BT_RESTRICTED)
414 return BLUETOOTH_ERROR_PERMISSION_DEINED;
416 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
418 return BLUETOOTH_ERROR_NONE;
421 int _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
424 int allow_bt = DPM_BT_ERROR;
426 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
428 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
429 if (allow_bt == DPM_BT_RESTRICTED)
430 return BLUETOOTH_ERROR_PERMISSION_DEINED;
432 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
433 char *address = l->data;
435 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
439 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
440 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
442 return BLUETOOTH_ERROR_NONE;
445 int _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
448 int allow_bt = DPM_BT_ERROR;
450 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
452 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
453 if (allow_bt == DPM_BT_RESTRICTED)
454 return BLUETOOTH_ERROR_PERMISSION_DEINED;
456 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
457 char *address = l->data;
459 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
463 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
464 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
466 return BLUETOOTH_ERROR_NONE;
469 int _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
472 int allow_bt = DPM_BT_ERROR;
474 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
476 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
477 if (allow_bt == DPM_BT_RESTRICTED)
478 return BLUETOOTH_ERROR_PERMISSION_DEINED;
480 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
481 char *l_uuid = l->data;
483 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
487 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
488 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
490 return BLUETOOTH_ERROR_NONE;
493 int _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
496 int allow_bt = DPM_BT_ERROR;
498 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
500 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
501 if (allow_bt == DPM_BT_RESTRICTED)
502 return BLUETOOTH_ERROR_PERMISSION_DEINED;
504 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
505 char *l_uuid = l->data;
507 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
511 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
512 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
514 return BLUETOOTH_ERROR_NONE;
517 int _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
519 int allow_bt = DPM_BT_ERROR;
521 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
523 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
524 if (allow_bt == DPM_BT_RESTRICTED)
525 return BLUETOOTH_ERROR_PERMISSION_DEINED;
527 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
529 return BLUETOOTH_ERROR_NONE;
532 int _bt_dpm_get_bluetooth_pairing_state(int *value)
534 int allow_bt = DPM_BT_ERROR;
536 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
538 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
539 if (allow_bt == DPM_BT_RESTRICTED)
540 return BLUETOOTH_ERROR_PERMISSION_DEINED;
542 *value = policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
544 return BLUETOOTH_ERROR_NONE;
547 int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
549 int allow_bt = DPM_BT_ERROR;
551 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
553 if (profile >= DPM_PROFILE_NONE)
554 return BLUETOOTH_ERROR_INTERNAL;
556 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
557 if (allow_bt == DPM_BT_RESTRICTED)
558 return BLUETOOTH_ERROR_PERMISSION_DEINED;
560 dpm_profile_state[profile].value = value;
562 /* In case of restriction, disconnect if connected profile is existing */
563 if (value == DPM_RESTRICTED) {
565 GArray *addr_list = NULL;
569 case DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE:
572 case DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE:
573 uuid = BT_AVRCP_TARGET_UUID;
575 case DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE:
576 uuid = "00001118-0000-1000-8000-00805f9b34fb"; // TODO: need to add definition and below also.
578 case DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE:
579 uuid = "00001103-0000-1000-8000-00805f9b34fb";
581 case DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE:
584 case DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE:
585 uuid = "0000111e-0000-1000-8000-00805f9b34fb";
587 case DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE:
588 uuid = "00001108-0000-1000-8000-00805f9b34fb";
590 case DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE:
591 uuid = BT_OBEX_PSE_UUID;
593 case DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE:
594 uuid = "0000112d-0000-1000-8000-00805f9b34fb";
596 case DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE:
600 BT_ERR("Unknown profile %d", profile);
601 return BLUETOOTH_ERROR_INTERNAL;
604 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
605 _bt_get_profile_connected_devices(uuid, &addr_list);
606 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
607 char address[BT_ADDRESS_STRING_SIZE];
609 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
610 _bt_convert_addr_type_to_string(address, addr->addr);
611 BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
612 // TODO: need to implement disconnect logic
614 g_array_free(addr_list, TRUE);
617 return BLUETOOTH_ERROR_NONE;
620 int _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile, int *value)
622 int allow_bt = DPM_BT_ERROR;
624 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
626 if (profile >= DPM_PROFILE_NONE)
627 return BLUETOOTH_ERROR_INTERNAL;
629 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
630 if (allow_bt == DPM_BT_RESTRICTED)
631 return BLUETOOTH_ERROR_PERMISSION_DEINED;
633 *value = dpm_profile_state[profile].value;
635 return BLUETOOTH_ERROR_NONE;
638 int _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
640 int allow_bt = DPM_BT_ERROR;
642 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
644 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
645 if (allow_bt == DPM_BT_RESTRICTED)
646 return BLUETOOTH_ERROR_PERMISSION_DEINED;
648 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
650 return BLUETOOTH_ERROR_NONE;
653 int _bt_dpm_get_bluetooth_desktop_connectivity_state(int *value)
655 int allow_bt = DPM_BT_ERROR;
657 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
659 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
660 if (allow_bt == DPM_BT_RESTRICTED)
661 return BLUETOOTH_ERROR_PERMISSION_DEINED;
663 *value = policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
665 return BLUETOOTH_ERROR_NONE;
668 int _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
670 int allow_bt = DPM_BT_ERROR;
672 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
674 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
675 if (allow_bt == DPM_BT_RESTRICTED)
676 return BLUETOOTH_ERROR_PERMISSION_DEINED;
678 if (value == DPM_RESTRICTED) {
679 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
680 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
683 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
685 return BLUETOOTH_ERROR_NONE;
688 int _bt_dpm_get_bluetooth_discoverable_state(int *value)
690 int allow_bt = DPM_BT_ERROR;
692 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
694 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
695 if (allow_bt == DPM_BT_RESTRICTED)
696 return BLUETOOTH_ERROR_PERMISSION_DEINED;
698 *value = policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
700 return BLUETOOTH_ERROR_NONE;
703 int _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
705 int allow_bt = DPM_BT_ERROR;
707 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
709 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
710 if (allow_bt == DPM_BT_RESTRICTED)
711 return BLUETOOTH_ERROR_PERMISSION_DEINED;
713 if (value == DPM_RESTRICTED) {
714 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
715 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
718 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
720 return BLUETOOTH_ERROR_NONE;
723 int _bt_dpm_get_bluetooth_limited_discoverable_state(int *value)
725 int allow_bt = DPM_BT_ERROR;
727 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
729 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
730 if (allow_bt == DPM_BT_RESTRICTED)
731 return BLUETOOTH_ERROR_PERMISSION_DEINED;
733 *value = policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
735 return BLUETOOTH_ERROR_NONE;
738 int _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
740 int allow_bt = DPM_BT_ERROR;
742 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
744 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
745 if (allow_bt == DPM_BT_RESTRICTED)
746 return BLUETOOTH_ERROR_PERMISSION_DEINED;
748 policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
749 return BLUETOOTH_ERROR_NONE;
752 int _bt_dpm_get_allow_bluetooth_data_transfer_state(int *value)
754 int allow_bt = DPM_BT_ERROR;
756 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
758 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
759 if (allow_bt == DPM_BT_RESTRICTED)
760 return BLUETOOTH_ERROR_PERMISSION_DEINED;
762 *value = policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
764 return BLUETOOTH_ERROR_NONE;
767 int _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
770 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
771 int allow_bt = DPM_BT_ERROR;
773 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
775 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
776 if (allow_bt == DPM_BT_RESTRICTED)
777 return BLUETOOTH_ERROR_PERMISSION_DEINED;
779 _bt_convert_addr_type_to_string(bd_addr,
780 (unsigned char *)device_address->addr);
782 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
783 char *l_device = l->data;
784 if (l_device && g_strcmp0(l_device, bd_addr)) {
785 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
789 return BLUETOOTH_ERROR_NONE;
792 int _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
795 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
796 int allow_bt = DPM_BT_ERROR;
798 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
800 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
801 if (allow_bt == DPM_BT_RESTRICTED)
802 return BLUETOOTH_ERROR_PERMISSION_DEINED;
804 _bt_convert_addr_type_to_string(bd_addr,
805 (unsigned char *)device_address->addr);
807 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
808 char *l_device = l->data;
809 if (l_device && g_strcmp0(l_device, bd_addr)) {
810 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
815 return BLUETOOTH_ERROR_NONE;
818 int _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
821 int allow_bt = DPM_BT_ERROR;
823 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
825 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
826 if (allow_bt == DPM_BT_RESTRICTED)
827 return BLUETOOTH_ERROR_PERMISSION_DEINED;
829 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
830 char *l_uuid = l->data;
831 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
832 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
836 return BLUETOOTH_ERROR_NONE;
839 int _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
842 int allow_bt = DPM_BT_ERROR;
844 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
846 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
847 if (allow_bt == DPM_BT_RESTRICTED)
848 return BLUETOOTH_ERROR_PERMISSION_DEINED;
850 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
851 char *l_uuid = l->data;
852 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
853 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
857 return BLUETOOTH_ERROR_NONE;
860 int _bt_dpm_clear_bluetooth_uuids_from_list(void)
862 int allow_bt = DPM_BT_ERROR;
863 int err = BLUETOOTH_ERROR_INTERNAL;
865 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
867 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
868 if (allow_bt == DPM_BT_RESTRICTED)
869 return BLUETOOTH_ERROR_PERMISSION_DEINED;
871 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
873 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
878 int _bt_dpm_clear_bluetooth_devices_from_list(void)
880 int allow_bt = DPM_BT_ERROR;
881 int err = BLUETOOTH_ERROR_INTERNAL;
883 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
885 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
886 if (allow_bt == DPM_BT_RESTRICTED)
887 return BLUETOOTH_ERROR_PERMISSION_DEINED;
889 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
891 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
895 #endif /* #ifdef TIZEN_FEATURE_BT_DPM */