From a2481739c9f24a46bd31634465fa507fc20b6818 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald@gmail.com" Date: Sun, 6 Jul 2014 22:21:34 +0000 Subject: [PATCH] prepare to move init sequence logic into hci_initializing_event_handler --- src/hci.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/hci.c b/src/hci.c index f6120696b..7c9b478dd 100644 --- a/src/hci.c +++ b/src/hci.c @@ -562,32 +562,40 @@ void le_handle_advertisement_report(uint8_t *packet, int size){ #endif static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){ - if (hci_stack->substate % 2){ - // odd: waiting for event - if (packet[0] == HCI_EVENT_COMMAND_COMPLETE){ - uint16_t opcode = READ_BT_16(packet,3); - if (opcode == hci_stack->last_cmd_opcode){ - hci_stack->substate++; - log_info("Command complete for expected opcode %04x -> new substate %u", opcode, hci_stack->substate); - } else { - log_info("Command complete for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode); - } + uint8_t command_completed = 0; + if ((hci_stack->substate % 2) == 0) return; + // odd: waiting for event + if (packet[0] == HCI_EVENT_COMMAND_COMPLETE){ + uint16_t opcode = READ_BT_16(packet,3); + if (opcode == hci_stack->last_cmd_opcode){ + command_completed = 1; + log_info("Command complete for expected opcode %04x -> new substate %u", opcode, hci_stack->substate); + } else { + log_info("Command complete for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode); } - if (packet[0] == HCI_EVENT_COMMAND_STATUS){ - uint8_t status = packet[2]; - uint16_t opcode = READ_BT_16(packet,4); - if (opcode == hci_stack->last_cmd_opcode){ - if (status){ - hci_stack->substate++; - log_error("Command status error 0x%02x for expected opcode %04x -> new substate %u", status, opcode, hci_stack->substate); - } else { - log_info("Command status OK for expected opcode %04x, waiting for command complete", opcode); - } + } + if (packet[0] == HCI_EVENT_COMMAND_STATUS){ + uint8_t status = packet[2]; + uint16_t opcode = READ_BT_16(packet,4); + if (opcode == hci_stack->last_cmd_opcode){ + if (status){ + command_completed = 1; + log_error("Command status error 0x%02x for expected opcode %04x -> new substate %u", status, opcode, hci_stack->substate); } else { - log_info("Command status for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode); + log_info("Command status OK for expected opcode %04x, waiting for command complete", opcode); } + } else { + log_info("Command status for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode); } } + + if (!command_completed) return; + + switch(hci_stack->substate >> 1){ + default: + hci_stack->substate++; + break; + } } static void hci_initializing_state_machine(){