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

Commit 5494a714 authored by Myles Watson's avatar Myles Watson Committed by Hansong Zhang
Browse files

HAL: Add unregisterIncomingPacketCallback

Test: bluetooth_test_gd
Change-Id: I17f8227c351451b4249c2a005ea4428ace734dc9
parent fe1a69e2
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -63,16 +63,16 @@ class HciHal : public ::bluetooth::Module {
  virtual ~HciHal() = default;

  // Register the callback for incoming packets. All incoming packets are dropped before
  // this callback is registered. Callback can only be registered once, but will be reset
  // after close().
  //
  // Call this function before initialize() to guarantee all incoming packets are received.
  // this callback is registered. Callback can only be registered once.
  //
  // @param callback implements BluetoothHciHalCallbacks which will
  //    receive callbacks when incoming HCI packets are received
  //    from the controller to be sent to the host.
  virtual void registerIncomingPacketCallback(HciHalCallbacks* callback) = 0;

  // Unregister the callback for incoming packets. Drop all further incoming packets.
  virtual void unregisterIncomingPacketCallback() = 0;

  // Send an HCI command (as specified in the Bluetooth Specification
  // V4.2, Vol 2, Part 5, Section 5.4.1) to the Bluetooth controller.
  // Commands must be executed in order.
+4 −0
Original line number Diff line number Diff line
@@ -120,6 +120,10 @@ class HciHalHidl : public HciHal {
    callbacks_->SetCallback(callback);
  }

  void unregisterIncomingPacketCallback() override {
    callbacks_->ResetCallback();
  }

  void sendHciCommand(HciPacket command) override {
    btsnoop_logger_->capture(command, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    bt_hci_->sendHciCommand(command);
+9 −1
Original line number Diff line number Diff line
@@ -96,6 +96,11 @@ class HciHalHostRootcanal : public HciHal {
    incoming_packet_callback_ = callback;
  }

  void unregisterIncomingPacketCallback() override {
    std::lock_guard<std::mutex> lock(mutex_);
    incoming_packet_callback_ = nullptr;
  }

  void sendHciCommand(HciPacket command) override {
    std::lock_guard<std::mutex> lock(mutex_);
    ASSERT(sock_fd_ != INVALID_FD);
@@ -190,7 +195,10 @@ class HciHalHostRootcanal : public HciHal {
  }

  void incoming_packet_received() {
    ASSERT(incoming_packet_callback_ != nullptr);
    if (incoming_packet_callback_ == nullptr) {
      LOG_INFO("Dropping a packet");
      return;
    }

    uint8_t buf[kBufSize] = {};

+1 −0
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ class HciHalRootcanalTest : public ::testing::Test {
  }

  void TearDown() override {
    hal_->unregisterIncomingPacketCallback();
    fake_registry_.StopAll();
    close(fake_server_socket_);
    delete fake_server_;
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ struct HciLayer::impl : public hal::HciHalCallbacks {
  }

  void Stop() {
    hal_->unregisterIncomingPacketCallback();
    acl_queue_.GetDownEnd()->UnregisterDequeue();
    delete hci_timeout_alarm_;
    command_queue_.clear();
Loading