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

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

Merge "RootCanal: Implement a quirk to send an Hardware Error event in case a...

Merge "RootCanal: Implement a quirk to send an Hardware Error event in case a command is received before HCI Reset"
parents b78886ed eca3f6e8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ message ControllerQuirks {
  // Send the Role Change event before the Connection Complete event
  // in the case where a role switch is initiated at connection establishment.
  optional bool send_role_change_before_connection_complete = 3;
  // Send an Hardware Error event if any command is called before HCI Reset.
  optional bool hardware_error_before_reset = 4;
}

message Controller {
+4 −0
Original line number Diff line number Diff line
@@ -1875,6 +1875,10 @@ ControllerProperties::ControllerProperties(
      quirks.has_default_random_address =
          config.quirks().has_default_random_address();
    }
    if (config.quirks().has_hardware_error_before_reset()) {
      quirks.hardware_error_before_reset =
          config.quirks().hardware_error_before_reset();
    }
    // TODO(b/270606199): support send_acl_data_before_connection_complete
    // TODO(b/274476773): support send_role_change_before_connection_complete
  }
+9 −0
Original line number Diff line number Diff line
@@ -40,6 +40,15 @@ struct ControllerQuirks {
  // to bypass this validation. The default random address will
  // be ba:db:ad:ba:db:ad.
  bool has_default_random_address{false};

  // This quirks configures the controller to send an Hardware Error event
  // in case a command is received before the HCI Reset command.
  //
  // Receiving a different command is indicative of the emulator being
  // started from a snapshot. In this case the controller state is lost
  // but the Host stack is loaded post-initialization. This quirk
  // ensures that the stack will reset itself after reloading.
  bool hardware_error_before_reset{false};
};

// Local controller information.
+10 −0
Original line number Diff line number Diff line
@@ -189,6 +189,15 @@ void DualModeController::HandleCommand(
    send_event_(bluetooth::hci::LoopbackCommandBuilder::Create(
        std::move(raw_builder_ptr)));
  }
  // Quirk to reset the host stack when a command is received before the Hci
  // Reset command.
  else if (properties_.quirks.hardware_error_before_reset &&
           !controller_reset_ &&
           op_code != OpCode::RESET) {
    LOG_WARN("Received command %s before HCI Reset; sending the Hardware"
             " Error event", OpCodeText(op_code).c_str());
    send_event_(bluetooth::hci::HardwareErrorBuilder::Create(0x42));
  }
  // Command is both supported and implemented.
  // Invoke the registered handler.
  else if (is_supported_command && is_implemented_command) {
@@ -276,6 +285,7 @@ void DualModeController::Reset(CommandView command) {
    loopback_mode_ = LoopbackMode::NO_LOOPBACK;
  }

  controller_reset_ = true;
  send_event_(bluetooth::hci::ResetCompleteBuilder::Create(kNumCommandPackets,
                                                           ErrorCode::SUCCESS));
}
+4 −0
Original line number Diff line number Diff line
@@ -602,6 +602,10 @@ class DualModeController : public Device {
  // with RootCanal.
  bluetooth::hci::LoopbackMode loopback_mode_{LoopbackMode::NO_LOOPBACK};

  // Flag set to true after the HCI Reset command has been received
  // the first time.
  bool controller_reset_{false};

  // Map command opcodes to the corresponding bit index in the
  // supported command mask.
  static const std::unordered_map<OpCode, OpCodeIndex>