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

Commit ef5180b3 authored by Qasim Javed's avatar Qasim Javed
Browse files

Handle root inflammation event properly.

Root inflammation event is a BQR event, not a BQR link quality event.

Currently, handle_root_inflammation function in hci_layer.cc is
unreachable because we try to check is the BQR link quality event is
valid. It will not be valid because root inflammation event is a BQR
event but not a BQR link quality event.

Bug: 248063430
Bug: 245578454
Bug: 243824983
Tag: #gd-refactor
Test: atest bluetooth_test_gd_unit

Change-Id: I934918605335e3d12cff14eedd0cea96a9e01df5
parent 28fee546
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -391,9 +391,9 @@ struct HciLayer::impl {
      auto view = VendorSpecificEventView::Create(event);
      auto view = VendorSpecificEventView::Create(event);
      ASSERT(view.IsValid());
      ASSERT(view.IsValid());
      if (view.GetSubeventCode() == VseSubeventCode::BQR_EVENT) {
      if (view.GetSubeventCode() == VseSubeventCode::BQR_EVENT) {
        auto bqr_quality_view = BqrLinkQualityEventView::Create(BqrEventView::Create(view));
        auto bqr_event = BqrEventView::Create(view);
        auto inflammation = BqrRootInflammationEventView::Create(bqr_quality_view);
        auto inflammation = BqrRootInflammationEventView::Create(bqr_event);
        if (bqr_quality_view.IsValid() && inflammation.IsValid()) {
        if (bqr_event.IsValid() && inflammation.IsValid()) {
          handle_root_inflammation(inflammation.GetVendorSpecificErrorCode());
          handle_root_inflammation(inflammation.GetVendorSpecificErrorCode());
          return;
          return;
        }
        }
+35 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,20 @@ using packet::PacketView;
using packet::RawBuilder;
using packet::RawBuilder;
using testing::LogCapture;
using testing::LogCapture;


std::vector<uint8_t> GetPacketBytes(std::unique_ptr<packet::BasePacketBuilder> packet) {
  std::vector<uint8_t> bytes;
  BitInserter i(bytes);
  bytes.reserve(packet->size());
  packet->Serialize(i);
  return bytes;
}

std::unique_ptr<packet::BasePacketBuilder> CreatePayload(std::vector<uint8_t> payload) {
  auto raw_builder = std::make_unique<packet::RawBuilder>();
  raw_builder->AddOctets(payload);
  return raw_builder;
}

class TestHciHal : public hal::HciHal {
class TestHciHal : public hal::HciHal {
 public:
 public:
  TestHciHal() : hal::HciHal() {}
  TestHciHal() : hal::HciHal() {}
@@ -97,6 +111,10 @@ class TestHciHal : public hal::HciHal {
    return outgoing_commands_.size();
    return outgoing_commands_.size();
  }
  }


  void InjectEvent(std::unique_ptr<packet::BasePacketBuilder> packet) {
    callbacks->hciEventReceived(GetPacketBytes(std::move(packet)));
  }

  std::string ToString() const override {
  std::string ToString() const override {
    return std::string("TestHciHal");
    return std::string("TestHciHal");
  }
  }
@@ -184,5 +202,22 @@ TEST_F(HciLayerTest, abort_after_hci_restart_timeout) {
      "");
      "");
}
}


TEST_F(HciLayerTest, abort_on_root_inflammation_event) {
  FailIfResetNotSent();

  auto payload = CreatePayload({'0'});
  auto root_inflammation_event = BqrRootInflammationEventBuilder::Create(0x01, 0x01, std::move(payload));
  hal_->InjectEvent(std::move(root_inflammation_event));
  std::promise<void> promise;
  log_capture_->WaitUntilLogContains(&promise, "Received a Root Inflammation Event");
  ASSERT_DEATH(
      {
        FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count());
        std::promise<void> promise;
        log_capture_->WaitUntilLogContains(&promise, "Root inflammation with reason");
      },
      "");
}

}  // namespace hci
}  // namespace hci
}  // namespace bluetooth
}  // namespace bluetooth