mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-07 13:42:43 +00:00
feat(ble/bluedroid): Support setting connection params when creating connection
This commit is contained in:
@@ -72,9 +72,14 @@ esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn
|
||||
{
|
||||
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;
|
||||
@@ -84,6 +89,83 @@ esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn
|
||||
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);
|
||||
}
|
||||
@@ -91,12 +173,13 @@ esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn
|
||||
#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;
|
||||
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)
|
||||
@@ -104,12 +187,13 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, e
|
||||
#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)
|
||||
{
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
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)
|
||||
|
Reference in New Issue
Block a user