From: Hansong Zhang Date: Wed, 13 Jan 2021 05:54:54 +0000 (-0800) Subject: L2cap shim: Implement L2CA_GetBleConnRole X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=989fd4a1dfbca39dc2096282c4bf4d35d7f94d3c;p=android-x86%2Fsystem-bt.git L2cap shim: Implement L2CA_GetBleConnRole Note: We haven't routed LE link property callbacks yet. Test: cert/run Tag: #gd-refactor Bug: 141555841 Change-Id: I987fbcede2e8e9e133418c72cb2d99dda0253b40 --- diff --git a/gd/l2cap/le/link_property_listener.h b/gd/l2cap/le/link_property_listener.h index 25b6d591d..e45b96c2d 100644 --- a/gd/l2cap/le/link_property_listener.h +++ b/gd/l2cap/le/link_property_listener.h @@ -35,7 +35,7 @@ class LinkPropertyListener { /** * Invoked when an ACL link is connected. */ - virtual void OnLinkConnected(hci::AddressWithType remote, uint16_t handle) {} + virtual void OnLinkConnected(hci::AddressWithType remote, uint16_t handle, hci::Role my_role) {} /** * Invoked when an ACL link is disconnected. diff --git a/main/shim/l2c_api.cc b/main/shim/l2c_api.cc index b93dcae8c..e6d9d74f1 100644 --- a/main/shim/l2c_api.cc +++ b/main/shim/l2c_api.cc @@ -484,9 +484,12 @@ bluetooth::l2cap::classic::SecurityInterface* security_interface_ = nullptr; struct LeLinkPropertyListenerShim : public bluetooth::l2cap::le::LinkPropertyListener { std::unordered_map address_to_handle_; + std::unordered_map address_to_role_; - void OnLinkConnected(hci::AddressWithType remote, uint16_t handle) override { + void OnLinkConnected(hci::AddressWithType remote, uint16_t handle, + hci::Role role) override { address_to_handle_[remote] = handle; + address_to_role_[remote] = role; } void OnLinkDisconnected(hci::AddressWithType remote) override { @@ -1042,6 +1045,15 @@ bool L2CA_IsLeLink(uint16_t acl_handle) { return false; } +hci_role_t L2CA_GetBleConnRole(const RawAddress& bd_addr) { + auto remote = ToAddressWithType(bd_addr, Btm::GetAddressType(bd_addr)); + if (le_link_property_listener_shim_.address_to_role_.count(remote) == 0) { + return HCI_ROLE_UNKNOWN; + } + return static_cast( + le_link_property_listener_shim_.address_to_role_[remote]); +} + void L2CA_ConnectForSecurity(const RawAddress& bd_addr) { security_interface_->InitiateConnectionForSecurity( bluetooth::ToGdAddress(bd_addr)); diff --git a/main/shim/l2c_api.h b/main/shim/l2c_api.h index 51e93f2d1..d83c97134 100644 --- a/main/shim/l2c_api.h +++ b/main/shim/l2c_api.h @@ -394,6 +394,7 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda, bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda); uint16_t L2CA_GetLeHandle(uint16_t cid, const RawAddress& rem_bda); +hci_role_t L2CA_GetBleConnRole(const RawAddress& bd_addr); void L2CA_LeConnectionUpdate(const RawAddress& rem_bda, uint16_t min_int, uint16_t max_int, uint16_t latency, diff --git a/stack/l2cap/l2c_ble.cc b/stack/l2cap/l2c_ble.cc index 5b95f3f88..7fdde0e64 100644 --- a/stack/l2cap/l2c_ble.cc +++ b/stack/l2cap/l2c_ble.cc @@ -162,6 +162,10 @@ bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable) { } hci_role_t L2CA_GetBleConnRole(const RawAddress& bd_addr) { + if (bluetooth::shim::is_gd_l2cap_enabled()) { + return bluetooth::shim::L2CA_GetBleConnRole(bd_addr); + } + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); if (p_lcb == nullptr) { return HCI_ROLE_UNKNOWN;