Loading system/main/shim/l2c_api.cc +61 −1 Original line number Diff line number Diff line Loading @@ -34,13 +34,17 @@ #include "osi/include/allocator.h" #include "stack/btm/btm_sec.h" #include "stack/include/acl_hci_link_interface.h" #include "stack/include/ble_acl_interface.h" #include "stack/include/btm_api.h" #include "stack/include/btu.h" #include "stack/include/gatt_api.h" #include "stack/include/sco_hci_link_interface.h" extern void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16_t latency, uint16_t timeout, tHCI_STATUS status); extern void gatt_notify_phy_updated(tGATT_STATUS status, uint16_t handle, uint8_t tx_phy, uint8_t rx_phy); void process_ssr_event(tHCI_STATUS status, uint16_t handle, uint16_t max_tx_lat, uint16_t max_rx_lat); Loading Loading @@ -404,6 +408,7 @@ class SecurityListenerShim } void OnAuthenticationComplete(bluetooth::hci::Address remote) override { // Note: if gd security is not enabled, we should use btu_hcif.cc path auto bda = bluetooth::ToRawAddress(remote); uint16_t handle = address_to_handle_[bda]; btm_sec_auth_complete(handle, HCI_SUCCESS); Loading @@ -420,6 +425,7 @@ class SecurityListenerShim void OnEncryptionChange(bluetooth::hci::Address remote, bool encrypted) override { // Note: if gd security is not enabled, we should use btu_hcif.cc path auto bda = bluetooth::ToRawAddress(remote); uint16_t handle = address_to_handle_[bda]; btm_sec_encrypt_change(handle, HCI_SUCCESS, encrypted); Loading Loading @@ -466,6 +472,52 @@ class SecurityListenerShim bluetooth::l2cap::classic::SecurityInterface* security_interface_ = nullptr; struct LeLinkPropertyListenerShim : public bluetooth::l2cap::le::LinkPropertyListener { std::unordered_map<hci::AddressWithType, uint16_t> address_to_handle_; void OnLinkConnected(hci::AddressWithType remote, uint16_t handle) override { address_to_handle_[remote] = handle; } void OnLinkDisconnected(hci::AddressWithType remote) override { address_to_handle_.erase(remote); } void OnReadRemoteVersionInformation(hci::AddressWithType remote, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override { auto bda = bluetooth::ToRawAddress(remote.GetAddress()); auto& entry = remote_feature_map_[bda]; entry.lmp_version = lmp_version; entry.manufacturer_name = manufacturer_name; entry.sub_version = sub_version; entry.version_info_received = true; } void OnConnectionUpdate(hci::AddressWithType remote, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout) override { acl_ble_update_event_received(HCI_SUCCESS, address_to_handle_[remote], connection_interval, connection_latency, supervision_timeout); } void OnPhyUpdate(hci::AddressWithType remote, uint8_t tx_phy, uint8_t rx_phy) override { gatt_notify_phy_updated(GATT_SUCCESS, address_to_handle_[remote], tx_phy, rx_phy); } void OnDataLengthChange(hci::AddressWithType remote, uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time) override { // Used by L2cap internal only. } } le_link_property_listener_shim_; std::unordered_map<intptr_t, bluetooth::common::ContextualOnceCallback<void(bool)>> le_security_enforce_callback_map = {}; Loading Loading @@ -543,6 +595,8 @@ void L2CA_UseLegacySecurityModule() { security_interface_ = GetL2capClassicModule()->GetSecurityInterface( GetGdShimHandler(), &security_listener_shim_); GetL2capLeModule()->SetLinkPropertyListener(GetGdShimHandler(), &le_link_property_listener_shim_); GetL2capLeModule()->InjectSecurityEnforcementInterface( &le_security_enforcement_shim_); Loading Loading @@ -688,7 +742,6 @@ bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr, uint16_t timeout, LOG_INFO("UNIMPLEMENTED %s", __func__); return false; } constexpr int GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP = 1; if (timeout == 0 || timeout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) { bluetooth::shim::L2CA_RemoveFixedChnl(kLeAttributeCid, bd_addr); return true; Loading Loading @@ -962,6 +1015,13 @@ bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, } } bool L2CA_IsLeLink(uint16_t acl_handle) { for (const auto& entry : le_link_property_listener_shim_.address_to_handle_) { if (entry.second == acl_handle) return true; } return false; } void L2CA_ConnectForSecurity(const RawAddress& bd_addr) { security_interface_->InitiateConnectionForSecurity( bluetooth::ToGdAddress(bd_addr)); Loading system/main/shim/l2c_api.h +2 −0 Original line number Diff line number Diff line Loading @@ -514,5 +514,7 @@ void L2CA_DisconnectLink(const RawAddress& remote); uint16_t L2CA_GetNumLinks(); bool L2CA_IsLeLink(uint16_t acl_handle); } // namespace shim } // namespace bluetooth system/stack/acl/btm_acl.cc +4 −0 Original line number Diff line number Diff line Loading @@ -2426,6 +2426,10 @@ bool BTM_IsBleConnection(uint16_t hci_handle) { ASSERT_LOG(false, "This should not be invoked from code path"); } if (bluetooth::shim::is_gd_l2cap_enabled()) { return bluetooth::shim::L2CA_IsLeLink(hci_handle); } const tACL_CONN* p_acl = internal_.acl_get_connection_from_handle(hci_handle); if (p_acl == nullptr) return false; return p_acl->is_transport_ble(); Loading system/stack/test/common/mock_main_shim_l2c_api.cc +4 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ bool bluetooth::shim::L2CA_IsLinkEstablished(const RawAddress& bd_addr, mock_function_count_map[__func__]++; return false; } bool bluetooth::shim::L2CA_IsLeLink(uint16_t) { mock_function_count_map[__func__]++; return false; } bool bluetooth::shim::L2CA_ReconfigCreditBasedConnsReq( const RawAddress& bd_addr, std::vector<uint16_t>& lcids, tL2CAP_LE_CFG_INFO* p_cfg) { Loading Loading
system/main/shim/l2c_api.cc +61 −1 Original line number Diff line number Diff line Loading @@ -34,13 +34,17 @@ #include "osi/include/allocator.h" #include "stack/btm/btm_sec.h" #include "stack/include/acl_hci_link_interface.h" #include "stack/include/ble_acl_interface.h" #include "stack/include/btm_api.h" #include "stack/include/btu.h" #include "stack/include/gatt_api.h" #include "stack/include/sco_hci_link_interface.h" extern void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16_t latency, uint16_t timeout, tHCI_STATUS status); extern void gatt_notify_phy_updated(tGATT_STATUS status, uint16_t handle, uint8_t tx_phy, uint8_t rx_phy); void process_ssr_event(tHCI_STATUS status, uint16_t handle, uint16_t max_tx_lat, uint16_t max_rx_lat); Loading Loading @@ -404,6 +408,7 @@ class SecurityListenerShim } void OnAuthenticationComplete(bluetooth::hci::Address remote) override { // Note: if gd security is not enabled, we should use btu_hcif.cc path auto bda = bluetooth::ToRawAddress(remote); uint16_t handle = address_to_handle_[bda]; btm_sec_auth_complete(handle, HCI_SUCCESS); Loading @@ -420,6 +425,7 @@ class SecurityListenerShim void OnEncryptionChange(bluetooth::hci::Address remote, bool encrypted) override { // Note: if gd security is not enabled, we should use btu_hcif.cc path auto bda = bluetooth::ToRawAddress(remote); uint16_t handle = address_to_handle_[bda]; btm_sec_encrypt_change(handle, HCI_SUCCESS, encrypted); Loading Loading @@ -466,6 +472,52 @@ class SecurityListenerShim bluetooth::l2cap::classic::SecurityInterface* security_interface_ = nullptr; struct LeLinkPropertyListenerShim : public bluetooth::l2cap::le::LinkPropertyListener { std::unordered_map<hci::AddressWithType, uint16_t> address_to_handle_; void OnLinkConnected(hci::AddressWithType remote, uint16_t handle) override { address_to_handle_[remote] = handle; } void OnLinkDisconnected(hci::AddressWithType remote) override { address_to_handle_.erase(remote); } void OnReadRemoteVersionInformation(hci::AddressWithType remote, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override { auto bda = bluetooth::ToRawAddress(remote.GetAddress()); auto& entry = remote_feature_map_[bda]; entry.lmp_version = lmp_version; entry.manufacturer_name = manufacturer_name; entry.sub_version = sub_version; entry.version_info_received = true; } void OnConnectionUpdate(hci::AddressWithType remote, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout) override { acl_ble_update_event_received(HCI_SUCCESS, address_to_handle_[remote], connection_interval, connection_latency, supervision_timeout); } void OnPhyUpdate(hci::AddressWithType remote, uint8_t tx_phy, uint8_t rx_phy) override { gatt_notify_phy_updated(GATT_SUCCESS, address_to_handle_[remote], tx_phy, rx_phy); } void OnDataLengthChange(hci::AddressWithType remote, uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time) override { // Used by L2cap internal only. } } le_link_property_listener_shim_; std::unordered_map<intptr_t, bluetooth::common::ContextualOnceCallback<void(bool)>> le_security_enforce_callback_map = {}; Loading Loading @@ -543,6 +595,8 @@ void L2CA_UseLegacySecurityModule() { security_interface_ = GetL2capClassicModule()->GetSecurityInterface( GetGdShimHandler(), &security_listener_shim_); GetL2capLeModule()->SetLinkPropertyListener(GetGdShimHandler(), &le_link_property_listener_shim_); GetL2capLeModule()->InjectSecurityEnforcementInterface( &le_security_enforcement_shim_); Loading Loading @@ -688,7 +742,6 @@ bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr, uint16_t timeout, LOG_INFO("UNIMPLEMENTED %s", __func__); return false; } constexpr int GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP = 1; if (timeout == 0 || timeout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) { bluetooth::shim::L2CA_RemoveFixedChnl(kLeAttributeCid, bd_addr); return true; Loading Loading @@ -962,6 +1015,13 @@ bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, } } bool L2CA_IsLeLink(uint16_t acl_handle) { for (const auto& entry : le_link_property_listener_shim_.address_to_handle_) { if (entry.second == acl_handle) return true; } return false; } void L2CA_ConnectForSecurity(const RawAddress& bd_addr) { security_interface_->InitiateConnectionForSecurity( bluetooth::ToGdAddress(bd_addr)); Loading
system/main/shim/l2c_api.h +2 −0 Original line number Diff line number Diff line Loading @@ -514,5 +514,7 @@ void L2CA_DisconnectLink(const RawAddress& remote); uint16_t L2CA_GetNumLinks(); bool L2CA_IsLeLink(uint16_t acl_handle); } // namespace shim } // namespace bluetooth
system/stack/acl/btm_acl.cc +4 −0 Original line number Diff line number Diff line Loading @@ -2426,6 +2426,10 @@ bool BTM_IsBleConnection(uint16_t hci_handle) { ASSERT_LOG(false, "This should not be invoked from code path"); } if (bluetooth::shim::is_gd_l2cap_enabled()) { return bluetooth::shim::L2CA_IsLeLink(hci_handle); } const tACL_CONN* p_acl = internal_.acl_get_connection_from_handle(hci_handle); if (p_acl == nullptr) return false; return p_acl->is_transport_ble(); Loading
system/stack/test/common/mock_main_shim_l2c_api.cc +4 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ bool bluetooth::shim::L2CA_IsLinkEstablished(const RawAddress& bd_addr, mock_function_count_map[__func__]++; return false; } bool bluetooth::shim::L2CA_IsLeLink(uint16_t) { mock_function_count_map[__func__]++; return false; } bool bluetooth::shim::L2CA_ReconfigCreditBasedConnsReq( const RawAddress& bd_addr, std::vector<uint16_t>& lcids, tL2CAP_LE_CFG_INFO* p_cfg) { Loading