Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39053fa7 authored by Sharvil Nanavati's avatar Sharvil Nanavati
Browse files

DO NOT MERGE ANYWHERE

Update btsnooz log file format to log ACL and SCO headers.

Change-Id: I72db1769197150f34ebba6fcb9c0e3db2404f342
parent 4b2f2c11
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@

#include <stdint.h>

#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;
+24 −4
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@

// Total btsnoop memory log buffer size
#ifndef BTSNOOP_MEM_BUFFER_SIZE
static const size_t BTSNOOP_MEM_BUFFER_SIZE = (128 * 1024);
static const size_t BTSNOOP_MEM_BUFFER_SIZE = (172 * 1024);
#endif

// Block size for copying buffers (for compression/encoding etc.)
@@ -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) {
+9 −4
Original line number Diff line number Diff line
@@ -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;
  }