1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <memory> 19 #include <vector> 20 21 #include "common/callback.h" 22 #include "hci/address_with_type.h" 23 #include "hci/hci_packets.h" 24 #include "hci/le_scanning_callback.h" 25 #include "hci/uuid.h" 26 #include "module.h" 27 28 namespace bluetooth { 29 namespace hci { 30 31 enum class BatchScanMode : uint8_t { 32 DISABLE = 0, 33 TRUNCATED = 1, 34 FULL = 2, 35 TRUNCATED_AND_FULL = 3, 36 }; 37 38 class LeScanningManager : public bluetooth::Module { 39 public: 40 static constexpr uint8_t kMaxAppNum = 32; 41 static constexpr uint8_t kAdvertisingDataInfoNotPresent = 0xff; 42 static constexpr uint8_t kTxPowerInformationNotPresent = 0x7f; 43 static constexpr uint8_t kNotPeriodicAdvertisement = 0x00; 44 static constexpr ScannerId kInvalidScannerId = 0xFF; 45 LeScanningManager(); 46 LeScanningManager(const LeScanningManager&) = delete; 47 LeScanningManager& operator=(const LeScanningManager&) = delete; 48 49 virtual void RegisterScanner(const Uuid app_uuid); 50 51 virtual void Unregister(ScannerId scanner_id); 52 53 virtual void Scan(bool start); 54 55 virtual void SetScanParameters( 56 ScannerId scanner_id, 57 LeScanType scan_type, 58 uint16_t scan_interval, 59 uint16_t scan_window, 60 uint8_t scan_phy); 61 62 virtual void SetScanFilterPolicy(LeScanningFilterPolicy filter_policy); 63 64 /* Scan filter */ 65 virtual void ScanFilterEnable(bool enable); 66 67 virtual void ScanFilterParameterSetup( 68 ApcfAction action, uint8_t filter_index, AdvertisingFilterParameter advertising_filter_parameter); 69 70 virtual void ScanFilterAdd(uint8_t filter_index, std::vector<AdvertisingPacketContentFilterCommand> filters); 71 72 /*Batch Scan*/ 73 virtual void BatchScanConifgStorage( 74 uint8_t batch_scan_full_max, 75 uint8_t batch_scan_truncated_max, 76 uint8_t batch_scan_notify_threshold, 77 ScannerId scanner_id); 78 virtual void BatchScanEnable( 79 BatchScanMode scan_mode, 80 uint32_t duty_cycle_scan_window_slots, 81 uint32_t duty_cycle_scan_interval_slots, 82 BatchScanDiscardRule batch_scan_discard_rule); 83 virtual void BatchScanDisable(); 84 virtual void BatchScanReadReport(ScannerId scanner_id, BatchScanMode scan_mode); 85 86 virtual void StartSync(uint8_t sid, const AddressWithType& address, uint16_t skip, uint16_t timeout, int reg_id); 87 88 virtual void StopSync(uint16_t handle); 89 90 virtual void CancelCreateSync(uint8_t sid, const Address& address); 91 92 virtual void TransferSync( 93 const Address& address, 94 uint16_t handle, 95 uint16_t service_data, 96 uint16_t sync_handle, 97 int pa_source); 98 99 virtual void TransferSetInfo( 100 const Address& address, 101 uint16_t handle, 102 uint16_t service_data, 103 uint8_t adv_handle, 104 int pa_source); 105 106 virtual void SyncTxParameters(const Address& addr, uint8_t mode, uint16_t skip, uint16_t timeout, int reg_id); 107 108 virtual void TrackAdvertiser(uint8_t filter_index, ScannerId scanner_id); 109 110 virtual void RegisterScanningCallback(ScanningCallback* scanning_callback); 111 112 virtual bool IsAdTypeFilterSupported() const; 113 114 static const ModuleFactory Factory; 115 116 protected: 117 void ListDependencies(ModuleList* list) const override; 118 119 void Start() override; 120 121 void Stop() override; 122 123 std::string ToString() const override; 124 125 private: 126 struct impl; 127 std::unique_ptr<impl> pimpl_; 128 }; 129 130 } // namespace hci 131 } // namespace bluetooth 132