• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 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_API_TYPES_H
20 #define BTM_API_TYPES_H
21 
22 #include "bt_target.h"
23 #include "device/include/esco_parameters.h"
24 #include "hcidefs.h"
25 #include "smp_api_types.h"
26 
27 /* Maximum number of bytes allowed for vendor specific command parameters */
28 #define BTM_MAX_VENDOR_SPECIFIC_LEN HCI_COMMAND_SIZE
29 
30 /* BTM application return status codes */
31 enum {
32   BTM_SUCCESS = 0,         /* 0  Command succeeded                 */
33   BTM_CMD_STARTED,         /* 1  Command started OK.               */
34   BTM_BUSY,                /* 2  Device busy with another command  */
35   BTM_NO_RESOURCES,        /* 3  No resources to issue command     */
36   BTM_MODE_UNSUPPORTED,    /* 4  Request for 1 or more unsupported modes */
37   BTM_ILLEGAL_VALUE,       /* 5  Illegal parameter value           */
38   BTM_WRONG_MODE,          /* 6  Device in wrong mode for request  */
39   BTM_UNKNOWN_ADDR,        /* 7  Unknown remote BD address         */
40   BTM_DEVICE_TIMEOUT,      /* 8  Device timeout                    */
41   BTM_BAD_VALUE_RET,       /* 9  A bad value was received from HCI */
42   BTM_ERR_PROCESSING,      /* 10 Generic error                     */
43   BTM_NOT_AUTHORIZED,      /* 11 Authorization failed              */
44   BTM_DEV_RESET,           /* 12 Device has been reset             */
45   BTM_CMD_STORED,          /* 13 request is stored in control block */
46   BTM_ILLEGAL_ACTION,      /* 14 state machine gets illegal command */
47   BTM_DELAY_CHECK,         /* 15 delay the check on encryption */
48   BTM_SCO_BAD_LENGTH,      /* 16 Bad SCO over HCI data length */
49   BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set  */
50   BTM_FAILED_ON_SECURITY,  /* 18 security failed                   */
51   BTM_REPEATED_ATTEMPTS,   /* 19 repeated attempts for LE security requests */
52   BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be
53                                      supported */
54   BTM_DEV_BLACKLISTED             /* 21 The device is Blacklisted */
55 };
56 
57 typedef uint8_t tBTM_STATUS;
58 
59 #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE)
60 typedef enum {
61   BTM_BR_ONE,         /*0 First state or BR/EDR scan 1*/
62   BTM_BLE_ONE,        /*1BLE scan 1*/
63   BTM_BR_TWO,         /*2 BR/EDR scan 2*/
64   BTM_BLE_TWO,        /*3 BLE scan 2*/
65   BTM_FINISH,         /*4 End of Interleave Scan, or normal scan*/
66   BTM_NO_INTERLEAVING /*5 No Interleaving*/
67 } btm_inq_state;
68 #endif
69 
70 /*************************
71  *  Device Control Types
72  *************************/
73 #define BTM_DEVICE_ROLE_BR 0x01
74 #define BTM_DEVICE_ROLE_DUAL 0x02
75 #define BTM_MAX_DEVICE_ROLE BTM_DEVICE_ROLE_DUAL
76 typedef uint8_t tBTM_DEVICE_ROLE;
77 
78 /* Device name of peer (may be truncated to save space in BTM database) */
79 typedef uint8_t tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1];
80 
81 /* Structure returned with local version information */
82 typedef struct {
83   uint8_t hci_version;
84   uint16_t hci_revision;
85   uint8_t lmp_version;
86   uint16_t manufacturer;
87   uint16_t lmp_subversion;
88 } tBTM_VERSION_INFO;
89 
90 /* Structure returned with Vendor Specific Command complete callback */
91 typedef struct {
92   uint16_t opcode;
93   uint16_t param_len;
94   uint8_t* p_param_buf;
95 } tBTM_VSC_CMPL;
96 
97 #define BTM_VSC_CMPL_DATA_SIZE \
98   (BTM_MAX_VENDOR_SPECIFIC_LEN + sizeof(tBTM_VSC_CMPL))
99 /**************************************************
100  *  Device Control and General Callback Functions
101  **************************************************/
102 /* Callback function for when device status changes. Appl must poll for
103  * what the new state is (BTM_IsDeviceUp). The event occurs whenever the stack
104  * has detected that the controller status has changed. This asynchronous event
105  * is enabled/disabled by calling BTM_RegisterForDeviceStatusNotif().
106 */
107 enum { BTM_DEV_STATUS_UP, BTM_DEV_STATUS_DOWN, BTM_DEV_STATUS_CMD_TOUT };
108 
109 typedef uint8_t tBTM_DEV_STATUS;
110 
111 typedef void(tBTM_DEV_STATUS_CB)(tBTM_DEV_STATUS status);
112 
113 /* Callback function for when a vendor specific event occurs. The length and
114  * array of returned parameter bytes are included. This asynchronous event
115  * is enabled/disabled by calling BTM_RegisterForVSEvents().
116 */
117 typedef void(tBTM_VS_EVT_CB)(uint8_t len, uint8_t* p);
118 
119 /* General callback function for notifying an application that a synchronous
120  * BTM function is complete. The pointer contains the address of any returned
121  * data.
122  */
123 typedef void(tBTM_CMPL_CB)(void* p1);
124 
125 /* VSC callback function for notifying an application that a synchronous
126  * BTM function is complete. The pointer contains the address of any returned
127  * data.
128  */
129 typedef void(tBTM_VSC_CMPL_CB)(tBTM_VSC_CMPL* p1);
130 
131 /* Callback for apps to check connection and inquiry filters.
132  * Parameters are the BD Address of remote and the Dev Class of remote. If the
133  * app returns none zero, the connection or inquiry result will be dropped.
134 */
135 typedef uint8_t(tBTM_FILTER_CB)(const RawAddress& bd_addr, DEV_CLASS dc);
136 
137 /*****************************************************************************
138  *  DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
139  ****************************************************************************/
140 /*******************************
141  *  Device Discovery Constants
142  *******************************/
143 /* Discoverable modes */
144 #define BTM_NON_DISCOVERABLE 0
145 #define BTM_LIMITED_DISCOVERABLE 1
146 #define BTM_GENERAL_DISCOVERABLE 2
147 #define BTM_DISCOVERABLE_MASK \
148   (BTM_LIMITED_DISCOVERABLE | BTM_GENERAL_DISCOVERABLE)
149 #define BTM_MAX_DISCOVERABLE BTM_GENERAL_DISCOVERABLE
150 /* high byte for BLE Discoverable modes */
151 #define BTM_BLE_NON_DISCOVERABLE 0x0000
152 #define BTM_BLE_LIMITED_DISCOVERABLE 0x0100
153 #define BTM_BLE_GENERAL_DISCOVERABLE 0x0200
154 #define BTM_BLE_MAX_DISCOVERABLE BTM_BLE_GENERAL_DISCOVERABLE
155 #define BTM_BLE_DISCOVERABLE_MASK                            \
156   (BTM_BLE_NON_DISCOVERABLE | BTM_BLE_LIMITED_DISCOVERABLE | \
157    BTM_BLE_GENERAL_DISCOVERABLE)
158 
159 /* Connectable modes */
160 #define BTM_NON_CONNECTABLE 0
161 #define BTM_CONNECTABLE 1
162 #define BTM_CONNECTABLE_MASK (BTM_NON_CONNECTABLE | BTM_CONNECTABLE)
163 /* high byte for BLE Connectable modes */
164 #define BTM_BLE_NON_CONNECTABLE 0x0000
165 #define BTM_BLE_CONNECTABLE 0x0100
166 #define BTM_BLE_MAX_CONNECTABLE BTM_BLE_CONNECTABLE
167 #define BTM_BLE_CONNECTABLE_MASK (BTM_BLE_NON_CONNECTABLE | BTM_BLE_CONNECTABLE)
168 
169 /* Inquiry modes
170  * Note: These modes are associated with the inquiry active values (BTM_*ACTIVE)
171  */
172 #define BTM_INQUIRY_NONE 0
173 #define BTM_GENERAL_INQUIRY 0x01
174 #define BTM_LIMITED_INQUIRY 0x02
175 #define BTM_BR_INQUIRY_MASK (BTM_GENERAL_INQUIRY | BTM_LIMITED_INQUIRY)
176 
177 /* high byte of inquiry mode for BLE inquiry mode */
178 #define BTM_BLE_INQUIRY_NONE 0x00
179 #define BTM_BLE_GENERAL_INQUIRY 0x10
180 #define BTM_BLE_LIMITED_INQUIRY 0x20
181 #define BTM_BLE_INQUIRY_MASK (BTM_BLE_GENERAL_INQUIRY | BTM_BLE_LIMITED_INQUIRY)
182 
183 /* BTM_IsInquiryActive return values (Bit Mask)
184  * Note: These bit masks are associated with the inquiry modes (BTM_*_INQUIRY)
185  */
186 /* no inquiry in progress */
187 #define BTM_INQUIRY_INACTIVE 0x0
188 /* a general inquiry is in progress */
189 #define BTM_GENERAL_INQUIRY_ACTIVE BTM_GENERAL_INQUIRY
190 /* a limited inquiry is in progress */
191 #define BTM_LIMITED_INQUIRY_ACTIVE BTM_LIMITED_INQUIRY
192 /* a periodic inquiry is active */
193 #define BTM_PERIODIC_INQUIRY_ACTIVE 0x8
194 /* SSP is active, so inquiry is disallowed (work around for FW bug) */
195 #define BTM_SSP_INQUIRY_ACTIVE 0x4
196 /* a general inquiry is in progress */
197 #define BTM_LE_GENERAL_INQUIRY_ACTIVE BTM_BLE_GENERAL_INQUIRY
198 /* a limited inquiry is in progress */
199 #define BTM_LE_LIMITED_INQUIRY_ACTIVE BTM_BLE_LIMITED_INQUIRY
200 
201 /* inquiry activity mask */
202 /* BR/EDR inquiry activity mask */
203 #define BTM_BR_INQ_ACTIVE_MASK                               \
204   (BTM_GENERAL_INQUIRY_ACTIVE | BTM_LIMITED_INQUIRY_ACTIVE | \
205    BTM_PERIODIC_INQUIRY_ACTIVE)
206 /* LE scan activity mask */
207 #define BTM_BLE_SCAN_ACTIVE_MASK 0xF0
208 /* LE inquiry activity mask*/
209 #define BTM_BLE_INQ_ACTIVE_MASK \
210   (BTM_LE_GENERAL_INQUIRY_ACTIVE | BTM_LE_LIMITED_INQUIRY_ACTIVE)
211 /* inquiry activity mask */
212 #define BTM_INQUIRY_ACTIVE_MASK \
213   (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK)
214 
215 /* Define scan types */
216 #define BTM_SCAN_TYPE_STANDARD 0
217 #define BTM_SCAN_TYPE_INTERLACED 1 /* 1.2 devices only */
218 
219 /* Define inquiry results mode */
220 #define BTM_INQ_RESULT_STANDARD 0
221 #define BTM_INQ_RESULT_WITH_RSSI 1
222 #define BTM_INQ_RESULT_EXTENDED 2
223 /* RSSI value not supplied (ignore it) */
224 #define BTM_INQ_RES_IGNORE_RSSI 0x7f
225 
226 /* Inquiry Filter Condition types (see tBTM_INQ_PARMS) */
227 /* Inquiry Filtering is turned off */
228 #define BTM_CLR_INQUIRY_FILTER 0
229 /* Filter on device class */
230 #define BTM_FILTER_COND_DEVICE_CLASS HCI_FILTER_COND_DEVICE_CLASS
231 /* Filter on device addr */
232 #define BTM_FILTER_COND_BD_ADDR HCI_FILTER_COND_BD_ADDR
233 
234 /* State of the remote name retrieval during inquiry operations.
235  * Used in the tBTM_INQ_INFO structure, and returned in the
236  * BTM_InqDbRead, BTM_InqDbFirst, and BTM_InqDbNext functions.
237  * The name field is valid when the state returned is
238  * BTM_INQ_RMT_NAME_DONE */
239 #define BTM_INQ_RMT_NAME_EMPTY 0
240 #define BTM_INQ_RMT_NAME_PENDING 1
241 #define BTM_INQ_RMT_NAME_DONE 2
242 #define BTM_INQ_RMT_NAME_FAILED 3
243 
244 /*********************************
245  *** Class of Device constants ***
246  *********************************/
247 #define BTM_FORMAT_TYPE_1 0x00
248 
249 /****************************
250  * minor device class field
251  ****************************/
252 
253 /* 0x00 is used as unclassified for all minor device classes */
254 #define BTM_COD_MINOR_UNCLASSIFIED 0x00
255 
256 /* minor device class field for Computer Major Class */
257 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
258 #define BTM_COD_MINOR_DESKTOP_WORKSTATION 0x04
259 #define BTM_COD_MINOR_SERVER_COMPUTER 0x08
260 #define BTM_COD_MINOR_LAPTOP 0x0C
261 #define BTM_COD_MINOR_HANDHELD_PC_PDA 0x10 /* clam shell */
262 #define BTM_COD_MINOR_PALM_SIZE_PC_PDA 0x14
263 #define BTM_COD_MINOR_WEARABLE_COMPUTER 0x18 /* watch sized */
264 
265 /* minor device class field for Phone Major Class */
266 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
267 #define BTM_COD_MINOR_CELLULAR 0x04
268 #define BTM_COD_MINOR_CORDLESS 0x08
269 #define BTM_COD_MINOR_SMART_PHONE 0x0C
270 /* wired modem or voice gatway */
271 #define BTM_COD_MINOR_WIRED_MDM_V_GTWY 0x10
272 #define BTM_COD_MINOR_ISDN_ACCESS 0x14
273 
274 /* minor device class field for LAN Access Point Major Class */
275 /* Load Factor Field bit 5-7 */
276 #define BTM_COD_MINOR_FULLY_AVAILABLE 0x00
277 #define BTM_COD_MINOR_1_17_UTILIZED 0x20
278 #define BTM_COD_MINOR_17_33_UTILIZED 0x40
279 #define BTM_COD_MINOR_33_50_UTILIZED 0x60
280 #define BTM_COD_MINOR_50_67_UTILIZED 0x80
281 #define BTM_COD_MINOR_67_83_UTILIZED 0xA0
282 #define BTM_COD_MINOR_83_99_UTILIZED 0xC0
283 #define BTM_COD_MINOR_NO_SERVICE_AVAILABLE 0xE0
284 /* sub-Field bit 2-4 */
285 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
286 
287 /* minor device class field for Audio/Video Major Class */
288 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
289 #define BTM_COD_MINOR_CONFM_HEADSET 0x04
290 #define BTM_COD_MINOR_CONFM_HANDSFREE 0x08
291 #define BTM_COD_MINOR_MICROPHONE 0x10
292 #define BTM_COD_MINOR_LOUDSPEAKER 0x14
293 #define BTM_COD_MINOR_HEADPHONES 0x18
294 #define BTM_COD_MINOR_PORTABLE_AUDIO 0x1C
295 #define BTM_COD_MINOR_CAR_AUDIO 0x20
296 #define BTM_COD_MINOR_SET_TOP_BOX 0x24
297 #define BTM_COD_MINOR_HIFI_AUDIO 0x28
298 #define BTM_COD_MINOR_VCR 0x2C
299 #define BTM_COD_MINOR_VIDEO_CAMERA 0x30
300 #define BTM_COD_MINOR_CAMCORDER 0x34
301 #define BTM_COD_MINOR_VIDEO_MONITOR 0x38
302 #define BTM_COD_MINOR_VIDDISP_LDSPKR 0x3C
303 #define BTM_COD_MINOR_VIDEO_CONFERENCING 0x40
304 #define BTM_COD_MINOR_GAMING_TOY 0x48
305 
306 /* minor device class field for Peripheral Major Class */
307 /* Bits 6-7 independently specify mouse, keyboard, or combo mouse/keyboard */
308 #define BTM_COD_MINOR_KEYBOARD 0x40
309 #define BTM_COD_MINOR_POINTING 0x80
310 #define BTM_COD_MINOR_COMBO 0xC0
311 /* Bits 2-5 OR'd with selection from bits 6-7 */
312 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
313 #define BTM_COD_MINOR_JOYSTICK 0x04
314 #define BTM_COD_MINOR_GAMEPAD 0x08
315 #define BTM_COD_MINOR_REMOTE_CONTROL 0x0C
316 #define BTM_COD_MINOR_SENSING_DEVICE 0x10
317 #define BTM_COD_MINOR_DIGITIZING_TABLET 0x14
318 #define BTM_COD_MINOR_CARD_READER 0x18 /* e.g. SIM card reader */
319 #define BTM_COD_MINOR_DIGITAL_PAN 0x1C
320 #define BTM_COD_MINOR_HAND_SCANNER 0x20
321 #define BTM_COD_MINOR_HAND_GESTURAL_INPUT 0x24
322 
323 /* minor device class field for Imaging Major Class */
324 /* Bits 5-7 independently specify display, camera, scanner, or printer */
325 #define BTM_COD_MINOR_DISPLAY 0x10
326 #define BTM_COD_MINOR_CAMERA 0x20
327 #define BTM_COD_MINOR_SCANNER 0x40
328 #define BTM_COD_MINOR_PRINTER 0x80
329 /* Bits 2-3 Reserved */
330 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
331 
332 /* minor device class field for Wearable Major Class */
333 /* Bits 2-7 meaningful    */
334 #define BTM_COD_MINOR_WRIST_WATCH 0x04
335 #define BTM_COD_MINOR_PAGER 0x08
336 #define BTM_COD_MINOR_JACKET 0x0C
337 #define BTM_COD_MINOR_HELMET 0x10
338 #define BTM_COD_MINOR_GLASSES 0x14
339 
340 /* minor device class field for Toy Major Class */
341 /* Bits 2-7 meaningful    */
342 #define BTM_COD_MINOR_ROBOT 0x04
343 #define BTM_COD_MINOR_VEHICLE 0x08
344 #define BTM_COD_MINOR_DOLL_ACTION_FIGURE 0x0C
345 #define BTM_COD_MINOR_CONTROLLER 0x10
346 #define BTM_COD_MINOR_GAME 0x14
347 
348 /* minor device class field for Health Major Class */
349 /* Bits 2-7 meaningful    */
350 #define BTM_COD_MINOR_BLOOD_MONITOR 0x04
351 #define BTM_COD_MINOR_THERMOMETER 0x08
352 #define BTM_COD_MINOR_WEIGHING_SCALE 0x0C
353 #define BTM_COD_MINOR_GLUCOSE_METER 0x10
354 #define BTM_COD_MINOR_PULSE_OXIMETER 0x14
355 #define BTM_COD_MINOR_HEART_PULSE_MONITOR 0x18
356 #define BTM_COD_MINOR_HEALTH_DATA_DISPLAY 0x1C
357 #define BTM_COD_MINOR_STEP_COUNTER 0x20
358 #define BTM_COD_MINOR_BODY_COM_ANALYZER 0x24
359 #define BTM_COD_MINOR_PEAK_FLOW_MONITOR 0x28
360 #define BTM_COD_MINOR_MEDICATION_MONITOR 0x2C
361 #define BTM_COD_MINOR_KNEE_PROSTHESIS 0x30
362 #define BTM_COD_MINOR_ANKLE_PROSTHESIS 0x34
363 
364 /***************************
365  * major device class field
366  ***************************/
367 #define BTM_COD_MAJOR_MISCELLANEOUS 0x00
368 #define BTM_COD_MAJOR_COMPUTER 0x01
369 #define BTM_COD_MAJOR_PHONE 0x02
370 #define BTM_COD_MAJOR_LAN_ACCESS_PT 0x03
371 #define BTM_COD_MAJOR_AUDIO 0x04
372 #define BTM_COD_MAJOR_PERIPHERAL 0x05
373 #define BTM_COD_MAJOR_IMAGING 0x06
374 #define BTM_COD_MAJOR_WEARABLE 0x07
375 #define BTM_COD_MAJOR_TOY 0x08
376 #define BTM_COD_MAJOR_HEALTH 0x09
377 #define BTM_COD_MAJOR_UNCLASSIFIED 0x1F
378 
379 /***************************
380  * service class fields
381  ***************************/
382 #define BTM_COD_SERVICE_LMTD_DISCOVER 0x0020
383 #define BTM_COD_SERVICE_POSITIONING 0x0100
384 #define BTM_COD_SERVICE_NETWORKING 0x0200
385 #define BTM_COD_SERVICE_RENDERING 0x0400
386 #define BTM_COD_SERVICE_CAPTURING 0x0800
387 #define BTM_COD_SERVICE_OBJ_TRANSFER 0x1000
388 #define BTM_COD_SERVICE_AUDIO 0x2000
389 #define BTM_COD_SERVICE_TELEPHONY 0x4000
390 #define BTM_COD_SERVICE_INFORMATION 0x8000
391 
392 /* class of device field macros */
393 #define BTM_COD_FORMAT_TYPE(u8, pd) \
394   { (u8) = (pd)[2] & 0x03; }
395 #define BTM_COD_MINOR_CLASS(u8, pd) \
396   { (u8) = (pd)[2] & 0xFC; }
397 #define BTM_COD_MAJOR_CLASS(u8, pd) \
398   { (u8) = (pd)[1] & 0x1F; }
399 #define BTM_COD_SERVICE_CLASS(u16, pd) \
400   {                                    \
401     (u16) = (pd)[0];                   \
402     (u16) <<= 8;                       \
403     (u16) += (pd)[1] & 0xE0;           \
404   }
405 
406 /* to set the fields (assumes that format type is always 0) */
407 #define FIELDS_TO_COD(pd, mn, mj, sv)                   \
408   {                                                     \
409     (pd)[2] = mn;                                       \
410     (pd)[1] = (mj) + ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \
411     (pd)[0] = (sv) >> 8;                                \
412   }
413 
414 /* the COD masks */
415 #define BTM_COD_FORMAT_TYPE_MASK 0x03
416 #define BTM_COD_MINOR_CLASS_MASK 0xFC
417 #define BTM_COD_MAJOR_CLASS_MASK 0x1F
418 #define BTM_COD_SERVICE_CLASS_LO_B 0x00E0
419 #define BTM_COD_SERVICE_CLASS_MASK 0xFFE0
420 
421 /* BTM service definitions
422  * Used for storing EIR data to bit mask
423 */
424 enum {
425   BTM_EIR_UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER,
426   /*    BTM_EIR_UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR,   */
427   /*    BTM_EIR_UUID_SERVCLASS_PUBLIC_BROWSE_GROUP,       */
428   BTM_EIR_UUID_SERVCLASS_SERIAL_PORT,
429   BTM_EIR_UUID_SERVCLASS_LAN_ACCESS_USING_PPP,
430   BTM_EIR_UUID_SERVCLASS_DIALUP_NETWORKING,
431   BTM_EIR_UUID_SERVCLASS_IRMC_SYNC,
432   BTM_EIR_UUID_SERVCLASS_OBEX_OBJECT_PUSH,
433   BTM_EIR_UUID_SERVCLASS_OBEX_FILE_TRANSFER,
434   BTM_EIR_UUID_SERVCLASS_IRMC_SYNC_COMMAND,
435   BTM_EIR_UUID_SERVCLASS_HEADSET,
436   BTM_EIR_UUID_SERVCLASS_CORDLESS_TELEPHONY,
437   BTM_EIR_UUID_SERVCLASS_AUDIO_SOURCE,
438   BTM_EIR_UUID_SERVCLASS_AUDIO_SINK,
439   BTM_EIR_UUID_SERVCLASS_AV_REM_CTRL_TARGET,
440   /*    BTM_EIR_UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION,    */
441   BTM_EIR_UUID_SERVCLASS_AV_REMOTE_CONTROL,
442   /*    BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING,        */
443   BTM_EIR_UUID_SERVCLASS_INTERCOM,
444   BTM_EIR_UUID_SERVCLASS_FAX,
445   BTM_EIR_UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY,
446   /*    BTM_EIR_UUID_SERVCLASS_WAP,                       */
447   /*    BTM_EIR_UUID_SERVCLASS_WAP_CLIENT,                */
448   BTM_EIR_UUID_SERVCLASS_PANU,
449   BTM_EIR_UUID_SERVCLASS_NAP,
450   BTM_EIR_UUID_SERVCLASS_GN,
451   BTM_EIR_UUID_SERVCLASS_DIRECT_PRINTING,
452   /*    BTM_EIR_UUID_SERVCLASS_REFERENCE_PRINTING,        */
453   BTM_EIR_UUID_SERVCLASS_IMAGING,
454   BTM_EIR_UUID_SERVCLASS_IMAGING_RESPONDER,
455   BTM_EIR_UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE,
456   BTM_EIR_UUID_SERVCLASS_IMAGING_REF_OBJECTS,
457   BTM_EIR_UUID_SERVCLASS_HF_HANDSFREE,
458   BTM_EIR_UUID_SERVCLASS_AG_HANDSFREE,
459   BTM_EIR_UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE,
460   /*    BTM_EIR_UUID_SERVCLASS_REFLECTED_UI,              */
461   BTM_EIR_UUID_SERVCLASS_BASIC_PRINTING,
462   BTM_EIR_UUID_SERVCLASS_PRINTING_STATUS,
463   BTM_EIR_UUID_SERVCLASS_HUMAN_INTERFACE,
464   BTM_EIR_UUID_SERVCLASS_CABLE_REPLACEMENT,
465   BTM_EIR_UUID_SERVCLASS_HCRP_PRINT,
466   BTM_EIR_UUID_SERVCLASS_HCRP_SCAN,
467   /*    BTM_EIR_UUID_SERVCLASS_COMMON_ISDN_ACCESS,        */
468   /*    BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING_GW,     */
469   /*    BTM_EIR_UUID_SERVCLASS_UDI_MT,                    */
470   /*    BTM_EIR_UUID_SERVCLASS_UDI_TA,                    */
471   /*    BTM_EIR_UUID_SERVCLASS_VCP,                       */
472   BTM_EIR_UUID_SERVCLASS_SAP,
473   BTM_EIR_UUID_SERVCLASS_PBAP_PCE,
474   BTM_EIR_UUID_SERVCLASS_PBAP_PSE,
475   /*    BTM_EIR_UUID_SERVCLASS_TE_PHONE_ACCESS,           */
476   /*    BTM_EIR_UUID_SERVCLASS_ME_PHONE_ACCESS,           */
477   BTM_EIR_UUID_SERVCLASS_PHONE_ACCESS,
478   BTM_EIR_UUID_SERVCLASS_HEADSET_HS,
479   BTM_EIR_UUID_SERVCLASS_PNP_INFORMATION,
480   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_NETWORKING,        */
481   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_FILETRANSFER,      */
482   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_AUDIO,             */
483   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_TELEPHONY,         */
484   /*    BTM_EIR_UUID_SERVCLASS_UPNP_SERVICE,              */
485   /*    BTM_EIR_UUID_SERVCLASS_UPNP_IP_SERVICE,           */
486   /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_PAN,          */
487   /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_LAP,          */
488   /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP,        */
489   BTM_EIR_UUID_SERVCLASS_VIDEO_SOURCE,
490   BTM_EIR_UUID_SERVCLASS_VIDEO_SINK,
491   /*    BTM_EIR_UUID_SERVCLASS_VIDEO_DISTRIBUTION         */
492   /*    BTM_EIR_UUID_SERVCLASS_HDP_PROFILE                */
493   BTM_EIR_UUID_SERVCLASS_MESSAGE_ACCESS,
494   BTM_EIR_UUID_SERVCLASS_MESSAGE_NOTIFICATION,
495   BTM_EIR_UUID_SERVCLASS_HDP_SOURCE,
496   BTM_EIR_UUID_SERVCLASS_HDP_SINK,
497   BTM_EIR_MAX_SERVICES
498 };
499 
500 /* search result in EIR of inquiry database */
501 #define BTM_EIR_FOUND 0
502 #define BTM_EIR_NOT_FOUND 1
503 #define BTM_EIR_UNKNOWN 2
504 
505 typedef uint8_t tBTM_EIR_SEARCH_RESULT;
506 
507 /* 0x01 */
508 #define BTM_EIR_FLAGS_TYPE HCI_EIR_FLAGS_TYPE
509 /* 0x02 */
510 #define BTM_EIR_MORE_16BITS_UUID_TYPE HCI_EIR_MORE_16BITS_UUID_TYPE
511 /* 0x03 */
512 #define BTM_EIR_COMPLETE_16BITS_UUID_TYPE HCI_EIR_COMPLETE_16BITS_UUID_TYPE
513 /* 0x04 */
514 #define BTM_EIR_MORE_32BITS_UUID_TYPE HCI_EIR_MORE_32BITS_UUID_TYPE
515 /* 0x05 */
516 #define BTM_EIR_COMPLETE_32BITS_UUID_TYPE HCI_EIR_COMPLETE_32BITS_UUID_TYPE
517 /* 0x06 */
518 #define BTM_EIR_MORE_128BITS_UUID_TYPE HCI_EIR_MORE_128BITS_UUID_TYPE
519 /* 0x07 */
520 #define BTM_EIR_COMPLETE_128BITS_UUID_TYPE HCI_EIR_COMPLETE_128BITS_UUID_TYPE
521 /* 0x08 */
522 #define BTM_EIR_SHORTENED_LOCAL_NAME_TYPE HCI_EIR_SHORTENED_LOCAL_NAME_TYPE
523 /* 0x09 */
524 #define BTM_EIR_COMPLETE_LOCAL_NAME_TYPE HCI_EIR_COMPLETE_LOCAL_NAME_TYPE
525 /* 0x0A */
526 #define BTM_EIR_TX_POWER_LEVEL_TYPE HCI_EIR_TX_POWER_LEVEL_TYPE
527 /* 0xFF */
528 #define BTM_EIR_MANUFACTURER_SPECIFIC_TYPE HCI_EIR_MANUFACTURER_SPECIFIC_TYPE
529 
530 /* the following EIR tags are defined to OOB, not regular EIR data */
531 /* 6 bytes */
532 #define BTM_EIR_OOB_BD_ADDR_TYPE HCI_EIR_OOB_BD_ADDR_TYPE
533 /* 3 bytes */
534 #define BTM_EIR_OOB_COD_TYPE HCI_EIR_OOB_COD_TYPE
535 /* 16 bytes */
536 #define BTM_EIR_OOB_SSP_HASH_C_TYPE HCI_EIR_OOB_SSP_HASH_C_TYPE
537 /* 16 bytes */
538 #define BTM_EIR_OOB_SSP_RAND_R_TYPE HCI_EIR_OOB_SSP_RAND_R_TYPE
539 
540 /* include 2 bytes length & 6 bytes bd_addr */
541 #define BTM_OOB_MANDATORY_SIZE 8
542 #define BTM_OOB_DATA_LEN_SIZE 2
543 #define BTM_OOB_BD_ADDR_SIZE 6
544 #define BTM_OOB_COD_SIZE BT_OOB_COD_SIZE
545 #define BTM_OOB_HASH_C_SIZE BT_OOB_HASH_C_SIZE
546 #define BTM_OOB_RAND_R_SIZE BT_OOB_RAND_R_SIZE
547 
548 #define BTM_BLE_SEC_NONE 0
549 /* encrypt the link using current key */
550 #define BTM_BLE_SEC_ENCRYPT 1
551 #define BTM_BLE_SEC_ENCRYPT_NO_MITM 2
552 #define BTM_BLE_SEC_ENCRYPT_MITM 3
553 typedef uint8_t tBTM_BLE_SEC_ACT;
554 
555 /*******************************************************************************
556  * BTM Services MACROS handle array of uint32_t bits for more than 32 services
557  ******************************************************************************/
558 /* Determine the number of uint32_t's necessary for services */
559 #define BTM_EIR_ARRAY_BITS 32 /* Number of bits in each array element */
560 #define BTM_EIR_SERVICE_ARRAY_SIZE                         \
561   (((uint32_t)BTM_EIR_MAX_SERVICES / BTM_EIR_ARRAY_BITS) + \
562    (((uint32_t)BTM_EIR_MAX_SERVICES % BTM_EIR_ARRAY_BITS) ? 1 : 0))
563 
564 /* MACRO to set the service bit mask in a bit stream */
565 #define BTM_EIR_SET_SERVICE(p, service)                              \
566   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] |= \
567    ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS)))
568 
569 /* MACRO to clear the service bit mask in a bit stream */
570 #define BTM_EIR_CLR_SERVICE(p, service)                              \
571   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] &= \
572    ~((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS)))
573 
574 /* MACRO to check the service bit mask in a bit stream */
575 #define BTM_EIR_HAS_SERVICE(p, service)                               \
576   ((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] &  \
577     ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) >> \
578    (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))
579 
580 /* start of EIR in HCI buffer, 4 bytes = HCI Command(2) + Length(1) + FEC_Req(1)
581  */
582 #define BTM_HCI_EIR_OFFSET (BT_HDR_SIZE + 4)
583 
584 /***************************
585  *  Device Discovery Types
586  ***************************/
587 /* Definitions of the parameters passed to BTM_StartInquiry and
588  * BTM_SetPeriodicInquiryMode.
589 */
590 typedef struct /* contains the two device class condition fields */
591 {
592   DEV_CLASS dev_class;
593   DEV_CLASS dev_class_mask;
594 } tBTM_COD_COND;
595 
596 typedef union /* contains the inquiry filter condition */
597 {
598   RawAddress bdaddr_cond;
599   tBTM_COD_COND cod_cond;
600 } tBTM_INQ_FILT_COND;
601 
602 typedef struct /* contains the parameters passed to the inquiry functions */
603 {
604   uint8_t mode;      /* general or limited */
605   uint8_t duration;  /* duration of the inquiry (1.28 sec increments) */
606   uint8_t max_resps; /* maximum number of responses to return */
607   bool report_dup; /* report duplicated inquiry response with higher RSSI value
608                       */
609   uint8_t filter_cond_type; /* new devices, BD ADDR, COD, or No filtering */
610   tBTM_INQ_FILT_COND filter_cond; /* filter value based on filter cond type */
611 #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE)
612   uint8_t intl_duration
613       [4]; /*duration array storing the interleave scan's time portions*/
614 #endif
615 } tBTM_INQ_PARMS;
616 
617 #define BTM_INQ_RESULT_BR 0x01
618 #define BTM_INQ_RESULT_BLE 0x02
619 
620 constexpr uint8_t BLE_EVT_CONNECTABLE_BIT = 0;
621 constexpr uint8_t BLE_EVT_SCANNABLE_BIT = 1;
622 constexpr uint8_t BLE_EVT_DIRECTED_BIT = 2;
623 constexpr uint8_t BLE_EVT_SCAN_RESPONSE_BIT = 3;
624 constexpr uint8_t BLE_EVT_LEGACY_BIT = 4;
625 
626 constexpr uint8_t PHY_LE_NO_PACKET = 0x00;
627 constexpr uint8_t PHY_LE_1M = 0x01;
628 constexpr uint8_t PHY_LE_2M = 0x02;
629 constexpr uint8_t PHY_LE_CODED = 0x03;
630 
631 constexpr uint8_t NO_ADI_PRESENT = 0xFF;
632 constexpr uint8_t TX_POWER_NOT_PRESENT = 0x7F;
633 
634 /* These are the fields returned in each device's response to the inquiry.  It
635  * is returned in the results callback if registered.
636 */
637 typedef struct {
638   uint16_t clock_offset;
639   RawAddress remote_bd_addr;
640   DEV_CLASS dev_class;
641   uint8_t page_scan_rep_mode;
642   uint8_t page_scan_per_mode;
643   uint8_t page_scan_mode;
644   int8_t rssi; /* Set to BTM_INQ_RES_IGNORE_RSSI if  not valid */
645   uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE];
646   bool eir_complete_list;
647   tBT_DEVICE_TYPE device_type;
648   uint8_t inq_result_type;
649   uint8_t ble_addr_type;
650   uint16_t ble_evt_type;
651   uint8_t ble_primary_phy;
652   uint8_t ble_secondary_phy;
653   uint8_t ble_advertising_sid;
654   int8_t ble_tx_power;
655   uint16_t ble_periodic_adv_int;
656   uint8_t flag;
657 } tBTM_INQ_RESULTS;
658 
659 /* This is the inquiry response information held in its database by BTM, and
660  * available to applications via BTM_InqDbRead, BTM_InqDbFirst, and
661  * BTM_InqDbNext.
662 */
663 typedef struct {
664   tBTM_INQ_RESULTS results;
665 
666   bool appl_knows_rem_name; /* set by application if it knows the remote name of
667                                the peer device.
668                                This is later used by application to determine if
669                                remote name request is
670                                required to be done. Having the flag here avoid
671                                duplicate store of inquiry results */
672   uint16_t remote_name_len;
673   tBTM_BD_NAME remote_name;
674   uint8_t remote_name_state;
675   uint8_t remote_name_type;
676 
677 } tBTM_INQ_INFO;
678 
679 /* Structure returned with inquiry complete callback */
680 typedef struct {
681   tBTM_STATUS status;
682   uint8_t num_resp; /* Number of results from the current inquiry */
683 } tBTM_INQUIRY_CMPL;
684 
685 /* Structure returned with remote name  request */
686 typedef struct {
687   uint16_t status;
688   RawAddress bd_addr;
689   uint16_t length;
690   BD_NAME remote_bd_name;
691 } tBTM_REMOTE_DEV_NAME;
692 
693 typedef struct {
694   uint8_t pcm_intf_rate; /* PCM interface rate: 0: 128kbps, 1: 256 kbps;
695                              2:512 bps; 3: 1024kbps; 4: 2048kbps */
696   uint8_t frame_type;    /* frame type: 0: short; 1: long */
697   uint8_t sync_mode;     /* sync mode: 0: slave; 1: master */
698   uint8_t clock_mode;    /* clock mode: 0: slave; 1: master */
699 
700 } tBTM_SCO_PCM_PARAM;
701 
702 /****************************************
703  *  Device Discovery Callback Functions
704  ****************************************/
705 /* Callback function for asynchronous notifications when the BTM inquiry DB
706  * changes. First param is inquiry database, second is if added to or removed
707  * from the inquiry database.
708 */
709 typedef void(tBTM_INQ_DB_CHANGE_CB)(void* p1, bool is_new);
710 
711 /* Callback function for notifications when the BTM gets inquiry response.
712  * First param is inquiry results database, second is pointer of EIR.
713 */
714 typedef void(tBTM_INQ_RESULTS_CB)(tBTM_INQ_RESULTS* p_inq_results,
715                                   uint8_t* p_eir, uint16_t eir_len);
716 
717 /*****************************************************************************
718  *  ACL CHANNEL MANAGEMENT
719  ****************************************************************************/
720 /******************
721  *  ACL Constants
722  ******************/
723 
724 /* ACL modes */
725 #define BTM_ACL_MODE_NORMAL HCI_MODE_ACTIVE
726 #define BTM_ACL_MODE_HOLD HCI_MODE_HOLD
727 #define BTM_ACL_MODE_SNIFF HCI_MODE_SNIFF
728 #define BTM_ACL_MODE_PARK HCI_MODE_PARK
729 
730 /* Returned with structure in role switch callback (tBTM_ROLE_SWITCH_CMPL) */
731 #define BTM_ROLE_MASTER HCI_ROLE_MASTER
732 #define BTM_ROLE_SLAVE HCI_ROLE_SLAVE
733 #define BTM_ROLE_UNDEFINED 0xff /* undefined value (error status) */
734 
735 /* ACL Packet Types */
736 #define BTM_ACL_PKT_TYPES_MASK_DM1 HCI_PKT_TYPES_MASK_DM1
737 #define BTM_ACL_PKT_TYPES_MASK_DH1 HCI_PKT_TYPES_MASK_DH1
738 #define BTM_ACL_PKT_TYPES_MASK_DM3 HCI_PKT_TYPES_MASK_DM3
739 #define BTM_ACL_PKT_TYPES_MASK_DH3 HCI_PKT_TYPES_MASK_DH3
740 #define BTM_ACL_PKT_TYPES_MASK_DM5 HCI_PKT_TYPES_MASK_DM5
741 #define BTM_ACL_PKT_TYPES_MASK_DH5 HCI_PKT_TYPES_MASK_DH5
742 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 HCI_PKT_TYPES_MASK_NO_2_DH1
743 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 HCI_PKT_TYPES_MASK_NO_3_DH1
744 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 HCI_PKT_TYPES_MASK_NO_2_DH3
745 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 HCI_PKT_TYPES_MASK_NO_3_DH3
746 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 HCI_PKT_TYPES_MASK_NO_2_DH5
747 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH5 HCI_PKT_TYPES_MASK_NO_3_DH5
748 
749 /***************
750  *  ACL Types
751  ***************/
752 
753 /* Structure returned with Role Switch information (in tBTM_CMPL_CB callback
754  * function) in response to BTM_SwitchRole call.
755 */
756 typedef struct {
757   uint8_t hci_status;     /* HCI status returned with the event */
758   uint8_t role;           /* BTM_ROLE_MASTER or BTM_ROLE_SLAVE */
759   RawAddress remote_bd_addr; /* Remote BD addr involved with the switch */
760 } tBTM_ROLE_SWITCH_CMPL;
761 
762 /* Structure returned with QoS information (in tBTM_CMPL_CB callback function)
763  * in response to BTM_SetQoS call.
764 */
765 typedef struct {
766   FLOW_SPEC flow;
767   uint16_t handle;
768   uint8_t status;
769 } tBTM_QOS_SETUP_CMPL;
770 
771 /* Structure returned with read RSSI event (in tBTM_CMPL_CB callback function)
772  * in response to BTM_ReadRSSI call.
773 */
774 typedef struct {
775   tBTM_STATUS status;
776   uint8_t hci_status;
777   int8_t rssi;
778   RawAddress rem_bda;
779 } tBTM_RSSI_RESULT;
780 
781 /* Structure returned with read failed contact counter event
782  * (in tBTM_CMPL_CB callback function) in response to
783  * BTM_ReadFailedContactCounter call.
784  */
785 typedef struct {
786   tBTM_STATUS status;
787   uint8_t hci_status;
788   uint16_t failed_contact_counter;
789   RawAddress rem_bda;
790 } tBTM_FAILED_CONTACT_COUNTER_RESULT;
791 
792 /* Structure returned with read automatic flush timeout event
793  * (in tBTM_CMPL_CB callback function) in response to
794  * BTM_ReadAutomaticFlushTimeout call.
795  */
796 typedef struct {
797   tBTM_STATUS status;
798   uint8_t hci_status;
799   uint16_t automatic_flush_timeout;
800   RawAddress rem_bda;
801 } tBTM_AUTOMATIC_FLUSH_TIMEOUT_RESULT;
802 
803 /* Structure returned with read current TX power event (in tBTM_CMPL_CB callback
804  * function) in response to BTM_ReadTxPower call.
805 */
806 typedef struct {
807   tBTM_STATUS status;
808   uint8_t hci_status;
809   int8_t tx_power;
810   RawAddress rem_bda;
811 } tBTM_TX_POWER_RESULT;
812 
813 /* Structure returned with read link quality event (in tBTM_CMPL_CB callback
814  * function) in response to BTM_ReadLinkQuality call.
815 */
816 typedef struct {
817   tBTM_STATUS status;
818   uint8_t hci_status;
819   uint8_t link_quality;
820   RawAddress rem_bda;
821 } tBTM_LINK_QUALITY_RESULT;
822 
823 /* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB
824  * callback function) in response to BTM_ReadInquiryRspTxPower call.
825 */
826 typedef struct {
827   tBTM_STATUS status;
828   uint8_t hci_status;
829   int8_t tx_power;
830 } tBTM_INQ_TXPWR_RESULT;
831 
832 enum {
833   BTM_BL_CONN_EVT,
834   BTM_BL_DISCN_EVT,
835   BTM_BL_UPDATE_EVT,
836   BTM_BL_ROLE_CHG_EVT,
837   BTM_BL_COLLISION_EVT
838 };
839 typedef uint8_t tBTM_BL_EVENT;
840 typedef uint16_t tBTM_BL_EVENT_MASK;
841 
842 #define BTM_BL_CONN_MASK 0x0001
843 #define BTM_BL_DISCN_MASK 0x0002
844 #define BTM_BL_UPDATE_MASK 0x0004
845 #define BTM_BL_ROLE_CHG_MASK 0x0008
846 
847 /* Device features mask definitions */
848 #define BTM_FEATURE_BYTES_PER_PAGE HCI_FEATURE_BYTES_PER_PAGE
849 #define BTM_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_MAX
850 
851 /* the data type associated with BTM_BL_CONN_EVT */
852 typedef struct {
853   tBTM_BL_EVENT event;     /* The event reported. */
854   const RawAddress* p_bda; /* The address of the newly connected device */
855   DEV_CLASS_PTR p_dc;      /* The device class */
856   BD_NAME_PTR p_bdn;       /* The device name */
857   uint8_t* p_features;     /* pointer to the remote device's features page[0]
858                               (supported features page) */
859   uint16_t handle;         /* connection handle */
860   tBT_TRANSPORT transport; /* link is LE or not */
861 } tBTM_BL_CONN_DATA;
862 
863 /* the data type associated with BTM_BL_DISCN_EVT */
864 typedef struct {
865   tBTM_BL_EVENT event;     /* The event reported. */
866   const RawAddress* p_bda; /* The address of the disconnected device */
867   uint16_t handle;         /* disconnected connection handle */
868   tBT_TRANSPORT transport; /* link is LE link or not */
869 } tBTM_BL_DISCN_DATA;
870 
871 /* Busy-Level shall have the inquiry_paging mask set when
872  * inquiry/paging is in progress, Else the number of ACL links */
873 #define BTM_BL_INQUIRY_PAGING_MASK 0x10
874 #define BTM_BL_INQUIRY_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x1)
875 #define BTM_BL_INQUIRY_CANCELLED (BTM_BL_INQUIRY_PAGING_MASK | 0x2)
876 #define BTM_BL_INQUIRY_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x3)
877 #define BTM_BL_PAGING_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x4)
878 #define BTM_BL_PAGING_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x5)
879 /* the data type associated with BTM_BL_UPDATE_EVT */
880 typedef struct {
881   tBTM_BL_EVENT event;      /* The event reported. */
882   uint8_t busy_level;       /* when paging or inquiring, level is 10.
883                              * Otherwise, the number of ACL links. */
884   uint8_t busy_level_flags; /* Notifies actual inquiry/page activities */
885 } tBTM_BL_UPDATE_DATA;
886 
887 /* the data type associated with BTM_BL_ROLE_CHG_EVT */
888 typedef struct {
889   tBTM_BL_EVENT event; /* The event reported. */
890   const RawAddress* p_bda; /* The address of the peer connected device */
891   uint8_t new_role;
892   uint8_t hci_status; /* HCI status returned with the event */
893 } tBTM_BL_ROLE_CHG_DATA;
894 
895 typedef union {
896   tBTM_BL_EVENT event;        /* The event reported. */
897   tBTM_BL_CONN_DATA conn;     /* The data associated with BTM_BL_CONN_EVT */
898   tBTM_BL_DISCN_DATA discn;   /* The data associated with BTM_BL_DISCN_EVT */
899   tBTM_BL_UPDATE_DATA update; /* The data associated with BTM_BL_UPDATE_EVT */
900   tBTM_BL_ROLE_CHG_DATA
901       role_chg; /*The data associated with BTM_BL_ROLE_CHG_EVT */
902 } tBTM_BL_EVENT_DATA;
903 
904 /* Callback function for notifications when the BTM busy level
905  * changes.
906 */
907 typedef void(tBTM_BL_CHANGE_CB)(tBTM_BL_EVENT_DATA* p_data);
908 
909 /***************************
910  *  ACL Callback Functions
911  ***************************/
912 /* Callback function for notifications when the BTM ACL connection DB
913  * changes. First param is BD address, second is if added or removed.
914  * Registered through BTM_AclRegisterForChanges call.
915 */
916 typedef void(tBTM_ACL_DB_CHANGE_CB)(const RawAddress& p_bda, DEV_CLASS p_dc,
917                                     BD_NAME p_bdn, uint8_t* features,
918                                     bool is_new, uint16_t handle,
919                                     tBT_TRANSPORT transport);
920 /*****************************************************************************
921  *  SCO CHANNEL MANAGEMENT
922  ****************************************************************************/
923 /******************
924  *  SCO Constants
925  ******************/
926 
927 /* Define an invalid SCO index and an invalid HCI handle */
928 #define BTM_INVALID_SCO_INDEX 0xFFFF
929 #define BTM_INVALID_HCI_HANDLE 0xFFFF
930 
931 /* Define an invalid SCO disconnect reason */
932 #define BTM_INVALID_SCO_DISC_REASON 0xFFFF
933 
934 /* Define first active SCO index */
935 #define BTM_FIRST_ACTIVE_SCO_INDEX BTM_MAX_SCO_LINKS
936 
937 #define BTM_SCO_LINK_ONLY_MASK \
938   (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 | ESCO_PKT_TYPES_MASK_HV3)
939 
940 #define BTM_ESCO_LINK_ONLY_MASK \
941   (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5)
942 
943 #define BTM_SCO_LINK_ALL_PKT_MASK \
944   (BTM_SCO_LINK_ONLY_MASK | BTM_ESCO_LINK_ONLY_MASK)
945 
946 #define BTM_VALID_SCO_ALL_PKT_TYPE HCI_VALID_SCO_ALL_PKT_TYPE
947 
948 /***************
949  *  SCO Types
950  ***************/
951 #define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO
952 #define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO
953 typedef uint8_t tBTM_SCO_TYPE;
954 
955 /*******************
956  * SCO Codec Types
957  *******************/
958 // TODO(google) This should use common definitions
959 #define BTM_SCO_CODEC_NONE 0x0000
960 #define BTM_SCO_CODEC_CVSD 0x0001
961 #define BTM_SCO_CODEC_MSBC 0x0002
962 typedef uint16_t tBTM_SCO_CODEC_TYPE;
963 
964 /*******************
965  * SCO Voice Settings
966  *******************/
967 #define BTM_VOICE_SETTING_CVSD                                         \
968   ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
969               HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD))
970 
971 #define BTM_VOICE_SETTING_TRANS                                        \
972   ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
973               HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_TRANSPNT))
974 
975 /*******************
976  * SCO Data Status
977  *******************/
978 enum {
979   BTM_SCO_DATA_CORRECT,
980   BTM_SCO_DATA_PAR_ERR,
981   BTM_SCO_DATA_NONE,
982   BTM_SCO_DATA_PAR_LOST
983 };
984 typedef uint8_t tBTM_SCO_DATA_FLAG;
985 
986 /***************************
987  *  SCO Callback Functions
988  ***************************/
989 typedef void(tBTM_SCO_CB)(uint16_t sco_inx);
990 typedef void(tBTM_SCO_DATA_CB)(uint16_t sco_inx, BT_HDR* p_data,
991                                tBTM_SCO_DATA_FLAG status);
992 
993 /***************
994  *  eSCO Types
995  ***************/
996 /* tBTM_ESCO_CBACK event types */
997 #define BTM_ESCO_CHG_EVT 1
998 #define BTM_ESCO_CONN_REQ_EVT 2
999 typedef uint8_t tBTM_ESCO_EVT;
1000 
1001 /* Structure passed with SCO change command and events.
1002  * Used by both Sync and Enhanced sync messaging
1003  */
1004 typedef struct {
1005   uint16_t max_latency_ms;
1006   uint16_t packet_types;
1007   uint8_t retransmission_effort;
1008 } tBTM_CHG_ESCO_PARAMS;
1009 
1010 /* Returned by BTM_ReadEScoLinkParms() */
1011 typedef struct {
1012   uint16_t rx_pkt_len;
1013   uint16_t tx_pkt_len;
1014   RawAddress bd_addr;
1015   uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */
1016   uint8_t tx_interval;
1017   uint8_t retrans_window;
1018   uint8_t air_mode;
1019 } tBTM_ESCO_DATA;
1020 
1021 typedef struct {
1022   uint16_t sco_inx;
1023   uint16_t rx_pkt_len;
1024   uint16_t tx_pkt_len;
1025   RawAddress bd_addr;
1026   uint8_t hci_status;
1027   uint8_t tx_interval;
1028   uint8_t retrans_window;
1029 } tBTM_CHG_ESCO_EVT_DATA;
1030 
1031 typedef struct {
1032   uint16_t sco_inx;
1033   RawAddress bd_addr;
1034   DEV_CLASS dev_class;
1035   tBTM_SCO_TYPE link_type;
1036 } tBTM_ESCO_CONN_REQ_EVT_DATA;
1037 
1038 typedef union {
1039   tBTM_CHG_ESCO_EVT_DATA chg_evt;
1040   tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt;
1041 } tBTM_ESCO_EVT_DATA;
1042 
1043 /***************************
1044  *  eSCO Callback Functions
1045  ***************************/
1046 typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data);
1047 
1048 /*****************************************************************************
1049  *  SECURITY MANAGEMENT
1050  ****************************************************************************/
1051 /*******************************
1052  *  Security Manager Constants
1053  *******************************/
1054 
1055 /* Security Mode (BTM_SetSecurityMode) */
1056 #define BTM_SEC_MODE_UNDEFINED 0
1057 #define BTM_SEC_MODE_NONE 1
1058 #define BTM_SEC_MODE_SERVICE 2
1059 #define BTM_SEC_MODE_LINK 3
1060 #define BTM_SEC_MODE_SP 4
1061 #define BTM_SEC_MODE_SP_DEBUG 5
1062 #define BTM_SEC_MODE_SC 6
1063 
1064 /* Maximum Number of BTM Security Modes */
1065 #define BTM_SEC_MODES_MAX 7
1066 
1067 /* Security Service Levels [bit mask] (BTM_SetSecurityLevel)
1068  * Encryption should not be used without authentication
1069 */
1070 /* Nothing required */
1071 #define BTM_SEC_NONE 0x0000
1072 /* Inbound call requires authorization */
1073 #define BTM_SEC_IN_AUTHORIZE 0x0001
1074 /* Inbound call requires authentication */
1075 #define BTM_SEC_IN_AUTHENTICATE 0x0002
1076 /* Inbound call requires encryption */
1077 #define BTM_SEC_IN_ENCRYPT 0x0004
1078 /* Outbound call requires authorization */
1079 #define BTM_SEC_OUT_AUTHORIZE 0x0008
1080 /* Outbound call requires authentication */
1081 #define BTM_SEC_OUT_AUTHENTICATE 0x0010
1082 /* Outbound call requires encryption */
1083 #define BTM_SEC_OUT_ENCRYPT 0x0020
1084 /* Secure Connections Only Mode */
1085 #define BTM_SEC_MODE4_LEVEL4 0x0040
1086 /* Need to switch connection to be master */
1087 #define BTM_SEC_FORCE_MASTER 0x0100
1088 /* Try to switch connection to be master */
1089 #define BTM_SEC_ATTEMPT_MASTER 0x0200
1090 /* Need to switch connection to be master */
1091 #define BTM_SEC_FORCE_SLAVE 0x0400
1092 /* Try to switch connection to be slave */
1093 #define BTM_SEC_ATTEMPT_SLAVE 0x0800
1094 /* inbound Do man in the middle protection */
1095 #define BTM_SEC_IN_MITM 0x1000
1096 /* outbound Do man in the middle protection */
1097 #define BTM_SEC_OUT_MITM 0x2000
1098 /* enforce a minimum of 16 digit for sec mode 2 */
1099 #define BTM_SEC_IN_MIN_16_DIGIT_PIN 0x4000
1100 
1101 /* Security Flags [bit mask] (BTM_GetSecurityFlags)
1102 */
1103 #define BTM_SEC_FLAG_AUTHORIZED 0x01
1104 #define BTM_SEC_FLAG_AUTHENTICATED 0x02
1105 #define BTM_SEC_FLAG_ENCRYPTED 0x04
1106 #define BTM_SEC_FLAG_LKEY_KNOWN 0x10
1107 #define BTM_SEC_FLAG_LKEY_AUTHED 0x20
1108 
1109 /* PIN types */
1110 #define BTM_PIN_TYPE_VARIABLE HCI_PIN_TYPE_VARIABLE
1111 #define BTM_PIN_TYPE_FIXED HCI_PIN_TYPE_FIXED
1112 
1113 /* Link Key types used to generate the new link key.
1114  * returned in link key notification callback function
1115 */
1116 #define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION
1117 #define BTM_LKEY_TYPE_LOCAL_UNIT HCI_LKEY_TYPE_LOCAL_UNIT
1118 #define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT
1119 #define BTM_LKEY_TYPE_DEBUG_COMB HCI_LKEY_TYPE_DEBUG_COMB
1120 #define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB
1121 #define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB
1122 #define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB
1123 
1124 #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256
1125 #define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256
1126 
1127 /* "easy" requirements for LK derived from LTK */
1128 #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20
1129 #define BTM_LKEY_TYPE_IGNORE               \
1130   0xff /* used when event is response from \
1131           hci return link keys request */
1132 
1133 typedef uint8_t tBTM_LINK_KEY_TYPE;
1134 
1135 /* Protocol level security (BTM_SetSecurityLevel) */
1136 #define BTM_SEC_PROTO_L2CAP 0
1137 #define BTM_SEC_PROTO_SDP 1
1138 #define BTM_SEC_PROTO_TCS 2
1139 #define BTM_SEC_PROTO_RFCOMM 3
1140 #define BTM_SEC_PROTO_OBEX 4
1141 #define BTM_SEC_PROTO_BNEP 5
1142 #define BTM_SEC_PROTO_HID 6 /* HID      */
1143 #define BTM_SEC_PROTO_AVDT 7
1144 #define BTM_SEC_PROTO_MCA 8
1145 
1146 /* Determine the number of uint32_t's necessary for security services */
1147 #define BTM_SEC_ARRAY_BITS 32 /* Number of bits in each array element */
1148 #define BTM_SEC_SERVICE_ARRAY_SIZE                         \
1149   (((uint32_t)BTM_SEC_MAX_SERVICES / BTM_SEC_ARRAY_BITS) + \
1150    (((uint32_t)BTM_SEC_MAX_SERVICES % BTM_SEC_ARRAY_BITS) ? 1 : 0))
1151 
1152 /* Security service definitions (BTM_SetSecurityLevel)
1153  * Used for Authorization APIs
1154 */
1155 #define BTM_SEC_SERVICE_SDP_SERVER 0
1156 #define BTM_SEC_SERVICE_SERIAL_PORT 1
1157 #define BTM_SEC_SERVICE_LAN_ACCESS 2
1158 #define BTM_SEC_SERVICE_DUN 3
1159 #define BTM_SEC_SERVICE_IRMC_SYNC 4
1160 #define BTM_SEC_SERVICE_IRMC_SYNC_CMD 5
1161 #define BTM_SEC_SERVICE_OBEX 6
1162 #define BTM_SEC_SERVICE_OBEX_FTP 7
1163 #define BTM_SEC_SERVICE_HEADSET 8
1164 #define BTM_SEC_SERVICE_CORDLESS 9
1165 #define BTM_SEC_SERVICE_INTERCOM 10
1166 #define BTM_SEC_SERVICE_FAX 11
1167 #define BTM_SEC_SERVICE_HEADSET_AG 12
1168 #define BTM_SEC_SERVICE_PNP_INFO 13
1169 #define BTM_SEC_SERVICE_GEN_NET 14
1170 #define BTM_SEC_SERVICE_GEN_FILE 15
1171 #define BTM_SEC_SERVICE_GEN_AUDIO 16
1172 #define BTM_SEC_SERVICE_GEN_TEL 17
1173 #define BTM_SEC_SERVICE_CTP_DATA 18
1174 #define BTM_SEC_SERVICE_HCRP_CTRL 19
1175 #define BTM_SEC_SERVICE_HCRP_DATA 20
1176 #define BTM_SEC_SERVICE_HCRP_NOTIF 21
1177 #define BTM_SEC_SERVICE_BPP_JOB 22
1178 #define BTM_SEC_SERVICE_BPP_STATUS 23
1179 #define BTM_SEC_SERVICE_BPP_REF 24
1180 #define BTM_SEC_SERVICE_BNEP_PANU 25
1181 #define BTM_SEC_SERVICE_BNEP_GN 26
1182 #define BTM_SEC_SERVICE_BNEP_NAP 27
1183 #define BTM_SEC_SERVICE_HF_HANDSFREE 28
1184 #define BTM_SEC_SERVICE_AG_HANDSFREE 29
1185 #define BTM_SEC_SERVICE_TE_PHONE_ACCESS 30
1186 #define BTM_SEC_SERVICE_ME_PHONE_ACCESS 31
1187 
1188 #define BTM_SEC_SERVICE_HIDH_SEC_CTRL 32
1189 #define BTM_SEC_SERVICE_HIDH_NOSEC_CTRL 33
1190 #define BTM_SEC_SERVICE_HIDH_INTR 34
1191 #define BTM_SEC_SERVICE_BIP 35
1192 #define BTM_SEC_SERVICE_BIP_REF 36
1193 #define BTM_SEC_SERVICE_AVDTP 37
1194 #define BTM_SEC_SERVICE_AVDTP_NOSEC 38
1195 #define BTM_SEC_SERVICE_AVCTP 39
1196 #define BTM_SEC_SERVICE_SAP 40
1197 #define BTM_SEC_SERVICE_PBAP 41
1198 #define BTM_SEC_SERVICE_RFC_MUX 42
1199 #define BTM_SEC_SERVICE_AVCTP_BROWSE 43
1200 #define BTM_SEC_SERVICE_MAP 44
1201 #define BTM_SEC_SERVICE_MAP_NOTIF 45
1202 #define BTM_SEC_SERVICE_MCAP_CTRL 46
1203 #define BTM_SEC_SERVICE_MCAP_DATA 47
1204 #define BTM_SEC_SERVICE_HDP_SNK 48
1205 #define BTM_SEC_SERVICE_HDP_SRC 49
1206 #define BTM_SEC_SERVICE_ATT 50
1207 #define BTM_SEC_SERVICE_HIDD_SEC_CTRL 51
1208 #define BTM_SEC_SERVICE_HIDD_NOSEC_CTRL 52
1209 #define BTM_SEC_SERVICE_HIDD_INTR 53
1210 
1211 /* Update these as services are added */
1212 #define BTM_SEC_SERVICE_FIRST_EMPTY 54
1213 
1214 #ifndef BTM_SEC_MAX_SERVICES
1215 #define BTM_SEC_MAX_SERVICES 75
1216 #endif
1217 
1218 /*******************************************************************************
1219  * Security Services MACROS handle array of uint32_t bits for more than 32
1220  * trusted services
1221  ******************************************************************************/
1222 /* MACRO to set the security service bit mask in a bit stream */
1223 #define BTM_SEC_SET_SERVICE(p, service)                              \
1224   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] |= \
1225    ((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))
1226 
1227 /* MACRO to clear the security service bit mask in a bit stream */
1228 #define BTM_SEC_CLR_SERVICE(p, service)                              \
1229   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] &= \
1230    ~((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))
1231 
1232 /* MACRO to check the security service bit mask in a bit stream (Returns true or
1233  * false) */
1234 #define BTM_SEC_IS_SERVICE_TRUSTED(p, service)                                 \
1235   (((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)]) &         \
1236     (uint32_t)(((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))) \
1237        ? true                                                                  \
1238        : false)
1239 
1240 /* MACRO to copy two trusted device bitmask */
1241 #define BTM_SEC_COPY_TRUSTED_DEVICE(p_src, p_dst)              \
1242   {                                                            \
1243     uint32_t trst;                                             \
1244     for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++)  \
1245       ((uint32_t*)(p_dst))[trst] = ((uint32_t*)(p_src))[trst]; \
1246   }
1247 
1248 /* MACRO to clear two trusted device bitmask */
1249 #define BTM_SEC_CLR_TRUSTED_DEVICE(p_dst)                     \
1250   {                                                           \
1251     uint32_t trst;                                            \
1252     for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \
1253       ((uint32_t*)(p_dst))[trst] = 0;                         \
1254   }
1255 
1256 /* Following bits can be provided by host in the trusted_mask array */
1257 /* 0..31 bits of mask[0] (Least Significant Word) */
1258 #define BTM_SEC_TRUST_SDP_SERVER (1 << BTM_SEC_SERVICE_SDP_SERVER)
1259 #define BTM_SEC_TRUST_SERIAL_PORT (1 << BTM_SEC_SERVICE_SERIAL_PORT)
1260 #define BTM_SEC_TRUST_LAN_ACCESS (1 << BTM_SEC_SERVICE_LAN_ACCESS)
1261 #define BTM_SEC_TRUST_DUN (1 << BTM_SEC_SERVICE_DUN)
1262 #define BTM_SEC_TRUST_IRMC_SYNC (1 << BTM_SEC_SERVICE_IRMC_SYNC)
1263 #define BTM_SEC_TRUST_IRMC_SYNC_CMD (1 << BTM_SEC_SERVICE_IRMC_SYNC_CMD)
1264 #define BTM_SEC_TRUST_OBEX (1 << BTM_SEC_SERVICE_OBEX)
1265 #define BTM_SEC_TRUST_OBEX_FTP (1 << BTM_SEC_SERVICE_OBEX_FTP)
1266 #define BTM_SEC_TRUST_HEADSET (1 << BTM_SEC_SERVICE_HEADSET)
1267 #define BTM_SEC_TRUST_CORDLESS (1 << BTM_SEC_SERVICE_CORDLESS)
1268 #define BTM_SEC_TRUST_INTERCOM (1 << BTM_SEC_SERVICE_INTERCOM)
1269 #define BTM_SEC_TRUST_FAX (1 << BTM_SEC_SERVICE_FAX)
1270 #define BTM_SEC_TRUST_HEADSET_AG (1 << BTM_SEC_SERVICE_HEADSET_AG)
1271 #define BTM_SEC_TRUST_PNP_INFO (1 << BTM_SEC_SERVICE_PNP_INFO)
1272 #define BTM_SEC_TRUST_GEN_NET (1 << BTM_SEC_SERVICE_GEN_NET)
1273 #define BTM_SEC_TRUST_GEN_FILE (1 << BTM_SEC_SERVICE_GEN_FILE)
1274 #define BTM_SEC_TRUST_GEN_AUDIO (1 << BTM_SEC_SERVICE_GEN_AUDIO)
1275 #define BTM_SEC_TRUST_GEN_TEL (1 << BTM_SEC_SERVICE_GEN_TEL)
1276 #define BTM_SEC_TRUST_CTP_DATA (1 << BTM_SEC_SERVICE_CTP_DATA)
1277 #define BTM_SEC_TRUST_HCRP_CTRL (1 << BTM_SEC_SERVICE_HCRP_CTRL)
1278 #define BTM_SEC_TRUST_HCRP_DATA (1 << BTM_SEC_SERVICE_HCRP_DATA)
1279 #define BTM_SEC_TRUST_HCRP_NOTIF (1 << BTM_SEC_SERVICE_HCRP_NOTIF)
1280 #define BTM_SEC_TRUST_BPP_JOB (1 << BTM_SEC_SERVICE_JOB)
1281 #define BTM_SEC_TRUST_BPP_STATUS (1 << BTM_SEC_SERVICE_STATUS)
1282 #define BTM_SEC_TRUST_BPP_REF (1 << BTM_SEC_SERVICE_REF)
1283 #define BTM_SEC_TRUST_BNEP_PANU (1 << BTM_SEC_SERVICE_BNEP_PANU)
1284 #define BTM_SEC_TRUST_BNEP_GN (1 << BTM_SEC_SERVICE_BNEP_GN)
1285 #define BTM_SEC_TRUST_BNEP_NAP (1 << BTM_SEC_SERVICE_BNEP_NAP)
1286 #define BTM_SEC_TRUST_HFP_HF (1 << BTM_SEC_SERVICE_HF_HANDSFREE)
1287 #define BTM_SEC_TRUST_HFP_AG (1 << BTM_SEC_SERVICE_AG_HANDSFREE)
1288 #define BTM_SEC_TRUST_TE_PHONE_ACCESS (1 << BTM_SEC_SERVICE_TE_PHONE_ACCESS)
1289 #define BTM_SEC_TRUST_ME_PHONE_ACCESS (1 << BTM_SEC_SERVICE_ME_PHONE_ACCESS)
1290 
1291 /* 0..31 bits of mask[1] (Most Significant Word) */
1292 #define BTM_SEC_TRUST_HIDH_CTRL (1 << (BTM_SEC_SERVICE_HIDH_SEC_CTRL - 32))
1293 #define BTM_SEC_TRUST_HIDH_NOSEC_CTRL \
1294   (1 << (BTM_SEC_SERVICE_HIDH_NOSEC_CTRL - 32))
1295 #define BTM_SEC_TRUST_HIDH_INTR (1 << (BTM_SEC_SERVICE_HIDH_INTR - 32))
1296 #define BTM_SEC_TRUST_BIP (1 << (BTM_SEC_SERVICE_BIP - 32))
1297 #define BTM_SEC_TRUST_BIP_REF (1 << (BTM_SEC_SERVICE_BIP_REF - 32))
1298 #define BTM_SEC_TRUST_AVDTP (1 << (BTM_SEC_SERVICE_AVDTP - 32))
1299 #define BTM_SEC_TRUST_AVDTP_NOSEC (1 << (BTM_SEC_SERVICE_AVDTP_NOSEC - 32))
1300 #define BTM_SEC_TRUST_AVCTP (1 << (BTM_SEC_SERVICE_AVCTP - 32))
1301 #define BTM_SEC_TRUST_SAP (1 << (BTM_SEC_SERVICE_SAP - 32))
1302 #define BTM_SEC_TRUST_PBAP (1 << (BTM_SEC_SERVICE_PBAP - 32))
1303 #define BTM_SEC_TRUST_RFC_MUX (1 << (BTM_SEC_SERVICE_RFC_MUX - 32))
1304 #define BTM_SEC_TRUST_AVCTP_BROWSE (1 << (BTM_SEC_SERVICE_AVCTP_BROWSE - 32))
1305 #define BTM_SEC_TRUST_MAP (1 << (BTM_SEC_SERVICE_MAP - 32))
1306 #define BTM_SEC_TRUST_MAP_NOTIF (1 << (BTM_SEC_SERVICE_MAP_NOTIF - 32))
1307 #define BTM_SEC_TRUST_MCAP_CTRL (1 << (BTM_SEC_SERVICE_MCAP_CTRL - 32))
1308 #define BTM_SEC_TRUST_MCAP_DATA (1 << (BTM_SEC_SERVICE_MCAP_DATA - 32))
1309 #define BTM_SEC_TRUST_HDP_SNK (1 << (BTM_SEC_SERVICE_HDP_SNK - 32))
1310 #define BTM_SEC_TRUST_HDP_SRC (1 << (BTM_SEC_SERVICE_HDP_SRC - 32))
1311 
1312 #define BTM_SEC_TRUST_ALL 0xFFFFFFFF /* for each array element */
1313 
1314 /****************************************
1315  *  Security Manager Callback Functions
1316  ****************************************/
1317 /* Authorize device for service.  Parameters are
1318  *              BD Address of remote
1319  *              Device Class of remote
1320  *              BD Name of remote
1321  *              Service name
1322  *              Service Id (NULL - unknown service or unused
1323  *                                 [BTM_SEC_SERVICE_NAME_LEN set to 0])
1324  *              Is originator of the connection
1325  *              Result of the operation
1326 */
1327 typedef uint8_t(tBTM_AUTHORIZE_CALLBACK)(
1328     const RawAddress& bd_addr, DEV_CLASS dev_class, tBTM_BD_NAME bd_name,
1329     uint8_t* service_name, uint8_t service_id, bool is_originator);
1330 
1331 /* Get PIN for the connection.  Parameters are
1332  *              BD Address of remote
1333  *              Device Class of remote
1334  *              BD Name of remote
1335  *              Flag indicating the minimum pin code length to be 16 digits
1336 */
1337 typedef uint8_t(tBTM_PIN_CALLBACK)(const RawAddress& bd_addr,
1338                                    DEV_CLASS dev_class, tBTM_BD_NAME bd_name,
1339                                    bool min_16_digit);
1340 
1341 /* New Link Key for the connection.  Parameters are
1342  *              BD Address of remote
1343  *              Link Key
1344  *              Key Type: Combination, Local Unit, or Remote Unit
1345 */
1346 typedef uint8_t(tBTM_LINK_KEY_CALLBACK)(const RawAddress& bd_addr,
1347                                         DEV_CLASS dev_class,
1348                                         tBTM_BD_NAME bd_name, uint8_t* key,
1349                                         uint8_t key_type);
1350 
1351 /* Remote Name Resolved.  Parameters are
1352  *              BD Address of remote
1353  *              BD Name of remote
1354 */
1355 typedef void(tBTM_RMT_NAME_CALLBACK)(const RawAddress& bd_addr, DEV_CLASS dc,
1356                                      tBTM_BD_NAME bd_name);
1357 
1358 /* Authentication complete for the connection.  Parameters are
1359  *              BD Address of remote
1360  *              Device Class of remote
1361  *              BD Name of remote
1362  *
1363 */
1364 typedef uint8_t(tBTM_AUTH_COMPLETE_CALLBACK)(const RawAddress& bd_addr,
1365                                              DEV_CLASS dev_class,
1366                                              tBTM_BD_NAME bd_name, int result);
1367 
1368 enum {
1369   BTM_SP_IO_REQ_EVT,    /* received IO_CAPABILITY_REQUEST event */
1370   BTM_SP_IO_RSP_EVT,    /* received IO_CAPABILITY_RESPONSE event */
1371   BTM_SP_CFM_REQ_EVT,   /* received USER_CONFIRMATION_REQUEST event */
1372   BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */
1373   BTM_SP_KEY_REQ_EVT,   /* received USER_PASSKEY_REQUEST event */
1374   BTM_SP_KEYPRESS_EVT,  /* received KEYPRESS_NOTIFY event */
1375   BTM_SP_LOC_OOB_EVT,   /* received result for READ_LOCAL_OOB_DATA command */
1376   BTM_SP_RMT_OOB_EVT,   /* received REMOTE_OOB_DATA_REQUEST event */
1377   BTM_SP_COMPLT_EVT,    /* received SIMPLE_PAIRING_COMPLETE event */
1378   BTM_SP_UPGRADE_EVT /* check if the application wants to upgrade the link key
1379                         */
1380 };
1381 typedef uint8_t tBTM_SP_EVT;
1382 
1383 #define BTM_IO_CAP_OUT 0    /* DisplayOnly */
1384 #define BTM_IO_CAP_IO 1     /* DisplayYesNo */
1385 #define BTM_IO_CAP_IN 2     /* KeyboardOnly */
1386 #define BTM_IO_CAP_NONE 3   /* NoInputNoOutput */
1387 #define BTM_IO_CAP_KBDISP 4 /* Keyboard display */
1388 #define BTM_IO_CAP_MAX 5
1389 #define BTM_IO_CAP_UNKNOWN 0xFF /* Unknown value */
1390 
1391 typedef uint8_t tBTM_IO_CAP;
1392 
1393 #define BTM_MAX_PASSKEY_VAL (999999)
1394 #define BTM_MIN_PASSKEY_VAL (0)
1395 
1396 /* MITM Protection Not Required - Single Profile/non-bonding Numeric comparison
1397  * with automatic accept allowed */
1398 #define BTM_AUTH_SP_NO 0
1399 /* MITM Protection Required - Single Profile/non-bonding. Use IO Capabilities to
1400  * determine authentication procedure */
1401 #define BTM_AUTH_SP_YES 1
1402 /* MITM Protection Not Required - All Profiles/dedicated bonding Numeric
1403  * comparison with automatic accept allowed */
1404 #define BTM_AUTH_AP_NO 2
1405 /* MITM Protection Required - All Profiles/dedicated bonding Use IO Capabilities
1406  * to determine authentication procedure */
1407 #define BTM_AUTH_AP_YES 3
1408 /* MITM Protection Not Required - Single Profiles/general bonding Numeric
1409  * comparison with automatic accept allowed */
1410 #define BTM_AUTH_SPGB_NO 4
1411 /* MITM Protection Required - Single Profiles/general bonding Use IO
1412  * Capabilities to determine authentication procedure */
1413 #define BTM_AUTH_SPGB_YES 5
1414 
1415 /* this bit is ORed with BTM_AUTH_SP_* when IO exchange for dedicated bonding */
1416 #define BTM_AUTH_DD_BOND 2
1417 #define BTM_AUTH_GB_BIT 4 /* the genernal bonding bit */
1418 #define BTM_AUTH_BONDS 6  /* the general/dedicated bonding bits  */
1419 #define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit  */
1420 
1421 #define BTM_BLE_INITIATOR_KEY_SIZE 15
1422 #define BTM_BLE_RESPONDER_KEY_SIZE 15
1423 #define BTM_BLE_MAX_KEY_SIZE 16
1424 
1425 typedef uint8_t tBTM_AUTH_REQ;
1426 
1427 enum { BTM_OOB_NONE, BTM_OOB_PRESENT, BTM_OOB_UNKNOWN };
1428 typedef uint8_t tBTM_OOB_DATA;
1429 
1430 /* data type for BTM_SP_IO_REQ_EVT */
1431 typedef struct {
1432   RawAddress bd_addr;     /* peer address */
1433   tBTM_IO_CAP io_cap;     /* local IO capabilities */
1434   tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */
1435   tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */
1436   bool is_orig;           /* true, if local device initiated the SP process */
1437 } tBTM_SP_IO_REQ;
1438 
1439 /* data type for BTM_SP_IO_RSP_EVT */
1440 typedef struct {
1441   RawAddress bd_addr; /* peer address */
1442   tBTM_IO_CAP io_cap; /* peer IO capabilities */
1443   tBTM_OOB_DATA
1444       oob_data; /* OOB data present at peer device for the local device */
1445   tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */
1446 } tBTM_SP_IO_RSP;
1447 
1448 /* data type for BTM_SP_CFM_REQ_EVT */
1449 typedef struct {
1450   RawAddress bd_addr;   /* peer address */
1451   DEV_CLASS dev_class;  /* peer CoD */
1452   tBTM_BD_NAME bd_name; /* peer device name */
1453   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
1454                        show this number to UI */
1455   bool just_works;  /* true, if "Just Works" association model */
1456   tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
1457   tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
1458   tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of the local device */
1459   tBTM_IO_CAP rmt_io_caps;    /* IO Capabilities of the remot device */
1460 } tBTM_SP_CFM_REQ;
1461 
1462 /* data type for BTM_SP_KEY_REQ_EVT */
1463 typedef struct {
1464   RawAddress bd_addr;   /* peer address */
1465   DEV_CLASS dev_class;  /* peer CoD */
1466   tBTM_BD_NAME bd_name; /* peer device name */
1467 } tBTM_SP_KEY_REQ;
1468 
1469 /* data type for BTM_SP_KEY_NOTIF_EVT */
1470 typedef struct {
1471   RawAddress bd_addr;   /* peer address */
1472   DEV_CLASS dev_class;  /* peer CoD */
1473   tBTM_BD_NAME bd_name; /* peer device name */
1474   uint32_t passkey;     /* passkey */
1475 } tBTM_SP_KEY_NOTIF;
1476 
1477 enum {
1478   BTM_SP_KEY_STARTED,     /* 0 - passkey entry started */
1479   BTM_SP_KEY_ENTERED,     /* 1 - passkey digit entered */
1480   BTM_SP_KEY_ERASED,      /* 2 - passkey digit erased */
1481   BTM_SP_KEY_CLEARED,     /* 3 - passkey cleared */
1482   BTM_SP_KEY_COMPLT,      /* 4 - passkey entry completed */
1483   BTM_SP_KEY_OUT_OF_RANGE /* 5 - out of range */
1484 };
1485 typedef uint8_t tBTM_SP_KEY_TYPE;
1486 
1487 /* data type for BTM_SP_KEYPRESS_EVT */
1488 typedef struct {
1489   RawAddress bd_addr; /* peer address */
1490   tBTM_SP_KEY_TYPE notif_type;
1491 } tBTM_SP_KEYPRESS;
1492 
1493 /* data type for BTM_SP_LOC_OOB_EVT */
1494 typedef struct {
1495   tBTM_STATUS status; /* */
1496   BT_OCTET16 c;       /* Simple Pairing Hash C */
1497   BT_OCTET16 r;       /* Simple Pairing Randomnizer R */
1498 } tBTM_SP_LOC_OOB;
1499 
1500 /* data type for BTM_SP_RMT_OOB_EVT */
1501 typedef struct {
1502   RawAddress bd_addr;   /* peer address */
1503   DEV_CLASS dev_class;  /* peer CoD */
1504   tBTM_BD_NAME bd_name; /* peer device name */
1505 } tBTM_SP_RMT_OOB;
1506 
1507 /* data type for BTM_SP_COMPLT_EVT */
1508 typedef struct {
1509   RawAddress bd_addr;   /* peer address */
1510   DEV_CLASS dev_class;  /* peer CoD */
1511   tBTM_BD_NAME bd_name; /* peer device name */
1512   tBTM_STATUS status;   /* status of the simple pairing process */
1513 } tBTM_SP_COMPLT;
1514 
1515 /* data type for BTM_SP_UPGRADE_EVT */
1516 typedef struct {
1517   RawAddress bd_addr; /* peer address */
1518   bool upgrade;    /* true, to upgrade the link key */
1519 } tBTM_SP_UPGRADE;
1520 
1521 typedef union {
1522   tBTM_SP_IO_REQ io_req;       /* BTM_SP_IO_REQ_EVT      */
1523   tBTM_SP_IO_RSP io_rsp;       /* BTM_SP_IO_RSP_EVT      */
1524   tBTM_SP_CFM_REQ cfm_req;     /* BTM_SP_CFM_REQ_EVT     */
1525   tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT   */
1526   tBTM_SP_KEY_REQ key_req;     /* BTM_SP_KEY_REQ_EVT     */
1527   tBTM_SP_KEYPRESS key_press;  /* BTM_SP_KEYPRESS_EVT    */
1528   tBTM_SP_LOC_OOB loc_oob;     /* BTM_SP_LOC_OOB_EVT     */
1529   tBTM_SP_RMT_OOB rmt_oob;     /* BTM_SP_RMT_OOB_EVT     */
1530   tBTM_SP_COMPLT complt;       /* BTM_SP_COMPLT_EVT      */
1531   tBTM_SP_UPGRADE upgrade;     /* BTM_SP_UPGRADE_EVT      */
1532 } tBTM_SP_EVT_DATA;
1533 
1534 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
1535  * events occur.
1536 */
1537 typedef uint8_t(tBTM_SP_CALLBACK)(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data);
1538 
1539 typedef void(tBTM_MKEY_CALLBACK)(const RawAddress& bd_addr, uint8_t status,
1540                                  uint8_t key_flag);
1541 
1542 /* Encryption enabled/disabled complete: Optionally passed with
1543  * BTM_SetEncryption.
1544  * Parameters are
1545  *              BD Address of remote
1546  *              optional data passed in by BTM_SetEncryption
1547  *              tBTM_STATUS - result of the operation
1548 */
1549 typedef void(tBTM_SEC_CBACK)(const RawAddress* bd_addr, tBT_TRANSPORT trasnport,
1550                              void* p_ref_data, tBTM_STATUS result);
1551 
1552 /* Bond Cancel complete. Parameters are
1553  *              Result of the cancel operation
1554  *
1555 */
1556 typedef void(tBTM_BOND_CANCEL_CMPL_CALLBACK)(tBTM_STATUS result);
1557 
1558 /* LE related event and data structure */
1559 /* received IO_CAPABILITY_REQUEST event */
1560 #define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT
1561 /* security request event */
1562 #define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT
1563 /* received USER_PASSKEY_NOTIFY event */
1564 #define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT
1565 /* received USER_PASSKEY_REQUEST event */
1566 #define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT
1567 /* OOB data request event */
1568 #define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT
1569 /* Numeric Comparison request event */
1570 #define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT
1571 /* Peer keypress notification recd event */
1572 #define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT
1573 /* SC OOB request event (both local and peer OOB data) can be expected in
1574  * response */
1575 #define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT
1576 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */
1577 #define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT
1578 /* SMP over BR keys request event */
1579 #define BTM_LE_BR_KEYS_REQ_EVT SMP_BR_KEYS_REQ_EVT
1580 /* SMP complete event */
1581 #define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT
1582 #define BTM_LE_LAST_FROM_SMP BTM_LE_BR_KEYS_REQ_EVT
1583 /* KEY update event */
1584 #define BTM_LE_KEY_EVT (BTM_LE_LAST_FROM_SMP + 1)
1585 typedef uint8_t tBTM_LE_EVT;
1586 
1587 #define BTM_LE_KEY_NONE 0
1588 /* encryption information of peer device */
1589 #define BTM_LE_KEY_PENC SMP_SEC_KEY_TYPE_ENC
1590 /* identity key of the peer device */
1591 #define BTM_LE_KEY_PID SMP_SEC_KEY_TYPE_ID
1592 /* peer SRK */
1593 #define BTM_LE_KEY_PCSRK SMP_SEC_KEY_TYPE_CSRK
1594 #define BTM_LE_KEY_PLK SMP_SEC_KEY_TYPE_LK
1595 #define BTM_LE_KEY_LLK (SMP_SEC_KEY_TYPE_LK << 4)
1596 /* master role security information:div */
1597 #define BTM_LE_KEY_LENC (SMP_SEC_KEY_TYPE_ENC << 4)
1598 /* master device ID key */
1599 #define BTM_LE_KEY_LID (SMP_SEC_KEY_TYPE_ID << 4)
1600 /* local CSRK has been deliver to peer */
1601 #define BTM_LE_KEY_LCSRK (SMP_SEC_KEY_TYPE_CSRK << 4)
1602 typedef uint8_t tBTM_LE_KEY_TYPE;
1603 
1604 #define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */
1605 #define BTM_LE_AUTH_REQ_BOND SMP_AUTH_GEN_BOND   /* 1 << 0 */
1606 #define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT     /* 1 << 2 */
1607 typedef uint8_t tBTM_LE_AUTH_REQ;
1608 #define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */
1609 #define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */
1610 #define BTM_LE_H7_SUPPORT_BIT SMP_H7_SUPPORT_BIT /* (1 << 5) */
1611 
1612 #define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY     /* 00101000 */
1613 #define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB           /* 00101001 */
1614 #define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB      /* 00101100 */
1615 #define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 00101101 */
1616 #define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK               /* 0x3D */
1617 
1618 /* LE security level */
1619 #define BTM_LE_SEC_NONE SMP_SEC_NONE
1620 #define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */
1621 #define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED   /* 4 */
1622 typedef uint8_t tBTM_LE_SEC;
1623 
1624 typedef struct {
1625   /* local IO capabilities */
1626   tBTM_IO_CAP io_cap;
1627   /* OOB data present (locally) for the peer device */
1628   uint8_t oob_data;
1629   /* Authentication request (for local device) containing bonding and MITM
1630    * info */
1631   tBTM_LE_AUTH_REQ auth_req;
1632   uint8_t max_key_size;       /* max encryption key size */
1633   tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */
1634   tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */
1635 } tBTM_LE_IO_REQ;
1636 
1637 /* data type for tBTM_LE_COMPLT */
1638 typedef struct {
1639   uint8_t reason;
1640   uint8_t sec_level;
1641   bool is_pair_cancel;
1642   bool smp_over_br;
1643 } tBTM_LE_COMPLT;
1644 
1645 /* BLE encryption keys */
1646 typedef struct {
1647   BT_OCTET16 ltk;
1648   BT_OCTET8 rand;
1649   uint16_t ediv;
1650   uint8_t sec_level;
1651   uint8_t key_size;
1652 } tBTM_LE_PENC_KEYS;
1653 
1654 /* BLE CSRK keys */
1655 typedef struct {
1656   uint32_t counter;
1657   BT_OCTET16 csrk;
1658   uint8_t sec_level;
1659 } tBTM_LE_PCSRK_KEYS;
1660 
1661 /* BLE Encryption reproduction keys */
1662 typedef struct {
1663   BT_OCTET16 ltk;
1664   uint16_t div;
1665   uint8_t key_size;
1666   uint8_t sec_level;
1667 } tBTM_LE_LENC_KEYS;
1668 
1669 /* BLE SRK keys */
1670 typedef struct {
1671   uint32_t counter;
1672   uint16_t div;
1673   uint8_t sec_level;
1674   BT_OCTET16 csrk;
1675 } tBTM_LE_LCSRK_KEYS;
1676 
1677 typedef struct {
1678   BT_OCTET16 irk;
1679   tBLE_ADDR_TYPE addr_type;
1680   RawAddress static_addr;
1681 } tBTM_LE_PID_KEYS;
1682 
1683 typedef union {
1684   tBTM_LE_PENC_KEYS penc_key;   /* received peer encryption key */
1685   tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
1686   tBTM_LE_PID_KEYS pid_key;     /* peer device ID key */
1687   tBTM_LE_LENC_KEYS lenc_key;   /* local encryption reproduction keys
1688                                  * LTK = = d1(ER,DIV,0) */
1689   tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
1690 } tBTM_LE_KEY_VALUE;
1691 
1692 typedef struct {
1693   tBTM_LE_KEY_TYPE key_type;
1694   tBTM_LE_KEY_VALUE* p_key_value;
1695 } tBTM_LE_KEY;
1696 
1697 typedef union {
1698   tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT      */
1699   uint32_t key_notif;    /* BTM_LE_KEY_NOTIF_EVT   */
1700                          /* BTM_LE_NC_REQ_EVT */
1701                          /* no callback data for
1702                           * BTM_LE_KEY_REQ_EVT
1703                           * and BTM_LE_OOB_REQ_EVT  */
1704   tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT      */
1705   tSMP_OOB_DATA_TYPE req_oob_type;
1706   tBTM_LE_KEY key;
1707 } tBTM_LE_EVT_DATA;
1708 
1709 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
1710  * events occur.
1711 */
1712 typedef uint8_t(tBTM_LE_CALLBACK)(tBTM_LE_EVT event, const RawAddress& bda,
1713                                   tBTM_LE_EVT_DATA* p_data);
1714 
1715 #define BTM_BLE_KEY_TYPE_ID 1
1716 #define BTM_BLE_KEY_TYPE_ER 2
1717 #define BTM_BLE_KEY_TYPE_COUNTER 3  // tobe obsolete
1718 
1719 typedef struct {
1720   BT_OCTET16 ir;
1721   BT_OCTET16 irk;
1722   BT_OCTET16 dhk;
1723 
1724 } tBTM_BLE_LOCAL_ID_KEYS;
1725 
1726 typedef union {
1727   tBTM_BLE_LOCAL_ID_KEYS id_keys;
1728   BT_OCTET16 er;
1729 } tBTM_BLE_LOCAL_KEYS;
1730 
1731 /* New LE identity key for local device.
1732 */
1733 typedef void(tBTM_LE_KEY_CALLBACK)(uint8_t key_type,
1734                                    tBTM_BLE_LOCAL_KEYS* p_key);
1735 
1736 /***************************
1737  *  Security Manager Types
1738  ***************************/
1739 /* Structure that applications use to register with BTM_SecRegister */
1740 typedef struct {
1741   tBTM_AUTHORIZE_CALLBACK* p_authorize_callback;
1742   tBTM_PIN_CALLBACK* p_pin_callback;
1743   tBTM_LINK_KEY_CALLBACK* p_link_key_callback;
1744   tBTM_AUTH_COMPLETE_CALLBACK* p_auth_complete_callback;
1745   tBTM_BOND_CANCEL_CMPL_CALLBACK* p_bond_cancel_cmpl_callback;
1746   tBTM_SP_CALLBACK* p_sp_callback;
1747   tBTM_LE_CALLBACK* p_le_callback;
1748   tBTM_LE_KEY_CALLBACK* p_le_key_callback;
1749 } tBTM_APPL_INFO;
1750 
1751 /* Callback function for when a link supervision timeout event occurs.
1752  * This asynchronous event is enabled/disabled by calling BTM_RegForLstoEvt().
1753 */
1754 typedef void(tBTM_LSTO_CBACK)(const RawAddress& remote_bda, uint16_t timeout);
1755 
1756 /*****************************************************************************
1757  *  POWER MANAGEMENT
1758  ****************************************************************************/
1759 /****************************
1760  *  Power Manager Constants
1761  ****************************/
1762 /* BTM Power manager status codes */
1763 enum {
1764   BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE,
1765   BTM_PM_STS_HOLD = HCI_MODE_HOLD,
1766   BTM_PM_STS_SNIFF = HCI_MODE_SNIFF,
1767   BTM_PM_STS_PARK = HCI_MODE_PARK,
1768   BTM_PM_STS_SSR,     /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */
1769   BTM_PM_STS_PENDING, /* when waiting for status from controller */
1770   BTM_PM_STS_ERROR    /* when HCI command status returns error */
1771 };
1772 typedef uint8_t tBTM_PM_STATUS;
1773 
1774 /* BTM Power manager modes */
1775 enum {
1776   BTM_PM_MD_ACTIVE = BTM_PM_STS_ACTIVE,
1777   BTM_PM_MD_HOLD = BTM_PM_STS_HOLD,
1778   BTM_PM_MD_SNIFF = BTM_PM_STS_SNIFF,
1779   BTM_PM_MD_PARK = BTM_PM_STS_PARK,
1780   BTM_PM_MD_FORCE = 0x10 /* OR this to force ACL link to a certain mode */
1781 };
1782 typedef uint8_t tBTM_PM_MODE;
1783 
1784 #define BTM_PM_SET_ONLY_ID 0x80
1785 
1786 /* Operation codes */
1787 /* The module wants to set the desired power mode */
1788 #define BTM_PM_REG_SET 1
1789 /* The module wants to receive mode change event */
1790 #define BTM_PM_REG_NOTIF 2
1791 /* The module does not want to involve with PM anymore */
1792 #define BTM_PM_DEREG 4
1793 
1794 /************************
1795  *  Power Manager Types
1796  ************************/
1797 typedef struct {
1798   uint16_t max;
1799   uint16_t min;
1800   uint16_t attempt;
1801   uint16_t timeout;
1802   tBTM_PM_MODE mode;
1803 } tBTM_PM_PWR_MD;
1804 
1805 /*************************************
1806  *  Power Manager Callback Functions
1807  *************************************/
1808 typedef void(tBTM_PM_STATUS_CBACK)(const RawAddress& p_bda,
1809                                    tBTM_PM_STATUS status, uint16_t value,
1810                                    uint8_t hci_status);
1811 
1812 /************************
1813  *  Stored Linkkey Types
1814  ************************/
1815 #define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4
1816 
1817 typedef struct {
1818   uint8_t event;
1819   uint8_t status;
1820   uint16_t num_keys;
1821 
1822 } tBTM_DELETE_STORED_LINK_KEY_COMPLETE;
1823 
1824 /* MIP evnets, callbacks    */
1825 enum {
1826   BTM_MIP_MODE_CHG_EVT,
1827   BTM_MIP_DISCONNECT_EVT,
1828   BTM_MIP_PKTS_COMPL_EVT,
1829   BTM_MIP_RXDATA_EVT
1830 };
1831 typedef uint8_t tBTM_MIP_EVT;
1832 
1833 typedef struct {
1834   tBTM_MIP_EVT event;
1835   RawAddress bd_addr;
1836   uint16_t mip_id;
1837 } tBTM_MIP_MODE_CHANGE;
1838 
1839 typedef struct {
1840   tBTM_MIP_EVT event;
1841   uint16_t mip_id;
1842   uint8_t disc_reason;
1843 } tBTM_MIP_CONN_TIMEOUT;
1844 
1845 #define BTM_MIP_MAX_RX_LEN 17
1846 
1847 typedef struct {
1848   tBTM_MIP_EVT event;
1849   uint16_t mip_id;
1850   uint8_t rx_len;
1851   uint8_t rx_data[BTM_MIP_MAX_RX_LEN];
1852 } tBTM_MIP_RXDATA;
1853 
1854 typedef struct {
1855   tBTM_MIP_EVT event;
1856   RawAddress bd_addr;
1857   uint8_t data[11]; /* data[0] shows Vender-specific device type */
1858 } tBTM_MIP_EIR_HANDSHAKE;
1859 
1860 typedef struct {
1861   tBTM_MIP_EVT event;
1862   uint16_t num_sent; /* Completed packet count at the controller */
1863 } tBTM_MIP_PKTS_COMPL;
1864 
1865 typedef union {
1866   tBTM_MIP_EVT event;
1867   tBTM_MIP_MODE_CHANGE mod_chg;
1868   tBTM_MIP_CONN_TIMEOUT conn_tmo;
1869   tBTM_MIP_EIR_HANDSHAKE eir;
1870   tBTM_MIP_PKTS_COMPL completed;
1871   tBTM_MIP_RXDATA rxdata;
1872 } tBTM_MIP_EVENT_DATA;
1873 
1874 /* MIP event callback function  */
1875 typedef void(tBTM_MIP_EVENTS_CB)(tBTM_MIP_EVT event, tBTM_MIP_EVENT_DATA data);
1876 
1877 /* MIP Device query callback function  */
1878 typedef bool(tBTM_MIP_QUERY_CB)(const RawAddress& dev_addr, uint8_t* p_mode,
1879                                 LINK_KEY link_key);
1880 
1881 /* ACL link on, SCO link ongoing, sniff mode */
1882 #define BTM_CONTRL_ACTIVE 1
1883 /* Scan state - paging/inquiry/trying to connect*/
1884 #define BTM_CONTRL_SCAN 2
1885 /* Idle state - page scan, LE advt, inquiry scan */
1886 #define BTM_CONTRL_IDLE 3
1887 
1888 typedef uint8_t tBTM_CONTRL_STATE;
1889 
1890 #endif  // BTM_API_TYPES_H
1891