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/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 = 29 base::Callback<void(uint8_t /* status */, uint16_t /* adv_handle */)>; 30 31 // methods we expose to c code: 32 void btm_ble_scanner_cleanup(void); 33 void btm_ble_scanner_init(); 34 35 class BleScannerHciInterface; 36 37 class BleScanningManager { 38 public: 39 virtual ~BleScanningManager() = default; 40 41 static void Initialize(BleScannerHciInterface* interface); 42 static void CleanUp(); 43 static bool IsInitialized(); 44 static base::WeakPtr<BleScanningManager> Get(); 45 46 virtual void PeriodicScanStart(uint8_t options, uint8_t set_id, 47 uint8_t adv_addr_type, 48 const RawAddress& adv_addr, uint16_t skip_num, 49 uint16_t sync_timeout, 50 uint8_t sync_cte_type) = 0; 51 virtual void PeriodicScanCancelStart(/*status_cb command_complete*/) = 0; 52 virtual void PeriodicScanTerminate(uint16_t sync_handle/*, 53 status_cb command_complete*/) = 0; 54 virtual void PeriodicAdvSyncTransfer(const RawAddress& bd_addr, 55 uint16_t service_data, 56 uint16_t sync_handle, 57 handle_cb command_complete) = 0; 58 virtual void PeriodicAdvSetInfoTransfer(const RawAddress& bd_addr, 59 uint16_t service_data, 60 uint8_t adv_handle, 61 handle_cb command_complete) = 0; 62 virtual void SetPeriodicAdvSyncTransferParams(const RawAddress& bd_addr, 63 uint8_t mode, uint16_t skip, 64 uint16_t sync_timeout, 65 uint8_t cte_type, 66 bool set_defaults, 67 status_cb command_complete) = 0; 68 69 virtual void OnPeriodicScanResult(uint16_t sync_handle, uint8_t tx_power, 70 int8_t rssi, uint8_t cte_type, 71 uint8_t pkt_data_status, 72 uint8_t pkt_data_len, 73 const uint8_t* pkt_data) = 0; 74 virtual void OnPeriodicScanEstablished(uint8_t status, uint16_t sync_handle, 75 uint8_t set_id, uint8_t adv_addr_type, 76 const RawAddress& adv_addr, 77 uint8_t adv_phy, uint16_t adv_interval, 78 uint8_t adv_clock_accuracy) = 0; 79 virtual void OnPeriodicScanLost(uint16_t sync_handle) = 0; 80 }; 81 82 #endif // BLE_SCANNER_H 83