OSDN Git Service

L2cap shim: Implement L2CA_GetBleConnRole
authorHansong Zhang <hsz@google.com>
Wed, 13 Jan 2021 05:54:54 +0000 (21:54 -0800)
committerHansong Zhang <hsz@google.com>
Wed, 13 Jan 2021 19:45:37 +0000 (11:45 -0800)
Note: We haven't routed LE link property callbacks yet.

Test: cert/run
Tag: #gd-refactor
Bug: 141555841
Change-Id: I987fbcede2e8e9e133418c72cb2d99dda0253b40

gd/l2cap/le/link_property_listener.h
main/shim/l2c_api.cc
main/shim/l2c_api.h
stack/l2cap/l2c_ble.cc

index 25b6d59..e45b96c 100644 (file)
@@ -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.
index b93dcae..e6d9d74 100644 (file)
@@ -484,9 +484,12 @@ bluetooth::l2cap::classic::SecurityInterface* security_interface_ = nullptr;
 struct LeLinkPropertyListenerShim
     : public bluetooth::l2cap::le::LinkPropertyListener {
   std::unordered_map<hci::AddressWithType, uint16_t> address_to_handle_;
+  std::unordered_map<hci::AddressWithType, hci::Role> 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<hci_role_t>(
+      le_link_property_listener_shim_.address_to_role_[remote]);
+}
+
 void L2CA_ConnectForSecurity(const RawAddress& bd_addr) {
   security_interface_->InitiateConnectionForSecurity(
       bluetooth::ToGdAddress(bd_addr));
index 51e93f2..d83c971 100644 (file)
@@ -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,
index 5b95f3f..7fdde0e 100644 (file)
@@ -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;