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

Commit e0cf5f94 authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Implement the LL phy update procedure

Implement the full semantic of the LE Set Phy and LE Set Default Phy
commands by performing the LL phy update procedure.

Bug: 275970864
Test: m root-canal
Change-Id: I144ec8c153e0f2a3d96bcc408a46f0d383077625
parent e1e32a6f
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -33,22 +33,6 @@ void AclConnection::Encrypt() { encrypted_ = true; };

bool AclConnection::IsEncrypted() const { return encrypted_; };

AddressWithType AclConnection::GetAddress() const { return address_; }

void AclConnection::SetAddress(AddressWithType address) { address_ = address; }

AddressWithType AclConnection::GetOwnAddress() const { return own_address_; }

AddressWithType AclConnection::GetResolvedAddress() const {
  return resolved_address_;
}

void AclConnection::SetOwnAddress(AddressWithType address) {
  own_address_ = address;
}

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

uint16_t AclConnection::GetLinkPolicySettings() const {
  return link_policy_settings_;
};
+22 −22
Original line number Diff line number Diff line
@@ -35,44 +35,39 @@ class AclConnection {

  virtual ~AclConnection() = default;

  void Encrypt();

  bool IsEncrypted() const;

  AddressWithType GetAddress() const;

  void SetAddress(AddressWithType address);

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

  void SetOwnAddress(AddressWithType address);
  AddressWithType GetAddress() const { return address_; }
  AddressWithType GetOwnAddress() const { return own_address_; }
  AddressWithType GetResolvedAddress() const { return resolved_address_; }

  AddressWithType GetResolvedAddress() const;

  Phy::Type GetPhyType() const;
  void Encrypt();
  bool IsEncrypted() const;

  uint16_t GetLinkPolicySettings() const;

  void SetLinkPolicySettings(uint16_t settings);

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

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

  int8_t GetRssi() const;

  void SetRssi(int8_t rssi);

  void ResetLinkTimer();

  std::chrono::steady_clock::duration TimeUntilNearExpiring() const;

  bool IsNearExpiring() const;

  std::chrono::steady_clock::duration TimeUntilExpired() const;

  void ResetLinkTimer();
  bool IsNearExpiring() const;
  bool HasExpired() const;

  // LE-ACL state.
  void InitiatePhyUpdate() { initiated_phy_update_ = true; }
  void PhyUpdateComplete() { initiated_phy_update_ = false; }
  bool InitiatedPhyUpdate() const { return initiated_phy_update_; }
  bluetooth::hci::PhyType GetTxPhy() const { return tx_phy_; }
  bluetooth::hci::PhyType GetRxPhy() const { return rx_phy_; }
  void SetTxPhy(bluetooth::hci::PhyType phy) { tx_phy_ = phy; }
  void SetRxPhy(bluetooth::hci::PhyType phy) { rx_phy_ = phy; }

 private:
  AddressWithType address_;
  AddressWithType own_address_;
@@ -89,6 +84,11 @@ class AclConnection {
  bluetooth::hci::Role role_{bluetooth::hci::Role::CENTRAL};
  std::chrono::steady_clock::time_point last_packet_timestamp_;
  std::chrono::steady_clock::duration timeout_;

  // LE-ACL state.
  bluetooth::hci::PhyType tx_phy_{bluetooth::hci::PhyType::LE_1M};
  bluetooth::hci::PhyType rx_phy_{bluetooth::hci::PhyType::LE_1M};
  bool initiated_phy_update_{false};
};

}  // namespace rootcanal
+5 −0
Original line number Diff line number Diff line
@@ -197,6 +197,11 @@ uint16_t AclConnectionHandler::GetHandleOnlyAddress(
  return kReservedHandle;
}

AclConnection& AclConnectionHandler::GetAclConnection(uint16_t handle) {
  ASSERT_LOG(HasHandle(handle), "Unknown handle %d", handle);
  return acl_connections_.at(handle);
}

AddressWithType AclConnectionHandler::GetAddress(uint16_t handle) const {
  ASSERT_LOG(HasHandle(handle), "Unknown handle %hd", handle);
  return acl_connections_.at(handle).GetAddress();
+4 −0
Original line number Diff line number Diff line
@@ -91,6 +91,10 @@ class AclConnectionHandler {
  bluetooth::hci::AddressWithType GetOwnAddress(uint16_t handle) const;
  bluetooth::hci::AddressWithType GetResolvedAddress(uint16_t handle) const;

  // Return the AclConnection for the selected connection handle, asserts
  // if the handle is not currently used.
  AclConnection& GetAclConnection(uint16_t handle);

  void Encrypt(uint16_t handle);
  bool IsEncrypted(uint16_t handle) const;

+4 −5
Original line number Diff line number Diff line
@@ -1824,8 +1824,8 @@ void DualModeController::LeSetDefaultPhy(CommandView command) {
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeSetDefaultPhy(
      command_view.GetAllPhysNoTransmitPreference(),
      command_view.GetAllPhysNoReceivePreference(),
      command_view.GetTxPhysBitmask(), command_view.GetRxPhysBitmask());
      command_view.GetAllPhysNoReceivePreference(), command_view.GetTxPhys(),
      command_view.GetRxPhys());
  send_event_(bluetooth::hci::LeSetDefaultPhyCompleteBuilder::Create(
      kNumCommandPackets, status));
}
@@ -1836,9 +1836,8 @@ void DualModeController::LeSetPhy(CommandView command) {
  ErrorCode status = link_layer_controller_.LeSetPhy(
      command_view.GetConnectionHandle(),
      command_view.GetAllPhysNoTransmitPreference(),
      command_view.GetAllPhysNoReceivePreference(),
      command_view.GetTxPhysBitmask(), command_view.GetRxPhysBitmask(),
      command_view.GetPhyOptions());
      command_view.GetAllPhysNoReceivePreference(), command_view.GetTxPhys(),
      command_view.GetRxPhys(), command_view.GetPhyOptions());
  send_event_(bluetooth::hci::LeSetPhyStatusBuilder::Create(
      status, kNumCommandPackets));
}
Loading