Skip to content

Commit

Permalink
Merge branch 'bugfix/crash_in_btc_hf_init_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
fix(bt/bluedroid): Avoided crash of LoadProhibited during HFP AG deinitialization (v5.2)

See merge request espressif/esp-idf!28115
  • Loading branch information
jack0c committed Dec 27, 2023
2 parents bdce46f + f30d282 commit 7823f6c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
4 changes: 0 additions & 4 deletions components/bt/host/bluedroid/bta/hf_ag/bta_ag_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/* =========================================================================
Expand Down
27 changes: 23 additions & 4 deletions components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)*/
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1251,9 +1267,12 @@ void btc_hf_cb_handler(btc_msg_t *msg)

switch (event) {
case BTA_AG_ENABLE_EVT:
break;
case BTA_AG_DISABLE_EVT:
{
btc_hf_cb_release();
break;

}
case BTA_AG_REGISTER_EVT:
{
idx = p_data->hdr.handle - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit 7823f6c

Please sign in to comment.