Skip to content

Commit 7b08388

Browse files
Add traces to HCI, BLE instance, Security DB and WSF cordio traces (#14138)
* ble HCI tracing * fix typo in SM trace * add BLE instance tracing * route wsf traces to mbed tr_debug * Update connectivity/FEATURE_BLE/source/cordio/source/BLEInstanceBaseImpl.cpp Co-authored-by: Vincent Coubard <[email protected]> * print hci on cordio side * trace controller supported features * log reset sequence * include config for printing enums * remove duplicate trace * add tracing to security db * workaround for macro error on use outside trace Co-authored-by: Vincent Coubard <[email protected]>
1 parent 5aa76e5 commit 7b08388

22 files changed

+729
-31
lines changed

connectivity/FEATURE_BLE/libraries/cordio_stack/wsf/include/wsf_trace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
#include <stdarg.h>
2828

29+
#if MBED_CONF_CORDIO_TRACE_HCI_PACKETS
30+
#include "mbed_wsf_trace.h"
31+
#endif
32+
2933
#ifdef __cplusplus
3034
extern "C" {
3135
#endif
@@ -289,6 +293,7 @@ bool_t WsfTokenService(void);
289293
/*! \brief 3 argument HCI error trace. */
290294
#define HCI_TRACE_ERR3(msg, var1, var2, var3) WSF_TRACE3("HCI", "ERR", msg, var1, var2, var3)
291295

296+
#if !MBED_CONF_CORDIO_TRACE_HCI_PACKETS
292297
/*! \brief HCI PDUMP on command. */
293298
#define HCI_PDUMP_CMD(len, pBuf)
294299
/*! \brief HCI PDUMP on event. */
@@ -301,6 +306,7 @@ bool_t WsfTokenService(void);
301306
#define HCI_PDUMP_TX_ISO(len, pBuf)
302307
/*! \brief HCI PDUMP on Received ISO message. */
303308
#define HCI_PDUMP_RX_ISO(len, pBuf)
309+
#endif // !MBED_CONF_CORDIO_TRACE_HCI_PACKETS
304310

305311
/*! \brief 0 argument DM info trace. */
306312
#define DM_TRACE_INFO0(msg) WSF_TRACE0("DM", "INFO", msg)

connectivity/FEATURE_BLE/mbed_lib.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,15 @@
108108
"value": 16,
109109
"macro_name": "BLE_GAP_HOST_PRIVACY_RESOLVED_CACHE_SIZE"
110110
},
111+
111112
"ble-passkey-display-reversed-digits-deprecation": {
112113
"help": "This option is part of the deprecation process. Set this to false to remove the deprecation notice. When set to true, the digits in the SecurityManager passkeyDiplay event are reversed. When set to false the digits are in the correct order.",
113114
"value": true,
114115
"macro_name": "BLE_PASSKEY_DISPLAY_REVERSED_DIGITS_DEPRECATION"
116+
},
117+
"trace-human-readable-enums": {
118+
"help": "More hexadecimal values in traces will be printed as human readable strings.",
119+
"value": false
115120
}
116121
},
117122
"target_overrides": {

connectivity/FEATURE_BLE/source/common/ble_trace_helpers.cpp

Lines changed: 337 additions & 0 deletions
Large diffs are not rendered by default.

connectivity/FEATURE_BLE/source/common/ble_trace_helpers.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@
2020

2121
#include "ble/SecurityManager.h"
2222
#include "mbed-trace/mbed_trace.h"
23+
#include "pal/GapTypes.h"
24+
#include "ble-host/include/dm_api.h"
2325

2426
namespace ble {
2527

28+
#if MBED_CONF_MBED_TRACE_ENABLE
29+
const char* dm_callback_event_to_string(uint8_t event);
30+
void trace_le_supported_features(uint64_t feat);
31+
const char* hci_opcode_to_string(uint16_t opcode);
32+
#endif //MBED_CONF_MBED_TRACE_ENABLE
33+
34+
template<typename T>
35+
static inline const char* tr_as_array(T item)
36+
{
37+
return (mbed_trace_array)((const uint8_t*)&item, sizeof(item));
38+
}
39+
2640
static inline constexpr const char* to_string(bool v)
2741
{
2842
if (v) {

connectivity/FEATURE_BLE/source/cordio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ target_sources(mbed-ble-cordio
2929
stack_adaptation/wsf_cs.c
3030
stack_adaptation/wsf_mbed_os_adaptation.c
3131
stack_adaptation/wsf_os.c
32+
stack_adaptation/mbed_wsf_trace.c
3233
)

connectivity/FEATURE_BLE/source/cordio/driver/CordioHCIDriver.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include "bstream.h"
2828
#include "hci_mbed_os_adaptation.h"
2929

30+
#include "mbed-trace/mbed_trace.h"
31+
#include "common/ble_trace_helpers.h"
32+
33+
#define TRACE_GROUP "BLHC"
34+
3035
#define HCI_RESET_RAND_CNT 4
3136

3237
namespace ble {
@@ -69,12 +74,14 @@ CordioHCIDriver::CordioHCIDriver(CordioHCITransportDriver& transport_driver) :
6974

7075
void CordioHCIDriver::initialize()
7176
{
77+
tr_info("CordioHCIDriver initializing");
7278
_transport_driver.initialize();
7379
do_initialize();
7480
}
7581

7682
void CordioHCIDriver::terminate()
7783
{
84+
tr_info("CordioHCIDriver terminating");
7885
do_terminate();
7986
_transport_driver.terminate();
8087
}
@@ -275,19 +282,34 @@ bool CordioHCIDriver::get_random_static_address(ble::address_t& address)
275282

276283
void CordioHCIDriver::signal_reset_sequence_done()
277284
{
285+
tr_debug("Signal cordio HCI reset sequence done");
278286
hci_mbed_os_signal_reset_sequence_done();
279287
}
280288

281289
uint16_t CordioHCIDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
282290
{
291+
#if MBED_CONF_CORDIO_TRACE_HCI_PACKETS
292+
const char *type_prefix;
293+
switch(type) {
294+
case 0x01: type_prefix = "CMD"; break;
295+
case 0x02: type_prefix = "ACL"; break;
296+
/* illegal packet */
297+
default: type_prefix = "ERR"; break;
298+
}
299+
tr_debug("HOST->LL %s %s", type_prefix, trace_array(pData, len));
300+
#endif
283301
return _transport_driver.write(type, len, pData);
284302
}
285303

286304
void CordioHCIDriver::on_host_stack_inactivity()
287305
{
288306
}
307+
289308
void CordioHCIDriver::handle_test_end(bool success, uint16_t packets)
290309
{
310+
MBED_ASSERT(_test_end_handler);
311+
tr_info("LE receiver mode ended (success: %s)", to_string(success));
312+
291313
if (_test_end_handler) {
292314
_test_end_handler(success, packets);
293315
_test_end_handler = nullptr;
@@ -299,17 +321,21 @@ ble_error_t CordioHCIDriver::rf_test_start_le_receiver_test(
299321
)
300322
{
301323
if (_test_end_handler) {
324+
tr_warning("Cannot start LE %s test mode - already started", "receiver");
302325
return BLE_ERROR_INVALID_STATE;
303326
}
304327

305328
if (!test_end_handler) {
329+
tr_warning("Cannot start LE %s test mode - invalid handler", "receiver");
306330
return BLE_ERROR_INVALID_PARAM;
307331
}
308332

309333
_test_end_handler = test_end_handler;
310334
uint8_t *buf = hciCmdAlloc(HCI_OPCODE_LE_RECEIVER_TEST, HCI_LEN_LE_RECEIVER_TEST);
311335

312336
if (buf) {
337+
tr_info("LE %s mode starter on channel %hhd", "receiver", channel);
338+
313339
uint8_t* p = buf + HCI_CMD_HDR_LEN;
314340
UINT8_TO_BSTREAM(p, channel);
315341
hciCmdSend(buf);
@@ -325,17 +351,21 @@ ble_error_t CordioHCIDriver::rf_test_start_le_transmitter_test(
325351
)
326352
{
327353
if (_test_end_handler) {
354+
tr_warning("Cannot start LE %s test mode - already started", "transmitter");
328355
return BLE_ERROR_INVALID_STATE;
329356
}
330357

331358
if (!test_end_handler) {
359+
tr_warning("Cannot start LE %s test mode - invalid handler", "transmitter");
332360
return BLE_ERROR_INVALID_PARAM;
333361
}
334362

335363
_test_end_handler = test_end_handler;
336364
uint8_t *buf = hciCmdAlloc(HCI_OPCODE_LE_TRANSMITTER_TEST, HCI_LEN_LE_TRANSMITTER_TEST);
337365

338366
if (buf) {
367+
tr_info("LE %s mode starter on channel %hhd", "transmitter", channel);
368+
339369
uint8_t* p = buf + HCI_CMD_HDR_LEN;
340370
UINT8_TO_BSTREAM(p, channel);
341371
UINT8_TO_BSTREAM(p, length);
@@ -350,14 +380,18 @@ ble_error_t CordioHCIDriver::rf_test_start_le_transmitter_test(
350380

351381
ble_error_t CordioHCIDriver::rf_test_end()
352382
{
383+
MBED_ASSERT(_test_end_handler);
384+
353385
if (!_test_end_handler) {
386+
tr_info("Cannot end LE transmitter mode test - missing handler (test never started?)");
354387
return BLE_ERROR_INVALID_STATE;
355388
}
356389

357390
uint8_t *buf = hciCmdAlloc(HCI_OPCODE_LE_TEST_END, HCI_LEN_LE_TEST_END);
358391

359392
if (buf) {
360393
hciCmdSend(buf);
394+
tr_info("LE transmitter mode ended");
361395

362396
return BLE_ERROR_NONE;
363397
}

connectivity/FEATURE_BLE/source/cordio/driver/CordioHCITransportDriver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "ble/driver/CordioHCITransportDriver.h"
2222
#include "ble/driver/CordioHCIDriver.h"
2323

24+
#include "mbed-trace/mbed_trace.h"
25+
#include "common/ble_trace_helpers.h"
26+
27+
#define TRACE_GROUP "BLHC"
28+
2429
extern "C" void hciTrSerialRxIncoming(uint8_t *pBuf, uint8_t len);
2530

2631
namespace ble {
@@ -40,6 +45,7 @@ void CordioHCITransportDriver::on_data_received(uint8_t* data, uint16_t len)
4045

4146
void CordioHCITransportDriver::set_data_received_handler(data_received_handler_t handler)
4247
{
48+
MBED_ASSERT(handler);
4349
data_received_handler = handler;
4450
}
4551

connectivity/FEATURE_BLE/source/cordio/mbed_lib.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@
8181
"help": "Check connection complete event if it needs the addresses swapped due to bug in controller",
8282
"value": null,
8383
"macro_name": "CORDIO_RPA_SWAP_WORKAROUND"
84+
},
85+
"trace-hci-packets": {
86+
"help": "If tracing is enabled at level DEBUG traces will include HCI packet traces.",
87+
"value": false
88+
},
89+
"trace-cordio-wsf-traces": {
90+
"help": "If tracing is enabled at level DEBUG traces will include WSF traces from Cordio packet traces.",
91+
"value": false,
92+
"macro_name": "WSF_TRACE_ENABLED"
8493
}
8594
},
8695
"target_overrides": {

0 commit comments

Comments
 (0)