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

Commit e293c192 authored by Henri Chataing's avatar Henri Chataing Committed by Thomas Girardier
Browse files

RootCanal: Remove unecessary std::move in DualModeController

- Add definition of SetEventMaskPage2 in hci_packets.pdl
- Use generated class for SetResolvablePrivateAddressTimeout
- Remove unecessary validation of LeIsoCommand views

Bug: 245578454
Test: m root-canal
Ignore-AOSP-First: Cherry-picked from AOSP
Merged-In: I223c9f56839a734f6b11e37a7ae3417ef9c25153
Change-Id: I223c9f56839a734f6b11e37a7ae3417ef9c25153
parent e3cc57a8
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2430,6 +2430,14 @@ packet SendKeypressNotificationComplete : CommandComplete (command_op_code = SEN
  bd_addr : Address,
}

packet SetEventMaskPage2 : Command (op_code = SET_EVENT_MASK_PAGE_2) {
  event_mask_page_2: 64,
}

packet SetEventMaskPage2Complete : CommandComplete (command_op_code = SET_EVENT_MASK_PAGE_2) {
  status: ErrorCode,
}

packet ReadLeHostSupport : Command (op_code = READ_LE_HOST_SUPPORT) {
}

+45 −66
Original line number Diff line number Diff line
@@ -303,7 +303,7 @@ DualModeController::DualModeController(const std::string& properties_filename,
  SET_SUPPORTED(WRITE_CONNECTION_ACCEPT_TIMEOUT, WriteConnectionAcceptTimeout);
  SET_SUPPORTED(LE_SET_ADDRESS_RESOLUTION_ENABLE, LeSetAddressResolutionEnable);
  SET_SUPPORTED(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT,
                LeSetResovalablePrivateAddressTimeout);
                LeSetResolvablePrivateAddressTimeout);
  SET_SUPPORTED(READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE,
                ReadSynchronousFlowControlEnable);
  SET_SUPPORTED(WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE,
@@ -372,9 +372,9 @@ void DualModeController::HandleSco(
  if (loopback_mode_ == LoopbackMode::ENABLE_LOCAL) {
    uint16_t handle = sco_packet.GetHandle();

    auto sco_builder = bluetooth::hci::ScoBuilder::Create(
        handle, sco_packet.GetPacketStatusFlag(), sco_packet.GetData());
    send_sco_(std::move(sco_builder));
    send_sco_(bluetooth::hci::ScoBuilder::Create(
        handle, sco_packet.GetPacketStatusFlag(), sco_packet.GetData()));

    std::vector<bluetooth::hci::CompletedPackets> completed_packets;
    bluetooth::hci::CompletedPackets cp;
    cp.connection_handle_ = handle;
@@ -1260,11 +1260,11 @@ void DualModeController::EnhancedFlush(CommandView command) {
}

void DualModeController::SetEventMaskPage2(CommandView command) {
  auto payload =
      std::make_unique<bluetooth::packet::RawBuilder>(std::vector<uint8_t>(
          {static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS)}));
  send_event_(bluetooth::hci::CommandCompleteBuilder::Create(
      kNumCommandPackets, command.GetOpCode(), std::move(payload)));
  auto command_view = bluetooth::hci::SetEventMaskPage2View::Create(command);
  ASSERT(command_view.IsValid());
  link_layer_controller_.SetEventMaskPage2(command_view.GetEventMaskPage2());
  send_event_(bluetooth::hci::SetEventMaskPage2CompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS));
}

void DualModeController::ReadLocalOobData(CommandView command) {
@@ -1301,7 +1301,6 @@ void DualModeController::ChangeConnectionPacketType(CommandView command) {

  auto status =
      link_layer_controller_.ChangeConnectionPacketType(handle, packet_type);

  send_event_(bluetooth::hci::ChangeConnectionPacketTypeStatusBuilder::Create(
      status, kNumCommandPackets));
}
@@ -2040,14 +2039,18 @@ void DualModeController::LeSetAddressResolutionEnable(CommandView command) {
          kNumCommandPackets, status));
}

