From 436ba67fed953327bf7b2563ca6e38ae3aa2eff7 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Wed, 24 Dec 2025 19:21:54 +0800 Subject: [PATCH] fix(bt): retry when L2CAP write fails --- .../host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c b/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c index 0abd4e81e0..ed31e6cf76 100644 --- a/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c +++ b/components/bt/host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c @@ -1026,6 +1026,15 @@ void btc_l2cap_cb_handler(btc_msg_t *msg) p_buf->event++; BTA_JvL2capWrite(p_data->l2c_write.handle, slot->id, p_buf->data + p_buf->offset, p_buf->len, (void *)slot->id); } + } else { + if (!p_data->l2c_write.cong && slot->connected) { + // retry + BTA_JvL2capWrite(p_data->l2c_write.handle, slot->id, p_buf->data + p_buf->offset, p_buf->len, (void *)slot->id); + } else { + p_buf->event--; + // Reset layer-specific flag to 0, marking packet as ready for transmission + p_buf->layer_specific = 0; + } } } osi_mutex_unlock(&l2cap_local_param.l2cap_slot_mutex); @@ -1086,7 +1095,7 @@ static ssize_t l2cap_vfs_write(int fd, const void * data, size_t size) } p_buf->offset = 0; p_buf->len = write_size; - p_buf->event = 0; // indicate the p_buf be sent count + p_buf->event = 0; // Indicate the count of successful sends of p_buf p_buf->layer_specific = 0; // indicate the p_buf whether to be sent, 0 - ready to send; 1 - have sent memcpy((UINT8 *)(p_buf + 1), data + sent, write_size); }