From 36a5e7359498fc63342fd0da39264b220f934315 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Fri, 29 Jul 2011 19:44:19 +0000 Subject: [PATCH] streamline buffer size definitions throughtout the stack, use single HCI_PACKET_BUFFER_SIZE --- src/hci.h | 32 +++++++++++++++++++++++++------- src/hci_transport_h4.c | 9 --------- src/hci_transport_h4_dma.c | 12 ++---------- src/l2cap.c | 6 +++--- src/sdp.c | 2 +- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/hci.h b/src/hci.h index facd03f1d..4bc89f6f3 100644 --- a/src/hci.h +++ b/src/hci.h @@ -38,6 +38,8 @@ #pragma once +#include "../config.h" + #include #include #include "hci_transport.h" @@ -52,11 +54,11 @@ extern "C" { #endif -// packet header lenghts -#define HCI_CMD_DATA_PKT_HDR 0x03 -#define HCI_ACL_DATA_PKT_HDR 0x04 -#define HCI_SCO_DATA_PKT_HDR 0x03 -#define HCI_EVENT_PKT_HDR 0x02 +// packet header sizes +#define HCI_CMD_HEADER_SIZE 3 +#define HCI_ACL_HEADER_SIZE 4 +#define HCI_SCO_HEADER_SIZE 3 +#define HCI_EVENT_HEADER_SIZE 2 // packet sizes (max payload) #define HCI_ACL_DM1_SIZE 17 @@ -72,8 +74,23 @@ extern "C" { #define HCI_ACL_2DH5_SIZE 679 #define HCI_ACL_3DH5_SIZE 1021 -#define HCI_EVENT_PKT_SIZE 255 - +#define HCI_EVENT_PAYLOAD_SIZE 255 +#define HCI_CMD_PAYLOAD_SIZE 255 + +// packet buffer sizes +// HCI_ACL_PAYLOAD_SIZE is configurable and defined in config.h +#define HCI_EVENT_BUFFER_SIZE (HCI_EVENT_HEADER_SIZE + HCI_EVENT_PAYLOAD_SIZE) +#define HCI_CMD_BUFFER_SIZE (HCI_CMD_HEADER_SIZE + HCI_CMD_PAYLOAD_SIZE) +#define HCI_ACL_BUFFER_SIZE (HCI_ACL_HEADER_SIZE + HCI_ACL_PAYLOAD_SIZE) + +// size of hci buffers, big enough for command, event, or acl packet without H4 packet type +// @note cmd buffer is bigger than event buffer +#if HCI_ACL_BUFFER_SIZE > HCI_CMD_BUFFER_SIZE +#define HCI_PACKET_BUFFER_SIZE HCI_ACL_BUFFER_SIZE +#else +#define HCI_PACKET_BUFFER_SIZE HCI_EVENT_BUFFER_SIZE +#endif + // OGFs #define OGF_LINK_CONTROL 0x01 #define OGF_LINK_POLICY 0x02 @@ -243,6 +260,7 @@ typedef struct { // single buffer for HCI Command assembly uint8_t hci_cmd_buffer[3+255]; // opcode (16), len(8) + uint8_t hci_packet_buffer[HCI_PACKET_BUFFER_SIZE]; // opcode (16), len(8) /* host to controller flow control */ uint8_t num_cmd_packets; diff --git a/src/hci_transport_h4.c b/src/hci_transport_h4.c index 949696b6a..efdaf7903 100644 --- a/src/hci_transport_h4.c +++ b/src/hci_transport_h4.c @@ -48,15 +48,6 @@ #include "hci_transport.h" #include "hci_dump.h" - -// determine size of receive buffer -// use one extra byte to guarantee zero terminated device name in remote name event -#if (HCI_ACL_DATA_PKT_HDR + HCI_ACL_BUFFER_SIZE) > (HCI_EVENT_PKT_HDR + HCI_EVENT_PKT_SIZE + 1) -#define HCI_PACKET_BUFFER_SIZE (HCI_ACL_DATA_PKT_HDR + HCI_ACL_BUFFER_SIZE) -#else -#define HCI_PACKET_BUFFER_SIZE (HCI_EVENT_PKT_HDR + HCI_EVENT_PKT_SIZE + 1) -#endif - // #define USE_HCI_READER_THREAD typedef enum { diff --git a/src/hci_transport_h4_dma.c b/src/hci_transport_h4_dma.c index c1d4b2e3a..c78bca539 100644 --- a/src/hci_transport_h4_dma.c +++ b/src/hci_transport_h4_dma.c @@ -47,14 +47,6 @@ #include -// determine size of receive buffer -// use one extra byte to guarantee zero terminated device name in remote name event -#if (HCI_ACL_DATA_PKT_HDR + HCI_ACL_BUFFER_SIZE) > (HCI_EVENT_PKT_HDR + HCI_EVENT_PKT_SIZE + 1) -#define HCI_PACKET_BUFFER_SIZE (HCI_ACL_DATA_PKT_HDR + HCI_ACL_BUFFER_SIZE) -#else -#define HCI_PACKET_BUFFER_SIZE (HCI_EVENT_PKT_HDR + HCI_EVENT_PKT_SIZE + 1) -#endif - typedef enum { H4_W4_PACKET_TYPE = 1, H4_W4_EVENT_HEADER, @@ -150,11 +142,11 @@ static void h4_block_received(void){ switch (hci_packet[0]) { case HCI_ACL_DATA_PACKET: h4_state = H4_W4_ACL_HEADER; - bytes_to_read = HCI_ACL_DATA_PKT_HDR; + bytes_to_read = HCI_ACL_HEADER_SIZE; break; case HCI_EVENT_PACKET: h4_state = H4_W4_EVENT_HEADER; - bytes_to_read = HCI_EVENT_PKT_HDR; + bytes_to_read = HCI_EVENT_HEADER_SIZE; break; default: log_error("h4_process: invalid packet type 0x%02x\r\n", hci_packet[0]); diff --git a/src/l2cap.c b/src/l2cap.c index a017dfaeb..945a52b8a 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -49,7 +49,7 @@ #include // size of HCI ACL + L2CAP Header for regular data packets (8) -#define COMPLETE_L2CAP_HEADER (HCI_ACL_DATA_PKT_HDR + L2CAP_HEADER_SIZE) +#define COMPLETE_L2CAP_HEADER (HCI_ACL_HEADER_SIZE + L2CAP_HEADER_SIZE) // minimum signaling MTU #define L2CAP_MINIMAL_MTU 48 @@ -57,9 +57,9 @@ // determine size of outgoing packet construction buffer - this includes ACL + L2CAP header #if (L2CAP_MINIMAL_MTU + L2CAP_HEADER_SIZE) > (HCI_ACL_BUFFER_SIZE) -#define L2CAP_PACKET_BUFFER_SIZE (HCI_ACL_DATA_PKT_HDR + L2CAP_HEADER_SIZE + L2CAP_MINIMAL_MTU) +#define L2CAP_PACKET_BUFFER_SIZE (HCI_ACL_HEADER_SIZE + L2CAP_HEADER_SIZE + L2CAP_MINIMAL_MTU) #else -#define L2CAP_PACKET_BUFFER_SIZE (HCI_ACL_DATA_PKT_HDR + HCI_ACL_BUFFER_SIZE) +#define L2CAP_PACKET_BUFFER_SIZE (HCI_ACL_HEADER_SIZE + HCI_ACL_BUFFER_SIZE) #endif diff --git a/src/sdp.c b/src/sdp.c index 84f812096..670ab2c56 100644 --- a/src/sdp.c +++ b/src/sdp.c @@ -50,7 +50,7 @@ #define maxReservedServiceRecordHandle 0xffff // max SDP response -#define SDP_RESPONSE_BUFFER_SIZE (HCI_ACL_BUFFER_SIZE-HCI_ACL_DATA_PKT_HDR) +#define SDP_RESPONSE_BUFFER_SIZE (HCI_ACL_BUFFER_SIZE-HCI_ACL_HEADER_SIZE) static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);