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.
19 #include <vconf-keys.h>
20 #include <vconf-internal-radio-keys.h>
22 #include <eventsystem.h>
24 #include <actd/unit_control.h>
26 #include "bt-core-main.h"
27 #include "bt-core-adapter.h"
28 #include "bt-core-common.h"
29 #include "bt-core-dbus-handler.h"
30 #include "bt-core-noti-handler.h"
32 #include "bt-internal-types.h"
34 #define BT_CORE_IDLE_TERM_TIME 200 /* 200ms */
35 #define BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX 50
37 #ifdef TIZEN_FEATURE_BT_OTP
38 #define BT_OTP_OBJECT_PATH "/org/projectx/otp"
39 #define BT_OTP_INTERFACE_NAME "org.projectx.otp_service"
40 #define BLE_DISABLED "LeDisabled"
43 static bt_status_t adapter_status = BT_DEACTIVATED;
44 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
45 static gboolean is_recovery_mode = FALSE;
46 static guint core_enable_timer_id;
49 static int bt_status_before[BT_MODE_MAX] = { VCONFKEY_BT_STATUS_OFF, };
50 static int bt_le_status_before[BT_MODE_MAX] = { VCONFKEY_BT_LE_STATUS_OFF, };
52 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value);
54 static void __bt_core_set_status(bt_status_t status)
56 adapter_status = status;
59 bt_status_t _bt_core_get_status(void)
61 return adapter_status;
64 static void __bt_core_set_le_status(bt_le_status_t status)
66 adapter_le_status = status;
69 bt_le_status_t _bt_core_get_le_status(void)
71 return adapter_le_status;
74 int _bt_core_get_bt_status(bt_mode_e mode)
76 return bt_status_before[mode];
79 int _bt_core_get_bt_le_status(bt_mode_e mode)
81 return bt_le_status_before[mode];
84 void _bt_core_set_bt_status(bt_mode_e mode, int status)
86 bt_status_before[mode] = status;
89 void _bt_core_set_bt_le_status(bt_mode_e mode, int status)
91 bt_le_status_before[mode] = status;
94 gboolean _bt_core_is_recovery_mode(void)
96 return is_recovery_mode;
99 static gboolean __bt_core_idle_terminate(gpointer data)
102 _bt_core_terminate();
106 gboolean _bt_core_is_flight_mode_enabled(void)
108 int isFlightMode = 0;
111 if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
112 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode);
114 BT_ERR("vconf_get_bool failed");
122 static int __bt_call_systemact_service(const char *service_name)
126 BT_DBG("Use System Activated : %s", service_name);
128 ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM, service_name, 5000);
130 if (ret != UNIT_CONTROL_OK) {
131 BT_ERR("Failed to activate the %s: %d", service_name, ret);
132 /* Return Success even if the activating result is fail */
139 static int __execute_command(const char *cmd, char *const arg_list[])
149 BT_ERR("fork failed");
155 BT_ERR("fork failed");
156 } else if (pid2 == 0) {
157 if (arg_list != NULL) {
158 execv(cmd, arg_list);
160 char *argv[] = { NULL };
169 BT_DBG("parent : forked[%d]", pid);
170 waitpid(pid, &status, 0);
171 BT_DBG("child is terminated : %d", status);
178 static int __bt_stack_up(void)
182 /* activate HCI logger */
183 ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_LOGGER_START);
185 BT_ERR("Failed to call systemact service");
190 ret = __bt_call_systemact_service(BT_SYSTEMACT_BLUEZ_START);
192 BT_ERR("Failed to call systemact service");
196 /* activate bluetooth-share */
197 if (!TIZEN_PROFILE_WEARABLE) {
198 ret = __bt_call_systemact_service(BT_SYSTEMACT_BLUETOOTH_SHARE_START);
200 BT_ERR("Failed to call systemact service");
208 int _bt_enable_adapter(void)
215 status = _bt_core_get_status();
216 if (status != BT_DEACTIVATED) {
217 BT_ERR("Invalid state %d", status);
218 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
222 /* only the concept of private
224 bt_le_status_t le_status;
226 le_status = _bt_core_get_le_status();
227 if (le_status == BT_LE_ACTIVATED) {
228 // Turn on PSCAN, (ISCAN if needed)
229 // Return with 0 for the Enabled response.
230 __bt_core_set_status(BT_ACTIVATED);
231 BT_INFO("BR/EDR is enabled.");
232 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
238 __bt_core_set_status(BT_ACTIVATING);
239 if (TIZEN_FEATURE_BT_USB_DONGLE) {
241 ret = __bt_call_systemact_service(BT_SYSTEMACT_BLUEZ_START);
243 BT_ERR("If bluez already exist, skip this error");
245 ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_UP);
247 BT_ERR("Failed to call systemact service");
249 ret = __bt_stack_up();
252 BT_ERR("running script failed");
253 if (TIZEN_FEATURE_BT_USB_DONGLE) {
254 ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN);
256 BT_ERR("Failed to call systemact service");
258 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
260 __bt_core_set_status(BT_DEACTIVATED);
267 int _bt_disable_adapter(void)
271 BT_INFO_C("Disable adapter");
273 /* only the concept of private
275 bt_le_status_t le_status;
277 le_status = _bt_core_get_le_status();
278 BT_DBG("le_status : %d", le_status);
279 if (le_status == BT_LE_ACTIVATED) {
280 // Turn off PSCAN, (ISCAN if needed)
281 // Return with 0 for the Disabled response.
282 __bt_core_set_status(BT_DEACTIVATED);
283 BT_INFO("BR/EDR is disabled. now LE only mode");
284 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
290 status = _bt_core_get_status();
291 if (status == BT_ACTIVATING) {
292 /* Forcely terminate */
293 if (TIZEN_FEATURE_BT_USB_DONGLE) {
294 if (__bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN) < 0)
295 BT_ERR("Failed to call systemact service");
297 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
299 /* Check if radio status on or off */
300 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
301 BT_ERR("Fail to get radio status");
303 BT_DBG("Radio status: %d", radio_status);
305 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
306 if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN_WITH_RADIO) < 0)
307 BT_ERR("running script failed");
309 if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN) < 0)
310 BT_ERR("running script failed");
313 _bt_core_terminate();
315 } else if (status != BT_ACTIVATED) {
316 BT_ERR("Invalid state %d", status);
317 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
320 __bt_core_set_status(BT_DEACTIVATING);
321 if (TIZEN_FEATURE_BT_USB_DONGLE) {
322 if (__bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN) < 0) {
323 BT_ERR("Failed to call systemact service");
324 __bt_core_set_status(BT_ACTIVATED);
327 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
329 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
331 /* Check if radio status on or off */
332 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
333 BT_ERR("Fail to get radio status");
335 BT_DBG("Radio status: %d", radio_status);
337 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
338 if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN_WITH_RADIO) < 0) {
339 BT_ERR("running script failed");
340 __bt_core_set_status(BT_ACTIVATED);
344 if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN) < 0) {
345 BT_ERR("running script failed");
346 __bt_core_set_status(BT_ACTIVATED);
355 int _bt_enable_adapter_le(void)
361 bt_le_status_t le_status;
362 le_status = _bt_core_get_le_status();
363 retv_if(le_status == BT_LE_ACTIVATED, 0);
364 retv_if(le_status != BT_LE_DEACTIVATED, -1);
366 status = _bt_core_get_status();
367 if (status == BT_DEACTIVATED) {
368 __bt_core_set_le_status(BT_LE_ACTIVATING);
369 BT_DBG("Activate BT");
370 if (TIZEN_FEATURE_BT_USB_DONGLE) {
371 ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_UP);
373 BT_ERR("Failed to call systemact service");
375 ret = __bt_stack_up();
378 BT_ERR("running script failed");
379 if (TIZEN_FEATURE_BT_USB_DONGLE) {
380 ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN);
382 BT_ERR("Failed to call systemact service");
384 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
386 __bt_core_set_status(BT_DEACTIVATED);
387 __bt_core_set_le_status(BT_LE_DEACTIVATED);
391 __bt_core_set_le_status(BT_LE_ACTIVATED);
392 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
394 #ifdef TIZEN_FEATURE_BT_HPS
395 ret = _bt_core_start_httpproxy();
397 BT_ERR("_bt_core_start_httpproxy() failed");
403 #ifdef TIZEN_FEATURE_BT_OTP
404 static void _bt_core_stop_otp()
406 GError *error = NULL;
407 GDBusMessage *msg = NULL;
408 GDBusConnection *conn = _bt_core_get_gdbus_connection();
409 msg = g_dbus_message_new_signal(BT_OTP_OBJECT_PATH, BT_OTP_INTERFACE_NAME, BLE_DISABLED);
410 if (!g_dbus_connection_send_message(conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL)) {
412 BT_ERR("Failed to send BLE_DISABLED signal to OTP : errCode[%x], \
414 error->code, error->message);
415 g_clear_error(&error);
421 int _bt_disable_adapter_le(void)
426 bt_le_status_t le_status;
428 le_status = _bt_core_get_le_status();
429 retv_if(le_status == BT_LE_DEACTIVATED, 0);
430 retv_if(le_status == BT_LE_DEACTIVATING, -1);
432 #ifdef TIZEN_FEATURE_BT_HPS
433 _bt_core_stop_httpproxy();
436 #ifdef TIZEN_FEATURE_BT_OTP
440 status = _bt_core_get_status();
441 BT_DBG("status : %d", status);
443 if (status == BT_DEACTIVATED) {
444 __bt_core_set_le_status(BT_LE_DEACTIVATING);
446 if (TIZEN_FEATURE_BT_USB_DONGLE) {
447 ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN);
449 BT_ERR("Failed to call systemact service");
451 ret = __execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL);
454 BT_ERR("running script failed");
455 __bt_core_set_le_status(BT_LE_ACTIVATED);
459 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
462 __bt_core_set_le_status(BT_LE_DEACTIVATED);
468 int _bt_core_service_request_adapter(int service_function)
472 GArray *in_param1 = NULL;
473 GArray *in_param2 = NULL;
474 GArray *in_param3 = NULL;
475 GArray *in_param4 = NULL;
476 GArray *out_param = NULL;
478 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
480 ret = _bt_core_service_request(BT_CORE_SERVICE, service_function,
481 in_param1, in_param2, in_param3, in_param4, &out_param);
483 BT_ERR("_bt_core_service_request_adapter() failed");
485 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
490 static gboolean __bt_core_check_the_adapter_path(void)
493 GDBusProxy *manager_proxy = NULL;
494 GVariant *result = NULL;
495 char *adapter_path = NULL;
496 GDBusConnection *conn = NULL;
498 conn = _bt_core_get_gdbus_connection();
502 manager_proxy = g_dbus_proxy_new_sync(conn,
503 G_DBUS_PROXY_FLAGS_NONE, NULL,
506 "org.freedesktop.DBus.ObjectManager",
509 if (!manager_proxy) {
511 BT_ERR("Unable to create proxy: %s", err->message);
514 BT_ERR("Fail to create proxy");
519 result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
520 G_DBUS_CALL_FLAGS_NONE, 1000, NULL, &err);
523 BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
526 BT_ERR("Fail to get DefaultAdapter");
531 if (g_strcmp0(g_variant_get_type_string(result), "(o)")) {
532 BT_ERR("Incorrect result\n");
536 g_variant_get(result, "(&o)", &adapter_path);
538 if (adapter_path == NULL ||
539 strlen(adapter_path) >= BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX) {
540 BT_ERR("Adapter path is inproper\n");
544 g_variant_unref(result);
545 g_object_unref(manager_proxy);
551 g_variant_unref(result);
554 g_object_unref(manager_proxy);
559 void _bt_core_update_status(void)
561 int bt_status = VCONFKEY_BT_STATUS_OFF;
562 int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
563 gboolean ret = FALSE;
565 ret = __bt_core_check_the_adapter_path();
566 BT_INFO("check the real status of bt_adapter");
569 __bt_core_set_status(BT_DEACTIVATED);
570 __bt_core_set_le_status(BT_DEACTIVATED);
572 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
573 BT_ERR("no bluetooth device info, so BT was disabled at previous session");
574 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0)
575 BT_ERR("no bluetooth le info, so BT LE was disabled at previous session");
577 BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status);
579 if (bt_status & VCONFKEY_BT_STATUS_ON)
580 __bt_core_set_status(BT_ACTIVATED);
581 if (bt_le_status & VCONFKEY_BT_LE_STATUS_ON)
582 __bt_core_set_le_status(BT_ACTIVATED);
586 gboolean _bt_core_enable_adapter(void)
590 _bt_set_flightmode_request(FALSE);
591 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
592 BT_ERR("Set vconf failed");
594 ret = _bt_enable_adapter();
601 static gboolean __bt_core_terminate_cb(gpointer data)
603 _bt_core_terminate();
608 gboolean _bt_core_disable_adapter(void)
611 gboolean adapter_state;
613 _bt_set_flightmode_request(FALSE);
615 adapter_state = __bt_core_check_the_adapter_path();
616 if (adapter_state == FALSE)
617 BT_INFO("Default adapter is NOT normal.");
619 ret = _bt_disable_adapter();
620 if (adapter_state == FALSE) {
621 g_timeout_add(BT_CORE_IDLE_TERM_TIME,
622 __bt_core_terminate_cb, NULL);
632 gboolean _bt_core_recover_adapter(void)
636 BT_INFO_C("Recover bt adapter");
638 _bt_set_flightmode_request(FALSE);
639 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
640 BT_ERR("Set vconf failed");
642 is_recovery_mode = TRUE;
644 _bt_core_update_status();
646 if (_bt_core_get_status() == BT_ACTIVATED) {
647 _bt_core_set_bt_status(BT_RECOVERY_MODE, 1);
649 if (_bt_core_get_le_status() == BT_LE_ACTIVATED) {
650 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1);
653 ret = _bt_disable_adapter();
655 BT_ERR("_bt_disable_adapter() failed");
657 /* In platform, don't seperate BR/EDR and LE status
661 ret_le = _bt_disable_adapter_le();
663 BT_ERR("_bt_disable_adapter_le() failed");
669 gboolean _bt_core_enable_adapter_le(void)
673 ret = _bt_enable_adapter_le();
680 gboolean _bt_core_disable_adapter_le(void)
686 ret = _bt_disable_adapter_le();
693 gboolean __bt_core_reset_adapter(void)
695 /* Forcely terminate */
696 if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0)
697 BT_ERR("running script failed");
699 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
704 static gboolean __bt_core_enable_core_timeout_cb(gpointer data)
708 core_enable_timer_id = 0;
710 _bt_core_init_vconf_value();
715 gboolean _bt_core_enable_core(void)
719 _bt_core_update_status();
721 if (core_enable_timer_id > 0)
722 g_source_remove(core_enable_timer_id);
724 core_enable_timer_id = g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
730 gboolean _bt_core_set_transfer_value(gboolean value)
732 const char *event_val = NULL;
735 BT_DBG("value: %d", value);
737 event_val = value ? EVT_VAL_BT_TRANSFERING : EVT_VAL_BT_NON_TRANSFERING;
739 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_TRANSFERING_STATE,
740 event_val) != ES_R_OK) {
741 BT_ERR("Fail to set BT state value");
745 if (ret == FALSE || value == FALSE) {
746 BT_DBG("Terminate bt-core process");
747 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
754 gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
757 BT_DBG("Test item : %s", type);
759 if (g_strcmp0(type, "Enable_RF_Test") == 0) {
760 ret = __bt_call_systemact_service(BT_SYSTEMACT_EDUTM_ON);
762 BT_ERR("Failed to call systemact service");
763 } else if (g_strcmp0(type, "Disable_RF_Test") == 0) {
764 ret = __bt_call_systemact_service(BT_SYSTEMACT_EDUTM_OFF);
766 BT_ERR("Failed to call systemact service");
768 BT_DBG("Terminate bt-core process");
769 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
776 static gboolean __bt_core_recovery_cb(gpointer data)
779 gboolean is_request_failed = FALSE;
780 static gboolean is_first_failure = TRUE;
784 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
785 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
787 is_request_failed = TRUE;
790 if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
791 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
793 is_request_failed = TRUE;
796 if (is_request_failed == TRUE) {
797 BT_ERR("Recovery is failed.");
798 if (is_first_failure == TRUE) {
799 g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
800 is_first_failure = FALSE;
803 is_first_failure = TRUE;
807 is_first_failure = TRUE;
809 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
810 _bt_core_set_bt_status(BT_RECOVERY_MODE, 0);
811 ret = _bt_enable_adapter();
813 BT_ERR("_bt_enable_adapter() failed");
816 is_recovery_mode = FALSE;
823 static gboolean __bt_core_enable_timeout_cb(gpointer data)
825 bt_status_t adapter_status;
826 bt_le_status_t adapter_status_le;
830 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
831 BT_ERR("Set vconf failed");
833 adapter_status = _bt_core_get_status();
834 adapter_status_le = _bt_core_get_le_status();
836 if (adapter_status == BT_DEACTIVATED &&
837 _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
838 _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
839 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
840 _bt_enable_adapter();
843 if (adapter_status_le == BT_LE_DEACTIVATED &&
844 _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
845 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
846 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
847 _bt_enable_adapter_le();
853 static gboolean __bt_core_disable_timeout_cb(gpointer data)
855 bt_status_t adapter_status;
856 bt_le_status_t adapter_status_le;
860 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
861 BT_ERR("Set vconf failed");
863 adapter_status = _bt_core_get_status();
864 adapter_status_le = _bt_core_get_le_status();
866 if (adapter_status == BT_ACTIVATED) {
867 int bt_status_before_mode = 0;
869 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
870 _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
872 _bt_disable_adapter();
875 if (adapter_status_le == BT_LE_ACTIVATED) {
876 int bt_le_status_before_mode = 0;
878 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
879 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
881 _bt_disable_adapter_le();
887 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value)
894 bundle_add_str(b, key, value);
896 ret = eventsystem_send_system_event(event, b);
898 BT_DBG("eventsystem_send_system_event result: %d", ret);
905 void _bt_core_adapter_added_cb(void)
908 bt_le_status_t le_status;
909 gboolean flight_mode_status;
913 status = _bt_core_get_status();
914 BT_DBG("status : %d", status);
915 le_status = _bt_core_get_le_status();
916 BT_DBG("le_status : %d", le_status);
918 if (status == BT_ACTIVATING)
919 __bt_core_set_status(BT_ACTIVATED);
920 if (le_status == BT_LE_ACTIVATING)
921 __bt_core_set_le_status(BT_LE_ACTIVATED);
923 flight_mode_status = _bt_core_is_flight_mode_enabled();
925 if (flight_mode_status == TRUE && _bt_is_flightmode_request() == TRUE) {
926 _bt_set_flightmode_request(FALSE);
927 g_timeout_add(2000, (GSourceFunc)__bt_core_disable_timeout_cb, NULL);
930 _bt_set_flightmode_request(FALSE);
932 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
933 EVT_VAL_BT_ON) != ES_R_OK)
934 BT_ERR("Fail to set BT state value");
936 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
937 EVT_VAL_BT_LE_ON) != ES_R_OK)
938 BT_ERR("Fail to set BT LE state value");
940 _bt_core_terminate();
943 void _bt_core_adapter_removed_cb(void)
945 int flight_mode_value = 0;
946 int power_saving_mode = 0;
947 gboolean flight_mode_status;
948 static int timer_id = -1;
950 BT_DBG("is_recovery_mode: %d", is_recovery_mode);
952 __bt_core_set_status(BT_DEACTIVATED);
953 __bt_core_set_le_status(BT_LE_DEACTIVATED);
954 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
955 BT_ERR("Set vconf failed");
956 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
957 BT_ERR("Set vconf failed");
959 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
960 EVT_VAL_BT_OFF) != ES_R_OK)
961 BT_ERR("Fail to set value");
963 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
964 EVT_VAL_BT_LE_OFF) != ES_R_OK)
965 BT_ERR("Fail to set value");
967 if (is_recovery_mode == TRUE) {
969 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
973 if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value) != 0)
974 BT_ERR("Fail to get the flight_mode_deactivated value");
976 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &power_saving_mode) != 0)
977 BT_ERR("Fail to get the ps_mode_deactivated value");
979 flight_mode_status = _bt_core_is_flight_mode_enabled();
981 if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
982 _bt_set_flightmode_request(FALSE);
984 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_enable_timeout_cb, NULL);
987 _bt_set_flightmode_request(FALSE);
989 if (flight_mode_value == 1 || power_saving_mode == 1) {
990 BT_DBG("Bt Core not terminated");
994 _bt_core_terminate();