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

Commit 18da6712 authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Implement all Role Change configurations

Role change may be requested at connection setup, or
after the connection setup, and rejected based on
specific configuration each time;

Listed below are the tested configurations:
- Peripheral connection at Setup, Accepted
- Peripheral connection at Setup, Rejected
- Peripheral connection, Accepted
- Peripheral connection, Rejected
- Central connection at Setup, Accepted
- Central connection at Setup, Rejected
- Central connection, Accepted
- Central connection, Rejected

What is not properly documented in the core specification, but is
well defined in the LMP test cases; a successful role switch
always generates an HCI Role Change event, at setup or not.

Bug: 274248798
Test: atest --host rootcanal_ll_test
Change-Id: Idf251f4e8234c015fc43863cd3d7f7928a510c2d
parent 78133222
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -294,6 +294,7 @@ python_test_host {
        "test/LL/CON_/PER/*.py",
        "test/LL/DDI/ADV/*.py",
        "test/LL/DDI/SCN/*.py",
        "test/LMP/LIH/*.py",
        "test/main.py",
    ],
    data: [
+1 −4
Original line number Diff line number Diff line
@@ -22,11 +22,8 @@ message ControllerQuirks {
  optional bool send_acl_data_before_connection_complete = 1;
  // Configure a default value for the LE random address.
  optional bool has_default_random_address = 2;
  // Send the Role Change event before the Connection Complete event
  // in the case where a role switch is initiated at connection establishment.
  optional bool send_role_change_before_connection_complete = 3;
  // Send an Hardware Error event if any command is called before HCI Reset.
  optional bool hardware_error_before_reset = 4;
  optional bool hardware_error_before_reset = 3;
}

message Controller {
+0 −4
Original line number Diff line number Diff line
@@ -33,10 +33,6 @@ void AclConnection::Encrypt() { encrypted_ = true; };

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

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

void AclConnection::SetLinkPolicySettings(uint16_t settings) {
  link_policy_settings_ = settings;
}
+15 −1
Original line number Diff line number Diff line
@@ -26,6 +26,12 @@ namespace rootcanal {

using ::bluetooth::hci::AddressWithType;

enum AclConnectionState {
  kActiveMode,
  kHoldMode,
  kSniffMode,
};

// Model the connection of a device to the controller.
class AclConnection {
 public:
@@ -44,8 +50,15 @@ class AclConnection {
  void Encrypt();
  bool IsEncrypted() const;

  uint16_t GetLinkPolicySettings() const;
  void SetLinkPolicySettings(uint16_t settings);
  uint16_t GetLinkPolicySettings() const { return link_policy_settings_; }
  bool IsRoleSwitchEnabled() const {
    return (link_policy_settings_ & 0x1) != 0;
  }
  bool IsHoldModeEnabled() const { return (link_policy_settings_ & 0x2) != 0; }
  bool IsSniffModeEnabled() const { return (link_policy_settings_ & 0x4) != 0; }

  AclConnectionState GetMode() const { return state_; }

  bluetooth::hci::Role GetRole() const;
  void SetRole(bluetooth::hci::Role role);
@@ -81,6 +94,7 @@ class AclConnection {
  // State variables
  bool encrypted_{false};
  uint16_t link_policy_settings_{0};
  AclConnectionState state_{kActiveMode};
  bluetooth::hci::Role role_{bluetooth::hci::Role::CENTRAL};
  std::chrono::steady_clock::time_point last_packet_timestamp_;
  std::chrono::steady_clock::duration timeout_;
+0 −1
Original line number Diff line number Diff line
@@ -1880,7 +1880,6 @@ ControllerProperties::ControllerProperties(
          config.quirks().hardware_error_before_reset();
    }
    // TODO(b/270606199): support send_acl_data_before_connection_complete
    // TODO(b/274476773): support send_role_change_before_connection_complete
  }

  if (!CheckSupportedFeatures()) {
Loading