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

Commit a39e2c61 authored by Myles Watson's avatar Myles Watson
Browse files

Revert "GD HCI: Support vendor specific event in GD"

This reverts commit 464efded.

Bug: 183057550
Test: Enable BQR events
Tag: #gd-refactor
Change-Id: Ibb9302ae6bb9495880174a1ed8c6457a1e781027
parent ee13091d
Loading
Loading
Loading
Loading
+1 −39
Original line number Diff line number Diff line
@@ -245,20 +245,6 @@ struct HciLayer::impl {
    subevent_handlers_.erase(subevent_handlers_.find(event));
  }

  void register_vendor_specific_event(
      VseSubeventCode vse_subevent_code, ContextualCallback<void(VendorSpecificEventView)> event_handler) {
    ASSERT_LOG(
        vendor_specific_event_handlers_.count(vse_subevent_code) == 0,
        "Can not register a second handler for %02hhx (%s)",
        vse_subevent_code,
        VseSubeventCodeText(vse_subevent_code).c_str());
    vendor_specific_event_handlers_[vse_subevent_code] = event_handler;
  }

  void unregister_vendor_specific_event(VseSubeventCode vse_subevent_code) {
    vendor_specific_event_handlers_.erase(vendor_specific_event_handlers_.find(vse_subevent_code));
  }

  void on_hci_event(EventView event) {
    ASSERT(event.IsValid());
    EventCode event_code = event.GetEventCode();
@@ -282,20 +268,6 @@ struct HciLayer::impl {
    subevent_handlers_[subevent_code].Invoke(meta_event_view);
  }

  void on_vendor_specific_event(EventView event) {
    VendorSpecificEventView vendor_specific_event_view = VendorSpecificEventView::Create(event);
    ASSERT(vendor_specific_event_view.IsValid());
    VseSubeventCode vse_subevent_code = vendor_specific_event_view.GetSubeventCode();
    if (vendor_specific_event_handlers_.find(vse_subevent_code) == vendor_specific_event_handlers_.end()) {
      LOG_ERROR(
          "Unhandled vendor specific event of type 0x%02hhx (%s)",
          vse_subevent_code,
          VseSubeventCodeText(vse_subevent_code).c_str());
      return;
    }
    vendor_specific_event_handlers_[vse_subevent_code].Invoke(vendor_specific_event_view);
  }

  hal::HciHal* hal_;
  HciLayer& module_;

@@ -304,7 +276,6 @@ struct HciLayer::impl {

  std::map<EventCode, ContextualCallback<void(EventView)>> event_handlers_;
  std::map<SubeventCode, ContextualCallback<void(LeMetaEventView)>> subevent_handlers_;
  std::map<VseSubeventCode, ContextualCallback<void(VendorSpecificEventView)>> vendor_specific_event_handlers_;
  OpCode waiting_command_{OpCode::NONE};
  uint8_t command_credits_{1};  // Send reset first
  Alarm* hci_timeout_alarm_{nullptr};
@@ -391,15 +362,6 @@ void HciLayer::UnregisterLeEventHandler(SubeventCode event) {
  CallOn(impl_, &impl::unregister_le_event, event);
}

void HciLayer::RegisterVendorSpecificEventHandler(
    VseSubeventCode vse_subevent_code, common::ContextualCallback<void(VendorSpecificEventView)> event_handler) {
  CallOn(impl_, &impl::register_vendor_specific_event, vse_subevent_code, event_handler);
}

void HciLayer::UnregisterVendorSpecificEventHandler(VseSubeventCode vse_subevent_code) {
  CallOn(impl_, &impl::unregister_vendor_specific_event, vse_subevent_code);
}

void HciLayer::on_disconnection_complete(EventView event_view) {
  auto disconnection_view = DisconnectionCompleteView::Create(event_view);
  if (!disconnection_view.IsValid()) {
@@ -526,7 +488,7 @@ void HciLayer::Start() {
  auto drop_packet = handler->BindOn(impl_, &impl::drop);
  RegisterEventHandler(EventCode::PAGE_SCAN_REPETITION_MODE_CHANGE, drop_packet);
  RegisterEventHandler(EventCode::MAX_SLOTS_CHANGE, drop_packet);
  RegisterEventHandler(EventCode::VENDOR_SPECIFIC, handler->BindOn(impl_, &impl::on_vendor_specific_event));
  RegisterEventHandler(EventCode::VENDOR_SPECIFIC, drop_packet);

  EnqueueCommand(ResetBuilder::Create(), handler->BindOnce(&fail_if_reset_complete_not_success));
  hal->registerIncomingPacketCallback(hal_callbacks_);
+0 −5
Original line number Diff line number Diff line
@@ -67,11 +67,6 @@ class HciLayer : public Module, public CommandInterface<CommandBuilder> {

  virtual void UnregisterLeEventHandler(SubeventCode subevent_code);

  virtual void RegisterVendorSpecificEventHandler(
      VseSubeventCode vse_subevent_code, common::ContextualCallback<void(VendorSpecificEventView)> event_handler);

  virtual void UnregisterVendorSpecificEventHandler(VseSubeventCode vse_subevent_code);

  virtual SecurityInterface* GetSecurityInterface(common::ContextualCallback<void(EventView)> event_handler);

  virtual LeSecurityInterface* GetLeSecurityInterface(common::ContextualCallback<void(LeMetaEventView)> event_handler);
+0 −96
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#include "hci/hci_layer.h"

#include <gtest/gtest.h>

#include <list>
#include <memory>

@@ -270,15 +269,6 @@ class DependsOnHci : public Module {
    return packetview;
  }

  void RegisterVendorSpecificEvent(VseSubeventCode event) {
    hci_->RegisterVendorSpecificEventHandler(
        event, GetHandler()->BindOn(this, &DependsOnHci::handle_event<VendorSpecificEventView>));
  }

  void UnregisterVendorSpecificEvent(VseSubeventCode event) {
    hci_->UnregisterVendorSpecificEventHandler(event);
  }

  void Start() {
    hci_ = GetDependency<HciLayer>();
    hci_->RegisterEventHandler(
@@ -459,92 +449,6 @@ TEST_F(HciTest, leMetaEvent) {
  ASSERT_TRUE(LeConnectionCompleteView::Create(LeMetaEventView::Create(EventView::Create(event))).IsValid());
}

TEST_F(HciTest, vendorSpecificEventRegistration) {
  auto event_future = upper->GetReceivedEventFuture();

  upper->RegisterVendorSpecificEvent(VseSubeventCode::BQR_EVENT);

  // Send a vendor specific event
  hal->callbacks->hciEventReceived(GetPacketBytes(BqrLinkQualityEventBuilder::Create(
      QualityReportId::A2DP_AUDIO_CHOPPY,
      BqrPacketType::TYPE_2DH1,
      /* handle */ 0x123,
      Role::CENTRAL,
      /* TX_Power_Level */ 0x05,
      /* RSSI */ 65,
      /* SNR */ 30,
      /* Unused_AFH_Channel_Count */ 0,
      /* AFH_Select_Unideal_Channel_Count */ 0,
      /* LSTO */ 12,
      /* Connection_Piconet_Clock */ 42,
      /* Retransmission_Count */ 1,
      /* No_RX_Count */ 1,
      /* NAK_Count */ 1,
      /* Last_TX_ACK_Timestamp */ 123456,
      /* Flow_Off_Count */ 78910,
      /* Last_Flow_On_Timestamp */ 123457,
      /* Buffer_Overflow_Bytes */ 42,
      /* Buffer_Underflow_Bytes */ 24,
      /* Vendor Specific Parameter */ std::make_unique<RawBuilder>())));

  // Wait for the event
  auto event_status = event_future.wait_for(kTimeout);
  ASSERT_EQ(event_status, std::future_status::ready);

  auto event = upper->GetReceivedEvent();
  ASSERT_TRUE(
      BqrLinkQualityEventView::Create(BqrEventView::Create(VendorSpecificEventView::Create(EventView::Create(event))))
          .IsValid());

  // Now test if we can unregister the vendor specific event handler
  event_future = upper->GetReceivedEventFuture();

  upper->UnregisterVendorSpecificEvent(VseSubeventCode::BQR_EVENT);

  hal->callbacks->hciEventReceived(GetPacketBytes(BqrLinkQualityEventBuilder::Create(
      QualityReportId::A2DP_AUDIO_CHOPPY,
      BqrPacketType::TYPE_2DH1,
      /* handle */ 0x123,
      Role::CENTRAL,
      /* TX_Power_Level */ 0x05,
      /* RSSI */ 65,
      /* SNR */ 30,
      /* Unused_AFH_Channel_Count */ 0,
      /* AFH_Select_Unideal_Channel_Count */ 0,
      /* LSTO */ 12,
      /* Connection_Piconet_Clock */ 42,
      /* Retransmission_Count */ 1,
      /* No_RX_Count */ 1,
      /* NAK_Count */ 1,
      /* Last_TX_ACK_Timestamp */ 123456,
      /* Flow_Off_Count */ 78910,
      /* Last_Flow_On_Timestamp */ 123457,
      /* Buffer_Overflow_Bytes */ 42,
      /* Buffer_Underflow_Bytes */ 24,
      /* Vendor Specific Parameter */ std::make_unique<RawBuilder>())));

  // Wait for unregistered event should timeout
  event_status = event_future.wait_for(kTimeout);
  ASSERT_NE(event_status, std::future_status::ready);
}

TEST_F(HciTest, vendorSpecificEventUnknown) {
  auto event_future = upper->GetReceivedEventFuture();

  upper->RegisterVendorSpecificEvent(VseSubeventCode::BQR_EVENT);

  // Send a vendor specific event
  // Make sure 0xFE is not used for any VSE, if not change this value to an unused one
  auto raw_builder = std::make_unique<RawBuilder>();
  raw_builder->AddOctets1(42);
  hal->callbacks->hciEventReceived(
      GetPacketBytes(VendorSpecificEventBuilder::Create(static_cast<VseSubeventCode>(0xFE), std::move(raw_builder))));

  // Wait for the event should timeout
  auto event_status = event_future.wait_for(kTimeout);
  ASSERT_NE(event_status, std::future_status::ready);
}

TEST_F(HciTest, hciTimeOut) {
  auto event_future = upper->GetReceivedEventFuture();
  auto reset_command_future = hal->GetSentCommandFuture();