mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-06 12:39:51 +00:00
hci: extract hci_power_transition_to_halting, try to wait for disconnection complete event
This commit is contained in:
parent
22df2fe23a
commit
184dbe2ff5
31
src/hci.c
31
src/hci.c
@ -4139,6 +4139,16 @@ static void hci_power_transition_to_initializing(void){
|
|||||||
hci_stack->substate = HCI_INIT_SEND_RESET;
|
hci_stack->substate = HCI_INIT_SEND_RESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_power_transition_to_halting(void){
|
||||||
|
// see hci_run
|
||||||
|
hci_stack->state = HCI_STATE_HALTING;
|
||||||
|
hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_TIMER;
|
||||||
|
// setup watchdog timer for disconnect - only triggers if Controller does not respond anymore
|
||||||
|
btstack_run_loop_set_timer(&hci_stack->timeout, 1000);
|
||||||
|
btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_halting_timeout_handler);
|
||||||
|
btstack_run_loop_add_timer(&hci_stack->timeout);
|
||||||
|
}
|
||||||
|
|
||||||
// returns error
|
// returns error
|
||||||
static int hci_power_control_state_off(HCI_POWER_MODE power_mode){
|
static int hci_power_control_state_off(HCI_POWER_MODE power_mode){
|
||||||
int err;
|
int err;
|
||||||
@ -4190,13 +4200,7 @@ static int hci_power_control_state_working(HCI_POWER_MODE power_mode) {
|
|||||||
// do nothing
|
// do nothing
|
||||||
break;
|
break;
|
||||||
case HCI_POWER_OFF:
|
case HCI_POWER_OFF:
|
||||||
// see hci_run
|
hci_power_transition_to_halting();
|
||||||
hci_stack->state = HCI_STATE_HALTING;
|
|
||||||
hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_NO_TIMER;
|
|
||||||
// setup watchdog timer for disconnect - only triggers if Controller does not respond anymore
|
|
||||||
btstack_run_loop_set_timer(&hci_stack->timeout, 1000);
|
|
||||||
btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_halting_timeout_handler);
|
|
||||||
btstack_run_loop_add_timer(&hci_stack->timeout);
|
|
||||||
break;
|
break;
|
||||||
case HCI_POWER_SLEEP:
|
case HCI_POWER_SLEEP:
|
||||||
// see hci_run
|
// see hci_run
|
||||||
@ -4236,9 +4240,7 @@ static int hci_power_control_state_falling_asleep(HCI_POWER_MODE power_mode) {
|
|||||||
hci_power_transition_to_initializing();
|
hci_power_transition_to_initializing();
|
||||||
break;
|
break;
|
||||||
case HCI_POWER_OFF:
|
case HCI_POWER_OFF:
|
||||||
// see hci_run
|
hci_power_transition_to_halting();
|
||||||
hci_stack->state = HCI_STATE_HALTING;
|
|
||||||
hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_NO_TIMER;
|
|
||||||
break;
|
break;
|
||||||
case HCI_POWER_SLEEP:
|
case HCI_POWER_SLEEP:
|
||||||
// do nothing
|
// do nothing
|
||||||
@ -4259,8 +4261,7 @@ static int hci_power_control_state_sleeping(HCI_POWER_MODE power_mode) {
|
|||||||
hci_power_transition_to_initializing();
|
hci_power_transition_to_initializing();
|
||||||
break;
|
break;
|
||||||
case HCI_POWER_OFF:
|
case HCI_POWER_OFF:
|
||||||
hci_stack->state = HCI_STATE_HALTING;
|
hci_power_transition_to_halting();
|
||||||
hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_NO_TIMER;
|
|
||||||
break;
|
break;
|
||||||
case HCI_POWER_SLEEP:
|
case HCI_POWER_SLEEP:
|
||||||
// do nothing
|
// do nothing
|
||||||
@ -4339,12 +4340,6 @@ static void hci_halting_run(void) {
|
|||||||
|
|
||||||
log_info("HCI_STATE_HALTING, connection %p, handle %u", connection, con_handle);
|
log_info("HCI_STATE_HALTING, connection %p, handle %u", connection, con_handle);
|
||||||
|
|
||||||
// cancel all l2cap connections right away instead of waiting for disconnection complete event ...
|
|
||||||
hci_emit_disconnection_complete(con_handle, 0x16); // terminated by local host
|
|
||||||
|
|
||||||
// ... which would be ignored anyway as we shutdown (free) the connection now
|
|
||||||
hci_shutdown_connection(connection);
|
|
||||||
|
|
||||||
// finally, send the disconnect command
|
// finally, send the disconnect command
|
||||||
hci_send_cmd(&hci_disconnect, con_handle, ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION);
|
hci_send_cmd(&hci_disconnect, con_handle, ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user