diff --git a/components/esp-tls/esp_tls.c b/components/esp-tls/esp_tls.c index a4839190b1..fe5ffccc01 100644 --- a/components/esp-tls/esp_tls.c +++ b/components/esp-tls/esp_tls.c @@ -267,7 +267,7 @@ static esp_err_t esp_tls_set_socket_non_blocking(int fd, bool non_blocking) return ESP_OK; } -esp_err_t esp_tls_tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd) +static inline esp_err_t tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd) { struct sockaddr_storage address; int fd; @@ -371,7 +371,7 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c _esp_tls_net_init(tls); tls->is_tls = true; } - if ((esp_ret = esp_tls_tcp_connect(hostname, hostlen, port, cfg, tls->error_handle, &tls->sockfd)) != ESP_OK) { + if ((esp_ret = tcp_connect(hostname, hostlen, port, cfg, tls->error_handle, &tls->sockfd)) != ESP_OK) { ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_ESP, esp_ret); return -1; } @@ -440,6 +440,17 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c return -1; } +/** + * @brief Create a new plain TCP connection + */ +esp_err_t esp_tls_plain_tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd) +{ + if (sockfd == NULL || error_handle == NULL) { + return ESP_ERR_INVALID_ARG; + } + return tcp_connect(host, hostlen, port, cfg, error_handle, sockfd); +} + /** * @brief Create a new TLS/SSL connection */ diff --git a/components/esp-tls/esp_tls.h b/components/esp-tls/esp_tls.h index 2ef4848c86..3cdedc0998 100644 --- a/components/esp-tls/esp_tls.h +++ b/components/esp-tls/esp_tls.h @@ -171,7 +171,10 @@ typedef struct esp_tls_cfg { void *ds_data; /*!< Pointer for digital signature peripheral context */ bool is_plain_tcp; /*!< Use non-TLS connection: When set to true, the esp-tls uses - plain TCP transport rather then TLS/SSL connection */ + plain TCP transport rather then TLS/SSL connection. + Note, that it is possible to connect using a plain tcp transport + directly with esp_tls_plain_tcp_connect() API */ + struct ifreq *if_name; /*!< The name of interface for data to go through. Use the default interface without setting */ } esp_tls_cfg_t; @@ -609,9 +612,10 @@ void esp_tls_server_session_delete(esp_tls_t *tls); * @param[out] error_handle ESP-TLS error handle holding potential errors occurred during connection * @param[out] sockfd Socket descriptor if successfully connected on TCP layer * @return ESP_OK on success + * ESP_ERR_INVALID_ARG if invalid output parameters * ESP-TLS based error codes on failure */ -esp_err_t esp_tls_tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd); +esp_err_t esp_tls_plain_tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd); #ifdef __cplusplus } diff --git a/components/tcp_transport/transport_ssl.c b/components/tcp_transport/transport_ssl.c index c1aecb72a7..a0048c33e0 100644 --- a/components/tcp_transport/transport_ssl.c +++ b/components/tcp_transport/transport_ssl.c @@ -134,7 +134,7 @@ static int tcp_connect(esp_transport_handle_t t, const char *host, int port, int esp_tls_last_error_t *err_handle = esp_transport_get_error_handle(t); ssl->cfg.timeout_ms = timeout_ms; - esp_err_t err = esp_tls_tcp_connect(host, strlen(host), port, &ssl->cfg, err_handle, &ssl->sockfd); + esp_err_t err = esp_tls_plain_tcp_connect(host, strlen(host), port, &ssl->cfg, err_handle, &ssl->sockfd); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to open a new connection: %d", err); err_handle->last_error = err;