From 5cfa545d0849d191c2389f5c1af3b7bd04a97f38 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 10 Feb 2021 13:25:09 +0100 Subject: [PATCH] esp-tls: Added _esp_tls_net_init to init fd for both mbedtls/wolfssl --- components/esp-tls/esp_tls.c | 10 ++++------ components/esp-tls/private_include/esp_tls_mbedtls.h | 8 ++++++++ components/esp-tls/private_include/esp_tls_wolfssl.h | 7 +++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/components/esp-tls/esp_tls.c b/components/esp-tls/esp_tls.c index ac27acee76..9eb1502c18 100644 --- a/components/esp-tls/esp_tls.c +++ b/components/esp-tls/esp_tls.c @@ -45,6 +45,7 @@ static const char *TAG = "esp-tls"; #define _esp_tls_read esp_mbedtls_read #define _esp_tls_write esp_mbedtls_write #define _esp_tls_conn_delete esp_mbedtls_conn_delete +#define _esp_tls_net_init esp_mbedtls_net_init #ifdef CONFIG_ESP_TLS_SERVER #define _esp_tls_server_session_create esp_mbedtls_server_session_create #define _esp_tls_server_session_delete esp_mbedtls_server_session_delete @@ -60,6 +61,7 @@ static const char *TAG = "esp-tls"; #define _esp_tls_read esp_wolfssl_read #define _esp_tls_write esp_wolfssl_write #define _esp_tls_conn_delete esp_wolfssl_conn_delete +#define _esp_tls_net_init esp_wolfssl_net_init #ifdef CONFIG_ESP_TLS_SERVER #define _esp_tls_server_session_create esp_wolfssl_server_session_create #define _esp_tls_server_session_delete esp_wolfssl_server_session_delete @@ -126,9 +128,7 @@ esp_tls_t *esp_tls_init(void) free(tls); return NULL; } -#ifdef CONFIG_ESP_TLS_USING_MBEDTLS - tls->server_fd.fd = -1; -#endif + _esp_tls_net_init(tls); tls->sockfd = -1; return tls; } @@ -353,9 +353,7 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c case ESP_TLS_INIT: tls->sockfd = -1; if (cfg != NULL && cfg->is_plain_tcp == false) { -#ifdef CONFIG_ESP_TLS_USING_MBEDTLS - mbedtls_net_init(&tls->server_fd); -#endif + _esp_tls_net_init(tls); tls->is_tls = true; } if ((esp_ret = esp_tcp_connect(hostname, hostlen, port, &tls->sockfd, tls, cfg)) != ESP_OK) { diff --git a/components/esp-tls/private_include/esp_tls_mbedtls.h b/components/esp-tls/private_include/esp_tls_mbedtls.h index 362a71fd64..7440f0c3c7 100644 --- a/components/esp-tls/private_include/esp_tls_mbedtls.h +++ b/components/esp-tls/private_include/esp_tls_mbedtls.h @@ -55,6 +55,14 @@ ssize_t esp_mbedtls_get_bytes_avail(esp_tls_t *tls); */ esp_err_t esp_create_mbedtls_handle(const char *hostname, size_t hostlen, const void *cfg, esp_tls_t *tls); +/** + * mbedTLS function for Initializing socket wrappers + */ +static inline void esp_mbedtls_net_init(esp_tls_t *tls) +{ + mbedtls_net_init(&tls->server_fd); +} + #ifdef CONFIG_ESP_TLS_SERVER /** * Internal Callback for set_server_config diff --git a/components/esp-tls/private_include/esp_tls_wolfssl.h b/components/esp-tls/private_include/esp_tls_wolfssl.h index a04ad796cc..f29e9332f8 100644 --- a/components/esp-tls/private_include/esp_tls_wolfssl.h +++ b/components/esp-tls/private_include/esp_tls_wolfssl.h @@ -71,6 +71,13 @@ void esp_wolfssl_free_global_ca_store(void); */ esp_err_t esp_wolfssl_init_global_ca_store(void); +/** + * wolfSSL function for Initializing socket wrappers (no-operation for wolfSSL) + */ +static inline void esp_wolfssl_net_init(esp_tls_t *tls) +{ +} + #ifdef CONFIG_ESP_TLS_SERVER /**