Data Buffers

API Reference

group bt_buf

Data buffers.

Defines

BT_BUF_RESERVE
BT_BUF_SIZE(size)

Helper to include reserved HCI data in buffer calculations

BT_BUF_ACL_SIZE(size)

Helper to calculate needed buffer size for HCI ACL packets

BT_BUF_EVT_SIZE(size)

Helper to calculate needed buffer size for HCI Event packets.

BT_BUF_CMD_SIZE(size)

Helper to calculate needed buffer size for HCI Command packets.

BT_BUF_ISO_SIZE(size)

Helper to calculate needed buffer size for HCI ISO packets.

BT_BUF_ACL_RX_SIZE

Data size needed for HCI ACL RX buffers

BT_BUF_EVT_RX_SIZE

Data size needed for HCI Event RX buffers

BT_BUF_ISO_RX_SIZE
BT_BUF_ISO_RX_COUNT
BT_BUF_RX_SIZE

Data size needed for HCI ACL, HCI ISO or Event RX buffers

BT_BUF_RX_COUNT

Buffer count needed for HCI ACL, HCI ISO or Event RX buffers

BT_BUF_CMD_TX_SIZE

Data size needed for HCI Command buffers.

Enums

enum bt_buf_type

Possible types of buffers passed around the Bluetooth stack

Values:

enumerator BT_BUF_CMD

HCI command

enumerator BT_BUF_EVT

HCI event

enumerator BT_BUF_ACL_OUT

Outgoing ACL data

enumerator BT_BUF_ACL_IN

Incoming ACL data

enumerator BT_BUF_ISO_OUT

Outgoing ISO data

enumerator BT_BUF_ISO_IN

Incoming ISO data

enumerator BT_BUF_H4

H:4 data

Functions

struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout)

Allocate a buffer for incoming data

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_recv_prio().

Parameters
  • type – Type of buffer. Only BT_BUF_EVT, BT_BUF_ACL_IN and BT_BUF_ISO_IN are allowed.

  • timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

Returns

A new buffer.

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

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_send().

Parameters
  • type – Type of buffer. Only BT_BUF_CMD, BT_BUF_ACL_OUT or BT_BUF_H4, when operating on H:4 mode, are allowed.

  • timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

  • data – Initial data to append to buffer.

  • size – Initial data size.

Returns

A new buffer.

struct net_buf *bt_buf_get_cmd_complete(k_timeout_t timeout)

Allocate a buffer for an HCI Command Complete/Status Event

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_recv_prio().

Parameters
  • timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

Returns

A new buffer.

struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout)

Allocate a buffer for an HCI Event

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_recv_prio() or bt_recv().

Parameters
  • evt – HCI event code

  • discardable – Whether the driver considers the event discardable.

  • timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

Returns

A new buffer.

static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)

Set the buffer type

Parameters
  • buf – Bluetooth buffer

  • type – The BT_* type to set the buffer to

static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)

Get the buffer type

Parameters
  • buf – Bluetooth buffer

Returns

The BT_* type to of the buffer

struct bt_buf_data
#include <buf.h>

This is a base type for bt_buf user data.