From ec6321ee39469b8acf366e0cfc0bcd0c86f1a539 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald@gmail.com" Date: Thu, 6 Nov 2014 20:09:57 +0000 Subject: [PATCH] reserve buffer in front of incoming hci_packet buffer for h4 (posix, dma, dma+ehcill) and h2 libusb, and acl recombination buffer --- src/hci.c | 8 ++++---- src/hci.h | 10 +++++++--- src/hci_transport_h4_dma.c | 5 ++++- src/hci_transport_h4_ehcill_dma.c | 6 +++++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/hci.c b/src/hci.c index b1d51aac4..9d9316d8c 100644 --- a/src/hci.c +++ b/src/hci.c @@ -570,7 +570,7 @@ static void acl_handler(uint8_t *packet, int size){ } // append fragment payload (header already stored) - memcpy(&conn->acl_recombination_buffer[conn->acl_recombination_pos], &packet[4], acl_length ); + memcpy(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + conn->acl_recombination_pos], &packet[4], acl_length ); conn->acl_recombination_pos += acl_length; // log_error( "ACL Cont Fragment: acl_len %u, combined_len %u, l2cap_len %u", acl_length, @@ -579,7 +579,7 @@ static void acl_handler(uint8_t *packet, int size){ // forward complete L2CAP packet if complete. if (conn->acl_recombination_pos >= conn->acl_recombination_length + 4 + 4){ // pos already incl. ACL header - hci_stack->packet_handler(HCI_ACL_DATA_PACKET, conn->acl_recombination_buffer, conn->acl_recombination_pos); + hci_stack->packet_handler(HCI_ACL_DATA_PACKET, &conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], conn->acl_recombination_pos); // reset recombination buffer conn->acl_recombination_length = 0; conn->acl_recombination_pos = 0; @@ -607,10 +607,10 @@ static void acl_handler(uint8_t *packet, int size){ } else { // store first fragment and tweak acl length for complete package - memcpy(conn->acl_recombination_buffer, packet, acl_length + 4); + memcpy(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], packet, acl_length + 4); conn->acl_recombination_pos = acl_length + 4; conn->acl_recombination_length = l2cap_length; - bt_store_16(conn->acl_recombination_buffer, 2, l2cap_length +4); + bt_store_16(conn->acl_recombination_buffer, HCI_INCOMING_PRE_BUFFER_SIZE + 2, l2cap_length +4); } break; diff --git a/src/hci.h b/src/hci.h index 8f8003294..559fc2114 100644 --- a/src/hci.h +++ b/src/hci.h @@ -110,8 +110,12 @@ extern "C" { // additional pre-buffer space for packets to Bluetooth module, for now, used for HCI Transport H4 DMA #define HCI_OUTGOING_PRE_BUFFER_SIZE 1 +// BNEP may uncompress the IP Header by 16 bytes +#ifdef HAVE_BNEP +#define HCI_INCOMING_PRE_BUFFER_SIZE (16 - HCI_ACL_HEADER_SIZE - 4) +#endif #ifndef HCI_INCOMING_PRE_BUFFER_SIZE -#define HCI_INCOMING_PRE_BUFFER_SIZE 0 + #define HCI_INCOMING_PRE_BUFFER_SIZE 0 #endif // OGFs @@ -366,8 +370,8 @@ typedef struct { uint32_t timestamp; // timeout in system ticks #endif - // ACL packet recombination - ACL Header + ACL payload - uint8_t acl_recombination_buffer[4 + HCI_ACL_BUFFER_SIZE]; + // ACL packet recombination - PRE_BUFFER + ACL Header + ACL payload + uint8_t acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 4 + HCI_ACL_BUFFER_SIZE]; uint16_t acl_recombination_pos; uint16_t acl_recombination_length; diff --git a/src/hci_transport_h4_dma.c b/src/hci_transport_h4_dma.c index 835ca0b3e..d435e965c 100644 --- a/src/hci_transport_h4_dma.c +++ b/src/hci_transport_h4_dma.c @@ -90,7 +90,10 @@ static int h4_can_send_packet_now(uint8_t packet_type); static H4_STATE h4_state; static int read_pos; static int bytes_to_read; -static uint8_t hci_packet[HCI_PACKET_BUFFER_SIZE]; // bigger than largest packet + + // bigger than largest packet +static uint8_t hci_packet_prefixed[HCI_INCOMING_PRE_BUFFER_SIZE + HCI_PACKET_BUFFER_SIZE]; +static uint8_t * hci_packet = &hci_packet_prefixed[HCI_INCOMING_PRE_BUFFER_SIZE]; // tx state static TX_STATE tx_state; diff --git a/src/hci_transport_h4_ehcill_dma.c b/src/hci_transport_h4_ehcill_dma.c index 3d3c6e7c1..7919b9e48 100644 --- a/src/hci_transport_h4_ehcill_dma.c +++ b/src/hci_transport_h4_ehcill_dma.c @@ -129,7 +129,11 @@ static uint8_t ehcill_command_to_send; static H4_STATE h4_state; static int read_pos; static int bytes_to_read; -static uint8_t hci_packet[HCI_PACKET_BUFFER_SIZE]; // bigger than largest packet + + // bigger than largest packet +static uint8_t hci_packet_prefixed[HCI_INCOMING_PRE_BUFFER_SIZE + HCI_PACKET_BUFFER_SIZE]; +static uint8_t * hci_packet = &hci_packet_prefixed[HCI_INCOMING_PRE_BUFFER_SIZE]; + static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = dummy_handler; // H4: tx state