Fix LE discovery state miss-matching issue
[platform/core/connectivity/bluetooth-frwk.git] / bt-core / bt-core-adapter.c
index 5a82fe5..7a79afc 100644 (file)
@@ -20,6 +20,8 @@
 #include <vconf-internal-radio-keys.h>
 #include <bundle.h>
 #include <eventsystem.h>
+#include <stdio.h>
+#include <actd/unit_control.h>
 
 #include "bt-core-main.h"
 #include "bt-core-adapter.h"
 #include "bt-core-dbus-handler.h"
 #include "bt-core-noti-handler.h"
 
+#include "bt-internal-types.h"
+
 #define BT_CORE_IDLE_TERM_TIME 200 /* 200ms */
 #define BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX 50
 
+#ifdef TIZEN_FEATURE_BT_OTP
+#define BT_OTP_OBJECT_PATH     "/org/projectx/otp"
+#define BT_OTP_INTERFACE_NAME  "org.projectx.otp_service"
+#define BLE_DISABLED           "LeDisabled"
+#endif
 
 static bt_status_t adapter_status = BT_DEACTIVATED;
 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
 static gboolean is_recovery_mode = FALSE;
+static guint core_enable_timer_id;
+
 
 static int bt_status_before[BT_MODE_MAX] = { VCONFKEY_BT_STATUS_OFF, };
 static int bt_le_status_before[BT_MODE_MAX] = { VCONFKEY_BT_LE_STATUS_OFF, };
@@ -94,18 +105,35 @@ static gboolean __bt_core_idle_terminate(gpointer data)
 
 gboolean _bt_core_is_flight_mode_enabled(void)
 {
-#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
        int isFlightMode = 0;
        int ret = -1;
 
-       ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode);
-       if (ret != 0) {
-               BT_ERR("vconf_get_bool failed");
+       if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
+               ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode);
+               if (ret != 0)
+                       BT_ERR("vconf_get_bool failed");
+
+               return isFlightMode;
+       } else {
+               return FALSE;
        }
-       return isFlightMode;
-#else
-       return FALSE;
-#endif
+}
+
+static int __bt_call_systemact_service(const char *service_name)
+{
+       int ret;
+
+       BT_DBG("Use System Activated : %s", service_name);
+
+       ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM, service_name, 5000);
+
+       if (ret != UNIT_CONTROL_OK) {
+               BT_ERR("Failed to activate the %s: %d", service_name, ret);
+               /* Return Success even if the activating result is fail */
+               return 0;
+       }
+
+       return 0;
 }
 
 static int __execute_command(const char *cmd, char *const arg_list[])
@@ -126,7 +154,12 @@ static int __execute_command(const char *cmd, char *const arg_list[])
                if (pid2 == -1) {
                        BT_ERR("fork failed");
                } else if (pid2 == 0) {
-                       execv(cmd, arg_list);
+                       if (arg_list != NULL) {
+                               execv(cmd, arg_list);
+                       } else {
+                               char *argv[] = { NULL };
+                               execv(cmd, argv);
+                       }
                        exit(256);
                }
                exit(0);
@@ -142,13 +175,41 @@ static int __execute_command(const char *cmd, char *const arg_list[])
        return 0;
 }
 
