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

Commit 6f54e938 authored by Michał Narajowski's avatar Michał Narajowski
Browse files

snoop_logger: Add support for logging to a socket

- Implements writing BTSnoop logs to socket.
- A default socket is registered on start if logs are enabled.
- snoop_logger allows to register a different socket interface
  which overrides the default one.
- This patch allows to see btsnoop logs in Wireshark or btmon
  in real time.
- No need to be root or to disable selinux.
- Wireshark has built-in support for btsnoop logs in Android
  and will detect capture option on startup.
- To enable the feature you need to run: adb shell device_config
  put bluetooth INIT_gd_hal_snoop_logger_socket true
- To use it with btmon: adb forward tcp:8872 tcp:8872 && nc
  localhost 8872 | btmon -P -r /dev/stdin

Test: atest bluetooth_test_gd
Tag: #feature
Bug: 247859568
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: Ia1d3fd8698ef4d2a3bdf92d0c78d20044cfdf96e
parent 6f990cdf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ table InitFlagsData {
    gatt_robust_caching_client_is_enabled:bool (privacy:"Any");
    gatt_robust_caching_server_is_enabled:bool (privacy:"Any");
    gd_core_is_enabled:bool (privacy:"Any");
    gd_hal_snoop_logger_socket_is_enabled:bool (privacy:"Any");
    gd_l2cap_is_enabled:bool (privacy:"Any");
    gd_link_policy_is_enabled:bool (privacy:"Any");
    gd_remote_name_request_is_enabled:bool (privacy:"Any");
+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@ class InitFlags final {
    return init_flags::btm_dm_flush_discovery_queue_on_search_cancel_is_enabled();
  }

  inline static bool IsSnoopLoggerSocketEnabled() {
    return init_flags::gd_hal_snoop_logger_socket_is_enabled();
  }

  inline static int GetAdapterIndex() {
    return init_flags::get_hci_adapter();
  }
+6 −0
Original line number Diff line number Diff line
@@ -68,3 +68,9 @@ TEST(InitFlagsTest, test_debug_logging_multiple_flags) {
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
}

TEST(InitFlagsTest, test_enable_snoop_logger_socket) {
  const char* input[] = {"INIT_gd_hal_snoop_logger_socket=true", nullptr};
  InitFlags::Load(input);
  ASSERT_TRUE(InitFlags::IsSnoopLoggerSocketEnabled());
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ flatbuffers::Offset<bluetooth::common::InitFlagsData> bluetooth::dumpsys::InitFl
  builder.add_gatt_robust_caching_client_is_enabled(initFlags::gatt_robust_caching_client_is_enabled());
  builder.add_gatt_robust_caching_server_is_enabled(initFlags::gatt_robust_caching_server_is_enabled());
  builder.add_gd_core_is_enabled(initFlags::gd_core_is_enabled());
  builder.add_gd_hal_snoop_logger_socket_is_enabled(
      bluetooth::common::init_flags::gd_hal_snoop_logger_socket_is_enabled());
  builder.add_gd_l2cap_is_enabled(initFlags::gd_l2cap_is_enabled());
  builder.add_gd_link_policy_is_enabled(initFlags::gd_link_policy_is_enabled());
  builder.add_gd_remote_name_request_is_enabled(initFlags::gd_remote_name_request_is_enabled());
+5 −0
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@ filegroup {
    name: "BluetoothHalSources",
    srcs: [
        "snoop_logger.cc",
        "snoop_logger_socket.cc",
        "snoop_logger_socket_thread.cc",
        "syscall_wrapper_impl.cc",
    ],
}

@@ -18,6 +21,8 @@ filegroup {
    name: "BluetoothHalTestSources",
    srcs: [
        "snoop_logger_test.cc",
        "snoop_logger_socket_test.cc",
        "snoop_logger_socket_thread_test.cc",
    ],
}

Loading