diff --git a/include/libwebsockets.h b/include/libwebsockets.h index e977afc4a..ab36ed89a 100644 --- a/include/libwebsockets.h +++ b/include/libwebsockets.h @@ -219,9 +219,12 @@ typedef unsigned long long lws_intptr_t; #if defined(LWS_WITH_MBEDTLS) #if defined(LWS_WITH_ESP32) /* this filepath is passed to us but without quotes or <> */ +#if !defined(LWS_AMAZON_RTOS) +/* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ #undef MBEDTLS_CONFIG_FILE #define MBEDTLS_CONFIG_FILE #endif +#endif #include #else #include diff --git a/include/libwebsockets/lws-esp32.h b/include/libwebsockets/lws-esp32.h index 2d1c0f42b..523693c78 100644 --- a/include/libwebsockets/lws-esp32.h +++ b/include/libwebsockets/lws-esp32.h @@ -36,6 +36,12 @@ struct pollfd { #define POLLHUP 0x0010 #define POLLNVAL 0x0020 +#if defined(LWS_AMAZON_RTOS) +#include +#include +#include +#include "timers.h" +#else /* LWS_AMAZON_RTOS */ #include #include #include @@ -47,6 +53,7 @@ struct pollfd { #include "driver/gpio.h" #include "esp_spi_flash.h" #include "freertos/timers.h" +#endif /* LWS_AMAZON_RTOS */ #if !defined(CONFIG_FREERTOS_HZ) #define CONFIG_FREERTOS_HZ 100 @@ -99,6 +106,9 @@ static LWS_INLINE void uv_close(uv_handle_t *h, void *v) xTimerDelete(*(uv_timer_t *)h, 0); } + +#if !defined(LWS_AMAZON_RTOS) + /* ESP32 helper declarations */ #include @@ -224,3 +234,5 @@ extern uint16_t lws_esp32_sine_interp(int n); /* required in external code by esp32 plat (may just return if no leds) */ extern void lws_esp32_leds_timer_cb(TimerHandle_t th); + +#endif /* LWS_AMAZON_RTOS */ diff --git a/lib/core-net/adopt.c b/lib/core-net/adopt.c index bf956508f..0513701d9 100644 --- a/lib/core-net/adopt.c +++ b/lib/core-net/adopt.c @@ -214,9 +214,11 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, if (new_wsi->role_ops->adoption_cb[lwsi_role_server(new_wsi)]) n = new_wsi->role_ops->adoption_cb[lwsi_role_server(new_wsi)]; +#if !defined(LWS_AMAZON_RTOS) if (context->event_loop_ops->accept) if (context->event_loop_ops->accept(new_wsi)) goto fail; +#endif #if LWS_MAX_SMP > 1 /* diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 175ab340d..b3c4f90ce 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -862,9 +862,11 @@ lws_create_event_pipes(struct lws_context *context) wsi->desc.sockfd = context->pt[n].dummy_pipe_fds[0]; lwsl_debug("event pipe fd %d\n", wsi->desc.sockfd); +#if !defined(LWS_AMAZON_RTOS) if (context->event_loop_ops->accept) if (context->event_loop_ops->accept(wsi)) return 1; +#endif if (__insert_wsi_socket_into_fds(context, wsi)) return 1; diff --git a/lib/core/alloc.c b/lib/core/alloc.c index d28c9f7a0..09d8882b0 100644 --- a/lib/core/alloc.c +++ b/lib/core/alloc.c @@ -88,7 +88,11 @@ _realloc(void *ptr, size_t size, const char *reason) if (size) { #if defined(LWS_WITH_ESP32) lwsl_notice("%s: size %lu: %s (free heap %d)\n", __func__, +#if defined(LWS_AMAZON_RTOS) + (unsigned long)size, reason, (unsigned int)xPortGetFreeHeapSize() - (int)size); +#else (unsigned long)size, reason, (unsigned int)esp_get_free_heap_size() - (int)size); +#endif #else lwsl_debug("%s: size %lu: %s\n", __func__, (unsigned long)size, reason); diff --git a/lib/core/context.c b/lib/core/context.c index 67367c2a9..942b1ef8e 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -413,8 +413,10 @@ lwsl_info("context created\n"); goto bail; } +#if !defined(LWS_AMAZON_RTOS) if (lws_create_event_pipes(context)) goto bail; +#endif #endif lws_context_init_ssl_library(info); @@ -786,5 +788,14 @@ lws_context_destroy(struct lws_context *context) } #endif +#if defined(LWS_WITH_ESP32) +#if defined(LWS_AMAZON_RTOS) + context->last_free_heap = xPortGetFreeHeapSize(); +#else + context->last_free_heap = esp_get_free_heap_size(); +#endif +#endif + lws_context_destroy2(context); } + diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index fe4922640..771bd5824 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -66,6 +66,7 @@ lws_hex_to_byte_array(const char *h, uint8_t *dest, int max) #if !defined(LWS_PLAT_OPTEE) +#if !defined(LWS_AMAZON_RTOS) int lws_open(const char *__file, int __oflag, ...) { va_list ap; @@ -92,7 +93,7 @@ int lws_open(const char *__file, int __oflag, ...) return n; } #endif - +#endif #if !(defined(LWS_PLAT_OPTEE) && !defined(LWS_WITH_NETWORK)) @@ -582,7 +583,11 @@ typedef enum { LWS_TOKZS_TOKEN_POST_TERMINAL } lws_tokenize_state; +#if defined(LWS_AMAZON_RTOS) +lws_tokenize_elem +#else int +#endif lws_tokenize(struct lws_tokenize *ts) { const char *rfc7230_delims = "(),/:;<=>?@[\\]{}"; diff --git a/lib/plat/esp32/esp32-file.c b/lib/plat/esp32/esp32-file.c index 92d7dd584..f2909bb70 100644 --- a/lib/plat/esp32/esp32-file.c +++ b/lib/plat/esp32/esp32-file.c @@ -111,6 +111,13 @@ _lws_plat_file_write(lws_fop_fd_t fops_fd, lws_filepos_t *amount, return 0; } +#if defined(LWS_AMAZON_RTOS) +int +lws_find_string_in_file(const char *filename, const char *string, int stringlen) +{ + return 0; +} +#else int lws_find_string_in_file(const char *filename, const char *string, int stringlen) { @@ -140,8 +147,9 @@ lws_find_string_in_file(const char *filename, const char *string, int stringlen) return !strcmp(p + 1, result); } +#endif - +#if !defined(LWS_AMAZON_RTOS) LWS_VISIBLE int lws_plat_write_file(const char *filename, void *buf, int len) { @@ -212,4 +220,4 @@ bail: return -1; } - +#endif /* LWS_AMAZON_RTOS */ diff --git a/lib/plat/esp32/esp32-misc.c b/lib/plat/esp32/esp32-misc.c index af8773257..ffb663152 100644 --- a/lib/plat/esp32/esp32-misc.c +++ b/lib/plat/esp32/esp32-misc.c @@ -35,7 +35,11 @@ lws_get_random(struct lws_context *context, void *buf, int len) uint8_t *pb = buf; while (len) { +#if defined(LWS_AMAZON_RTOS) + uint32_t r = rand(); +#else uint32_t r = esp_random(); +#endif uint8_t *p = (uint8_t *)&r; int b = 4; diff --git a/lib/plat/esp32/esp32-service.c b/lib/plat/esp32/esp32-service.c index 2f7f05e26..62b9d74c6 100644 --- a/lib/plat/esp32/esp32-service.c +++ b/lib/plat/esp32/esp32-service.c @@ -27,7 +27,9 @@ lws_plat_service(struct lws_context *context, int timeout_ms) int n = _lws_plat_service_tsi(context, timeout_ms, 0); lws_service_fd_tsi(context, NULL, 0); +#if !defined(LWS_AMAZON_RTOS) esp_task_wdt_reset(); +#endif return n; } @@ -52,7 +54,11 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) if (m > context->time_last_state_dump) { context->time_last_state_dump = m; +#if defined(LWS_AMAZON_RTOS) + n = xPortGetFreeHeapSize(); +#else n = esp_get_free_heap_size(); +#endif if (n != context->last_free_heap) { if (n > context->last_free_heap) lwsl_notice(" heap :%d (+%d)\n", n, diff --git a/lib/plat/esp32/private.h b/lib/plat/esp32/private.h index 4726dfa68..d3e0d826b 100644 --- a/lib/plat/esp32/private.h +++ b/lib/plat/esp32/private.h @@ -24,7 +24,10 @@ #define MSG_NOSIGNAL 0 #define SOMAXCONN 3 +#if !defined(LWS_AMAZON_RTOS) #include +#endif + #include #include #include @@ -37,12 +40,20 @@ #endif #include #include +#if !defined(LWS_AMAZON_RTOS) #include +#endif -#include "freertos/timers.h" -#include -#include -#include +#if defined(LWS_AMAZON_RTOS) + #include "FreeRTOS.h" + #include "timers.h" + #include +#else + #include "freertos/timers.h" + #include + #include + #include +#endif #include "lwip/apps/sntp.h" diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index 984560983..a953a02f1 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -446,6 +446,17 @@ lws_h2_settings(struct lws *wsi, struct http2_settings *settings, "Inital Window beyond max"); return 1; } + +#if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_NOART) + //FIXME: Workaround for FIRMWARE-4632 until cloud-side issue is fixed. + if (b == 0x7fffffff) { + b = 65535; + lwsl_info("init window size 0x7fffffff\n"); + break; + } + //FIXME: end of FIRMWARE-4632 workaround +#endif + /* * In addition to changing the flow-control window for * streams that are not yet active, a SETTINGS frame @@ -822,8 +833,13 @@ lws_h2_parse_frame_header(struct lws *wsi) } /* let the network wsi live a bit longer if subs are active */ + if (!wsi->immortal_substream_count) +#if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_NOART) + lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, wsi->vhost->keepalive_timeout); +#else lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, 31); +#endif if (h2n->sid) h2n->swsi = lws_h2_wsi_from_id(wsi, h2n->sid); @@ -1808,7 +1824,11 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, if (!wsi->immortal_substream_count) lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, +#if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_NOART) + wsi->vhost->keepalive_timeout); +#else 31); +#endif if (!h2n->swsi) break; diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 24828690b..d77b8d50e 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -620,12 +620,14 @@ ads_known: lwsi_set_state(wsi, LRS_WAITING_CONNECT); +#if !defined(LWS_AMAZON_RTOS) if (wsi->context->event_loop_ops->accept) if (wsi->context->event_loop_ops->accept(wsi)) { compatible_close(wsi->desc.sockfd); cce = "event loop accept failed"; goto oom4; } +#endif if (__insert_wsi_socket_into_fds(wsi->context, wsi)) { compatible_close(wsi->desc.sockfd); diff --git a/lib/roles/http/server/parsers.c b/lib/roles/http/server/parsers.c index 2d0386cb7..0ce2a2bad 100644 --- a/lib/roles/http/server/parsers.c +++ b/lib/roles/http/server/parsers.c @@ -22,7 +22,11 @@ #include "core/private.h" static const unsigned char lextable[] = { +#if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_NOART) + #include "roles/http/lextable.h" +#else #include "../lextable.h" +#endif }; #define FAIL_CHAR 0x08 diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index 3641963c9..2523d7018 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -38,6 +38,7 @@ static const char * const intermediates[] = { "private", "public" }; * REQUIRES CONTEXT LOCK HELD */ +#ifndef LWS_NO_SERVER int _lws_vhost_init_server(const struct lws_context_creation_info *info, struct lws_vhost *vhost) @@ -315,6 +316,7 @@ bail: return -1; } +#endif struct lws_vhost * lws_select_vhost(struct lws_context *context, int port, const char *servername) @@ -462,6 +464,7 @@ lws_vfs_prepare_flags(struct lws *wsi) return f; } +#if !defined(LWS_AMAZON_RTOS) static int lws_http_serve(struct lws *wsi, char *uri, const char *origin, const struct lws_http_mount *m) @@ -741,6 +744,7 @@ notfound: return 1; } +#endif #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) const struct lws_http_mount * @@ -1565,8 +1569,10 @@ lws_http_action(struct lws *wsi) wsi->cache_intermediaries = hit->cache_intermediaries; m = 1; +#if !defined(LWS_AMAZON_RTOS) if (hit->origin_protocol == LWSMPRO_FILE) m = lws_http_serve(wsi, s, hit->origin, hit); +#endif if (m > 0) { /* @@ -1756,6 +1762,7 @@ bad_format: return 1; } +#if !defined(LWS_NO_SERVER) int lws_http_to_fallback(struct lws *wsi, unsigned char *obuf, size_t olen) { @@ -2104,6 +2111,7 @@ bail_nuke_ah: return 1; } +#endif LWS_VISIBLE int LWS_WARN_UNUSED_RESULT lws_http_transaction_completed(struct lws *wsi) @@ -2252,7 +2260,7 @@ lws_http_transaction_completed(struct lws *wsi) return 0; } - +#if !defined(LWS_AMAZON_RTOS) LWS_VISIBLE int lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, const char *other_headers, int other_headers_len) @@ -2533,6 +2541,7 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, return 0; } +#endif LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi) { @@ -2809,7 +2818,7 @@ file_had_it: return -1; } - +#ifndef LWS_NO_SERVER LWS_VISIBLE void lws_server_get_canonical_hostname(struct lws_context *context, const struct lws_context_creation_info *info) @@ -2827,7 +2836,7 @@ lws_server_get_canonical_hostname(struct lws_context *context, (void)context; #endif } - +#endif LWS_VISIBLE LWS_EXTERN int lws_chunked_html_process(struct lws_process_html_args *args, diff --git a/lib/tls/mbedtls/mbedtls-server.c b/lib/tls/mbedtls/mbedtls-server.c index 5acd964da..a0c5e3d03 100644 --- a/lib/tls/mbedtls/mbedtls-server.c +++ b/lib/tls/mbedtls/mbedtls-server.c @@ -279,7 +279,11 @@ lws_tls_server_new_nonblocking(struct lws *wsi, lws_sockfd_type accept_fd) return 0; } +#if defined(LWS_AMAZON_RTOS) +enum lws_ssl_capable_status +#else int +#endif lws_tls_server_abort_connection(struct lws *wsi) { __lws_tls_shutdown(wsi); diff --git a/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h b/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h index 35d2d852b..324336549 100644 --- a/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h +++ b/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h @@ -22,8 +22,11 @@ //#include "core/private.h" #include #if defined(LWS_WITH_ESP32) -#undef MBEDTLS_CONFIG_FILE -#define MBEDTLS_CONFIG_FILE + /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ + #if !defined(LWS_AMAZON_RTOS) + #undef MBEDTLS_CONFIG_FILE + #define MBEDTLS_CONFIG_FILE + #endif #endif #include "ssl_code.h" diff --git a/lib/tls/private.h b/lib/tls/private.h index 6d9aba250..6aab36916 100644 --- a/lib/tls/private.h +++ b/lib/tls/private.h @@ -51,8 +51,11 @@ #else /* WOLFSSL */ #if defined(LWS_WITH_ESP32) #define OPENSSL_NO_TLSEXT - #undef MBEDTLS_CONFIG_FILE - #define MBEDTLS_CONFIG_FILE + #if !defined(LWS_AMAZON_RTOS) + /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ + #undef MBEDTLS_CONFIG_FILE + #define MBEDTLS_CONFIG_FILE + #endif #include #include #include diff --git a/lib/tls/tls-server.c b/lib/tls/tls-server.c index ef986570b..26b8d7788 100644 --- a/lib/tls/tls-server.c +++ b/lib/tls/tls-server.c @@ -98,6 +98,7 @@ lws_tls_server_conn_alpn(struct lws *wsi) return 0; } +#if !defined(LWS_NO_SERVER) LWS_VISIBLE int lws_context_init_server_ssl(const struct lws_context_creation_info *info, struct lws_vhost *vhost) @@ -176,6 +177,7 @@ lws_context_init_server_ssl(const struct lws_context_creation_info *info, return 0; } +#endif LWS_VISIBLE int lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd) diff --git a/lib/tls/tls.c b/lib/tls/tls.c index 9b5da2121..013257303 100644 --- a/lib/tls/tls.c +++ b/lib/tls/tls.c @@ -23,7 +23,7 @@ #include "tls/private.h" #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_DEV_KIT) -#if defined(LWS_WITH_ESP32) +#if defined(LWS_WITH_ESP32) && !defined(LWS_AMAZON_RTOS) int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf, lws_filepos_t *amount) { @@ -275,6 +275,7 @@ lws_tls_extant(const char *name) * 4) LWS_TLS_EXTANT_YES: The certs are present with the correct name and we * have the rights to read them. */ +#if !defined(LWS_AMAZON_RTOS) enum lws_tls_extant lws_tls_use_any_upgrade_check_extant(const char *name) { @@ -331,3 +332,5 @@ lws_tls_use_any_upgrade_check_extant(const char *name) #endif return LWS_TLS_EXTANT_YES; } +#endif +