Loading system/gd/hal/BUILD.gn +4 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,10 @@ source_set("BluetoothHalSources") { ] configs += [ "//bt/system/gd:gd_defaults" ] deps = [ "//bt/system/gd:gd_default_deps" ] deps = [ "//bt/flags:bluetooth_flags_c_lib", "//bt/system/gd:gd_default_deps" ] } source_set("BluetoothHalSources_hci_host") { Loading system/gd/hal/snoop_logger.cc +64 −0 Original line number Diff line number Diff line Loading @@ -14,10 +14,16 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_APP #include "hal/snoop_logger.h" #include <arpa/inet.h> #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #ifdef __ANDROID__ #include <cutils/trace.h> #endif // __ANDROID__ #include <sys/stat.h> #include <algorithm> Loading @@ -28,6 +34,7 @@ #include "common/circular_buffer.h" #include "common/strings.h" #include "hal/snoop_logger_common.h" #include "hci/hci_packets.h" #include "module_dumper_flatbuffer.h" #include "os/files.h" #include "os/parameter_provider.h" Loading Loading @@ -1123,6 +1130,13 @@ void SnoopLogger::Capture(const HciPacket& immutable_packet, Direction direction HciPacket mutable_packet(immutable_packet); HciPacket& packet = mutable_packet; ////////////////////////////////////////////////////////////////////////// #ifdef __ANDROID__ if (com::android::bluetooth::flags::snoop_logger_tracing()) { LogTracePoint(packet, direction, type); } #endif // __ANDROID__ uint64_t timestamp_us = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::system_clock::now().time_since_epoch()) .count(); Loading Loading @@ -1401,5 +1415,55 @@ const ModuleFactory SnoopLogger::Factory = ModuleFactory([]() { IsBtSnoopLogPersisted()); }); #ifdef __ANDROID__ void SnoopLogger::LogTracePoint(const HciPacket& packet, Direction direction, PacketType type) { switch (type) { case PacketType::EVT: { uint8_t evt_code = packet[0]; if (evt_code == static_cast<uint8_t>(hci::EventCode::LE_META_EVENT) || evt_code == static_cast<uint8_t>(hci::EventCode::VENDOR_SPECIFIC)) { uint8_t subevt_code = packet[2]; std::string message = fmt::format("BTSL:{}/{}/{}/{:02x}/{:02x}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), evt_code, subevt_code); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } else { std::string message = fmt::format("BTSL:{}/{}/{}/{:02x}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), evt_code); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } } break; case PacketType::CMD: { uint16_t op_code = packet[0] | (packet[1] << 8); std::string message = fmt::format("BTSL:{}/{}/{}/{:04x}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), op_code); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } break; case PacketType::ACL: { uint16_t handle = (packet[0] | (packet[1] << 8)) & 0x0fff; uint8_t pb_flag = (packet[1] & 0x30) >> 4; std::string message = fmt::format("BTSL:{}/{}/{}/{:03x}/{}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), handle, pb_flag); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } break; case PacketType::ISO: case PacketType::SCO: { std::string message = fmt::format("BTSL:{}/{}/{}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size()); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } break; } } #endif // __ANDROID__ } // namespace hal } // namespace bluetooth system/gd/hal/snoop_logger.h +4 −0 Original line number Diff line number Diff line Loading @@ -319,6 +319,10 @@ protected: std::unique_ptr<SnoopLoggerSocketThread> snoop_logger_socket_thread_; #ifdef __ANDROID__ void LogTracePoint(const HciPacket& packet, Direction direction, PacketType type); #endif // __ANDROID__ private: static std::string btsnoop_mode_; std::string snoop_log_path_; Loading system/stack/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -1741,6 +1741,7 @@ cc_test { shared_libs: [ "libaconfig_storage_read_api_cc", "libcrypto", "libcutils", "server_configurable_flags", ], sanitize: { Loading Loading @@ -2313,6 +2314,7 @@ cc_test { shared_libs: [ "libaconfig_storage_read_api_cc", "libcrypto", "libcutils", "server_configurable_flags", ], sanitize: { Loading Loading
system/gd/hal/BUILD.gn +4 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,10 @@ source_set("BluetoothHalSources") { ] configs += [ "//bt/system/gd:gd_defaults" ] deps = [ "//bt/system/gd:gd_default_deps" ] deps = [ "//bt/flags:bluetooth_flags_c_lib", "//bt/system/gd:gd_default_deps" ] } source_set("BluetoothHalSources_hci_host") { Loading
system/gd/hal/snoop_logger.cc +64 −0 Original line number Diff line number Diff line Loading @@ -14,10 +14,16 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_APP #include "hal/snoop_logger.h" #include <arpa/inet.h> #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #ifdef __ANDROID__ #include <cutils/trace.h> #endif // __ANDROID__ #include <sys/stat.h> #include <algorithm> Loading @@ -28,6 +34,7 @@ #include "common/circular_buffer.h" #include "common/strings.h" #include "hal/snoop_logger_common.h" #include "hci/hci_packets.h" #include "module_dumper_flatbuffer.h" #include "os/files.h" #include "os/parameter_provider.h" Loading Loading @@ -1123,6 +1130,13 @@ void SnoopLogger::Capture(const HciPacket& immutable_packet, Direction direction HciPacket mutable_packet(immutable_packet); HciPacket& packet = mutable_packet; ////////////////////////////////////////////////////////////////////////// #ifdef __ANDROID__ if (com::android::bluetooth::flags::snoop_logger_tracing()) { LogTracePoint(packet, direction, type); } #endif // __ANDROID__ uint64_t timestamp_us = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::system_clock::now().time_since_epoch()) .count(); Loading Loading @@ -1401,5 +1415,55 @@ const ModuleFactory SnoopLogger::Factory = ModuleFactory([]() { IsBtSnoopLogPersisted()); }); #ifdef __ANDROID__ void SnoopLogger::LogTracePoint(const HciPacket& packet, Direction direction, PacketType type) { switch (type) { case PacketType::EVT: { uint8_t evt_code = packet[0]; if (evt_code == static_cast<uint8_t>(hci::EventCode::LE_META_EVENT) || evt_code == static_cast<uint8_t>(hci::EventCode::VENDOR_SPECIFIC)) { uint8_t subevt_code = packet[2]; std::string message = fmt::format("BTSL:{}/{}/{}/{:02x}/{:02x}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), evt_code, subevt_code); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } else { std::string message = fmt::format("BTSL:{}/{}/{}/{:02x}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), evt_code); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } } break; case PacketType::CMD: { uint16_t op_code = packet[0] | (packet[1] << 8); std::string message = fmt::format("BTSL:{}/{}/{}/{:04x}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), op_code); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } break; case PacketType::ACL: { uint16_t handle = (packet[0] | (packet[1] << 8)) & 0x0fff; uint8_t pb_flag = (packet[1] & 0x30) >> 4; std::string message = fmt::format("BTSL:{}/{}/{}/{:03x}/{}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size(), handle, pb_flag); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } break; case PacketType::ISO: case PacketType::SCO: { std::string message = fmt::format("BTSL:{}/{}/{}", static_cast<uint8_t>(type), static_cast<uint8_t>(direction), packet.size()); ATRACE_INSTANT_FOR_TRACK(LOG_TAG, message.c_str()); } break; } } #endif // __ANDROID__ } // namespace hal } // namespace bluetooth
system/gd/hal/snoop_logger.h +4 −0 Original line number Diff line number Diff line Loading @@ -319,6 +319,10 @@ protected: std::unique_ptr<SnoopLoggerSocketThread> snoop_logger_socket_thread_; #ifdef __ANDROID__ void LogTracePoint(const HciPacket& packet, Direction direction, PacketType type); #endif // __ANDROID__ private: static std::string btsnoop_mode_; std::string snoop_log_path_; Loading
system/stack/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -1741,6 +1741,7 @@ cc_test { shared_libs: [ "libaconfig_storage_read_api_cc", "libcrypto", "libcutils", "server_configurable_flags", ], sanitize: { Loading Loading @@ -2313,6 +2314,7 @@ cc_test { shared_libs: [ "libaconfig_storage_read_api_cc", "libcrypto", "libcutils", "server_configurable_flags", ], sanitize: { Loading