From 09f5d7f4653b0efdd80a0aceddf1620e75012fbb Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Fri, 25 Sep 2020 17:03:33 -0700 Subject: [PATCH] Use gap_on_l2cap_error for error handling Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I8faaa5f586e3133d1a5c7ff890ad27a87ee9433a --- stack/gap/gap_conn.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index 494862927..5c2e8b61b 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -683,6 +683,16 @@ static void gap_sec_check_complete(const RawAddress*, tBT_TRANSPORT, } } +static void gap_on_l2cap_error(uint16_t l2cap_cid, uint16_t result) { + tGAP_CCB* p_ccb = gap_find_ccb_by_cid(l2cap_cid); + + /* Tell the user if there is a callback */ + if (p_ccb->p_callback) + (*p_ccb->p_callback)(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); + + gap_release_ccb(p_ccb); +} + /******************************************************************************* * * Function gap_connect_cfm @@ -728,11 +738,7 @@ static void gap_connect_cfm(uint16_t l2cap_cid, uint16_t result) { gap_checks_con_flags(p_ccb); } } else { - /* Tell the user if there is a callback */ - if (p_ccb->p_callback) - (*p_ccb->p_callback)(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); - - gap_release_ccb(p_ccb); + gap_on_l2cap_error(l2cap_cid, result); } } @@ -789,8 +795,7 @@ static void gap_config_cfm(uint16_t l2cap_cid, uint16_t result) { p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; gap_checks_con_flags(p_ccb); } else { - p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); - gap_release_ccb(p_ccb); + gap_on_l2cap_error(l2cap_cid, result); } } -- 2.11.0