1d4afb5ceSopenharmony_ci/*
2d4afb5ceSopenharmony_ci * libwebsockets - small server side websockets and web server implementation
3d4afb5ceSopenharmony_ci *
4d4afb5ceSopenharmony_ci * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5d4afb5ceSopenharmony_ci *
6d4afb5ceSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
7d4afb5ceSopenharmony_ci * of this software and associated documentation files (the "Software"), to
8d4afb5ceSopenharmony_ci * deal in the Software without restriction, including without limitation the
9d4afb5ceSopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10d4afb5ceSopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is
11d4afb5ceSopenharmony_ci * furnished to do so, subject to the following conditions:
12d4afb5ceSopenharmony_ci *
13d4afb5ceSopenharmony_ci * The above copyright notice and this permission notice shall be included in
14d4afb5ceSopenharmony_ci * all copies or substantial portions of the Software.
15d4afb5ceSopenharmony_ci *
16d4afb5ceSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17d4afb5ceSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18d4afb5ceSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19d4afb5ceSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20d4afb5ceSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21d4afb5ceSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22d4afb5ceSopenharmony_ci * IN THE SOFTWARE.
23d4afb5ceSopenharmony_ci */
24d4afb5ceSopenharmony_ci
25d4afb5ceSopenharmony_ci#include "private-lib-core.h"
26d4afb5ceSopenharmony_ci
27d4afb5ceSopenharmony_ciint
28d4afb5ceSopenharmony_cilws_plat_context_early_init(void)
29d4afb5ceSopenharmony_ci{
30d4afb5ceSopenharmony_ci	return 0;
31d4afb5ceSopenharmony_ci}
32d4afb5ceSopenharmony_ci
33d4afb5ceSopenharmony_civoid
34d4afb5ceSopenharmony_cilws_plat_context_early_destroy(struct lws_context *context)
35d4afb5ceSopenharmony_ci{
36d4afb5ceSopenharmony_ci#if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS)
37d4afb5ceSopenharmony_ci	mbedtls_ctr_drbg_free(&context->mcdc);
38d4afb5ceSopenharmony_ci	mbedtls_entropy_free(&context->mec);
39d4afb5ceSopenharmony_ci#endif
40d4afb5ceSopenharmony_ci}
41d4afb5ceSopenharmony_ci
42d4afb5ceSopenharmony_civoid
43d4afb5ceSopenharmony_cilws_plat_context_late_destroy(struct lws_context *context)
44d4afb5ceSopenharmony_ci{
45d4afb5ceSopenharmony_ci#ifdef LWS_WITH_PLUGINS
46d4afb5ceSopenharmony_ci	if (context->plugin_list)
47d4afb5ceSopenharmony_ci		lws_plat_plugins_destroy(context);
48d4afb5ceSopenharmony_ci#endif
49d4afb5ceSopenharmony_ci
50d4afb5ceSopenharmony_ci	if (context->lws_lookup)
51d4afb5ceSopenharmony_ci		lws_free(context->lws_lookup);
52d4afb5ceSopenharmony_ci}
53d4afb5ceSopenharmony_ci
54d4afb5ceSopenharmony_ci#if defined(LWS_WITH_HTTP2)
55d4afb5ceSopenharmony_ci/*
56d4afb5ceSopenharmony_ci * These are the default SETTINGS used on this platform.  The user
57d4afb5ceSopenharmony_ci * can selectively modify them for a vhost during vhost creation.
58d4afb5ceSopenharmony_ci */
59d4afb5ceSopenharmony_ciconst struct http2_settings lws_h2_defaults_esp32 = { {
60d4afb5ceSopenharmony_ci	1,
61d4afb5ceSopenharmony_ci	/* H2SET_HEADER_TABLE_SIZE */			 512,
62d4afb5ceSopenharmony_ci	/* H2SET_ENABLE_PUSH */				   0,
63d4afb5ceSopenharmony_ci	/* H2SET_MAX_CONCURRENT_STREAMS */		   8,
64d4afb5ceSopenharmony_ci	/* H2SET_INITIAL_WINDOW_SIZE */		           0,
65d4afb5ceSopenharmony_ci	/* H2SET_MAX_FRAME_SIZE */		       16384,
66d4afb5ceSopenharmony_ci	/* H2SET_MAX_HEADER_LIST_SIZE */	 	 512,
67d4afb5ceSopenharmony_ci	/* H2SET_RESERVED7 */				   0,
68d4afb5ceSopenharmony_ci	/* H2SET_ENABLE_CONNECT_PROTOCOL */		   1,
69d4afb5ceSopenharmony_ci}};
70d4afb5ceSopenharmony_ci#endif
71d4afb5ceSopenharmony_ci
72d4afb5ceSopenharmony_ciint
73d4afb5ceSopenharmony_cilws_plat_init(struct lws_context *context,
74d4afb5ceSopenharmony_ci	      const struct lws_context_creation_info *info)
75d4afb5ceSopenharmony_ci{
76d4afb5ceSopenharmony_ci#if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS)
77d4afb5ceSopenharmony_ci	int n;
78d4afb5ceSopenharmony_ci
79d4afb5ceSopenharmony_ci	/* initialize platform random through mbedtls */
80d4afb5ceSopenharmony_ci	mbedtls_entropy_init(&context->mec);
81d4afb5ceSopenharmony_ci	mbedtls_ctr_drbg_init(&context->mcdc);
82d4afb5ceSopenharmony_ci
83d4afb5ceSopenharmony_ci	n = mbedtls_ctr_drbg_seed(&context->mcdc, mbedtls_entropy_func,
84d4afb5ceSopenharmony_ci				  &context->mec, NULL, 0);
85d4afb5ceSopenharmony_ci	if (n) {
86d4afb5ceSopenharmony_ci		lwsl_err("%s: mbedtls_ctr_drbg_seed() returned 0x%x\n",
87d4afb5ceSopenharmony_ci			 __func__, n);
88d4afb5ceSopenharmony_ci
89d4afb5ceSopenharmony_ci		return 1;
90d4afb5ceSopenharmony_ci	}
91d4afb5ceSopenharmony_ci#endif
92d4afb5ceSopenharmony_ci
93d4afb5ceSopenharmony_ci	/* context has the global fd lookup array */
94d4afb5ceSopenharmony_ci	context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
95d4afb5ceSopenharmony_ci					 context->max_fds, "esp32 lws_lookup");
96d4afb5ceSopenharmony_ci	if (context->lws_lookup == NULL) {
97d4afb5ceSopenharmony_ci		lwsl_err("OOM on lws_lookup array for %d connections\n",
98d4afb5ceSopenharmony_ci			 context->max_fds);
99d4afb5ceSopenharmony_ci		return 1;
100d4afb5ceSopenharmony_ci	}
101d4afb5ceSopenharmony_ci
102d4afb5ceSopenharmony_ci	lwsl_notice(" mem: platform fd map: %5lu bytes\n",
103d4afb5ceSopenharmony_ci		    (unsigned long)(sizeof(struct lws *) * context->max_fds));
104d4afb5ceSopenharmony_ci
105d4afb5ceSopenharmony_ci#ifdef LWS_WITH_PLUGINS
106d4afb5ceSopenharmony_ci	if (info->plugin_dirs)
107d4afb5ceSopenharmony_ci		lws_plat_plugins_init(context, info->plugin_dirs);
108d4afb5ceSopenharmony_ci#endif
109d4afb5ceSopenharmony_ci#if defined(LWS_WITH_HTTP2)
110d4afb5ceSopenharmony_ci	/* override settings */
111d4afb5ceSopenharmony_ci	context->set = lws_h2_defaults_esp32;
112d4afb5ceSopenharmony_ci#endif
113d4afb5ceSopenharmony_ci
114d4afb5ceSopenharmony_ci#if defined(LWS_ESP_PLATFORM)
115d4afb5ceSopenharmony_ci	gpio_install_isr_service(0);
116d4afb5ceSopenharmony_ci#endif
117d4afb5ceSopenharmony_ci
118d4afb5ceSopenharmony_ci	return 0;
119d4afb5ceSopenharmony_ci}
120