From 3e7a47a566e4a8eab66806ec5f61412cb508e9a0 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Fri, 18 Aug 2023 15:08:30 +0800 Subject: [PATCH 1/9] fix(bt/bluedroid): Fixed NULL Bluetooth device address in HF-AG events was reported to application layer --- .../bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index bd27e0565d7..57b9bc5dd4c 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -1368,6 +1368,7 @@ void btc_hf_cb_handler(btc_msg_t *msg) do { memset(¶m, 0, sizeof(esp_hf_cb_param_t)); param.vra_rep.value = p_data->val.num; + memcpy(param.vra_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); btc_hf_cb_to_app(ESP_HF_BVRA_RESPONSE_EVT, ¶m); if (p_data->val.num) { btc_hf_connect_audio(&hf_local_param[idx].btc_hf_cb.connected_bda); @@ -1463,9 +1464,12 @@ void btc_hf_cb_handler(btc_msg_t *msg) case BTA_AG_AT_BLDN_EVT: case BTA_AG_AT_D_EVT: { + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); do { if (event == BTA_AG_AT_D_EVT) { // dial_number_or_memory memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.out_call.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.out_call.num_or_loc = osi_malloc((strlen(p_data->val.str) + 1) * sizeof(char)); sprintf(param.out_call.num_or_loc, "%s", p_data->val.str); btc_hf_cb_to_app(ESP_HF_DIAL_EVT, ¶m); From ccfcc6a153a14c51e46b8d9279b5f8ed82330717 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Mon, 21 Aug 2023 10:06:49 +0800 Subject: [PATCH 2/9] fix(bt/bluedroid): Fixed errors in parsing ATD command in HFP AG --- .../bluedroid/api/include/api/esp_hf_ag_api.h | 9 +++++++ .../bt/host/bluedroid/bta/hf_ag/bta_ag_cmd.c | 24 +++++++++++++++++++ .../btc/profile/std/hf_ag/btc_hf_ag.c | 1 + .../classic_bt/hfp_ag/main/bt_app_hf.c | 21 +++++++++++++--- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h b/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h index adac556529f..20b02215562 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h @@ -64,6 +64,14 @@ typedef enum ESP_HF_BCS_RESPONSE_EVT, /*!< Final Codec Choice */ } esp_hf_cb_event_t; +/// Dial type of ESP_HF_DIAL_EVT +typedef enum +{ + ESP_HF_DIAL_MEM = 0, /*!< Dial with a memory position */ + ESP_HF_DIAL_VOIP, /*!< Dial with VoIP */ + ESP_HF_DIAL_NUM, /*!< Dial with a phone number */ +} esp_hf_dial_type_t; + /// HFP AG callback parameters typedef union { @@ -126,6 +134,7 @@ typedef union */ struct hf_out_call_param { esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + esp_hf_dial_type_t type; /*!< dial type */ char *num_or_loc; /*!< location in phone memory */ } out_call; /*!< AG callback param of ESP_HF_DIAL_EVT */ diff --git a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_cmd.c b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_cmd.c index 2f997c0f31c..1a49ad36a72 100644 --- a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_cmd.c +++ b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_cmd.c @@ -146,6 +146,14 @@ enum BTA_AG_HF_CMD_BAC }; +/* dialing type of BTA_AG_HF_CMD_D */ +enum +{ + BTA_AG_HF_DIAL_NUM = 0, + BTA_AG_HF_DIAL_VOIP, + BTA_AG_HF_DIAL_MEM, +}; + /* HFP AT command interpreter table */ const tBTA_AG_AT_CMD bta_ag_hfp_cmd[] = { @@ -856,6 +864,8 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, case BTA_AG_HF_CMD_D: { + UINT16 src = 0; + UINT16 dst = 0; /* Do not send OK for Dial cmds Let application decide whether to send OK or ERROR*/ /* if mem dial cmd, make sure string contains only digits */ if(p_arg[0] == '>') { @@ -863,6 +873,8 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, event = 0; bta_ag_send_error(p_scb, BTA_AG_ERR_INV_CHAR_IN_DSTR); } + val.value = BTA_AG_HF_DIAL_MEM; + src = 1; } else if (p_arg[0] == 'V') { /* ATDV : Dial VoIP Call */ /* We do not check string. Code will be added later if needed. */ @@ -870,6 +882,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, event = 0; bta_ag_send_error(p_scb, BTA_AG_ERR_OP_NOT_SUPPORTED); } + val.value = BTA_AG_HF_DIAL_VOIP; } else { /* If dial cmd, make sure string contains only dial digits ** Dial digits are 0-9, A-C, *, #, + */ @@ -877,6 +890,17 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, event = 0; bta_ag_send_error(p_scb, BTA_AG_ERR_INV_CHAR_IN_DSTR); } + val.value = BTA_AG_HF_DIAL_NUM; + } + if (event != 0) { + while ((val.str[dst] = p_arg[src]) != '\0') { + if (val.str[dst] == ';') { + val.str[dst] = '\0'; + break; + } + src++; + dst++; + } } break; } diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index 57b9bc5dd4c..ee74e28bce5 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -1470,6 +1470,7 @@ void btc_hf_cb_handler(btc_msg_t *msg) if (event == BTA_AG_AT_D_EVT) { // dial_number_or_memory memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.out_call.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + param.out_call.type = p_data->val.value; param.out_call.num_or_loc = osi_malloc((strlen(p_data->val.str) + 1) * sizeof(char)); sprintf(param.out_call.num_or_loc, "%s", p_data->val.str); btc_hf_cb_to_app(ESP_HF_DIAL_EVT, ¶m); diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c index d860a5b2c89..aadb5ad05a6 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c @@ -441,11 +441,26 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) case ESP_HF_DIAL_EVT: { if (param->out_call.num_or_loc) { - //dia_num_or_mem - ESP_LOGI(BT_HF_TAG, "--Dial \"%s\".", param->out_call.num_or_loc); - esp_hf_ag_out_call(hf_peer_addr,1,0,1,0,param->out_call.num_or_loc,0); + if (param->out_call.type == ESP_HF_DIAL_NUM) { + // dia_num + ESP_LOGI(BT_HF_TAG, "--Dial number \"%s\".", param->out_call.num_or_loc); + esp_hf_ag_out_call(hf_peer_addr,1,0,1,0,param->out_call.num_or_loc,0); + } else if (param->out_call.type == ESP_HF_DIAL_MEM) { + // dia_mem + ESP_LOGI(BT_HF_TAG, "--Dial memory \"%s\".", param->out_call.num_or_loc); + // AG found phone number by memory position + bool num_found = true; + if (num_found) { + char *number = "123456"; + esp_hf_ag_cmee_send(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_OK, ESP_HF_CME_AG_FAILURE); + esp_hf_ag_out_call(hf_peer_addr,1,0,1,0,number,0); + } else { + esp_hf_ag_cmee_send(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_CME, ESP_HF_CME_MEMORY_FAILURE); + } + } } else { //dia_last + //refer to dia_mem ESP_LOGI(BT_HF_TAG, "--Dial last number."); } break; From 0c4dc366958425cf23dd6f6ff7e8acd12f3aafae Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Mon, 21 Aug 2023 10:10:43 +0800 Subject: [PATCH 3/9] fix(bt/bluedroid): Fixed wrong code logic in 'AT+CIND?' of HFP --- .../bluedroid/api/include/api/esp_hf_ag_api.h | 13 -------- .../btc/profile/std/hf_ag/btc_hf_ag.c | 33 +------------------ 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h b/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h index 20b02215562..153ced24f00 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h @@ -116,19 +116,6 @@ typedef union char *unat; /*!< Unknown AT command string */ }unat_rep; /*!< AG callback param of ESP_HF_UNAT_RESPONSE_EVT */ - /** - * @brief ESP_HF_CIND_RESPONSE_EVT - */ - struct hf_cind_param { - esp_hf_call_status_t call_status; /*!< call status indicator */ - esp_hf_call_setup_status_t call_setup_status; /*!< call setup status indicator */ - esp_hf_network_state_t svc; /*!< bluetooth proprietary call hold status indicator */ - int signal_strength; /*!< bluetooth proprietary call hold status indicator */ - esp_hf_roaming_status_t roam; /*!< bluetooth proprietary call hold status indicator */ - int battery_level; /*!< battery charge value, ranges from 0 to 5 */ - esp_hf_call_held_status_t call_held_status; /*!< bluetooth proprietary call hold status indicator */ - } cind; /*!< AG callback param of ESP_HF_CIND_RESPONSE_EVT */ - /** * @brief ESP_HF_DIAL_EVT */ diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index ee74e28bce5..bc0efb6afef 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -214,37 +214,6 @@ static void send_indicator_update(UINT16 indicator, UINT16 value) BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_IND_RES, &ag_res); } -static void btc_hf_cind_evt(tBTA_AG_IND *ind) -{ - esp_hf_cb_param_t param; - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); - - switch (ind->type) { - case BTA_AG_IND_CALL: - param.cind.call_status = ind->value; - break; - case BTA_AG_IND_CALLSETUP: - param.cind.call_setup_status = ind->value; - break; - case BTA_AG_IND_SERVICE: - param.cind.svc = ind->value; - break; - case BTA_AG_IND_SIGNAL: - param.cind.signal_strength = ind->value; - break; - case BTA_AG_IND_ROAM: - param.cind.roam = ind->value; - break; - case BTA_AG_IND_BATTCHG: - param.cind.battery_level = ind->value; - break; - case BTA_AG_IND_CALLHELD: - param.cind.call_held_status = ind->value; - break; - } - btc_hf_cb_to_app(ESP_HF_CIND_RESPONSE_EVT, ¶m); -} - static void bte_hf_evt(tBTA_AG_EVT event, tBTA_AG *param) { int param_len = 0; @@ -1407,7 +1376,7 @@ void btc_hf_cb_handler(btc_msg_t *msg) case BTA_AG_AT_CIND_EVT: { - btc_hf_cind_evt(&p_data->ind); + btc_hf_cb_to_app(ESP_HF_CIND_RESPONSE_EVT, NULL); break; } From a93b6674c4935514cd8dde4ccd5486fcd1b0a21b Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 23 Aug 2023 14:51:26 +0800 Subject: [PATCH 4/9] fix(bt/bluedroid): Changed log level from WARNING to DEBUG in bta_ag_sco_read_cback --- components/bt/host/bluedroid/bta/hf_ag/bta_ag_sco.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_sco.c b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_sco.c index 16d43980537..50b60a224a6 100644 --- a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_sco.c +++ b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_sco.c @@ -342,7 +342,7 @@ static void bta_ag_sco_read_cback(UINT16 sco_inx, BT_HDR *p_data, tBTM_SCO_DATA_ { if (status != BTM_SCO_DATA_CORRECT) { - APPL_TRACE_WARNING("bta_ag_sco_read_cback: status(%d)", status); + APPL_TRACE_DEBUG("bta_ag_sco_read_cback: status(%d)", status); } /* Callout function must free the data. */ From 6d301d11bcef34b0ed4a42ed39f497763a28d805 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 23 Aug 2023 19:30:40 +0800 Subject: [PATCH 5/9] fix(bt/bluedroid): Added peer Bluetooth device address into HF callback parameters --- .../bluedroid/api/include/api/esp_hf_ag_api.h | 61 ++++++++++++++++++- .../btc/profile/std/hf_ag/btc_hf_ag.c | 50 +++++++++++---- .../classic_bt/hfp_ag/main/bt_app_hf.c | 24 ++++---- 3 files changed, 108 insertions(+), 27 deletions(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h b/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h index 153ced24f00..f997bff2749 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h @@ -105,6 +105,7 @@ typedef union * @brief ESP_HF_VOLUME_CONTROL_EVT */ struct hf_volume_control_param { + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ esp_hf_volume_type_t type; /*!< Volume control target, speaker or microphone */ int volume; /*!< Gain, ranges from 0 to 15 */ } volume_control; /*!< AG callback param of ESP_HF_VOLUME_CONTROL_EVT */ @@ -113,8 +114,9 @@ typedef union * @brief ESP_HF_UNAT_RESPONSE_EVT */ struct hf_unat_rep_param { + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ char *unat; /*!< Unknown AT command string */ - }unat_rep; /*!< AG callback param of ESP_HF_UNAT_RESPONSE_EVT */ + } unat_rep; /*!< AG callback param of ESP_HF_UNAT_RESPONSE_EVT */ /** * @brief ESP_HF_DIAL_EVT @@ -125,24 +127,76 @@ typedef union char *num_or_loc; /*!< location in phone memory */ } out_call; /*!< AG callback param of ESP_HF_DIAL_EVT */ + /** + * @brief ESP_HF_IND_UPDATE_EVT + */ + struct hf_ind_upd_param { + esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + } ind_upd; /*!< AG callback param of ESP_HF_IND_UPDATE_EVT */ + + /** + * @brief ESP_HF_CIND_RESPONSE_EVT + */ + struct hf_cind_rep_param { + esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + } cind_rep; /*!< AG callback param of ESP_HF_CIND_RESPONSE_EVT */ + + /** + * @brief ESP_HF_COPS_RESPONSE_EVT + */ + struct hf_cops_rep_param { + esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + } cops_rep; /*!< AG callback param of ESP_HF_COPS_RESPONSE_EVT */ + + /** + * @brief ESP_HF_CLCC_RESPONSE_EVT + */ + struct hf_clcc_rep_param { + esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + } clcc_rep; /*!< AG callback param of ESP_HF_CLCC_RESPONSE_EVT */ + + /** + * @brief ESP_HF_CNUM_RESPONSE_EVT + */ + struct hf_cnum_rep_param { + esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + } cnum_rep; /*!< AG callback param of ESP_HF_CNUM_RESPONSE_EVT */ + /** * @brief ESP_HF_VTS_RESPONSE_EVT */ struct hf_vts_rep_param { + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ char *code; /*!< MTF code from HF Client */ - }vts_rep; /*!< AG callback param of ESP_HF_VTS_RESPONSE_EVT */ + } vts_rep; /*!< AG callback param of ESP_HF_VTS_RESPONSE_EVT */ /** * @brief ESP_HF_NREC_RESPONSE_EVT */ struct hf_nrec_param { - esp_hf_nrec_t state; /*!< NREC enabled or disabled */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + esp_hf_nrec_t state; /*!< NREC enabled or disabled */ } nrec; /*!< AG callback param of ESP_HF_NREC_RESPONSE_EVT */ + /** + * @brief ESP_HF_ATA_RESPONSE_EVT + */ + struct hf_ata_rep_param { + esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + } ata_rep; /*!< AG callback param of ESP_HF_ATA_RESPONSE_EVT */ + + /** + * @brief ESP_HF_CHUP_RESPONSE_EVT + */ + struct hf_chup_rep_param { + esp_bd_addr_t remote_addr; /*!< remote bluetooth device address */ + } chup_rep; /*!< AG callback param of ESP_HF_CHUP_RESPONSE_EVT */ + /** * @brief ESP_HF_WBS_RESPONSE_EVT */ struct hf_wbs_rep_param { + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ esp_hf_wbs_config_t codec; /*!< codec mode CVSD or mSBC */ } wbs_rep; /*!< AG callback param of ESP_HF_WBS_RESPONSE_EVT */ @@ -150,6 +204,7 @@ typedef union * @brief ESP_HF_BCS_RESPONSE_EVT */ struct hf_bcs_rep_param { + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ esp_hf_wbs_config_t mode; /*!< codec mode CVSD or mSBC */ } bcs_rep; /*!< AG callback param of ESP_HF_BCS_RESPONSE_EVT */ diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index bc0efb6afef..71cefbad110 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -1351,8 +1351,11 @@ void btc_hf_cb_handler(btc_msg_t *msg) case BTA_AG_SPK_EVT: case BTA_AG_MIC_EVT: { + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); do { memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.volume_control.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.volume_control.type = (event == BTA_AG_SPK_EVT) ? ESP_HF_VOLUME_CONTROL_TARGET_SPK : ESP_HF_VOLUME_CONTROL_TARGET_MIC; param.volume_control.volume = p_data->val.num; btc_hf_cb_to_app(ESP_HF_VOLUME_CONTROL_EVT, ¶m); @@ -1362,9 +1365,14 @@ void btc_hf_cb_handler(btc_msg_t *msg) case BTA_AG_AT_UNAT_EVT: { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); - param.unat_rep.unat = p_data->val.str; - btc_hf_cb_to_app(ESP_HF_UNAT_RESPONSE_EVT, ¶m); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + do { + memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.unat_rep.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + param.unat_rep.unat = p_data->val.str; + btc_hf_cb_to_app(ESP_HF_UNAT_RESPONSE_EVT, ¶m); + } while (0); break; } @@ -1400,8 +1408,11 @@ void btc_hf_cb_handler(btc_msg_t *msg) case BTA_AG_AT_VTS_EVT: { + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); do { memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.vts_rep.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.vts_rep.code = p_data->val.str; btc_hf_cb_to_app(ESP_HF_VTS_RESPONSE_EVT, ¶m); } while(0); @@ -1410,8 +1421,11 @@ void btc_hf_cb_handler(btc_msg_t *msg) case BTA_AG_AT_NREC_EVT: { + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); do { memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.nrec.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.nrec.state = p_data->val.num; btc_hf_cb_to_app(ESP_HF_NREC_RESPONSE_EVT, ¶m); } while(0); @@ -1447,6 +1461,8 @@ void btc_hf_cb_handler(btc_msg_t *msg) osi_free(param.out_call.num_or_loc); } else if (event == BTA_AG_AT_BLDN_EVT) { //dial_last memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.out_call.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + param.out_call.num_or_loc = NULL; btc_hf_cb_to_app(ESP_HF_DIAL_EVT, ¶m); } } while(0); @@ -1489,20 +1505,30 @@ void btc_hf_cb_handler(btc_msg_t *msg) #if (BTM_WBS_INCLUDED == TRUE) case BTA_AG_WBS_EVT: { - BTC_TRACE_DEBUG("Set codec status %d codec %d 1=CVSD 2=MSBC", p_data->val.hdr.status, p_data->val.num); - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); - param.wbs_rep.codec = p_data->val.num; - btc_hf_cb_to_app(ESP_HF_WBS_RESPONSE_EVT, ¶m); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + do { + BTC_TRACE_DEBUG("Set codec status %d codec %d 1=CVSD 2=MSBC", p_data->val.hdr.status, p_data->val.num); + memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.wbs_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + param.wbs_rep.codec = p_data->val.num; + btc_hf_cb_to_app(ESP_HF_WBS_RESPONSE_EVT, ¶m); + } while (0); break; } case BTA_AG_AT_BCS_EVT: { - BTC_TRACE_DEBUG("AG final seleded codec is %d 1=CVSD 2=MSBC", p_data->val.num); - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); - param.bcs_rep.mode = p_data->val.num; - /* No ESP_HF_WBS_NONE case, becuase HFP 1.6 supported device can send BCS */ - btc_hf_cb_to_app(ESP_HF_BCS_RESPONSE_EVT, ¶m); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + do { + BTC_TRACE_DEBUG("AG final seleded codec is %d 1=CVSD 2=MSBC", p_data->val.num); + memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + memcpy(param.bcs_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + param.bcs_rep.mode = p_data->val.num; + /* No ESP_HF_WBS_NONE case, becuase HFP 1.6 supported device can send BCS */ + btc_hf_cb_to_app(ESP_HF_BCS_RESPONSE_EVT, ¶m); + } while (0); break; } #endif diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c index aadb5ad05a6..0478a5d38c6 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c @@ -348,7 +348,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) case ESP_HF_UNAT_RESPONSE_EVT: { ESP_LOGI(BT_HF_TAG, "--UNKOW AT CMD: %s", param->unat_rep.unat); - esp_hf_ag_unknown_at_send(hf_peer_addr, NULL); + esp_hf_ag_unknown_at_send(param->unat_rep.remote_bda, NULL); break; } @@ -359,7 +359,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) esp_hf_call_setup_status_t call_setup_state = 2; esp_hf_network_state_t ntk_state = 1; int signal = 2; - esp_hf_ag_devices_status_indchange(hf_peer_addr,call_state,call_setup_state,ntk_state,signal); + esp_hf_ag_devices_status_indchange(param->ind_upd.remote_addr,call_state,call_setup_state,ntk_state,signal); break; } @@ -373,14 +373,14 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) esp_hf_roaming_status_t roam = 0; int batt_lev = 3; esp_hf_call_held_status_t call_held_status = 0; - esp_hf_ag_cind_response(hf_peer_addr,call_status,call_setup_status,ntk_state,signal,roam,batt_lev,call_held_status); + esp_hf_ag_cind_response(param->cind_rep.remote_addr,call_status,call_setup_status,ntk_state,signal,roam,batt_lev,call_held_status); break; } case ESP_HF_COPS_RESPONSE_EVT: { const int svc_type = 1; - esp_hf_ag_cops_response(hf_peer_addr, c_operator_name_str[svc_type]); + esp_hf_ag_cops_response(param->cops_rep.remote_addr, c_operator_name_str[svc_type]); break; } @@ -397,7 +397,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) esp_hf_call_addr_type_t type = ESP_HF_CALL_ADDR_TYPE_UNKNOWN; ESP_LOGI(BT_HF_TAG, "--Calling Line Identification."); - esp_hf_ag_clcc_response(hf_peer_addr, index, dir, current_call_status, mode, mpty, number, type); + esp_hf_ag_clcc_response(param->clcc_rep.remote_addr, index, dir, current_call_status, mode, mpty, number, type); break; } @@ -406,7 +406,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) char *number = {"123456"}; esp_hf_subscriber_service_type_t type = 1; ESP_LOGI(BT_HF_TAG, "--Current Number is %s ,Type is %s.", number, c_subscriber_service_type_str[type]); - esp_hf_ag_cnum_response(hf_peer_addr, number,type); + esp_hf_ag_cnum_response(param->cnum_rep.remote_addr, number,type); break; } @@ -426,7 +426,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) { ESP_LOGI(BT_HF_TAG, "--Asnwer Incoming Call."); char *number = {"123456"}; - esp_hf_ag_answer_call(hf_peer_addr,1,0,1,0,number,0); + esp_hf_ag_answer_call(param->ata_rep.remote_addr,1,0,1,0,number,0); break; } @@ -434,7 +434,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) { ESP_LOGI(BT_HF_TAG, "--Reject Incoming Call."); char *number = {"123456"}; - esp_hf_ag_reject_call(hf_peer_addr,0,0,0,0,number,0); + esp_hf_ag_reject_call(param->chup_rep.remote_addr,0,0,0,0,number,0); break; } @@ -444,7 +444,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) if (param->out_call.type == ESP_HF_DIAL_NUM) { // dia_num ESP_LOGI(BT_HF_TAG, "--Dial number \"%s\".", param->out_call.num_or_loc); - esp_hf_ag_out_call(hf_peer_addr,1,0,1,0,param->out_call.num_or_loc,0); + esp_hf_ag_out_call(param->out_call.remote_addr,1,0,1,0,param->out_call.num_or_loc,0); } else if (param->out_call.type == ESP_HF_DIAL_MEM) { // dia_mem ESP_LOGI(BT_HF_TAG, "--Dial memory \"%s\".", param->out_call.num_or_loc); @@ -452,10 +452,10 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) bool num_found = true; if (num_found) { char *number = "123456"; - esp_hf_ag_cmee_send(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_OK, ESP_HF_CME_AG_FAILURE); - esp_hf_ag_out_call(hf_peer_addr,1,0,1,0,number,0); + esp_hf_ag_cmee_send(param->out_call.remote_addr, ESP_HF_AT_RESPONSE_CODE_OK, ESP_HF_CME_AG_FAILURE); + esp_hf_ag_out_call(param->out_call.remote_addr,1,0,1,0,number,0); } else { - esp_hf_ag_cmee_send(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_CME, ESP_HF_CME_MEMORY_FAILURE); + esp_hf_ag_cmee_send(param->out_call.remote_addr, ESP_HF_AT_RESPONSE_CODE_CME, ESP_HF_CME_MEMORY_FAILURE); } } } else { From fbb69daaaafa7a94877e37aeac52958f3faf109d Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 23 Aug 2023 20:07:42 +0800 Subject: [PATCH 6/9] fix(bt/bluedroid): Fixed wrong indexes of HF-AG indicators --- .../host/bluedroid/bta/include/bta/bta_ag_api.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_ag_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_ag_api.h index b407583485d..5fd908810e0 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_ag_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_ag_api.h @@ -261,15 +261,15 @@ typedef UINT8 tBTA_AG_BTRH_TYPE; #endif /* indicator constants HFP 1.1 and later */ -#define BTA_AG_IND_CALL 0 /* position of call indicator */ -#define BTA_AG_IND_CALLSETUP 1 /* position of callsetup indicator */ -#define BTA_AG_IND_SERVICE 2 /* position of service indicator */ +#define BTA_AG_IND_CALL 1 /* position of call indicator */ +#define BTA_AG_IND_CALLSETUP 2 /* position of callsetup indicator */ +#define BTA_AG_IND_SERVICE 3 /* position of service indicator */ /* indicator constants HFP 1.5 and later */ -#define BTA_AG_IND_SIGNAL 3 /* position of signal strength indicator */ -#define BTA_AG_IND_ROAM 4 /* position of roaming indicator */ -#define BTA_AG_IND_BATTCHG 5 /* position of battery charge indicator */ -#define BTA_AG_IND_CALLHELD 6 /* position of callheld indicator */ -#define BTA_AG_IND_BEARER 7 /* position of bearer indicator */ +#define BTA_AG_IND_SIGNAL 4 /* position of signal strength indicator */ +#define BTA_AG_IND_ROAM 5 /* position of roaming indicator */ +#define BTA_AG_IND_BATTCHG 6 /* position of battery charge indicator */ +#define BTA_AG_IND_CALLHELD 7 /* position of callheld indicator */ +#define BTA_AG_IND_BEARER 8 /* position of bearer indicator */ typedef UINT16 tBTA_AG_IND_TYPE; /* call indicator values */ From 2668df265e4e09a436a9bddd47c44d68e87bd5a5 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Thu, 24 Aug 2023 19:58:52 +0800 Subject: [PATCH 7/9] fix(bt/bluedroid): Fixed invalid access to freed semaphore --- .../bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c index 0478a5d38c6..392b1faf9d8 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c @@ -275,14 +275,14 @@ void bt_app_send_data_shut_down(void) vTaskDelete(s_bt_app_send_data_task_handler); s_bt_app_send_data_task_handler = NULL; } - if (s_send_data_Semaphore) { - vSemaphoreDelete(s_send_data_Semaphore); - s_send_data_Semaphore = NULL; - } if(s_periodic_timer) { ESP_ERROR_CHECK(esp_timer_stop(s_periodic_timer)); ESP_ERROR_CHECK(esp_timer_delete(s_periodic_timer)); } + if (s_send_data_Semaphore) { + vSemaphoreDelete(s_send_data_Semaphore); + s_send_data_Semaphore = NULL; + } if (s_m_rb) { vRingbufferDelete(s_m_rb); } From 0a03f7e03a1b28d226b58cb552462f95f0062bb6 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Fri, 25 Aug 2023 14:00:56 +0800 Subject: [PATCH 8/9] docs(bt/bluedroid): Changed the description of esp_hf_client_reject_call --- .../bt/host/bluedroid/api/include/api/esp_hf_client_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_hf_client_api.h b/components/bt/host/bluedroid/api/include/api/esp_hf_client_api.h index 449941fba74..2a259e95b62 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_hf_client_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_hf_client_api.h @@ -508,7 +508,7 @@ esp_err_t esp_hf_client_answer_call(void); /** * - * @brief Reject an incoming call(send AT+CHUP command). + * @brief Reject an incoming call or terminate an ongoing call(send AT+CHUP command). * As a precondition to use this API, Service Level Connection shall exist with AG. * * @return From cde05ef49552e1c5172d818e068b627c2cbf32bd Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Thu, 31 Aug 2023 19:44:37 +0800 Subject: [PATCH 9/9] fix(bt/bluedroid): Deleted the redundant 'memset' in btc_hf_cb_handler --- .../bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index 71cefbad110..5e7a2a61788 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -1194,6 +1194,8 @@ void btc_hf_cb_handler(btc_msg_t *msg) BTC_TRACE_DEBUG("%s: event = %s", __FUNCTION__, dump_hf_event(event)); + memset(¶m, 0, sizeof(esp_hf_cb_param_t)); + switch (event) { case BTA_AG_ENABLE_EVT: case BTA_AG_DISABLE_EVT: @@ -1230,7 +1232,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) } do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.conn_stat.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda, sizeof(esp_bd_addr_t)); param.conn_stat.state = hf_local_param[idx].btc_hf_cb.connection_state; param.conn_stat.peer_feat = 0; @@ -1257,7 +1258,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) hf_local_param[idx].btc_hf_cb.connection_state = ESP_HF_CONNECTION_STATE_SLC_CONNECTED; do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); param.conn_stat.state = hf_local_param[idx].btc_hf_cb.connection_state; param.conn_stat.peer_feat = hf_local_param[idx].btc_hf_cb.peer_feat; param.conn_stat.chld_feat = hf_local_param[idx].btc_hf_cb.chld_feat; @@ -1278,7 +1278,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) BTC_TRACE_DEBUG("%s: BTA_AG_CLOSE_EVT," "hf_local_param[%d].btc_hf_cb.handle = %d", __FUNCTION__, idx, hf_local_param[idx].btc_hf_cb.handle); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); param.conn_stat.state = ESP_HF_CONNECTION_STATE_DISCONNECTED; param.conn_stat.peer_feat = 0; param.conn_stat.chld_feat = 0; @@ -1297,7 +1296,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); param.audio_stat.state = ESP_HF_AUDIO_STATE_CONNECTED; memcpy(param.audio_stat.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); btc_hf_cb_to_app(ESP_HF_AUDIO_STATE_EVT, ¶m); @@ -1310,7 +1308,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); param.audio_stat.state = ESP_HF_AUDIO_STATE_CONNECTED_MSBC; memcpy(param.audio_stat.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); btc_hf_cb_to_app(ESP_HF_AUDIO_STATE_EVT, ¶m); @@ -1322,7 +1319,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); param.audio_stat.state = ESP_HF_AUDIO_STATE_DISCONNECTED; memcpy(param.audio_stat.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_cb_to_app(ESP_HF_AUDIO_STATE_EVT, ¶m); @@ -1335,7 +1331,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); param.vra_rep.value = p_data->val.num; memcpy(param.vra_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); btc_hf_cb_to_app(ESP_HF_BVRA_RESPONSE_EVT, ¶m); @@ -1354,7 +1349,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.volume_control.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.volume_control.type = (event == BTA_AG_SPK_EVT) ? ESP_HF_VOLUME_CONTROL_TARGET_SPK : ESP_HF_VOLUME_CONTROL_TARGET_MIC; param.volume_control.volume = p_data->val.num; @@ -1368,7 +1362,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.unat_rep.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.unat_rep.unat = p_data->val.str; btc_hf_cb_to_app(ESP_HF_UNAT_RESPONSE_EVT, ¶m); @@ -1411,7 +1404,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.vts_rep.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.vts_rep.code = p_data->val.str; btc_hf_cb_to_app(ESP_HF_VTS_RESPONSE_EVT, ¶m); @@ -1424,7 +1416,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) idx = p_data->hdr.handle - 1; CHECK_HF_IDX(idx); do { - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.nrec.remote_bda, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.nrec.state = p_data->val.num; btc_hf_cb_to_app(ESP_HF_NREC_RESPONSE_EVT, ¶m); @@ -1451,7 +1442,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) CHECK_HF_IDX(idx); do { if (event == BTA_AG_AT_D_EVT) { // dial_number_or_memory - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.out_call.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.out_call.type = p_data->val.value; param.out_call.num_or_loc = osi_malloc((strlen(p_data->val.str) + 1) * sizeof(char)); @@ -1460,7 +1450,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) send_indicator_update(BTA_AG_IND_CALLSETUP,BTA_AG_CALLSETUP_OUTGOING); osi_free(param.out_call.num_or_loc); } else if (event == BTA_AG_AT_BLDN_EVT) { //dial_last - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.out_call.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.out_call.num_or_loc = NULL; btc_hf_cb_to_app(ESP_HF_DIAL_EVT, ¶m); @@ -1509,7 +1498,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) CHECK_HF_IDX(idx); do { BTC_TRACE_DEBUG("Set codec status %d codec %d 1=CVSD 2=MSBC", p_data->val.hdr.status, p_data->val.num); - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.wbs_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.wbs_rep.codec = p_data->val.num; btc_hf_cb_to_app(ESP_HF_WBS_RESPONSE_EVT, ¶m); @@ -1523,7 +1511,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) CHECK_HF_IDX(idx); do { BTC_TRACE_DEBUG("AG final seleded codec is %d 1=CVSD 2=MSBC", p_data->val.num); - memset(¶m, 0, sizeof(esp_hf_cb_param_t)); memcpy(param.bcs_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); param.bcs_rep.mode = p_data->val.num; /* No ESP_HF_WBS_NONE case, becuase HFP 1.6 supported device can send BCS */