Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ca01a4b
[nrf fromtree] Bluetooth: L2CAP: Fix leaking tx metadata
Tronil Nov 22, 2023
d7405d1
[nrf fromtree] Bluetooth: L2CAP: stop stealing buffers from SDU pool
jori-nordic Jan 11, 2024
f58da74
[nrf fromtree] Bluetooth: L2CAP: Don't try to send on disconnected ch…
jori-nordic Apr 17, 2024
cacf7de
[nrf fromtree] Bluetooth: host: handle not getting a buffer
jori-nordic May 2, 2024
93b9835
[nrf fromtree] Bluetooth: Host: Guard set state in conn_destroy
Thalley May 14, 2024
8c443bc
[nrf fromtree] Bluetooth: Host: Free ACL RX fragments on disconnection
jori-nordic Aug 8, 2024
834fa7e
[nrf fromtree] Bluetooth: host: Fix bug in disconnected handling
jthm-ot Nov 15, 2024
d170de6
[nrf fromtree] Bluetooth: Host: Use actual user_data size
LingaoM Dec 6, 2023
b462852
[nrf fromtree] Bluetooth: Host: Remove use of `bt_buf_get_cmd_complete`
alwa-nordic Jan 22, 2024
8c9e904
[nrf fromtree] Bluetooth: Host: Remove `bt_buf_get_cmd_complete`
alwa-nordic Jan 24, 2024
f86abef
[nrf fromtree] Bluetooth: Host: Refactor `bt_buf_get_evt`
alwa-nordic Jan 25, 2024
3bd7830
[nrf fromtree] Bluetooth: ISO: Add CONFIG_BT_ISO_{RX/TX}
Thalley Feb 28, 2024
5d34244
[nrf fromtree] Bluetooth: Rename `num_complete_pool` -> `sync_evt_pool`
alwa-nordic Apr 23, 2024
714b3f1
[nrf fromtree] Bluetooth: host: Use correct user_data size for hci_rx…
jori-nordic Jul 11, 2024
6fbd605
[nrf fromtree] Bluetooth: buf: Put command complete/status in sync bu…
jori-nordic Sep 13, 2024
932eb8e
[nrf fromtree] Bluetooth: Host: Deprecate `BT_BUF_ACL_RX_COUNT` symbol
theob-pro Nov 21, 2024
1aaac36
[nrf fromtree] Bluetooth: Controller: Fix HCI command buffer allocati…
cvinayak Jan 10, 2025
f564264
[nrf noup] Bluetooth: Controller: Fix use of HAS_BT_CTLR with BT_CTLR
cvinayak Jan 10, 2025
d30692e
[nrf fromtree] bluetooth: buf: Add a callback for freed buffer in rx …
PavelVPV Nov 7, 2024
194fd27
[nrf fromtree] Bluetoth: Host: Fix buffer allocation warnings in syst…
jhedberg Feb 21, 2025
cc62268
[nrf fromtree] Bluetooth: Host: Fix deadlock when failing to alloc on…
KyraLengfeld Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/releases/migration-guide-3.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ Bluetooth
Any pointer to a UUID must be prefixed with `const`, otherwise there will be a compilation warning.
For example change ``struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)`` to
``const struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)``. (:github:`66136`)
* The :c:func:`bt_l2cap_chan_send` API no longer allocates buffers from the same pool as its `buf`
parameter when segmenting SDUs into PDUs. In order to reproduce the previous behavior, the
application should register the `alloc_seg` channel callback and allocate from the same pool as
`buf`.

* Mesh

