• 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.
577  */
578 typedef struct /* contains the two device class condition fields */
579 {
580   DEV_CLASS dev_class;
581   DEV_CLASS dev_class_mask;
582 } tBTM_COD_COND;
583 
584 typedef union /* contains the inquiry filter condition */
585 {
586   RawAddress bdaddr_cond;
587   tBTM_COD_COND cod_cond;
588 } tBTM_INQ_FILT_COND;
589 
590 typedef struct /* contains the parameters passed to the inquiry functions */
591 {
592   uint8_t mode;      /* general or limited */
593   uint8_t duration;  /* duration of the inquiry (1.28 sec increments) */
594   uint8_t max_resps; /* maximum number of responses to return */
595   bool report_dup; /* report duplicated inquiry response with higher RSSI value
596                       */
597   uint8_t filter_cond_type; /* new devices, BD ADDR, COD, or No filtering */
598   tBTM_INQ_FILT_COND filter_cond; /* filter value based on filter cond type */
599 } tBTM_INQ_PARMS;
600 
601 #define BTM_INQ_RESULT_BR 0x01
602 #define BTM_INQ_RESULT_BLE 0x02
603 
604 constexpr uint8_t BLE_EVT_CONNECTABLE_BIT = 0;
605 constexpr uint8_t BLE_EVT_SCANNABLE_BIT = 1;
606 constexpr uint8_t BLE_EVT_DIRECTED_BIT = 2;
607 constexpr uint8_t BLE_EVT_SCAN_RESPONSE_BIT = 3;
608 constexpr uint8_t BLE_EVT_LEGACY_BIT = 4;
609 
610 constexpr uint8_t PHY_LE_NO_PACKET = 0x00;
611 constexpr uint8_t PHY_LE_1M = 0x01;
612 constexpr uint8_t PHY_LE_2M = 0x02;
613 constexpr uint8_t PHY_LE_CODED = 0x04;
614 
615 constexpr uint8_t NO_ADI_PRESENT = 0xFF;
616 constexpr uint8_t TX_POWER_NOT_PRESENT = 0x7F;
617 
618 /* These are the fields returned in each device's response to the inquiry.  It
619  * is returned in the results callback if registered.
620 */
621 typedef struct {
622   uint16_t clock_offset;
623   RawAddress remote_bd_addr;
624   DEV_CLASS dev_class;
625   uint8_t page_scan_rep_mode;
626   uint8_t page_scan_per_mode;
627   uint8_t page_scan_mode;
628   int8_t rssi; /* Set to BTM_INQ_RES_IGNORE_RSSI if  not valid */
629   uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE];
630   bool eir_complete_list;
631   tBT_DEVICE_TYPE device_type;
632   uint8_t inq_result_type;
633   uint8_t ble_addr_type;
634   uint16_t ble_evt_type;
635   uint8_t ble_primary_phy;
636   uint8_t ble_secondary_phy;
637   uint8_t ble_advertising_sid;
638   int8_t ble_tx_power;
639   uint16_t ble_periodic_adv_int;
640   uint8_t flag;
641 } tBTM_INQ_RESULTS;
642 
643 /* This is the inquiry response information held in its database by BTM, and
644  * available to applications via BTM_InqDbRead, BTM_InqDbFirst, and
645  * BTM_InqDbNext.
646 */
647 typedef struct {
648   tBTM_INQ_RESULTS results;
649 
650   bool appl_knows_rem_name; /* set by application if it knows the remote name of
651                                the peer device.
652                                This is later used by application to determine if
653                                remote name request is
654                                required to be done. Having the flag here avoid
655                                duplicate store of inquiry results */
656   uint16_t remote_name_len;
657   tBTM_BD_NAME remote_name;
658   uint8_t remote_name_state;
659   uint8_t remote_name_type;
660 
661 } tBTM_INQ_INFO;
662 
663 /* Structure returned with inquiry complete callback */
664 typedef struct {
665   tBTM_STATUS status;
666   uint8_t num_resp; /* Number of results from the current inquiry */
667 } tBTM_INQUIRY_CMPL;
668 
669 /* Structure returned with remote name  request */
670 typedef struct {
671   uint16_t status;
672   RawAddress bd_addr;
673   uint16_t length;
674   BD_NAME remote_bd_name;
675 } tBTM_REMOTE_DEV_NAME;
676 
677 typedef struct {
678   uint8_t pcm_intf_rate; /* PCM interface rate: 0: 128kbps, 1: 256 kbps;
679                              2:512 bps; 3: 1024kbps; 4: 2048kbps */
680   uint8_t frame_type;    /* frame type: 0: short; 1: long */
681   uint8_t sync_mode;     /* sync mode: 0: slave; 1: master */
682   uint8_t clock_mode;    /* clock mode: 0: slave; 1: master */
683 
684 } tBTM_SCO_PCM_PARAM;
685 
686 /****************************************
687  *  Device Discovery Callback Functions
688  ****************************************/
689 /* Callback function for asynchronous notifications when the BTM inquiry DB
690  * changes. First param is inquiry database, second is if added to or removed
691  * from the inquiry database.
692 */
693 typedef void(tBTM_INQ_DB_CHANGE_CB)(void* p1, bool is_new);
694 
695 /* Callback function for notifications when the BTM gets inquiry response.
696  * First param is inquiry results database, second is pointer of EIR.
697 */
698 typedef void(tBTM_INQ_RESULTS_CB)(tBTM_INQ_RESULTS* p_inq_results,
699                                   uint8_t* p_eir, uint16_t eir_len);
700 
701 /*****************************************************************************
702  *  ACL CHANNEL MANAGEMENT
703  ****************************************************************************/
704 /******************
705  *  ACL Constants
706  ******************/
707 
708 /* ACL modes */
709 #define BTM_ACL_MODE_NORMAL HCI_MODE_ACTIVE
710 #define BTM_ACL_MODE_HOLD HCI_MODE_HOLD
711 #define BTM_ACL_MODE_SNIFF HCI_MODE_SNIFF
712 #define BTM_ACL_MODE_PARK HCI_MODE_PARK
713 
714 /* Returned with structure in role switch callback (tBTM_ROLE_SWITCH_CMPL) */
715 #define BTM_ROLE_MASTER HCI_ROLE_MASTER
716 #define BTM_ROLE_SLAVE HCI_ROLE_SLAVE
717 #define BTM_ROLE_UNDEFINED 0xff /* undefined value (error status) */
718 
719 /* ACL Packet Types */
720 #define BTM_ACL_PKT_TYPES_MASK_DM1 HCI_PKT_TYPES_MASK_DM1
721 #define BTM_ACL_PKT_TYPES_MASK_DH1 HCI_PKT_TYPES_MASK_DH1
722 #define BTM_ACL_PKT_TYPES_MASK_DM3 HCI_PKT_TYPES_MASK_DM3
723 #define BTM_ACL_PKT_TYPES_MASK_DH3 HCI_PKT_TYPES_MASK_DH3
724 #define BTM_ACL_PKT_TYPES_MASK_DM5 HCI_PKT_TYPES_MASK_DM5
725 #define BTM_ACL_PKT_TYPES_MASK_DH5 HCI_PKT_TYPES_MASK_DH5
726 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 HCI_PKT_TYPES_MASK_NO_2_DH1
727 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 HCI_PKT_TYPES_MASK_NO_3_DH1
728 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 HCI_PKT_TYPES_MASK_NO_2_DH3
729 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 HCI_PKT_TYPES_MASK_NO_3_DH3
730 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 HCI_PKT_TYPES_MASK_NO_2_DH5
731 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH5 HCI_PKT_TYPES_MASK_NO_3_DH5
732 
733 /***************
734  *  ACL Types
735  ***************/
736 
737 /* Structure returned with Role Switch information (in tBTM_CMPL_CB callback
738  * function) in response to BTM_SwitchRole call.
739 */
740 typedef struct {
741   uint8_t hci_status;     /* HCI status returned with the event */
742   uint8_t role;           /* BTM_ROLE_MASTER or BTM_ROLE_SLAVE */
743   RawAddress remote_bd_addr; /* Remote BD addr involved with the switch */
744 } tBTM_ROLE_SWITCH_CMPL;
745 
746 /* Structure returned with QoS information (in tBTM_CMPL_CB callback function)
747  * in response to BTM_SetQoS call.
748 */
749 typedef struct {
750   FLOW_SPEC flow;
751   uint16_t handle;
752   uint8_t status;
753 } tBTM_QOS_SETUP_CMPL;
754 
755 /* Structure returned with read RSSI event (in tBTM_CMPL_CB callback function)
756  * in response to BTM_ReadRSSI call.
757 */
758 typedef struct {
759   tBTM_STATUS status;
760   uint8_t hci_status;
761   int8_t rssi;
762   RawAddress rem_bda;
763 } tBTM_RSSI_RESULT;
764 
765 /* Structure returned with read failed contact counter event
766  * (in tBTM_CMPL_CB callback function) in response to
767  * BTM_ReadFailedContactCounter call.
768  */
769 typedef struct {
770   tBTM_STATUS status;
771   uint8_t hci_status;
772   uint16_t failed_contact_counter;
773   RawAddress rem_bda;
774 } tBTM_FAILED_CONTACT_COUNTER_RESULT;
775 
776 /* Structure returned with read automatic flush timeout event
777  * (in tBTM_CMPL_CB callback function) in response to
778  * BTM_ReadAutomaticFlushTimeout call.
779  */
780 typedef struct {
781   tBTM_STATUS status;
782   uint8_t hci_status;
783   uint16_t automatic_flush_timeout;
784   RawAddress rem_bda;
785 } tBTM_AUTOMATIC_FLUSH_TIMEOUT_RESULT;
786 
787 /* Structure returned with read current TX power event (in tBTM_CMPL_CB callback
788  * function) in response to BTM_ReadTxPower call.
789 */
790 typedef struct {
791   tBTM_STATUS status;
792   uint8_t hci_status;
793   int8_t tx_power;
794   RawAddress rem_bda;
795 } tBTM_TX_POWER_RESULT;
796 
797 /* Structure returned with read link quality event (in tBTM_CMPL_CB callback
798  * function) in response to BTM_ReadLinkQuality call.
799 */
800 typedef struct {
801   tBTM_STATUS status;
802   uint8_t hci_status;
803   uint8_t link_quality;
804   RawAddress rem_bda;
805 } tBTM_LINK_QUALITY_RESULT;
806 
807 /* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB
808  * callback function) in response to BTM_ReadInquiryRspTxPower call.
809 */
810 typedef struct {
811   tBTM_STATUS status;
812   uint8_t hci_status;
813   int8_t tx_power;
814 } tBTM_INQ_TXPWR_RESULT;
815 
816 enum {
817   BTM_BL_CONN_EVT,
818   BTM_BL_DISCN_EVT,
819   BTM_BL_UPDATE_EVT,
820   BTM_BL_ROLE_CHG_EVT,
821   BTM_BL_COLLISION_EVT
822 };
823 typedef uint8_t tBTM_BL_EVENT;
824 typedef uint16_t tBTM_BL_EVENT_MASK;
825 
826 #define BTM_BL_CONN_MASK 0x0001
827 #define BTM_BL_DISCN_MASK 0x0002
828 #define BTM_BL_UPDATE_MASK 0x0004
829 #define BTM_BL_ROLE_CHG_MASK 0x0008
830 
831 /* Device features mask definitions */
832 #define BTM_FEATURE_BYTES_PER_PAGE HCI_FEATURE_BYTES_PER_PAGE
833 #define BTM_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_MAX
834 
835 /* the data type associated with BTM_BL_CONN_EVT */
836 typedef struct {
837   tBTM_BL_EVENT event;     /* The event reported. */
838   const RawAddress* p_bda; /* The address of the newly connected device */
839   DEV_CLASS_PTR p_dc;      /* The device class */
840   BD_NAME_PTR p_bdn;       /* The device name */
841   uint8_t* p_features;     /* pointer to the remote device's features page[0]
842                               (supported features page) */
843   uint16_t handle;         /* connection handle */
844   tBT_TRANSPORT transport; /* link is LE or not */
845 } tBTM_BL_CONN_DATA;
846 
847 /* the data type associated with BTM_BL_DISCN_EVT */
848 typedef struct {
849   tBTM_BL_EVENT event;     /* The event reported. */
850   const RawAddress* p_bda; /* The address of the disconnected device */
851   uint16_t handle;         /* disconnected connection handle */
852   tBT_TRANSPORT transport; /* link is LE link or not */
853 } tBTM_BL_DISCN_DATA;
854 
855 /* Busy-Level shall have the inquiry_paging mask set when
856  * inquiry/paging is in progress, Else the number of ACL links */
857 #define BTM_BL_INQUIRY_PAGING_MASK 0x10
858 #define BTM_BL_INQUIRY_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x1)
859 #define BTM_BL_INQUIRY_CANCELLED (BTM_BL_INQUIRY_PAGING_MASK | 0x2)
860 #define BTM_BL_INQUIRY_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x3)
861 #define BTM_BL_PAGING_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x4)
862 #define BTM_BL_PAGING_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x5)
863 /* the data type associated with BTM_BL_UPDATE_EVT */
864 typedef struct {
865   tBTM_BL_EVENT event;      /* The event reported. */
866   uint8_t busy_level;       /* when paging or inquiring, level is 10.
867                              * Otherwise, the number of ACL links. */
868   uint8_t busy_level_flags; /* Notifies actual inquiry/page activities */
869 } tBTM_BL_UPDATE_DATA;
870 
871 /* the data type associated with BTM_BL_ROLE_CHG_EVT */
872 typedef struct {
873   tBTM_BL_EVENT event; /* The event reported. */
874   const RawAddress* p_bda; /* The address of the peer connected device */
875   uint8_t new_role;
876   uint8_t hci_status; /* HCI status returned with the event */
877 } tBTM_BL_ROLE_CHG_DATA;
878 
879 typedef union {
880   tBTM_BL_EVENT event;        /* The event reported. */
881   tBTM_BL_CONN_DATA conn;     /* The data associated with BTM_BL_CONN_EVT */
882   tBTM_BL_DISCN_DATA discn;   /* The data associated with BTM_BL_DISCN_EVT */
883   tBTM_BL_UPDATE_DATA update; /* The data associated with BTM_BL_UPDATE_EVT */
884   tBTM_BL_ROLE_CHG_DATA
885       role_chg; /*The data associated with BTM_BL_ROLE_CHG_EVT */
886 } tBTM_BL_EVENT_DATA;
887 
888 /* Callback function for notifications when the BTM busy level
889  * changes.
890 */
891 typedef void(tBTM_BL_CHANGE_CB)(tBTM_BL_EVENT_DATA* p_data);
892 
893 /***************************
894  *  ACL Callback Functions
895  ***************************/
896 /* Callback function for notifications when the BTM ACL connection DB
897  * changes. First param is BD address, second is if added or removed.
898  * Registered through BTM_AclRegisterForChanges call.
899 */
900 typedef void(tBTM_ACL_DB_CHANGE_CB)(const RawAddress& p_bda, DEV_CLASS p_dc,
901                                     BD_NAME p_bdn, uint8_t* features,
902                                     bool is_new, uint16_t handle,
903                                     tBT_TRANSPORT transport);
904 /*****************************************************************************
905  *  SCO CHANNEL MANAGEMENT
906  ****************************************************************************/
907 /******************
908  *  SCO Constants
909  ******************/
910 
911 /* Define an invalid SCO index and an invalid HCI handle */
912 #define BTM_INVALID_SCO_INDEX 0xFFFF
913 #define BTM_INVALID_HCI_HANDLE 0xFFFF
914 
915 /* Define an invalid SCO disconnect reason */
916 #define BTM_INVALID_SCO_DISC_REASON 0xFFFF
917 
918 /* Define first active SCO index */
919 #define BTM_FIRST_ACTIVE_SCO_INDEX BTM_MAX_SCO_LINKS
920 
921 #define BTM_SCO_LINK_ONLY_MASK \
922   (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 | ESCO_PKT_TYPES_MASK_HV3)
923 
924 #define BTM_ESCO_LINK_ONLY_MASK \
925   (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5)
926 
927 #define BTM_SCO_LINK_ALL_PKT_MASK \
928   (BTM_SCO_LINK_ONLY_MASK | BTM_ESCO_LINK_ONLY_MASK)
929 
930 #define BTM_VALID_SCO_ALL_PKT_TYPE HCI_VALID_SCO_ALL_PKT_TYPE
931 
932 /***************
933  *  SCO Types
934  ***************/
935 #define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO
936 #define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO
937 typedef uint8_t tBTM_SCO_TYPE;
938 
939 /*******************
940  * SCO Codec Types
941  *******************/
942 // TODO(google) This should use common definitions
943 #define BTM_SCO_CODEC_NONE 0x0000
944 #define BTM_SCO_CODEC_CVSD 0x0001
945 #define BTM_SCO_CODEC_MSBC 0x0002
946 typedef uint16_t tBTM_SCO_CODEC_TYPE;
947 
948 /*******************
949  * SCO Voice Settings
950  *******************/
951 #define BTM_VOICE_SETTING_CVSD                                         \
952   ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
953               HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD))
954 
955 #define BTM_VOICE_SETTING_TRANS                                        \
956   ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
957               HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_TRANSPNT))
958 
959 /*******************
960  * SCO Data Status
961  *******************/
962 enum {
963   BTM_SCO_DATA_CORRECT,
964   BTM_SCO_DATA_PAR_ERR,
965   BTM_SCO_DATA_NONE,
966   BTM_SCO_DATA_PAR_LOST
967 };
968 typedef uint8_t tBTM_SCO_DATA_FLAG;
969 
970 /***************************
971  *  SCO Callback Functions
972  ***************************/
973 typedef void(tBTM_SCO_CB)(uint16_t sco_inx);
974 typedef void(tBTM_SCO_DATA_CB)(uint16_t sco_inx, BT_HDR* p_data,
975                                tBTM_SCO_DATA_FLAG status);
976 
977 /***************
978  *  eSCO Types
979  ***************/
980 /* tBTM_ESCO_CBACK event types */
981 #define BTM_ESCO_CHG_EVT 1
982 #define BTM_ESCO_CONN_REQ_EVT 2
983 typedef uint8_t tBTM_ESCO_EVT;
984 
985 /* Structure passed with SCO change command and events.
986  * Used by both Sync and Enhanced sync messaging
987  */
988 typedef struct {
989   uint16_t max_latency_ms;
990   uint16_t packet_types;
991   uint8_t retransmission_effort;
992 } tBTM_CHG_ESCO_PARAMS;
993 
994 /* Returned by BTM_ReadEScoLinkParms() */
995 typedef struct {
996   uint16_t rx_pkt_len;
997   uint16_t tx_pkt_len;
998   RawAddress bd_addr;
999   uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */
1000   uint8_t tx_interval;
1001   uint8_t retrans_window;
1002   uint8_t air_mode;
1003 } tBTM_ESCO_DATA;
1004 
1005 typedef struct {
1006   uint16_t sco_inx;
1007   uint16_t rx_pkt_len;
1008   uint16_t tx_pkt_len;
1009   RawAddress bd_addr;
1010   uint8_t hci_status;
1011   uint8_t tx_interval;
1012   uint8_t retrans_window;
1013 } tBTM_CHG_ESCO_EVT_DATA;
1014 
1015 typedef struct {
1016   uint16_t sco_inx;
1017   RawAddress bd_addr;
1018   DEV_CLASS dev_class;
1019   tBTM_SCO_TYPE link_type;
1020 } tBTM_ESCO_CONN_REQ_EVT_DATA;
1021 
1022 typedef union {
1023   tBTM_CHG_ESCO_EVT_DATA chg_evt;
1024   tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt;
1025 } tBTM_ESCO_EVT_DATA;
1026 
1027 /***************************
1028  *  eSCO Callback Functions
1029  ***************************/
1030 typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data);
1031 
1032 /*****************************************************************************
1033  *  SECURITY MANAGEMENT
1034  ****************************************************************************/
1035 /*******************************
1036  *  Security Manager Constants
1037  *******************************/
1038 
1039 /* Security Mode (BTM_SetSecurityMode) */
1040 #define BTM_SEC_MODE_UNDEFINED 0
1041 #define BTM_SEC_MODE_NONE 1
1042 #define BTM_SEC_MODE_SERVICE 2
1043 #define BTM_SEC_MODE_LINK 3
1044 #define BTM_SEC_MODE_SP 4
1045 #define BTM_SEC_MODE_SP_DEBUG 5
1046 #define BTM_SEC_MODE_SC 6
1047 
1048 /* Security Service Levels [bit mask] (BTM_SetSecurityLevel)
1049  * Encryption should not be used without authentication
1050 */
1051 /* Nothing required */
1052 #define BTM_SEC_NONE 0x0000
1053 /* Inbound call requires authorization */
1054 #define BTM_SEC_IN_AUTHORIZE 0x0001
1055 /* Inbound call requires authentication */
1056 #define BTM_SEC_IN_AUTHENTICATE 0x0002
1057 /* Inbound call requires encryption */
1058 #define BTM_SEC_IN_ENCRYPT 0x0004
1059 /* Outbound call requires authorization */
1060 #define BTM_SEC_OUT_AUTHORIZE 0x0008
1061 /* Outbound call requires authentication */
1062 #define BTM_SEC_OUT_AUTHENTICATE 0x0010
1063 /* Outbound call requires encryption */
1064 #define BTM_SEC_OUT_ENCRYPT 0x0020
1065 /* Secure Connections Only Mode */
1066 #define BTM_SEC_MODE4_LEVEL4 0x0040
1067 /* Need to switch connection to be master */
1068 #define BTM_SEC_FORCE_MASTER 0x0100
1069 /* Try to switch connection to be master */
1070 #define BTM_SEC_ATTEMPT_MASTER 0x0200
1071 /* Need to switch connection to be master */
1072 #define BTM_SEC_FORCE_SLAVE 0x0400
1073 /* Try to switch connection to be slave */
1074 #define BTM_SEC_ATTEMPT_SLAVE 0x0800
1075 /* inbound Do man in the middle protection */
1076 #define BTM_SEC_IN_MITM 0x1000
1077 /* outbound Do man in the middle protection */
1078 #define BTM_SEC_OUT_MITM 0x2000
1079 /* enforce a minimum of 16 digit for sec mode 2 */
1080 #define BTM_SEC_IN_MIN_16_DIGIT_PIN 0x4000
1081 
1082 /* Security Flags [bit mask] (BTM_GetSecurityFlags)
1083 */
1084 #define BTM_SEC_FLAG_AUTHORIZED 0x01
1085 #define BTM_SEC_FLAG_AUTHENTICATED 0x02
1086 #define BTM_SEC_FLAG_ENCRYPTED 0x04
1087 #define BTM_SEC_FLAG_LKEY_KNOWN 0x10
1088 #define BTM_SEC_FLAG_LKEY_AUTHED 0x20
1089 
1090 /* PIN types */
1091 #define BTM_PIN_TYPE_VARIABLE HCI_PIN_TYPE_VARIABLE
1092 #define BTM_PIN_TYPE_FIXED HCI_PIN_TYPE_FIXED
1093 
1094 /* Link Key types used to generate the new link key.
1095  * returned in link key notification callback function
1096 */
1097 #define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION
1098 #define BTM_LKEY_TYPE_LOCAL_UNIT HCI_LKEY_TYPE_LOCAL_UNIT
1099 #define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT
1100 #define BTM_LKEY_TYPE_DEBUG_COMB HCI_LKEY_TYPE_DEBUG_COMB
1101 #define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB
1102 #define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB
1103 #define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB
1104 
1105 #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256
1106 #define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256
1107 
1108 /* "easy" requirements for LK derived from LTK */
1109 #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20
1110 #define BTM_LKEY_TYPE_IGNORE               \
1111   0xff /* used when event is response from \
1112           hci return link keys request */
1113 
1114 typedef uint8_t tBTM_LINK_KEY_TYPE;
1115 
1116 /* Protocol level security (BTM_SetSecurityLevel) */
1117 #define BTM_SEC_PROTO_RFCOMM 3
1118 #define BTM_SEC_PROTO_BNEP 5
1119 #define BTM_SEC_PROTO_HID 6 /* HID      */
1120 #define BTM_SEC_PROTO_AVDT 7
1121 
1122 /* Determine the number of uint32_t's necessary for security services */
1123 #define BTM_SEC_ARRAY_BITS 32 /* Number of bits in each array element */
1124 #define BTM_SEC_SERVICE_ARRAY_SIZE                         \
1125   (((uint32_t)BTM_SEC_MAX_SERVICES / BTM_SEC_ARRAY_BITS) + \
1126    (((uint32_t)BTM_SEC_MAX_SERVICES % BTM_SEC_ARRAY_BITS) ? 1 : 0))
1127 
1128 /* Security service definitions (BTM_SetSecurityLevel)
1129  * Used for Authorization APIs
1130 */
1131 #define BTM_SEC_SERVICE_SDP_SERVER 0
1132 #define BTM_SEC_SERVICE_SERIAL_PORT 1
1133 #define BTM_SEC_SERVICE_LAN_ACCESS 2
1134 #define BTM_SEC_SERVICE_DUN 3
1135 #define BTM_SEC_SERVICE_IRMC_SYNC 4
1136 #define BTM_SEC_SERVICE_IRMC_SYNC_CMD 5
1137 #define BTM_SEC_SERVICE_OBEX 6
1138 #define BTM_SEC_SERVICE_OBEX_FTP 7
1139 #define BTM_SEC_SERVICE_HEADSET 8
1140 #define BTM_SEC_SERVICE_CORDLESS 9
1141 #define BTM_SEC_SERVICE_INTERCOM 10
1142 #define BTM_SEC_SERVICE_FAX 11
1143 #define BTM_SEC_SERVICE_HEADSET_AG 12
1144 #define BTM_SEC_SERVICE_PNP_INFO 13
1145 #define BTM_SEC_SERVICE_GEN_NET 14
1146 #define BTM_SEC_SERVICE_GEN_FILE 15
1147 #define BTM_SEC_SERVICE_GEN_AUDIO 16
1148 #define BTM_SEC_SERVICE_GEN_TEL 17
1149 #define BTM_SEC_SERVICE_CTP_DATA 18
1150 #define BTM_SEC_SERVICE_HCRP_CTRL 19
1151 #define BTM_SEC_SERVICE_HCRP_DATA 20
1152 #define BTM_SEC_SERVICE_HCRP_NOTIF 21
1153 #define BTM_SEC_SERVICE_BPP_JOB 22
1154 #define BTM_SEC_SERVICE_BPP_STATUS 23
1155 #define BTM_SEC_SERVICE_BPP_REF 24
1156 #define BTM_SEC_SERVICE_BNEP_PANU 25
1157 #define BTM_SEC_SERVICE_BNEP_GN 26
1158 #define BTM_SEC_SERVICE_BNEP_NAP 27
1159 #define BTM_SEC_SERVICE_HF_HANDSFREE 28
1160 #define BTM_SEC_SERVICE_AG_HANDSFREE 29
1161 #define BTM_SEC_SERVICE_TE_PHONE_ACCESS 30
1162 #define BTM_SEC_SERVICE_ME_PHONE_ACCESS 31
1163 
1164 #define BTM_SEC_SERVICE_HIDH_SEC_CTRL 32
1165 #define BTM_SEC_SERVICE_HIDH_NOSEC_CTRL 33
1166 #define BTM_SEC_SERVICE_HIDH_INTR 34
1167 #define BTM_SEC_SERVICE_BIP 35
1168 #define BTM_SEC_SERVICE_BIP_REF 36
1169 #define BTM_SEC_SERVICE_AVDTP 37
1170 #define BTM_SEC_SERVICE_AVDTP_NOSEC 38
1171 #define BTM_SEC_SERVICE_AVCTP 39
1172 #define BTM_SEC_SERVICE_SAP 40
1173 #define BTM_SEC_SERVICE_PBAP 41
1174 #define BTM_SEC_SERVICE_RFC_MUX 42
1175 #define BTM_SEC_SERVICE_AVCTP_BROWSE 43
1176 #define BTM_SEC_SERVICE_MAP 44
1177 #define BTM_SEC_SERVICE_MAP_NOTIF 45
1178 #define BTM_SEC_SERVICE_MCAP_CTRL 46
1179 #define BTM_SEC_SERVICE_MCAP_DATA 47
1180 #define BTM_SEC_SERVICE_HDP_SNK 48
1181 #define BTM_SEC_SERVICE_HDP_SRC 49
1182 #define BTM_SEC_SERVICE_ATT 50
1183 #define BTM_SEC_SERVICE_HIDD_SEC_CTRL 51
1184 #define BTM_SEC_SERVICE_HIDD_NOSEC_CTRL 52
1185 #define BTM_SEC_SERVICE_HIDD_INTR 53
1186 #define BTM_SEC_SERVICE_HEARING_AID_LEFT 54
1187 #define BTM_SEC_SERVICE_HEARING_AID_RIGHT 55
1188 
1189 /* Update these as services are added */
1190 #define BTM_SEC_SERVICE_FIRST_EMPTY 56
1191 
1192 #ifndef BTM_SEC_MAX_SERVICES
1193 #define BTM_SEC_MAX_SERVICES 75
1194 #endif
1195 
1196 /*******************************************************************************
1197  * Security Services MACROS handle array of uint32_t bits for more than 32
1198  * trusted services
1199  ******************************************************************************/
1200 /* MACRO to set the security service bit mask in a bit stream */
1201 #define BTM_SEC_SET_SERVICE(p, service)                              \
1202   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] |= \
1203    ((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))
1204 
1205 /* MACRO to clear the security service bit mask in a bit stream */
1206 #define BTM_SEC_CLR_SERVICE(p, service)                              \
1207   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] &= \
1208    ~((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))
1209 
1210 /* MACRO to check the security service bit mask in a bit stream (Returns true or
1211  * false) */
1212 #define BTM_SEC_IS_SERVICE_TRUSTED(p, service)                                 \
1213   (((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)]) &         \
1214     (uint32_t)(((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))) \
1215        ? true                                                                  \
1216        : false)
1217 
1218 /* MACRO to copy two trusted device bitmask */
1219 #define BTM_SEC_COPY_TRUSTED_DEVICE(p_src, p_dst)              \
1220   {                                                            \
1221     uint32_t trst;                                             \
1222     for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++)  \
1223       ((uint32_t*)(p_dst))[trst] = ((uint32_t*)(p_src))[trst]; \
1224   }
1225 
1226 /* MACRO to clear two trusted device bitmask */
1227 #define BTM_SEC_CLR_TRUSTED_DEVICE(p_dst)                     \
1228   {                                                           \
1229     uint32_t trst;                                            \
1230     for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \
1231       ((uint32_t*)(p_dst))[trst] = 0;                         \
1232   }
1233 
1234 #define BTM_SEC_TRUST_ALL 0xFFFFFFFF /* for each array element */
1235 
1236 /****************************************
1237  *  Security Manager Callback Functions
1238  ****************************************/
1239 /* Authorize device for service.  Parameters are
1240  *              BD Address of remote
1241  *              Device Class of remote
1242  *              BD Name of remote
1243  *              Service name
1244  *              Service Id (NULL - unknown service or unused
1245  *                                 [BTM_SEC_SERVICE_NAME_LEN set to 0])
1246  *              Is originator of the connection
1247  *              Result of the operation
1248 */
1249 typedef uint8_t(tBTM_AUTHORIZE_CALLBACK)(
1250     const RawAddress& bd_addr, DEV_CLASS dev_class, tBTM_BD_NAME bd_name,
1251     uint8_t* service_name, uint8_t service_id, bool is_originator);
1252 
1253 /* Get PIN for the connection.  Parameters are
1254  *              BD Address of remote
1255  *              Device Class of remote
1256  *              BD Name of remote
1257  *              Flag indicating the minimum pin code length to be 16 digits
1258 */
1259 typedef uint8_t(tBTM_PIN_CALLBACK)(const RawAddress& bd_addr,
1260                                    DEV_CLASS dev_class, tBTM_BD_NAME bd_name,
1261                                    bool min_16_digit);
1262 
1263 /* New Link Key for the connection.  Parameters are
1264  *              BD Address of remote
1265  *              Link Key
1266  *              Key Type: Combination, Local Unit, or Remote Unit
1267 */
1268 typedef uint8_t(tBTM_LINK_KEY_CALLBACK)(const RawAddress& bd_addr,
1269                                         DEV_CLASS dev_class,
1270                                         tBTM_BD_NAME bd_name,
1271                                         const LinkKey& key, uint8_t key_type);
1272 
1273 /* Remote Name Resolved.  Parameters are
1274  *              BD Address of remote
1275  *              BD Name of remote
1276 */
1277 typedef void(tBTM_RMT_NAME_CALLBACK)(const RawAddress& bd_addr, DEV_CLASS dc,
1278                                      tBTM_BD_NAME bd_name);
1279 
1280 /* Authentication complete for the connection.  Parameters are
1281  *              BD Address of remote
1282  *              Device Class of remote
1283  *              BD Name of remote
1284  *
1285 */
1286 typedef uint8_t(tBTM_AUTH_COMPLETE_CALLBACK)(const RawAddress& bd_addr,
1287                                              DEV_CLASS dev_class,
1288                                              tBTM_BD_NAME bd_name, int result);
1289 
1290 enum {
1291   BTM_SP_IO_REQ_EVT,    /* received IO_CAPABILITY_REQUEST event */
1292   BTM_SP_IO_RSP_EVT,    /* received IO_CAPABILITY_RESPONSE event */
1293   BTM_SP_CFM_REQ_EVT,   /* received USER_CONFIRMATION_REQUEST event */
1294   BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */
1295   BTM_SP_KEY_REQ_EVT,   /* received USER_PASSKEY_REQUEST event */
1296   BTM_SP_KEYPRESS_EVT,  /* received KEYPRESS_NOTIFY event */
1297   BTM_SP_LOC_OOB_EVT,   /* received result for READ_LOCAL_OOB_DATA command */
1298   BTM_SP_RMT_OOB_EVT,   /* received REMOTE_OOB_DATA_REQUEST event */
1299   BTM_SP_COMPLT_EVT,    /* received SIMPLE_PAIRING_COMPLETE event */
1300   BTM_SP_UPGRADE_EVT /* check if the application wants to upgrade the link key
1301                         */
1302 };
1303 typedef uint8_t tBTM_SP_EVT;
1304 
1305 #define BTM_IO_CAP_OUT 0    /* DisplayOnly */
1306 #define BTM_IO_CAP_IO 1     /* DisplayYesNo */
1307 #define BTM_IO_CAP_IN 2     /* KeyboardOnly */
1308 #define BTM_IO_CAP_NONE 3   /* NoInputNoOutput */
1309 #define BTM_IO_CAP_KBDISP 4 /* Keyboard display */
1310 #define BTM_IO_CAP_MAX 5
1311 #define BTM_IO_CAP_UNKNOWN 0xFF /* Unknown value */
1312 
1313 typedef uint8_t tBTM_IO_CAP;
1314 
1315 #define BTM_MAX_PASSKEY_VAL (999999)
1316 #define BTM_MIN_PASSKEY_VAL (0)
1317 
1318 /* MITM Protection Not Required - Single Profile/non-bonding Numeric comparison
1319  * with automatic accept allowed */
1320 #define BTM_AUTH_SP_NO 0
1321 /* MITM Protection Required - Single Profile/non-bonding. Use IO Capabilities to
1322  * determine authentication procedure */
1323 #define BTM_AUTH_SP_YES 1
1324 /* MITM Protection Not Required - All Profiles/dedicated bonding Numeric
1325  * comparison with automatic accept allowed */
1326 #define BTM_AUTH_AP_NO 2
1327 /* MITM Protection Required - All Profiles/dedicated bonding Use IO Capabilities
1328  * to determine authentication procedure */
1329 #define BTM_AUTH_AP_YES 3
1330 /* MITM Protection Not Required - Single Profiles/general bonding Numeric
1331  * comparison with automatic accept allowed */
1332 #define BTM_AUTH_SPGB_NO 4
1333 /* MITM Protection Required - Single Profiles/general bonding Use IO
1334  * Capabilities to determine authentication procedure */
1335 #define BTM_AUTH_SPGB_YES 5
1336 
1337 /* this bit is ORed with BTM_AUTH_SP_* when IO exchange for dedicated bonding */
1338 #define BTM_AUTH_DD_BOND 2
1339 #define BTM_AUTH_GB_BIT 4 /* the genernal bonding bit */
1340 #define BTM_AUTH_BONDS 6  /* the general/dedicated bonding bits  */
1341 #define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit  */
1342 
1343 #define BTM_BLE_INITIATOR_KEY_SIZE 15
1344 #define BTM_BLE_RESPONDER_KEY_SIZE 15
1345 #define BTM_BLE_MAX_KEY_SIZE 16
1346 
1347 typedef uint8_t tBTM_AUTH_REQ;
1348 
1349 enum { BTM_OOB_NONE, BTM_OOB_PRESENT, BTM_OOB_UNKNOWN };
1350 typedef uint8_t tBTM_OOB_DATA;
1351 
1352 /* data type for BTM_SP_IO_REQ_EVT */
1353 typedef struct {
1354   RawAddress bd_addr;     /* peer address */
1355   tBTM_IO_CAP io_cap;     /* local IO capabilities */
1356   tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */
1357   tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */
1358   bool is_orig;           /* true, if local device initiated the SP process */
1359 } tBTM_SP_IO_REQ;
1360 
1361 /* data type for BTM_SP_IO_RSP_EVT */
1362 typedef struct {
1363   RawAddress bd_addr; /* peer address */
1364   tBTM_IO_CAP io_cap; /* peer IO capabilities */
1365   tBTM_OOB_DATA
1366       oob_data; /* OOB data present at peer device for the local device */
1367   tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */
1368 } tBTM_SP_IO_RSP;
1369 
1370 /* data type for BTM_SP_CFM_REQ_EVT */
1371 typedef struct {
1372   RawAddress bd_addr;   /* peer address */
1373   DEV_CLASS dev_class;  /* peer CoD */
1374   tBTM_BD_NAME bd_name; /* peer device name */
1375   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
1376                        show this number to UI */
1377   bool just_works;  /* true, if "Just Works" association model */
1378   tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
1379   tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
1380   tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of the local device */
1381   tBTM_IO_CAP rmt_io_caps;    /* IO Capabilities of the remot device */
1382 } tBTM_SP_CFM_REQ;
1383 
1384 /* data type for BTM_SP_KEY_REQ_EVT */
1385 typedef struct {
1386   RawAddress bd_addr;   /* peer address */
1387   DEV_CLASS dev_class;  /* peer CoD */
1388   tBTM_BD_NAME bd_name; /* peer device name */
1389 } tBTM_SP_KEY_REQ;
1390 
1391 /* data type for BTM_SP_KEY_NOTIF_EVT */
1392 typedef struct {
1393   RawAddress bd_addr;   /* peer address */
1394   DEV_CLASS dev_class;  /* peer CoD */
1395   tBTM_BD_NAME bd_name; /* peer device name */
1396   uint32_t passkey;     /* passkey */
1397 } tBTM_SP_KEY_NOTIF;
1398 
1399 enum {
1400   BTM_SP_KEY_STARTED,     /* 0 - passkey entry started */
1401   BTM_SP_KEY_ENTERED,     /* 1 - passkey digit entered */
1402   BTM_SP_KEY_ERASED,      /* 2 - passkey digit erased */
1403   BTM_SP_KEY_CLEARED,     /* 3 - passkey cleared */
1404   BTM_SP_KEY_COMPLT,      /* 4 - passkey entry completed */
1405   BTM_SP_KEY_OUT_OF_RANGE /* 5 - out of range */
1406 };
1407 typedef uint8_t tBTM_SP_KEY_TYPE;
1408 
1409 /* data type for BTM_SP_KEYPRESS_EVT */
1410 typedef struct {
1411   RawAddress bd_addr; /* peer address */
1412   tBTM_SP_KEY_TYPE notif_type;
1413 } tBTM_SP_KEYPRESS;
1414 
1415 /* data type for BTM_SP_LOC_OOB_EVT */
1416 typedef struct {
1417   tBTM_STATUS status; /* */
1418   Octet16 c;          /* Simple Pairing Hash C */
1419   Octet16 r;          /* Simple Pairing Randomnizer R */
1420 } tBTM_SP_LOC_OOB;
1421 
1422 /* data type for BTM_SP_RMT_OOB_EVT */
1423 typedef struct {
1424   RawAddress bd_addr;   /* peer address */
1425   DEV_CLASS dev_class;  /* peer CoD */
1426   tBTM_BD_NAME bd_name; /* peer device name */
1427 } tBTM_SP_RMT_OOB;
1428 
1429 /* data type for BTM_SP_COMPLT_EVT */
1430 typedef struct {
1431   RawAddress bd_addr;   /* peer address */
1432   DEV_CLASS dev_class;  /* peer CoD */
1433   tBTM_BD_NAME bd_name; /* peer device name */
1434   tBTM_STATUS status;   /* status of the simple pairing process */
1435 } tBTM_SP_COMPLT;
1436 
1437 /* data type for BTM_SP_UPGRADE_EVT */
1438 typedef struct {
1439   RawAddress bd_addr; /* peer address */
1440   bool upgrade;    /* true, to upgrade the link key */
1441 } tBTM_SP_UPGRADE;
1442 
1443 typedef union {
1444   tBTM_SP_IO_REQ io_req;       /* BTM_SP_IO_REQ_EVT      */
1445   tBTM_SP_IO_RSP io_rsp;       /* BTM_SP_IO_RSP_EVT      */
1446   tBTM_SP_CFM_REQ cfm_req;     /* BTM_SP_CFM_REQ_EVT     */
1447   tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT   */
1448   tBTM_SP_KEY_REQ key_req;     /* BTM_SP_KEY_REQ_EVT     */
1449   tBTM_SP_KEYPRESS key_press;  /* BTM_SP_KEYPRESS_EVT    */
1450   tBTM_SP_LOC_OOB loc_oob;     /* BTM_SP_LOC_OOB_EVT     */
1451   tBTM_SP_RMT_OOB rmt_oob;     /* BTM_SP_RMT_OOB_EVT     */
1452   tBTM_SP_COMPLT complt;       /* BTM_SP_COMPLT_EVT      */
1453   tBTM_SP_UPGRADE upgrade;     /* BTM_SP_UPGRADE_EVT      */
1454 } tBTM_SP_EVT_DATA;
1455 
1456 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
1457  * events occur.
1458 */
1459 typedef uint8_t(tBTM_SP_CALLBACK)(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data);
1460 
1461 typedef void(tBTM_MKEY_CALLBACK)(const RawAddress& bd_addr, uint8_t status,
1462                                  uint8_t key_flag);
1463 
1464 /* Encryption enabled/disabled complete: Optionally passed with
1465  * BTM_SetEncryption.
1466  * Parameters are
1467  *              BD Address of remote
1468  *              optional data passed in by BTM_SetEncryption
1469  *              tBTM_STATUS - result of the operation
1470 */
1471 typedef void(tBTM_SEC_CBACK)(const RawAddress* bd_addr, tBT_TRANSPORT trasnport,
1472                              void* p_ref_data, tBTM_STATUS result);
1473 
1474 /* Bond Cancel complete. Parameters are
1475  *              Result of the cancel operation
1476  *
1477 */
1478 typedef void(tBTM_BOND_CANCEL_CMPL_CALLBACK)(tBTM_STATUS result);
1479 
1480 /* LE related event and data structure */
1481 /* received IO_CAPABILITY_REQUEST event */
1482 #define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT
1483 /* security request event */
1484 #define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT
1485 /* received USER_PASSKEY_NOTIFY event */
1486 #define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT
1487 /* received USER_PASSKEY_REQUEST event */
1488 #define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT
1489 /* OOB data request event */
1490 #define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT
1491 /* Numeric Comparison request event */
1492 #define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT
1493 /* Peer keypress notification recd event */
1494 #define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT
1495 /* SC OOB request event (both local and peer OOB data) can be expected in
1496  * response */
1497 #define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT
1498 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */
1499 #define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT
1500 /* SMP over BR keys request event */
1501 #define BTM_LE_BR_KEYS_REQ_EVT SMP_BR_KEYS_REQ_EVT
1502 /* SMP complete event */
1503 #define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT
1504 #define BTM_LE_LAST_FROM_SMP BTM_LE_BR_KEYS_REQ_EVT
1505 /* KEY update event */
1506 #define BTM_LE_KEY_EVT (BTM_LE_LAST_FROM_SMP + 1)
1507 #define BTM_LE_CONSENT_REQ_EVT SMP_CONSENT_REQ_EVT
1508 typedef uint8_t tBTM_LE_EVT;
1509 
1510 #define BTM_LE_KEY_NONE 0
1511 /* encryption information of peer device */
1512 #define BTM_LE_KEY_PENC SMP_SEC_KEY_TYPE_ENC
1513 /* identity key of the peer device */
1514 #define BTM_LE_KEY_PID SMP_SEC_KEY_TYPE_ID
1515 /* peer SRK */
1516 #define BTM_LE_KEY_PCSRK SMP_SEC_KEY_TYPE_CSRK
1517 #define BTM_LE_KEY_PLK SMP_SEC_KEY_TYPE_LK
1518 #define BTM_LE_KEY_LLK (SMP_SEC_KEY_TYPE_LK << 4)
1519 /* master role security information:div */
1520 #define BTM_LE_KEY_LENC (SMP_SEC_KEY_TYPE_ENC << 4)
1521 /* master device ID key */
1522 #define BTM_LE_KEY_LID (SMP_SEC_KEY_TYPE_ID << 4)
1523 /* local CSRK has been deliver to peer */
1524 #define BTM_LE_KEY_LCSRK (SMP_SEC_KEY_TYPE_CSRK << 4)
1525 typedef uint8_t tBTM_LE_KEY_TYPE;
1526 
1527 #define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */
1528 #define BTM_LE_AUTH_REQ_BOND SMP_AUTH_BOND       /* 1 << 0 */
1529 #define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT     /* 1 << 2 */
1530 typedef uint8_t tBTM_LE_AUTH_REQ;
1531 #define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */
1532 #define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */
1533 #define BTM_LE_H7_SUPPORT_BIT SMP_H7_SUPPORT_BIT /* (1 << 5) */
1534 
1535 #define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY     /* 00101000 */
1536 #define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB           /* 00101001 */
1537 #define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB      /* 00101100 */
1538 #define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 00101101 */
1539 #define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK               /* 0x3D */
1540 
1541 /* LE security level */
1542 #define BTM_LE_SEC_NONE SMP_SEC_NONE
1543 #define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */
1544 #define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED   /* 4 */
1545 typedef uint8_t tBTM_LE_SEC;
1546 
1547 typedef struct {
1548   /* local IO capabilities */
1549   tBTM_IO_CAP io_cap;
1550   /* OOB data present (locally) for the peer device */
1551   uint8_t oob_data;
1552   /* Authentication request (for local device) containing bonding and MITM
1553    * info */
1554   tBTM_LE_AUTH_REQ auth_req;
1555   uint8_t max_key_size;       /* max encryption key size */
1556   tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */
1557   tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */
1558 } tBTM_LE_IO_REQ;
1559 
1560 /* data type for tBTM_LE_COMPLT */
1561 typedef struct {
1562   uint8_t reason;
1563   uint8_t sec_level;
1564   bool is_pair_cancel;
1565   bool smp_over_br;
1566 } tBTM_LE_COMPLT;
1567 
1568 /* BLE encryption keys */
1569 typedef struct {
1570   Octet16 ltk;
1571   BT_OCTET8 rand;
1572   uint16_t ediv;
1573   uint8_t sec_level;
1574   uint8_t key_size;
1575 } tBTM_LE_PENC_KEYS;
1576 
1577 /* BLE CSRK keys */
1578 typedef struct {
1579   uint32_t counter;
1580   Octet16 csrk;
1581   uint8_t sec_level;
1582 } tBTM_LE_PCSRK_KEYS;
1583 
1584 /* BLE Encryption reproduction keys */
1585 typedef struct {
1586   Octet16 ltk;
1587   uint16_t div;
1588   uint8_t key_size;
1589   uint8_t sec_level;
1590 } tBTM_LE_LENC_KEYS;
1591 
1592 /* BLE SRK keys */
1593 typedef struct {
1594   uint32_t counter;
1595   uint16_t div;
1596   uint8_t sec_level;
1597   Octet16 csrk;
1598 } tBTM_LE_LCSRK_KEYS;
1599 
1600 typedef struct {
1601   Octet16 irk;
1602   tBLE_ADDR_TYPE identity_addr_type;
1603   RawAddress identity_addr;
1604 } tBTM_LE_PID_KEYS;
1605 
1606 typedef union {
1607   tBTM_LE_PENC_KEYS penc_key;   /* received peer encryption key */
1608   tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
1609   tBTM_LE_PID_KEYS pid_key;     /* peer device ID key */
1610   tBTM_LE_LENC_KEYS lenc_key;   /* local encryption reproduction keys
1611                                  * LTK = = d1(ER,DIV,0) */
1612   tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
1613 } tBTM_LE_KEY_VALUE;
1614 
1615 typedef struct {
1616   tBTM_LE_KEY_TYPE key_type;
1617   tBTM_LE_KEY_VALUE* p_key_value;
1618 } tBTM_LE_KEY;
1619 
1620 typedef union {
1621   tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT      */
1622   uint32_t key_notif;    /* BTM_LE_KEY_NOTIF_EVT   */
1623                          /* BTM_LE_NC_REQ_EVT */
1624                          /* no callback data for
1625                           * BTM_LE_KEY_REQ_EVT
1626                           * and BTM_LE_OOB_REQ_EVT  */
1627   tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT      */
1628   tSMP_OOB_DATA_TYPE req_oob_type;
1629   tBTM_LE_KEY key;
1630 } tBTM_LE_EVT_DATA;
1631 
1632 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
1633  * events occur.
1634 */
1635 typedef uint8_t(tBTM_LE_CALLBACK)(tBTM_LE_EVT event, const RawAddress& bda,
1636                                   tBTM_LE_EVT_DATA* p_data);
1637 
1638 #define BTM_BLE_KEY_TYPE_ID 1
1639 #define BTM_BLE_KEY_TYPE_ER 2
1640 #define BTM_BLE_KEY_TYPE_COUNTER 3  // tobe obsolete
1641 
1642 typedef struct {
1643   Octet16 ir;
1644   Octet16 irk;
1645   Octet16 dhk;
1646 
1647 } tBTM_BLE_LOCAL_ID_KEYS;
1648 
1649 typedef union {
1650   tBTM_BLE_LOCAL_ID_KEYS id_keys;
1651   Octet16 er;
1652 } tBTM_BLE_LOCAL_KEYS;
1653 
1654 /* New LE identity key for local device.
1655 */
1656 typedef void(tBTM_LE_KEY_CALLBACK)(uint8_t key_type,
1657                                    tBTM_BLE_LOCAL_KEYS* p_key);
1658 
1659 /***************************
1660  *  Security Manager Types
1661  ***************************/
1662 /* Structure that applications use to register with BTM_SecRegister */
1663 typedef struct {
1664   tBTM_AUTHORIZE_CALLBACK* p_authorize_callback;
1665   tBTM_PIN_CALLBACK* p_pin_callback;
1666   tBTM_LINK_KEY_CALLBACK* p_link_key_callback;
1667   tBTM_AUTH_COMPLETE_CALLBACK* p_auth_complete_callback;
1668   tBTM_BOND_CANCEL_CMPL_CALLBACK* p_bond_cancel_cmpl_callback;
1669   tBTM_SP_CALLBACK* p_sp_callback;
1670   tBTM_LE_CALLBACK* p_le_callback;
1671   tBTM_LE_KEY_CALLBACK* p_le_key_callback;
1672 } tBTM_APPL_INFO;
1673 
1674 /* Callback function for when a link supervision timeout event occurs.
1675  * This asynchronous event is enabled/disabled by calling BTM_RegForLstoEvt().
1676 */
1677 typedef void(tBTM_LSTO_CBACK)(const RawAddress& remote_bda, uint16_t timeout);
1678 
1679 /*****************************************************************************
1680  *  POWER MANAGEMENT
1681  ****************************************************************************/
1682 /****************************
1683  *  Power Manager Constants
1684  ****************************/
1685 /* BTM Power manager status codes */
1686 enum {
1687   BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE,
1688   BTM_PM_STS_HOLD = HCI_MODE_HOLD,
1689   BTM_PM_STS_SNIFF = HCI_MODE_SNIFF,
1690   BTM_PM_STS_PARK = HCI_MODE_PARK,
1691   BTM_PM_STS_SSR,     /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */
1692   BTM_PM_STS_PENDING, /* when waiting for status from controller */
1693   BTM_PM_STS_ERROR    /* when HCI command status returns error */
1694 };
1695 typedef uint8_t tBTM_PM_STATUS;
1696 
1697 /* BTM Power manager modes */
1698 enum {
1699   BTM_PM_MD_ACTIVE = BTM_PM_STS_ACTIVE,
1700   BTM_PM_MD_HOLD = BTM_PM_STS_HOLD,
1701   BTM_PM_MD_SNIFF = BTM_PM_STS_SNIFF,
1702   BTM_PM_MD_PARK = BTM_PM_STS_PARK,
1703   BTM_PM_MD_FORCE = 0x10 /* OR this to force ACL link to a certain mode */
1704 };
1705 typedef uint8_t tBTM_PM_MODE;
1706 
1707 #define BTM_PM_SET_ONLY_ID 0x80
1708 
1709 /* Operation codes */
1710 /* The module wants to set the desired power mode */
1711 #define BTM_PM_REG_SET 1
1712 /* The module wants to receive mode change event */
1713 #define BTM_PM_REG_NOTIF 2
1714 /* The module does not want to involve with PM anymore */
1715 #define BTM_PM_DEREG 4
1716 
1717 /************************
1718  *  Power Manager Types
1719  ************************/
1720 typedef struct {
1721   uint16_t max;
1722   uint16_t min;
1723   uint16_t attempt;
1724   uint16_t timeout;
1725   tBTM_PM_MODE mode;
1726 } tBTM_PM_PWR_MD;
1727 
1728 /*************************************
1729  *  Power Manager Callback Functions
1730  *************************************/
1731 typedef void(tBTM_PM_STATUS_CBACK)(const RawAddress& p_bda,
1732                                    tBTM_PM_STATUS status, uint16_t value,
1733                                    uint8_t hci_status);
1734 
1735 /************************
1736  *  Stored Linkkey Types
1737  ************************/
1738 #define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4
1739 
1740 typedef struct {
1741   uint8_t event;
1742   uint8_t status;
1743   uint16_t num_keys;
1744 
1745 } tBTM_DELETE_STORED_LINK_KEY_COMPLETE;
1746 
1747 /* ACL link on, SCO link ongoing, sniff mode */
1748 #define BTM_CONTRL_ACTIVE 1
1749 /* Scan state - paging/inquiry/trying to connect*/
1750 #define BTM_CONTRL_SCAN 2
1751 /* Idle state - page scan, LE advt, inquiry scan */
1752 #define BTM_CONTRL_IDLE 3
1753 
1754 typedef uint8_t tBTM_CONTRL_STATE;
1755 
1756 #endif  // BTM_API_TYPES_H
1757