From a6ddbcb91c0a0832fd25509d300a30dd97e46749 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 22 Mar 2016 22:15:59 +0100 Subject: [PATCH] hci: re-add local version information callback for dynamic chipset configuration --- port/posix-h4/main.c | 13 +++---------- src/hci.c | 12 ++++++++++++ src/hci.h | 9 +++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/port/posix-h4/main.c b/port/posix-h4/main.c index 52869c226..e2c314347 100644 --- a/port/posix-h4/main.c +++ b/port/posix-h4/main.c @@ -75,8 +75,6 @@ static hci_transport_config_uart_t config = { NULL, }; -static btstack_packet_callback_registration_t hci_event_callback_registration; - static void sigint_handler(int param){ #ifndef _WIN32 @@ -101,11 +99,7 @@ static void using_921600_baud(void){ config.baudrate_main = 921600; } -static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){ - - if (packet_type != HCI_EVENT_PACKET) return; - if (!HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_version_information)) return; - +static void local_version_information_callback(uint8_t * packet){ printf("Local version information:\n"); uint16_t hci_version = little_endian_read_16(packet, 4); uint16_t hci_revision = little_endian_read_16(packet, 6); @@ -165,9 +159,8 @@ int main(int argc, const char * argv[]){ hci_init(transport, (void*) &config); hci_set_link_key_db(link_key_db); - // register for HCI events - hci_event_callback_registration.callback = &hci_event_handler; - hci_add_event_handler(&hci_event_callback_registration); + // setup dynamic chipset driver setup + hci_set_local_version_information_callback(&local_version_information_callback); // handle CTRL-c signal(SIGINT, sigint_handler); diff --git a/src/hci.c b/src/hci.c index 6686c4ab7..0d26bfad9 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1399,6 +1399,10 @@ static void event_handler(uint8_t *packet, int size){ hci_stack->manufacturer = little_endian_read_16(packet, 10); // hci_stack->lmp_subversion = little_endian_read_16(packet, 12); log_info("Manufacturer: 0x%04x", hci_stack->manufacturer); + // notify app + if (hci_stack->local_version_information_callback){ + hci_stack->local_version_information_callback(packet); + } } if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_supported_commands)){ hci_stack->local_supported_commands[0] = @@ -3553,6 +3557,14 @@ void hci_set_hardware_error_callback(void (*fn)(void)){ hci_stack->hardware_error_callback = fn; } +/** + * @brief Set callback for local information from Bluetooth controller right after HCI Reset + * @note Can be used to select chipset driver dynamically during startup + */ +void hci_set_local_version_information_callback(void (*fn)(uint8_t * local_version_information)){ + hci_stack->local_version_information_callback = fn; +} + void hci_disconnect_all(void){ btstack_linked_list_iterator_t it; btstack_linked_list_iterator_init(&it, &hci_stack->connections); diff --git a/src/hci.h b/src/hci.h index fcd1e1e5b..16c6a3de6 100644 --- a/src/hci.h +++ b/src/hci.h @@ -546,6 +546,9 @@ typedef struct { /* callbacks for events */ btstack_linked_list_t event_handlers; + // local version information callback + void (*local_version_information_callback)(uint8_t * local_version_information); + // hardware error callback void (*hardware_error_callback)(void); @@ -697,6 +700,12 @@ void hci_set_class_of_device(uint32_t class_of_device); */ void hci_set_hardware_error_callback(void (*fn)(void)); +/** + * @brief Set callback for local information from Bluetooth controller right after HCI Reset + * @note Can be used to select chipset driver dynamically during startup + */ +void hci_set_local_version_information_callback(void (*fn)(uint8_t * local_version_information)); + /** * @brief Set Public BD ADDR - passed on to Bluetooth chipset during init if supported in bt_control_h */