11#ifndef ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
12#define ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
24#include <zephyr/autoconf.h>
82 __ASSERT_NO_MSG(
false);
110#define BT_BUF_RESERVE 1
113#define BT_BUF_SIZE(size) (BT_BUF_RESERVE + (size))
116#define BT_BUF_ACL_SIZE(size) BT_BUF_SIZE(BT_HCI_ACL_HDR_SIZE + (size))
119#define BT_BUF_EVT_SIZE(size) BT_BUF_SIZE(BT_HCI_EVT_HDR_SIZE + (size))
122#define BT_BUF_CMD_SIZE(size) BT_BUF_SIZE(BT_HCI_CMD_HDR_SIZE + (size))
125#define BT_BUF_ISO_SIZE(size) BT_BUF_SIZE(BT_HCI_ISO_HDR_SIZE + \
126 BT_HCI_ISO_SDU_TS_HDR_SIZE + \
130#define BT_BUF_ACL_RX_SIZE BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE)
133#define BT_BUF_EVT_RX_SIZE BT_BUF_EVT_SIZE(CONFIG_BT_BUF_EVT_RX_SIZE)
135#if defined(CONFIG_BT_ISO)
136#define BT_BUF_ISO_RX_SIZE BT_BUF_ISO_SIZE(CONFIG_BT_ISO_RX_MTU)
137#define BT_BUF_ISO_RX_COUNT CONFIG_BT_ISO_RX_BUF_COUNT
139#define BT_BUF_ISO_RX_SIZE 0
140#define BT_BUF_ISO_RX_COUNT 0
144#define BT_BUF_ACL_RX_COUNT_MAX 65535
146#if defined(CONFIG_BT_CONN) && defined(CONFIG_BT_HCI_HOST)
157#define BT_BUF_ACL_RX_COUNT_EXTRA CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA
158#define BT_BUF_ACL_RX_COUNT (MAX(CONFIG_BT_BUF_ACL_RX_COUNT, 1) + BT_BUF_ACL_RX_COUNT_EXTRA)
160#define BT_BUF_ACL_RX_COUNT_EXTRA 0
161#define BT_BUF_ACL_RX_COUNT 0
164#if defined(CONFIG_BT_BUF_ACL_RX_COUNT) && CONFIG_BT_BUF_ACL_RX_COUNT > 0
165#warning "CONFIG_BT_BUF_ACL_RX_COUNT is deprecated, see Zephyr 4.1 migration guide"
169 "Maximum number of ACL RX buffer is 65535, reduce CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA");
172#define BT_BUF_RX_SIZE (MAX(MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE), \
178BUILD_ASSERT(CONFIG_BT_BUF_EVT_RX_COUNT > CONFIG_BT_BUF_ACL_TX_COUNT,
179 "Increase Event RX buffer count to be greater than ACL TX buffer count");
182#define BT_BUF_RX_COUNT (CONFIG_BT_BUF_EVT_RX_COUNT + \
183 MAX(BT_BUF_ACL_RX_COUNT, BT_BUF_ISO_RX_COUNT))
186#define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE)
static enum bt_buf_type bt_buf_type_from_h4(uint8_t h4_type, enum bt_buf_dir dir)
Convert from H:4 type to bt_buf_type.
Definition buf.h:93
#define BT_BUF_ACL_RX_COUNT
Definition buf.h:161
static enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
Get the buffer type.
Definition buf.h:267
struct net_buf * bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout)
Allocate a buffer for incoming data.
struct net_buf * bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, const void *data, size_t size)
Allocate a buffer for outgoing data.
struct net_buf * bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout)
Allocate a buffer for an HCI Event.
#define BT_BUF_ACL_RX_COUNT_MAX
Definition buf.h:144
bt_buf_dir
Direction of HCI packets.
Definition buf.h:56
static uint8_t bt_buf_type_to_h4(enum bt_buf_type type)
Convert from bt_buf_type to H:4 type.
Definition buf.h:68
static void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
Set the buffer type.
Definition buf.h:253
void(* bt_buf_rx_freed_cb_t)(enum bt_buf_type type_mask)
A callback to notify about freed buffer in the incoming data pool.
Definition buf.h:212
void bt_buf_rx_freed_cb_set(bt_buf_rx_freed_cb_t cb)
Set the callback to notify about freed buffer in the incoming data pool.
bt_buf_type
Possible types of buffers passed around the Bluetooth stack in a form of bitmask.
Definition buf.h:38
@ BT_BUF_OUT
Packet from the host to the controller.
Definition buf.h:60
@ BT_BUF_IN
Packet from the controller to the host.
Definition buf.h:58
@ BT_BUF_EVT
HCI event.
Definition buf.h:44
@ BT_BUF_TYPE_NONE
Unknown/invalid packet type, used for error checking.
Definition buf.h:40
@ BT_BUF_ISO_OUT
Outgoing ISO data.
Definition buf.h:50
@ BT_BUF_ACL_OUT
Outgoing ACL data.
Definition buf.h:46
@ BT_BUF_ISO_IN
Incoming ISO data.
Definition buf.h:52
@ BT_BUF_CMD
HCI command.
Definition buf.h:42
@ BT_BUF_ACL_IN
Incoming ACL data.
Definition buf.h:48
static uint8_t net_buf_pull_u8(struct net_buf *buf)
Remove a 8-bit value from the beginning of the buffer.
Definition net_buf.h:2258
static void net_buf_push_u8(struct net_buf *buf, uint8_t val)
Push 8-bit value to the beginning of the buffer.
Definition net_buf.h:2043
static size_t net_buf_headroom(const struct net_buf *buf)
Check buffer headroom.
Definition net_buf.h:2466
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define BT_HCI_H4_ACL
Definition hci_types.h:31
#define BT_HCI_H4_CMD
Definition hci_types.h:30
#define BT_HCI_H4_EVT
Definition hci_types.h:33
#define BT_HCI_H4_ISO
Definition hci_types.h:34
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Kernel timeout type.
Definition sys_clock.h:65
Network buffer representation.
Definition net_buf.h:1006
uint16_t size
Amount of data that this buffer can store.
Definition net_buf.h:1038
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1032
Variables needed for system clock.