int _bt_enable_adapter(void)
{
+ bt_le_status_t le_status = BT_LE_DEACTIVATED;
+
+ le_status = _bt_adapter_get_le_status();
+
+ BT_INFO("Current state [%d], LE [%d]", adapter_state, le_status);
+
+ if (adapter_state == BT_ACTIVATING || le_status == BT_LE_ACTIVATING) {
+ BT_ERR("Enabling in progress");
+ return BLUETOOTH_ERROR_IN_PROGRESS;
+ }
+
+ if (adapter_state == BT_ACTIVATED) {
+ BT_ERR("Already enabled");
+ return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
+ }
+
+ if (adapter_state == BT_DEACTIVATING ||
+ adapter_state == BT_TERMINATING ||
+ le_status == BT_LE_DEACTIVATING) {
+ BT_ERR("Disabling in progress");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
return __bt_adapter_state_handle_request(TRUE);
}
int _bt_disable_adapter(void)
{
+ bt_le_status_t le_status = BT_LE_DEACTIVATED;
+
+ le_status = _bt_adapter_get_le_status();
+
+ BT_INFO("Current state [%d], LE [%d]", adapter_state, le_status);
+
+ if (adapter_state == BT_DEACTIVATING ||
+ adapter_state == BT_TERMINATING ||
+ le_status == BT_LE_DEACTIVATING) {
+ BT_DBG("Disabling in progress");
+ return BLUETOOTH_ERROR_IN_PROGRESS;
+ }
+
+ if (adapter_state == BT_DEACTIVATED) {
+ BT_DBG("Already disabled");
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ if (adapter_state == BT_ACTIVATING || le_status == BT_LE_ACTIVATING) {
+ BT_ERR("Enabling in progress");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
+ /* TODO: Need to add the function to disconnect all devices */
+ /* __bt_disconnect_all(); */
+
return __bt_adapter_state_handle_request(FALSE);
}
switch (bt_status) {
case BT_DEACTIVATED:
- __bt_adapter_state_set_status(bt_status);
+ __bt_adapter_state_set_status(BT_TERMINATING);
/* Adapter is disabled, unregister event handlers */
_bt_service_unregister_event_handler_callback(BT_ADAPTER_MODULE);
BT_DBG("");
switch (adapter_state) {
- case BT_ACTIVATING: {
- BT_INFO("Adapter is currently in activating state, state [%d]",
- adapter_state);
- if (enable) {
- return BLUETOOTH_ERROR_IN_PROGRESS;
- } else {
- if (adapter_discovery_state == ADAPTER_DISCOVERY_STARTED ||
- adapter_discovery_state == ADAPTER_DISCOVERY_STARTING) {
- /*TODO Stop Discovery*/
- __bt_adapter_update_discovery_status(FALSE);
- }
- result = adapter_disable();
- if (result != OAL_STATUS_SUCCESS) {
- BT_ERR("adapter_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_state_set_status(BT_DEACTIVATING);
- result = BLUETOOTH_ERROR_NONE;
- }
- }
+ case BT_ACTIVATING:
+ case BT_DEACTIVATING:
+ BT_INFO("Should not be callded : state [%d]", adapter_state);
+ return BLUETOOTH_ERROR_INTERNAL;
break;
- }
case BT_ACTIVATED: {
BT_INFO("Adapter is currently in activated state, state [%d]",
adapter_state);
}
break;
}
- case BT_DEACTIVATING: {
- BT_INFO("Adapter is currently in deactivating state, state [%d]",
- adapter_state);
- if (!enable) {
- return BLUETOOTH_ERROR_IN_PROGRESS;
-
- } else {
- result = adapter_enable();
- if (result != OAL_STATUS_SUCCESS && result != OAL_STATUS_PENDING) {
- BT_ERR("adapter_enable failed: [%d]", result);
- adapter_disable();
- result = BLUETOOTH_ERROR_INTERNAL;
- /*TODO: perform if anything more needs to be done to handle failure */
- } else {
- /* TODO: To be handled */
- __bt_adapter_state_set_status(BT_ACTIVATING);
- result = BLUETOOTH_ERROR_NONE;
- }
- }
- break;
- }
case BT_DEACTIVATED: {
BT_INFO("Adapter is currently in deactivated state, state [%d]",
adapter_state);