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 typedef uint16_t tBTM_SCO_CODEC_TYPE;
200
201 /*******************
202 * SCO Voice Settings
203 *******************/
204 #define BTM_VOICE_SETTING_CVSD \
205 ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
206 HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD))
207
208 #define BTM_VOICE_SETTING_TRANS \
209 ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \
210 HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_TRANSPNT))
211
212 /*******************
213 * SCO Data Status
214 *******************/
215 typedef uint8_t tBTM_SCO_DATA_FLAG;
216
217 /***************************
218 * SCO Callback Functions
219 ***************************/
220 typedef void(tBTM_SCO_CB)(uint16_t sco_inx);
221
222 /***************
223 * eSCO Types
224 ***************/
225 /* tBTM_ESCO_CBACK event types */
226 #define BTM_ESCO_CONN_REQ_EVT 2
227 typedef uint8_t tBTM_ESCO_EVT;
228
229 /* Structure passed with SCO change command and events.
230 * Used by both Sync and Enhanced sync messaging
231 */
232 typedef struct {
233 uint16_t max_latency_ms;
234 uint16_t packet_types;
235 uint8_t retransmission_effort;
236 } tBTM_CHG_ESCO_PARAMS;
237
238 /* Returned by BTM_ReadEScoLinkParms() */
239 struct tBTM_ESCO_DATA {
240 RawAddress bd_addr;
241 uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */
242 };
243
244 typedef struct {
245 uint16_t sco_inx;
246 RawAddress bd_addr;
247 DEV_CLASS dev_class;
248 tBTM_SCO_TYPE link_type;
249 } tBTM_ESCO_CONN_REQ_EVT_DATA;
250
251 typedef union {
252 tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt;
253 } tBTM_ESCO_EVT_DATA;
254
255 /***************************
256 * eSCO Callback Functions
257 ***************************/
258 typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data);
259
260 /*****************************************************************************
261 * SECURITY MANAGEMENT
262 ****************************************************************************/
263 /*******************************
264 * Security Manager Constants
265 *******************************/
266
267 typedef enum : uint8_t {
268 BTM_SEC_MODE_SERVICE = 2,
269 BTM_SEC_MODE_SP = 4,
270 BTM_SEC_MODE_SC = 6,
271 } tSECURITY_MODE;
272
security_mode_text(const tSECURITY_MODE & security_mode)273 inline std::string security_mode_text(const tSECURITY_MODE& security_mode) {
274 switch (security_mode) {
275 case BTM_SEC_MODE_SERVICE:
276 return std::string("service");
277 case BTM_SEC_MODE_SP:
278 return std::string("simple pairing");
279 case BTM_SEC_MODE_SC:
280 return std::string("secure connections only");
281 default:
282 return base::StringPrintf("UNKNOWN[%hhu]", security_mode);
283 }
284 }
285
286 /* BTM_SEC security masks */
287 enum : uint16_t {
288 /* Nothing required */
289 BTM_SEC_NONE = 0x0000,
290 /* Inbound call requires authentication */
291 BTM_SEC_IN_AUTHENTICATE = 0x0002,
292 /* Inbound call requires encryption */
293 BTM_SEC_IN_ENCRYPT = 0x0004,
294 /* Outbound call requires authentication */
295 BTM_SEC_OUT_AUTHENTICATE = 0x0010,
296 /* Outbound call requires encryption */
297 BTM_SEC_OUT_ENCRYPT = 0x0020,
298 /* Secure Connections Only Mode */
299 BTM_SEC_MODE4_LEVEL4 = 0x0040,
300 /* Need to switch connection to be central */
301 BTM_SEC_FORCE_CENTRAL = 0x0100,
302 /* Need to switch connection to be central */
303 BTM_SEC_ATTEMPT_CENTRAL = 0x0200,
304 /* Need to switch connection to be peripheral */
305 BTM_SEC_FORCE_PERIPHERAL = 0x0400,
306 /* Try to switch connection to be peripheral */
307 BTM_SEC_ATTEMPT_PERIPHERAL = 0x0800,
308 /* inbound Do man in the middle protection */
309 BTM_SEC_IN_MITM = 0x1000,
310 /* outbound Do man in the middle protection */
311 BTM_SEC_OUT_MITM = 0x2000,
312 /* enforce a minimum of 16 digit for sec mode 2 */
313 BTM_SEC_IN_MIN_16_DIGIT_PIN = 0x4000,
314 };
315
316 /* Security Flags [bit mask] (BTM_GetSecurityFlags)
317 */
318 #define BTM_SEC_FLAG_AUTHENTICATED 0x02
319 #define BTM_SEC_FLAG_ENCRYPTED 0x04
320 #define BTM_SEC_FLAG_LKEY_KNOWN 0x10
321 #define BTM_SEC_FLAG_LKEY_AUTHED 0x20
322
323 /* Link Key types used to generate the new link key.
324 * returned in link key notification callback function
325 */
326 #define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION
327 #define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT
328 #define BTM_LKEY_TYPE_DEBUG_COMB HCI_LKEY_TYPE_DEBUG_COMB
329 #define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB
330 #define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB
331 #define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB
332
333 #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256
334 #define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256
335
linkkey_type_text(const int linkkey_type)336 inline std::string linkkey_type_text(const int linkkey_type) {
337 switch (linkkey_type) {
338 case BTM_LKEY_TYPE_COMBINATION:
339 return std::string("COMBINATION");
340 case BTM_LKEY_TYPE_REMOTE_UNIT:
341 return std::string("REMOTE_UNIT");
342 case BTM_LKEY_TYPE_DEBUG_COMB:
343 return std::string("DEBUG_COMB");
344 case BTM_LKEY_TYPE_UNAUTH_COMB:
345 return std::string("UNAUTH_COMB");
346 case BTM_LKEY_TYPE_AUTH_COMB:
347 return std::string("AUTH_COMB");
348 case BTM_LKEY_TYPE_CHANGED_COMB:
349 return std::string("CHANGED_COMB");
350 case BTM_LKEY_TYPE_UNAUTH_COMB_P_256:
351 return std::string("UNAUTH_COMB_P_256");
352 case BTM_LKEY_TYPE_AUTH_COMB_P_256:
353 return std::string("AUTH_COMB_P_256");
354 default:
355 return base::StringPrintf("UNKNOWN[0x%02x]", linkkey_type);
356 }
357 }
358
359 /* "easy" requirements for LK derived from LTK */
360 #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20
361 #define BTM_LKEY_TYPE_IGNORE \
362 0xff /* used when event is response from \
363 hci return link keys request */
364
365 typedef uint8_t tBTM_LINK_KEY_TYPE;
366
367 /* Protocol level security (BTM_SetSecurityLevel) */
368 #define BTM_SEC_PROTO_RFCOMM 3
369 #define BTM_SEC_PROTO_BNEP 5
370 #define BTM_SEC_PROTO_HID 6 /* HID */
371 #define BTM_SEC_PROTO_AVDT 7
372
373 #define BTM_SEC_SERVICE_HEADSET 8
374 #define BTM_SEC_SERVICE_HEADSET_AG 12
375 #define BTM_SEC_SERVICE_AG_HANDSFREE 29
376 #define BTM_SEC_SERVICE_RFC_MUX 42
377 #define BTM_SEC_SERVICE_HEARING_AID_LEFT 54
378 #define BTM_SEC_SERVICE_HEARING_AID_RIGHT 55
379 #define BTM_SEC_SERVICE_EATT 56
380
381 /* Update these as services are added */
382 #define BTM_SEC_SERVICE_FIRST_EMPTY 57
383
384 #ifndef BTM_SEC_MAX_SERVICES
385 #define BTM_SEC_MAX_SERVICES 75
386 #endif
387
388 /*******************************************************************************
389 * Security Services MACROS handle array of uint32_t bits for more than 32
390 * trusted services
391 ******************************************************************************/
392
393 enum {
394 BTM_SP_IO_REQ_EVT, /* received IO_CAPABILITY_REQUEST event */
395 BTM_SP_IO_RSP_EVT, /* received IO_CAPABILITY_RESPONSE event */
396 BTM_SP_CFM_REQ_EVT, /* received USER_CONFIRMATION_REQUEST event */
397 BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */
398 BTM_SP_KEY_REQ_EVT, /* received USER_PASSKEY_REQUEST event */
399 BTM_SP_LOC_OOB_EVT, /* received result for READ_LOCAL_OOB_DATA command */
400 BTM_SP_RMT_OOB_EVT, /* received REMOTE_OOB_DATA_REQUEST event */
401 };
402 typedef uint8_t tBTM_SP_EVT;
403
404 enum : uint8_t {
405 BTM_IO_CAP_OUT = 0, /* DisplayOnly */
406 BTM_IO_CAP_IO = 1, /* DisplayYesNo */
407 BTM_IO_CAP_IN = 2, /* KeyboardOnly */
408 BTM_IO_CAP_NONE = 3, /* NoInputNoOutput */
409 BTM_IO_CAP_KBDISP = 4, /* Keyboard display */
410 BTM_IO_CAP_MAX = 5,
411 BTM_IO_CAP_UNKNOWN = 0xFF /* Unknown value */
412 };
413 typedef uint8_t tBTM_IO_CAP;
414
io_capabilities_text(const tBTM_IO_CAP & io_caps)415 inline std::string io_capabilities_text(const tBTM_IO_CAP& io_caps) {
416 switch (io_caps) {
417 case BTM_IO_CAP_OUT:
418 return std::string("Display only");
419 case BTM_IO_CAP_IO:
420 return std::string("Display yes-no");
421 case BTM_IO_CAP_IN:
422 return std::string("Keyboard Only");
423 case BTM_IO_CAP_NONE:
424 return std::string("No input or output");
425 case BTM_IO_CAP_KBDISP:
426 return std::string("Keyboard-Display");
427 default:
428 return base::StringPrintf("UNKNOWN[%hhu]", io_caps);
429 }
430 }
431
432 #define BTM_MAX_PASSKEY_VAL (999999)
433
434 typedef enum : uint8_t {
435 /* MITM Protection Not Required - Single Profile/non-bonding Numeric
436 * comparison with automatic accept allowed */
437 // NO_BONDING
438 BTM_AUTH_SP_NO = 0,
439 /* MITM Protection Required - Single Profile/non-bonding. Use IO Capabilities
440 * to determine authentication procedure */
441 // NO_BONDING_MITM_PROTECTION
442 BTM_AUTH_SP_YES = 1,
443 /* MITM Protection Not Required - All Profiles/dedicated bonding Numeric
444 * comparison with automatic accept allowed */
445 // DEDICATED_BONDING
446 BTM_AUTH_AP_NO = 2,
447 /* MITM Protection Required - All Profiles/dedicated bonding Use IO
448 * Capabilities to determine authentication procedure */
449 // DEDICATED_BONDING_MITM_PROTECTION
450 BTM_AUTH_AP_YES = 3,
451 /* MITM Protection Not Required - Single Profiles/general bonding Numeric
452 * comparison with automatic accept allowed */
453 // GENERAL_BONDING
454 BTM_AUTH_SPGB_NO = 4,
455 /* MITM Protection Required - Single Profiles/general bonding Use IO
456 * Capabilities to determine authentication procedure */
457 // GENERAL_BONDING_MITM_PROTECTION
458 BTM_AUTH_SPGB_YES = 5,
459 } tBTM_AUTH;
460
461 /* this bit is ORed with BTM_AUTH_SP_* when IO exchange for dedicated bonding */
462 #define BTM_AUTH_DD_BOND 2
463 #define BTM_AUTH_BONDS 6 /* the general/dedicated bonding bits */
464 #define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit */
465
466 #define BTM_BLE_INITIATOR_KEY_SIZE 15
467 #define BTM_BLE_RESPONDER_KEY_SIZE 15
468 #define BTM_BLE_MAX_KEY_SIZE 16
469
470 typedef uint8_t tBTM_AUTH_REQ;
471
472 enum {
473 BTM_OOB_NONE,
474 BTM_OOB_PRESENT_192,
475 BTM_OOB_PRESENT_256,
476 BTM_OOB_PRESENT_192_AND_256,
477 BTM_OOB_UNKNOWN
478 };
479
480 typedef uint8_t tBTM_OOB_DATA;
481
482 /* data type for BTM_SP_IO_REQ_EVT */
483 typedef struct {
484 RawAddress bd_addr; /* peer address */
485 tBTM_IO_CAP io_cap; /* local IO capabilities */
486 tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */
487 tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */
488 bool is_orig; /* true, if local device initiated the SP process */
489 } tBTM_SP_IO_REQ;
490
491 /* data type for BTM_SP_IO_RSP_EVT */
492 typedef struct {
493 RawAddress bd_addr; /* peer address */
494 tBTM_IO_CAP io_cap; /* peer IO capabilities */
495 tBTM_OOB_DATA
496 oob_data; /* OOB data present at peer device for the local device */
497 tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */
498 } tBTM_SP_IO_RSP;
499
500 /* data type for BTM_SP_CFM_REQ_EVT */
501 typedef struct {
502 RawAddress bd_addr; /* peer address */
503 DEV_CLASS dev_class; /* peer CoD */
504 tBTM_BD_NAME bd_name; /* peer device name */
505 uint32_t num_val; /* the numeric value for comparison. If just_works, do not
506 show this number to UI */
507 bool just_works; /* true, if "Just Works" association model */
508 tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
509 tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
510 tBTM_IO_CAP loc_io_caps; /* IO Capabilities of the local device */
511 tBTM_IO_CAP rmt_io_caps; /* IO Capabilities of the remot device */
512 } tBTM_SP_CFM_REQ;
513
514 /* data type for BTM_SP_KEY_REQ_EVT */
515 typedef struct {
516 RawAddress bd_addr; /* peer address */
517 DEV_CLASS dev_class; /* peer CoD */
518 tBTM_BD_NAME bd_name; /* peer device name */
519 } tBTM_SP_KEY_REQ;
520
521 /* data type for BTM_SP_KEY_NOTIF_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 passkey; /* passkey */
527 } tBTM_SP_KEY_NOTIF;
528
529 /* data type for BTM_SP_LOC_OOB_EVT */
530 typedef struct {
531 tBTM_STATUS status; /* */
532 Octet16 c; /* Simple Pairing Hash C */
533 Octet16 r; /* Simple Pairing Randomnizer R */
534 } tBTM_SP_LOC_OOB;
535
536 /* data type for BTM_SP_RMT_OOB_EVT */
537 typedef struct {
538 RawAddress bd_addr; /* peer address */
539 DEV_CLASS dev_class; /* peer CoD */
540 tBTM_BD_NAME bd_name; /* peer device name */
541 } tBTM_SP_RMT_OOB;
542
543 typedef union {
544 tBTM_SP_IO_REQ io_req; /* BTM_SP_IO_REQ_EVT */
545 tBTM_SP_IO_RSP io_rsp; /* BTM_SP_IO_RSP_EVT */
546 tBTM_SP_CFM_REQ cfm_req; /* BTM_SP_CFM_REQ_EVT */
547 tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT */
548 tBTM_SP_KEY_REQ key_req; /* BTM_SP_KEY_REQ_EVT */
549 tBTM_SP_LOC_OOB loc_oob; /* BTM_SP_LOC_OOB_EVT */
550 tBTM_SP_RMT_OOB rmt_oob; /* BTM_SP_RMT_OOB_EVT */
551 } tBTM_SP_EVT_DATA;
552
553 /* Simple Pairing Events. Called by the stack when Simple Pairing related
554 * events occur.
555 */
556 typedef tBTM_STATUS(tBTM_SP_CALLBACK)(tBTM_SP_EVT event,
557 tBTM_SP_EVT_DATA* p_data);
558
559 typedef void(tBTM_MKEY_CALLBACK)(const RawAddress& bd_addr, uint8_t status,
560 uint8_t key_flag);
561
562 /* Encryption enabled/disabled complete: Optionally passed with
563 * BTM_SetEncryption.
564 * Parameters are
565 * BD Address of remote
566 * optional data passed in by BTM_SetEncryption
567 * tBTM_STATUS - result of the operation
568 */
569 typedef void(tBTM_SEC_CALLBACK)(const RawAddress* bd_addr,
570 tBT_TRANSPORT trasnport, void* p_ref_data,
571 tBTM_STATUS result);
572 typedef tBTM_SEC_CALLBACK tBTM_SEC_CALLBACK;
573
574 /* Bond Cancel complete. Parameters are
575 * Result of the cancel operation
576 *
577 */
578 typedef void(tBTM_BOND_CANCEL_CMPL_CALLBACK)(tBTM_STATUS result);
579
580 /* LE related event and data structure */
581 /* received IO_CAPABILITY_REQUEST event */
582 #define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT
583 /* security request event */
584 #define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT
585 /* received USER_PASSKEY_NOTIFY event */
586 #define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT
587 /* received USER_PASSKEY_REQUEST event */
588 #define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT
589 /* OOB data request event */
590 #define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT
591 /* Numeric Comparison request event */
592 #define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT
593 /* Peer keypress notification recd event */
594 #define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT
595 /* SC OOB request event (both local and peer OOB data) can be expected in
596 * response */
597 #define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT
598 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */
599 #define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT
600 /* SMP complete event */
601 #define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT
602 #define BTM_LE_LAST_FROM_SMP SMP_BR_KEYS_REQ_EVT
603 /* KEY update event */
604 #define BTM_LE_KEY_EVT (BTM_LE_LAST_FROM_SMP + 1)
605 #define BTM_LE_CONSENT_REQ_EVT SMP_CONSENT_REQ_EVT
606 /* Identity address associate event */
607 #define BTM_LE_ADDR_ASSOC_EVT SMP_LE_ADDR_ASSOC_EVT
608 typedef uint8_t tBTM_LE_EVT;
609
610 enum : uint8_t {
611 BTM_LE_KEY_NONE = 0,
612 BTM_LE_KEY_PENC = SMP_SEC_KEY_TYPE_ENC,
613 /* identity key of the peer device */
614 BTM_LE_KEY_PID = SMP_SEC_KEY_TYPE_ID,
615 /* peer SRK */
616 BTM_LE_KEY_PCSRK = SMP_SEC_KEY_TYPE_CSRK,
617 BTM_LE_KEY_PLK = SMP_SEC_KEY_TYPE_LK,
618 BTM_LE_KEY_LLK = (SMP_SEC_KEY_TYPE_LK << 4),
619 /* master role security information:div */
620 BTM_LE_KEY_LENC = (SMP_SEC_KEY_TYPE_ENC << 4),
621 /* master device ID key */
622 BTM_LE_KEY_LID = (SMP_SEC_KEY_TYPE_ID << 4),
623 /* local CSRK has been deliver to peer */
624 BTM_LE_KEY_LCSRK = (SMP_SEC_KEY_TYPE_CSRK << 4),
625 };
626 typedef uint8_t tBTM_LE_KEY_TYPE;
627
628 #define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */
629 #define BTM_LE_AUTH_REQ_BOND SMP_AUTH_BOND /* 1 << 0 */
630 #define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT /* 1 << 2 */
631 typedef uint8_t tBTM_LE_AUTH_REQ;
632 #define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */
633 #define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */
634 #define BTM_LE_H7_SUPPORT_BIT SMP_H7_SUPPORT_BIT /* (1 << 5) */
635
636 #define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY /* 00101000 */
637 #define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB /* 00101001 */
638 #define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB /* 00101100 */
639 #define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 00101101 */
640 #define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK /* 0x3D */
641
642 /* LE security level */
643 #define BTM_LE_SEC_NONE SMP_SEC_NONE
644 #define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */
645 #define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED /* 4 */
646 typedef uint8_t tBTM_LE_SEC;
647
648 typedef struct {
649 /* local IO capabilities */
650 tBTM_IO_CAP io_cap;
651 /* OOB data present (locally) for the peer device */
652 uint8_t oob_data;
653 /* Authentication request (for local device) containing bonding and MITM
654 * info */
655 tBTM_LE_AUTH_REQ auth_req;
656 uint8_t max_key_size; /* max encryption key size */
657 tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */
658 tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */
659 } tBTM_LE_IO_REQ;
660
661 /* data type for tBTM_LE_COMPLT */
662 typedef struct {
663 uint8_t reason;
664 uint8_t sec_level;
665 bool is_pair_cancel;
666 bool smp_over_br;
667 } tBTM_LE_COMPLT;
668
669 /*****************************************************************************
670 * POWER MANAGEMENT
671 ****************************************************************************/
672 /****************************
673 * Power Manager Constants
674 ****************************/
675 /* BTM Power manager status codes */
676 enum : uint8_t {
677 BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE, // 0x00
678 BTM_PM_STS_HOLD = HCI_MODE_HOLD, // 0x01
679 BTM_PM_STS_SNIFF = HCI_MODE_SNIFF, // 0x02
680 BTM_PM_STS_PARK = HCI_MODE_PARK, // 0x03
681 BTM_PM_STS_SSR, /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */
682 BTM_PM_STS_PENDING, /* when waiting for status from controller */
683 BTM_PM_STS_ERROR /* when HCI command status returns error */
684 };
685 typedef uint8_t tBTM_PM_STATUS;
686
power_mode_status_text(tBTM_PM_STATUS status)687 inline std::string power_mode_status_text(tBTM_PM_STATUS status) {
688 switch (status) {
689 case BTM_PM_STS_ACTIVE:
690 return std::string("active");
691 case BTM_PM_STS_HOLD:
692 return std::string("hold");
693 case BTM_PM_STS_SNIFF:
694 return std::string("sniff");
695 case BTM_PM_STS_PARK:
696 return std::string("park");
697 case BTM_PM_STS_SSR:
698 return std::string("sniff_subrating");
699 case BTM_PM_STS_PENDING:
700 return std::string("pending");
701 case BTM_PM_STS_ERROR:
702 return std::string("error");
703 default:
704 return std::string("UNKNOWN");
705 }
706 }
707
708 /* BTM Power manager modes */
709 enum : uint8_t {
710 BTM_PM_MD_ACTIVE = HCI_MODE_ACTIVE, // 0x00
711 BTM_PM_MD_HOLD = HCI_MODE_HOLD, // 0x01
712 BTM_PM_MD_SNIFF = HCI_MODE_SNIFF, // 0x02
713 BTM_PM_MD_PARK = HCI_MODE_PARK, // 0x03
714 BTM_PM_MD_FORCE = 0x10, /* OR this to force ACL link to a certain mode */
715 BTM_PM_MD_UNKNOWN = 0xEF,
716 };
717 typedef uint8_t tBTM_PM_MODE;
718 #define HCI_TO_BTM_POWER_MODE(mode) (static_cast<tBTM_PM_MODE>(mode))
719
is_legal_power_mode(tBTM_PM_MODE mode)720 inline bool is_legal_power_mode(tBTM_PM_MODE mode) {
721 switch (mode & ~BTM_PM_MD_FORCE) {
722 case BTM_PM_MD_ACTIVE:
723 case BTM_PM_MD_HOLD:
724 case BTM_PM_MD_SNIFF:
725 case BTM_PM_MD_PARK:
726 return true;
727 default:
728 return false;
729 }
730 }
731
power_mode_text(tBTM_PM_MODE mode)732 inline std::string power_mode_text(tBTM_PM_MODE mode) {
733 std::string s = base::StringPrintf((mode & BTM_PM_MD_FORCE) ? "" : "forced:");
734 switch (mode & ~BTM_PM_MD_FORCE) {
735 case BTM_PM_MD_ACTIVE:
736 return s + std::string("active");
737 case BTM_PM_MD_HOLD:
738 return s + std::string("hold");
739 case BTM_PM_MD_SNIFF:
740 return s + std::string("sniff");
741 case BTM_PM_MD_PARK:
742 return s + std::string("park");
743 default:
744 return s + std::string("UNKNOWN");
745 }
746 }
747
748 #define BTM_PM_SET_ONLY_ID 0x80
749
750 /* Operation codes */
751 typedef enum : uint8_t {
752 /* The module wants to set the desired power mode */
753 BTM_PM_REG_SET = (1u << 0),
754 /* The module does not want to involve with PM anymore */
755 BTM_PM_DEREG = (1u << 2),
756 } tBTM_PM_REGISTER;
757
758 /************************
759 * Power Manager Types
760 ************************/
761 typedef struct {
762 uint16_t max = 0;
763 uint16_t min = 0;
764 uint16_t attempt = 0;
765 uint16_t timeout = 0;
766 tBTM_PM_MODE mode = BTM_PM_MD_ACTIVE; // 0
767 } tBTM_PM_PWR_MD;
768
769 /*************************************
770 * Power Manager Callback Functions
771 *************************************/
772 typedef void(tBTM_PM_STATUS_CBACK)(const RawAddress& p_bda,
773 tBTM_PM_STATUS status, uint16_t value,
774 tHCI_STATUS hci_status);
775
776 /************************
777 * Stored Linkkey Types
778 ************************/
779 #define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4
780
781 typedef struct {
782 uint8_t event;
783 uint8_t status;
784 uint16_t num_keys;
785
786 } tBTM_DELETE_STORED_LINK_KEY_COMPLETE;
787
788 #define BTM_CONTRL_UNKNOWN 0
789 /* ACL link on, SCO link ongoing, sniff mode */
790 #define BTM_CONTRL_ACTIVE 1
791 /* Scan state - paging/inquiry/trying to connect*/
792 #define BTM_CONTRL_SCAN 2
793 /* Idle state - page scan, LE advt, inquiry scan */
794 #define BTM_CONTRL_IDLE 3
795
796 typedef uint8_t tBTM_CONTRL_STATE;
797
798 // Bluetooth Quality Report - Report receiver
799 typedef void(tBTM_BT_QUALITY_REPORT_RECEIVER)(uint8_t len,
800 const uint8_t* p_stream);
801
802 struct tREMOTE_VERSION_INFO {
803 uint8_t lmp_version{0};
804 uint16_t lmp_subversion{0};
805 uint16_t manufacturer{0};
806 bool valid{false};
ToStringtREMOTE_VERSION_INFO807 std::string ToString() const {
808 return (valid) ? base::StringPrintf("%02hhu-%05hu-%05hu", lmp_version,
809 lmp_subversion, manufacturer)
810 : std::string("UNKNOWN");
811 }
812 };
813 using remote_version_info = tREMOTE_VERSION_INFO;
814
815 #endif // BTM_API_TYPES_H
816