components/bt: Add QOS for SPP, to decrease the delay from slave to master

This commit is contained in:
baohongde 2020-12-23 16:21:19 +08:00
parent ecc2dd4b23
commit 567562a0fb
11 changed files with 152 additions and 2 deletions

View File

@ -96,6 +96,7 @@ if(CONFIG_BT_ENABLED)
"host/bluedroid/bta/dm/bta_dm_main.c"
"host/bluedroid/bta/dm/bta_dm_pm.c"
"host/bluedroid/bta/dm/bta_dm_sco.c"
"host/bluedroid/bta/dm/bta_dm_qos.c"
"host/bluedroid/bta/gatt/bta_gatt_common.c"
"host/bluedroid/bta/gatt/bta_gattc_act.c"
"host/bluedroid/bta/gatt/bta_gattc_api.c"

View File

@ -78,6 +78,10 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_pm_btm_status, /* BTA_DM_PM_BTM_STATUS_EVT */
bta_dm_pm_timer, /* BTA_DM_PM_TIMER_EVT */
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */
#if (BTA_DM_QOS_INCLUDED == TRUE)
/* Quality of Service set events */
bta_dm_set_qos, /* BTA_DM_API_QOS_SET_EVT */
#endif /* #if (BTA_DM_QOS_INCLUDED == TRUE) */
/* simple pairing events */
#if (SMP_INCLUDED == TRUE)
bta_dm_confirm, /* BTA_DM_API_CONFIRM_EVT */

View File

@ -0,0 +1,68 @@
/******************************************************************************
*
* Copyright (C) 2003-2012 Broadcom Corporation
*
* 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.
*
******************************************************************************/
/******************************************************************************
*
* This file contains the action functions for QoS state
* machine.
*
******************************************************************************/
#include "bta/bta_sys.h"
#include "bta/bta_api.h"
#include "bta_dm_int.h"
#include "stack/btm_api.h"
#include "osi/allocator.h"
#if (BTA_DM_QOS_INCLUDED == TRUE)
void bta_dm_set_qos(tBTA_DM_MSG *p_data)
{
FLOW_SPEC p_flow = {
.qos_flags = 0, /* TBD */
.service_type = GUARANTEED, /* see below */
.token_rate = 0, /* bytes/second */
.token_bucket_size = 0, /* bytes */
.peak_bandwidth = 0, /* bytes/second */
.latency = 625 * p_data->qos_set.t_poll, /* microseconds */
.delay_variation = 0xFFFFFFFF /* microseconds */
};
tBTM_STATUS status = BTM_SetQoS (p_data->qos_set.bd_addr, &p_flow, p_data->qos_set.p_cb);
if(status != BTM_CMD_STARTED) {
APPL_TRACE_ERROR("%s ERROR: 0x%x\n", __func__, status);
}
}
void BTA_DmSetQos(BD_ADDR bd_addr, UINT32 t_poll, tBTM_CMPL_CB *p_cb)
{
tBTA_DM_API_QOS_SET *p_msg;
if ((p_msg = (tBTA_DM_API_QOS_SET *) osi_malloc(sizeof(tBTA_DM_API_QOS_SET))) != NULL) {
p_msg->hdr.event = BTA_DM_API_QOS_SET_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->t_poll = t_poll;
p_msg->p_cb = p_cb;
bta_sys_sendmsg(p_msg);
}
}
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)

View File

