From df2e4440e0add798a2893f67d548d0e80204d6d0 Mon Sep 17 00:00:00 2001 From: Mayank Tyagi Date: Mon, 16 Mar 2026 12:56:31 +0530 Subject: [PATCH] feat(nimble): Add BLE HCI logging support for ESP Insights --- nimble/host/src/ble_hs.c | 9 +++++++-- nimble/host/src/ble_hs_hci.c | 6 ++++++ nimble/host/src/ble_hs_hci_cmd.c | 14 ++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index e2be2f642..7ba168da8 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -844,6 +844,9 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg) data[0] = 0x02; os_mbuf_copydata(om, 0, len, &data[1]); bt_hci_log_record_hci_data(HCI_LOG_DATA_TYPE_C2H_ACL, &data[1], len); +#if BT_HCI_INSIGHTS_INCLUDED + bt_hci_log_record_insights(HCI_LOG_DATA_TYPE_C2H_ACL, &data[1], len); +#endif } #endif // (BT_HCI_LOG_INCLUDED == TRUE) @@ -879,10 +882,12 @@ ble_hs_tx_data(struct os_mbuf *om) uint8_t data[BLE_HS_HCI_LOG_BUF_SIZE]; data[0] = 0x02; os_mbuf_copydata(om, 0, pkt_len, &data[1]); - bt_hci_log_record_hci_data(data[0], &data[1], pkt_len); + bt_hci_log_record_hci_data(HCI_LOG_DATA_TYPE_H2C_ACL, &data[1], pkt_len); +#if BT_HCI_INSIGHTS_INCLUDED + bt_hci_log_record_insights(HCI_LOG_DATA_TYPE_H2C_ACL, &data[1], pkt_len); +#endif } #endif - return ble_transport_to_ll_acl(om); } #endif diff --git a/nimble/host/src/ble_hs_hci.c b/nimble/host/src/ble_hs_hci.c index 57e85e280..fd52157b0 100644 --- a/nimble/host/src/ble_hs_hci.c +++ b/nimble/host/src/ble_hs_hci.c @@ -698,8 +698,14 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg) uint16_t len = hci_ev[1] + 3; if (host_recv_adv_packet(hci_ev)) { bt_hci_log_record_hci_adv(HCI_LOG_DATA_TYPE_ADV, &hci_ev[1], len - 2); +#if BT_HCI_INSIGHTS_INCLUDED + bt_hci_log_record_insights(HCI_LOG_DATA_TYPE_ADV, &hci_ev[1], len - 2); +#endif } else { bt_hci_log_record_hci_data(0x04, &hci_ev[0], len - 1); +#if BT_HCI_INSIGHTS_INCLUDED + bt_hci_log_record_insights(0x04, &hci_ev[0], len - 1); +#endif } #endif // #if (BT_HCI_LOG_INCLUDED == TRUE) diff --git a/nimble/host/src/ble_hs_hci_cmd.c b/nimble/host/src/ble_hs_hci_cmd.c index 851260027..24888d8dc 100644 --- a/nimble/host/src/ble_hs_hci_cmd.c +++ b/nimble/host/src/ble_hs_hci_cmd.c @@ -27,8 +27,6 @@ #if (BT_HCI_LOG_INCLUDED == TRUE) #include "hci_log/bt_hci_log.h" #endif // (BT_HCI_LOG_INCLUDED == TRUE) - - /* * HCI Command Header * @@ -39,7 +37,6 @@ * command header */ #define BLE_HCI_CMD_HDR_LEN (3) - static int ble_hs_hci_cmd_transport(struct ble_hci_cmd *cmd) { @@ -96,14 +93,11 @@ ble_hs_hci_cmd_send(uint16_t opcode, uint8_t len, const void *cmddata) buf--; #endif -#if ((BT_HCI_LOG_INCLUDED == TRUE)) - uint8_t *data; -#if !(SOC_ESP_NIMBLE_CONTROLLER) && CONFIG_BT_CONTROLLER_ENABLED - data = (uint8_t *)buf + 1; -#else - data = (uint8_t *)buf; +#if ((BT_HCI_LOG_INCLUDED == TRUE) && SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED) + bt_hci_log_record_hci_data(0x01, (uint8_t *)buf, len + BLE_HCI_CMD_HDR_LEN); +#if BT_HCI_INSIGHTS_INCLUDED + bt_hci_log_record_insights(0x01, (uint8_t *)buf, len + BLE_HCI_CMD_HDR_LEN); #endif - bt_hci_log_record_hci_data(0x01, data, len + BLE_HCI_CMD_HDR_LEN); #endif rc = ble_hs_hci_cmd_transport((void *) buf);