From 2d5e09d6d414e68e1ff909778712418ffa26b5d0 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 11 Feb 2016 20:10:17 +0100 Subject: [PATCH] hci: set link_key_db via hci_set_link_key_db instead of via hci_init(). --- platform/daemon/daemon.c | 5 ++++- port/arduino/BTstack.cpp | 2 +- port/ez430-rf2560/src/main.c | 5 ++--- port/libusb/main.c | 4 ++-- .../example/hid_demo.c | 5 +++-- port/msp-exp430f5438-cc2564b/src/main.c | 5 ++--- port/msp430f5229lp-cc2564b/src/main.c | 5 ++--- port/pic32-harmony/src/btstack_port.c | 2 +- port/posix-h4/main.c | 3 ++- port/stm32-f103rb-nucleo/main.c | 5 ++--- port/wiced/main.c | 5 ++--- src/hci.c | 22 ++++++++++--------- src/hci.h | 7 +++++- test/ble_client/advertising_data_parser.c | 2 +- 14 files changed, 42 insertions(+), 35 deletions(-) diff --git a/platform/daemon/daemon.c b/platform/daemon/daemon.c index b5ad9edff..577eba981 100644 --- a/platform/daemon/daemon.c +++ b/platform/daemon/daemon.c @@ -2068,7 +2068,10 @@ int main (int argc, char * const * argv){ log_info("version %s, build %s", BTSTACK_VERSION, BTSTACK_DATE); // init HCI - hci_init(transport, config, btstack_link_key_db); + hci_init(transport, config) + if (btstack_link_key_db){ + hci_set_link_key_db(btstack_link_key_db); + } if (control){ hci_set_control(control); } diff --git a/port/arduino/BTstack.cpp b/port/arduino/BTstack.cpp index f9a6e750b..2597c96c4 100644 --- a/port/arduino/BTstack.cpp +++ b/port/arduino/BTstack.cpp @@ -746,7 +746,7 @@ void BTstackManager::setup(void){ btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); const hci_transport_t * transport = hci_transport_h4_instance(); - hci_init(transport, NULL, NULL); + hci_init(transport, NULL); hci_set_chipset(btstack_chipset_em9301_instance()); if (have_custom_addr){ diff --git a/port/ez430-rf2560/src/main.c b/port/ez430-rf2560/src/main.c index 2d450b03f..53852498e 100644 --- a/port/ez430-rf2560/src/main.c +++ b/port/ez430-rf2560/src/main.c @@ -98,9 +98,8 @@ int main(void) btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - const hci_transport_t * transport = hci_transport_h4_instance(); - remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, &config, remote_db); + hci_init(hci_transport_h4_instance(), &config); + hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); // use eHCILL diff --git a/port/libusb/main.c b/port/libusb/main.c index d8b1933fd..aaac6859f 100644 --- a/port/libusb/main.c +++ b/port/libusb/main.c @@ -91,8 +91,8 @@ int main(int argc, const char * argv[]){ hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI - const hci_transport_t * transport = hci_transport_usb_instance(); - hci_init(transport, NULL, btstack_link_key_db_fs_instance()); + hci_init(hci_transport_usb_instance(), NULL); + hci_set_link_key_db(btstack_link_key_db_fs_instance()); // handle CTRL-c signal(SIGINT, sigint_handler); diff --git a/port/msp-exp430f5438-cc2564b/example/hid_demo.c b/port/msp-exp430f5438-cc2564b/example/hid_demo.c index 3f99a735c..41982a5a2 100644 --- a/port/msp-exp430f5438-cc2564b/example/hid_demo.c +++ b/port/msp-exp430f5438-cc2564b/example/hid_demo.c @@ -378,8 +378,9 @@ int main(void){ // init HCI const hci_transport_t * transport = hci_transport_h4_instance(); - remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, &config, remote_db); + remote_device_db_t * link_key_db = (remote_device_db_t *) &remote_device_db_memory; + hci_init(transport, &config, link_key_db); + hci_set_link_key_db(link_key_db); hci_set_chipset(btstack_chipset_cc256x_instance()); // use eHCILL diff --git a/port/msp-exp430f5438-cc2564b/src/main.c b/port/msp-exp430f5438-cc2564b/src/main.c index 97d342b70..b6ba10694 100644 --- a/port/msp-exp430f5438-cc2564b/src/main.c +++ b/port/msp-exp430f5438-cc2564b/src/main.c @@ -98,9 +98,8 @@ static void btstack_setup(void){ btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - const hci_transport_t * transport = hci_transport_h4_instance(); - remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, &config, remote_db); + hci_init(hci_transport_h4_instance, &config); + hci_set_link_key_db(btstack_link_key_db_memory_instance); hci_set_chipset(btstack_chipset_cc256x_instance()); // use eHCILL diff --git a/port/msp430f5229lp-cc2564b/src/main.c b/port/msp430f5229lp-cc2564b/src/main.c index 260cac4ab..c6a7f1e0c 100644 --- a/port/msp430f5229lp-cc2564b/src/main.c +++ b/port/msp430f5229lp-cc2564b/src/main.c @@ -105,9 +105,8 @@ static void btstack_setup(void){ btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - const hci_transport_t * transport = hci_transport_h4_instance(); - remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, &config, remote_db); + hci_init(hci_transport_h4_instance, &config); + hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); // use eHCILL diff --git a/port/pic32-harmony/src/btstack_port.c b/port/pic32-harmony/src/btstack_port.c index be0072fd7..0af1092a7 100644 --- a/port/pic32-harmony/src/btstack_port.c +++ b/port/pic32-harmony/src/btstack_port.c @@ -226,7 +226,7 @@ void BTSTACK_Initialize ( void ) hci_dump_open(NULL, HCI_DUMP_STDOUT); const hci_transport_t * transport = hci_transport_h4_instance(); - hci_init(transport, &config, NULL); + hci_init(transport, &config); hci_set_chipset(btstack_chipset_csr_instance()); // hci_power_control(HCI_POWER_ON); diff --git a/port/posix-h4/main.c b/port/posix-h4/main.c index 632394a93..836abc935 100644 --- a/port/posix-h4/main.c +++ b/port/posix-h4/main.c @@ -162,7 +162,8 @@ int main(int argc, const char * argv[]){ // init HCI const hci_transport_t * transport = hci_transport_h4_instance(); const btstack_link_key_db_t * link_key_db = btstack_link_key_db_fs_instance(); - hci_init(transport, (void*) &config, link_key_db); + 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; diff --git a/port/stm32-f103rb-nucleo/main.c b/port/stm32-f103rb-nucleo/main.c index 5af4a45f2..624485af4 100644 --- a/port/stm32-f103rb-nucleo/main.c +++ b/port/stm32-f103rb-nucleo/main.c @@ -424,9 +424,8 @@ int main(void) btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - const hci_transport_t * transport = hci_transport_h4_instance(); - remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, (void*) &config, remote_db); + hci_init(hci_transport_h4_instance(), (void*) &config); + hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); // enable eHCILL diff --git a/port/wiced/main.c b/port/wiced/main.c index efce54eb4..adbe7f9c8 100644 --- a/port/wiced/main.c +++ b/port/wiced/main.c @@ -92,9 +92,8 @@ void application_start(void){ // hci_dump_open(NULL, HCI_DUMP_STDOUT); // init HCI - const hci_transport_t * transport = hci_transport_h4_instance(); - remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, (void*) &hci_transport_config_uart, remote_db); + hci_init(hci_transport_h4_instance, (void*) &hci_transport_config_uart); + hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_bcm_instance()); // use WIFI Mac address + 1 for Bluetooth diff --git a/src/hci.c b/src/hci.c index ca2fe4e61..3f1296558 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1880,7 +1880,18 @@ static void hci_state_reset(void){ hci_stack->le_connection_parameter_range.le_supervision_timeout_max = 3200; } -void hci_init(const hci_transport_t *transport, const void *config, btstack_link_key_db_t const * link_key_db){ +/** + * @brief Configure Bluetooth hardware control. Has to be called before power on. + */ +void hci_set_link_key_db(btstack_link_key_db_t const * link_key_db){ + // store and open remote device db + hci_stack->link_key_db = link_key_db; + if (hci_stack->link_key_db) { + hci_stack->link_key_db->open(); + } +} + +void hci_init(const hci_transport_t *transport, const void *config){ #ifdef HAVE_MALLOC if (!hci_stack) { @@ -1897,15 +1908,6 @@ void hci_init(const hci_transport_t *transport, const void *config, btstack_link // reference to used config hci_stack->config = config; - // init used hardware control with NULL - // init used chipset with NULL - - // store and open remote device db - hci_stack->link_key_db = link_key_db; - if (hci_stack->link_key_db) { - hci_stack->link_key_db->open(); - } - // max acl payload size defined in config.h hci_stack->acl_data_packet_length = HCI_ACL_PAYLOAD_SIZE; diff --git a/src/hci.h b/src/hci.h index c9aa3f552..db12c84a7 100644 --- a/src/hci.h +++ b/src/hci.h @@ -696,7 +696,7 @@ void hci_local_bd_addr(bd_addr_t address_buffer); /** * @brief Set up HCI. Needs to be called before any other function. */ -void hci_init(const hci_transport_t *transport, const void *config, btstack_link_key_db_t const * btstack_link_key_db); +void hci_init(const hci_transport_t *transport, const void *config); /** * @brief Configure Bluetooth chipset driver. Has to be called before power on, or right after receiving the local version information. @@ -708,6 +708,11 @@ void hci_set_chipset(const btstack_chipset_t *chipset_driver); */ void hci_set_control(const btstack_control_t *hardware_control); +/** + * @brief Configure Bluetooth hardware control. Has to be called before power on. + */ +void hci_set_link_key_db(btstack_link_key_db_t const * link_key_db); + /** * @brief Set class of device that will be set during Bluetooth init. */ diff --git a/test/ble_client/advertising_data_parser.c b/test/ble_client/advertising_data_parser.c index 543ad0767..572e1dde2 100644 --- a/test/ble_client/advertising_data_parser.c +++ b/test/ble_client/advertising_data_parser.c @@ -149,7 +149,7 @@ bool nameHasPrefix(const char * name_prefix, uint16_t data_length, uint8_t * dat TEST_GROUP(ADParser){ void setup(void){ - hci_init(&dummy_transport, NULL, NULL); + hci_init(&dummy_transport, NULL); hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); }