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

Commit cff9e10a authored by Martin Brabham's avatar Martin Brabham
Browse files

L2cap/Hci: Add call for feature exchange

Bug: 145638034
Test: N/A
Change-Id: I811856672663874928b98137f16e6aee2e612caf
parent a8a8f693
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -198,6 +198,12 @@ struct AclManager::impl {
                                     Bind(&impl::on_flow_specification_complete, common::Unretained(this)), handler_);
    hci_layer_->RegisterEventHandler(EventCode::FLUSH_OCCURRED,
                                     Bind(&impl::on_flush_occurred, common::Unretained(this)), handler_);
    hci_layer_->RegisterEventHandler(EventCode::READ_REMOTE_SUPPORTED_FEATURES_COMPLETE,
                                     Bind(&impl::on_read_remote_supported_features_complete, common::Unretained(this)),
                                     handler_);
    hci_layer_->RegisterEventHandler(EventCode::READ_REMOTE_EXTENDED_FEATURES_COMPLETE,
                                     Bind(&impl::on_read_remote_extended_features_complete, common::Unretained(this)),
                                     handler_);
    hci_mtu_ = controller_->GetControllerAclPacketLength();
  }

@@ -206,6 +212,8 @@ struct AclManager::impl {
    hci_layer_->UnregisterEventHandler(EventCode::CONNECTION_COMPLETE);
    hci_layer_->UnregisterEventHandler(EventCode::CONNECTION_REQUEST);
    hci_layer_->UnregisterEventHandler(EventCode::AUTHENTICATION_COMPLETE);
    hci_layer_->UnregisterEventHandler(EventCode::READ_REMOTE_SUPPORTED_FEATURES_COMPLETE);
    hci_layer_->UnregisterEventHandler(EventCode::READ_REMOTE_EXTENDED_FEATURES_COMPLETE);
    hci_queue_end_->UnregisterDequeue();
    unregister_all_connections();
    acl_connections_.clear();
@@ -726,6 +734,14 @@ struct AclManager::impl {
    }
  }

  void on_read_remote_supported_features_complete(EventPacketView packet) {
    LOG_INFO("called");
  }

  void on_read_remote_extended_features_complete(EventPacketView packet) {
    LOG_INFO("called");
  }

  void on_role_discovery_complete(CommandCompleteView view) {
    auto complete_view = RoleDiscoveryCompleteView::Create(view);
    if (!complete_view.IsValid()) {
@@ -935,6 +951,14 @@ struct AclManager::impl {
    }
  }

  void on_read_remote_supported_features_status(CommandStatusView view) {
    LOG_INFO("called");
  }

  void on_read_remote_extended_features_status(CommandStatusView view) {
    LOG_INFO("called");
  }

  void on_read_clock_complete(CommandCompleteView view) {
    auto complete_view = ReadClockCompleteView::Create(view);
    if (!complete_view.IsValid()) {
@@ -1329,6 +1353,19 @@ struct AclManager::impl {
                               common::BindOnce(&impl::on_read_rssi_complete, common::Unretained(this)), handler_);
  }

  void handle_read_remote_supported_features(uint16_t handle) {
    hci_layer_->EnqueueCommand(
        ReadRemoteSupportedFeaturesBuilder::Create(handle),
        common::BindOnce(&impl::on_read_remote_supported_features_status, common::Unretained(this)), handler_);
  }

  void handle_read_remote_extended_features(uint16_t handle) {
    // TODO(optedoblivion): Read the other pages until max pages
    hci_layer_->EnqueueCommand(
        ReadRemoteExtendedFeaturesBuilder::Create(handle, 1),
        common::BindOnce(&impl::on_read_remote_extended_features_status, common::Unretained(this)), handler_);
  }

  void handle_read_clock(uint16_t handle, WhichClock which_clock) {
    std::unique_ptr<ReadClockBuilder> packet = ReadClockBuilder::Create(handle, which_clock);
    hci_layer_->EnqueueCommand(std::move(packet),
@@ -1729,6 +1766,26 @@ struct AclManager::impl {
    return true;
  }

  bool ReadRemoteSupportedFeatures(uint16_t handle) {
    auto& connection = check_and_get_connection(handle);
    if (connection.is_disconnected_) {
      LOG_INFO("Already disconnected");
      return false;
    }
    handler_->Post(BindOnce(&impl::handle_read_remote_supported_features, common::Unretained(this), handle));
    return true;
  }

  bool ReadRemoteExtendedFeatures(uint16_t handle) {
    auto& connection = check_and_get_connection(handle);
    if (connection.is_disconnected_) {
      LOG_INFO("Already disconnected");
      return false;
    }
    handler_->Post(BindOnce(&impl::handle_read_remote_extended_features, common::Unretained(this), handle));
    return true;
  }

  bool ReadClock(uint16_t handle, WhichClock which_clock) {
    auto& connection = check_and_get_connection(handle);
    if (connection.is_disconnected_) {
@@ -1923,6 +1980,14 @@ bool AclConnection::ReadRssi() {
  return manager_->pimpl_->ReadRssi(handle_);
}

bool AclConnection::ReadRemoteSupportedFeatures() {
  return manager_->pimpl_->ReadRemoteSupportedFeatures(handle_);
}

bool AclConnection::ReadRemoteExtendedFeatures() {
  return manager_->pimpl_->ReadRemoteExtendedFeatures(handle_);
}

bool AclConnection::ReadClock(WhichClock which_clock) {
  return manager_->pimpl_->ReadClock(handle_, which_clock);
}
+2 −0
Original line number Diff line number Diff line
@@ -142,6 +142,8 @@ class AclConnection {
  virtual bool ReadAfhChannelMap();
  virtual bool ReadRssi();
  virtual bool ReadClock(WhichClock which_clock);
  virtual bool ReadRemoteSupportedFeatures();
  virtual bool ReadRemoteExtendedFeatures();

  // LE ACL Method
  virtual bool LeConnectionUpdate(uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency,
+8 −0
Original line number Diff line number Diff line
@@ -63,6 +63,14 @@ void Link::Authenticate() {
  acl_connection_->AuthenticationRequested();
}

void Link::ReadRemoteSupportedFeatures() {
  acl_connection_->ReadRemoteSupportedFeatures();
}

void Link::ReadRemoteExtendedFeatures() {
  acl_connection_->ReadRemoteExtendedFeatures();
}

std::shared_ptr<FixedChannelImpl> Link::AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
  auto channel = fixed_channel_allocator_.AllocateChannel(cid, security_policy);
  data_pipeline_manager_.AttachChannel(cid, channel, l2cap::internal::DataPipelineManager::ChannelMode::BASIC);
+4 −0
Original line number Diff line number Diff line
@@ -69,6 +69,10 @@ class Link : public l2cap::internal::ILink {

  virtual void Authenticate();

  virtual void ReadRemoteSupportedFeatures();

  virtual void ReadRemoteExtendedFeatures();

  // FixedChannel methods

  std::shared_ptr<FixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy);
+7 −0
Original line number Diff line number Diff line
@@ -52,6 +52,11 @@ void LinkManager::ConnectFixedChannelServices(hci::Address device,
        // This channel is already allocated for this link, do not allocated twice
        continue;
      }
      if (fixed_channel_service.first == kClassicPairingTriggerCid) {
        link->Authenticate();
        link->ReadRemoteSupportedFeatures();
        link->ReadRemoteExtendedFeatures();
      }
      // Allocate channel for newly registered fixed channels
      auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
      fixed_channel_service.second->NotifyChannelCreation(
@@ -128,6 +133,8 @@ void LinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_conne
        std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
    if (fixed_channel_service.first == kClassicPairingTriggerCid) {
      link->Authenticate();
      link->ReadRemoteSupportedFeatures();
      link->ReadRemoteExtendedFeatures();
    }
  }
  if (pending_dynamic_channels_.find(device) != pending_dynamic_channels_.end()) {