2 * Copyright (c) 2015 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Anupam Roy <anupam.r@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include <vconf-internal-keys.h>
28 #include <bundle_internal.h>
29 #include <eventsystem.h>
33 /*bt-service headers */
34 #include "bt-internal-types.h"
35 #include "bt-service-common.h"
36 #include "bt-service-util.h"
37 #include "bt-service-main.h"
38 #include "bt-service-core-adapter.h"
39 #include "bt-service-core-device.h"
40 #include "bt-service-event-receiver.h"
41 #include "bt-request-handler.h"
42 #include "bt-service-event.h"
43 #include "bt-service-audio-common.h"
44 #include "bt-service-core-adapter-le.h"
45 #include "bt-service-gatt.h"
47 #ifdef TIZEN_FEATURE_BT_DPM
48 #include "bt-service-dpm.h"
50 #include "bt-service-hidhost.h"
51 #include "bt-service-socket.h"
52 #include "bt-service-hdp.h"
55 #include <oal-event.h>
56 #include <oal-manager.h>
57 #include <oal-adapter-mgr.h>
59 #ifdef TIZEN_FEATURE_BT_PAN_NAP
60 #include "bt-service-network.h"
62 /*This file will contain state machines related to adapter and remote device */
64 #include "bt-internal-types.h"
66 /* Global variables */
75 static bt_adapter_timer_t visible_timer;
77 static guint timer_id = 0;
79 static gboolean a2dp_init_pending = FALSE;
82 /* Adapter default states */
83 static bt_status_t adapter_state = BT_DEACTIVATED;
84 static bt_adapter_discovery_state_t adapter_discovery_state = ADAPTER_DISCOVERY_STOPPED;
86 /* Forward declarations */
87 static void __bt_adapter_event_handler(int event_type, gpointer event_data);
88 static void __bt_post_oal_init(void);
89 static void __bt_handle_oal_initialisation(oal_event_t event);
90 static void __bt_adapter_handle_pending_requests(int service_function, void *user_data, unsigned int size);
91 static gboolean __bt_adapter_post_set_enabled(gpointer user_data);
92 static gboolean __bt_adapter_post_set_disabled(gpointer user_data);
93 static void __bt_adapter_update_bt_enabled(void);
94 static void __bt_adapter_update_bt_disabled(void);
95 static void __bt_adapter_state_set_status(bt_status_t status);
96 static void __bt_adapter_update_discovery_status(bt_adapter_discovery_state_t status);
97 static void __bt_adapter_state_change_callback(int bt_status);
98 static int __bt_adapter_state_handle_request(gboolean enable);
99 static int __bt_adapter_state_discovery_request(gboolean enable,
100 unsigned short max_response, unsigned short duration, unsigned int mask);
101 static void __bt_adapter_discovery_state_change_callback(int bt_discovery_status);
102 static gboolean __bt_is_service_request_present(int service_function);
104 static void __bt_set_visible_mode(void);
105 static void __bt_set_local_name(void);
107 /* Initialize BT stack (Initialize OAL layer) */
108 int _bt_stack_init(void)
112 BT_INFO("[bt-service] Start to initialize BT stack");
113 /* Adapter enable request is successful, setup event handlers */
114 _bt_service_register_event_handler_callback(
115 BT_ADAPTER_MODULE, __bt_adapter_event_handler);
117 ret = oal_bt_init(_bt_service_oal_event_receiver);
119 if (OAL_STATUS_PENDING == ret) {
120 BT_INFO("OAL Initialisation Pending, Profiles Init will be done once oal initialised...");
121 return BLUETOOTH_ERROR_NONE;
122 } else if (OAL_STATUS_SUCCESS != ret) {
123 _bt_service_unregister_event_handler_callback(BT_ADAPTER_MODULE);
124 return BLUETOOTH_ERROR_INTERNAL;
127 return BLUETOOTH_ERROR_NONE;
130 int _bt_enable_adapter(void)
132 return __bt_adapter_state_handle_request(TRUE);
135 int _bt_enable_core(void)
137 /* TODO_40 : 4.0 merge */
138 return BLUETOOTH_ERROR_NOT_SUPPORT;
141 int _bt_recover_adapter(void)
143 /* TODO_40 : 4.0 merge */
144 return BLUETOOTH_ERROR_NOT_SUPPORT;
147 int _bt_disable_adapter(void)
149 return __bt_adapter_state_handle_request(FALSE);
152 int _bt_start_discovery(unsigned short max_response,
153 unsigned short duration, unsigned int cod_mask)
155 return __bt_adapter_state_discovery_request(TRUE, max_response, duration, cod_mask);
158 int _bt_cancel_discovery(void)
160 return __bt_adapter_state_discovery_request(FALSE, 0, 0, 0);
163 gboolean _bt_is_discovering(void)
165 if (adapter_discovery_state == ADAPTER_DISCOVERY_STARTED
166 || adapter_discovery_state == ADAPTER_DISCOVERY_STARTING)
172 int _bt_get_local_address(void)
178 result = adapter_get_address();
179 if (result != OAL_STATUS_SUCCESS) {
180 BT_ERR("adapter_get_address failed: %d", result);
181 result = BLUETOOTH_ERROR_INTERNAL;
183 result = BLUETOOTH_ERROR_NONE;
189 int _bt_get_local_version(void)
194 result = adapter_get_version();
195 if (result != OAL_STATUS_SUCCESS) {
196 BT_ERR("adapter_get_version failed: %d", result);
197 result = BLUETOOTH_ERROR_INTERNAL;
199 result = BLUETOOTH_ERROR_NONE;
205 int _bt_get_local_name(void)
211 result = adapter_get_name();
212 if (result != OAL_STATUS_SUCCESS) {
213 BT_ERR("adapter_get_name failed: %d", result);
214 result = BLUETOOTH_ERROR_INTERNAL;
216 result = BLUETOOTH_ERROR_NONE;
222 int _bt_set_local_name(char *local_name)
224 int result = BLUETOOTH_ERROR_NONE;
227 retv_if(NULL == local_name, BLUETOOTH_ERROR_INVALID_PARAM);
229 result = adapter_set_name(local_name);
230 if (result != OAL_STATUS_SUCCESS) {
231 BT_ERR("adapter_set_name failed: %d", result);
232 result = BLUETOOTH_ERROR_INTERNAL;
234 result = BLUETOOTH_ERROR_NONE;
240 int _bt_get_discoverable_mode(int *mode)
247 retv_if(NULL == mode, BLUETOOTH_ERROR_INVALID_PARAM);
249 adapter_is_discoverable(&scan_mode);
250 if (TRUE == scan_mode) {
251 adapter_get_discoverable_timeout(&timeout);
253 *mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
255 *mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
257 adapter_is_connectable(&scan_mode);
258 if(scan_mode == TRUE)
259 *mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
262 * TODO: NON CONNECTABLE is not defined in bluetooth_discoverable_mode_t.
263 * After adding BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE, set mode as
264 * BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE. Until then set -1.
271 return BLUETOOTH_ERROR_NONE;
274 int _bt_get_timeout_value(int *timeout)
279 /* Take current time */
281 time_diff = difftime(current_time, visible_timer.start_time);
283 BT_DBG("Time diff = %d\n", time_diff);
284 *timeout = visible_timer.timeout - time_diff;
286 return BLUETOOTH_ERROR_NONE;
289 static void __bt_visibility_alarm_remove()
291 if (visible_timer.event_id > 0) {
292 g_source_remove(visible_timer.event_id);
293 visible_timer.event_id = 0;
296 if (visible_timer.alarm_id > 0) {
297 alarmmgr_remove_alarm(visible_timer.alarm_id);
298 visible_timer.alarm_id = 0;
302 static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param)
304 int result = BLUETOOTH_ERROR_NONE;
307 BT_DBG("__bt_visibility_alarm_cb - alram id = [%d] \n", alarm_id);
309 if (alarm_id != visible_timer.alarm_id)
312 if (visible_timer.event_id) {
313 _bt_send_event(BT_ADAPTER_EVENT,
314 BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
315 g_variant_new("(in)", result, timeout));
316 g_source_remove(visible_timer.event_id);
317 visible_timer.event_id = 0;
318 visible_timer.timeout = 0;
320 if (!TIZEN_PROFILE_WEARABLE) {
321 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
322 BT_ERR("Set vconf failed\n");
325 /* Switch Off visibility in Bluez */
326 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
327 visible_timer.alarm_id = 0;
331 static gboolean __bt_timeout_handler(gpointer user_data)
333 int result = BLUETOOTH_ERROR_NONE;
337 /* Take current time */
339 time_diff = difftime(current_time, visible_timer.start_time);
341 /* Send event to application */
342 _bt_send_event(BT_ADAPTER_EVENT,
343 BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
344 g_variant_new("(in)", result, time_diff));
346 if (visible_timer.timeout <= time_diff) {
347 g_source_remove(visible_timer.event_id);
348 visible_timer.event_id = 0;
349 visible_timer.timeout = 0;
351 if (!TIZEN_PROFILE_WEARABLE) {
352 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
353 BT_ERR("Set vconf failed\n");
362 static void __bt_visibility_alarm_create()
367 result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, visible_timer.timeout,
370 BT_ERR("Failed to create alarm error = %d\n", result);
372 BT_DBG("Alarm created = %d\n", alarm_id);
373 visible_timer.alarm_id = alarm_id;
377 static int __bt_set_visible_time(int timeout)
380 #ifdef TIZEN_FEATURE_BT_DPM
381 int discoverable_state = DPM_BT_ERROR;
384 __bt_visibility_alarm_remove();
386 visible_timer.timeout = timeout;
388 #ifdef TIZEN_FEATURE_BT_DPM
389 _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state);
390 if (discoverable_state != DPM_RESTRICTED) {
392 if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0)
393 BT_ERR("Set vconf failed");
394 #ifdef TIZEN_FEATURE_BT_DPM
399 return BLUETOOTH_ERROR_NONE;
401 if (!visible_timer.alarm_init) {
402 /* Set Alarm timer to switch off BT */
403 result = alarmmgr_init("bt-service");
405 return BLUETOOTH_ERROR_INTERNAL;
407 visible_timer.alarm_init = TRUE;
410 result = alarmmgr_set_cb(__bt_visibility_alarm_cb, NULL);
412 return BLUETOOTH_ERROR_INTERNAL;
414 /* Take start time */
415 time(&(visible_timer.start_time));
416 visible_timer.event_id = g_timeout_add_seconds(1,
417 __bt_timeout_handler, NULL);
419 __bt_visibility_alarm_create();
421 return BLUETOOTH_ERROR_NONE;
424 int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
427 #ifdef TIZEN_FEATURE_BT_DPM
428 int discoverable_state = DPM_BT_ERROR;
433 BT_INFO("discoverable_mode: %d, timeout: %d", discoverable_mode, timeout);
435 #ifdef TIZEN_FEATURE_BT_DPM
436 _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state);
437 if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE &&
438 discoverable_state == DPM_RESTRICTED) {
439 if (headed_plugin_info->plugin_headed_enabled)
440 headed_plugin_info->headed_plugin->bt_launch_dpmpopup("DPM_POLICY_DISABLE_BT_HANDSFREE");
441 return BLUETOOTH_ERROR_ACCESS_DENIED;
443 if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE &&
444 discoverable_state == DPM_RESTRICTED) {
445 if (headed_plugin_info->plugin_headed_enabled)
446 headed_plugin_info->headed_plugin->bt_launch_dpmpopup("DPM_POLICY_DISABLE_BT");
447 return BLUETOOTH_ERROR_ACCESS_DENIED;
451 switch (discoverable_mode) {
452 case BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE:
453 result = adapter_set_connectable(TRUE);
456 case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE:
457 result = adapter_set_discoverable();
460 case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE:
461 result = adapter_set_discoverable();
464 return BLUETOOTH_ERROR_INVALID_PARAM;
467 if (result != OAL_STATUS_SUCCESS) {
468 BT_ERR("set scan mode failed %d", result);
469 return BLUETOOTH_ERROR_INTERNAL;
472 result = adapter_set_discoverable_timeout(timeout);
473 if (result != OAL_STATUS_SUCCESS) {
474 BT_ERR("adapter_set_discoverable_timeout failed %d", result);
475 return BLUETOOTH_ERROR_INTERNAL;
478 if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
481 result = __bt_set_visible_time(timeout);
487 gboolean _bt_is_connectable(void)
494 adapter_is_connectable(&connectable);
500 BT_DBG("Connectable: [%s]", result ? "TRUE":"FALSE");
505 int _bt_set_connectable(gboolean connectable)
507 int result = BLUETOOTH_ERROR_NONE;
510 result = adapter_set_connectable(connectable);
511 if (result != OAL_STATUS_SUCCESS) {
512 BT_ERR("adapter_set_connectable failed: %d", result);
513 result = BLUETOOTH_ERROR_INTERNAL;
515 result = BLUETOOTH_ERROR_NONE;
521 int _bt_is_service_used(void)
527 result = adapter_get_service_uuids();
528 if (result != OAL_STATUS_SUCCESS) {
529 BT_ERR("adapter_get_service_uuids failed: %d", result);
530 result = BLUETOOTH_ERROR_INTERNAL;
532 result = BLUETOOTH_ERROR_NONE;
539 int _bt_adapter_get_bonded_devices(void)
541 int result = BLUETOOTH_ERROR_NONE;
544 result = adapter_get_bonded_devices();
545 if (result != OAL_STATUS_SUCCESS) {
546 BT_ERR("adapter_get_bonded_devices failed: %d", result);
547 result = BLUETOOTH_ERROR_INTERNAL;
549 result = BLUETOOTH_ERROR_NONE;
555 static void __bt_handle_pending_a2dp_init(service_uuid_t *service_list, unsigned int count)
560 char uuid_str[BT_UUID_STRING_SIZE];
562 if (!a2dp_init_pending)
566 a2dp_init_pending = FALSE;
567 for (i = 0; i < count; i++) {
568 uuid = service_list[i].uuid;
569 _bt_service_convert_uuid_type_to_string(uuid_str, uuid);
570 BT_INFO("Adapter Service: [%s]", uuid_str);
571 if (!strcasecmp(uuid_str, A2DP_SINK_UUID)) {
572 BT_INFO("Enable A2DP Sink role");
573 /* Initialize A2DP Sink */
574 ret = _bt_audio_initialize(BT_A2DP_SINK_MODULE);
575 if (ret != BLUETOOTH_ERROR_NONE)
576 BT_ERR("_bt_audio_initialize(BT_A2DP_SINK_MODULE) Failed");
578 /* Initialize AVRCP Controller */
579 ret = _bt_audio_initialize(BT_AVRCP_CTRL_MODULE);
580 if (ret != BLUETOOTH_ERROR_NONE)
581 BT_ERR("_bt_audio_initialize(BT_AVRCP_CTRL_MODULE) Failed");
583 _bt_audio_set_current_role(BLUETOOTH_A2DP_SINK);
588 BT_INFO("Enable A2DP Source role by default");
589 /* Initialize A2DP Source */
590 ret = _bt_audio_initialize(BT_A2DP_SOURCE_MODULE);
591 if (ret != BLUETOOTH_ERROR_NONE)
592 BT_ERR("_bt_audio_initialize(BT_A2DP_SOURCE_MODULE) Failed");
594 /* Initialize AVRCP Target */
595 ret = _bt_audio_initialize(BT_AVRCP_MODULE);
596 if (ret != BLUETOOTH_ERROR_NONE)
597 BT_ERR("_bt_audio_initialize(BT_AVRCP_MODULE) Failed");
599 _bt_audio_set_current_role(BLUETOOTH_A2DP_SOURCE);
603 static void __bt_adapter_event_handler(int event_type, gpointer event_data)
605 int result = BLUETOOTH_ERROR_NONE;
610 case OAL_EVENT_OAL_INITIALISED_SUCCESS:
611 case OAL_EVENT_OAL_INITIALISED_FAILED:
612 __bt_handle_oal_initialisation(event_type);
614 case OAL_EVENT_ADAPTER_ENABLED:
615 __bt_adapter_state_change_callback(BT_ACTIVATED);
617 case OAL_EVENT_ADAPTER_DISABLED:
618 __bt_adapter_state_change_callback(BT_DEACTIVATED);
620 case OAL_EVENT_ADAPTER_INQUIRY_STARTED:
621 __bt_adapter_discovery_state_change_callback(ADAPTER_DISCOVERY_STARTED);
623 case OAL_EVENT_ADAPTER_INQUIRY_FINISHED:
624 __bt_adapter_discovery_state_change_callback(ADAPTER_DISCOVERY_STOPPED);
626 case OAL_EVENT_ADAPTER_PROPERTY_ADDRESS: {
627 bt_address_t *bd_addr = event_data;
628 bluetooth_device_address_t local_address;
631 memcpy(local_address.addr, bd_addr->addr, BT_ADDRESS_LENGTH_MAX);
632 BT_DBG("Adapter address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
633 local_address.addr[0], local_address.addr[1], local_address.addr[2],
634 local_address.addr[3], local_address.addr[4], local_address.addr[5]);
636 __bt_adapter_handle_pending_requests(BT_GET_LOCAL_ADDRESS,
637 (void *) &local_address, sizeof(bluetooth_device_address_t));
640 case OAL_EVENT_ADAPTER_PROPERTY_NAME: {
641 char *name = event_data;
642 BT_DBG("Adapter Name: %s", name);
644 if (__bt_is_service_request_present(BT_GET_LOCAL_NAME)) {
645 bluetooth_device_name_t local_name;
647 memset(&local_name, 0x00, sizeof(bluetooth_device_name_t));
648 g_strlcpy(local_name.name,
649 (const gchar *)name, BLUETOOTH_DEVICE_NAME_LENGTH_MAX);
650 __bt_adapter_handle_pending_requests(BT_GET_LOCAL_NAME,
651 (void *) &local_name, sizeof(bluetooth_device_name_t));
653 /* Send event to application */
654 _bt_send_event(BT_ADAPTER_EVENT,
655 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
656 g_variant_new("(is)", result, name));
660 case OAL_EVENT_ADAPTER_PROPERTY_VERSION: {
661 char *ver = event_data;
662 bluetooth_version_t local_version;
664 memset(&local_version, 0x00, sizeof(bluetooth_version_t));
665 g_strlcpy(local_version.version,
666 (const gchar *)ver, BLUETOOTH_VERSION_LENGTH_MAX);
667 BT_DBG("BT Version: %s", local_version.version);
669 __bt_adapter_handle_pending_requests(BT_GET_LOCAL_VERSION,
670 (void *) &local_version, sizeof(bluetooth_version_t));
673 case OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE: {
675 gboolean connectable = FALSE;
677 BT_INFO("Adapter discoverable mode:"
678 " BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE");
679 _bt_send_event(BT_ADAPTER_EVENT,
680 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
681 g_variant_new("(b)", connectable));
683 _bt_send_event(BT_ADAPTER_EVENT,
684 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
685 g_variant_new("(in)", result, mode));
688 case OAL_EVENT_ADAPTER_MODE_CONNECTABLE: {
690 gboolean connectable = TRUE;
692 BT_INFO("Adapter discoverable mode:"
693 " BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE");
694 _bt_send_event(BT_ADAPTER_EVENT,
695 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
696 g_variant_new("(b)", connectable));
698 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
699 _bt_send_event(BT_ADAPTER_EVENT,
700 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
701 g_variant_new("(in)", result, mode));
704 case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE: {
707 BT_INFO("Adapter discoverable mode:"
708 " BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE");
710 /* Send event to application */
711 mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
712 _bt_send_event(BT_ADAPTER_EVENT,
713 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
714 g_variant_new("(in)", result, mode));
718 case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT: {
719 int *timeout = event_data;
722 BT_INFO("Discoverable timeout: [%d]", *timeout);
724 /* Send event to application */
725 _bt_get_discoverable_mode(&mode);
726 _bt_send_event(BT_ADAPTER_EVENT,
727 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
728 g_variant_new("(in)", result, mode));
731 case OAL_EVENT_ADAPTER_PROPERTY_SERVICES: {
733 service_uuid_t *service_list;
734 event_adapter_services_t *list = event_data;
737 service_list = list->service_list;
738 __bt_handle_pending_a2dp_init(service_list, count);
739 __bt_adapter_handle_pending_requests(BT_IS_SERVICE_USED, service_list, count);
742 case OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST: {
745 bluetooth_device_address_t *addr_list;
747 event_device_list_t *bonded_device_list = event_data;
748 count = bonded_device_list->num;
750 addr_list = g_malloc0(count * sizeof(bluetooth_device_address_t));
751 for (i = 0; i < count; i++) {
752 memcpy(addr_list[i].addr,
753 bonded_device_list->devices[i].addr,
754 BLUETOOTH_ADDRESS_LENGTH);
757 BT_INFO("Adapter Bonded device List count: [%d]", count);
758 __bt_adapter_handle_pending_requests(BT_GET_BONDED_DEVICES,
759 (void *)addr_list, bonded_device_list->num);
763 BT_ERR("Unhandled event..");
770 int _bt_init_profiles()
774 /*TODO: Init bluetooth profiles */
775 ret = _bt_hidhost_initialize();
776 if (ret != BLUETOOTH_ERROR_NONE) {
777 BT_ERR("_bt_hidhost_initialize Failed");
781 ret = _bt_socket_init();
782 if (ret != BLUETOOTH_ERROR_NONE) {
783 BT_ERR("_bt_socket_init Failed");
788 * Query local adapter services and based on a2dp service uuids initialized
789 * in bluetooth stack, enable A2DP sourec or A2DP sink role.
791 ret = adapter_get_service_uuids();
792 if (ret != OAL_STATUS_SUCCESS) {
793 BT_ERR("adapter_get_service_uuids failed: %d", ret);
794 return BLUETOOTH_ERROR_INTERNAL;
796 a2dp_init_pending = TRUE;
799 /* Initialize HFP Audio Gateway */
800 ret = _bt_audio_initialize(BT_AG_MODULE);
801 if (ret != BLUETOOTH_ERROR_NONE) {
802 BT_ERR("_bt_audio_initialize(BT_AG_MODULE) Failed");
805 /* Registering callback for receiving audio services searched */
806 ret = _bt_audio_initialize(BT_AUDIO_ALL_MODULE);
807 if (ret != BLUETOOTH_ERROR_NONE) {
808 BT_ERR("_bt_audio_initialize(BT_AUDIO_ALL_MODULE) Failed");
812 ret = _bt_hdp_init();
813 if (ret != BLUETOOTH_ERROR_NONE) {
814 BT_ERR("_bt_hdp_init Failed");
819 if (ret != BLUETOOTH_ERROR_NONE) {
820 BT_ERR("_bt_le_init Failed");
824 ret = _bt_gatt_init();
825 if (ret != BLUETOOTH_ERROR_NONE) {
826 BT_ERR("_bt_gatt_init Failed");
830 return BLUETOOTH_ERROR_NONE;
833 int _bt_cleanup_profiles(void)
835 /* TODO: Cleanup bluetooth profiles */
836 _bt_hidhost_deinitialize();
839 /* TODO: Cleanup bluetooth audio profiles */
840 //_bt_audio_deinitialize(BT_A2DP_SOURCE_MODULE);
841 //_bt_audio_deinitialize(BT_AVRCP_MODULE);
842 //_bt_audio_deinitialize(BT_A2DP_SINK_MODULE);
843 //_bt_audio_deinitialize(BT_AG_MODULE);
844 //_bt_audio_deinitialize(BT_AVRCP_CTRL_MODULE);
845 //_bt_audio_deinitialize(BT_AUDIO_ALL_MODULE);
850 return BLUETOOTH_ERROR_NONE;
853 /* OAL post initialization handler */
854 static void __bt_post_oal_init(void)
857 int status = VCONFKEY_BT_STATUS_OFF;
859 BT_DBG("OAL initialized");
860 if (vconf_get_int(VCONFKEY_BT_STATUS, &status) != 0) {
861 BT_ERR("Fail to get the enabled value");
864 /* Update Bluetooth Status to OFF */
865 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
866 BT_ERR("Set vconf failed\n");
868 if (status & VCONFKEY_BT_STATUS_ON) {
869 ret = _bt_enable_adapter();
870 if (ret != BLUETOOTH_ERROR_NONE)
871 BT_ERR("_bt_enable_adapter failed with error: %d", ret);
875 /* OAL initialization handler */
876 static void __bt_handle_oal_initialisation(oal_event_t event)
881 case OAL_EVENT_OAL_INITIALISED_SUCCESS:
882 __bt_post_oal_init();
884 case OAL_EVENT_OAL_INITIALISED_FAILED:
885 BT_ERR("OAL Initialisation Failed, terminate bt-service daemon..");
886 g_idle_add(_bt_terminate_service, NULL);
889 BT_ERR("Unknown Event");
894 static gboolean __bt_is_service_request_present(int service_function)
897 invocation_info_t *req_info;
901 /* Get method invocation context */
902 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
904 if (req_info && req_info->service_function == service_function)
912 /* Internal functions of core adapter service */
913 static void __bt_adapter_handle_pending_requests(int service_function, void *user_data, unsigned int size)
917 invocation_info_t *req_info;
920 /* Get method invocation context */
921 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
923 if (req_info == NULL || req_info->service_function != service_function)
926 /* Create out param */
927 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
929 switch(service_function) {
930 case BT_ENABLE_ADAPTER:
931 case BT_DISABLE_ADAPTER: {
932 gboolean done = TRUE;
933 g_array_append_vals(out_param, &done, sizeof(gboolean));
936 case BT_GET_LOCAL_NAME:
937 case BT_GET_LOCAL_ADDRESS:
938 case BT_GET_LOCAL_VERSION:
939 g_array_append_vals(out_param, user_data, size);
941 case BT_IS_SERVICE_USED: {
943 gboolean used = FALSE;
945 char uuid_str[BT_UUID_STRING_SIZE];
946 char *request_uuid = req_info->user_data;
947 service_uuid_t *service_list = user_data;
949 BT_INFO("Check for service uuid: %s", request_uuid);
950 for (i = 0; i < size; i++) {
951 uuid = service_list[i].uuid;
952 _bt_service_convert_uuid_type_to_string(uuid_str, uuid);
953 BT_INFO("Adapter Service: [%s]", uuid_str);
954 if (strcasecmp(uuid_str, request_uuid) == 0) {
955 BT_INFO("UUID matched!!");
961 g_array_append_vals(out_param, &used, sizeof(gboolean));
964 case BT_GET_BONDED_DEVICES: {
965 bluetooth_device_address_t *addr_list = user_data;
966 bonded_devices_req_info_t *bonded_devices_req_info;
967 char address[BT_ADDRESS_STRING_SIZE];
969 int res = BLUETOOTH_ERROR_NONE;
972 * BT_GET_BONDED_DEVICES is already processed for this request,
973 * continue for next BT_GET_BONDED_DEVICES request if any
975 if (NULL != req_info->user_data)
978 BT_DBG("BT_GET_BONDED_DEVICES: count = [%d]", count);
979 /* No bonded devices, return method invocation */
980 if (0 == count || !addr_list)
983 /* Save address list in user data for futur reference. */
984 bonded_devices_req_info = g_malloc0(sizeof(bonded_devices_req_info));
985 if (!bonded_devices_req_info) {
986 BT_ERR("Memory allocation failed");
987 req_info->result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
992 bonded_devices_req_info->count = count;
993 bonded_devices_req_info->addr_list = addr_list;
994 bonded_devices_req_info->out_param = out_param;
995 req_info->user_data = bonded_devices_req_info;
997 while (bonded_devices_req_info->count > 0) {
998 bonded_devices_req_info->count -= 1;
999 res = _bt_device_get_bonded_device_info(
1000 &addr_list[bonded_devices_req_info->count]);
1001 if (BLUETOOTH_ERROR_NONE == res)
1004 _bt_convert_addr_type_to_string((char *)address,
1005 addr_list[bonded_devices_req_info->count].addr);
1006 BT_ERR("_bt_device_get_bonded_device_info Failed for [%s]", address);
1007 if (bonded_devices_req_info->count == 0) {
1008 g_free(bonded_devices_req_info->addr_list);
1009 g_free(bonded_devices_req_info);
1010 req_info->user_data = NULL;
1017 BT_ERR("Unknown service function[%d]", service_function);
1020 _bt_service_method_return(req_info->context, out_param, req_info->result);
1021 g_array_free(out_param, TRUE);
1022 /* Now free invocation info for this request*/
1023 _bt_free_info_from_invocation_list(req_info);
1027 static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
1029 char *phone_name = NULL;
1035 if (vconf_keynode_get_type(node) == VCONF_TYPE_STRING) {
1036 phone_name = vconf_keynode_get_str(node);
1038 if (phone_name && strlen(phone_name) != 0) {
1039 if (!g_utf8_validate(phone_name, -1,
1040 (const char **)&ptr))
1043 _bt_set_local_name(phone_name);
1048 /* Request return handlings */
1049 static gboolean __bt_adapter_post_set_enabled(gpointer user_data)
1051 BT_INFO("__bt_adapter_post_set_enabled>>");
1053 if (!TIZEN_PROFILE_TV) {
1054 __bt_set_visible_mode();
1056 /* add the vconf noti handler */
1057 if (0 != vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
1058 (vconf_callback_fn)__bt_phone_name_changed_cb, NULL))
1059 BT_ERR("DEVICE_NAME key changed notification registration failed");
1061 __bt_set_local_name();
1063 if (BLUETOOTH_ERROR_NONE != _bt_set_discoverable_mode(
1064 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0))
1065 BT_ERR("Fail to set discoverable mode");
1068 /* Get All properties */
1069 if (OAL_STATUS_SUCCESS != adapter_get_properties())
1070 BT_ERR("adapter_get_properties failed");
1072 /* Add Adapter enabled post processing codes */
1076 static gboolean __bt_adapter_post_set_disabled(gpointer user_data)
1078 BT_INFO("_bt_adapter_post_set_disabled>>");
1080 if (!TIZEN_PROFILE_TV) {
1081 /* Add Adapter disabled post processing codes */
1082 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
1083 (vconf_callback_fn)__bt_phone_name_changed_cb) != 0)
1084 BT_ERR("vconf_ignore_key_changed failed");
1090 static void __bt_adapter_update_bt_enabled(void)
1092 int result = BLUETOOTH_ERROR_NONE;
1093 BT_INFO("_bt_adapter_update_bt_enabled >> Init profiles...");
1094 if (BLUETOOTH_ERROR_NONE != _bt_init_profiles())
1095 BT_ERR("Bluetooth profile init failed");
1097 /* Update Bluetooth Status to notify other modules */
1098 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
1099 BT_ERR("Set vconf failed\n");
1101 /* TODO:Add timer function to handle any further post processing */
1102 g_idle_add((GSourceFunc)__bt_adapter_post_set_enabled, NULL);
1104 /*Return BT_ADAPTER_ENABLE Method invocation context */
1105 __bt_adapter_handle_pending_requests(BT_ENABLE_ADAPTER, NULL, 0);
1106 /*Send BT Enabled event to application */
1107 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
1108 g_variant_new("(i)", result));
1111 static void __bt_adapter_update_bt_disabled(void)
1113 int result = BLUETOOTH_ERROR_NONE;
1114 BT_INFO("_bt_adapter_update_bt_disabled >> Cleanup profiles...");
1115 _bt_cleanup_profiles();
1117 int power_off_status = 0;
1120 /* Update the vconf BT status in normal Deactivation case only */
1121 ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
1122 BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status);
1124 /* Update Bluetooth Status to notify other modules */
1125 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
1126 BT_ERR("Set vconf failed");
1128 /* TODO:Add timer function to handle any further post processing */
1129 g_idle_add((GSourceFunc)__bt_adapter_post_set_disabled, NULL);
1131 /* Return BT_ADAPTER_DISABLE Method invocation context */
1132 __bt_adapter_handle_pending_requests(BT_DISABLE_ADAPTER, NULL, 0);
1134 /* Send BT Disabled event to application */
1135 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
1136 g_variant_new("(i)", result));
1139 static void __bt_adapter_state_set_status(bt_status_t status)
1141 BT_INFO("adapter_status changed [%d] -> [%d]", adapter_state, status);
1142 adapter_state = status;
1145 static void __bt_adapter_update_discovery_status(bt_adapter_discovery_state_t status)
1147 BT_INFO("adapter_discovery_status changed [%d] -> [%d]", adapter_discovery_state, status);
1148 adapter_discovery_state = status;
1151 static void __bt_adapter_state_change_callback(int bt_status)
1153 BT_INFO("__bt_adapter_state_change_callback: status [%d]", bt_status);
1155 switch (bt_status) {
1156 case BT_DEACTIVATED:
1157 __bt_adapter_state_set_status(bt_status);
1159 /* Adapter is disabled, unregister event handlers */
1160 _bt_service_unregister_event_handler_callback(BT_ADAPTER_MODULE);
1161 //_bt_deinit_device_event_handler();
1163 /* Add Adapter disabled post processing codes */
1164 __bt_adapter_update_bt_disabled();
1167 __bt_adapter_state_set_status(bt_status);
1168 /* Add Adapter enabled post processing codes */
1170 BT_DBG("g_source is removed");
1171 g_source_remove(timer_id);
1174 __bt_adapter_update_bt_enabled();
1177 BT_ERR("Incorrect Bluetooth adapter state changed status");
1182 static int __bt_adapter_state_handle_request(gboolean enable)
1184 int result = BLUETOOTH_ERROR_NONE;
1187 switch (adapter_state) {
1188 case BT_ACTIVATING: {
1189 BT_INFO("Adapter is currently in activating state, state [%d]",
1192 return BLUETOOTH_ERROR_IN_PROGRESS;
1194 if (adapter_discovery_state == ADAPTER_DISCOVERY_STARTED ||
1195 adapter_discovery_state == ADAPTER_DISCOVERY_STARTING) {
1196 /*TODO Stop Discovery*/
1197 if (result != OAL_STATUS_SUCCESS)
1198 BT_ERR("Discover stop failed: %d", result);
1199 __bt_adapter_update_discovery_status(FALSE);
1201 result = adapter_disable();
1202 if (result != OAL_STATUS_SUCCESS) {
1203 BT_ERR("adapter_enable failed: [%d]", result);
1204 result = BLUETOOTH_ERROR_INTERNAL;
1205 /*TODO: perform if anything more needs to be done to handle failure */
1207 /* TODO: To be handled */
1208 __bt_adapter_state_set_status(BT_DEACTIVATING);
1209 result = BLUETOOTH_ERROR_NONE;
1214 case BT_ACTIVATED: {
1215 BT_INFO("Adapter is currently in activated state, state [%d]",
1218 return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
1220 if (adapter_discovery_state == ADAPTER_DISCOVERY_STARTED ||
1221 adapter_discovery_state == ADAPTER_DISCOVERY_STARTING) {
1222 /*TODO Stop Discovery*/
1223 if (result != OAL_STATUS_SUCCESS)
1224 BT_ERR("Discover stop failed: %d", result);
1225 __bt_adapter_update_discovery_status(FALSE);
1227 result = adapter_disable();
1228 if (result != OAL_STATUS_SUCCESS) {
1229 BT_ERR("adapter_enable failed: [%d]", result);
1230 result = BLUETOOTH_ERROR_INTERNAL;
1231 /*TODO: perform if anything more needs to be done to handle failure */
1233 /* TODO: To be handled */
1234 __bt_adapter_state_set_status(BT_DEACTIVATING);
1235 result = BLUETOOTH_ERROR_NONE;
1240 case BT_DEACTIVATING: {
1241 BT_INFO("Adapter is currently in deactivating state, state [%d]",
1244 return BLUETOOTH_ERROR_IN_PROGRESS;
1247 result = adapter_enable();
1248 if (result != OAL_STATUS_SUCCESS && result != OAL_STATUS_PENDING) {
1249 BT_ERR("adapter_enable failed: [%d]", result);
1251 result = BLUETOOTH_ERROR_INTERNAL;
1252 /*TODO: perform if anything more needs to be done to handle failure */
1254 /* TODO: To be handled */
1255 __bt_adapter_state_set_status(BT_ACTIVATING);
1256 result = BLUETOOTH_ERROR_NONE;
1261 case BT_DEACTIVATED: {
1262 BT_INFO("Adapter is currently in deactivated state, state [%d]",
1265 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1267 result = adapter_enable();
1268 if (result != OAL_STATUS_SUCCESS && result != OAL_STATUS_PENDING) {
1269 BT_ERR("adapter_enable failed: [%d]", result);
1271 result = BLUETOOTH_ERROR_INTERNAL;
1272 /*TODO: perform if anything more needs to be done to handle failure */
1274 /* TODO: To be handled */
1275 __bt_adapter_state_set_status(BT_ACTIVATING);
1276 result = BLUETOOTH_ERROR_NONE;
1282 BT_ERR("Unknown state: %d", adapter_state);
1286 if (enable && result == BLUETOOTH_ERROR_NONE) {
1287 /* Adapter enable request is successful, setup event handlers */
1288 _bt_service_register_event_handler_callback(
1289 BT_ADAPTER_MODULE, __bt_adapter_event_handler);
1290 _bt_device_state_handle_callback_set_request();
1295 static int __bt_adapter_state_discovery_request(gboolean enable,
1296 unsigned short max_response, unsigned short duration, unsigned int mask)
1298 int result = BLUETOOTH_ERROR_NONE;
1301 switch (adapter_discovery_state) {
1302 case ADAPTER_DISCOVERY_STARTED: {
1303 BT_INFO("Adapter is currently in discovery started state, state [%d]",
1304 adapter_discovery_state);
1306 return BLUETOOTH_ERROR_IN_PROGRESS;
1308 result = adapter_stop_inquiry();
1309 if (result != OAL_STATUS_SUCCESS) {
1310 BT_ERR("Discover stop failed: %d", result);
1311 result = BLUETOOTH_ERROR_INTERNAL;
1313 BT_ERR("Stop Discovery Triggered successfully");
1314 __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STOPPING);
1315 result = BLUETOOTH_ERROR_NONE;
1320 case ADAPTER_DISCOVERY_STARTING: {
1321 BT_INFO("Adapter is currently in discovery starting state, state [%d]",
1322 adapter_discovery_state);
1324 return BLUETOOTH_ERROR_IN_PROGRESS;
1326 result = adapter_stop_inquiry();
1327 if (result != OAL_STATUS_SUCCESS) {
1328 BT_ERR("Discover stop failed: %d", result);
1329 result = BLUETOOTH_ERROR_INTERNAL;
1331 BT_ERR("Stop Discovery Triggered successfully");
1332 __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STOPPING);
1333 result = BLUETOOTH_ERROR_NONE;
1338 case ADAPTER_DISCOVERY_STOPPED: {
1339 BT_INFO("Adapter is currently in discovery stopped state, state [%d]",
1340 adapter_discovery_state);
1342 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
1344 BT_DBG("max_resp: %u, duration: %u, cod: 0x%X", max_response, duration, mask);
1345 result = adapter_start_inquiry(duration);
1346 if (result != OAL_STATUS_SUCCESS) {
1347 BT_ERR("Start Discovery failed: %d", result);
1348 result = BLUETOOTH_ERROR_INTERNAL;
1350 BT_ERR("Start Discovery Triggered successfully");
1351 __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STARTING);
1352 result = BLUETOOTH_ERROR_NONE;
1357 case ADAPTER_DISCOVERY_STOPPING: {
1358 BT_INFO("Adapter is currently in discovery stopping state, state [%d]",
1359 adapter_discovery_state);
1361 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
1363 BT_DBG("max_resp: %u, duration: %u, cod: 0x%X", max_response, duration, mask);
1364 result = adapter_start_inquiry(duration);
1365 if (result != OAL_STATUS_SUCCESS) {
1366 BT_ERR("Start Discovery failed: %d", result);
1367 result = BLUETOOTH_ERROR_INTERNAL;
1369 BT_ERR("Start Discovery Triggered successfully");
1370 __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STARTING);
1371 result = BLUETOOTH_ERROR_NONE;
1377 BT_ERR("Unknown state: %d", adapter_discovery_state);
1385 static void __bt_adapter_discovery_state_change_callback(int bt_discovery_status)
1387 BT_INFO("__bt_adapter_discovery_state_change_callback: status [%d]", bt_discovery_status);
1388 GVariant *param = NULL;
1389 int result = BLUETOOTH_ERROR_NONE;
1391 switch (bt_discovery_status) {
1392 case ADAPTER_DISCOVERY_STOPPED:
1394 __bt_adapter_update_discovery_status(bt_discovery_status);
1395 param = g_variant_new("(i)", result);
1396 _bt_send_event(BT_ADAPTER_EVENT,
1397 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
1401 case ADAPTER_DISCOVERY_STARTED:
1403 __bt_adapter_update_discovery_status(bt_discovery_status);
1404 param = g_variant_new("(i)", result);
1405 _bt_send_event(BT_ADAPTER_EVENT,
1406 BLUETOOTH_EVENT_DISCOVERY_STARTED,
1411 BT_ERR("Incorrect Bluetooth adapter Discovery state changed status");
1415 static void __bt_set_visible_mode(void)
1418 #ifdef TIZEN_FEATURE_BT_DPM
1419 int discoverable_state = DPM_BT_ERROR;
1422 if (vconf_get_int(BT_FILE_VISIBLE_TIME, &timeout) != 0)
1423 BT_ERR("Fail to get the timeout value");
1425 #ifdef TIZEN_FEATURE_BT_DPM
1426 _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state);
1427 if (timeout == -1 || discoverable_state == DPM_RESTRICTED) {
1428 if (_bt_set_discoverable_mode(
1429 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE,
1430 timeout) != BLUETOOTH_ERROR_NONE) {
1431 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
1432 BT_ERR("Set vconf failed");
1435 if (_bt_set_discoverable_mode(
1436 BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE,
1437 timeout) != BLUETOOTH_ERROR_NONE) {
1438 BT_ERR("Set connectable mode failed");
1442 if (timeout == -1) {
1443 if (_bt_set_discoverable_mode(
1444 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE,
1445 timeout) != BLUETOOTH_ERROR_NONE) {
1446 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
1447 BT_ERR("Set vconf failed");
1450 if (_bt_set_discoverable_mode(
1451 BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE,
1452 timeout) != BLUETOOTH_ERROR_NONE) {
1453 BT_ERR("Set connectable mode failed");
1459 static void __bt_set_local_name(void)
1461 char *phone_name = NULL;
1464 phone_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1469 if (strlen(phone_name) != 0) {
1470 if (!g_utf8_validate(phone_name, -1, (const char **)&ptr))
1473 _bt_set_local_name(phone_name);
1478 void _bt_adapter_set_status(bt_status_t status)
1480 BT_INFO("adapter_status changed [%d] -> [%d]", adapter_state, status);
1481 adapter_state = status;
1484 bt_status_t _bt_adapter_get_status(void)
1486 return adapter_state;
1489 void _bt_set_disabled(int result)
1491 int power_off_status = 0;
1494 int pm_ignore_mode = 0;
1496 ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
1497 BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status);
1499 ret_pm_ignore = vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &pm_ignore_mode);
1501 /* Update the vconf BT status in normal Deactivation case only */
1502 if (ret == 0 && power_off_status == VCONFKEY_SYSMAN_POWER_OFF_NONE &&
1503 ret_pm_ignore == 0 && pm_ignore_mode != VCONFKEY_PM_KEY_LOCK) {
1505 BT_DBG("Update vconf for BT normal Deactivation");
1507 if (result == BLUETOOTH_ERROR_TIMEOUT)
1508 if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 1) != 0)
1509 BT_ERR("Set vconf failed");
1511 /* Update Bluetooth Status to notify other modules */
1512 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
1513 BT_ERR("Set vconf failed");
1515 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
1516 EVT_VAL_BT_OFF) != ES_R_OK)
1517 BT_ERR("Fail to set value");
1520 if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
1521 BT_ERR("Set vconf failed\n");
1523 _bt_cancel_queued_transfers();
1524 _bt_adapter_set_status(BT_DEACTIVATED);
1525 __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STOPPED);
1527 BT_INFO("Adapter disabled");