diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index 767578a76..220759009 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -31,6 +31,10 @@ #endif #include "host/ble_hs_pvcy.h" +#include "bt_common.h" +#if (BT_HCI_LOG_INCLUDED == TRUE) +#include "hci_log/bt_hci_log.h" +#endif // (BT_HCI_LOG_INCLUDED == TRUE) #define BLE_HS_HCI_EVT_COUNT (MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT) + \ MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT)) @@ -693,6 +697,16 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg) { int rc; +#if (BT_HCI_LOG_INCLUDED == TRUE) + uint16_t len = OS_MBUF_PKTHDR(om)->omp_len + 1; + uint8_t *data = (uint8_t *)malloc(len); + assert(data != NULL); + data[0] = 0x02; + os_mbuf_copydata(om, 0, len - 1, &data[1]); + bt_hci_log_record_hci_data(HCI_LOG_DATA_TYPE_C2H_ACL, &data[1], len - 1); + free(data); +#endif // (BT_HCI_LOG_INCLUDED == TRUE) + /* If flow control is enabled, mark this packet with its corresponding * connection handle. */ @@ -719,6 +733,17 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg) int ble_hs_tx_data(struct os_mbuf *om) { +#if (BT_HCI_LOG_INCLUDED == TRUE) + uint16_t len = 0; + uint8_t data[MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE) + 1]; + data[0] = 0x02; + len++; + os_mbuf_copydata(om, 0, OS_MBUF_PKTLEN(om), &data[1]); + len += OS_MBUF_PKTLEN(om); + + bt_hci_log_record_hci_data(data[0], &data[1], len - 1); +#endif + return ble_transport_to_ll_acl(om); } diff --git a/nimble/host/src/ble_hs_hci.c b/nimble/host/src/ble_hs_hci.c index 227128f4f..b1ac4bdba 100644 --- a/nimble/host/src/ble_hs_hci.c +++ b/nimble/host/src/ble_hs_hci.c @@ -25,6 +25,10 @@ #include "ble_hs_priv.h" #include "nimble/transport.h" +#include "bt_common.h" +#if (BT_HCI_LOG_INCLUDED == TRUE) +#include "hci_log/bt_hci_log.h" +#endif // (BT_HCI_LOG_INCLUDED == TRUE) #define BLE_HCI_CMD_TIMEOUT_MS 2000 @@ -387,6 +391,24 @@ ble_hs_hci_rx_ack(uint8_t *ack_ev) ble_npl_sem_release(&ble_hs_hci_sem); } +#if (BT_HCI_LOG_INCLUDED == TRUE) +bool host_recv_adv_packet(uint8_t *data) +{ + assert(data); + if(data[0] == BLE_HCI_EVCODE_LE_META) { + if((data[2] == BLE_HCI_LE_SUBEV_ADV_RPT) || (data[2] == BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT) || + (data[2] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT) || (data[2] == BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT) +#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) + || (data[2] == BLE_HCI_LE_SUBEV_DISCARD_REPORT_EVT) +#endif + ) { + return true; + } + } + return false; +} +#endif // (BT_HCI_LOG_INCLUDED == TRUE) + int ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg) { @@ -397,6 +419,15 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg) BLE_HS_DBG_ASSERT(hci_ev != NULL); +#if (BT_HCI_LOG_INCLUDED == TRUE) + 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); + } else { + bt_hci_log_record_hci_data(0x04, &hci_ev[0], len - 1); + } +#endif // #if (BT_HCI_LOG_INCLUDED == TRUE) + switch (ev->opcode) { case BLE_HCI_EVCODE_COMMAND_COMPLETE: enqueue = (cmd_complete->opcode == BLE_HCI_OPCODE_NOP); diff --git a/nimble/host/src/ble_hs_hci_cmd.c b/nimble/host/src/ble_hs_hci_cmd.c index 45df30538..76ec034da 100644 --- a/nimble/host/src/ble_hs_hci_cmd.c +++ b/nimble/host/src/ble_hs_hci_cmd.c @@ -24,6 +24,11 @@ #include "os/os.h" #include "nimble/hci_common.h" #include "ble_hs_priv.h" +#include "bt_common.h" +#if (BT_HCI_LOG_INCLUDED == TRUE) +#include "hci_log/bt_hci_log.h" +#endif // (BT_HCI_LOG_INCLUDED == TRUE) + /* * HCI Command Header @@ -86,6 +91,16 @@ 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; +#endif + bt_hci_log_record_hci_data(0x01, data, len + BLE_HCI_CMD_HDR_LEN); +#endif + rc = ble_hs_hci_cmd_transport((void *) buf); if (rc == 0) { diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 7121ce501..76a8b8712 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -2003,6 +2003,11 @@ struct ble_hci_ev_le_subev_subrate_change { uint16_t supervision_tmo; } __attribute__((packed)); +#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) +// LE vendor hci event +#define BLE_HCI_LE_SUBEV_DISCARD_REPORT_EVT 0XF0 +#endif // (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) + /* Data buffer overflow event */ #define BLE_HCI_EVENT_ACL_BUF_OVERFLOW (0x01) diff --git a/porting/nimble/src/nimble_port.c b/porting/nimble/src/nimble_port.c index 14916f4a1..87059f23c 100644 --- a/porting/nimble/src/nimble_port.c +++ b/porting/nimble/src/nimble_port.c @@ -44,6 +44,10 @@ #if !CONFIG_BT_CONTROLLER_ENABLED #include "nimble/transport.h" #endif +#if (BT_HCI_LOG_INCLUDED == TRUE) +#include "hci_log/bt_hci_log.h" +#endif // (BT_HCI_LOG_INCLUDED == TRUE) +#include "bt_common.h" #define NIMBLE_PORT_LOG_TAG "BLE_INIT" @@ -209,6 +213,10 @@ nimble_port_init(void) return ret; } +#if (BT_HCI_LOG_INCLUDED == TRUE) + bt_hci_log_init(); +#endif // (BT_HCI_LOG_INCLUDED == TRUE) + return ESP_OK; } @@ -243,6 +251,10 @@ nimble_port_deinit(void) } #endif +#if (BT_HCI_LOG_INCLUDED == TRUE) + bt_hci_log_deinit(); +#endif // (BT_HCI_LOG_INCLUDED == TRUE) + return ESP_OK; }