| // Copyright 2024 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef SRC_CONNECTIVITY_BLUETOOTH_CORE_BT_HOST_PUBLIC_PW_BLUETOOTH_SAPPHIRE_INTERNAL_HOST_HCI_EXTENDED_LOW_ENERGY_SCANNER_H_ |
| #define SRC_CONNECTIVITY_BLUETOOTH_CORE_BT_HOST_PUBLIC_PW_BLUETOOTH_SAPPHIRE_INTERNAL_HOST_HCI_EXTENDED_LOW_ENERGY_SCANNER_H_ |
| |
| #include "src/connectivity/bluetooth/core/bt-host/public/pw_bluetooth_sapphire/internal/host/hci/low_energy_scanner.h" |
| namespace bt::hci { |
| |
| // ExtendedLowEnergyScanner implements the LowEnergyScanner interface for |
| // controllers that support the 5.0 Extended Advertising feature. This uses the |
| // extended HCI LE scan commands and events: |
| // |
| // - HCI_LE_Set_Extended_Scan_Parameters |
| // - HCI_LE_Set_Extended_Scan_Enable |
| // - HCI_LE_Extended_Advertising_Report event |
| // |
| // After enabling scanning, zero or more HCI_LE_Extended_Advertising_Report |
| // events are generated by the Controller based on any advertising packets |
| // received and the duplicate filtering in effect. ExtendedLowEnergyAdvertiser |
| // subscribes to this event, parses the results, and returns discovered peers |
| // via the delegate. |
| // |
| // As currently implemented, this scanner uses a continuous scan duration and |
| // doesn't subscribe to the HCI_LE_Scan_Timeout Event. |
| class ExtendedLowEnergyScanner final : public LowEnergyScanner { |
| public: |
| ExtendedLowEnergyScanner(LocalAddressDelegate* local_addr_delegate, |
| Transport::WeakPtr transport, |
| pw::async::Dispatcher& pw_dispatcher); |
| ~ExtendedLowEnergyScanner() override; |
| |
| bool StartScan(const ScanOptions& options, |
| ScanStatusCallback callback) override; |
| |
| private: |
| // Build the HCI command packet to set the scan parameters for the flavor of |
| // low energy scanning being implemented. |
| EmbossCommandPacket BuildSetScanParametersPacket( |
| const DeviceAddress& local_address, const ScanOptions& options) override; |
| |
| // Build the HCI command packet to enable scanning for the flavor of low |
| // energy scanning being implemented. |
| EmbossCommandPacket BuildEnablePacket( |
| const ScanOptions& options, |
| pw::bluetooth::emboss::GenericEnableParam enable) override; |
| |
| // Parse out all the advertising reports that came in an HCI LE Extended |
| // Advertising Report. |
| static std::vector<pw::bluetooth::emboss::LEExtendedAdvertisingReportDataView> |
| ParseAdvertisingReports(const EmbossEventPacket& event); |
| |
| // Event handler for HCI LE Extended Advertising Report event. |
| void OnExtendedAdvertisingReportEvent(const EmbossEventPacket& event); |
| |
| // Our event handler ID for the LE Extended Advertising Report event. |
| CommandChannel::EventHandlerId event_handler_id_; |
| |
| BT_DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(ExtendedLowEnergyScanner); |
| }; |
| |
| } // namespace bt::hci |
| |
| #endif // SRC_CONNECTIVITY_BLUETOOTH_CORE_BT_HOST_PUBLIC_PW_BLUETOOTH_SAPPHIRE_INTERNAL_HOST_HCI_EXTENDED_LOW_ENERGY_SCANNER_H_ |