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

Commit 8b7a674c authored by Rahul Arya's avatar Rahul Arya Committed by Thomas Girardier
Browse files

[RootCanal] Add support for LinkPolicy and RoleChange in RootCanal

Needed for HID PTS tests. We just fake the link policy and our current
role by tracking them locally, rather than using LMP to coordinate with
the peer. This can be changed at a future date if a test depends on this
working.

Bug: 239986609
Test: HID PTS tests
Tag: #feature
Ignore-AOSP-First: Cherry-picked from AOSP
Merged-In: I3b2b97a200b0279251fc68e37e23b8d3cfb8bdeb
Change-Id: I3b2b97a200b0279251fc68e37e23b8d3cfb8bdeb
parent cd9fe99e
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -46,4 +46,16 @@ void AclConnection::SetOwnAddress(AddressWithType address) {

Phy::Type AclConnection::GetPhyType() const { return type_; }

uint16_t AclConnection::GetLinkPolicySettings() const {
  return link_policy_settings_;
};

void AclConnection::SetLinkPolicySettings(uint16_t settings) {
  link_policy_settings_ = settings;
}

bluetooth::hci::Role AclConnection::GetRole() const { return role_; };

void AclConnection::SetRole(bluetooth::hci::Role role) { role_ = role; }

}  // namespace rootcanal
+10 −0
Original line number Diff line number Diff line
@@ -49,6 +49,14 @@ class AclConnection {

  Phy::Type GetPhyType() const;

  uint16_t GetLinkPolicySettings() const;

  void SetLinkPolicySettings(uint16_t settings);

  bluetooth::hci::Role GetRole() const;

  void SetRole(bluetooth::hci::Role role);

 private:
  AddressWithType address_;
  AddressWithType own_address_;
@@ -57,6 +65,8 @@ class AclConnection {

  // State variables
  bool encrypted_{false};
  uint16_t link_policy_settings_{0};
  bluetooth::hci::Role role_{bluetooth::hci::Role::CENTRAL};
};

}  // namespace rootcanal
+18 −0
Original line number Diff line number Diff line
@@ -223,6 +223,24 @@ Phy::Type AclConnectionHandler::GetPhyType(uint16_t handle) const {
  return acl_connections_.at(handle).GetPhyType();
}

uint16_t AclConnectionHandler::GetAclLinkPolicySettings(uint16_t handle) const {
  return acl_connections_.at(handle).GetLinkPolicySettings();
};

void AclConnectionHandler::SetAclLinkPolicySettings(uint16_t handle,
                                                    uint16_t settings) {
  acl_connections_.at(handle).SetLinkPolicySettings(settings);
}

bluetooth::hci::Role AclConnectionHandler::GetAclRole(uint16_t handle) const {
  return acl_connections_.at(handle).GetRole();
};

void AclConnectionHandler::SetAclRole(uint16_t handle,
                                      bluetooth::hci::Role role) {
  acl_connections_.at(handle).SetRole(role);
}

std::unique_ptr<bluetooth::hci::LeSetCigParametersCompleteBuilder>
AclConnectionHandler::SetCigParameters(
    uint8_t id, uint32_t sdu_interval_m_to_s, uint32_t sdu_interval_s_to_m,
+6 −0
Original line number Diff line number Diff line
@@ -84,6 +84,12 @@ class AclConnectionHandler {

  Phy::Type GetPhyType(uint16_t handle) const;

  uint16_t GetAclLinkPolicySettings(uint16_t handle) const;
  void SetAclLinkPolicySettings(uint16_t handle, uint16_t settings);

  bluetooth::hci::Role GetAclRole(uint16_t handle) const;
  void SetAclRole(uint16_t handle, bluetooth::hci::Role role);

  std::unique_ptr<bluetooth::hci::LeSetCigParametersCompleteBuilder>
  SetCigParameters(uint8_t id, uint32_t sdu_interval_m_to_s,
                   uint32_t sdu_interval_s_to_m,
+22 −4
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ DualModeController::DualModeController(const std::string& properties_filename,
  SET_SUPPORTED(WRITE_DEFAULT_LINK_POLICY_SETTINGS,
                WriteDefaultLinkPolicySettings);
  SET_SUPPORTED(FLOW_SPECIFICATION, FlowSpecification);
  SET_SUPPORTED(READ_LINK_POLICY_SETTINGS, ReadLinkPolicySettings);
  SET_SUPPORTED(WRITE_LINK_POLICY_SETTINGS, WriteLinkPolicySettings);
  SET_SUPPORTED(CHANGE_CONNECTION_PACKET_TYPE, ChangeConnectionPacketType);
  SET_SUPPORTED(WRITE_LOCAL_NAME, WriteLocalName);
@@ -629,8 +630,8 @@ void DualModeController::SwitchRole(CommandView command) {
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  auto status = link_layer_controller_.SwitchRole(
      command_view.GetBdAddr(), static_cast<uint8_t>(command_view.GetRole()));
  auto status = link_layer_controller_.SwitchRole(command_view.GetBdAddr(),
                                                  command_view.GetRole());

  send_event_(bluetooth::hci::SwitchRoleStatusBuilder::Create(
      status, kNumCommandPackets));
@@ -1586,10 +1587,11 @@ void DualModeController::RoleDiscovery(CommandView command) {
  ASSERT(command_view.IsValid());
  uint16_t handle = command_view.GetConnectionHandle();

  auto status = link_layer_controller_.RoleDiscovery(handle);
  auto role = bluetooth::hci::Role::CENTRAL;
  auto status = link_layer_controller_.RoleDiscovery(handle, &role);

  send_event_(bluetooth::hci::RoleDiscoveryCompleteBuilder::Create(
      kNumCommandPackets, status, handle, bluetooth::hci::Role::CENTRAL));
      kNumCommandPackets, status, handle, role));
}

void DualModeController::ReadDefaultLinkPolicySettings(CommandView command) {
@@ -1637,6 +1639,22 @@ void DualModeController::FlowSpecification(CommandView command) {
      status, kNumCommandPackets));
}

void DualModeController::ReadLinkPolicySettings(CommandView command) {
  auto command_view = gd_hci::ReadLinkPolicySettingsView::Create(
      gd_hci::ConnectionManagementCommandView::Create(
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  uint16_t handle = command_view.GetConnectionHandle();
  uint16_t settings;

  auto status =
      link_layer_controller_.ReadLinkPolicySettings(handle, &settings);

  send_event_(bluetooth::hci::ReadLinkPolicySettingsCompleteBuilder::Create(
      kNumCommandPackets, status, handle, settings));
}

void DualModeController::WriteLinkPolicySettings(CommandView command) {
  auto command_view = gd_hci::WriteLinkPolicySettingsView::Create(
      gd_hci::ConnectionManagementCommandView::Create(
Loading