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 "bt-core-main.h"
25 #include "bt-core-adapter.h"
26 #include "bt-core-common.h"
27 #include "bt-core-dbus-handler.h"
28 #include "bt-core-noti-handler.h"
30 #define BT_CORE_IDLE_TERM_TIME 200 /* 200ms */
31 #define BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX 50
34 static bt_status_t adapter_status = BT_DEACTIVATED;
35 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
36 static gboolean is_recovery_mode = FALSE;
38 static int bt_status_before[BT_MODE_MAX] = { VCONFKEY_BT_STATUS_OFF, };
39 static int bt_le_status_before[BT_MODE_MAX] = { VCONFKEY_BT_LE_STATUS_OFF, };
41 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value);
43 static void __bt_core_set_status(bt_status_t status)
45 adapter_status = status;
48 bt_status_t _bt_core_get_status(void)
50 return adapter_status;
53 static void __bt_core_set_le_status(bt_le_status_t status)
55 adapter_le_status = status;
58 bt_le_status_t _bt_core_get_le_status(void)
60 return adapter_le_status;
63 int _bt_core_get_bt_status(bt_mode_e mode)
65 return bt_status_before[mode];
68 int _bt_core_get_bt_le_status(bt_mode_e mode)
70 return bt_le_status_before[mode];
73 void _bt_core_set_bt_status(bt_mode_e mode, int status)
75 bt_status_before[mode] = status;
78 void _bt_core_set_bt_le_status(bt_mode_e mode, int status)
80 bt_le_status_before[mode] = status;
83 gboolean _bt_core_is_recovery_mode(void)
85 return is_recovery_mode;
88 static gboolean __bt_core_idle_terminate(gpointer data)
95 gboolean _bt_core_is_flight_mode_enabled(void)
97 #ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
101 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode);
103 BT_ERR("vconf_get_bool failed");
111 static int __execute_command(const char *cmd, char *const arg_list[])
121 BT_ERR("fork failed");
127 BT_ERR("fork failed");
128 } else if (pid2 == 0) {
129 execv(cmd, arg_list);
136 BT_DBG("parent : forked[%d]", pid);
137 waitpid(pid, &status, 0);
138 BT_DBG("child is terminated : %d", status);
145 int _bt_enable_adapter(void)
150 bt_le_status_t le_status;
154 status = _bt_core_get_status();
155 if (status != BT_DEACTIVATED) {
156 BT_ERR("Invalid state %d", status);
157 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
161 #if 0 /* only the concept of private */
162 le_status = _bt_core_get_le_status();
163 if (le_status == BT_LE_ACTIVATED) {
164 /* Turn on PSCAN, (ISCAN if needed) */
165 /* Return with 0 for the Enabled response. */
166 __bt_core_set_status(BT_ACTIVATED);
167 BT_INFO("BR/EDR is enabled.");
168 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
173 __bt_core_set_status(BT_ACTIVATING);
175 char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
176 ret = __execute_command("/usr/bin/hciconfig", argv_up);
178 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
181 BT_ERR("running script failed");
183 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
184 ret = __execute_command("/usr/bin/hciconfig", argv_down);
186 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
188 __bt_core_set_status(BT_DEACTIVATED);
195 int _bt_disable_adapter(void)
199 bt_le_status_t le_status;
202 BT_INFO_C("Disable adapter");
204 #if 0 /* only the concept of private */
205 le_status = _bt_core_get_le_status();
206 BT_DBG("le_status : %d", le_status);
207 if (le_status == BT_LE_ACTIVATED) {
208 /* Turn off PSCAN, (ISCAN if needed) */
209 /* Return with 0 for the Disabled response. */
210 __bt_core_set_status(BT_DEACTIVATED);
211 BT_INFO("BR/EDR is disabled. now LE only mode");
212 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
217 status = _bt_core_get_status();
218 if (status == BT_ACTIVATING) {
219 /* Forcely terminate */
221 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
222 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0)
223 BT_ERR("running script failed");
226 #ifdef TIZEN_FEATURE_RADIO
227 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
229 /* Check if radio status on or off */
230 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
231 BT_ERR("Fail to get radio status");
233 BT_DBG("Radio status: %d", radio_status);
235 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
236 if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0)
237 BT_ERR("running script failed");
239 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
240 BT_ERR("running script failed");
243 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
244 BT_ERR("running script failed");
247 _bt_core_terminate();
249 } else if (status != BT_ACTIVATED) {
250 BT_ERR("Invalid state %d", status);
251 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
254 __bt_core_set_status(BT_DEACTIVATING);
256 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
257 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0) {
258 BT_ERR("running script failed");
259 __bt_core_set_status(BT_ACTIVATED);
263 #ifdef TIZEN_FEATURE_RADIO
264 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
266 /* Check if radio status on or off */
267 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
268 BT_ERR("Fail to get radio status");
270 BT_DBG("Radio status: %d", radio_status);
272 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
273 if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0) {
274 BT_ERR("running script failed");
275 __bt_core_set_status(BT_ACTIVATED);
279 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
280 BT_ERR("running script failed");
281 __bt_core_set_status(BT_ACTIVATED);
286 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
287 BT_ERR("running script failed");
288 __bt_core_set_status(BT_ACTIVATED);
297 int _bt_enable_adapter_le(void)
303 bt_le_status_t le_status;
304 le_status = _bt_core_get_le_status();
305 retv_if(le_status != BT_LE_DEACTIVATED, -1);
307 status = _bt_core_get_status();
308 if (status == BT_DEACTIVATED) {
309 __bt_core_set_le_status(BT_LE_ACTIVATING);
310 BT_DBG("Activate BT");
312 char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
313 ret = __execute_command("/usr/bin/hciconfig", argv_up);
315 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
318 BT_ERR("running script failed");
320 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
321 ret = __execute_command("/usr/bin/hciconfig", argv_down);
323 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
325 __bt_core_set_status(BT_DEACTIVATED);
326 __bt_core_set_le_status(BT_LE_DEACTIVATED);
330 __bt_core_set_le_status(BT_LE_ACTIVATED);
331 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
334 ret = _bt_core_start_httpproxy();
336 BT_ERR("_bt_core_start_httpproxy() failed");
343 int _bt_disable_adapter_le(void)
348 bt_le_status_t le_status;
350 le_status = _bt_core_get_le_status();
351 retv_if(le_status == BT_LE_DEACTIVATED, 0);
352 retv_if(le_status == BT_LE_DEACTIVATING, -1);
355 _bt_core_stop_httpproxy();
358 status = _bt_core_get_status();
359 BT_DBG("status : %d", status);
361 if (status == BT_DEACTIVATED) {
362 __bt_core_set_le_status(BT_LE_DEACTIVATING);
364 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
365 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0) {
367 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
369 BT_ERR("running script failed");
370 __bt_core_set_le_status(BT_LE_ACTIVATED);
374 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
377 __bt_core_set_le_status(BT_LE_DEACTIVATED);
383 int _bt_core_service_request_adapter(int service_function)
385 /* busact module is not in platform */
386 #ifndef TIZEN_FEATURE_BUSACT
387 return BLUETOOTH_ERROR_NONE;
391 GArray *in_param1 = NULL;
392 GArray *in_param2 = NULL;
393 GArray *in_param3 = NULL;
394 GArray *in_param4 = NULL;
395 GArray *out_param = NULL;
397 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
399 ret = _bt_core_service_request(BT_CORE_SERVICE, service_function,
400 in_param1, in_param2, in_param3, in_param4, &out_param);
402 BT_ERR("_bt_core_service_request_adapter() failed");
404 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
410 static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn)
413 GDBusProxy *manager_proxy = NULL;
414 GVariant *result = NULL;
415 char *adapter_path = NULL;
420 manager_proxy = g_dbus_proxy_new_sync(conn,
421 G_DBUS_PROXY_FLAGS_NONE, NULL,
424 "org.freedesktop.DBus.ObjectManager",
427 if (!manager_proxy) {
429 BT_ERR("Unable to create proxy: %s", err->message);
432 BT_ERR("Fail to create proxy");
437 result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
438 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
441 BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
444 BT_ERR("Fail to get DefaultAdapter");
449 if (g_strcmp0(g_variant_get_type_string(result), "(o)")) {
450 BT_ERR("Incorrect result\n");
454 g_variant_get(result, "(&o)", &adapter_path);
456 if (adapter_path == NULL ||
457 strlen(adapter_path) >= BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX) {
458 BT_ERR("Adapter path is inproper\n");
462 g_variant_unref(result);
463 g_object_unref(manager_proxy);
469 g_variant_unref(result);
472 g_object_unref(manager_proxy);
477 void _bt_core_update_status(void)
479 int bt_status = VCONFKEY_BT_STATUS_OFF;
480 int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
481 gboolean ret = FALSE;
483 ret = __bt_core_check_the_adapter_path(_bt_core_get_gdbus_connection());
484 BT_INFO("check the real status of bt_adapter");
487 __bt_core_set_status(BT_DEACTIVATED);
488 __bt_core_set_le_status(BT_DEACTIVATED);
490 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
491 BT_ERR("no bluetooth device info, so BT was disabled at previous session");
492 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0)
493 BT_ERR("no bluetooth le info, so BT LE was disabled at previous session");
495 BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status);
497 if (bt_status & VCONFKEY_BT_STATUS_ON)
498 __bt_core_set_status(BT_ACTIVATED);
499 if (bt_le_status & VCONFKEY_BT_LE_STATUS_ON)
500 __bt_core_set_le_status(BT_ACTIVATED);
504 gboolean _bt_core_enable_adapter(void)
508 _bt_set_flightmode_request(FALSE);
509 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
510 BT_ERR("Set vconf failed");
512 ret = _bt_enable_adapter();
519 gboolean _bt_core_disable_adapter(void)
523 _bt_set_flightmode_request(FALSE);
524 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
525 BT_ERR("Set vconf failed");
527 ret = _bt_disable_adapter();
534 gboolean _bt_core_recover_adapter(void)
537 #ifdef TIZEN_FEATURE_BUSACT
540 BT_INFO_C("Recover bt adapter");
542 _bt_set_flightmode_request(FALSE);
543 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
544 BT_ERR("Set vconf failed");
546 is_recovery_mode = TRUE;
548 _bt_core_update_status();
550 if (_bt_core_get_status() == BT_ACTIVATED) {
551 _bt_core_set_bt_status(BT_RECOVERY_MODE, 1);
552 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
554 if (_bt_core_get_le_status() == BT_LE_ACTIVATED) {
555 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1);
556 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
559 ret = _bt_disable_adapter();
561 BT_ERR("_bt_disable_adapter() failed");
563 /* In platform, don't seperate BR/EDR and LE status */
565 ret_le = _bt_disable_adapter_le();
567 BT_ERR("_bt_disable_adapter_le() failed");
572 gboolean _bt_core_enable_adapter_le(void)
576 ret = _bt_enable_adapter_le();
583 gboolean _bt_core_disable_adapter_le(void)
589 ret = _bt_disable_adapter_le();
596 gboolean __bt_core_reset_adapter(void)
598 /* Forcely terminate */
599 if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0) {
600 BT_ERR("running script failed");
602 _bt_core_terminate();
607 static gboolean __bt_core_enable_core_timeout_cb(gpointer data)
611 _bt_core_init_vconf_value();
616 gboolean _bt_core_enable_core(void)
620 _bt_core_update_status();
622 g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
628 gboolean _bt_core_set_transfer_value(gboolean value)
630 const char *event_val = NULL;
633 BT_DBG("value: %d", value);
635 event_val = value ? EVT_VAL_BT_TRANSFERING : EVT_VAL_BT_NON_TRANSFERING;
637 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_TRANSFERING_STATE,
638 event_val) != ES_R_OK) {
639 BT_ERR("Fail to set BT state value");
643 if (ret == FALSE || value == FALSE) {
644 BT_DBG("Terminate bt-core process");
645 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
652 gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
656 char *arg_list[3] = { NULL, NULL, NULL };
658 BT_DBG("Test item : %s", type);
660 if (g_strcmp0(type, "Enable_RF_Test") == 0) {
661 cmd = "/usr/etc/bluetooth/bt-edutm-on.sh";
662 arg_list[0] = "bt-edutm-on.sh";
663 } else if (g_strcmp0(type, "Disable_RF_Test") == 0) {
664 cmd = "/usr/etc/bluetooth/bt-edutm-off.sh";
665 arg_list[0] = "bt-edutm-off.sh";
666 } else if (g_strcmp0(type, "Slave_Mode") == 0) {
667 cmd = "/usr/etc/bluetooth/bt-mode-slave.sh";
668 arg_list[0] = "bt-mode-slave.sh";
669 } else if (g_strcmp0(type, "Master_Mode") == 0) {
670 cmd = "/usr/etc/bluetooth/bt-mode-master.sh";
671 arg_list[0] = "bt-mode-master.sh";
672 } else if (g_strcmp0(type, "SSP_Debug_Mode") == 0) {
673 cmd = "/usr/etc/bluetooth/bt-set-ssp-debug-mode.sh";
674 arg_list[0] = "bt-set-ssp-debug-mode.sh";
675 arg_list[1] = (char *)arg;
676 } else if (g_strcmp0(type, "RF_Channel") == 0) {
677 cmd = "/usr/etc/bluetooth/bt-enable-rf-channel.sh";
678 arg_list[0] = "bt-enable-rf-channel.sh";
679 arg_list[1] = (char *)arg;
681 _bt_core_terminate();
685 BT_DBG("Run %s", cmd);
686 if (__execute_command(cmd, arg_list) < 0) {
687 BT_ERR("running script failed");
690 _bt_core_terminate();
694 static gboolean __bt_core_recovery_cb(gpointer data)
697 #ifdef TIZEN_FEATURE_BUSACT
698 gboolean is_request_failed = FALSE;
699 static gboolean is_first_failure = TRUE;
704 #ifdef TIZEN_FEATURE_BUSACT
705 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
706 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
708 is_request_failed = TRUE;
711 if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
712 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
714 is_request_failed = TRUE;
717 if (is_request_failed == TRUE) {
718 BT_ERR("Recovery is failed.");
719 if (is_first_failure == TRUE) {
720 g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
721 is_first_failure = FALSE;
724 is_first_failure = TRUE;
728 is_first_failure = TRUE;
731 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
732 _bt_core_set_bt_status(BT_RECOVERY_MODE, 0);
733 ret = _bt_enable_adapter();
735 BT_ERR("_bt_enable_adapter() failed");
739 if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
740 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 0);
741 ret = _bt_enable_adapter_le();
743 BT_ERR("_bt_enable_adapter_le() failed");
746 is_recovery_mode = FALSE;
753 static gboolean __bt_core_enable_timeout_cb(gpointer data)
755 bt_status_t adapter_status;
756 bt_le_status_t adapter_status_le;
760 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
761 BT_ERR("Set vconf failed");
763 adapter_status = _bt_core_get_status();
764 adapter_status_le = _bt_core_get_le_status();
766 if (adapter_status == BT_DEACTIVATED &&
767 _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
768 _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
769 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
770 _bt_enable_adapter();
773 if (adapter_status_le == BT_LE_DEACTIVATED &&
774 _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
775 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
776 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
777 _bt_enable_adapter_le();
783 static gboolean __bt_core_disable_timeout_cb(gpointer data)
785 bt_status_t adapter_status;
786 bt_le_status_t adapter_status_le;
790 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
791 BT_ERR("Set vconf failed");
793 adapter_status = _bt_core_get_status();
794 adapter_status_le = _bt_core_get_le_status();
796 if (adapter_status == BT_ACTIVATED) {
797 int bt_status_before_mode = 0;
799 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
800 _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
802 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
803 _bt_disable_adapter();
806 if (adapter_status_le == BT_LE_ACTIVATED) {
807 int bt_le_status_before_mode = 0;
809 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
810 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
812 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
813 _bt_disable_adapter_le();
819 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value)
826 bundle_add_str(b, key, value);
828 ret = eventsystem_send_system_event(event, b);
830 BT_DBG("eventsystem_send_system_event result: %d", ret);
837 void _bt_core_adapter_added_cb(void)
840 bt_le_status_t le_status;
841 gboolean flight_mode_status;
845 status = _bt_core_get_status();
846 BT_DBG("status : %d", status);
847 le_status = _bt_core_get_le_status();
848 BT_DBG("le_status : %d", le_status);
850 if (status == BT_ACTIVATING)
851 __bt_core_set_status(BT_ACTIVATED);
852 if (le_status == BT_LE_ACTIVATING)
853 __bt_core_set_le_status(BT_LE_ACTIVATED);
855 flight_mode_status = _bt_core_is_flight_mode_enabled();
857 if (flight_mode_status == TRUE && _bt_is_flightmode_request() == TRUE) {
858 _bt_set_flightmode_request(FALSE);
859 g_timeout_add(2000, (GSourceFunc)__bt_core_disable_timeout_cb, NULL);
862 _bt_set_flightmode_request(FALSE);
864 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
865 EVT_VAL_BT_ON) != ES_R_OK)
866 BT_ERR("Fail to set BT state value");
868 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
869 EVT_VAL_BT_LE_ON) != ES_R_OK)
870 BT_ERR("Fail to set BT LE state value");
872 _bt_core_terminate();
875 void _bt_core_adapter_removed_cb(void)
877 int flight_mode_value = 0;
878 int power_saving_mode = 0;
879 gboolean flight_mode_status;
880 static int timer_id = -1;
882 BT_DBG("is_recovery_mode: %d", is_recovery_mode);
884 __bt_core_set_status(BT_DEACTIVATED);
885 __bt_core_set_le_status(BT_LE_DEACTIVATED);
886 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
887 BT_ERR("Set vconf failed");
888 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
889 BT_ERR("Set vconf failed");
891 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
892 EVT_VAL_BT_OFF) != ES_R_OK)
893 BT_ERR("Fail to set value");
895 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
896 EVT_VAL_BT_LE_OFF) != ES_R_OK)
897 BT_ERR("Fail to set value");
899 if (is_recovery_mode == TRUE) {
901 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
905 if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value) != 0)
906 BT_ERR("Fail to get the flight_mode_deactivated value");
908 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &power_saving_mode) != 0)
909 BT_ERR("Fail to get the ps_mode_deactivated value");
911 flight_mode_status = _bt_core_is_flight_mode_enabled();
913 if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
914 _bt_set_flightmode_request(FALSE);
916 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_enable_timeout_cb, NULL);
919 _bt_set_flightmode_request(FALSE);
921 if (flight_mode_value == 1 || power_saving_mode == 1) {
922 BT_DBG("Bt Core not terminated");
926 _bt_core_terminate();