+static int __bt_stack_up(void)
+{
+       int ret;
+
+       /* activate HCI logger */
+       ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_LOGGER_START);
+       if (ret < 0) {
+               BT_ERR("Failed to call systemact service");
+               return -1;
+       }
+
+       /* activate Bluez */
+       ret = __bt_call_systemact_service(BT_SYSTEMACT_BLUEZ_START);
+       if (ret < 0) {
+               BT_ERR("Failed to call systemact service");
+               return -1;
+       }
+
+       /* activate bluetooth-share */
+       if (!TIZEN_PROFILE_WEARABLE) {
+               ret = __bt_call_systemact_service(BT_SYSTEMACT_BLUETOOTH_SHARE_START);
+               if (ret < 0) {
+                       BT_ERR("Failed to call systemact service");
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
 int _bt_enable_adapter(void)
 {
        int ret;
        bt_status_t status;
-#if 0
-       bt_le_status_t le_status;
-#endif
+
        BT_INFO("");
 
        status = _bt_core_get_status();
@@ -158,33 +219,44 @@ int _bt_enable_adapter(void)
                return -1;
        }
 
-#if 0 /* only the concept of private */
+/* only the concept of private
+#if 0
+       bt_le_status_t le_status;
+
        le_status = _bt_core_get_le_status();
        if (le_status == BT_LE_ACTIVATED) {
-               /* Turn on PSCAN, (ISCAN if needed) */
-               /* Return with 0 for the Enabled response. */
+               // Turn on PSCAN, (ISCAN if needed)
+               // Return with 0 for the Enabled response.
                __bt_core_set_status(BT_ACTIVATED);
                BT_INFO("BR/EDR is enabled.");
                g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
                return 0;
        }
 #endif
+*/
 
        __bt_core_set_status(BT_ACTIVATING);
-#ifdef USB_BLUETOOTH
-       char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
-       ret = __execute_command("/usr/bin/hciconfig", argv_up);
-#else
-       ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
-#endif
+       if (TIZEN_FEATURE_BT_USB_DONGLE) {
+               /* activate Bluez */
+               ret = __bt_call_systemact_service(BT_SYSTEMACT_BLUEZ_START);
+               if (ret < 0)
+                       BT_ERR("If bluez already exist, skip this error");
+
+               ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_UP);
+               if (ret < 0)
+                       BT_ERR("Failed to call systemact service");
+       } else {
+               ret = __bt_stack_up();
+       }
        if (ret < 0) {
                BT_ERR("running script failed");
-#ifdef USB_BLUETOOTH
-               char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
-               ret = __execute_command("/usr/bin/hciconfig", argv_down);
-#else
-               ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
-#endif
+               if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                       ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN);
+                       if (ret < 0)
+                               BT_ERR("Failed to call systemact service");
+               } else {
+                       ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
+               }
                __bt_core_set_status(BT_DEACTIVATED);
                return -1;
        }
@@ -195,55 +267,49 @@ int _bt_enable_adapter(void)
 int _bt_disable_adapter(void)
 {
        bt_status_t status;
-#if 0
-       bt_le_status_t le_status;
-#endif
 
        BT_INFO_C("Disable adapter");
 
-#if 0 /* only the concept of private */
+/* only the concept of private
+#if 0
+       bt_le_status_t le_status;
+
        le_status = _bt_core_get_le_status();
        BT_DBG("le_status : %d", le_status);
        if (le_status == BT_LE_ACTIVATED) {
-               /* Turn off PSCAN, (ISCAN if needed) */
-               /* Return with 0 for the Disabled response. */
+               // Turn off PSCAN, (ISCAN if needed)
+               // Return with 0 for the Disabled response.
                __bt_core_set_status(BT_DEACTIVATED);
                BT_INFO("BR/EDR is disabled. now LE only mode");
                g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
                return 0;
        }
 #endif
+*/
 
        status = _bt_core_get_status();
        if (status == BT_ACTIVATING) {
                /* Forcely terminate */
-#ifdef USB_BLUETOOTH
-               char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
-               if (__execute_command("/usr/bin/hciconfig", argv_down) < 0)
-                       BT_ERR("running script failed");
-#else
-
-#ifdef TIZEN_FEATURE_RADIO
-               int radio_status = VCONFKEY_RADIO_STATUS_OFF;
+               if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                       if (__bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN) < 0)
+                               BT_ERR("Failed to call systemact service");
+               } else {
+                       int radio_status = VCONFKEY_RADIO_STATUS_OFF;
 
-               /* Check if radio status on or off */
-               if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
-                       BT_ERR("Fail to get radio status");
+                       /* Check if radio status on or off */
+                       if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
+                               BT_ERR("Fail to get radio status");
 
-               BT_DBG("Radio status: %d", radio_status);
+                       BT_DBG("Radio status: %d", radio_status);
 
-               if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
-                       if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0)
-                               BT_ERR("running script failed");
-               } else {
-                       if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
-                               BT_ERR("running script failed");
+                       if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
+                               if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN_WITH_RADIO) < 0)
+                                       BT_ERR("running script failed");
+                       } else {
+                               if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN) < 0)
+                                       BT_ERR("running script failed");
+                       }
                }
-#else
-               if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
-                       BT_ERR("running script failed");
-#endif
-#endif
                _bt_core_terminate();
                return 0;
        } else if (status != BT_ACTIVATED) {
@@ -252,44 +318,36 @@ int _bt_disable_adapter(void)
        }
 
        __bt_core_set_status(BT_DEACTIVATING);
