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

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

RootCanal: Delay the first ACL packet sent on a connection

The PTS test L2CAP/CMC/BV-13-C's flakiness is caused by the PTS tool
handling a received ACL packet before the connection complete event
when it is received too early after the connection establishment.

This change adds a delay of 100ms to the first ACL packet being
sent to work around this issue.

Bug: 275294283
Test: atest pts-bot:L2CAP/CMC/BV-13-C
Change-Id: If32e40f4ef13f948791719fc813ae3aebd6e61aa
parent fec3d3ff
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ AclConnection::AclConnection(AddressWithType address,
      resolved_address_(resolved_address),
      type_(phy_type),
      role_(role),
      established_timestamp_(std::chrono::steady_clock::now()),
      last_packet_timestamp_(std::chrono::steady_clock::now()),
      timeout_(std::chrono::seconds(1)) {}

+5 −0
Original line number Diff line number Diff line
@@ -59,6 +59,10 @@ class AclConnection {
  bool IsNearExpiring() const;
  bool HasExpired() const;

  std::chrono::steady_clock::duration GetUptime() const {
    return std::chrono::steady_clock::now() - established_timestamp_;
  }

  // LE-ACL state.
  void InitiatePhyUpdate() { initiated_phy_update_ = true; }
  void PhyUpdateComplete() { initiated_phy_update_ = false; }
@@ -82,6 +86,7 @@ class AclConnection {
  bool encrypted_{false};
  uint16_t link_policy_settings_{0};
  bluetooth::hci::Role role_{bluetooth::hci::Role::CENTRAL};
  std::chrono::steady_clock::time_point established_timestamp_;
  std::chrono::steady_clock::time_point last_packet_timestamp_;
  std::chrono::steady_clock::duration timeout_;

+20 −9
Original line number Diff line number Diff line
@@ -2043,20 +2043,20 @@ LinkLayerController::~LinkLayerController() {}

void LinkLayerController::SendLeLinkLayerPacket(
    std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet,
    int8_t tx_power) {
    int8_t tx_power, std::chrono::milliseconds delay) {
  std::shared_ptr<model::packets::LinkLayerPacketBuilder> shared_packet =
      std::move(packet);
  ScheduleTask(kNoDelayMs, [this, shared_packet, tx_power]() {
  ScheduleTask(delay, [this, shared_packet, tx_power]() {
    send_to_remote_(shared_packet, Phy::Type::LOW_ENERGY, tx_power);
  });
}

void LinkLayerController::SendLinkLayerPacket(
    std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet,
    int8_t tx_power) {
    int8_t tx_power, std::chrono::milliseconds delay) {
  std::shared_ptr<model::packets::LinkLayerPacketBuilder> shared_packet =
      std::move(packet);
  ScheduleTask(kNoDelayMs, [this, shared_packet, tx_power]() {
  ScheduleTask(delay, [this, shared_packet, tx_power]() {
    send_to_remote_(shared_packet, Phy::Type::BR_EDR, tx_power);
  });
}
@@ -2143,10 +2143,21 @@ ErrorCode LinkLayerController::SendAclToRemote(
    return ErrorCode::UNKNOWN_CONNECTION;
  }

  AddressWithType my_address = connections_.GetOwnAddress(handle);
  AddressWithType destination = connections_.GetAddress(handle);
  AclConnection& connection = connections_.GetAclConnection(handle);
  AddressWithType my_address = connection.GetOwnAddress();
  AddressWithType destination = connection.GetAddress();
  Phy::Type phy = connections_.GetPhyType(handle);

  // The PTS test L2CAP/CMC/BV-13-C flakes if the first ACL packet is
  // sent too early after the connection establishment; the PTS in
  // this case is handling the packet before the Connection Complete
  // event and this causes the test to fail.
  std::chrono::milliseconds connection_uptime =
      std::chrono::duration_cast<std::chrono::milliseconds>(
          connection.GetUptime());
  std::chrono::milliseconds delay =
      connection_uptime > 100ms ? 0ms : 100ms - connection_uptime;

  auto acl_packet_payload = acl_packet.GetPayload();
  auto acl = model::packets::AclBuilder::Create(
      my_address.GetAddress(), destination.GetAddress(),
@@ -2156,14 +2167,14 @@ ErrorCode LinkLayerController::SendAclToRemote(

  switch (phy) {
    case Phy::Type::BR_EDR:
      SendLinkLayerPacket(std::move(acl));
      SendLinkLayerPacket(std::move(acl), 0, delay);
      break;
    case Phy::Type::LOW_ENERGY:
      SendLeLinkLayerPacket(std::move(acl));
      SendLeLinkLayerPacket(std::move(acl), 0, delay);
      break;
  }

  ScheduleTask(kNoDelayMs, [this, handle]() {
  ScheduleTask(delay, [this, handle]() {
    send_event_(bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(
        {bluetooth::hci::CompletedPackets(handle, 1)}));
  });
+4 −2
Original line number Diff line number Diff line
@@ -600,10 +600,12 @@ class LinkLayerController {
 protected:
  void SendLinkLayerPacket(
      std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet,
      int8_t tx_power = 0);
      int8_t tx_power = 0,
      std::chrono::milliseconds delay = std::chrono::milliseconds(0));
  void SendLeLinkLayerPacket(
      std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet,
      int8_t tx_power = 0);
      int8_t tx_power = 0,
      std::chrono::milliseconds delay = std::chrono::milliseconds(0));

  void IncomingAclPacket(model::packets::LinkLayerPacketView incoming,
                         int8_t rssi);