Skip to content

Commit 321f51d

Browse files
committed
Merge branch 'feat/add_hci_log_record_for_nimble_v5.3' into 'release/v5.3'
feat(bt/nimble): support hci log for nimble (backport v5.3) See merge request espressif/esp-idf!31424
2 parents e819b8c + 679df9e commit 321f51d

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

components/bt/common/hci_log/bt_hci_log.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static const char s_hex_to_char_mapping[16] = {
3131
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
3232
};
3333

34-
bt_hci_log_t g_bt_hci_log_data_ctl = {0};
35-
bt_hci_log_t g_bt_hci_log_adv_ctl = {0};
34+
static bt_hci_log_t g_bt_hci_log_data_ctl = {0};
35+
static bt_hci_log_t g_bt_hci_log_adv_ctl = {0};
3636

3737
esp_err_t bt_hci_log_init(void)
3838
{
@@ -98,35 +98,35 @@ static char IRAM_ATTR *bt_data_type_to_str(uint8_t data_type)
9898
{
9999
case HCI_LOG_DATA_TYPE_COMMAND:
100100
// hci cmd data
101-
tag = "CMD";
101+
tag = "C";
102102
break;
103103
case HCI_LOG_DATA_TYPE_H2C_ACL:
104104
// host to controller hci acl data
105-
tag = "HAL";
105+
tag = "H";
106106
break;
107107
case HCI_LOG_DATA_TYPE_SCO:
108108
// hci sco data
109-
tag = "SCO";
109+
tag = "S";
110110
break;
111111
case HCI_LOG_DATA_TYPE_EVENT:
112112
// hci event
113-
tag = "EVT";
113+
tag = "E";
114114
break;
115115
case HCI_LOG_DATA_TYPE_ADV:
116116
// controller adv report data
117-
tag = "ADV";
117+
tag = NULL;
118118
break;
119119
case HCI_LOG_DATA_TYPE_C2H_ACL:
120120
// controller to host hci acl data
121-
tag = "CAL";
121+
tag = "D";
122122
break;
123123
case HCI_LOG_DATA_TYPE_SELF_DEFINE:
124124
// self-defining data
125-
tag = "ST";
125+
tag = "S";
126126
break;
127127
default:
128128
// unknown data type
129-
tag = "UK";
129+
tag = "U";
130130
break;
131131
}
132132

components/bt/host/bluedroid/api/esp_bluedroid_hci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool hci_host_check_send_available(void)
6161
void hci_host_send_packet(uint8_t *data, uint16_t len)
6262
{
6363
#if (BT_HCI_LOG_INCLUDED == TRUE)
64-
bt_hci_log_record_hci_data(data[0], data, len);
64+
bt_hci_log_record_hci_data(data[0], &data[1], len - 1);
6565
#endif
6666
#if (BT_CONTROLLER_INCLUDED == TRUE)
6767
esp_vhci_host_send_packet(data, len);

components/bt/host/bluedroid/hci/hci_hal_h4.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,26 @@ static void host_send_pkt_available_cb(void)
541541
hci_downstream_data_post(OSI_THREAD_MAX_TIMEOUT);
542542
}
543543

544+
545+
void bt_record_hci_data(uint8_t *data, uint16_t len)
546+
{
547+
#if (BT_HCI_LOG_INCLUDED == TRUE)
548+
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)
549+
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
550+
|| (data[3] == HCI_BLE_ADV_DISCARD_REPORT_EVT)
551+
#endif // (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
552+
#if (BLE_50_FEATURE_SUPPORT == TRUE)
553+
|| (data[3] == HCI_BLE_EXT_ADV_REPORT_EVT) || (data[3] == HCI_BLE_PERIOD_ADV_REPORT_EVT)
554+
#endif // (BLE_50_FEATURE_SUPPORT == TRUE)
555+
)) {
556+
bt_hci_log_record_hci_adv(HCI_LOG_DATA_TYPE_ADV, &data[2], len - 2);
557+
} else {
558+
uint8_t data_type = ((data[0] == 2) ? HCI_LOG_DATA_TYPE_C2H_ACL : data[0]);
559+
bt_hci_log_record_hci_data(data_type, &data[1], len - 1);
560+
}
561+
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
562+
}
563+
544564
static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
545565
{
546566
//Target has packet to host, malloc new buffer for packet
@@ -552,13 +572,11 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
552572
return 0;
553573
}
554574

575+
bt_record_hci_data(data, len);
576+
555577
bool is_adv_rpt = host_recv_adv_packet(data);
556578

