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

Commit e74b33a3 authored by Henri Chataing's avatar Henri Chataing Committed by Automerger Merge Worker
Browse files

Merge changes from topic "rootcanal-config-by-value" am: 397eb904

parents 2cdedb2d 397eb904
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -199,7 +199,8 @@ Return<void> BluetoothHci::initialize_impl(
    SetUpHciServer([this](std::shared_ptr<AsyncDataChannel> socket,
                          AsyncDataChannelServer* srv) {
      auto transport = HciSocketTransport::Create(socket);
      test_model_.AddHciConnection(HciDevice::Create(transport, ""));
      test_model_.AddHciConnection(
          HciDevice::Create(transport, rootcanal::ControllerProperties()));
      srv->StartListening();
    });
    SetUpLinkLayerServer([this](std::shared_ptr<AsyncDataChannel> socket,
+12 −26
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ void TestEnvironment::initialize(std::promise<void> barrier) {
    if (enable_hci_sniffer_) {
      transport = HciSniffer::Create(transport);
    }
    auto device = HciDevice::Create(transport, controller_properties_file_);
    auto device = HciDevice::Create(transport, controller_properties_);
    async_manager_.ExecAsync(user_id, std::chrono::milliseconds(0), [=]() {
      test_model_.AddHciConnection(device);
    });
@@ -115,44 +115,32 @@ void TestEnvironment::close() {
}

void TestEnvironment::SetUpHciServer(ConnectCallback on_connect) {
  test_channel_.RegisterSendResponse([](const std::string& response) {
    LOG_INFO("No HCI Response channel: %s", response.c_str());
  });

  if (!remote_hci_transport_.SetUp(hci_socket_server_, on_connect)) {
    LOG_ERROR("Remote HCI channel SetUp failed.");
    return;
  }
  hci_socket_server_->SetOnConnectCallback(on_connect);
  hci_socket_server_->StartListening();
}

void TestEnvironment::SetUpLinkBleLayerServer() {
  remote_link_layer_transport_.SetUp(
      link_ble_socket_server_, [this](std::shared_ptr<AsyncDataChannel> socket,
  link_ble_socket_server_->SetOnConnectCallback(
      [this](std::shared_ptr<AsyncDataChannel> socket,
             AsyncDataChannelServer* srv) {
        auto phy_type = Phy::Type::LOW_ENERGY;
        test_model_.AddLinkLayerConnection(
            LinkLayerSocketDevice::Create(socket, phy_type), phy_type);
        srv->StartListening();
      });

  test_channel_.RegisterSendResponse([](const std::string& response) {
    LOG_INFO("No LinkLayer Response channel: %s", response.c_str());
  });
  link_ble_socket_server_->StartListening();
}

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

  test_channel_.RegisterSendResponse([](const std::string& response) {
    LOG_INFO("No LinkLayer Response channel: %s", response.c_str());
  });
  link_socket_server_->StartListening();
}

std::shared_ptr<Device> TestEnvironment::ConnectToRemoteServer(
@@ -188,9 +176,7 @@ void TestEnvironment::SetUpTestChannel() {
        });
        return false;
      });
  test_channel_.RegisterSendResponse([](const std::string& response) {
    LOG_INFO("No test channel: %s", response.c_str());
  });

  test_channel_.AddPhy({"BR_EDR"});
  test_channel_.AddPhy({"LOW_ENERGY"});
  test_channel_.SetTimerPeriod({"5"});
+5 −12
Original line number Diff line number Diff line
@@ -64,13 +64,11 @@ class TestEnvironment {
        link_socket_server_(link_server_port),
        link_ble_socket_server_(link_ble_server_port),
        connector_(connector),
        controller_properties_file_(controller_properties_file),
        controller_properties_(controller_properties_file),
        default_commands_file_(default_commands_file),
        enable_hci_sniffer_(enable_hci_sniffer),
        enable_baseband_sniffer_(enable_baseband_sniffer),
        enable_pcap_filter_(enable_pcap_filter),
        controller_(std::make_shared<rootcanal::DualModeController>(
            controller_properties_file)) {
        enable_pcap_filter_(enable_pcap_filter) {
    test_model_.SetReuseDeviceIds(!disable_address_reuse);
  }

@@ -80,12 +78,13 @@ class TestEnvironment {

 private:
  rootcanal::AsyncManager async_manager_;
  rootcanal::TestChannelTransport test_channel_transport_;
  std::shared_ptr<AsyncDataChannelServer> test_socket_server_;
  std::shared_ptr<AsyncDataChannelServer> hci_socket_server_;
  std::shared_ptr<AsyncDataChannelServer> link_socket_server_;
  std::shared_ptr<AsyncDataChannelServer> link_ble_socket_server_;
  std::shared_ptr<AsyncDataChannelConnector> connector_;
  std::string controller_properties_file_;
  rootcanal::ControllerProperties controller_properties_;
  std::string default_commands_file_;
  bool enable_hci_sniffer_;
  bool enable_baseband_sniffer_;
@@ -97,16 +96,10 @@ class TestEnvironment {
  void SetUpHciServer(ConnectCallback on_connect);
  void SetUpLinkLayerServer();
  void SetUpLinkBleLayerServer();

  std::shared_ptr<Device> ConnectToRemoteServer(const std::string& server,
                                                int port, Phy::Type phy_type);

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

  rootcanal::TestChannelTransport test_channel_transport_;
  rootcanal::TestChannelTransport remote_hci_transport_;
  rootcanal::TestChannelTransport remote_link_layer_transport_;
  rootcanal::TestChannelTransport remote_link_ble_layer_transport_;

  rootcanal::TestModel test_model_{
      [this]() { return async_manager_.GetNextUserId(); },
      [this](rootcanal::AsyncUserId user_id, std::chrono::milliseconds delay,
+23 −97
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ using std::vector;

namespace rootcanal {
constexpr uint16_t kNumCommandPackets = 0x01;
constexpr uint16_t kLeMaximumAdvertisingDataLength = 512;
constexpr uint16_t kLeMaximumDataLength = 64;
constexpr uint16_t kLeMaximumDataTime = 0x148;

@@ -61,11 +60,8 @@ void DualModeController::SendCommandCompleteUnknownOpCodeEvent(
          static_cast<uint8_t>(ErrorCode::UNKNOWN_HCI_COMMAND)})));
}

DualModeController::DualModeController(const std::string& properties_filename,
                                       uint16_t /*num_keys*/)
    : properties_(properties_filename) {
  loopback_mode_ = LoopbackMode::NO_LOOPBACK;

DualModeController::DualModeController(ControllerProperties properties)
    : properties_(std::move(properties)) {
  Address public_address{};
  ASSERT(Address::FromString("3C:5A:B4:04:05:06", public_address));
  SetAddress(public_address);
@@ -77,6 +73,10 @@ DualModeController::DualModeController(const std::string& properties_filename,
      });
}

void DualModeController::ForwardToLm(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::SniffSubrating(CommandView command) {
  auto command_view = bluetooth::hci::SniffSubratingView::Create(command);
  ASSERT(command_view.IsValid());
@@ -797,53 +797,6 @@ void DualModeController::RejectSynchronousConnection(CommandView command) {
      status, kNumCommandPackets));
}

void DualModeController::IoCapabilityRequestReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::UserConfirmationRequestReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::UserConfirmationRequestNegativeReply(
    CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::PinCodeRequestReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::PinCodeRequestNegativeReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::UserPasskeyRequestReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::UserPasskeyRequestNegativeReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::RemoteOobDataRequestReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::RemoteOobDataRequestNegativeReply(
    CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::IoCapabilityRequestNegativeReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::RemoteOobExtendedDataRequestReply(
    CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::ReadInquiryResponseTransmitPowerLevel(
    CommandView command) {
  auto command_view =
@@ -857,10 +810,6 @@ void DualModeController::ReadInquiryResponseTransmitPowerLevel(
          Create(kNumCommandPackets, ErrorCode::SUCCESS, tx_power));
}

void DualModeController::SendKeypressNotification(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::EnhancedFlush(CommandView command) {
  auto command_view = bluetooth::hci::EnhancedFlushView::Create(command);
  ASSERT(command_view.IsValid());
@@ -1004,14 +953,6 @@ void DualModeController::WriteInquiryScanType(CommandView command) {
      kNumCommandPackets, ErrorCode::SUCCESS));
}

void DualModeController::AuthenticationRequested(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::SetConnectionEncryption(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::ChangeConnectionLinkKey(CommandView command) {
  auto command_view =
      bluetooth::hci::ChangeConnectionLinkKeyView::Create(command);
@@ -1466,14 +1407,6 @@ void DualModeController::RejectConnectionRequest(CommandView command) {
      status, kNumCommandPackets));
}

void DualModeController::LinkKeyRequestReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::LinkKeyRequestNegativeReply(CommandView command) {
  link_layer_controller_.ForwardToLm(command);
}

void DualModeController::DeleteStoredLinkKey(CommandView command) {
  auto command_view = bluetooth::hci::DeleteStoredLinkKeyView::Create(command);
  ASSERT(command_view.IsValid());
@@ -2634,7 +2567,7 @@ void DualModeController::LeReadMaximumAdvertisingDataLength(
  send_event_(
      bluetooth::hci::LeReadMaximumAdvertisingDataLengthCompleteBuilder::Create(
          kNumCommandPackets, ErrorCode::SUCCESS,
          kLeMaximumAdvertisingDataLength));
          properties_.le_max_advertising_data_length));
}

void DualModeController::LeReadNumberOfSupportedAdvertisingSets(
@@ -3300,20 +3233,16 @@ const std::unordered_map<OpCode, DualModeController::CommandHandler>
         &DualModeController::AcceptConnectionRequest},
        {OpCode::REJECT_CONNECTION_REQUEST,
         &DualModeController::RejectConnectionRequest},
        {OpCode::LINK_KEY_REQUEST_REPLY,
         &DualModeController::LinkKeyRequestReply},
        {OpCode::LINK_KEY_REQUEST_REPLY, &DualModeController::ForwardToLm},
        {OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY,
         &DualModeController::LinkKeyRequestNegativeReply},
        {OpCode::PIN_CODE_REQUEST_REPLY,
         &DualModeController::PinCodeRequestReply},
         &DualModeController::ForwardToLm},
        {OpCode::PIN_CODE_REQUEST_REPLY, &DualModeController::ForwardToLm},
        {OpCode::PIN_CODE_REQUEST_NEGATIVE_REPLY,
         &DualModeController::PinCodeRequestNegativeReply},
         &DualModeController::ForwardToLm},
        {OpCode::CHANGE_CONNECTION_PACKET_TYPE,
         &DualModeController::ChangeConnectionPacketType},
        {OpCode::AUTHENTICATION_REQUESTED,
         &DualModeController::AuthenticationRequested},
        {OpCode::SET_CONNECTION_ENCRYPTION,
         &DualModeController::SetConnectionEncryption},
        {OpCode::AUTHENTICATION_REQUESTED, &DualModeController::ForwardToLm},
        {OpCode::SET_CONNECTION_ENCRYPTION, &DualModeController::ForwardToLm},
        {OpCode::CHANGE_CONNECTION_LINK_KEY,
         &DualModeController::ChangeConnectionLinkKey},
        {OpCode::CENTRAL_LINK_KEY, &DualModeController::CentralLinkKey},
@@ -3334,22 +3263,20 @@ const std::unordered_map<OpCode, DualModeController::CommandHandler>
         &DualModeController::AcceptSynchronousConnection},
        {OpCode::REJECT_SYNCHRONOUS_CONNECTION,
         &DualModeController::RejectSynchronousConnection},
        {OpCode::IO_CAPABILITY_REQUEST_REPLY,
         &DualModeController::IoCapabilityRequestReply},
        {OpCode::IO_CAPABILITY_REQUEST_REPLY, &DualModeController::ForwardToLm},
        {OpCode::USER_CONFIRMATION_REQUEST_REPLY,
         &DualModeController::UserConfirmationRequestReply},
         &DualModeController::ForwardToLm},
        {OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY,
         &DualModeController::UserConfirmationRequestNegativeReply},
        {OpCode::USER_PASSKEY_REQUEST_REPLY,
         &DualModeController::UserPasskeyRequestReply},
         &DualModeController::ForwardToLm},
        {OpCode::USER_PASSKEY_REQUEST_REPLY, &DualModeController::ForwardToLm},
        {OpCode::USER_PASSKEY_REQUEST_NEGATIVE_REPLY,
         &DualModeController::UserPasskeyRequestNegativeReply},
         &DualModeController::ForwardToLm},
        {OpCode::REMOTE_OOB_DATA_REQUEST_REPLY,
         &DualModeController::RemoteOobDataRequestReply},
         &DualModeController::ForwardToLm},
        {OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY,
         &DualModeController::RemoteOobDataRequestNegativeReply},
         &DualModeController::ForwardToLm},
        {OpCode::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY,
         &DualModeController::IoCapabilityRequestNegativeReply},
         &DualModeController::ForwardToLm},
        {OpCode::ENHANCED_SETUP_SYNCHRONOUS_CONNECTION,
         &DualModeController::EnhancedSetupSynchronousConnection},
        {OpCode::ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION,
@@ -3366,7 +3293,7 @@ const std::unordered_map<OpCode, DualModeController::CommandHandler>
        //{OpCode::RECEIVE_SYNCHRONIZATION_TRAIN,
        //&DualModeController::ReceiveSynchronizationTrain},
        {OpCode::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY,
         &DualModeController::RemoteOobExtendedDataRequestReply},
         &DualModeController::ForwardToLm},

        // LINK_POLICY
        {OpCode::HOLD_MODE, &DualModeController::HoldMode},
