OSDN Git Service

LE L2cap shim: Implement fixed channel timeout
authorHansong Zhang <hsz@google.com>
Wed, 30 Dec 2020 22:54:32 +0000 (14:54 -0800)
committerHansong Zhang <hsz@google.com>
Wed, 6 Jan 2021 20:59:25 +0000 (12:59 -0800)
Implement timeout settings with Fixed channel acquire/release.  So far
we only have two timeout options: no timeout, and disconnect
immediately, which we can use existing methods to implement.

Test: CtsVerifier
Tag: #gd-refactor
Bug: 141555841
Change-Id: If262e2773575b5c3c99a7286d66ca5f6a7fe7e58

main/shim/l2c_api.cc

index d49c526..01aa576 100644 (file)
@@ -637,8 +637,18 @@ bool L2CA_ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id,
  */
 bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr, uint16_t timeout,
                                  tBT_TRANSPORT transport) {
-  LOG_INFO("UNIMPLEMENTED %s", __func__);
-  return false;
+  if (transport == BT_TRANSPORT_BR_EDR) {
+    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;
+  } else {
+    LOG_INFO("UNIMPLEMENTED %s", __func__);
+    return false;
+  }
 }
 
 bool L2CA_SetAclPriority(const RawAddress& bd_addr, tL2CAP_PRIORITY priority) {
@@ -845,8 +855,16 @@ bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority) {
 
 bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda, uint16_t fixed_cid,
                               uint16_t idle_tout) {
-  LOG_INFO("UNIMPLEMENTED %s", __func__);
-  return false;
+  if (fixed_cid != kLeAttributeCid) {
+    LOG_INFO("UNIMPLEMENTED %s", __func__);
+    return false;
+  }
+  if (idle_tout == 0xffff) {
+    bluetooth::shim::L2CA_ConnectFixedChnl(kLeAttributeCid, rem_bda);
+  } else {
+    bluetooth::shim::L2CA_RemoveFixedChnl(kLeAttributeCid, rem_bda);
+  }
+  return true;
 }
 
 bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable) {