From 9bc4e5285e8d32689f8db7de5174f5ac1a2f70bb Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Sat, 3 Oct 2020 09:22:57 -0700 Subject: [PATCH] Streamline stack/l2cap/l2c_ble::l2cble_notify_le_connection 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 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/stack/l2cap/l2c_ble.cc b/stack/l2cap/l2c_ble.cc index e760d659b..4e69d9b5f 100644 --- a/stack/l2cap/l2c_ble.cc +++ b/stack/l2cap/l2c_ble.cc @@ -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); } } -- 2.11.0