OSDN Git Service

L2cap shim: Add role switch
authorHansong Zhang <hsz@google.com>
Thu, 5 Nov 2020 23:35:45 +0000 (15:35 -0800)
committerHansong Zhang <hsz@google.com>
Tue, 17 Nov 2020 22:41:36 +0000 (14:41 -0800)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I7fd643ca263e47a4d1f28ee87c72622774c61469

main/shim/l2c_api.cc
main/shim/l2c_api.h
stack/acl/btm_acl.cc

index 638cd7d..60191b9 100644 (file)
@@ -837,3 +837,8 @@ uint8_t bluetooth::shim::L2CA_LECocDataWrite(uint16_t cid, BT_HDR* p_data) {
              MakeUniquePacket(data, len)) *
          len;
 }
+
+void bluetooth::shim::L2CA_SwitchRoleToCentral(const RawAddress& addr) {
+  bluetooth::shim::GetAclManager()->SwitchRole(ToGdAddress(addr),
+                                               bluetooth::hci::Role::CENTRAL);
+}
index 6971e29..a13854e 100644 (file)
@@ -515,5 +515,6 @@ void L2CA_SetBondingState(const RawAddress& p_bd_addr, bool is_bonding);
 // Indicated by shim stack manager that GD L2cap is enabled but Security is not
 void L2CA_UseLegacySecurityModule();
 
+void L2CA_SwitchRoleToCentral(const RawAddress& addr);
 }  // namespace shim
 }  // namespace bluetooth
index 28ebf3f..bc1944a 100644 (file)
@@ -44,6 +44,7 @@
 #include "include/l2cap_hci_link_interface.h"
 #include "main/shim/acl_api.h"
 #include "main/shim/btm_api.h"
+#include "main/shim/l2c_api.h"
 #include "main/shim/shim.h"
 #include "osi/include/log.h"
 #include "stack/acl/acl.h"
@@ -468,6 +469,10 @@ tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, uint8_t* p_role) {
  *
  ******************************************************************************/
 tBTM_STATUS BTM_SwitchRoleToCentral(const RawAddress& remote_bd_addr) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
+    bluetooth::shim::L2CA_SwitchRoleToCentral(remote_bd_addr);
+    return BTM_SUCCESS;
+  }
   if (!controller_get_interface()->supports_central_peripheral_role_switch()) {
     LOG_INFO("Local controller does not support role switching");
     return BTM_MODE_UNSUPPORTED;