Data Buffers

API Reference

group bt_buf

Data buffers.

Defines

BT_BUF_USER_DATA_MIN

Minimum amount of user data size for buffers passed to the stack.

BT_BUF_RESERVE
BT_BUF_SIZE(size)
BT_BUF_RX_SIZE

Data size neeed for HCI RX 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().

Return

A new buffer.

Parameters
  • type: Type of buffer. Only BT_BUF_EVT and BT_BUF_ACL_IN are allowed.

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

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().

Return

A new buffer.

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.

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().

Return

A new buffer.

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

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().

Return

A new buffer.

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.

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

Return

The BT_* type to of the buffer

Parameters
  • buf: Bluetooth buffer

struct bt_buf_data
#include <buf.h>

This is a base type for bt_buf user data.