1 /*
2  * Copyright 2021 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 
17 #ifndef BLE_SCANNER_H
18 #define BLE_SCANNER_H
19 
20 #include <base/functional/bind.h>
21 #include <base/memory/weak_ptr.h>
22 
23 #include <vector>
24 
25 #include "btm_ble_api.h"
26 
27 using status_cb = base::Callback<void(uint8_t /* status */)>;
28 using handle_cb = base::Callback<void(uint8_t /* status */, uint16_t /* adv_handle */)>;
29 
30 // methods we expose to c code:
31 void btm_ble_scanner_cleanup(void);
32 void btm_ble_scanner_init();
33 
34 class BleScannerHciInterface;
35 
36 class BleScanningManager {
37 public:
38   virtual ~BleScanningManager() = default;
39 
40   static void Initialize(BleScannerHciInterface* interface);
41   static void CleanUp();
42   static bool IsInitialized();
43   static base::WeakPtr<BleScanningManager> Get();
44 
45   virtual void PeriodicScanStart(uint8_t options, uint8_t set_id, uint8_t adv_addr_type,
46                                  const RawAddress& adv_addr, uint16_t skip_num,
47                                  uint16_t sync_timeout, uint8_t sync_cte_type) = 0;
48   virtual void PeriodicScanCancelStart(/*status_cb command_complete*/) = 0;
49   virtual void PeriodicScanTerminate(uint16_t sync_handle/*,
50                                      status_cb command_complete*/) = 0;
51   virtual void PeriodicAdvSyncTransfer(const RawAddress& bd_addr, uint16_t service_data,
52                                        uint16_t sync_handle, handle_cb command_complete) = 0;
53   virtual void PeriodicAdvSetInfoTransfer(const RawAddress& bd_addr, uint16_t service_data,
54                                           uint8_t adv_handle, handle_cb command_complete) = 0;
55   virtual void SetPeriodicAdvSyncTransferParams(const RawAddress& bd_addr, uint8_t mode,
56                                                 uint16_t skip, uint16_t sync_timeout,
57                                                 uint8_t cte_type, bool set_defaults,
58                                                 status_cb command_complete) = 0;
59 
60   virtual void OnPeriodicScanResult(uint16_t sync_handle, uint8_t tx_power, int8_t rssi,
61                                     uint8_t cte_type, uint8_t pkt_data_status, uint8_t pkt_data_len,
62                                     const uint8_t* pkt_data) = 0;
63   virtual void OnPeriodicScanEstablished(uint8_t status, uint16_t sync_handle, uint8_t set_id,
64                                          uint8_t adv_addr_type, const RawAddress& adv_addr,
65                                          uint8_t adv_phy, uint16_t adv_interval,
66                                          uint8_t adv_clock_accuracy) = 0;
67   virtual void OnPeriodicScanLost(uint16_t sync_handle) = 0;
68 };
69 
70 #endif  // BLE_SCANNER_H
71