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

Commit 98f24171 authored by Myles Watson's avatar Myles Watson
Browse files

AclManager: Handle default data length

Bug: 145832107
Test: cert/run --host
Tag: #gd-refactor
Change-Id: I851f22db86687801232621e738deeecf2df51834
parent 7b9f8e82
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -141,6 +141,10 @@ void AclManager::CreateLeConnection(AddressWithType address_with_type) {
  CallOn(pimpl_->le_impl_, &le_impl::create_le_connection, address_with_type, true);
}

void AclManager::SetLeSuggestedDefaultDataParameters(uint16_t octets, uint16_t time) {
  CallOn(pimpl_->le_impl_, &le_impl::set_le_suggested_default_data_parameters, octets, time);
}

void AclManager::SetPrivacyPolicyForInitiatorAddress(
    LeAddressManager::AddressPolicy address_policy,
    AddressWithType fixed_address,
+3 −0
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ class AclManager : public Module {
  // Generates OnLeConnectSuccess if connected, or OnLeConnectFail otherwise
  virtual void CreateLeConnection(AddressWithType address_with_type);

  // Ask the controller for specific data parameters
  virtual void SetLeSuggestedDefaultDataParameters(uint16_t octets, uint16_t time);

  virtual void SetPrivacyPolicyForInitiatorAddress(
      LeAddressManager::AddressPolicy address_policy,
      AddressWithType fixed_address,
+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ class LeAclConnectionTracker : public LeConnectionManagementCallbacks {
    SAVE_OR_CALL(OnConnectionUpdate, conn_interval, conn_latency, supervision_timeout)
  }

  void OnDataLengthChange(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time) override {
    SAVE_OR_CALL(OnDataLengthChange, tx_octets, tx_time, rx_octets, rx_time)
  }

  void OnDisconnection(ErrorCode reason) override {
    SAVE_OR_CALL(OnDisconnection, reason);
  }
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ class LeConnectionManagementCallbacks {
  virtual ~LeConnectionManagementCallbacks() = default;
  virtual void OnConnectionUpdate(uint16_t connection_interval, uint16_t connection_latency,
                                  uint16_t supervision_timeout) = 0;
  virtual void OnDataLengthChange(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time) = 0;
  virtual void OnDisconnection(ErrorCode reason) = 0;
};

+28 −0
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      case SubeventCode::PHY_UPDATE_COMPLETE:
        LOG_INFO("PHY_UPDATE_COMPLETE");
        break;
      case SubeventCode::DATA_LENGTH_CHANGE:
        on_data_length_change(event_packet);
        break;
      default:
        LOG_ALWAYS_FATAL("Unhandled event code %s", SubeventCodeText(code).c_str());
    }
@@ -244,6 +247,25 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
        handler_->BindOnce(&LeAddressManager::OnCommandComplete, common::Unretained(le_address_manager_)));
  }

  void on_data_length_change(LeMetaEventView view) {
    auto data_length_view = LeDataLengthChangeView::Create(view);
    if (!data_length_view.IsValid()) {
      LOG_ERROR("Invalid packet");
      return;
    }
    auto handle = data_length_view.GetConnectionHandle();
    auto connection_iterator = le_acl_connections_.find(handle);
    if (connection_iterator == le_acl_connections_.end()) {
      LOG_WARN("Can't find connection %hd", handle);
      return;
    }
    connection_iterator->second.le_connection_management_callbacks_->OnDataLengthChange(
        data_length_view.GetMaxTxOctets(),
        data_length_view.GetMaxTxTime(),
        data_length_view.GetMaxRxOctets(),
        data_length_view.GetMaxRxTime());
  }

  void add_device_to_connect_list(AddressWithType address_with_type) {
    AddressType address_type = address_with_type.GetAddressType();
    if (!address_manager_registered) {
@@ -361,6 +383,12 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    remove_device_from_connect_list(address_with_type);
  }

  void set_le_suggested_default_data_parameters(uint16_t length, uint16_t time) {
    auto packet = LeWriteSuggestedDefaultDataLengthBuilder::Create(length, time);
    le_acl_connection_interface_->EnqueueCommand(
        std::move(packet), handler_->BindOnce([](CommandCompleteView complete) {}));
  }

  void remove_device_from_connect_list(AddressWithType address_with_type) {
    AddressType address_type = address_with_type.GetAddressType();
    if (!address_manager_registered) {
Loading