From: Hansong Zhang Date: Fri, 25 Sep 2020 23:54:05 +0000 (-0700) Subject: Use gatt_on_l2cap_error for error handling X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e8dc945f4d9e59b409a21548ef2af2ffdaea7f1f;p=android-x86%2Fsystem-bt.git Use gatt_on_l2cap_error for error handling Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I7a2fbc5805662270588d152ead932ffa02fc9dc6 --- diff --git a/stack/gatt/gatt_main.cc b/stack/gatt/gatt_main.cc index 38ae8bf9f..e41fffded 100644 --- a/stack/gatt/gatt_main.cc +++ b/stack/gatt/gatt_main.cc @@ -581,6 +581,15 @@ static void gatt_l2cif_connect_ind_cback(const RawAddress& bd_addr, gatt_set_ch_state(p_tcb, GATT_CH_CFG); } +static void gatt_on_l2cap_error(uint16_t lcid, uint16_t result) { + tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); + if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) { + gatt_cleanup_upon_disc(p_tcb->peer_bda, result, BT_TRANSPORT_BR_EDR); + } else { + gatt_l2cif_disconnect(lcid); + } +} + /** This is the L2CAP connect confirm callback function */ static void gatt_l2cif_connect_cfm_cback(uint16_t lcid, uint16_t result) { tGATT_TCB* p_tcb; @@ -593,24 +602,10 @@ static void gatt_l2cif_connect_cfm_cback(uint16_t lcid, uint16_t result) { << StringPrintf(" result: %d ch_state: %d, lcid:0x%x", result, gatt_get_ch_state(p_tcb), p_tcb->att_lcid); - /* if in correct state */ - if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) { - /* if result successful */ - if (result == L2CAP_CONN_OK) { - /* set channel state */ - gatt_set_ch_state(p_tcb, GATT_CH_CFG); - } - /* else initiating connection failure */ - else { - gatt_cleanup_upon_disc(p_tcb->peer_bda, result, BT_TRANSPORT_BR_EDR); - } - } else /* wrong state, disconnect it */ - { - if (result == L2CAP_CONN_OK) { - /* just in case the peer also accepts our connection - Send L2CAP - * disconnect req */ - gatt_l2cif_disconnect(lcid); - } + if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN && result == L2CAP_CONN_OK) { + gatt_set_ch_state(p_tcb, GATT_CH_CFG); + } else { + gatt_on_l2cap_error(lcid, result); } } @@ -625,8 +620,7 @@ void gatt_l2cif_config_cfm_cback(uint16_t lcid, uint16_t result) { /* if result not successful */ if (result != L2CAP_CFG_OK) { - /* Send L2CAP disconnect req */ - gatt_l2cif_disconnect(lcid); + gatt_on_l2cap_error(lcid, result); return; }