components/bt: Add API to config QoS

This commit is contained in:
baohongde 2021-01-04 11:53:04 +08:00
parent 567562a0fb
commit f3c9a71138
9 changed files with 102 additions and 18 deletions

View File

@ -410,4 +410,21 @@ esp_err_t esp_bt_gap_read_remote_name(esp_bd_addr_t remote_bda)
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_bt_gap_set_qos(esp_bd_addr_t remote_bda, uint32_t t_poll)
{
btc_msg_t msg;
btc_gap_bt_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BT;
msg.act = BTC_GAP_BT_ACT_SET_QOS;
memcpy(&arg.set_qos.bda, remote_bda, sizeof(bt_bdaddr_t));
arg.set_qos.t_poll = t_poll;
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* #if BTC_GAP_BT_INCLUDED == TRUE */

View File

@ -211,6 +211,7 @@ typedef enum {
ESP_BT_GAP_SET_AFH_CHANNELS_EVT, /*!< set AFH channels event */
ESP_BT_GAP_READ_REMOTE_NAME_EVT, /*!< read Remote Name event */
ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT, /*!< remove bond device complete event */
ESP_BT_GAP_QOS_CMPL_EVT, /*!< QOS complete event */
ESP_BT_GAP_EVT_MAX,
} esp_bt_gap_cb_event_t;
@ -345,6 +346,16 @@ typedef union {
esp_bt_status_t status; /*!< Indicate the remove bond device operation success status */
}remove_bond_dev_cmpl; /*!< Event parameter of ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT */
/**
* @brief ESP_BT_GAP_QOS_CMPL_EVT
*/
struct qos_cmpl_param {
esp_bt_status_t stat; /*!< QoS status */
esp_bd_addr_t bda; /*!< remote bluetooth device address*/
uint32_t t_poll; /*!< poll interval, the maximum time between transmissions
which from the master to a particular slave on the ACL
logical transport. unit is 0.625ms. */
} qos_cmpl; /*!< QoS complete parameter struct */
} esp_bt_gap_cb_param_t;
/**
@ -701,6 +712,21 @@ esp_err_t esp_bt_gap_set_afh_channels(esp_bt_gap_afh_channels channels);
*/
esp_err_t esp_bt_gap_read_remote_name(esp_bd_addr_t remote_bda);
/**
* @brief Config Quality of service
*
* @param[in] remote_bda: The remote device's address
* @param[in] t_poll: Poll interval, the maximum time between transmissions
which from the master to a particular slave on the ACL
logical transport. unit is 0.625ms
*
* @return - ESP_OK : success
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
* - other : failed
*
*/
esp_err_t esp_bt_gap_set_qos(esp_bd_addr_t remote_bda, uint32_t t_poll);
#ifdef __cplusplus
}
#endif

View File

@ -1399,11 +1399,6 @@ typedef UINT8 tBTA_DM_LINK_TYPE;
#define ALLOW_ALL_FILTER 0x00
#define LOWEST_RSSI_VALUE 129
#if (BTA_DM_QOS_INCLUDED == TRUE)
#define BTA_DM_QOS_TPOLL_SPP 20
#define BTA_DM_QOS_TPOLL_DEFAULT 40
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)
/*****************************************************************************
** External Function Declarations
*****************************************************************************/

View File

@ -757,6 +757,37 @@ static void btc_gap_bt_read_remote_name(btc_gap_bt_args_t *arg)
BTA_DmGetRemoteName(arg->rmt_name_bda.address, btc_gap_bt_read_remote_name_cmpl_callback);
}
#if (BTA_DM_QOS_INCLUDED == TRUE)
static void btc_gap_bt_set_qos_cmpl_callback(void *p_data)
{
tBTM_QOS_SETUP_CMPL *result = (tBTM_QOS_SETUP_CMPL *)p_data;
esp_bt_gap_cb_param_t param;
btc_msg_t msg;
bt_status_t ret;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BT;
msg.act = BTC_GAP_BT_QOS_EVT;
param.qos_cmpl.stat = btc_btm_status_to_esp_status(result->status);
param.qos_cmpl.t_poll = result->flow.latency / 625;
memcpy(param.qos_cmpl.bda,result->rem_bda,BD_ADDR_LEN);
ret = btc_transfer_context(&msg, &param, sizeof(esp_bt_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)
static void btc_gap_bt_set_qos(btc_gap_bt_args_t *arg)
{
#if (BTA_DM_QOS_INCLUDED == TRUE)
BTA_DmSetQos(arg->set_qos.bda.address, arg->set_qos.t_poll, btc_gap_bt_set_qos_cmpl_callback);
#else
BTC_TRACE_ERROR("%s: QoS is not supported.\n",__func__);
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)
}
void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
switch (msg->act) {
@ -772,6 +803,7 @@ void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
case BTC_GAP_BT_ACT_SET_PIN_TYPE:
case BTC_GAP_BT_ACT_SET_AFH_CHANNELS:
case BTC_GAP_BT_ACT_READ_REMOTE_NAME:
case BTC_GAP_BT_ACT_SET_QOS:
break;
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_PASSKEY_REPLY:
@ -837,6 +869,7 @@ void btc_gap_bt_arg_deep_free(btc_msg_t *msg)
case BTC_GAP_BT_ACT_SET_PIN_TYPE:
case BTC_GAP_BT_ACT_SET_AFH_CHANNELS:
case BTC_GAP_BT_ACT_READ_REMOTE_NAME:
case BTC_GAP_BT_ACT_SET_QOS:
break;
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_PASSKEY_REPLY:
@ -935,6 +968,10 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
btc_gap_bt_read_remote_name(arg);
break;
}
case BTC_GAP_BT_ACT_SET_QOS: {
btc_gap_bt_set_qos(arg);
break;
}
default:
break;
}
@ -976,6 +1013,7 @@ void btc_gap_bt_cb_deep_free(btc_msg_t *msg)
case BTC_GAP_BT_SET_AFH_CHANNELS_EVT:
case BTC_GAP_BT_READ_REMOTE_NAME_EVT:
case BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT:
case BTC_GAP_BT_QOS_EVT:
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_CFM_REQ_EVT:
case BTC_GAP_BT_KEY_NOTIF_EVT:
@ -1047,6 +1085,11 @@ void btc_gap_bt_cb_handler(btc_msg_t *msg)
btc_gap_bt_cb_to_app(ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT,(esp_bt_gap_cb_param_t *)msg->arg);
break;
}
case BTC_GAP_BT_QOS_EVT:{
btc_gap_bt_cb_to_app(ESP_BT_GAP_QOS_CMPL_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break;
}
default:
BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act);
break;

