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

Commit 6082680b authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Register an handler for invalid packets in DualModeController

The handle (currently unused) will be used to report invalid HCI packets
to external trackers. Invalid packets include incorrectly formatted
(or incorrectly parsed..) packets, but also packets that trigger
unimplemented behavior in the controller implementation.

The handler reports four parameters:
  - controller instance ID
  - numeric reason code
  - reason string
  - packet bytes

Test: m root-canal
Flags: EXEMPT, tool change
Bug: 323226412
Change-Id: Ic3494867c791a7acb67340b0d0b3f8a66d7509cd
parent 5c664cbc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -237,6 +237,13 @@ void DualModeController::HandleCommand(
  }
}

void DualModeController::RegisterInvalidPacketHandler(
    std::function<void(uint32_t, InvalidPacketReason, std::string,
                       std::vector<uint8_t> const&)>& handler) {
  INFO(id_, "updating the invalid packet handler");
  invalid_packet_handler_ = handler;
}

void DualModeController::RegisterEventChannel(
    const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>&
        send_event) {
+19 −0
Original line number Diff line number Diff line
@@ -40,6 +40,13 @@ namespace rootcanal {
using ::bluetooth::hci::Address;
using ::bluetooth::hci::CommandView;

// List of reject reasons for invalid packets.
enum InvalidPacketReason {
  kUnknown = 0,
  kParseError = 1,
  kUnsupported = 2,
};

// Emulates a dual mode BR/EDR + LE controller by maintaining the link layer
// state machine detailed in the Bluetooth Core Specification Version 4.2,
// Volume 6, Part B, Section 1.1 (page 30). Provides methods corresponding to
@@ -78,6 +85,13 @@ class DualModeController : public Device {
  void HandleSco(std::shared_ptr<std::vector<uint8_t>> sco_packet);
  void HandleIso(std::shared_ptr<std::vector<uint8_t>> iso_packet);

  /// Report invalid packets received for this controller instance
  /// to an external tracker. Packets are rejected if they failed to
  /// be parsed, or run into an unimplemented part of the controller.
  void RegisterInvalidPacketHandler(
      std::function<void(uint32_t, InvalidPacketReason, std::string,
                         std::vector<uint8_t> const&)>& handler);

  // Set the callbacks for sending packets to the HCI.
  void RegisterEventChannel(
      const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>&
@@ -546,6 +560,11 @@ class DualModeController : public Device {
  std::function<void(std::shared_ptr<bluetooth::hci::ScoBuilder>)> send_sco_;
  std::function<void(std::shared_ptr<bluetooth::hci::IsoBuilder>)> send_iso_;

  // Report invalid packets received on this controller instance.
  std::function<void(uint32_t, InvalidPacketReason, std::string,
                     std::vector<uint8_t> const&)>
      invalid_packet_handler_;

  // Loopback mode (Vol 4, Part E § 7.6.1).
  // The local loopback mode is used to pass the android Vendor Test Suite
  // with RootCanal.