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

Commit 867889cb authored by Animesh Fatehpuria's avatar Animesh Fatehpuria Committed by Soma Jagannathan
Browse files

Fix BT Snoop log size issue

Added support for a new "truncated" mode that truncates ACL packet data
to at most 100 bytes. This is useful for devices with smaller memory.

Bug: 263323082
Bug: 189496862
Tag: #refactor
Test: Manual
Add merged-in as there is a new feature for U+ that cannot be backported
to tm-*. But we do not want this change to conflict with it
Merged-In: I4b7bb84ec2f14aff60388b10eae24d8896f61f5b
Change-Id: Ia71726d145a22b23152e03d53a9c4e1fb51cbc38
(cherry picked from commit 404a81c1a01a9fb02507d4d6219ff536dfbf652e)
parent f1b2021f
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -193,6 +193,7 @@ size_t get_btsnooz_packet_length_to_write(
}  // namespace

const std::string SnoopLogger::kBtSnoopLogModeDisabled = "disabled";
const std::string SnoopLogger::kBtSnoopLogModeTruncated = "truncated";
const std::string SnoopLogger::kBtSnoopLogModeFiltered = "filtered";
const std::string SnoopLogger::kBtSnoopLogModeFull = "full";
const std::string SnoopLogger::kSoCManufacturerQualcomm = "Qualcomm";
@@ -203,6 +204,10 @@ const std::string SnoopLogger::kBtSnoopLogModeProperty = "persist.bluetooth.btsn
const std::string SnoopLogger::kBtSnoopDefaultLogModeProperty = "persist.bluetooth.btsnoopdefaultmode";
const std::string SnoopLogger::kSoCManufacturerProperty = "ro.soc.manufacturer";

// The max ACL packet size (in bytes) in truncated logging mode. All information
// past this point is truncated from a packet.
static constexpr uint32_t kMaxTruncatedAclPacketSize = 100;

SnoopLogger::SnoopLogger(
    std::string snoop_log_path,
    std::string snooz_log_path,
@@ -236,6 +241,15 @@ SnoopLogger::SnoopLogger(
    delete_btsnoop_files(get_btsnoop_log_path(snoop_log_path_, true));
    // delete snooz logs
    delete_btsnoop_files(snooz_log_path_);
  } else if (btsnoop_mode == kBtSnoopLogModeTruncated) {
    LOG_INFO("Snoop Logs truncated. Limiting to %u", kMaxTruncatedAclPacketSize);
    is_enabled_ = true;
    is_truncated_ = true;
    is_filtered_ = false;
    // delete filtered logs
    delete_btsnoop_files(get_btsnoop_log_path(snoop_log_path_, true));
    // delete snooz logs
    delete_btsnoop_files(snooz_log_path_);
  } else {
    LOG_INFO("Snoop Logs disabled");
    is_enabled_ = false;
@@ -320,6 +334,9 @@ void SnoopLogger::Capture(const HciPacket& packet, Direction direction, PacketTy
                             .dropped_packets = 0,
                             .timestamp = htonll(timestamp_us + kBtSnoopEpochDelta),
                             .type = static_cast<uint8_t>(type)};
  if (is_truncated_ && type == PacketType::ACL) {
    header.length_captured = htonl(std::min(length, kMaxTruncatedAclPacketSize));
  }
  {
    std::lock_guard<std::recursive_mutex> lock(file_mutex_);
    if (!is_enabled_) {
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ class SnoopLogger : public ::bluetooth::Module {
  static const ModuleFactory Factory;

  static const std::string kBtSnoopLogModeDisabled;
  static const std::string kBtSnoopLogModeTruncated;
  static const std::string kBtSnoopLogModeFiltered;
  static const std::string kBtSnoopLogModeFull;
  static const std::string kSoCManufacturerQualcomm;
@@ -124,6 +125,7 @@ class SnoopLogger : public ::bluetooth::Module {
  std::ofstream btsnoop_ostream_;
  bool is_enabled_ = false;
  bool is_filtered_ = false;
  bool is_truncated_ = false;
  size_t max_packets_per_file_;
  common::CircularBuffer<std::string> btsnooz_buffer_;
  bool qualcomm_debug_log_enabled_ = false;