@@ -3492,8 +3419,7 @@ const std::unordered_map<OpCode, DualModeController::CommandHandler>
        //{OpCode::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING,
        //&DualModeController::WriteDefaultErroneousDataReporting},
        {OpCode::ENHANCED_FLUSH, &DualModeController::EnhancedFlush},
        {OpCode::SEND_KEYPRESS_NOTIFICATION,
         &DualModeController::SendKeypressNotification},
        {OpCode::SEND_KEYPRESS_NOTIFICATION, &DualModeController::ForwardToLm},
        {OpCode::SET_EVENT_MASK_PAGE_2, &DualModeController::SetEventMaskPage2},
        //{OpCode::READ_FLOW_CONTROL_MODE,
        //&DualModeController::ReadFlowControlMode},
+13 −67
Original line number Diff line number Diff line
@@ -48,24 +48,22 @@ using ::bluetooth::hci::CommandView;
// corresponding Bluetooth command in the Core Specification with the prefix
// "Hci" to distinguish it as a controller command.
class DualModeController : public Device {
  static constexpr uint16_t kSecurityManagerNumKeys = 15;

 public:
  // Sets all of the methods to be used as callbacks in the HciHandler.
  DualModeController(const std::string& properties_filename = "",
                     uint16_t num_keys = kSecurityManagerNumKeys);

