mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/btdm_add_set_pkt_data_length_evt_cback' into 'master'
component / bt: add set pkt data length event callback See merge request !869
This commit is contained in:
commit
fd12a6c706
@ -41,7 +41,9 @@ typedef enum {
|
||||
ESP_BT_STATUS_PENDING, /* relate to BT_STATUS_PENDING in bt_def.h */
|
||||
ESP_BT_STATUS_UNACCEPT_CONN_INTERVAL, /* relate to BT_UNACCEPT_CONN_INTERVAL in bt_def.h */
|
||||
ESP_BT_STATUS_PARAM_OUT_OF_RANGE, /* relate to BT_PARAM_OUT_OF_RANGE in bt_def.h */
|
||||
ESP_BT_STATUS_TIMEOUT, /* relate to BT_STATUS_TIMEOUT in bt_def.h */
|
||||
ESP_BT_STATUS_TIMEOUT, /* relate to BT_STATUS_TIMEOUT in bt_def.h */
|
||||
ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED, /* relate to BTM_PEER_LE_DATA_LEN_UNSUPPORTED in btm_api.h */
|
||||
ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* relate to BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED in btm_api.h */
|
||||
} esp_bt_status_t;
|
||||
|
||||
|
||||
|
@ -92,6 +92,7 @@ typedef enum {
|
||||
ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, /*!< When stop scan complete, the event comes */
|
||||
ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, /*!< When set the static rand address complete, the event comes */
|
||||
ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, /*!< When update connection parameters complete, the event comes */
|
||||
ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, /*!< When set pkt lenght complete, the event comes */
|
||||
} esp_gap_ble_cb_event_t;
|
||||
|
||||
/// Advertising data maximum length
|
||||
@ -273,6 +274,15 @@ typedef struct {
|
||||
Time Range: 100 msec to 32 seconds */
|
||||
} esp_ble_conn_update_params_t;
|
||||
|
||||
/**
|
||||
* @brief BLE pkt date length keys
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t rx_len; /*!< pkt rx data length value */
|
||||
uint16_t tx_len; /*!< pkt tx data length value */
|
||||
}esp_ble_pkt_data_length_params_t;
|
||||
|
||||
/**
|
||||
* @brief BLE encryption keys
|
||||
*/
|
||||
@ -522,6 +532,13 @@ typedef union {
|
||||
uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
|
||||
Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec */
|
||||
}update_conn_params; /*!< Event parameter of ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT
|
||||
*/
|
||||
struct ble_pkt_data_length_cmpl_evt_param {
|
||||
esp_bt_status_t status; /*!< Indicate the set pkt data length operation success status */
|
||||
esp_ble_pkt_data_length_params_t params; /*!< pkt data length value */
|
||||
} pkt_data_lenth_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT */
|
||||
} esp_ble_gap_cb_param_t;
|
||||
|
||||
/**
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "utl.h"
|
||||
#include "gap_api.h" /* For GAP_BleReadPeerPrefConnParams */
|
||||
#include <string.h>
|
||||
#include "controller.h"
|
||||
|
||||
#define LOG_TAG "bt_bta_dm"
|
||||
// #include "osi/include/log.h"
|
||||
@ -4794,9 +4795,25 @@ void bta_dm_ble_set_scan_rsp_raw (tBTA_DM_MSG *p_data)
|
||||
*******************************************************************************/
|
||||
void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data)
|
||||
{
|
||||
if (BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda,
|
||||
p_data->ble_set_data_length.tx_data_length) != BTM_SUCCESS) {
|
||||
tACL_CONN *p_acl_cb = btm_bda_to_acl(p_data->ble_set_data_length.remote_bda, BT_TRANSPORT_LE);
|
||||
if (p_acl_cb == NULL) {
|
||||
APPL_TRACE_ERROR("%s error: Invalid connection remote_bda.", __func__);
|
||||
return;
|
||||
} else {
|
||||
p_acl_cb->p_set_pkt_data_cback = p_data->ble_set_data_length.p_set_pkt_data_cback;
|
||||
}
|
||||
UINT8 status = BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda,
|
||||
p_data->ble_set_data_length.tx_data_length);
|
||||
if (status != BTM_SUCCESS) {
|
||||
APPL_TRACE_ERROR("%s failed\n", __FUNCTION__);
|
||||
if (p_data->ble_set_data_length.p_set_pkt_data_cback) {
|
||||
if (p_acl_cb->data_length_params.tx_len == 0){
|
||||
uint16_t length = controller_get_interface()->get_acl_data_size_ble();
|
||||
p_acl_cb->data_length_params.rx_len = length;
|
||||
p_acl_cb->data_length_params.tx_len = length;
|
||||
}
|
||||
(*p_data->ble_set_data_length.p_set_pkt_data_cback)(status, &p_acl_cb->data_length_params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2042,7 +2042,7 @@ void BTA_DmBleDisconnect(BD_ADDR bd_addr)
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length)
|
||||
void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback)
|
||||
{
|
||||
tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg;
|
||||
|
||||
@ -2051,6 +2051,7 @@ void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length)
|
||||
bdcpy(p_msg->remote_bda, remote_device);
|
||||
p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
|
||||
p_msg->tx_data_length = tx_data_length;
|
||||
p_msg->p_set_pkt_data_cback = p_set_pkt_data_cback;
|
||||
|
||||
bta_sys_sendmsg(p_msg);
|
||||
}
|
||||
|
@ -490,6 +490,7 @@ typedef struct {
|
||||
BT_HDR hdr;
|
||||
BD_ADDR remote_bda;
|
||||
UINT16 tx_data_length;
|
||||
tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback;
|
||||
} tBTA_DM_API_BLE_SET_DATA_LENGTH;
|
||||
|
||||
/* set the address for BLE device
|
||||
|
@ -402,6 +402,8 @@ typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status);
|
||||
|
||||
typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status);
|
||||
|
||||
typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK;
|
||||
|
||||
/* advertising channel map */
|
||||
#define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37
|
||||
#define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38
|
||||
@ -2228,7 +2230,7 @@ extern void BTA_DmBleDisconnect(BD_ADDR bd_addr);
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length);
|
||||
extern void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
@ -132,6 +132,27 @@ static esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status)
|
||||
return esp_status;
|
||||
}
|
||||
|
||||
static esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status)
|
||||
{
|
||||
esp_bt_status_t esp_status = ESP_BT_STATUS_FAIL;
|
||||
switch(btm_status){
|
||||
case BTM_SUCCESS:
|
||||
esp_status = ESP_BT_STATUS_SUCCESS;
|
||||
break;
|
||||
case BTM_PEER_LE_DATA_LEN_UNSUPPORTED:
|
||||
esp_status = ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED;
|
||||
break;
|
||||
case BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED:
|
||||
esp_status = ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED;
|
||||
break;
|
||||
default:
|
||||
esp_status = ESP_BT_STATUS_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return esp_status;
|
||||
}
|
||||
|
||||
static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DATA *bta_adv_data, uint32_t *data_mask)
|
||||
{
|
||||
uint32_t mask;
|
||||
@ -621,6 +642,25 @@ void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr,
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_len_params)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
bt_status_t ret;
|
||||
btc_msg_t msg;
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT;
|
||||
param.pkt_data_lenth_cmpl.status = btc_btm_status_to_esp_status(status);
|
||||
param.pkt_data_lenth_cmpl.params.rx_len = data_len_params->rx_len;
|
||||
param.pkt_data_lenth_cmpl.params.tx_len = data_len_params->tx_len;
|
||||
ret = btc_transfer_context(&msg, ¶m,
|
||||
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
static void btc_set_encryption_callback(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS enc_status)
|
||||
@ -674,7 +714,7 @@ static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int,
|
||||
latency, timeout, update_conn_param_cb);
|
||||
}
|
||||
|
||||
static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_length)
|
||||
static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback)
|
||||
{
|
||||
if (tx_data_length > BTM_BLE_DATA_SIZE_MAX) {
|
||||
tx_data_length = BTM_BLE_DATA_SIZE_MAX;
|
||||
@ -682,7 +722,7 @@ static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_len
|
||||
tx_data_length = BTM_BLE_DATA_SIZE_MIN;
|
||||
}
|
||||
|
||||
BTA_DmBleSetDataLength(remote_device, tx_data_length);
|
||||
BTA_DmBleSetDataLength(remote_device, tx_data_length, p_set_pkt_data_cback);
|
||||
}
|
||||
|
||||
static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
|
||||
@ -794,6 +834,9 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
|
||||
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||
btc_gap_ble_cb_to_app(ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, param);
|
||||
break;
|
||||
case ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT:
|
||||
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, param);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -948,7 +991,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
||||
btc_update_conn_param_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN:
|
||||
btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length);
|
||||
btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length, btc_set_pkt_length_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_RAND_ADDRESS: {
|
||||
BD_ADDR bd_addr;
|
||||
|
@ -136,6 +136,31 @@ UINT8 btm_handle_to_acl_index (UINT16 hci_handle)
|
||||
return (xx);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_handle_to_acl
|
||||
**
|
||||
** Description This function returns the FIRST acl_db entry for the passed hci_handle.
|
||||
**
|
||||
** Returns Returns pointer to the ACL DB for the requested BDA if found.
|
||||
** NULL if not found.
|
||||
**
|
||||
*******************************************************************************/
|
||||
tACL_CONN *btm_handle_to_acl (UINT16 hci_handle)
|
||||
{
|
||||
tACL_CONN *p = &btm_cb.acl_db[0];
|
||||
UINT8 xx;
|
||||
BTM_TRACE_DEBUG ("btm_handle_to_acl_index\n");
|
||||
for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) {
|
||||
if ((p->in_use) && (p->hci_handle == hci_handle)) {
|
||||
return(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* If here, no BD Addr found */
|
||||
return ((tACL_CONN *)NULL);
|
||||
}
|
||||
|
||||
#if BLE_PRIVACY_SPT == TRUE
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
@ -802,12 +802,12 @@ tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, UINT16 tx_pdu_length)
|
||||
|
||||
if (!controller_get_interface()->supports_ble_packet_extension()) {
|
||||
BTM_TRACE_ERROR("%s failed, request not supported", __FUNCTION__);
|
||||
return BTM_ILLEGAL_VALUE;
|
||||
return BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (!HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl->peer_le_features)) {
|
||||
BTM_TRACE_ERROR("%s failed, peer does not support request", __FUNCTION__);
|
||||
return BTM_ILLEGAL_VALUE;
|
||||
return BTM_PEER_LE_DATA_LEN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (p_acl != NULL) {
|
||||
|
@ -67,7 +67,9 @@ enum {
|
||||
BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set */
|
||||
BTM_FAILED_ON_SECURITY, /* 18 security failed */
|
||||
BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */
|
||||
BTM_MODE4_LEVEL4_NOT_SUPPORTED /* 20 Secure Connections Only Mode can't be supported */
|
||||
BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be supported */
|
||||
BTM_PEER_LE_DATA_LEN_UNSUPPORTED, /* 21 peer setting data length is unsupported*/
|
||||
BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED /* 22 controller setting data length is unsupported*/
|
||||
};
|
||||
|
||||
typedef uint8_t tBTM_STATUS;
|
||||
@ -129,6 +131,11 @@ enum {
|
||||
|
||||
typedef UINT8 tBTM_DEV_STATUS;
|
||||
|
||||
typedef struct {
|
||||
UINT16 rx_len;
|
||||
UINT16 tx_len;
|
||||
}tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS;
|
||||
|
||||
typedef struct {
|
||||
UINT16 min_conn_int;
|
||||
UINT16 max_conn_int;
|
||||
@ -166,6 +173,8 @@ typedef UINT8 (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc);
|
||||
|
||||
typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params);
|
||||
|
||||
typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params);
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
** DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
|
||||
|
@ -116,6 +116,8 @@ BD_ADDR active_remote_addr; /* remote address used on this connectio
|
||||
UINT8 active_remote_addr_type; /* local device address type for this connection */
|
||||
BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */
|
||||
tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb;
|
||||
tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback;
|
||||
tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params;
|
||||
#endif
|
||||
|
||||
} tACL_CONN;
|
||||
@ -932,6 +934,7 @@ void btm_cont_rswitch (tACL_CONN *p,
|
||||
UINT8 hci_status);
|
||||
|
||||
UINT8 btm_handle_to_acl_index (UINT16 hci_handle);
|
||||
tACL_CONN *btm_handle_to_acl (UINT16 hci_handle);
|
||||
void btm_read_link_policy_complete (UINT8 *p);
|
||||
void btm_read_rssi_complete (UINT8 *p);
|
||||
void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble);
|
||||
|
@ -1024,7 +1024,14 @@ void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len,
|
||||
p_lcb->tx_data_len = tx_data_len;
|
||||
}
|
||||
|
||||
/* ignore rx_data len for now */
|
||||
tACL_CONN *p_acl = btm_handle_to_acl(handle);
|
||||
if (p_acl != NULL && p_acl->p_set_pkt_data_cback){
|
||||
tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params;
|
||||
data_length_params.rx_len = tx_data_len;
|
||||
data_length_params.tx_len = rx_data_len;
|
||||
p_acl->data_length_params = data_length_params;
|
||||
(*p_acl->p_set_pkt_data_cback)(BTM_SUCCESS, &data_length_params);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user