From 2dd280f1264bb8c77a05930c81e8890395867ad1 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 10 Apr 2023 13:55:05 +0530 Subject: [PATCH] esp-tls: Added getter/setter function for the conn_state. * Added the setter function to set the connection sockfd value Closes https://github.com/espressif/esp-idf/issues/10871 --- components/esp-tls/esp_tls.c | 30 ++++++++++++++++++++++++++++++ components/esp-tls/esp_tls.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/components/esp-tls/esp_tls.c b/components/esp-tls/esp_tls.c index 4b40f56a4d93..799c30acf61b 100644 --- a/components/esp-tls/esp_tls.c +++ b/components/esp-tls/esp_tls.c @@ -698,6 +698,36 @@ esp_err_t esp_tls_get_conn_sockfd(esp_tls_t *tls, int *sockfd) return ESP_OK; } +esp_err_t esp_tls_set_conn_sockfd(esp_tls_t *tls, int sockfd) +{ + if (!tls || sockfd < 0) { + ESP_LOGE(TAG, "Invalid arguments passed"); + return ESP_ERR_INVALID_ARG; + } + tls->sockfd = sockfd; + return ESP_OK; +} + +esp_err_t esp_tls_get_conn_state(esp_tls_t *tls, esp_tls_conn_state_t *conn_state) +{ + if (!tls || !conn_state) { + ESP_LOGE(TAG, "Invalid arguments passed"); + return ESP_ERR_INVALID_ARG; + } + *conn_state = tls->conn_state; + return ESP_OK; +} + +esp_err_t esp_tls_set_conn_state(esp_tls_t *tls, esp_tls_conn_state_t conn_state) +{ + if (!tls || conn_state < ESP_TLS_INIT || conn_state > ESP_TLS_DONE) { + ESP_LOGE(TAG, "Invalid arguments passed"); + return ESP_ERR_INVALID_ARG; + } + tls->conn_state = conn_state; + return ESP_OK; +} + esp_err_t esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *esp_tls_code, int *esp_tls_flags) { if (!h) { diff --git a/components/esp-tls/esp_tls.h b/components/esp-tls/esp_tls.h index 0efe587b53b1..555caed37d7a 100644 --- a/components/esp-tls/esp_tls.h +++ b/components/esp-tls/esp_tls.h @@ -502,6 +502,42 @@ ssize_t esp_tls_get_bytes_avail(esp_tls_t *tls); */ esp_err_t esp_tls_get_conn_sockfd(esp_tls_t *tls, int *sockfd); +/** + * @brief Sets the connection socket file descriptor for the esp_tls session + * + * @param[in] tls handle to esp_tls context + * + * @param[in] sockfd sockfd value to set. + * + * @return - ESP_OK on success and value of sockfd for the tls connection shall updated withthe provided value + * - ESP_ERR_INVALID_ARG if (tls == NULL || sockfd < 0) + */ +esp_err_t esp_tls_set_conn_sockfd(esp_tls_t *tls, int sockfd); + +/** + * @brief Gets the connection state for the esp_tls session + * + * @param[in] tls handle to esp_tls context + * + * @param[out] conn_state pointer to the connection state value. + * + * @return - ESP_OK on success and value of sockfd for the tls connection shall updated withthe provided value + * - ESP_ERR_INVALID_ARG (Invalid arguments) + */ +esp_err_t esp_tls_get_conn_state(esp_tls_t *tls, esp_tls_conn_state_t *conn_state); + +/** + * @brief Sets the connection state for the esp_tls session + * + * @param[in] tls handle to esp_tls context + * + * @param[in] conn_state connection state value to set. + * + * @return - ESP_OK on success and value of sockfd for the tls connection shall updated withthe provided value + * - ESP_ERR_INVALID_ARG (Invalid arguments) + */ +esp_err_t esp_tls_set_conn_state(esp_tls_t *tls, esp_tls_conn_state_t conn_state); + /** * @brief Returns the ssl context *