-#ifdef USB_BLUETOOTH
-       char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
-       if (__execute_command("/usr/bin/hciconfig", argv_down) < 0) {
-               BT_ERR("running script failed");
-               __bt_core_set_status(BT_ACTIVATED);
-               return -1;
-       }
-#else
-#ifdef TIZEN_FEATURE_RADIO
-       int radio_status = VCONFKEY_RADIO_STATUS_OFF;
-
-       /* Check if radio status on or off */
-       if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
-               BT_ERR("Fail to get radio status");
-
-       BT_DBG("Radio status: %d", radio_status);
-
-       if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
-               if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0) {
-                       BT_ERR("running script failed");
+       if (TIZEN_FEATURE_BT_USB_DONGLE) {
+               if (__bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN) < 0) {
+                       BT_ERR("Failed to call systemact service");
                        __bt_core_set_status(BT_ACTIVATED);
                        return -1;
                }
+               g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
        } else {
-               if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
-                       BT_ERR("running script failed");
-                       __bt_core_set_status(BT_ACTIVATED);
-                       return -1;
+               int radio_status = VCONFKEY_RADIO_STATUS_OFF;
+
+               /* Check if radio status on or off */
+               if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
+                       BT_ERR("Fail to get radio status");
+
+               BT_DBG("Radio status: %d", radio_status);
+
+               if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
+                       if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN_WITH_RADIO) < 0) {
+                               BT_ERR("running script failed");
+                               __bt_core_set_status(BT_ACTIVATED);
+                               return -1;
+                       }
+               } else {
+                       if (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN) < 0) {
+                               BT_ERR("running script failed");
+                               __bt_core_set_status(BT_ACTIVATED);
+                               return -1;
+                       }
                }
        }
-#else
-       if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
-                       BT_ERR("running script failed");
-                       __bt_core_set_status(BT_ACTIVATED);
-                       return -1;
-       }
-#endif
-#endif
 
        return 0;
 }
@@ -302,26 +360,29 @@ int _bt_enable_adapter_le(void)
        bt_status_t status;
        bt_le_status_t le_status;
        le_status = _bt_core_get_le_status();
+       retv_if(le_status == BT_LE_ACTIVATED, 0);
        retv_if(le_status != BT_LE_DEACTIVATED, -1);
 
        status = _bt_core_get_status();
        if (status == BT_DEACTIVATED) {
                __bt_core_set_le_status(BT_LE_ACTIVATING);
                BT_DBG("Activate BT");
-#ifdef USB_BLUETOOTH
-               char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
-               ret = __execute_command("/usr/bin/hciconfig", argv_up);
-#else
-               ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
-#endif
+               if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                       ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_UP);
+                       if (ret < 0)
+                               BT_ERR("Failed to call systemact service");
+               } else {
+                       ret = __bt_stack_up();
+               }
                if (ret < 0) {
                        BT_ERR("running script failed");
-#ifdef USB_BLUETOOTH
-                       char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
-                       ret = __execute_command("/usr/bin/hciconfig", argv_down);
-#else
-                       ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
-#endif
+                       if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                               ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN);
+                               if (ret < 0)
+                                       BT_ERR("Failed to call systemact service");
+                       } else {
+                               ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
+                       }
                        __bt_core_set_status(BT_DEACTIVATED);
                        __bt_core_set_le_status(BT_LE_DEACTIVATED);
                        return -1;
@@ -330,16 +391,33 @@ int _bt_enable_adapter_le(void)
                __bt_core_set_le_status(BT_LE_ACTIVATED);
                g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
        }
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
        ret = _bt_core_start_httpproxy();
-       if (ret < 0) {
+       if (ret < 0)
                BT_ERR("_bt_core_start_httpproxy() failed");
-       }
 #endif
 
        return 0;
 }
 
