1 // Copyright 2024 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #pragma once 16 17 #include "pw_bluetooth_sapphire/internal/host/hci/low_energy_scanner.h" 18 namespace bt::hci { 19 20 // ExtendedLowEnergyScanner implements the LowEnergyScanner interface for 21 // controllers that support the 5.0 Extended Advertising feature. This uses the 22 // extended HCI LE scan commands and events: 23 // 24 // - HCI_LE_Set_Extended_Scan_Parameters 25 // - HCI_LE_Set_Extended_Scan_Enable 26 // - HCI_LE_Extended_Advertising_Report event 27 // 28 // After enabling scanning, zero or more HCI_LE_Extended_Advertising_Report 29 // events are generated by the Controller based on any advertising packets 30 // received and the duplicate filtering in effect. ExtendedLowEnergyAdvertiser 31 // subscribes to this event, parses the results, and returns discovered peers 32 // via the delegate. 33 // 34 // As currently implemented, this scanner uses a continuous scan duration and 35 // doesn't subscribe to the HCI_LE_Scan_Timeout Event. 36 class ExtendedLowEnergyScanner final : public LowEnergyScanner { 37 public: 38 ExtendedLowEnergyScanner(LocalAddressDelegate* local_addr_delegate, 39 Transport::WeakPtr transport, 40 pw::async::Dispatcher& pw_dispatcher); 41 ~ExtendedLowEnergyScanner() override; 42 43 bool StartScan(const ScanOptions& options, 44 ScanStatusCallback callback) override; 45 46 private: 47 // Build the HCI command packet to set the scan parameters for the flavor of 48 // low energy scanning being implemented. 49 CommandPacket BuildSetScanParametersPacket( 50 const DeviceAddress& local_address, const ScanOptions& options) override; 51 52 // Build the HCI command packet to enable scanning for the flavor of low 53 // energy scanning being implemented. 54 CommandPacket BuildEnablePacket( 55 const ScanOptions& options, 56 pw::bluetooth::emboss::GenericEnableParam enable) override; 57 58 // Parse out all the advertising reports that came in an HCI LE Extended 59 // Advertising Report. 60 static std::vector<pw::bluetooth::emboss::LEExtendedAdvertisingReportDataView> 61 ParseAdvertisingReports(const EventPacket& event); 62 63 // Event handler for HCI LE Extended Advertising Report event. 64 void OnExtendedAdvertisingReportEvent(const EventPacket& event); 65 66 // Our event handler ID for the LE Extended Advertising Report event. 67 CommandChannel::EventHandlerId event_handler_id_; 68 69 BT_DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(ExtendedLowEnergyScanner); 70 }; 71 72 } // namespace bt::hci 73