diff --git a/chipset/cc256x/bt_control_cc256x.c b/chipset/cc256x/bt_control_cc256x.c index 0bb0e7b75..1c059dc64 100644 --- a/chipset/cc256x/bt_control_cc256x.c +++ b/chipset/cc256x/bt_control_cc256x.c @@ -279,13 +279,6 @@ static const bt_control_t bt_control_cc256x = { NULL, // set_bd_addr_cmd }; -static const hci_uart_config_t hci_uart_config_cc256x = { - NULL, - 115200, - 1000000, - 0 -}; - // MARK: public API void bt_control_cc256x_enable_ehcill(int on){ @@ -302,7 +295,3 @@ void bt_control_cc256x_set_power(int16_t power_in_dB){ bt_control_t *bt_control_cc256x_instance(void){ return (bt_control_t*) &bt_control_cc256x; } - -hci_uart_config_t *hci_uart_config_cc256x_instance(void){ - return (hci_uart_config_t*) &hci_uart_config_cc256x; -} diff --git a/chipset/cc256x/bt_control_cc256x.h b/chipset/cc256x/bt_control_cc256x.h index 35d290ec9..7efa7b98e 100644 --- a/chipset/cc256x/bt_control_cc256x.h +++ b/chipset/cc256x/bt_control_cc256x.h @@ -57,8 +57,6 @@ void bt_control_cc256x_set_power(int16_t power_in_dB); void bt_control_cc256x_enable_ehcill(int on); int bt_control_cc256x_ehcill_enabled(void); -hci_uart_config_t *hci_uart_config_cc256x_instance(void); - #if defined __cplusplus } #endif diff --git a/chipset/csr/bt_control_csr.c b/chipset/csr/bt_control_csr.c index 8335ab6db..2a8ed2467 100644 --- a/chipset/csr/bt_control_csr.c +++ b/chipset/csr/bt_control_csr.c @@ -74,7 +74,7 @@ static int bt_control_csr_on(void *config){ } // set requested baud rate -static void bt_control_csr_update_command(hci_uart_config_t *config, uint8_t *hci_cmd_buffer){ +static void bt_control_csr_update_command(hci_transport_config_uart_t *config, uint8_t *hci_cmd_buffer){ uint16_t varid = READ_BT_16(hci_cmd_buffer, 10); if (varid != 0x7003) return; uint16_t key = READ_BT_16(hci_cmd_buffer, 14); @@ -104,7 +104,7 @@ static int bt_control_csr_next_cmd(void *config, uint8_t *hci_cmd_buffer){ memcpy(&hci_cmd_buffer[3], (uint8_t *) &init_script[init_script_offset], payload_len); // support for on-the-fly configuration updates - bt_control_csr_update_command((hci_uart_config_t*)config, hci_cmd_buffer); + bt_control_csr_update_command((hci_transport_config_uart_t*)config, hci_cmd_buffer); init_script_offset += payload_len; @@ -134,13 +134,6 @@ static const bt_control_t bt_control_csr = { NULL, // set_bd_addr_cmd }; -static const hci_uart_config_t hci_uart_config_csr = { - NULL, - 115200, - 0, // 1000000, - 0 -}; - // MARK: public API void bt_control_csr_set_power(int16_t power_in_dB){ } @@ -148,7 +141,3 @@ void bt_control_csr_set_power(int16_t power_in_dB){ bt_control_t *bt_control_csr_instance(void){ return (bt_control_t*) &bt_control_csr; } - -hci_uart_config_t *hci_uart_config_csr_instance(void){ - return (hci_uart_config_t*) &hci_uart_config_csr; -} diff --git a/chipset/csr/bt_control_csr.h b/chipset/csr/bt_control_csr.h index 481617350..ffae2b42c 100644 --- a/chipset/csr/bt_control_csr.h +++ b/chipset/csr/bt_control_csr.h @@ -54,7 +54,6 @@ extern "C" { bt_control_t * bt_control_csr_instance(void); void bt_control_csr_set_power(int16_t power_in_dB); -hci_uart_config_t *hci_uart_config_csr_instance(void); #if defined __cplusplus } diff --git a/platform/daemon/src/daemon.c b/platform/daemon/src/daemon.c index cef7fa764..3348ce239 100644 --- a/platform/daemon/src/daemon.c +++ b/platform/daemon/src/daemon.c @@ -173,7 +173,7 @@ static client_state_t * client_for_connection(connection_t *connection); // MARK: globals static hci_transport_t * transport; -static hci_uart_config_t config; +static hci_transport_config_uart_t hci_transport_config_uart; static timer_source_t timeout; static uint8_t timeout_active = 0; static int power_management_sleep = 0; @@ -1943,16 +1943,18 @@ int main (int argc, char * const * argv){ #endif bt_control_t * control = NULL; - + void * config; + #ifdef HAVE_TRANSPORT_H4 - config.device_name = UART_DEVICE; - config.baudrate_init = UART_SPEED; - config.baudrate_main = 0; - config.flowcontrol = 1; + hci_transport_config_uart.type = HCI_TRANSPORT_CONFIG_UART; + hci_transport_config_uart.baudrate_init = UART_SPEED; + hci_transport_config_uart.baudrate_main = 0; + hci_transport_config_uart.flowcontrol = 1; + hci_transport_config_uart.device_name = UART_DEVICE; #if defined(USE_BLUETOOL) && defined(USE_POWERMANAGEMENT) if (bt_control_iphone_power_management_supported()){ - // use default (max) UART baudrate over netraph interface - config.baudrate_init = 0; + // use default (max) UART baudrate over netgraph interface + hci_transport_config_uart.baudrate_init = 0; transport = hci_transport_h4_iphone_instance(); } else { transport = hci_transport_h4_instance(); @@ -1960,6 +1962,7 @@ int main (int argc, char * const * argv){ #else transport = hci_transport_h4_instance(); #endif + config = &hci_transport_config_uart; #endif #ifdef HAVE_TRANSPORT_USB @@ -2007,7 +2010,7 @@ int main (int argc, char * const * argv){ log_info("version %s, build %s", BTSTACK_VERSION, BTSTACK_DATE); // init HCI - hci_init(transport, &config, control, remote_device_db); + hci_init(transport, config, control, remote_device_db); #ifdef USE_BLUETOOL // iPhone doesn't use SSP yet as there's no UI for it yet and auto accept is not an option diff --git a/platform/posix/src/hci_transport_h4.c b/platform/posix/src/hci_transport_h4.c index e4ce63ba0..27a564fd5 100644 --- a/platform/posix/src/hci_transport_h4.c +++ b/platform/posix/src/hci_transport_h4.c @@ -63,7 +63,7 @@ static int h4_process(struct data_source *ds); static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size); -static hci_uart_config_t *hci_uart_config; +static hci_transport_config_uart_t *hci_transport_config_uart; typedef enum { H4_W4_PACKET_TYPE, @@ -133,13 +133,13 @@ static int h4_set_baudrate(uint32_t baudrate){ } static int h4_open(void *transport_config){ - hci_uart_config = (hci_uart_config_t*) transport_config; + hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config; struct termios toptions; int flags = O_RDWR | O_NOCTTY | O_NONBLOCK; - int fd = open(hci_uart_config->device_name, flags); + int fd = open(hci_transport_config_uart->device_name, flags); if (fd == -1) { perror("init_serialport: Unable to open port "); - perror(hci_uart_config->device_name); + perror(hci_transport_config_uart->device_name); return -1; } @@ -154,7 +154,7 @@ static int h4_open(void *transport_config){ toptions.c_cflag &= ~CSTOPB; toptions.c_cflag |= CS8; - if (hci_uart_config->flowcontrol) { + if (hci_transport_config_uart->flowcontrol) { // with flow control toptions.c_cflag |= CRTSCTS; } else { @@ -183,7 +183,7 @@ static int h4_open(void *transport_config){ run_loop_add_data_source(hci_transport_h4->ds); // also set baudrate - if (h4_set_baudrate(hci_uart_config->baudrate_init) < 0){ + if (h4_set_baudrate(hci_transport_config_uart->baudrate_init) < 0){ return -1; } diff --git a/platform/posix/src/hci_transport_h5.c b/platform/posix/src/hci_transport_h5.c index 796ac5a52..89e00c1d0 100644 --- a/platform/posix/src/hci_transport_h5.c +++ b/platform/posix/src/hci_transport_h5.c @@ -81,18 +81,18 @@ static hci_transport_h5_t * hci_transport_h5 = NULL; static int h5_process(struct data_source *ds); static void dummy_handler(uint8_t packet_type, uint8_t *packet, int size); -static hci_uart_config_t *hci_uart_config; +static hci_transport_config_uart_t *hci_transport_config_uart; static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, int size) = dummy_handler; // prototypes static int h5_open(void *transport_config){ - hci_uart_config = (hci_uart_config_t*) transport_config; + hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config; struct termios toptions; - int fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY); + int fd = open(hci_transport_config_uart->device_name, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { perror("init_serialport: Unable to open port "); - perror(hci_uart_config->device_name); + perror(hci_transport_config_uart->device_name); return -1; } @@ -100,8 +100,8 @@ static int h5_open(void *transport_config){ perror("init_serialport: Couldn't get term attributes"); return -1; } - speed_t brate = hci_uart_config->baudrate; // let you override switch below if needed - switch(hci_uart_config->baudrate) { + speed_t brate = hci_transport_config_uart->baudrate; // let you override switch below if needed + switch(hci_transport_config_uart->baudrate) { case 57600: brate=B57600; break; case 115200: brate=B115200; break; #ifdef B230400 @@ -123,7 +123,7 @@ static int h5_open(void *transport_config){ toptions.c_cflag &= ~CSIZE; toptions.c_cflag |= CS8; - if (hci_uart_config->flowcontrol) { + if (hci_transport_config_uart->flowcontrol) { // with flow control toptions.c_cflag |= CRTSCTS; } else { diff --git a/port/arduino/BTstack.cpp b/port/arduino/BTstack.cpp index 6e5579bc8..d5db776f8 100644 --- a/port/arduino/BTstack.cpp +++ b/port/arduino/BTstack.cpp @@ -724,9 +724,6 @@ void BTstackManager::setPublicBdAddr(bd_addr_t addr){ memcpy(public_bd_addr, addr ,6); } -// static hci_uart_config_t config; - - void bluetooth_hardware_error(){ printf("Bluetooth Hardware Error event. Restarting...\n\n\n"); #ifdef __AVR__ diff --git a/port/ez430-rf2560/src/main.c b/port/ez430-rf2560/src/main.c index 7e2ff252d..91eb9a105 100644 --- a/port/ez430-rf2560/src/main.c +++ b/port/ez430-rf2560/src/main.c @@ -65,6 +65,14 @@ int btstack_main(int argc, const char * argv[]); +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, + 115200, + 1000000, // main baudrate + 1, // flow control + NULL, +}; + // main int main(void) { @@ -92,9 +100,8 @@ int main(void) // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); - hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, config, control, remote_db); + hci_init(transport, &config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); diff --git a/port/ios/src/bt_control_iphone.m b/port/ios/src/bt_control_iphone.m index 4dad906a0..87c5eaf86 100644 --- a/port/ios/src/bt_control_iphone.m +++ b/port/ios/src/bt_control_iphone.m @@ -448,13 +448,13 @@ static void iphone_write_configscript(int fd, int baudrate){ } static int iphone_on (void *transport_config){ - // hci_uart_config->baudrate_init == 0, if using native speed + // hci_transport_config_uart->baudrate_init == 0, if using native speed log_info("iphone_on: entered\n"); int err = 0; - hci_uart_config_t * hci_uart_config = (hci_uart_config_t*) transport_config; + hci_transport_config_uart_t * hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config; // get local-mac-addr and transport-speed from IORegistry ioregistry_get_info(); @@ -508,23 +508,23 @@ static int iphone_on (void *transport_config){ } // quick test if Bluetooth UART can be opened - and try to start cleanly - int fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY); + int fd = open(hci_transport_config_uart->device_name, O_RDWR | O_NOCTTY | O_NDELAY); if (fd > 0) { // everything's fine close(fd); } else { // no way! - log_error( "bt_control.c:iphone_on(): Failed to open '%s', trying killall %s\n", hci_uart_config->device_name, bluetool); + log_error( "bt_control.c:iphone_on(): Failed to open '%s', trying killall %s\n", hci_transport_config_uart->device_name, bluetool); system("killall -9 BlueToolH4"); system("killall -9 BlueTool"); sleep(3); // try again - fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY); + fd = open(hci_transport_config_uart->device_name, O_RDWR | O_NOCTTY | O_NDELAY); if (fd > 0){ close(fd); } else { - log_error( "bt_control.c:iphone_on(): Failed to open '%s' again, trying killall BTServer and killall %s\n", hci_uart_config->device_name, bluetool); + log_error( "bt_control.c:iphone_on(): Failed to open '%s' again, trying killall BTServer and killall %s\n", hci_transport_config_uart->device_name, bluetool); system("killall -9 BTServer"); system("killall -9 BlueToolH4"); system("killall -9 BlueTool"); @@ -547,10 +547,10 @@ static int iphone_on (void *transport_config){ if (os4x) { // 4.x - send custom config - iphone_write_configscript(output, hci_uart_config->baudrate_init); + iphone_write_configscript(output, hci_transport_config_uart->baudrate_init); } else { // 3.x - modify original script on the fly - iphone_write_initscript(output, hci_uart_config->baudrate_init); + iphone_write_initscript(output, hci_transport_config_uart->baudrate_init); } // log output @@ -577,8 +577,8 @@ static int iphone_on (void *transport_config){ power_management_active = bt_control_iphone_power_management_supported(); // if baud == 0, we're using system default: set in transport config - if (hci_uart_config->baudrate_init == 0) { - hci_uart_config->baudrate_init = transport_speed; + if (hci_transport_config_uart->baudrate_init == 0) { + hci_transport_config_uart->baudrate_init = transport_speed; } #endif diff --git a/port/ios/src/hci_transport_h4_iphone.c b/port/ios/src/hci_transport_h4_iphone.c index 1db2eb0af..04379e801 100644 --- a/port/ios/src/hci_transport_h4_iphone.c +++ b/port/ios/src/hci_transport_h4_iphone.c @@ -84,7 +84,7 @@ static int h4_process(struct data_source *ds); static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size); -static hci_uart_config_t *hci_uart_config; +static hci_transport_config_uart_t *hci_transport_config_uart; static void h4_enforce_wake_on(void); static void h4_enforce_wake_off(void); @@ -134,7 +134,7 @@ static uint8_t hci_packet[1+HCI_PACKET_BUFFER_SIZE]; // packet type + max(acl he static int h4_open(void *transport_config) { - hci_uart_config = (hci_uart_config_t *) transport_config; + hci_transport_config_uart = (hci_transport_config_uart_t *) transport_config; int fd = socket(PF_NETGRAPH, SOCK_STREAM, NG_CONTROL); log_info("h4_open: open socket(%u, %u, %u) %d", PF_NETGRAPH, SOCK_STREAM, NG_CONTROL, fd); @@ -188,7 +188,7 @@ static int h4_open(void *transport_config) // make raw and set speed cfmakeraw(&toptions); - speed_t brate = (speed_t) hci_uart_config->baudrate_init; + speed_t brate = (speed_t) hci_transport_config_uart->baudrate_init; cfsetspeed(&toptions, brate); toptions.c_iflag |= IGNPAR; toptions.c_cflag = 0x00038b00; diff --git a/port/libusb/main.c b/port/libusb/main.c index 1d8413901..ecddc02e1 100644 --- a/port/libusb/main.c +++ b/port/libusb/main.c @@ -92,7 +92,7 @@ int main(int argc, const char * argv[]){ // init HCI hci_transport_t * transport = hci_transport_usb_instance(); - hci_uart_config_t * config = NULL; + void * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; diff --git a/port/msp-exp430f5438-cc2564b/example/hid_demo.c b/port/msp-exp430f5438-cc2564b/example/hid_demo.c index b25ae3b30..170d73a96 100644 --- a/port/msp-exp430f5438-cc2564b/example/hid_demo.c +++ b/port/msp-exp430f5438-cc2564b/example/hid_demo.c @@ -342,6 +342,14 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } } +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, + 115200, + 1000000, // main baudrate + 1, // flow control + NULL, +}; + int main(void){ // stop watchdog timer @@ -369,9 +377,8 @@ int main(void){ // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); - hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, config, control, remote_db); + hci_init(transport, &config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); diff --git a/port/msp-exp430f5438-cc2564b/src/main.c b/port/msp-exp430f5438-cc2564b/src/main.c index 8a6efeb61..c5f022f33 100644 --- a/port/msp-exp430f5438-cc2564b/src/main.c +++ b/port/msp-exp430f5438-cc2564b/src/main.c @@ -84,6 +84,14 @@ static void hw_setup(void){ __enable_interrupt(); } +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, + 115200, + 1000000, // main baudrate + 1, // flow control + NULL, +}; + static void btstack_setup(void){ /// GET STARTED with BTstack /// btstack_memory_init(); @@ -92,9 +100,8 @@ static void btstack_setup(void){ // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); - hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, config, control, remote_db); + hci_init(transport, &config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); diff --git a/port/msp430f5229lp-cc2564b/src/main.c b/port/msp430f5229lp-cc2564b/src/main.c index 76778031c..bccc84314 100644 --- a/port/msp430f5229lp-cc2564b/src/main.c +++ b/port/msp430f5229lp-cc2564b/src/main.c @@ -88,6 +88,14 @@ static void hw_setup(void){ __enable_interrupt(); } +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, + 115200, + 1000000, // main baudrate + 1, // flow control + NULL, +}; + static void btstack_setup(void){ hci_dump_open(NULL, HCI_DUMP_STDOUT); @@ -99,9 +107,8 @@ static void btstack_setup(void){ // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); - hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, config, control, remote_db); + hci_init(transport, &config, control, remote_db); // use eHCILL // bt_control_cc256x_enable_ehcill(1); diff --git a/port/pic32-harmony/src/btstack_port.c b/port/pic32-harmony/src/btstack_port.c index aa69cc6fe..1597d8d81 100644 --- a/port/pic32-harmony/src/btstack_port.c +++ b/port/pic32-harmony/src/btstack_port.c @@ -207,13 +207,15 @@ void hal_uart_dma_receive_block(uint8_t *data, uint16_t size){ } /// -static const hci_uart_config_t hci_uart_config_csr = { - NULL, +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, 115200, - 0, // 1000000, - 0 + 0, // main baudrate + 1, // flow control + NULL, }; + void BTSTACK_Initialize ( void ) { printf("\n\nBTstack_Initialize()\n"); @@ -225,7 +227,7 @@ void BTSTACK_Initialize ( void ) hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_csr_instance(); - hci_init(transport, (void*) &hci_uart_config_csr, control, NULL); + hci_init(transport, &config, control, NULL); // hci_power_control(HCI_POWER_ON); btstack_main(0, NULL); diff --git a/port/posix-cc2564b/main.c b/port/posix-cc2564b/main.c index 64ee20198..19382fe84 100644 --- a/port/posix-cc2564b/main.c +++ b/port/posix-cc2564b/main.c @@ -50,6 +50,7 @@ #include "btstack-config.h" #include "run_loop.h" +#include "run_loop_posix.h" #include "debug.h" #include "btstack_memory.h" @@ -61,9 +62,13 @@ int btstack_main(int argc, const char * argv[]); -static hci_uart_config_t hci_uart_config_cc256x = { - NULL, + +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, 115200, + 0, // main baudrate + 1, // flow control + NULL, }; static void sigint_handler(int param){ @@ -96,14 +101,14 @@ int main(int argc, const char * argv[]){ hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // pick serial port - hci_uart_config_cc256x.device_name = "/dev/tty.usbserial-AD025KU2"; + config.device_name = "/dev/tty.usbserial-AD025KU2"; // init HCI hci_transport_t * transport = hci_transport_h4_instance(); bt_control_t * control = bt_control_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; - hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); + hci_init(transport, &config, control, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); diff --git a/port/posix-h4/main.c b/port/posix-h4/main.c index 265302dc0..d09be5d57 100644 --- a/port/posix-h4/main.c +++ b/port/posix-h4/main.c @@ -54,13 +54,17 @@ #include "hci.h" #include "hci_dump.h" #include "run_loop.h" +#include "run_loop_posix.h" #include "stdin_support.h" int btstack_main(int argc, const char * argv[]); -static hci_uart_config_t hci_uart_config_generic = { - NULL, +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, 115200, + 0, // main baudrate + 1, // flow control + NULL, }; static void sigint_handler(int param){ @@ -93,13 +97,13 @@ int main(int argc, const char * argv[]){ hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // pick serial port - hci_uart_config_generic.device_name = "/dev/tty.usbmodem1413"; + config.device_name = "/dev/tty.usbmodem1413"; // init HCI hci_transport_t * transport = hci_transport_h4_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; - hci_init(transport, (void*) &hci_uart_config_generic, NULL, remote_db); + hci_init(transport, (void*) &config, NULL, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); diff --git a/port/posix-stlc2500d/main.c b/port/posix-stlc2500d/main.c index 701aefa85..9762be5a2 100644 --- a/port/posix-stlc2500d/main.c +++ b/port/posix-stlc2500d/main.c @@ -50,6 +50,7 @@ #include "btstack-config.h" #include "run_loop.h" +#include "run_loop_posix.h" #include "debug.h" #include "btstack_memory.h" @@ -60,10 +61,12 @@ int btstack_main(int argc, const char * argv[]); -static hci_uart_config_t hci_uart_config_cc256x = { - NULL, +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, 115200, - 0, // main baudrate: set to higher standard values if needed e.g. 460800 + 0, // main baudrate + 1, // flow control + NULL, }; static void sigint_handler(int param){ @@ -96,14 +99,14 @@ int main(int argc, const char * argv[]){ hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // pick serial port - hci_uart_config_cc256x.device_name = "/dev/tty.usbserial-AD025KU2"; + config.device_name = "/dev/tty.usbserial-AD025KU2"; // init HCI hci_transport_t * transport = hci_transport_h4_instance(); bt_control_t * control = bt_control_stlc2500d_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; - hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); + hci_init(transport, (void*) &config, control, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); diff --git a/port/posix-wl183x/main.c b/port/posix-wl183x/main.c index 64ee20198..bbc209124 100644 --- a/port/posix-wl183x/main.c +++ b/port/posix-wl183x/main.c @@ -50,6 +50,7 @@ #include "btstack-config.h" #include "run_loop.h" +#include "run_loop_posix.h" #include "debug.h" #include "btstack_memory.h" @@ -61,9 +62,12 @@ int btstack_main(int argc, const char * argv[]); -static hci_uart_config_t hci_uart_config_cc256x = { - NULL, +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, 115200, + 0, // main baudrate + 1, // flow control + NULL, }; static void sigint_handler(int param){ @@ -96,14 +100,14 @@ int main(int argc, const char * argv[]){ hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // pick serial port - hci_uart_config_cc256x.device_name = "/dev/tty.usbserial-AD025KU2"; + config.device_name = "/dev/tty.usbserial-AD025KU2"; // init HCI hci_transport_t * transport = hci_transport_h4_instance(); bt_control_t * control = bt_control_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; - hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); + hci_init(transport, (void*) &config, control, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); diff --git a/port/stm32-f103rb-nucleo/main.c b/port/stm32-f103rb-nucleo/main.c index 3209dd4c8..fc358c049 100644 --- a/port/stm32-f103rb-nucleo/main.c +++ b/port/stm32-f103rb-nucleo/main.c @@ -403,11 +403,12 @@ static void bluetooth_power_cycle(void){ // after HCI Reset, use 115200. Then increase baud reate to 468000. // (on nucleo board without external crystall, running at 8 Mhz, 1 mbps was not possible) -static const hci_uart_config_t hci_uart_config_cc256x = { - NULL, +static const hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, 115200, 460800, - 0 + 1, + NULL }; int main(void) @@ -426,7 +427,7 @@ int main(void) hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); + hci_init(transport, (void*) &config, control, remote_db); // enable eHCILL bt_control_cc256x_enable_ehcill(1); diff --git a/port/wiced/main.c b/port/wiced/main.c index 262089d4d..1e2fa4127 100644 --- a/port/wiced/main.c +++ b/port/wiced/main.c @@ -48,11 +48,12 @@ // see generated_mac_address.txt - "macaddr=02:0A:F7:3d:76:be" static const char * wifi_mac_address = NVRAM_GENERATED_MAC_ADDRESS; -static const hci_uart_config_t hci_uart_config = { - NULL, +static const hci_transport_config_uart_t hci_transport_config_uart = { + HCI_TRANSPORT_CONFIG_UART, 115200, 3000000, - 0 + 1, + NULL, }; extern int btstack_main(void); @@ -94,7 +95,7 @@ void application_start(void){ hci_transport_t * transport = hci_transport_h4_wiced_instance(); bt_control_t * control = bt_control_bcm_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; - hci_init(transport, (void*) &hci_uart_config, control, remote_db); + hci_init(transport, (void*) &hci_transport_config_uart, control, remote_db); // use WIFI Mac address + 1 for Bluetooth bd_addr_t dummy = { 1,2,3,4,5,6}; diff --git a/src/hci.c b/src/hci.c index c6d45fbd9..0ff423c17 100644 --- a/src/hci.c +++ b/src/hci.c @@ -846,7 +846,7 @@ void le_handle_advertisement_report(uint8_t *packet, int size){ static uint32_t hci_transport_uart_get_main_baud_rate(void){ if (!hci_stack->config) return 0; - uint32_t baud_rate = ((hci_uart_config_t *)hci_stack->config)->baudrate_main; + uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; // Limit baud rate for Broadcom chipsets to 3 mbps if (hci_stack->manufacturer == COMPANY_ID_BROADCOM_CORPORATION && baud_rate > 3000000){ baud_rate = 3000000; @@ -974,9 +974,9 @@ static void hci_initializing_run(void){ && hci_stack->control && hci_stack->control->baudrate_cmd && hci_stack->hci_transport->set_baudrate - && ((hci_uart_config_t *)hci_stack->config)->baudrate_main; + && ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; if (need_baud_change) { - uint32_t baud_rate = ((hci_uart_config_t *)hci_stack->config)->baudrate_init; + uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_init; log_info("Local baud rate change to %"PRIu32" after init script", baud_rate); hci_stack->hci_transport->set_baudrate(baud_rate); } @@ -1119,7 +1119,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){ && hci_stack->control && hci_stack->control->baudrate_cmd && hci_stack->hci_transport->set_baudrate - && ((hci_uart_config_t *)hci_stack->config)->baudrate_main; + && ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; int need_addr_change = hci_stack->custom_bd_addr_set && hci_stack->control diff --git a/src/hci_transport.h b/src/hci_transport.h index 51538352f..17ecb4a63 100644 --- a/src/hci_transport.h +++ b/src/hci_transport.h @@ -68,12 +68,22 @@ typedef struct { int (*can_send_packet_now)(uint8_t packet_type); } hci_transport_t; +typedef enum { + HCI_TRANSPORT_CONFIG_UART, + HCI_TRANSPORT_CONFIG_USB +} hci_transport_config_type_t; + typedef struct { - const char *device_name; + hci_transport_config_type_t type; +} hci_transport_config_t; + +typedef struct { + hci_transport_config_type_t type; // == HCI_TRANSPORT_CONFIG_UART uint32_t baudrate_init; // initial baud rate uint32_t baudrate_main; // = 0: same as initial baudrate - int flowcontrol; // -} hci_uart_config_t; + int flowcontrol; // + const char *device_name; +} hci_transport_config_uart_t; // inline various hci_transport_X.h files diff --git a/test/gatt_client/Makefile b/test/gatt_client/Makefile index 441a6dab2..af86e9017 100644 --- a/test/gatt_client/Makefile +++ b/test/gatt_client/Makefile @@ -22,7 +22,7 @@ COMMON = \ hci_dump.c \ le_device_db_memory.c \ memory_pool.c \ - mock.c + mock.c \ utils.c \ diff --git a/test/pts/ble_peripheral_test.c b/test/pts/ble_peripheral_test.c index b22a065cb..5ede9d33b 100644 --- a/test/pts/ble_peripheral_test.c +++ b/test/pts/ble_peripheral_test.c @@ -939,17 +939,6 @@ static int get_oob_data_callback(uint8_t addres_type, bd_addr_t addr, uint8_t * return 1; } -#if defined(HAVE_UART_CSR) || defined(HAVE_UART_CC256x) -static hci_uart_config_t hci_uart_config = { - // "/dev/tty.usbserial-A40081HW", - "/dev/tty.usbserial-AD025KU2", - 115200, - 0, // 1000000, - 1 -}; -#endif - - int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ diff --git a/test/security_manager/security_manager.c b/test/security_manager/security_manager.c index 8ea1c148e..41de1fb31 100644 --- a/test/security_manager/security_manager.c +++ b/test/security_manager/security_manager.c @@ -14,6 +14,8 @@ #include "CppUTest/TestHarness.h" #include "CppUTest/CommandLineTestRunner.h" +#include "run_loop_posix.h" + #include "hci_cmds.h" #include "utils.h"