blob: 273cbc5e43cca8fee35e7b99f69f06cc1ac08c6f [file] [log] [blame]
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -07001/*
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 Pawlowski1e24ce92016-10-27 12:26:07 -070022#include "bt_common_types.h"
23#include "bt_gatt_client.h"
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080024#include "bt_gatt_types.h"
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070025
26/** Callback invoked when batchscan storage config operation has completed */
27typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
28
29/** Callback invoked when batchscan enable / disable operation has completed */
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080030typedef void (*batchscan_enable_disable_callback)(int action, int client_if,
31 int status);
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070032
33/** Callback invoked when batchscan reports are obtained */
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080034typedef void (*batchscan_reports_callback)(int client_if, int status,
35 int report_format, int num_records,
36 std::vector<uint8_t> data);
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070037
38/** Callback invoked when batchscan storage threshold limit is crossed */
39typedef void (*batchscan_threshold_callback)(int client_if);
40
41/** Track ADV VSE callback invoked when tracked device is found or lost */
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080042typedef void (*track_adv_event_callback)(
43 btgatt_track_adv_info_t *p_track_adv_info);
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070044
45/** Callback invoked when scan parameter setup has completed */
46typedef void (*scan_parameter_setup_completed_callback)(int client_if,
47 btgattc_error_t status);
48
49/** Callback for scan results */
Jakub Pawlowski701ab732017-01-30 06:44:55 -080050typedef void (*scan_result_callback)(uint16_t event_type, uint8_t addr_type,
51 bt_bdaddr_t *bda, uint8_t primary_phy,
52 uint8_t secondary_phy,
53 uint8_t advertising_sid, int8_t tx_power,
54 int8_t rssi, uint16_t periodic_adv_int,
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080055 std::vector<uint8_t> adv_data);
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070056
57/** Callback invoked when a scan filter configuration command has completed */
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080058typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status,
59 int filt_type, int avbl_space);
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070060
61/** Callback invoked when scan param has been added, cleared, or deleted */
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080062typedef void (*scan_filter_param_callback)(int action, int client_if,
63 int status, int avbl_space);
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070064
65/** Callback invoked when a scan filter configuration command has completed */
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080066typedef void (*scan_filter_status_callback)(int enable, int client_if,
67 int status);
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070068
69typedef struct {
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080070 scan_result_callback scan_result_cb;
71 batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
72 batchscan_enable_disable_callback batchscan_enb_disable_cb;
73 batchscan_reports_callback batchscan_reports_cb;
74 batchscan_threshold_callback batchscan_threshold_cb;
75 track_adv_event_callback track_adv_event_cb;
76 scan_parameter_setup_completed_callback scan_parameter_setup_completed_cb;
77 scan_filter_cfg_callback scan_filter_cfg_cb;
78 scan_filter_param_callback scan_filter_param_cb;
79 scan_filter_status_callback scan_filter_status_cb;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070080} btgatt_scanner_callbacks_t;
81
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080082class BleScannerInterface {
83 public:
84 virtual ~BleScannerInterface() = default;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070085
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080086 using RegisterCallback =
87 base::Callback<void(uint8_t /* scanner_id */, uint8_t /* status */)>;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070088
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080089 /** Registers a scanner with the stack */
90 virtual void RegisterScanner(RegisterCallback) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070091
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080092 /** Unregister a scanner from the stack */
93 virtual void Unregister(int scanner_id) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070094
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080095 /** Start or stop LE device scanning */
96 virtual void Scan(bool start) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -070097
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -080098 /** Setup scan filter params */
Jakub Pawlowski442eae02016-12-19 11:52:19 -080099 virtual void ScanFilterParamSetup(
100 uint8_t client_if, uint8_t action, uint8_t filt_index,
101 std::unique_ptr<btgatt_filt_param_setup_t> filt_param) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700102
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800103 /** Configure a scan filter condition */
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800104 virtual void ScanFilterAddRemove(int client_if, int action, int filt_type,
105 int filt_index, int company_id,
106 int company_id_mask, const bt_uuid_t *p_uuid,
107 const bt_uuid_t *p_uuid_mask,
108 const bt_bdaddr_t *bd_addr, char addr_type,
109 std::vector<uint8_t> data,
110 std::vector<uint8_t> p_mask) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700111
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800112 /** Clear all scan filter conditions for specific filter index*/
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800113 virtual void ScanFilterClear(int client_if, int filt_index) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700114
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800115 /** Enable / disable scan filter feature*/
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800116 virtual void ScanFilterEnable(int client_if, bool enable) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700117
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800118 /** Sets the LE scan interval and window in units of N*0.625 msec */
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800119 virtual void SetScanParameters(int client_if, int scan_interval,
120 int scan_window) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700121
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800122 /* Configure the batchscan storage */
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800123 virtual void BatchscanConfigStorage(int client_if, int batch_scan_full_max,
124 int batch_scan_trunc_max,
125 int batch_scan_notify_threshold) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700126
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800127 /* Enable batchscan */
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800128 virtual void BatchscanEnable(int client_if, int scan_mode, int scan_interval,
129 int scan_window, int addr_type,
130 int discard_rule) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700131
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800132 /* Disable batchscan */
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800133 virtual void BatchscanDisable(int client_if) = 0;
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700134
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800135 /* Read out batchscan reports */
Jakub Pawlowski442eae02016-12-19 11:52:19 -0800136 virtual void BatchscanReadReports(int client_if, int scan_mode) = 0;
Jakub Pawlowskid5286ae2016-12-14 13:38:18 -0800137};
Jakub Pawlowski1e24ce92016-10-27 12:26:07 -0700138
139#endif /* ANDROID_INCLUDE_BLE_SCANNER_H */