  DualModeController(ControllerProperties properties = ControllerProperties());
  DualModeController(DualModeController&&) = delete;
  DualModeController(const DualModeController&) = delete;
  ~DualModeController() = default;

  DualModeController& operator=(const DualModeController&) = delete;

  // Device methods.
  virtual std::string GetTypeString() const override;
  std::string GetTypeString() const override;

  virtual void ReceiveLinkLayerPacket(
      model::packets::LinkLayerPacketView incoming, Phy::Type type,
      int8_t rssi) override;
  void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView incoming,
                              Phy::Type type, int8_t rssi) override;

  virtual void Tick() override;
  virtual void Close() override;
  void Tick() override;
  void Close() override;

  // Route commands and data from the stack.
  void HandleAcl(std::shared_ptr<std::vector<uint8_t>> acl_packet);
@@ -120,27 +118,9 @@ class DualModeController : public Device {
  // 7.1.9
  void RejectConnectionRequest(CommandView command);

  // 7.1.10
  void LinkKeyRequestReply(CommandView command);

  // 7.1.11
  void LinkKeyRequestNegativeReply(CommandView command);

  // 7.1.12
  void PinCodeRequestReply(CommandView command);

  // 7.1.13
  void PinCodeRequestNegativeReply(CommandView command);

  // 7.1.14
  void ChangeConnectionPacketType(CommandView command);

  // 7.1.15
  void AuthenticationRequested(CommandView command);

  // 7.1.16
  void SetConnectionEncryption(CommandView command);

  // 7.1.17
  void ChangeConnectionLinkKey(CommandView command);

@@ -174,39 +154,12 @@ class DualModeController : public Device {
  // 7.1.28
  void RejectSynchronousConnection(CommandView command);

  // 7.1.29
  void IoCapabilityRequestReply(CommandView command);

  // 7.1.30
  void UserConfirmationRequestReply(CommandView command);

  // 7.1.31
  void UserConfirmationRequestNegativeReply(CommandView command);

  // 7.1.32
  void UserPasskeyRequestReply(CommandView command);

  // 7.1.33
  void UserPasskeyRequestNegativeReply(CommandView command);

  // 7.1.34
  void RemoteOobDataRequestReply(CommandView command);

  // 7.1.35
  void RemoteOobDataRequestNegativeReply(CommandView command);

  // 7.1.36
  void IoCapabilityRequestNegativeReply(CommandView command);

  // 7.1.45
  void EnhancedSetupSynchronousConnection(CommandView command);

  // 7.1.46
  void EnhancedAcceptSynchronousConnection(CommandView command);

  // 7.1.53
  void RemoteOobExtendedDataRequestReply(CommandView command);

  // Link Policy Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.2

@@ -354,9 +307,6 @@ class DualModeController : public Device {
  // 7.3.61
  void ReadInquiryResponseTransmitPowerLevel(CommandView command);

  // 7.3.63
  void SendKeypressNotification(CommandView command);

  // 7.3.66
  void EnhancedFlush(CommandView command);

@@ -624,9 +574,8 @@ class DualModeController : public Device {
  void CsrReadPskey(CsrPskey pskey, std::vector<uint8_t>& value);
  void CsrWritePskey(CsrPskey pskey, std::vector<uint8_t> const& value);

  void SetTimerPeriod(std::chrono::milliseconds new_period);
  void StartTimer();
  void StopTimer();
  // Command pass-through.
  void ForwardToLm(CommandView command);

 protected:
  // Controller configuration.
@@ -651,7 +600,7 @@ class DualModeController : public Device {
  // Loopback mode (Vol 4, Part E § 7.6.1).
  // The local loopback mode is used to pass the android Vendor Test Suite
  // with RootCanal.
  bluetooth::hci::LoopbackMode loopback_mode_;
  bluetooth::hci::LoopbackMode loopback_mode_{LoopbackMode::NO_LOOPBACK};

  // Map command opcodes to the corresponding bit index in the
  // supported command mask.
@@ -665,9 +614,6 @@ class DualModeController : public Device {
  using CommandHandler =
      std::function<void(DualModeController*, bluetooth::hci::CommandView)>;
  static const std::unordered_map<OpCode, CommandHandler> hci_command_handlers_;

  DualModeController(const DualModeController& other) = delete;
  DualModeController& operator=(const DualModeController& other) = delete;
};

}  // namespace rootcanal
Loading