LE adapter Enable/Disable implementation in New HAL architecture ,OAL 77/146677/1
authorAbhishek Chandra <abhishek.ch@samsung.com>
Wed, 30 Aug 2017 04:30:26 +0000 (10:00 +0530)
committerAbhishek Chandra <abhishek.ch@samsung.com>
Wed, 30 Aug 2017 04:30:26 +0000 (10:00 +0530)
and Bt-service in Tizen_Next.

Change-Id: Iad836a5da661ef4f9cf1182e6874bf3d3dc24d17
Signed-off-by: Abhishek Chandra <abhishek.ch@samsung.com>
19 files changed:
bt-core/bt-core-adapter.c
bt-oal/bluez_hal/hardware/bluetooth.h [changed mode: 0755->0644]
bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.h
bt-oal/bluez_hal/src/bt-hal-adapter-le.c
bt-oal/bluez_hal/src/bt-hal-adapter-le.h
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/include/oal-adapter-mgr.h [changed mode: 0755->0644]
bt-oal/include/oal-event.h [changed mode: 0755->0644]
bt-oal/oal-adapter-mgr.c [changed mode: 0755->0644]
bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c
bt-service-adaptation/services/adapter/bt-service-core-adapter.c
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/bt-service-event-receiver.c
bt-service-adaptation/services/bt-service-main.c
bt-service-adaptation/services/include/bt-service-core-adapter-le.h
bt-service-adaptation/services/include/bt-service-core-adapter.h [changed mode: 0755->0644]

index 196df7a..5a8fe67 100644 (file)
@@ -298,16 +298,13 @@ int _bt_disable_adapter(void)
 
 int _bt_enable_adapter_le(void)
 {
-       BT_DBG("");
+       BT_DBG("+");
 
        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_DEACTIVATED, -1);
 
