Skip to content

Commit

Permalink
[nrf noup] bluetooth: conn: Allow for an extra ref in bt_l2cap_send_pdu
Browse files Browse the repository at this point in the history
Allow for an additional buffer reference if callback is provided. This
can be used to extend lifetime of the net buffer until the data
transmission is confirmed by ACK of the remote.

Signed-off-by: Marek Pieta <[email protected]>
  • Loading branch information
MarekPieta authored and nordicjm committed Aug 1, 2024
1 parent ee94b90 commit e84675a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,13 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf,

uint16_t frag_len = MIN(conn_mtu(conn), len);

__ASSERT_NO_MSG(buf->ref == 1);
if (buf->ref > 1 + (cb ? 1 : 0)) {
/* Allow for an additional buffer reference if callback is provided.
* This can be used to extend lifetime of the net buffer until the
* data transmission is confirmed by ACK of the remote.
*/
__ASSERT_NO_MSG(false);
}

if (buf->len > frag_len) {
LOG_DBG("keep %p around", buf);
Expand Down
8 changes: 6 additions & 2 deletions subsys/bluetooth/host/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,17 @@ static void cancel_data_ready(struct bt_l2cap_le_chan *le_chan)
int bt_l2cap_send_pdu(struct bt_l2cap_le_chan *le_chan, struct net_buf *pdu,
bt_conn_tx_cb_t cb, void *user_data)
{
if (pdu->ref != 1) {
/* Allow for an additional buffer reference if callback is provided. This can be used to
* extend lifetime of the net buffer until the data transmission is confirmed by ACK of the
* remote.
*/
if (pdu->ref > 1 + (cb ? 1 : 0)) {
/* The host may alter the buf contents when fragmenting. Higher
* layers cannot expect the buf contents to stay intact. Extra
* refs suggests a silent data corruption would occur if not for
* this error.
*/
LOG_ERR("Expecting 1 ref, got %d", pdu->ref);
LOG_ERR("Expecting up to %d refs, got %d", cb ? 2 : 1, pdu->ref);
return -EINVAL;
}

Expand Down

0 comments on commit e84675a

Please sign in to comment.