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
33 #ifdef TIZEN_FEATURE_BT_OTP
34 #define BT_OTP_OBJECT_PATH "/org/projectx/otp"
35 #define BT_OTP_INTERFACE_NAME "org.projectx.otp_service"
36 #define BLE_DISABLED "LeDisabled"
39 static bt_status_t adapter_status = BT_DEACTIVATED;
40 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
41 static gboolean is_recovery_mode = FALSE;
42 static guint core_enable_timer_id;
45 static int bt_status_before[BT_MODE_MAX] = { VCONFKEY_BT_STATUS_OFF, };
46 static int bt_le_status_before[BT_MODE_MAX] = { VCONFKEY_BT_LE_STATUS_OFF, };
48 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value);
50 static void __bt_core_set_status(bt_status_t status)
52 adapter_status = status;
55 bt_status_t _bt_core_get_status(void)
57 return adapter_status;
60 static void __bt_core_set_le_status(bt_le_status_t status)
62 adapter_le_status = status;
65 bt_le_status_t _bt_core_get_le_status(void)
67 return adapter_le_status;
70 int _bt_core_get_bt_status(bt_mode_e mode)
72 return bt_status_before[mode];
75 int _bt_core_get_bt_le_status(bt_mode_e mode)
77 return bt_le_status_before[mode];
80 void _bt_core_set_bt_status(bt_mode_e mode, int status)
82 bt_status_before[mode] = status;
85 void _bt_core_set_bt_le_status(bt_mode_e mode, int status)
87 bt_le_status_before[mode] = status;
90 gboolean _bt_core_is_recovery_mode(void)
92 return is_recovery_mode;
95 static gboolean __bt_core_idle_terminate(gpointer data)
102 gboolean _bt_core_is_flight_mode_enabled(void)
104 int isFlightMode = 0;
107 if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
108 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode);
110 BT_ERR("vconf_get_bool failed");
118 static int __execute_command(const char *cmd, char *const arg_list[])
128 BT_ERR("fork failed");
134 BT_ERR("fork failed");
135 } else if (pid2 == 0) {
136 execv(cmd, arg_list);
143 BT_DBG("parent : forked[%d]", pid);
144 waitpid(pid, &status, 0);
145 BT_DBG("child is terminated : %d", status);
152 int _bt_enable_adapter(void)
157 bt_le_status_t le_status;
161 status = _bt_core_get_status();
162 if (status != BT_DEACTIVATED) {
163 BT_ERR("Invalid state %d", status);
164 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
168 #if 0 /* only the concept of private */
169 le_status = _bt_core_get_le_status();
170 if (le_status == BT_LE_ACTIVATED) {
171 /* Turn on PSCAN, (ISCAN if needed) */
172 /* Return with 0 for the Enabled response. */
173 __bt_core_set_status(BT_ACTIVATED);
174 BT_INFO("BR/EDR is enabled.");
175 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
180 __bt_core_set_status(BT_ACTIVATING);
181 if (TIZEN_FEATURE_BT_USB_DONGLE) {
182 char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
183 ret = __execute_command("/usr/bin/hciconfig", argv_up);
185 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
188 BT_ERR("running script failed");
189 if (TIZEN_FEATURE_BT_USB_DONGLE) {
190 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
191 ret = __execute_command("/usr/bin/hciconfig", argv_down);
193 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
195 __bt_core_set_status(BT_DEACTIVATED);
202 int _bt_disable_adapter(void)
206 bt_le_status_t le_status;
209 BT_INFO_C("Disable adapter");
211 #if 0 /* only the concept of private */
212 le_status = _bt_core_get_le_status();
213 BT_DBG("le_status : %d", le_status);
214 if (le_status == BT_LE_ACTIVATED) {
215 /* Turn off PSCAN, (ISCAN if needed) */
216 /* Return with 0 for the Disabled response. */
217 __bt_core_set_status(BT_DEACTIVATED);
218 BT_INFO("BR/EDR is disabled. now LE only mode");
219 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
224 status = _bt_core_get_status();
225 if (status == BT_ACTIVATING) {
226 /* Forcely terminate */
227 if (TIZEN_FEATURE_BT_USB_DONGLE) {
228 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
229 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0)
230 BT_ERR("running script failed");
233 #ifdef TIZEN_FEATURE_RADIO
234 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
236 /* Check if radio status on or off */
237 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
238 BT_ERR("Fail to get radio status");
240 BT_DBG("Radio status: %d", radio_status);
242 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
243 if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0)
244 BT_ERR("running script failed");
246 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
247 BT_ERR("running script failed");
250 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
251 BT_ERR("running script failed");
254 _bt_core_terminate();
256 } else if (status != BT_ACTIVATED) {
257 BT_ERR("Invalid state %d", status);
258 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
261 __bt_core_set_status(BT_DEACTIVATING);
262 if (TIZEN_FEATURE_BT_USB_DONGLE) {
263 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
264 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0) {
265 BT_ERR("running script failed");
266 __bt_core_set_status(BT_ACTIVATED);
270 #ifdef TIZEN_FEATURE_RADIO
271 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
273 /* Check if radio status on or off */
274 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
275 BT_ERR("Fail to get radio status");
277 BT_DBG("Radio status: %d", radio_status);
279 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
280 if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0) {
281 BT_ERR("running script failed");
282 __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);
293 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
294 BT_ERR("running script failed");
295 __bt_core_set_status(BT_ACTIVATED);
304 int _bt_enable_adapter_le(void)
310 bt_le_status_t le_status;
311 le_status = _bt_core_get_le_status();
312 retv_if(le_status != BT_LE_DEACTIVATED, -1);
314 status = _bt_core_get_status();
315 if (status == BT_DEACTIVATED) {
316 __bt_core_set_le_status(BT_LE_ACTIVATING);
317 BT_DBG("Activate BT");
318 if (TIZEN_FEATURE_BT_USB_DONGLE) {
319 char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
320 ret = __execute_command("/usr/bin/hciconfig", argv_up);
322 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
325 BT_ERR("running script failed");
326 if (TIZEN_FEATURE_BT_USB_DONGLE) {
327 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
328 ret = __execute_command("/usr/bin/hciconfig", argv_down);
330 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
332 __bt_core_set_status(BT_DEACTIVATED);
333 __bt_core_set_le_status(BT_LE_DEACTIVATED);
337 __bt_core_set_le_status(BT_LE_ACTIVATED);
338 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
340 #ifdef TIZEN_FEATURE_BT_HPS
341 ret = _bt_core_start_httpproxy();
343 BT_ERR("_bt_core_start_httpproxy() failed");
349 #ifdef TIZEN_FEATURE_BT_OTP
350 static void _bt_core_stop_otp()
352 GError *error = NULL;
353 GDBusMessage *msg = NULL;
354 GDBusConnection *conn = _bt_core_get_gdbus_connection();
355 msg = g_dbus_message_new_signal(BT_OTP_OBJECT_PATH, BT_OTP_INTERFACE_NAME, BLE_DISABLED);
356 if (!g_dbus_connection_send_message(conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL)) {
358 BT_ERR("Failed to send BLE_DISABLED signal to OTP : errCode[%x], \
360 error->code, error->message);
361 g_clear_error(&error);
367 int _bt_disable_adapter_le(void)
372 bt_le_status_t le_status;
374 le_status = _bt_core_get_le_status();
375 retv_if(le_status == BT_LE_DEACTIVATED, 0);
376 retv_if(le_status == BT_LE_DEACTIVATING, -1);
378 #ifdef TIZEN_FEATURE_BT_HPS
379 _bt_core_stop_httpproxy();
382 #ifdef TIZEN_FEATURE_BT_OTP
386 status = _bt_core_get_status();
387 BT_DBG("status : %d", status);
389 if (status == BT_DEACTIVATED) {
390 __bt_core_set_le_status(BT_LE_DEACTIVATING);
392 if (TIZEN_FEATURE_BT_USB_DONGLE) {
393 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
394 ret = __execute_command("/usr/bin/hciconfig", argv_down);
396 ret = __execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL);
399 BT_ERR("running script failed");
400 __bt_core_set_le_status(BT_LE_ACTIVATED);
404 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
407 __bt_core_set_le_status(BT_LE_DEACTIVATED);
413 int _bt_core_service_request_adapter(int service_function)
417 GArray *in_param1 = NULL;
418 GArray *in_param2 = NULL;
419 GArray *in_param3 = NULL;
420 GArray *in_param4 = NULL;
421 GArray *out_param = NULL;
423 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
425 ret = _bt_core_service_request(BT_CORE_SERVICE, service_function,
426 in_param1, in_param2, in_param3, in_param4, &out_param);
428 BT_ERR("_bt_core_service_request_adapter() failed");
430 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
435 static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn)
438 GDBusProxy *manager_proxy = NULL;
439 GVariant *result = NULL;
440 char *adapter_path = NULL;
445 manager_proxy = g_dbus_proxy_new_sync(conn,
446 G_DBUS_PROXY_FLAGS_NONE, NULL,
449 "org.freedesktop.DBus.ObjectManager",
452 if (!manager_proxy) {
454 BT_ERR("Unable to create proxy: %s", err->message);
457 BT_ERR("Fail to create proxy");
462 result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
463 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
466 BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
469 BT_ERR("Fail to get DefaultAdapter");
474 if (g_strcmp0(g_variant_get_type_string(result), "(o)")) {
475 BT_ERR("Incorrect result\n");
479 g_variant_get(result, "(&o)", &adapter_path);
481 if (adapter_path == NULL ||
482 strlen(adapter_path) >= BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX) {
483 BT_ERR("Adapter path is inproper\n");
487 g_variant_unref(result);
488 g_object_unref(manager_proxy);
494 g_variant_unref(result);
497 g_object_unref(manager_proxy);
502 void _bt_core_update_status(void)
504 int bt_status = VCONFKEY_BT_STATUS_OFF;
505 int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
506 gboolean ret = FALSE;
508 ret = __bt_core_check_the_adapter_path(_bt_core_get_gdbus_connection());
509 BT_INFO("check the real status of bt_adapter");
512 __bt_core_set_status(BT_DEACTIVATED);
513 __bt_core_set_le_status(BT_DEACTIVATED);
515 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
516 BT_ERR("no bluetooth device info, so BT was disabled at previous session");
517 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0)
518 BT_ERR("no bluetooth le info, so BT LE was disabled at previous session");
520 BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status);
522 if (bt_status & VCONFKEY_BT_STATUS_ON)
523 __bt_core_set_status(BT_ACTIVATED);
524 if (bt_le_status & VCONFKEY_BT_LE_STATUS_ON)
525 __bt_core_set_le_status(BT_ACTIVATED);
529 gboolean _bt_core_enable_adapter(void)
533 _bt_set_flightmode_request(FALSE);
534 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
535 BT_ERR("Set vconf failed");
537 ret = _bt_enable_adapter();
544 gboolean _bt_core_disable_adapter(void)
548 _bt_set_flightmode_request(FALSE);
549 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
550 BT_ERR("Set vconf failed");
552 ret = _bt_disable_adapter();
559 gboolean _bt_core_recover_adapter(void)
565 BT_INFO_C("Recover bt adapter");
567 _bt_set_flightmode_request(FALSE);
568 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
569 BT_ERR("Set vconf failed");
571 is_recovery_mode = TRUE;
573 _bt_core_update_status();
575 if (_bt_core_get_status() == BT_ACTIVATED) {
576 _bt_core_set_bt_status(BT_RECOVERY_MODE, 1);
577 #ifdef TIZEN_FEATURE_BUSACT
578 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
581 if (_bt_core_get_le_status() == BT_LE_ACTIVATED) {
582 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1);
583 #ifdef TIZEN_FEATURE_BUSACT
584 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
588 ret = _bt_disable_adapter();
590 BT_ERR("_bt_disable_adapter() failed");
592 /* In platform, don't seperate BR/EDR and LE status */
594 ret_le = _bt_disable_adapter_le();
596 BT_ERR("_bt_disable_adapter_le() failed");
601 gboolean _bt_core_enable_adapter_le(void)
605 ret = _bt_enable_adapter_le();
612 gboolean _bt_core_disable_adapter_le(void)
618 ret = _bt_disable_adapter_le();
625 gboolean __bt_core_reset_adapter(void)
627 /* Forcely terminate */
628 if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0)
629 BT_ERR("running script failed");
631 _bt_core_terminate();
636 static gboolean __bt_core_enable_core_timeout_cb(gpointer data)
640 core_enable_timer_id = 0;
642 _bt_core_init_vconf_value();
647 gboolean _bt_core_enable_core(void)
651 _bt_core_update_status();
653 if (core_enable_timer_id > 0)
654 g_source_remove(core_enable_timer_id);
656 core_enable_timer_id = g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
662 gboolean _bt_core_set_transfer_value(gboolean value)
664 const char *event_val = NULL;
667 BT_DBG("value: %d", value);
669 event_val = value ? EVT_VAL_BT_TRANSFERING : EVT_VAL_BT_NON_TRANSFERING;
671 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_TRANSFERING_STATE,
672 event_val) != ES_R_OK) {
673 BT_ERR("Fail to set BT state value");
677 if (ret == FALSE || value == FALSE) {
678 BT_DBG("Terminate bt-core process");
679 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
686 gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
690 char *arg_list[3] = { NULL, NULL, NULL };
692 BT_DBG("Test item : %s", type);
694 if (g_strcmp0(type, "Enable_RF_Test") == 0) {
695 cmd = "/usr/etc/bluetooth/bt-edutm-on.sh";
696 arg_list[0] = "bt-edutm-on.sh";
697 } else if (g_strcmp0(type, "Disable_RF_Test") == 0) {
698 cmd = "/usr/etc/bluetooth/bt-edutm-off.sh";
699 arg_list[0] = "bt-edutm-off.sh";
700 } else if (g_strcmp0(type, "Slave_Mode") == 0) {
701 cmd = "/usr/etc/bluetooth/bt-mode-slave.sh";
702 arg_list[0] = "bt-mode-slave.sh";
703 } else if (g_strcmp0(type, "Master_Mode") == 0) {
704 cmd = "/usr/etc/bluetooth/bt-mode-master.sh";
705 arg_list[0] = "bt-mode-master.sh";
706 } else if (g_strcmp0(type, "SSP_Debug_Mode") == 0) {
707 cmd = "/usr/etc/bluetooth/bt-set-ssp-debug-mode.sh";
708 arg_list[0] = "bt-set-ssp-debug-mode.sh";
709 arg_list[1] = (char *)arg;
710 } else if (g_strcmp0(type, "RF_Channel") == 0) {
711 cmd = "/usr/etc/bluetooth/bt-enable-rf-channel.sh";
712 arg_list[0] = "bt-enable-rf-channel.sh";
713 arg_list[1] = (char *)arg;
715 _bt_core_terminate();
719 BT_DBG("Run %s", cmd);
720 if (__execute_command(cmd, arg_list) < 0)
721 BT_ERR("running script failed");
723 _bt_core_terminate();
727 static gboolean __bt_core_recovery_cb(gpointer data)
730 #ifdef TIZEN_FEATURE_BUSACT
731 gboolean is_request_failed = FALSE;
732 static gboolean is_first_failure = TRUE;
737 #ifdef TIZEN_FEATURE_BUSACT
738 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
739 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
741 is_request_failed = TRUE;
744 if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
745 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
747 is_request_failed = TRUE;
750 if (is_request_failed == TRUE) {
751 BT_ERR("Recovery is failed.");
752 if (is_first_failure == TRUE) {
753 g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
754 is_first_failure = FALSE;
757 is_first_failure = TRUE;
761 is_first_failure = TRUE;
764 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
765 _bt_core_set_bt_status(BT_RECOVERY_MODE, 0);
766 ret = _bt_enable_adapter();
768 BT_ERR("_bt_enable_adapter() failed");
772 if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
773 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 0);
774 ret = _bt_enable_adapter_le();
776 BT_ERR("_bt_enable_adapter_le() failed");
779 is_recovery_mode = FALSE;
786 static gboolean __bt_core_enable_timeout_cb(gpointer data)
788 bt_status_t adapter_status;
789 bt_le_status_t adapter_status_le;
793 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
794 BT_ERR("Set vconf failed");
796 adapter_status = _bt_core_get_status();
797 adapter_status_le = _bt_core_get_le_status();
799 if (adapter_status == BT_DEACTIVATED &&
800 _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
801 _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
802 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
803 _bt_enable_adapter();
806 if (adapter_status_le == BT_LE_DEACTIVATED &&
807 _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
808 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
809 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
810 _bt_enable_adapter_le();
816 static gboolean __bt_core_disable_timeout_cb(gpointer data)
818 bt_status_t adapter_status;
819 bt_le_status_t adapter_status_le;
823 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
824 BT_ERR("Set vconf failed");
826 adapter_status = _bt_core_get_status();
827 adapter_status_le = _bt_core_get_le_status();
829 if (adapter_status == BT_ACTIVATED) {
830 int bt_status_before_mode = 0;
832 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
833 _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
835 #ifdef TIZEN_FEATURE_BUSACT
836 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
838 _bt_disable_adapter();
841 if (adapter_status_le == BT_LE_ACTIVATED) {
842 int bt_le_status_before_mode = 0;
844 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
845 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
847 #ifdef TIZEN_FEATURE_BUSACT
848 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
850 _bt_disable_adapter_le();
856 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value)
863 bundle_add_str(b, key, value);
865 ret = eventsystem_send_system_event(event, b);
867 BT_DBG("eventsystem_send_system_event result: %d", ret);
874 void _bt_core_adapter_added_cb(void)
877 bt_le_status_t le_status;
878 gboolean flight_mode_status;
882 status = _bt_core_get_status();
883 BT_DBG("status : %d", status);
884 le_status = _bt_core_get_le_status();
885 BT_DBG("le_status : %d", le_status);
887 if (status == BT_ACTIVATING)
888 __bt_core_set_status(BT_ACTIVATED);
889 if (le_status == BT_LE_ACTIVATING)
890 __bt_core_set_le_status(BT_LE_ACTIVATED);
892 flight_mode_status = _bt_core_is_flight_mode_enabled();
894 if (flight_mode_status == TRUE && _bt_is_flightmode_request() == TRUE) {
895 _bt_set_flightmode_request(FALSE);
896 g_timeout_add(2000, (GSourceFunc)__bt_core_disable_timeout_cb, NULL);
899 _bt_set_flightmode_request(FALSE);
901 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
902 EVT_VAL_BT_ON) != ES_R_OK)
903 BT_ERR("Fail to set BT state value");
905 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
906 EVT_VAL_BT_LE_ON) != ES_R_OK)
907 BT_ERR("Fail to set BT LE state value");
909 _bt_core_terminate();
912 void _bt_core_adapter_removed_cb(void)
914 int flight_mode_value = 0;
915 int power_saving_mode = 0;
916 gboolean flight_mode_status;
917 static int timer_id = -1;
919 BT_DBG("is_recovery_mode: %d", is_recovery_mode);
921 __bt_core_set_status(BT_DEACTIVATED);
922 __bt_core_set_le_status(BT_LE_DEACTIVATED);
923 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
924 BT_ERR("Set vconf failed");
925 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
926 BT_ERR("Set vconf failed");
928 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
929 EVT_VAL_BT_OFF) != ES_R_OK)
930 BT_ERR("Fail to set value");
932 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
933 EVT_VAL_BT_LE_OFF) != ES_R_OK)
934 BT_ERR("Fail to set value");
936 if (is_recovery_mode == TRUE) {
938 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
942 if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value) != 0)
943 BT_ERR("Fail to get the flight_mode_deactivated value");
945 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &power_saving_mode) != 0)
946 BT_ERR("Fail to get the ps_mode_deactivated value");
948 flight_mode_status = _bt_core_is_flight_mode_enabled();
950 if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
951 _bt_set_flightmode_request(FALSE);
953 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_enable_timeout_cb, NULL);
956 _bt_set_flightmode_request(FALSE);
958 if (flight_mode_value == 1 || power_saving_mode == 1) {
959 BT_DBG("Bt Core not terminated");
963 _bt_core_terminate();