From f3c9a711389e5d262691e279d8b706c4e6df1644 Mon Sep 17 00:00:00 2001 From: baohongde Date: Mon, 4 Jan 2021 11:53:04 +0800 Subject: [PATCH] components/bt: Add API to config QoS --- .../bt/host/bluedroid/api/esp_gap_bt_api.c | 17 ++++++++ .../api/include/api/esp_gap_bt_api.h | 26 +++++++++++ .../host/bluedroid/bta/include/bta/bta_api.h | 5 --- .../btc/profile/std/gap/btc_gap_bt.c | 43 +++++++++++++++++++ .../btc/profile/std/include/btc_gap_bt.h | 8 ++++ .../bluedroid/btc/profile/std/spp/btc_spp.c | 6 --- .../bt/host/bluedroid/stack/btm/btm_acl.c | 4 ++ .../bt/host/bluedroid/stack/btu/btu_task.c | 10 ++--- .../bluedroid/stack/include/stack/btm_api.h | 1 + 9 files changed, 102 insertions(+), 18 deletions(-) diff --git a/components/bt/host/bluedroid/api/esp_gap_bt_api.c b/components/bt/host/bluedroid/api/esp_gap_bt_api.c index 5a1371408a..be91604363 100644 --- a/components/bt/host/bluedroid/api/esp_gap_bt_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_bt_api.c @@ -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 */ diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h index 211eb3d514..e354dcfc6d 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h @@ -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 diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index 46e6afcac0..5b8c9c526b 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -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 *****************************************************************************/ diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c index 69e433378f..06d3c8c35d 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c @@ -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, ¶m, 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; diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h index f8f05cde5f..d763d1611d 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h @@ -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); diff --git a/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c b/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c index 7641052796..c55633a89c 100644 --- a/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c +++ b/components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c @@ -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); diff --git a/components/bt/host/bluedroid/stack/btm/btm_acl.c b/components/bt/host/bluedroid/stack/btm/btm_acl.c index 94f7c965b0..ed5469aea2 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/host/bluedroid/stack/btm/btm_acl.c @@ -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; diff --git a/components/bt/host/bluedroid/stack/btu/btu_task.c b/components/bt/host/bluedroid/stack/btu/btu_task.c index 4f2d220851..e60fcfa43b 100644 --- a/components/bt/host/bluedroid/stack/btu/btu_task.c +++ b/components/bt/host/bluedroid/stack/btu/btu_task.c @@ -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) 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 0d2558ed75..6af1b3ba05 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_api.h @@ -765,6 +765,7 @@ typedef struct { FLOW_SPEC flow; UINT16 handle; UINT8 status; + BD_ADDR rem_bda; } tBTM_QOS_SETUP_CMPL;