From 91f531b14efe2c85823dd4ae872350d644a77bd3 Mon Sep 17 00:00:00 2001 From: luomanruo Date: Thu, 24 Aug 2023 14:42:15 +0800 Subject: [PATCH 1/2] ble: Fix hci issues when chain mbuf exists --- components/bt/host/bluedroid/hci/hci_hal_h4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/hci/hci_hal_h4.c b/components/bt/host/bluedroid/hci/hci_hal_h4.c index d7dbe2ef57..7a1377f611 100644 --- a/components/bt/host/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/host/bluedroid/hci/hci_hal_h4.c @@ -613,7 +613,7 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg) int ble_hs_rx_data(struct os_mbuf *om, void *arg) { - uint16_t len = om->om_len + 1; + uint16_t len = OS_MBUF_PKTHDR(om)->omp_len + 1; uint8_t *data = (uint8_t *)malloc(len); assert(data != NULL); data[0] = 0x02; From 3f6dd76e41a69858bed2ee032c2b17d77d56a2d9 Mon Sep 17 00:00:00 2001 From: luomanruo Date: Thu, 24 Aug 2023 15:13:55 +0800 Subject: [PATCH 2/2] ble: Assert when getting memory fail --- components/bt/controller/esp32c2/bt.c | 1 + components/bt/controller/esp32c6/bt.c | 1 + components/bt/controller/esp32h2/bt.c | 1 + 3 files changed, 3 insertions(+) diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index a0bd38381d..bdf1d9f36a 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -311,6 +311,7 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len) if (*(data) == DATA_TYPE_COMMAND) { struct ble_hci_cmd *cmd = NULL; cmd = (struct ble_hci_cmd *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD); + assert(cmd); memcpy((uint8_t *)cmd, data + 1, len - 1); ble_hci_trans_hs_cmd_tx((uint8_t *)cmd); } diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 4525ccd1f3..4072d0286f 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -317,6 +317,7 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len) if (*(data) == DATA_TYPE_COMMAND) { struct ble_hci_cmd *cmd = NULL; cmd = (struct ble_hci_cmd *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD); + assert(cmd); memcpy((uint8_t *)cmd, data + 1, len - 1); ble_hci_trans_hs_cmd_tx((uint8_t *)cmd); } diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 70be325b2a..d676aa4822 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -313,6 +313,7 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len) if (*(data) == DATA_TYPE_COMMAND) { struct ble_hci_cmd *cmd = NULL; cmd = (struct ble_hci_cmd *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD); + assert(cmd); memcpy((uint8_t *)cmd, data + 1, len - 1); ble_hci_trans_hs_cmd_tx((uint8_t *)cmd); }