[OAL] Add support for 'Reset Adapter'
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-adapter-mgr.c
old mode 100755 (executable)
new mode 100644 (file)
index 7f26147..7bc9d71
@@ -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,7 +163,100 @@ oal_status_t adapter_disable(void)
        return OAL_STATUS_SUCCESS;
 }
 
-oal_status_t adapter_start_inquiry(void)
+oal_status_t le_enable(void)
+{
+       int ret = BT_STATUS_SUCCESS;
+
+       API_TRACE();
+       CHECK_OAL_INITIALIZED();
+
+#ifdef TIZEN_BT_HAL
+       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);
+       }
+#else
+       BT_INFO("Not Supported");
+       ret = OAL_STATUS_NOT_SUPPORT;
+#endif
+
+       return ret;
+}
+
+oal_status_t le_disable(void)
+{
+       int ret;
+
+       API_TRACE();
+
+       CHECK_OAL_INITIALIZED();
+
+#ifdef TIZEN_BT_HAL
+       ret = blued_api->le_disable();
+
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("Disable failed: [%s]", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+#else
+       BT_INFO("Not Supported");
+       ret = OAL_STATUS_NOT_SUPPORT;
+#endif
+       return ret;
+}
+
+oal_status_t adapter_start_custom_inquiry(discovery_type_t disc_type)
+{
+       int ret;
+
+       API_TRACE();
+
+       CHECK_OAL_INITIALIZED();
+       BT_INFO("Custom Discovery Type [0x%x]", disc_type);
+
+#ifdef TIZEN_BT_HAL
+       ret = blued_api->start_custom_discovery(disc_type);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("start_custom_discovery failed: [%s]", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+#else
+       BT_INFO("Not Supported");
+       ret = OAL_STATUS_NOT_SUPPORT;
+#endif
+       return ret;
+}
+
+oal_status_t adapter_reset(void)
+{
+       int ret;
+
+       API_TRACE();
+
+       CHECK_OAL_INITIALIZED();
+       BT_INFO("Adapter Reset");
+
+#ifdef TIZEN_BT_HAL
+       ret = blued_api->reset();
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("Adapter Reset failed: [%s]", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+#else
+       BT_INFO("Not Supported");
+       ret = OAL_STATUS_NOT_SUPPORT;
+#endif
+       return ret;
+}
+
+oal_status_t adapter_start_inquiry(unsigned short duration)
 {
        int ret;
 
@@ -203,12 +301,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;