mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Component/bt: add new api to get connection parameters
This commit is contained in:
parent
0521296264
commit
76b3a64b76
@ -706,6 +706,17 @@ esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_params_t *conn_params)
|
||||
{
|
||||
if(!bd_addr || !conn_params) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if(BTM_GetCurrentConnParams(bd_addr, &conn_params->interval, &conn_params->latency, &conn_params->timeout)) {
|
||||
return ESP_OK;
|
||||
}
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -377,6 +377,15 @@ typedef struct {
|
||||
advertising reports for each packet received */
|
||||
} esp_ble_scan_params_t;
|
||||
|
||||
/// connection parameters information
|
||||
typedef struct {
|
||||
uint16_t interval; /*!< connection interval */
|
||||
uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
|
||||
uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
|
||||
Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec
|
||||
Time Range: 100 msec to 32 seconds */
|
||||
} esp_gap_conn_params_t;
|
||||
|
||||
/// Connection update parameters
|
||||
typedef struct {
|
||||
esp_bd_addr_t bda; /*!< Bluetooth device address */
|
||||
@ -1233,6 +1242,19 @@ esp_err_t esp_ble_oob_req_reply(esp_bd_addr_t bd_addr, uint8_t *TK, uint8_t len)
|
||||
*/
|
||||
esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device);
|
||||
|
||||
/**
|
||||
* @brief This function is called to read the connection
|
||||
* parameters information of the device
|
||||
*
|
||||
* @param[in] bd_addr: BD address of the peer device.
|
||||
* @param[out] conn_params: the connection parameters information
|
||||
*
|
||||
* @return - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_params_t *conn_params);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -387,6 +387,17 @@ typedef enum {
|
||||
ESP_GATT_WRITE_TYPE_RSP, /*!< Gatt write attribute need remote response */
|
||||
} esp_gatt_write_type_t;
|
||||
|
||||
/**
|
||||
* @brief Connection parameters information
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t interval; /*!< connection interval */
|
||||
uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
|
||||
uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
|
||||
Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec
|
||||
Time Range: 100 msec to 32 seconds */
|
||||
} esp_gatt_conn_params_t;
|
||||
|
||||
#define ESP_GATT_IF_NONE 0xff /*!< If callback report gattc_if/gatts_if as this macro, means this event is not correspond to any app */
|
||||
|
||||
typedef uint8_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */
|
||||
|
@ -210,6 +210,7 @@ typedef union {
|
||||
struct gattc_connect_evt_param {
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
esp_gatt_conn_params_t conn_params; /*!< current connection parameters */
|
||||
} connect; /*!< Gatt client callback param of ESP_GATTC_CONNECT_EVT */
|
||||
|
||||
/**
|
||||
|
@ -197,6 +197,7 @@ typedef union {
|
||||
struct gatts_connect_evt_param {
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
esp_gatt_conn_params_t conn_params; /*!< current Connection parameters */
|
||||
} connect; /*!< Gatt server callback param of ESP_GATTS_CONNECT_EVT */
|
||||
|
||||
/**
|
||||
|
@ -729,7 +729,7 @@ void bta_gattc_conncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data)
|
||||
if (p_rcb) {
|
||||
bta_gattc_send_connect_cback(p_rcb,
|
||||
p_data->int_conn.remote_bda,
|
||||
p_data->int_conn.hdr.layer_specific);
|
||||
p_data->int_conn.hdr.layer_specific, p_data->int_conn.conn_params);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1654,6 +1654,16 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
|
||||
|
||||
p_buf->int_conn.hdr.event = connected ? BTA_GATTC_INT_CONN_EVT :
|
||||
BTA_GATTC_INT_DISCONN_EVT;
|
||||
if(p_buf->int_conn.hdr.event == BTA_GATTC_INT_CONN_EVT) {
|
||||
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE);
|
||||
if(p_lcb != NULL) {
|
||||
p_buf->int_conn.conn_params.interval = p_lcb->current_used_conn_interval;
|
||||
p_buf->int_conn.conn_params.latency = p_lcb->current_used_conn_latency;
|
||||
p_buf->int_conn.conn_params.timeout = p_lcb->current_used_conn_timeout;
|
||||
} else {
|
||||
APPL_TRACE_WARNING("%s not found connection parameters of the device ", __func__);
|
||||
}
|
||||
}
|
||||
p_buf->int_conn.hdr.layer_specific = conn_id;
|
||||
p_buf->int_conn.client_if = gattc_if;
|
||||
p_buf->int_conn.role = L2CA_GetBleConnRole(bda);
|
||||
|
@ -738,7 +738,7 @@ void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status
|
||||
** Returns
|
||||
**
|
||||
*******************************************************************************/
|
||||
void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id)
|
||||
void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id, tBTA_GATT_CONN_PARAMS conn_params)
|
||||
{
|
||||
tBTA_GATTC cb_data;
|
||||
|
||||
@ -747,6 +747,9 @@ void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda,
|
||||
|
||||
cb_data.connect.client_if = p_clreg->client_if;
|
||||
cb_data.connect.conn_id = conn_id;
|
||||
cb_data.connect.conn_params.interval = conn_params.interval;
|
||||
cb_data.connect.conn_params.latency = conn_params.latency;
|
||||
cb_data.connect.conn_params.timeout = conn_params.timeout;
|
||||
bdcpy(cb_data.connect.remote_bda, remote_bda);
|
||||
|
||||
(*p_clreg->p_cback)(BTA_GATTC_CONNECT_EVT, &cb_data);
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "stack/btm_ble_api.h"
|
||||
#include <string.h>
|
||||
#include "osi/allocator.h"
|
||||
#include "l2c_int.h"
|
||||
|
||||
static void bta_gatts_nv_save_cback(BOOLEAN is_saved, tGATTS_HNDL_RANGE *p_hndl_range);
|
||||
static BOOLEAN bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ *p_req,
|
||||
@ -965,7 +966,7 @@ static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
|
||||
BOOLEAN connected, tGATT_DISCONN_REASON reason,
|
||||
tGATT_TRANSPORT transport)
|
||||
{
|
||||
tBTA_GATTS cb_data;
|
||||
tBTA_GATTS cb_data = {0};
|
||||
UINT8 evt = connected ? BTA_GATTS_CONNECT_EVT : BTA_GATTS_DISCONNECT_EVT;
|
||||
tBTA_GATTS_RCB *p_reg;
|
||||
|
||||
@ -993,7 +994,16 @@ static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
|
||||
bta_sys_conn_close( BTA_ID_GATTS , BTA_ALL_APP_ID, bda);
|
||||
}
|
||||
}
|
||||
|
||||
if(evt == BTA_GATTS_CONNECT_EVT) {
|
||||
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE);
|
||||
if(p_lcb != NULL) {
|
||||
cb_data.conn.conn_params.interval = p_lcb->current_used_conn_interval;
|
||||
cb_data.conn.conn_params.latency = p_lcb->current_used_conn_latency;
|
||||
cb_data.conn.conn_params.timeout = p_lcb->current_used_conn_timeout;
|
||||
}else {
|
||||
APPL_TRACE_WARNING("%s not found connection parameters of the device ", __func__);
|
||||
}
|
||||
}
|
||||
cb_data.conn.conn_id = conn_id;
|
||||
cb_data.conn.server_if = gatt_if;
|
||||
cb_data.conn.reason = reason;
|
||||
|
@ -216,6 +216,7 @@ typedef struct {
|
||||
tBT_TRANSPORT transport;
|
||||
tGATT_DISCONN_REASON reason;
|
||||
BOOLEAN already_connect;
|
||||
tBTA_GATT_CONN_PARAMS conn_params;
|
||||
} tBTA_GATTC_INT_CONN;
|
||||
|
||||
typedef struct {
|
||||
@ -467,7 +468,7 @@ extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *
|
||||
extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data);
|
||||
extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
|
||||
BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport, UINT16 mtu);
|
||||
extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id);
|
||||
extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id, tBTA_GATT_CONN_PARAMS conn_params);
|
||||
extern void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason,
|
||||
BD_ADDR remote_bda, UINT16 conn_id);
|
||||
extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
|
||||
|
@ -201,6 +201,12 @@ typedef struct {
|
||||
UINT8 name_spc; /* The name space of the description */
|
||||
} tBTA_GATT_CHAR_PRES;
|
||||
|
||||
typedef struct {
|
||||
UINT16 interval;
|
||||
UINT16 latency;
|
||||
UINT16 timeout;
|
||||
} tBTA_GATT_CONN_PARAMS;
|
||||
|
||||
#define BTA_GATT_CLT_CONFIG_NONE GATT_CLT_CONFIG_NONE /* 0x0000 */
|
||||
#define BTA_GATT_CLT_CONFIG_NOTIFICATION GATT_CLT_CONFIG_NOTIFICATION /* 0x0001 */
|
||||
#define BTA_GATT_CLT_CONFIG_INDICATION GATT_CLT_CONFIG_INDICATION /* 0x0002 */
|
||||
@ -403,6 +409,7 @@ typedef struct {
|
||||
UINT16 conn_id;
|
||||
tBTA_GATTC_IF client_if;
|
||||
BD_ADDR remote_bda;
|
||||
tBTA_GATT_CONN_PARAMS conn_params;
|
||||
} tBTA_GATTC_CONNECT;
|
||||
|
||||
typedef struct {
|
||||
@ -610,6 +617,7 @@ typedef struct {
|
||||
UINT16 conn_id;
|
||||
tBTA_GATT_REASON reason; /* report disconnect reason */
|
||||
tBTA_GATT_TRANSPORT transport;
|
||||
tBTA_GATT_CONN_PARAMS conn_params;
|
||||
} tBTA_GATTS_CONN;
|
||||
|
||||
typedef struct {
|
||||
|
@ -901,6 +901,9 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
|
||||
gattc_if = connect->client_if;
|
||||
param.connect.conn_id = BTC_GATT_GET_CONN_ID(connect->conn_id);
|
||||
memcpy(param.connect.remote_bda, connect->remote_bda, sizeof(esp_bd_addr_t));
|
||||
param.connect.conn_params.interval = connect->conn_params.interval;
|
||||
param.connect.conn_params.latency = connect->conn_params.latency;
|
||||
param.connect.conn_params.timeout = connect->conn_params.timeout;
|
||||
btc_gattc_cb_to_app(ESP_GATTC_CONNECT_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
|
@ -901,7 +901,9 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
|
||||
gatts_if = p_data->conn.server_if;
|
||||
param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
|
||||
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
|
||||
|
||||
param.connect.conn_params.interval = p_data->conn.conn_params.interval;
|
||||
param.connect.conn_params.latency = p_data->conn.conn_params.latency;
|
||||
param.connect.conn_params.timeout = p_data->conn.conn_params.timeout;
|
||||
btc_gatts_cb_to_app(ESP_GATTS_CONNECT_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_DISCONNECT_EVT:
|
||||
|
@ -2732,4 +2732,35 @@ void btm_ble_set_keep_rfu_in_auth_req(BOOLEAN keep_rfu)
|
||||
|
||||
#endif /* BTM_BLE_CONFORMANCE_TESTING */
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_get_current_conn_params
|
||||
**
|
||||
** Description This function is called to get current connection parameters
|
||||
** information of the device
|
||||
**
|
||||
** Returns TRUE if the information is geted, else FALSE
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
BOOLEAN btm_get_current_conn_params(BD_ADDR bda, UINT16 *interval, UINT16 *latency, UINT16 *timeout)
|
||||
{
|
||||
if( (interval == NULL) || (latency == NULL) || (timeout == NULL) ) {
|
||||
BTM_TRACE_ERROR("%s invalid parameters ", __func__);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE);
|
||||
if(p_lcb != NULL) {
|
||||
(*interval) = p_lcb->current_used_conn_interval;
|
||||
(*latency) = p_lcb->current_used_conn_latency;
|
||||
(*timeout) = p_lcb->current_used_conn_timeout;
|
||||
return TRUE;
|
||||
}
|
||||
BTM_TRACE_WARNING("%s Device is not connected", __func__);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
#endif /* BLE_INCLUDED */
|
||||
|
@ -2045,6 +2045,31 @@ void BTM_Recovery_Pre_State(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_GetCurrentConnParams
|
||||
**
|
||||
** Description This function is called to read the current connection parameters
|
||||
** of the device
|
||||
**
|
||||
** Returns TRUE or FALSE
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
BOOLEAN BTM_GetCurrentConnParams(BD_ADDR bda, uint16_t *interval, uint16_t *latency, uint16_t *timeout)
|
||||
{
|
||||
if( (interval == NULL) || (latency == NULL) || (timeout == NULL) ) {
|
||||
BTM_TRACE_ERROR("%s error ", __func__);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(btm_get_current_conn_params(bda, interval, latency, timeout)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_ble_build_adv_data
|
||||
|
@ -506,6 +506,8 @@ void btm_set_random_address(BD_ADDR random_bda);
|
||||
void btm_ble_set_keep_rfu_in_auth_req(BOOLEAN keep_rfu);
|
||||
#endif
|
||||
|
||||
BOOLEAN btm_get_current_conn_params(BD_ADDR bda, UINT16 *interval, UINT16 *latency, UINT16 *timeout);
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -2099,6 +2099,19 @@ tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, UINT16 tx_pdu_length);
|
||||
*******************************************************************************/
|
||||
|
||||
tBTM_STATUS BTM_UpdateBleDuplicateExceptionalList(uint8_t subcode, uint32_t type, BD_ADDR device_info, tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK update_exceptional_list_cmp_cb);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_GetCurrentConnParams
|
||||
**
|
||||
** Description This function is called to read the current connection parameters
|
||||
** of the device
|
||||
**
|
||||
** Returns TRUE or FALSE
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
BOOLEAN BTM_GetCurrentConnParams(BD_ADDR bda, uint16_t *interval, uint16_t *latency, uint16_t *timeout);
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user