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