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.
21 #include <bundle_internal.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-core-adapter.h"
29 #include "bt-service-dpm.h"
31 static dpm_policy_t policy_table[DPM_POLICY_END] = {
32 [DPM_POLICY_ALLOW_BLUETOOTH] = { {DPM_BT_ERROR} },
33 [DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION] = { {DPM_STATUS_ERROR} },
34 [DPM_POLICY_BLUETOOTH_UUID_RESTRICTION] = { {DPM_STATUS_ERROR} },
35 [DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST] = { { } },
36 [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = { { } },
37 [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = { { } },
38 [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = { { } },
39 [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = { {DPM_STATUS_ERROR} },
40 [DPM_POLICY_BLUETOOTH_PAIRING_STATE] = { {DPM_STATUS_ERROR} },
41 [DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE] = { {DPM_STATUS_ERROR} },
42 [DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
43 [DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
44 [DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE] = { {DPM_STATUS_ERROR} },
49 * @brief DPM profile state
52 static dpm_profile_state_t dpm_profile_state[DPM_PROFILE_NONE] = {
53 [DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE] = {DPM_STATUS_ERROR},
54 [DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE] = {DPM_STATUS_ERROR},
55 [DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
56 [DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE] = {DPM_STATUS_ERROR},
57 [DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE] = {DPM_STATUS_ERROR},
58 [DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE] = {DPM_STATUS_ERROR},
59 [DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE] = {DPM_STATUS_ERROR},
60 [DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
61 [DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
62 [DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
65 int _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
67 BT_INFO("_bt_dpm_set_allow_bluetooth_mode");
69 policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value = value;
71 return BLUETOOTH_ERROR_NONE;
74 int _bt_dpm_get_allow_bluetooth_mode(int *value)
76 BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
78 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
80 return BLUETOOTH_ERROR_NONE;
83 int _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
85 int allow_bt = DPM_BT_ERROR;
86 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
88 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
89 if (allow_bt == DPM_BT_RESTRICTED)
90 return BLUETOOTH_ERROR_PERMISSION_DEINED;
92 policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value = value;
94 return BLUETOOTH_ERROR_NONE;
97 int _bt_dpm_is_bluetooth_device_restriction_active(int *value)
99 int allow_bt = DPM_BT_ERROR;
101 BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
103 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
104 if (allow_bt == DPM_BT_RESTRICTED)
105 return BLUETOOTH_ERROR_PERMISSION_DEINED;
107 *value = policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
109 return BLUETOOTH_ERROR_NONE;
112 dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
114 int allow_bt = DPM_BT_ERROR;
116 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
118 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
119 if (allow_bt == DPM_BT_RESTRICTED)
120 return BLUETOOTH_ERROR_PERMISSION_DEINED;
122 policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value = value;
124 return BLUETOOTH_ERROR_NONE;
127 dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(int *value)
129 int allow_bt = DPM_BT_ERROR;
131 BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
133 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
134 if (allow_bt == DPM_BT_RESTRICTED)
135 return BLUETOOTH_ERROR_PERMISSION_DEINED;
137 *value = policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
139 return BLUETOOTH_ERROR_NONE;
142 dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr)
144 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
145 char *dev_addr = NULL;
146 int allow_bt = DPM_BT_ERROR;
148 BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
150 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
151 if (allow_bt == DPM_BT_RESTRICTED)
152 return BLUETOOTH_ERROR_PERMISSION_DEINED;
154 BT_CHECK_PARAMETER(bd_addr, return);
156 _bt_convert_addr_type_to_string(device_address,
157 (unsigned char *)bd_addr->addr);
159 dev_addr = g_strdup(device_address);
161 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
163 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
165 /* Disconnect if connected blacklist device is existing */
166 // TODO: need to implement disconnect logic
168 return BLUETOOTH_ERROR_NONE;
171 int _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
173 int ret = BLUETOOTH_ERROR_INTERNAL;
174 int allow_bt = DPM_BT_ERROR;
175 bt_dpm_device_list_t device_list = { 0, };
176 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
179 BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
181 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
182 if (allow_bt == DPM_BT_RESTRICTED)
183 return BLUETOOTH_ERROR_PERMISSION_DEINED;
186 ret = BLUETOOTH_ERROR_NONE;
187 for (; list; list = list->next, i++) {
188 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
189 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
191 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
192 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
194 ret = BLUETOOTH_ERROR_NONE;
195 device_list.count = 0;
196 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
201 int _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
203 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
204 char *dev_addr = NULL;
205 int allow_bt = DPM_BT_ERROR;
207 BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
209 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
210 if (allow_bt == DPM_BT_RESTRICTED)
211 return BLUETOOTH_ERROR_PERMISSION_DEINED;
213 BT_CHECK_PARAMETER(bd_addr, return);
215 _bt_convert_addr_type_to_string(device_address,
216 (unsigned char *)bd_addr->addr);
218 dev_addr = g_strdup(device_address);
220 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
221 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
222 return BLUETOOTH_ERROR_NONE;
225 int _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
227 dpm_result_t ret = BLUETOOTH_ERROR_INTERNAL;
228 int allow_bt = DPM_BT_ERROR;
229 bt_dpm_device_list_t device_list = { 0, };
230 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
233 BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
235 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
236 if (allow_bt == DPM_BT_RESTRICTED)
237 return BLUETOOTH_ERROR_PERMISSION_DEINED;
240 ret = BLUETOOTH_ERROR_NONE;
241 for (; list; list = list->next, i++) {
242 memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
243 _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
246 device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
247 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
249 ret = BLUETOOTH_ERROR_NONE;
250 device_list.count = 0;
251 g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
256 int _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
259 int allow_bt = DPM_BT_ERROR;
260 //GArray *addr_list = NULL;
263 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
265 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
266 if (allow_bt == DPM_BT_RESTRICTED)
267 return BLUETOOTH_ERROR_PERMISSION_DEINED;
269 l_uuid = g_strdup(uuid);
271 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
273 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
275 /* Use device functions if this logic required in later */
276 /* Disconnect if connected blacklist uuid is existing */
278 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
279 _bt_get_profile_connected_devices((char *)uuid, &addr_list);
280 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
281 char address[BT_ADDRESS_STRING_SIZE];
283 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
284 _bt_convert_addr_type_to_string(address, addr->addr);
285 BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
286 // TODO: need to implement disconnect logic
288 g_array_free(addr_list, TRUE);
291 return BLUETOOTH_ERROR_NONE;
294 int _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
296 int ret = BLUETOOTH_ERROR_INTERNAL;
297 int allow_bt = DPM_BT_ERROR;
298 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
299 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
302 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
304 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
305 if (allow_bt == DPM_BT_RESTRICTED)
306 return BLUETOOTH_ERROR_PERMISSION_DEINED;
309 ret = BLUETOOTH_ERROR_NONE;
310 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
311 for (; list; list = list->next, i++) {
312 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
313 g_strlcpy(uuids_list.uuids[i], list->data,
314 BLUETOOTH_UUID_STRING_MAX);
316 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
318 ret = BLUETOOTH_ERROR_NONE;
319 uuids_list.count = 0;
320 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
326 int _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
329 int allow_bt = DPM_BT_ERROR;
331 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
333 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
334 if (allow_bt == DPM_BT_RESTRICTED)
335 return BLUETOOTH_ERROR_PERMISSION_DEINED;
337 l_uuid = g_strdup(uuid);
339 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
341 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
342 return BLUETOOTH_ERROR_NONE;
346 int _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
348 int ret = BLUETOOTH_ERROR_INTERNAL;
349 int allow_bt = DPM_BT_ERROR;
350 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
351 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
354 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
356 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
357 if (allow_bt == DPM_BT_RESTRICTED)
358 return BLUETOOTH_ERROR_PERMISSION_DEINED;
361 ret = BLUETOOTH_ERROR_NONE;
362 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
363 for (; list; list = list->next, i++) {
364 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
365 g_strlcpy(uuids_list.uuids[i], list->data,
366 BLUETOOTH_UUID_STRING_MAX);
368 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
370 ret = BLUETOOTH_ERROR_NONE;
371 uuids_list.count = 0;
372 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
379 int _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
381 int allow_bt = DPM_BT_ERROR;
383 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
385 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
386 if (allow_bt == DPM_BT_RESTRICTED)
387 return BLUETOOTH_ERROR_PERMISSION_DEINED;
389 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
391 return BLUETOOTH_ERROR_NONE;
394 int _bt_dpm_get_allow_bluetooth_outgoing_call(int *value)
396 int allow_bt = DPM_BT_ERROR;
398 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
400 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
401 if (allow_bt == DPM_BT_RESTRICTED)
402 return BLUETOOTH_ERROR_PERMISSION_DEINED;
404 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
406 return BLUETOOTH_ERROR_NONE;
409 int _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
412 int allow_bt = DPM_BT_ERROR;
414 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
416 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
417 if (allow_bt == DPM_BT_RESTRICTED)
418 return BLUETOOTH_ERROR_PERMISSION_DEINED;
420 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
421 char *address = l->data;
423 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
427 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
428 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
430 return BLUETOOTH_ERROR_NONE;
433 int _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
436 int allow_bt = DPM_BT_ERROR;
438 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
440 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
441 if (allow_bt == DPM_BT_RESTRICTED)
442 return BLUETOOTH_ERROR_PERMISSION_DEINED;
444 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
445 char *address = l->data;
447 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
451 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
452 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
454 return BLUETOOTH_ERROR_NONE;
457 int _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
460 int allow_bt = DPM_BT_ERROR;
462 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
464 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
465 if (allow_bt == DPM_BT_RESTRICTED)
466 return BLUETOOTH_ERROR_PERMISSION_DEINED;
468 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
469 char *l_uuid = l->data;
471 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
475 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
476 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
478 return BLUETOOTH_ERROR_NONE;
481 int _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
484 int allow_bt = DPM_BT_ERROR;
486 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
488 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
489 if (allow_bt == DPM_BT_RESTRICTED)
490 return BLUETOOTH_ERROR_PERMISSION_DEINED;
492 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
493 char *l_uuid = l->data;
495 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
499 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
500 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
502 return BLUETOOTH_ERROR_NONE;
505 int _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
507 int allow_bt = DPM_BT_ERROR;
509 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
511 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
512 if (allow_bt == DPM_BT_RESTRICTED)
513 return BLUETOOTH_ERROR_PERMISSION_DEINED;
515 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
517 return BLUETOOTH_ERROR_NONE;
520 int _bt_dpm_get_bluetooth_pairing_state(int *value)
522 int allow_bt = DPM_BT_ERROR;
524 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
526 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
527 if (allow_bt == DPM_BT_RESTRICTED)
528 return BLUETOOTH_ERROR_PERMISSION_DEINED;
530 *value = policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
532 return BLUETOOTH_ERROR_NONE;
535 int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
537 int allow_bt = DPM_BT_ERROR;
539 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
541 if (profile >= DPM_PROFILE_NONE)
542 return BLUETOOTH_ERROR_INTERNAL;
544 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
545 if (allow_bt == DPM_BT_RESTRICTED)
546 return BLUETOOTH_ERROR_PERMISSION_DEINED;
548 dpm_profile_state[profile].value = value;
551 /* Use other functions if this logic required in later */
552 /* In case of restriction, disconnect if connected profile is existing */
554 if (value == DPM_RESTRICTED) {
556 GArray *addr_list = NULL;
560 case DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE:
563 case DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE:
564 uuid = BT_AVRCP_TARGET_UUID;
566 case DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE:
567 uuid = "00001118-0000-1000-8000-00805f9b34fb"; // TODO: need to add definition and below also.
569 case DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE:
570 uuid = "00001103-0000-1000-8000-00805f9b34fb";
572 case DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE:
575 case DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE:
576 uuid = "0000111e-0000-1000-8000-00805f9b34fb";
578 case DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE:
579 uuid = "00001108-0000-1000-8000-00805f9b34fb";
581 case DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE:
582 uuid = BT_OBEX_PSE_UUID;
584 case DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE:
585 uuid = "0000112d-0000-1000-8000-00805f9b34fb";
587 case DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE:
591 BT_ERR("Unknown profile %d", profile);
592 return BLUETOOTH_ERROR_INTERNAL;
595 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
596 _bt_get_profile_connected_devices(uuid, &addr_list);
597 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
598 char address[BT_ADDRESS_STRING_SIZE];
600 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
601 _bt_convert_addr_type_to_string(address, addr->addr);
602 BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
603 // TODO: need to implement disconnect logic
605 g_array_free(addr_list, TRUE);
609 return BLUETOOTH_ERROR_NONE;
612 int _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile, int *value)
614 int allow_bt = DPM_BT_ERROR;
616 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
618 if (profile >= DPM_PROFILE_NONE)
619 return BLUETOOTH_ERROR_INTERNAL;
621 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
622 if (allow_bt == DPM_BT_RESTRICTED)
623 return BLUETOOTH_ERROR_PERMISSION_DEINED;
625 *value = dpm_profile_state[profile].value;
627 return BLUETOOTH_ERROR_NONE;
630 int _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
632 int allow_bt = DPM_BT_ERROR;
634 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
636 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
637 if (allow_bt == DPM_BT_RESTRICTED)
638 return BLUETOOTH_ERROR_PERMISSION_DEINED;
640 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
642 return BLUETOOTH_ERROR_NONE;
645 int _bt_dpm_get_bluetooth_desktop_connectivity_state(int *value)
647 int allow_bt = DPM_BT_ERROR;
649 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
651 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
652 if (allow_bt == DPM_BT_RESTRICTED)
653 return BLUETOOTH_ERROR_PERMISSION_DEINED;
655 *value = policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
657 return BLUETOOTH_ERROR_NONE;
660 int _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
662 int allow_bt = DPM_BT_ERROR;
664 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
666 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
667 if (allow_bt == DPM_BT_RESTRICTED)
668 return BLUETOOTH_ERROR_PERMISSION_DEINED;
670 if (value == DPM_RESTRICTED) {
671 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
672 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
675 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
677 return BLUETOOTH_ERROR_NONE;
680 int _bt_dpm_get_bluetooth_discoverable_state(int *value)
682 int allow_bt = DPM_BT_ERROR;
684 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
686 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
687 if (allow_bt == DPM_BT_RESTRICTED)
688 return BLUETOOTH_ERROR_PERMISSION_DEINED;
690 *value = policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
692 return BLUETOOTH_ERROR_NONE;
695 int _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
697 int allow_bt = DPM_BT_ERROR;
699 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
701 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
702 if (allow_bt == DPM_BT_RESTRICTED)
703 return BLUETOOTH_ERROR_PERMISSION_DEINED;
705 if (value == DPM_RESTRICTED) {
706 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
707 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
710 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
712 return BLUETOOTH_ERROR_NONE;
715 int _bt_dpm_get_bluetooth_limited_discoverable_state(int *value)
717 int allow_bt = DPM_BT_ERROR;
719 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
721 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
722 if (allow_bt == DPM_BT_RESTRICTED)
723 return BLUETOOTH_ERROR_PERMISSION_DEINED;
725 *value = policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
727 return BLUETOOTH_ERROR_NONE;
730 int _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
732 int allow_bt = DPM_BT_ERROR;
734 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
736 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
737 if (allow_bt == DPM_BT_RESTRICTED)
738 return BLUETOOTH_ERROR_PERMISSION_DEINED;
740 policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
741 return BLUETOOTH_ERROR_NONE;
744 int _bt_dpm_get_allow_bluetooth_data_transfer_state(int *value)
746 int allow_bt = DPM_BT_ERROR;
748 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
750 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
751 if (allow_bt == DPM_BT_RESTRICTED)
752 return BLUETOOTH_ERROR_PERMISSION_DEINED;
754 *value = policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
756 return BLUETOOTH_ERROR_NONE;
759 int _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
762 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
763 int allow_bt = DPM_BT_ERROR;
765 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
767 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
768 if (allow_bt == DPM_BT_RESTRICTED)
769 return BLUETOOTH_ERROR_PERMISSION_DEINED;
771 _bt_convert_addr_type_to_string(bd_addr,
772 (unsigned char *)device_address->addr);
774 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
775 char *l_device = l->data;
776 if (l_device && g_strcmp0(l_device, bd_addr)) {
777 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
781 return BLUETOOTH_ERROR_NONE;
784 int _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
787 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
788 int allow_bt = DPM_BT_ERROR;
790 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
792 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
793 if (allow_bt == DPM_BT_RESTRICTED)
794 return BLUETOOTH_ERROR_PERMISSION_DEINED;
796 _bt_convert_addr_type_to_string(bd_addr,
797 (unsigned char *)device_address->addr);
799 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
800 char *l_device = l->data;
801 if (l_device && g_strcmp0(l_device, bd_addr)) {
802 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
807 return BLUETOOTH_ERROR_NONE;
810 int _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
813 int allow_bt = DPM_BT_ERROR;
815 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
817 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
818 if (allow_bt == DPM_BT_RESTRICTED)
819 return BLUETOOTH_ERROR_PERMISSION_DEINED;
821 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
822 char *l_uuid = l->data;
823 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
824 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
828 return BLUETOOTH_ERROR_NONE;
831 int _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
834 int allow_bt = DPM_BT_ERROR;
836 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
838 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
839 if (allow_bt == DPM_BT_RESTRICTED)
840 return BLUETOOTH_ERROR_PERMISSION_DEINED;
842 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
843 char *l_uuid = l->data;
844 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
845 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
849 return BLUETOOTH_ERROR_NONE;
852 int _bt_dpm_clear_bluetooth_uuids_from_list(void)
854 int allow_bt = DPM_BT_ERROR;
855 int err = BLUETOOTH_ERROR_INTERNAL;
857 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
859 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
860 if (allow_bt == DPM_BT_RESTRICTED)
861 return BLUETOOTH_ERROR_PERMISSION_DEINED;
863 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
865 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
870 int _bt_dpm_clear_bluetooth_devices_from_list(void)
872 int allow_bt = DPM_BT_ERROR;
873 int err = BLUETOOTH_ERROR_INTERNAL;
875 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
877 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
878 if (allow_bt == DPM_BT_RESTRICTED)
879 return BLUETOOTH_ERROR_PERMISSION_DEINED;
881 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
883 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();