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 #pragma once
20
21 #include <base/logging.h>
22 #include <base/strings/stringprintf.h>
23 #include <string.h>
24
25 #include <cstdint>
26 #include <string>
27
28 #include "gd/crypto_toolbox/crypto_toolbox.h"
29 #include "main/shim/dumpsys.h"
30 #include "osi/include/alarm.h"
31 #include "stack/include/bt_device_type.h"
32 #include "stack/include/bt_octets.h"
33 #include "stack/include/btm_api_types.h"
34 #include "types/hci_role.h"
35 #include "types/raw_address.h"
36
37 typedef struct {
38 uint16_t min_conn_int;
39 uint16_t max_conn_int;
40 uint16_t peripheral_latency;
41 uint16_t supervision_tout;
42
43 } tBTM_LE_CONN_PRAMS;
44
45 /* The MSB of the clock offset field indicates whether the offset is valid. */
46 #define BTM_CLOCK_OFFSET_VALID 0x8000
47
48 /*
49 * Define structure for Security Service Record.
50 * A record exists for each service registered with the Security Manager
51 */
52 #define BTM_SEC_OUT_FLAGS (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT)
53 #define BTM_SEC_IN_FLAGS (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT)
54
55 #define BTM_SEC_OUT_LEVEL4_FLAGS \
56 (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_MITM | \
57 BTM_SEC_MODE4_LEVEL4)
58
59 #define BTM_SEC_IN_LEVEL4_FLAGS \
60 (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_MITM | \
61 BTM_SEC_MODE4_LEVEL4)
62 typedef struct {
63 uint32_t mx_proto_id; /* Service runs over this multiplexer protocol */
64 uint32_t orig_mx_chan_id; /* Channel on the multiplexer protocol */
65 uint32_t term_mx_chan_id; /* Channel on the multiplexer protocol */
66 uint16_t psm; /* L2CAP PSM value */
67 uint16_t security_flags; /* Bitmap of required security features */
68 uint8_t service_id; /* Passed in authorization callback */
69 uint8_t orig_service_name[BT_MAX_SERVICE_NAME_LEN + 1];
70 uint8_t term_service_name[BT_MAX_SERVICE_NAME_LEN + 1];
71 } tBTM_SEC_SERV_REC;
72
73 /* LE Security information of device in Peripheral Role */
74 typedef struct {
75 Octet16 irk; /* peer diverified identity root */
76 Octet16 pltk; /* peer long term key */
77 Octet16 pcsrk; /* peer SRK peer device used to secured sign local data */
78
79 Octet16 lltk; /* local long term key */
80 Octet16 lcsrk; /* local SRK peer device used to secured sign local data */
81
82 BT_OCTET8 rand; /* random vector for LTK generation */
83 uint16_t ediv; /* LTK diversifier of this peripheral device */
84 uint16_t div; /* local DIV to generate local LTK=d1(ER,DIV,0) and
85 CSRK=d1(ER,DIV,1) */
86 uint8_t sec_level; /* local pairing security level */
87 uint8_t key_size; /* key size of the LTK delivered to peer device */
88 uint8_t srk_sec_level; /* security property of peer SRK for this device */
89 uint8_t local_csrk_sec_level; /* security property of local CSRK for this
90 device */
91
92 uint32_t counter; /* peer sign counter for verifying rcv signed cmd */
93 uint32_t local_counter; /* local sign counter for sending signed write cmd*/
94 } tBTM_SEC_BLE_KEYS;
95
96 struct tBTM_SEC_BLE {
97 RawAddress pseudo_addr; /* LE pseudo address of the device if different from
98 device address */
99 private:
100 tBLE_ADDR_TYPE ble_addr_type_; /* LE device type: public or random address */
101
102 public:
AddressTypetBTM_SEC_BLE103 tBLE_ADDR_TYPE AddressType() const { return ble_addr_type_; }
SetAddressTypetBTM_SEC_BLE104 void SetAddressType(tBLE_ADDR_TYPE ble_addr_type) {
105 if (is_ble_addr_type_known(ble_addr_type)) {
106 ble_addr_type_ = ble_addr_type;
107 } else {
108 LOG(ERROR) << "Please don't store illegal addresses into security record:"
109 << AddressTypeText(ble_addr_type);
110 }
111 }
112
113 tBLE_BD_ADDR identity_address_with_type;
114
115 #define BTM_RESOLVING_LIST_BIT 0x02
116 uint8_t in_controller_list; /* in controller resolving list or not */
117 uint8_t resolving_list_index;
118 RawAddress cur_rand_addr; /* current random address */
119
120 typedef enum : uint8_t {
121 BTM_BLE_ADDR_PSEUDO = 0,
122 BTM_BLE_ADDR_RRA = 1,
123 BTM_BLE_ADDR_STATIC = 2,
124 } tADDRESS_TYPE;
125 tADDRESS_TYPE active_addr_type;
126
127 tBTM_LE_KEY_TYPE key_type; /* bit mask of valid key types in record */
128 tBTM_SEC_BLE_KEYS keys; /* LE device security info in peripheral rode */
129 };
130 typedef struct tBTM_SEC_BLE tBTM_SEC_BLE;
131
132 enum : uint16_t {
133 BTM_SEC_AUTHENTICATED = 0x0002,
134 BTM_SEC_ENCRYPTED = 0x0004,
135 BTM_SEC_NAME_KNOWN = 0x0008,
136 BTM_SEC_LINK_KEY_KNOWN = 0x0010,
137 BTM_SEC_LINK_KEY_AUTHED = 0x0020,
138 BTM_SEC_ROLE_SWITCHED = 0x0040, // UNUSED - only cleared
139 BTM_SEC_IN_USE = 0x0080, // UNUSED - only set
140 /* LE link security flag */
141 /* LE link is encrypted after pairing with MITM */
142 BTM_SEC_LE_AUTHENTICATED = 0x0200,
143 /* LE link is encrypted */
144 BTM_SEC_LE_ENCRYPTED = 0x0400,
145 /* not used */
146 BTM_SEC_LE_NAME_KNOWN = 0x0800, // UNUSED
147 /* bonded with peer (peer LTK and/or SRK is saved) */
148 BTM_SEC_LE_LINK_KEY_KNOWN = 0x1000,
149 /* pairing is done with MITM */
150 BTM_SEC_LE_LINK_KEY_AUTHED = 0x2000,
151 /* pairing is done with 16 digit pin */
152 BTM_SEC_16_DIGIT_PIN_AUTHED = 0x4000,
153 };
154
155 #define CASE_RETURN_TEXT(code) \
156 case code: \
157 return #code
158
159 typedef enum : uint8_t {
160 BTM_SEC_STATE_IDLE = 0,
161 BTM_SEC_STATE_AUTHENTICATING = 1,
162 BTM_SEC_STATE_ENCRYPTING = 2,
163 BTM_SEC_STATE_GETTING_NAME = 3,
164 BTM_SEC_STATE_AUTHORIZING = 4,
165 BTM_SEC_STATE_SWITCHING_ROLE = 5,
166 /* disconnecting BR/EDR */
167 BTM_SEC_STATE_DISCONNECTING = 6,
168 /* delay to check for encryption to work around */
169 /* controller problems */
170 BTM_SEC_STATE_DELAY_FOR_ENC = 7,
171 BTM_SEC_STATE_DISCONNECTING_BLE = 8,
172 BTM_SEC_STATE_DISCONNECTING_BOTH = 9,
173 BTM_SEC_STATE_LE_ENCRYPTING = 10,
174 } tSECURITY_STATE;
175
security_state_text(const tSECURITY_STATE & state)176 static inline std::string security_state_text(const tSECURITY_STATE& state) {
177 switch (state) {
178 CASE_RETURN_TEXT(BTM_SEC_STATE_IDLE);
179 CASE_RETURN_TEXT(BTM_SEC_STATE_AUTHENTICATING);
180 CASE_RETURN_TEXT(BTM_SEC_STATE_ENCRYPTING);
181 CASE_RETURN_TEXT(BTM_SEC_STATE_GETTING_NAME);
182 CASE_RETURN_TEXT(BTM_SEC_STATE_AUTHORIZING);
183 CASE_RETURN_TEXT(BTM_SEC_STATE_SWITCHING_ROLE);
184 CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING);
185 CASE_RETURN_TEXT(BTM_SEC_STATE_DELAY_FOR_ENC);
186 CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING_BLE);
187 CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING_BOTH);
188 CASE_RETURN_TEXT(BTM_SEC_STATE_LE_ENCRYPTING);
189 default:
190 return base::StringPrintf("UNKNOWN[%hhu]", state);
191 }
192 }
193
194 typedef enum : uint8_t {
195 BTM_SM4_UNKNOWN = 0x00,
196 BTM_SM4_KNOWN = 0x10,
197 BTM_SM4_TRUE = 0x11,
198 BTM_SM4_REQ_PEND = 0x08, /* set this bit when getting remote features */
199 BTM_SM4_UPGRADE = 0x04, /* set this bit when upgrading link key */
200 BTM_SM4_RETRY = 0x02, /* set this bit to retry on HCI_ERR_KEY_MISSING or \
201 HCI_ERR_LMP_ERR_TRANS_COLLISION */
202 BTM_SM4_DD_ACP =
203 0x20, /* set this bit to indicate peer initiated dedicated bonding */
204 BTM_SM4_CONN_PEND = 0x40, /* set this bit to indicate accepting acl conn; to
205 be cleared on \ btm_acl_created */
206 } tBTM_SM4_BIT;
207
class_of_device_text(const DEV_CLASS & cod)208 inline std::string class_of_device_text(const DEV_CLASS& cod) {
209 return base::StringPrintf("0x%02x%02x%02x", cod[2], cod[1], cod[0]);
210 }
211
212 /*
213 * Define structure for Security Device Record.
214 * A record exists for each device authenticated with this device
215 */
216 struct tBTM_SEC_DEV_REC {
217 /* Peering bond type */
218 typedef enum : uint8_t {
219 BOND_TYPE_UNKNOWN = 0,
220 BOND_TYPE_PERSISTENT = 1,
221 BOND_TYPE_TEMPORARY = 2
222 } tBTM_BOND_TYPE;
223
224 uint32_t required_security_flags_for_pairing;
225 tBTM_SEC_CALLBACK* p_callback;
226 void* p_ref_data;
227 uint32_t timestamp; /* Timestamp of the last connection */
228 uint16_t hci_handle; /* Handle to connection when exists */
229 uint16_t suggested_tx_octets; /* Recently suggested tx octects for data length
230 extension */
231 uint16_t clock_offset; /* Latest known clock offset */
232 RawAddress bd_addr; /* BD_ADDR of the device */
233 DEV_CLASS dev_class; /* DEV_CLASS of the device */
234 LinkKey link_key; /* Device link key */
235 tHCI_STATUS sec_status; /* Status in encryption change event */
236
237 public:
RemoteAddresstBTM_SEC_DEV_REC238 RawAddress RemoteAddress() const { return bd_addr; }
get_br_edr_hci_handletBTM_SEC_DEV_REC239 uint16_t get_br_edr_hci_handle() const { return hci_handle; }
240
241 private:
242 friend bool BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
243 const BD_NAME& bd_name, uint8_t* features,
244 LinkKey* p_link_key, uint8_t key_type,
245 uint8_t pin_length);
246 friend void BTM_PINCodeReply(const RawAddress& bd_addr, tBTM_STATUS res,
247 uint8_t pin_len, uint8_t* p_pin);
248 friend void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status);
249 friend void btm_sec_connected(const RawAddress& bda, uint16_t handle,
250 tHCI_STATUS status, uint8_t enc_mode,
251 tHCI_ROLE);
252 friend void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status,
253 uint8_t encr_enable);
254 friend void btm_sec_link_key_notification(const RawAddress& p_bda,
255 const Octet16& link_key,
256 uint8_t key_type);
257 friend tBTM_STATUS btm_sec_bond_by_transport(const RawAddress& bd_addr,
258 tBLE_ADDR_TYPE addr_type,
259 tBT_TRANSPORT transport,
260 uint8_t pin_len, uint8_t* p_pin);
261 uint8_t pin_code_length; /* Length of the pin_code used for paring */
262
263 public:
264 uint16_t sec_flags; /* Current device security state */
is_device_authenticatedtBTM_SEC_DEV_REC265 bool is_device_authenticated() const {
266 return sec_flags & BTM_SEC_AUTHENTICATED;
267 }
set_device_authenticatedtBTM_SEC_DEV_REC268 void set_device_authenticated() { sec_flags |= BTM_SEC_AUTHENTICATED; }
reset_device_authenticatedtBTM_SEC_DEV_REC269 void reset_device_authenticated() { sec_flags &= ~BTM_SEC_AUTHENTICATED; }
270
is_device_encryptedtBTM_SEC_DEV_REC271 bool is_device_encrypted() const { return sec_flags & BTM_SEC_ENCRYPTED; }
set_device_encryptedtBTM_SEC_DEV_REC272 void set_device_encrypted() { sec_flags |= BTM_SEC_ENCRYPTED; }
reset_device_encryptedtBTM_SEC_DEV_REC273 void reset_device_encrypted() { sec_flags &= ~BTM_SEC_ENCRYPTED; }
274
is_name_knowntBTM_SEC_DEV_REC275 bool is_name_known() const { return sec_flags & BTM_SEC_NAME_KNOWN; }
set_device_knowntBTM_SEC_DEV_REC276 void set_device_known() { sec_flags |= BTM_SEC_NAME_KNOWN; }
reset_device_knowntBTM_SEC_DEV_REC277 void reset_device_known() { sec_flags &= ~BTM_SEC_NAME_KNOWN; }
278
is_link_key_knowntBTM_SEC_DEV_REC279 bool is_link_key_known() const { return sec_flags & BTM_SEC_LINK_KEY_KNOWN; }
set_link_key_knowntBTM_SEC_DEV_REC280 void set_link_key_known() { sec_flags |= BTM_SEC_LINK_KEY_KNOWN; }
reset_link_key_knowntBTM_SEC_DEV_REC281 void reset_link_key_known() { sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN; }
282
is_link_key_authenticatedtBTM_SEC_DEV_REC283 bool is_link_key_authenticated() const {
284 return sec_flags & BTM_SEC_LINK_KEY_AUTHED;
285 }
set_link_key_authenticatedtBTM_SEC_DEV_REC286 void set_link_key_authenticated() { sec_flags |= BTM_SEC_LINK_KEY_AUTHED; }
reset_link_key_authenticatedtBTM_SEC_DEV_REC287 void reset_link_key_authenticated() { sec_flags &= ~BTM_SEC_LINK_KEY_AUTHED; }
288
is_le_device_authenticatedtBTM_SEC_DEV_REC289 bool is_le_device_authenticated() const {
290 return sec_flags & BTM_SEC_LE_AUTHENTICATED;
291 }
set_le_device_authenticatedtBTM_SEC_DEV_REC292 void set_le_device_authenticated() { sec_flags |= BTM_SEC_LE_AUTHENTICATED; }
reset_le_device_authenticatedtBTM_SEC_DEV_REC293 void reset_le_device_authenticated() {
294 sec_flags &= ~BTM_SEC_LE_AUTHENTICATED;
295 }
296
is_le_device_encryptedtBTM_SEC_DEV_REC297 bool is_le_device_encrypted() const {
298 return sec_flags & BTM_SEC_LE_ENCRYPTED;
299 }
set_le_device_encryptedtBTM_SEC_DEV_REC300 void set_le_device_encrypted() { sec_flags |= BTM_SEC_LE_ENCRYPTED; }
reset_le_device_encryptedtBTM_SEC_DEV_REC301 void reset_le_device_encrypted() { sec_flags &= ~BTM_SEC_LE_ENCRYPTED; }
302
is_le_link_key_knowntBTM_SEC_DEV_REC303 bool is_le_link_key_known() const {
304 return sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN;
305 }
set_le_link_key_knowntBTM_SEC_DEV_REC306 void set_le_link_key_known() { sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; }
reset_le_link_key_knowntBTM_SEC_DEV_REC307 void reset_le_link_key_known() { sec_flags &= ~BTM_SEC_LE_LINK_KEY_KNOWN; }
308
is_le_link_key_authenticatedtBTM_SEC_DEV_REC309 bool is_le_link_key_authenticated() const {
310 return sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED;
311 }
set_le_link_key_authenticatedtBTM_SEC_DEV_REC312 void set_le_link_key_authenticated() {
313 sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED;
314 }
reset_le_link_key_authenticatedtBTM_SEC_DEV_REC315 void reset_le_link_key_authenticated() {
316 sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED;
317 }
318
is_le_link_16_digit_key_authenticatedtBTM_SEC_DEV_REC319 bool is_le_link_16_digit_key_authenticated() const {
320 return sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED;
321 }
set_le_link_16_digit_key_authenticatedtBTM_SEC_DEV_REC322 void set_le_link_16_digit_key_authenticated() {
323 sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED;
324 }
reset_le_link_16_digit_key_authenticatedtBTM_SEC_DEV_REC325 void reset_le_link_16_digit_key_authenticated() {
326 sec_flags &= ~BTM_SEC_16_DIGIT_PIN_AUTHED;
327 }
328
329 tBTM_BD_NAME sec_bd_name; /* User friendly name of the device. (may be
330 truncated to save space in dev_rec table) */
331
332 tSECURITY_STATE sec_state; /* Operating state */
is_security_state_idletBTM_SEC_DEV_REC333 bool is_security_state_idle() const {
334 return sec_state == BTM_SEC_STATE_IDLE;
335 }
is_security_state_authenticatingtBTM_SEC_DEV_REC336 bool is_security_state_authenticating() const {
337 return sec_state == BTM_SEC_STATE_AUTHENTICATING;
338 }
is_security_state_bredr_encryptingtBTM_SEC_DEV_REC339 bool is_security_state_bredr_encrypting() const {
340 return sec_state == BTM_SEC_STATE_ENCRYPTING;
341 }
is_security_state_le_encryptingtBTM_SEC_DEV_REC342 bool is_security_state_le_encrypting() const {
343 return sec_state == BTM_SEC_STATE_LE_ENCRYPTING;
344 }
is_security_state_encryptingtBTM_SEC_DEV_REC345 bool is_security_state_encrypting() const {
346 return (is_security_state_bredr_encrypting() ||
347 is_security_state_le_encrypting());
348 }
is_security_state_getting_nametBTM_SEC_DEV_REC349 bool is_security_state_getting_name() const {
350 return sec_state == BTM_SEC_STATE_GETTING_NAME;
351 }
is_security_state_authorizingtBTM_SEC_DEV_REC352 bool is_security_state_authorizing() const {
353 return sec_state == BTM_SEC_STATE_AUTHORIZING;
354 }
is_security_state_switching_roletBTM_SEC_DEV_REC355 bool is_security_state_switching_role() const {
356 return sec_state == BTM_SEC_STATE_SWITCHING_ROLE;
357 }
is_security_state_disconnectingtBTM_SEC_DEV_REC358 bool is_security_state_disconnecting() const {
359 return sec_state == BTM_SEC_STATE_DISCONNECTING;
360 }
is_security_state_wait_for_encryptiontBTM_SEC_DEV_REC361 bool is_security_state_wait_for_encryption() const {
362 return sec_state == BTM_SEC_STATE_DELAY_FOR_ENC;
363 }
is_security_state_ble_disconnectingtBTM_SEC_DEV_REC364 bool is_security_state_ble_disconnecting() const {
365 return sec_state == BTM_SEC_STATE_DISCONNECTING_BLE;
366 }
is_security_state_br_edr_and_bletBTM_SEC_DEV_REC367 bool is_security_state_br_edr_and_ble() const {
368 return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH;
369 }
370
371 /* Data length extension */
set_suggested_tx_octecttBTM_SEC_DEV_REC372 void set_suggested_tx_octect(uint16_t octets) {
373 suggested_tx_octets = octets;
374 }
375
get_suggested_tx_octetstBTM_SEC_DEV_REC376 uint16_t get_suggested_tx_octets() const { return suggested_tx_octets; }
377
378 private:
379 bool is_originator; /* true if device is originating connection */
380 friend tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
381 tBT_TRANSPORT transport,
382 tBTM_SEC_CALLBACK* p_callback,
383 void* p_ref_data,
384 tBTM_BLE_SEC_ACT sec_act);
385 friend tBTM_STATUS btm_sec_l2cap_access_req_by_requirement(
386 const RawAddress& bd_addr, uint16_t security_required, bool is_originator,
387 tBTM_SEC_CALLBACK* p_callback, void* p_ref_data);
388 friend tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr,
389 bool is_originator,
390 uint16_t security_required,
391 tBTM_SEC_CALLBACK* p_callback,
392 void* p_ref_data);
393
394 public:
395 // whether the peer device can read GAP characteristics only visible in
396 // "discoverable" mode
397 bool can_read_discoverable{true};
398
IsLocallyInitiatedtBTM_SEC_DEV_REC399 bool IsLocallyInitiated() const { return is_originator; }
400
401 bool role_central; /* true if current mode is central */
402 uint16_t security_required; /* Security required for connection */
403 bool link_key_not_sent; /* link key notification has not been sent waiting for
404 name */
405 uint8_t link_key_type; /* Type of key used in pairing */
406
407 uint8_t sm4; /* BTM_SM4_TRUE, if the peer supports SM4 */
408 tBTM_IO_CAP rmt_io_caps; /* IO capability of the peer device */
409 tBTM_AUTH_REQ rmt_auth_req; /* the auth_req flag as in the IO caps rsp evt */
410
411 bool remote_supports_secure_connections;
412 friend void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
413 bool sc_supported,
414 bool hci_role_switch_supported,
415 bool br_edr_supported,
416 bool le_supported);
417
418 public:
SupportsSecureConnectionstBTM_SEC_DEV_REC419 bool SupportsSecureConnections() const {
420 return remote_supports_secure_connections;
421 }
422
423 bool remote_features_needed; /* set to true if the local device is in */
424 /* "Secure Connections Only" mode and it receives */
425 /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */
426 /* it knows peer's support for Secure Connections */
427 bool remote_supports_hci_role_switch = false;
428 bool remote_supports_bredr;
429 bool remote_supports_ble;
430 bool remote_feature_received = false;
431
432 uint16_t ble_hci_handle; /* use in DUMO connection */
get_ble_hci_handletBTM_SEC_DEV_REC433 uint16_t get_ble_hci_handle() const { return ble_hci_handle; }
434
435 uint8_t enc_key_size; /* current link encryption key size */
get_encryption_key_sizetBTM_SEC_DEV_REC436 uint8_t get_encryption_key_size() const { return enc_key_size; }
437
438 tBT_DEVICE_TYPE device_type;
is_device_type_br_edrtBTM_SEC_DEV_REC439 bool is_device_type_br_edr() const {
440 return device_type == BT_DEVICE_TYPE_BREDR;
441 }
is_device_type_bletBTM_SEC_DEV_REC442 bool is_device_type_ble() const { return device_type == BT_DEVICE_TYPE_BLE; }
is_device_type_dual_modetBTM_SEC_DEV_REC443 bool is_device_type_dual_mode() const {
444 return device_type == BT_DEVICE_TYPE_DUMO;
445 }
446
is_device_type_has_bletBTM_SEC_DEV_REC447 bool is_device_type_has_ble() const {
448 return device_type & BT_DEVICE_TYPE_BLE;
449 }
450 bool new_encryption_key_is_p256; /* Set to true when the newly generated LK
451 ** is generated from P-256.
452 ** Link encrypted with such LK can be used
453 ** for SM over BR/EDR.
454 */
455 tBTM_BOND_TYPE bond_type; /* peering bond type */
is_bond_type_unknowntBTM_SEC_DEV_REC456 bool is_bond_type_unknown() const { return bond_type == BOND_TYPE_UNKNOWN; }
is_bond_type_persistenttBTM_SEC_DEV_REC457 bool is_bond_type_persistent() const {
458 return bond_type == BOND_TYPE_PERSISTENT;
459 }
is_bond_type_temporarytBTM_SEC_DEV_REC460 bool is_bond_type_temporary() const {
461 return bond_type == BOND_TYPE_TEMPORARY;
462 }
463
464 tBTM_SEC_BLE ble;
465 tBTM_LE_CONN_PRAMS conn_params;
466
467 tREMOTE_VERSION_INFO remote_version_info;
468
ToStringtBTM_SEC_DEV_REC469 std::string ToString() const {
470 return base::StringPrintf(
471 "%s %6s cod:%s remote_info:%-14s sm4:0x%02x SecureConn:%c name:\"%s\"",
472 ADDRESS_TO_LOGGABLE_CSTR(bd_addr), DeviceTypeText(device_type).c_str(),
473 class_of_device_text(dev_class).c_str(),
474 remote_version_info.ToString().c_str(), sm4,
475 (remote_supports_secure_connections) ? 'T' : 'F',
476 PRIVATE_NAME(sec_bd_name));
477 }
478 };
479
bond_type_text(const tBTM_SEC_DEV_REC::tBTM_BOND_TYPE & bond_type)480 inline std::string bond_type_text(
481 const tBTM_SEC_DEV_REC::tBTM_BOND_TYPE& bond_type) {
482 switch (bond_type) {
483 CASE_RETURN_TEXT(tBTM_SEC_DEV_REC::BOND_TYPE_UNKNOWN);
484 CASE_RETURN_TEXT(tBTM_SEC_DEV_REC::BOND_TYPE_PERSISTENT);
485 CASE_RETURN_TEXT(tBTM_SEC_DEV_REC::BOND_TYPE_TEMPORARY);
486 default:
487 return base::StringPrintf("UNKNOWN[%hhu]", bond_type);
488 }
489 }
490