mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-02 13:30:59 +02:00
Esp32 s3 support (#6341)
Co-authored-by: Jason2866 <24528715+Jason2866@users.noreply.github.com> Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com> Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com> Co-authored-by: Tomáš Pilný <34927466+PilnyTomas@users.noreply.github.com> Co-authored-by: Pedro Minatel <pedro.minatel@espressif.com> Co-authored-by: Ivan Grokhotkov <ivan@espressif.com> Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net>
This commit is contained in:
346
tools/sdk/esp32s3/include/tcp_transport/include/esp_transport.h
Normal file
346
tools/sdk/esp32s3/include/tcp_transport/include/esp_transport.h
Normal file
@ -0,0 +1,346 @@
|
||||
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_TRANSPORT_H_
|
||||
#define _ESP_TRANSPORT_H_
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Keep alive parameters structure
|
||||
*/
|
||||
typedef struct esp_transport_keepalive {
|
||||
bool keep_alive_enable; /*!< Enable keep-alive timeout */
|
||||
int keep_alive_idle; /*!< Keep-alive idle time (second) */
|
||||
int keep_alive_interval; /*!< Keep-alive interval time (second) */
|
||||
int keep_alive_count; /*!< Keep-alive packet retry send count */
|
||||
} esp_transport_keep_alive_t;
|
||||
|
||||
typedef struct esp_transport_internal* esp_transport_list_handle_t;
|
||||
typedef struct esp_transport_item_t* esp_transport_handle_t;
|
||||
|
||||
typedef int (*connect_func)(esp_transport_handle_t t, const char *host, int port, int timeout_ms);
|
||||
typedef int (*io_func)(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms);
|
||||
typedef int (*io_read_func)(esp_transport_handle_t t, char *buffer, int len, int timeout_ms);
|
||||
typedef int (*trans_func)(esp_transport_handle_t t);
|
||||
typedef int (*poll_func)(esp_transport_handle_t t, int timeout_ms);
|
||||
typedef int (*connect_async_func)(esp_transport_handle_t t, const char *host, int port, int timeout_ms);
|
||||
typedef esp_transport_handle_t (*payload_transfer_func)(esp_transport_handle_t);
|
||||
|
||||
typedef struct esp_tls_last_error* esp_tls_error_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Create transport list
|
||||
*
|
||||
* @return A handle can hold all transports
|
||||
*/
|
||||
esp_transport_list_handle_t esp_transport_list_init(void);
|
||||
|
||||
/**
|
||||
* @brief Cleanup and free all transports, include itself,
|
||||
* this function will invoke esp_transport_destroy of every transport have added this the list
|
||||
*
|
||||
* @param[in] list The list
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_transport_list_destroy(esp_transport_list_handle_t list);
|
||||
|
||||
/**
|
||||
* @brief Add a transport to the list, and define a scheme to indentify this transport in the list
|
||||
*
|
||||
* @param[in] list The list
|
||||
* @param[in] t The Transport
|
||||
* @param[in] scheme The scheme
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
*/
|
||||
esp_err_t esp_transport_list_add(esp_transport_list_handle_t list, esp_transport_handle_t t, const char *scheme);
|
||||
|
||||
/**
|
||||
* @brief This function will remove all transport from the list,
|
||||
* invoke esp_transport_destroy of every transport have added this the list
|
||||
*
|
||||
* @param[in] list The list
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_ERR_INVALID_ARG
|
||||
*/
|
||||
esp_err_t esp_transport_list_clean(esp_transport_list_handle_t list);
|
||||
|
||||
/**
|
||||
* @brief Get the transport by scheme, which has been defined when calling function `esp_transport_list_add`
|
||||
*
|
||||
* @param[in] list The list
|
||||
* @param[in] tag The tag
|
||||
*
|
||||
* @return The transport handle
|
||||
*/
|
||||
esp_transport_handle_t esp_transport_list_get_transport(esp_transport_list_handle_t list, const char *scheme);
|
||||
|
||||
/**
|
||||
* @brief Initialize a transport handle object
|
||||
*
|
||||
* @return The transport handle
|
||||
*/
|
||||
esp_transport_handle_t esp_transport_init(void);
|
||||
|
||||
/**
|
||||
* @brief Cleanup and free memory the transport
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_transport_destroy(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Get default port number used by this transport
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
*
|
||||
* @return the port number
|
||||
*/
|
||||
int esp_transport_get_default_port(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Set default port number that can be used by this transport
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] port The port number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_transport_set_default_port(esp_transport_handle_t t, int port);
|
||||
|
||||
/**
|
||||
* @brief Transport connection function, to make a connection to server
|
||||
*
|
||||
* @param t The transport handle
|
||||
* @param[in] host Hostname
|
||||
* @param[in] port Port
|
||||
* @param[in] timeout_ms The timeout milliseconds (-1 indicates wait forever)
|
||||
*
|
||||
* @return
|
||||
* - socket for will use by this transport
|
||||
* - (-1) if there are any errors, should check errno
|
||||
*/
|
||||
int esp_transport_connect(esp_transport_handle_t t, const char *host, int port, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Non-blocking transport connection function, to make a connection to server
|
||||
*
|
||||
* @param t The transport handle
|
||||
* @param[in] host Hostname
|
||||
* @param[in] port Port
|
||||
* @param[in] timeout_ms The timeout milliseconds (-1 indicates wait forever)
|
||||
*
|
||||
* @return
|
||||
* - socket for will use by this transport
|
||||
* - (-1) if there are any errors, should check errno
|
||||
*/
|
||||
int esp_transport_connect_async(esp_transport_handle_t t, const char *host, int port, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Transport read function
|
||||
*
|
||||
* @param t The transport handle
|
||||
* @param buffer The buffer
|
||||
* @param[in] len The length
|
||||
* @param[in] timeout_ms The timeout milliseconds (-1 indicates wait forever)
|
||||
*
|
||||
* @return
|
||||
* - Number of bytes was read
|
||||
* - (-1) if there are any errors, should check errno
|
||||
*/
|
||||
int esp_transport_read(esp_transport_handle_t t, char *buffer, int len, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Poll the transport until readable or timeout
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] timeout_ms The timeout milliseconds (-1 indicates wait forever)
|
||||
*
|
||||
* @return
|
||||
* - 0 Timeout
|
||||
* - (-1) If there are any errors, should check errno
|
||||
* - other The transport can read
|
||||
*/
|
||||
int esp_transport_poll_read(esp_transport_handle_t t, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Transport write function
|
||||
*
|
||||
* @param t The transport handle
|
||||
* @param buffer The buffer
|
||||
* @param[in] len The length
|
||||
* @param[in] timeout_ms The timeout milliseconds (-1 indicates wait forever)
|
||||
*
|
||||
* @return
|
||||
* - Number of bytes was written
|
||||
* - (-1) if there are any errors, should check errno
|
||||
*/
|
||||
int esp_transport_write(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Poll the transport until writeable or timeout
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] timeout_ms The timeout milliseconds (-1 indicates wait forever)
|
||||
*
|
||||
* @return
|
||||
* - 0 Timeout
|
||||
* - (-1) If there are any errors, should check errno
|
||||
* - other The transport can write
|
||||
*/
|
||||
int esp_transport_poll_write(esp_transport_handle_t t, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Transport close
|
||||
*
|
||||
* @param t The transport handle
|
||||
*
|
||||
* @return
|
||||
* - 0 if ok
|
||||
* - (-1) if there are any errors, should check errno
|
||||
*/
|
||||
int esp_transport_close(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Get user data context of this transport
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
*
|
||||
* @return The user data context
|
||||
*/
|
||||
void *esp_transport_get_context_data(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Get transport handle of underlying protocol
|
||||
* which can access this protocol payload directly
|
||||
* (used for receiving longer msg multiple times)
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
*
|
||||
* @return Payload transport handle
|
||||
*/
|
||||
esp_transport_handle_t esp_transport_get_payload_transport_handle(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Set the user context data for this transport
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param data The user data context
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
*/
|
||||
esp_err_t esp_transport_set_context_data(esp_transport_handle_t t, void *data);
|
||||
|
||||
/**
|
||||
* @brief Set transport functions for the transport handle
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] _connect The connect function pointer
|
||||
* @param[in] _read The read function pointer
|
||||
* @param[in] _write The write function pointer
|
||||
* @param[in] _close The close function pointer
|
||||
* @param[in] _poll_read The poll read function pointer
|
||||
* @param[in] _poll_write The poll write function pointer
|
||||
* @param[in] _destroy The destroy function pointer
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
*/
|
||||
esp_err_t esp_transport_set_func(esp_transport_handle_t t,
|
||||
connect_func _connect,
|
||||
io_read_func _read,
|
||||
io_func _write,
|
||||
trans_func _close,
|
||||
poll_func _poll_read,
|
||||
poll_func _poll_write,
|
||||
trans_func _destroy);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set transport functions for the transport handle
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] _connect_async_func The connect_async function pointer
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_transport_set_async_connect_func(esp_transport_handle_t t, connect_async_func _connect_async_func);
|
||||
|
||||
/**
|
||||
* @brief Set parent transport function to the handle
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] _parent_transport The underlying transport getter pointer
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_transport_set_parent_transport_func(esp_transport_handle_t t, payload_transfer_func _parent_transport);
|
||||
|
||||
/**
|
||||
* @brief Returns esp_tls error handle.
|
||||
* Warning: The returned pointer is valid only as long as esp_transport_handle_t exists. Once transport
|
||||
* handle gets destroyed, this value (esp_tls_error_handle_t) is freed automatically.
|
||||
*
|
||||
* @param[in] A transport handle
|
||||
*
|
||||
* @return
|
||||
* - valid pointer of esp_error_handle_t
|
||||
* - NULL if invalid transport handle
|
||||
*/
|
||||
esp_tls_error_handle_t esp_transport_get_error_handle(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Get and clear last captured socket errno
|
||||
*
|
||||
* Socket errno is internally stored whenever any of public facing API
|
||||
* for reading, writing, polling or connection fails returning negative return code.
|
||||
* The error code corresponds to the `SO_ERROR` value retrieved from the underlying
|
||||
* transport socket using `getsockopt()` API. After reading the captured errno,
|
||||
* the internal value is cleared to 0.
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
*
|
||||
* @return
|
||||
* - >=0 Last captured socket errno
|
||||
* - -1 Invalid transport handle or invalid transport's internal error storage
|
||||
*/
|
||||
int esp_transport_get_errno(esp_transport_handle_t t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _ESP_TRANSPORT_ */
|
@ -0,0 +1,196 @@
|
||||
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_TRANSPORT_SSL_H_
|
||||
#define _ESP_TRANSPORT_SSL_H_
|
||||
|
||||
#include "esp_transport.h"
|
||||
#include "esp_tls.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create new SSL transport, the transport handle must be release esp_transport_destroy callback
|
||||
*
|
||||
* @return the allocated esp_transport_handle_t, or NULL if the handle can not be allocated
|
||||
*/
|
||||
esp_transport_handle_t esp_transport_ssl_init(void);
|
||||
|
||||
/**
|
||||
* @brief Set SSL certificate data (as PEM format).
|
||||
* Note that, this function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] data The pem data
|
||||
* @param[in] len The length
|
||||
*/
|
||||
void esp_transport_ssl_set_cert_data(esp_transport_handle_t t, const char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief Set SSL certificate data (as DER format).
|
||||
* Note that, this function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] data The der data
|
||||
* @param[in] len The length
|
||||
*/
|
||||
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
|
||||
* an SSL connection.
|
||||
* It must be first enabled in menuconfig.
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] crt_bundle_attach Function pointer to esp_crt_bundle_attach
|
||||
*/
|
||||
void esp_transport_ssl_crt_bundle_attach(esp_transport_handle_t t, esp_err_t ((*crt_bundle_attach)(void *conf)));
|
||||
|
||||
/**
|
||||
* @brief Enable global CA store for SSL connection
|
||||
*
|
||||
* @param t ssl transport
|
||||
*/
|
||||
void esp_transport_ssl_enable_global_ca_store(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Set SSL client certificate data for mutual authentication (as PEM format).
|
||||
* Note that, this function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] data The pem data
|
||||
* @param[in] len The length
|
||||
*/
|
||||
void esp_transport_ssl_set_client_cert_data(esp_transport_handle_t t, const char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief Set SSL client certificate data for mutual authentication (as DER format).
|
||||
* Note that, this function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] data The der data
|
||||
* @param[in] len The length
|
||||
*/
|
||||
void esp_transport_ssl_set_client_cert_data_der(esp_transport_handle_t t, const char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief Set SSL client key data for mutual authentication (as PEM format).
|
||||
* Note that, this function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] data The pem data
|
||||
* @param[in] len The length
|
||||
*/
|
||||
void esp_transport_ssl_set_client_key_data(esp_transport_handle_t t, const char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief Set SSL client key password if the key is password protected. The configured
|
||||
* password is passed to the underlying TLS stack to decrypt the client key
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] password Pointer to the password
|
||||
* @param[in] password_len Password length
|
||||
*/
|
||||
void esp_transport_ssl_set_client_key_password(esp_transport_handle_t t, const char *password, int password_len);
|
||||
|
||||
/**
|
||||
* @brief Set SSL client key data for mutual authentication (as DER format).
|
||||
* Note that, this function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] data The der data
|
||||
* @param[in] len The length
|
||||
*/
|
||||
void esp_transport_ssl_set_client_key_data_der(esp_transport_handle_t t, const char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief Set the list of supported application protocols to be used with ALPN.
|
||||
* Note that, this function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] alpn_porot The list of ALPN protocols, the last entry must be NULL
|
||||
*/
|
||||
void esp_transport_ssl_set_alpn_protocol(esp_transport_handle_t t, const char **alpn_protos);
|
||||
|
||||
/**
|
||||
* @brief Skip validation of certificate's common name field
|
||||
*
|
||||
* @note Skipping CN validation is not recommended
|
||||
*
|
||||
* @param t ssl transport
|
||||
*/
|
||||
void esp_transport_ssl_skip_common_name_check(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Set the ssl context to use secure element (atecc608a) for client(device) private key and certificate
|
||||
*
|
||||
* @note Recommended to be used with ESP32-WROOM-32SE (which has inbuilt ATECC608A a.k.a Secure Element)
|
||||
*
|
||||
* @param t ssl transport
|
||||
*/
|
||||
void esp_transport_ssl_use_secure_element(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Set the ds_data handle in ssl context.(used for the digital signature operation)
|
||||
*
|
||||
* @param t ssl transport
|
||||
* ds_data the handle for ds data params
|
||||
*/
|
||||
void esp_transport_ssl_set_ds_data(esp_transport_handle_t t, void *ds_data);
|
||||
|
||||
/**
|
||||
* @brief Set PSK key and hint for PSK server/client verification in esp-tls component.
|
||||
* Important notes:
|
||||
* - This function stores the pointer to data, rather than making a copy.
|
||||
* So this data must remain valid until after the connection is cleaned up
|
||||
* - ESP_TLS_PSK_VERIFICATION config option must be enabled in menuconfig
|
||||
* - certificate verification takes priority so it must not be configured
|
||||
* to enable PSK method.
|
||||
*
|
||||
* @param t ssl transport
|
||||
* @param[in] psk_hint_key psk key and hint structure defined in esp_tls.h
|
||||
*/
|
||||
void esp_transport_ssl_set_psk_key_hint(esp_transport_handle_t t, const psk_hint_key_t* psk_hint_key);
|
||||
|
||||
/**
|
||||
* @brief Set keep-alive status in current ssl context
|
||||
*
|
||||
* @param[in] t ssl transport
|
||||
* @param[in] keep_alive_cfg The handle for keep-alive configuration
|
||||
*/
|
||||
void esp_transport_ssl_set_keep_alive(esp_transport_handle_t t, esp_transport_keep_alive_t *keep_alive_cfg);
|
||||
|
||||
/**
|
||||
* @brief Set name of interface that socket can be binded on
|
||||
* So the data can transport on this interface
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] if_name The interface name
|
||||
*/
|
||||
void esp_transport_ssl_set_interface_name(esp_transport_handle_t t, struct ifreq *if_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _ESP_TRANSPORT_SSL_H_ */
|
@ -0,0 +1,55 @@
|
||||
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_TRANSPORT_TCP_H_
|
||||
#define _ESP_TRANSPORT_TCP_H_
|
||||
|
||||
#include "esp_transport.h"
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Set TCP keep-alive configuration
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] keep_alive_cfg The keep-alive config
|
||||
*
|
||||
*/
|
||||
void esp_transport_tcp_set_keep_alive(esp_transport_handle_t t, esp_transport_keep_alive_t *keep_alive_cfg);
|
||||
|
||||
/**
|
||||
* @brief Set name of interface that socket can be binded on
|
||||
* So the data can transport on this interface
|
||||
*
|
||||
* @param[in] t The transport handle
|
||||
* @param[in] if_name The interface name
|
||||
*/
|
||||
void esp_transport_tcp_set_interface_name(esp_transport_handle_t t, struct ifreq *if_name);
|
||||
|
||||
/**
|
||||
* @brief Create TCP transport, the transport handle must be release esp_transport_destroy callback
|
||||
*
|
||||
* @return the allocated esp_transport_handle_t, or NULL if the handle can not be allocated
|
||||
*/
|
||||
esp_transport_handle_t esp_transport_tcp_init(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_TRANSPORT_TCP_H_ */
|
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE', which is part of this source code package.
|
||||
* Tuan PM <tuanpm at live dot com>
|
||||
*/
|
||||
|
||||
#ifndef _ESP_TRANSPORT_WS_H_
|
||||
#define _ESP_TRANSPORT_WS_H_
|
||||
|
||||
#include "esp_transport.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum ws_transport_opcodes {
|
||||
WS_TRANSPORT_OPCODES_CONT = 0x00,
|
||||
WS_TRANSPORT_OPCODES_TEXT = 0x01,
|
||||
WS_TRANSPORT_OPCODES_BINARY = 0x02,
|
||||
WS_TRANSPORT_OPCODES_CLOSE = 0x08,
|
||||
WS_TRANSPORT_OPCODES_PING = 0x09,
|
||||
WS_TRANSPORT_OPCODES_PONG = 0x0a,
|
||||
WS_TRANSPORT_OPCODES_FIN = 0x80,
|
||||
WS_TRANSPORT_OPCODES_NONE = 0x100, /*!< not a valid opcode to indicate no message previously received
|
||||
* from the API esp_transport_ws_get_read_opcode() */
|
||||
} ws_transport_opcodes_t;
|
||||
|
||||
/**
|
||||
* WS transport configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
const char *ws_path; /*!< HTTP path to update protocol to websocket */
|
||||
const char *sub_protocol; /*!< WS subprotocol */
|
||||
const char *user_agent; /*!< WS user agent */
|
||||
const char *headers; /*!< WS additional headers */
|
||||
bool propagate_control_frames; /*!< If true, control frames are passed to the reader
|
||||
* If false, only user frames are propagated, control frames are handled
|
||||
* automatically during read operations
|
||||
*/
|
||||
} esp_transport_ws_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create web socket transport
|
||||
*
|
||||
* @return
|
||||
* - transport
|
||||
* - NULL
|
||||
*/
|
||||
esp_transport_handle_t esp_transport_ws_init(esp_transport_handle_t parent_handle);
|
||||
|
||||
/**
|
||||
* @brief Set HTTP path to update protocol to websocket
|
||||
*
|
||||
* @param t websocket transport handle
|
||||
* @param path The HTTP Path
|
||||
*/
|
||||
void esp_transport_ws_set_path(esp_transport_handle_t t, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Set websocket sub protocol header
|
||||
*
|
||||
* @param t websocket transport handle
|
||||
* @param sub_protocol Sub protocol string
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - One of the error codes
|
||||
*/
|
||||
esp_err_t esp_transport_ws_set_subprotocol(esp_transport_handle_t t, const char *sub_protocol);
|
||||
|
||||
/**
|
||||
* @brief Set websocket user-agent header
|
||||
*
|
||||
* @param t websocket transport handle
|
||||
* @param sub_protocol user-agent string
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - One of the error codes
|
||||
*/
|
||||
esp_err_t esp_transport_ws_set_user_agent(esp_transport_handle_t t, const char *user_agent);
|
||||
|
||||
/**
|
||||
* @brief Set websocket additional headers
|
||||
*
|
||||
* @param t websocket transport handle
|
||||
* @param sub_protocol additional header strings each terminated with \r\n
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - One of the error codes
|
||||
*/
|
||||
esp_err_t esp_transport_ws_set_headers(esp_transport_handle_t t, const char *headers);
|
||||
|
||||
/**
|
||||
* @brief Set websocket transport parameters
|
||||
*
|
||||
* @param t websocket transport handle
|
||||
* @param config pointer to websocket config structure
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - One of the error codes
|
||||
*/
|
||||
esp_err_t esp_transport_ws_set_config(esp_transport_handle_t t, const esp_transport_ws_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Sends websocket raw message with custom opcode and payload
|
||||
*
|
||||
* Note that generic esp_transport_write for ws handle sends
|
||||
* binary massages by default if size is > 0 and
|
||||
* ping message if message size is set to 0.
|
||||
* This API is provided to support explicit messages with arbitrary opcode,
|
||||
* should it be PING, PONG or TEXT message with arbitrary data.
|
||||
*
|
||||
* @param[in] t Websocket transport handle
|
||||
* @param[in] opcode ws operation code
|
||||
* @param[in] buffer The buffer
|
||||
* @param[in] len The length
|
||||
* @param[in] timeout_ms The timeout milliseconds (-1 indicates block forever)
|
||||
*
|
||||
* @return
|
||||
* - Number of bytes was written
|
||||
* - (-1) if there are any errors, should check errno
|
||||
*/
|
||||
int esp_transport_ws_send_raw(esp_transport_handle_t t, ws_transport_opcodes_t opcode, const char *b, int len, int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Returns websocket op-code for last received data
|
||||
*
|
||||
* @param t websocket transport handle
|
||||
*
|
||||
* @return
|
||||
* - Received op-code as enum
|
||||
*/
|
||||
ws_transport_opcodes_t esp_transport_ws_get_read_opcode(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Returns payload length of the last received data
|
||||
*
|
||||
* @param t websocket transport handle
|
||||
*
|
||||
* @return
|
||||
* - Number of bytes in the payload
|
||||
*/
|
||||
int esp_transport_ws_get_read_payload_len(esp_transport_handle_t t);
|
||||
|
||||
/**
|
||||
* @brief Polls the active connection for termination
|
||||
*
|
||||
* This API is typically used by the client to wait for clean connection closure
|
||||
* by websocket server
|
||||
*
|
||||
* @param t Websocket transport handle
|
||||
* @param[in] timeout_ms The timeout milliseconds
|
||||
*
|
||||
* @return
|
||||
* 0 - no activity on read and error socket descriptor within timeout
|
||||
* 1 - Success: either connection terminated by FIN or the most common RST err codes
|
||||
* -1 - Failure: Unexpected error code or socket is normally readable
|
||||
*/
|
||||
int esp_transport_ws_poll_connection_closed(esp_transport_handle_t t, int timeout_ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_TRANSPORT_WS_H_ */
|
Reference in New Issue
Block a user