mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
feat(tcp_transport): add an api to configure the addr family
This commit is contained in:
parent
5ad7de7154
commit
4be36fdb8b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -15,6 +15,7 @@
|
||||
#include "http_header.h"
|
||||
#include "esp_transport.h"
|
||||
#include "esp_transport_tcp.h"
|
||||
#include "esp_transport_ssl.h"
|
||||
#include "http_utils.h"
|
||||
#include "http_auth.h"
|
||||
#include "sdkconfig.h"
|
||||
@ -739,10 +740,26 @@ static bool init_common_tcp_transport(esp_http_client_handle_t client, const esp
|
||||
return true;
|
||||
}
|
||||
|
||||
static esp_err_t http_convert_addr_family_to_tls(esp_http_client_addr_type_t http_addr_family, esp_tls_addr_family_t *tls_addr_family)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
if (http_addr_family == HTTP_ADDR_TYPE_UNSPEC) {
|
||||
*tls_addr_family = ESP_TLS_AF_UNSPEC;
|
||||
} else if (http_addr_family == HTTP_ADDR_TYPE_INET) {
|
||||
*tls_addr_family = ESP_TLS_AF_INET;
|
||||
} else if (http_addr_family == HTTP_ADDR_TYPE_INET6) {
|
||||
*tls_addr_family = ESP_TLS_AF_INET6;
|
||||
} else {
|
||||
ret = ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *config)
|
||||
{
|
||||
|
||||
esp_http_client_handle_t client;
|
||||
esp_tls_addr_family_t addr_family = ESP_TLS_AF_UNSPEC;
|
||||
esp_err_t ret = ESP_OK;
|
||||
esp_transport_handle_t tcp = NULL;
|
||||
char *host_name;
|
||||
@ -776,6 +793,8 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
||||
ESP_LOGE(TAG, "Error initialize transport");
|
||||
goto error;
|
||||
}
|
||||
ESP_GOTO_ON_ERROR(http_convert_addr_family_to_tls(config->addr_type, &addr_family), error, TAG, "Failed to convert addr type %d", config->addr_type);
|
||||
esp_transport_ssl_set_addr_family(tcp, addr_family);
|
||||
|
||||
ESP_GOTO_ON_FALSE(init_common_tcp_transport(client, config, tcp), ESP_FAIL, error, TAG, "Failed to set TCP config");
|
||||
|
||||
@ -791,6 +810,7 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
||||
ESP_LOGE(TAG, "Error initialize SSL Transport");
|
||||
goto error;
|
||||
}
|
||||
esp_transport_ssl_set_addr_family(ssl, addr_family);
|
||||
|
||||
ESP_GOTO_ON_FALSE(init_common_tcp_transport(client, config, ssl), ESP_FAIL, error, TAG, "Failed to set SSL config");
|
||||
|
||||
|
@ -129,6 +129,15 @@ typedef enum {
|
||||
HTTP_AUTH_TYPE_DIGEST, /*!< HTTP Digest authentication */
|
||||
} esp_http_client_auth_type_t;
|
||||
|
||||
/*
|
||||
* @brief HTTP Address type
|
||||
*/
|
||||
typedef enum {
|
||||
HTTP_ADDR_TYPE_UNSPEC = AF_UNSPEC, /**< Unspecified address family. */
|
||||
HTTP_ADDR_TYPE_INET = AF_INET, /**< IPv4 address family. */
|
||||
HTTP_ADDR_TYPE_INET6 = AF_INET6, /**< IPv6 address family. */
|
||||
} esp_http_client_addr_type_t;
|
||||
|
||||
/**
|
||||
* @brief HTTP configuration
|
||||
*/
|
||||
@ -194,6 +203,7 @@ typedef struct {
|
||||
#if CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT
|
||||
struct esp_transport_item_t *transport;
|
||||
#endif
|
||||
esp_http_client_addr_type_t addr_type; /*!< Address type used in http client configurations */
|
||||
} esp_http_client_config_t;
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*/
|
||||
@ -45,7 +45,7 @@ void esp_transport_ssl_set_cert_data(esp_transport_handle_t t, const char *data,
|
||||
void esp_transport_ssl_set_cert_data_der(esp_transport_handle_t t, const char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief Enable the use of certification bundle for server verfication for
|
||||
* @brief Enable the use of certification bundle for server verification for
|
||||
* an SSL connection.
|
||||
* It must be first enabled in menuconfig.
|
||||
*
|
||||
@ -211,6 +211,14 @@ void esp_transport_ssl_set_keep_alive(esp_transport_handle_t t, esp_transport_ke
|
||||
*/
|
||||
void esp_transport_ssl_set_interface_name(esp_transport_handle_t t, struct ifreq *if_name);
|
||||
|
||||
/**
|
||||
* @brief Set addr family of transport
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] addr_family The addr family
|
||||
*/
|
||||
void esp_transport_ssl_set_addr_family(esp_transport_handle_t t, esp_tls_addr_family_t addr_family);
|
||||
|
||||
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||
/**
|
||||
* @brief Session ticket operation
|
||||
|
@ -397,6 +397,12 @@ void esp_transport_ssl_set_client_cert_data(esp_transport_handle_t t, const char
|
||||
ssl->cfg.clientcert_pem_bytes = len + 1;
|
||||
}
|
||||
|
||||
void esp_transport_ssl_set_addr_family(esp_transport_handle_t t, esp_tls_addr_family_t addr_family)
|
||||
{
|
||||
GET_SSL_FROM_TRANSPORT_OR_RETURN(ssl, t);
|
||||
ssl->cfg.addr_family = addr_family;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MBEDTLS_HARDWARE_ECDSA_SIGN
|
||||
void esp_transport_ssl_set_client_key_ecdsa_peripheral(esp_transport_handle_t t, uint8_t ecdsa_efuse_blk)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user