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

Commit b82d5d32 authored by Joseph Hwang's avatar Joseph Hwang Committed by Sonny Sasaka
Browse files

gd/hci: handle MSFT_LE_MONITOR_DEVICE_EVENT in gd layer

Allow MsftExtensionManager to accept `ScanningCallback` to be
registered, which will be triggered on MSFT scan events (e.g. device
found and lost).

Bug: 261482382
Tag: #floss
Test: ./build.py --target test
Test: Manual test on a ChromeOS device, e.g., zork/morphius
      localhost # btclient
      bluetooth> le-scan register-scanner
      bluetooth> le-scan start-scan 1
      # If a target LE device is found and then lost, the log shows
      # something like
      bluetooth> btclient:info: Scan result lost: ScanResult {
        name: ...,
        address: ...,
        ...
      }

Change-Id: Ie255ef5c7d058a621e83c0eed241916de29a51a8
parent 4a1991d9
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -84,8 +84,19 @@ struct MsftExtensionManager::impl {

  void handle_le_monitor_device_event(MsftLeMonitorDeviceEventPayloadView view) {
    ASSERT(view.IsValid());
    LOG_WARN("The Microsoft MSFT_LE_MONITOR_DEVICE_EVENT is not supported yet.");
    // TODO: to call a callback here.

    // The monitor state is 0x00 when the controller stops monitoring the device.
    if (view.GetMonitorState() == 0x00) {
      AdvertisingFilterOnFoundOnLostInfo on_found_on_lost_info;
      on_found_on_lost_info.advertiser_address_type = view.GetAddressType();
      on_found_on_lost_info.advertiser_address = view.GetBdAddr();
      scanning_callbacks_->OnTrackAdvFoundLost(on_found_on_lost_info);
    } else if (view.GetMonitorState() == 0x01) {
      // TODO: Bubble up this event via `OnScanResult`.
    } else {
      LOG_WARN("The Microsoft vendor event monitor state is invalid.");
      return;
    }
  }

  void handle_msft_events(VendorSpecificEventView view) {
@@ -171,6 +182,10 @@ struct MsftExtensionManager::impl {
        module_handler_->BindOnceOn(this, &impl::on_msft_adv_monitor_enable_complete));
  }

  void set_scanning_callback(ScanningCallback* callbacks) {
    scanning_callbacks_ = callbacks;
  }

  /*
   * Get the event prefix from the packet for configuring MSFT's
   * Vendor Specific events. Also get the MSFT supported features.
@@ -268,6 +283,7 @@ struct MsftExtensionManager::impl {
  MsftAdvMonitorAddCallback msft_adv_monitor_add_cb_;
  MsftAdvMonitorRemoveCallback msft_adv_monitor_remove_cb_;
  MsftAdvMonitorEnableCallback msft_adv_monitor_enable_cb_;
  ScanningCallback* scanning_callbacks_;
};

MsftExtensionManager::MsftExtensionManager() {
@@ -315,5 +331,9 @@ void MsftExtensionManager::MsftAdvMonitorEnable(bool enable, MsftAdvMonitorEnabl
  CallOn(pimpl_.get(), &impl::msft_adv_monitor_enable, enable, cb);
}

void MsftExtensionManager::SetScanningCallback(ScanningCallback* callbacks) {
  CallOn(pimpl_.get(), &impl::set_scanning_callback, callbacks);
}

}  // namespace hci
}  // namespace bluetooth
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#pragma once

#include "hci/hci_packets.h"
#include "hci/le_scanning_callback.h"
#include "module.h"

struct MsftAdvMonitor;
@@ -39,6 +40,7 @@ class MsftExtensionManager : public bluetooth::Module {
  void MsftAdvMonitorAdd(const MsftAdvMonitor& monitor, MsftAdvMonitorAddCallback cb);
  void MsftAdvMonitorRemove(uint8_t monitor_handle, MsftAdvMonitorRemoveCallback cb);
  void MsftAdvMonitorEnable(bool enable, MsftAdvMonitorEnableCallback cb);
  void SetScanningCallback(ScanningCallback* callbacks);

  static const ModuleFactory Factory;

+4 −0
Original line number Diff line number Diff line
@@ -134,6 +134,10 @@ using bluetooth::shim::BleScannerInterfaceImpl;
void BleScannerInterfaceImpl::Init() {
  LOG_INFO("init BleScannerInterfaceImpl");
  bluetooth::shim::GetScanning()->RegisterScanningCallback(this);

  if (bluetooth::shim::GetMsftExtensionManager()) {
    bluetooth::shim::GetMsftExtensionManager()->SetScanningCallback(this);
  }
}

/** Registers a scanner with the stack */