X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-core%2Fbt-core-adapter.c;h=10ea862460d98e56c824cb897cd5aaf955cf2d05;hb=b9c46edbb2fc8e97620e733791a7d96547c37f64;hp=0c4f2232c4118bda625f740daea6adfc7039fb83;hpb=15a8da0024995b8eef2d95dac6f278d03e879c1b;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-core/bt-core-adapter.c b/bt-core/bt-core-adapter.c index 0c4f223..10ea862 100644 --- a/bt-core/bt-core-adapter.c +++ b/bt-core/bt-core-adapter.c @@ -1,11 +1,5 @@ /* - * Bluetooth-frwk - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Hocheol Seo - * Girishashok Joshi - * Chanyeol Park + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +17,12 @@ #include #include +#include #include -#if 0 #include +#include +#ifdef TIZEN_FEATURE_ACTD +#include #endif #include "bt-core-main.h" @@ -34,12 +31,27 @@ #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] = { 0, }; +static int bt_le_status_before[BT_MODE_MAX] = { VCONFKEY_BT_LE_STATUS_OFF, }; + +static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value); static void __bt_core_set_status(bt_status_t status) { @@ -86,21 +98,75 @@ gboolean _bt_core_is_recovery_mode(void) return is_recovery_mode; } +static gboolean __bt_core_idle_terminate(gpointer data) +{ + BT_DBG("+"); + _bt_core_terminate(); + return FALSE; +} + gboolean _bt_core_is_flight_mode_enabled(void) { -#ifdef TIZEN_BT_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; + } +} + +#ifdef TIZEN_FEATURE_ACTD +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 isFlightMode; + + return 0; +} #else - return FALSE; -#endif +static int __bt_call_systemact_service(const char *file_path) +{ + BT_DBG("+"); + FILE *fp; + + if (!file_path) { + BT_ERR("service file path is NULL"); + return -1; + } + + if (!access(file_path, F_OK)) { + remove(file_path); + usleep(100); + } + + fp = fopen(file_path, "w"); + if (!fp) { + BT_ERR("Failed to fopen service file"); + return -1; + } + + + fclose(fp); + BT_DBG("-"); + return 0; + } +#endif static int __execute_command(const char *cmd, char *const arg_list[]) { @@ -120,7 +186,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); @@ -136,35 +207,86 @@ 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(); if (status != BT_DEACTIVATED) { BT_ERR("Invalid state %d", status); + g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL); return -1; } +#if 0 /* only the concept of private */ 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. */ __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); + 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 = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL); + 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"); - ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL); + 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; } @@ -175,10 +297,13 @@ 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 */ le_status = _bt_core_get_le_status(); BT_DBG("le_status : %d", le_status); if (le_status == BT_LE_ACTIVATED) { @@ -186,27 +311,84 @@ int _bt_disable_adapter(void) /* 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 */ - if (__execute_command("/usr/etc/bluetooth/bt-stack-down.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"); + } 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 (__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 (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN) < 0) + BT_ERR("running script failed"); +#endif } _bt_core_terminate(); return 0; } else if (status != BT_ACTIVATED) { BT_ERR("Invalid state %d", status); + g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL); } __bt_core_set_status(BT_DEACTIVATING); + 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 { +#ifdef TIZEN_FEATURE_RADIO + int radio_status = VCONFKEY_RADIO_STATUS_OFF; - 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; + /* 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 (__bt_call_systemact_service(BT_SYSTEMACT_STACK_DOWN) < 0) { + BT_ERR("running script failed"); + __bt_core_set_status(BT_ACTIVATED); + return -1; + } +#endif } return 0; @@ -220,26 +402,64 @@ 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"); - ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL); + 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"); - ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL); + 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; } } else { __bt_core_set_le_status(BT_LE_ACTIVATED); + g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL); } +#ifdef TIZEN_FEATURE_BT_HPS + ret = _bt_core_start_httpproxy(); + 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("+"); @@ -251,17 +471,34 @@ int _bt_disable_adapter_le(void) retv_if(le_status == BT_LE_DEACTIVATED, 0); retv_if(le_status == BT_LE_DEACTIVATING, -1); +#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); - - if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) { + 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; } + } else { + g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL); } __bt_core_set_le_status(BT_LE_DEACTIVATED); @@ -292,29 +529,100 @@ int _bt_core_service_request_adapter(int service_function) return ret; } -static void __bt_core_update_status(void) +static gboolean __bt_core_check_the_adapter_path(void) { - int bt_status = VCONFKEY_BT_STATUS_OFF; - int bt_le_status = 0; + 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; - if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) - BT_ERR("no bluetooth device info, so BT was disabled at previous session"); -#ifdef ENABLE_TIZEN_2_4 - if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) - BT_ERR("no bluetooth le info, so BT LE was disabled at previous session"); -#endif + manager_proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_NONE, NULL, + "org.bluez", + "/", + "org.freedesktop.DBus.ObjectManager", + NULL, &err); + + if (!manager_proxy) { + if (err != NULL) { + BT_ERR("Unable to create proxy: %s", err->message); + g_clear_error(&err); + } else { + BT_ERR("Fail to create proxy"); + } + goto fail; + } - BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status); + result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL, + G_DBUS_CALL_FLAGS_NONE, 1000, NULL, &err); + if (!result) { + if (err != NULL) { + BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message); + g_clear_error(&err); + } else{ + BT_ERR("Fail to get DefaultAdapter"); + } + goto fail; + } + + if (g_strcmp0(g_variant_get_type_string(result), "(o)")) { + BT_ERR("Incorrect result\n"); + goto fail; + } + + g_variant_get(result, "(&o)", &adapter_path); + + if (adapter_path == NULL || + strlen(adapter_path) >= BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX) { + BT_ERR("Adapter path is inproper\n"); + goto fail; + } - if (bt_status == VCONFKEY_BT_STATUS_OFF) + g_variant_unref(result); + g_object_unref(manager_proxy); + + return TRUE; + +fail: + if (result) + g_variant_unref(result); + + if (manager_proxy) + g_object_unref(manager_proxy); + + return FALSE; +} + +void _bt_core_update_status(void) +{ + int bt_status = VCONFKEY_BT_STATUS_OFF; + int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF; + gboolean ret = FALSE; + + ret = __bt_core_check_the_adapter_path(); + BT_INFO("check the real status of bt_adapter"); + + if (ret != TRUE) { __bt_core_set_status(BT_DEACTIVATED); - else - __bt_core_set_status(BT_ACTIVATED); + __bt_core_set_le_status(BT_DEACTIVATED); + } else { + if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) + BT_ERR("no bluetooth device info, so BT was disabled at previous session"); + if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) + BT_ERR("no bluetooth le info, so BT LE was disabled at previous session"); - if (bt_le_status == 0) - __bt_core_set_le_status(BT_LE_DEACTIVATED); - else - __bt_core_set_le_status(BT_LE_ACTIVATED); + BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status); + + if (bt_status & VCONFKEY_BT_STATUS_ON) + __bt_core_set_status(BT_ACTIVATED); + if (bt_le_status & VCONFKEY_BT_LE_STATUS_ON) + __bt_core_set_le_status(BT_ACTIVATED); + } } gboolean _bt_core_enable_adapter(void) @@ -332,26 +640,43 @@ 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; +#if 0 int ret_le; - +#endif BT_INFO_C("Recover bt adapter"); _bt_set_flightmode_request(FALSE); @@ -360,24 +685,31 @@ gboolean _bt_core_recover_adapter(void) is_recovery_mode = TRUE; - __bt_core_update_status(); + _bt_core_update_status(); if (_bt_core_get_status() == BT_ACTIVATED) { _bt_core_set_bt_status(BT_RECOVERY_MODE, 1); +#ifdef TIZEN_FEATURE_BUSACT _bt_core_service_request_adapter(BT_DISABLE_ADAPTER); +#endif } if (_bt_core_get_le_status() == BT_LE_ACTIVATED) { _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1); +#ifdef TIZEN_FEATURE_BUSACT _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE); +#endif } 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 ret_le = _bt_disable_adapter_le(); if (ret_le < 0) BT_ERR("_bt_disable_adapter_le() failed"); - +#endif return TRUE; } @@ -408,10 +740,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; } @@ -420,6 +752,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; @@ -429,22 +763,64 @@ gboolean _bt_core_enable_core(void) { BT_DBG("+"); - __bt_core_update_status(); + _bt_core_update_status(); + + if (core_enable_timer_id > 0) + g_source_remove(core_enable_timer_id); - g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL); + core_enable_timer_id = g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL); BT_DBG("-"); return TRUE; } +gboolean _bt_core_set_transfer_value(gboolean value) +{ + const char *event_val = NULL; + gboolean ret = TRUE; + + BT_DBG("value: %d", value); + + event_val = value ? EVT_VAL_BT_TRANSFERING : EVT_VAL_BT_NON_TRANSFERING; + + if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_TRANSFERING_STATE, + event_val) != ES_R_OK) { + BT_ERR("Fail to set BT state value"); + ret = FALSE; + } + + if (ret == FALSE || value == FALSE) { + BT_DBG("Terminate bt-core process"); + g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL); + } + + BT_DBG("-"); + return ret; +} + gboolean _bt_core_factory_test_mode(const char *type, const char *arg) { + int ret; + BT_DBG("Test item : %s", type); +#ifdef TIZEN_FEATURE_ACTD + if (g_strcmp0(type, "Enable_RF_Test") == 0) { + 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) { + ret = __bt_call_systemact_service(BT_SYSTEMACT_EDUTM_OFF); + if (ret < 0) + BT_ERR("Failed to call systemact service"); + } else { + BT_DBG("Terminate bt-core process"); + g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL); + return FALSE; + } +#else char *cmd = NULL; char *arg_list[3] = { NULL, NULL, NULL }; - 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"; @@ -466,16 +842,14 @@ gboolean _bt_core_factory_test_mode(const char *type, const char *arg) arg_list[0] = "bt-enable-rf-channel.sh"; arg_list[1] = (char *)arg; } else { - _bt_core_terminate(); return FALSE; } BT_DBG("Run %s", cmd); - if (__execute_command(cmd, arg_list) < 0) { + if (__execute_command(cmd, arg_list) < 0) BT_ERR("running script failed"); - } +#endif - _bt_core_terminate(); return TRUE; } @@ -518,13 +892,15 @@ static gboolean __bt_core_recovery_cb(gpointer data) if (ret < 0) BT_ERR("_bt_enable_adapter() failed"); } + +#if 0 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"); } - +#endif is_recovery_mode = FALSE; BT_DBG("-"); @@ -581,25 +957,27 @@ 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); +#ifdef TIZEN_FEATURE_BUSACT _bt_core_service_request_adapter(BT_DISABLE_ADAPTER); +#endif _bt_disable_adapter(); } if (adapter_status_le == BT_LE_ACTIVATED) { int bt_le_status_before_mode = 0; -#ifdef ENABLE_TIZEN_2_4 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); -#endif +#ifdef TIZEN_FEATURE_BUSACT _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE); +#endif _bt_disable_adapter_le(); } return FALSE; } -#if 0 + static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value) { int ret; @@ -609,15 +987,15 @@ static int __bt_eventsystem_set_value(const char *event, const char *key, const bundle_add_str(b, key, value); - ret = eventsystem_request_sending_system_event(event, b); + ret = eventsystem_send_system_event(event, b); - BT_DBG("request_sending_system_event result: %d", ret); + BT_DBG("eventsystem_send_system_event result: %d", ret); bundle_free(b); return ret; } -#endif + void _bt_core_adapter_added_cb(void) { bt_status_t status; @@ -644,6 +1022,15 @@ void _bt_core_adapter_added_cb(void) return; } _bt_set_flightmode_request(FALSE); + + if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE, + EVT_VAL_BT_ON) != ES_R_OK) + BT_ERR("Fail to set BT state value"); + + if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE, + EVT_VAL_BT_LE_ON) != ES_R_OK) + BT_ERR("Fail to set BT LE state value"); + _bt_core_terminate(); } @@ -654,18 +1041,15 @@ 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); if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0) BT_ERR("Set vconf failed"); -#ifdef ENABLE_TIZEN_2_4 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0) BT_ERR("Set vconf failed"); -#endif -#if 0 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE, EVT_VAL_BT_OFF) != ES_R_OK) BT_ERR("Fail to set value"); @@ -673,9 +1057,8 @@ void _bt_core_adapter_removed_cb(void) if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE, EVT_VAL_BT_LE_OFF) != ES_R_OK) BT_ERR("Fail to set value"); -#endif - if (is_recovery_mode == TRUE) - { + + if (is_recovery_mode == TRUE) { if (timer_id < 0) timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL); return; @@ -697,7 +1080,7 @@ void _bt_core_adapter_removed_cb(void) } _bt_set_flightmode_request(FALSE); - if (flight_mode_value == 1 || power_saving_mode == 1){ + if (flight_mode_value == 1 || power_saving_mode == 1) { BT_DBG("Bt Core not terminated"); return; }