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

Commit ecec3ca9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Root-Canal: Implement support for eSCO connections"

parents d8365b3d a6103528
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ cc_library_static {
        "model/controller/isochronous_connection_handler.cc",
        "model/controller/le_advertiser.cc",
        "model/controller/link_layer_controller.cc",
        "model/controller/sco_connection.cc",
        "model/controller/security_manager.cc",
        "model/devices/beacon.cc",
        "model/devices/beacon_swarm.cc",
+67 −0
Original line number Diff line number Diff line
@@ -400,4 +400,71 @@ StreamParameters AclConnectionHandler::GetStreamParameters(
  return isochronous_connection_handler_.GetStreamParameters(handle);
}

void AclConnectionHandler::CreatePendingScoConnection(
  bluetooth::hci::Address addr, ScoConnectionParameters const &parameters) {

  uint16_t sco_handle = GetUnusedHandle();
  sco_connections_.emplace(
    sco_handle, ScoConnection(addr, parameters));
}

bool AclConnectionHandler::HasPendingScoConnection(bluetooth::hci::Address addr) const {
  for (auto pair : sco_connections_) {
    if (std::get<ScoConnection>(pair).GetAddress() == addr) {
      return true;
    }
  }
  return false;
}

void AclConnectionHandler::CancelPendingScoConnection(bluetooth::hci::Address addr) {
  for (auto it = sco_connections_.begin(); it != sco_connections_.end(); it++) {
    if (std::get<ScoConnection>(*it).GetAddress() == addr) {
      sco_connections_.erase(it);
      return;
    }
  }
}

bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr,
  ScoLinkParameters const &parameters) {

  for (auto pair : sco_connections_) {
    if (std::get<ScoConnection>(pair).GetAddress() == addr) {
      std::get<ScoConnection>(pair).SetLinkParameters(parameters);
      return true;
    }
  }
  return false;
}

bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr,
  ScoConnectionParameters const &parameters) {

  for (auto pair : sco_connections_) {
    if (std::get<ScoConnection>(pair).GetAddress() == addr) {
      return std::get<ScoConnection>(pair).NegotiateLinkParameters(parameters);
    }
  }
  return false;
}

uint16_t AclConnectionHandler::GetScoHandle(bluetooth::hci::Address addr) const {
  for (auto pair : sco_connections_) {
    if (std::get<ScoConnection>(pair).GetAddress() == addr) {
      return std::get<0>(pair);
    }
  }
  return 0;
}

ScoLinkParameters AclConnectionHandler::GetScoLinkParameters(bluetooth::hci::Address addr) const {
  for (auto pair : sco_connections_) {
    if (std::get<ScoConnection>(pair).GetAddress() == addr) {
      return std::get<ScoConnection>(pair).GetLinkParameters();
    }
  }
  return {};
}

}  // namespace test_vendor_lib
+14 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include "hci/address_with_type.h"
#include "isochronous_connection_handler.h"
#include "phy.h"
#include "sco_connection.h"

