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

Commit bdf803b2 authored by JaeMan Park's avatar JaeMan Park
Browse files

Fix handshaking error between HCI driver and rootcanal

Rootcanal needs to implement response of request
  READ_CLASS_OF_DEVICE
  READ_VOICE_SETTING
  WRITE_CONNECTION_ACCEPT_TIMEOUT

Bug: 180860482
Test: m root-canal
Change-Id: I53e67649c3558ea7d64e6521aa1a602b2245c942
parent a41cd707
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -283,6 +283,11 @@ DualModeController::DualModeController(const std::string& properties_filename, u
  // Testing Commands
  SET_SUPPORTED(READ_LOOPBACK_MODE, ReadLoopbackMode);
  SET_SUPPORTED(WRITE_LOOPBACK_MODE, WriteLoopbackMode);

  SET_SUPPORTED(READ_CLASS_OF_DEVICE, ReadClassOfDevice);
  SET_SUPPORTED(READ_VOICE_SETTING, ReadVoiceSetting);
  SET_SUPPORTED(READ_CONNECTION_ACCEPT_TIMEOUT, ReadConnectionAcceptTimeout);
  SET_SUPPORTED(WRITE_CONNECTION_ACCEPT_TIMEOUT, WriteConnectionAcceptTimeout);
#undef SET_HANDLER
#undef SET_SUPPORTED
  properties_.SetSupportedCommands(supported_commands);
@@ -1308,6 +1313,9 @@ void DualModeController::RefreshEncryptionKey(CommandView command) {
void DualModeController::WriteVoiceSetting(CommandView command) {
  auto command_view = gd_hci::WriteVoiceSettingView::Create(command);
  ASSERT(command_view.IsValid());

  properties_.SetVoiceSetting(command_view.GetVoiceSetting());

  auto packet = bluetooth::hci::WriteVoiceSettingCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS);
  send_event_(std::move(packet));
@@ -2442,6 +2450,52 @@ void DualModeController::LeLongTermKeyRequestNegativeReply(
          kNumCommandPackets, status, handle));
}

void DualModeController::ReadClassOfDevice(CommandView command) {
  auto command_view = gd_hci::ReadClassOfDeviceView::Create(
      gd_hci::DiscoveryCommandView::Create(command));
  ASSERT(command_view.IsValid());

  auto packet = bluetooth::hci::ReadClassOfDeviceCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS, properties_.GetClassOfDevice());
  send_event_(std::move(packet));
}

void DualModeController::ReadVoiceSetting(CommandView command) {
  auto command_view = gd_hci::ReadVoiceSettingView::Create(command);
  ASSERT(command_view.IsValid());

  auto packet = bluetooth::hci::ReadVoiceSettingCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS, properties_.GetVoiceSetting());
  send_event_(std::move(packet));
}

void DualModeController::ReadConnectionAcceptTimeout(CommandView command) {
  auto command_view = gd_hci::ReadConnectionAcceptTimeoutView::Create(
      gd_hci::ConnectionManagementCommandView::Create(
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  auto packet =
      bluetooth::hci::ReadConnectionAcceptTimeoutCompleteBuilder::Create(
          kNumCommandPackets, ErrorCode::SUCCESS,
          properties_.GetConnectionAcceptTimeout());
  send_event_(std::move(packet));
}

void DualModeController::WriteConnectionAcceptTimeout(CommandView command) {
  auto command_view = gd_hci::WriteConnectionAcceptTimeoutView::Create(
      gd_hci::ConnectionManagementCommandView::Create(
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  properties_.SetConnectionAcceptTimeout(command_view.GetConnAcceptTimeout());

  auto packet =
      bluetooth::hci::WriteConnectionAcceptTimeoutCompleteBuilder::Create(
          kNumCommandPackets, ErrorCode::SUCCESS);
  send_event_(std::move(packet));
}

void DualModeController::ReadLoopbackMode(CommandView command) {
  auto command_view = gd_hci::ReadLoopbackModeView::Create(command);
  ASSERT(command_view.IsValid());
+6 −0
Original line number Diff line number Diff line
@@ -543,6 +543,12 @@ class DualModeController : public Device {
  void LeAdvertisingFilter(CommandView args);
  void LeExtendedScanParams(CommandView args);

  // Required commands for handshaking with hci driver
  void ReadClassOfDevice(CommandView args);
  void ReadVoiceSetting(CommandView args);
  void ReadConnectionAcceptTimeout(CommandView args);
  void WriteConnectionAcceptTimeout(CommandView args);

  void SetTimerPeriod(std::chrono::milliseconds new_period);
  void StartTimer();
  void StopTimer();
+16 −0
Original line number Diff line number Diff line
@@ -109,6 +109,20 @@ class DeviceProperties {

  uint8_t GetEncryptionKeySize() const { return encryption_key_size_; }

  uint16_t GetVoiceSetting() const { return voice_setting_; }

  void SetVoiceSetting(uint16_t voice_setting) {
    voice_setting_ = voice_setting;
  }

  uint16_t GetConnectionAcceptTimeout() const {
    return connection_accept_timeout_;
  }

  void SetConnectionAcceptTimeout(uint16_t connection_accept_timeout) {
    connection_accept_timeout_ = connection_accept_timeout;
  }

  uint16_t GetTotalNumAclDataPackets() const {
    return num_acl_data_packets_;
  }
@@ -371,6 +385,8 @@ class DeviceProperties {
  uint8_t page_scan_repetition_mode_{};
  uint16_t clock_offset_{};
  uint8_t encryption_key_size_{10};
  uint16_t voice_setting_{0x0060};
  uint16_t connection_accept_timeout_{0x7d00};

  // Low Energy
  uint16_t le_data_packet_length_;