• 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 <base/strings/stringprintf.h>
23 #include <cstdint>
24 #include <string>
25 
26 #include "device/include/esco_parameters.h"
27 #include "internal_include/bt_target.h"
28 #include "stack/include/btm_status.h"
29 #include "stack/include/hcidefs.h"
30 #include "stack/include/smp_api_types.h"
31 #include "types/ble_address_with_type.h"
32 #include "types/bt_transport.h"
33 
34 /* Device name of peer (may be truncated to save space in BTM database) */
35 typedef uint8_t tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1];
36 
37 /* Structure returned with Vendor Specific Command complete callback */
38 typedef struct {
39   uint16_t opcode;
40   uint16_t param_len;
41   uint8_t* p_param_buf;
42 } tBTM_VSC_CMPL;
43 
44 /**************************************************
45  *  Device Control and General Callback Functions
46  **************************************************/
47 /* Callback function for when a vendor specific event occurs. The length and
48  * array of returned parameter bytes are included. This asynchronous event
49  * is enabled/disabled by calling BTM_RegisterForVSEvents().
50 */
51 typedef void(tBTM_VS_EVT_CB)(uint8_t len, uint8_t* p);
52 
53 /* General callback function for notifying an application that a synchronous
54  * BTM function is complete. The pointer contains the address of any returned
55  * data.
56  */
57 typedef void(tBTM_CMPL_CB)(void* p1);
58 
59 /* VSC callback function for notifying an application that a synchronous
60  * BTM function is complete. The pointer contains the address of any returned
61  * data.
62  */
63 typedef void(tBTM_VSC_CMPL_CB)(tBTM_VSC_CMPL* p1);
64 
65 /*****************************************************************************
66  *  DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
67  ****************************************************************************/
68 /*******************************
69  *  Device Discovery Constants
70  *******************************/
71 /****************************
72  * minor device class field
73  ****************************/
74 
75 /* 0x00 is used as unclassified for all minor device classes */
76 #define BTM_COD_MINOR_UNCLASSIFIED 0x00
77 #define BTM_COD_MINOR_CONFM_HANDSFREE 0x08
78 #define BTM_COD_MINOR_CAR_AUDIO 0x20
79 #define BTM_COD_MINOR_SET_TOP_BOX 0x24
80 
81 /* minor device class field for Peripheral Major Class */
82 /* Bits 6-7 independently specify mouse, keyboard, or combo mouse/keyboard */
83 #define BTM_COD_MINOR_KEYBOARD 0x40
84 #define BTM_COD_MINOR_POINTING 0x80
85 /* Bits 2-5 OR'd with selection from bits 6-7 */
86 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
87 #define BTM_COD_MINOR_JOYSTICK 0x04
88 #define BTM_COD_MINOR_GAMEPAD 0x08
89 #define BTM_COD_MINOR_REMOTE_CONTROL 0x0C
90 #define BTM_COD_MINOR_DIGITIZING_TABLET 0x14
91 #define BTM_COD_MINOR_CARD_READER 0x18 /* e.g. SIM card reader */
92 #define BTM_COD_MINOR_DIGITAL_PAN 0x1C
93 
94 /* minor device class field for Imaging Major Class */
95 /* Bits 5-7 independently specify display, camera, scanner, or printer */
96 #define BTM_COD_MINOR_DISPLAY 0x10
97 /* Bits 2-3 Reserved */
98 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
99 
100 /* minor device class field for Wearable Major Class */
101 /* Bits 2-7 meaningful    */
102 #define BTM_COD_MINOR_WRIST_WATCH 0x04
103 #define BTM_COD_MINOR_GLASSES 0x14
104 
105 /* minor device class field for Health Major Class */
106 /* Bits 2-7 meaningful    */
107 #define BTM_COD_MINOR_BLOOD_MONITOR 0x04
108 #define BTM_COD_MINOR_THERMOMETER 0x08
109 #define BTM_COD_MINOR_WEIGHING_SCALE 0x0C
110 #define BTM_COD_MINOR_GLUCOSE_METER 0x10
111 #define BTM_COD_MINOR_PULSE_OXIMETER 0x14
112 #define BTM_COD_MINOR_HEART_PULSE_MONITOR 0x18
113 #define BTM_COD_MINOR_STEP_COUNTER 0x20
114 
115 /***************************
116  * major device class field
117  ***************************/
118 #define BTM_COD_MAJOR_COMPUTER 0x01
119 #define BTM_COD_MAJOR_PHONE 0x02
120 #define BTM_COD_MAJOR_AUDIO 0x04
121 #define BTM_COD_MAJOR_PERIPHERAL 0x05
122 #define BTM_COD_MAJOR_IMAGING 0x06
123 #define BTM_COD_MAJOR_WEARABLE 0x07
124 #define BTM_COD_MAJOR_HEALTH 0x09
125 #define BTM_COD_MAJOR_UNCLASSIFIED 0x1F
126 
127 /***************************
128  * service class fields
129  ***************************/
130 #define BTM_COD_SERVICE_LMTD_DISCOVER 0x0020
131 #define BTM_COD_SERVICE_POSITIONING 0x0100
132 #define BTM_COD_SERVICE_NETWORKING 0x0200
133 #define BTM_COD_SERVICE_RENDERING 0x0400
134 #define BTM_COD_SERVICE_CAPTURING 0x0800
135 #define BTM_COD_SERVICE_OBJ_TRANSFER 0x1000
136 #define BTM_COD_SERVICE_AUDIO 0x2000
137 #define BTM_COD_SERVICE_TELEPHONY 0x4000
138 #define BTM_COD_SERVICE_INFORMATION 0x8000
139 
140 /* class of device field macros */
141 #define BTM_COD_MINOR_CLASS(u8, pd) \
142   { (u8) = (pd)[2] & 0xFC; }
143 #define BTM_COD_MAJOR_CLASS(u8, pd) \
144   { (u8) = (pd)[1] & 0x1F; }
145 #define BTM_COD_SERVICE_CLASS(u16, pd) \
146   {                                    \
147     (u16) = (pd)[0];                   \
148     (u16) <<= 8;                       \
149     (u16) += (pd)[1] & 0xE0;           \
150   }
151 
152 /* to set the fields (assumes that format type is always 0) */
153 #define FIELDS_TO_COD(pd, mn, mj, sv)                   \
154   {                                                     \
155     (pd)[2] = mn;                                       \
156     (pd)[1] = (mj) + ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \
157     (pd)[0] = (sv) >> 8;                                \
158   }
159 
160 /* the COD masks */
161 #define BTM_COD_MINOR_CLASS_MASK 0xFC
162 #define BTM_COD_MAJOR_CLASS_MASK 0x1F
163 #define BTM_COD_SERVICE_CLASS_LO_B 0x00E0
164 #define BTM_COD_SERVICE_CLASS_MASK 0xFFE0
165 
166 /* BTM service definitions
167  * Used for storing EIR data to bit mask
168 */
169 enum {
170   BTM_EIR_UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER,
171   /*    BTM_EIR_UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR,   */
172   /*    BTM_EIR_UUID_SERVCLASS_PUBLIC_BROWSE_GROUP,       */
173   BTM_EIR_UUID_SERVCLASS_SERIAL_PORT,
174   BTM_EIR_UUID_SERVCLASS_LAN_ACCESS_USING_PPP,
175   BTM_EIR_UUID_SERVCLASS_DIALUP_NETWORKING,
176   BTM_EIR_UUID_SERVCLASS_IRMC_SYNC,
177   BTM_EIR_UUID_SERVCLASS_OBEX_OBJECT_PUSH,
178   BTM_EIR_UUID_SERVCLASS_OBEX_FILE_TRANSFER,
179   BTM_EIR_UUID_SERVCLASS_IRMC_SYNC_COMMAND,
180   BTM_EIR_UUID_SERVCLASS_HEADSET,
181   BTM_EIR_UUID_SERVCLASS_CORDLESS_TELEPHONY,
182   BTM_EIR_UUID_SERVCLASS_AUDIO_SOURCE,
183   BTM_EIR_UUID_SERVCLASS_AUDIO_SINK,
184   BTM_EIR_UUID_SERVCLASS_AV_REM_CTRL_TARGET,
185   /*    BTM_EIR_UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION,    */
186   BTM_EIR_UUID_SERVCLASS_AV_REMOTE_CONTROL,
187   /*    BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING,        */
188   BTM_EIR_UUID_SERVCLASS_INTERCOM,
189   BTM_EIR_UUID_SERVCLASS_FAX,
190   BTM_EIR_UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY,
191   /*    BTM_EIR_UUID_SERVCLASS_WAP,                       */
192   /*    BTM_EIR_UUID_SERVCLASS_WAP_CLIENT,                */
193   BTM_EIR_UUID_SERVCLASS_PANU,
194   BTM_EIR_UUID_SERVCLASS_NAP,
195   BTM_EIR_UUID_SERVCLASS_GN,
196   BTM_EIR_UUID_SERVCLASS_DIRECT_PRINTING,
197   /*    BTM_EIR_UUID_SERVCLASS_REFERENCE_PRINTING,        */
198   BTM_EIR_UUID_SERVCLASS_IMAGING,
199   BTM_EIR_UUID_SERVCLASS_IMAGING_RESPONDER,
200   BTM_EIR_UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE,
201   BTM_EIR_UUID_SERVCLASS_IMAGING_REF_OBJECTS,
202   BTM_EIR_UUID_SERVCLASS_HF_HANDSFREE,
203   BTM_EIR_UUID_SERVCLASS_AG_HANDSFREE,
204   BTM_EIR_UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE,
205   /*    BTM_EIR_UUID_SERVCLASS_REFLECTED_UI,              */
206   BTM_EIR_UUID_SERVCLASS_BASIC_PRINTING,
207   BTM_EIR_UUID_SERVCLASS_PRINTING_STATUS,
208   BTM_EIR_UUID_SERVCLASS_HUMAN_INTERFACE,
209   BTM_EIR_UUID_SERVCLASS_CABLE_REPLACEMENT,
210   BTM_EIR_UUID_SERVCLASS_HCRP_PRINT,
211   BTM_EIR_UUID_SERVCLASS_HCRP_SCAN,
212   /*    BTM_EIR_UUID_SERVCLASS_COMMON_ISDN_ACCESS,        */
213   /*    BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING_GW,     */
214   /*    BTM_EIR_UUID_SERVCLASS_UDI_MT,                    */
215   /*    BTM_EIR_UUID_SERVCLASS_UDI_TA,                    */
216   /*    BTM_EIR_UUID_SERVCLASS_VCP,                       */
217   BTM_EIR_UUID_SERVCLASS_SAP,
218   BTM_EIR_UUID_SERVCLASS_PBAP_PCE,
219   BTM_EIR_UUID_SERVCLASS_PBAP_PSE,
220   /*    BTM_EIR_UUID_SERVCLASS_TE_PHONE_ACCESS,           */
221   /*    BTM_EIR_UUID_SERVCLASS_ME_PHONE_ACCESS,           */
222   BTM_EIR_UUID_SERVCLASS_PHONE_ACCESS,
223   BTM_EIR_UUID_SERVCLASS_HEADSET_HS,
224   BTM_EIR_UUID_SERVCLASS_PNP_INFORMATION,
225   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_NETWORKING,        */
226   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_FILETRANSFER,      */
227   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_AUDIO,             */
228   /*    BTM_EIR_UUID_SERVCLASS_GENERIC_TELEPHONY,         */
229   /*    BTM_EIR_UUID_SERVCLASS_UPNP_SERVICE,              */
230   /*    BTM_EIR_UUID_SERVCLASS_UPNP_IP_SERVICE,           */
231   /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_PAN,          */
232   /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_LAP,          */
233   /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP,        */
234   BTM_EIR_UUID_SERVCLASS_VIDEO_SOURCE,
235   BTM_EIR_UUID_SERVCLASS_VIDEO_SINK,
236   /*    BTM_EIR_UUID_SERVCLASS_VIDEO_DISTRIBUTION         */
237   /*    BTM_EIR_UUID_SERVCLASS_HDP_PROFILE                */
238   BTM_EIR_UUID_SERVCLASS_MESSAGE_ACCESS,
239   BTM_EIR_UUID_SERVCLASS_MESSAGE_NOTIFICATION,
240   BTM_EIR_UUID_SERVCLASS_HDP_SOURCE,
241   BTM_EIR_UUID_SERVCLASS_HDP_SINK,
242   BTM_EIR_MAX_SERVICES
243 };
244 
245 /* search result in EIR of inquiry database */
246 #define BTM_EIR_FOUND 0
247 #define BTM_EIR_NOT_FOUND 1
248 #define BTM_EIR_UNKNOWN 2
249 
250 typedef uint8_t tBTM_EIR_SEARCH_RESULT;
251 
252 /* 0x01 */
253 #define BTM_EIR_FLAGS_TYPE HCI_EIR_FLAGS_TYPE
254 /* 0x02 */
255 #define BTM_EIR_MORE_16BITS_UUID_TYPE HCI_EIR_MORE_16BITS_UUID_TYPE
256 /* 0x03 */
257 #define BTM_EIR_COMPLETE_16BITS_UUID_TYPE HCI_EIR_COMPLETE_16BITS_UUID_TYPE
258 /* 0x04 */
259 #define BTM_EIR_MORE_32BITS_UUID_TYPE HCI_EIR_MORE_32BITS_UUID_TYPE
260 /* 0x05 */
261 #define BTM_EIR_COMPLETE_32BITS_UUID_TYPE HCI_EIR_COMPLETE_32BITS_UUID_TYPE
262 /* 0x06 */
263 #define BTM_EIR_MORE_128BITS_UUID_TYPE HCI_EIR_MORE_128BITS_UUID_TYPE
264 /* 0x07 */
265 #define BTM_EIR_COMPLETE_128BITS_UUID_TYPE HCI_EIR_COMPLETE_128BITS_UUID_TYPE
266 /* 0x08 */
267 #define BTM_EIR_SHORTENED_LOCAL_NAME_TYPE HCI_EIR_SHORTENED_LOCAL_NAME_TYPE
268 /* 0x09 */
269 #define BTM_EIR_COMPLETE_LOCAL_NAME_TYPE HCI_EIR_COMPLETE_LOCAL_NAME_TYPE
270 /* 0x0A */
271 #define BTM_EIR_TX_POWER_LEVEL_TYPE HCI_EIR_TX_POWER_LEVEL_TYPE
272 
273 typedef enum : uint8_t {
274   BTM_BLE_SEC_NONE = 0,
275   /* encrypt the link using current key */
276   BTM_BLE_SEC_ENCRYPT = 1,
277   BTM_BLE_SEC_ENCRYPT_NO_MITM = 2,
278   BTM_BLE_SEC_ENCRYPT_MITM = 3,
279 } tBTM_BLE_SEC_ACT;
280 
281 /*******************************************************************************
282  * BTM Services MACROS handle array of uint32_t bits for more than 32 services
283  ******************************************************************************/
284 /* Determine the number of uint32_t's necessary for services */
285 #define BTM_EIR_ARRAY_BITS 32 /* Number of bits in each array element */
286 #define BTM_EIR_SERVICE_ARRAY_SIZE                         \
287   (((uint32_t)BTM_EIR_MAX_SERVICES / BTM_EIR_ARRAY_BITS) + \
288    (((uint32_t)BTM_EIR_MAX_SERVICES % BTM_EIR_ARRAY_BITS) ? 1 : 0))
289 
290 /* MACRO to set the service bit mask in a bit stream */
291 #define BTM_EIR_SET_SERVICE(p, service)                              \
292   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] |= \
293    ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS)))
294 
295 /* MACRO to clear the service bit mask in a bit stream */
296 #define BTM_EIR_CLR_SERVICE(p, service)                              \
297   (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] &= \
298    ~((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS)))
299 
300 /* MACRO to check the service bit mask in a bit stream */
301 #define BTM_EIR_HAS_SERVICE(p, service)                               \
302   ((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] &  \
303     ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) >> \
304    (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))
305 
306 /* start of EIR in HCI buffer, 4 bytes = HCI Command(2) + Length(1) + FEC_Req(1)
307  */
308 #define BTM_HCI_EIR_OFFSET (BT_HDR_SIZE + 4)
309 
310 /***************************
311  *  Device Discovery Types
312  ***************************/
313 /* Definitions of the parameters passed to BTM_StartInquiry.
314  */
315 typedef struct /* contains the two device class condition fields */
316 {
317   DEV_CLASS dev_class;
318   DEV_CLASS dev_class_mask;
319 } tBTM_COD_COND;
320 
321 constexpr uint8_t BLE_EVT_CONNECTABLE_BIT = 0;
322 constexpr uint8_t BLE_EVT_SCANNABLE_BIT = 1;
323 constexpr uint8_t BLE_EVT_DIRECTED_BIT = 2;
324 constexpr uint8_t BLE_EVT_SCAN_RESPONSE_BIT = 3;
325 constexpr uint8_t BLE_EVT_LEGACY_BIT = 4;
326 
327 constexpr uint8_t PHY_LE_NO_PACKET = 0x00;
328 constexpr uint8_t PHY_LE_1M = 0x01;
329 constexpr uint8_t PHY_LE_2M = 0x02;
330 constexpr uint8_t PHY_LE_CODED = 0x04;
331 
332 constexpr uint8_t NO_ADI_PRESENT = 0xFF;
333 constexpr uint8_t TX_POWER_NOT_PRESENT = 0x7F;
334 
335 typedef struct {
336   uint8_t pcm_intf_rate; /* PCM interface rate: 0: 128kbps, 1: 256 kbps;
337                              2:512 bps; 3: 1024kbps; 4: 2048kbps */
338   uint8_t frame_type;    /* frame type: 0: short; 1: long */
339   uint8_t sync_mode;     /* sync mode: 0: peripheral; 1: central */
340   uint8_t clock_mode;    /* clock mode: 0: peripheral; 1: central */
341 
342 } tBTM_SCO_PCM_PARAM;
343 
344 /*****************************************************************************
345  *  ACL CHANNEL MANAGEMENT
346  ****************************************************************************/
347 // NOTE: Moved to stack/include/acl_api_types.h
348 
349 /*****************************************************************************
350  *  SCO CHANNEL MANAGEMENT
351  ****************************************************************************/
352 /******************
353  *  SCO Constants
354  ******************/
355 
356 /* Define an invalid SCO index and an invalid HCI handle */
357 #define BTM_INVALID_SCO_INDEX 0xFFFF
358 
359 /* Define an invalid SCO disconnect reason */
360 #define BTM_INVALID_SCO_DISC_REASON 0xFFFF
361 
362 #define BTM_SCO_LINK_ONLY_MASK \
363   (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 | ESCO_PKT_TYPES_MASK_HV3)
364 
365 #define BTM_ESCO_LINK_ONLY_MASK \
366   (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5)
367 
368 /***************
369  *  SCO Types
370  ***************/
371 #define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO
372 #define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO
373 typedef uint8_t tBTM_SCO_TYPE;
374 
375 /*******************
376  * SCO Codec Types
377  *******************/
378 // TODO(google) This should use common definitions
379 #define BTM_SCO_CODEC_NONE 0x0000
380 #define BTM_SCO_CODEC_CVSD 0x0001
381 #define BTM_SCO_CODEC_MSBC 0x0002
382 typedef uint16_t tBTM_SCO_CODEC_TYPE;
383 
384 /*******************
385  * SCO Voice Settings
386  *******************/
387 #define BTM_VOICE_SETTING_CVSD                                         \
388   ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
389               HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD))
390 
391 #define BTM_VOICE_SETTING_TRANS                                        \
392   ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
393               HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_TRANSPNT))
394 
395 /*******************
396  * SCO Data Status
397  *******************/
398 typedef uint8_t tBTM_SCO_DATA_FLAG;
399 
400 /***************************
401  *  SCO Callback Functions
402  ***************************/
403 typedef void(tBTM_SCO_CB)(uint16_t sco_inx);
404 
405 /***************
406  *  eSCO Types
407  ***************/
408 /* tBTM_ESCO_CBACK event types */
409 #define BTM_ESCO_CHG_EVT 1
410 #define BTM_ESCO_CONN_REQ_EVT 2
411 typedef uint8_t tBTM_ESCO_EVT;
412 
413 /* Structure passed with SCO change command and events.
414  * Used by both Sync and Enhanced sync messaging
415  */
416 typedef struct {
417   uint16_t max_latency_ms;
418   uint16_t packet_types;
419   uint8_t retransmission_effort;
420 } tBTM_CHG_ESCO_PARAMS;
421 
422 /* Returned by BTM_ReadEScoLinkParms() */
423 struct tBTM_ESCO_DATA {
424   uint16_t rx_pkt_len;
425   uint16_t tx_pkt_len;
426   RawAddress bd_addr;
427   uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */
428   uint8_t tx_interval;
429   uint8_t retrans_window;
430   uint8_t air_mode;
431 };
432 
433 typedef struct {
434   uint16_t sco_inx;
435   uint16_t rx_pkt_len;
436   uint16_t tx_pkt_len;
437   RawAddress bd_addr;
438   uint8_t hci_status;
439   uint8_t tx_interval;
440   uint8_t retrans_window;
441 } tBTM_CHG_ESCO_EVT_DATA;
442 
443 typedef struct {
444   uint16_t sco_inx;
445   RawAddress bd_addr;
446   DEV_CLASS dev_class;
447   tBTM_SCO_TYPE link_type;
448 } tBTM_ESCO_CONN_REQ_EVT_DATA;
449 
450 typedef union {
451   tBTM_CHG_ESCO_EVT_DATA chg_evt;
452   tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt;
453 } tBTM_ESCO_EVT_DATA;
454 
455 /***************************
456  *  eSCO Callback Functions
457  ***************************/
458 typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data);
459 
460 /*****************************************************************************
461  *  SECURITY MANAGEMENT
462  ****************************************************************************/
463 /*******************************
464  *  Security Manager Constants
465  *******************************/
466 
467 typedef enum : uint8_t {
468   BTM_SEC_MODE_SERVICE = 2,
469   BTM_SEC_MODE_SP = 4,
470   BTM_SEC_MODE_SC = 6,
471 } tSECURITY_MODE;
472 
security_mode_text(const tSECURITY_MODE & security_mode)473 inline std::string security_mode_text(const tSECURITY_MODE& security_mode) {
474   switch (security_mode) {
475     case BTM_SEC_MODE_SERVICE:
476       return std::string("service");
477     case BTM_SEC_MODE_SP:
478       return std::string("simple pairing");
479     case BTM_SEC_MODE_SC:
480       return std::string("secure connections only");
481     default:
482       return std::string("UNKNOWN[%hhu]", security_mode);
483   }
484 }
485 
486 enum : uint16_t {
487   /* Nothing required */
488   BTM_SEC_NONE = 0x0000,
489   /* Inbound call requires authentication */
490   BTM_SEC_IN_AUTHENTICATE = 0x0002,
491   /* Inbound call requires encryption */
492   BTM_SEC_IN_ENCRYPT = 0x0004,
493   /* Outbound call requires authentication */
494   BTM_SEC_OUT_AUTHENTICATE = 0x0010,
495   /* Outbound call requires encryption */
496   BTM_SEC_OUT_ENCRYPT = 0x0020,
497   /* Secure Connections Only Mode */
498   BTM_SEC_MODE4_LEVEL4 = 0x0040,
499   /* Need to switch connection to be central */
500   BTM_SEC_FORCE_CENTRAL = 0x0100,
501   /* Need to switch connection to be central */
502   BTM_SEC_ATTEMPT_CENTRAL = 0x0200,
503   /* Need to switch connection to be peripheral */
504   BTM_SEC_FORCE_PERIPHERAL = 0x0400,
505   /* Try to switch connection to be peripheral */
506   BTM_SEC_ATTEMPT_PERIPHERAL = 0x0800,
507   /* inbound Do man in the middle protection */
508   BTM_SEC_IN_MITM = 0x1000,
509   /* outbound Do man in the middle protection */
510   BTM_SEC_OUT_MITM = 0x2000,
511   /* enforce a minimum of 16 digit for sec mode 2 */
512   BTM_SEC_IN_MIN_16_DIGIT_PIN = 0x4000,
513 };
514 
515 /* Security Flags [bit mask] (BTM_GetSecurityFlags)
516 */
517 #define BTM_SEC_FLAG_AUTHENTICATED 0x02
518 #define BTM_SEC_FLAG_ENCRYPTED 0x04
519 #define BTM_SEC_FLAG_LKEY_KNOWN 0x10
520 #define BTM_SEC_FLAG_LKEY_AUTHED 0x20
521 
522 /* Link Key types used to generate the new link key.
523  * returned in link key notification callback function
524 */
525 #define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION
526 #define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT
527 #define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB
528 #define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB
529 #define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB
530 
531 #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256
532 #define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256
533 
534 /* "easy" requirements for LK derived from LTK */
535 #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20
536 #define BTM_LKEY_TYPE_IGNORE               \
537   0xff /* used when event is response from \
538           hci return link keys request */
539 
540 typedef uint8_t tBTM_LINK_KEY_TYPE;
541 
542 /* Protocol level security (BTM_SetSecurityLevel) */
543 #define BTM_SEC_PROTO_RFCOMM 3
544 #define BTM_SEC_PROTO_BNEP 5
545 #define BTM_SEC_PROTO_HID 6 /* HID      */
546 #define BTM_SEC_PROTO_AVDT 7
547 
548 #define BTM_SEC_SERVICE_HEADSET 8
549 #define BTM_SEC_SERVICE_HEADSET_AG 12
550 #define BTM_SEC_SERVICE_AG_HANDSFREE 29
551 #define BTM_SEC_SERVICE_RFC_MUX 42
552 #define BTM_SEC_SERVICE_HEARING_AID_LEFT 54
553 #define BTM_SEC_SERVICE_HEARING_AID_RIGHT 55
554 #define BTM_SEC_SERVICE_EATT 56
555 
556 /* Update these as services are added */
557 #define BTM_SEC_SERVICE_FIRST_EMPTY 57
558 
559 #ifndef BTM_SEC_MAX_SERVICES
560 #define BTM_SEC_MAX_SERVICES 75
561 #endif
562 
563 /*******************************************************************************
564  * Security Services MACROS handle array of uint32_t bits for more than 32
565  * trusted services
566  ******************************************************************************/
567 
568 enum {
569   BTM_SP_IO_REQ_EVT,    /* received IO_CAPABILITY_REQUEST event */
570   BTM_SP_IO_RSP_EVT,    /* received IO_CAPABILITY_RESPONSE event */
571   BTM_SP_CFM_REQ_EVT,   /* received USER_CONFIRMATION_REQUEST event */
572   BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */
573   BTM_SP_KEY_REQ_EVT,   /* received USER_PASSKEY_REQUEST event */
574   BTM_SP_LOC_OOB_EVT,   /* received result for READ_LOCAL_OOB_DATA command */
575   BTM_SP_RMT_OOB_EVT,   /* received REMOTE_OOB_DATA_REQUEST event */
576 };
577 typedef uint8_t tBTM_SP_EVT;
578 
579 enum : uint8_t {
580   BTM_IO_CAP_OUT = 0,    /* DisplayOnly */
581   BTM_IO_CAP_IO = 1,     /* DisplayYesNo */
582   BTM_IO_CAP_IN = 2,     /* KeyboardOnly */
583   BTM_IO_CAP_NONE = 3,   /* NoInputNoOutput */
584   BTM_IO_CAP_KBDISP = 4, /* Keyboard display */
585   BTM_IO_CAP_MAX = 5,
586   BTM_IO_CAP_UNKNOWN = 0xFF /* Unknown value */
587 };
588 typedef uint8_t tBTM_IO_CAP;
589 
io_capabilities_text(const tBTM_IO_CAP & io_caps)590 inline std::string io_capabilities_text(const tBTM_IO_CAP& io_caps) {
591   switch (io_caps) {
592     case BTM_IO_CAP_OUT:
593       return std::string("Display only");
594     case BTM_IO_CAP_IO:
595       return std::string("Display yes-no");
596     case BTM_IO_CAP_IN:
597       return std::string("Keyboard Only");
598     case BTM_IO_CAP_NONE:
599       return std::string("No input or output");
600     case BTM_IO_CAP_KBDISP:
601       return std::string("Keyboard-Display");
602     default:
603       return base::StringPrintf("UNKNOWN[%hhu]", io_caps);
604   }
605 }
606 
607 #define BTM_MAX_PASSKEY_VAL (999999)
608 
609 typedef enum : uint8_t {
610   /* MITM Protection Not Required - Single Profile/non-bonding Numeric
611    * comparison with automatic accept allowed */
612   // NO_BONDING
613   BTM_AUTH_SP_NO = 0,
614   /* MITM Protection Required - Single Profile/non-bonding. Use IO Capabilities
615    * to determine authentication procedure */
616   // NO_BONDING_MITM_PROTECTION
617   BTM_AUTH_SP_YES = 1,
618   /* MITM Protection Not Required - All Profiles/dedicated bonding Numeric
619    * comparison with automatic accept allowed */
620   // DEDICATED_BONDING
621   BTM_AUTH_AP_NO = 2,
622   /* MITM Protection Required - All Profiles/dedicated bonding Use IO
623    * Capabilities to determine authentication procedure */
624   // DEDICATED_BONDING_MITM_PROTECTION
625   BTM_AUTH_AP_YES = 3,
626   /* MITM Protection Not Required - Single Profiles/general bonding Numeric
627    * comparison with automatic accept allowed */
628   // GENERAL_BONDING
629   BTM_AUTH_SPGB_NO = 4,
630   /* MITM Protection Required - Single Profiles/general bonding Use IO
631    * Capabilities to determine authentication procedure */
632   // GENERAL_BONDING_MITM_PROTECTION
633   BTM_AUTH_SPGB_YES = 5,
634 } tBTM_AUTH;
635 
636 /* this bit is ORed with BTM_AUTH_SP_* when IO exchange for dedicated bonding */
637 #define BTM_AUTH_DD_BOND 2
638 #define BTM_AUTH_BONDS 6  /* the general/dedicated bonding bits  */
639 #define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit  */
640 
641 #define BTM_BLE_INITIATOR_KEY_SIZE 15
642 #define BTM_BLE_RESPONDER_KEY_SIZE 15
643 #define BTM_BLE_MAX_KEY_SIZE 16
644 
645 typedef uint8_t tBTM_AUTH_REQ;
646 
647 enum {
648   BTM_OOB_NONE,
649   BTM_OOB_PRESENT_192,
650   BTM_OOB_PRESENT_256,
651   BTM_OOB_PRESENT_192_AND_256,
652   BTM_OOB_UNKNOWN
653 };
654 
655 typedef uint8_t tBTM_OOB_DATA;
656 
657 /* data type for BTM_SP_IO_REQ_EVT */
658 typedef struct {
659   RawAddress bd_addr;     /* peer address */
660   tBTM_IO_CAP io_cap;     /* local IO capabilities */
661   tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */
662   tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */
663   bool is_orig;           /* true, if local device initiated the SP process */
664 } tBTM_SP_IO_REQ;
665 
666 /* data type for BTM_SP_IO_RSP_EVT */
667 typedef struct {
668   RawAddress bd_addr; /* peer address */
669   tBTM_IO_CAP io_cap; /* peer IO capabilities */
670   tBTM_OOB_DATA
671       oob_data; /* OOB data present at peer device for the local device */
672   tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */
673 } tBTM_SP_IO_RSP;
674 
675 /* data type for BTM_SP_CFM_REQ_EVT */
676 typedef struct {
677   RawAddress bd_addr;   /* peer address */
678   DEV_CLASS dev_class;  /* peer CoD */
679   tBTM_BD_NAME bd_name; /* peer device name */
680   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
681                        show this number to UI */
682   bool just_works;  /* true, if "Just Works" association model */
683   tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
684   tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
685   tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of the local device */
686   tBTM_IO_CAP rmt_io_caps;    /* IO Capabilities of the remot device */
687 } tBTM_SP_CFM_REQ;
688 
689 /* data type for BTM_SP_KEY_REQ_EVT */
690 typedef struct {
691   RawAddress bd_addr;   /* peer address */
692   DEV_CLASS dev_class;  /* peer CoD */
693   tBTM_BD_NAME bd_name; /* peer device name */
694 } tBTM_SP_KEY_REQ;
695 
696 /* data type for BTM_SP_KEY_NOTIF_EVT */
697 typedef struct {
698   RawAddress bd_addr;   /* peer address */
699   DEV_CLASS dev_class;  /* peer CoD */
700   tBTM_BD_NAME bd_name; /* peer device name */
701   uint32_t passkey;     /* passkey */
702 } tBTM_SP_KEY_NOTIF;
703 
704 /* data type for BTM_SP_LOC_OOB_EVT */
705 typedef struct {
706   tBTM_STATUS status; /* */
707   Octet16 c;          /* Simple Pairing Hash C */
708   Octet16 r;          /* Simple Pairing Randomnizer R */
709 } tBTM_SP_LOC_OOB;
710 
711 /* data type for BTM_SP_RMT_OOB_EVT */
712 typedef struct {
713   RawAddress bd_addr;   /* peer address */
714   DEV_CLASS dev_class;  /* peer CoD */
715   tBTM_BD_NAME bd_name; /* peer device name */
716 } tBTM_SP_RMT_OOB;
717 
718 typedef union {
719   tBTM_SP_IO_REQ io_req;       /* BTM_SP_IO_REQ_EVT      */
720   tBTM_SP_IO_RSP io_rsp;       /* BTM_SP_IO_RSP_EVT      */
721   tBTM_SP_CFM_REQ cfm_req;     /* BTM_SP_CFM_REQ_EVT     */
722   tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT   */
723   tBTM_SP_KEY_REQ key_req;     /* BTM_SP_KEY_REQ_EVT     */
724   tBTM_SP_LOC_OOB loc_oob;     /* BTM_SP_LOC_OOB_EVT     */
725   tBTM_SP_RMT_OOB rmt_oob;     /* BTM_SP_RMT_OOB_EVT     */
726 } tBTM_SP_EVT_DATA;
727 
728 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
729  * events occur.
730 */
731 typedef tBTM_STATUS(tBTM_SP_CALLBACK)(tBTM_SP_EVT event,
732                                       tBTM_SP_EVT_DATA* p_data);
733 
734 typedef void(tBTM_MKEY_CALLBACK)(const RawAddress& bd_addr, uint8_t status,
735                                  uint8_t key_flag);
736 
737 /* Encryption enabled/disabled complete: Optionally passed with
738  * BTM_SetEncryption.
739  * Parameters are
740  *              BD Address of remote
741  *              optional data passed in by BTM_SetEncryption
742  *              tBTM_STATUS - result of the operation
743 */
744 typedef void(tBTM_SEC_CALLBACK)(const RawAddress* bd_addr,
745                                 tBT_TRANSPORT trasnport, void* p_ref_data,
746                                 tBTM_STATUS result);
747 typedef tBTM_SEC_CALLBACK tBTM_SEC_CALLBACK;
748 
749 /* Bond Cancel complete. Parameters are
750  *              Result of the cancel operation
751  *
752 */
753 typedef void(tBTM_BOND_CANCEL_CMPL_CALLBACK)(tBTM_STATUS result);
754 
755 /* LE related event and data structure */
756 /* received IO_CAPABILITY_REQUEST event */
757 #define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT
758 /* security request event */
759 #define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT
760 /* received USER_PASSKEY_NOTIFY event */
761 #define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT
762 /* received USER_PASSKEY_REQUEST event */
763 #define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT
764 /* OOB data request event */
765 #define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT
766 /* Numeric Comparison request event */
767 #define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT
768 /* Peer keypress notification recd event */
769 #define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT
770 /* SC OOB request event (both local and peer OOB data) can be expected in
771  * response */
772 #define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT
773 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */
774 #define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT
775 /* SMP complete event */
776 #define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT
777 #define BTM_LE_LAST_FROM_SMP SMP_BR_KEYS_REQ_EVT
778 /* KEY update event */
779 #define BTM_LE_KEY_EVT (BTM_LE_LAST_FROM_SMP + 1)
780 #define BTM_LE_CONSENT_REQ_EVT SMP_CONSENT_REQ_EVT
781 typedef uint8_t tBTM_LE_EVT;
782 
783 enum : uint8_t {
784   BTM_LE_KEY_NONE = 0,
785   BTM_LE_KEY_PENC = SMP_SEC_KEY_TYPE_ENC,
786   /* identity key of the peer device */
787   BTM_LE_KEY_PID = SMP_SEC_KEY_TYPE_ID,
788   /* peer SRK */
789   BTM_LE_KEY_PCSRK = SMP_SEC_KEY_TYPE_CSRK,
790   BTM_LE_KEY_PLK = SMP_SEC_KEY_TYPE_LK,
791   BTM_LE_KEY_LLK = (SMP_SEC_KEY_TYPE_LK << 4),
792   /* master role security information:div */
793   BTM_LE_KEY_LENC = (SMP_SEC_KEY_TYPE_ENC << 4),
794   /* master device ID key */
795   BTM_LE_KEY_LID = (SMP_SEC_KEY_TYPE_ID << 4),
796   /* local CSRK has been deliver to peer */
797   BTM_LE_KEY_LCSRK = (SMP_SEC_KEY_TYPE_CSRK << 4),
798 };
799 typedef uint8_t tBTM_LE_KEY_TYPE;
800 
801 #define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */
802 #define BTM_LE_AUTH_REQ_BOND SMP_AUTH_BOND       /* 1 << 0 */
803 #define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT     /* 1 << 2 */
804 typedef uint8_t tBTM_LE_AUTH_REQ;
805 #define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */
806 #define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */
807 #define BTM_LE_H7_SUPPORT_BIT SMP_H7_SUPPORT_BIT /* (1 << 5) */
808 
809 #define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY     /* 00101000 */
810 #define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB           /* 00101001 */
811 #define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB      /* 00101100 */
812 #define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 00101101 */
813 #define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK               /* 0x3D */
814 
815 /* LE security level */
816 #define BTM_LE_SEC_NONE SMP_SEC_NONE
817 #define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */
818 #define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED   /* 4 */
819 typedef uint8_t tBTM_LE_SEC;
820 
821 typedef struct {
822   /* local IO capabilities */
823   tBTM_IO_CAP io_cap;
824   /* OOB data present (locally) for the peer device */
825   uint8_t oob_data;
826   /* Authentication request (for local device) containing bonding and MITM
827    * info */
828   tBTM_LE_AUTH_REQ auth_req;
829   uint8_t max_key_size;       /* max encryption key size */
830   tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */
831   tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */
832 } tBTM_LE_IO_REQ;
833 
834 /* data type for tBTM_LE_COMPLT */
835 typedef struct {
836   uint8_t reason;
837   uint8_t sec_level;
838   bool is_pair_cancel;
839   bool smp_over_br;
840 } tBTM_LE_COMPLT;
841 
842 /*****************************************************************************
843  *  POWER MANAGEMENT
844  ****************************************************************************/
845 /****************************
846  *  Power Manager Constants
847  ****************************/
848 /* BTM Power manager status codes */
849 enum : uint8_t {
850   BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE,  // 0x00
851   BTM_PM_STS_HOLD = HCI_MODE_HOLD,      // 0x01
852   BTM_PM_STS_SNIFF = HCI_MODE_SNIFF,    // 0x02
853   BTM_PM_STS_PARK = HCI_MODE_PARK,      // 0x03
854   BTM_PM_STS_SSR,     /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */
855   BTM_PM_STS_PENDING, /* when waiting for status from controller */
856   BTM_PM_STS_ERROR    /* when HCI command status returns error */
857 };
858 typedef uint8_t tBTM_PM_STATUS;
859 
power_mode_status_text(tBTM_PM_STATUS status)860 inline std::string power_mode_status_text(tBTM_PM_STATUS status) {
861   switch (status) {
862     case BTM_PM_STS_ACTIVE:
863       return std::string("active");
864     case BTM_PM_STS_HOLD:
865       return std::string("hold");
866     case BTM_PM_STS_SNIFF:
867       return std::string("sniff");
868     case BTM_PM_STS_PARK:
869       return std::string("park");
870     case BTM_PM_STS_SSR:
871       return std::string("sniff_subrating");
872     case BTM_PM_STS_PENDING:
873       return std::string("pending");
874     case BTM_PM_STS_ERROR:
875       return std::string("error");
876     default:
877       return std::string("UNKNOWN");
878   }
879 }
880 
881 /* BTM Power manager modes */
882 enum : uint8_t {
883   BTM_PM_MD_ACTIVE = HCI_MODE_ACTIVE,  // 0x00
884   BTM_PM_MD_HOLD = HCI_MODE_HOLD,      // 0x01
885   BTM_PM_MD_SNIFF = HCI_MODE_SNIFF,    // 0x02
886   BTM_PM_MD_PARK = HCI_MODE_PARK,      // 0x03
887   BTM_PM_MD_FORCE = 0x10, /* OR this to force ACL link to a certain mode */
888   BTM_PM_MD_UNKNOWN = 0xEF,
889 };
890 typedef uint8_t tBTM_PM_MODE;
891 #define HCI_TO_BTM_POWER_MODE(mode) (static_cast<tBTM_PM_MODE>(mode))
892 
is_legal_power_mode(tBTM_PM_MODE mode)893 inline bool is_legal_power_mode(tBTM_PM_MODE mode) {
894   switch (mode & ~BTM_PM_MD_FORCE) {
895     case BTM_PM_MD_ACTIVE:
896     case BTM_PM_MD_HOLD:
897     case BTM_PM_MD_SNIFF:
898     case BTM_PM_MD_PARK:
899       return true;
900     default:
901       return false;
902   }
903 }
904 
power_mode_text(tBTM_PM_MODE mode)905 inline std::string power_mode_text(tBTM_PM_MODE mode) {
906   std::string s = base::StringPrintf((mode & BTM_PM_MD_FORCE) ? "" : "forced:");
907   switch (mode & ~BTM_PM_MD_FORCE) {
908     case BTM_PM_MD_ACTIVE:
909       return s + std::string("active");
910     case BTM_PM_MD_HOLD:
911       return s + std::string("hold");
912     case BTM_PM_MD_SNIFF:
913       return s + std::string("sniff");
914     case BTM_PM_MD_PARK:
915       return s + std::string("park");
916     default:
917       return s + std::string("UNKNOWN");
918   }
919 }
920 
921 #define BTM_PM_SET_ONLY_ID 0x80
922 
923 /* Operation codes */
924 typedef enum : uint8_t {
925   /* The module wants to set the desired power mode */
926   BTM_PM_REG_SET = (1u << 0),
927   /* The module does not want to involve with PM anymore */
928   BTM_PM_DEREG = (1u << 2),
929 } tBTM_PM_REGISTER;
930 
931 /************************
932  *  Power Manager Types
933  ************************/
934 typedef struct {
935   uint16_t max = 0;
936   uint16_t min = 0;
937   uint16_t attempt = 0;
938   uint16_t timeout = 0;
939   tBTM_PM_MODE mode = BTM_PM_MD_ACTIVE;  // 0
940 } tBTM_PM_PWR_MD;
941 
942 /*************************************
943  *  Power Manager Callback Functions
944  *************************************/
945 typedef void(tBTM_PM_STATUS_CBACK)(const RawAddress& p_bda,
946                                    tBTM_PM_STATUS status, uint16_t value,
947                                    tHCI_STATUS hci_status);
948 
949 /************************
950  *  Stored Linkkey Types
951  ************************/
952 #define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4
953 
954 typedef struct {
955   uint8_t event;
956   uint8_t status;
957   uint16_t num_keys;
958 
959 } tBTM_DELETE_STORED_LINK_KEY_COMPLETE;
960 
961 /* ACL link on, SCO link ongoing, sniff mode */
962 #define BTM_CONTRL_ACTIVE 1
963 /* Scan state - paging/inquiry/trying to connect*/
964 #define BTM_CONTRL_SCAN 2
965 /* Idle state - page scan, LE advt, inquiry scan */
966 #define BTM_CONTRL_IDLE 3
967 
968 typedef uint8_t tBTM_CONTRL_STATE;
969 
970 // Bluetooth Quality Report - Report receiver
971 typedef void(tBTM_BT_QUALITY_REPORT_RECEIVER)(uint8_t len, uint8_t* p_stream);
972 
973 struct tREMOTE_VERSION_INFO {
974   uint8_t lmp_version{0};
975   uint16_t lmp_subversion{0};
976   uint16_t manufacturer{0};
977   bool valid{false};
ToStringtREMOTE_VERSION_INFO978   std::string ToString() const {
979     return (valid) ? base::StringPrintf("%02hhu-%05hu-%05hu", lmp_version,
980                                         lmp_subversion, manufacturer)
981                    : std::string("UNKNOWN");
982   }
983 };
984 using remote_version_info = tREMOTE_VERSION_INFO;
985 
986 #endif  // BTM_API_TYPES_H
987