Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
buf.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2016 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10
11#ifndef ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
12#define ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
13
21#include <stdint.h>
22
23#include <zephyr/net_buf.h>
25#include <zephyr/sys/util.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
48
53
54/* Headroom reserved in buffers, primarily for HCI transport encoding purposes */
55#define BT_BUF_RESERVE 1
56
58#define BT_BUF_SIZE(size) (BT_BUF_RESERVE + (size))
59
61#define BT_BUF_ACL_SIZE(size) BT_BUF_SIZE(BT_HCI_ACL_HDR_SIZE + (size))
62
64#define BT_BUF_EVT_SIZE(size) BT_BUF_SIZE(BT_HCI_EVT_HDR_SIZE + (size))
65
67#define BT_BUF_CMD_SIZE(size) BT_BUF_SIZE(BT_HCI_CMD_HDR_SIZE + (size))
68
70#define BT_BUF_ISO_SIZE(size) BT_BUF_SIZE(BT_HCI_ISO_HDR_SIZE + \
71 BT_HCI_ISO_SDU_TS_HDR_SIZE + \
72 (size))
73
75#define BT_BUF_ACL_RX_SIZE BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE)
76
78#define BT_BUF_EVT_RX_SIZE BT_BUF_EVT_SIZE(CONFIG_BT_BUF_EVT_RX_SIZE)
79
80#if defined(CONFIG_BT_ISO)
81#define BT_BUF_ISO_RX_SIZE BT_BUF_ISO_SIZE(CONFIG_BT_ISO_RX_MTU)
82#define BT_BUF_ISO_RX_COUNT CONFIG_BT_ISO_RX_BUF_COUNT
83#else
84#define BT_BUF_ISO_RX_SIZE 0
85#define BT_BUF_ISO_RX_COUNT 0
86#endif /* CONFIG_BT_ISO */
87
89#define BT_BUF_RX_SIZE (MAX(MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE), \
90 BT_BUF_ISO_RX_SIZE))
91
93#define BT_BUF_RX_COUNT (MAX(MAX(CONFIG_BT_BUF_EVT_RX_COUNT, \
94 CONFIG_BT_BUF_ACL_RX_COUNT), \
95 BT_BUF_ISO_RX_COUNT))
96
98#define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE)
99
111struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout);
112
126struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout,
127 const void *data, size_t size);
128
140struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout);
141
147static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
148{
149 ((struct bt_buf_data *)net_buf_user_data(buf))->type = type;
150}
151
158static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
159{
160 return (enum bt_buf_type)((struct bt_buf_data *)net_buf_user_data(buf))
161 ->type;
162}
163
168#ifdef __cplusplus
169}
170#endif
171
172#endif /* ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_ */
static enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
Get the buffer type.
Definition buf.h:158
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.
static void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
Set the buffer type.
Definition buf.h:147
bt_buf_type
Possible types of buffers passed around the Bluetooth stack.
Definition buf.h:32
@ BT_BUF_EVT
HCI event.
Definition buf.h:36
@ BT_BUF_ISO_OUT
Outgoing ISO data.
Definition buf.h:42
@ BT_BUF_ACL_OUT
Outgoing ACL data.
Definition buf.h:38
@ BT_BUF_ISO_IN
Incoming ISO data.
Definition buf.h:44
@ BT_BUF_CMD
HCI command.
Definition buf.h:34
@ BT_BUF_H4
H:4 data.
Definition buf.h:46
@ BT_BUF_ACL_IN
Incoming ACL data.
Definition buf.h:40
static void * net_buf_user_data(const struct net_buf *buf)
Get a pointer to the user data of a buffer.
Definition net_buf.h:1576
Buffer management.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
This is a base type for bt_buf user data.
Definition buf.h:50
uint8_t type
Definition buf.h:51
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
Misc utilities.