• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include "common/callback.h"
21 #include "hci/address_with_type.h"
22 #include "hci/hci_packets.h"
23 #include "hci/le_scanning_callback.h"
24 #include "hci/uuid.h"
25 #include "module.h"
26 
27 namespace bluetooth {
28 namespace hci {
29 
30 enum class BatchScanMode : uint8_t {
31   DISABLE = 0,
32   TRUNCATED = 1,
33   FULL = 2,
34   TRUNCATED_AND_FULL = 3,
35 };
36 
37 class LeScanningManager : public bluetooth::Module {
38  public:
39   static constexpr uint8_t kMaxAppNum = 32;
40   static constexpr uint8_t kAdvertisingDataInfoNotPresent = 0xff;
41   static constexpr uint8_t kTxPowerInformationNotPresent = 0x7f;
42   static constexpr uint8_t kNotPeriodicAdvertisement = 0x00;
43   static constexpr ScannerId kInvalidScannerId = 0xFF;
44   LeScanningManager();
45   LeScanningManager(const LeScanningManager&) = delete;
46   LeScanningManager& operator=(const LeScanningManager&) = delete;
47 
48   virtual void RegisterScanner(const Uuid app_uuid);
49 
50   virtual void Unregister(ScannerId scanner_id);
51 
52   virtual void Scan(bool start);
53 
54   virtual void SetScanParameters(
55       ScannerId scanner_id, LeScanType scan_type, uint16_t scan_interval, uint16_t scan_window);
56 
57   /* Scan filter */
58   virtual void ScanFilterEnable(bool enable);
59 
60   virtual void ScanFilterParameterSetup(
61       ApcfAction action, uint8_t filter_index, AdvertisingFilterParameter advertising_filter_parameter);
62 
63   virtual void ScanFilterAdd(uint8_t filter_index, std::vector<AdvertisingPacketContentFilterCommand> filters);
64 
65   /*Batch Scan*/
66   virtual void BatchScanConifgStorage(
67       uint8_t batch_scan_full_max,
68       uint8_t batch_scan_truncated_max,
69       uint8_t batch_scan_notify_threshold,
70       ScannerId scanner_id);
71   virtual void BatchScanEnable(
72       BatchScanMode scan_mode,
73       uint32_t duty_cycle_scan_window_slots,
74       uint32_t duty_cycle_scan_interval_slots,
75       BatchScanDiscardRule batch_scan_discard_rule);
76   virtual void BatchScanDisable();
77   virtual void BatchScanReadReport(ScannerId scanner_id, BatchScanMode scan_mode);
78 
79   virtual void StartSync(uint8_t sid, const AddressWithType& address, uint16_t skip, uint16_t timeout, int reg_id);
80 
81   virtual void StopSync(uint16_t handle);
82 
83   virtual void CancelCreateSync(uint8_t sid, const Address& address);
84 
85   virtual void TransferSync(const Address& address, uint16_t service_data, uint16_t sync_handle, int pa_source);
86 
87   virtual void TransferSetInfo(const Address& address, uint16_t service_data, uint8_t adv_handle, int pa_source);
88 
89   virtual void SyncTxParameters(const Address& addr, uint8_t mode, uint16_t skip, uint16_t timeout, int reg_id);
90 
91   virtual void TrackAdvertiser(uint8_t filter_index, ScannerId scanner_id);
92 
93   virtual void RegisterScanningCallback(ScanningCallback* scanning_callback);
94 
95   virtual bool IsAdTypeFilterSupported() const;
96 
97   static const ModuleFactory Factory;
98 
99  protected:
100   void ListDependencies(ModuleList* list) const override;
101 
102   void Start() override;
103 
104   void Stop() override;
105 
106   std::string ToString() const override;
107 
108  private:
109   struct impl;
110   std::unique_ptr<impl> pimpl_;
111 };
112 
113 }  // namespace hci
114 }  // namespace bluetooth
115