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

Commit 0f5c8888 authored by David Duarte's avatar David Duarte Committed by Gerrit Code Review
Browse files

Merge changes Ia516a414,I8b2a7f18

* changes:
  RootCanal: Decouple TestModel from {LinkLayer,Hci}SocketDevice
  RootCanal: Fix device registration
parents d2ef8d7c 5b236200
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@

#include "hci_internals.h"
#include "log/log.h"
#include "model/devices/hci_socket_device.h"
#include "model/devices/link_layer_socket_device.h"

namespace android {
namespace hardware {
@@ -35,6 +37,8 @@ namespace sim {
using android::hardware::hidl_vec;
using rootcanal::AsyncTaskId;
using rootcanal::DualModeController;
using rootcanal::HciSocketDevice;
using rootcanal::LinkLayerSocketDevice;
using rootcanal::TaskCallback;

namespace {
@@ -201,12 +205,14 @@ Return<void> BluetoothHci::initialize_impl(
    SetUpTestChannel();
    SetUpHciServer([this](std::shared_ptr<AsyncDataChannel> socket,
                          AsyncDataChannelServer* srv) {
      test_model_.IncomingHciConnection(socket);
      test_model_.AddHciConnection(HciSocketDevice::Create(socket, ""));
      srv->StartListening();
    });
    SetUpLinkLayerServer([this](std::shared_ptr<AsyncDataChannel> socket,
                                AsyncDataChannelServer* srv) {
      test_model_.IncomingLinkLayerConnection(socket);
      auto phy_type = Phy::Type::BR_EDR;
      test_model_.AddLinkLayerConnection(
          LinkLayerSocketDevice::Create(socket, phy_type), phy_type);
      srv->StartListening();
    });
  } else {
@@ -313,9 +319,11 @@ void BluetoothHci::SetUpLinkLayerServer(ConnectCallback connection_callback) {
  });
}

std::shared_ptr<AsyncDataChannel> BluetoothHci::ConnectToRemoteServer(
    const std::string& server, int port) {
  return connector_->ConnectToRemoteServer(server, port);
std::shared_ptr<Device> BluetoothHci::ConnectToRemoteServer(
    const std::string& server, int port, Phy::Type phy_type) {
  auto socket = connector_->ConnectToRemoteServer(server, port);
  if (!socket->Connected()) return nullptr;
  return LinkLayerSocketDevice::Create(socket, phy_type);
}

void BluetoothHci::SetUpTestChannel() {
+7 −4
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ using android::net::AsyncDataChannelConnector;
using android::net::AsyncDataChannelServer;
using android::net::ConnectCallback;

using rootcanal::Device;
using rootcanal::Phy;

class BluetoothHci : public IBluetoothHci {
 public:
  BluetoothHci();
@@ -89,8 +92,8 @@ class BluetoothHci : public IBluetoothHci {
  void SetUpTestChannel();
  void SetUpHciServer(ConnectCallback on_connect);
  void SetUpLinkLayerServer(ConnectCallback on_connect);
  std::shared_ptr<AsyncDataChannel> ConnectToRemoteServer(
      const std::string& server, int port);
  std::shared_ptr<Device> ConnectToRemoteServer(const std::string& server,
                                                int port, Phy::Type phy_type);

  std::shared_ptr<rootcanal::DualModeController> controller_;

@@ -121,8 +124,8 @@ class BluetoothHci : public IBluetoothHci {
        async_manager_.CancelAsyncTask(task);
      },

      [this](const std::string& server, int port) {
        return ConnectToRemoteServer(server, port);
      [this](const std::string& server, int port, Phy::Type phy_type) {
        return ConnectToRemoteServer(server, port, phy_type);
      }};
  rootcanal::TestCommandHandler test_channel_{test_model_};
};
+52 −50
Original line number Diff line number Diff line
@@ -12,13 +12,61 @@ package {
    ],
}

cc_library_static {
    name: "libbt-rootcanal",
cc_defaults {
    name: "rootcanal_defaults",
    defaults: [
        "gd_defaults",
        "gd_clang_tidy",
        "gd_clang_tidy_ignore_android",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-fvisibility=hidden",
    ],
    local_include_dirs: [
        "include",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
    ],
    generated_headers: [
        "RootCanalGeneratedPackets_h",
        "BluetoothGeneratedPackets_h",
        "libbt_init_flags_bridge_header",
    ],
}

// Compile devices and device boutique into a single object to force the linker
// to pick all the symbols for static registration to work
cc_object {
    name: "libbt-rootcanal-devices",
    defaults: ["rootcanal_defaults"],
    host_supported: true,
    proprietary: true,
    cflags: ["-fPIC"],
    srcs: [
        "model/devices/beacon.cc",
        "model/devices/beacon_swarm.cc",
        "model/devices/broken_adv.cc",
        "model/devices/car_kit.cc",
        "model/devices/classic.cc",
        "model/devices/keyboard.cc",
        "model/devices/loopback.cc",
        "model/devices/scripted_beacon.cc",
        "model/devices/sniffer.cc",
        "model/setup/device_boutique.cc",
    ],
    static_libs: [
        "libscriptedbeaconpayload-protos-lite",
    ]
}

cc_library_static {
    name: "libbt-rootcanal",
    defaults: ["rootcanal_defaults"],
    host_supported: true,
    proprietary: true,
    srcs: [
@@ -30,11 +78,6 @@ cc_library_static {
        "model/controller/link_layer_controller.cc",
        "model/controller/sco_connection.cc",
        "model/controller/security_manager.cc",
        "model/devices/beacon.cc",
        "model/devices/beacon_swarm.cc",
        "model/devices/broken_adv.cc",
        "model/devices/car_kit.cc",
        "model/devices/classic.cc",
        "model/devices/device.cc",
        "model/devices/device_properties.cc",
        "model/devices/h4_data_channel_packetizer.cc",
@@ -42,14 +85,9 @@ cc_library_static {
        "model/devices/h4_parser.cc",
        "model/devices/hci_protocol.cc",
        "model/devices/hci_socket_device.cc",
        "model/devices/keyboard.cc",
        "model/devices/link_layer_socket_device.cc",
        "model/devices/loopback.cc",
        "model/devices/remote_loopback_device.cc",
        "model/devices/scripted_beacon.cc",
        "model/devices/sniffer.cc",
        "model/setup/async_manager.cc",
        "model/setup/device_boutique.cc",
        "model/setup/phy_layer_factory.cc",
        "model/setup/test_channel_transport.cc",
        "model/setup/test_command_handler.cc",
@@ -60,35 +98,17 @@ cc_library_static {
        ":BluetoothPacketSources",
        ":BluetoothHciClassSources",
        ":BluetoothCryptoToolboxSources",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-fvisibility=hidden",
    ],
    local_include_dirs: [
        "include",
        ":libbt-rootcanal-devices",
    ],
    export_include_dirs: [
        "include",
        ".",
    ],
    generated_headers: [
        "RootCanalGeneratedPackets_h",
        "BluetoothGeneratedPackets_h",
        "libbt_init_flags_bridge_header",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
    ],
    shared_libs: [
        "liblog",
    ],
    static_libs: [
        "libjsoncpp",
        "libscriptedbeaconpayload-protos-lite",
    ],
}

@@ -149,9 +169,7 @@ cc_test_host {
// Linux RootCanal Executable
cc_binary_host {
    name: "root-canal",
    defaults: [
        "gd_clang_tidy",
    ],
    defaults: ["rootcanal_defaults"],
    srcs: [
        "desktop/root_canal_main.cc",
        "desktop/test_environment.cc",
@@ -159,17 +177,6 @@ cc_binary_host {
    header_libs: [
        "libbluetooth_headers",
    ],
    local_include_dirs: [
        "include",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
    ],
    generated_headers: [
        "RootCanalGeneratedPackets_h",
        "BluetoothGeneratedPackets_h",
    ],
    shared_libs: [
        "liblog",
        "libbacktrace",
@@ -182,11 +189,6 @@ cc_binary_host {
        "breakpad_client",
        "libgflags",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
    ],
    sanitize: {
        address: true,
        all_undefined: true,
+20 −8
Original line number Diff line number Diff line
@@ -20,7 +20,10 @@
#include <utility>      // for move
#include <vector>       // for vector

#include "model/devices/hci_socket_device.h"         // for HciSocketDevice
#include "model/devices/link_layer_socket_device.h"  // for LinkLayerSocketDevice
#include "net/async_data_channel.h"                  // for AsyncDataChannel
#include "net/async_data_channel_connector.h"  // for AsyncDataChannelConnector
#include "os/log.h"  // for LOG_INFO, LOG_ERROR, LOG_WARN

namespace android {
@@ -28,6 +31,8 @@ namespace bluetooth {
namespace root_canal {

using rootcanal::AsyncTaskId;
using rootcanal::HciSocketDevice;
using rootcanal::LinkLayerSocketDevice;
using rootcanal::TaskCallback;

void TestEnvironment::initialize(std::promise<void> barrier) {
@@ -52,7 +57,8 @@ void TestEnvironment::initialize(std::promise<void> barrier) {
  SetUpTestChannel();
  SetUpHciServer([this](std::shared_ptr<AsyncDataChannel> socket,
                        AsyncDataChannelServer* srv) {
    test_model_.IncomingHciConnection(socket, controller_properties_file_);
    test_model_.AddHciConnection(
        HciSocketDevice::Create(socket, controller_properties_file_));
    srv->StartListening();
  });
  SetUpLinkLayerServer();
@@ -81,7 +87,9 @@ void TestEnvironment::SetUpLinkBleLayerServer() {
  remote_link_layer_transport_.SetUp(
      link_ble_socket_server_, [this](std::shared_ptr<AsyncDataChannel> socket,
                                      AsyncDataChannelServer* srv) {
        test_model_.IncomingLinkBleLayerConnection(socket);
        auto phy_type = Phy::Type::LOW_ENERGY;
        test_model_.AddLinkLayerConnection(
            LinkLayerSocketDevice::Create(socket, phy_type), phy_type);
        srv->StartListening();
      });

@@ -94,7 +102,9 @@ void TestEnvironment::SetUpLinkLayerServer() {
  remote_link_layer_transport_.SetUp(
      link_socket_server_, [this](std::shared_ptr<AsyncDataChannel> socket,
                                  AsyncDataChannelServer* srv) {
        test_model_.IncomingLinkLayerConnection(socket);
        auto phy_type = Phy::Type::BR_EDR;
        test_model_.AddLinkLayerConnection(
            LinkLayerSocketDevice::Create(socket, phy_type), phy_type);
        srv->StartListening();
      });

@@ -103,9 +113,11 @@ void TestEnvironment::SetUpLinkLayerServer() {
  });
}

std::shared_ptr<AsyncDataChannel> TestEnvironment::ConnectToRemoteServer(
    const std::string& server, int port) {
  return connector_->ConnectToRemoteServer(server, port);
std::shared_ptr<Device> TestEnvironment::ConnectToRemoteServer(
    const std::string& server, int port, Phy::Type phy_type) {
  auto socket = connector_->ConnectToRemoteServer(server, port);
  if (!socket->Connected()) return nullptr;
  return LinkLayerSocketDevice::Create(socket, phy_type);
}

void TestEnvironment::SetUpTestChannel() {
+8 −5
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ using android::net::AsyncDataChannelConnector;
using android::net::AsyncDataChannelServer;
using android::net::ConnectCallback;

using rootcanal::Device;
using rootcanal::Phy;

class TestEnvironment {
 public:
  TestEnvironment(std::shared_ptr<AsyncDataChannelServer> test_port,
@@ -82,8 +85,8 @@ class TestEnvironment {
  void SetUpHciServer(ConnectCallback on_connect);
  void SetUpLinkLayerServer();
  void SetUpLinkBleLayerServer();
  std::shared_ptr<AsyncDataChannel> ConnectToRemoteServer(
      const std::string& server, int port);
  std::shared_ptr<Device> ConnectToRemoteServer(const std::string& server,
                                                int port, Phy::Type phy_type);

  std::shared_ptr<rootcanal::DualModeController> controller_;

@@ -114,8 +117,8 @@ class TestEnvironment {
        async_manager_.CancelAsyncTask(task);
      },

      [this](const std::string& server, int port) {
        return ConnectToRemoteServer(server, port);
      [this](const std::string& server, int port, Phy::Type phy_type) {
        return ConnectToRemoteServer(server, port, phy_type);
      }};

  rootcanal::TestCommandHandler test_channel_{test_model_};
Loading