From 4f46d1190df5015a09eaf156dc0e88209a234c80 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Sun, 17 Jan 2021 12:30:02 -0800 Subject: [PATCH] Simplify get role API Just use BTM_GetRole() Test: cert/run Tag: #gd-refactor Bug: 141555841 Change-Id: Ic90c23afe6512ee45acefdc9d04fca47ad5c550b --- stack/acl/btm_acl.cc | 27 --------------------------- stack/btm/btm_sec.cc | 9 ++++++--- stack/eatt/eatt_impl.h | 2 +- stack/include/acl_api.h | 4 ---- stack/test/common/mock_l2cap_layer.cc | 6 +++++- stack/test/common/mock_l2cap_layer.h | 1 + stack/test/eatt/eatt_test.cc | 8 ++++---- 7 files changed, 17 insertions(+), 40 deletions(-) diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index 72e063c6d..312fd19ae 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -124,7 +124,6 @@ inline bool IsEprAvailable(const tACL_CONN& p_acl) { controller_get_interface()->supports_encryption_pause(); } -static bool acl_is_role_central(const RawAddress& bda, tBT_TRANSPORT transport); static void btm_acl_chk_peer_pkt_type_support(tACL_CONN* p, uint16_t* p_pkt_type); static void btm_process_remote_ext_features(tACL_CONN* p_acl_cb, @@ -2324,23 +2323,6 @@ void btm_acl_chk_peer_pkt_type_support(tACL_CONN* p, uint16_t* p_pkt_type) { } } -bool acl_is_role_central(const RawAddress& bda, tBT_TRANSPORT transport) { - tACL_CONN* p = internal_.btm_bda_to_acl(bda, BT_TRANSPORT_BR_EDR); - if (p == nullptr) { - LOG_WARN("Unable to find active acl"); - return false; - } - return (p->link_role == HCI_ROLE_CENTRAL); -} - -bool acl_br_edr_is_role_central(const RawAddress& bda) { - return acl_is_role_central(bda, BT_TRANSPORT_BR_EDR); -} - -bool acl_ble_is_role_central(const RawAddress& bda) { - return acl_is_role_central(bda, BT_TRANSPORT_LE); -} - bool BTM_BLE_IS_RESOLVE_BDA(const RawAddress& x) { return ((x.address)[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB; } @@ -2592,15 +2574,6 @@ bool BTM_ReadRemoteConnectionAddr(const RawAddress& pseudo_addr, return st; } -uint8_t acl_link_role(const RawAddress& bd_addr, tBT_TRANSPORT transport) { - tACL_CONN* p_acl = internal_.btm_bda_to_acl(bd_addr, transport); - if (p_acl == nullptr) { - LOG_WARN("Unable to find active acl"); - return HCI_ROLE_UNKNOWN; - } - return p_acl->link_role; -} - uint8_t acl_link_role_from_handle(uint16_t handle) { tACL_CONN* p_acl = internal_.acl_get_connection_from_handle(handle); if (p_acl == nullptr) { diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc index 0fa4ed086..394bcccf7 100644 --- a/stack/btm/btm_sec.cc +++ b/stack/btm/btm_sec.cc @@ -3107,7 +3107,9 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) { BTM_TRACE_DEBUG( "link encrypted afer dedic bonding can use SMP_BR_CHNL"); - if (acl_br_edr_is_role_central(p_dev_rec->bd_addr)) { + uint8_t role = HCI_ROLE_UNKNOWN; + BTM_GetRole(p_dev_rec->bd_addr, &role); + if (role == HCI_ROLE_CENTRAL) { // Encryption is required to start SM over BR/EDR // indicate that this is encryption after authentication BTM_SetEncryption(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, NULL, NULL, @@ -3233,9 +3235,10 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, BTM_TRACE_DEBUG("%s: BR key is temporary, skip derivation of LE LTK", __func__); } + uint8_t role = HCI_ROLE_UNKNOWN; + BTM_GetRole(p_dev_rec->bd_addr, &role); if (p_dev_rec->new_encryption_key_is_p256) { - if (btm_sec_use_smp_br_chnl(p_dev_rec) && - acl_br_edr_is_role_central(p_dev_rec->bd_addr) && + if (btm_sec_use_smp_br_chnl(p_dev_rec) && role == HCI_ROLE_CENTRAL && /* if LE key is not known, do deriving */ (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) || /* or BR key is higher security than existing LE keys */ diff --git a/stack/eatt/eatt_impl.h b/stack/eatt/eatt_impl.h index ad64e53bf..c2f6a4e0b 100644 --- a/stack/eatt/eatt_impl.h +++ b/stack/eatt/eatt_impl.h @@ -595,7 +595,7 @@ struct eatt_impl { void connect(const RawAddress& bd_addr) { eatt_device* eatt_dev = find_device_by_address(bd_addr); - uint8_t role = acl_link_role(bd_addr, BT_TRANSPORT_LE); + uint8_t role = L2CA_GetBleConnRole(bd_addr); if (role == HCI_ROLE_UNKNOWN) { LOG(ERROR) << __func__ << "Could not get device role" << bd_addr; return; diff --git a/stack/include/acl_api.h b/stack/include/acl_api.h index dac414d46..caec36c0a 100644 --- a/stack/include/acl_api.h +++ b/stack/include/acl_api.h @@ -214,9 +214,6 @@ void btm_set_packet_types_from_address(const RawAddress& bda, tBT_TRANSPORT transport, uint16_t pkt_types); -bool acl_br_edr_is_role_central(const RawAddress& bda); -bool acl_ble_is_role_central(const RawAddress& bda); - #define BLE_RESOLVE_ADDR_MASK 0xc0 #define BLE_RESOLVE_ADDR_MSB 0x40 @@ -279,7 +276,6 @@ void btm_ble_refresh_local_resolvable_private_addr( void btm_cont_rswitch_from_handle(uint16_t hci_handle); -uint8_t acl_link_role(const RawAddress& remote_bda, tBT_TRANSPORT transport); uint8_t acl_link_role_from_handle(uint16_t handle); tBT_TRANSPORT acl_get_transport_from_handle(uint16_t handle); diff --git a/stack/test/common/mock_l2cap_layer.cc b/stack/test/common/mock_l2cap_layer.cc index b9699f990..4e305078a 100644 --- a/stack/test/common/mock_l2cap_layer.cc +++ b/stack/test/common/mock_l2cap_layer.cc @@ -70,6 +70,10 @@ void L2CA_DeregisterLECoc(uint16_t psm) { return l2cap_interface->DeregisterLECoc(psm); } +uint8_t L2CA_GetBleConnRole(const RawAddress& bd_addr) { + return l2cap_interface->GetBleConnRole(bd_addr); +} + std::vector L2CA_ConnectCreditBasedReq(uint16_t psm, const RawAddress& bd_addr, tL2CAP_LE_CFG_INFO* p_cfg) { @@ -86,4 +90,4 @@ bool L2CA_ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id, bool L2CA_ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, std::vector &lcids, tL2CAP_LE_CFG_INFO* peer_cfg) { return l2cap_interface->ReconfigCreditBasedConnsReq(bd_addr, lcids, peer_cfg); -} \ No newline at end of file +} diff --git a/stack/test/common/mock_l2cap_layer.h b/stack/test/common/mock_l2cap_layer.h index 4c29fd00e..15ffcae00 100644 --- a/stack/test/common/mock_l2cap_layer.h +++ b/stack/test/common/mock_l2cap_layer.h @@ -70,6 +70,7 @@ class MockL2capInterface : public L2capInterface { MOCK_METHOD3(RegisterLECoc, uint16_t(uint16_t psm, const tL2CAP_APPL_INFO &cb_info, uint16_t sec_level)); MOCK_METHOD1(DeregisterLECoc, void(uint16_t psm)); + MOCK_METHOD1(GetBleConnRole, uint8_t(const RawAddress& bd_addr)); MOCK_METHOD5(ConnectCreditBasedRsp, bool(const RawAddress& p_bd_addr, uint8_t id, std::vector &lcids, diff --git a/stack/test/eatt/eatt_test.cc b/stack/test/eatt/eatt_test.cc index f346f5232..08e7e9866 100644 --- a/stack/test/eatt/eatt_test.cc +++ b/stack/test/eatt/eatt_test.cc @@ -125,14 +125,14 @@ class EattTest : public testing::Test { return; }); - ON_CALL(btm_api_interface_, acl_link_role(_, BT_TRANSPORT_LE)) + hci_role_ = HCI_ROLE_CENTRAL; + + ON_CALL(l2cap_interface_, GetBleConnRole(_)) .WillByDefault(DoAll(Return(hci_role_))); ON_CALL(controller_interface, GetAclDataSizeBle()) .WillByDefault(Return(128)); - hci_role_ = HCI_ROLE_CENTRAL; - eatt_instance_ = EattExtension::GetInstance(); eatt_instance_->Start(); @@ -165,7 +165,7 @@ class EattTest : public testing::Test { tL2CAP_APPL_INFO l2cap_app_info_; EattExtension* eatt_instance_; std::vector connected_cids_; - uint8_t hci_role_; + uint8_t hci_role_ = HCI_ROLE_CENTRAL; }; TEST_F(EattTest, ConnectSucceed) { -- 2.11.0