Skip to content

Commit 90daf74

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]> (cherry picked from commit 14c7424)
1 parent 1b7ccc6 commit 90daf74

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
@@ -702,12 +702,19 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf,
702702

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

705-
/* Check that buf->ref is 1 or 2. It would be 1 if this
706-
* was the only reference (e.g. buf was removed
707-
* from the conn tx_queue). It would be 2 if the
708-
* tx_data_pull kept it on the tx_queue for segmentation.
705+
/* Check that buf->ref is 1 or 2. It would be 1 if this was
706+
* the only reference (e.g. buf was removed from the conn
707+
* tx_queue). It would be 2 if the tx_data_pull kept it on
708+
* the tx_queue for segmentation.
709+
*
710+
* Allow for an additional buffer reference if callback is
711+
* provided. This can be used to extend lifetime of the net
712+
* buffer until the data transmission is confirmed by ACK of
713+
* the remote.
709714
*/
710-
__ASSERT_NO_MSG((buf->ref == 1) || (buf->ref == 2));
715+
if (buf->ref > 2 + (cb ? 1 : 0)) {
716+
__ASSERT_NO_MSG(false);
717+
}
711718

712719
/* The reference is always transferred to the frag, so when
713720
* 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
@@ -729,13 +729,17 @@ int bt_l2cap_send_pdu(struct bt_l2cap_le_chan *le_chan, struct net_buf *pdu,
729729
return -ENOTCONN;
730730
}
731731

732-
if (pdu->ref != 1) {
732+
/* Allow for an additional buffer reference if callback is provided. This can be used to
733+
* extend lifetime of the net buffer until the data transmission is confirmed by ACK of the
734+
* remote.
735+
*/
736+
if (pdu->ref > 1 + (cb ? 1 : 0)) {
733737
/* The host may alter the buf contents when fragmenting. Higher
734738
* layers cannot expect the buf contents to stay intact. Extra
735739
* refs suggests a silent data corruption would occur if not for
736740
* this error.
737741
*/
738-
LOG_ERR("Expecting 1 ref, got %d", pdu->ref);
742+
LOG_ERR("Expecting up to %d refs, got %d", cb ? 2 : 1, pdu->ref);
739743
return -EINVAL;
740744
}
741745

0 commit comments

Comments
 (0)