1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GD_RUST_TOPSHIM_GATT_GATT_BLE_SCANNER_SHIM_H
#define GD_RUST_TOPSHIM_GATT_GATT_BLE_SCANNER_SHIM_H
#include <memory>
#include "include/hardware/ble_scanner.h"
#include "include/hardware/bt_gatt.h"
#include "rust/cxx.h"
namespace bluetooth {
namespace topshim {
namespace rust {
struct RustApcfCommand;
struct RustGattFilterParam;
struct RustRawAddress;
struct RustUuid;
class BleScannerIntf : public ScanningCallbacks {
public:
BleScannerIntf(BleScannerInterface* scanner_intf) : scanner_intf_(scanner_intf){};
~BleScannerIntf() = default;
// ScanningCallbacks overrides
void OnScannerRegistered(const bluetooth::Uuid app_uuid, uint8_t scannerId, uint8_t status) override;
void OnSetScannerParameterComplete(uint8_t scannerId, uint8_t status) override;
void OnScanResult(
uint16_t event_type,
uint8_t addr_type,
RawAddress bda,
uint8_t primary_phy,
uint8_t secondary_phy,
uint8_t advertising_sid,
int8_t tx_power,
int8_t rssi,
uint16_t periodic_adv_int,
std::vector<uint8_t> adv_data) override;
void OnTrackAdvFoundLost(AdvertisingTrackInfo advertising_track_info) override;
void OnBatchScanReports(
int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) override;
void OnBatchScanThresholdCrossed(int client_if) override;
void OnPeriodicSyncStarted(
int reg_id,
uint8_t status,
uint16_t sync_handle,
uint8_t advertising_sid,
uint8_t address_type,
RawAddress address,
uint8_t phy,
uint16_t interval) override;
void OnPeriodicSyncReport(
uint16_t sync_handle, int8_t tx_power, int8_t rssi, uint8_t status, std::vector<uint8_t> data) override;
void OnPeriodicSyncLost(uint16_t sync_handle) override;
void OnPeriodicSyncTransferred(int pa_source, uint8_t status, RawAddress address) override;
// Implementations of BleScannerInterface. These don't inherit from
// BleScannerInterface because the Rust FFI boundary requires some clever
// modifications.
// Register a scanner for a Uuid. Response comes back via
// |OnRegisterCallback|.
void RegisterScanner(RustUuid uuid);
// Unregister a scanner with a |scanner_id|.
void Unregister(uint8_t scanner_id);
// Start/Stop LE scanning.
void Scan(bool start);
// Setup scan filter parameters. Get responses via
// |OnFilterParamSetupCallback|.
void ScanFilterParamSetup(uint8_t scanner_id, uint8_t action, uint8_t filter_index, RustGattFilterParam filter_param);
// Adds filters to given filter index. Gets responses via
// |OnFilterConfigCallback|.
void ScanFilterAdd(uint8_t filter_index, ::rust::Vec<RustApcfCommand> filters);
// Clear scan filter conditions for a specific index.
void ScanFilterClear(uint8_t filter_index);
// Enable/disable scan filter. Gets responses via |OnEnableCallback|.
void ScanFilterEnable(bool enable);
// Sets the LE scan interval and window in units of N * 0.625 msec. The result
// of this action is returned via |OnStatusCallback|.
void SetScanParameters(uint8_t scanner_id, uint16_t scan_interval, uint16_t scan_window);
// Configure the batchscan storage and get a response via |OnStatusCallback|.
void BatchscanConfigStorage(
uint8_t scanner_id,
int32_t batch_scan_full_max,
int32_t batch_scan_trunc_max,
int32_t batch_scan_notify_threshold);
// Enable batchscan. Gets responses via |OnStatusCallback| with scanner id
// = 0 (since multiple scanners can be registered).
void BatchscanEnable(
int32_t scan_mode, uint16_t scan_interval, uint16_t scan_window, int32_t addr_type, int32_t discard_rule);
// Disable batchscan. Gets responses via |OnStatusCallback| with a scanner id
// = 0 (since multiple scanners can be registered).
void BatchscanDisable();
// Read out batchscan report for a specific scanner. Gets responses via
// |ScanningCallbacks::OnBatchScanReports|.
void BatchscanReadReports(uint8_t scanner_id, int32_t scan_mode);
// Start periodic sync. Gets responses via |OnStartSyncCb|. Periodic reports
// come via |OnSyncReportCb| and |OnSyncLostCb|.
void StartSync(uint8_t sid, RustRawAddress address, uint16_t skip, uint16_t timeout);
// Stop periodic sync.
void StopSync(uint16_t handle);
// Cancel creating a periodic sync.
void CancelCreateSync(uint8_t sid, RustRawAddress address);
// Transfer sync data to target address. Gets responses via
// |OnSyncTransferCb|.
void TransferSync(RustRawAddress address, uint16_t service_data, uint16_t sync_handle);
// Transfer set info to target address. Gets responses via |OnSyncTransferCb|.
void TransferSetInfo(RustRawAddress address, uint16_t service_data, uint8_t adv_handle);
// Sync tx parameters to target address. Gets responses via |OnStartSyncCb|.
void SyncTxParameters(RustRawAddress address, uint8_t mode, uint16_t skip, uint16_t timeout);
// Register scanning callbacks to be dispatched to the Rust layer via static
// methods.
void RegisterCallbacks();
private:
// The callback functions below will get base::Bind to the apis that need it
// and will call the same Rust function with all the parameters. Some of these
// callbacks don't have all the parameters coming back in the original
// callback and will need the values to be base::Bind at the callsite.
void OnRegisterCallback(RustUuid uuid, uint8_t scanner_id, uint8_t btm_status);
void OnStatusCallback(uint8_t scanner_id, uint8_t btm_status);
void OnEnableCallback(uint8_t action, uint8_t btm_status);
void OnFilterParamSetupCallback(uint8_t scanner_id, uint8_t avbl_space, uint8_t action_type, uint8_t btm_status);
void OnFilterConfigCallback(
uint8_t filt_index, uint8_t filt_type, uint8_t avbl_space, uint8_t action, uint8_t btm_status);
BleScannerInterface* scanner_intf_;
};
std::unique_ptr<BleScannerIntf> GetBleScannerIntf(const unsigned char* gatt_intf);
} // namespace rust
} // namespace topshim
} // namespace bluetooth
#endif // GD_RUST_TOPSHIM_GATT_GATT_BLE_SCANNER_SHIM_H
|