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

Commit 93526827 authored by More Kuo's avatar More Kuo Committed by Chris Manton
Browse files

Enable Qualcomm 3804 log in snoop log with base 64 format

Bug: 203015591
Tag: #feature
Test: manually checked content of partial btsnoop log
Change-Id: I8e0e85b1493332405147f572cceaa24c56771a3d
parent 773ebd5d
Loading
Loading
Loading
Loading
+19 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include <zlib.h>
#include <zlib.h>


#include "internal_include/bt_target.h"
#include "internal_include/bt_target.h"
#include "osi/include/properties.h"
#include "osi/include/ringbuffer.h"
#include "osi/include/ringbuffer.h"


#define REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type) ((type) >> 8)
#define REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type) ((type) >> 8)
@@ -35,6 +36,7 @@ static const size_t BTSNOOP_MEM_BUFFER_SIZE = (256 * 1024);
static std::mutex buffer_mutex;
static std::mutex buffer_mutex;
static ringbuffer_t* buffer = NULL;
static ringbuffer_t* buffer = NULL;
static uint64_t last_timestamp_ms = 0;
static uint64_t last_timestamp_ms = 0;
static bool qualcomm_debug_log_enable = false;


static size_t btsnoop_calculate_packet_length(uint16_t type,
static size_t btsnoop_calculate_packet_length(uint16_t type,
                                              const uint8_t* data,
                                              const uint8_t* data,
@@ -77,6 +79,9 @@ static size_t btsnoop_calculate_packet_length(uint16_t type,
  static const size_t L2CAP_CID_OFFSET = (HCI_ACL_HEADER_SIZE + 2);
  static const size_t L2CAP_CID_OFFSET = (HCI_ACL_HEADER_SIZE + 2);
  static const uint16_t L2CAP_SIGNALING_CID = 0x0001;
  static const uint16_t L2CAP_SIGNALING_CID = 0x0001;


  static const size_t HCI_ACL_HANDLE_OFFSET = 0;
  static const uint16_t QUALCOMM_DEBUG_LOG_HANDLE = 0xedc;

  // Maximum amount of ACL data to log.
  // Maximum amount of ACL data to log.
  // Enough for an RFCOMM frame up to the frame check;
  // Enough for an RFCOMM frame up to the frame check;
  // not enough for a HID report or audio data.
  // not enough for a HID report or audio data.
@@ -98,11 +103,19 @@ static size_t btsnoop_calculate_packet_length(uint16_t type,
      if (length > len_hci_acl) {
      if (length > len_hci_acl) {
        uint16_t l2cap_cid =
        uint16_t l2cap_cid =
            data[L2CAP_CID_OFFSET] | (data[L2CAP_CID_OFFSET + 1] << 8);
            data[L2CAP_CID_OFFSET] | (data[L2CAP_CID_OFFSET + 1] << 8);
        uint16_t hci_acl_packet_handle = data[HCI_ACL_HANDLE_OFFSET] |
                                         (data[HCI_ACL_HANDLE_OFFSET + 1] << 8);
        hci_acl_packet_handle &= 0x0FFF;

        if (l2cap_cid == L2CAP_SIGNALING_CID) {
        if (l2cap_cid == L2CAP_SIGNALING_CID) {
          // For the signaling CID, take the full packet.
          // For the signaling CID, take the full packet.
          // That way, the PSM setup is captured, allowing decoding of PSMs down
          // That way, the PSM setup is captured, allowing decoding of PSMs down
          // the road.
          // the road.
          return length;
          return length;
        } else if (qualcomm_debug_log_enable &&
                   hci_acl_packet_handle == QUALCOMM_DEBUG_LOG_HANDLE) {
          // For the enhanced controller debug log, take the full packet.
          return length;
        } else {
        } else {
          // Otherwise, return as much as we reasonably can
          // Otherwise, return as much as we reasonably can
          len_hci_acl = MAX_HCI_ACL_LEN;
          len_hci_acl = MAX_HCI_ACL_LEN;
@@ -128,6 +141,12 @@ static size_t btsnoop_calculate_packet_length(uint16_t type,
void btif_debug_btsnoop_init(void) {
void btif_debug_btsnoop_init(void) {
  if (buffer == NULL) buffer = ringbuffer_init(BTSNOOP_MEM_BUFFER_SIZE);
  if (buffer == NULL) buffer = ringbuffer_init(BTSNOOP_MEM_BUFFER_SIZE);
  btsnoop_mem_set_callback(btsnoop_cb);
  btsnoop_mem_set_callback(btsnoop_cb);

  char value[PROPERTY_VALUE_MAX] = {0};
  int ret = osi_property_get("ro.soc.manufacturer", value, "");
  if (ret > 0 && strncmp(value, "Qualcomm", ret) == 0) {
    qualcomm_debug_log_enable = true;
  }
}
}


#ifndef OS_ANDROID
#ifndef OS_ANDROID