Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 ANDROID_INCLUDE_BLE_SCANNER_H |
| 18 | #define ANDROID_INCLUDE_BLE_SCANNER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <vector> |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 22 | #include "bt_common_types.h" |
| 23 | #include "bt_gatt_client.h" |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 24 | #include "bt_gatt_types.h" |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 25 | |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 26 | /** Callback invoked when batchscan reports are obtained */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 27 | typedef void (*batchscan_reports_callback)(int client_if, int status, |
| 28 | int report_format, int num_records, |
| 29 | std::vector<uint8_t> data); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 30 | |
| 31 | /** Callback invoked when batchscan storage threshold limit is crossed */ |
| 32 | typedef void (*batchscan_threshold_callback)(int client_if); |
| 33 | |
| 34 | /** Track ADV VSE callback invoked when tracked device is found or lost */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 35 | typedef void (*track_adv_event_callback)( |
| 36 | btgatt_track_adv_info_t *p_track_adv_info); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 37 | |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 38 | /** Callback for scan results */ |
Jakub Pawlowski | 701ab73 | 2017-01-30 06:44:55 -0800 | [diff] [blame] | 39 | typedef void (*scan_result_callback)(uint16_t event_type, uint8_t addr_type, |
| 40 | bt_bdaddr_t *bda, uint8_t primary_phy, |
| 41 | uint8_t secondary_phy, |
| 42 | uint8_t advertising_sid, int8_t tx_power, |
| 43 | int8_t rssi, uint16_t periodic_adv_int, |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 44 | std::vector<uint8_t> adv_data); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 45 | |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 46 | typedef struct { |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 47 | scan_result_callback scan_result_cb; |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 48 | batchscan_reports_callback batchscan_reports_cb; |
| 49 | batchscan_threshold_callback batchscan_threshold_cb; |
| 50 | track_adv_event_callback track_adv_event_cb; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 51 | } btgatt_scanner_callbacks_t; |
| 52 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 53 | class BleScannerInterface { |
| 54 | public: |
| 55 | virtual ~BleScannerInterface() = default; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 56 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 57 | using RegisterCallback = |
| 58 | base::Callback<void(uint8_t /* scanner_id */, uint8_t /* status */)>; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 59 | |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 60 | using Callback = base::Callback<void(uint8_t /* status */)>; |
| 61 | |
| 62 | using EnableCallback = |
| 63 | base::Callback<void(uint8_t /* action */, uint8_t /* status */)>; |
| 64 | |
| 65 | using FilterParamSetupCallback = |
| 66 | base::Callback<void(uint8_t /* avbl_space */, uint8_t /* action_type */, |
| 67 | uint8_t /* status */)>; |
| 68 | |
| 69 | using FilterConfigCallback = |
| 70 | base::Callback<void(uint8_t /* filt_type */, uint8_t /* avbl_space */, |
| 71 | uint8_t /* action */, uint8_t /* status */)>; |
| 72 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 73 | /** Registers a scanner with the stack */ |
| 74 | virtual void RegisterScanner(RegisterCallback) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 75 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 76 | /** Unregister a scanner from the stack */ |
| 77 | virtual void Unregister(int scanner_id) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 78 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 79 | /** Start or stop LE device scanning */ |
| 80 | virtual void Scan(bool start) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 81 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 82 | /** Setup scan filter params */ |
Jakub Pawlowski | 442eae0 | 2016-12-19 11:52:19 -0800 | [diff] [blame] | 83 | virtual void ScanFilterParamSetup( |
| 84 | uint8_t client_if, uint8_t action, uint8_t filt_index, |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 85 | std::unique_ptr<btgatt_filt_param_setup_t> filt_param, |
| 86 | FilterParamSetupCallback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 87 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 88 | /** Configure a scan filter condition */ |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 89 | virtual void ScanFilterAddRemove(int action, int filt_type, int filt_index, |
| 90 | int company_id, int company_id_mask, |
| 91 | const bt_uuid_t *p_uuid, |
Jakub Pawlowski | 442eae0 | 2016-12-19 11:52:19 -0800 | [diff] [blame] | 92 | const bt_uuid_t *p_uuid_mask, |
| 93 | const bt_bdaddr_t *bd_addr, char addr_type, |
| 94 | std::vector<uint8_t> data, |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 95 | std::vector<uint8_t> p_mask, |
| 96 | FilterConfigCallback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 97 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 98 | /** Clear all scan filter conditions for specific filter index*/ |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 99 | virtual void ScanFilterClear(int filt_index, FilterConfigCallback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 100 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 101 | /** Enable / disable scan filter feature*/ |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 102 | virtual void ScanFilterEnable(bool enable, EnableCallback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 103 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 104 | /** Sets the LE scan interval and window in units of N*0.625 msec */ |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 105 | virtual void SetScanParameters(int scan_interval, int scan_window, |
| 106 | Callback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 107 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 108 | /* Configure the batchscan storage */ |
Jakub Pawlowski | 442eae0 | 2016-12-19 11:52:19 -0800 | [diff] [blame] | 109 | virtual void BatchscanConfigStorage(int client_if, int batch_scan_full_max, |
| 110 | int batch_scan_trunc_max, |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 111 | int batch_scan_notify_threshold, |
| 112 | Callback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 113 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 114 | /* Enable batchscan */ |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 115 | virtual void BatchscanEnable(int scan_mode, int scan_interval, |
| 116 | int scan_window, int addr_type, int discard_rule, |
| 117 | Callback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 118 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 119 | /* Disable batchscan */ |
Jakub Pawlowski | 62ddb5d | 2017-02-16 11:57:11 -0800 | [diff] [blame] | 120 | virtual void BatchscanDisable(Callback cb) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 121 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 122 | /* Read out batchscan reports */ |
Jakub Pawlowski | 442eae0 | 2016-12-19 11:52:19 -0800 | [diff] [blame] | 123 | virtual void BatchscanReadReports(int client_if, int scan_mode) = 0; |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 124 | }; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 125 | |
| 126 | #endif /* ANDROID_INCLUDE_BLE_SCANNER_H */ |