Merge branch 'bugfix/l2cap_malloc_fail_v5.2' into 'release/v5.2'

fix(bt): fix l2cap malloc fail in throughput test(v5.2)

See merge request espressif/esp-idf!44848
This commit is contained in:
Wang Meng Yang
2026-01-14 20:05:00 +08:00
3 changed files with 22 additions and 11 deletions

View File

@@ -42,6 +42,7 @@
#define VFS_CLOSE_TIMEOUT (20 * 1000)
#define BTC_L2CAP_ROLE_MASTER 0
#define BTC_L2CAP_ROLE_SLAVE 1
#define BTC_L2CAP_RX_MTU (990)
typedef struct {
bool peer_fc; /* true if flow control is set based on peer's request */
@@ -101,10 +102,10 @@ static const tL2CAP_ERTM_INFO obex_l2c_etm_opt =
{
L2CAP_FCR_ERTM_MODE, /* Mandatory for OBEX over l2cap */
L2CAP_FCR_CHAN_OPT_ERTM, /* Mandatory for OBEX over l2cap */
OBX_USER_RX_POOL_ID,
OBX_USER_TX_POOL_ID,
OBX_FCR_RX_POOL_ID,
OBX_FCR_TX_POOL_ID
L2CAP_USER_RX_BUF_SIZE,
L2CAP_USER_TX_BUF_SIZE,
L2CAP_FCR_RX_BUF_SIZE,
L2CAP_FCR_TX_BUF_SIZE
};
#if L2CAP_DYNAMIC_MEMORY == FALSE
@@ -554,7 +555,7 @@ static void btc_l2cap_start_srv(btc_l2cap_args_t *arg)
cfg.fcr_present = TRUE;
cfg.fcr = obex_l2c_fcr_opts_def;
BTA_JvL2capStartServer(slot->security, slot->role, &obex_l2c_etm_opt, slot->psm,
L2CAP_MAX_SDU_LENGTH, &cfg, (tBTA_JV_L2CAP_CBACK *)btc_l2cap_inter_cb, (void *)slot->id);
BTC_L2CAP_RX_MTU, &cfg, (tBTA_JV_L2CAP_CBACK *)btc_l2cap_inter_cb, (void *)slot->id);
osi_mutex_unlock(&l2cap_local_param.l2cap_slot_mutex);
} while(0);
@@ -695,7 +696,7 @@ static void btc_l2cap_connect(btc_l2cap_args_t *arg)
cfg.fcr = obex_l2c_fcr_opts_def;
BTA_JvL2capConnect(slot->security, slot->role, &obex_l2c_etm_opt, slot->psm,
L2CAP_MAX_SDU_LENGTH, &cfg, slot->addr, (tBTA_JV_L2CAP_CBACK *)btc_l2cap_inter_cb, (void *)slot->id);
BTC_L2CAP_RX_MTU, &cfg, slot->addr, (tBTA_JV_L2CAP_CBACK *)btc_l2cap_inter_cb, (void *)slot->id);
osi_mutex_unlock(&l2cap_local_param.l2cap_slot_mutex);
} while (0);
@@ -1025,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);
@@ -1085,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);
}

View File

@@ -1992,7 +1992,7 @@
* in basic and streaming modes. Range: 1 - 63
*/
#ifndef OBX_FCR_OPT_TX_WINDOW_SIZE_BR_EDR
#define OBX_FCR_OPT_TX_WINDOW_SIZE_BR_EDR 20
#define OBX_FCR_OPT_TX_WINDOW_SIZE_BR_EDR 10
#endif
/*

View File

@@ -510,18 +510,19 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT
}
while (max_len) {
UINT16 length = (p_ccb->rem_mtu_size < max_len) ? p_ccb->rem_mtu_size : max_len;
if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) {
if ((p_buf = (BT_HDR *)osi_malloc(L2CAP_FCR_ERTM_BUF_SIZE)) == NULL) {
if ((p_buf = (BT_HDR *)osi_malloc(BT_HDR_SIZE + length + L2CAP_MIN_OFFSET + L2CAP_FCS_LEN)) == NULL) {
return (GAP_ERR_CONGESTED);
}
} else {
if ((p_buf = (BT_HDR *)osi_malloc(GAP_DATA_BUF_SIZE)) == NULL) {
if ((p_buf = (BT_HDR *)osi_malloc(BT_HDR_SIZE + length + L2CAP_MIN_OFFSET)) == NULL) {
return (GAP_ERR_CONGESTED);
}
}
p_buf->offset = L2CAP_MIN_OFFSET;
p_buf->len = (p_ccb->rem_mtu_size < max_len) ? p_ccb->rem_mtu_size : max_len;
p_buf->len = length;
p_buf->event = BT_EVT_TO_BTU_SP_DATA;
memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset, p_data, p_buf->len);