fix(ble/bluedroid): Optimize BLE API "esp_ble_gattc_enh_open"

This commit is contained in:
zhanghaipeng
2024-12-03 18:01:04 +08:00
committed by chenjianhua
parent 984c023ef4
commit 68991d317c
13 changed files with 98 additions and 99 deletions
@@ -68,7 +68,7 @@ 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);
}
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)
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;
@@ -79,11 +79,11 @@ esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_OPEN;
arg.open.gattc_if = gattc_if;
memcpy(arg.open.remote_bda, esp_gatt_create_conn.remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = esp_gatt_create_conn.remote_addr_type;
arg.open.is_direct = esp_gatt_create_conn.is_direct;
arg.open.is_aux= esp_gatt_create_conn.is_aux;
arg.open.own_addr_type = esp_gatt_create_conn.own_addr_type;
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;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@@ -91,26 +91,26 @@ 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 esp_gatt_create_conn;
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
esp_gatt_create_conn.is_direct = is_direct;
esp_gatt_create_conn.is_aux = false;
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
esp_ble_gatt_creat_conn_params_t creat_conn_params;
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
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)
{
esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn;
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
esp_gatt_create_conn.is_direct = is_direct;
esp_gatt_create_conn.is_aux = true;
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
esp_ble_gatt_creat_conn_params_t creat_conn_params;
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
return esp_ble_gattc_enh_open(gattc_if, &creat_conn_params);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
@@ -319,14 +319,14 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
* 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: Structure containing connection parameters.
* @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);
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
+7 -7
View File
@@ -723,14 +723,14 @@ 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;
esp_ble_gatt_creat_conn_params_t esp_ble_gatt_create_conn;
memcpy(&esp_ble_gatt_create_conn.remote_bda, dev->bda, ESP_BD_ADDR_LEN);
esp_ble_gatt_create_conn.remote_addr_type = dev->ble.address_type;
esp_ble_gatt_create_conn.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
esp_ble_gatt_create_conn.is_direct = true;
esp_ble_gatt_create_conn.is_aux = false;
esp_ble_gatt_creat_conn_params_t creat_conn_params;
memcpy(&creat_conn_params.remote_bda, dev->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;
ret = esp_ble_gattc_enh_open(hid_gattc_if,
esp_ble_gatt_create_conn);
&creat_conn_params);
if (ret) {
esp_hidh_dev_free_inner(dev);
ESP_LOGE(TAG, "esp_ble_gattc_enh_open failed: %d", ret);