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_ALLOWLIST] = { { } },
36 [DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST] = { { } },
37 [DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST] = { { } },
38 [DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST] = { { } },
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 int _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 int _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 int _bt_dpm_add_bluetooth_devices_to_blocklist(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_blocklist");
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_BLOCKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST].list, dev_addr);
165 /* Disconnect if connected blocklist device is existing */
166 // TODO: need to implement disconnect logic
168 return BLUETOOTH_ERROR_NONE;
171 int _bt_dpm_get_bluetooth_devices_from_blocklist(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_BLOCKLIST].list;
179 BT_INFO("_bt_dpm_get_bluetooth_devices_from_blocklist");
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_BLOCKLIST].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_allowlist(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_allowlist");
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_ALLOWLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list, dev_addr);
222 return BLUETOOTH_ERROR_NONE;
225 int _bt_dpm_get_bluetooth_devices_from_allowlist(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_ALLOWLIST].list;
233 BT_INFO("_bt_dpm_get_bluetooth_devices_from_allowlist");
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_ALLOWLIST].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_blocklist(const char *uuid)
259 int allow_bt = DPM_BT_ERROR;
260 //GArray *addr_list = NULL;
263 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blocklist");
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;
274 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list, l_uuid);
276 /* Use device functions if this logic required in later */
277 /* Disconnect if connected blocklist uuid is existing */
279 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
280 _bt_get_profile_connected_devices((char *)uuid, &addr_list);
281 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
282 char address[BT_ADDRESS_STRING_SIZE];
284 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
285 _bt_convert_addr_type_to_string(address, addr->addr);
286 BT_INFO("device[%s] is in blocklist uuid, will be disconnected", address);
287 // TODO: need to implement disconnect logic
289 g_array_free(addr_list, TRUE);
292 return BLUETOOTH_ERROR_NONE;
295 int _bt_dpm_get_bluetooth_uuids_from_blocklist(GArray **out_param1)
297 int ret = BLUETOOTH_ERROR_INTERNAL;
298 int allow_bt = DPM_BT_ERROR;
299 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
300 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list;
303 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blocklist");
305 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
306 if (allow_bt == DPM_BT_RESTRICTED)
307 return BLUETOOTH_ERROR_PERMISSION_DEINED;
310 ret = BLUETOOTH_ERROR_NONE;
311 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list);
312 for (; list; list = list->next, i++) {
313 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
314 g_strlcpy(uuids_list.uuids[i], list->data,
315 BLUETOOTH_UUID_STRING_MAX);
317 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
319 ret = BLUETOOTH_ERROR_NONE;
320 uuids_list.count = 0;
321 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
327 int _bt_dpm_add_bluetooth_uuids_to_allowlist(const char *uuid)
330 int allow_bt = DPM_BT_ERROR;
332 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_allowlist");
334 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
335 if (allow_bt == DPM_BT_RESTRICTED)
336 return BLUETOOTH_ERROR_PERMISSION_DEINED;
338 l_uuid = g_strdup(uuid);
340 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
342 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list, l_uuid);
343 return BLUETOOTH_ERROR_NONE;
347 int _bt_dpm_get_bluetooth_uuids_from_allowlist(GArray **out_param1)
349 int ret = BLUETOOTH_ERROR_INTERNAL;
350 int allow_bt = DPM_BT_ERROR;
351 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
352 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list;
355 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_allowlist");
357 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
358 if (allow_bt == DPM_BT_RESTRICTED)
359 return BLUETOOTH_ERROR_PERMISSION_DEINED;
362 ret = BLUETOOTH_ERROR_NONE;
363 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list);
364 for (; list; list = list->next, i++) {
365 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
366 g_strlcpy(uuids_list.uuids[i], list->data,
367 BLUETOOTH_UUID_STRING_MAX);
369 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
371 ret = BLUETOOTH_ERROR_NONE;
372 uuids_list.count = 0;
373 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
380 int _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
382 int allow_bt = DPM_BT_ERROR;
384 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
386 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
387 if (allow_bt == DPM_BT_RESTRICTED)
388 return BLUETOOTH_ERROR_PERMISSION_DEINED;
390 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
392 return BLUETOOTH_ERROR_NONE;
395 int _bt_dpm_get_allow_bluetooth_outgoing_call(int *value)
397 int allow_bt = DPM_BT_ERROR;
399 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
401 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
402 if (allow_bt == DPM_BT_RESTRICTED)
403 return BLUETOOTH_ERROR_PERMISSION_DEINED;
405 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
407 return BLUETOOTH_ERROR_NONE;
410 int _bt_dpm_clear_bluetooth_devices_from_blocklist(void)
413 int allow_bt = DPM_BT_ERROR;
415 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blocklist");
417 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
418 if (allow_bt == DPM_BT_RESTRICTED)
419 return BLUETOOTH_ERROR_PERMISSION_DEINED;
421 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST].list; l; l = g_slist_next(l)) {
422 char *address = l->data;
424 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST].list, address);
428 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST].list);
429 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST].list = NULL;
431 return BLUETOOTH_ERROR_NONE;
434 int _bt_dpm_clear_bluetooth_devices_from_allowlist(void)
437 int allow_bt = DPM_BT_ERROR;
439 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blocklist");
441 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
442 if (allow_bt == DPM_BT_RESTRICTED)
443 return BLUETOOTH_ERROR_PERMISSION_DEINED;
445 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list; l; l = g_slist_next(l)) {
446 char *address = l->data;
448 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list, address);
452 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list);
453 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list = NULL;
455 return BLUETOOTH_ERROR_NONE;
458 int _bt_dpm_clear_bluetooth_uuids_from_blocklist(void)
461 int allow_bt = DPM_BT_ERROR;
463 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blocklist");
465 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
466 if (allow_bt == DPM_BT_RESTRICTED)
467 return BLUETOOTH_ERROR_PERMISSION_DEINED;
469 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list; l; l = g_slist_next(l)) {
470 char *l_uuid = l->data;
472 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list, l_uuid);
476 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list);
477 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list = NULL;
479 return BLUETOOTH_ERROR_NONE;
482 int _bt_dpm_clear_bluetooth_uuids_from_allowlist(void)
485 int allow_bt = DPM_BT_ERROR;
487 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_allowlist");
489 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
490 if (allow_bt == DPM_BT_RESTRICTED)
491 return BLUETOOTH_ERROR_PERMISSION_DEINED;
493 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list; l; l = g_slist_next(l)) {
494 char *l_uuid = l->data;
496 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list, l_uuid);
500 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list);
501 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list = NULL;
503 return BLUETOOTH_ERROR_NONE;
506 int _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
508 int allow_bt = DPM_BT_ERROR;
510 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
512 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
513 if (allow_bt == DPM_BT_RESTRICTED)
514 return BLUETOOTH_ERROR_PERMISSION_DEINED;
516 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
518 return BLUETOOTH_ERROR_NONE;
521 int _bt_dpm_get_bluetooth_pairing_state(int *value)
523 int allow_bt = DPM_BT_ERROR;
525 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
527 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
528 if (allow_bt == DPM_BT_RESTRICTED)
529 return BLUETOOTH_ERROR_PERMISSION_DEINED;
531 *value = policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
533 return BLUETOOTH_ERROR_NONE;
536 int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
538 int allow_bt = DPM_BT_ERROR;
540 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
542 if (profile >= DPM_PROFILE_NONE)
543 return BLUETOOTH_ERROR_INTERNAL;
545 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
546 if (allow_bt == DPM_BT_RESTRICTED)
547 return BLUETOOTH_ERROR_PERMISSION_DEINED;
549 dpm_profile_state[profile].value = value;
552 /* Use other functions if this logic required in later */
553 /* In case of restriction, disconnect if connected profile is existing */
555 if (value == DPM_RESTRICTED) {
557 GArray *addr_list = NULL;
561 case DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE:
564 case DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE:
565 uuid = BT_AVRCP_TARGET_UUID;
567 case DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE:
568 uuid = "00001118-0000-1000-8000-00805f9b34fb"; // TODO: need to add definition and below also.
570 case DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE:
571 uuid = "00001103-0000-1000-8000-00805f9b34fb";
573 case DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE:
576 case DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE:
577 uuid = "0000111e-0000-1000-8000-00805f9b34fb";
579 case DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE:
580 uuid = "00001108-0000-1000-8000-00805f9b34fb";
582 case DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE:
583 uuid = BT_OBEX_PSE_UUID;
585 case DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE:
586 uuid = "0000112d-0000-1000-8000-00805f9b34fb";
588 case DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE:
592 BT_ERR("Unknown profile %d", profile);
593 return BLUETOOTH_ERROR_INTERNAL;
596 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
597 _bt_get_profile_connected_devices(uuid, &addr_list);
598 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
599 char address[BT_ADDRESS_STRING_SIZE];
601 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
602 _bt_convert_addr_type_to_string(address, addr->addr);
603 BT_INFO("device[%s] is in blocklist uuid, will be disconnected", address);
604 // TODO: need to implement disconnect logic
606 g_array_free(addr_list, TRUE);
610 return BLUETOOTH_ERROR_NONE;
613 int _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile, int *value)
615 int allow_bt = DPM_BT_ERROR;
617 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
619 if (profile >= DPM_PROFILE_NONE)
620 return BLUETOOTH_ERROR_INTERNAL;
622 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
623 if (allow_bt == DPM_BT_RESTRICTED)
624 return BLUETOOTH_ERROR_PERMISSION_DEINED;
626 *value = dpm_profile_state[profile].value;
628 return BLUETOOTH_ERROR_NONE;
631 int _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
633 int allow_bt = DPM_BT_ERROR;
635 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
637 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
638 if (allow_bt == DPM_BT_RESTRICTED)
639 return BLUETOOTH_ERROR_PERMISSION_DEINED;
641 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
643 return BLUETOOTH_ERROR_NONE;
646 int _bt_dpm_get_bluetooth_desktop_connectivity_state(int *value)
648 int allow_bt = DPM_BT_ERROR;
650 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
652 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
653 if (allow_bt == DPM_BT_RESTRICTED)
654 return BLUETOOTH_ERROR_PERMISSION_DEINED;
656 *value = policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
658 return BLUETOOTH_ERROR_NONE;
661 int _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
663 int allow_bt = DPM_BT_ERROR;
665 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
667 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
668 if (allow_bt == DPM_BT_RESTRICTED)
669 return BLUETOOTH_ERROR_PERMISSION_DEINED;
671 if (value == DPM_RESTRICTED) {
672 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
673 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
676 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
678 return BLUETOOTH_ERROR_NONE;
681 int _bt_dpm_get_bluetooth_discoverable_state(int *value)
683 int allow_bt = DPM_BT_ERROR;
685 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
687 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
688 if (allow_bt == DPM_BT_RESTRICTED)
689 return BLUETOOTH_ERROR_PERMISSION_DEINED;
691 *value = policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
693 return BLUETOOTH_ERROR_NONE;
696 int _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
698 int allow_bt = DPM_BT_ERROR;
700 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
702 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
703 if (allow_bt == DPM_BT_RESTRICTED)
704 return BLUETOOTH_ERROR_PERMISSION_DEINED;
706 if (value == DPM_RESTRICTED) {
707 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
708 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
711 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
713 return BLUETOOTH_ERROR_NONE;
716 int _bt_dpm_get_bluetooth_limited_discoverable_state(int *value)
718 int allow_bt = DPM_BT_ERROR;
720 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
722 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
723 if (allow_bt == DPM_BT_RESTRICTED)
724 return BLUETOOTH_ERROR_PERMISSION_DEINED;
726 *value = policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
728 return BLUETOOTH_ERROR_NONE;
731 int _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
733 int allow_bt = DPM_BT_ERROR;
735 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
737 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
738 if (allow_bt == DPM_BT_RESTRICTED)
739 return BLUETOOTH_ERROR_PERMISSION_DEINED;
741 policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
742 return BLUETOOTH_ERROR_NONE;
745 int _bt_dpm_get_allow_bluetooth_data_transfer_state(int *value)
747 int allow_bt = DPM_BT_ERROR;
749 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
751 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
752 if (allow_bt == DPM_BT_RESTRICTED)
753 return BLUETOOTH_ERROR_PERMISSION_DEINED;
755 *value = policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
757 return BLUETOOTH_ERROR_NONE;
760 int _bt_dpm_remove_bluetooth_devices_from_allowlist(bluetooth_device_address_t *device_address)
763 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
764 int allow_bt = DPM_BT_ERROR;
766 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_allowlist");
768 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
769 if (allow_bt == DPM_BT_RESTRICTED)
770 return BLUETOOTH_ERROR_PERMISSION_DEINED;
772 _bt_convert_addr_type_to_string(bd_addr,
773 (unsigned char *)device_address->addr);
775 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list; l; l = g_slist_next(l)) {
776 char *l_device = l->data;
777 if (l_device && g_strcmp0(l_device, bd_addr)) {
778 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list, l_device);
782 return BLUETOOTH_ERROR_NONE;
785 int _bt_dpm_remove_bluetooth_devices_from_blocklist(bluetooth_device_address_t *device_address)
788 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
789 int allow_bt = DPM_BT_ERROR;
791 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blocklist");
793 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
794 if (allow_bt == DPM_BT_RESTRICTED)
795 return BLUETOOTH_ERROR_PERMISSION_DEINED;
797 _bt_convert_addr_type_to_string(bd_addr,
798 (unsigned char *)device_address->addr);
800 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLOCKLIST].list; l; l = g_slist_next(l)) {
801 char *l_device = l->data;
802 if (l_device && g_strcmp0(l_device, bd_addr)) {
803 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_ALLOWLIST].list, l_device);
808 return BLUETOOTH_ERROR_NONE;
811 int _bt_dpm_remove_bluetooth_uuids_from_allowlist(const char *uuids)
814 int allow_bt = DPM_BT_ERROR;
816 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_allowlist");
818 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
819 if (allow_bt == DPM_BT_RESTRICTED)
820 return BLUETOOTH_ERROR_PERMISSION_DEINED;
822 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list; l; l = g_slist_next(l)) {
823 char *l_uuid = l->data;
824 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
825 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_ALLOWLIST].list, l_uuid);
829 return BLUETOOTH_ERROR_NONE;
832 int _bt_dpm_remove_bluetooth_uuids_from_blocklist(const char *uuids)
835 int allow_bt = DPM_BT_ERROR;
837 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blocklist");
839 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
840 if (allow_bt == DPM_BT_RESTRICTED)
841 return BLUETOOTH_ERROR_PERMISSION_DEINED;
843 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list; l; l = g_slist_next(l)) {
844 char *l_uuid = l->data;
845 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
846 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLOCKLIST].list, l_uuid);
850 return BLUETOOTH_ERROR_NONE;
853 int _bt_dpm_clear_bluetooth_uuids_from_list(void)
855 int allow_bt = DPM_BT_ERROR;
856 int err = BLUETOOTH_ERROR_INTERNAL;
858 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
860 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
861 if (allow_bt == DPM_BT_RESTRICTED)
862 return BLUETOOTH_ERROR_PERMISSION_DEINED;
864 err = _bt_dpm_clear_bluetooth_uuids_from_blocklist();
866 err = _bt_dpm_clear_bluetooth_uuids_from_blocklist();
871 int _bt_dpm_clear_bluetooth_devices_from_list(void)
873 int allow_bt = DPM_BT_ERROR;
874 int err = BLUETOOTH_ERROR_INTERNAL;
876 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
878 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
879 if (allow_bt == DPM_BT_RESTRICTED)
880 return BLUETOOTH_ERROR_PERMISSION_DEINED;
882 err = _bt_dpm_clear_bluetooth_devices_from_blocklist();
884 err = _bt_dpm_clear_bluetooth_devices_from_blocklist();