OSDN Git Service

Refactor L2CA_SetFixedChannelTout
authorHansong Zhang <hsz@google.com>
Thu, 14 Jan 2021 21:00:45 +0000 (13:00 -0800)
committerHansong Zhang <hsz@google.com>
Fri, 15 Jan 2021 19:42:35 +0000 (11:42 -0800)
It's always used by LE GATT, so let's change it to
L2CA_SetLeGattTimeout.

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

main/shim/l2c_api.cc
main/shim/l2c_api.h
stack/gatt/gatt_api.cc
stack/include/l2c_api.h
stack/l2cap/l2c_api.cc
stack/test/common/mock_l2cap_l2c_api.cc
stack/test/common/mock_main_shim_l2c_api.cc

index 57fa92f..700af45 100644 (file)
@@ -1077,12 +1077,7 @@ bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority) {
   return false;
 }
 
-bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda, uint16_t fixed_cid,
-                              uint16_t idle_tout) {
-  if (fixed_cid != kLeAttributeCid) {
-    LOG_INFO("UNIMPLEMENTED %s", __func__);
-    return false;
-  }
+bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout) {
   if (idle_tout == 0xffff) {
     bluetooth::shim::L2CA_ConnectFixedChnl(kLeAttributeCid, rem_bda);
   } else {
index 02db5f1..5d675ca 100644 (file)
@@ -407,7 +407,7 @@ bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable);
 
 /*******************************************************************************
  *
- * Function         L2CA_SetFixedChannelTout
+ * Function         L2CA_SetLeGattTimeout
  *
  * Description      Higher layers call this function to set the idle timeout for
  *                  a fixed channel. The "idle timeout" is the amount of time
@@ -422,8 +422,7 @@ bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable);
  * Returns          true if command succeeded, false if failed
  *
  ******************************************************************************/
-bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda, uint16_t fixed_cid,
-                              uint16_t idle_tout);
+bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout);
 
 bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda, uint16_t min_int,
                               uint16_t max_int, uint16_t latency,
index 2253479..fb3dfcf 100644 (file)
@@ -959,7 +959,7 @@ void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout,
 
   tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
   if (p_tcb != NULL) {
-    status = L2CA_SetFixedChannelTout(bd_addr, L2CAP_ATT_CID, idle_tout);
+    status = L2CA_SetLeGattTimeout(bd_addr, idle_tout);
 
     if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP)
       L2CA_SetIdleTimeoutByBdAddr(
index 80efdf6..5e568ce 100644 (file)
@@ -741,7 +741,7 @@ extern bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda);
 
 /*******************************************************************************
  *
- * Function         L2CA_SetFixedChannelTout
+ * Function         L2CA_SetLeGattTimeout
  *
  * Description      Higher layers call this function to set the idle timeout for
  *                  a fixed channel. The "idle timeout" is the amount of time
@@ -756,8 +756,8 @@ extern bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda);
  * Returns          true if command succeeded, false if failed
  *
  ******************************************************************************/
-extern bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda,
-                                     uint16_t fixed_cid, uint16_t idle_tout);
+extern bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda,
+                                  uint16_t idle_tout);
 
 extern bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda,
                                      uint16_t min_int, uint16_t max_int,
index 1f2dfa6..823e62f 100644 (file)
@@ -1421,7 +1421,7 @@ bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda) {
 
 /*******************************************************************************
  *
- * Function         L2CA_SetFixedChannelTout
+ * Function         L2CA_SetLeGattTimeout
  *
  * Description      Higher layers call this function to set the idle timeout for
  *                  a fixed channel. The "idle timeout" is the amount of time
@@ -1434,30 +1434,24 @@ bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda) {
  * Returns          true if command succeeded, false if failed
  *
  ******************************************************************************/
-bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda, uint16_t fixed_cid,
-                              uint16_t idle_tout) {
+bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout) {
   if (bluetooth::shim::is_gd_l2cap_enabled()) {
-    return bluetooth::shim::L2CA_SetFixedChannelTout(rem_bda, fixed_cid,
-                                                     idle_tout);
+    return bluetooth::shim::L2CA_SetLeGattTimeout(rem_bda, idle_tout);
   }
 
-  tL2C_LCB* p_lcb;
-  tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
-
-  if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID)
-    transport = BT_TRANSPORT_LE;
+  constexpr uint16_t kAttCid = 4;
 
   /* Is a fixed channel connected to the remote BDA ?*/
-  p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport);
+  tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE);
   if (((p_lcb) == NULL) ||
-      (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL])) {
+      (!p_lcb->p_fixed_ccbs[kAttCid - L2CAP_FIRST_FIXED_CHNL])) {
     LOG(WARNING) << __func__ << " BDA: " << rem_bda
-                 << StringPrintf(" CID: 0x%04x not connected", fixed_cid);
+                 << StringPrintf(" CID: 0x%04x not connected", kAttCid);
     return (false);
   }
 
-  p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]
-      ->fixed_chnl_idle_tout = idle_tout;
+  p_lcb->p_fixed_ccbs[kAttCid - L2CAP_FIRST_FIXED_CHNL]->fixed_chnl_idle_tout =
+      idle_tout;
 
   if (p_lcb->in_use && p_lcb->link_state == LST_CONNECTED &&
       !p_lcb->ccb_queue.p_first_ccb) {
index 5d0cae5..8f8326d 100644 (file)
@@ -91,8 +91,7 @@ bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable) {
   mock_function_count_map[__func__]++;
   return false;
 }
-bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda, uint16_t fixed_cid,
-                              uint16_t idle_tout) {
+bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout) {
   mock_function_count_map[__func__]++;
   return false;
 }
index 5c8a48d..77b4cb2 100644 (file)
@@ -106,9 +106,8 @@ bool bluetooth::shim::L2CA_SetChnlFlushability(uint16_t cid,
   mock_function_count_map[__func__]++;
   return false;
 }
-bool bluetooth::shim::L2CA_SetFixedChannelTout(const RawAddress& rem_bda,
-                                               uint16_t fixed_cid,
-                                               uint16_t idle_tout) {
+bool bluetooth::shim::L2CA_SetLeGattTimeout(const RawAddress& rem_bda,
+                                            uint16_t idle_tout) {
   mock_function_count_map[__func__]++;
   return false;
 }