diff options
Diffstat (limited to 'gd/hal/snoop_logger.h')
-rw-r--r-- | gd/hal/snoop_logger.h | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/gd/hal/snoop_logger.h b/gd/hal/snoop_logger.h index 8021c2b37..a332e3d01 100644 --- a/gd/hal/snoop_logger.h +++ b/gd/hal/snoop_logger.h @@ -21,6 +21,7 @@ #include <mutex> #include <string> +#include "common/circular_buffer.h" #include "hal/hci_hal.h" #include "module.h" @@ -31,37 +32,85 @@ class SnoopLogger : public ::bluetooth::Module { public: static const ModuleFactory Factory; - // Each transport using SnoopLogger should define its own DefaultFilepath - static const std::string DefaultFilePath; - // Set File Path before module is started to ensure all packets are written to the right file - static void SetFilePath(const std::string& filename); - // Flag to allow flush into persistent memory on every packet captured. This is enabled on host for debugging. - static const bool AlwaysFlush; + static const std::string kBtSnoopLogModeDisabled; + static const std::string kBtSnoopLogModeFiltered; + static const std::string kBtSnoopLogModeFull; - enum class PacketType { + static const std::string kBtSnoopMaxPacketsPerFileProperty; + static const std::string kIsDebuggableProperty; + static const std::string kBtSnoopLogModeProperty; + static const std::string kBtSnoopDefaultLogModeProperty; + + // Put in header for test + struct PacketHeaderType { + uint32_t length_original; + uint32_t length_captured; + uint32_t flags; + uint32_t dropped_packets; + uint64_t timestamp; + uint8_t type; + } __attribute__((__packed__)); + + // Put in header for test + struct FileHeaderType { + uint8_t identification_pattern[8]; + uint32_t version_number; + uint32_t datalink_type; + } __attribute__((__packed__)); + + // Returns the maximum number of packets per file + // Changes to this value is only effective after restarting Bluetooth + static size_t GetMaxPacketsPerFile(); + + // Get snoop logger mode based on current system setup + // Changes to this values is only effective after restarting Bluetooth + static std::string GetBtSnoopMode(); + + // Has to be defined from 1 to 4 per btsnoop format + enum PacketType { CMD = 1, ACL = 2, SCO = 3, EVT = 4, + ISO = 5, }; - enum class Direction { + enum Direction { INCOMING, OUTGOING, }; - void capture(const HciPacket& packet, Direction direction, PacketType type); + void Capture(const HciPacket& packet, Direction direction, PacketType type); protected: void ListDependencies(ModuleList* list) override; void Start() override; void Stop() override; + DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const override; + std::string ToString() const override { + return std::string("SnoopLogger"); + } + + // Visible for testing + SnoopLogger( + std::string snoop_log_path, + std::string snooz_log_path, + size_t max_packets_per_file, + const std::string& btsnoop_mode); + void CloseCurrentSnoopLogFile(); + void OpenNextSnoopLogFile(); + void DumpSnoozLogToFile(const std::vector<std::string>& data) const; private: - SnoopLogger(); - static std::string file_path; + std::string snoop_log_path_; + std::string snooz_log_path_; std::ofstream btsnoop_ostream_; - std::mutex file_mutex_; + bool is_enabled_ = false; + bool is_filtered_ = false; + size_t max_packets_per_file_; + common::CircularBuffer<std::string> btsnooz_buffer_; + size_t packet_counter_ = 0; + mutable std::recursive_mutex file_mutex_; }; } // namespace hal |