Merge branch 'bugfix/crash_in_btc_hf_init_v5.2' into 'release/v5.2'

fix(bt/bluedroid): Avoided crash of LoadProhibited during HFP AG deinitialization (v5.2)

See merge request espressif/esp-idf!28115
This commit is contained in:
Jiang Jiang Jian 2023-12-27 10:26:19 +08:00
commit 7823f6c996
6 changed files with 30 additions and 14 deletions

View File

@ -397,10 +397,6 @@ void bta_ag_rfc_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
bta_sys_conn_close(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
/* call close call-out */
#if (BTM_SCO_HCI_INCLUDED == TRUE)
bta_ag_sco_co_close();
#endif
/* call close cback */
(*bta_ag_cb.p_cback)(BTA_AG_CLOSE_EVT, (tBTA_AG *) &close);

View File

@ -61,7 +61,8 @@ static const uint8_t bta_hf_client_cb_data_size[] = {
sizeof(tBTA_HF_CLIENT_VAL), // #define BTA_HF_CLIENT_BSIR_EVT 19
sizeof(tBTA_HF_CLIENT_NUMBER), // #define BTA_HF_CLIENT_BINP_EVT 20
sizeof(tBTA_HF_CLIENT_VAL), // #define BTA_HF_CLIENT_RING_INDICATION 21
0, // #define BTA_HF_CLIENT_DISABLE_EVT 30
0, // #define BTA_HF_CLIENT_DISABLE_EVT 22
sizeof(tBTA_SCO_PKT_STAT_NUMS), // #define BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT 23
};
/*****************************************************************************
** External Function Declarations

View File

@ -112,8 +112,8 @@ typedef UINT8 tBTA_HF_CLIENT_AT_RESULT_TYPE;
#define BTA_HF_CLIENT_BSIR_EVT 19 /* in-band ring tone setting changed event */
#define BTA_HF_CLIENT_BINP_EVT 20 /* binp number event */
#define BTA_HF_CLIENT_RING_INDICATION 21 /* HF Client ring indication */
#define BTA_HF_CLIENT_DISABLE_EVT 30 /* HF Client disabled */
#define BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT 31 /* HF Client packet status nums */
#define BTA_HF_CLIENT_DISABLE_EVT 22 /* HF Client disabled */
#define BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT 23 /* HF Client packet status nums */
typedef UINT8 tBTA_HF_CLIENT_EVT;

View File

@ -82,7 +82,7 @@ static bta_ag_co_cb_t *bta_ag_co_cb_ptr;
#define bta_ag_co_cb (*bta_ag_co_cb_ptr)
#endif /* HFP_DYNAMIC_MEMORY == FALSE */
static UINT8 hf_air_mode = BTM_SCO_AIR_MODE_TRANSPNT;
static UINT8 hf_air_mode = BTM_SCO_AIR_MODE_UNKNOWN;
static UINT8 hf_inout_pkt_size = 0;
/* =========================================================================

View File

@ -68,7 +68,7 @@ static UINT16 btc_max_hf_clients = BTC_HF_NUM_CB;
#if HFP_DYNAMIC_MEMORY == FALSE
static hf_local_param_t hf_local_param[BTC_HF_NUM_CB];
#else
static hf_local_param_t *hf_local_param;
static hf_local_param_t *hf_local_param = NULL;
#endif
#if (BTM_WBS_INCLUDED == TRUE)
@ -317,6 +317,19 @@ bt_status_t btc_hf_init(void)
int idx = 0;
BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients);
#if HFP_DYNAMIC_MEMORY == TRUE
if (hf_local_param != NULL) {
return BT_STATUS_FAIL;
}
if ((hf_local_param = (hf_local_param_t *)osi_malloc(BTC_HF_NUM_CB * sizeof(hf_local_param_t))) == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
return BT_STATUS_NOMEM;
}
memset((void *)hf_local_param, 0, BTC_HF_NUM_CB * sizeof(hf_local_param_t));
#endif
/* Invoke the enable service API to the core to set the appropriate service_id
* Internally, the HSP_SERVICE_ID shall also be enabled if HFP is enabled (phone)
* othwerwise only HSP is enabled (tablet)*/
@ -345,13 +358,16 @@ void btc_hf_deinit(void)
{
BTC_TRACE_EVENT("%s", __FUNCTION__);
btc_dm_disable_service(BTA_HFP_SERVICE_ID);
hf_local_param[0].btc_hf_cb.initialized = false;
}
static void btc_hf_cb_release(void)
{
#if HFP_DYNAMIC_MEMORY == TRUE
if (hf_local_param) {
osi_free(hf_local_param);
hf_local_param = NULL;
}
#else
hf_local_param[0].btc_hf_cb.initialized = false;
#endif
}
@ -1251,9 +1267,12 @@ void btc_hf_cb_handler(btc_msg_t *msg)
switch (event) {
case BTA_AG_ENABLE_EVT:
case BTA_AG_DISABLE_EVT:
break;
case BTA_AG_DISABLE_EVT:
{
btc_hf_cb_release();
break;
}
case BTA_AG_REGISTER_EVT:
{
idx = p_data->hdr.handle - 1;

View File

@ -1018,7 +1018,7 @@
/* TRUE to include Sniff Subrating */
#if (BTA_DM_PM_INCLUDED == TRUE)
#ifndef BTM_SSR_INCLUDED
#define BTM_SSR_INCLUDED TRUE
#define BTM_SSR_INCLUDED FALSE
#endif
#endif /* BTA_DM_PM_INCLUDED */