namespace test_vendor_lib {
static constexpr uint16_t kReservedHandle = 0xF00;
@@ -41,6 +42,17 @@ class AclConnectionHandler {
  bool CancelPendingConnection(bluetooth::hci::Address addr);
  bool AuthenticatePendingConnection() const;

  bool HasPendingScoConnection(bluetooth::hci::Address addr) const;
  void CreatePendingScoConnection(bluetooth::hci::Address addr,
    ScoConnectionParameters const &parameters);
  void CancelPendingScoConnection(bluetooth::hci::Address addr);
  bool AcceptPendingScoConnection(bluetooth::hci::Address addr,
    ScoLinkParameters const &parameters);
  bool AcceptPendingScoConnection(bluetooth::hci::Address addr,
    ScoConnectionParameters const &parameters);
  uint16_t GetScoHandle(bluetooth::hci::Address addr) const;
  ScoLinkParameters GetScoLinkParameters(bluetooth::hci::Address addr) const;

  bool CreatePendingLeConnection(bluetooth::hci::AddressWithType addr);
  bool HasPendingLeConnection(bluetooth::hci::AddressWithType addr) const;
  bool CancelPendingLeConnection(bluetooth::hci::AddressWithType addr);
@@ -104,6 +116,8 @@ class AclConnectionHandler {

 private:
  std::unordered_map<uint16_t, AclConnection> acl_connections_;
  std::unordered_map<uint16_t, ScoConnection> sco_connections_;

  bool classic_connection_pending_{false};
  bluetooth::hci::Address pending_connection_address_{
      bluetooth::hci::Address::kEmpty};
+51 −0
Original line number Diff line number Diff line
@@ -122,6 +122,9 @@ DualModeController::DualModeController(const std::string& properties_filename, u
  SET_SUPPORTED(SWITCH_ROLE, SwitchRole);
  SET_SUPPORTED(READ_REMOTE_SUPPORTED_FEATURES, ReadRemoteSupportedFeatures);
  SET_SUPPORTED(READ_CLOCK_OFFSET, ReadClockOffset);
  SET_SUPPORTED(SETUP_SYNCHRONOUS_CONNECTION, SetupSynchronousConnection);
  SET_SUPPORTED(ACCEPT_SYNCHRONOUS_CONNECTION, AcceptSynchronousConnection);
  SET_SUPPORTED(REJECT_SYNCHRONOUS_CONNECTION, RejectSynchronousConnection);
  SET_SUPPORTED(IO_CAPABILITY_REQUEST_REPLY, IoCapabilityRequestReply);
  SET_SUPPORTED(USER_CONFIRMATION_REQUEST_REPLY, UserConfirmationRequestReply);
  SET_SUPPORTED(USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY,
@@ -657,6 +660,54 @@ void DualModeController::ReadClockOffset(CommandView command) {
  send_event_(std::move(packet));
}

void DualModeController::SetupSynchronousConnection(CommandView command) {
  auto command_view = gd_hci::SetupSynchronousConnectionView::Create(
    gd_hci::ScoConnectionCommandView::Create(
      gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  auto status = link_layer_controller_.SetupSynchronousConnection(
    command_view.GetConnectionHandle(), command_view.GetTransmitBandwidth(),
    command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(),
    command_view.GetVoiceSetting(), command_view.GetRetransmissionEffort(),
    command_view.GetPacketType());

  auto packet = bluetooth::hci::SetupSynchronousConnectionStatusBuilder::Create(
      status, kNumCommandPackets);
  send_event_(std::move(packet));
}

void DualModeController::AcceptSynchronousConnection(CommandView command) {
  auto command_view = gd_hci::AcceptSynchronousConnectionView::Create(
    gd_hci::ScoConnectionCommandView::Create(
      gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  auto status = link_layer_controller_.AcceptSynchronousConnection(
    command_view.GetBdAddr(), command_view.GetTransmitBandwidth(),
    command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(),
    command_view.GetVoiceSetting(), command_view.GetRetransmissionEffort(),
    command_view.GetPacketType());

  auto packet = bluetooth::hci::AcceptSynchronousConnectionStatusBuilder::Create(
      status, kNumCommandPackets);
  send_event_(std::move(packet));
}

void DualModeController::RejectSynchronousConnection(CommandView command) {
  auto command_view = gd_hci::RejectSynchronousConnectionView::Create(
    gd_hci::ScoConnectionCommandView::Create(
      gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  auto status = link_layer_controller_.RejectSynchronousConnection(
    command_view.GetBdAddr(), (uint16_t)command_view.GetReason());

  auto packet = bluetooth::hci::RejectSynchronousConnectionStatusBuilder::Create(
      status, kNumCommandPackets);
  send_event_(std::move(packet));
}

void DualModeController::IoCapabilityRequestReply(CommandView command) {
  auto command_view = gd_hci::IoCapabilityRequestReplyView::Create(
      gd_hci::SecurityCommandView::Create(command));
+9 −0
Original line number Diff line number Diff line
@@ -172,6 +172,15 @@ class DualModeController : public Device {
  // 7.1.24
  void ReadClockOffset(CommandView args);

  // 7.1.26
  void SetupSynchronousConnection(CommandView command);

  // 7.1.27
  void AcceptSynchronousConnection(CommandView command);

  // 7.1.28
  void RejectSynchronousConnection(CommandView command);

  // 7.1.29
  void IoCapabilityRequestReply(CommandView args);

Loading