From 0d75f97bf2dc43df922306bb10ad8acb8275e162 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Fri, 18 Aug 2023 15:08:30 +0800 Subject: [PATCH 01/11] 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 62f2d30b2e..f4c46e5bc5 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 @@ -1356,6 +1356,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); @@ -1451,9 +1452,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 && p_data->val.str) { // 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, p_data->val.str); btc_hf_cb_to_app(ESP_HF_DIAL_EVT, ¶m); From dec7165a8f034ddde380273d8f16ee217438e690 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Mon, 21 Aug 2023 10:06:49 +0800 Subject: [PATCH 02/11] 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 8637d74a31..3ac218c6a2 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 @@ -72,6 +72,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 { @@ -134,6 +142,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 24ef3656b7..8aef6d8505 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 f4c46e5bc5..1701415c98 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 @@ -1458,6 +1458,7 @@ void btc_hf_cb_handler(btc_msg_t *msg) if (event == BTA_AG_AT_D_EVT && p_data->val.str) { // 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, 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 11fa79a574..76bedeae47 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 @@ -442,11 +442,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_bt_hf_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_bt_hf_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_bt_hf_cmee_response(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_OK, ESP_HF_CME_AG_FAILURE); + esp_bt_hf_out_call(hf_peer_addr,1,0,1,0,number,0); + } else { + esp_bt_hf_cmee_response(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_CME, ESP_HF_CME_MEMEORY_FAILURE); + } + } } else { //dia_last + //refer to dia_mem ESP_LOGI(BT_HF_TAG, "--Dial last number."); } break; From 37b8bc13d5d22c865ba1dc1b9911aba762e5ff43 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Mon, 21 Aug 2023 10:10:43 +0800 Subject: [PATCH 03/11] 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 3ac218c6a2..a6523fcc66 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 @@ -124,19 +124,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 1701415c98..9d3976d0e0 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 @@ -193,37 +193,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; @@ -1395,7 +1364,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 6ae76b7b69d1b468f087a44b322be4488df2cc26 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 23 Aug 2023 14:51:26 +0800 Subject: [PATCH 04/11] 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 16d4398053..50b60a224a 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 820e3263fb3663b92cb815cd39664bdc1e28f03f Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 23 Aug 2023 19:30:40 +0800 Subject: [PATCH 05/11] fix(bt/bluedroid): Added peer Bluetooth device address into HF callback parameters --- .../bluedroid/api/include/api/esp_hf_ag_api.h | 83 ++++++++++++++---- .../btc/profile/std/hf_ag/btc_hf_ag.c | 87 ++++++++++++++----- .../classic_bt/hfp_ag/main/bt_app_hf.c | 24 ++--- 3 files changed, 142 insertions(+), 52 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 a6523fcc66..8de29267fe 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,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef __ESP_HF_AG_API_H__ #define __ESP_HF_AG_API_H__ @@ -84,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 */ @@ -113,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 */ @@ -121,8 +114,9 @@ typedef union * @brief ESP_HF_UNAT_RESPOSNE_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 @@ -134,23 +128,75 @@ typedef union } out_call; /*!< AG callback param of ESP_HF_DIAL_EVT */ /** - * @brief ESP_HF_VTS_RESPOSNE_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_RESPOSNE_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 */ @@ -158,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 9d3976d0e0..ae285bd6f7 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 @@ -1339,8 +1339,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); @@ -1350,46 +1352,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); @@ -1398,8 +1421,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); @@ -1408,13 +1433,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; } @@ -1435,6 +1466,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); @@ -1477,20 +1510,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 76bedeae47..e2064bdd4c 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 @@ -349,7 +349,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_unat_response(hf_peer_addr, NULL); + esp_hf_unat_response(param->unat_rep.remote_addr, NULL); break; } @@ -360,7 +360,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_bt_hf_indchange_notification(hf_peer_addr,call_state,call_setup_state,ntk_state,signal); + esp_bt_hf_indchange_notification(param->ind_upd.remote_addr,call_state,call_setup_state,ntk_state,signal); break; } @@ -374,14 +374,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_bt_hf_cind_response(hf_peer_addr,call_status,call_setup_status,ntk_state,signal,roam,batt_lev,call_held_status); + esp_bt_hf_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_bt_hf_cops_response(hf_peer_addr, c_operator_name_str[svc_type]); + esp_bt_hf_cops_response(param->cops_rep.remote_addr, c_operator_name_str[svc_type]); break; } @@ -398,7 +398,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_bt_hf_clcc_response(hf_peer_addr, index, dir, current_call_status, mode, mpty, number, type); + esp_bt_hf_clcc_response(param->clcc_rep.remote_addr, index, dir, current_call_status, mode, mpty, number, type); break; } @@ -407,7 +407,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_bt_hf_cnum_response(hf_peer_addr, number,type); + esp_bt_hf_cnum_response(param->cnum_rep.remote_addr, number,type); break; } @@ -427,7 +427,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_bt_hf_answer_call(hf_peer_addr,1,0,1,0,number,0); + esp_bt_hf_answer_call(param->ata_rep.remote_addr,1,0,1,0,number,0); break; } @@ -435,7 +435,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_bt_hf_reject_call(hf_peer_addr,0,0,0,0,number,0); + esp_bt_hf_reject_call(param->chup_rep.remote_addr,0,0,0,0,number,0); break; } @@ -445,7 +445,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_bt_hf_out_call(hf_peer_addr,1,0,1,0,param->out_call.num_or_loc,0); + esp_bt_hf_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); @@ -453,10 +453,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_bt_hf_cmee_response(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_OK, ESP_HF_CME_AG_FAILURE); - esp_bt_hf_out_call(hf_peer_addr,1,0,1,0,number,0); + esp_bt_hf_cmee_response(param->out_call.remote_addr, ESP_HF_AT_RESPONSE_CODE_OK, ESP_HF_CME_AG_FAILURE); + esp_bt_hf_out_call(param->out_call.remote_addr,1,0,1,0,number,0); } else { - esp_bt_hf_cmee_response(hf_peer_addr, ESP_HF_AT_RESPONSE_CODE_CME, ESP_HF_CME_MEMEORY_FAILURE); + esp_bt_hf_cmee_response(param->out_call.remote_addr, ESP_HF_AT_RESPONSE_CODE_CME, ESP_HF_CME_MEMEORY_FAILURE); } } } else { From a0c505d128ac8d5a6ba5a1b2b7545f23c553f82b Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 23 Aug 2023 20:07:42 +0800 Subject: [PATCH 06/11] 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 b407583485..5fd908810e 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 e4f65d9629f18ae485a9f2c7757f55c56998c962 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Thu, 24 Aug 2023 19:58:52 +0800 Subject: [PATCH 07/11] 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 e2064bdd4c..c29a326de4 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 @@ -276,14 +276,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 812f919706ef81807d552605f736fa7950fcd7e4 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Fri, 25 Aug 2023 14:00:56 +0800 Subject: [PATCH 08/11] 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 55569bc5c8..157895647e 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 670e8f9049d9d94aa732bec337262bea52734431 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Thu, 31 Aug 2023 19:44:37 +0800 Subject: [PATCH 09/11] fix(bt/bluedroid): Deleted the redundant 'memset' in btc_hf_cb_handler --- .../bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 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 ae285bd6f7..96a5625835 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 @@ -1182,6 +1182,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: @@ -1218,7 +1220,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; @@ -1245,7 +1246,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; @@ -1266,7 +1266,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; @@ -1285,7 +1284,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); @@ -1298,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_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); @@ -1310,7 +1307,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); @@ -1323,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.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); @@ -1456,7 +1451,6 @@ void btc_hf_cb_handler(btc_msg_t *msg) CHECK_HF_IDX(idx); do { if (event == BTA_AG_AT_D_EVT && p_data->val.str) { // 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)); @@ -1465,7 +1459,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); @@ -1514,7 +1507,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); @@ -1528,7 +1520,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 */ From 79493578f2d85af32ef3658f097822ee2f80559b Mon Sep 17 00:00:00 2001 From: chenqingqing Date: Fri, 18 Aug 2023 14:31:16 +0800 Subject: [PATCH 10/11] feat(bt/api): Add new apis for hfp to get the numbers of packet status received and sent --- .../bt/host/bluedroid/api/esp_hf_ag_api.c | 40 ++++++---- .../bt/host/bluedroid/api/esp_hf_client_api.c | 41 ++++++---- .../bluedroid/api/include/api/esp_hf_ag_api.h | 31 ++++++++ .../api/include/api/esp_hf_client_api.h | 49 +++++++++--- .../bt/host/bluedroid/bta/hf_ag/bta_ag_api.c | 28 ++++++- .../bt/host/bluedroid/bta/hf_ag/bta_ag_main.c | 18 +++-- .../bt/host/bluedroid/bta/hf_ag/bta_ag_sco.c | 27 +++++++ .../bluedroid/bta/hf_ag/include/bta_ag_int.h | 12 ++- .../bta/hf_client/bta_hf_client_api.c | 23 +++++- .../bta/hf_client/bta_hf_client_main.c | 11 ++- .../bta/hf_client/bta_hf_client_sco.c | 26 +++++- .../bta/hf_client/include/bta_hf_client_int.h | 9 +++ .../bluedroid/bta/include/bta/bta_ag_api.h | 27 +++++++ .../bta/include/bta/bta_hf_client_api.h | 26 ++++++ .../btc/profile/std/hf_ag/btc_hf_ag.c | 33 +++++++- .../btc/profile/std/hf_client/btc_hf_client.c | 69 ++++++++-------- .../btc/profile/std/include/btc_hf_ag.h | 26 +++--- .../btc/profile/std/include/btc_hf_client.h | 25 +++--- .../bt/host/bluedroid/stack/btm/btm_sco.c | 79 +++++++++++++++++++ .../bluedroid/stack/btm/include/btm_int.h | 1 + .../bluedroid/stack/include/stack/btm_api.h | 22 ++++++ .../classic_bt/hfp_ag/main/bt_app_hf.c | 20 +++-- .../classic_bt/hfp_hf/main/bt_app_hf.c | 19 +++-- 23 files changed, 530 insertions(+), 132 deletions(-) diff --git a/components/bt/host/bluedroid/api/esp_hf_ag_api.c b/components/bt/host/bluedroid/api/esp_hf_ag_api.c index f0661c02b3..56dee5f80e 100644 --- a/components/bt/host/bluedroid/api/esp_hf_ag_api.c +++ b/components/bt/host/bluedroid/api/esp_hf_ag_api.c @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -528,10 +520,30 @@ esp_err_t esp_bt_hf_register_data_callback(esp_hf_incoming_data_cb_t recv, esp_h } #if (BTM_SCO_HCI_INCLUDED == TRUE) +esp_err_t esp_hf_ag_pkt_stat_nums_get(uint16_t sync_conn_handle) +{ + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + btc_msg_t msg; + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_HF; + msg.act = BTC_HF_REQUEST_PKT_STAT_EVT; + + btc_hf_args_t arg; + memset(&arg, 0, sizeof(btc_hf_args_t)); + arg.pkt_sync_hd.sync_conn_handle = sync_conn_handle; + + /* Switch to BTC context */ + bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL, NULL); + return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL; +} + void esp_hf_outgoing_data_ready(void) { btc_hf_ci_sco_data(); } -#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) */ +#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE) */ #endif // BTC_HF_INCLUDED diff --git a/components/bt/host/bluedroid/api/esp_hf_client_api.c b/components/bt/host/bluedroid/api/esp_hf_client_api.c index f7feaefa25..37acb43080 100644 --- a/components/bt/host/bluedroid/api/esp_hf_client_api.c +++ b/components/bt/host/bluedroid/api/esp_hf_client_api.c @@ -1,16 +1,8 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "common/bt_target.h" #include @@ -470,8 +462,27 @@ esp_err_t esp_hf_client_register_data_callback(esp_hf_client_incoming_data_cb_t return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL; } +#if (BTM_SCO_HCI_INCLUDED == TRUE) +esp_err_t esp_hf_client_pkt_stat_nums_get(uint16_t sync_conn_handle) +{ + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + btc_msg_t msg; + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_HF_CLIENT; + msg.act = BTC_HF_CLIENT_REQUEST_PKT_STAT_EVT; + + btc_hf_client_args_t arg; + memset(&arg, 0, sizeof(btc_hf_client_args_t)); + arg.pkt_sync_hd.sync_conn_handle = sync_conn_handle; + + /* Switch to BTC context */ + bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hf_client_args_t), NULL, NULL); + return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL; +} -#if (BTM_SCO_HCI_INCLUDED == TRUE ) void esp_hf_client_outgoing_data_ready(void) { BTA_HfClientCiData(); @@ -492,6 +503,6 @@ int32_t esp_hf_client_pcm_resample(void *src, uint32_t in_bytes, void *dst) return BTA_DmPcmResample(src, in_bytes, dst); } -#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) */ +#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE) */ #endif /* BTC_HF_CLIENT_INCLUDED */ 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 8de29267fe..c768f29b78 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 @@ -62,6 +62,7 @@ typedef enum ESP_HF_DIAL_EVT, /*!< Origin an outgoing call with specific number or the dial the last number */ ESP_HF_WBS_RESPONSE_EVT, /*!< Codec Status */ ESP_HF_BCS_RESPONSE_EVT, /*!< Final Codec Choice */ + ESP_HF_PKT_STAT_NUMS_GET_EVT, /*!< Request number of packet different status */ } esp_hf_cb_event_t; /// Dial type of ESP_HF_DIAL_EVT @@ -91,6 +92,7 @@ typedef union struct hf_audio_stat_param { esp_bd_addr_t remote_addr; /*!< Remote bluetooth device address */ esp_hf_audio_state_t state; /*!< Audio connection state */ + uint16_t sync_conn_handle; /*!< (e)SCO connection handle */ } audio_stat; /*!< AG callback param of ESP_HF_AUDIO_STATE_EVT */ /** @@ -208,6 +210,19 @@ typedef union esp_hf_wbs_config_t mode; /*!< codec mode CVSD or mSBC */ } bcs_rep; /*!< AG callback param of ESP_HF_BCS_RESPONSE_EVT */ + /** + * @brief ESP_HF_PKT_STAT_NUMS_GET_EVT + */ + struct ag_pkt_status_nums { + uint32_t rx_total; /*!< the total number of packets received */ + uint32_t rx_correct; /*!< the total number of packets data correctly received */ + uint32_t rx_err; /*!< the total number of packets data with possible invalid */ + uint32_t rx_none; /*!< the total number of packets data no received */ + uint32_t rx_lost; /*!< the total number of packets data partially lost */ + uint32_t tx_total; /*!< the total number of packets send */ + uint32_t tx_discarded; /*!< the total number of packets send lost */ + } pkt_nums; /*!< AG callback param of ESP_HF_PKT_STAT_NUMS_GET_EVT */ + } esp_hf_cb_param_t; /*!< HFP AG callback param compound*/ /** @@ -641,6 +656,22 @@ esp_err_t esp_bt_hf_end_call(esp_bd_addr_t remote_addr, int num_active, int num_ */ esp_err_t esp_bt_hf_register_data_callback(esp_hf_incoming_data_cb_t recv, esp_hf_outgoing_data_cb_t send); +/** + * + * @brief Get the number of packets received and sent + * + * This function is only used in the case that Voice Over HCI is enabled and the audio state is connected. + * When the operation is completed, the callback function will be called with ESP_HF_PKT_STAT_NUMS_GET_EVT. + * + * @param[in] sync_conn_handle: the (e)SCO connection handle + * + * @return + * - ESP_OK: if the request is sent successfully + * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled + * - ESP_FAIL: others + * + */ +esp_err_t esp_hf_ag_pkt_stat_nums_get(uint16_t sync_conn_handle); /** * @brief Trigger the lower-layer to fetch and send audio data. 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 157895647e..3ef9262b9d 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 @@ -1,16 +1,8 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef __ESP_HF_CLIENT_API_H__ #define __ESP_HF_CLIENT_API_H__ @@ -96,6 +88,7 @@ typedef enum { ESP_HF_CLIENT_BSIR_EVT, /*!< setting of in-band ring tone */ ESP_HF_CLIENT_BINP_EVT, /*!< requested number of last voice tag from AG */ ESP_HF_CLIENT_RING_IND_EVT, /*!< ring indication event */ + ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT, /*!< requested number of packet different status */ } esp_hf_client_cb_event_t; /// HFP client callback parameters @@ -116,6 +109,7 @@ typedef union { struct hf_client_audio_stat_param { esp_hf_client_audio_state_t state; /*!< audio connection state */ esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */ + uint16_t sync_conn_handle; /*!< (e)SCO connection handle */ } audio_stat; /*!< HF callback param of ESP_HF_CLIENT_AUDIO_STATE_EVT */ /** @@ -251,6 +245,19 @@ typedef union { const char *number; /*!< phone number corresponding to the last voice tag in the HF */ } binp; /*!< HF callback param of ESP_HF_CLIENT_BINP_EVT */ + /** + * @brief ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT + */ + struct hf_client_pkt_status_nums { + uint32_t rx_total; /*!< the total number of packets received */ + uint32_t rx_correct; /*!< the total number of packets data correctly received */ + uint32_t rx_err; /*!< the total number of packets data with possible invalid */ + uint32_t rx_none; /*!< the total number of packets data no received */ + uint32_t rx_lost; /*!< the total number of packets data partially lost */ + uint32_t tx_total; /*!< the total number of packets send */ + uint32_t tx_discarded; /*!< the total number of packets send lost */ + } pkt_nums; /*!< HF callback param of ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT */ + } esp_hf_client_cb_param_t; /*!< HFP client callback parameters */ /** @@ -617,6 +624,22 @@ esp_err_t esp_hf_client_send_nrec(void); esp_err_t esp_hf_client_register_data_callback(esp_hf_client_incoming_data_cb_t recv, esp_hf_client_outgoing_data_cb_t send); +/** + * + * @brief Get the number of packets received and sent + * This function is only used in the case that Voice Over HCI is enabled and the audio state is connected. + * When the operation is completed, the callback function will be called with ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT. + * + * @param[in] sync_conn_handle: the (e)SCO connection handle + * + * @return + * - ESP_OK: if the request is sent successfully + * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled + * - ESP_FAIL: others + * + */ +esp_err_t esp_hf_client_pkt_stat_nums_get(uint16_t sync_conn_handle); + /** * @brief Trigger the lower-layer to fetch and send audio data. * This function is only only used in the case that Voice Over HCI is enabled. After this diff --git a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_api.c b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_api.c index 465192802e..ca0dfa8b81 100644 --- a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_api.c +++ b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_api.c @@ -245,7 +245,6 @@ void BTA_AgAudioClose(UINT16 handle) } } - /******************************************************************************* ** ** Function BTA_AgResult @@ -297,7 +296,30 @@ void BTA_AgSetCodec(UINT16 handle, tBTA_AG_PEER_CODEC codec) } } -#if (BTM_SCO_HCI_INCLUDED == TRUE ) +#if (BTM_SCO_HCI_INCLUDED == TRUE) +/******************************************************************************* +** +** Function BTA_AgPktStatsNumsGet +** +** Description Specify the sync_conn_handle to be used for the packet numbers +** received or send. +** +** +** Returns void +** +*******************************************************************************/ +void BTA_AgPktStatsNumsGet(UINT16 handle, UINT16 sync_conn_handle) +{ + tBTA_AG_PKT_STAT_GET *p_buf; + + if ((p_buf = (tBTA_AG_PKT_STAT_GET *) osi_malloc(sizeof(tBTA_AG_PKT_STAT_GET))) != NULL) { + p_buf->hdr.event = BTA_AG_PKT_STAT_NUMS_GET_EVT; + p_buf->hdr.layer_specific = handle; + p_buf->sync_conn_handle = sync_conn_handle; + bta_sys_sendmsg(p_buf); + } +} + /************************************************************************************************ * Function BTA_AgCiData * @@ -317,6 +339,6 @@ void BTA_AgCiData(UINT16 handle) bta_sys_sendmsg(p_buf); } } -#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) */ +#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE) */ #endif /* #if (BTA_AG_INCLUDED == TRUE)*/ diff --git a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_main.c b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_main.c index f8554d0077..bcbe5b7425 100644 --- a/components/bt/host/bluedroid/bta/hf_ag/bta_ag_main.c +++ b/components/bt/host/bluedroid/bta/hf_ag/bta_ag_main.c @@ -91,6 +91,7 @@ enum BTA_AG_CI_SCO_DATA, BTA_AG_CI_RX_DATA, BTA_AG_RCVD_SLC_READY, + BTA_AG_PKT_STAT_NUMS, BTA_AG_NUM_ACTIONS }; @@ -133,7 +134,8 @@ const tBTA_AG_ACTION bta_ag_action[] = bta_ag_send_ring, bta_ag_ci_sco_data, bta_ag_ci_rx_data, - bta_ag_rcvd_slc_ready + bta_ag_rcvd_slc_ready, + bta_ag_pkt_stat_nums }; /* state table information */ @@ -167,7 +169,8 @@ const UINT8 bta_ag_st_init[][BTA_AG_NUM_COLS] = /* RING_TOUT_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_INIT_ST}, /* SVC_TOUT_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_INIT_ST}, /* CI_SCO_DATA_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_INIT_ST}, -/* CI_SLC_READY_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_INIT_ST} +/* CI_SLC_READY_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_INIT_ST}, +/* PKT_STAT_NUMS_GET_EVT */ {BTA_AG_PKT_STAT_NUMS, BTA_AG_IGNORE, BTA_AG_INIT_ST} }; /* state table for opening state */ @@ -196,7 +199,8 @@ const UINT8 bta_ag_st_opening[][BTA_AG_NUM_COLS] = /* RING_TOUT_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_OPENING_ST}, /* SVC_TOUT_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_OPENING_ST}, /* CI_SCO_DATA_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_OPENING_ST}, -/* CI_SLC_READY_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_OPENING_ST} +/* CI_SLC_READY_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_OPENING_ST}, +/* PKT_STAT_NUMS_GET_EVT */ {BTA_AG_PKT_STAT_NUMS, BTA_AG_IGNORE, BTA_AG_OPENING_ST} }; /* state table for open state */ @@ -225,7 +229,8 @@ const UINT8 bta_ag_st_open[][BTA_AG_NUM_COLS] = /* RING_TOUT_EVT */ {BTA_AG_SEND_RING, BTA_AG_IGNORE, BTA_AG_OPEN_ST}, /* SVC_TOUT_EVT */ {BTA_AG_START_CLOSE, BTA_AG_IGNORE, BTA_AG_CLOSING_ST}, /* CI_SCO_DATA_EVT */ {BTA_AG_CI_SCO_DATA, BTA_AG_IGNORE, BTA_AG_OPEN_ST}, -/* CI_SLC_READY_EVT */ {BTA_AG_RCVD_SLC_READY, BTA_AG_IGNORE, BTA_AG_OPEN_ST} +/* CI_SLC_READY_EVT */ {BTA_AG_RCVD_SLC_READY, BTA_AG_IGNORE, BTA_AG_OPEN_ST}, +/* PKT_STAT_NUMS_GET_EVT */ {BTA_AG_PKT_STAT_NUMS, BTA_AG_IGNORE, BTA_AG_OPEN_ST} }; /* state table for closing state */ @@ -254,7 +259,8 @@ const UINT8 bta_ag_st_closing[][BTA_AG_NUM_COLS] = /* RING_TOUT_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_CLOSING_ST}, /* SVC_TOUT_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_CLOSING_ST}, /* CI_SCO_DATA_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_CLOSING_ST}, -/* CI_SLC_READY_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_CLOSING_ST} +/* CI_SLC_READY_EVT */ {BTA_AG_IGNORE, BTA_AG_IGNORE, BTA_AG_CLOSING_ST}, +/* PKT_STAT_NUMS_GET_EVT */ {BTA_AG_PKT_STAT_NUMS, BTA_AG_IGNORE, BTA_AG_CLOSING_ST} }; /* type for state table */ @@ -357,6 +363,8 @@ static char *bta_ag_evt_str(UINT16 event, tBTA_AG_RES result) return "SCO data Callin"; case BTA_AG_CI_SLC_READY_EVT: return "SLC Ready Callin"; + case BTA_AG_PKT_STAT_NUMS_GET_EVT: + return "Get Packet Nums"; default: return "Unknown AG Event"; } 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 50b60a224a..661d237266 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 @@ -475,6 +475,7 @@ static void bta_ag_cback_sco(tBTA_AG_SCB *p_scb, UINT8 event) sco.handle = bta_ag_scb_to_idx(p_scb); sco.app_id = p_scb->app_id; + sco.sync_conn_handle = BTM_ReadScoHandle(p_scb->sco_idx); /* call close cback */ (*bta_ag_cb.p_cback)(event, (tBTA_AG *) &sco); @@ -1477,6 +1478,32 @@ void bta_ag_sco_codec_nego(tBTA_AG_SCB *p_scb, BOOLEAN result) } #endif +/******************************************************************************* +** +** Function bta_ag_pkt_stat_nums +** +** Description Get the number of packet states +** +** +** Returns void +** +*******************************************************************************/ +void bta_ag_pkt_stat_nums(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data) +{ + UNUSED(p_scb); + +#if (BTM_SCO_HCI_INCLUDED == TRUE) + tBTA_AG_PKT_STAT_NUMS pkt_stat_nums; + uint16_t sync_conn_handle = p_data->pkt_stat.sync_conn_handle; + BTM_PktStatNumsGet(sync_conn_handle, (tBTM_SCO_PKT_STAT_NUMS *) &pkt_stat_nums); + + /* call app cback */ + if (bta_ag_cb.p_cback) { + (*bta_ag_cb.p_cback)(BTA_AG_PKT_NUMS_GET_EVT, (tBTA_AG*) &pkt_stat_nums); + } +#endif +} + /******************************************************************************* ** ** Function bta_ag_sco_shutdown diff --git a/components/bt/host/bluedroid/bta/hf_ag/include/bta_ag_int.h b/components/bt/host/bluedroid/bta/hf_ag/include/bta_ag_int.h index 4956916d7d..c890e4d879 100644 --- a/components/bt/host/bluedroid/bta/hf_ag/include/bta_ag_int.h +++ b/components/bt/host/bluedroid/bta/hf_ag/include/bta_ag_int.h @@ -113,6 +113,7 @@ enum BTA_AG_SVC_TOUT_EVT, BTA_AG_CI_SCO_DATA_EVT, BTA_AG_CI_SLC_READY_EVT, + BTA_AG_PKT_STAT_NUMS_GET_EVT, BTA_AG_MAX_EVT, /* these events are handled outside of the state machine */ @@ -218,6 +219,13 @@ typedef struct char p_data[BTA_AG_MTU+1]; } tBTA_AG_CI_RX_WRITE; +/* data type for BTA_AG_PKT_STAT_NUMS_GET_EVT */ +typedef struct +{ + BT_HDR hdr; + UINT16 sync_conn_handle; +} tBTA_AG_PKT_STAT_GET; + /* union of all event datatypes */ typedef union { @@ -232,6 +240,7 @@ typedef union tBTA_AG_DISC_RESULT disc_result; tBTA_AG_RFC rfc; tBTA_AG_CI_RX_WRITE ci_rx_write; + tBTA_AG_PKT_STAT_GET pkt_stat; } tBTA_AG_DATA; /* type for each profile */ @@ -276,7 +285,7 @@ typedef struct tBTA_AG_SCO_MSBC_SETTINGS codec_msbc_settings; /* settings to be used for the impending eSCO */ TIMER_LIST_ENT cn_timer; /* codec negotiation timer */ #endif - UINT16 sco_idx; /* SCO handle */ + UINT16 sco_idx; /* SCO connection index */ BOOLEAN in_use; /* scb in use */ BOOLEAN dealloc; /* TRUE if service shutting down */ BOOLEAN clip_enabled; /* set to TRUE if HF enables CLIP reporting */ @@ -437,6 +446,7 @@ extern void bta_ag_ci_sco_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); extern void bta_ag_set_esco_param(BOOLEAN set_reset, tBTM_ESCO_PARAMS *param); extern void bta_ag_ci_rx_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); extern void bta_ag_rcvd_slc_ready(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); +extern void bta_ag_pkt_stat_nums(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); #endif /* #if (BTA_AG_INCLUDED == TRUE) */ diff --git a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c index 4cb1c9b953..5aef946155 100644 --- a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c +++ b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c @@ -294,7 +294,28 @@ void BTA_HfClientSendAT(UINT16 handle, tBTA_HF_CLIENT_AT_CMD_TYPE at, UINT32 val bta_sys_sendmsg(p_buf); } } -#if (BTM_SCO_HCI_INCLUDED == TRUE ) + +#if (BTM_SCO_HCI_INCLUDED == TRUE) +/******************************************************************************* +** +** Function BTA_HfClientPktStatsNumsGet +** +** Description Get the packet ststus numbers received and send for a specific (e)SCO connection handle. +** +** +** Returns void +** +*******************************************************************************/ +void BTA_HfClientPktStatsNumsGet(UINT16 sync_conn_handle) +{ + tBTA_HF_CLIENT_PKT_STAT_GET *p_buf; + if ((p_buf = (tBTA_HF_CLIENT_PKT_STAT_GET *) osi_malloc(sizeof(tBTA_HF_CLIENT_PKT_STAT_GET))) != NULL) { + p_buf->hdr.event = BTA_HF_CLIENT_PKT_NUMS_GET_EVT; + p_buf->sync_conn_handle = sync_conn_handle; + bta_sys_sendmsg(p_buf); + } +} + void BTA_HfClientCiData(void) { BT_HDR *p_buf; diff --git a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_main.c b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_main.c index b47ffcac6e..1716f96ba1 100644 --- a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_main.c +++ b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_main.c @@ -75,6 +75,7 @@ enum { BTA_HF_CLIENT_SEND_AT_CMD, #if (BTM_SCO_HCI_INCLUDED == TRUE) BTA_HF_CLIENT_CI_SCO_DATA, + BTA_HF_CLIENT_PKT_STAT_NUMS, #endif BTA_HF_CLIENT_NUM_ACTIONS, }; @@ -111,8 +112,9 @@ const tBTA_HF_CLIENT_ACTION bta_hf_client_action[] = { /* BTA_HF_CLIENT_DISC_ACP_RES */ bta_hf_client_disc_acp_res, /* BTA_HF_CLIENT_SVC_CONN_OPEN */ bta_hf_client_svc_conn_open, /* BTA_HF_CLIENT_SEND_AT_CMD */ bta_hf_client_send_at_cmd, -#if (BTM_SCO_HCI_INCLUDED == TRUE ) +#if (BTM_SCO_HCI_INCLUDED == TRUE) /* BTA_HF_CLIENT_CI_SCO_DATA */ bta_hf_client_ci_sco_data, + /* BTA_HF_CLIENT_PKT_STAT_NUMS */ bta_hf_client_pkt_stat_nums, #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */ }; @@ -143,6 +145,7 @@ const UINT8 bta_hf_client_st_init[][BTA_HF_CLIENT_NUM_COLS] = { /* SEND_AT_CMD_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_INIT_ST}, #if (BTM_SCO_HCI_INCLUDED == TRUE ) /* CI_SCO_DATA_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_INIT_ST}, + /* PKT_STAT_NUMS_GET_EVT */ {BTA_HF_CLIENT_PKT_STAT_NUMS, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_INIT_ST}, #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */ }; @@ -166,8 +169,9 @@ const UINT8 bta_hf_client_st_opening[][BTA_HF_CLIENT_NUM_COLS] = { /* SCO_OPEN_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPENING_ST}, /* SCO_CLOSE_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPENING_ST}, /* SEND_AT_CMD_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPENING_ST}, -#if (BTM_SCO_HCI_INCLUDED == TRUE ) +#if (BTM_SCO_HCI_INCLUDED == TRUE) /* CI_SCO_DATA_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPENING_ST}, + /* PKT_STAT_NUMS_GET_EVT */ {BTA_HF_CLIENT_PKT_STAT_NUMS, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPENING_ST}, #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */ }; @@ -193,6 +197,7 @@ const UINT8 bta_hf_client_st_open[][BTA_HF_CLIENT_NUM_COLS] = { /* SEND_AT_CMD_EVT */ {BTA_HF_CLIENT_SEND_AT_CMD, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPEN_ST}, #if (BTM_SCO_HCI_INCLUDED == TRUE ) /* CI_SCO_DATA_EVT */ {BTA_HF_CLIENT_CI_SCO_DATA, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPEN_ST}, + /* PKT_STAT_NUMS_GET_EVT */ {BTA_HF_CLIENT_PKT_STAT_NUMS, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_OPEN_ST}, #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */ }; @@ -218,6 +223,7 @@ const UINT8 bta_hf_client_st_closing[][BTA_HF_CLIENT_NUM_COLS] = { /* SEND_AT_CMD_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_CLOSING_ST}, #if (BTM_SCO_HCI_INCLUDED == TRUE ) /* CI_SCO_DATA_EVT */ {BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_CLOSING_ST}, + /* PKT_STAT_NUMS_GET_EVT */ {BTA_HF_CLIENT_PKT_STAT_NUMS, BTA_HF_CLIENT_IGNORE, BTA_HF_CLIENT_CLOSING_ST}, #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */ }; @@ -640,6 +646,7 @@ static char *bta_hf_client_evt_str(UINT16 event) CASE_RETURN_STR(BTA_HF_CLIENT_SCO_OPEN_EVT) CASE_RETURN_STR(BTA_HF_CLIENT_SCO_CLOSE_EVT) CASE_RETURN_STR(BTA_HF_CLIENT_SEND_AT_CMD_EVT) + CASE_RETURN_STR(BTA_HF_CLIENT_PKT_NUMS_GET_EVT) default: return "Unknown HF Client Event"; } diff --git a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_sco.c b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_sco.c index 5d7c8ab528..e4fe45c8c4 100644 --- a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_sco.c +++ b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_sco.c @@ -155,6 +155,7 @@ void bta_hf_client_cback_sco(UINT8 event) tBTA_HF_CLIENT_HDR evt; memset(&evt, 0, sizeof(evt)); + evt.sync_conn_handle = BTM_ReadScoHandle(bta_hf_client_cb.scb.sco_idx); /* call app cback */ (*bta_hf_client_cb.p_cback)(event, (tBTA_HF_CLIENT_HDR *) &evt); @@ -237,7 +238,29 @@ static void bta_hf_client_sco_conn_rsp(tBTM_ESCO_CONN_REQ_EVT_DATA *p_data) BTM_EScoConnRsp(p_data->sco_inx, hci_status, &resp); } -#if (BTM_SCO_HCI_INCLUDED == TRUE ) +#if (BTM_SCO_HCI_INCLUDED == TRUE) +/******************************************************************************* +** +** Function bta_hf_client_pkt_stat_nums +** +** Description Get the packet status number +** +** +** Returns void +** +*******************************************************************************/ +void bta_hf_client_pkt_stat_nums(tBTA_HF_CLIENT_DATA *p_data) +{ + tBTA_SCO_PKT_STAT_NUMS pkt_stat_nums; + uint16_t sync_conn_handle = p_data->pkt_stat.sync_conn_handle; + BTM_PktStatNumsGet(sync_conn_handle, (tBTM_SCO_PKT_STAT_NUMS *) &pkt_stat_nums); + + /* call app cback */ + if (bta_hf_client_cb.p_cback) { + (*bta_hf_client_cb.p_cback)(BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT, (void*) &pkt_stat_nums); + } +} + /******************************************************************************* ** ** Function bta_hf_client_ci_sco_data @@ -254,6 +277,7 @@ void bta_hf_client_ci_sco_data(tBTA_HF_CLIENT_DATA *p_data) bta_hf_client_sco_event(BTA_HF_CLIENT_SCO_CI_DATA_E); } #endif + /******************************************************************************* ** ** Function bta_hf_client_sco_connreq_cback diff --git a/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h b/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h index ddfc62442d..f5b897ddb9 100644 --- a/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h +++ b/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h @@ -64,6 +64,7 @@ enum { BTA_HF_CLIENT_SEND_AT_CMD_EVT, #if (BTM_SCO_HCI_INCLUDED == TRUE ) BTA_HF_CLIENT_CI_SCO_DATA_EVT, + BTA_HF_CLIENT_PKT_NUMS_GET_EVT, #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */ BTA_HF_CLIENT_MAX_EVT, @@ -120,6 +121,12 @@ typedef struct { char str[BTA_HF_CLIENT_NUMBER_LEN + 1]; } tBTA_HF_CLIENT_DATA_VAL; +/* data type for BTA_HF_CLIENT_PKT_NUMS_GET_EVT */ +typedef struct { + BT_HDR hdr; + UINT16 sync_conn_handle; +} tBTA_HF_CLIENT_PKT_STAT_GET; + /* union of all event datatypes */ typedef union { BT_HDR hdr; @@ -129,6 +136,7 @@ typedef union { tBTA_HF_CLIENT_DISC_RESULT disc_result; tBTA_HF_CLIENT_RFC rfc; tBTA_HF_CLIENT_DATA_VAL val; + tBTA_HF_CLIENT_PKT_STAT_GET pkt_stat; } tBTA_HF_CLIENT_DATA; @@ -299,6 +307,7 @@ extern void bta_hf_client_binp(char *number); extern void bta_hf_client_dial(tBTA_HF_CLIENT_DATA *p_data); extern void bta_hf_client_send_at_cmd(tBTA_HF_CLIENT_DATA *p_data); #if (BTM_SCO_HCI_INCLUDED == TRUE ) +extern void bta_hf_client_pkt_stat_nums(tBTA_HF_CLIENT_DATA *p_data); extern void bta_hf_client_ci_sco_data(tBTA_HF_CLIENT_DATA *p_data); #endif /* (BTM_SCO_HCI_INCLUDED == TRUE ) */ #endif /* #if (BTA_HF_INCLUDED == TRUE) */ 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 5fd908810e..35bb6ab5e6 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 @@ -158,6 +158,8 @@ typedef UINT8 tBTA_AG_RES; #endif #define BTA_AG_AUDIO_MSBC_OPEN_EVT 32 /* Audio connection with mSBC codec open */ +#define BTA_AG_PKT_NUMS_GET_EVT 33 /* AG packet status nums */ + /* Values below are for HFP only */ #define BTA_AG_AT_A_EVT 10 /* Answer a incoming call */ #define BTA_AG_AT_D_EVT 11 /* Place a call using number or memory dial */ @@ -327,6 +329,7 @@ typedef struct UINT16 handle; UINT8 app_id; tBTA_AG_STATUS status; + UINT16 sync_conn_handle; } tBTA_AG_HDR; /* data associated with BTA_AG_REGISTER_EVT */ @@ -405,6 +408,17 @@ typedef struct { char number[BTA_AG_NUMBER_LEN + 1]; } tBTA_AG_CNUM; +/* data associated with BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT */ +typedef struct { + UINT32 rx_total; + UINT32 rx_correct; + UINT32 rx_err; + UINT32 rx_none; + UINT32 rx_lost; + UINT32 tx_total; + UINT32 tx_discarded; +} tBTA_AG_PKT_STAT_NUMS; + /* union of data associated with AG callback */ typedef union { @@ -421,6 +435,7 @@ typedef union tBTA_AG_AT_RESULT result; tBTA_AG_CLCC clcc; tBTA_AG_CNUM cnum; + tBTA_AG_PKT_STAT_NUMS pkt_num; } tBTA_AG; /* AG callback */ @@ -581,6 +596,18 @@ void BTA_AgSetCodec(UINT16 handle, tBTA_AG_PEER_CODEC codec); #if (BTM_SCO_HCI_INCLUDED == TRUE ) +/******************************************************************************* +** +** Function BTA_AgPktStatsNumsGet +** +** Description Get the Number of packets status received +** +** +** Returns void +** +*******************************************************************************/ +void BTA_AgPktStatsNumsGet(UINT16 handle, UINT16 sync_conn_handle); + /******************************************************************************* ** ** Function BTA_AgCiData diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h index e01b7a1c75..027f635717 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h @@ -113,6 +113,7 @@ typedef UINT8 tBTA_HF_CLIENT_AT_RESULT_TYPE; #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 */ typedef UINT8 tBTA_HF_CLIENT_EVT; @@ -159,6 +160,7 @@ typedef UINT8 tBTA_HF_CLIENT_AT_CMD_TYPE; /* data associated with most non-AT events */ /* placeholder, if not needed should be removed*/ typedef struct { + UINT16 sync_conn_handle; } tBTA_HF_CLIENT_HDR; /* data associated with BTA_HF_CLIENT_REGISTER_EVT */ @@ -228,6 +230,17 @@ typedef struct { UINT16 value; } tBTA_HF_CLIENT_VAL; +/* data associated with BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT */ +typedef struct { + UINT32 rx_total; + UINT32 rx_correct; + UINT32 rx_err; + UINT32 rx_none; + UINT32 rx_lost; + UINT32 tx_total; + UINT32 tx_discarded; +} tBTA_SCO_PKT_STAT_NUMS; + /* union of data associated with AG callback */ typedef union { tBTA_HF_CLIENT_HDR hdr; @@ -241,6 +254,7 @@ typedef union { tBTA_HF_CLIENT_AT_RESULT result; tBTA_HF_CLIENT_CLCC clcc; tBTA_HF_CLIENT_CNUM cnum; + tBTA_SCO_PKT_STAT_NUMS pkt_num; } tBTA_HF_CLIENT; typedef UINT32 tBTA_HF_CLIENT_FEAT; @@ -376,6 +390,18 @@ void BTA_HfClientAudioClose(UINT16 handle); void BTA_HfClientSendAT(UINT16 handle, tBTA_HF_CLIENT_AT_CMD_TYPE at, UINT32 val1, UINT32 val2, const char *str); #if (BTM_SCO_HCI_INCLUDED == TRUE ) +/******************************************************************************* +** +** Function BTA_HfClientPktStatsNumsGet +** +** Description Get the Number of packets status received and send +** +** +** Returns void +** +*******************************************************************************/ +void BTA_HfClientPktStatsNumsGet(UINT16 sync_conn_handle); + void BTA_HfClientCiData(void); #endif /*#if (BTM_SCO_HCI_INCLUDED == TRUE ) */ 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 96a5625835..484ef9f718 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 @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -398,6 +398,21 @@ bt_status_t btc_hf_disconnect_audio(bt_bdaddr_t *bd_addr) return BT_STATUS_FAIL; } +static bt_status_t btc_hf_pkt_stat_nums_get(UINT16 sync_conn_handle) +{ + bt_status_t status = BT_STATUS_FAIL; +#if (BTM_SCO_HCI_INCLUDED == TRUE) + int idx = btc_hf_latest_connected_idx(); + CHECK_HF_SLC_CONNECTED(idx); + + if (idx != BTC_HF_INVALID_IDX) { + BTA_AgPktStatsNumsGet(hf_local_param[idx].btc_hf_cb.handle, sync_conn_handle); + status = BT_STATUS_SUCCESS; + } +#endif /*#if (BTM_SCO_HCI_INCLUDED == TRUE) */ + return status; +} + /************************************************************************************ ** AT cmd Handle ************************************************************************************/ @@ -1163,8 +1178,13 @@ void btc_hf_call_handler(btc_msg_t *msg) case BTC_HF_REGISTER_DATA_CALLBACK_EVT: { btc_hf_reg_data_cb(arg->reg_data_cb.recv, arg->reg_data_cb.send); - } break; + } + case BTC_HF_REQUEST_PKT_STAT_EVT: + { + btc_hf_pkt_stat_nums_get(arg->pkt_sync_hd.sync_conn_handle); + break; + } default: BTC_TRACE_WARNING("%s : unhandled event: %d\n", __FUNCTION__, msg->act); @@ -1286,6 +1306,7 @@ void btc_hf_cb_handler(btc_msg_t *msg) do { 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)); + param.audio_stat.sync_conn_handle = p_data->hdr.sync_conn_handle; btc_hf_cb_to_app(ESP_HF_AUDIO_STATE_EVT, ¶m); } while(0); break; @@ -1298,6 +1319,7 @@ void btc_hf_cb_handler(btc_msg_t *msg) do { 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)); + param.audio_stat.sync_conn_handle = p_data->hdr.sync_conn_handle; btc_hf_cb_to_app(ESP_HF_AUDIO_STATE_EVT, ¶m); } while (0); break; @@ -1309,6 +1331,7 @@ void btc_hf_cb_handler(btc_msg_t *msg) do { 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)); + param.audio_stat.sync_conn_handle = p_data->hdr.sync_conn_handle; btc_hf_cb_to_app(ESP_HF_AUDIO_STATE_EVT, ¶m); } while(0); break; @@ -1528,6 +1551,12 @@ void btc_hf_cb_handler(btc_msg_t *msg) break; } #endif + case BTA_AG_PKT_NUMS_GET_EVT: + { + memcpy(¶m.pkt_nums, &p_data->pkt_num, sizeof(struct ag_pkt_status_nums)); + btc_hf_cb_to_app(ESP_HF_PKT_STAT_NUMS_GET_EVT, ¶m); + break; + } default: BTC_TRACE_WARNING("%s: Unhandled event: %d", __FUNCTION__, event); break; diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_client/btc_hf_client.c b/components/bt/host/bluedroid/btc/profile/std/hf_client/btc_hf_client.c index ddaa07b721..c3f7cf4920 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_client/btc_hf_client.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_client/btc_hf_client.c @@ -1,16 +1,8 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /****************************************************************************** ** @@ -650,6 +642,24 @@ static bt_status_t btc_hf_client_send_nrec(void) return BT_STATUS_UNSUPPORTED; } +/******************************************************************************* +** +** Function btc_hf_client_pkt_stat_nums_get; +** +** Description Request packet status numbers for a specific (e)SCO connection handle +** +** Returns bt_status_t +** +*******************************************************************************/ +static bt_status_t btc_hf_client_pkt_stat_nums_get(UINT16 sync_conn_handle) +{ + CHECK_HF_CLIENT_SLC_CONNECTED(); +#if (BTM_SCO_HCI_INCLUDED == TRUE) + BTA_HfClientPktStatsNumsGet(sync_conn_handle); +#endif /*#if (BTM_SCO_HCI_INCLUDED == TRUE) */ + return BT_STATUS_SUCCESS; +} + /******************************************************************************* ** ** Function bte_hf_client_evt @@ -775,6 +785,8 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) esp_hf_client_cb_param_t param; bdstr_t bdstr; + memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); + switch (event) { case BTA_HF_CLIENT_ENABLE_EVT: @@ -805,7 +817,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) } do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.conn_stat.state = hf_client_local_param.btc_hf_client_cb.state; param.conn_stat.peer_feat = 0; param.conn_stat.chld_feat = 0; @@ -831,7 +842,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED; do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.conn_stat.state = hf_client_local_param.btc_hf_client_cb.state; param.conn_stat.peer_feat = hf_client_local_param.btc_hf_client_cb.peer_feat; param.conn_stat.chld_feat = hf_client_local_param.btc_hf_client_cb.chld_feat; @@ -846,7 +856,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_INBAND) { do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.bsir.state = ESP_HF_CLIENT_IN_BAND_RINGTONE_PROVIDED; btc_hf_client_cb_to_app(ESP_HF_CLIENT_BSIR_EVT, ¶m); } while (0); @@ -858,7 +867,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) case BTA_HF_CLIENT_CLOSE_EVT: hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.conn_stat.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; param.conn_stat.peer_feat = 0; param.conn_stat.chld_feat = 0; @@ -879,7 +887,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_MIC_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.volume_control.type = ESP_HF_VOLUME_CONTROL_TARGET_MIC; param.volume_control.volume = p_data->val.value; @@ -888,7 +895,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_SPK_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.volume_control.type = ESP_HF_VOLUME_CONTROL_TARGET_SPK; param.volume_control.volume = p_data->val.value; @@ -897,7 +903,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_VOICE_REC_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.bvra.value = p_data->val.value; btc_hf_client_cb_to_app(ESP_HF_CLIENT_BVRA_EVT, ¶m); @@ -905,35 +910,30 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_OPERATOR_NAME_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.cops.name = p_data->operator.name; btc_hf_client_cb_to_app(ESP_HF_CLIENT_COPS_CURRENT_OPERATOR_EVT, ¶m); } while (0); break; case BTA_HF_CLIENT_CLIP_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.clip.number = p_data->number.number; btc_hf_client_cb_to_app(ESP_HF_CLIENT_CLIP_EVT, ¶m); } while (0); break; case BTA_HF_CLIENT_BINP_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.binp.number = p_data->number.number; btc_hf_client_cb_to_app(ESP_HF_CLIENT_BINP_EVT, ¶m); } while (0); break; case BTA_HF_CLIENT_CCWA_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.ccwa.number = p_data->number.number; btc_hf_client_cb_to_app(ESP_HF_CLIENT_CCWA_EVT, ¶m); } while (0); break; case BTA_HF_CLIENT_AT_RESULT_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.at_response.code = p_data->result.type; param.at_response.cme = p_data->result.cme; @@ -942,7 +942,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_CLCC_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.clcc.idx = p_data->clcc.idx; param.clcc.dir = p_data->clcc.inc ? ESP_HF_CURRENT_CALL_DIRECTION_INCOMING : ESP_HF_CURRENT_CALL_DIRECTION_OUTGOING; @@ -955,7 +954,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_CNUM_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.cnum.number = p_data->cnum.number; if (p_data->cnum.service == 4) { param.cnum.type = ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE; @@ -971,7 +969,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) case BTA_HF_CLIENT_BTRH_EVT: if (p_data->val.value <= ESP_HF_BTRH_STATUS_REJECTED) { do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.btrh.status = p_data->val.value; btc_hf_client_cb_to_app(ESP_HF_CLIENT_BTRH_EVT, ¶m); @@ -979,7 +976,6 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) } break; case BTA_HF_CLIENT_BSIR_EVT: - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); if (p_data->val.value != 0) { param.bsir.state = ESP_HF_CLIENT_IN_BAND_RINGTONE_PROVIDED; @@ -992,28 +988,28 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_AUDIO_OPEN_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED; memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); + param.audio_stat.sync_conn_handle = p_data->hdr.sync_conn_handle; btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, ¶m); } while (0); break; case BTA_HF_CLIENT_AUDIO_MSBC_OPEN_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED_MSBC; memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); + param.audio_stat.sync_conn_handle = p_data->hdr.sync_conn_handle; btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, ¶m); } while (0); break; case BTA_HF_CLIENT_AUDIO_CLOSE_EVT: do { - memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_DISCONNECTED; memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); + param.audio_stat.sync_conn_handle = p_data->hdr.sync_conn_handle; btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, ¶m); } while (0); break; @@ -1022,6 +1018,12 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) btc_hf_client_cb_to_app(ESP_HF_CLIENT_RING_IND_EVT, NULL); } while (0); break; + case BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT: + { + memcpy(¶m.pkt_nums, &p_data->pkt_num, sizeof(struct hf_client_pkt_status_nums)); + btc_hf_client_cb_to_app(ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT, ¶m); + break; + } default: BTC_TRACE_WARNING("%s: Unhandled event: %d", __FUNCTION__, event); break; @@ -1099,6 +1101,9 @@ void btc_hf_client_call_handler(btc_msg_t *msg) case BTC_HF_CLIENT_SEND_NREC_EVT: btc_hf_client_send_nrec(); break; + case BTC_HF_CLIENT_REQUEST_PKT_STAT_EVT: + btc_hf_client_pkt_stat_nums_get(arg->pkt_sync_hd.sync_conn_handle); + break; default: BTC_TRACE_WARNING("%s : unhandled event: %d\n", __FUNCTION__, msg->act); } diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h index c7b9151901..e200768a56 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h @@ -1,16 +1,8 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * @@ -63,7 +55,8 @@ typedef enum BTC_HF_OUT_CALL_EVT, BTC_HF_END_CALL_EVT, //REG - BTC_HF_REGISTER_DATA_CALLBACK_EVT + BTC_HF_REGISTER_DATA_CALLBACK_EVT, + BTC_HF_REQUEST_PKT_STAT_EVT } btc_hf_act_t; /* btc_hf_args_t */ @@ -194,6 +187,11 @@ typedef union esp_hf_outgoing_data_cb_t send; } reg_data_cb; + // BTC_HF_REQUEST_PKT_STAT_EVT + struct req_pkt_stat_sync_handle { + UINT16 sync_conn_handle; + } pkt_sync_hd; + } btc_hf_args_t; /************************************************************************************ diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_client.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_client.h index e3befc9f4a..4a9104552b 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_client.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_client.h @@ -1,16 +1,8 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* @@ -58,6 +50,7 @@ typedef enum { BTC_HF_CLIENT_REQUEST_LAST_VOICE_TAG_NUMBER_EVT, BTC_HF_CLIENT_REGISTER_DATA_CALLBACK_EVT, BTC_HF_CLIENT_SEND_NREC_EVT, + BTC_HF_CLIENT_REQUEST_PKT_STAT_EVT, } btc_hf_client_act_t; /* btc_hf_client_args_t */ @@ -111,6 +104,12 @@ typedef union { esp_hf_client_incoming_data_cb_t recv; esp_hf_client_outgoing_data_cb_t send; } reg_data_cb; + + // BTC_HF_CLIENT_REQUEST_PKT_STAT_EVT + struct req_pkt_stat_sync_handle { + UINT16 sync_conn_handle; + } pkt_sync_hd; + } btc_hf_client_args_t; /************************************************************************************ diff --git a/components/bt/host/bluedroid/stack/btm/btm_sco.c b/components/bt/host/bluedroid/stack/btm/btm_sco.c index 6f5dd7806d..8431a7d77b 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_sco.c +++ b/components/bt/host/bluedroid/stack/btm/btm_sco.c @@ -341,6 +341,82 @@ void btm_sco_process_num_completed_pkts (UINT8 *p) return; } + +/******************************************************************************* +** +** Function btm_pkt_stat_nums_update +** +** Description Update the number of received SCO data packet status. +** +** Returns void +** +*******************************************************************************/ +static void btm_pkt_stat_nums_update(uint16_t sco_inx, uint8_t pkt_status) +{ + tSCO_CONN *p_ccb = &btm_cb.sco_cb.sco_db[sco_inx]; + p_ccb->pkt_stat_nums.rx_total++; + if (pkt_status == BTM_SCO_DATA_CORRECT) { + p_ccb->pkt_stat_nums.rx_correct++; + } else if (pkt_status == BTM_SCO_DATA_PAR_ERR) { + p_ccb->pkt_stat_nums.rx_err++; + } else if (pkt_status == BTM_SCO_DATA_NONE) { + p_ccb->pkt_stat_nums.rx_none++; + } else { + p_ccb->pkt_stat_nums.rx_lost++; + } +} + +/******************************************************************************* +** +** Function btm_pkt_stat_send_nums_update +** +** Description Update the number of send packet status. +** +** Returns void +** +*******************************************************************************/ +static void btm_pkt_stat_send_nums_update(uint16_t sco_inx, uint8_t pkt_status) +{ + tSCO_CONN *p_ccb = &btm_cb.sco_cb.sco_db[sco_inx]; + p_ccb->pkt_stat_nums.tx_total++; + if (pkt_status != BTM_SUCCESS) { + p_ccb->pkt_stat_nums.tx_discarded++; + } +} + +/******************************************************************************* +** +** Function btm_pkt_stat_nums_reset +** +** Description This function is called to reset the number of packet status struct +** +** Returns void +** +*******************************************************************************/ +static void btm_pkt_stat_nums_reset(uint16_t sco_inx) +{ + memset(&btm_cb.sco_cb.sco_db[sco_inx].pkt_stat_nums, 0, sizeof(tBTM_SCO_PKT_STAT_NUMS)); +} + +/******************************************************************************* +** +** Function BTM_PktStatNumsGet +** +** Description This function is called to get the number of packet status struct +** +** Returns void +** +*******************************************************************************/ +void BTM_PktStatNumsGet(uint16_t sync_conn_handle, tBTM_SCO_PKT_STAT_NUMS *p_pkt_nums) +{ + uint16_t sco_inx = btm_find_scb_by_handle(sync_conn_handle); + if (sco_inx < BTM_MAX_SCO_LINKS) { + memcpy(p_pkt_nums, &btm_cb.sco_cb.sco_db[sco_inx].pkt_stat_nums, sizeof(tBTM_SCO_PKT_STAT_NUMS)); + } else { + memset(p_pkt_nums, 0, sizeof(tBTM_SCO_PKT_STAT_NUMS)); + } +} + #endif /* BTM_SCO_HCI_INCLUDED == TRUE */ /******************************************************************************* @@ -374,6 +450,7 @@ void btm_route_sco_data(BT_HDR *p_msg) { osi_free (p_msg); } else { + btm_pkt_stat_nums_update(sco_inx, pkt_status); (*btm_cb.sco_cb.p_data_cb)(sco_inx, p_msg, (tBTM_SCO_DATA_FLAG) pkt_status); } } else { /* no mapping handle SCO connection is active, free the buffer */ @@ -461,6 +538,7 @@ tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf) BTM_TRACE_WARNING ("stat %d", status); osi_free(p_buf); } + btm_pkt_stat_send_nums_update(sco_inx, status); return (status); #else @@ -994,6 +1072,7 @@ void btm_sco_connected (UINT8 hci_status, BD_ADDR bda, UINT16 hci_handle, } #if BTM_SCO_HCI_INCLUDED == TRUE p->sent_not_acked = 0; + btm_pkt_stat_nums_reset(xx); #endif p->state = SCO_ST_CONNECTED; p->hci_handle = hci_handle; diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index 82d99467c2..b991e32ed0 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -431,6 +431,7 @@ typedef struct { #define BTM_SCO_XMIT_QUEUE_HIGH_WM 20 fixed_queue_t *xmit_data_q; /* SCO data transmitting queue */ INT16 sent_not_acked; + tBTM_SCO_PKT_STAT_NUMS pkt_stat_nums; #endif tBTM_SCO_CB *p_conn_cb; /* Callback for when connected */ tBTM_SCO_CB *p_disc_cb; /* Callback for when disconnect */ diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_api.h index 4c05ba0a29..da053ee34a 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_api.h @@ -1062,6 +1062,17 @@ enum { }; typedef UINT8 tBTM_SCO_DATA_FLAG; +/* Count the number of SCO Data Packet Status */ +typedef struct { + UINT32 rx_total; + UINT32 rx_correct; + UINT32 rx_err; + UINT32 rx_none; + UINT32 rx_lost; + UINT32 tx_total; + UINT32 tx_discarded; +} tBTM_SCO_PKT_STAT_NUMS; + /*************************** ** SCO Callback Functions ****************************/ @@ -4186,6 +4197,17 @@ tBTM_STATUS BTM_SetAfhChannels (AFH_CHANNELS channels, tBTM_CMPL_CB *p_afh_chann *******************************************************************************/ tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback); +/******************************************************************************* +** +** Function BTM_PktStatNumsGet +** +** Description This function is called to get the number of packet status struct +** +** Returns void +** +*******************************************************************************/ +void BTM_PktStatNumsGet(UINT16 sync_conn_handle, tBTM_SCO_PKT_STAT_NUMS *pkt_nums); + /* #ifdef __cplusplus } 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 c29a326de4..e399571511 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 @@ -1,10 +1,8 @@ /* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include @@ -46,6 +44,7 @@ const char *c_hf_evt_str[] = { "DIAL_EVT", /*!< DIAL INCOMING EVT */ "WBS_EVT", /*!< CURRENT CODEC EVT */ "BCS_EVT", /*!< CODEC NEGO EVT */ + "PKT_STAT_EVT", /*!< REQUEST PACKET STATUS EVT */ }; //esp_hf_connection_state_t @@ -213,7 +212,7 @@ static void bt_app_send_data_timer_cb(void *arg) static void bt_app_send_data_task(void *arg) { uint64_t frame_data_num; - uint32_t item_size = 0; + size_t item_size = 0; uint8_t *buf = NULL; for (;;) { if (xSemaphoreTake(s_send_data_Semaphore, (portTickType)portMAX_DELAY)) { @@ -293,7 +292,7 @@ void bt_app_send_data_shut_down(void) void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) { - if (event <= ESP_HF_BCS_RESPONSE_EVT) { + if (event <= ESP_HF_PKT_STAT_NUMS_GET_EVT) { ESP_LOGI(BT_HF_TAG, "APP HFP event: %s", c_hf_evt_str[event]); } else { ESP_LOGE(BT_HF_TAG, "APP HFP invalid event %d", event); @@ -478,6 +477,11 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) ESP_LOGI(BT_HF_TAG, "--Consequence of codec negotiation: %s",c_codec_mode_str[param->bcs_rep.mode]); break; } + case ESP_HF_PKT_STAT_NUMS_GET_EVT: + { + ESP_LOGI(BT_HF_TAG, "ESP_HF_PKT_STAT_NUMS_GET_EVT: %d.", event); + break; + } default: ESP_LOGI(BT_HF_TAG, "Unsupported HF_AG EVT: %d.", event); diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/bt_app_hf.c b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/bt_app_hf.c index d24a7c9154..4ffd2bb7a0 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/bt_app_hf.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/bt_app_hf.c @@ -1,10 +1,8 @@ /* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express esp_hf_ag_apiied. -*/ + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include @@ -49,6 +47,7 @@ const char *c_hf_evt_str[] = { "INBAND_RING_TONE_EVT", /*!< in-band ring tone settings */ "LAST_VOICE_TAG_NUMBER_EVT", /*!< requested number from AG event */ "RING_IND_EVT", /*!< ring indication event */ + "PKT_STAT_EVT", /*!< requested number of packet status event */ }; // esp_hf_client_connection_state_t @@ -229,7 +228,7 @@ static void bt_app_hf_client_incoming_cb(const uint8_t *buf, uint32_t sz) /* callback for HF_CLIENT */ void bt_app_hf_client_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_t *param) { - if (event <= ESP_HF_CLIENT_RING_IND_EVT) { + if (event <= ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT) { ESP_LOGI(BT_HF_TAG, "APP HFP event: %s", c_hf_evt_str[event]); } else { ESP_LOGE(BT_HF_TAG, "APP HFP invalid event %d", event); @@ -394,7 +393,11 @@ void bt_app_hf_client_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_ (param->binp.number == NULL) ? "NULL" : param->binp.number); break; } - + case ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT: + { + ESP_LOGE(BT_HF_TAG, "ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT: %d", event); + break; + } default: ESP_LOGE(BT_HF_TAG, "HF_CLIENT EVT: %d", event); break; From 1d70553ee6c26cc4b2ef72d8d78a961186d5d104 Mon Sep 17 00:00:00 2001 From: Wang Mengyang Date: Tue, 5 Sep 2023 08:14:56 +0800 Subject: [PATCH 11/11] ci(bt/bluedroid): Add CI build test for HFP examples with voice over HCI enabled --- .../bluedroid/classic_bt/hfp_ag/sdkconfig.ci.vohci | 11 +++++++++++ .../bluedroid/classic_bt/hfp_hf/sdkconfig.ci.vohci | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 examples/bluetooth/bluedroid/classic_bt/hfp_ag/sdkconfig.ci.vohci create mode 100644 examples/bluetooth/bluedroid/classic_bt/hfp_hf/sdkconfig.ci.vohci diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/sdkconfig.ci.vohci b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/sdkconfig.ci.vohci new file mode 100644 index 0000000000..6b57232479 --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/sdkconfig.ci.vohci @@ -0,0 +1,11 @@ +# Override some defaults so BT stack is enabled and +# Classic BT is enabled and BT_DRAM_RELEASE is disabled +CONFIG_BT_ENABLED=y +CONFIG_BT_BLE_ENABLED=n +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y +CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN=1 +CONFIG_BT_BLUEDROID_ENABLED=y +CONFIG_BT_CLASSIC_ENABLED=y +CONFIG_BT_HFP_ENABLE=y +CONFIG_BT_HFP_AG_ENABLE=y +CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI=y diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/sdkconfig.ci.vohci b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/sdkconfig.ci.vohci new file mode 100644 index 0000000000..6116dfe13c --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/sdkconfig.ci.vohci @@ -0,0 +1,11 @@ +# Override some defaults so BT stack is enabled and +# Classic BT is enabled and BT_DRAM_RELEASE is disabled +CONFIG_BT_ENABLED=y +CONFIG_BT_BLE_ENABLED=n +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y +CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN=1 +CONFIG_BT_BLUEDROID_ENABLED=y +CONFIG_BT_CLASSIC_ENABLED=y +CONFIG_BT_HFP_ENABLE=y +CONFIG_BT_HFP_CLIENT_ENABLE=y +CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI=y