Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_some_bluedroid_bugs_v4.4' into 'release/v4.4'
Browse files Browse the repository at this point in the history
Fixed some bluedroid bugs (backport v4.4)

See merge request espressif/esp-idf!24862
  • Loading branch information
jack0c committed Jul 19, 2023
2 parents fc31da6 + b2325e5 commit 2dd51c1
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ typedef union {
} search_res; /*!< Gatt client callback param of ESP_GATTC_SEARCH_RES_EVT */

/**
* @brief ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT
* @brief ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT, ESP_GATTC_READ_MULTIPLE_EVT, ESP_GATTC_READ_MULTI_VAR_EVT
*/
struct gattc_read_char_evt_param {

Expand Down
10 changes: 0 additions & 10 deletions components/bt/host/bluedroid/bta/dm/bta_dm_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,10 +982,6 @@ static void bta_dm_process_remove_device(BD_ADDR bd_addr, tBT_TRANSPORT transpor

BTM_SecDeleteDevice(bd_addr, transport);

#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* remove all cached GATT information */
BTA_GATTC_Refresh(bd_addr, false);
#endif
if (bta_dm_cb.p_sec_cback) {
tBTA_DM_SEC sec_event;
bdcpy(sec_event.link_down.bd_addr, bd_addr);
Expand Down Expand Up @@ -1140,8 +1136,6 @@ void bta_dm_close_acl(tBTA_DM_MSG *p_data)
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* need to remove all pending background connection if any */
BTA_GATTC_CancelOpen(0, p_remove_acl->bd_addr, FALSE);
/* remove all cached GATT information */
BTA_GATTC_Refresh(p_remove_acl->bd_addr, false);
#endif
}
/* otherwise, no action needed */
Expand Down Expand Up @@ -3636,8 +3630,6 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* need to remove all pending background connection */
BTA_GATTC_CancelOpen(0, p_bda, FALSE);
/* remove all cached GATT information */
BTA_GATTC_Refresh(p_bda, false);
#endif
}

Expand Down Expand Up @@ -3815,8 +3807,6 @@ static BOOLEAN bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr)
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* need to remove all pending background connection */
BTA_GATTC_CancelOpen(0, remote_bd_addr, FALSE);
/* remove all cached GATT information */
BTA_GATTC_Refresh(remote_bd_addr, false);
#endif
}
return is_device_deleted;
Expand Down
2 changes: 0 additions & 2 deletions components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,6 @@ void bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
bta_sys_conn_close( BTA_ID_GATTC , BTA_ALL_APP_ID, p_clcb->bda);
}

bta_gattc_clcb_dealloc(p_clcb);

if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) {
cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific);
} else if (p_data->hdr.event == BTA_GATTC_INT_DISCONN_EVT) {
Expand Down
10 changes: 10 additions & 0 deletions components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb)
}
}

void bta_gattc_clcb_dealloc_by_conn_id(UINT16 conn_id)
{
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);

if (p_clcb) {
bta_gattc_clcb_dealloc(p_clcb);
}
}

/*******************************************************************************
**
** Function bta_gattc_find_srcb
Expand Down Expand Up @@ -421,6 +430,7 @@ tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda)
{
if (p_tcb->p_srvc_cache != NULL) {
list_free(p_tcb->p_srvc_cache);
p_tcb->p_srvc_cache = NULL;
}
osi_free(p_tcb->p_srvc_list);
p_tcb->p_srvc_list = NULL;
Expand Down
2 changes: 2 additions & 0 deletions components/bt/host/bluedroid/bta/include/bta/bta_gatt_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ extern void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start,
BD_ADDR_PTR target_bda);


extern void bta_gattc_clcb_dealloc_by_conn_id(UINT16 conn_id);

#ifdef __cplusplus

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ static void btc_gap_ble_get_dev_name_callback(UINT8 status, char *name)
param.get_dev_name_cmpl.status = btc_btm_status_to_esp_status(status);
param.get_dev_name_cmpl.name = (char *)osi_malloc(BTC_MAX_LOC_BD_NAME_LEN + 1);
if (param.get_dev_name_cmpl.name) {
BCM_STRNCPY_S(param.get_dev_name_cmpl.name, name, BTC_MAX_LOC_BD_NAME_LEN + 1);
BCM_STRNCPY_S(param.get_dev_name_cmpl.name, name, BTC_MAX_LOC_BD_NAME_LEN);
param.get_dev_name_cmpl.name[BTC_MAX_LOC_BD_NAME_LEN] = '\0';
} else {
param.get_dev_name_cmpl.status = ESP_BT_STATUS_NOMEM;
}
Expand Down
2 changes: 2 additions & 0 deletions components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
case BTA_GATTC_CLOSE_EVT: {
tBTA_GATTC_CLOSE *close = &arg->close;

// Free gattc clcb in BTC task to avoid race condition
bta_gattc_clcb_dealloc_by_conn_id(close->conn_id);
gattc_if = close->client_if;
param.close.status = close->status;
param.close.conn_id = BTC_GATT_GET_CONN_ID(close->conn_id);
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/stack/include/stack/l2c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ extern BOOLEAN L2CA_CheckIsCongest(UINT16 fixed_cid, BD_ADDR addr);
#define L2CA_DECREASE_BTU_NUM 4
#define L2CA_BUFF_INI 5
#define L2CA_BUFF_DEINIT 6
#define L2CA_BUFF_FREE 7

typedef struct {
UINT16 conn_id;
Expand Down
6 changes: 6 additions & 0 deletions components/bt/host/bluedroid/stack/l2cap/l2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,12 @@ void l2ble_update_att_acl_pkt_num(UINT8 type, tl2c_buff_param_t *param)
buff_semaphore = NULL;
break;
}
case L2CA_BUFF_FREE:{
xSemaphoreTake(buff_semaphore, portMAX_DELAY);
// Do nothing
xSemaphoreGive(buff_semaphore);
break;
}
default:
break;
}
Expand Down
6 changes: 6 additions & 0 deletions components/bt/host/bluedroid/stack/l2cap/l2c_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,12 @@ void l2cu_release_ccb (tL2C_CCB *p_ccb)
if (!p_ccb->in_use) {
return;
}
#if BLE_INCLUDED == TRUE
if (p_lcb->transport == BT_TRANSPORT_LE) {
/* Take samephore to avoid race condition */
l2ble_update_att_acl_pkt_num(L2CA_BUFF_FREE, NULL);
}
#endif
#if (SDP_INCLUDED == TRUE)
if (p_rcb && (p_rcb->psm != p_rcb->real_psm)) {
btm_sec_clr_service_by_psm(p_rcb->psm);
Expand Down

0 comments on commit 2dd51c1

Please sign in to comment.