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