1 /*
2 *
3 * Copyright 2023 The Android Open Source Project
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 #pragma once
20
21 #include <base/strings/stringprintf.h>
22 #include <bluetooth/log.h>
23
24 #include <cstdint>
25 #include <string>
26
27 #include "macros.h"
28 #include "stack/include/bt_dev_class.h"
29 #include "stack/include/bt_name.h"
30 #include "stack/include/bt_octets.h"
31 #include "stack/include/hcidefs.h"
32 #include "stack/include/smp_api_types.h"
33 #include "stack/include/smp_status.h"
34 #include "types/bt_transport.h"
35 #include "types/raw_address.h"
36
37 typedef enum : uint8_t {
38 BTM_BLE_SEC_NONE = 0,
39 /* encrypt the link using current key */
40 BTM_BLE_SEC_ENCRYPT = 1,
41 BTM_BLE_SEC_ENCRYPT_NO_MITM = 2,
42 BTM_BLE_SEC_ENCRYPT_MITM = 3,
43 } tBTM_BLE_SEC_ACT;
44
45 /*****************************************************************************
46 * SECURITY MANAGEMENT
47 ****************************************************************************/
48 /*******************************
49 * Security Manager Constants
50 *******************************/
51
52 typedef enum : uint8_t {
53 BTM_SEC_MODE_SERVICE = 2,
54 BTM_SEC_MODE_SP = 4,
55 BTM_SEC_MODE_SC = 6,
56 } tSECURITY_MODE;
57
security_mode_text(const tSECURITY_MODE & security_mode)58 inline std::string security_mode_text(const tSECURITY_MODE& security_mode) {
59 switch (security_mode) {
60 case BTM_SEC_MODE_SERVICE:
61 return std::string("service");
62 case BTM_SEC_MODE_SP:
63 return std::string("simple pairing");
64 case BTM_SEC_MODE_SC:
65 return std::string("secure connections only");
66 default:
67 return base::StringPrintf("UNKNOWN[%hhu]", security_mode);
68 }
69 }
70
71 /* BTM_SEC security masks */
72 enum : uint16_t {
73 /* Nothing required */
74 BTM_SEC_NONE = 0x0000,
75 /* Inbound call requires authentication */
76 BTM_SEC_IN_AUTHENTICATE = 0x0002,
77 /* Inbound call requires encryption */
78 BTM_SEC_IN_ENCRYPT = 0x0004,
79 /* Outbound call requires authentication */
80 BTM_SEC_OUT_AUTHENTICATE = 0x0010,
81 /* Outbound call requires encryption */
82 BTM_SEC_OUT_ENCRYPT = 0x0020,
83 /* Secure Connections Only Mode */
84 BTM_SEC_MODE4_LEVEL4 = 0x0040,
85 /* Need to switch connection to be central */
86 BTM_SEC_FORCE_CENTRAL = 0x0100,
87 /* Need to switch connection to be central */
88 BTM_SEC_ATTEMPT_CENTRAL = 0x0200,
89 /* Need to switch connection to be peripheral */
90 BTM_SEC_FORCE_PERIPHERAL = 0x0400,
91 /* Try to switch connection to be peripheral */
92 BTM_SEC_ATTEMPT_PERIPHERAL = 0x0800,
93 /* inbound Do man in the middle protection */
94 BTM_SEC_IN_MITM = 0x1000,
95 /* outbound Do man in the middle protection */
96 BTM_SEC_OUT_MITM = 0x2000,
97 /* enforce a minimum of 16 digit for sec mode 2 */
98 BTM_SEC_IN_MIN_16_DIGIT_PIN = 0x4000,
99 };
100
101 /* Security Flags [bit mask] (BTM_GetSecurityFlags)
102 */
103 #define BTM_SEC_FLAG_AUTHENTICATED 0x02
104 #define BTM_SEC_FLAG_ENCRYPTED 0x04
105 #define BTM_SEC_FLAG_LKEY_KNOWN 0x10
106 #define BTM_SEC_FLAG_LKEY_AUTHED 0x20
107
108 /* Link Key types used to generate the new link key.
109 * returned in link key notification callback function
110 */
111 #define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION
112 #define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT
113 #define BTM_LKEY_TYPE_DEBUG_COMB HCI_LKEY_TYPE_DEBUG_COMB
114 #define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB
115 #define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB
116 #define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB
117
118 #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256
119 #define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256
120
linkkey_type_text(const int linkkey_type)121 inline std::string linkkey_type_text(const int linkkey_type) {
122 switch (linkkey_type) {
123 case BTM_LKEY_TYPE_COMBINATION:
124 return std::string("COMBINATION");
125 case BTM_LKEY_TYPE_REMOTE_UNIT:
126 return std::string("REMOTE_UNIT");
127 case BTM_LKEY_TYPE_DEBUG_COMB:
128 return std::string("DEBUG_COMB");
129 case BTM_LKEY_TYPE_UNAUTH_COMB:
130 return std::string("UNAUTH_COMB");
131 case BTM_LKEY_TYPE_AUTH_COMB:
132 return std::string("AUTH_COMB");
133 case BTM_LKEY_TYPE_CHANGED_COMB:
134 return std::string("CHANGED_COMB");
135 case BTM_LKEY_TYPE_UNAUTH_COMB_P_256:
136 return std::string("UNAUTH_COMB_P_256");
137 case BTM_LKEY_TYPE_AUTH_COMB_P_256:
138 return std::string("AUTH_COMB_P_256");
139 default:
140 return base::StringPrintf("UNKNOWN[0x%02x]", linkkey_type);
141 }
142 }
143
144 /* "easy" requirements for LK derived from LTK */
145 #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20
146 #define BTM_LKEY_TYPE_IGNORE \
147 0xff /* used when event is response from \
148 hci return link keys request */
149
150 typedef uint8_t tBTM_LINK_KEY_TYPE;
151
152 /* Protocol level security (BTM_SetSecurityLevel) */
153 #define BTM_SEC_PROTO_RFCOMM 3
154 #define BTM_SEC_PROTO_BNEP 5
155 #define BTM_SEC_PROTO_HID 6 /* HID */
156 #define BTM_SEC_PROTO_AVDT 7
157
158 #define BTM_SEC_SERVICE_HEADSET 8
159 #define BTM_SEC_SERVICE_HEADSET_AG 12
160 #define BTM_SEC_SERVICE_AG_HANDSFREE 29
161 #define BTM_SEC_SERVICE_RFC_MUX 42
162 #define BTM_SEC_SERVICE_HEARING_AID_LEFT 54
163 #define BTM_SEC_SERVICE_HEARING_AID_RIGHT 55
164 #define BTM_SEC_SERVICE_EATT 56
165
166 /* Update these as services are added */
167 #define BTM_SEC_SERVICE_FIRST_EMPTY 57
168
169 #ifndef BTM_SEC_MAX_SERVICES
170 #define BTM_SEC_MAX_SERVICES 75
171 #endif
172
173 /*******************************************************************************
174 * Security Services MACROS handle array of uint32_t bits for more than 32
175 * trusted services
176 ******************************************************************************/
177
178 typedef enum : uint8_t {
179 BTM_SP_IO_REQ_EVT, /* received IO_CAPABILITY_REQUEST event */
180 BTM_SP_IO_RSP_EVT, /* received IO_CAPABILITY_RESPONSE event */
181 BTM_SP_CFM_REQ_EVT, /* received USER_CONFIRMATION_REQUEST event */
182 BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */
183 BTM_SP_KEY_REQ_EVT, /* received USER_PASSKEY_REQUEST event */
184 BTM_SP_LOC_OOB_EVT, /* received result for READ_LOCAL_OOB_DATA command */
185 BTM_SP_RMT_OOB_EVT, /* received REMOTE_OOB_DATA_REQUEST event */
186 } tBTM_SP_EVT;
187
sp_evt_to_text(const tBTM_SP_EVT evt)188 inline std::string sp_evt_to_text(const tBTM_SP_EVT evt) {
189 switch (evt) {
190 CASE_RETURN_TEXT(BTM_SP_IO_REQ_EVT);
191 CASE_RETURN_TEXT(BTM_SP_IO_RSP_EVT);
192 CASE_RETURN_TEXT(BTM_SP_CFM_REQ_EVT);
193 CASE_RETURN_TEXT(BTM_SP_KEY_NOTIF_EVT);
194 CASE_RETURN_TEXT(BTM_SP_KEY_REQ_EVT);
195 CASE_RETURN_TEXT(BTM_SP_LOC_OOB_EVT);
196 CASE_RETURN_TEXT(BTM_SP_RMT_OOB_EVT);
197 }
198
199 return base::StringPrintf("UNKNOWN[%hhu]", evt);
200 }
201
202 enum : uint8_t {
203 BTM_IO_CAP_OUT = 0, /* DisplayOnly */
204 BTM_IO_CAP_IO = 1, /* DisplayYesNo */
205 BTM_IO_CAP_IN = 2, /* KeyboardOnly */
206 BTM_IO_CAP_NONE = 3, /* NoInputNoOutput */
207 BTM_IO_CAP_KBDISP = 4, /* Keyboard display */
208 BTM_IO_CAP_MAX = 5,
209 BTM_IO_CAP_UNKNOWN = 0xFF /* Unknown value */
210 };
211 typedef uint8_t tBTM_IO_CAP;
212
io_capabilities_text(const tBTM_IO_CAP & io_caps)213 inline std::string io_capabilities_text(const tBTM_IO_CAP& io_caps) {
214 switch (io_caps) {
215 case BTM_IO_CAP_OUT:
216 return std::string("Display only");
217 case BTM_IO_CAP_IO:
218 return std::string("Display yes-no");
219 case BTM_IO_CAP_IN:
220 return std::string("Keyboard Only");
221 case BTM_IO_CAP_NONE:
222 return std::string("No input or output");
223 case BTM_IO_CAP_KBDISP:
224 return std::string("Keyboard-Display");
225 default:
226 return base::StringPrintf("UNKNOWN[%hhu]", io_caps);
227 }
228 }
229
230 #define BTM_MAX_PASSKEY_VAL (999999)
231
232 typedef enum : uint8_t {
233 /* MITM Protection Not Required - Single Profile/non-bonding Numeric
234 * comparison with automatic accept allowed */
235 // NO_BONDING
236 BTM_AUTH_SP_NO = 0,
237 /* MITM Protection Required - Single Profile/non-bonding. Use IO Capabilities
238 * to determine authentication procedure */
239 // NO_BONDING_MITM_PROTECTION
240 BTM_AUTH_SP_YES = 1,
241 /* MITM Protection Not Required - All Profiles/dedicated bonding Numeric
242 * comparison with automatic accept allowed */
243 // DEDICATED_BONDING
244 BTM_AUTH_AP_NO = 2,
245 /* MITM Protection Required - All Profiles/dedicated bonding Use IO
246 * Capabilities to determine authentication procedure */
247 // DEDICATED_BONDING_MITM_PROTECTION
248 BTM_AUTH_AP_YES = 3,
249 /* MITM Protection Not Required - Single Profiles/general bonding Numeric
250 * comparison with automatic accept allowed */
251 // GENERAL_BONDING
252 BTM_AUTH_SPGB_NO = 4,
253 /* MITM Protection Required - Single Profiles/general bonding Use IO
254 * Capabilities to determine authentication procedure */
255 // GENERAL_BONDING_MITM_PROTECTION
256 BTM_AUTH_SPGB_YES = 5,
257 } tBTM_AUTH;
258
259 /* this bit is ORed with BTM_AUTH_SP_* when IO exchange for dedicated bonding */
260 #define BTM_AUTH_DD_BOND 2
261 #define BTM_AUTH_BONDS 6 /* the general/dedicated bonding bits */
262 #define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit */
263
264 #define BTM_BLE_INITIATOR_KEY_SIZE 15
265 #define BTM_BLE_RESPONDER_KEY_SIZE 15
266 #define BTM_BLE_MAX_KEY_SIZE 16
267
268 typedef uint8_t tBTM_AUTH_REQ;
269
270 enum {
271 BTM_OOB_NONE,
272 BTM_OOB_PRESENT_192,
273 BTM_OOB_PRESENT_256,
274 BTM_OOB_PRESENT_192_AND_256,
275 BTM_OOB_UNKNOWN
276 };
277
278 typedef uint8_t tBTM_OOB_DATA;
279
btm_oob_data_text(const tBTM_OOB_DATA & data)280 inline std::string btm_oob_data_text(const tBTM_OOB_DATA& data) {
281 switch (data) {
282 CASE_RETURN_TEXT(BTM_OOB_NONE);
283 CASE_RETURN_TEXT(BTM_OOB_PRESENT_192);
284 CASE_RETURN_TEXT(BTM_OOB_PRESENT_256);
285 CASE_RETURN_TEXT(BTM_OOB_PRESENT_192_AND_256);
286 CASE_RETURN_TEXT(BTM_OOB_UNKNOWN);
287 default:
288 return std::string("UNKNOWN[") + std::to_string(data) + std::string("]");
289 }
290 }
291
292 /* data type for BTM_SP_IO_REQ_EVT */
293 typedef struct {
294 RawAddress bd_addr; /* peer address */
295 tBTM_IO_CAP io_cap; /* local IO capabilities */
296 tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */
297 tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */
298 bool is_orig; /* true, if local device initiated the SP process */
299 } tBTM_SP_IO_REQ;
300
301 /* data type for BTM_SP_IO_RSP_EVT */
302 typedef struct {
303 RawAddress bd_addr; /* peer address */
304 tBTM_IO_CAP io_cap; /* peer IO capabilities */
305 tBTM_OOB_DATA
306 oob_data; /* OOB data present at peer device for the local device */
307 tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */
308 } tBTM_SP_IO_RSP;
309
310 /* data type for BTM_SP_CFM_REQ_EVT */
311 typedef struct {
312 RawAddress bd_addr; /* peer address */
313 DEV_CLASS dev_class; /* peer CoD */
314 BD_NAME bd_name; /* peer device name */
315 uint32_t num_val; /* the numeric value for comparison. If just_works, do not
316 show this number to UI */
317 bool just_works; /* true, if "Just Works" association model */
318 tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
319 tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
320 tBTM_IO_CAP loc_io_caps; /* IO Capabilities of the local device */
321 tBTM_IO_CAP rmt_io_caps; /* IO Capabilities of the remot device */
322 } tBTM_SP_CFM_REQ;
323
324 /* data type for BTM_SP_KEY_REQ_EVT */
325 typedef struct {
326 RawAddress bd_addr; /* peer address */
327 DEV_CLASS dev_class; /* peer CoD */
328 BD_NAME bd_name; /* peer device name */
329 } tBTM_SP_KEY_REQ;
330
331 /* data type for BTM_SP_KEY_NOTIF_EVT */
332 typedef struct {
333 RawAddress bd_addr; /* peer address */
334 DEV_CLASS dev_class; /* peer CoD */
335 BD_NAME bd_name; /* peer device name */
336 uint32_t passkey; /* passkey */
337 } tBTM_SP_KEY_NOTIF;
338
339 /* data type for BTM_SP_LOC_OOB_EVT */
340 typedef struct {
341 tBTM_STATUS status; /* */
342 Octet16 c_192; /* Simple Pairing Hash C from P-192 public key */
343 Octet16 r_192; /* Simple Pairing Randomnizer R from P-192 public key */
344 Octet16 c_256; /* Simple Pairing Hash C from P-256 public key */
345 Octet16 r_256; /* Simple Pairing Randomnizer R from P-256 public key */
346 } tBTM_SP_LOC_OOB;
347
348 /* data type for BTM_SP_RMT_OOB_EVT */
349 typedef struct {
350 RawAddress bd_addr; /* peer address */
351 DEV_CLASS dev_class; /* peer CoD */
352 BD_NAME bd_name; /* peer device name */
353 } tBTM_SP_RMT_OOB;
354
355 typedef union {
356 tBTM_SP_IO_REQ io_req; /* BTM_SP_IO_REQ_EVT */
357 tBTM_SP_IO_RSP io_rsp; /* BTM_SP_IO_RSP_EVT */
358 tBTM_SP_CFM_REQ cfm_req; /* BTM_SP_CFM_REQ_EVT */
359 tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT */
360 tBTM_SP_KEY_REQ key_req; /* BTM_SP_KEY_REQ_EVT */
361 tBTM_SP_LOC_OOB loc_oob; /* BTM_SP_LOC_OOB_EVT */
362 tBTM_SP_RMT_OOB rmt_oob; /* BTM_SP_RMT_OOB_EVT */
363 } tBTM_SP_EVT_DATA;
364
365 /* Simple Pairing Events. Called by the stack when Simple Pairing related
366 * events occur.
367 */
368 typedef tBTM_STATUS(tBTM_SP_CALLBACK)(tBTM_SP_EVT event,
369 tBTM_SP_EVT_DATA* p_data);
370
371 typedef void(tBTM_MKEY_CALLBACK)(const RawAddress& bd_addr, uint8_t status,
372 uint8_t key_flag);
373
374 /* Encryption enabled/disabled complete: Optionally passed with
375 * BTM_SetEncryption.
376 * Parameters are
377 * BD Address of remote
378 * optional data passed in by BTM_SetEncryption
379 * tBTM_STATUS - result of the operation
380 */
381 typedef void(tBTM_SEC_CALLBACK)(RawAddress bd_addr, tBT_TRANSPORT transport,
382 void* p_ref_data, tBTM_STATUS result);
383 typedef tBTM_SEC_CALLBACK tBTM_SEC_CALLBACK;
384
385 /* Bond Cancel complete. Parameters are
386 * Result of the cancel operation
387 *
388 */
389 typedef void(tBTM_BOND_CANCEL_CMPL_CALLBACK)(tBTM_STATUS result);
390
391 typedef enum : uint8_t {
392 /* LE related event and data structure */
393 /* received IO_CAPABILITY_REQUEST event */
394 BTM_LE_IO_REQ_EVT = SMP_IO_CAP_REQ_EVT,
395 /* security request event */
396 BTM_LE_SEC_REQUEST_EVT = SMP_SEC_REQUEST_EVT,
397
398 /* received USER_PASSKEY_NOTIFY event */
399 BTM_LE_KEY_NOTIF_EVT = SMP_PASSKEY_NOTIF_EVT,
400
401 /* received USER_PASSKEY_REQUEST event */
402 BTM_LE_KEY_REQ_EVT = SMP_PASSKEY_REQ_EVT,
403
404 /* OOB data request event */
405 BTM_LE_OOB_REQ_EVT = SMP_OOB_REQ_EVT,
406
407 /* Numeric Comparison request event */
408 BTM_LE_NC_REQ_EVT = SMP_NC_REQ_EVT,
409
410 /* Peer keypress notification recd event */
411 BTM_LE_PR_KEYPR_NOT_EVT = SMP_PEER_KEYPR_NOT_EVT,
412
413 /* SC OOB request event (both local and peer OOB data) can be expected in
414 * response */
415 BTM_LE_SC_OOB_REQ_EVT = SMP_SC_OOB_REQ_EVT,
416
417 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */
418 BTM_LE_SC_LOC_OOB_EVT = SMP_SC_LOC_OOB_DATA_UP_EVT,
419 /* SMP complete event */
420 BTM_LE_COMPLT_EVT = SMP_COMPLT_EVT,
421 BTM_LE_LAST_FROM_SMP = SMP_BR_KEYS_REQ_EVT,
422 /* KEY update event */
423 BTM_LE_KEY_EVT = (BTM_LE_LAST_FROM_SMP + 1),
424 BTM_LE_CONSENT_REQ_EVT = SMP_CONSENT_REQ_EVT,
425
426 /* Identity address associate event */
427 BTM_LE_ADDR_ASSOC_EVT = SMP_LE_ADDR_ASSOC_EVT,
428 } tBTM_LE_EVT;
429
ble_evt_to_text(const tBTM_LE_EVT evt)430 inline std::string ble_evt_to_text(const tBTM_LE_EVT evt) {
431 switch (evt) {
432 CASE_RETURN_TEXT(BTM_LE_IO_REQ_EVT);
433 CASE_RETURN_TEXT(BTM_LE_SEC_REQUEST_EVT);
434 CASE_RETURN_TEXT(BTM_LE_KEY_NOTIF_EVT);
435 CASE_RETURN_TEXT(BTM_LE_KEY_REQ_EVT);
436 CASE_RETURN_TEXT(BTM_LE_OOB_REQ_EVT);
437 CASE_RETURN_TEXT(BTM_LE_NC_REQ_EVT);
438 CASE_RETURN_TEXT(BTM_LE_PR_KEYPR_NOT_EVT);
439 CASE_RETURN_TEXT(BTM_LE_SC_OOB_REQ_EVT);
440 CASE_RETURN_TEXT(BTM_LE_SC_LOC_OOB_EVT);
441 CASE_RETURN_TEXT(BTM_LE_COMPLT_EVT);
442 CASE_RETURN_TEXT(BTM_LE_LAST_FROM_SMP);
443 CASE_RETURN_TEXT(BTM_LE_KEY_EVT);
444 CASE_RETURN_TEXT(BTM_LE_CONSENT_REQ_EVT);
445 CASE_RETURN_TEXT(BTM_LE_ADDR_ASSOC_EVT);
446 }
447
448 return base::StringPrintf("UNKNOWN[%hhu]", evt);
449 }
450
451 enum : uint8_t {
452 BTM_LE_KEY_NONE = 0,
453 BTM_LE_KEY_PENC = SMP_SEC_KEY_TYPE_ENC,
454 /* identity key of the peer device */
455 BTM_LE_KEY_PID = SMP_SEC_KEY_TYPE_ID,
456 /* peer SRK */
457 BTM_LE_KEY_PCSRK = SMP_SEC_KEY_TYPE_CSRK,
458 BTM_LE_KEY_PLK = SMP_SEC_KEY_TYPE_LK,
459 BTM_LE_KEY_LLK = (SMP_SEC_KEY_TYPE_LK << 4),
460 /* master role security information:div */
461 BTM_LE_KEY_LENC = (SMP_SEC_KEY_TYPE_ENC << 4),
462 /* master device ID key */
463 BTM_LE_KEY_LID = (SMP_SEC_KEY_TYPE_ID << 4),
464 /* local CSRK has been deliver to peer */
465 BTM_LE_KEY_LCSRK = (SMP_SEC_KEY_TYPE_CSRK << 4),
466 };
467 typedef uint8_t tBTM_LE_KEY_TYPE;
468
469 #define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */
470 #define BTM_LE_AUTH_REQ_BOND SMP_AUTH_BOND /* 1 << 0 */
471 #define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT /* 1 << 2 */
472 typedef uint8_t tBTM_LE_AUTH_REQ;
473 #define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */
474 #define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */
475 #define BTM_LE_H7_SUPPORT_BIT SMP_H7_SUPPORT_BIT /* (1 << 5) */
476
477 #define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY /* 00101000 */
478 #define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB /* 00101001 */
479 #define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB /* 00101100 */
480 #define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 00101101 */
481 #define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK /* 0x3D */
482
483 typedef struct {
484 /* local IO capabilities */
485 tBTM_IO_CAP io_cap;
486 /* OOB data present (locally) for the peer device */
487 uint8_t oob_data;
488 /* Authentication request (for local device) containing bonding and MITM
489 * info */
490 tBTM_LE_AUTH_REQ auth_req;
491 uint8_t max_key_size; /* max encryption key size */
492 tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */
493 tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */
494 } tBTM_LE_IO_REQ;
495
496 /* data type for tBTM_LE_COMPLT */
497 typedef struct {
498 tSMP_STATUS reason;
499 uint8_t sec_level;
500 bool is_pair_cancel;
501 bool smp_over_br;
502 } tBTM_LE_COMPLT;
503
504 /************************
505 * Stored Linkkey Types
506 ************************/
507 #define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4
508
509 typedef struct {
510 uint8_t event;
511 uint8_t status;
512 uint16_t num_keys;
513 } tBTM_DELETE_STORED_LINK_KEY_COMPLETE;
514
515 enum tBTM_BOND_TYPE : uint8_t {
516 BOND_TYPE_UNKNOWN = 0,
517 BOND_TYPE_PERSISTENT = 1,
518 BOND_TYPE_TEMPORARY = 2
519 };
520
bond_type_text(const tBTM_BOND_TYPE & bond_type)521 inline std::string bond_type_text(const tBTM_BOND_TYPE& bond_type) {
522 switch (bond_type) {
523 CASE_RETURN_TEXT(BOND_TYPE_UNKNOWN);
524 CASE_RETURN_TEXT(BOND_TYPE_PERSISTENT);
525 CASE_RETURN_TEXT(BOND_TYPE_TEMPORARY);
526 default:
527 return base::StringPrintf("UNKNOWN[%hhu]", bond_type);
528 }
529 }
530
531 namespace fmt {
532 template <>
533 struct formatter<tBTM_BLE_SEC_ACT> : enum_formatter<tBTM_BLE_SEC_ACT> {};
534 template <>
535 struct formatter<tBTM_BOND_TYPE> : enum_formatter<tBTM_BOND_TYPE> {};
536 } // namespace fmt
537