View File

@ -37,6 +37,7 @@ typedef enum {
BTC_GAP_BT_SET_AFH_CHANNELS_EVT,
BTC_GAP_BT_READ_REMOTE_NAME_EVT,
BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT,
BTC_GAP_BT_QOS_EVT,
}btc_gap_bt_evt_t;
typedef enum {
@ -56,6 +57,7 @@ typedef enum {
BTC_GAP_BT_ACT_CONFIG_EIR,
BTC_GAP_BT_ACT_SET_AFH_CHANNELS,
BTC_GAP_BT_ACT_READ_REMOTE_NAME,
BTC_GAP_BT_ACT_SET_QOS,
} btc_gap_bt_act_t;
/* btc_bt_gap_args_t */
@ -146,6 +148,12 @@ typedef union {
// BTC_GAP_BT_ACT_READ_REMOTE_NAME
bt_bdaddr_t rmt_name_bda;
// BTC_GAP_BT_ACT_SET_QOS
struct set_qos_args {
bt_bdaddr_t bda;
uint32_t t_poll;
} set_qos;
} btc_gap_bt_args_t;
void btc_gap_bt_call_handler(btc_msg_t *msg);

View File

@ -326,9 +326,6 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
slot_new->rfc_handle = p_data->rfc_srv_open.new_listen_handle;
slot_new->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_data->rfc_srv_open.new_listen_handle);
}
#if (BTA_DM_QOS_INCLUDED == TRUE)
BTA_DmSetQos(slot->addr, BTA_DM_QOS_TPOLL_SPP, NULL);
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)
break;
case BTA_JV_RFCOMM_OPEN_EVT:
slot = spp_find_slot_by_id(id);
@ -341,9 +338,6 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
slot->rfc_handle = p_data->rfc_open.handle;
slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_data->rfc_open.handle);
BTA_JvSetPmProfile(p_data->rfc_open.handle, BTA_JV_PM_ID_1, BTA_JV_CONN_OPEN);
#if (BTA_DM_QOS_INCLUDED == TRUE)
BTA_DmSetQos(slot->addr, BTA_DM_QOS_TPOLL_SPP, NULL);
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)
break;
case BTA_JV_RFCOMM_CLOSE_EVT:
slot = spp_find_slot_by_id(id);

View File

@ -1901,6 +1901,10 @@ void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL));
qossu.status = status;
qossu.handle = handle;
tACL_CONN *p = btm_handle_to_acl(handle);
if (p != NULL) {
memcpy (qossu.rem_bda, p->remote_addr, BD_ADDR_LEN);
}
if (p_flow != NULL) {
qossu.flow.qos_flags = p_flow->qos_flags;
qossu.flow.service_type = p_flow->service_type;

View File

@ -388,22 +388,18 @@ static void btu_general_alarm_process(void *param)
case BTU_TTYPE_BTM_QOS:
btm_qos_setup_timeout(p_tle);
break;
default: {
int i = 0;
BOOLEAN handled = FALSE;
for (; !handled && i < BTU_MAX_REG_TIMER; i++) {
default:
for (int i = 0; i < BTU_MAX_REG_TIMER; i++) {
if (btu_cb.timer_reg[i].timer_cb == NULL) {
continue;
}
if (btu_cb.timer_reg[i].p_tle == p_tle) {
btu_cb.timer_reg[i].timer_cb(p_tle);
handled = TRUE;
break;
}
}
break;
}
}
}
void btu_general_alarm_cb(void *data)

View File

@ -765,6 +765,7 @@ typedef struct {
FLOW_SPEC flow;
UINT16 handle;
UINT8 status;
BD_ADDR rem_bda;
} tBTM_QOS_SETUP_CMPL;