mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-14 00:40:57 +00:00
streamline buffer size definitions throughtout the stack, use single HCI_PACKET_BUFFER_SIZE
This commit is contained in:
parent
db8946af91
commit
36a5e73594
32
src/hci.h
32
src/hci.h
@ -38,6 +38,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
#include <btstack/hci_cmds.h>
|
||||
#include <btstack/utils.h>
|
||||
#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;
|
||||
|
@ -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 {
|
||||
|
@ -47,14 +47,6 @@
|
||||
|
||||
#include <btstack/hal_uart_dma.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
|
||||
|
||||
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]);
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user