1 /******************************************************************************
2  *
3  *  Copyright 1999-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef BTM_BLE_API_TYPES_H
20 #define BTM_BLE_API_TYPES_H
21 
22 #include <base/callback_forward.h>
23 #include <hardware/bt_common_types.h>
24 #include <cstdint>
25 #include <vector>
26 
27 #include "stack/include/btm_api_types.h"
28 #include "stack/include/btm_status.h"
29 #include "stack/include/hci_error_code.h"
30 #include "types/ble_address_with_type.h"
31 
32 #define CHNL_MAP_LEN 5
33 typedef uint8_t tBTM_BLE_CHNL_MAP[CHNL_MAP_LEN];
34 
35 enum : uint8_t {
36   /* 0x00-0x04 only used for set advertising parameter command */
37   BTM_BLE_CONNECT_EVT = 0x00,
38   /* Connectable directed advertising */
39   BTM_BLE_CONNECT_DIR_EVT = 0x01,
40   /* Scannable undirected advertising */
41   BTM_BLE_DISCOVER_EVT = 0x02,
42   /* Non connectable undirected advertising */
43   BTM_BLE_NON_CONNECT_EVT = 0x03,
44   /* Connectable low duty cycle directed advertising  */
45   BTM_BLE_CONNECT_LO_DUTY_DIR_EVT = 0x04,
46 };
47 
48 /* 0x00 - 0x04 can be received on adv event type */
49 typedef enum : uint8_t {
50   BTM_BLE_ADV_IND_EVT = 0x00,
51   BTM_BLE_ADV_DIRECT_IND_EVT = 0x01,
52   BTM_BLE_ADV_SCAN_IND_EVT = 0x02,
53   BTM_BLE_ADV_NONCONN_IND_EVT = 0x03,
54   BTM_BLE_SCAN_RSP_EVT = 0x04,
55 } tBTM_BLE_EVT;
56 
57 typedef uint32_t tBTM_BLE_REF_VALUE;
58 
59 #define BTM_BLE_SCAN_MODE_PASS 0
60 #define BTM_BLE_SCAN_MODE_ACTI 1
61 #define BTM_BLE_SCAN_MODE_NONE 0xff
62 typedef uint8_t tBLE_SCAN_MODE;
63 
64 #define BTM_BLE_BATCH_SCAN_MODE_DISABLE 0
65 #define BTM_BLE_BATCH_SCAN_MODE_PASS 1
66 #define BTM_BLE_BATCH_SCAN_MODE_ACTI 2
67 #define BTM_BLE_BATCH_SCAN_MODE_PASS_ACTI 3
68 
69 typedef uint8_t tBTM_BLE_BATCH_SCAN_MODE;
70 
71 /* advertising channel map */
72 #define BTM_BLE_ADV_CHNL_37 (0x01 << 0)
73 #define BTM_BLE_ADV_CHNL_38 (0x01 << 1)
74 #define BTM_BLE_ADV_CHNL_39 (0x01 << 2)
75 typedef uint8_t tBTM_BLE_ADV_CHNL_MAP;
76 
77 /*d efault advertising channel map */
78 #ifndef BTM_BLE_DEFAULT_ADV_CHNL_MAP
79 #define BTM_BLE_DEFAULT_ADV_CHNL_MAP \
80   (BTM_BLE_ADV_CHNL_37 | BTM_BLE_ADV_CHNL_38 | BTM_BLE_ADV_CHNL_39)
81 #endif
82 
83 /* advertising filter policy */
84 #define AP_SCAN_CONN_ALL 0x00 /* default */
85 #define AP_SCAN_WL_CONN_ALL 0x01
86 #define AP_SCAN_ALL_CONN_WL 0x02
87 #define AP_SCAN_CONN_WL 0x03
88 #define AP_SCAN_CONN_POLICY_MAX 0x04
89 typedef uint8_t tBTM_BLE_AFP;
90 
91 /* default advertising filter policy */
92 #ifndef BTM_BLE_DEFAULT_AFP
93 #define BTM_BLE_DEFAULT_AFP AP_SCAN_CONN_ALL
94 #endif
95 
96 /* scanning filter policy */
97 /* 0: accept adv packet from all, directed adv pkt not directed */
98 /*    to local device is ignored */
99 #define SP_ADV_ALL 0x00
100 
101 typedef uint8_t tBTM_BLE_SFP;
102 
103 #ifndef BTM_BLE_DEFAULT_SFP
104 #define BTM_BLE_DEFAULT_SFP SP_ADV_ALL
105 #endif
106 
107 /* Full scan boundary values */
108 #define BTM_BLE_ADV_SCAN_FULL_MIN 0x00
109 #define BTM_BLE_ADV_SCAN_FULL_MAX 0x64
110 
111 /* Partial scan boundary values */
112 #define BTM_BLE_ADV_SCAN_TRUNC_MAX BTM_BLE_ADV_SCAN_FULL_MAX
113 
114 /* Threshold values */
115 #define BTM_BLE_ADV_SCAN_THR_MAX BTM_BLE_ADV_SCAN_FULL_MAX
116 
117 /* connection parameter boundary values */
118 #define BTM_BLE_SCAN_INT_MIN 0x0004
119 #define BTM_BLE_SCAN_INT_MAX 0x4000
120 #define BTM_BLE_SCAN_WIN_MIN 0x0004
121 #define BTM_BLE_SCAN_WIN_MAX 0x4000
122 #define BTM_BLE_EXT_SCAN_INT_MAX 0x00FFFFFF
123 #define BTM_BLE_EXT_SCAN_WIN_MAX 0xFFFF
124 #define BTM_BLE_CONN_INT_MIN 0x0006
125 #define BTM_BLE_CONN_INT_MAX 0x0C80
126 #define BTM_BLE_CONN_LATENCY_MAX 500
127 #define BTM_BLE_CONN_SUP_TOUT_MIN 0x000A
128 #define BTM_BLE_CONN_SUP_TOUT_MAX 0x0C80
129 /* use this value when a specific value not to be overwritten */
130 #define BTM_BLE_CONN_PARAM_UNDEF 0xffff
131 #define BTM_BLE_SCAN_PARAM_UNDEF 0xffff
132 
133 /* default connection parameters if not configured, use GAP recommended value
134  * for auto/selective connection */
135 /* default scan interval */
136 #ifndef BTM_BLE_SCAN_FAST_INT
137 #define BTM_BLE_SCAN_FAST_INT 96 /* 30 ~ 60 ms (use 60)  = 96 *0.625 */
138 #endif
139 /* default scan window for background connection, applicable for auto connection
140  * or selective connection */
141 #ifndef BTM_BLE_SCAN_FAST_WIN
142 #define BTM_BLE_SCAN_FAST_WIN 48 /* 30 ms = 48 *0.625 */
143 #endif
144 
145 /* default scan paramter used in reduced power cycle (background scanning) */
146 #ifndef BTM_BLE_SCAN_SLOW_INT_1
147 #define BTM_BLE_SCAN_SLOW_INT_1 2048 /* 1.28 s   = 2048 *0.625 */
148 #endif
149 #ifndef BTM_BLE_SCAN_SLOW_WIN_1
150 #define BTM_BLE_SCAN_SLOW_WIN_1 48 /* 30 ms = 48 *0.625 */
151 #endif
152 
153 /* default scan paramter used in reduced power cycle (background scanning) */
154 #ifndef BTM_BLE_SCAN_SLOW_INT_2
155 #define BTM_BLE_SCAN_SLOW_INT_2 4096 /* 2.56 s   = 4096 *0.625 */
156 #endif
157 #ifndef BTM_BLE_SCAN_SLOW_WIN_2
158 #define BTM_BLE_SCAN_SLOW_WIN_2 36 /* 22.5 ms = 36 *0.625 */
159 #endif
160 
161 /* default connection interval min */
162 #ifndef BTM_BLE_CONN_INT_MIN_DEF
163 /* recommended min: 30ms  = 24 * 1.25 */
164 #ifndef BTM_BLE_CONN_INT_MIN_DEF
165 #define BTM_BLE_CONN_INT_MIN_DEF 24
166 #endif
167 #endif
168 
169 /* default connectino interval max */
170 #ifndef BTM_BLE_CONN_INT_MAX_DEF
171 /* recommended max: 50 ms = 56 * 1.25 */
172 #ifndef BTM_BLE_CONN_INT_MAX_DEF
173 #define BTM_BLE_CONN_INT_MAX_DEF 40
174 #endif
175 #endif
176 
177 /* default peripheral latency */
178 #ifndef BTM_BLE_CONN_PERIPHERAL_LATENCY_DEF
179 #define BTM_BLE_CONN_PERIPHERAL_LATENCY_DEF 0 /* 0 */
180 #endif
181 
182 /* default supervision timeout */
183 #ifndef BTM_BLE_CONN_TIMEOUT_DEF
184 #define BTM_BLE_CONN_TIMEOUT_DEF 500
185 #endif
186 
187 /* minimum supervision timeout */
188 #ifndef BTM_BLE_CONN_TIMEOUT_MIN_DEF
189 #define BTM_BLE_CONN_TIMEOUT_MIN_DEF 100
190 #endif
191 
192 /* minimum acceptable connection interval */
193 #ifndef BTM_BLE_CONN_INT_MIN_LIMIT
194 #define BTM_BLE_CONN_INT_MIN_LIMIT 0x0009
195 #endif
196 
197 /* minimum acceptable connection interval when there is bonded Hearing Aid
198  * device */
199 #ifndef BTM_BLE_CONN_INT_MIN_HEARINGAID
200 #define BTM_BLE_CONN_INT_MIN_HEARINGAID 0x0010
201 #endif
202 
203 #define BTM_CMAC_TLEN_SIZE 8 /* 64 bits */
204 #define BTM_BLE_AUTH_SIGN_LEN \
205   12 /* BLE data signature length 8 Bytes + 4 bytes counter*/
206 typedef uint8_t BLE_SIGNATURE[BTM_BLE_AUTH_SIGN_LEN]; /* Device address */
207 
208 #ifndef BTM_BLE_HOST_SUPPORT
209 #define BTM_BLE_HOST_SUPPORT 0x01
210 #endif
211 
212 #ifndef BTM_BLE_SIMULTANEOUS_HOST
213 #define BTM_BLE_SIMULTANEOUS_HOST 0x01
214 #endif
215 
216 /* Appearance Values Reported with BTM_BLE_AD_TYPE_APPEARANCE */
217 #define BTM_BLE_APPEARANCE_UKNOWN 0x0000
218 #define BTM_BLE_APPEARANCE_GENERIC_PHONE 0x0040
219 #define BTM_BLE_APPEARANCE_GENERIC_COMPUTER 0x0080
220 #define BTM_BLE_APPEARANCE_GENERIC_WATCH 0x00C0
221 #define BTM_BLE_APPEARANCE_SPORTS_WATCH 0x00C1
222 #define BTM_BLE_APPEARANCE_GENERIC_CLOCK 0x0100
223 #define BTM_BLE_APPEARANCE_GENERIC_DISPLAY 0x0140
224 #define BTM_BLE_APPEARANCE_GENERIC_REMOTE 0x0180
225 #define BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES 0x01C0
226 #define BTM_BLE_APPEARANCE_GENERIC_TAG 0x0200
227 #define BTM_BLE_APPEARANCE_GENERIC_KEYRING 0x0240
228 #define BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 0x0280
229 #define BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 0x02C0
230 #define BTM_BLE_APPEARANCE_GENERIC_THERMOMETER 0x0300
231 #define BTM_BLE_APPEARANCE_THERMOMETER_EAR 0x0301
232 #define BTM_BLE_APPEARANCE_GENERIC_HEART_RATE 0x0340
233 #define BTM_BLE_APPEARANCE_HEART_RATE_BELT 0x0341
234 #define BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 0x0380
235 #define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM 0x0381
236 #define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 0x0382
237 #define BTM_BLE_APPEARANCE_GENERIC_HID 0x03C0
238 #define BTM_BLE_APPEARANCE_HID_KEYBOARD 0x03C1
239 #define BTM_BLE_APPEARANCE_HID_MOUSE 0x03C2
240 #define BTM_BLE_APPEARANCE_HID_JOYSTICK 0x03C3
241 #define BTM_BLE_APPEARANCE_HID_GAMEPAD 0x03C4
242 #define BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET 0x03C5
243 #define BTM_BLE_APPEARANCE_HID_CARD_READER 0x03C6
244 #define BTM_BLE_APPEARANCE_HID_DIGITAL_PEN 0x03C7
245 #define BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER 0x03C8
246 #define BTM_BLE_APPEARANCE_GENERIC_GLUCOSE 0x0400
247 #define BTM_BLE_APPEARANCE_GENERIC_WALKING 0x0440
248 #define BTM_BLE_APPEARANCE_WALKING_IN_SHOE 0x0441
249 #define BTM_BLE_APPEARANCE_WALKING_ON_SHOE 0x0442
250 #define BTM_BLE_APPEARANCE_WALKING_ON_HIP 0x0443
251 #define BTM_BLE_APPEARANCE_GENERIC_CYCLING 0x0480
252 #define BTM_BLE_APPEARANCE_CYCLING_COMPUTER 0x0481
253 #define BTM_BLE_APPEARANCE_CYCLING_SPEED 0x0482
254 #define BTM_BLE_APPEARANCE_CYCLING_CADENCE 0x0483
255 #define BTM_BLE_APPEARANCE_CYCLING_POWER 0x0484
256 #define BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE 0x0485
257 #define BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 0x0C40
258 #define BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 0x0C41
259 #define BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST 0x0C42
260 #define BTM_BLE_APPEARANCE_GENERIC_WEIGHT 0x0C80
261 #define BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS 0x1440
262 #define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION 0x1441
263 #define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV 0x1442
264 #define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD 0x1443
265 #define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV 0x1444
266 
267 /* Structure returned with Rand/Encrypt complete callback */
268 typedef struct {
269   uint8_t status;
270   uint8_t param_len;
271   uint16_t opcode;
272   uint8_t param_buf[OCTET16_LEN];
273 } tBTM_RAND_ENC;
274 
275 /* General callback function for notifying an application that a synchronous
276  * BTM function is complete. The pointer contains the address of any returned
277  * data.
278 */
279 typedef void(tBTM_RAND_ENC_CB)(tBTM_RAND_ENC* p1);
280 
281 /* ADV data flag bit definition used for BTM_BLE_AD_TYPE_FLAG */
282 #define BTM_BLE_LIMIT_DISC_FLAG (0x01 << 0)
283 #define BTM_BLE_GEN_DISC_FLAG (0x01 << 1)
284 #define BTM_BLE_BREDR_NOT_SPT (0x01 << 2)
285 /* 4.1 spec adv flag for simultaneous BR/EDR+LE connection support */
286 #define BTM_BLE_DMT_CONTROLLER_SPT (0x01 << 3)
287 #define BTM_BLE_DMT_HOST_SPT (0x01 << 4)
288 
289 // TODO(jpawlowski): this should be removed with code that depend on it.
290 #define BTM_BLE_AD_BIT_FLAGS (0x00000001 << 1)
291 
292 #define BTM_BLE_AD_TYPE_FLAG HCI_EIR_FLAGS_TYPE /* 0x01 */
293 #define BTM_BLE_AD_TYPE_16SRV_CMPL          \
294   HCI_EIR_COMPLETE_16BITS_UUID_TYPE /* 0x03 \
295                                        */
296 #define BTM_BLE_AD_TYPE_APPEARANCE 0x19
297 
298 /*  Min/max Preferred  number of payload octets that the local Controller
299     should include in a single Link Layer Data Channel PDU. */
300 #define BTM_BLE_DATA_SIZE_MAX 0x00fb
301 #define BTM_BLE_DATA_SIZE_MIN 0x001b
302 
303 /*  Preferred maximum number of microseconds that the local Controller
304     should use to transmit a single Link Layer Data Channel PDU. */
305 #define BTM_BLE_DATA_TX_TIME_MAX_LEGACY  0x0848
306 #define BTM_BLE_DATA_TX_TIME_MAX         0x4290
307 
308 /* adv tx power in dBm */
309 typedef struct {
310   uint8_t adv_inst_max; /* max adv instance supported in controller */
311   uint8_t rpa_offloading;
312   uint16_t tot_scan_results_strg;
313   uint8_t max_irk_list_sz;
314   uint8_t filter_support;
315   uint8_t max_filter;
316   uint8_t energy_support;
317   bool values_read;
318   uint16_t version_supported;
319   uint16_t total_trackable_advertisers;
320   uint8_t extended_scan_support;
321   uint8_t debug_logging_supported;
322   uint8_t le_address_generation_offloading_support;
323   uint32_t a2dp_source_offload_capability_mask;
324   uint8_t quality_report_support;
325   uint32_t dynamic_audio_buffer_support;
326 } tBTM_BLE_VSC_CB;
327 
328 /* Stored the default/maximum/minimum buffer time for dynamic audio buffer.
329  * For A2DP offload usage, the unit is millisecond.
330  * For A2DP legacy usage, the unit is buffer queue size*/
331 typedef struct {
332   uint16_t default_buffer_time;
333   uint16_t maximum_buffer_time;
334   uint16_t minimum_buffer_time;
335 } tBTM_BT_DYNAMIC_AUDIO_BUFFER_CB;
336 
337 typedef void(tBTM_BLE_ADV_DATA_CMPL_CBACK)(tBTM_STATUS status);
338 
339 #ifndef BTM_BLE_MULTI_ADV_MAX
340 #define BTM_BLE_MULTI_ADV_MAX                           \
341   16 /* controller returned adv_inst_max should be less \
342         than this number */
343 #endif
344 
345 typedef uint8_t tGATT_IF;
346 
347 typedef void(tBTM_BLE_SCAN_THRESHOLD_CBACK)(tBTM_BLE_REF_VALUE ref_value);
348 using tBTM_BLE_SCAN_REP_CBACK =
349     base::Callback<void(tBTM_STATUS /* status */, uint8_t /* report_format */,
350                         uint8_t /* num_reports */, std::vector<uint8_t>)>;
351 
352 #ifndef BTM_BLE_BATCH_SCAN_MAX
353 #define BTM_BLE_BATCH_SCAN_MAX 5
354 #endif
355 
356 #ifndef BTM_BLE_BATCH_REP_MAIN_Q_SIZE
357 #define BTM_BLE_BATCH_REP_MAIN_Q_SIZE 2
358 #endif
359 
360 typedef enum {
361   BTM_BLE_SCAN_INVALID_STATE = 0,
362   BTM_BLE_SCAN_ENABLE_CALLED = 1,
363   BTM_BLE_SCAN_ENABLED_STATE = 2,
364   BTM_BLE_SCAN_DISABLE_CALLED = 3,
365   BTM_BLE_SCAN_DISABLED_STATE = 4
366 } tBTM_BLE_BATCH_SCAN_STATE;
367 
368 enum { BTM_BLE_DISCARD_OLD_ITEMS, BTM_BLE_DISCARD_LOWER_RSSI_ITEMS };
369 typedef uint8_t tBTM_BLE_DISCARD_RULE;
370 
371 typedef struct {
372   tBTM_BLE_BATCH_SCAN_STATE cur_state;
373   tBTM_BLE_BATCH_SCAN_MODE scan_mode;
374   uint32_t scan_interval;
375   uint32_t scan_window;
376   tBLE_ADDR_TYPE addr_type;
377   tBTM_BLE_DISCARD_RULE discard_rule;
378   tBTM_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback;
379   tBTM_BLE_REF_VALUE ref_value;
380 } tBTM_BLE_BATCH_SCAN_CB;
381 
382 /* filter selection bit index  */
383 #define BTM_BLE_PF_ADDR_FILTER 0
384 #define BTM_BLE_PF_SRVC_DATA 1
385 #define BTM_BLE_PF_SRVC_UUID 2
386 #define BTM_BLE_PF_SRVC_SOL_UUID 3
387 #define BTM_BLE_PF_LOCAL_NAME 4
388 #define BTM_BLE_PF_MANU_DATA 5
389 #define BTM_BLE_PF_SRVC_DATA_PATTERN 6
390 /* when passed in payload filter type all, only clear action is applicable */
391 #define BTM_BLE_PF_TYPE_ALL 7
392 #define BTM_BLE_PF_TYPE_MAX 8
393 
394 /* max number of filter spot for different filter type */
395 #ifndef BTM_BLE_MAX_UUID_FILTER
396 #define BTM_BLE_MAX_UUID_FILTER 8
397 #endif
398 #ifndef BTM_BLE_MAX_ADDR_FILTER
399 #define BTM_BLE_MAX_ADDR_FILTER 8
400 #endif
401 #ifndef BTM_BLE_PF_STR_COND_MAX
402 #define BTM_BLE_PF_STR_COND_MAX 4 /* apply to manu data , or local name */
403 #endif
404 #ifndef BTM_BLE_PF_STR_LEN_MAX
405 #define BTM_BLE_PF_STR_LEN_MAX 29 /* match for first 29 bytes */
406 #endif
407 
408 typedef uint8_t tBTM_BLE_PF_COND_TYPE;
409 
410 #define BTM_BLE_PF_LOGIC_OR 0
411 #define BTM_BLE_PF_LOGIC_AND 1
412 typedef uint8_t tBTM_BLE_PF_LOGIC_TYPE;
413 
414 #define BTM_BLE_PF_ENABLE 1
415 #define BTM_BLE_PF_CONFIG 2
416 
417 typedef uint8_t tBTM_BLE_PF_FILT_INDEX;
418 
419 enum {
420   BTM_BLE_SCAN_COND_ADD,
421   BTM_BLE_SCAN_COND_DELETE,
422   BTM_BLE_SCAN_COND_CLEAR = 2
423 };
424 typedef uint8_t tBTM_BLE_SCAN_COND_OP;
425 
426 /* BLE adv payload filtering config complete callback */
427 using tBTM_BLE_PF_CFG_CBACK = base::Callback<void(
428     uint8_t /* avbl_space */, uint8_t /* action */, uint8_t /* btm_status */)>;
429 
430 /* BLE adv payload filtering status setup complete callback */
431 using tBTM_BLE_PF_STATUS_CBACK =
432     base::Callback<void(uint8_t /*action*/, uint8_t /* btm_status */)>;
433 
434 /* BLE adv payload filtering param setup complete callback */
435 using tBTM_BLE_PF_PARAM_CB = base::Callback<void(
436     uint8_t /* avbl_space */, uint8_t /* action */, uint8_t /* btm_status */)>;
437 
438 #ifndef BTM_CS_IRK_LIST_MAX
439 #define BTM_CS_IRK_LIST_MAX 0x20
440 #endif
441 
442 typedef struct {
443   bool in_use;
444   RawAddress bd_addr;
445   uint8_t pf_counter[BTM_BLE_PF_TYPE_MAX]; /* number of filter indexed by
446                                               tBTM_BLE_PF_COND_TYPE */
447 } tBTM_BLE_PF_COUNT;
448 
449 typedef struct {
450   bool enable;
451   uint8_t op_type;
452   tBTM_BLE_PF_COUNT* p_addr_filter_count; /* per BDA filter array */
453   tBLE_BD_ADDR cur_filter_target;
454 } tBTM_BLE_ADV_FILTER_CB;
455 
456 /* Sub codes */
457 #define BTM_BLE_META_PF_ENABLE 0x00
458 #define BTM_BLE_META_PF_FEAT_SEL 0x01
459 #define BTM_BLE_META_PF_ADDR 0x02
460 #define BTM_BLE_META_PF_UUID 0x03
461 #define BTM_BLE_META_PF_SOL_UUID 0x04
462 #define BTM_BLE_META_PF_LOCAL_NAME 0x05
463 #define BTM_BLE_META_PF_MANU_DATA 0x06
464 #define BTM_BLE_META_PF_SRVC_DATA 0x07
465 #define BTM_BLE_META_PF_ALL 0x08
466 
467 #define ADV_INFO_PRESENT 0x00
468 #define NO_ADV_INFO_PRESENT 0x01
469 
470 typedef btgatt_track_adv_info_t tBTM_BLE_TRACK_ADV_DATA;
471 
472 typedef void(tBTM_BLE_TRACK_ADV_CBACK)(
473     tBTM_BLE_TRACK_ADV_DATA* p_track_adv_data);
474 
475 typedef struct {
476   tBTM_BLE_REF_VALUE ref_value;
477   tBTM_BLE_TRACK_ADV_CBACK* p_track_cback;
478 } tBTM_BLE_ADV_TRACK_CB;
479 
480 typedef uint32_t tBTM_BLE_TX_TIME_MS;
481 typedef uint32_t tBTM_BLE_RX_TIME_MS;
482 typedef uint32_t tBTM_BLE_IDLE_TIME_MS;
483 typedef uint32_t tBTM_BLE_ENERGY_USED;
484 
485 typedef void(tBTM_BLE_ENERGY_INFO_CBACK)(tBTM_BLE_TX_TIME_MS tx_time,
486                                          tBTM_BLE_RX_TIME_MS rx_time,
487                                          tBTM_BLE_IDLE_TIME_MS idle_time,
488                                          tBTM_BLE_ENERGY_USED energy_used,
489                                          tHCI_STATUS status);
490 
491 typedef struct {
492   tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback;
493 } tBTM_BLE_ENERGY_INFO_CB;
494 
495 typedef void(tBTM_BLE_CTRL_FEATURES_CBACK)(tHCI_STATUS status);
496 
497 /* BLE encryption keys */
498 typedef struct {
499   Octet16 ltk;
500   BT_OCTET8 rand;
501   uint16_t ediv;
502   uint8_t sec_level;
503   uint8_t key_size;
504 } tBTM_LE_PENC_KEYS;
505 
506 /* BLE CSRK keys */
507 typedef struct {
508   uint32_t counter;
509   Octet16 csrk;
510   uint8_t sec_level;
511 } tBTM_LE_PCSRK_KEYS;
512 
513 /* BLE Encryption reproduction keys */
514 typedef struct {
515   Octet16 ltk;
516   uint16_t div;
517   uint8_t key_size;
518   uint8_t sec_level;
519 } tBTM_LE_LENC_KEYS;
520 
521 /* BLE SRK keys */
522 typedef struct {
523   uint32_t counter;
524   uint16_t div;
525   uint8_t sec_level;
526   Octet16 csrk;
527 } tBTM_LE_LCSRK_KEYS;
528 
529 typedef struct {
530   Octet16 irk;
531   tBLE_ADDR_TYPE identity_addr_type;
532   RawAddress identity_addr;
533 } tBTM_LE_PID_KEYS;
534 
535 typedef union {
536   tBTM_LE_PENC_KEYS penc_key;   /* received peer encryption key */
537   tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
538   tBTM_LE_PID_KEYS pid_key;     /* peer device ID key */
539   tBTM_LE_LENC_KEYS lenc_key;   /* local encryption reproduction keys
540                                  * LTK = = d1(ER,DIV,0) */
541   tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
542 } tBTM_LE_KEY_VALUE;
543 
544 typedef struct {
545   tBTM_LE_KEY_TYPE key_type;
546   tBTM_LE_KEY_VALUE* p_key_value;
547 } tBTM_LE_KEY;
548 
549 typedef union {
550   tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT      */
551   uint32_t key_notif;    /* BTM_LE_KEY_NOTIF_EVT   */
552                          /* BTM_LE_NC_REQ_EVT */
553                          /* no callback data for
554                           * BTM_LE_KEY_REQ_EVT
555                           * and BTM_LE_OOB_REQ_EVT  */
556   tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT      */
557   tSMP_OOB_DATA_TYPE req_oob_type;
558   tBTM_LE_KEY key;
559   tSMP_LOC_OOB_DATA local_oob_data;
560 } tBTM_LE_EVT_DATA;
561 
562 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
563  * events occur.
564  */
565 typedef uint8_t(tBTM_LE_CALLBACK)(tBTM_LE_EVT event, const RawAddress& bda,
566                                   tBTM_LE_EVT_DATA* p_data);
567 
568 #define BTM_BLE_KEY_TYPE_ID 1
569 #define BTM_BLE_KEY_TYPE_ER 2
570 #define BTM_BLE_KEY_TYPE_COUNTER 3  // tobe obsolete
571 
572 typedef struct {
573   Octet16 ir;
574   Octet16 irk;
575   Octet16 dhk;
576 
577 } tBTM_BLE_LOCAL_ID_KEYS;
578 
579 typedef union {
580   tBTM_BLE_LOCAL_ID_KEYS id_keys;
581   Octet16 er;
582 } tBTM_BLE_LOCAL_KEYS;
583 
584 /* New LE identity key for local device.
585  */
586 typedef void(tBTM_LE_KEY_CALLBACK)(uint8_t key_type,
587                                    tBTM_BLE_LOCAL_KEYS* p_key);
588 
589 #endif  // BTM_BLE_API_TYPES_H
590