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

Commit f7ec69cb authored by Joseph Hwang's avatar Joseph Hwang Committed by Gerrit Code Review
Browse files

Merge changes I41fca51e,I416010b0

* changes:
  floss: check msft supported
  gd/hci: MSFT operations disallowed if not supported
parents 3b04bc72 d0a5c394
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -138,6 +138,11 @@ struct MsftExtensionManager::impl {
  }

  void msft_adv_monitor_add(const MsftAdvMonitor& monitor, MsftAdvMonitorAddCallback cb) {
    if (!supports_msft_extensions()) {
      LOG_WARN("Disallowed as MSFT extension is not supported.");
      return;
    }

    std::vector<MsftLeMonitorAdvConditionPattern> patterns;
    MsftLeMonitorAdvConditionPattern pattern;
    // The Microsoft Extension specifies 1 octet for the number of patterns.
@@ -168,6 +173,11 @@ struct MsftExtensionManager::impl {
  }

  void msft_adv_monitor_remove(uint8_t monitor_handle, MsftAdvMonitorRemoveCallback cb) {
    if (!supports_msft_extensions()) {
      LOG_WARN("Disallowed as MSFT extension is not supported.");
      return;
    }

    msft_adv_monitor_remove_cb_ = cb;
    hci_layer_->EnqueueCommand(
        MsftLeCancelMonitorAdvBuilder::Create(
@@ -176,6 +186,11 @@ struct MsftExtensionManager::impl {
  }

  void msft_adv_monitor_enable(bool enable, MsftAdvMonitorEnableCallback cb) {
    if (!supports_msft_extensions()) {
      LOG_WARN("Disallowed as MSFT extension is not supported.");
      return;
    }

    msft_adv_monitor_enable_cb_ = cb;
    hci_layer_->EnqueueCommand(
        MsftLeSetAdvFilterEnableBuilder::Create(static_cast<OpCode>(msft_.opcode.value()), enable),
+41 −34
Original line number Diff line number Diff line
@@ -1696,8 +1696,10 @@ impl IBluetoothGatt for BluetoothGatt {
            let mut gatt_async = gatt_async.lock().await;

            // 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 {
            if is_msft_supported {
                if let Some(filter) = filter {
                    let monitor_handle =
                        match gatt_async.msft_adv_monitor_add((&filter).into()).await {
                            Ok((handle, 0)) => handle,
                            _ => {
                                log::error!("Error adding advertisement monitor");
@@ -1726,6 +1728,7 @@ impl IBluetoothGatt for BluetoothGatt {
                    // the state machine to avoid calling enable/disable if it's already at that state
                    log::error!("Error updating Advertisement Monitor enable");
                }
            }

            gatt_async.update_scan().await;
        });
@@ -1755,6 +1758,7 @@ impl IBluetoothGatt for BluetoothGatt {
            .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none());

        let gatt_async = self.gatt_async.clone();
        let is_msft_supported = self.is_msft_supported();
        tokio::spawn(async move {
            // The two operations below (monitor remove, update scan) happen one after another, and
            // cannot be interleaved with other GATT async operations.
@@ -1762,6 +1766,8 @@ impl IBluetoothGatt for BluetoothGatt {
            // at the end of this block.
            let mut gatt_async = gatt_async.lock().await;

            // Remove and disable the monitor only when the MSFT extension is supported.
            if is_msft_supported {
                if let Some(handle) = monitor_handle {
                    let _res = gatt_async.msft_adv_monitor_remove(handle).await;
                }
@@ -1773,6 +1779,7 @@ impl IBluetoothGatt for BluetoothGatt {
                {
                    log::error!("Error updating Advertisement Monitor enable");
                }
            }

            gatt_async.update_scan().await;
        });