1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

rtos: add support for AMAZON_RTOS

This commit is contained in:
Chen Xi 2019-06-05 05:04:17 +01:00 committed by Andy Green
parent 10660466c1
commit 892cde2c71
20 changed files with 133 additions and 15 deletions

View file

@ -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 <mbedtls/esp_config.h>
#endif
#endif
#include <mbedtls/ssl.h>
#else
#include <openssl/ssl.h>

View file

@ -36,6 +36,12 @@ struct pollfd {
#define POLLHUP 0x0010
#define POLLNVAL 0x0020
#if defined(LWS_AMAZON_RTOS)
#include <FreeRTOS.h>
#include <event_groups.h>
#include <string.h>
#include "timers.h"
#else /* LWS_AMAZON_RTOS */
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#include <string.h>
@ -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 <mdns.h>
@ -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 */

View file

@ -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
/*

View file

@ -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;

View file

@ -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);

View file

@ -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);
}

View file

@ -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 = "(),/:;<=>?@[\\]{}";

View file

@ -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 */

View file

@ -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;

View file

@ -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,

View file

@ -24,7 +24,10 @@
#define MSG_NOSIGNAL 0
#define SOMAXCONN 3
#if !defined(LWS_AMAZON_RTOS)
#include <fcntl.h>
#endif
#include <strings.h>
#include <unistd.h>
#include <sys/stat.h>
@ -37,12 +40,20 @@
#endif
#include <netdb.h>
#include <signal.h>
#if !defined(LWS_AMAZON_RTOS)
#include <sys/socket.h>
#endif
#include "freertos/timers.h"
#include <esp_attr.h>
#include <esp_system.h>
#include <esp_task_wdt.h>
#if defined(LWS_AMAZON_RTOS)
#include "FreeRTOS.h"
#include "timers.h"
#include <esp_attr.h>
#else
#include "freertos/timers.h"
#include <esp_attr.h>
#include <esp_system.h>
#include <esp_task_wdt.h>
#endif
#include "lwip/apps/sntp.h"

View file

@ -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;

View file

@ -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);

View file

@ -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

View file

@ -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,

View file

@ -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);

View file

@ -22,8 +22,11 @@
//#include "core/private.h"
#include <lws_config.h>
#if defined(LWS_WITH_ESP32)
#undef MBEDTLS_CONFIG_FILE
#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
/* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */
#if !defined(LWS_AMAZON_RTOS)
#undef MBEDTLS_CONFIG_FILE
#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
#endif
#endif
#include "ssl_code.h"

View file

@ -51,8 +51,11 @@
#else /* WOLFSSL */
#if defined(LWS_WITH_ESP32)
#define OPENSSL_NO_TLSEXT
#undef MBEDTLS_CONFIG_FILE
#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
#if !defined(LWS_AMAZON_RTOS)
/* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */
#undef MBEDTLS_CONFIG_FILE
#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
#endif
#include <mbedtls/ssl.h>
#include <mbedtls/aes.h>
#include <mbedtls/gcm.h>

View file

@ -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)

View file

@ -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