/*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- * Girishashok Joshi <girish.joshi@samsung.com>
- * Chanyeol Park <chanyeol.park@samsung.com>
+ * 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.
#include <vconf.h>
#include <vconf-keys.h>
+#include <vconf-internal-radio-keys.h>
+#include <bundle.h>
+#include <eventsystem.h>
+#include <stdio.h>
+#ifdef TIZEN_FEATURE_ACTD
+#include <actd/unit_control.h>
+#endif
#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] = { 0, };
+static int bt_le_status_before[BT_MODE_MAX] = { VCONFKEY_BT_LE_STATUS_OFF, };
-static DBusGConnection *conn = NULL;
+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)
{
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_TELEPHONY_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 gboolean bt_core_enable_adapter(BtCore *agent,
- DBusGMethodInvocation *context);
-
-static gboolean bt_core_disable_adapter(BtCore *agent,
- DBusGMethodInvocation *context);
-
-static gboolean bt_core_recover_adapter(BtCore *agent,
- DBusGMethodInvocation *context);
-
-static gboolean bt_core_enable_adapter_le(BtCore *agent,
- DBusGMethodInvocation *context);
-
-static gboolean bt_core_disable_adapter_le(BtCore *agent,
- DBusGMethodInvocation *context);
-
-static gboolean bt_core_reset_adapter(BtCore *agent,
- DBusGMethodInvocation *context);
-
-static gboolean bt_core_enable_core(BtCore *agent,
- DBusGMethodInvocation *context);
-
-static int __execute_command(const char *cmd, char *const arg_list[]);
+#ifdef TIZEN_FEATURE_ACTD
+static int __bt_call_systemact_service(const char *service_name)
+{
+ int ret;
-#include "bt-core-adapter-method.h"
+ BT_DBG("Use System Activated : %s", service_name);
+ ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM, service_name, 5000);
-G_DEFINE_TYPE(BtCore, bt_core, G_TYPE_OBJECT);
+ 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;
+ }
-/*This is part of platform provided code skeleton for client server model*/
-static void bt_core_class_init (BtCoreClass *bt_core_class)
-{
- dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(bt_core_class),
- &dbus_glib_bt_core_object_info);
+ return 0;
}
-
-/*This is part of platform provided code skeleton for client server model*/
-static void bt_core_init (BtCore *core)
+#else
+static int __bt_call_systemact_service(const char *file_path)
{
-}
+ BT_DBG("+");
+ FILE *fp;
-typedef enum {
- BT_CORE_ERROR_REJECT,
- BT_CORE_ERROR_CANCEL,
- BT_CORE_ERROR_TIMEOUT,
-} BtCoreError;
+ if (!file_path) {
+ BT_ERR("service file path is NULL");
+ return -1;
+ }
-#define BT_CORE_ERROR (bt_core_error_quark())
+ if (!access(file_path, F_OK)) {
+ remove(file_path);
+ usleep(100);
+ }
-static GQuark bt_core_error_quark(void)
-{
- static GQuark quark = 0;
- if (!quark)
- quark = g_quark_from_static_string("BtCore");
+ fp = fopen(file_path, "w");
+ if (!fp) {
+ BT_ERR("Failed to fopen service file");
+ return -1;
+ }
- return quark;
-}
-#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+ fclose(fp);
+ BT_DBG("-");
+ return 0;
-static GError *bt_core_error(BtCoreError error, const char *err_msg)
-{
- return g_error_new(BT_CORE_ERROR, error, err_msg, NULL);
}
+#endif
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);
return 0;
}
-static DBusGProxy *_bt_get_connman_proxy(void)
+static int __bt_stack_up(void)
{
- DBusGProxy *proxy;
+ int ret;
- if (conn == NULL) {
- conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(conn == NULL, NULL);
+ /* 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;
}
- proxy = dbus_g_proxy_new_for_name(conn,
- CONNMAN_DBUS_NAME,
- CONNMAN_BLUETOOTH_TECHNOLOGY_PATH,
- CONNMAN_BLUETOTOH_TECHNOLOGY_INTERFACE);
- retv_if(proxy == NULL, NULL);
-
- return proxy;
-}
-
-static int _bt_power_adapter(gboolean powered)
-{
- GValue state = { 0 };
- GError *error = NULL;
- DBusGProxy *proxy;
-
- proxy = _bt_get_connman_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- g_value_init(&state, G_TYPE_BOOLEAN);
- g_value_set_boolean(&state, powered);
-
- BT_DBG("set power property state: %d to connman", powered);
-
- dbus_g_proxy_call(proxy, "SetProperty", &error,
- G_TYPE_STRING, "Powered",
- G_TYPE_VALUE, &state,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ /* activate Bluez */
+ ret = __bt_call_systemact_service(BT_SYSTEMACT_BLUEZ_START);
+ if (ret < 0) {
+ BT_ERR("Failed to call systemact service");
+ return -1;
+ }
- if (error != NULL) {
- BT_ERR("Powered set err: \n [%s]", error->message);
- g_error_free(error);
- g_value_unset(&state);
- return BLUETOOTH_ERROR_INTERNAL;
+ /* 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 BLUETOOTH_ERROR_NONE;
+
+ return 0;
}
int _bt_enable_adapter(void)
{
int ret;
bt_status_t status;
+#if 0
bt_le_status_t le_status;
-#ifdef __TIZEN_MOBILE__
- __bt_core_set_status(BT_ACTIVATING);
+#endif
+ BT_INFO("");
- ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
+ 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) {
+ 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;
}
-#else
- _bt_power_adapter(TRUE);
-#endif
return 0;
}
int _bt_disable_adapter(void)
{
+ bt_status_t status;
+#if 0
+ bt_le_status_t le_status;
+#endif
+
BT_INFO_C("Disable adapter");
-#ifdef __TIZEN_MOBILE__
- __bt_core_set_status(BT_DEACTIVATING);
- 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;
+#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) {
+ /* 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 */
+ 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
- _bt_power_adapter(FALSE);
+ 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;
+
+ /* 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;
}
int _bt_enable_adapter_le(void)
{
BT_DBG("");
-#ifdef __TIZEN_MOBILE__
+
int ret;
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 = system("/usr/etc/bluetooth/bt-stack-up.sh &");
+ 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);
}
-#else
- _bt_power_adapter(TRUE);
+#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("+");
-#ifdef __TIZEN_MOBILE__
bt_status_t status;
+ bt_le_status_t le_status;
+
+ le_status = _bt_core_get_le_status();
+ 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);
-#else
- _bt_power_adapter(FALSE);
-#endif
BT_DBG("-");
return 0;
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;
+ }
+
+ 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;
+ }
+
+ 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;
+}
- BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status);
+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 (bt_status == VCONFKEY_BT_STATUS_OFF)
+ 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);
+ }
}
-static gboolean bt_core_enable_adapter(BtCore *agent,
- DBusGMethodInvocation *context)
+gboolean _bt_core_enable_adapter(void)
{
- char *sender = dbus_g_method_get_sender(context);
int ret;
- if (sender == NULL)
- return FALSE;
-
_bt_set_flightmode_request(FALSE);
if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
BT_ERR("Set vconf failed");
ret = _bt_enable_adapter();
- if (ret < 0) {
- GError *error = bt_core_error(BT_CORE_ERROR_REJECT,
- "Activation failed");
- dbus_g_method_return_error(context, error);
- g_error_free(error);
- g_free(sender);
+ if (ret < 0)
return FALSE;
- } else {
- dbus_g_method_return(context);
- }
+ else
+ return TRUE;
+}
- g_free(sender);
- return TRUE;
+static gboolean __bt_core_terminate_cb(gpointer data)
+{
+ _bt_core_terminate();
+
+ return FALSE;
}
-static gboolean bt_core_disable_adapter(BtCore *agent,
- DBusGMethodInvocation *context)
+gboolean _bt_core_disable_adapter(void)
{
- char *sender = dbus_g_method_get_sender(context);
int ret;
-
- if (sender == NULL)
- return FALSE;
+ 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) {
- GError *error = bt_core_error(BT_CORE_ERROR_REJECT,
- "Deactivation failed");
- dbus_g_method_return_error(context, error);
- g_error_free(error);
- g_free(sender);
- return FALSE;
+ if (adapter_state == FALSE) {
+ g_timeout_add(BT_CORE_IDLE_TERM_TIME,
+ __bt_core_terminate_cb, NULL);
+ return TRUE;
} else {
- dbus_g_method_return(context);
+ if (ret < 0)
+ return FALSE;
+ else
+ return TRUE;
}
-
- g_free(sender);
- return TRUE;
}
-static gboolean bt_core_recover_adapter(BtCore *agent,
- DBusGMethodInvocation *context)
+gboolean _bt_core_recover_adapter(void)
{
int ret;
+#if 0
int ret_le;
-
+#endif
BT_INFO_C("Recover bt adapter");
- dbus_g_method_return(context);
-
_bt_set_flightmode_request(FALSE);
if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
BT_ERR("Set vconf failed");
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;
}
-static gboolean bt_core_enable_adapter_le(BtCore *agent,
- DBusGMethodInvocation *context)
+gboolean _bt_core_enable_adapter_le(void)
{
- char *sender = dbus_g_method_get_sender(context);
int ret;
- if (sender == NULL)
- return FALSE;
-
ret = _bt_enable_adapter_le();
- if (ret < 0) {
- GError *error = bt_core_error(BT_CORE_ERROR_REJECT,
- "LE Activation failed");
- dbus_g_method_return_error(context, error);
- g_error_free(error);
- g_free(sender);
- BT_DBG("-");
+ if (ret < 0)
return FALSE;
- } else {
- dbus_g_method_return(context);
- }
-
- g_free(sender);
- BT_DBG("-");
- return TRUE;
+ else
+ return TRUE;
}
-static gboolean bt_core_disable_adapter_le(BtCore *agent,
- DBusGMethodInvocation *context)
+gboolean _bt_core_disable_adapter_le(void)
{
BT_DBG("+");
- char *sender = dbus_g_method_get_sender(context);
- BT_DBG("sender : %s", sender);
int ret;
- if (sender == NULL)
- return FALSE;
-
ret = _bt_disable_adapter_le();
- if (ret < 0) {
- GError *error = bt_core_error(BT_CORE_ERROR_REJECT,
- "LE Deactivation failed");
- dbus_g_method_return_error(context, error);
- g_error_free(error);
- g_free(sender);
+ if (ret < 0)
return FALSE;
- } else {
- dbus_g_method_return(context);
- }
-
- g_free(sender);
- BT_DBG("-");
- return TRUE;
+ else
+ return TRUE;
}
-static int __bt_reset_adapter(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();
- return 0;
-}
-static gboolean bt_core_reset_adapter(BtCore *agent,
- DBusGMethodInvocation *context)
-{
- char *sender = dbus_g_method_get_sender(context);
- int ret;
-
- if (sender == NULL)
- return FALSE;
+ g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
- ret = __bt_reset_adapter();
- if (ret < 0) {
- GError *error = bt_core_error(BT_CORE_ERROR_REJECT,
- "Deactivation failed");
- dbus_g_method_return_error(context, error);
- g_error_free(error);
- g_free(sender);
- return FALSE;
- } else {
- dbus_g_method_return(context);
- }
-
- g_free(sender);
return TRUE;
}
{
BT_DBG("+");
+ core_enable_timer_id = 0;
+
_bt_core_init_vconf_value();
return FALSE;
}
-static gboolean bt_core_enable_core(BtCore *agent,
- DBusGMethodInvocation *context)
+gboolean _bt_core_enable_core(void)
{
- char *sender = dbus_g_method_get_sender(context);
+ BT_DBG("+");
- if (sender == NULL)
- return FALSE;
+ _bt_core_update_status();
- BT_DBG("+");
+ 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;
+}
- __bt_core_update_status();
+gboolean _bt_core_set_transfer_value(gboolean value)
+{
+ const char *event_val = NULL;
+ gboolean ret = TRUE;
- g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
+ BT_DBG("value: %d", value);
- dbus_g_method_return(context);
+ event_val = value ? EVT_VAL_BT_TRANSFERING : EVT_VAL_BT_NON_TRANSFERING;
- g_free(sender);
+ 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 };
+
+ if (g_strcmp0(type, "Enable_RF_Test") == 0) {
+ cmd = "/usr/etc/bluetooth/bt-edutm-on.sh";
+ arg_list[0] = "bt-edutm-on.sh";
+ } 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;
+ } else {
+ return FALSE;
+ }
+
+ BT_DBG("Run %s", cmd);
+ if (__execute_command(cmd, arg_list) < 0)
+ BT_ERR("running script failed");
+#endif
+
return TRUE;
}
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("-");
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;
}
+static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value)
+{
+ int ret;
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ bundle_add_str(b, key, value);
+
+ ret = eventsystem_send_system_event(event, b);
+
+ BT_DBG("eventsystem_send_system_event result: %d", ret);
+
+ bundle_free(b);
+
+ return ret;
+}
+
void _bt_core_adapter_added_cb(void)
{
bt_status_t status;
}
_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();
}
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 (is_recovery_mode == TRUE)
- {
+ 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");
+
+ 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");
+
+ if (is_recovery_mode == TRUE) {
if (timer_id < 0)
timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
return;
return;
}
_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;
}
_bt_core_terminate();
}
-