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;
<< 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);
}
}
/* if result not successful */
if (result != L2CAP_CFG_OK) {
- /* Send L2CAP disconnect req */
- gatt_l2cif_disconnect(lcid);
+ gatt_on_l2cap_error(lcid, result);
return;
}