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

Commit 2d7b8cf2 authored by Chienyuan's avatar Chienyuan
Browse files

RootCanal: Gracefully handle HCI Event

* remove obsoleted function for EventPacketBuilder
* prevent to use raw_packet_builder
* add constant for num_hci_command_packets

Bug: 140386699
Test: run_cert.sh
Change-Id: I4b499a434520cedb05e0cf9115e7a5814a9b8912
parent fa681f3f
Loading
Loading
Loading
Loading
+299 −210

File changed.

Preview size limit exceeded, changes collapsed.

+1 −15
Original line number Diff line number Diff line
@@ -281,7 +281,7 @@ class DualModeController : public Device {
  void HciWriteLeHostSupport(packets::PacketView<true> args);

  // 7.3.92
  void HciWriteSecureConnectionHostSupport(packets::PacketView<true> args);
  void HciWriteSecureConnectionsHostSupport(packets::PacketView<true> args);

  // Informational Parameters Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4
@@ -427,22 +427,8 @@ class DualModeController : public Device {
  // Creates a command complete event and sends it back to the HCI.
  void SendCommandComplete(hci::OpCode command_opcode, const std::vector<uint8_t>& return_parameters) const;

  // Sends a command complete event with no return parameters.
  void SendCommandCompleteSuccess(bluetooth::hci::OpCode command_opcode) const;

  void SendCommandCompleteUnknownOpCodeEvent(uint16_t command_opcode) const;

  // Sends a command complete event with no return parameters.
  void SendCommandCompleteOnlyStatus(bluetooth::hci::OpCode command_opcode,
                                     bluetooth::hci::ErrorCode status) const;

  // Creates a command status event and sends it back to the HCI.
  void SendCommandStatus(bluetooth::hci::ErrorCode status,
                         bluetooth::hci::OpCode command_opcode) const;

  // Sends a command status event with default event parameters.
  void SendCommandStatusSuccess(bluetooth::hci::OpCode command_opcode) const;

  // Callbacks to send packets back to the HCI.
  std::function<void(std::shared_ptr<std::vector<uint8_t>>)> send_acl_;
  std::function<void(std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>
+10 −10
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ using namespace test_vendor_lib::packets;

namespace test_vendor_lib {

constexpr uint16_t kNumCommandPackets = 0x01;

// TODO: Model Rssi?
static uint8_t GetRssi() {
  static uint8_t rssi = 0;
@@ -109,15 +111,13 @@ hci::Status LinkLayerController::SendAclToRemote(AclPacketView acl_packet) {
           static_cast<int>(acl_packet.size()));

  ScheduleTask(milliseconds(5), [this, handle]() {
    std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
        std::make_unique<bluetooth::packet::RawBuilder>();
    raw_builder_ptr->AddOctets1(0x01);
    raw_builder_ptr->AddOctets2(handle);
    raw_builder_ptr->AddOctets2(0x01);

    auto packet = bluetooth::hci::EventPacketBuilder::Create(
        bluetooth::hci::EventCode::NUMBER_OF_COMPLETED_PACKETS,
        std::move(raw_builder_ptr));
    std::vector<bluetooth::hci::CompletedPackets> completed_packets;
    bluetooth::hci::CompletedPackets cp;
    cp.connection_handle_ = handle;
    cp.host_num_of_completed_packets_ = kNumCommandPackets;
    completed_packets.push_back(cp);
    auto packet = bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(
        completed_packets);
    send_event_(std::move(packet));
  });

@@ -473,7 +473,7 @@ void LinkLayerController::IncomingInquiryResponsePacket(

      std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
          std::make_unique<bluetooth::packet::RawBuilder>();
      raw_builder_ptr->AddOctets1(0x01);  // num_responses
      raw_builder_ptr->AddOctets1(kNumCommandPackets);
      raw_builder_ptr->AddAddress(inquiry_response.GetSourceAddress());
      raw_builder_ptr->AddOctets1(inquiry_response.GetPageScanRepetitionMode());
      raw_builder_ptr->AddOctets1(0x00);  // _reserved_