From 71ec923e552063600675ac96704e15605cee2d89 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 23 Aug 2023 19:30:40 +0800 Subject: [PATCH] fix(bt/bluedroid): Added peer Bluetooth device address into HF callback parameters --- .../bluedroid/api/include/api/esp_hf_ag_api.h | 65 ++++++++++++-- .../btc/profile/std/hf_ag/btc_hf_ag.c | 87 ++++++++++++++----- .../classic_bt/hfp_ag/main/bt_app_hf.c | 24 ++--- 3 files changed, 137 insertions(+), 39 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 153ced24f0..0851f36f20 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 @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -76,7 +76,7 @@ typedef enum typedef union { /** - * @brief ESP_HS_CONNECTION_STATE_EVT + * @brief ESP_HF_CONNECTION_STATE_EVT */ struct hf_conn_stat_param { esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ @@ -105,6 +105,7 @@ typedef union * @brief ESP_HF_VOLUME_CONTROL_EVT */ struct hf_volume_control_param { + esp_bd_addr_t remote_addr; /*!< 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_addr; /*!< 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_addr; /*!< 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_addr; /*!< 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_addr; /*!< 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_addr; /*!< 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 bc0efb6afe..ef99c2b5b2 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,10 @@ 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_addr, &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,46 +1364,67 @@ 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 { + memcpy(param.unat_rep.remote_addr, &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; } case BTA_AG_AT_CBC_EVT: { - btc_hf_cb_to_app(ESP_HF_IND_UPDATE_EVT, NULL); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + memcpy(param.ind_upd.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + btc_hf_cb_to_app(ESP_HF_IND_UPDATE_EVT, ¶m); break; } case BTA_AG_AT_CIND_EVT: { - btc_hf_cb_to_app(ESP_HF_CIND_RESPONSE_EVT, NULL); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + memcpy(param.cind_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + btc_hf_cb_to_app(ESP_HF_CIND_RESPONSE_EVT, ¶m); break; } case BTA_AG_AT_COPS_EVT: { - btc_hf_cb_to_app(ESP_HF_COPS_RESPONSE_EVT, NULL); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + memcpy(param.cops_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + btc_hf_cb_to_app(ESP_HF_COPS_RESPONSE_EVT, ¶m); break; } case BTA_AG_AT_CLCC_EVT: { - btc_hf_cb_to_app(ESP_HF_CLCC_RESPONSE_EVT, NULL); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + memcpy(param.clcc_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + btc_hf_cb_to_app(ESP_HF_CLCC_RESPONSE_EVT, ¶m); break; } case BTA_AG_AT_CNUM_EVT: { - btc_hf_cb_to_app(ESP_HF_CNUM_RESPONSE_EVT, NULL); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + memcpy(param.cnum_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + btc_hf_cb_to_app(ESP_HF_CNUM_RESPONSE_EVT, ¶m); break; } 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_addr, &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 +1433,10 @@ 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_addr, &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); @@ -1420,13 +1445,19 @@ void btc_hf_cb_handler(btc_msg_t *msg) case BTA_AG_AT_A_EVT: { - btc_hf_cb_to_app(ESP_HF_ATA_RESPONSE_EVT, NULL); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + memcpy(param.ata_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + btc_hf_cb_to_app(ESP_HF_ATA_RESPONSE_EVT, ¶m); break; } case BTA_AG_AT_CHUP_EVT: { - btc_hf_cb_to_app(ESP_HF_CHUP_RESPONSE_EVT, NULL); + idx = p_data->hdr.handle - 1; + CHECK_HF_IDX(idx); + memcpy(param.chup_rep.remote_addr, &hf_local_param[idx].btc_hf_cb.connected_bda,sizeof(esp_bd_addr_t)); + btc_hf_cb_to_app(ESP_HF_CHUP_RESPONSE_EVT, ¶m); break; } @@ -1447,6 +1478,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 +1522,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 f0ea99165e..4c2f024b17 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_addr, 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 {