Skip to content

Commit

Permalink
Merge branch 'test/bqb_test_bt_classic_hfp_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
feat(bt/hfp): Add support for HFP BQB auto test (backport v5.1)

See merge request espressif/esp-idf!26222
  • Loading branch information
jack0c committed Sep 27, 2023
2 parents 67e5366 + 83a6683 commit 8008dbe
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 61 deletions.
29 changes: 27 additions & 2 deletions components/bt/host/bluedroid/api/esp_hf_ag_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ esp_err_t esp_hf_ag_devices_status_indchange(esp_bd_addr_t remote_addr,
return (state == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

esp_err_t esp_hf_ag_ciev_report(esp_bd_addr_t remote_addr, esp_hf_ciev_report_type_t ind_type, int value)
{
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_CIEV_REPORT_EVT;

btc_hf_args_t arg;
memset(&arg, 0, sizeof(btc_hf_args_t));
memcpy(&(arg.ciev_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
arg.ciev_rep.ind.type = ind_type;
arg.ciev_rep.ind.value = value;

/* Switch to BTC context */
bt_status_t state = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL, NULL);
return (state == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

esp_err_t esp_hf_ag_cind_response(esp_bd_addr_t remote_addr,
esp_hf_call_status_t call_state,
esp_hf_call_setup_status_t call_setup_state,
Expand Down Expand Up @@ -337,11 +358,14 @@ esp_err_t esp_hf_ag_clcc_response(esp_bd_addr_t remote_addr, int index, esp_hf_c
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_hf_subscriber_service_type_t type)
esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, int number_type, esp_hf_subscriber_service_type_t service_type)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (number == NULL) {
return ESP_ERR_INVALID_ARG;
}
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_HF;
Expand All @@ -351,7 +375,8 @@ esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_h
memset(&arg, 0, sizeof(btc_hf_args_t));
memcpy(&(arg.cnum_rep), remote_addr, sizeof(esp_bd_addr_t));
arg.cnum_rep.number = number; //deep_copy
arg.cnum_rep.type = type;
arg.cnum_rep.number_type = number_type;
arg.cnum_rep.service_type = service_type;

/* Switch to BTC context */
bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t),
Expand Down
44 changes: 35 additions & 9 deletions components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ esp_err_t esp_hf_ag_vra_control(esp_bd_addr_t remote_bda, esp_hf_vr_state_t valu
*/
esp_err_t esp_hf_ag_volume_control(esp_bd_addr_t remote_bda, esp_hf_volume_control_target_t type, int volume);

/**
/**
*
* @brief Handle Unknown AT command from HFP Client.
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
Expand All @@ -419,7 +419,7 @@ esp_err_t esp_hf_ag_volume_control(esp_bd_addr_t remote_bda, esp_hf_volume_contr
*/
esp_err_t esp_hf_ag_unknown_at_send(esp_bd_addr_t remote_addr, char *unat);

/**
/**
*
* @brief Unsolicited send extend AT error code to HFP Client.
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
Expand All @@ -435,7 +435,7 @@ esp_err_t esp_hf_ag_unknown_at_send(esp_bd_addr_t remote_addr, char *unat);
*/
esp_err_t esp_hf_ag_cmee_send(esp_bd_addr_t remote_bda, esp_hf_at_response_code_t response_code, esp_hf_cme_err_t error_code);

/**
/**
*
* @brief Unsolicited send device status notification to HFP Client.
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
Expand All @@ -452,10 +452,29 @@ esp_err_t esp_hf_ag_cmee_send(esp_bd_addr_t remote_bda, esp_hf_at_response_code_
*
*/
esp_err_t esp_hf_ag_devices_status_indchange(esp_bd_addr_t remote_addr, esp_hf_call_status_t call_state,
esp_hf_call_setup_status_t call_setup_state,
esp_hf_network_state_t ntk_state, int signal);
esp_hf_call_setup_status_t call_setup_state,
esp_hf_network_state_t ntk_state, int signal) __attribute__((
deprecated("Please use esp_hf_ag_ciev_report")
));

/**
*
* @brief Send indicator report "+CIEV: <ind> <value>" to HFP Client. "CIEV" means “indicator events reporting",
* and all indicator types can be sent one type at a time.
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
*
* @param[in] remote_addr: remote bluetooth device address
* @param[in] ind_type: indicator type
* @param[in] value: indicator value
* @return
* - ESP_OK: disconnect request is sent to lower layer
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
* - ESP_FAIL: others
*
*/
esp_err_t esp_hf_ag_ciev_report(esp_bd_addr_t remote_addr, esp_hf_ciev_report_type_t ind_type, int value);

/**
/**
*
* @brief Response to device individual indicators to HFP Client.
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
Expand Down Expand Up @@ -501,7 +520,7 @@ esp_err_t esp_hf_ag_cops_response(esp_bd_addr_t remote_addr, char *name);
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
*
* @param[in] remote_addr: remote bluetooth device address
* @param[in] index: the index of current call
* @param[in] index: the index of current call, starting with 1, finishing response with 0 (send OK)
* @param[in] dir: call direction (incoming/outgoing)
* @param[in] current_call_state: current call state
* @param[in] mode: current call mode (voice/data/fax)
Expand All @@ -525,14 +544,18 @@ esp_err_t esp_hf_ag_clcc_response(esp_bd_addr_t remote_addr, int index, esp_hf_c
*
* @param[in] remote_addr: remote bluetooth device address
* @param[in] number: registration number
* @param[in] type: service type (unknown/voice/fax)
* @param[in] number_type: value of number type from
* 128-143: national or international, may contain prefix and/or escape digits
* 144-159: international, includes country code prefix, add "+" if needed
* 160-175: national, but no prefix nor escape digits
* @param[in] service_type: service type (unknown/voice/fax)
* @return
* - ESP_OK: disconnect request is sent to lower layer
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
* - ESP_FAIL: others
*
*/
esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_hf_subscriber_service_type_t type);
esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, int number_type, esp_hf_subscriber_service_type_t service_type);

/**
*
Expand Down Expand Up @@ -597,6 +620,9 @@ esp_err_t esp_hf_ag_reject_call(esp_bd_addr_t remote_addr, int num_active, int n
*
* @brief Initiate a call from AG.
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
* If the AG is driven by the HF to call esp_hf_ag_out_call, it needs to response an OK or ERROR
* to HF. But if the AG is actively calling esp_hf_ag_out_call, it does not need to take a response
* to HF.
*
* @param[in] remote_addr: remote bluetooth device address
* @param[in] num_active: the number of active call
Expand Down
17 changes: 14 additions & 3 deletions components/bt/host/bluedroid/api/include/api/esp_hf_defs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -51,6 +51,17 @@ typedef enum
ESP_HF_NETWORK_STATE_AVAILABLE
} esp_hf_network_state_t;

/// +CIEV report type
typedef enum {
ESP_HF_IND_TYPE_CALL = 1, /*!< position of call indicator */
ESP_HF_IND_TYPE_CALLSETUP, /*!< position of callsetup indicator */
ESP_HF_IND_TYPE_SERVICE, /*!< position of service indicator */
ESP_HF_IND_TYPE_SIGNAL, /*!< position of signal strength indicator, range: 0-5 */
ESP_HF_IND_TYPE_ROAM, /*!< position of roaming indicator */
ESP_HF_IND_TYPE_BATTCHG, /*!< position of battery charge indicator, range: 0-5 */
ESP_HF_IND_TYPE_CALLHELD /*!< position of callheld indicator */
} esp_hf_ciev_report_type_t;

/** +CIEV Service type */
typedef enum
{
Expand All @@ -60,7 +71,7 @@ typedef enum

/// +CIND call status indicator values
typedef enum {
ESP_HF_CALL_STATUS_NO_CALLS = 0, /*!< no call in progress */
ESP_HF_CALL_STATUS_NO_CALLS = 0, /*!< no call in progress */
ESP_HF_CALL_STATUS_CALL_IN_PROGRESS = 1, /*!< call is present(active or held) */
} esp_hf_call_status_t;

Expand Down Expand Up @@ -124,7 +135,7 @@ typedef enum {
/// +CNUM service type of the phone number
typedef enum {
ESP_HF_SUBSCRIBER_SERVICE_TYPE_UNKNOWN = 0, /*!< unknown */
ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE, /*!< voice service */
ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE = 4, /*!< voice service */
ESP_HF_SUBSCRIBER_SERVICE_TYPE_FAX, /*!< fax service */
} esp_hf_subscriber_service_type_t;

Expand Down
30 changes: 28 additions & 2 deletions components/bt/host/bluedroid/bta/hf_ag/bta_ag_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include "stack/port_api.h"
#include "bta/utl.h"

#if BT_HF_AG_BQB_INCLUDED
static BOOLEAN s_bta_hf_ag_bqb_brsf_flag = false;
#endif /* BT_HF_AG_BQB_INCLUDED */

#if (BTA_AG_INCLUDED == TRUE)
/*****************************************************************************
Expand Down Expand Up @@ -338,6 +341,22 @@ const UINT8 bta_ag_callsetup_ind_tbl[] =
#define COLON_IDX_4_VGSVGM 4
#endif

/*******************************************************************************
**
** Function bta_hf_ag_bqb_brsf_ctrl
**
** Description Control the usage of BTA_AG_BQB_BRSF_FEAT_SPEC for BQB test
**
** Returns void
**
*******************************************************************************/
#if BT_HF_AG_BQB_INCLUDED
void bta_hf_ag_bqb_brsf_ctrl(BOOLEAN enable)
{
s_bta_hf_ag_bqb_brsf_flag = enable;
}
#endif /* BT_HF_AG_BQB_INCLUDED */

/*******************************************
* Funcitons Result
********************************************/
Expand Down Expand Up @@ -1025,7 +1044,15 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
/* store peer features */
p_scb->peer_features = (UINT16) int_arg;
/* send BRSF, send OK */
bta_ag_send_result(p_scb, BTA_AG_RES_BRSF, NULL, (INT16) (p_scb->features & BTA_AG_BSRF_FEAT_SPEC));
#if BT_HF_AG_BQB_INCLUDED
if (s_bta_hf_ag_bqb_brsf_flag == true) {
bta_ag_send_result(p_scb, BTA_AG_RES_BRSF, NULL, (INT16) (p_scb->features & BTA_AG_BQB_BRSF_FEAT_SPEC));
} else {
bta_ag_send_result(p_scb, BTA_AG_RES_BRSF, NULL, (INT16) (p_scb->features & BTA_AG_BRSF_FEAT_SPEC));
}
#else
bta_ag_send_result(p_scb, BTA_AG_RES_BRSF, NULL, (INT16) (p_scb->features & BTA_AG_BRSF_FEAT_SPEC));
#endif /* BT_HF_AG_BQB_INCLUDED */
bta_ag_send_ok(p_scb);
break;
}
Expand Down Expand Up @@ -1522,7 +1549,6 @@ void bta_ag_hfp_result(tBTA_AG_SCB *p_scb, tBTA_AG_API_RESULT *p_result)
if (p_result->data.ok_flag != BTA_AG_OK_ERROR) {
if (p_result->data.str[0] != 0) {
bta_ag_send_result(p_scb, code, p_result->data.str, 0);
bta_ag_send_ok(p_scb);
}
if (p_result->data.ok_flag == BTA_AG_OK_DONE) {
bta_ag_send_ok(p_scb);
Expand Down
26 changes: 17 additions & 9 deletions components/bt/host/bluedroid/bta/hf_ag/include/bta_ag_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,24 @@
#define BTA_AG_ACP 0 /* accepted connection */
#define BTA_AG_INT 1 /* initiating connection */

#if BT_HF_AG_BQB_INCLUDED
/* feature mask that matches spec for BQB test */
#define BTA_AG_BQB_BRSF_FEAT_SPEC (BTA_AG_FEAT_VOIP | \
BTA_AG_FEAT_VTAG | BTA_AG_FEAT_CODEC | \
BTA_AG_FEAT_ECS | BTA_AG_FEAT_ECC | \
BTA_AG_FEAT_ESCO_S4 | BTA_AG_FEAT_EXTERR)
#endif /* BT_HF_AG_BQB_INCLUDED */

/* feature mask that matches spec */
#define BTA_AG_BSRF_FEAT_SPEC (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | \
BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND | \
BTA_AG_FEAT_VTAG | BTA_AG_FEAT_REJECT | \
BTA_AG_FEAT_ECS | BTA_AG_FEAT_ECC | \
BTA_AG_FEAT_EXTERR | BTA_AG_FEAT_CODEC | \
BTA_AG_FEAT_ESCO_S4| BTA_AG_FEAT_VOIP)

#define BTA_AG_SDP_FEAT_SPEC (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | \
BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND | \
#define BTA_AG_BRSF_FEAT_SPEC (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | \
BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND | \
BTA_AG_FEAT_VTAG | BTA_AG_FEAT_REJECT | \
BTA_AG_FEAT_ECS | BTA_AG_FEAT_ECC | \
BTA_AG_FEAT_EXTERR | BTA_AG_FEAT_CODEC | \
BTA_AG_FEAT_ESCO_S4 | BTA_AG_FEAT_VOIP)

#define BTA_AG_SDP_FEAT_SPEC (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | \
BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND | \
BTA_AG_FEAT_VTAG)

