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 #if 0 /* Use device functions if this logic required in later */
291 /* Disconnect if connected blacklist uuid is existing */
292 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
293 _bt_get_profile_connected_devices((char *)uuid, &addr_list);
294 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
295 char address[BT_ADDRESS_STRING_SIZE];
297 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
298 _bt_convert_addr_type_to_string(address, addr->addr);
299 BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
300 // TODO: need to implement disconnect logic
302 g_array_free(addr_list, TRUE);
305 return BLUETOOTH_ERROR_NONE;
308 int _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
310 int ret = BLUETOOTH_ERROR_INTERNAL;
311 int allow_bt = DPM_BT_ERROR;
312 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
313 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
316 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
318 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
319 if (allow_bt == DPM_BT_RESTRICTED)
320 return BLUETOOTH_ERROR_PERMISSION_DEINED;
323 ret = BLUETOOTH_ERROR_NONE;
324 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
325 for (; list; list = list->next, i++) {
326 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
327 g_strlcpy(uuids_list.uuids[i], list->data,
328 BLUETOOTH_UUID_STRING_MAX);
330 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
332 ret = BLUETOOTH_ERROR_NONE;
333 uuids_list.count = 0;
334 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
340 int _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
343 int allow_bt = DPM_BT_ERROR;
345 BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
347 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
348 if (allow_bt == DPM_BT_RESTRICTED)
349 return BLUETOOTH_ERROR_PERMISSION_DEINED;
351 l_uuid = g_strdup(uuid);
353 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
355 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
356 return BLUETOOTH_ERROR_NONE;
360 int _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
362 int ret = BLUETOOTH_ERROR_INTERNAL;
363 int allow_bt = DPM_BT_ERROR;
364 bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
365 GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
368 BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
370 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
371 if (allow_bt == DPM_BT_RESTRICTED)
372 return BLUETOOTH_ERROR_PERMISSION_DEINED;
375 ret = BLUETOOTH_ERROR_NONE;
376 uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
377 for (; list; list = list->next, i++) {
378 memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
379 g_strlcpy(uuids_list.uuids[i], list->data,
380 BLUETOOTH_UUID_STRING_MAX);
382 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
384 ret = BLUETOOTH_ERROR_NONE;
385 uuids_list.count = 0;
386 g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
393 int _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
395 int allow_bt = DPM_BT_ERROR;
397 BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
399 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
400 if (allow_bt == DPM_BT_RESTRICTED)
401 return BLUETOOTH_ERROR_PERMISSION_DEINED;
403 policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
405 return BLUETOOTH_ERROR_NONE;
408 int _bt_dpm_get_allow_bluetooth_outgoing_call(int *value)
410 int allow_bt = DPM_BT_ERROR;
412 BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
414 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
415 if (allow_bt == DPM_BT_RESTRICTED)
416 return BLUETOOTH_ERROR_PERMISSION_DEINED;
418 *value = policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
420 return BLUETOOTH_ERROR_NONE;
423 int _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
426 int allow_bt = DPM_BT_ERROR;
428 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
430 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
431 if (allow_bt == DPM_BT_RESTRICTED)
432 return BLUETOOTH_ERROR_PERMISSION_DEINED;
434 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
435 char *address = l->data;
437 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
441 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
442 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
444 return BLUETOOTH_ERROR_NONE;
447 int _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
450 int allow_bt = DPM_BT_ERROR;
452 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
454 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
455 if (allow_bt == DPM_BT_RESTRICTED)
456 return BLUETOOTH_ERROR_PERMISSION_DEINED;
458 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
459 char *address = l->data;
461 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
465 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
466 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
468 return BLUETOOTH_ERROR_NONE;
471 int _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
474 int allow_bt = DPM_BT_ERROR;
476 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
478 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
479 if (allow_bt == DPM_BT_RESTRICTED)
480 return BLUETOOTH_ERROR_PERMISSION_DEINED;
482 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
483 char *l_uuid = l->data;
485 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
489 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
490 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
492 return BLUETOOTH_ERROR_NONE;
495 int _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
498 int allow_bt = DPM_BT_ERROR;
500 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
502 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
503 if (allow_bt == DPM_BT_RESTRICTED)
504 return BLUETOOTH_ERROR_PERMISSION_DEINED;
506 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
507 char *l_uuid = l->data;
509 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
513 g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
514 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
516 return BLUETOOTH_ERROR_NONE;
519 int _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
521 int allow_bt = DPM_BT_ERROR;
523 BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
525 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
526 if (allow_bt == DPM_BT_RESTRICTED)
527 return BLUETOOTH_ERROR_PERMISSION_DEINED;
529 policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
531 return BLUETOOTH_ERROR_NONE;
534 int _bt_dpm_get_bluetooth_pairing_state(int *value)
536 int allow_bt = DPM_BT_ERROR;
538 BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
540 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
541 if (allow_bt == DPM_BT_RESTRICTED)
542 return BLUETOOTH_ERROR_PERMISSION_DEINED;
544 *value = policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
546 return BLUETOOTH_ERROR_NONE;
549 int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
551 int allow_bt = DPM_BT_ERROR;
553 BT_INFO("_bt_dpm_set_bluetooth_profile_state");
555 if (profile >= DPM_PROFILE_NONE)
556 return BLUETOOTH_ERROR_INTERNAL;
558 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
559 if (allow_bt == DPM_BT_RESTRICTED)
560 return BLUETOOTH_ERROR_PERMISSION_DEINED;
562 dpm_profile_state[profile].value = value;
565 #if 0 /* Use other functions if this logic required in later */
566 /* In case of restriction, disconnect if connected profile is existing */
567 if (value == DPM_RESTRICTED) {
569 GArray *addr_list = NULL;
573 case DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE:
576 case DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE:
577 uuid = BT_AVRCP_TARGET_UUID;
579 case DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE:
580 uuid = "00001118-0000-1000-8000-00805f9b34fb"; // TODO: need to add definition and below also.
582 case DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE:
583 uuid = "00001103-0000-1000-8000-00805f9b34fb";
585 case DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE:
588 case DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE:
589 uuid = "0000111e-0000-1000-8000-00805f9b34fb";
591 case DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE:
592 uuid = "00001108-0000-1000-8000-00805f9b34fb";
594 case DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE:
595 uuid = BT_OBEX_PSE_UUID;
597 case DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE:
598 uuid = "0000112d-0000-1000-8000-00805f9b34fb";
600 case DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE:
604 BT_ERR("Unknown profile %d", profile);
605 return BLUETOOTH_ERROR_INTERNAL;
608 addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
609 _bt_get_profile_connected_devices(uuid, &addr_list);
610 for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) {
611 char address[BT_ADDRESS_STRING_SIZE];
613 bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i);
614 _bt_convert_addr_type_to_string(address, addr->addr);
615 BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address);
616 // TODO: need to implement disconnect logic
618 g_array_free(addr_list, TRUE);
622 return BLUETOOTH_ERROR_NONE;
625 int _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile, int *value)
627 int allow_bt = DPM_BT_ERROR;
629 BT_INFO("_bt_dpm_get_bluetooth_profile_state");
631 if (profile >= DPM_PROFILE_NONE)
632 return BLUETOOTH_ERROR_INTERNAL;
634 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
635 if (allow_bt == DPM_BT_RESTRICTED)
636 return BLUETOOTH_ERROR_PERMISSION_DEINED;
638 *value = dpm_profile_state[profile].value;
640 return BLUETOOTH_ERROR_NONE;
643 int _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
645 int allow_bt = DPM_BT_ERROR;
647 BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
649 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
650 if (allow_bt == DPM_BT_RESTRICTED)
651 return BLUETOOTH_ERROR_PERMISSION_DEINED;
653 policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
655 return BLUETOOTH_ERROR_NONE;
658 int _bt_dpm_get_bluetooth_desktop_connectivity_state(int *value)
660 int allow_bt = DPM_BT_ERROR;
662 BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
664 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
665 if (allow_bt == DPM_BT_RESTRICTED)
666 return BLUETOOTH_ERROR_PERMISSION_DEINED;
668 *value = policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
670 return BLUETOOTH_ERROR_NONE;
673 int _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
675 int allow_bt = DPM_BT_ERROR;
677 BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
679 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
680 if (allow_bt == DPM_BT_RESTRICTED)
681 return BLUETOOTH_ERROR_PERMISSION_DEINED;
683 if (value == DPM_RESTRICTED) {
684 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
685 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
688 policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
690 return BLUETOOTH_ERROR_NONE;
693 int _bt_dpm_get_bluetooth_discoverable_state(int *value)
695 int allow_bt = DPM_BT_ERROR;
697 BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
699 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
700 if (allow_bt == DPM_BT_RESTRICTED)
701 return BLUETOOTH_ERROR_PERMISSION_DEINED;
703 *value = policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
705 return BLUETOOTH_ERROR_NONE;
708 int _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
710 int allow_bt = DPM_BT_ERROR;
712 BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
714 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
715 if (allow_bt == DPM_BT_RESTRICTED)
716 return BLUETOOTH_ERROR_PERMISSION_DEINED;
718 if (value == DPM_RESTRICTED) {
719 /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
720 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
723 policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
725 return BLUETOOTH_ERROR_NONE;
728 int _bt_dpm_get_bluetooth_limited_discoverable_state(int *value)
730 int allow_bt = DPM_BT_ERROR;
732 BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
734 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
735 if (allow_bt == DPM_BT_RESTRICTED)
736 return BLUETOOTH_ERROR_PERMISSION_DEINED;
738 *value = policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
740 return BLUETOOTH_ERROR_NONE;
743 int _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
745 int allow_bt = DPM_BT_ERROR;
747 BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
749 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
750 if (allow_bt == DPM_BT_RESTRICTED)
751 return BLUETOOTH_ERROR_PERMISSION_DEINED;
753 policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
754 return BLUETOOTH_ERROR_NONE;
757 int _bt_dpm_get_allow_bluetooth_data_transfer_state(int *value)
759 int allow_bt = DPM_BT_ERROR;
761 BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
763 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
764 if (allow_bt == DPM_BT_RESTRICTED)
765 return BLUETOOTH_ERROR_PERMISSION_DEINED;
767 *value = policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
769 return BLUETOOTH_ERROR_NONE;
772 int _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
775 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
776 int allow_bt = DPM_BT_ERROR;
778 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
780 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
781 if (allow_bt == DPM_BT_RESTRICTED)
782 return BLUETOOTH_ERROR_PERMISSION_DEINED;
784 _bt_convert_addr_type_to_string(bd_addr,
785 (unsigned char *)device_address->addr);
787 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
788 char *l_device = l->data;
789 if (l_device && g_strcmp0(l_device, bd_addr)) {
790 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
794 return BLUETOOTH_ERROR_NONE;
797 int _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
800 char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
801 int allow_bt = DPM_BT_ERROR;
803 BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
805 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
806 if (allow_bt == DPM_BT_RESTRICTED)
807 return BLUETOOTH_ERROR_PERMISSION_DEINED;
809 _bt_convert_addr_type_to_string(bd_addr,
810 (unsigned char *)device_address->addr);
812 for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
813 char *l_device = l->data;
814 if (l_device && g_strcmp0(l_device, bd_addr)) {
815 policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
820 return BLUETOOTH_ERROR_NONE;
823 int _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
826 int allow_bt = DPM_BT_ERROR;
828 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
830 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
831 if (allow_bt == DPM_BT_RESTRICTED)
832 return BLUETOOTH_ERROR_PERMISSION_DEINED;
834 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
835 char *l_uuid = l->data;
836 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
837 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
841 return BLUETOOTH_ERROR_NONE;
844 int _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
847 int allow_bt = DPM_BT_ERROR;
849 BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
851 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
852 if (allow_bt == DPM_BT_RESTRICTED)
853 return BLUETOOTH_ERROR_PERMISSION_DEINED;
855 for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
856 char *l_uuid = l->data;
857 if (l_uuid && g_strcmp0(l_uuid, uuids)) {
858 policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
862 return BLUETOOTH_ERROR_NONE;
865 int _bt_dpm_clear_bluetooth_uuids_from_list(void)
867 int allow_bt = DPM_BT_ERROR;
868 int err = BLUETOOTH_ERROR_INTERNAL;
870 BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
872 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
873 if (allow_bt == DPM_BT_RESTRICTED)
874 return BLUETOOTH_ERROR_PERMISSION_DEINED;
876 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
878 err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
883 int _bt_dpm_clear_bluetooth_devices_from_list(void)
885 int allow_bt = DPM_BT_ERROR;
886 int err = BLUETOOTH_ERROR_INTERNAL;
888 BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
890 _bt_dpm_get_allow_bluetooth_mode(&allow_bt);
891 if (allow_bt == DPM_BT_RESTRICTED)
892 return BLUETOOTH_ERROR_PERMISSION_DEINED;
894 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
896 err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
900 #endif /* #ifdef TIZEN_FEATURE_BT_DPM */