From d1c0313cfd95456536359d27dc55ef50cebf7382 Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Thu, 11 Mar 2021 22:30:46 -0800 Subject: [PATCH] Store remote lmp version in security record Toward loggable code Bug: 163134718 Test: gd/cert/run Tag: #refactor BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines Change-Id: I928bcb52c65b5c9a3cbfd67d48a3465b7e14959f --- stack/acl/acl.h | 7 +------ stack/acl/btm_acl.cc | 6 ++++++ stack/btm/btm_sec.cc | 8 ++++++++ stack/btm/security_device_record.h | 14 +++++++++++--- stack/include/btm_api_types.h | 13 +++++++++++++ 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/stack/acl/acl.h b/stack/acl/acl.h index 653406478..8b62881c7 100644 --- a/stack/acl/acl.h +++ b/stack/acl/acl.h @@ -231,12 +231,7 @@ struct tACL_CONN { tHCI_ROLE link_role; uint8_t switch_role_failed_attempts; - struct { - uint8_t lmp_version{0}; - uint16_t lmp_subversion{0}; - uint16_t manufacturer{0}; - bool valid{false}; - } remote_version_info; + tREMOTE_VERSION_INFO remote_version_info; #define BTM_SEC_RS_NOT_PENDING 0 /* Role Switch not in progress */ #define BTM_SEC_RS_PENDING 1 /* Role Switch in progress */ diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index 26106519d..487b47ccf 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -66,6 +66,9 @@ #include "types/hci_role.h" #include "types/raw_address.h" +void BTM_update_version_info(const RawAddress& bd_addr, + const remote_version_info& remote_version_info); + void gatt_find_in_device_record(const RawAddress& bd_addr, tBLE_BD_ADDR* address_with_type); void l2c_link_hci_conn_comp(tHCI_STATUS status, uint16_t handle, @@ -781,6 +784,9 @@ void btm_process_remote_version_complete(uint8_t status, uint16_t handle, p_acl_cb->remote_version_info.manufacturer = manufacturer; p_acl_cb->remote_version_info.lmp_subversion = lmp_subversion; p_acl_cb->remote_version_info.valid = true; + BTM_update_version_info(p_acl_cb->RemoteAddress(), + p_acl_cb->remote_version_info); + bluetooth::common::LogRemoteVersionInfo(handle, status, lmp_version, manufacturer, lmp_subversion); } else { diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc index 85744df1b..2971b87c0 100644 --- a/stack/btm/btm_sec.cc +++ b/stack/btm/btm_sec.cc @@ -4860,3 +4860,11 @@ const uint8_t* btm_get_dev_class(const RawAddress& bda) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(bda); return p_dev_rec->dev_class; } + +void BTM_update_version_info(const RawAddress& bd_addr, + const remote_version_info& remote_version_info) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec == NULL) return; + + p_dev_rec->remote_version_info = remote_version_info; +} diff --git a/stack/btm/security_device_record.h b/stack/btm/security_device_record.h index 36692b5a1..c9c89c800 100644 --- a/stack/btm/security_device_record.h +++ b/stack/btm/security_device_record.h @@ -188,6 +188,10 @@ typedef enum : uint8_t { be cleared on \ btm_acl_created */ } tBTM_SM4_BIT; +inline std::string class_of_device_text(const DEV_CLASS& cod) { + return base::StringPrintf("0x%01x%01x%01x", cod[2], cod[1], cod[0]); +} + /* * Define structure for Security Device Record. * A record exists for each device authenticated with this device @@ -416,10 +420,14 @@ struct tBTM_SEC_DEV_REC { tBTM_SEC_BLE ble; tBTM_LE_CONN_PRAMS conn_params; + tREMOTE_VERSION_INFO remote_version_info; + std::string ToString() const { return base::StringPrintf( - "%s %6s name:\"%s\" supports_SC:%s", PRIVATE_ADDRESS(bd_addr), - DeviceTypeText(device_type).c_str(), sec_bd_name, - logbool(remote_supports_secure_connections).c_str()); + "%s %6s name:\"%s\" supports_SC:%s cod:%s remote_info%s", + PRIVATE_ADDRESS(bd_addr), DeviceTypeText(device_type).c_str(), + sec_bd_name, logbool(remote_supports_secure_connections).c_str(), + class_of_device_text(dev_class).c_str(), + remote_version_info.ToString().c_str()); } }; diff --git a/stack/include/btm_api_types.h b/stack/include/btm_api_types.h index 2aa65a0a2..061c810f4 100644 --- a/stack/include/btm_api_types.h +++ b/stack/include/btm_api_types.h @@ -970,4 +970,17 @@ typedef uint8_t tBTM_CONTRL_STATE; // Bluetooth Quality Report - Report receiver typedef void(tBTM_BT_QUALITY_REPORT_RECEIVER)(uint8_t len, uint8_t* p_stream); +struct tREMOTE_VERSION_INFO { + uint8_t lmp_version{0}; + uint16_t lmp_subversion{0}; + uint16_t manufacturer{0}; + bool valid{false}; + std::string ToString() const { + return (valid) ? base::StringPrintf("%02hhu-%05hu-%05hu", lmp_version, + lmp_subversion, manufacturer) + : std::string("UNKNOWN"); + } +}; +using remote_version_info = tREMOTE_VERSION_INFO; + #endif // BTM_API_TYPES_H -- 2.11.0