@ -74,6 +74,10 @@ enum {
BTA_DM_PM_BTM_STATUS_EVT,
BTA_DM_PM_TIMER_EVT,
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */
#if (BTA_DM_QOS_INCLUDED == TRUE)
/* Quality of Service set events */
BTA_DM_API_QOS_SET_EVT,
#endif /* #if (BTA_DM_QOS_INCLUDED == TRUE) */
#if (SMP_INCLUDED == TRUE)
/* simple pairing events */
BTA_DM_API_CONFIRM_EVT,
@ -459,6 +463,16 @@ typedef struct {
} tBTA_DM_PM_TIMER;
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */
#if (BTA_DM_QOS_INCLUDED == TRUE)
/* data type for BTA_DM_API_QOS_SET_EVT */
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
UINT32 t_poll;
tBTM_CMPL_CB *p_cb;
} tBTA_DM_API_QOS_SET;
#endif /* #if (BTA_DM_QOS_INCLUDED == TRUE) */
/* data type for BTA_DM_API_ADD_DEVICE_EVT */
typedef struct {
BT_HDR hdr;
@ -887,6 +901,11 @@ typedef union {
tBTA_DM_PM_TIMER pm_timer;
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */
#if (BTA_DM_QOS_INCLUDED == TRUE)
/* Quality of Service set events */
tBTA_DM_API_QOS_SET qos_set;
#endif /* #if (BTA_DM_QOS_INCLUDED == TRUE) */
tBTA_DM_API_DI_DISC di_disc;
tBTA_DM_API_EXECUTE_CBACK exec_cback;
@ -1390,6 +1409,10 @@ extern void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data);
extern void bta_dm_pm_timer(tBTA_DM_MSG *p_data);
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */
#if (BTA_DM_QOS_INCLUDED == TRUE)
extern void bta_dm_set_qos(tBTA_DM_MSG *p_data);
#endif /* #if (BTA_DM_QOS_INCLUDED == TRUE) */
extern UINT8 bta_dm_get_av_count(void);
extern void bta_dm_search_start (tBTA_DM_MSG *p_data);
extern void bta_dm_search_cancel (tBTA_DM_MSG *p_data);

View File

@ -1399,6 +1399,11 @@ 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
*****************************************************************************/
@ -1510,6 +1515,20 @@ extern void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config);
*******************************************************************************/
void BTA_DmSetAfhChannels(const uint8_t *channels, tBTA_CMPL_CB *set_afh_cb);
#if (BTA_DM_QOS_INCLUDED == TRUE)
/*******************************************************************************
**
** Function BTA_DmSetQos
**
** Description This function sets the QOS
**
**
** Returns void
**
*******************************************************************************/
void BTA_DmSetQos(BD_ADDR bd_addr, UINT32 t_poll, tBTM_CMPL_CB *p_cb);
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)
#if (BLE_INCLUDED == TRUE)
/*******************************************************************************
**

View File

@ -326,6 +326,9 @@ 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);
@ -338,6 +341,9 @@ 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

@ -58,6 +58,7 @@
#define BTA_SDP_INCLUDED TRUE
#define BTA_DM_PM_INCLUDED TRUE
#define SDP_INCLUDED TRUE
#define BTA_DM_QOS_INCLUDED TRUE
#if (UC_BT_A2DP_ENABLED == TRUE)
#define BTA_AR_INCLUDED TRUE
@ -300,6 +301,10 @@
#define BTA_DM_PM_INCLUDED FALSE
#endif
#ifndef BTA_DM_QOS_INCLUDED
#define BTA_DM_QOS_INCLUDED FALSE
#endif
#ifndef BTA_PAN_INCLUDED
#define BTA_PAN_INCLUDED FALSE
#endif

View File

@ -1860,7 +1860,7 @@ tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
}
if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL) {
btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_QOS, BTM_DEV_REPLY_TIMEOUT);
btm_cb.devcb.p_qossu_cmpl_cb = p_cb;
if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type,
@ -1915,6 +1915,22 @@ void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
}
}
/*******************************************************************************
**
** Function btm_qos_setup_timeout
**
** Description This function processes a timeout.
** Currently, we just report an error log
**
** Returns void
**
*******************************************************************************/
void btm_qos_setup_timeout (void *p_tle)
{
BTM_TRACE_DEBUG ("%s\n", __func__);
btm_qos_setup_complete (HCI_ERR_HOST_TIMEOUT, 0, NULL);
}
/*******************************************************************************
**

View File

@ -1042,6 +1042,7 @@ void btm_sco_process_num_completed_pkts (UINT8 *p);
#define btm_sco_chk_pend_unpark(hci_status, hci_handle)
#endif /* BTM_SCO_INCLUDED */
void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow);
void btm_qos_setup_timeout (void *p_tle);
/* Internal functions provided by btm_sco.c

View File

@ -385,7 +385,10 @@ static void btu_general_alarm_process(void *param)
}
break;
default:;
case BTU_TTYPE_BTM_QOS:
btm_qos_setup_timeout(p_tle);
break;
default: {
int i = 0;
BOOLEAN handled = FALSE;
@ -400,6 +403,7 @@ static void btu_general_alarm_process(void *param)
}
break;
}
}
}
void btu_general_alarm_cb(void *data)

View File

@ -164,6 +164,9 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr);
#define BTU_TTYPE_UCD_TO 108
#define BTU_TTYPE_BLE_SCAN 109
/* BTU internal timer for QOS */
#define BTU_TTYPE_BTM_QOS 110
/* BTU Task Signal */
typedef enum {
SIG_BTU_START_UP = 0,