hci.c (22df2fe23a982f04bc7d9cea1706c93ab2f4706a) | hci.c (184dbe2ff5e6ecd28e4dbb9072fce8524e024f1e) |
---|---|
1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 4125 unchanged lines hidden (view full) --- 4134static void hci_power_transition_to_initializing(void){ 4135 // set up state machine 4136 hci_stack->num_cmd_packets = 1; // assume that one cmd can be sent 4137 hci_stack->hci_packet_buffer_reserved = false; 4138 hci_stack->state = HCI_STATE_INITIALIZING; 4139 hci_stack->substate = HCI_INIT_SEND_RESET; 4140} 4141 | 1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 4125 unchanged lines hidden (view full) --- 4134static void hci_power_transition_to_initializing(void){ 4135 // set up state machine 4136 hci_stack->num_cmd_packets = 1; // assume that one cmd can be sent 4137 hci_stack->hci_packet_buffer_reserved = false; 4138 hci_stack->state = HCI_STATE_INITIALIZING; 4139 hci_stack->substate = HCI_INIT_SEND_RESET; 4140} 4141 |
4142static void hci_power_transition_to_halting(void){ 4143 // see hci_run 4144 hci_stack->state = HCI_STATE_HALTING; 4145 hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_TIMER; 4146 // setup watchdog timer for disconnect - only triggers if Controller does not respond anymore 4147 btstack_run_loop_set_timer(&hci_stack->timeout, 1000); 4148 btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_halting_timeout_handler); 4149 btstack_run_loop_add_timer(&hci_stack->timeout); 4150} 4151 |
|
4142// returns error 4143static int hci_power_control_state_off(HCI_POWER_MODE power_mode){ 4144 int err; 4145 switch (power_mode){ 4146 case HCI_POWER_ON: 4147 err = hci_power_control_on(); 4148 if (err != 0) { 4149 log_error("hci_power_control_on() error %d", err); --- 35 unchanged lines hidden (view full) --- 4185} 4186 4187static int hci_power_control_state_working(HCI_POWER_MODE power_mode) { 4188 switch (power_mode){ 4189 case HCI_POWER_ON: 4190 // do nothing 4191 break; 4192 case HCI_POWER_OFF: | 4152// returns error 4153static int hci_power_control_state_off(HCI_POWER_MODE power_mode){ 4154 int err; 4155 switch (power_mode){ 4156 case HCI_POWER_ON: 4157 err = hci_power_control_on(); 4158 if (err != 0) { 4159 log_error("hci_power_control_on() error %d", err); --- 35 unchanged lines hidden (view full) --- 4195} 4196 4197static int hci_power_control_state_working(HCI_POWER_MODE power_mode) { 4198 switch (power_mode){ 4199 case HCI_POWER_ON: 4200 // do nothing 4201 break; 4202 case HCI_POWER_OFF: |
4193 // see hci_run 4194 hci_stack->state = HCI_STATE_HALTING; 4195 hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_NO_TIMER; 4196 // setup watchdog timer for disconnect - only triggers if Controller does not respond anymore 4197 btstack_run_loop_set_timer(&hci_stack->timeout, 1000); 4198 btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_halting_timeout_handler); 4199 btstack_run_loop_add_timer(&hci_stack->timeout); | 4203 hci_power_transition_to_halting(); |
4200 break; 4201 case HCI_POWER_SLEEP: 4202 // see hci_run 4203 hci_stack->state = HCI_STATE_FALLING_ASLEEP; 4204 hci_stack->substate = HCI_FALLING_ASLEEP_DISCONNECT; 4205 break; 4206 default: 4207 btstack_assert(false); --- 23 unchanged lines hidden (view full) --- 4231} 4232 4233static int hci_power_control_state_falling_asleep(HCI_POWER_MODE power_mode) { 4234 switch (power_mode){ 4235 case HCI_POWER_ON: 4236 hci_power_transition_to_initializing(); 4237 break; 4238 case HCI_POWER_OFF: | 4204 break; 4205 case HCI_POWER_SLEEP: 4206 // see hci_run 4207 hci_stack->state = HCI_STATE_FALLING_ASLEEP; 4208 hci_stack->substate = HCI_FALLING_ASLEEP_DISCONNECT; 4209 break; 4210 default: 4211 btstack_assert(false); --- 23 unchanged lines hidden (view full) --- 4235} 4236 4237static int hci_power_control_state_falling_asleep(HCI_POWER_MODE power_mode) { 4238 switch (power_mode){ 4239 case HCI_POWER_ON: 4240 hci_power_transition_to_initializing(); 4241 break; 4242 case HCI_POWER_OFF: |
4239 // see hci_run 4240 hci_stack->state = HCI_STATE_HALTING; 4241 hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_NO_TIMER; | 4243 hci_power_transition_to_halting(); |
4242 break; 4243 case HCI_POWER_SLEEP: 4244 // do nothing 4245 break; 4246 default: 4247 btstack_assert(false); 4248 break; 4249 } --- 4 unchanged lines hidden (view full) --- 4254 int err; 4255 switch (power_mode){ 4256 case HCI_POWER_ON: 4257 err = hci_power_control_wake(); 4258 if (err) return err; 4259 hci_power_transition_to_initializing(); 4260 break; 4261 case HCI_POWER_OFF: | 4244 break; 4245 case HCI_POWER_SLEEP: 4246 // do nothing 4247 break; 4248 default: 4249 btstack_assert(false); 4250 break; 4251 } --- 4 unchanged lines hidden (view full) --- 4256 int err; 4257 switch (power_mode){ 4258 case HCI_POWER_ON: 4259 err = hci_power_control_wake(); 4260 if (err) return err; 4261 hci_power_transition_to_initializing(); 4262 break; 4263 case HCI_POWER_OFF: |
4262 hci_stack->state = HCI_STATE_HALTING; 4263 hci_stack->substate = HCI_HALTING_DISCONNECT_ALL_NO_TIMER; | 4264 hci_power_transition_to_halting(); |
4264 break; 4265 case HCI_POWER_SLEEP: 4266 // do nothing 4267 break; 4268 default: 4269 btstack_assert(false); 4270 break; 4271 } --- 62 unchanged lines hidden (view full) --- 4334 if (!hci_can_send_command_packet_now()) return; 4335 4336 // check state 4337 if (connection->state == SENT_DISCONNECT) return; 4338 connection->state = SENT_DISCONNECT; 4339 4340 log_info("HCI_STATE_HALTING, connection %p, handle %u", connection, con_handle); 4341 | 4265 break; 4266 case HCI_POWER_SLEEP: 4267 // do nothing 4268 break; 4269 default: 4270 btstack_assert(false); 4271 break; 4272 } --- 62 unchanged lines hidden (view full) --- 4335 if (!hci_can_send_command_packet_now()) return; 4336 4337 // check state 4338 if (connection->state == SENT_DISCONNECT) return; 4339 connection->state = SENT_DISCONNECT; 4340 4341 log_info("HCI_STATE_HALTING, connection %p, handle %u", connection, con_handle); 4342 |
4342 // cancel all l2cap connections right away instead of waiting for disconnection complete event ... 4343 hci_emit_disconnection_complete(con_handle, 0x16); // terminated by local host 4344 4345 // ... which would be ignored anyway as we shutdown (free) the connection now 4346 hci_shutdown_connection(connection); 4347 | |
4348 // finally, send the disconnect command 4349 hci_send_cmd(&hci_disconnect, con_handle, ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION); 4350 return; 4351 } 4352 4353 btstack_run_loop_remove_timer(&hci_stack->timeout); 4354 4355 if (hci_stack->substate == HCI_HALTING_DISCONNECT_ALL_TIMER) { --- 3466 unchanged lines hidden --- | 4343 // finally, send the disconnect command 4344 hci_send_cmd(&hci_disconnect, con_handle, ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION); 4345 return; 4346 } 4347 4348 btstack_run_loop_remove_timer(&hci_stack->timeout); 4349 4350 if (hci_stack->substate == HCI_HALTING_DISCONNECT_ALL_TIMER) { --- 3466 unchanged lines hidden --- |