Skip to content

Commit

Permalink
[nrf noup] bluetooth: att: Allow ATT sent callback after data TX is done
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
MarekPieta authored and anangl committed Jul 1, 2024
1 parent 178b807 commit d74e0b5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions subsys/bluetooth/host/Kconfig.gatt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ config BT_ATT_RETRY_ON_SEC_ERR
If an ATT request fails due to insufficient security, the host will
try to elevate the security level and retry the ATT request.

config BT_ATT_SENT_CB_AFTER_TX
bool "Delay ATT sent callback until data transmission is done by controller [EXPERIMENTAL]"
select EXPERIMENTAL
help
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 called
upon receiving the Number of Completed Packets HCI Event).

The feature is not available in Zephyr RTOS (it's specific to NCS
Zephyr fork). It is a temporary solution allowing to control flow of
GATT notifications with HID reports for HID use-case.

Enabling this option may require increasing CONFIG_BT_CONN_TX_MAX in
configuration, because ATT would use additional TX contexts.

config BT_EATT
bool "Enhanced ATT Bearers support [EXPERIMENTAL]"
depends on BT_L2CAP_ECRED
Expand Down
18 changes: 17 additions & 1 deletion subsys/bluetooth/host/att.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ static void att_sent(void *user_data)
bt_att_sent(chan);
}

static void chan_sent_cb(struct bt_conn *conn, void *user_data, int err)
{
struct net_buf *nb = user_data;

net_buf_unref(nb);
}

/* In case of success the ownership of the buffer is transferred to the stack
* which takes care of releasing it when it completes transmitting to the
* controller.
Expand Down Expand Up @@ -353,7 +360,16 @@ static int chan_send(struct bt_att_chan *chan, struct net_buf *buf)

data->att_chan = chan;

err = bt_l2cap_send(chan->att->conn, BT_L2CAP_CID_ATT, buf);
if (IS_ENABLED(CONFIG_BT_ATT_SENT_CB_AFTER_TX)) {
err = bt_l2cap_send_cb(chan->att->conn, BT_L2CAP_CID_ATT, buf, chan_sent_cb,
net_buf_ref(buf));
if (err) {
net_buf_unref(buf);
}
} else {
err = bt_l2cap_send(chan->att->conn, BT_L2CAP_CID_ATT, buf);
}

if (err) {
if (err == -ENOBUFS) {
LOG_ERR("Ran out of TX buffers or contexts.");
Expand Down

0 comments on commit d74e0b5

Please sign in to comment.