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 | |
| 26 | /** Callback invoked when batchscan storage config operation has completed */ |
| 27 | typedef void (*batchscan_cfg_storage_callback)(int client_if, int status); |
| 28 | |
| 29 | /** Callback invoked when batchscan enable / disable operation has completed */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 30 | typedef void (*batchscan_enable_disable_callback)(int action, int client_if, |
| 31 | int status); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 32 | |
| 33 | /** Callback invoked when batchscan reports are obtained */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 34 | typedef void (*batchscan_reports_callback)(int client_if, int status, |
| 35 | int report_format, int num_records, |
| 36 | std::vector<uint8_t> data); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 37 | |
| 38 | /** Callback invoked when batchscan storage threshold limit is crossed */ |
| 39 | typedef void (*batchscan_threshold_callback)(int client_if); |
| 40 | |
| 41 | /** Track ADV VSE callback invoked when tracked device is found or lost */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 42 | typedef void (*track_adv_event_callback)( |
| 43 | btgatt_track_adv_info_t *p_track_adv_info); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 44 | |
| 45 | /** Callback invoked when scan parameter setup has completed */ |
| 46 | typedef void (*scan_parameter_setup_completed_callback)(int client_if, |
| 47 | btgattc_error_t status); |
| 48 | |
| 49 | /** Callback for scan results */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 50 | typedef void (*scan_result_callback)(bt_bdaddr_t *bda, int rssi, |
| 51 | std::vector<uint8_t> adv_data); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 52 | |
| 53 | /** Callback invoked when a scan filter configuration command has completed */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 54 | typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, |
| 55 | int filt_type, int avbl_space); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 56 | |
| 57 | /** Callback invoked when scan param has been added, cleared, or deleted */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 58 | typedef void (*scan_filter_param_callback)(int action, int client_if, |
| 59 | int status, int avbl_space); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 60 | |
| 61 | /** Callback invoked when a scan filter configuration command has completed */ |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 62 | typedef void (*scan_filter_status_callback)(int enable, int client_if, |
| 63 | int status); |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 64 | |
| 65 | typedef struct { |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 66 | scan_result_callback scan_result_cb; |
| 67 | batchscan_cfg_storage_callback batchscan_cfg_storage_cb; |
| 68 | batchscan_enable_disable_callback batchscan_enb_disable_cb; |
| 69 | batchscan_reports_callback batchscan_reports_cb; |
| 70 | batchscan_threshold_callback batchscan_threshold_cb; |
| 71 | track_adv_event_callback track_adv_event_cb; |
| 72 | scan_parameter_setup_completed_callback scan_parameter_setup_completed_cb; |
| 73 | scan_filter_cfg_callback scan_filter_cfg_cb; |
| 74 | scan_filter_param_callback scan_filter_param_cb; |
| 75 | scan_filter_status_callback scan_filter_status_cb; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 76 | } btgatt_scanner_callbacks_t; |
| 77 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 78 | class BleScannerInterface { |
| 79 | public: |
| 80 | virtual ~BleScannerInterface() = default; |
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 | using RegisterCallback = |
| 83 | base::Callback<void(uint8_t /* scanner_id */, uint8_t /* status */)>; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 84 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 85 | /** Registers a scanner with the stack */ |
| 86 | virtual void RegisterScanner(RegisterCallback) = 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 | /** Unregister a scanner from the stack */ |
| 89 | virtual void Unregister(int scanner_id) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 90 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 91 | /** Start or stop LE device scanning */ |
| 92 | virtual void Scan(bool start) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 93 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 94 | /** Setup scan filter params */ |
Jakub Pawlowski | b4a82ba | 2016-12-16 14:26:20 -0800 | [diff] [blame^] | 95 | virtual void ScanFilterParamSetup(uint8_t client_if, uint8_t action, |
| 96 | uint8_t filt_index, |
| 97 | std::unique_ptr<btgatt_filt_param_setup_t> filt_param) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 98 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 99 | /** Configure a scan filter condition */ |
| 100 | virtual bt_status_t scan_filter_add_remove( |
| 101 | int client_if, int action, int filt_type, int filt_index, int company_id, |
| 102 | int company_id_mask, const bt_uuid_t *p_uuid, |
| 103 | const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr, char addr_type, |
| 104 | std::vector<uint8_t> data, std::vector<uint8_t> p_mask) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 105 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 106 | /** Clear all scan filter conditions for specific filter index*/ |
| 107 | virtual bt_status_t scan_filter_clear(int client_if, int filt_index) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 108 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 109 | /** Enable / disable scan filter feature*/ |
| 110 | virtual bt_status_t scan_filter_enable(int client_if, bool enable) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 111 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 112 | /** Sets the LE scan interval and window in units of N*0.625 msec */ |
| 113 | virtual bt_status_t set_scan_parameters(int client_if, int scan_interval, |
| 114 | int scan_window) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 115 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 116 | /* Configure the batchscan storage */ |
| 117 | virtual bt_status_t batchscan_cfg_storage( |
| 118 | int client_if, int batch_scan_full_max, int batch_scan_trunc_max, |
| 119 | int batch_scan_notify_threshold) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 120 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 121 | /* Enable batchscan */ |
| 122 | virtual bt_status_t batchscan_enb_batch_scan(int client_if, int scan_mode, |
| 123 | int scan_interval, |
| 124 | int scan_window, int addr_type, |
| 125 | int discard_rule) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 126 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 127 | /* Disable batchscan */ |
| 128 | virtual bt_status_t batchscan_dis_batch_scan(int client_if) = 0; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 129 | |
Jakub Pawlowski | d5286ae | 2016-12-14 13:38:18 -0800 | [diff] [blame] | 130 | /* Read out batchscan reports */ |
| 131 | virtual bt_status_t batchscan_read_reports(int client_if, int scan_mode) = 0; |
| 132 | }; |
Jakub Pawlowski | 1e24ce9 | 2016-10-27 12:26:07 -0700 | [diff] [blame] | 133 | |
| 134 | #endif /* ANDROID_INCLUDE_BLE_SCANNER_H */ |