Skip to content

Commit d74e0b5

Browse files
MarekPietaanangl
authored andcommitted
[nrf noup] bluetooth: att: Allow ATT sent callback after data TX is done
By default, the BLE stack calls sent callback for ATT data when the data is passed to BLE controller for transmission. Enabling this Kconfig option delays calling the sent callback until data transmission is finished by BLE controller (the callback is delayed until receiving the num complete packets event). Jira: NCSDK-27422 Signed-off-by: Marek Pieta <[email protected]> (cherry picked from commit 3611f46)
1 parent 178b807 commit d74e0b5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

subsys/bluetooth/host/Kconfig.gatt

+17
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ config BT_ATT_RETRY_ON_SEC_ERR
3030
If an ATT request fails due to insufficient security, the host will
3131
try to elevate the security level and retry the ATT request.
3232

33+
config BT_ATT_SENT_CB_AFTER_TX
34+
bool "Delay ATT sent callback until data transmission is done by controller [EXPERIMENTAL]"
35+
select EXPERIMENTAL
36+
help
37+
By default, the BLE stack calls sent callback for ATT data when the
38+
data is passed to BLE controller for transmission. Enabling this
39+
Kconfig option delays calling the sent callback until data
40+
transmission is finished by BLE controller (the callback is called
41+
upon receiving the Number of Completed Packets HCI Event).
42+
43+
The feature is not available in Zephyr RTOS (it's specific to NCS
44+
Zephyr fork). It is a temporary solution allowing to control flow of
45+
GATT notifications with HID reports for HID use-case.
46+
47+
Enabling this option may require increasing CONFIG_BT_CONN_TX_MAX in
48+
configuration, because ATT would use additional TX contexts.
49+
3350
config BT_EATT
3451
bool "Enhanced ATT Bearers support [EXPERIMENTAL]"
3552
depends on BT_L2CAP_ECRED

subsys/bluetooth/host/att.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ static void att_sent(void *user_data)
260260
bt_att_sent(chan);
261261
}
262262

263+
static void chan_sent_cb(struct bt_conn *conn, void *user_data, int err)
264+
{
265+
struct net_buf *nb = user_data;
266+
267+
net_buf_unref(nb);
268+
}
269+
263270
/* In case of success the ownership of the buffer is transferred to the stack
264271
* which takes care of releasing it when it completes transmitting to the
265272
* controller.
@@ -353,7 +360,16 @@ static int chan_send(struct bt_att_chan *chan, struct net_buf *buf)
353360

354361
data->att_chan = chan;
355362

356-
err = bt_l2cap_send(chan->att->conn, BT_L2CAP_CID_ATT, buf);
363+
if (IS_ENABLED(CONFIG_BT_ATT_SENT_CB_AFTER_TX)) {
364+
err = bt_l2cap_send_cb(chan->att->conn, BT_L2CAP_CID_ATT, buf, chan_sent_cb,
365+
net_buf_ref(buf));
366+
if (err) {
367+
net_buf_unref(buf);
368+
}
369+
} else {
370+
err = bt_l2cap_send(chan->att->conn, BT_L2CAP_CID_ATT, buf);
371+
}
372+
357373
if (err) {
358374
if (err == -ENOBUFS) {
359375
LOG_ERR("Ran out of TX buffers or contexts.");

0 commit comments

Comments
 (0)