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

Commit 7b8ae911 authored by Joseph Hwang's avatar Joseph Hwang
Browse files

floss: handle Microsoft advertisement commands

Wiring the MSFT APIs with the support from the gd/msft module.

Bug: 246404026
Tag: #floss
Test: ./build.py --target test
Test: mm
Test: Manual test on a ChromeOS devic
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I758820a1846b28bdd9bc69a93df2d886530a0bff
parent 706e9560
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -214,6 +214,10 @@ cc_defaults {
        "libbt_shim_bridge",
        "libbt_shim_ffi",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system/include",
        "packages/modules/Bluetooth/system/types",
    ],
    export_static_lib_headers: [ "libbluetooth_rust_interop" ],
}

+12 −4
Original line number Diff line number Diff line
@@ -1228,8 +1228,7 @@ impl Into<MsftAdvMonitor> for &ScanFilter {

impl IBluetoothGatt for BluetoothGatt {
    fn is_msft_supported(&self) -> bool {
        // TODO(b/244505567): Wire the real capability from lower layer.
        false
        self.gatt.as_ref().unwrap().lock().unwrap().scanner.is_msft_supported()
    }

    fn register_scanner_callback(&mut self, callback: Box<dyn IScannerCallback + Send>) -> u32 {
@@ -1278,7 +1277,6 @@ impl IBluetoothGatt for BluetoothGatt {
        // Multiplexing scanners happens at this layer. The implementations of start_scan
        // and stop_scan maintains the state of all registered scanners and based on the states
        // update the scanning and/or filter states of libbluetooth.
        // TODO(b/217274432): Honor settings and filters.
        {
            let mut scanners_lock = self.scanners.lock().unwrap();

@@ -1292,6 +1290,8 @@ impl IBluetoothGatt for BluetoothGatt {
        }

        let gatt_async = self.gatt_async.clone();
        let scanners = self.scanners.clone();
        let is_msft_supported = self.is_msft_supported();
        tokio::spawn(async move {
            // The three operations below (monitor add, monitor enable, update scan) happen one
            // after another, and cannot be interleaved with other GATT async operations.
@@ -1301,7 +1301,8 @@ impl IBluetoothGatt for BluetoothGatt {
            // handling callbacks.
            let mut gatt_async = gatt_async.lock().await;

            if let Some(filter) = filter {
            // Add and enable the monitor filter only when the MSFT extension is supported.
            if let (true, Some(filter)) = (is_msft_supported, filter) {
                let monitor_handle = match gatt_async.msft_adv_monitor_add((&filter).into()).await {
                    Ok((handle, 0)) => handle,
                    _ => {
@@ -1310,6 +1311,13 @@ impl IBluetoothGatt for BluetoothGatt {
                    }
                };

                if let Some(scanner) =
                    Self::find_scanner_by_id(&mut scanners.lock().unwrap(), scanner_id)
                {
                    // The monitor handle is needed in stop_scan().
                    scanner.monitor_handle = Some(monitor_handle);
                }

                log::debug!("Added adv monitor handle = {}", monitor_handle);

                if !gatt_async
+4 −0
Original line number Diff line number Diff line
@@ -245,6 +245,10 @@ void BleScannerIntf::ScanFilterEnable(bool enable) {
  scanner_intf_->ScanFilterEnable(enable, base::Bind(&BleScannerIntf::OnEnableCallback, base::Unretained(this)));
}

bool BleScannerIntf::IsMsftSupported() {
  return scanner_intf_->IsMsftSupported();
}

void BleScannerIntf::MsftAdvMonitorAdd(uint32_t call_id, const RustMsftAdvMonitor& monitor) {
  scanner_intf_->MsftAdvMonitorAdd(
      internal::ConvertAdvMonitor(monitor),
+3 −0
Original line number Diff line number Diff line
@@ -102,6 +102,9 @@ class BleScannerIntf : public ScanningCallbacks {
  // Enable/disable scan filter. Gets responses via |OnEnableCallback|.
  void ScanFilterEnable(bool enable);

  // Is MSFT Extension supported?
  bool IsMsftSupported();

  // Adds an MSFT filter. Gets responses via |OnMsftAdvMonitorAddCallback|.
  void MsftAdvMonitorAdd(uint32_t call_id, const RustMsftAdvMonitor& monitor);

+5 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@ pub mod ffi {
        );
        fn ScanFilterClear(self: Pin<&mut BleScannerIntf>, filter_index: u8);
        fn ScanFilterEnable(self: Pin<&mut BleScannerIntf>, enable: bool);
        fn IsMsftSupported(self: Pin<&mut BleScannerIntf>) -> bool;
        fn MsftAdvMonitorAdd(
            self: Pin<&mut BleScannerIntf>,
            call_id: u32,
@@ -1473,6 +1474,10 @@ impl BleScanner {
        mutcxxcall!(self, ScanFilterEnable, false);
    }

    pub fn is_msft_supported(&mut self) -> bool {
        mutcxxcall!(self, IsMsftSupported)
    }

    pub fn msft_adv_monitor_add(&mut self, call_id: u32, monitor: &MsftAdvMonitor) {
        mutcxxcall!(self, MsftAdvMonitorAdd, call_id, monitor);
    }
Loading