diff --git a/components/bt/common/hci_log/bt_hci_log.c b/components/bt/common/hci_log/bt_hci_log.c index 1cc95a46ce..e35bf1a7a6 100644 --- a/components/bt/common/hci_log/bt_hci_log.c +++ b/components/bt/common/hci_log/bt_hci_log.c @@ -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; } diff --git a/components/bt/host/bluedroid/api/esp_bluedroid_hci.c b/components/bt/host/bluedroid/api/esp_bluedroid_hci.c index d17ab91494..1676ae8824 100644 --- a/components/bt/host/bluedroid/api/esp_bluedroid_hci.c +++ b/components/bt/host/bluedroid/api/esp_bluedroid_hci.c @@ -61,7 +61,7 @@ bool hci_host_check_send_available(void) void hci_host_send_packet(uint8_t *data, uint16_t len) { #if (BT_HCI_LOG_INCLUDED == TRUE) - bt_hci_log_record_hci_data(data[0], data, len); + bt_hci_log_record_hci_data(data[0], &data[1], len - 1); #endif #if (BT_CONTROLLER_INCLUDED == TRUE) esp_vhci_host_send_packet(data, len); diff --git a/components/bt/host/bluedroid/hci/hci_hal_h4.c b/components/bt/host/bluedroid/hci/hci_hal_h4.c index 8f312e60a2..a2ee1d1121 100644 --- a/components/bt/host/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/host/bluedroid/hci/hci_hal_h4.c @@ -541,6 +541,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 @@ -552,13 +572,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) { @@ -572,10 +590,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) { diff --git a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c index 8dbe78c36a..605b831211 100644 --- a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c +++ b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c @@ -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 diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 4e63dba9c3..040b56ba3b 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 4e63dba9c358fe3ed8ee70446d6668921cea8f5b +Subproject commit 040b56ba3b6a9d41e630ce927e9ec58415dad4b0