Merge branch 'bugfix/fix_ble_creat_conn_fail_enh_v5.4' into 'release/v5.4'

fix(ble/bluedroid): Fixed BLE create connection fail because of invalid own address type (v5.4)

See merge request espressif/esp-idf!35019
This commit is contained in:
Jiang Jiang Jian 2024-11-29 23:40:55 +08:00
commit 3f63fd91ec
34 changed files with 606 additions and 197 deletions

View File

@ -1931,7 +1931,7 @@ esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path)
return ESP_OK;
}
esp_err_t esp_ble_scan_dupilcate_list_flush(void)
esp_err_t esp_ble_scan_duplicate_list_flush(void)
{
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
@ -1940,6 +1940,11 @@ esp_err_t esp_ble_scan_dupilcate_list_flush(void)
return ESP_OK;
}
esp_err_t esp_ble_scan_dupilcate_list_flush(void)
{
return esp_ble_scan_duplicate_list_flush();
}
/**
* This function re-write controller's function,
* As coredump can not show parameters in function which is in a .a file.

View File

@ -260,7 +260,6 @@ extern int API_vhci_host_register_callback(const vhci_host_callback_t *callback)
extern int ble_txpwr_set(int power_type, uint16_t handle, int power_level);
extern int ble_txpwr_get(int power_type, uint16_t handle);
extern uint16_t l2c_ble_link_get_tx_buf_num(void);
extern void coex_pti_v2(void);
extern bool btdm_deep_sleep_mem_init(void);
@ -1877,11 +1876,6 @@ int IRAM_ATTR esp_bt_h4tl_eif_io_event_notify(int event)
return btdm_hci_tl_io_event_post(event);
}
uint16_t esp_bt_get_tx_buf_num(void)
{
return l2c_ble_link_get_tx_buf_num();
}
static void coex_wifi_sleep_set_hook(bool sleep)
{

View File

@ -1198,6 +1198,7 @@ uint16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
{
tBTA_BLE_CONN_PARAMS conn_1m_param = {0};
uint8_t zero[6] = {0};
int i;
@ -1251,10 +1252,14 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
* Slave_latency: 0x0
* Supervision_timeout: 1s
*/
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr.val, 0x18, 0x18, 0x00, 0x64);
conn_1m_param.interval_min = 0x18;
conn_1m_param.interval_max = 0x18;
conn_1m_param.latency = 0;
conn_1m_param.supervision_timeout = 0x64;
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE,
BTA_BLE_PHY_1M_MASK, &conn_1m_param, NULL, NULL);
return 0;
}

View File

@ -1217,19 +1217,23 @@ config BT_BLE_RPA_TIMEOUT
Default is 900 s (15 minutes). Range is 1 s to 1 hour (3600 s).
config BT_BLE_50_FEATURES_SUPPORTED
bool "Enable BLE 5.0 features"
bool "Enable BLE 5.0 features(please disable BLE 4.2 if enable BLE 5.0)"
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_50_SUPPORTED) || BT_CONTROLLER_DISABLED))
default y
help
Enabling this option activates BLE 5.0 features.
This option is universally supported in chips that support BLE, except for ESP32.
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
config BT_BLE_42_FEATURES_SUPPORTED
bool "Enable BLE 4.2 features"
bool "Enable BLE 4.2 features(please disable BLE 5.0 if enable BLE 4.2)"
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_SUPPORTED) || BT_CONTROLLER_DISABLED))
default n
help
This enables BLE 4.2 features.
This option is universally supported by all ESP chips with BLE capabilities.
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
bool "Enable BLE periodic advertising sync transfer feature"

View File

