Skip to content

Commit d694659

Browse files
committed
Merge branch 'bugfix/btdm_fix_gattc_open_API' into 'master'
component/bt: fix gattc open api See merge request idf/esp-idf!2004
2 parents 9a6fcab + d140518 commit d694659

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

components/bt/bluedroid/bta/gatt/bta_gattc_act.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,12 @@ void bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
493493
void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
494494
{
495495
tBTA_GATTC_DATA gattc_data;
496+
BOOLEAN found_app = FALSE;
496497

498+
tGATT_TCB *p_tcb = gatt_find_tcb_by_addr(p_data->api_conn.remote_bda, BT_TRANSPORT_LE);
499+
if(p_tcb && p_clcb && p_data) {
500+
found_app = gatt_find_specific_app_in_hold_link(p_tcb, p_clcb->p_rcb->client_if);
501+
}
497502
/* open/hold a connection */
498503
if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda,
499504
TRUE, p_data->api_conn.transport)) {
@@ -507,7 +512,7 @@ void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
507512
&p_clcb->bta_conn_id,
508513
p_data->api_conn.transport)) {
509514
gattc_data.int_conn.hdr.layer_specific = p_clcb->bta_conn_id;
510-
515+
gattc_data.int_conn.already_connect = found_app;
511516
bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, &gattc_data);
512517
}
513518
/* else wait for the callback event */
@@ -672,14 +677,14 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
672677
if (bta_gattc_cache_load(p_clcb)) {
673678
p_clcb->p_srcb->state = BTA_GATTC_SERV_IDLE;
674679
bta_gattc_reset_discover_st(p_clcb->p_srcb, BTA_GATT_OK);
675-
} else { /* cache is building */
680+
} else { /* cache is building */
676681
p_clcb->p_srcb->state = BTA_GATTC_SERV_DISC;
677682
/* cache load failure, start discovery */
678683
bta_gattc_start_discover(p_clcb, NULL);
684+
}
685+
} else { /* cache is building */
686+
p_clcb->state = BTA_GATTC_DISCOVER_ST;
679687
}
680-
} else { /* cache is building */
681-
p_clcb->state = BTA_GATTC_DISCOVER_ST;
682-
}
683688
} else {
684689
/* a pending service handle change indication */
685690
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)
694699
if (p_clcb->transport == BTA_TRANSPORT_BR_EDR) {
695700
bta_sys_conn_open(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
696701
}
697-
702+
tBTA_GATT_STATUS status = BTA_GATT_OK;
703+
if (p_data && p_data->int_conn.already_connect) {
704+
//clear already_connect
705+
p_data->int_conn.already_connect = FALSE;
706+
status = BTA_GATT_ALREADY_OPEN;
707+
}
698708
bta_gattc_send_open_cback(p_clcb->p_rcb,
699-
BTA_GATT_OK,
709+
status,
700710
p_clcb->bda,
701711
p_clcb->bta_conn_id,
702712
p_clcb->transport,

components/bt/bluedroid/bta/gatt/bta_gattc_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] = {
183183
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_READ_MULTI, BTA_GATTC_CONN_ST},
184184
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
185185

186-
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
186+
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST},
187187
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_START_DISCOVER, BTA_GATTC_DISCOVER_ST},
188188
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
189189
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_OP_CMPL, BTA_GATTC_CONN_ST},
@@ -212,7 +212,7 @@ static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] = {
212212
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
213213
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
214214

215-
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
215+
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_DISCOVER_ST},
216216
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_RESTART_DISCOVER, BTA_GATTC_DISCOVER_ST},
217217
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_DISC_CMPL, BTA_GATTC_CONN_ST},
218218
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE_OP_CMPL, BTA_GATTC_DISCOVER_ST},

components/bt/bluedroid/bta/gatt/bta_gattc_utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status
709709
BD_ADDR remote_bda, UINT16 conn_id,
710710
tBTA_TRANSPORT transport, UINT16 mtu)
711711
{
712+
712713
tBTA_GATTC cb_data;
713714

714715
if (p_clreg->p_cback) {

components/bt/bluedroid/bta/include/bta_gattc_int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ typedef struct {
192192
UINT8 role;
193193
tBT_TRANSPORT transport;
194194
tGATT_DISCONN_REASON reason;
195+
BOOLEAN already_connect;
195196
} tBTA_GATTC_INT_CONN;
196197

197198
typedef struct {

components/bt/bluedroid/stack/gatt/gatt_utils.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,29 @@ BOOLEAN gatt_find_app_hold_link(tGATT_TCB *p_tcb, UINT8 start_idx, UINT8 *p_foun
19981998
return found;
19991999
}
20002000

2001+
/*******************************************************************************
2002+
**
2003+
** Function gatt_find_specific_app_in_hold_link
2004+
**
2005+
** Description find the specific applicaiton that is holding the specified link
2006+
**
2007+
** Returns Boolean
2008+
**
2009+
*******************************************************************************/
2010+
BOOLEAN gatt_find_specific_app_in_hold_link(tGATT_TCB *p_tcb, tGATT_IF p_gatt_if)
2011+
{
2012+
UINT8 i;
2013+
BOOLEAN found = FALSE;
2014+
2015+
for (i = 0; i < GATT_MAX_APPS; i ++) {
2016+
if (p_tcb->app_hold_link[i] && p_tcb->app_hold_link[i] == p_gatt_if) {
2017+
found = TRUE;
2018+
break;
2019+
}
2020+
}
2021+
return found;
2022+
}
2023+
20012024
/*******************************************************************************
20022025
**
20032026
** Function gatt_cmd_enq

components/bt/bluedroid/stack/gatt/include/gatt_int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ extern void gatt_sr_update_cback_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, BOOLEAN
682682
extern void gatt_sr_update_prep_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, BOOLEAN is_inc, BOOLEAN is_reset_first);
683683

684684
extern BOOLEAN gatt_find_app_hold_link(tGATT_TCB *p_tcb, UINT8 start_idx, UINT8 *p_found_idx, tGATT_IF *p_gatt_if);
685+
extern BOOLEAN gatt_find_specific_app_in_hold_link(tGATT_TCB *p_tcb, tGATT_IF p_gatt_if);
685686
extern UINT8 gatt_num_apps_hold_link(tGATT_TCB *p_tcb);
686687
extern UINT8 gatt_num_clcb_by_bd_addr(BD_ADDR bda);
687688
extern tGATT_TCB *gatt_find_tcb_by_cid(UINT16 lcid);

0 commit comments

Comments
 (0)