OSDN Git Service

Streamline stack/l2cap/l2c_ble::l2cble_notify_le_connection
authorChris Manton <cmanton@google.com>
Sat, 3 Oct 2020 16:22:57 +0000 (09:22 -0700)
committerChris Manton <cmanton@google.com>
Tue, 6 Oct 2020 06:04:40 +0000 (06:04 +0000)
Towards readable code

Bug: 163134718
Tag: #refactor
Test: act.py -tc BleCocTest
Test: ble paired 2 phones
Test: classic paired Bose SoundLink
Change-Id: I1ffb5df7acd8f616822ec3eeacef7d88d6dbc249

stack/l2cap/l2c_ble.cc

index e760d65..4e69d9b 100644 (file)
@@ -239,24 +239,26 @@ uint16_t L2CA_GetDisconnectReason(const RawAddress& remote_bda,
  ******************************************************************************/
 void l2cble_notify_le_connection(const RawAddress& bda) {
   tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE);
-  tL2C_CCB* p_ccb;
+  if (p_lcb == nullptr) {
+    LOG_WARN("Received notification for le connection but no lcb found");
+    return;
+  }
 
-  if (p_lcb != NULL && BTM_IsAclConnectionUp(bda, BT_TRANSPORT_LE) &&
+  if (BTM_IsAclConnectionUp(bda, BT_TRANSPORT_LE) &&
       p_lcb->link_state != LST_CONNECTED) {
     /* update link status */
+    // TODO Move this back into acl layer
     btm_establish_continue_from_address(bda, BT_TRANSPORT_LE);
     /* update l2cap link status and send callback */
     p_lcb->link_state = LST_CONNECTED;
     l2cu_process_fixed_chnl_resp(p_lcb);
   }
 
-  if (p_lcb != NULL) {
-    /* For all channels, send the event through their FSMs */
-    for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb;
-         p_ccb = p_ccb->p_next_ccb) {
-      if (p_ccb->chnl_state == CST_CLOSED)
-        l2c_csm_execute(p_ccb, L2CEVT_LP_CONNECT_CFM, NULL);
-    }
+  /* For all channels, send the event through their FSMs */
+  for (tL2C_CCB* p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb;
+       p_ccb = p_ccb->p_next_ccb) {
+    if (p_ccb->chnl_state == CST_CLOSED)
+      l2c_csm_execute(p_ccb, L2CEVT_LP_CONNECT_CFM, NULL);
   }
 }