@ -67,46 +67,134 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t *creat_conn_params)
{
btc_msg_t msg = {0};
btc_ble_gattc_args_t arg;
const esp_ble_conn_params_t *conn_params;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (!creat_conn_params) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_OPEN;
arg.open.gattc_if = gattc_if;
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = remote_addr_type;
arg.open.is_direct = is_direct;
arg.open.is_aux = false;
memcpy(arg.open.remote_bda, creat_conn_params->remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = creat_conn_params->remote_addr_type;
arg.open.is_direct = creat_conn_params->is_direct;
arg.open.is_aux= creat_conn_params->is_aux;
arg.open.own_addr_type = creat_conn_params->own_addr_type;
arg.open.phy_mask = creat_conn_params->phy_mask;
// If not aux open, shouldn't set 2M and coded PHY connection params
if (!creat_conn_params->is_aux &&
((creat_conn_params->phy_mask & ESP_BLE_PHY_2M_PREF_MASK) ||
(creat_conn_params->phy_mask & ESP_BLE_PHY_CODED_PREF_MASK))) {
return ESP_ERR_INVALID_ARG;
}
if (creat_conn_params->phy_mask & ESP_BLE_PHY_1M_PREF_MASK) {
if (!creat_conn_params->phy_1m_conn_params) {
return ESP_ERR_INVALID_ARG;
}
conn_params = creat_conn_params->phy_1m_conn_params;
if (ESP_BLE_IS_VALID_PARAM(conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
ESP_BLE_IS_VALID_PARAM(conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
ESP_BLE_IS_VALID_PARAM(conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
(conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX) &&
((conn_params->supervision_timeout * 10) >= ((1 + conn_params->latency) * ((conn_params->interval_max * 5) >> 1))) &&
(conn_params->interval_min <= conn_params->interval_max)) {
memcpy(&arg.open.phy_1m_conn_params, conn_params, sizeof(esp_ble_conn_params_t));
} else {
LOG_ERROR("%s, invalid 1M PHY connection params: min_int = %d, max_int = %d, latency = %d, timeout = %d", __func__,
conn_params->interval_min,
conn_params->interval_max,
conn_params->latency,
conn_params->supervision_timeout);
return ESP_ERR_INVALID_ARG;
}
}
if (creat_conn_params->phy_mask & ESP_BLE_PHY_2M_PREF_MASK) {
if (!creat_conn_params->phy_2m_conn_params) {
return ESP_ERR_INVALID_ARG;
}
conn_params = creat_conn_params->phy_2m_conn_params;
if (ESP_BLE_IS_VALID_PARAM(conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
ESP_BLE_IS_VALID_PARAM(conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
ESP_BLE_IS_VALID_PARAM(conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
(conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX) &&
((conn_params->supervision_timeout * 10) >= ((1 + conn_params->latency) * ((conn_params->interval_max * 5) >> 1))) &&
(conn_params->interval_min <= conn_params->interval_max)) {
memcpy(&arg.open.phy_2m_conn_params, conn_params, sizeof(esp_ble_conn_params_t));
} else {
LOG_ERROR("%s, invalid 2M PHY connection params: min_int = %d, max_int = %d, latency = %d, timeout = %d", __func__,
conn_params->interval_min,
conn_params->interval_max,
conn_params->latency,
conn_params->supervision_timeout);
return ESP_ERR_INVALID_ARG;
}
}
if (creat_conn_params->phy_mask & ESP_BLE_PHY_CODED_PREF_MASK) {
if (!creat_conn_params->phy_coded_conn_params) {
return ESP_ERR_INVALID_ARG;
}
conn_params = creat_conn_params->phy_coded_conn_params;
if (ESP_BLE_IS_VALID_PARAM(conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
ESP_BLE_IS_VALID_PARAM(conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
ESP_BLE_IS_VALID_PARAM(conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
(conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX) &&
((conn_params->supervision_timeout * 10) >= ((1 + conn_params->latency) * ((conn_params->interval_max * 5) >> 1))) &&
(conn_params->interval_min <= conn_params->interval_max)) {
memcpy(&arg.open.phy_coded_conn_params, conn_params, sizeof(esp_ble_conn_params_t));
} else {
LOG_ERROR("%s, invalid Coded PHY connection params: min_int = %d, max_int = %d, latency = %d, timeout = %d", __func__,
conn_params->interval_min,
conn_params->interval_max,
conn_params->latency,
conn_params->supervision_timeout);
return ESP_ERR_INVALID_ARG;
}
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
{
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(creat_conn_params.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = remote_addr_type;
creat_conn_params.is_direct = is_direct;
creat_conn_params.is_aux = false;
creat_conn_params.own_addr_type = 0xff; //undefined, will use local value
creat_conn_params.phy_mask = 0x0;
return esp_ble_gattc_enh_open(gattc_if, &creat_conn_params);
}
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
#if (BLE_50_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_AUX_OPEN;
arg.open.gattc_if = gattc_if;
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = remote_addr_type;
arg.open.is_direct = is_direct;
arg.open.is_aux = true;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(creat_conn_params.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = remote_addr_type;
creat_conn_params.is_direct = is_direct;
creat_conn_params.is_aux = true;
creat_conn_params.own_addr_type = 0xff; //undefined, will use local value
creat_conn_params.phy_mask = 0x0;
return esp_ble_gattc_enh_open(gattc_if, &creat_conn_params);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)

View File

@ -145,6 +145,25 @@ typedef uint8_t esp_link_key[ESP_BT_OCTET16_LEN]; /* Link Key */
#define ESP_BLE_CONN_SUP_TOUT_MIN 0x000A /*!< relate to BTM_BLE_CONN_SUP_TOUT_MIN in stack/btm_ble_api.h */
#define ESP_BLE_CONN_SUP_TOUT_MAX 0x0C80 /*!< relate to ESP_BLE_CONN_SUP_TOUT_MAX in stack/btm_ble_api.h */
#define ESP_BLE_PHY_1M_PREF_MASK (1 << 0) /*!< The Host prefers use the LE1M transmitter or receiver PHY */
#define ESP_BLE_PHY_2M_PREF_MASK (1 << 1) /*!< The Host prefers use the LE2M transmitter or receiver PHY */
#define ESP_BLE_PHY_CODED_PREF_MASK (1 << 2) /*!< The Host prefers use the LE CODED transmitter or receiver PHY */
typedef uint8_t esp_ble_phy_mask_t;
/**
* @brief create connection parameters
*/
typedef struct {
uint16_t scan_interval; /*!< Initial scan interval, in units of 0.625ms, the range is 0x0004(2.5ms) to 0xFFFF(10.24s). */
uint16_t scan_window; /*!< Initial scan window, in units of 0.625ms, the range is 0x0004(2.5ms) to 0xFFFF(10.24s). */
uint16_t interval_min; /*!< Minimum connection interval, in units of 1.25ms, the range is 0x0006(7.5ms) to 0x0C80(4s). */
uint16_t interval_max; /*!< Maximum connection interval, in units of 1.25ms, the range is 0x0006(7.5ms) to 0x0C80(4s). */
uint16_t latency; /*!< Connection latency, the range is 0x0000(0) to 0x01F3(499). */
uint16_t supervision_timeout; /*!< Connection supervision timeout, in units of 10ms, the range is from 0x000A(100ms) to 0x0C80(32s). */
uint16_t min_ce_len; /*!< Minimum connection event length, in units of 0.625ms, setting to 0 for no preferred parameters. */
uint16_t max_ce_len; /*!< Maximum connection event length, in units of 0.625ms, setting to 0 for no preferred parameters. */
} esp_ble_conn_params_t;
/// Check the param is valid or not
#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) )

View File

@ -682,6 +682,19 @@ typedef struct {
esp_bt_uuid_t uuid; /*!< Included service UUID. */
} esp_gattc_incl_svc_elem_t;
/** @brief Represents a creat connection element. */
typedef struct {
esp_bd_addr_t remote_bda; /*!< The Bluetooth address of the remote device */
esp_ble_addr_type_t remote_addr_type; /*!< Address type of the remote device */
bool is_direct; /*!< Direct connection or background auto connection(by now, background auto connection is not supported */
bool is_aux; /*!< Set to true for BLE 5.0 or higher to enable auxiliary connections; set to false for BLE 4.2 or lower. */
esp_ble_addr_type_t own_addr_type; /*!< Specifies the address type used in the connection request. Set to 0xFF if the address type is unknown. */
esp_ble_phy_mask_t phy_mask; /*!< Indicates which PHY connection parameters will be used. When is_aux is false, only the connection params for 1M PHY can be specified */
const esp_ble_conn_params_t *phy_1m_conn_params; /*!< Connection parameters for the LE 1M PHY */
const esp_ble_conn_params_t *phy_2m_conn_params; /*!< Connection parameters for the LE 2M PHY */
const esp_ble_conn_params_t *phy_coded_conn_params; /*!< Connection parameters for the LE Coded PHY */
} esp_ble_gatt_creat_conn_params_t;
#ifdef __cplusplus
}
#endif

View File

@ -314,7 +314,20 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
*/
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
#if (BLE_42_FEATURE_SUPPORT == TRUE)
/**
* @brief Open a direct connection or add a background auto connection.
* Note: Do not enable both BLE_42_FEATURE_SUPPORT and BLE_50_FEATURE_SUPPORT configuration options simultaneously.
*
* @param[in] gattc_if: GATT client access interface.
* @param[in] esp_gatt_create_conn: Pointer to the structure containing connection parameters.
*
* @return
* - ESP_OK: Operation successful
* - others: Operation failed
*
*/
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t *esp_gatt_create_conn);
/**
* @brief Open a direct connection or add a background auto connection
*
@ -328,12 +341,14 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
* - other: failed
*
*/
#if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
#if (BLE_50_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
/**
* @brief Close the virtual connection to the GATT server. gattc may have multiple virtual GATT server connections when multiple app_id registered,
* this API only close one virtual GATT server connection. if there exist other virtual GATT server connections,

View File

@ -6049,7 +6049,7 @@ void bta_dm_ble_gap_set_prefer_ext_conn_params(tBTA_DM_MSG *p_data)
sizeof(tBTA_DM_BLE_CONN_PARAMS));
}
if (conn_params.phy_mask & BTAS_PHY_CODED_MASK) {
if (conn_params.phy_mask & BTA_PHY_CODED_MASK) {
memcpy(&conn_params.phy_coded_conn_params, &p_data->ble_set_per_ext_conn_params.phy_coded_conn_params,
sizeof(tBTA_DM_BLE_CONN_PARAMS));
}
@ -6673,7 +6673,9 @@ void btm_dm_start_gatt_discovery (BD_ADDR bd_addr)
btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
} else {
//TODO need to add addr_type in future
BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE,
BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE, 0, NULL, NULL, NULL);
}
}
#endif /* #if (GATTC_INCLUDED == TRUE) */

View File

@ -1040,7 +1040,7 @@ typedef struct {
#define BTA_PHY_1M_MASK (1 << 0)
#define BTA_PHY_2M_MASK (1 << 1)
#define BTAS_PHY_CODED_MASK (1 << 2)
#define BTA_PHY_CODED_MASK (1 << 2)
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;

View File

@ -36,6 +36,7 @@
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "bta_hh_int.h"
#include "btm_int.h"
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
#include "bta_hh_int.h"
@ -70,6 +71,7 @@ static void bta_gattc_req_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYP
static tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda);
extern void btc_gattc_congest_callback(tBTA_GATTC *param);
extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb);
static const tGATT_CBACK bta_gattc_cl_cback = {
bta_gattc_conn_cback,
@ -336,6 +338,10 @@ void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
UNUSED(p_cb);
if (p_clreg != NULL) {
if (p_msg->api_conn.own_addr_type <= BLE_ADDR_TYPE_MAX) {
// update own address type for creating connection
BTM_BleUpdateOwnType(&p_msg->api_conn.own_addr_type, NULL);
}
if (p_msg->api_conn.is_direct) {
if ((p_clcb = bta_gattc_find_alloc_clcb(p_msg->api_conn.client_if,
p_msg->api_conn.remote_bda,
@ -503,6 +509,7 @@ void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
tBTA_GATTC_DATA gattc_data;
BOOLEAN found_app = FALSE;
tGATT_TCB *p_tcb;
tBTM_SEC_DEV_REC *p_dev_rec = NULL;
if (!p_clcb || !p_data) {
return;
@ -512,6 +519,25 @@ void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
if(p_tcb) {
found_app = gatt_find_specific_app_in_hold_link(p_tcb, p_clcb->p_rcb->client_if);
}
if (p_data->api_conn.phy_mask) {
p_dev_rec = btm_find_or_alloc_dev(p_data->api_conn.remote_bda);
if (p_dev_rec) {
if (p_data->api_conn.is_aux) {
#if (BLE_50_FEATURE_SUPPORT == TRUE)
p_dev_rec->ext_conn_params.phy_mask = p_data->api_conn.phy_mask;
memcpy(&p_dev_rec->ext_conn_params.phy_1m_conn_params, &p_data->api_conn.phy_1m_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
memcpy(&p_dev_rec->ext_conn_params.phy_2m_conn_params, &p_data->api_conn.phy_2m_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
memcpy(&p_dev_rec->ext_conn_params.phy_coded_conn_params, &p_data->api_conn.phy_coded_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
#endif
} else {
memcpy(&p_dev_rec->conn_params, &p_data->api_conn.phy_1m_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
}
} else {
APPL_TRACE_ERROR("Unknown Device, setting rejected");
}
}
/* open/hold a connection */
if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, p_data->api_conn.remote_addr_type,
TRUE, p_data->api_conn.transport, p_data->api_conn.is_aux)) {
@ -1807,8 +1833,8 @@ static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda)
*******************************************************************************/
void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
{
tBTA_GATTC_SERV *p_srvc_cb = bta_gattc_find_srvr_cache(p_msg->api_conn.remote_bda);
tBTA_GATTC_CLCB *p_clcb = &bta_gattc_cb.clcb[0];
tBTA_GATTC_SERV *p_srvc_cb = bta_gattc_find_srvr_cache(p_msg->api_refresh.remote_bda);
tBTA_GATTC_CLCB *p_clcb = &bta_gattc_cb.clcb[0];
BOOLEAN found = FALSE;
UINT8 i;
UNUSED(p_cb);
@ -1928,7 +1954,7 @@ void bta_gattc_process_api_cache_get_addr_list(tBTA_GATTC_CB *p_cb, tBTA_GATTC_D
*******************************************************************************/
void bta_gattc_process_api_cache_clean(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
{
tBTA_GATTC_SERV *p_srvc_cb = bta_gattc_find_srvr_cache(p_msg->api_conn.remote_bda);
tBTA_GATTC_SERV *p_srvc_cb = bta_gattc_find_srvr_cache(p_msg->api_clean.remote_bda);
UNUSED(p_cb);
if (p_srvc_cb != NULL && p_srvc_cb->p_srvc_cache != NULL) {

View File

@ -128,7 +128,7 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
/*******************************************************************************
**
** Function BTA_GATTC_Open
** Function BTA_GATTC_Enh_Open
**
** Description Open a direct connection or add a background auto connection
** bd address
@ -142,8 +142,10 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
** Returns void
**
*******************************************************************************/
void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux)
void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type,
UINT8 phy_mask, tBTA_BLE_CONN_PARAMS *phy_1m_conn_params, tBTA_BLE_CONN_PARAMS *phy_2m_conn_params,
tBTA_BLE_CONN_PARAMS *phy_coded_conn_params)
{
tBTA_GATTC_API_OPEN *p_buf;
@ -155,8 +157,12 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE
p_buf->transport = transport;
p_buf->is_aux = is_aux;
p_buf->remote_addr_type = remote_addr_type;
p_buf->own_addr_type = own_addr_type;
p_buf->phy_mask = phy_mask;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
memcpy(&p_buf->phy_1m_conn_params, phy_1m_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
memcpy(&p_buf->phy_2m_conn_params, phy_2m_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
memcpy(&p_buf->phy_coded_conn_params, phy_coded_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
bta_sys_sendmsg(p_buf);
}
@ -472,7 +478,7 @@ void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle
** Description This function is called to read a characteristics value
**
** Parameters conn_id - connection ID.
** handle - characteritic handle to read.
** handle - characteristic handle to read.
**
** Returns None
**
@ -607,7 +613,7 @@ void BTA_GATTC_ReadMultipleVariable(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_mul
**
** Parameters conn_id - connection ID.
** s_handle - start handle.
** e_handle - end hanle
** e_handle - end handle
** uuid - The attribute UUID.
**
** Returns None
@ -687,7 +693,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
** Description This function is called to write descriptor value.
**
** Parameters conn_id - connection ID
** handle - descriptor hadle to write.
** handle - descriptor handle to write.
** write_type - write type.
** p_value - the value to be written.
**
@ -738,7 +744,7 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
** Description This function is called to prepare write a characteristic value.
**
** Parameters conn_id - connection ID.
** p_char_id - GATT characteritic ID of the service.
** p_char_id - GATT characteristic ID of the service.
** offset - offset of the write value.
** len: length of the data to be written.
** p_value - the value to be written.
@ -781,7 +787,7 @@ void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle,
** Description This function is called to prepare write a characteristic descriptor value.
**
** Parameters conn_id - connection ID.
** p_char_descr_id - GATT characteritic descriptor ID of the service.
** p_char_descr_id - GATT characteristic descriptor ID of the service.
** offset - offset of the write value.
** len: length of the data to be written.
** p_value - the value to be written.
@ -1010,9 +1016,9 @@ void BTA_GATTC_Refresh(BD_ADDR remote_bda, bool erase_flash)
if(bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
return;
}
tBTA_GATTC_API_OPEN *p_buf;
tBTA_GATTC_API_CACHE_REFRESH *p_buf;
if ((p_buf = (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
if ((p_buf = (tBTA_GATTC_API_CACHE_REFRESH *) osi_malloc(sizeof(tBTA_GATTC_API_CACHE_REFRESH))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_REFRESH_EVT;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
@ -1068,9 +1074,9 @@ void BTA_GATTC_Clean(BD_ADDR remote_bda)
bta_gattc_cache_reset(remote_bda);
#endif
tBTA_GATTC_API_OPEN *p_buf;
tBTA_GATTC_API_CACHE_CLEAN *p_buf;
if ((p_buf = (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
if ((p_buf = (tBTA_GATTC_API_CACHE_CLEAN *) osi_malloc(sizeof(tBTA_GATTC_API_CACHE_CLEAN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CACHE_CLEAN_EVT;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);

View File

@ -110,7 +110,7 @@ typedef enum {
#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE
#define BTA_GATTC_INVALID_HANDLE 0
/* internal strucutre for GATTC register API */
/* internal structure for GATTC register API */
typedef struct {
BT_HDR hdr;
tBT_UUID app_uuid;
@ -133,9 +133,20 @@ typedef struct {
BOOLEAN is_direct;
BOOLEAN is_aux;
tBTA_TRANSPORT transport;
tBTA_ADDR_TYPE own_addr_type;
UINT8 phy_mask;
tBTA_BLE_CONN_PARAMS phy_1m_conn_params;
tBTA_BLE_CONN_PARAMS phy_2m_conn_params;
tBTA_BLE_CONN_PARAMS phy_coded_conn_params;
} tBTA_GATTC_API_OPEN;
typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN;
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
tBTA_ADDR_TYPE remote_addr_type;
tBTA_GATTC_IF client_if;
BOOLEAN is_direct;
} tBTA_GATTC_API_CANCEL_OPEN;
typedef struct {
BT_HDR hdr;
@ -202,6 +213,11 @@ typedef struct {
BT_HDR hdr;
} tBTA_GATTC_API_CFG_MTU;
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
} tBTA_GATTC_API_CACHE_REFRESH;
typedef struct {
BT_HDR hdr;
tBTA_GATTC_IF client_if;
@ -215,6 +231,11 @@ typedef struct {
tBTA_GATTC_IF client_if;
} tBTA_GATTC_API_GET_ADDR;
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
} tBTA_GATTC_API_CACHE_CLEAN;
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
@ -247,8 +268,10 @@ typedef union {
tBTA_GATTC_API_EXEC api_exec;
tBTA_GATTC_API_READ_MULTI api_read_multi;
tBTA_GATTC_API_CFG_MTU api_mtu;
tBTA_GATTC_API_CACHE_REFRESH api_refresh;
tBTA_GATTC_API_CACHE_ASSOC api_assoc;
tBTA_GATTC_API_GET_ADDR api_get_addr;
tBTA_GATTC_API_CACHE_CLEAN api_clean;
tBTA_GATTC_OP_CMPL op_cmpl;
tBTA_GATTC_INT_CONN int_conn;
tBTA_GATTC_ENC_CMPL enc_cmpl;
@ -313,7 +336,7 @@ typedef struct {
UINT16 total_char;
UINT16 total_attr;
UINT8 srvc_hdl_chg; /* service handle change indication pending */
UINT16 attr_index; /* cahce NV saving/loading attribute index */
UINT16 attr_index; /* cache NV saving/loading attribute index */
UINT16 mtu;
bool update_incl_srvc;

View File

@ -117,7 +117,7 @@ static void bta_hh_le_hid_report_dbg(tBTA_HH_DEV_CB *p_cb)
if (p_cb->hid_srvc[i].in_use) {
p_rpt = &p_cb->hid_srvc[i].report[0];
APPL_TRACE_DEBUG("\t HID serivce inst: %d", i);
APPL_TRACE_DEBUG("\t HID service inst: %d", i);
for (j = 0; j < BTA_HH_LE_RPT_MAX; j ++, p_rpt++) {
rpt_name = "Unknown";
@ -334,14 +334,15 @@ void bta_hh_le_open_conn(tBTA_HH_DEV_CB *p_cb, BD_ADDR remote_bda)
bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] = p_cb->index;
p_cb->in_use = TRUE;
BTA_GATTC_Open(bta_hh_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bta_hh_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE,
BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE, 0, NULL, NULL, NULL);
}
/*******************************************************************************
**
** Function bta_hh_le_fill_16bits_gatt_id
**
** Description Utility function to fill a GATT ID strucure
** Description Utility function to fill a GATT ID structure
**
*******************************************************************************/
void bta_hh_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID *p_output)
@ -355,7 +356,7 @@ void bta_hh_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID *p_
**
** Function bta_hh_le_fill_16bits_srvc_id
**
** Description Utility function to fill a service ID strucure with a 16 bits
** Description Utility function to fill a service ID structure with a 16 bits
** service UUID.
**
*******************************************************************************/
@ -372,7 +373,7 @@ void bta_hh_le_fill_16bits_srvc_id(BOOLEAN is_pri, UINT8 inst_id, UINT16 srvc_uu
**
** Function bta_hh_le_fill_16bits_char_id
**
** Description Utility function to fill a char ID strucure with a 16 bits
** Description Utility function to fill a char ID structure with a 16 bits
** char UUID.
**
*******************************************************************************/
@ -624,7 +625,7 @@ tBTA_HH_STATUS bta_hh_le_read_char_dscrpt(tBTA_HH_DEV_CB *p_cb, UINT16 srvc_uuid
**
** Function bta_hh_le_read_rpt_ref_descr
**
** Description read report refernece descriptors in service discovery process
** Description read report reference descriptors in service discovery process
**
*******************************************************************************/
void bta_hh_le_read_rpt_ref_descr(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rpt)
@ -841,7 +842,7 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 srvc_inst,
}
}
/*
else unknow protocol mode */
else unknown protocol mode */
}
}
}
@ -1486,7 +1487,7 @@ void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_STATUS status)
{
APPL_TRACE_DEBUG("bta_hh_le_gatt_disc_cmpl ");
/* if open sucessful or protocol mode not desired, keep the connection open but inform app */
/* if open successful or protocol mode not desired, keep the connection open but inform app */
if (status == BTA_HH_OK || status == BTA_HH_ERR_PROTO) {
/* assign a special APP ID temp, since device type unknown */
p_cb->app_id = BTA_HH_APP_ID_LE;
@ -1504,7 +1505,7 @@ void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_STATUS status)
**
** Function bta_hh_le_srvc_expl_srvc
**
** Description This function discover the next avaible HID service.
** Description This function discover the next available HID service.
**
** Parameters:
**
@ -2076,7 +2077,7 @@ void bta_hh_w4_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
**
** Function bta_hh_w4_le_write_cmpl
**
** Description Write charactersitic complete event at W4_CONN st.
** Description Write characteristic complete event at W4_CONN st.
**
** Parameters:
**
@ -2104,7 +2105,7 @@ void bta_hh_w4_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
**
** Function bta_hh_le_write_cmpl
**
** Description Write charactersitic complete event at CONN st.
** Description Write characteristic complete event at CONN st.
**
** Parameters:
**
@ -2162,7 +2163,7 @@ void bta_hh_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
**
** Function bta_hh_le_write_char_descr_cmpl
**
** Description Write charactersitic descriptor complete event
** Description Write characteristic descriptor complete event
**
** Parameters:
**
@ -2216,7 +2217,7 @@ void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_b
**
** Function bta_hh_le_input_rpt_notify
**
** Description process the notificaton event, most likely for input report.
** Description process the notification event, most likely for input report.
**
** Parameters:
**
@ -2357,7 +2358,7 @@ void bta_hh_gatt_close(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
**
** Function bta_hh_le_api_disc_act
**
** Description initaite a Close API to a remote HID device
** Description initiate a Close API to a remote HID device
**
** Returns void
**
@ -2601,7 +2602,8 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB *p_cb, BOOLEAN check_bond)
if (/*p_cb->dscp_info.flag & BTA_HH_LE_NORMAL_CONN &&*/
!p_cb->in_bg_conn && to_add) {
/* add device into BG connection to accept remote initiated connection */
BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, BLE_ADDR_UNKNOWN_TYPE, FALSE, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bta_hh_cb.gatt_if, p_cb->addr, BLE_ADDR_UNKNOWN_TYPE, FALSE,
BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE, 0, NULL, NULL);
p_cb->in_bg_conn = TRUE;
BTA_DmBleSetBgConnType(BTA_DM_BLE_CONN_AUTO, NULL);
@ -2682,7 +2684,7 @@ void bta_hh_le_update_scpp(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
if (!p_dev_cb->is_le_device ||
p_dev_cb->mode != BTA_HH_PROTO_RPT_MODE ||
p_dev_cb->scps_supported == FALSE) {
APPL_TRACE_ERROR("Can not set ScPP scan paramter as boot host, or remote does not support ScPP ");
APPL_TRACE_ERROR("Can not set ScPP scan parameter as boot host, or remote does not support ScPP ");
cback_data.handle = p_dev_cb->hid_handle;
cback_data.status = BTA_HH_ERR;
@ -2908,7 +2910,7 @@ static void bta_hh_le_search_scps_chars(tBTA_HH_DEV_CB *p_cb)
**
** Function bta_hh_le_register_scpp_notif
**
** Description register scan parameter refresh notitication complete
** Description register scan parameter refresh notification complete
**
**
** Parameters:
@ -2919,7 +2921,7 @@ static void bta_hh_le_register_scpp_notif(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATT_ST
UINT8 sec_flag = 0;
tBTA_GATTC_CHAR_ID char_id;
/* if write scan parameter sucessful */
/* if write scan parameter successful */
/* if bonded and notification is not enabled, configure the client configuration */
if (status == BTA_GATT_OK &&
(p_dev_cb->scps_notify & BTA_HH_LE_SCPS_NOTIFY_SPT) != 0 &&
@ -2949,7 +2951,7 @@ static void bta_hh_le_register_scpp_notif(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATT_ST
**
** Function bta_hh_le_register_scpp_notif_cmpl
**
** Description action function to register scan parameter refresh notitication
** Description action function to register scan parameter refresh notification
**
** Parameters:
**

View File

@ -180,7 +180,7 @@ typedef UINT8 tBTA_GATT_STATUS;
#define BTA_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
#define BTA_GATTC_CONNECT_EVT 35 /* GATTC CONNECT event */
#define BTA_GATTC_DISCONNECT_EVT 36 /* GATTC DISCONNECT event */
#define BTA_GATTC_READ_MULTIPLE_EVT 37 /* GATTC Read mutiple event */
#define BTA_GATTC_READ_MULTIPLE_EVT 37 /* GATTC Read multiple event */
#define BTA_GATTC_QUEUE_FULL_EVT 38 /* GATTC queue full event */
#define BTA_GATTC_ASSOC_EVT 39 /* GATTC association address event */
#define BTA_GATTC_GET_ADDR_LIST_EVT 40 /* GATTC get address list in the cache event */
@ -728,6 +728,21 @@ typedef struct
tBTA_GATTC_SERVICE *included_service;
} __attribute__((packed)) tBTA_GATTC_INCLUDED_SVC;
typedef struct {
UINT16 scan_interval;
UINT16 scan_window;
UINT16 interval_min;
UINT16 interval_max;
UINT16 latency;
UINT16 supervision_timeout;
UINT16 min_ce_len;
UINT16 max_ce_len;
} tBTA_BLE_CONN_PARAMS;
#define BTA_BLE_PHY_1M_MASK (1 << 0)
#define BTA_BLE_PHY_2M_MASK (1 << 1)
#define BTA_BLE_PHY_CODED_MASK (1 << 2)
/*****************************************************************************
** External Function Declarations
*****************************************************************************/
@ -783,9 +798,10 @@ extern void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_clie
*******************************************************************************/
extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
/*******************************************************************************
**
** Function BTA_GATTC_Open
** Function BTA_GATTC_Enh_Open
**
** Description Open a direct connection or add a background auto connection
** bd address
@ -793,13 +809,16 @@ extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
** Parameters client_if: server interface.
** remote_bda: remote device BD address.
** remote_addr_type: remote device BD address type.
** is_direct: direct connection or background auto connection
** is_direct: direct connection or background auto connection.
** own_addr_type: own address type.
**
** Returns void
**
*******************************************************************************/
extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux);
extern void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type,
UINT8 phy_mask, tBTA_BLE_CONN_PARAMS *phy_1m_conn_params, tBTA_BLE_CONN_PARAMS *phy_2m_conn_params,
tBTA_BLE_CONN_PARAMS *phy_coded_conn_params);
/*******************************************************************************
**
@ -937,8 +956,8 @@ extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_
**
** Description This function is called to read a characteristics value
**
** Parameters conn_id - connectino ID.
** handle - characteritic handle to read.
** Parameters conn_id - connection ID.
** handle - characteristic handle to read.
**
** Returns None
**
@ -953,7 +972,7 @@ void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_
**
** Parameters conn_id - connection ID.
** s_handle - start handle.
** e_handle - end hanle
** e_handle - end handle
** uuid - The attribute UUID.
**
** Returns None
@ -1072,7 +1091,7 @@ extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF
** Description This function is called to prepare write a characteristic value.
**
** Parameters conn_id - connection ID.
** handle - GATT characteritic handle.
** handle - GATT characteristic handle.
** offset - offset of the write value.
** len - length of the data to be written.
** p_value - the value to be written.
@ -1094,7 +1113,7 @@ extern void BTA_GATTC_PrepareWrite (UINT16 conn_id,
** Description This function is called to prepare write a characteristic descriptor value.
**
** Parameters conn_id - connection ID.
** p_char_descr_id - GATT characteritic descriptor ID of the service.
** p_char_descr_id - GATT characteristic descriptor ID of the service.
** offset - offset of the write value.
** len: length of the data to be written.
** p_value - the value to be written.
@ -1238,7 +1257,7 @@ extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id);
**
** Function BTA_GATTS_Init
**
** Description This function is called to initalize GATTS module
** Description This function is called to initialize GATTS module
**
** Parameters None
**

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
@ -212,9 +212,12 @@ static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg)
static void btc_gattc_open(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda,
BTA_GATTC_Enh_Open(arg->open.gattc_if, arg->open.remote_bda,
arg->open.remote_addr_type, arg->open.is_direct,
transport, arg->open.is_aux);
transport, arg->open.is_aux, arg->open.own_addr_type,
arg->open.phy_mask, (void *)&arg->open.phy_1m_conn_params,
(void *)&arg->open.phy_2m_conn_params, (void *)&arg->open.phy_coded_conn_params);
}
static void btc_gattc_close(btc_ble_gattc_args_t *arg)

View File

@ -57,6 +57,11 @@ typedef union {
esp_ble_addr_type_t remote_addr_type;
bool is_direct;
bool is_aux;
esp_ble_addr_type_t own_addr_type;
esp_ble_phy_mask_t phy_mask;
esp_ble_conn_params_t phy_1m_conn_params;
esp_ble_conn_params_t phy_2m_conn_params;
esp_ble_conn_params_t phy_coded_conn_params;
} open;
//BTC_GATTC_ACT_CLOSE,
struct close_arg {

View File

@ -212,11 +212,14 @@ typedef struct {
#define BTM_BLE_MAX_BG_CONN_DEV_NUM 10
typedef struct {
UINT16 scan_interval;
UINT16 scan_window;
UINT16 min_conn_int;
UINT16 max_conn_int;
UINT16 slave_latency;
UINT16 supervision_tout;
UINT16 min_ce_len;
UINT16 max_ce_len;
} tBTM_LE_CONN_PRAMS;

View File

@ -349,8 +349,8 @@ BOOLEAN btsnd_hcic_ble_create_ll_conn (UINT16 scan_int, UINT16 scan_win,
UINT16_TO_STREAM (pp, conn_latency);
UINT16_TO_STREAM (pp, conn_timeout);
UINT16_TO_STREAM (pp, min_ce_len);
UINT16_TO_STREAM (pp, max_ce_len);
UINT16_TO_STREAM (pp, min_ce_len ? min_ce_len : BLE_CE_LEN_MIN);
UINT16_TO_STREAM (pp, max_ce_len ? max_ce_len : BLE_CE_LEN_MIN);
btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
return (TRUE);
@ -1594,8 +1594,8 @@ BOOLEAN btsnd_hcic_ble_create_ext_conn(tHCI_CreatExtConn *p_conn)
UINT16_TO_STREAM(pp, params->conn_interval_max);
UINT16_TO_STREAM(pp, params->conn_latency);
UINT16_TO_STREAM(pp, params->sup_timeout);
UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, params->min_ce_len ? params->min_ce_len : BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, params->max_ce_len ? params->max_ce_len : BLE_CE_LEN_MIN);
}
if (p_conn->init_phy_mask & 0x02) {
@ -1606,8 +1606,8 @@ BOOLEAN btsnd_hcic_ble_create_ext_conn(tHCI_CreatExtConn *p_conn)
UINT16_TO_STREAM(pp, params->conn_interval_max);
UINT16_TO_STREAM(pp, params->conn_latency);
UINT16_TO_STREAM(pp, params->sup_timeout);
UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, params->min_ce_len ? params->min_ce_len : BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, params->max_ce_len ? params->max_ce_len : BLE_CE_LEN_MIN);
}
if (p_conn->init_phy_mask & 0x04) {
@ -1618,8 +1618,8 @@ BOOLEAN btsnd_hcic_ble_create_ext_conn(tHCI_CreatExtConn *p_conn)
UINT16_TO_STREAM(pp, params->conn_interval_max);
UINT16_TO_STREAM(pp, params->conn_latency);
UINT16_TO_STREAM(pp, params->sup_timeout);
UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, params->min_ce_len ? params->min_ce_len : BLE_CE_LEN_MIN);
UINT16_TO_STREAM(pp, params->max_ce_len ? params->max_ce_len : BLE_CE_LEN_MIN);
}
btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);

View File

@ -902,6 +902,12 @@ BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb)
scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
if (p_dev_rec->conn_params.scan_interval && p_dev_rec->conn_params.scan_interval != BTM_BLE_CONN_PARAM_UNDEF) {
scan_int = p_dev_rec->conn_params.scan_interval;
}
if (p_dev_rec->conn_params.scan_window && p_dev_rec->conn_params.scan_window != BTM_BLE_CONN_PARAM_UNDEF) {
scan_win = p_dev_rec->conn_params.scan_window;
}
peer_addr_type = p_lcb->ble_addr_type;
memcpy(peer_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN);
@ -966,22 +972,24 @@ BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb)
}
if (!p_lcb->is_aux) {
if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int */
scan_win, /* UINT16 scan_win */
FALSE, /* UINT8 white_list */
peer_addr_type, /* UINT8 addr_type_peer */
peer_addr, /* BD_ADDR bda_peer */
own_addr_type, /* UINT8 addr_type_own */
if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */
scan_win, /* UINT16 scan_win */
FALSE, /* UINT8 white_list */
peer_addr_type, /* UINT8 addr_type_peer */
peer_addr, /* BD_ADDR bda_peer */
own_addr_type, /* UINT8 addr_type_own */
(UINT16) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ?
p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* UINT16 conn_int_min */
p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* UINT16 conn_int_min */
(UINT16) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ?
p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* UINT16 conn_int_max */
p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* UINT16 conn_int_max */
(UINT16) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ?
p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* UINT16 conn_latency */
p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* UINT16 conn_latency */
(UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ?
p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */
BLE_CE_LEN_MIN, /* UINT16 min_len */
BLE_CE_LEN_MIN)) { /* UINT16 max_len */
p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* UINT16 conn_timeout */
(UINT16) ((p_dev_rec->conn_params.min_ce_len != BTM_BLE_CONN_PARAM_UNDEF) ?
p_dev_rec->conn_params.min_ce_len : BLE_CE_LEN_MIN), /* UINT16 min_ce_len */
(UINT16) ((p_dev_rec->conn_params.max_ce_len != BTM_BLE_CONN_PARAM_UNDEF) ?
p_dev_rec->conn_params.max_ce_len : BLE_CE_LEN_MIN) /* UINT16 max_ce_len */)) {
l2cu_release_lcb (p_lcb);
L2CAP_TRACE_ERROR("initiate direct connection fail, no resources");
return (FALSE);

View File

@ -637,14 +637,14 @@ esp_err_t esp_bt_sleep_disable(void);
* @brief Manually clear the scan duplicate list
*
* @note
* 1. This function name is incorrectly spelled, it will be fixed in release 5.x version.
* 2. The scan duplicate list will be automatically cleared when the maximum amount of devices in the filter is reached.
* The amount of devices in the filter can be configured in menuconfig.
* The scan duplicate list will be automatically cleared when the maximum amount of devices in the filter is reached. The amount of devices in the filter can be configured in menuconfig.
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
*/
esp_err_t esp_ble_scan_duplicate_list_flush(void);
esp_err_t esp_ble_scan_dupilcate_list_flush(void);
#ifdef __cplusplus

View File

@ -570,8 +570,6 @@ esp_err_t esp_bt_controller_disable(void);
*/
esp_bt_controller_status_t esp_bt_controller_get_status(void);
uint16_t esp_bt_get_tx_buf_num(void);
/** @brief esp_vhci_host_callback
* used for vhci call host function to notify what host need to do
*/

View File

@ -672,10 +672,18 @@ esp_hidh_dev_t *esp_ble_hidh_dev_open(esp_bd_addr_t bda, esp_ble_addr_type_t add
dev->ble.address_type = address_type;
dev->ble.appearance = ESP_HID_APPEARANCE_GENERIC;
ret = esp_ble_gattc_open(hid_gattc_if, dev->addr.bda, dev->ble.address_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, dev->addr.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = dev->ble.address_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
ret = esp_ble_gattc_enh_open(hid_gattc_if,
&creat_conn_params);
if (ret) {
esp_hidh_dev_free_inner(dev);
ESP_LOGE(TAG, "esp_ble_gattc_open failed: %d", ret);
ESP_LOGE(TAG, "esp_ble_gattc_enh_open failed: %d", ret);
return NULL;
}
WAIT_CB();

View File

@ -563,7 +563,15 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
//ESP_LOGI(BLE_ANCS_TAG, "ESP_GATTC_CONNECT_EVT");
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, param->connect.remote_bda, 6);
// create gattc virtual connection
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, BLE_ADDR_TYPE_RANDOM, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = BLE_ADDR_TYPE_RANDOM;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
break;
case ESP_GATTC_DIS_SRVC_CMPL_EVT:
ESP_LOGI(BLE_ANCS_TAG, "ESP_GATTC_DIS_SRVC_CMPL_EVT");

View File

@ -238,7 +238,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
ESP_LOGI(GATTC_TAG, "Scan stop successfully");
if (is_connect == false) {
ESP_LOGI(GATTC_TAG, "Connect to the remote device.");
esp_ble_gattc_open(gl_profile_tab[PROFILE_APP_ID].gattc_if, scan_rst.scan_rst.bda, scan_rst.scan_rst.ble_addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_rst.scan_rst.bda,ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_rst.scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_APP_ID].gattc_if,
&creat_conn_params);
}
break;
case ESP_GAP_BLE_SCAN_RESULT_EVT: {

View File

@ -401,14 +401,29 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
if (connect == false) {
connect = true;
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
#if(CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT && CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
esp_ble_gap_set_prefer_conn_params(scan_result->scan_rst.bda, 34, 34, 0, 600);
#else
esp_ble_gap_set_prefer_conn_params(scan_result->scan_rst.bda, 32, 32, 0, 600);
#endif
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, BLE_ADDR_TYPE_PUBLIC, true);
esp_ble_conn_params_t phy_1m_conn_params = {0};
#if(CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT && CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
phy_1m_conn_params.interval_max = 34;
phy_1m_conn_params.interval_max = 34;
#else
phy_1m_conn_params.interval_max = 32;
phy_1m_conn_params.interval_min = 32;
#endif
phy_1m_conn_params.latency = 0;
phy_1m_conn_params.supervision_timeout = 600;
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = ESP_BLE_PHY_1M_PREF_MASK;
creat_conn_params.phy_1m_conn_params = &phy_1m_conn_params;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
}
}
}

View File

@ -370,7 +370,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
connect = true;
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
}
}
}

View File

@ -372,7 +372,15 @@ We are interested in the `ESP_GAP_SEARCH_INQ_RES_EVT` event, which is called eve
connect = true;
ESP_LOGI(GATTC_TAG, "connect to the remote device.");
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
}
}
}
@ -405,7 +413,7 @@ ESP_LOGI(GATTC_TAG, "searched Device Name Len %d", adv_name_len);
ESP_LOG_BUFFER_CHAR(GATTC_TAG, adv_name, adv_name_len);
```
Finally if the remote device name is the same as we have defined above, the local device stops scanning and tries to open a connection to the remote device using the `esp_ble_gattc_open()` function. This function takes as parameters the Application Profile GATT interface, the remote server address and a boolean value. The boolean value is used to indicate if the connection is done directly or if its done in the background (auto-connection), at the moment this boolean value must be set to true in order to establish the connection. Notice that the client opens a virtual connection to the server. The virtual connection returns a connection ID. The virtual connection is the connection between the Application Profile and the remote server. Since many Application Profiles can run on one ESP32, there could be many virtual connection opened to the same remote server. There is also the physical connection which is the actual BLE link between the client and the server. Therefore, if the physical connection is disconnected with the `esp_ble_gap_disconnect()` function, all other virtual connections are closed as well. In this example, each Application Profile creates a virtual connection to the same server with the `esp_ble_gattc_open()` function, so when the close function is called, only that connection from the Application Profile is closed, while if the gap disconnect function is called, both connections will be closed. In addition, connect events are propagated to all profiles because it relates to the physical connection, while open events are propagated only to the profile that creates the virtual connection.
Finally if the remote device name is the same as we have defined above, the local device stops scanning and tries to open a connection to the remote device using the `esp_ble_gattc_enh_open()` function. This function takes as parameters the Application Profile GATT interface, the remote server address and a boolean value. The boolean value is used to indicate if the connection is done directly or if its done in the background (auto-connection), at the moment this boolean value must be set to true in order to establish the connection. Notice that the client opens a virtual connection to the server. The virtual connection returns a connection ID. The virtual connection is the connection between the Application Profile and the remote server. Since many Application Profiles can run on one ESP32, there could be many virtual connection opened to the same remote server. There is also the physical connection which is the actual BLE link between the client and the server. Therefore, if the physical connection is disconnected with the `esp_ble_gap_disconnect()` function, all other virtual connections are closed as well. In this example, each Application Profile creates a virtual connection to the same server with the `esp_ble_gattc_enh_open()` function, so when the close function is called, only that connection from the Application Profile is closed, while if the gap disconnect function is called, both connections will be closed. In addition, connect events are propagated to all profiles because it relates to the physical connection, while open events are propagated only to the profile that creates the virtual connection.
## Configuring the MTU Size

View File

@ -465,7 +465,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
connect = true;
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
}
}
}

View File

@ -817,7 +817,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
conn_device_a = true;
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[0]);
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
Isconnecting = true;
}
break;
@ -827,7 +835,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
conn_device_b = true;
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[1]);
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
Isconnecting = true;
}
@ -837,7 +853,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
conn_device_c = true;
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[2]);
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_C_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
Isconnecting = true;
}
break;

View File

@ -116,35 +116,109 @@ if (find_device_1 && find_device_2 && find_device_3 && stop_scan == false {
The scan stop triggers an ``ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT`` event which is used to open a connection to the first remote device. The second and third devices get connected once the client searches for services, gets characteristics and registers for notifications on the first device. This workflow is designed to test that the communication between each remote device is working correctly before trying to connect to the next device or in case of error, skip to the next device.
```c
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
ESP_LOGE(GATTC_TAG, "Scan stop failed");
break;
}
ESP_LOGI(GATTC_TAG, "Stop scan successfully");
if (!stop_scan){
ESP_LOGE(GATTC_TAG, "Did not find all devices");
}
if (find_device_1){
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, true);
}
break;
```
* The connection is opened with the ``esp_ble_gattc_open()`` function which takes the GATT interface, the remote device address and a boolean value set to true for direct connection or false for background auto connection. To disconnect the physical connection, the GAP API function ``esp_ble_gap_disconnect()`` is used.
When connecting to the first device, an ``ESP_GATTC_CONNECT_EVT`` event is generated which is forwarded to all profiles. It also triggers an ``ESP_GATTC_OPEN_EVT`` event that is forwarded to the Profile A event handler only, or ``gattc_profile_a_event_handler()`` function. The event checks that the connection is opened successfully, if not, the device is ignored and the client tries to open a connection to the second device:
```c
case ESP_GATTC_OPEN_EVT:
if (p_data->open.status != ESP_GATT_OK){
//open failed, ignore the first device, connect the second device
ESP_LOGE(GATTC_TAG, "connect device failed, status %d", p_data->open.status);
if (find_device_2){
esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, gl_profile_tab[PROFILE_B_APP_ID].remote_bda, true);
}
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
ESP_LOGE(GATTC_TAG, "Scan stop failed");
break;
}
ESP_LOGI(GATTC_TAG, "Stop scan successfully");
break;
```
* The connection is opened with the ``esp_ble_gattc_enh_open()`` function which takes the GATT interface, the remote device address and a boolean value set to true for direct connection or false for background auto connection. To disconnect the physical connection, the GAP API function ``esp_ble_gap_disconnect()`` is used.
When connecting to the first device, an ``ESP_GATTC_CONNECT_EVT`` event is generated which is forwarded to all profiles. It also triggers an ``ESP_GATTC_OPEN_EVT`` event that is forwarded to the Profile A event handler only, or ``gattc_profile_a_event_handler()`` function. The event checks that the connection is opened successfully, if not, the device is ignored and the client tries to open a connection to the second device.
```c
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
switch (scan_result->scan_rst.search_evt) {
case ESP_GAP_SEARCH_INQ_RES_EVT:
ESP_LOG_BUFFER_HEX(GATTC_TAG, scan_result->scan_rst.bda, 6);
ESP_LOGI(GATTC_TAG, "Searched Adv Data Len %d, Scan Response Len %d", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len);
adv_name = esp_ble_resolve_adv_data_by_type(scan_result->scan_rst.ble_adv,
scan_result->scan_rst.adv_data_len + scan_result->scan_rst.scan_rsp_len,
ESP_BLE_AD_TYPE_NAME_CMPL,
&adv_name_len);
ESP_LOGI(GATTC_TAG, "Searched Device Name Len %d", adv_name_len);
ESP_LOG_BUFFER_CHAR(GATTC_TAG, adv_name, adv_name_len);
ESP_LOGI(GATTC_TAG, " ");
if (Isconnecting){
break;
}
if (conn_device_a && conn_device_b && conn_device_c && !stop_scan_done){
stop_scan_done = true;
esp_ble_gap_stop_scanning();
ESP_LOGI(GATTC_TAG, "all devices are connected");
break;
}
if (adv_name != NULL) {
if (strlen(remote_device_name[0]) == adv_name_len && strncmp((char *)adv_name, remote_device_name[0], adv_name_len) == 0) {
if (conn_device_a == false) {
conn_device_a = true;
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[0]);
esp_ble_gap_stop_scanning();
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
Isconnecting = true;
}
break;
}
else if (strlen(remote_device_name[1]) == adv_name_len && strncmp((char *)adv_name, remote_device_name[1], adv_name_len) == 0) {
if (conn_device_b == false) {
conn_device_b = true;
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[1]);
esp_ble_gap_stop_scanning();
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
Isconnecting = true;
}
}
else if (strlen(remote_device_name[2]) == adv_name_len && strncmp((char *)adv_name, remote_device_name[2], adv_name_len) == 0) {
if (conn_device_c == false) {
conn_device_c = true;
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[2]);
esp_ble_gap_stop_scanning();
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
&creat_conn_params);
Isconnecting = true;
}
break;
}
}
break;
case ESP_GAP_SEARCH_INQ_CMPL_EVT:
break;
default:
break;
}
break;
}
```
If the connection is successful the client saves the connection ID, prints the remote device information and configures the MTU size to 200 bytes.
@ -305,35 +379,29 @@ At this point the client has acquired all characteristics from the remote device
break;
```
* If the writing procedure is acknowledged then the remote device has connected successfully and communication is established without error. Immediately, the write procedure generates an ``ESP_GATTC_WRITE_CHAR_EVT`` event which in this example is used to print information and connect to the second remote device:
* If the writing procedure is acknowledged then the remote device has connected successfully and communication is established without error. Immediately, the write procedure generates an ``ESP_GATTC_WRITE_CHAR_EVT`` event which in this example is used to print information and start scan again to connect to the second remote device:
```c
case ESP_GATTC_WRITE_CHAR_EVT:
case ESP_GATTC_WRITE_CHAR_EVT:
if (p_data->write.status != ESP_GATT_OK){
ESP_LOGE(GATTC_TAG, "write char failed, error status = %x", p_data->write.status);
}else{
ESP_LOGI(GATTC_TAG, "write char success");
}
//connect the second device
if (find_device_2){
esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, gl_profile_tab[PROFILE_B_APP_ID].remote_bda, true);
}
start_scan();
break;
```
* This triggers an open event which is handled by the Profile B event handler. This handler follows the same steps to search for services, get characteristics, register for notifications and write to the characteristic as the first device. The sequence for the second device also ends with an ``ESP_GATTC_WRITE_CHAR_EVT`` event which in turn is used to connect to the third device:
```c
case ESP_GATTC_WRITE_CHAR_EVT:
case ESP_GATTC_WRITE_CHAR_EVT:
if (p_data->write.status != ESP_GATT_OK){
ESP_LOGE(GATTC_TAG, "Write char failed, error status = %x", p_data->write.status);
ESP_LOGE(GATTC_TAG, "write char failed, error status = %x", p_data->write.status);
}else{
ESP_LOGI(GATTC_TAG, "Write char success");
}
//connect the third device
if (find_device_3){
esp_ble_gattc_open(gl_profile_tab[PROFILE_C_APP_ID].gattc_if, gl_profile_tab[PROFILE_C_APP_ID].remote_bda, true);
ESP_LOGI(GATTC_TAG, "write char success");
}
start_scan();
break;
```

View File

@ -65,7 +65,7 @@ static esp_ble_ext_scan_params_t ext_scan_params = {
.coded_cfg = {BLE_SCAN_TYPE_ACTIVE, 40, 40},
};
const esp_ble_gap_conn_params_t phy_1m_conn_params = {
const esp_ble_conn_params_t phy_1m_conn_params = {
.scan_interval = 0x40,
.scan_window = 0x40,
.interval_min = 320,
@ -75,7 +75,7 @@ const esp_ble_gap_conn_params_t phy_1m_conn_params = {
.min_ce_len = 0,
.max_ce_len = 0,
};
const esp_ble_gap_conn_params_t phy_2m_conn_params = {
const esp_ble_conn_params_t phy_2m_conn_params = {
.scan_interval = 0x40,
.scan_window = 0x40,
.interval_min = 320,
@ -85,7 +85,7 @@ const esp_ble_gap_conn_params_t phy_2m_conn_params = {
.min_ce_len = 0,
.max_ce_len = 0,
};
const esp_ble_gap_conn_params_t phy_coded_conn_params = {
const esp_ble_conn_params_t phy_coded_conn_params = {
.scan_interval = 0x40,
.scan_window = 0x40,
.interval_min = 320, // 306-> 362Kbps
@ -500,12 +500,18 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
ESP_LOG_BUFFER_CHAR("Adv name", adv_name, adv_name_len);
ESP_LOGI(GATTC_TAG, "Stop extend scan and create aux open, primary_phy %d secondary phy %d", param->ext_adv_report.params.primary_phy, param->ext_adv_report.params.secondly_phy);
esp_ble_gap_prefer_ext_connect_params_set(param->ext_adv_report.params.addr,
ESP_BLE_GAP_PHY_1M_PREF_MASK | ESP_BLE_GAP_PHY_2M_PREF_MASK | ESP_BLE_GAP_PHY_CODED_PREF_MASK ,
&phy_1m_conn_params, &phy_2m_conn_params, &phy_coded_conn_params);
esp_ble_gattc_aux_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
param->ext_adv_report.params.addr,
param->ext_adv_report.params.addr_type, true);
// create gattc virtual connection
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, param->ext_adv_report.params.addr, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = param->ext_adv_report.params.addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = true;
creat_conn_params.phy_mask = ESP_BLE_PHY_1M_PREF_MASK | ESP_BLE_PHY_2M_PREF_MASK | ESP_BLE_PHY_CODED_PREF_MASK;
creat_conn_params.phy_1m_conn_params = &phy_1m_conn_params;
creat_conn_params.phy_2m_conn_params = &phy_2m_conn_params;
creat_conn_params.phy_coded_conn_params = &phy_coded_conn_params;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, &creat_conn_params);
}
break;

View File

@ -95,7 +95,7 @@ static esp_bt_uuid_t notify_descr_uuid = {
};
static esp_ble_ext_scan_params_t ext_scan_params = {
.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC,
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
.filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
.scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE,
.cfg_mask = ESP_BLE_GAP_EXT_SCAN_CFG_CODE_MASK | ESP_BLE_GAP_EXT_SCAN_CFG_UNCODE_MASK,
@ -104,7 +104,7 @@ static esp_ble_ext_scan_params_t ext_scan_params = {
};
// If the interference in the air is severe, the connection interval can be reduced.
const esp_ble_gap_conn_params_t phy_1m_conn_params = {
const esp_ble_conn_params_t phy_1m_conn_params = {
.interval_max = 104, // 130ms
.interval_min = 104,
.latency = 0,
@ -115,7 +115,7 @@ const esp_ble_gap_conn_params_t phy_1m_conn_params = {
.supervision_timeout = 600,
};
const esp_ble_gap_conn_params_t phy_2m_conn_params = {
const esp_ble_conn_params_t phy_2m_conn_params = {
.interval_max = 104, // 130ms
.interval_min = 104,
.latency = 0,
@ -126,7 +126,7 @@ const esp_ble_gap_conn_params_t phy_2m_conn_params = {
.supervision_timeout = 600,
};
const esp_ble_gap_conn_params_t phy_coded_conn_params = {
const esp_ble_conn_params_t phy_coded_conn_params = {
.interval_max = 104, // 130ms
.interval_min = 104,
.latency = 0,
@ -441,12 +441,17 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
ESP_LOGI(GATTC_TAG, "Device found "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(param->ext_adv_report.params.addr));
ESP_LOG_BUFFER_CHAR("Adv name", adv_name, adv_name_len);
ESP_LOGI(GATTC_TAG, "Stop extend scan and create aux open, primary_phy %d secondary phy %d", param->ext_adv_report.params.primary_phy, param->ext_adv_report.params.secondly_phy);
esp_ble_gap_prefer_ext_connect_params_set(param->ext_adv_report.params.addr,
ESP_BLE_GAP_PHY_1M_PREF_MASK | ESP_BLE_GAP_PHY_2M_PREF_MASK | ESP_BLE_GAP_PHY_CODED_PREF_MASK,
&phy_1m_conn_params, &phy_2m_conn_params, &phy_coded_conn_params);
esp_ble_gattc_aux_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
param->ext_adv_report.params.addr,
param->ext_adv_report.params.addr_type, true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, param->ext_adv_report.params.addr, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = param->ext_adv_report.params.addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = true;
creat_conn_params.phy_mask = ESP_BLE_PHY_1M_PREF_MASK | ESP_BLE_PHY_2M_PREF_MASK | ESP_BLE_PHY_CODED_PREF_MASK;
creat_conn_params.phy_1m_conn_params = &phy_1m_conn_params;
creat_conn_params.phy_2m_conn_params = &phy_2m_conn_params;
creat_conn_params.phy_coded_conn_params = &phy_coded_conn_params;
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, &creat_conn_params);
}
break;
}

View File

@ -307,10 +307,15 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
// Initiate GATT connection with the remote device,
// If ble physical connection is set up, ESP_GATTS_CONNECT_EVT and ESP_GATTC_CONNECT_EVT event will come
esp_ble_gattc_open(gattc_profile_tab[GATTC_PROFILE_C_APP_ID].gattc_if,
scan_result->scan_rst.bda,
scan_result->scan_rst.ble_addr_type,
true);
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
creat_conn_params.is_direct = true;
creat_conn_params.is_aux = false;
creat_conn_params.phy_mask = 0x0;
esp_ble_gattc_enh_open(gattc_profile_tab[GATTC_PROFILE_C_APP_ID].gattc_if,
&creat_conn_params);
// Update peer gatt server address
memcpy(peer_gatts_addr, scan_result->scan_rst.bda, sizeof(esp_bd_addr_t));