From 25ad7c220c101bfc12c3a4773fae29d6ae9b4d26 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 15 Feb 2016 14:07:37 +0100 Subject: [PATCH 1/6] libusb: use & operator for function pointers --- platforms/posix/src/hci_transport_h2_libusb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/platforms/posix/src/hci_transport_h2_libusb.c b/platforms/posix/src/hci_transport_h2_libusb.c index 5a117004e..8bd8b0834 100644 --- a/platforms/posix/src/hci_transport_h2_libusb.c +++ b/platforms/posix/src/hci_transport_h2_libusb.c @@ -256,7 +256,7 @@ static int usb_send_sco_packet(uint8_t *packet, int size){ // setup transfer struct libusb_transfer * sco_transfer = sco_ring_transfers[tranfer_index]; - libusb_fill_iso_transfer(sco_transfer, handle, sco_out_addr, data, size, NUM_ISO_PACKETS, async_callback, NULL, 0); + libusb_fill_iso_transfer(sco_transfer, handle, sco_out_addr, data, size, NUM_ISO_PACKETS, &async_callback, NULL, 0); libusb_set_iso_packet_lengths(sco_transfer, ISO_PACKET_SIZE); r = libusb_submit_transfer(sco_transfer); if (r < 0) { @@ -769,7 +769,7 @@ static int usb_open(void *transport_config){ } // configure sco_in handlers libusb_fill_iso_transfer(sco_in_transfer[c], handle, sco_in_addr, - hci_sco_in_buffer[c], SCO_PACKET_SIZE, NUM_ISO_PACKETS, async_callback, NULL, 0); + hci_sco_in_buffer[c], SCO_PACKET_SIZE, NUM_ISO_PACKETS, &async_callback, NULL, 0); libusb_set_iso_packet_lengths(sco_in_transfer[c], ISO_PACKET_SIZE); r = libusb_submit_transfer(sco_in_transfer[c]); log_info("Submit iso transfer res = %d", r); @@ -789,7 +789,7 @@ static int usb_open(void *transport_config){ for (c = 0 ; c < ASYNC_BUFFERS ; c++) { // configure event_in handlers libusb_fill_interrupt_transfer(event_in_transfer[c], handle, event_in_addr, - hci_event_in_buffer[c], HCI_ACL_BUFFER_SIZE, async_callback, NULL, 0) ; + hci_event_in_buffer[c], HCI_ACL_BUFFER_SIZE, &async_callback, NULL, 0) ; r = libusb_submit_transfer(event_in_transfer[c]); if (r) { log_error("Error submitting interrupt transfer %d", r); @@ -799,7 +799,7 @@ static int usb_open(void *transport_config){ // configure acl_in handlers libusb_fill_bulk_transfer(acl_in_transfer[c], handle, acl_in_addr, - hci_acl_in_buffer[c] + HCI_INCOMING_PRE_BUFFER_SIZE, HCI_ACL_BUFFER_SIZE, async_callback, NULL, 0) ; + hci_acl_in_buffer[c] + HCI_INCOMING_PRE_BUFFER_SIZE, HCI_ACL_BUFFER_SIZE, &async_callback, NULL, 0) ; r = libusb_submit_transfer(acl_in_transfer[c]); if (r) { log_error("Error submitting bulk in transfer %d", r); @@ -926,7 +926,7 @@ static int usb_send_cmd_packet(uint8_t *packet, int size){ // prepare transfer int completed = 0; - libusb_fill_control_transfer(command_out_transfer, handle, hci_cmd_buffer, async_callback, &completed, 0); + libusb_fill_control_transfer(command_out_transfer, handle, hci_cmd_buffer, &async_callback, &completed, 0); command_out_transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER; // update stata before submitting transfer @@ -953,8 +953,7 @@ static int usb_send_acl_packet(uint8_t *packet, int size){ // prepare transfer int completed = 0; - libusb_fill_bulk_transfer(acl_out_transfer, handle, acl_out_addr, packet, size, - async_callback, &completed, 0); + libusb_fill_bulk_transfer(acl_out_transfer, handle, acl_out_addr, packet, size, &async_callback, &completed, 0); acl_out_transfer->type = LIBUSB_TRANSFER_TYPE_BULK; // update stata before submitting transfer From b2faedc9fab1c1a0afaadefb3b47290c98f32edd Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 15 Feb 2016 14:29:20 +0100 Subject: [PATCH 2/6] libusb: fix compile on win32 --- platforms/posix/src/hci_transport_h2_libusb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platforms/posix/src/hci_transport_h2_libusb.c b/platforms/posix/src/hci_transport_h2_libusb.c index 8bd8b0834..b743ca1ab 100644 --- a/platforms/posix/src/hci_transport_h2_libusb.c +++ b/platforms/posix/src/hci_transport_h2_libusb.c @@ -211,8 +211,9 @@ static void queue_transfer(struct libusb_transfer *transfer){ temp->user_data = transfer; } -static void async_callback(struct libusb_transfer *transfer) -{ +// LIBUSB_CALL is needed on WIN32 (and resolveds to nothing on other platforms) +static void LIBUSB_CALL async_callback(struct libusb_transfer *transfer) { + if (libusb_state != LIB_USB_TRANSFERS_ALLOCATED) return; int r; // log_info("begin async_callback endpoint %x, status %x, actual length %u", transfer->endpoint, transfer->status, transfer->actual_length ); From c9b5173dc5e4ec48971a7d7aeee60a606c0ed554 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 15 Feb 2016 21:01:31 +0100 Subject: [PATCH 3/6] libubs: fix compile without SCO --- platforms/posix/src/hci_transport_h2_libusb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/platforms/posix/src/hci_transport_h2_libusb.c b/platforms/posix/src/hci_transport_h2_libusb.c index b743ca1ab..0a9c28ca0 100644 --- a/platforms/posix/src/hci_transport_h2_libusb.c +++ b/platforms/posix/src/hci_transport_h2_libusb.c @@ -179,17 +179,21 @@ static int acl_out_addr; static int sco_in_addr; static int sco_out_addr; - +#ifdef HAVE_SCO static void sco_ring_init(void){ sco_ring_write = 0; sco_ring_transfers_active = 0; } +#endif static int sco_ring_have_space(void){ +#ifdef HAVE_SCO return sco_ring_transfers_active < SCO_RING_BUFFER_COUNT; +#else + return 0; +#endif } - // static void queue_transfer(struct libusb_transfer *transfer){ @@ -283,6 +287,7 @@ static int usb_send_sco_packet(uint8_t *packet, int size){ return 0; } +#ifdef HAVE_SCO static void sco_state_machine_init(void){ sco_state = H2_W4_SCO_HEADER; sco_read_pos = 0; @@ -318,6 +323,7 @@ static void handle_isochronous_data(uint8_t * buffer, uint16_t size){ } } } +#endif static void handle_completed_transfer(struct libusb_transfer *transfer){ @@ -332,6 +338,7 @@ static void handle_completed_transfer(struct libusb_transfer *transfer){ packet_handler(HCI_ACL_DATA_PACKET, transfer-> buffer, transfer->actual_length); resubmit = 1; } else if (transfer->endpoint == sco_in_addr) { +#ifdef HAVE_SCO // log_info("handle_completed_transfer for SCO IN! num packets %u", transfer->NUM_ISO_PACKETS); int i; for (i = 0; i < transfer->num_iso_packets; i++) { @@ -347,6 +354,7 @@ static void handle_completed_transfer(struct libusb_transfer *transfer){ handle_isochronous_data(data, pack->actual_length); } resubmit = 1; +#endif } else if (transfer->endpoint == 0){ // log_info("command done, size %u", transfer->actual_length); usb_command_active = 0; @@ -356,6 +364,7 @@ static void handle_completed_transfer(struct libusb_transfer *transfer){ usb_acl_out_active = 0; signal_done = 1; } else if (transfer->endpoint == sco_out_addr){ +#ifdef HAVE_SCO log_info("sco out done, {{ %u/%u (%x)}, { %u/%u (%x)}, { %u/%u (%x)}}", transfer->iso_packet_desc[0].actual_length, transfer->iso_packet_desc[0].length, transfer->iso_packet_desc[0].status, transfer->iso_packet_desc[1].actual_length, transfer->iso_packet_desc[1].length, transfer->iso_packet_desc[1].status, @@ -367,6 +376,7 @@ static void handle_completed_transfer(struct libusb_transfer *transfer){ // decrease tab sco_ring_transfers_active--; // log_info("H2: sco out complete, num active num active %u", sco_ring_transfers_active); +#endif } else { log_info("usb_process_ds endpoint unknown %x", transfer->endpoint); } @@ -634,8 +644,10 @@ static int prepare_device(libusb_device_handle * aHandle){ static int usb_open(void *transport_config){ int r; +#ifdef HAVE_SCO sco_state_machine_init(); sco_ring_init(); +#endif handle_packet = NULL; // default endpoint addresses From e50ca9fbb85287b970cfeefed3a21492fca7eddf Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 15 Feb 2016 21:07:35 +0100 Subject: [PATCH 4/6] examples: delete .exe on make clean --- example/embedded/Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/embedded/Makefile.inc b/example/embedded/Makefile.inc index 28fb766c6..3a78804df 100644 --- a/example/embedded/Makefile.inc +++ b/example/embedded/Makefile.inc @@ -173,7 +173,7 @@ hsp_hs_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_hs.o hsp_hs_test.c clean: rm -f ${EXAMPLES} - rm -f *.o *.out *.hex + rm -f *.o *.out *.hex *.exe rm -f ${BTSTACK_ROOT}/include/btstack/version.h rm -f ancs_client.h profile.h spp_and_le_counter.h rm -rf *.dSYM From 042a40aaa542a4ed1e1a3c588d42d70bb5a1cd00 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 15 Feb 2016 21:49:39 +0100 Subject: [PATCH 5/6] libusb: #error with HAVE_SCO on Win32 --- platforms/posix/src/hci_transport_h2_libusb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platforms/posix/src/hci_transport_h2_libusb.c b/platforms/posix/src/hci_transport_h2_libusb.c index 0a9c28ca0..1d5091039 100644 --- a/platforms/posix/src/hci_transport_h2_libusb.c +++ b/platforms/posix/src/hci_transport_h2_libusb.c @@ -138,6 +138,10 @@ static struct libusb_transfer *acl_in_transfer[ASYNC_BUFFERS]; #ifdef HAVE_SCO +#ifdef _WIN32 +#error "SCO not working on Win32 (Windows 8, libusb 1.0.19, Zadic WinUSB), please uncomment HAVE_SCO in btstack-config.h for now" +#endif + // incoming SCO static H2_SCO_STATE sco_state; static uint8_t sco_buffer[255+3 + SCO_PACKET_SIZE]; From 2c8a33fdec3dc3066485750aee5ca722b4a5ebe7 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 16 Feb 2016 16:21:35 +0100 Subject: [PATCH 6/6] daemon: log retries --- platforms/daemon/src/socket_connection.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platforms/daemon/src/socket_connection.c b/platforms/daemon/src/socket_connection.c index c04b53859..b89987525 100644 --- a/platforms/daemon/src/socket_connection.c +++ b/platforms/daemon/src/socket_connection.c @@ -267,9 +267,11 @@ void socket_connection_retry_parked(void){ connection_t * conn = (connection_t *) it->next; // dispatch packet !!! connection, type, channel, data, size - log_info("socket_connection_hci_process retry parked %p", conn); - int dispatch_err = (*socket_connection_packet_callback)(conn, READ_BT_16( conn->buffer, 0), READ_BT_16( conn->buffer, 2), - &conn->buffer[sizeof(packet_header_t)], READ_BT_16( conn->buffer, 4)); + uint16_t packet_type = READ_BT_16( conn->buffer, 0); + uint16_t channel = READ_BT_16( conn->buffer, 2); + uint16_t length = READ_BT_16( conn->buffer, 4); + log_info("socket_connection_hci_process retry parked %p (type %u, channel %04x, length %u", conn, packet_type, channel, length); + int dispatch_err = (*socket_connection_packet_callback)(conn, packet_type, channel, &conn->buffer[sizeof(packet_header_t)], length); // "un-park" if successful if (!dispatch_err) { log_info("socket_connection_hci_process dispatch succeeded -> un-park connection %p", conn);