enum
Expand Down
26 changes: 26 additions & 0 deletions components/bt/host/bluedroid/bta/hf_client/bta_hf_client_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "bta/bta_hf_client_api.h"
#include "bta_hf_client_int.h"

#if BT_HF_CLIENT_BQB_INCLUDED
static BOOLEAN s_bta_hf_client_bqb_clip_flag = TRUE;
#endif /* BT_HF_CLIENT_BQB_INCLUDED */

#if (BTA_HF_INCLUDED == TRUE)
/* uncomment to enable extra debug */
/* #define BTA_HF_CLIENT_DEBUG TRUE */
Expand Down Expand Up @@ -247,6 +251,21 @@ tBTA_HF_CLIENT_CB bta_hf_client_cb;
tBTA_HF_CLIENT_CB *bta_hf_client_cb_ptr;
#endif

/*******************************************************************************
**
** Function bta_hf_client_bqb_clip_ctrl
**
** Description Control if send the command AT+CLIP for BQB test
**
** Returns void
**
*******************************************************************************/
#if BT_HF_CLIENT_BQB_INCLUDED
void bta_hf_client_bqb_clip_ctrl(BOOLEAN enable)
{
s_bta_hf_client_bqb_clip_flag = enable;
}
#endif /* BT_HF_CLIENT_BQB_INCLUDED */

/*******************************************************************************
**
Expand Down Expand Up @@ -538,7 +557,14 @@ static void send_post_slc_cmd(void)
bta_hf_client_send_at_cmee(TRUE);
bta_hf_client_send_at_cops(FALSE);
bta_hf_client_send_at_btrh(TRUE, 0);

#if BT_HF_CLIENT_BQB_INCLUDED
if (s_bta_hf_client_bqb_clip_flag == TRUE) {
bta_hf_client_send_at_clip(TRUE);
}
#else
bta_hf_client_send_at_clip(TRUE);
#endif /* BT_HF_CLIENT_BQB_INCLUDED */
}

/*******************************************************************************
Expand Down
Loading

0 comments on commit 8008dbe

Please sign in to comment.