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