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 f1168ec221..84c6890ef9 100644 --- a/components/bt/host/bluedroid/api/esp_gap_bt_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_bt_api.c @@ -375,4 +375,22 @@ esp_err_t esp_bt_gap_ssp_confirm_reply(esp_bd_addr_t bd_addr, bool accept) #endif /*(BT_SSP_INCLUDED == TRUE)*/ +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 aaf06a63b0..1fb7eedf7f 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 @@ -205,6 +205,7 @@ typedef enum { ESP_BT_GAP_READ_RSSI_DELTA_EVT, /*!< read rssi event */ ESP_BT_GAP_CONFIG_EIR_DATA_EVT, /*!< config EIR data 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; @@ -324,6 +325,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; /** @@ -652,6 +663,21 @@ esp_err_t esp_bt_gap_ssp_confirm_reply(esp_bd_addr_t bd_addr, bool accept); #endif /*(BT_SSP_INCLUDED == TRUE)*/ +/** +* @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 5ed7ded8ff..5b174bb1d1 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -1388,11 +1388,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 9317ea72a2..dff6cfce52 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 @@ -708,6 +708,37 @@ static void btc_gap_bt_config_eir(btc_gap_bt_args_t *arg) BTA_DmConfigEir(&eir_config); } +#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) { @@ -721,6 +752,7 @@ void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE: case BTC_GAP_BT_ACT_PIN_REPLY: case BTC_GAP_BT_ACT_SET_PIN_TYPE: + case BTC_GAP_BT_ACT_SET_QOS: break; #if (BT_SSP_INCLUDED == TRUE) case BTC_GAP_BT_ACT_PASSKEY_REPLY: @@ -784,6 +816,7 @@ void btc_gap_bt_arg_deep_free(btc_msg_t *msg) case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE: case BTC_GAP_BT_ACT_PIN_REPLY: case BTC_GAP_BT_ACT_SET_PIN_TYPE: + case BTC_GAP_BT_ACT_SET_QOS: break; #if (BT_SSP_INCLUDED == TRUE) case BTC_GAP_BT_ACT_PASSKEY_REPLY: @@ -873,6 +906,11 @@ void btc_gap_bt_call_handler(btc_msg_t *msg) btc_gap_bt_config_eir(arg); break; } + + case BTC_GAP_BT_ACT_SET_QOS: { + btc_gap_bt_set_qos(arg); + break; + } default: break; } @@ -912,6 +950,7 @@ void btc_gap_bt_cb_deep_free(btc_msg_t *msg) case BTC_GAP_BT_AUTH_CMPL_EVT: case BTC_GAP_BT_PIN_REQ_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: @@ -973,6 +1012,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 6ccc6d9aa7..d1b87d11ac 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 @@ -35,6 +35,7 @@ typedef enum { BTC_GAP_BT_READ_RSSI_DELTA_EVT, BTC_GAP_BT_CONFIG_EIR_DATA_EVT, BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT, + BTC_GAP_BT_QOS_EVT, }btc_gap_bt_evt_t; typedef enum { @@ -52,6 +53,7 @@ typedef enum { BTC_GAP_BT_ACT_PASSKEY_REPLY, BTC_GAP_BT_ACT_CONFIRM_REPLY, BTC_GAP_BT_ACT_CONFIG_EIR, + BTC_GAP_BT_ACT_SET_QOS, } btc_gap_bt_act_t; /* btc_bt_gap_args_t */ @@ -133,6 +135,13 @@ typedef union { struct config_eir_args { esp_bt_eir_data_t eir_data; } config_eir; + + // 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 cf53f93d06..b44d07892e 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 @@ -330,9 +330,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); @@ -345,9 +342,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 6fc1625b11..13b34c3ebb 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;