Expand Down
73 changes: 58 additions & 15 deletions include/zephyr/bluetooth/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,47 @@ struct bt_buf_data {
#define BT_BUF_ISO_RX_COUNT 0
#endif /* CONFIG_BT_ISO */

/* see Core Spec v6.0 vol.4 part E 7.4.5 */
#define BT_BUF_ACL_RX_COUNT_MAX 65535

#if defined(CONFIG_BT_CONN) && defined(CONFIG_BT_HCI_HOST)
/* The host needs more ACL buffers than maximum ACL links. This is because of
* the way we re-assemble ACL packets into L2CAP PDUs.
*
* We keep around the first buffer (that comes from the driver) to do
* re-assembly into, and if all links are re-assembling, there will be no buffer
* available for the HCI driver to allocate from.
*
* TODO: When CONFIG_BT_BUF_ACL_RX_COUNT is removed,
* remove the MAX and only keep the 1.
*/
#define BT_BUF_ACL_RX_COUNT_EXTRA CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA
#define BT_BUF_ACL_RX_COUNT (MAX(CONFIG_BT_BUF_ACL_RX_COUNT, 1) + BT_BUF_ACL_RX_COUNT_EXTRA)
#else
#define BT_BUF_ACL_RX_COUNT_EXTRA 0
#define BT_BUF_ACL_RX_COUNT 0
#endif /* CONFIG_BT_CONN && CONFIG_BT_HCI_HOST */

#if defined(CONFIG_BT_BUF_ACL_RX_COUNT) && CONFIG_BT_BUF_ACL_RX_COUNT > 0
#warning "CONFIG_BT_BUF_ACL_RX_COUNT is deprecated, see Zephyr 4.1 migration guide"
#endif /* CONFIG_BT_BUF_ACL_RX_COUNT && CONFIG_BT_BUF_ACL_RX_COUNT > 0 */

BUILD_ASSERT(BT_BUF_ACL_RX_COUNT <= BT_BUF_ACL_RX_COUNT_MAX,
"Maximum number of ACL RX buffer is 65535, reduce CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA");

/** Data size needed for HCI ACL, HCI ISO or Event RX buffers */
#define BT_BUF_RX_SIZE (MAX(MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE), \
BT_BUF_ISO_RX_SIZE))

/** Buffer count needed for HCI ACL, HCI ISO or Event RX buffers */
#define BT_BUF_RX_COUNT (MAX(MAX(CONFIG_BT_BUF_EVT_RX_COUNT, \
CONFIG_BT_BUF_ACL_RX_COUNT), \
BT_BUF_ISO_RX_COUNT))
/* Controller can generate up to CONFIG_BT_BUF_ACL_TX_COUNT number of unique HCI Number of Completed
* Packets events.
*/
BUILD_ASSERT(CONFIG_BT_BUF_EVT_RX_COUNT > CONFIG_BT_BUF_ACL_TX_COUNT,
"Increase Event RX buffer count to be greater than ACL TX buffer count");

/** Buffer count needed for HCI ACL or HCI ISO plus Event RX buffers */
#define BT_BUF_RX_COUNT (CONFIG_BT_BUF_EVT_RX_COUNT + \
MAX(BT_BUF_ACL_RX_COUNT, BT_BUF_ISO_RX_COUNT))

/** Data size needed for HCI Command buffers. */
#define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE)
Expand All @@ -113,6 +146,27 @@ struct bt_buf_data {
*/
struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout);

/** A callback to notify about freed buffer in the incoming data pool.
*
* This callback is called when a buffer of a given type is freed and can be requested through the
* @ref bt_buf_get_rx function. However, this callback is called from the context of the buffer
* freeing operation and must not attempt to allocate a new buffer from the same pool.
*
* @warning When this callback is called, the scheduler is locked and the callee must not perform
* any action that makes the current thread unready. This callback must only be used for very
* short non-blocking operation (e.g. submitting a work item).
*
* @param type_mask A bit mask of buffer types that have been freed.
*/
typedef void (*bt_buf_rx_freed_cb_t)(enum bt_buf_type type_mask);

/** Set the callback to notify about freed buffer in the incoming data pool.
*
* @param cb Callback to notify about freed buffer in the incoming data pool. If NULL, the callback
* is disabled.
*/
void bt_buf_rx_freed_cb_set(bt_buf_rx_freed_cb_t cb);

/** Allocate a buffer for outgoing data
*
* This will set the buffer type so bt_buf_set_type() does not need to
Expand All @@ -129,17 +183,6 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout);
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 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().
*
* @param timeout Non-negative waiting period to obtain a buffer or one of the
* special values K_NO_WAIT and K_FOREVER.
* @return A new buffer.
*/
struct net_buf *bt_buf_get_cmd_complete(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
Expand Down
7 changes: 4 additions & 3 deletions include/zephyr/bluetooth/l2cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,10 @@ int bt_l2cap_chan_disconnect(struct bt_l2cap_chan *chan);
* If the application is reserving the bytes it should use the
* BT_L2CAP_BUF_SIZE() helper to correctly size the buffers for the for the
* outgoing buffer pool.
* When segmenting an L2CAP SDU into L2CAP PDUs the stack will first attempt
* to allocate buffers from the original buffer pool of the L2CAP SDU before
* using the stacks own buffer pool.
* When segmenting an L2CAP SDU into L2CAP PDUs the stack will first attempt to
* allocate buffers from the channel's `alloc_seg` callback and will fallback
* on the stack's global buffer pool (sized
* @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}).
*
* @note Buffer ownership is transferred to the stack in case of success, in
* case of an error the caller retains the ownership of the buffer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=16


# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

# Controller
CONFIG_BT_LL_SW_SPLIT=y

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
5 changes: 0 additions & 5 deletions samples/bluetooth/hci_ipc/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=16


# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

# Enable and adjust the below value as necessary
# CONFIG_BT_BUF_EVT_RX_COUNT=16
# CONFIG_BT_BUF_EVT_RX_SIZE=255
Expand Down
4 changes: 0 additions & 4 deletions samples/bluetooth/hci_uart/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@ CONFIG_BT_TINYCRYPT_ECC=n
CONFIG_BT_CTLR_DTM_HCI=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10
4 changes: 0 additions & 4 deletions samples/bluetooth/hci_usb/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10
4 changes: 3 additions & 1 deletion samples/bluetooth/mesh/boards/bbc_microbit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ CONFIG_BT_PERIPHERAL=n
CONFIG_BT_EXT_ADV=n
CONFIG_BT_RX_STACK_SIZE=1100
CONFIG_BT_BUF_EVT_RX_COUNT=3
CONFIG_BT_BUF_ACL_RX_COUNT=3
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=3

# CONFIG_BT_BUF_ACL_TX_COUNT has to be less than CONFIG_BT_BUF_EVT_RX_COUNT
CONFIG_BT_BUF_ACL_TX_COUNT=1

CONFIG_BT_CTLR_ADV_EXT=n

CONFIG_BT_MESH_ADV_BUF_COUNT=3
Expand Down
3 changes: 1 addition & 2 deletions samples/bluetooth/peripheral_hr/prj_minimal.conf
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ CONFIG_BT_CTLR_PHY_2M=n
# Reduce Bluetooth buffers
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=45
CONFIG_BT_BUF_ACL_RX_COUNT=2
CONFIG_BT_BUF_EVT_RX_COUNT=2
CONFIG_BT_BUF_EVT_RX_COUNT=4

CONFIG_BT_CONN_TX_MAX=2
CONFIG_BT_L2CAP_TX_BUF_COUNT=2
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ config BT_MAX_CONN

config BT_CONN_TX
bool
default BT_CONN || BT_ISO_BROADCASTER
default BT_CONN || BT_ISO_TX
help
Hidden configuration that is true if ACL or broadcast ISO is enabled

Expand Down
10 changes: 10 additions & 0 deletions subsys/bluetooth/Kconfig.iso
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
config BT_ISO
bool

config BT_ISO_TX
bool

config BT_ISO_RX
bool

# TODO: Split between client (central) and server (peripheral)
config BT_ISO_UNICAST
bool
depends on BT_CONN
select BT_ISO
select BT_ISO_TX
select BT_ISO_RX
help
This option enables support for Bluetooth Unicast
Isochronous channels.
Expand Down Expand Up @@ -45,6 +53,7 @@ config BT_ISO_BROADCASTER
bool "Bluetooth Isochronous Broadcaster Support [EXPERIMENTAL]"
depends on !BT_CTLR || BT_CTLR_ADV_ISO_SUPPORT
select BT_ISO_BROADCAST
select BT_ISO_TX
select BT_BROADCASTER
select BT_PER_ADV
select EXPERIMENTAL
Expand All @@ -55,6 +64,7 @@ config BT_ISO_SYNC_RECEIVER
bool "Bluetooth Isochronous Synchronized Receiver Support [EXPERIMENTAL]"
depends on !BT_CTLR || BT_CTLR_SYNC_ISO_SUPPORT
select BT_ISO_BROADCAST
select BT_ISO_RX
select BT_OBSERVER
select BT_PER_ADV_SYNC
select EXPERIMENTAL
Expand Down
Loading
Loading