+#ifdef TIZEN_FEATURE_BT_OTP
+static void _bt_core_stop_otp()
+{
+       GError *error = NULL;
+       GDBusMessage *msg = NULL;
+       GDBusConnection *conn = _bt_core_get_gdbus_connection();
+       msg = g_dbus_message_new_signal(BT_OTP_OBJECT_PATH, BT_OTP_INTERFACE_NAME, BLE_DISABLED);
+       if (!g_dbus_connection_send_message(conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL)) {
+               if (error != NULL) {
+                       BT_ERR("Failed to send BLE_DISABLED signal to OTP : errCode[%x], \
+                                       message[%s]",
+                                       error->code, error->message);
+                       g_clear_error(&error);
+               }
+       }
+}
+#endif
+
 int _bt_disable_adapter_le(void)
 {
        BT_DBG("+");
@@ -351,21 +429,28 @@ int _bt_disable_adapter_le(void)
        retv_if(le_status == BT_LE_DEACTIVATED, 0);
        retv_if(le_status == BT_LE_DEACTIVATING, -1);
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
        _bt_core_stop_httpproxy();
 #endif
 
+#ifdef TIZEN_FEATURE_BT_OTP
+       _bt_core_stop_otp();
+#endif
+
        status = _bt_core_get_status();
        BT_DBG("status : %d", status);
 
        if (status == BT_DEACTIVATED) {
                __bt_core_set_le_status(BT_LE_DEACTIVATING);
-#ifdef USB_BLUETOOTH
-               char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
-               if (__execute_command("/usr/bin/hciconfig", argv_down) < 0) {
-#else
-               if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
-#endif
+               int ret;
+               if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                       ret = __bt_call_systemact_service(BT_SYSTEMACT_HCI_DOWN);
+                       if (ret < 0)
+                               BT_ERR("Failed to call systemact service");
+               } else {
+                       ret = __execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL);
+               }
+               if (ret < 0) {
                        BT_ERR("running script failed");
                        __bt_core_set_le_status(BT_LE_ACTIVATED);
                        return -1;
@@ -402,13 +487,15 @@ int _bt_core_service_request_adapter(int service_function)
        return ret;
 }
 
-static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn)
+static gboolean __bt_core_check_the_adapter_path(void)
 {
        GError *err = NULL;
        GDBusProxy *manager_proxy = NULL;
        GVariant *result = NULL;
        char *adapter_path = NULL;
+       GDBusConnection *conn = NULL;
 
+       conn = _bt_core_get_gdbus_connection();
        if (conn == NULL)
                return FALSE;
 
@@ -430,7 +517,7 @@ static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn)
        }
 
        result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
-                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+                       G_DBUS_CALL_FLAGS_NONE, 1000, NULL, &err);
        if (!result) {
                if (err != NULL) {
                        BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
@@ -475,7 +562,7 @@ void _bt_core_update_status(void)
        int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
        gboolean ret = FALSE;
 
-       ret = __bt_core_check_the_adapter_path(_bt_core_get_gdbus_connection());
+       ret = __bt_core_check_the_adapter_path();
        BT_INFO("check the real status of bt_adapter");
 
        if (ret != TRUE) {
@@ -511,25 +598,40 @@ gboolean _bt_core_enable_adapter(void)
                return TRUE;
 }
 
+static gboolean __bt_core_terminate_cb(gpointer data)
+{
+       _bt_core_terminate();
+
+       return FALSE;
+}
+
 gboolean _bt_core_disable_adapter(void)
 {
        int ret;
+       gboolean adapter_state;
 
        _bt_set_flightmode_request(FALSE);
-       if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
-               BT_ERR("Set vconf failed");
+
+       adapter_state = __bt_core_check_the_adapter_path();
+       if (adapter_state == FALSE)
+               BT_INFO("Default adapter is NOT normal.");
 
        ret = _bt_disable_adapter();
-       if (ret < 0)
-               return FALSE;
-       else
+       if (adapter_state == FALSE) {
+               g_timeout_add(BT_CORE_IDLE_TERM_TIME,
+                             __bt_core_terminate_cb, NULL);
                return TRUE;
+       } else {
+               if (ret < 0)
+                       return FALSE;
+               else
+                       return TRUE;
+       }
 }
 
 gboolean _bt_core_recover_adapter(void)
 {
        int ret;
-       int ret_le;
 
        BT_INFO_C("Recover bt adapter");
 
@@ -543,20 +645,24 @@ gboolean _bt_core_recover_adapter(void)
 
        if (_bt_core_get_status() == BT_ACTIVATED) {
                _bt_core_set_bt_status(BT_RECOVERY_MODE, 1);
-               _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
        }
        if (_bt_core_get_le_status() == BT_LE_ACTIVATED) {
                _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1);
-               _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
        }
 
        ret = _bt_disable_adapter();
        if (ret < 0)
                BT_ERR("_bt_disable_adapter() failed");
+
+/* In platform, don't seperate BR/EDR and LE status
+#if 0
+       int ret_le;
+
        ret_le = _bt_disable_adapter_le();
        if (ret_le < 0)
                BT_ERR("_bt_disable_adapter_le() failed");
-
+#endif
+*/
        return TRUE;
 }
 
@@ -587,10 +693,10 @@ gboolean _bt_core_disable_adapter_le(void)
 gboolean __bt_core_reset_adapter(void)
 {
        /* Forcely terminate */
-       if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0) {
+       if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0)
                BT_ERR("running script failed");
-       }
-       _bt_core_terminate();
+
+       g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
 
        return TRUE;
 }
