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

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

Merge changes I4ebefde3,I2817cd86

* changes:
  RootCanal: Add Iso Commands to controller
  RootCanal: Create Connection Cancel
parents e7837622 2f4817e0
Loading
Loading
Loading
Loading
+152 −10
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ DualModeController::DualModeController(const std::string& properties_filename, u
  SET_HANDLER(OpCode::LE_SET_SCAN_ENABLE, LeSetScanEnable);
  SET_HANDLER(OpCode::LE_CREATE_CONNECTION, LeCreateConnection);
  SET_HANDLER(OpCode::CREATE_CONNECTION, CreateConnection);
  SET_HANDLER(OpCode::CREATE_CONNECTION_CANCEL, CreateConnectionCancel);
  SET_HANDLER(OpCode::DISCONNECT, Disconnect);
  SET_HANDLER(OpCode::LE_CREATE_CONNECTION_CANCEL, LeConnectionCancel);
  SET_HANDLER(OpCode::LE_READ_CONNECT_LIST_SIZE, LeReadConnectListSize);
@@ -249,6 +250,20 @@ DualModeController::DualModeController(const std::string& properties_filename, u
              LeExtendedCreateConnection);
  SET_HANDLER(OpCode::LE_SET_PRIVACY_MODE, LeSetPrivacyMode);
  SET_HANDLER(OpCode::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, LeReadSuggestedDefaultDataLength);
  // ISO Commands
  SET_HANDLER(OpCode::LE_READ_ISO_TX_SYNC, LeReadIsoTxSync);
  SET_HANDLER(OpCode::LE_SET_CIG_PARAMETERS, LeSetCigParameters);
  SET_HANDLER(OpCode::LE_CREATE_CIS, LeCreateCis);
  SET_HANDLER(OpCode::LE_REMOVE_CIG, LeRemoveCig);
  SET_HANDLER(OpCode::LE_ACCEPT_CIS_REQUEST, LeAcceptCisRequest);
  SET_HANDLER(OpCode::LE_REJECT_CIS_REQUEST, LeRejectCisRequest);
  SET_HANDLER(OpCode::LE_CREATE_BIG, LeCreateBig);
  SET_HANDLER(OpCode::LE_TERMINATE_BIG, LeTerminateBig);
  SET_HANDLER(OpCode::LE_BIG_CREATE_SYNC, LeBigCreateSync);
  SET_HANDLER(OpCode::LE_BIG_TERMINATE_SYNC, LeBigTerminateSync);
  SET_HANDLER(OpCode::LE_REQUEST_PEER_SCA, LeRequestPeerSca);
  SET_HANDLER(OpCode::LE_SETUP_ISO_DATA_PATH, LeSetupIsoDataPath);
  SET_HANDLER(OpCode::LE_REMOVE_ISO_DATA_PATH, LeRemoveIsoDataPath);
  // Testing Commands
  SET_HANDLER(OpCode::READ_LOOPBACK_MODE, ReadLoopbackMode);
  SET_HANDLER(OpCode::WRITE_LOOPBACK_MODE, WriteLoopbackMode);
@@ -1604,6 +1619,20 @@ void DualModeController::CreateConnection(CommandPacketView command) {
  send_event_(std::move(packet));
}

void DualModeController::CreateConnectionCancel(CommandPacketView command) {
  auto command_view = gd_hci::CreateConnectionCancelView::Create(
      gd_hci::ConnectionManagementCommandView::Create(command));
  ASSERT(command_view.IsValid());

  Address address = command_view.GetBdAddr();

  auto status = link_layer_controller_.CreateConnectionCancel(address);

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

void DualModeController::Disconnect(CommandPacketView command) {
  auto command_view = gd_hci::DisconnectView::Create(
      gd_hci::ConnectionManagementCommandView::Create(command));
@@ -1623,16 +1652,9 @@ void DualModeController::LeConnectionCancel(CommandPacketView command) {
  auto command_view = gd_hci::LeCreateConnectionCancelView::Create(
      gd_hci::LeConnectionManagementCommandView::Create(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.SetLeConnect(false);
  auto packet = bluetooth::hci::LeCreateConnectionCancelCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS);
  send_event_(std::move(packet));
  /* For testing Jakub's patch:  Figure out a neat way to call this without
     recompiling.  I'm thinking about a bad device. */
  /*
  SendCommandCompleteOnlyStatus(OpCode::LE_CREATE_CONNECTION_CANCEL,
                                ErrorCode::COMMAND_DISALLOWED);
  */
  ErrorCode status = link_layer_controller_.SetLeConnect(false);
  send_event_(bluetooth::hci::LeCreateConnectionCancelCompleteBuilder::Create(
      kNumCommandPackets, status));
}

void DualModeController::LeReadConnectListSize(CommandPacketView command) {
@@ -1872,6 +1894,126 @@ void DualModeController::LeSetPrivacyMode(CommandPacketView command) {
  send_event_(std::move(packet));
}

void DualModeController::LeReadIsoTxSync(CommandPacketView command) {
  auto command_view = gd_hci::LeReadIsoTxSyncView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeReadIsoTxSync(command_view.GetConnectionHandle());
}

void DualModeController::LeSetCigParameters(CommandPacketView command) {
  auto command_view =
      gd_hci::LeSetCigParametersView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeSetCigParameters(
      command_view.GetCigId(), command_view.GetSduIntervalMToS(),
      command_view.GetSduIntervalSToM(), command_view.GetSlavesClockAccuracy(),
      command_view.GetPacking(), command_view.GetFraming(),
      command_view.GetMaxTransportLatencyMToS(),
      command_view.GetMaxTransportLatencySToM(), command_view.GetCisConfig());
}

void DualModeController::LeCreateCis(CommandPacketView command) {
  auto command_view = gd_hci::LeCreateCisView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  ErrorCode status =
      link_layer_controller_.LeCreateCis(command_view.GetCisConfig());
  send_event_(bluetooth::hci::LeCreateCisStatusBuilder::Create(
      status, kNumCommandPackets));
}

void DualModeController::LeRemoveCig(CommandPacketView command) {
  auto command_view = gd_hci::LeRemoveCigView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeRemoveCig(command_view.GetCigId());
}

void DualModeController::LeAcceptCisRequest(CommandPacketView command) {
  auto command_view =
      gd_hci::LeAcceptCisRequestView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeAcceptCisRequest(
      command_view.GetConnectionHandle());
  send_event_(bluetooth::hci::LeAcceptCisRequestStatusBuilder::Create(
      status, kNumCommandPackets));
}

void DualModeController::LeRejectCisRequest(CommandPacketView command) {
  auto command_view =
      gd_hci::LeRejectCisRequestView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeRejectCisRequest(command_view.GetConnectionHandle(),
                                            command_view.GetReason());
}

void DualModeController::LeCreateBig(CommandPacketView command) {
  auto command_view = gd_hci::LeCreateBigView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeCreateBig(
      command_view.GetBigHandle(), command_view.GetAdvertisingHandle(),
      command_view.GetNumBis(), command_view.GetSduInterval(),
      command_view.GetMaxSdu(), command_view.GetMaxTransportLatency(),
      command_view.GetRtn(), command_view.GetPhy(), command_view.GetPacking(),
      command_view.GetFraming(), command_view.GetEncryption(),
      command_view.GetBroadcastCode());
  send_event_(bluetooth::hci::LeCreateBigStatusBuilder::Create(
      status, kNumCommandPackets));
}

void DualModeController::LeTerminateBig(CommandPacketView command) {
  auto command_view = gd_hci::LeTerminateBigView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeTerminateBig(
      command_view.GetBigHandle(), command_view.GetReason());
  send_event_(bluetooth::hci::LeTerminateBigStatusBuilder::Create(
      status, kNumCommandPackets));
}

void DualModeController::LeBigCreateSync(CommandPacketView command) {
  auto command_view = gd_hci::LeBigCreateSyncView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeBigCreateSync(
      command_view.GetBigHandle(), command_view.GetSyncHandle(),
      command_view.GetEncryption(), command_view.GetBroadcastCode(),
      command_view.GetMse(), command_view.GetBigSyncTimeout(),
      command_view.GetBis());
  send_event_(bluetooth::hci::LeBigCreateSyncStatusBuilder::Create(
      status, kNumCommandPackets));
}

void DualModeController::LeBigTerminateSync(CommandPacketView command) {
  auto command_view =
      gd_hci::LeBigTerminateSyncView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeBigTerminateSync(command_view.GetBigHandle());
}

void DualModeController::LeRequestPeerSca(CommandPacketView command) {
  auto command_view = gd_hci::LeRequestPeerScaView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeRequestPeerSca(
      command_view.GetConnectionHandle());
  send_event_(bluetooth::hci::LeRequestPeerScaStatusBuilder::Create(
      status, kNumCommandPackets));
}

void DualModeController::LeSetupIsoDataPath(CommandPacketView command) {
  auto command_view =
      gd_hci::LeSetupIsoDataPathView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeSetupIsoDataPath(
      command_view.GetConnectionHandle(), command_view.GetDataPathDirection(),
      command_view.GetDataPathId(), command_view.GetCodecId(),
      command_view.GetControllerDelay(), command_view.GetCodecConfiguration());
}

void DualModeController::LeRemoveIsoDataPath(CommandPacketView command) {
  auto command_view =
      gd_hci::LeRemoveIsoDataPathView::Create(std::move(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeRemoveIsoDataPath(
      command_view.GetConnectionHandle(), command_view.GetDataPathDirection());
}

void DualModeController::LeReadRemoteFeatures(CommandPacketView command) {
  auto command_view = gd_hci::LeReadRemoteFeaturesView::Create(
      gd_hci::LeConnectionManagementCommandView::Create(command));
+18 −0
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ class DualModeController : public Device {
  // 7.1.6
  void Disconnect(CommandPacketView args);

  // 7.1.7
  void CreateConnectionCancel(CommandPacketView args);

  // 7.1.8
  void AcceptConnectionRequest(CommandPacketView args);

@@ -493,6 +496,21 @@ class DualModeController : public Device {
  // 7.8.77
  void LeSetPrivacyMode(CommandPacketView args);

  // 7.8.96 - 7.8.110
  void LeReadIsoTxSync(CommandPacketView packet_view);
  void LeSetCigParameters(CommandPacketView packet_view);
  void LeCreateCis(CommandPacketView packet_view);
  void LeRemoveCig(CommandPacketView packet_view);
  void LeAcceptCisRequest(CommandPacketView packet_view);
  void LeRejectCisRequest(CommandPacketView packet_view);
  void LeCreateBig(CommandPacketView packet_view);
  void LeTerminateBig(CommandPacketView packet_view);
  void LeBigCreateSync(CommandPacketView packet_view);
  void LeBigTerminateSync(CommandPacketView packet_view);
  void LeRequestPeerSca(CommandPacketView packet_view);
  void LeSetupIsoDataPath(CommandPacketView packet_view);
  void LeRemoveIsoDataPath(CommandPacketView packet_view);

  // Vendor-specific Commands

  void LeVendorSleepMode(CommandPacketView args);
+61 −0
Original line number Diff line number Diff line
@@ -1954,6 +1954,67 @@ void LinkLayerController::LeSetPrivacyMode(uint8_t address_type, Address addr,
  LOG_INFO("mode = %d ", mode);
}

void LinkLayerController::LeReadIsoTxSync(uint16_t handle) {}

void LinkLayerController::LeSetCigParameters(
    uint8_t cig_id, uint32_t sdu_interval_m_to_s, uint32_t sdu_interval_s_to_m,
    bluetooth::hci::ClockAccuracy clock_accuracy,
    bluetooth::hci::Packing packing, bluetooth::hci::Enable framing,
    uint16_t max_transport_latency_m_to_s,
    uint16_t max_transport_latency_s_to_m,
    std::vector<bluetooth::hci::CisParametersConfig> cis_config) {}

ErrorCode LinkLayerController::LeCreateCis(
    std::vector<bluetooth::hci::CreateCisConfig> cis_config) {
  return ErrorCode::SUCCESS;
}

void LinkLayerController::LeRemoveCig(uint8_t cig_id) {}

ErrorCode LinkLayerController::LeAcceptCisRequest(uint16_t handle) {
  return ErrorCode::SUCCESS;
}

void LinkLayerController::LeRejectCisRequest(uint16_t handle,
                                             ErrorCode reason) {}

ErrorCode LinkLayerController::LeCreateBig(
    uint8_t big_handle, uint8_t advertising_handle, uint8_t num_bis,
    uint32_t sdu_interval, uint16_t max_sdu, uint16_t max_transport_latency,
    uint8_t rtn, bluetooth::hci::SecondaryPhyType phy,
    bluetooth::hci::Packing packing, bluetooth::hci::Enable framing,
    bluetooth::hci::Enable encryption, std::vector<uint16_t> broadcast_code) {
  return ErrorCode::SUCCESS;
}

ErrorCode LinkLayerController::LeTerminateBig(uint8_t big_handle,
                                              ErrorCode reason) {
  return ErrorCode::SUCCESS;
}

ErrorCode LinkLayerController::LeBigCreateSync(
    uint8_t big_handle, uint16_t sync_handle, bluetooth::hci::Enable encryption,
    std::vector<uint16_t> broadcast_code, uint8_t mse,
    uint16_t big_syunc_timeout, std::vector<uint8_t> bis) {
  return ErrorCode::SUCCESS;
}

void LinkLayerController::LeBigTerminateSync(uint8_t big_handle) {}

ErrorCode LinkLayerController::LeRequestPeerSca(uint16_t request_handle) {
  return ErrorCode::SUCCESS;
}

void LinkLayerController::LeSetupIsoDataPath(
    uint16_t connection_handle,
    bluetooth::hci::DataPathDirection data_path_direction, uint8_t data_path_id,
    uint64_t codec_id, uint32_t controller_Delay,
    std::vector<uint8_t> codec_configuration) {}

void LinkLayerController::LeRemoveIsoDataPath(
    uint16_t connection_handle,
    bluetooth::hci::DataPathDirection data_path_direction) {}

void LinkLayerController::HandleLeEnableEncryption(
    uint16_t handle, std::array<uint8_t, 8> rand, uint16_t ediv,
    std::array<uint8_t, 16> ltk) {
+40 −0
Original line number Diff line number Diff line
@@ -165,6 +165,43 @@ class LinkLayerController {
  bool LeResolvingListFull();
  void LeSetPrivacyMode(uint8_t address_type, Address addr, uint8_t mode);

  void LeReadIsoTxSync(uint16_t handle);
  void LeSetCigParameters(
      uint8_t cig_id, uint32_t sdu_interval_m_to_s,
      uint32_t sdu_interval_s_to_m,
      bluetooth::hci::ClockAccuracy clock_accuracy,
      bluetooth::hci::Packing packing, bluetooth::hci::Enable framing,
      uint16_t max_transport_latency_m_to_s,
      uint16_t max_transport_latency_s_to_m,
      std::vector<bluetooth::hci::CisParametersConfig> cis_config);
  bluetooth::hci::ErrorCode LeCreateCis(
      std::vector<bluetooth::hci::CreateCisConfig> cis_config);
  void LeRemoveCig(uint8_t cig_id);
  bluetooth::hci::ErrorCode LeAcceptCisRequest(uint16_t handle);
  void LeRejectCisRequest(uint16_t handle, bluetooth::hci::ErrorCode reason);
  bluetooth::hci::ErrorCode LeCreateBig(
      uint8_t big_handle, uint8_t advertising_handle, uint8_t num_bis,
      uint32_t sdu_interval, uint16_t max_sdu, uint16_t max_transport_latency,
      uint8_t rtn, bluetooth::hci::SecondaryPhyType phy,
      bluetooth::hci::Packing packing, bluetooth::hci::Enable framing,
      bluetooth::hci::Enable encryption, std::vector<uint16_t> broadcast_code);
  bluetooth::hci::ErrorCode LeTerminateBig(uint8_t big_handle,
                                           bluetooth::hci::ErrorCode reason);
  bluetooth::hci::ErrorCode LeBigCreateSync(
      uint8_t big_handle, uint16_t sync_handle,
      bluetooth::hci::Enable encryption, std::vector<uint16_t> broadcast_code,
      uint8_t mse, uint16_t big_syunc_timeout, std::vector<uint8_t> bis);
  void LeBigTerminateSync(uint8_t big_handle);
  bluetooth::hci::ErrorCode LeRequestPeerSca(uint16_t request_handle);
  void LeSetupIsoDataPath(uint16_t connection_handle,
                          bluetooth::hci::DataPathDirection data_path_direction,
                          uint8_t data_path_id, uint64_t codec_id,
                          uint32_t controller_Delay,
                          std::vector<uint8_t> codec_configuration);
  void LeRemoveIsoDataPath(
      uint16_t connection_handle,
      bluetooth::hci::DataPathDirection data_path_direction);

  void HandleLeEnableEncryption(uint16_t handle, std::array<uint8_t, 8> rand,
                                uint16_t ediv, std::array<uint8_t, 16> ltk);

@@ -208,6 +245,9 @@ class LinkLayerController {
    le_address_type_ = le_address_type;
  }
  ErrorCode SetLeConnect(bool le_connect) {
    if (le_connect_ == le_connect) {
      return ErrorCode::COMMAND_DISALLOWED;
    }
    le_connect_ = le_connect;
    return ErrorCode::SUCCESS;
  }