mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-05 18:40:27 +00:00
hci: extract hci_initializing_event_handler_command_completed
This commit is contained in:
parent
55573af2da
commit
07fd2f3183
36
src/hci.c
36
src/hci.c
@ -1535,16 +1535,12 @@ static void hci_init_done(void){
|
|||||||
hci_run();
|
hci_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
static bool hci_initializing_event_handler_command_completed(const uint8_t * packet){
|
||||||
|
bool command_completed = false;
|
||||||
UNUSED(size); // ok: less than 6 bytes are read from our buffer
|
|
||||||
|
|
||||||
uint8_t command_completed = 0;
|
|
||||||
|
|
||||||
if (hci_event_packet_get_type(packet) == HCI_EVENT_COMMAND_COMPLETE){
|
if (hci_event_packet_get_type(packet) == HCI_EVENT_COMMAND_COMPLETE){
|
||||||
uint16_t opcode = little_endian_read_16(packet,3);
|
uint16_t opcode = little_endian_read_16(packet,3);
|
||||||
if (opcode == hci_stack->last_cmd_opcode){
|
if (opcode == hci_stack->last_cmd_opcode){
|
||||||
command_completed = 1;
|
command_completed = true;
|
||||||
log_debug("Command complete for expected opcode %04x at substate %u", opcode, hci_stack->substate);
|
log_debug("Command complete for expected opcode %04x at substate %u", opcode, hci_stack->substate);
|
||||||
} else {
|
} else {
|
||||||
log_info("Command complete for different opcode %04x, expected %04x, at substate %u", opcode, hci_stack->last_cmd_opcode, hci_stack->substate);
|
log_info("Command complete for different opcode %04x, expected %04x, at substate %u", opcode, hci_stack->last_cmd_opcode, hci_stack->substate);
|
||||||
@ -1556,7 +1552,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
|||||||
uint16_t opcode = little_endian_read_16(packet,4);
|
uint16_t opcode = little_endian_read_16(packet,4);
|
||||||
if (opcode == hci_stack->last_cmd_opcode){
|
if (opcode == hci_stack->last_cmd_opcode){
|
||||||
if (status){
|
if (status){
|
||||||
command_completed = 1;
|
command_completed = true;
|
||||||
log_debug("Command status error 0x%02x for expected opcode %04x at substate %u", status, opcode, hci_stack->substate);
|
log_debug("Command status error 0x%02x for expected opcode %04x at substate %u", status, opcode, hci_stack->substate);
|
||||||
} else {
|
} else {
|
||||||
log_info("Command status OK for expected opcode %04x, waiting for command complete", opcode);
|
log_info("Command status OK for expected opcode %04x, waiting for command complete", opcode);
|
||||||
@ -1565,22 +1561,32 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
|||||||
log_debug("Command status for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode);
|
log_debug("Command status for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||||
|
|
||||||
// Vendor == CSR
|
// Vendor == CSR
|
||||||
if ((hci_stack->substate == HCI_INIT_W4_CUSTOM_INIT) && (hci_event_packet_get_type(packet) == HCI_EVENT_VENDOR_SPECIFIC)){
|
if ((hci_stack->substate == HCI_INIT_W4_CUSTOM_INIT) && (hci_event_packet_get_type(packet) == HCI_EVENT_VENDOR_SPECIFIC)){
|
||||||
// TODO: track actual command
|
// TODO: track actual command
|
||||||
command_completed = 1;
|
command_completed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vendor == Toshiba
|
// Vendor == Toshiba
|
||||||
if ((hci_stack->substate == HCI_INIT_W4_SEND_BAUD_CHANGE) && (hci_event_packet_get_type(packet) == HCI_EVENT_VENDOR_SPECIFIC)){
|
if ((hci_stack->substate == HCI_INIT_W4_SEND_BAUD_CHANGE) && (hci_event_packet_get_type(packet) == HCI_EVENT_VENDOR_SPECIFIC)){
|
||||||
// TODO: track actual command
|
// TODO: track actual command
|
||||||
command_completed = 1;
|
command_completed = true;
|
||||||
// Fix: no HCI Command Complete received, so num_cmd_packets not reset
|
// Fix: no HCI Command Complete received, so num_cmd_packets not reset
|
||||||
hci_stack->num_cmd_packets = 1;
|
hci_stack->num_cmd_packets = 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return command_completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hci_initializing_event_handler(const uint8_t * packet, uint16_t size){
|
||||||
|
|
||||||
|
UNUSED(size); // ok: less than 6 bytes are read from our buffer
|
||||||
|
|
||||||
|
bool command_completed = hci_initializing_event_handler_command_completed(packet);
|
||||||
|
|
||||||
|
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||||
|
|
||||||
// Late response (> 100 ms) for HCI Reset e.g. on Toshiba TC35661:
|
// Late response (> 100 ms) for HCI Reset e.g. on Toshiba TC35661:
|
||||||
// Command complete for HCI Reset arrives after we've resent the HCI Reset command
|
// Command complete for HCI Reset arrives after we've resent the HCI Reset command
|
||||||
@ -1637,8 +1643,8 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
|||||||
|
|
||||||
if (!command_completed) return;
|
if (!command_completed) return;
|
||||||
|
|
||||||
int need_baud_change = 0;
|
bool need_baud_change = false;
|
||||||
int need_addr_change = 0;
|
bool need_addr_change = false;
|
||||||
|
|
||||||
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
|
||||||
need_baud_change = hci_stack->config
|
need_baud_change = hci_stack->config
|
||||||
@ -1665,7 +1671,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
|||||||
btstack_run_loop_remove_timer(&hci_stack->timeout);
|
btstack_run_loop_remove_timer(&hci_stack->timeout);
|
||||||
break;
|
break;
|
||||||
case HCI_INIT_W4_SEND_READ_LOCAL_NAME:
|
case HCI_INIT_W4_SEND_READ_LOCAL_NAME:
|
||||||
log_info("Received local name, need baud change %d", need_baud_change);
|
log_info("Received local name, need baud change %d", (int) need_baud_change);
|
||||||
if (need_baud_change){
|
if (need_baud_change){
|
||||||
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE;
|
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE;
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user