• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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(LeScanType scan_type, ScannerId scanner_id_1m,
56                                  uint16_t scan_interval_1m, uint16_t scan_window_1m,
57                                  ScannerId scanner_id_coded, uint16_t scan_interval_coded,
58                                  uint16_t scan_window_coded, uint8_t scan_phy);
59 
60   virtual void SetScanFilterPolicy(LeScanningFilterPolicy filter_policy);
61 
62   /* Scan filter */
63   virtual void ScanFilterEnable(bool enable);
64 
65   virtual void ScanFilterParameterSetup(ApcfAction action, uint8_t filter_index,
66                                         AdvertisingFilterParameter advertising_filter_parameter);
67 
68   virtual void ScanFilterAdd(uint8_t filter_index,
69                              std::vector<AdvertisingPacketContentFilterCommand> filters);
70 
71   /*Batch Scan*/
72   virtual void BatchScanConifgStorage(uint8_t batch_scan_full_max, uint8_t batch_scan_truncated_max,
73                                       uint8_t batch_scan_notify_threshold, ScannerId scanner_id);
74   virtual void BatchScanEnable(BatchScanMode scan_mode, uint32_t duty_cycle_scan_window_slots,
75                                uint32_t duty_cycle_scan_interval_slots,
76                                BatchScanDiscardRule batch_scan_discard_rule);
77   virtual void BatchScanDisable();
78   virtual void BatchScanReadReport(ScannerId scanner_id, BatchScanMode scan_mode);
79 
80   virtual void StartSync(uint8_t sid, const AddressWithType& address, uint16_t skip,
81                          uint16_t timeout, int reg_id);
82 
83   virtual void StopSync(uint16_t handle);
84 
85   virtual void CancelCreateSync(uint8_t sid, const Address& address);
86 
87   virtual void TransferSync(const Address& address, uint16_t handle, uint16_t service_data,
88                             uint16_t sync_handle, int pa_source);
89 
90   virtual void TransferSetInfo(const Address& address, uint16_t handle, uint16_t service_data,
91                                uint8_t adv_handle, int pa_source);
92 
93   virtual void SyncTxParameters(const Address& addr, uint8_t mode, uint16_t skip, uint16_t timeout,
94                                 int reg_id);
95 
96   virtual void TrackAdvertiser(uint8_t filter_index, ScannerId scanner_id);
97 
98   virtual void RegisterScanningCallback(ScanningCallback* scanning_callback);
99 
100   virtual bool IsAdTypeFilterSupported() const;
101 
102   static const ModuleFactory Factory;
103 
104 protected:
105   void ListDependencies(ModuleList* list) const override;
106 
107   void Start() override;
108 
109   void Stop() override;
110 
111   std::string ToString() const override;
112 
113 private:
114   struct impl;
115   std::unique_ptr<impl> pimpl_;
116 };
117 
118 }  // namespace hci
119 }  // namespace bluetooth
120