From e8c3dde6cfec13e8a0b3f87397319eab4cb86ad5 Mon Sep 17 00:00:00 2001 From: Sharvil Nanavati Date: Fri, 15 Jan 2016 13:41:56 -0800 Subject: [PATCH] Update btsnooz log file format to log ACL and SCO headers. Change-Id: I72db1769197150f34ebba6fcb9c0e3db2404f342 --- btif/include/btif_debug_btsnoop.h | 3 ++- btif/src/btif_debug_btsnoop.c | 26 +++++++++++++++++++++++--- hci/src/btsnoop_mem.c | 13 +++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/btif/include/btif_debug_btsnoop.h b/btif/include/btif_debug_btsnoop.h index 8c8ef0fa9..e82421a40 100644 --- a/btif/include/btif_debug_btsnoop.h +++ b/btif/include/btif_debug_btsnoop.h @@ -20,7 +20,7 @@ #include -#define BTSNOOZ_CURRENT_VERSION 0x01 +#define BTSNOOZ_CURRENT_VERSION 0x02 // The preamble is stored un-encrypted as the first part // of the file. @@ -32,6 +32,7 @@ typedef struct btsnooz_preamble_t { // One header for each HCI packet typedef struct btsnooz_header_t { uint16_t length; + uint16_t packet_length; uint32_t delta_time_ms; uint8_t type; } __attribute__((__packed__)) btsnooz_header_t; diff --git a/btif/src/btif_debug_btsnoop.c b/btif/src/btif_debug_btsnoop.c index 1deda9c38..5387de9a9 100644 --- a/btif/src/btif_debug_btsnoop.c +++ b/btif/src/btif_debug_btsnoop.c @@ -45,9 +45,28 @@ static uint64_t last_timestamp_ms = 0; static void btsnoop_cb(const uint16_t type, const uint8_t *data, const size_t length) { btsnooz_header_t header; + // Only log packet content for HCI commands and events (privacy). + size_t included_length = 0; + switch (type) { + case BT_EVT_TO_LM_HCI_CMD: + included_length = length; + break; + case BT_EVT_TO_BTU_HCI_EVT: + included_length = length; + break; + case BT_EVT_TO_LM_HCI_ACL: + case BT_EVT_TO_BTU_HCI_ACL: + included_length = 4; + break; + case BT_EVT_TO_LM_HCI_SCO: + case BT_EVT_TO_BTU_HCI_SCO: + included_length = 2; + break; + } + // Make room in the ring buffer - while (ringbuffer_available(buffer) < (length + sizeof(btsnooz_header_t))) { + while (ringbuffer_available(buffer) < (included_length + sizeof(btsnooz_header_t))) { ringbuffer_pop(buffer, (uint8_t *)&header, sizeof(btsnooz_header_t)); ringbuffer_delete(buffer, header.length - 1); } @@ -57,12 +76,13 @@ static void btsnoop_cb(const uint16_t type, const uint8_t *data, const size_t le const uint64_t now = btif_debug_ts(); header.type = REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type); - header.length = length; + header.length = included_length + 1; // +1 for type byte + header.packet_length = length + 1; // +1 for type byte. header.delta_time_ms = last_timestamp_ms ? now - last_timestamp_ms : 0; last_timestamp_ms = now; ringbuffer_insert(buffer, (uint8_t *)&header, sizeof(btsnooz_header_t)); - ringbuffer_insert(buffer, data, length - 1); + ringbuffer_insert(buffer, data, included_length); } static bool btsnoop_compress(ringbuffer_t *rb_dst, ringbuffer_t *rb_src) { diff --git a/hci/src/btsnoop_mem.c b/hci/src/btsnoop_mem.c index 55efc1be2..6b5d6c518 100644 --- a/hci/src/btsnoop_mem.c +++ b/hci/src/btsnoop_mem.c @@ -40,19 +40,24 @@ void btsnoop_mem_capture(const BT_HDR *packet) { switch (type) { case BT_EVT_TO_LM_HCI_CMD: if (packet->len > 2) - length = data[2] + 4; + length = data[2] + 3; break; case BT_EVT_TO_BTU_HCI_EVT: if (packet->len > 1) - length = data[1] + 3; + length = data[1] + 2; break; - // Ignore data for privacy case BT_EVT_TO_LM_HCI_ACL: - case BT_EVT_TO_LM_HCI_SCO: case BT_EVT_TO_BTU_HCI_ACL: + if (packet->len > 3) + length = (data[2] | (data[3] << 8)) + 4; + break; + + case BT_EVT_TO_LM_HCI_SCO: case BT_EVT_TO_BTU_HCI_SCO: + if (packet->len > 2) + length = data[2] + 3; break; } -- 2.11.0