Loading system/gd/hci/le_scanning_manager.cc +12 −1 Original line number Diff line number Diff line Loading @@ -504,7 +504,10 @@ struct LeScanningManager::impl : public LeAddressManagerCallback { return; } if (is_scannable && !is_scan_response) { // Don't wait for scan response if it's a filtered scan since the filter might miss the scan // response. if (is_scannable && !is_scan_response && filter_policy_ != LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY) { // Waiting for scan response return; } Loading Loading @@ -710,6 +713,10 @@ struct LeScanningManager::impl : public LeAddressManagerCallback { scanning_callbacks_->OnSetScannerParameterComplete(scanner_id, ScanningCallback::SUCCESS); } void set_scan_filter_policy(LeScanningFilterPolicy filter_policy) { filter_policy_ = filter_policy; } void scan_filter_enable(bool enable) { if (!is_filter_supported_) { LOG_WARN("Advertising filter is not supported"); Loading Loading @@ -1686,6 +1693,10 @@ void LeScanningManager::SetScanParameters( CallOn(pimpl_.get(), &impl::set_scan_parameters, scanner_id, scan_type, scan_interval, scan_window); } void LeScanningManager::SetScanFilterPolicy(LeScanningFilterPolicy filter_policy) { CallOn(pimpl_.get(), &impl::set_scan_filter_policy, filter_policy); } void LeScanningManager::ScanFilterEnable(bool enable) { CallOn(pimpl_.get(), &impl::scan_filter_enable, enable); } Loading system/gd/hci/le_scanning_manager.h +2 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,8 @@ class LeScanningManager : public bluetooth::Module { virtual void SetScanParameters( ScannerId scanner_id, LeScanType scan_type, uint16_t scan_interval, uint16_t scan_window); virtual void SetScanFilterPolicy(LeScanningFilterPolicy filter_policy); /* Scan filter */ virtual void ScanFilterEnable(bool enable); Loading system/gd/hci/msft.cc +22 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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. Loading Loading @@ -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() { Loading Loading @@ -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 system/gd/hci/msft.h +2 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #pragma once #include "hci/hci_packets.h" #include "hci/le_scanning_callback.h" #include "module.h" struct MsftAdvMonitor; Loading @@ -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; Loading system/gd/rust/linux/stack/src/bluetooth_gatt.rs +39 −7 Original line number Diff line number Diff line Loading @@ -1268,6 +1268,11 @@ impl GattAsyncIntf { /// May be converted into real async in the future if btif supports it. async fn update_scan(&mut self) { if self.scanners.lock().unwrap().values().find(|scanner| scanner.is_active).is_some() { // Toggle the scan off and on so that we reset the scan parameters based on whether // we have active scanners using hardware filtering. // TODO(b/266752123): We can do more bookkeeping to optimize when we really need to // toggle. Also improve toggling API into 1 operation that guarantees correct ordering. self.gatt.as_ref().unwrap().lock().unwrap().scanner.stop_scan(); self.gatt.as_ref().unwrap().lock().unwrap().scanner.start_scan(); } else { self.gatt.as_ref().unwrap().lock().unwrap().scanner.stop_scan(); Loading Loading @@ -1669,9 +1674,17 @@ impl IBluetoothGatt for BluetoothGatt { } } let has_active_unfiltered_scanner = self .scanners .lock() .unwrap() .iter() .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none()); 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. Loading Loading @@ -1699,14 +1712,18 @@ impl IBluetoothGatt for BluetoothGatt { } log::debug!("Added adv monitor handle = {}", monitor_handle); } if !gatt_async .msft_adv_monitor_enable(true) .msft_adv_monitor_enable(!has_active_unfiltered_scanner) .await .map_or(false, |status| status == 0) { log::error!("Error enabling Advertisement Monitor"); } // TODO(b/266752123): // Intel controller throws "Command Disallowed" error if we tried to enable/disable // filter but it's already at the same state. This is harmless but we can improve // 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; Loading @@ -1729,6 +1746,13 @@ impl IBluetoothGatt for BluetoothGatt { } }; let has_active_unfiltered_scanner = self .scanners .lock() .unwrap() .iter() .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none()); let gatt_async = self.gatt_async.clone(); tokio::spawn(async move { // The two operations below (monitor remove, update scan) happen one after another, and Loading @@ -1741,6 +1765,14 @@ impl IBluetoothGatt for BluetoothGatt { let _res = gatt_async.msft_adv_monitor_remove(handle).await; } if !gatt_async .msft_adv_monitor_enable(!has_active_unfiltered_scanner) .await .map_or(false, |status| status == 0) { log::error!("Error updating Advertisement Monitor enable"); } gatt_async.update_scan().await; }); Loading Loading
system/gd/hci/le_scanning_manager.cc +12 −1 Original line number Diff line number Diff line Loading @@ -504,7 +504,10 @@ struct LeScanningManager::impl : public LeAddressManagerCallback { return; } if (is_scannable && !is_scan_response) { // Don't wait for scan response if it's a filtered scan since the filter might miss the scan // response. if (is_scannable && !is_scan_response && filter_policy_ != LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY) { // Waiting for scan response return; } Loading Loading @@ -710,6 +713,10 @@ struct LeScanningManager::impl : public LeAddressManagerCallback { scanning_callbacks_->OnSetScannerParameterComplete(scanner_id, ScanningCallback::SUCCESS); } void set_scan_filter_policy(LeScanningFilterPolicy filter_policy) { filter_policy_ = filter_policy; } void scan_filter_enable(bool enable) { if (!is_filter_supported_) { LOG_WARN("Advertising filter is not supported"); Loading Loading @@ -1686,6 +1693,10 @@ void LeScanningManager::SetScanParameters( CallOn(pimpl_.get(), &impl::set_scan_parameters, scanner_id, scan_type, scan_interval, scan_window); } void LeScanningManager::SetScanFilterPolicy(LeScanningFilterPolicy filter_policy) { CallOn(pimpl_.get(), &impl::set_scan_filter_policy, filter_policy); } void LeScanningManager::ScanFilterEnable(bool enable) { CallOn(pimpl_.get(), &impl::scan_filter_enable, enable); } Loading
system/gd/hci/le_scanning_manager.h +2 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,8 @@ class LeScanningManager : public bluetooth::Module { virtual void SetScanParameters( ScannerId scanner_id, LeScanType scan_type, uint16_t scan_interval, uint16_t scan_window); virtual void SetScanFilterPolicy(LeScanningFilterPolicy filter_policy); /* Scan filter */ virtual void ScanFilterEnable(bool enable); Loading
system/gd/hci/msft.cc +22 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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. Loading Loading @@ -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() { Loading Loading @@ -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
system/gd/hci/msft.h +2 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #pragma once #include "hci/hci_packets.h" #include "hci/le_scanning_callback.h" #include "module.h" struct MsftAdvMonitor; Loading @@ -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; Loading
system/gd/rust/linux/stack/src/bluetooth_gatt.rs +39 −7 Original line number Diff line number Diff line Loading @@ -1268,6 +1268,11 @@ impl GattAsyncIntf { /// May be converted into real async in the future if btif supports it. async fn update_scan(&mut self) { if self.scanners.lock().unwrap().values().find(|scanner| scanner.is_active).is_some() { // Toggle the scan off and on so that we reset the scan parameters based on whether // we have active scanners using hardware filtering. // TODO(b/266752123): We can do more bookkeeping to optimize when we really need to // toggle. Also improve toggling API into 1 operation that guarantees correct ordering. self.gatt.as_ref().unwrap().lock().unwrap().scanner.stop_scan(); self.gatt.as_ref().unwrap().lock().unwrap().scanner.start_scan(); } else { self.gatt.as_ref().unwrap().lock().unwrap().scanner.stop_scan(); Loading Loading @@ -1669,9 +1674,17 @@ impl IBluetoothGatt for BluetoothGatt { } } let has_active_unfiltered_scanner = self .scanners .lock() .unwrap() .iter() .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none()); 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. Loading Loading @@ -1699,14 +1712,18 @@ impl IBluetoothGatt for BluetoothGatt { } log::debug!("Added adv monitor handle = {}", monitor_handle); } if !gatt_async .msft_adv_monitor_enable(true) .msft_adv_monitor_enable(!has_active_unfiltered_scanner) .await .map_or(false, |status| status == 0) { log::error!("Error enabling Advertisement Monitor"); } // TODO(b/266752123): // Intel controller throws "Command Disallowed" error if we tried to enable/disable // filter but it's already at the same state. This is harmless but we can improve // 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; Loading @@ -1729,6 +1746,13 @@ impl IBluetoothGatt for BluetoothGatt { } }; let has_active_unfiltered_scanner = self .scanners .lock() .unwrap() .iter() .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none()); let gatt_async = self.gatt_async.clone(); tokio::spawn(async move { // The two operations below (monitor remove, update scan) happen one after another, and Loading @@ -1741,6 +1765,14 @@ impl IBluetoothGatt for BluetoothGatt { let _res = gatt_async.msft_adv_monitor_remove(handle).await; } if !gatt_async .msft_adv_monitor_enable(!has_active_unfiltered_scanner) .await .map_or(false, |status| status == 0) { log::error!("Error updating Advertisement Monitor enable"); } gatt_async.update_scan().await; }); Loading