From 05b5671fc450170bcb7227f90a94ea71d89e05cf Mon Sep 17 00:00:00 2001 From: zwj Date: Fri, 2 Mar 2018 21:33:28 +0800 Subject: [PATCH] component/bt: fix gattc open api --- .../bt/bluedroid/bta/gatt/bta_gattc_act.c | 24 +++++++++++++------ .../bt/bluedroid/bta/gatt/bta_gattc_main.c | 4 ++-- .../bt/bluedroid/bta/gatt/bta_gattc_utils.c | 1 + .../bt/bluedroid/bta/include/bta_gattc_int.h | 1 + .../bt/bluedroid/stack/gatt/gatt_utils.c | 23 ++++++++++++++++++ .../bluedroid/stack/gatt/include/gatt_int.h | 1 + 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index 37c349dad..c9189b20d 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -493,7 +493,12 @@ void bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) { tBTA_GATTC_DATA gattc_data; + BOOLEAN found_app = FALSE; + tGATT_TCB *p_tcb = gatt_find_tcb_by_addr(p_data->api_conn.remote_bda, BT_TRANSPORT_LE); + if(p_tcb && p_clcb && p_data) { + found_app = gatt_find_specific_app_in_hold_link(p_tcb, p_clcb->p_rcb->client_if); + } /* open/hold a connection */ if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, TRUE, p_data->api_conn.transport)) { @@ -507,7 +512,7 @@ void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) &p_clcb->bta_conn_id, p_data->api_conn.transport)) { gattc_data.int_conn.hdr.layer_specific = p_clcb->bta_conn_id; - + gattc_data.int_conn.already_connect = found_app; bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, &gattc_data); } /* else wait for the callback event */ @@ -672,14 +677,14 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) if (bta_gattc_cache_load(p_clcb)) { p_clcb->p_srcb->state = BTA_GATTC_SERV_IDLE; bta_gattc_reset_discover_st(p_clcb->p_srcb, BTA_GATT_OK); - } else { /* cache is building */ + } else { /* cache is building */ p_clcb->p_srcb->state = BTA_GATTC_SERV_DISC; /* cache load failure, start discovery */ bta_gattc_start_discover(p_clcb, NULL); + } + } else { /* cache is building */ + p_clcb->state = BTA_GATTC_DISCOVER_ST; } - } else { /* cache is building */ - p_clcb->state = BTA_GATTC_DISCOVER_ST; - } } else { /* a pending service handle change indication */ if (p_clcb->p_srcb->srvc_hdl_chg) { @@ -694,9 +699,14 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) if (p_clcb->transport == BTA_TRANSPORT_BR_EDR) { bta_sys_conn_open(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda); } - + tBTA_GATT_STATUS status = BTA_GATT_OK; + if (p_data && p_data->int_conn.already_connect) { + //clear already_connect + p_data->int_conn.already_connect = FALSE; + status = BTA_GATT_ALREADY_OPEN; + } bta_gattc_send_open_cback(p_clcb->p_rcb, - BTA_GATT_OK, + status, p_clcb->bda, p_clcb->bta_conn_id, p_clcb->transport, diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c index 0551c0871..373b0e275 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c @@ -182,7 +182,7 @@ static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] = { /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_READ_MULTI, BTA_GATTC_CONN_ST}, /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, - /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, + /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST}, /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_START_DISCOVER, BTA_GATTC_DISCOVER_ST}, /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}, /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_OP_CMPL, BTA_GATTC_CONN_ST}, @@ -211,7 +211,7 @@ static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] = { /* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST}, /* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST}, - /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST}, + /* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_DISCOVER_ST}, /* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_RESTART_DISCOVER, BTA_GATTC_DISCOVER_ST}, /* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_DISC_CMPL, BTA_GATTC_CONN_ST}, /* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE_OP_CMPL, BTA_GATTC_DISCOVER_ST}, diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c index 4e3cf9737..22a6f24b8 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c @@ -709,6 +709,7 @@ void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport, UINT16 mtu) { + tBTA_GATTC cb_data; if (p_clreg->p_cback) { diff --git a/components/bt/bluedroid/bta/include/bta_gattc_int.h b/components/bt/bluedroid/bta/include/bta_gattc_int.h index e05a3eb9c..4151cb858 100644 --- a/components/bt/bluedroid/bta/include/bta_gattc_int.h +++ b/components/bt/bluedroid/bta/include/bta_gattc_int.h @@ -192,6 +192,7 @@ typedef struct { UINT8 role; tBT_TRANSPORT transport; tGATT_DISCONN_REASON reason; + BOOLEAN already_connect; } tBTA_GATTC_INT_CONN; typedef struct { diff --git a/components/bt/bluedroid/stack/gatt/gatt_utils.c b/components/bt/bluedroid/stack/gatt/gatt_utils.c index 98339c04e..594844c2f 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_utils.c +++ b/components/bt/bluedroid/stack/gatt/gatt_utils.c @@ -1998,6 +1998,29 @@ BOOLEAN gatt_find_app_hold_link(tGATT_TCB *p_tcb, UINT8 start_idx, UINT8 *p_foun return found; } +/******************************************************************************* +** +** Function gatt_find_specific_app_in_hold_link +** +** Description find the specific applicaiton that is holding the specified link +** +** Returns Boolean +** +*******************************************************************************/ +BOOLEAN gatt_find_specific_app_in_hold_link(tGATT_TCB *p_tcb, tGATT_IF p_gatt_if) +{ + UINT8 i; + BOOLEAN found = FALSE; + + for (i = 0; i < GATT_MAX_APPS; i ++) { + if (p_tcb->app_hold_link[i] && p_tcb->app_hold_link[i] == p_gatt_if) { + found = TRUE; + break; + } + } + return found; +} + /******************************************************************************* ** ** Function gatt_cmd_enq diff --git a/components/bt/bluedroid/stack/gatt/include/gatt_int.h b/components/bt/bluedroid/stack/gatt/include/gatt_int.h index 1f9be3092..4f236f28c 100644 --- a/components/bt/bluedroid/stack/gatt/include/gatt_int.h +++ b/components/bt/bluedroid/stack/gatt/include/gatt_int.h @@ -682,6 +682,7 @@ extern void gatt_sr_update_cback_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, BOOLEAN extern void gatt_sr_update_prep_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, BOOLEAN is_inc, BOOLEAN is_reset_first); extern BOOLEAN gatt_find_app_hold_link(tGATT_TCB *p_tcb, UINT8 start_idx, UINT8 *p_found_idx, tGATT_IF *p_gatt_if); +extern BOOLEAN gatt_find_specific_app_in_hold_link(tGATT_TCB *p_tcb, tGATT_IF p_gatt_if); extern UINT8 gatt_num_apps_hold_link(tGATT_TCB *p_tcb); extern UINT8 gatt_num_clcb_by_bd_addr(BD_ADDR bda); extern tGATT_TCB *gatt_find_tcb_by_cid(UINT16 lcid);