feat(bt/nimble): support hci log for nimble

This commit is contained in:
zhiweijian 2024-05-14 11:13:54 +08:00
parent 3f9ab2d6a6
commit 42aa1be457
4 changed files with 34 additions and 46 deletions

View File

@ -31,8 +31,8 @@ static const char s_hex_to_char_mapping[16] = {
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
bt_hci_log_t g_bt_hci_log_data_ctl = {0};
bt_hci_log_t g_bt_hci_log_adv_ctl = {0};
static bt_hci_log_t g_bt_hci_log_data_ctl = {0};
static bt_hci_log_t g_bt_hci_log_adv_ctl = {0};
esp_err_t bt_hci_log_init(void)
{
@ -98,35 +98,35 @@ static char IRAM_ATTR *bt_data_type_to_str(uint8_t data_type)
{
case HCI_LOG_DATA_TYPE_COMMAND:
// hci cmd data
tag = "CMD";
tag = "C";
break;
case HCI_LOG_DATA_TYPE_H2C_ACL:
// host to controller hci acl data
tag = "HAL";
tag = "H";
break;
case HCI_LOG_DATA_TYPE_SCO:
// hci sco data
tag = "SCO";
tag = "S";
break;
case HCI_LOG_DATA_TYPE_EVENT:
// hci event
tag = "EVT";
tag = "E";
break;
case HCI_LOG_DATA_TYPE_ADV:
// controller adv report data
tag = "ADV";
tag = NULL;
break;
case HCI_LOG_DATA_TYPE_C2H_ACL:
// controller to host hci acl data
tag = "CAL";
tag = "D";
break;
case HCI_LOG_DATA_TYPE_SELF_DEFINE:
// self-defining data
tag = "ST";
tag = "S";
break;
default:
// unknown data type
tag = "UK";
tag = "U";
break;
}

View File

@ -213,7 +213,7 @@ static uint16_t transmit_data(serial_data_type_t type,
BTTRC_DUMP_BUFFER("Transmit Pkt", data, length);
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_record_hci_data(data[0], data, length);
bt_hci_log_record_hci_data(data[0], &data[1], length - 1);
#endif
// TX Data to target
esp_vhci_host_send_packet(data, length);
@ -540,6 +540,26 @@ static void host_send_pkt_available_cb(void)
hci_downstream_data_post(OSI_THREAD_MAX_TIMEOUT);
}
void bt_record_hci_data(uint8_t *data, uint16_t len)
{
#if (BT_HCI_LOG_INCLUDED == TRUE)
if ((data[0] == DATA_TYPE_EVENT) && (data[1] == HCI_BLE_EVENT) && ((data[3] == HCI_BLE_ADV_PKT_RPT_EVT) || (data[3] == HCI_BLE_DIRECT_ADV_EVT)
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
|| (data[3] == HCI_BLE_ADV_DISCARD_REPORT_EVT)
#endif // (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
#if (BLE_50_FEATURE_SUPPORT == TRUE)
|| (data[3] == HCI_BLE_EXT_ADV_REPORT_EVT) || (data[3] == HCI_BLE_PERIOD_ADV_REPORT_EVT)
#endif // (BLE_50_FEATURE_SUPPORT == TRUE)
)) {
bt_hci_log_record_hci_adv(HCI_LOG_DATA_TYPE_ADV, &data[2], len - 2);
} else {
uint8_t data_type = ((data[0] == 2) ? HCI_LOG_DATA_TYPE_C2H_ACL : data[0]);
bt_hci_log_record_hci_data(data_type, &data[1], len - 1);
}
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
}
static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
{
//Target has packet to host, malloc new buffer for packet
@ -551,13 +571,11 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
return 0;
}
bt_record_hci_data(data, len);
bool is_adv_rpt = host_recv_adv_packet(data);
if (!is_adv_rpt) {
#if (BT_HCI_LOG_INCLUDED == TRUE)
uint8_t data_type = ((data[0] == 2) ? HCI_LOG_DATA_TYPE_C2H_ACL : data[0]);
bt_hci_log_record_hci_data(data_type, data, len);
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
pkt_size = BT_HDR_SIZE + len;
pkt = (BT_HDR *) osi_calloc(pkt_size);
if (!pkt) {
@ -571,10 +589,6 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
memcpy(pkt->data, data, len);
fixed_queue_enqueue(hci_hal_env.rx_q, pkt, FIXED_QUEUE_MAX_TIMEOUT);
} else {
#if (BT_HCI_LOG_INCLUDED == TRUE)
// data type is adv report
bt_hci_log_record_hci_adv(HCI_LOG_DATA_TYPE_ADV, data, len);
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
#if !BLE_ADV_REPORT_FLOW_CONTROL
// drop the packets if pkt_queue length goes beyond upper limit
if (pkt_queue_length(hci_hal_env.adv_rpt_q) > HCI_HAL_BLE_ADV_RPT_QUEUE_LEN_MAX) {

View File

@ -21,8 +21,6 @@
#include "freertos/semphr.h"
#include "esp_compiler.h"
#include "soc/soc_caps.h"
#include "bt_common.h"
#include "hci_log/bt_hci_log.h"
#define NIMBLE_VHCI_TIMEOUT_MS 2000
#define BLE_HCI_EVENT_HDR_LEN (2)
@ -77,9 +75,6 @@ int ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
}
if (xSemaphoreTake(vhci_send_sem, NIMBLE_VHCI_TIMEOUT_MS / portTICK_PERIOD_MS) == pdTRUE) {
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_record_hci_data(cmd[0], cmd, len);
#endif
esp_vhci_host_send_packet(cmd, len);
} else {
rc = BLE_HS_ETIMEOUT_HCI;
@ -117,9 +112,6 @@ int ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
len += OS_MBUF_PKTLEN(om);
if (xSemaphoreTake(vhci_send_sem, NIMBLE_VHCI_TIMEOUT_MS / portTICK_PERIOD_MS) == pdTRUE) {
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_record_hci_data(data[0], data, len);
#endif
esp_vhci_host_send_packet(data, len);
} else {
rc = BLE_HS_ETIMEOUT_HCI;
@ -178,7 +170,6 @@ static void ble_hci_rx_acl(uint8_t *data, uint16_t len)
OS_EXIT_CRITICAL(sr);
}
/*
* @brief: BT controller callback function, used to notify the upper layer that
* controller is ready to receive command
@ -223,18 +214,12 @@ static int host_rcv_pkt(uint8_t *data, uint16_t len)
/* Allocate LE Advertising Report Event from lo pool only */
if ((data[1] == BLE_HCI_EVCODE_LE_META) &&
(data[3] == BLE_HCI_LE_SUBEV_ADV_RPT || data[3] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT)) {
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_record_hci_adv(HCI_LOG_DATA_TYPE_ADV, data, len);
#endif
evbuf = ble_transport_alloc_evt(1);
/* Skip advertising report if we're out of memory */
if (!evbuf) {
return 0;
}
} else {
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_record_hci_data(data[0], data, len);
#endif
evbuf = ble_transport_alloc_evt(0);
assert(evbuf != NULL);
}
@ -245,9 +230,6 @@ static int host_rcv_pkt(uint8_t *data, uint16_t len)
rc = ble_hci_trans_ll_evt_tx(evbuf);
assert(rc == 0);
} else if (data[0] == BLE_HCI_UART_H4_ACL) {
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_record_hci_data(HCI_LOG_DATA_TYPE_C2H_ACL, data, len);
#endif
ble_hci_rx_acl(data + 1, len - 1);
}
return 0;
@ -282,10 +264,6 @@ esp_err_t esp_nimble_hci_init(void)
goto err;
}
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_init();
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
xSemaphoreGive(vhci_send_sem);
#if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK)
@ -313,10 +291,6 @@ esp_err_t esp_nimble_hci_deinit(void)
ble_buf_free();
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_deinit();
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
#if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK)
ble_adv_list_deinit();
#endif

@ -1 +1 @@
Subproject commit 98381c527889fe55d9fd1db72410148beb41ce55
Subproject commit 3fa33344efef576e7c7b5028679f751337393b10