557579
if (!is_adv_rpt) {
558-
#if (BT_HCI_LOG_INCLUDED == TRUE)
559-
uint8_t data_type = ((data[0] == 2) ? HCI_LOG_DATA_TYPE_C2H_ACL : data[0]);
560-
bt_hci_log_record_hci_data(data_type, data, len);
561-
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
562580
pkt_size = BT_HDR_SIZE + len;
563581
pkt = (BT_HDR *) osi_calloc(pkt_size);
564582
if (!pkt) {
@@ -572,10 +590,6 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
572590
memcpy(pkt->data, data, len);
573591
fixed_queue_enqueue(hci_hal_env.rx_q, pkt, FIXED_QUEUE_MAX_TIMEOUT);
574592
} else {
575-
#if (BT_HCI_LOG_INCLUDED == TRUE)
576-
// data type is adv report
577-
bt_hci_log_record_hci_adv(HCI_LOG_DATA_TYPE_ADV, data, len);
578-
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
579593
#if !BLE_ADV_REPORT_FLOW_CONTROL
580594
// drop the packets if pkt_queue length goes beyond upper limit
581595
if (pkt_queue_length(hci_hal_env.adv_rpt_q) > HCI_HAL_BLE_ADV_RPT_QUEUE_LEN_MAX) {

components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "freertos/semphr.h"
2222
#include "esp_compiler.h"
2323
#include "soc/soc_caps.h"
24-
#include "bt_common.h"
25-
#include "hci_log/bt_hci_log.h"
2624

2725
#define NIMBLE_VHCI_TIMEOUT_MS 2000
2826
#define BLE_HCI_EVENT_HDR_LEN (2)
@@ -77,9 +75,6 @@ int ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
7775
}
7876

7977
if (xSemaphoreTake(vhci_send_sem, NIMBLE_VHCI_TIMEOUT_MS / portTICK_PERIOD_MS) == pdTRUE) {
80-
#if (BT_HCI_LOG_INCLUDED == TRUE)
81-
bt_hci_log_record_hci_data(cmd[0], cmd, len);
82-
#endif
8378
esp_vhci_host_send_packet(cmd, len);
8479
} else {
8580
rc = BLE_HS_ETIMEOUT_HCI;
@@ -117,9 +112,6 @@ int ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
117112
len += OS_MBUF_PKTLEN(om);
118113

119114
if (xSemaphoreTake(vhci_send_sem, NIMBLE_VHCI_TIMEOUT_MS / portTICK_PERIOD_MS) == pdTRUE) {
120-
#if (BT_HCI_LOG_INCLUDED == TRUE)
121-
bt_hci_log_record_hci_data(data[0], data, len);
122-
#endif
123115
esp_vhci_host_send_packet(data, len);
124116
} else {
125117
rc = BLE_HS_ETIMEOUT_HCI;
@@ -178,7 +170,6 @@ static void ble_hci_rx_acl(uint8_t *data, uint16_t len)
178170
OS_EXIT_CRITICAL(sr);
179171
}
180172

181-
182173
/*
183174
* @brief: BT controller callback function, used to notify the upper layer that
184175
* controller is ready to receive command
@@ -223,18 +214,12 @@ static int host_rcv_pkt(uint8_t *data, uint16_t len)
223214
/* Allocate LE Advertising Report Event from lo pool only */
224215
if ((data[1] == BLE_HCI_EVCODE_LE_META) &&
225216
(data[3] == BLE_HCI_LE_SUBEV_ADV_RPT || data[3] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT)) {
226-
#if (BT_HCI_LOG_INCLUDED == TRUE)
227-
bt_hci_log_record_hci_adv(HCI_LOG_DATA_TYPE_ADV, data, len);
228-
#endif
229217
evbuf = ble_transport_alloc_evt(1);
230218
/* Skip advertising report if we're out of memory */
231219
if (!evbuf) {
232220
return 0;
233221
}
234222
} else {
235-
#if (BT_HCI_LOG_INCLUDED == TRUE)
236-
bt_hci_log_record_hci_data(data[0], data, len);
237-
#endif
238223
evbuf = ble_transport_alloc_evt(0);
239224
assert(evbuf != NULL);
240225
}
@@ -245,9 +230,6 @@ static int host_rcv_pkt(uint8_t *data, uint16_t len)
245230
rc = ble_hci_trans_ll_evt_tx(evbuf);
246231
assert(rc == 0);
247232
} else if (data[0] == BLE_HCI_UART_H4_ACL) {
248-
#if (BT_HCI_LOG_INCLUDED == TRUE)
249-
bt_hci_log_record_hci_data(HCI_LOG_DATA_TYPE_C2H_ACL, data, len);
250-
#endif
251233
ble_hci_rx_acl(data + 1, len - 1);
252234
}
253235
return 0;
@@ -282,10 +264,6 @@ esp_err_t esp_nimble_hci_init(void)
282264
goto err;
283265
}
284266

285-
#if (BT_HCI_LOG_INCLUDED == TRUE)
286-
bt_hci_log_init();
287-
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
288-
289267
xSemaphoreGive(vhci_send_sem);
290268

291269
#if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK)
@@ -313,10 +291,6 @@ esp_err_t esp_nimble_hci_deinit(void)
313291

314292
ble_buf_free();
315293

316-
#if (BT_HCI_LOG_INCLUDED == TRUE)
317-
bt_hci_log_deinit();
318-
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
319-
320294
#if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK)
321295
ble_adv_list_deinit();
322296
#endif

0 commit comments

Comments
 (0)