From 95da64b7486afb6d847233c9ebaeb9f763f52ffc Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 25 May 2018 10:48:43 +0200 Subject: [PATCH] debug: Add missing debug logs for LE Meta Events This adds debug logs for LE Meta Events. Those are not too heavy to limit the console output. --- nimble/host/src/ble_hs_dbg.c | 182 +++++++++++++++++++++++++++++ nimble/include/nimble/hci_common.h | 83 +++++++++++++ 2 files changed, 265 insertions(+) diff --git a/nimble/host/src/ble_hs_dbg.c b/nimble/host/src/ble_hs_dbg.c index a71d8bdde..a03bfe88a 100644 --- a/nimble/host/src/ble_hs_dbg.c +++ b/nimble/host/src/ble_hs_dbg.c @@ -149,6 +149,188 @@ ble_hs_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata) get_le16(evdata + 1), evdata[3], evdata[4]); break; + case BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT: + { + struct hci_le_subev_direct_adv_rpt *data = (void *) evdata; + struct hci_le_subev_direct_adv_rpt_param *params = data->params; + + if (len < sizeof(*data) || + len < sizeof(*data) + data->num_reports * sizeof(*params)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Directed Advertising Report " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Directed Advertising Report len=%u " + "num=0x%02x ", len, data->num_reports); + + for (i = 0; i < data->num_reports; i++) { + BLE_HS_LOG(DEBUG, "[%d]={evttype=0x%02x}\n", i, params->evt_type); + params += 1; + } + break; + } + + case BLE_HCI_LE_SUBEV_RD_LOC_P256_PUBKEY: + { + struct hci_le_subev_rd_loc_p256_pubkey *data = (void *) evdata; + + if (len != sizeof(*data)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Read Local P-256 Public Key " + "Complete Event len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Read Local P-256 Public Key Complete " + "len=%u status=0x%02x", len, data->status); + break; + } + + case BLE_HCI_LE_SUBEV_GEN_DHKEY_COMPLETE: + { + struct hci_le_subev_gen_dhkey_complete *data = (void *) evdata; + + if (len != sizeof(*data)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Generate DHKey Complete " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Generate DHKey Complete Event len=%u " + "status=0x%02x", len, data->status); + break; + } + +#if MYNEWT_VAL(BLE_EXT_ADV) + case BLE_HCI_LE_SUBEV_EXT_ADV_RPT: + { + struct hci_le_subev_ext_adv_rpt *data = (void *) evdata; + struct hci_ext_adv_report_param *params; + + if (len < sizeof(*data) + sizeof(*params)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Extended Advertising Report " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Extended Advertising Report len=%u num=0x%02x ", + len, data->num_reports); + + for (i = 0, dptr = &evdata[1]; i < data->num_reports; i++) { + params = (void *) dptr; + BLE_HS_LOG(DEBUG, "[%d]={evttype=0x%04x advlen=%u}\n", + i, le16toh(params->evt_type), params->adv_data_len); + dptr += sizeof(*params) + params->adv_data_len; + } + break; + } + + case BLE_HCI_LE_SUBEV_PER_ADV_SYNC_ESTAB: + { + struct hci_le_subev_per_adv_sync_estab *data = (void *) evdata; + + if (len != sizeof(*data)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Periodic Advertising Sync " + "Established len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Periodic Advertising Sync Established " + "len=%u status=0x%02x handle=0x%04x", len, data->status, + le16toh(data->sync_handle)); + break; + } + + case BLE_HCI_LE_SUBEV_PER_ADV_RPT: + { + struct hci_le_subev_per_adv_rpt *data = (void *) evdata; + + if (len < sizeof(*data) || len != sizeof(*data) + data->data_length) { + BLE_HS_LOG(DEBUG, "Corrupted LE Periodic Advertising Report " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Periodic Advertising Report " + "len=%u handle=0x%04x data_status=0x%02x data_len=0x%02x", + len, le16toh(data->sync_handle), data->data_status, + data->data_length); + break; + } + + case BLE_HCI_LE_SUBEV_PER_ADV_SYNC_LOST: + { + struct hci_le_subev_per_adv_sync_lost *data = (void *) evdata; + + if (len != sizeof(*data)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Periodic Advertising Sync Lost " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Periodic Advertising Sync Lost " + "len=%u handle=0x%04x", len, le16toh(data->sync_handle)); + break; + } + + case BLE_HCI_LE_SUBEV_SCAN_TIMEOUT: + if (len) { + BLE_HS_LOG(DEBUG, "Corrupted LE Scan Timeout len=%u", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Scan Timeout Event len=%u", len); + break; + + case BLE_HCI_LE_SUBEV_ADV_SET_TERMINATED: + { + struct hci_le_subev_adv_set_terminated *data = (void *) evdata; + + if (len != sizeof(*data)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Advertising Set Terminated " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Advertising Set Terminated len=%u " + "status=0x%02x adv_handle=0x%02x conn_handle=0x%04x " + "num_compl_ext_adv_ev=0x%02x", len, data->adv_handle, + le16toh(data->conn_handle), data->num_compl_ext_adv_ev); + break; + } + + case BLE_HCI_LE_SUBEV_SCAN_REQ_RCVD: + { + struct hci_le_subev_scan_req_rcvd *data = (void *) evdata; + + if (len != sizeof(*data)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Scan Request Received " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Scan Request Received len=%u " + "adv_handle=0x%02x", len, data->adv_handle); + break; + } +#endif /* MYNEWT_VAL(BLE_EXT_ADV) */ + + case BLE_HCI_LE_SUBEV_CHAN_SEL_ALG: + { + struct hci_le_subev_chan_sel_alg *data = (void *) evdata; + + if (len != sizeof(*data)) { + BLE_HS_LOG(DEBUG, "Corrupted LE Channel Selection Algorithm " + "len=%u\n", len); + break; + } + + BLE_HS_LOG(DEBUG, "LE Channel Selection Algorithm len=%u " + "conn_handle=0x%04x chan_sel_alg=0x%02x", len, + le16toh(data->conn_handle), data->chan_sel_alg); + break; + } + default: BLE_HS_LOG(DEBUG, "LE Meta SubEvent op=0x%02x\n", subev); break; diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 6f7722224..d7be6889a 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -879,6 +879,33 @@ struct hci_create_conn uint16_t max_ce_len; }; +/* LE Read Local P-256 Public Key Complete Event */ +struct hci_le_subev_rd_loc_p256_pubkey { + uint8_t status; + uint8_t pubkey[64]; +} __attribute__((packed)); + +/* LE Generate DHKey Complete Event */ +struct hci_le_subev_gen_dhkey_complete { + uint8_t status; + uint8_t dhkey[32]; +} __attribute__((packed)); + +/* LE Directed Advertising Report Event */ +struct hci_le_subev_direct_adv_rpt_param { + uint8_t evt_type; + uint8_t addr_type; + uint8_t addr[6]; + uint8_t dir_addr_type; + uint8_t dir_addr[6]; + int8_t rssi; +} __attribute__((packed)); + +struct hci_le_subev_direct_adv_rpt { + uint8_t num_reports; + struct hci_le_subev_direct_adv_rpt_param params[0]; +} __attribute__((packed)); + #if MYNEWT_VAL(BLE_EXT_ADV) /* LE create connection command (ocf=0x0043). */ struct hci_ext_conn_params @@ -952,8 +979,64 @@ struct hci_ext_adv_params uint8_t sid; uint8_t scan_req_notif; }; + +/* LE Extended Advertising Report Event */ +struct hci_le_subev_ext_adv_rpt { + uint8_t num_reports; + struct hci_ext_adv_report_param params[0]; +} __attribute__((packed)); + +/* LE Periodic Advertising Sync Established Event */ +struct hci_le_subev_per_adv_sync_estab { + uint8_t status; + uint16_t sync_handle; + uint8_t sid; + uint8_t adv_addr_type; + uint8_t adv_addr[6]; + uint8_t adv_phy; + uint16_t per_adv_ival; + uint8_t adv_clk_accuracy; +} __attribute__((packed)); + +/* LE Periodic Advertising Report Event */ +struct hci_le_subev_per_adv_rpt { + uint16_t sync_handle; + uint8_t tx_power; + int8_t rssi; + uint8_t _unused; + uint8_t data_status; + uint8_t data_length; + uint8_t data[0]; +} __attribute__((packed)); + +/* LE Periodic Advertising Sync Lost Event */ +struct hci_le_subev_per_adv_sync_lost { + uint16_t sync_handle; +} __attribute__((packed)); + +/* LE Advertising Set Terminated Event */ +struct hci_le_subev_adv_set_terminated { + uint8_t status; + uint8_t adv_handle; + uint16_t conn_handle; + uint8_t num_compl_ext_adv_ev; +} __attribute__((packed)); + +/* LE Scan Request Received Event */ +struct hci_le_subev_scan_req_rcvd { + uint8_t adv_handle; + uint8_t scan_addr_type; + uint8_t scan_addr[6]; +} __attribute__((packed)); + #endif +/* LE Channel Selection Algorithm Event */ +struct hci_le_subev_chan_sel_alg { + uint16_t conn_handle; + uint8_t chan_sel_alg; +} __attribute__((packed)); + /* LE connection update command (ocf=0x0013). */ struct hci_conn_update {