Skip to content

Commit ae06abb

Browse files
MarekPietarlubos
authored andcommitted
[nrf noup] bluetooth: conn: Allow for an extra ref in bt_l2cap_send_pdu
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]>
1 parent 9efb149 commit ae06abb

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,13 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf,
695695

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

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

700706
if (buf->len > frag_len) {
701707
LOG_DBG("keep %p around", buf);

subsys/bluetooth/host/l2cap.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,17 @@ int bt_l2cap_send_pdu(struct bt_l2cap_le_chan *le_chan, struct net_buf *pdu,
721721
return -ENOTCONN;
722722
}
723723

724-
if (pdu->ref != 1) {
724+
/* Allow for an additional buffer reference if callback is provided. This can be used to
725+
* extend lifetime of the net buffer until the data transmission is confirmed by ACK of the
726+
* remote.
727+
*/
728+
if (pdu->ref > 1 + (cb ? 1 : 0)) {
725729
/* The host may alter the buf contents when fragmenting. Higher
726730
* layers cannot expect the buf contents to stay intact. Extra
727731
* refs suggests a silent data corruption would occur if not for
728732
* this error.
729733
*/
730-
LOG_ERR("Expecting 1 ref, got %d", pdu->ref);
734+
LOG_ERR("Expecting up to %d refs, got %d", cb ? 2 : 1, pdu->ref);
731735
return -EINVAL;
732736
}
733737

0 commit comments

Comments
 (0)