fix(bt/nimble): split hci log in nimble

This commit is contained in:
zhiweijian 2024-07-05 19:24:53 +08:00
parent 67e446d6c2
commit 0e504dbc90
2 changed files with 27 additions and 3 deletions

View File

@ -19,6 +19,8 @@
#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)
@ -70,6 +72,13 @@ void ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
ble_hci_rx_acl_hs_arg = acl_arg;
}
void esp_vhci_host_send_packet_wrapper(uint8_t *data, uint16_t len)
{
#if (BT_HCI_LOG_INCLUDED == TRUE)
bt_hci_log_record_hci_data(data[0], &data[1], len - 1);
#endif
esp_vhci_host_send_packet(data, len);
}
int ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
{
@ -84,7 +93,7 @@ int ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
}
if (xSemaphoreTake(vhci_send_sem, NIMBLE_VHCI_TIMEOUT_MS / portTICK_PERIOD_MS) == pdTRUE) {
esp_vhci_host_send_packet(cmd, len);
esp_vhci_host_send_packet_wrapper(cmd, len);
} else {
rc = BLE_HS_ETIMEOUT_HCI;
}
@ -123,7 +132,7 @@ 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) {
esp_vhci_host_send_packet(data, len);
esp_vhci_host_send_packet_wrapper(data, len);
} else {
rc = BLE_HS_ETIMEOUT_HCI;
}
@ -329,11 +338,26 @@ static void controller_rcv_pkt_ready(void)
}
}
void bt_record_hci_data(uint8_t *data, uint16_t len)
{
#if (BT_HCI_LOG_INCLUDED == TRUE)
if ((data[0] == BLE_HCI_UART_H4_EVT) && (data[1] == BLE_HCI_EVCODE_LE_META) && ((data[3] == BLE_HCI_LE_SUBEV_ADV_RPT) || (data[3] == BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT)
|| (data[3] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT) || (data[3] == BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT))) {
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)
}
/*
* @brief: BT controller callback function, to transfer data packet to the host
*/
static int host_rcv_pkt(uint8_t *data, uint16_t len)
{
bt_record_hci_data(data, len);
if(!ble_hs_enabled_state) {
/* If host is not enabled, drop the packet */
ESP_LOGE(TAG, "Host not enabled. Dropping the packet!");

@ -1 +1 @@
Subproject commit da88221de4aac8aa9043d2c21d49a993aa8ddd20
Subproject commit 1e6768d610cb49a3c00c8be2bc83a30c3a5be685