From d58bac0eb7e29f52649dd589e7a2fce5d1dcafef Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Thu, 29 Oct 2020 20:37:13 -0700 Subject: [PATCH] Move btm_sec_set_peer_sec_caps to btm_sec Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I1d05c78b08deeb7120fc0eaced20384e2f438e79 --- stack/acl/btm_acl.cc | 57 ---------------------------------------------------- stack/btm/btm_sec.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ stack/btm/btm_sec.h | 14 +++++++++++++ 3 files changed, 68 insertions(+), 57 deletions(-) diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index e9c183ff4..9bef30235 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -125,9 +125,6 @@ static void btm_read_rssi_timeout(void* data); static void btm_read_tx_power_timeout(void* data); static void btm_process_remote_ext_features(tACL_CONN* p_acl_cb, uint8_t num_read_pages); -static void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported, - bool sc_supported, - bool hci_role_switch_supported); static bool acl_is_role_central(const RawAddress& bda, tBT_TRANSPORT transport); static void btm_set_link_policy(tACL_CONN* conn, uint16_t policy); static bool btm_ble_get_acl_remote_addr(const tBTM_SEC_DEV_REC& p_dev_rec, @@ -2513,60 +2510,6 @@ void btm_ble_refresh_local_resolvable_private_addr( } } -/******************************************************************************* - * - * Function btm_sec_set_peer_sec_caps - * - * Description This function is called to set sm4 and rmt_sec_caps fields - * based on the available peer device features. - * - * Returns void - * - ******************************************************************************/ -void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported, - bool sc_supported, - bool hci_role_switch_supported) { - tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(hci_handle); - if (p_dev_rec == nullptr) return; - - p_dev_rec->remote_feature_received = true; - p_dev_rec->remote_supports_hci_role_switch = hci_role_switch_supported; - - uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); - - if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) || - p_dev_rec->is_originator) { - uint8_t status = btm_sec_execute_procedure(p_dev_rec); - if (status != BTM_CMD_STARTED) { - LOG_WARN("Security procedure not started! status:%s", - hci_error_code_text(status).c_str()); - btm_sec_dev_rec_cback_event(p_dev_rec, status, false); - } - } - - /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ - if ((btm_cb.security_mode == BTM_SEC_MODE_SP || - btm_cb.security_mode == BTM_SEC_MODE_SC) && - ssp_supported) { - p_dev_rec->sm4 = BTM_SM4_TRUE; - p_dev_rec->remote_supports_secure_connections = sc_supported; - } else { - p_dev_rec->sm4 = BTM_SM4_KNOWN; - p_dev_rec->remote_supports_secure_connections = false; - } - - if (p_dev_rec->remote_features_needed) { - LOG_DEBUG("Now device in SC Only mode, waiting for peer remote features!"); - btm_io_capabilities_req(p_dev_rec->bd_addr); - p_dev_rec->remote_features_needed = false; - } - - if (req_pend) { - /* Request for remaining Security Features (if any) */ - l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr); - } -} - bool sco_peer_supports_esco_2m_phy(uint16_t hci_handle) { tACL_CONN* p_acl = internal_.acl_get_connection_from_handle(hci_handle); if (p_acl == nullptr) { diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc index 3232f97b7..fb8db9e64 100644 --- a/stack/btm/btm_sec.cc +++ b/stack/btm/btm_sec.cc @@ -4772,3 +4772,57 @@ static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC* p_dev_rec) { return true; } + +/******************************************************************************* + * + * Function btm_sec_set_peer_sec_caps + * + * Description This function is called to set sm4 and rmt_sec_caps fields + * based on the available peer device features. + * + * Returns void + * + ******************************************************************************/ +void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported, + bool sc_supported, + bool hci_role_switch_supported) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(hci_handle); + if (p_dev_rec == nullptr) return; + + p_dev_rec->remote_feature_received = true; + p_dev_rec->remote_supports_hci_role_switch = hci_role_switch_supported; + + uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); + + if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) || + p_dev_rec->is_originator) { + uint8_t status = btm_sec_execute_procedure(p_dev_rec); + if (status != BTM_CMD_STARTED) { + LOG_WARN("Security procedure not started! status:%s", + hci_error_code_text(status).c_str()); + btm_sec_dev_rec_cback_event(p_dev_rec, status, false); + } + } + + /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ + if ((btm_cb.security_mode == BTM_SEC_MODE_SP || + btm_cb.security_mode == BTM_SEC_MODE_SC) && + ssp_supported) { + p_dev_rec->sm4 = BTM_SM4_TRUE; + p_dev_rec->remote_supports_secure_connections = sc_supported; + } else { + p_dev_rec->sm4 = BTM_SM4_KNOWN; + p_dev_rec->remote_supports_secure_connections = false; + } + + if (p_dev_rec->remote_features_needed) { + LOG_DEBUG("Now device in SC Only mode, waiting for peer remote features!"); + btm_io_capabilities_req(p_dev_rec->bd_addr); + p_dev_rec->remote_features_needed = false; + } + + if (req_pend) { + /* Request for remaining Security Features (if any) */ + l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr); + } +} diff --git a/stack/btm/btm_sec.h b/stack/btm/btm_sec.h index d230b926c..0e655815d 100644 --- a/stack/btm/btm_sec.h +++ b/stack/btm/btm_sec.h @@ -764,3 +764,17 @@ void btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC* p_dev_rec); * ******************************************************************************/ bool btm_sec_is_a_bonded_dev(const RawAddress& bda); + +/******************************************************************************* + * + * Function btm_sec_set_peer_sec_caps + * + * Description This function is called to set sm4 and rmt_sec_caps fields + * based on the available peer device features. + * + * Returns void + * + ******************************************************************************/ +void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported, + bool sc_supported, + bool hci_role_switch_supported); \ No newline at end of file -- 2.11.0