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

Commit 12e4870c authored by William Escande's avatar William Escande
Browse files

BT5.3 Subrating -- handle event in Gd

Handle Subrating event in Gd and plumbing to go back to shim legacy.

BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Bug: 248126637
Test: bluetooth_test_gd_unit64 --gtest_filter="*on_le_event__SUBRATE_CHANGE_EVENT"
Change-Id: I8afe38f27020fe16b867d210df147bf22a33885f
parent af4d4c97
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -74,6 +74,15 @@ class LeAclConnectionTracker : public LeConnectionManagementCallbacks {
  void OnLocalAddressUpdate(AddressWithType address_with_type) override {
    SAVE_OR_CALL(OnLocalAddressUpdate, address_with_type);
  }
  void OnLeSubrateChange(
      hci::ErrorCode hci_status,
      uint16_t subrate_factor,
      uint16_t peripheral_latency,
      uint16_t continuation_number,
      uint16_t supervision_timeout) override {
    SAVE_OR_CALL(
        OnLeSubrateChange, hci_status, subrate_factor, peripheral_latency, continuation_number, supervision_timeout);
  }

  void OnDisconnection(ErrorCode reason) override {
    SAVE_OR_CALL(OnDisconnection, reason);
+6 −0
Original line number Diff line number Diff line
@@ -40,6 +40,12 @@ class LeConnectionManagementCallbacks {
  virtual void OnLeReadRemoteFeaturesComplete(hci::ErrorCode hci_status, uint64_t features) = 0;
  virtual void OnPhyUpdate(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy) = 0;
  virtual void OnLocalAddressUpdate(AddressWithType address_with_type) = 0;
  virtual void OnLeSubrateChange(
      hci::ErrorCode hci_status,
      uint16_t subrate_factor,
      uint16_t peripheral_latency,
      uint16_t continuation_number,
      uint16_t supervision_timeout) = 0;
};

}  // namespace acl_manager
+20 −0
Original line number Diff line number Diff line
@@ -169,6 +169,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      case SubeventCode::REMOTE_CONNECTION_PARAMETER_REQUEST:
        on_remote_connection_parameter_request(event_packet);
        break;
      case SubeventCode::LE_SUBRATE_CHANGE:
        on_le_subrate_change(event_packet);
        break;
      default:
        LOG_ALWAYS_FATAL("Unhandled event code %s", SubeventCodeText(code).c_str());
    }
@@ -643,6 +646,23 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    });
  }

  void on_le_subrate_change(LeMetaEventView view) {
    auto subrate_change_view = LeSubrateChangeView::Create(view);
    if (!subrate_change_view.IsValid()) {
      LOG_ERROR("Invalid packet");
      return;
    }
    auto handle = subrate_change_view.GetConnectionHandle();
    connections.execute(handle, [=](LeConnectionManagementCallbacks* callbacks) {
      callbacks->OnLeSubrateChange(
          subrate_change_view.GetStatus(),
          subrate_change_view.GetSubrateFactor(),
          subrate_change_view.GetPeripheralLatency(),
          subrate_change_view.GetContinuationNumber(),
          subrate_change_view.GetSupervisionTimeout());
    });
  }

  uint16_t HACK_get_handle(Address address) {
    return connections.HACK_get_handle(address);
  }
+21 −0
Original line number Diff line number Diff line
@@ -418,6 +418,15 @@ class MockLeConnectionManagementCallbacks : public LeConnectionManagementCallbac
  MOCK_METHOD(void, OnLeReadRemoteFeaturesComplete, (hci::ErrorCode hci_status, uint64_t features), (override));
  MOCK_METHOD(void, OnPhyUpdate, (hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy), (override));
  MOCK_METHOD(void, OnLocalAddressUpdate, (AddressWithType address_with_type), (override));
  MOCK_METHOD(
      void,
      OnLeSubrateChange,
      (hci::ErrorCode hci_status,
       uint16_t subrate_factor,
       uint16_t peripheral_latency,
       uint16_t continuation_number,
       uint16_t supervision_timeout),
      (override));
};

class LeImplTest : public ::testing::Test {
@@ -1313,6 +1322,18 @@ TEST_F(LeImplWithConnectionTest, on_le_event__PHY_UPDATE_COMPLETE) {
  ASSERT_EQ(PhyType::LE_2M, rx_phy);
}

TEST_F(LeImplWithConnectionTest, on_le_event__SUBRATE_CHANGE_EVENT) {
  // Send a subrate event
  EXPECT_CALL(connection_management_callbacks_, OnLeSubrateChange(ErrorCode::SUCCESS, 0x01, 0x02, 0x03, 0x04));
  auto command = LeSubrateChangeBuilder::Create(ErrorCode::SUCCESS, kHciHandle, 0x01, 0x02, 0x03, 0x04);
  auto bytes = Serialize<LeSubrateChangeBuilder>(std::move(command));
  auto view = CreateLeEventView<hci::LeSubrateChangeView>(bytes);
  ASSERT_TRUE(view.IsValid());
  le_impl_->on_le_event(view);

  sync_handler();
}

TEST_F(LeImplWithConnectionTest, on_le_event__DATA_LENGTH_CHANGE) {
  uint16_t tx_octets{0};
  uint16_t tx_time{0};
+8 −0
Original line number Diff line number Diff line
@@ -695,6 +695,14 @@ class AclManagerWithLeConnectionTest : public AclManagerTest {
    MOCK_METHOD2(OnLeReadRemoteFeaturesComplete, void(hci::ErrorCode hci_status, uint64_t features));
    MOCK_METHOD3(OnPhyUpdate, void(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy));
    MOCK_METHOD1(OnLocalAddressUpdate, void(AddressWithType address_with_type));
    MOCK_METHOD5(
        OnLeSubrateChange,
        void(
            hci::ErrorCode hci_status,
            uint16_t subrate_factor,
            uint16_t peripheral_latency,
            uint16_t continuation_number,
            uint16_t supervision_timeout));
  } mock_le_connection_management_callbacks_;
};

Loading