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

Commit e8e1d164 authored by Martin Brabham's avatar Martin Brabham
Browse files

Floss: LeRand controller plumbing

Add ability to call LeRand and provide a callback function.

Bug: 219982689
Test: mma -j $(nproc)
Test: ./build.py
Test: atest bluetooth_test_gd_unit --test-filter="*controller*"
Tag: #floss
Change-Id: Id501efa2073f3b8887f7ca9a3894050becebc5cd
parent a472419d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -21,9 +21,12 @@
#include <cstddef>
#include <cstdint>

#include "base/callback.h"
#include "btcore/include/version.h"
#include "types/raw_address.h"

using LeRandCallback = base::Callback<void(uint64_t)>;

typedef struct controller_t {
  bool (*get_is_ready)(void);

@@ -116,6 +119,7 @@ typedef struct controller_t {
  uint8_t (*get_le_all_initiating_phys)(void);
  uint8_t (*clear_event_filter)(void);
  uint8_t (*clear_event_mask)(void);
  uint8_t (*le_rand)(LeRandCallback);

} controller_t;

+20 −0
Original line number Diff line number Diff line
@@ -511,6 +511,22 @@ struct Controller::impl {
                         module_.GetHandler()->BindOnceOn(this, &Controller::impl::check_status<ResetCompleteView>));
  }

  void le_rand(LeRandCallback cb) {
    std::unique_ptr<LeRandBuilder> packet = LeRandBuilder::Create();
    hci_->EnqueueCommand(
        std::move(packet),
        module_.GetHandler()->BindOnceOn(this, &Controller::impl::le_rand_cb<LeRandCompleteView>, cb));
  }

  template <class T>
  void le_rand_cb(LeRandCallback cb, CommandCompleteView view) {
    ASSERT(view.IsValid());
    auto status_view = T::Create(view);
    ASSERT(status_view.IsValid());
    ASSERT(status_view.GetStatus() == ErrorCode::SUCCESS);
    cb.Run(status_view.GetRandomNumber());
  }

  void set_event_filter(std::unique_ptr<SetEventFilterBuilder> packet) {
    hci_->EnqueueCommand(std::move(packet), module_.GetHandler()->BindOnceOn(
                                                this, &Controller::impl::check_status<SetEventFilterCompleteView>));
@@ -1020,6 +1036,10 @@ void Controller::Reset() {
  CallOn(impl_.get(), &impl::reset);
}

void Controller::LeRand(LeRandCallback cb) {
  CallOn(impl_.get(), &impl::le_rand, cb);
}

void Controller::SetEventFilterClearAll() {
  std::unique_ptr<SetEventFilterClearAllBuilder> packet = SetEventFilterClearAllBuilder::Create();
  CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
+3 −1
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

#pragma once

#include "common/contextual_callback.h"
#include "hci/address.h"
#include "hci/hci_packets.h"
#include "hci/le_rand_callback.h"
#include "module.h"
#include "os/handler.h"

@@ -127,6 +127,8 @@ class Controller : public Module {

  virtual void Reset();

  virtual void LeRand(LeRandCallback cb);

  virtual void SetEventFilterClearAll();

  virtual void SetEventFilterInquiryResultAllDevices();
+1 −0
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ class MockController : public Controller {
  MOCK_METHOD(uint8_t, GetLePeriodicAdvertiserListSize, (), (const));
  MOCK_METHOD(VendorCapabilities, GetVendorCapabilities, (), (const));
  MOCK_METHOD(bool, IsSupported, (OpCode op_code), (const));
  MOCK_METHOD(void, LeRand, (LeRandCallback cb));
};

}  // namespace testing
+12 −0
Original line number Diff line number Diff line
@@ -462,6 +462,18 @@ TEST_F(ControllerTest, aclCreditCallbackListenerUnregistered) {

  test_hci_layer_->IncomingCredit();
}

std::promise<uint64_t> le_rand_set;

void le_rand_callback(uint64_t random) {
  le_rand_set.set_value(random);
}

TEST_F(ControllerTest, leRandTest) {
  controller_->LeRand(client_handler_->Bind(&le_rand_callback));
  le_rand_set.get_future().wait();
}

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