From 55015964ef5180aca63eb8b9ddb070201e3168ec Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Mon, 15 Apr 2019 22:07:27 +0200 Subject: [PATCH] Send connected callback immediately when attempting to connect to already connected device Instead of adding the device to the connection manager, just send the successfull connection callback. This patch is restoring behaviour from before Connection Manager refactor. During the refactor this behaviour was broken. Bug: 130273570 Test: sl4a GattConnectTest Change-Id: Ic4fa7089a8262f6f792206496a7cfb9c83a16eb2 Merged-In: Ic4fa7089a8262f6f792206496a7cfb9c83a16eb2 --- stack/gatt/gatt_main.cc | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/stack/gatt/gatt_main.cc b/stack/gatt/gatt_main.cc index 6a007505e..fa8c79c44 100644 --- a/stack/gatt/gatt_main.cc +++ b/stack/gatt/gatt_main.cc @@ -197,21 +197,38 @@ void gatt_free(void) { bool gatt_connect(const RawAddress& rem_bda, tGATT_TCB* p_tcb, tBT_TRANSPORT transport, uint8_t initiating_phys, tGATT_IF gatt_if) { - bool gatt_ret = false; - if (gatt_get_ch_state(p_tcb) != GATT_CH_OPEN) gatt_set_ch_state(p_tcb, GATT_CH_CONN); - if (transport == BT_TRANSPORT_LE) { - p_tcb->att_lcid = L2CAP_ATT_CID; - - gatt_ret = connection_manager::direct_connect_add(gatt_if, rem_bda); - } else { + if (transport != BT_TRANSPORT_LE) { p_tcb->att_lcid = L2CA_ConnectReq(BT_PSM_ATT, rem_bda); - if (p_tcb->att_lcid != 0) gatt_ret = true; + return p_tcb->att_lcid != 0; + } + + // Already connected, send the callback, mark the link as used + if (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) { + /* very similar to gatt_send_conn_cback, but no good way to reuse the code + */ + + /* notifying application about the connection up event */ + for (int i = 0; i < GATT_MAX_APPS; i++) { + tGATT_REG* p_reg = &gatt_cb.cl_rcb[i]; + + if (!p_reg->in_use || p_reg->gatt_if != gatt_if) continue; + + gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true); + if (p_reg->app_cb.p_conn_cb) { + uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, + true, 0, p_tcb->transport); + } + } + + return true; } - return gatt_ret; + p_tcb->att_lcid = L2CAP_ATT_CID; + return connection_manager::direct_connect_add(gatt_if, rem_bda); } /******************************************************************************* -- 2.11.0