-       status = _bt_core_get_status();
-       if (status == BT_DEACTIVATED) {
+       le_status = _bt_core_get_le_status();
+       if (le_status == BT_LE_DEACTIVATED) {
                __bt_core_set_le_status(BT_LE_ACTIVATING);
                BT_DBG("Activate BT");
                if (TIZEN_FEATURE_BT_USB_DONGLE) {
@@ -324,12 +321,10 @@ int _bt_enable_adapter_le(void)
                        } 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 HPS_FEATURE
@@ -337,6 +332,8 @@ int _bt_enable_adapter_le(void)
        if (ret < 0)
                BT_ERR("_bt_core_start_httpproxy() failed");
 #endif
+       __bt_core_set_le_status(BT_LE_ACTIVATED);
+       BT_DBG("-");
 
        return 0;
 }
@@ -345,7 +342,6 @@ int _bt_disable_adapter_le(void)
 {
        BT_DBG("+");
 
-       bt_status_t status;
        bt_le_status_t le_status;
 
        le_status = _bt_core_get_le_status();
@@ -356,10 +352,10 @@ int _bt_disable_adapter_le(void)
        _bt_core_stop_httpproxy();
 #endif
 
-       status = _bt_core_get_status();
-       BT_DBG("status : %d", status);
+       le_status = _bt_core_get_le_status();
+       BT_DBG("status : %d", le_status);
 
-       if (status == BT_DEACTIVATED) {
+       if (le_status == BT_LE_ACTIVATED) {
                __bt_core_set_le_status(BT_LE_DEACTIVATING);
                int ret;
                if (TIZEN_FEATURE_BT_USB_DONGLE) {
@@ -495,7 +491,7 @@ void _bt_core_update_status(void)
                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);
+                       __bt_core_set_le_status(BT_LE_ACTIVATED);
        }
 }
 
old mode 100755 (executable)
new mode 100644 (file)
index bcac8fa..fd5a317
@@ -400,6 +400,11 @@ typedef enum {
 /** Bluetooth Enable/Disable Callback. */
 typedef void (*adapter_state_changed_callback)(bt_state_t state);
 
+#ifdef TIZEN_BT_HAL
+/** BLE Enable/Disable Callback. */
+typedef void (*le_state_changed_callback)(bt_state_t state);
+#endif
+
 /** GET/SET Adapter Properties callback */
 /* TODO: For the GET/SET property APIs/callbacks, we may need a session
  * identifier to associate the call with the callback. This would be needed
@@ -519,6 +524,7 @@ typedef struct {
     device_trust_state_changed_callback device_trust_state_changed_cb;
 #ifdef TIZEN_BT_HAL
     sock_authorize_request_callback socket_authorize_request_cb;
+       le_state_changed_callback le_state_changed_cb;
 #endif
 } bt_callbacks_t;
 
@@ -575,6 +581,14 @@ typedef struct {
     /** Disable Bluetooth. */
     int (*disable)(void);
 
+#ifdef TIZEN_BT_HAL
+    /** Enable LE Bluetooth. */
+    int (*le_enable)(void);
+
+    /** Disable LE Bluetooth. */
+    int (*le_disable)(void);
+#endif
+
     /** Closes the interface. */
     void (*cleanup)(void);
 
index 3fe509f..a1b9eb6 100644 (file)
@@ -582,5 +582,11 @@ struct hal_ev_gatt_server_notifcation_change {
        uint8_t notify;
        uint8_t bdaddr[6];
 } __attribute__((packed));
+
+#define HAL_EV_LE_STATE_CHANGED    0xB7
+struct hal_ev_le_state_changed {
+        uint8_t state;
+} __attribute__((packed));
+
 #endif
 #endif //_BT_HAL_MSG_H_
index bc87058..5074e69 100644 (file)
@@ -182,7 +182,83 @@ int _bt_hal_dbus_disable_adapter(void)
        g_variant_unref(result);
        return BT_STATUS_SUCCESS;
 }
+#ifdef TIZEN_BT_HAL
+int _bt_hal_dbus_enable_le(void)
+{
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       GVariant *result = NULL;
+
+       DBG("+");
+       proxy = __bt_get_core_proxy();
+
+       if (!proxy) {
+               DBG("_bt_hal_dbus_enable_le: Core proxy get failed!!!");
+               return BT_STATUS_FAIL;
+       }
+
+       result = g_dbus_proxy_call_sync(proxy, "EnableAdapterLe",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
+                       NULL, &error);
+       if (error) {
+               DBG("EnableAdapter failed: %s", error->message);
+               g_clear_error(&error);
+               error = NULL;
+               result = g_dbus_proxy_call_sync(proxy,
+                               "DisableAdapter",
+                               NULL,
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1,
+                               NULL,
+                               &error);
+
+               if (error != NULL) {
+                       DBG("Bt core call failed(Error: %s)", error->message);
+                       g_clear_error(&error);
+               }
+               g_variant_unref(result);
+
+               return BT_STATUS_FAIL;
+       }
+
+       DBG("-");
+       g_variant_unref(result);
+       return BT_STATUS_SUCCESS;
+}
+
+int _bt_hal_dbus_disable_le(void)
+{
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       GVariant *result = NULL;
+
+       DBG("+");
+       proxy = __bt_get_core_proxy();
+
+       if (!proxy) {
+               DBG("_bt_hal_dbus_disable_le: Core proxy get failed!!!");
+               return BT_STATUS_FAIL;
+       }
 
+       result = g_dbus_proxy_call_sync(proxy, "DisableAdapterLe",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       if (error) {
+               DBG("DisableAdapter failed: %s", error->message);
+               g_clear_error(&error);
+               error = NULL;
+               g_variant_unref(result);
+
+               return BT_STATUS_FAIL;
+       }
+
+       DBG("-");
+       g_variant_unref(result);
+       return BT_STATUS_SUCCESS;
+}
+#endif
 int _bt_hal_dbus_start_discovery(void)
 {
        GDBusProxy *proxy;
index 3585648..318fe61 100644 (file)
 extern "C" {
 #endif
 
+#ifdef TIZEN_BT_HAL
+int _bt_hal_dbus_enable_le(void);
+
+int _bt_hal_dbus_disable_le(void);
+#endif
+
 void _bt_hal_dbus_store_stack_msg_cb(handle_stack_msg cb);
 
 int _bt_hal_dbus_enable_adapter(void);
index e947371..b65ca02 100644 (file)
@@ -105,6 +105,20 @@ static gboolean __bt_hal_is_factory_test_mode(void);
 static void __bt_hal_free_le_adv_slot(void);
 static gboolean __bt_hal_adv_event_cb(gpointer param);
 
+#ifdef TIZEN_BT_HAL
+/* Enable LE Adapter */
+int _bt_hal_le_enable(void)
+{
+       return _bt_hal_dbus_enable_le();
+}
+
+/* Disable LE Adapter */
+int _bt_hal_le_disable(void)
+{
+       return _bt_hal_dbus_disable_le();
+}
+#endif
+
 static void __bt_hal_free_le_adv_slot(void)
 {
        int i;
index c1c8460..11d2ec1 100644 (file)
 extern "C" {
 #endif
 
+#ifdef TIZEN_BT_HAL
+int _bt_hal_le_enable(void);
+
+int _bt_hal_le_disable(void);
+#endif
+
 void _bt_hal_register_gatt_le_dbus_handler_cb(handle_stack_msg cb);
 
 void _bt_hal_unregister_gatt_le_dbus_handler_cb();
index f5980eb..004b2e2 100644 (file)
@@ -41,6 +41,9 @@
 #include <bt-hal-avrcp-tg.h>
 #include <bt-hal-avrcp-ctrl.h>
 #include <bt-hal-gatt.h>
+#ifdef TIZEN_BT_HAL
+#include <bt-hal-adapter-le.h>
+#endif
 
 #define enum_prop_to_hal(prop, hal_prop, type) do { \
        static type e; \
@@ -321,6 +324,10 @@ static const bt_interface_t bluetooth_if = {
        .init = init,
        .enable = enable,
        .disable = disable,
+#ifdef TIZEN_BT_HAL
+       .le_enable = _bt_hal_le_enable,
+       .le_disable = _bt_hal_le_disable,
+#endif
        .cleanup = cleanup,
        .get_adapter_properties = get_adapter_properties,
        .get_adapter_property = get_adapter_property,
@@ -413,6 +420,18 @@ static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len)
                _bt_hal_avrcp_tg_register_media_player();
 }
 
+#ifdef TIZEN_BT_HAL
+static void __bt_hal_handle_le_state_changed(void *buf, uint16_t len)
+{
+       struct hal_ev_le_state_changed *ev = buf;
+
+       DBG("Adapter State: %d", ev->state);
+
+       if (bt_hal_cbacks->le_state_changed_cb)
+               bt_hal_cbacks->le_state_changed_cb(ev->state);
+}
+#endif
+
 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop,
                uint8_t num_props, uint16_t len)
 {
@@ -831,6 +850,10 @@ static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
                        DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
                        __bt_hal_handle_socket_authorize_request_event(buf, len);
                        break;
+               case HAL_EV_LE_STATE_CHANGED:
+                       DBG("Event: HAL_EV_LE_STATE_CHANGED");
+                       __bt_hal_handle_le_state_changed(buf, len);
+                       break;
 #endif
                default:
                        DBG("Event Currently not handled!!");
index de6ab41..35d3988 100644 (file)
@@ -281,6 +281,9 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
                                struct hal_ev_adapter_state_changed ev;
                                ev.state = HAL_POWER_OFF;
                                event_cb(HAL_EV_ADAPTER_STATE_CHANGED, &ev, sizeof(ev));
+#ifdef TIZEN_BT_HAL
+                               event_cb(HAL_EV_LE_STATE_CHANGED, &ev, sizeof(ev));
+#endif
                                /* Destroy Agent */
                                _bt_hal_destroy_adapter_agent();
                        } else {
@@ -288,6 +291,9 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
                                struct hal_ev_adapter_state_changed ev;
                                ev.state = HAL_POWER_ON;
                                event_cb(HAL_EV_ADAPTER_STATE_CHANGED, &ev, sizeof(ev));
+#ifdef TIZEN_BT_HAL
+                               event_cb(HAL_EV_LE_STATE_CHANGED, &ev, sizeof(ev));
+#endif
                                /* Create Agent */
                                _bt_hal_initialize_adapter_agent();
                        }
old mode 100755 (executable)
new mode 100644 (file)
index ced1d18..d280e08
@@ -66,6 +66,41 @@ oal_status_t adapter_enable(void);
  */
 oal_status_t adapter_disable(void);
 
+#ifdef TIZEN_BT_HAL
+
+/**
+ * @brief Enable LE Mode BT chip for usage.
+ *
+ * @remarks Other API can only be used after successful event. \n
+ *
+ * @details EVENT: OAL_EVENT_LE_ENABLED/OAL_EVENT_LE_DISABLED
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS  Successful
+ *
+ * @pre OAL API must be initialized with oal_bt_init().
+ *
+ * @see  le_disable()
+ */
+oal_status_t le_enable(void);
+
+
+/**
+ * @brief Disable LE Adapter.
+ *
+ * @remarks  Disables the LE mode in the chip. After this, no OAL API is valid except "le_enable()"
+ *
+ * @details EVENT: OAL_EVENT_LE_DISABLED
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre LE Adapter must be enabled with le_enable() followed by OAL_EVENT_LE_ENABLED
+ *
+ * @see  le_enable()
+ */
+oal_status_t le_disable(void);
+#endif
 /**
  * @brief Start device discovery
  *
old mode 100755 (executable)
new mode 100644 (file)
index f80a14e..cc85329
@@ -118,6 +118,8 @@ extern "C" {
        EVENT(OAL_EVENT_HDP_CHANNEL_CONNECTED)                  /* HDP channel connected */ \
        EVENT(OAL_EVENT_HDP_CHANNEL_DESTROYED)                  /* HDP channel destroyed */ \
        EVENT(OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED)    /*event_ble_adv_status */ \
+               EVENT(OAL_EVENT_BLE_ENABLED)                    /*ble adapter enable */ \
+               EVENT(OAL_EVENT_BLE_DISABLED)                   /*ble adapter disable */ \
         EVENT(OAL_EVENT_BLE_ADVERTISING_STARTED)                        /* NULL */\
         EVENT(OAL_EVENT_BLE_ADVERTISING_STOPPED)                        /* NULL*/\
         EVENT(OAL_EVENT_BLE_MULTI_ADVERTISING_ENABLE)           /* NULL*/\
old mode 100755 (executable)
new mode 100644 (file)
index 51127f4..489554c
@@ -47,6 +47,9 @@ static int discoverable_timeout = 0;
 /* Forward declarations */
 oal_status_t convert_to_oal_status(bt_status_t status);
 static gboolean retry_enable_adapter(gpointer data);
+#ifdef TIZEN_BT_HAL
+static gboolean retry_enable_le(gpointer data);
+#endif
 oal_status_t oal_mgr_init_internal(void);
 
 
@@ -69,6 +72,7 @@ extern void cb_device_authorize_request(bt_bdaddr_t *remote_bd_addr, bt_service_
 extern void cb_device_trust_state_changed(bt_bdaddr_t *remote_bd_addr, bt_device_trust_state_t trusted);
 #ifdef TIZEN_BT_HAL
 extern void cb_socket_conn_authorize_request(bt_bdaddr_t *remote_bd_addr, bt_uuid_t *uuid);
+static void cb_ble_state_change(bt_state_t status);
 #endif
 
 static bt_callbacks_t callbacks = {
@@ -90,6 +94,7 @@ static bt_callbacks_t callbacks = {
        cb_device_trust_state_changed,
 #ifdef TIZEN_BT_HAL
        cb_socket_conn_authorize_request,
+       cb_ble_state_change,
 #endif
 };
 
@@ -158,6 +163,45 @@ oal_status_t adapter_disable(void)
        return OAL_STATUS_SUCCESS;
 }
 
+#ifdef TIZEN_BT_HAL
+oal_status_t le_enable(void)
+{
+       int ret = BT_STATUS_SUCCESS;
+
+       API_TRACE();
+       CHECK_OAL_INITIALIZED();
+       if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
+               g_timeout_add(200, retry_enable_le, NULL);
+               return OAL_STATUS_PENDING;
+       }
+
+       ret = blued_api->le_enable();
+
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("Enable failed: [%s]", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t le_disable(void)
+{
+       int ret;
+
+       API_TRACE();
+
+       CHECK_OAL_INITIALIZED();
+
+       ret = blued_api->le_disable();
+
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("Disable failed: [%s]", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+       return OAL_STATUS_SUCCESS;
+}
+#endif
 oal_status_t adapter_start_inquiry(unsigned short duration)
 {
        int ret;
@@ -203,12 +247,32 @@ static void cb_adapter_state_change(bt_state_t status)
        send_event(event, NULL, 0);
 }
 
+#ifdef TIZEN_BT_HAL
+/* Callbacks from Stack */
+static void cb_ble_state_change(bt_state_t status)
+{
+       BT_DBG("+");
+       oal_event_t event;
+
+       event = (BT_STATE_ON == status)?OAL_EVENT_BLE_ENABLED:OAL_EVENT_BLE_DISABLED;
+
+       send_event(event, NULL, 0);
+}
+#endif
+
 static gboolean retry_enable_adapter(gpointer data)
 {
        adapter_enable();
        return FALSE;
 }
 
+#ifdef TIZEN_BT_HAL
+static gboolean retry_enable_le(gpointer data)
+{
+       le_enable();
+       return FALSE;
+}
+#endif
 oal_status_t adapter_get_properties(void)
 {
        int ret;
index 7de8fda..0e2d67b 100644 (file)
@@ -32,6 +32,7 @@
 #include "bt-service-event-receiver.h"
 #include "bt-service-gatt.h"
 #include "bt-service-util.h"
+#include "bt-service-core-device.h"
 
 #include <oal-hardware.h>
 #include <oal-manager.h>
@@ -61,7 +62,11 @@ typedef struct {
        bluetooth_advertising_params_t params; /* Adv Parameters */
 } bt_pending_adv_data_set_t;
 
+static guint timer_id = 0;
+
 static GSList *adv_data_pending_list = NULL;
+static bt_le_status_t adapter_le_state = BT_LE_DEACTIVATED;
+static bt_le_discovery_state_t adapter_le_discovery_state = LE_DISCOVERY_STOPPED;
 
 /******************************************* LE Scan *********************************************/
 #define BT_LE_SCAN_INTERVAL_MIN 2.5
@@ -81,6 +86,121 @@ GSList *scanner_list = NULL;
 static gboolean is_le_set_scan_parameter = FALSE;
 static gboolean is_le_scanning = FALSE;
 /******************************************* LE Scan *********************************************/
+
+void _bt_adapter_set_le_status(bt_le_status_t status)
+{
+       BT_INFO("adapter_le_state changed [%d] -> [%d]", adapter_le_state, status);
+       adapter_le_state = status;
+}
+
+bt_le_status_t _bt_adapter_get_le_state(void)
+{
+       return adapter_le_state;
+}
+
+
+/* Internal functions of core adapter service */
+static void __bt_le_handle_pending_requests(int service_function, void *user_data, unsigned int size)
+{
+       GSList *l;
+       GArray *out_param;
+       invocation_info_t *req_info;
+       BT_INFO("+");
+
+       /* Get method invocation context */
+       for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+               req_info = l->data;
+               if (req_info == NULL || req_info->service_function != service_function)
+                       continue;
+
+               /* Create out param */
+               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+
+               switch(service_function) {
+               case BT_ENABLE_ADAPTER_LE:
+               case BT_DISABLE_ADAPTER_LE: {
+                       gboolean done = TRUE;
+                       g_array_append_vals(out_param, &done, sizeof(gboolean));
+                       break;
+               }
+               default:
+                       BT_ERR("Unknown service function[%d]", service_function);
+               }
+
+               _bt_service_method_return(req_info->context, out_param, req_info->result);
+               g_array_free(out_param, TRUE);
+               /* Now free invocation info for this request*/
+               _bt_free_info_from_invocation_list(req_info);
+       }
+}
+
+
+/* Request return handlings */
+static gboolean __bt_le_post_set_enabled(gpointer user_data)
+{
+       BT_INFO("__bt_adapter_post_set_enabled>>");
+
+       /* Add LE enabled post processing codes */
+
+       return FALSE;
+}
+
+
+static gboolean __bt_le_post_set_disabled(gpointer user_data)
+{
+       BT_INFO("_bt_adapter_post_set_disabled>>");
+
+       /* Add LE disabled post processing codes */
+
+       return FALSE;
+}
+
+static void __bt_le_update_bt_enabled(void)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       BT_ERR("_bt_adapter_update_bt_enabled>>");
+       /* Update Bluetooth Status to notify other modules */
+       if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_ON) != 0)
+               BT_ERR("Set vconf failed\n");
+
+       /* TODO:Add timer function to handle any further post processing */
+       g_idle_add((GSourceFunc)__bt_le_post_set_enabled, NULL);
+
+       /*Return BT_ADAPTER_ENABLE Method invocation context */
+       __bt_le_handle_pending_requests(BT_ENABLE_ADAPTER_LE, NULL, 0);
+       /*Send BT Enabled event to application */
+       _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_ENABLED,
+                       g_variant_new("(i)", result));
+}
+
+static void __bt_le_update_bt_disabled(void)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       BT_INFO("_bt_adapter_update_bt_disabled>>");
+
+       int power_off_status = 0;
+       int ret;
+
+       /* Update the vconf LE status in normal Deactivation case only */
+       ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
+       BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status);
+
+       /* Update LE Status to notify other modules */
+       if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
+               BT_ERR("Set vconf failed");
+
+       /* TODO:Add timer function to handle any further post processing */
+       g_idle_add((GSourceFunc)__bt_le_post_set_disabled, NULL);
+
+       /* Return BT_ADAPTER_DISABLE Method invocation context */
+       __bt_le_handle_pending_requests(BT_DISABLE_ADAPTER_LE, NULL, 0);
+
+       /* Send BT Disabled event to application */
+       _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
+                       g_variant_new("(i)", result));
+}
+
+
 static void __bt_set_le_scan_status(gboolean mode)
 {
        is_le_scanning = mode;
@@ -451,11 +571,51 @@ static void __bt_le_handle_device_found(event_ble_scan_result_info *scan_result)
        BT_DBG("-");
 }
 
+static void __bt_le_state_change_callback(int bt_status)
+{
+       BT_INFO("__bt_adapter_state_change_callback: status [%d]", bt_status);
+
+       switch (bt_status) {
+       case BT_LE_DEACTIVATED:
+               _bt_adapter_set_le_status(bt_status);
+
+               /* LE is disabled, unregister event handlers */
+               _bt_service_unregister_event_handler_callback(BT_ADAPTER_LE_MODULE);
+
+               /* Add Adapter disabled post processing codes */
+               __bt_le_update_bt_disabled();
+               break;
+       case BT_LE_ACTIVATED:
+               _bt_adapter_set_le_status(bt_status);
+
+               /* Add Adapter enabled post processing codes */
+               if (timer_id > 0) {
+                       BT_DBG("g_source is removed");
+                       g_source_remove(timer_id);
+                       timer_id = 0;
+               }
+               __bt_le_update_bt_enabled();
+               break;
+       default:
+               BT_ERR("Incorrect Bluetooth adapter state changed status");
+               break;
+
+       }
+}
+
 static void __bt_le_event_handler(int event_type, gpointer event_data)
 {
         BT_INFO("OAL event = 0x%x, \n", event_type);
 
         switch (event_type) {
+       case OAL_EVENT_BLE_ENABLED: {
+               __bt_le_state_change_callback(BT_LE_ACTIVATED);
+               break;
+       }
+       case OAL_EVENT_BLE_DISABLED: {
+               __bt_le_state_change_callback(BT_LE_DEACTIVATED);
+               break;
+       }
        case OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED: {
                 BT_INFO("OAL Event: Server Instance Registered");
                 event_gatts_register_t* event = g_memdup(event_data, sizeof(event_gatts_register_t));
@@ -547,6 +707,136 @@ void _bt_le_deinit(void)
        BT_DBG("-");
 }
 
+static void __bt_le_update_discovery_status(bt_adapter_discovery_state_t status)
+{
+        BT_INFO("adapter_discovery_status changed [%d] -> [%d]", adapter_le_discovery_state, status);
+        adapter_le_discovery_state = status;
+}
+
+static int __bt_le_state_handle_request(gboolean enable)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       BT_DBG("");
+
+       switch (_bt_adapter_get_le_state()) {
+       case BT_LE_ACTIVATING: {
+               BT_INFO("LE is currently in activating state, state [%d]",
+                               _bt_adapter_get_le_state());
+               if (enable) {
+                       return BLUETOOTH_ERROR_IN_PROGRESS;
+               } else {
+                       if (adapter_le_discovery_state == LE_DISCOVERY_STARTED ||
+                                       adapter_le_discovery_state == LE_DISCOVERY_STARTING) {
+                               /*TODO Stop Discovery*/
+                               if (result != OAL_STATUS_SUCCESS)
+                                       BT_ERR("Discover stop failed: %d", result);
+                               __bt_le_update_discovery_status(FALSE);
+                       }
+                       result = le_disable();  //change
+                       if (result != OAL_STATUS_SUCCESS) {
+                               BT_ERR("LE_enable failed: [%d]", result);
+                               result = BLUETOOTH_ERROR_INTERNAL;
+                               /*TODO: perform if anything more needs to be done to handle failure */
+                       } else {
+                               /* TODO: To be handled */
+                               _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
+                               result = BLUETOOTH_ERROR_NONE;
+                       }
+               }
+               break;
+       }
+       case BT_LE_ACTIVATED: {
+               BT_INFO("LE is currently in activated state, state [%d]",
+                               _bt_adapter_get_le_state());
+               if (enable) {
+                       return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
+               } else {
+                       if (adapter_le_discovery_state == LE_DISCOVERY_STARTED ||
+                                       adapter_le_discovery_state == LE_DISCOVERY_STARTING) {
+                               /*TODO Stop Discovery*/
+                               if (result != OAL_STATUS_SUCCESS)
+                                       BT_ERR("Discover stop failed: %d", result);
+                               __bt_le_update_discovery_status(FALSE);
+                       }
+                       result = le_disable();
+                       if (result != OAL_STATUS_SUCCESS) {
+                               BT_ERR("LE_enable failed: [%d]", result);
+                               result = BLUETOOTH_ERROR_INTERNAL;
+                               /*TODO: perform if anything more needs to be done to handle failure */
+                       } else {
+                               /* TODO: To be handled */
+                               _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
+                               result = BLUETOOTH_ERROR_NONE;
+                       }
+               }
+               break;
+       }
+       case BT_LE_DEACTIVATING: {
+               BT_INFO("LE is currently in deactivating state, state [%d]",
+                               _bt_adapter_get_le_state());
+               if (!enable) {
+                       return BLUETOOTH_ERROR_IN_PROGRESS;
+
+               } else {
+                       result = le_enable();
+                       if (result != OAL_STATUS_SUCCESS && result != OAL_STATUS_PENDING) {
+                               BT_ERR("LE_enable failed: [%d]", result);
+                               le_disable();
+                               result = BLUETOOTH_ERROR_INTERNAL;
+                               /*TODO: perform if anything more needs to be done to handle failure */
+                       } else {
+                               /* TODO: To be handled */
+                               _bt_adapter_set_le_status(BT_LE_ACTIVATING);
+                               result = BLUETOOTH_ERROR_NONE;
+                       }
+               }
+               break;
+       }
+       case BT_LE_DEACTIVATED: {
+               BT_INFO("LE is currently in deactivated state, state [%d]",
+                               _bt_adapter_get_le_state());
+               if (!enable) {
+                       return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+               } else {
+                       result = le_enable();
+                       if (result != OAL_STATUS_SUCCESS && result != OAL_STATUS_PENDING) {
+                               BT_ERR("LE_enable failed: [%d]", result);
+                               le_disable();
+                               result = BLUETOOTH_ERROR_INTERNAL;
+                               /*TODO: perform if anything more needs to be done to handle failure */
+                       } else {
+                               /* TODO: To be handled */
+                               _bt_adapter_set_le_status(BT_LE_ACTIVATING);
+                               result = BLUETOOTH_ERROR_NONE;
+                       }
+               }
+               break;
+       }
+       default:
+               BT_ERR("Unknown state: %d", _bt_adapter_get_le_state);
+               break;
+       }
+
+       if (enable && result == BLUETOOTH_ERROR_NONE) {
+               /* Adapter enable request is successful, setup event handlers */
+               _bt_service_register_event_handler_callback(
+                               BT_ADAPTER_LE_MODULE, __bt_le_event_handler);
+               _bt_device_state_handle_callback_set_request();
+       }
+       return result;
+}
+
+int _bt_enable_adapter_le(void)
+{
+       return __bt_le_state_handle_request(TRUE);
+}
+
+int _bt_disable_adapter_le(void)
+{
+       return __bt_le_state_handle_request(FALSE);
+}
+
+
 static gboolean __bt_is_factory_test_mode(void)
 {
        int mode = 0;
index 02a891e..817b8e9 100644 (file)
@@ -93,7 +93,6 @@ static gboolean is_recovery_mode = FALSE;
 static gboolean is_discovering;
 static void *adapter_agent = NULL;
 static guint le_timer_id = 0;
-static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
 static uint status_reg_id;
 static void alarm_data_free(void *data);
 #endif
@@ -162,12 +161,6 @@ int _bt_enable_core(void)
        return BLUETOOTH_ERROR_NOT_SUPPORT;
 }
 
-int _bt_enable_adapter_le(void)
-{
-       /* TODO_40 : 4.0 merge  */
-       return BLUETOOTH_ERROR_NOT_SUPPORT;
-}
-
 int _bt_recover_adapter(void)
 {
        /* TODO_40 : 4.0 merge  */
@@ -205,18 +198,6 @@ gboolean _bt_is_discovering(void)
        else
                return FALSE;
 }
-#ifdef TIZEN_FEATURE_BT_OBEX
-void _bt_adapter_set_le_status(bt_le_status_t status)
-{
-       BT_INFO("adapter_le_status changed [%d] -> [%d]", adapter_le_status, status);
-       adapter_le_status = status;
-}
-
-bt_le_status_t _bt_adapter_get_le_status(void)
-{
-       return adapter_le_status;
-}
-#endif
 
 int _bt_get_local_address(void)
 {
@@ -1636,7 +1617,7 @@ void _bt_set_disabled(int result)
        _bt_set_discovery_status(FALSE);
 
        if (!TIZEN_FEATURE_BT_USB_DONGLE &&
-            _bt_adapter_get_le_status() != BT_LE_DEACTIVATED) {
+            _bt_adapter_get_le_state() != BT_LE_DEACTIVATED) {
                /* Send disabled event */
                _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
                                g_variant_new("(i)", result));
@@ -1726,7 +1707,7 @@ void _bt_handle_adapter_added(void)
        int ret;
 
        status = _bt_adapter_get_status();
-       le_status = _bt_adapter_get_le_status();
+       le_status = _bt_adapter_get_le_state();
        BT_DBG("status : %d", status);
        BT_DBG("le_status : %d", le_status);
 
index a300657..5878ab6 100644 (file)
@@ -66,6 +66,8 @@ GSList *invocation_list = NULL;
 static GDBusConnection *bt_service_conn;
 static guint owner_id = 0;
 static guint owner_sig_id = 0;
+static gboolean is_le_intended = FALSE;
+
 
 static cynara *p_cynara;
 static cynara_configuration *conf;
@@ -167,6 +169,11 @@ void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
 
 }
 
+void _bt_set_le_intended_status(gboolean value)
+{
+       is_le_intended = value;
+}
+
 static void __bt_service_get_parameters(GVariant *in_param,
                void *value, int size)
 {
@@ -411,6 +418,14 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+       case BT_ENABLE_ADAPTER_LE:
+               _bt_set_le_intended_status(TRUE);
+               result = _bt_enable_adapter_le();
+               break;
+       case BT_DISABLE_ADAPTER_LE:
+               _bt_set_le_intended_status(FALSE);
+               result = _bt_disable_adapter_le();
+               break;
        case BT_START_DISCOVERY: {
                unsigned short max_response;
                unsigned short discovery_duration;
index 22e959b..652184d 100644 (file)
@@ -293,6 +293,8 @@ static gboolean __bt_handle_oal_events(gpointer data)
                if(avrcp_ctrl_cb)
                        avrcp_ctrl_cb(event_type, event_data);
                break;
+       case OAL_EVENT_BLE_ENABLED:
+       case OAL_EVENT_BLE_DISABLED:
        case OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED:
        case OAL_EVENT_BLE_ADVERTISING_STARTED:
        case OAL_EVENT_BLE_ADVERTISING_STOPPED:
index 21a9912..53ff037 100644 (file)
@@ -36,6 +36,9 @@
 #include "bt-service-util.h"
 
 #include "bt-service-core-adapter.h"
+#include "bt-service-core-adapter-le.h"
+
+
 
 /* OAL headers */
 #include <oal-event.h>
@@ -77,7 +80,7 @@ static gboolean __bt_check_bt_service(void *data)
 #endif
 
        status = _bt_adapter_get_status();
-       le_status = _bt_adapter_get_le_status();
+       le_status = _bt_adapter_get_le_state();
        BT_DBG("State: %d, LE State: %d", status, le_status);
 
        if (TIZEN_PROFILE_TV) {
@@ -127,7 +130,7 @@ static gboolean __bt_check_bt_service(void *data)
                        _bt_enable_adapter_le();
                } else {
                        status = _bt_adapter_get_status();
-                       le_status = _bt_adapter_get_le_status();
+                       le_status = _bt_adapter_get_le_state();
                        BT_DBG("State: %d, LE State: %d", status, le_status);
 
                        if ((status != BT_ACTIVATING && status != BT_ACTIVATED) &&
index b677853..4d6a6bf 100644 (file)
 extern "C" {
 #endif
 
+typedef enum {
+        LE_DISCOVERY_STOPPED,
+        LE_DISCOVERY_STARTED,
+        LE_DISCOVERY_STARTING,
+        LE_DISCOVERY_STOPPING,
+} bt_le_discovery_state_t;
+
+typedef enum {
+       BT_LE_DEACTIVATED,
+       BT_LE_ACTIVATED,
+       BT_LE_ACTIVATING,
+       BT_LE_DEACTIVATING,
+} bt_le_status_t;
+
+int _bt_enable_adapter_le(void);
+
+int _bt_disable_adapter_le(void);
+
 int _bt_le_init(void);
 
 void _bt_le_deinit(void);
@@ -55,6 +73,11 @@ gboolean _bt_is_le_scanning(void);
 
 void _bt_check_le_scanner_app_termination(const char *sender);
 
+void _bt_adapter_set_le_status(bt_le_status_t status);
+
+bt_le_status_t _bt_adapter_get_le_state(void);
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
old mode 100755 (executable)
new mode 100644 (file)
index 88b7764..5cd46e4
@@ -42,14 +42,6 @@ typedef enum {
        BT_ACTIVATING,
        BT_DEACTIVATING,
 } bt_status_t;
-#ifdef TIZEN_FEATURE_BT_OBEX
-typedef enum {
-       BT_LE_DEACTIVATED,
-       BT_LE_ACTIVATED,
-       BT_LE_ACTIVATING,
-       BT_LE_DEACTIVATING,
-} bt_le_status_t;
-#endif
 
 int _bt_enable_adapter(void);
 
@@ -57,8 +49,6 @@ int _bt_disable_adapter(void);
 
 int _bt_enable_core(void);
 
-int _bt_enable_adapter_le(void);
-
 int _bt_recover_adapter(void);
 
 int _bt_start_discovery(unsigned short max_response,
@@ -102,10 +92,6 @@ void _bt_adapter_set_status(bt_status_t status);
 
 bt_status_t _bt_adapter_get_status(void);
 
-void _bt_adapter_set_le_status(bt_le_status_t status);
-
-bt_le_status_t _bt_adapter_get_le_status(void);
-
 void _bt_set_disabled(int result);
 
 typedef int (*bt_set_alarm_cb) (alarm_id_t alarm_id, void* user_param);