Skip to content

Commit eb046f3

Browse files
MarekPietajukkar
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]> (cherry picked from commit 90daf74)
1 parent 068b311 commit eb046f3

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,12 +711,19 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf,
711711

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

714-
/* Check that buf->ref is 1 or 2. It would be 1 if this
715-
* was the only reference (e.g. buf was removed
716-
* from the conn tx_queue). It would be 2 if the
717-
* tx_data_pull kept it on the tx_queue for segmentation.
714+
/* Check that buf->ref is 1 or 2. It would be 1 if this was
715+
* the only reference (e.g. buf was removed from the conn
716+
* tx_queue). It would be 2 if the tx_data_pull kept it on
717+
* the tx_queue for segmentation.
718+
*
719+
* Allow for an additional buffer reference if callback is
720+
* provided. This can be used to extend lifetime of the net
721+
* buffer until the data transmission is confirmed by ACK of
722+
* the remote.
718723
*/
719-
__ASSERT_NO_MSG((buf->ref == 1) || (buf->ref == 2));
724+
if (buf->ref > 2 + (cb ? 1 : 0)) {
725+
__ASSERT_NO_MSG(false);
726+
}
720727

721728
/* The reference is always transferred to the frag, so when
722729
* the frag is destroyed, the parent reference is decremented.

subsys/bluetooth/host/l2cap.c

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

747-
if (pdu->ref != 1) {
747+
/* Allow for an additional buffer reference if callback is provided. This can be used to
748+
* extend lifetime of the net buffer until the data transmission is confirmed by ACK of the
749+
* remote.
750+
*/
751+
if (pdu->ref > 1 + (cb ? 1 : 0)) {
748752
/* The host may alter the buf contents when fragmenting. Higher
749753
* layers cannot expect the buf contents to stay intact. Extra
750754
* refs suggests a silent data corruption would occur if not for
751755
* this error.
752756
*/
753-
LOG_ERR("Expecting 1 ref, got %d", pdu->ref);
757+
LOG_ERR("Expecting up to %d refs, got %d", cb ? 2 : 1, pdu->ref);
754758
return -EINVAL;
755759
}
756760

0 commit comments

Comments
 (0)