From 4ea196a400ee1cbcee5cf1adf8230d541246c978 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 7 Jul 2016 11:26:05 +0200 Subject: [PATCH 1/4] btstack_run_loop: don't return of void function --- src/btstack_run_loop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/btstack_run_loop.c b/src/btstack_run_loop.c index 2f0411e19..13b92502a 100644 --- a/src/btstack_run_loop.c +++ b/src/btstack_run_loop.c @@ -82,7 +82,7 @@ int btstack_run_loop_get_data_source_fd(btstack_data_source_t *ds){ void btstack_run_loop_enable_data_source_callbacks(btstack_data_source_t *ds, uint16_t callbacks){ btstack_run_loop_assert(); if (the_run_loop->enable_data_source_callbacks){ - return the_run_loop->enable_data_source_callbacks(ds, callbacks); + the_run_loop->enable_data_source_callbacks(ds, callbacks); } else { log_error("btstack_run_loop_remove_data_source not implemented"); } @@ -91,7 +91,7 @@ void btstack_run_loop_enable_data_source_callbacks(btstack_data_source_t *ds, ui void btstack_run_loop_disable_data_source_callbacks(btstack_data_source_t *ds, uint16_t callbacks){ btstack_run_loop_assert(); if (the_run_loop->disable_data_source_callbacks){ - return the_run_loop->disable_data_source_callbacks(ds, callbacks); + the_run_loop->disable_data_source_callbacks(ds, callbacks); } else { log_error("btstack_run_loop_disable_data_source_callbacks not implemented"); } From a77ee77c5e2bdd694840c192847fe4494f38e00b Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 8 Jul 2016 22:50:35 +0200 Subject: [PATCH 2/4] libusb: print path for USB dongle --- port/libusb/hci_transport_h2_libusb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/port/libusb/hci_transport_h2_libusb.c b/port/libusb/hci_transport_h2_libusb.c index ae84b6084..ed378dae0 100644 --- a/port/libusb/hci_transport_h2_libusb.c +++ b/port/libusb/hci_transport_h2_libusb.c @@ -570,8 +570,22 @@ static int scan_for_bt_device(libusb_device **devs, int start_index) { } #endif +// seems to be the max depth for USB 3 +#define MAX_PATH_DEPTH 7 static int prepare_device(libusb_device_handle * aHandle){ + // print device path + uint8_t port_numbers[MAX_PATH_DEPTH]; + libusb_device * device = libusb_get_device(aHandle); + int path_len = libusb_get_port_numbers(device, port_numbers, MAX_PATH_DEPTH); + printf("USB Path: "); + int i; + for (i=0;i Date: Sat, 9 Jul 2016 16:10:45 +0200 Subject: [PATCH 3/4] libusb: allows to specify USB dongle with hci_transport_usb_set_path --- port/libusb/hci_transport_h2_libusb.c | 131 +++++++++++++++++--------- src/hci_transport.h | 4 + 2 files changed, 90 insertions(+), 45 deletions(-) diff --git a/port/libusb/hci_transport_h2_libusb.c b/port/libusb/hci_transport_h2_libusb.c index ed378dae0..ab0f8243c 100644 --- a/port/libusb/hci_transport_h2_libusb.c +++ b/port/libusb/hci_transport_h2_libusb.c @@ -101,6 +101,9 @@ #define SCO_RING_BUFFER_COUNT (8) #define SCO_RING_BUFFER_SIZE (SCO_RING_BUFFER_COUNT * SCO_PACKET_SIZE) +// seems to be the max depth for USB 3 +#define USB_MAX_PATH_LEN 7 + // prototypes static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size); static int usb_close(void); @@ -185,6 +188,10 @@ static int acl_out_addr; static int sco_in_addr; static int sco_out_addr; +// device path +static int usb_path_len; +static uint8_t usb_path[USB_MAX_PATH_LEN]; + #ifdef ENABLE_SCO_OVER_HCI static void sco_ring_init(void){ @@ -196,6 +203,14 @@ static int sco_ring_have_space(void){ } #endif +void hci_transport_usb_set_path(int len, uint8_t * port_numbers){ + if (len > USB_MAX_PATH_LEN || !port_numbers){ + log_error("hci_transport_usb_set_path: len or port numbers invalid"); + return; + } + usb_path_len = len; + memcpy(usb_path, port_numbers, len); +} // static void queue_transfer(struct libusb_transfer *transfer){ @@ -570,14 +585,12 @@ static int scan_for_bt_device(libusb_device **devs, int start_index) { } #endif -// seems to be the max depth for USB 3 -#define MAX_PATH_DEPTH 7 static int prepare_device(libusb_device_handle * aHandle){ // print device path - uint8_t port_numbers[MAX_PATH_DEPTH]; + uint8_t port_numbers[USB_MAX_PATH_LEN]; libusb_device * device = libusb_get_device(aHandle); - int path_len = libusb_get_port_numbers(device, port_numbers, MAX_PATH_DEPTH); + int path_len = libusb_get_port_numbers(device, port_numbers, USB_MAX_PATH_LEN); printf("USB Path: "); int i; for (i=0;i Date: Sat, 9 Jul 2016 16:26:41 +0200 Subject: [PATCH 4/4] libusb: parse -u 11:22:33 as USB path --- port/libusb/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/port/libusb/main.c b/port/libusb/main.c index 6e17e6f6b..a6822f733 100644 --- a/port/libusb/main.c +++ b/port/libusb/main.c @@ -92,12 +92,36 @@ void hal_led_toggle(void){ } +#define USB_MAX_PATH_LEN 7 int main(int argc, const char * argv[]){ + uint8_t usb_path[USB_MAX_PATH_LEN]; + int usb_path_len = 0; + if (argc >= 3 && strcmp(argv[1], "-u") == 0){ + // parse command line options for "-u 11:22:33" + const char * port_str = argv[2]; + printf("Specified USB Path: "); + while (1){ + char * delimiter; + int port = strtol(port_str, &delimiter, 16); + usb_path[usb_path_len] = port; + usb_path_len++; + printf("%02x ", port); + if (!delimiter) break; + if (*delimiter != ':') break; + port_str = delimiter+1; + } + printf("\n"); + } + /// GET STARTED with BTstack /// btstack_memory_init(); btstack_run_loop_init(btstack_run_loop_posix_get_instance()); + if (usb_path_len){ + hci_transport_usb_set_path(usb_path_len, usb_path); + } + // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);