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