mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 02:30:52 +03:00
fix(ble/bluedroid): re-lookup GATT TCB after enc-complete callback
(cherry picked from commit 37562af0ea)
Co-authored-by: zhiweijian <zhiweijian@espressif.com>
This commit is contained in:
@@ -232,34 +232,40 @@ void gatt_notify_enc_cmpl(BD_ADDR bd_addr)
|
||||
tGATT_TCB *p_tcb;
|
||||
UINT8 i = 0;
|
||||
|
||||
if ((p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE)) != NULL) {
|
||||
for (i = 0; i < GATT_MAX_APPS; i++) {
|
||||
if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) {
|
||||
(*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, bd_addr);
|
||||
}
|
||||
}
|
||||
|
||||
if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) {
|
||||
gatt_set_sec_act(p_tcb, GATT_SEC_NONE);
|
||||
|
||||
size_t count = fixed_queue_length(p_tcb->pending_enc_clcb);
|
||||
for (; count > 0; count--) {
|
||||
tGATT_PENDING_ENC_CLCB *p_buf =
|
||||
(tGATT_PENDING_ENC_CLCB *)fixed_queue_dequeue(p_tcb->pending_enc_clcb, 0);
|
||||
if (p_buf != NULL) {
|
||||
gatt_security_check_start(p_buf->p_clcb);
|
||||
osi_free(p_buf);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if (BLE_EATT_INCLUDED == TRUE)
|
||||
gatt_eatt_on_encrypted(bd_addr);
|
||||
#endif
|
||||
} else {
|
||||
if ((p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE)) == NULL) {
|
||||
GATT_TRACE_DEBUG("notify GATT for encryption completion of unknown device");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < GATT_MAX_APPS; i++) {
|
||||
if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) {
|
||||
(*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, bd_addr);
|
||||
}
|
||||
}
|
||||
|
||||
/* p_tcb may be removed in p_enc_cmpl_cb (e.g. disconnect); re-lookup before use */
|
||||
if ((p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE)) == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) {
|
||||
gatt_set_sec_act(p_tcb, GATT_SEC_NONE);
|
||||
|
||||
size_t count = fixed_queue_length(p_tcb->pending_enc_clcb);
|
||||
for (; count > 0; count--) {
|
||||
tGATT_PENDING_ENC_CLCB *p_buf =
|
||||
(tGATT_PENDING_ENC_CLCB *)fixed_queue_dequeue(p_tcb->pending_enc_clcb, 0);
|
||||
if (p_buf != NULL) {
|
||||
gatt_security_check_start(p_buf->p_clcb);
|
||||
osi_free(p_buf);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if (BLE_EATT_INCLUDED == TRUE)
|
||||
gatt_eatt_on_encrypted(bd_addr);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#endif // (SMP_INCLUDED == TRUE)
|
||||
|
||||
Reference in New Issue
Block a user