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 const PacketFilterConfig& packet_filter_config, 40 Transport::WeakPtr transport, 41 pw::async::Dispatcher& pw_dispatcher); 42 ~ExtendedLowEnergyScanner() override; 43 44 bool StartScan(const ScanOptions& options, 45 ScanStatusCallback callback) override; 46 47 private: 48 // Build the HCI command packet to set the scan parameters for the flavor of 49 // low energy scanning being implemented. 50 CommandPacket BuildSetScanParametersPacket( 51 const DeviceAddress& local_address, const ScanOptions& options) override; 52 53 // Build the HCI command packet to enable scanning for the flavor of low 54 // energy scanning being implemented. 55 CommandPacket BuildEnablePacket( 56 const ScanOptions& options, 57 pw::bluetooth::emboss::GenericEnableParam enable) override; 58 59 // Parse out all the advertising reports that came in an HCI LE Extended 60 // Advertising Report. 61 static std::vector<pw::bluetooth::emboss::LEExtendedAdvertisingReportDataView> 62 ParseAdvertisingReports(const EventPacket& event); 63 64 // Event handler for HCI LE Extended Advertising Report event. 65 void OnExtendedAdvertisingReportEvent(const EventPacket& event); 66 67 // Our event handler ID for the LE Extended Advertising Report event. 68 CommandChannel::EventHandlerId event_handler_id_; 69 70 BT_DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(ExtendedLowEnergyScanner); 71 }; 72 73 } // namespace bt::hci 74