void DualModeController::LeSetResovalablePrivateAddressTimeout(
void DualModeController::LeSetResolvablePrivateAddressTimeout(
    CommandView command) {
  // NOP
  auto payload =
      std::make_unique<bluetooth::packet::RawBuilder>(std::vector<uint8_t>(
          {static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS)}));
  send_event_(bluetooth::hci::CommandCompleteBuilder::Create(
      kNumCommandPackets, command.GetOpCode(), std::move(payload)));
  auto command_view =
      bluetooth::hci::LeSetResolvablePrivateAddressTimeoutView::Create(
          bluetooth::hci::LeSecurityCommandView::Create(command));
  ASSERT(command_view.IsValid());
  ErrorCode status =
      link_layer_controller_.LeSetResolvablePrivateAddressTimeout(
          command_view.GetRpaTimeout());
  send_event_(
      bluetooth::hci::LeSetResolvablePrivateAddressTimeoutCompleteBuilder::
          Create(kNumCommandPackets, status));
}

void DualModeController::LeReadLocalSupportedFeatures(CommandView command) {
@@ -2453,19 +2456,15 @@ void DualModeController::LeSetPrivacyMode(CommandView command) {
}

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

void DualModeController::LeSetCigParameters(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeSetCigParametersView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeSetCigParametersView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeSetCigParameters(
      command_view.GetCigId(), command_view.GetSduIntervalMToS(),
@@ -2476,10 +2475,8 @@ void DualModeController::LeSetCigParameters(CommandView command) {
}

void DualModeController::LeCreateCis(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeCreateCisView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeCreateCisView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  ErrorCode status =
      link_layer_controller_.LeCreateCis(command_view.GetCisConfig());
@@ -2488,10 +2485,8 @@ void DualModeController::LeCreateCis(CommandView command) {
}

void DualModeController::LeRemoveCig(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeRemoveCigView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeRemoveCigView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  uint8_t cig = command_view.GetCigId();
  ErrorCode status = link_layer_controller_.LeRemoveCig(cig);
@@ -2500,10 +2495,8 @@ void DualModeController::LeRemoveCig(CommandView command) {
}

void DualModeController::LeAcceptCisRequest(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeAcceptCisRequestView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeAcceptCisRequestView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeAcceptCisRequest(
      command_view.GetConnectionHandle());
@@ -2512,20 +2505,16 @@ void DualModeController::LeAcceptCisRequest(CommandView command) {
}

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

void DualModeController::LeCreateBig(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeCreateBigView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeCreateBigView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeCreateBig(
      command_view.GetBigHandle(), command_view.GetAdvertisingHandle(),
@@ -2539,10 +2528,8 @@ void DualModeController::LeCreateBig(CommandView command) {
}

void DualModeController::LeTerminateBig(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeTerminateBigView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeTerminateBigView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeTerminateBig(
      command_view.GetBigHandle(), command_view.GetReason());
@@ -2551,10 +2538,8 @@ void DualModeController::LeTerminateBig(CommandView command) {
}

void DualModeController::LeBigCreateSync(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeBigCreateSyncView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeBigCreateSyncView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeBigCreateSync(
      command_view.GetBigHandle(), command_view.GetSyncHandle(),
@@ -2566,16 +2551,14 @@ void DualModeController::LeBigCreateSync(CommandView command) {
}

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

void DualModeController::LeRequestPeerSca(CommandView command) {
  auto command_view = gd_hci::LeRequestPeerScaView::Create(std::move(command));
  auto command_view = gd_hci::LeRequestPeerScaView::Create(command);
  ASSERT(command_view.IsValid());
  ErrorCode status = link_layer_controller_.LeRequestPeerSca(
      command_view.GetConnectionHandle());
@@ -2584,10 +2567,8 @@ void DualModeController::LeRequestPeerSca(CommandView command) {
}

void DualModeController::LeSetupIsoDataPath(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeSetupIsoDataPathView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeSetupIsoDataPathView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeSetupIsoDataPath(
      command_view.GetConnectionHandle(), command_view.GetDataPathDirection(),
@@ -2596,10 +2577,8 @@ void DualModeController::LeSetupIsoDataPath(CommandView command) {
}

void DualModeController::LeRemoveIsoDataPath(CommandView command) {
  auto iso_command_view = gd_hci::LeIsoCommandView::Create(command);
  ASSERT(iso_command_view.IsValid());
  auto command_view =
      gd_hci::LeRemoveIsoDataPathView::Create(std::move(iso_command_view));
  auto command_view = gd_hci::LeRemoveIsoDataPathView::Create(
      gd_hci::LeIsoCommandView::Create(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeRemoveIsoDataPath(
      command_view.GetConnectionHandle(),
+1 −1
Original line number Diff line number Diff line
@@ -531,7 +531,7 @@ class DualModeController : public Device {
  void LeSetAddressResolutionEnable(CommandView args);

  // 7.8.45
  void LeSetResovalablePrivateAddressTimeout(CommandView args);
  void LeSetResolvablePrivateAddressTimeout(CommandView args);

  // 7.8.46
  void LeReadMaximumDataLength(CommandView args);
+16 −0
Original line number Diff line number Diff line
@@ -254,6 +254,22 @@ ErrorCode LinkLayerController::LeSetRandomAddress(Address random_address) {
  return ErrorCode::SUCCESS;
}

// HCI LE Set Host Feature command (Vol 4, Part E § 7.8.45).
ErrorCode LinkLayerController::LeSetResolvablePrivateAddressTimeout(
    uint16_t rpa_timeout) {
  // Note: no documented status code for this case.
  if (rpa_timeout < 0x1 || rpa_timeout > 0x0e10) {
    LOG_INFO(
        "rpa_timeout (0x%04x) is outside the range of supported values "
        " 0x1 - 0x0e10",
        rpa_timeout);
    return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS;
  }

  resolvable_private_address_timeout_ = seconds(rpa_timeout);
  return ErrorCode::SUCCESS;
}

// HCI LE Set Host Feature command (Vol 4, Part E § 7.8.115).
ErrorCode LinkLayerController::LeSetHostFeature(uint8_t bit_number,
                                                uint8_t bit_value) {
+13 −0
Original line number Diff line number Diff line
@@ -364,6 +364,10 @@ class LinkLayerController {
  // HCI LE Set Random Address command (Vol 4, Part E § 7.8.4).
  ErrorCode LeSetRandomAddress(Address random_address);

  // HCI LE Set Resolvable Private Address Timeout command
  // (Vol 4, Part E § 7.8.45).
  ErrorCode LeSetResolvablePrivateAddressTimeout(uint16_t rpa_timeout);

  // HCI LE Set Host Feature command (Vol 4, Part E § 7.8.115).
  ErrorCode LeSetHostFeature(uint8_t bit_number, uint8_t bit_value);

@@ -714,6 +718,10 @@ class LinkLayerController {
    voice_setting_ = voice_setting;
  }
  void SetEventMask(uint64_t event_mask) { event_mask_ = event_mask; }

  void SetEventMaskPage2(uint64_t event_mask) {
    event_mask_page_2_ = event_mask;
  }
  void SetLeEventMask(uint64_t le_event_mask) {
    le_event_mask_ = le_event_mask;
  }
@@ -834,14 +842,19 @@ class LinkLayerController {
  uint8_t min_encryption_key_size_{16};

  // Event Mask (Vol 4, Part E § 7.3.1) and
  // Event Mask Page 2 (Vol 4, Part E § 7.3.69) and
  // LE Event Mask (Vol 4, Part E § 7.8.1).
  uint64_t event_mask_{0x00001fffffffffff};
  uint64_t event_mask_page_2_{0x0};
  uint64_t le_event_mask_{0x01f};

  // Suggested Default Data Length (Vol 4, Part E § 7.8.34).
  uint16_t le_suggested_max_tx_octets_{0x001b};
  uint16_t le_suggested_max_tx_time_{0x0148};

  // Resolvable Private Address Timeout (Vol 4, Part E § 7.8.45).
  std::chrono::seconds resolvable_private_address_timeout_{0x0384};

  // Page Scan Repetition Mode (Vol 2 Part B § 8.3.1 Page Scan substate).
  // The Page Scan Repetition Mode depends on the selected Page Scan Interval.
  PageScanRepetitionMode page_scan_repetition_mode_{PageScanRepetitionMode::R0};