@@ -599,6 +705,8 @@ static gboolean __bt_core_enable_core_timeout_cb(gpointer data)
 {
        BT_DBG("+");
 
+       core_enable_timer_id = 0;
+
        _bt_core_init_vconf_value();
 
        return FALSE;
@@ -610,7 +718,10 @@ gboolean _bt_core_enable_core(void)
 
        _bt_core_update_status();
 
-       g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
+       if (core_enable_timer_id > 0)
+               g_source_remove(core_enable_timer_id);
+
+       core_enable_timer_id = g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
 
        BT_DBG("-");
        return TRUE;
@@ -642,43 +753,23 @@ gboolean _bt_core_set_transfer_value(gboolean value)
 
 gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
 {
-
-       char *cmd = NULL;
-       char *arg_list[3] = { NULL, NULL, NULL };
-
+       int ret;
        BT_DBG("Test item : %s", type);
 
        if (g_strcmp0(type, "Enable_RF_Test") == 0) {
-               cmd = "/usr/etc/bluetooth/bt-edutm-on.sh";
-               arg_list[0] = "bt-edutm-on.sh";
+               ret = __bt_call_systemact_service(BT_SYSTEMACT_EDUTM_ON);
+               if (ret < 0)
+                       BT_ERR("Failed to call systemact service");
        } else if (g_strcmp0(type, "Disable_RF_Test") == 0) {
-               cmd = "/usr/etc/bluetooth/bt-edutm-off.sh";
-               arg_list[0] = "bt-edutm-off.sh";
-       } else if (g_strcmp0(type, "Slave_Mode") == 0) {
-               cmd = "/usr/etc/bluetooth/bt-mode-slave.sh";
-               arg_list[0] = "bt-mode-slave.sh";
-       } else if (g_strcmp0(type, "Master_Mode") == 0) {
-               cmd = "/usr/etc/bluetooth/bt-mode-master.sh";
-               arg_list[0] = "bt-mode-master.sh";
-       } else if (g_strcmp0(type, "SSP_Debug_Mode") == 0) {
-               cmd = "/usr/etc/bluetooth/bt-set-ssp-debug-mode.sh";
-               arg_list[0] = "bt-set-ssp-debug-mode.sh";
-               arg_list[1] = (char *)arg;
-       } else if (g_strcmp0(type, "RF_Channel") == 0) {
-               cmd = "/usr/etc/bluetooth/bt-enable-rf-channel.sh";
-               arg_list[0] = "bt-enable-rf-channel.sh";
-               arg_list[1] = (char *)arg;
+               ret = __bt_call_systemact_service(BT_SYSTEMACT_EDUTM_OFF);
+               if (ret < 0)
+                       BT_ERR("Failed to call systemact service");
        } else {
-               _bt_core_terminate();
+               BT_DBG("Terminate bt-core process");
+               g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
                return FALSE;
        }
 
-       BT_DBG("Run %s", cmd);
-       if (__execute_command(cmd, arg_list) < 0) {
-               BT_ERR("running script failed");
-       }
-
-       _bt_core_terminate();
        return TRUE;
 }
 
@@ -721,12 +812,6 @@ static gboolean __bt_core_recovery_cb(gpointer data)
                if (ret < 0)
                        BT_ERR("_bt_enable_adapter() failed");
        }
-       if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
-               _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 0);
-               ret = _bt_enable_adapter_le();
-               if (ret < 0)
-                       BT_ERR("_bt_enable_adapter_le() failed");
-       }
 
        is_recovery_mode = FALSE;
 
@@ -784,7 +869,6 @@ static gboolean __bt_core_disable_timeout_cb(gpointer data)
                if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
                        _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
 
-               _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
                _bt_disable_adapter();
        }
 
@@ -794,7 +878,6 @@ static gboolean __bt_core_disable_timeout_cb(gpointer data)
                if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
                        _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
 
-               _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
                _bt_disable_adapter_le();
        }
 
@@ -864,7 +947,7 @@ void _bt_core_adapter_removed_cb(void)
        gboolean flight_mode_status;
        static int timer_id = -1;
 
-       BT_DBG("");
+       BT_DBG("is_recovery_mode: %d", is_recovery_mode);
 
        __bt_core_set_status(BT_DEACTIVATED);
        __bt_core_set_le_status(BT_LE_DEACTIVATED);