SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
httpd_tls/example.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
3 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com> (STK threading adaptation)
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * ---------------------------------------------------------------------------
8 * Pico W lwIP httpd + mDNS example, ported to STK
9 * ---------------------------------------------------------------------------
10 *
11 * A direct port of Raspberry Pi's original single-superloop example onto STK
12 * threading. It follows the same split used in example-blinky.cpp: one-time
13 * hardware bring-up runs directly in RunExample(), and everything ongoing
14 * (Wi-Fi connect, server setup, and the polling loop) runs inside a task's
15 * Run().
16 *
17 * Exception to that split: cyw43_arch_init() is called from inside the
18 * task's Run(), not from RunExample() alongside the rest of one-time
19 * bring-up. cyw43_arch_init() builds (or reuses) an async_context_stk,
20 * whose locking/ownership checks - async_context_stk_lock_check(),
21 * async_context_stk_execute_sync() - call stk::GetTid() to identify the
22 * calling task. stk::GetTid() only means something once it's called from a
23 * real, running STK task, i.e. after kernel.Start(). RunExample() runs
24 * before that, so cyw43_arch_init() can't live there. sys_arch_set_kernel()
25 * and cyw43_arch_stk_preinit() have no such restriction - they only stash
26 * pointers - so those still run from RunExample() as usual.
27 *
28 * Threading model: this targets cyw43_arch_stk's task-based background
29 * model, the STK analogue of upstream's FREERTOS backend, rather than
30 * POLL or THREADSAFE_BACKGROUND. cyw43_arch_stk.cpp hard-errors under
31 * NO_SYS=1, so this port only ever runs under NO_SYS=0: cyw43_arch_init()
32 * spins up async_context_stk's own worker task to drive the driver, and -
33 * since CYW43_LWIP is set - also spawns lwIP's tcpip thread via
34 * tcpip_init()/sys_thread_new(), sharing its core lock with the async
35 * context through sys_arch's LWIP_STK_CUSTOM_CORE_LOCKING hook (see
36 * lwip_stk.cpp/.h). This task itself never polls the driver; it just needs
37 * to stay alive after setup.
38 *
39 * Efficiency: WifiHttpdTask blocks on s_ControlFlags.Wait() rather than
40 * spinning, so it only runs when there's actually something to do (an LED
41 * request, a connect/init/shutdown request). The same holds one level down:
42 * async_context_stk's worker task and lwIP's tcpip thread are themselves
43 * STK tasks that block on their own queues/semaphores when idle, rather than
44 * polling the cyw43 driver or the network stack in a loop. With every task
45 * in the system blocked on an event rather than busy-waiting, the STK
46 * scheduler has nothing runnable and puts the CPU to sleep (WFI, or a
47 * tickless idle that also skips the periodic tick - see KERNEL_TICKLESS /
48 * STK_TICKLESS_IDLE below) until an interrupt - Wi-Fi/lwIP activity, a POST
49 * request, a timer - wakes something up. None of that requires any explicit
50 * power-management code in this file: it falls out of every task in the
51 * chain (this one, the driver's worker, lwIP's tcpip thread) using
52 * event-driven waits instead of polling.
53 * ---------------------------------------------------------------------------
54 */
55
61
62#include <assert.h>
63
64#include <stk.h>
65#include <sync/stk_sync.h>
66#include <time/stk_time.h>
67
68#include "example.h"
69
70#include "pico/stdlib.h"
71#include "pico/cyw43_arch.h"
72#include "hardware/structs/rosc.h"
73
74#include "lwip/ip4_addr.h"
75#include "lwip/apps/mdns.h"
76#include "lwip/apps/mdns_priv.h"
77#include "lwip/init.h"
78#include "lwip/apps/httpd.h"
79#include "lwip/altcp_tls.h"
80
81// Certificates generated by generate_certs_h.py to DER format, to use .crt/,key contents directly
82// #define MBEDTLS_PEM_PARSE_C in mbedtls_config.h.
83#include "example_certs.h"
84
85// mbedTLS
86#include "psa/crypto.h"
87#include "mbedtls/platform.h"
88
89// STK
90#include "arch/sys_arch.h" // lwIP
91#include "pico/cyw43_arch_stk.h" // Pico SDK
92#include "threading_alt.h" // mbedTLS
93
94// The driver work plus httpd/mDNS buffers make this a heavier task than a
95// typical blinky-style one, so the stack is sized generously.
96enum { TASK_STACK_SIZE = 4096 };
97
98#define STR_HELPER(x) #x
99#define STR(x) STR_HELPER(x)
100
101void httpd_init(void);
102
103const char WIFI_SSID[] = ENV_WIFI_SSID;
104const char WIFI_PASSWORD[] = ENV_WIFI_PASSWORD;
105
106// Tag names are capped by LWIP_HTTPD_MAX_TAG_NAME_LEN - keep entries within it.
107static const char *SSI_TAGS[] =
108{
109 "status",
110 "welcome",
111 "uptime",
112 "ledstate",
113 "ledinv",
114 "table",
115};
116
117#if LWIP_HTTPD_SUPPORT_POST
118#define LED_STATE_BUFSIZE 4
119
120static const uint32_t FLAG_LED_UPDATE = (1U << 0); // A POST handler requested a GPIO write.
121static const uint32_t FLAG_CONNECT_WIFI = (1U << 1); // Wi-Fi should (re)connect.
122static const uint32_t FLAG_INIT_NET = (1U << 2); // The network stack should (re)initialize.
123static const uint32_t FLAG_SHUTDOWN_NET = (1U << 3); // The network stack should shut down.
124
125static void *s_CurrentConnection;
126static absolute_time_t s_ConnectedTime;
127static bool s_LedOn = false;
128static altcp_tls_config *s_TlsConfig = NULL;
129stk::sync::EventFlags s_ControlFlags;
130
131static void RequestLedUpdate() { s_ControlFlags.Set(FLAG_LED_UPDATE); } // ISR-safe - callable from lwIP callback context.
132static void RequestConnectWiFi() { s_ControlFlags.Set(FLAG_CONNECT_WIFI); }
133static void RequestInitNetwork() { s_ControlFlags.Set(FLAG_INIT_NET); }
134static void RequestShutdownNetwork() { s_ControlFlags.Set(FLAG_SHUTDOWN_NET); }
135
136#if LWIP_MDNS_RESPONDER
137static void srv_txt(struct mdns_service *service, void *txt_userdata)
138{
139 err_t res;
140 LWIP_UNUSED_ARG(txt_userdata);
141
142 res = mdns_resp_add_service_txtitem(service, "path=/", 6);
143 LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return);
144}
145#endif
146
147// Writes a substring of the MAC address's ASCII hex representation
148// (e.g. "112233445566") into dest_in, starting at character index chr_off
149// and taking chr_len characters - e.g. chr_off=8, chr_len=4 returns "5566".
150// Returns the number of characters written.
151static size_t get_mac_ascii(int idx, size_t chr_off, size_t chr_len, char *dest_in)
152{
153 static const char hexchr[] = "0123456789ABCDEF";
154 uint8_t mac[6];
155 char *dest = dest_in;
156 assert(chr_off + chr_len <= (2 * sizeof(mac)));
157 cyw43_hal_get_mac(idx, mac);
158 for (; chr_len && (chr_off >> 1) < sizeof(mac); ++chr_off, --chr_len)
159 {
160 *dest++ = hexchr[mac[chr_off >> 1] >> (4 * (1 - (chr_off & 1))) & 0xf];
161 }
162 return dest - dest_in;
163}
164
165static const char *cgi_handler_test(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
166{
167 STK_UNUSED(iIndex);
168 STK_UNUSED(pcValue);
169
170 if (iNumParams > 0)
171 {
172 if (strcmp(pcParam[0], "test") == 0)
173 {
174 return "/test.shtml";
175 }
176 }
177 return "/index.shtml";
178}
179
180static const char *cgi_handler_restart(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
181{
182 //RequestShutdownNetwork(); // Disabled: network shutdown doesn't work reliably with lwIP.
183 return "/index.shtml";
184}
185
186static const tCGI CGI_HANDLERS[] =
187{
188 { "/", cgi_handler_test },
189 { "/index.shtml", cgi_handler_test },
190 { "/restart", cgi_handler_restart },
191};
192
193// pcInsert is capped at LWIP_HTTPD_MAX_TAG_INSERT_LEN; use LWIP_HTTPD_SSI_MULTIPART
194// (see the "table" tag below) to stream larger amounts of data across multiple calls.
195u16_t ssi_example_ssi_handler(int iIndex, char *pcInsert, int iInsertLen
197 , uint16_t current_tag_part, uint16_t *next_tag_part
198#endif
199 )
200{
201 size_t printed;
202 switch (iIndex)
203 {
204 case 0: // "status"
205 {
206 printed = snprintf(pcInsert, iInsertLen, "Pass");
207 break;
208 }
209 case 1: // "welcome"
210 {
211 printed = snprintf(pcInsert, iInsertLen, "Hello from Pico");
212 break;
213 }
214 case 2: // "uptime"
215 {
216 uint64_t uptime_s = absolute_time_diff_us(s_ConnectedTime, get_absolute_time()) / 1e6;
217 printed = snprintf(pcInsert, iInsertLen, "%d", (int)uptime_s);
218 break;
219 }
220 case 3: // "ledstate"
221 {
222 printed = snprintf(pcInsert, iInsertLen, "%s", s_LedOn ? "ON" : "OFF");
223 break;
224 }
225 case 4: // "ledinv"
226 {
227 printed = snprintf(pcInsert, iInsertLen, "%s", s_LedOn ? "OFF" : "ON");
228 break;
229 }
230#if LWIP_HTTPD_SSI_MULTIPART
231 case 5: /* "table" */
232 {
233 printed = snprintf(pcInsert, iInsertLen, "<tr><td>This is table row number %d</td></tr>", current_tag_part + 1);
234 // Advance next_tag_part to request another call for the next row; leaving it
235 // unchanged (once we hit 9) tells lwIP this tag is fully sent.
236 if (current_tag_part < 9)
237 {
238 *next_tag_part = current_tag_part + 1;
239 }
240 break;
241 }
242#endif
243 default: // unknown tag
244 {
245 printed = 0;
246 break;
247 }
248 }
249 return (u16_t)printed;
250}
251
252err_t httpd_post_begin(void *connection, const char *uri, const char *http_request,
253 u16_t http_request_len, int content_len, char *response_uri,
254 u16_t response_uri_len, u8_t *post_auto_wnd)
255{
256 STK_UNUSED(http_request);
257 STK_UNUSED(http_request_len);
258 STK_UNUSED(content_len);
259
260 if (memcmp(uri, "/led.cgi", 8) == 0 && s_CurrentConnection != connection)
261 {
262 s_CurrentConnection = connection;
263 snprintf(response_uri, response_uri_len, "/ledfail.shtml");
264 *post_auto_wnd = 1;
265 return ERR_OK;
266 }
267 return ERR_VAL;
268}
269
270// Finds param_name in the POST body pbuf chain and copies its value into
271// value_buf (NUL-terminated). Returns value_buf on success, NULL if the
272// parameter is missing or its value doesn't fit in value_buf_len.
273char *httpd_param_value(struct pbuf *p, const char *param_name, char *value_buf, size_t value_buf_len)
274{
275 size_t param_len = strlen(param_name);
276 u16_t param_pos = pbuf_memfind(p, param_name, param_len, 0);
277 if (param_pos != 0xFFFF)
278 {
279 u16_t param_value_pos = param_pos + param_len;
280 u16_t param_value_len = 0;
281 u16_t tmp = pbuf_memfind(p, "&", 1, param_value_pos);
282 if (tmp != 0xFFFF)
283 {
284 param_value_len = tmp - param_value_pos;
285 }
286 else
287 {
288 param_value_len = p->tot_len - param_value_pos;
289 }
290 if (param_value_len > 0 && param_value_len < value_buf_len)
291 {
292 char *result = (char *)pbuf_get_contiguous(p, value_buf, value_buf_len, param_value_len, param_value_pos);
293 if (result)
294 {
295 result[param_value_len] = 0;
296 return result;
297 }
298 }
299 }
300 return NULL;
301}
302
303err_t httpd_post_receive_data(void *connection, struct pbuf *p)
304{
305 err_t ret = ERR_VAL;
306 LWIP_ASSERT("NULL pbuf", p != NULL);
307 if (s_CurrentConnection == connection)
308 {
309 char buf[LED_STATE_BUFSIZE];
310 char *val = httpd_param_value(p, "led_state=", buf, sizeof(buf));
311 if (val)
312 {
313 s_LedOn = (strcmp(val, "ON") == 0) ? true : false;
314 RequestLedUpdate();
315 ret = ERR_OK;
316 }
317 }
318 pbuf_free(p);
319 return ret;
320}
321
322void httpd_post_finished(void *connection, char *response_uri, u16_t response_uri_len)
323{
324 snprintf(response_uri, response_uri_len, "/ledfail.shtml");
325 if (s_CurrentConnection == connection)
326 {
327 snprintf(response_uri, response_uri_len, "/ledpass.shtml");
328 }
329 s_CurrentConnection = NULL;
330}
331#endif
332
333static bool InitNetwork()
334{
335 // Must run from inside the task, not from RunExample() before kernel.Start() -
336 // see the file header for why (cyw43_arch_init()'s async_context_stk needs a
337 // running STK task to call stk::GetTid() from).
338 if (cyw43_arch_init())
339 {
340 printf("failed to initialise\n");
341 return false;
342 }
343
344 // Initialize PSA Crypto engine (Required for Mbed TLS 4)
345 psa_status_t status = psa_crypto_init();
346 if (status != PSA_SUCCESS)
347 {
348 printf("failed to initialise PSA crypto: %d\n", (int)status);
349 cyw43_arch_deinit();
350 return false;
351 }
352
353 cyw43_arch_enable_sta_mode();
354
355 return true;
356}
357
358static void ShutdownNetwork()
359{
360#if LWIP_MDNS_RESPONDER
361 mdns_resp_remove_netif(&cyw43_state.netif[CYW43_ITF_STA]);
362 udp_remove(get_mdns_pcb());
363 // KNOWN ISSUE: this doesn't decrement netif_client_id in netif.c, so a later
364 // mdns_resp_add_netif() will assert in netif_alloc_client_data_id() on reinit.
365#endif
366 cyw43_arch_disable_sta_mode();
367 cyw43_arch_deinit();
368}
369
370static void InitServer()
371{
372 char hostname[sizeof(CYW43_HOST_NAME) + 4];
373 memcpy(&hostname[0], CYW43_HOST_NAME, sizeof(CYW43_HOST_NAME) - 1);
374 get_mac_ascii(CYW43_HAL_MAC_WLAN0, 8, 4, &hostname[sizeof(CYW43_HOST_NAME) - 1]);
375 hostname[sizeof(hostname) - 1] = '\0';
376 netif_set_hostname(&cyw43_state.netif[CYW43_ITF_STA], hostname);
377
378#if LWIP_MDNS_RESPONDER
379 // Set up the mDNS responder.
380 cyw43_arch_lwip_begin();
381 mdns_resp_init();
382 printf("mdns host name %s.local\n", hostname);
383#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 2
384 mdns_resp_add_netif(&cyw43_state.netif[CYW43_ITF_STA], hostname);
385 mdns_resp_add_service(&cyw43_state.netif[CYW43_ITF_STA], "pico_httpd", "_http", DNSSD_PROTO_TCP, 80, srv_txt, NULL);
386#else
387 mdns_resp_add_netif(&cyw43_state.netif[CYW43_ITF_STA], hostname, 60);
388 mdns_resp_add_service(&cyw43_state.netif[CYW43_ITF_STA], "pico_httpd", "_http", DNSSD_PROTO_TCP, 80, 60, srv_txt, NULL);
389#endif
390 cyw43_arch_lwip_end();
391#endif
392 // Set up the HTTP server. CGI/SSI handlers are global state shared by
393 // both the plain-HTTP and HTTPS listeners below, so only need setting once.
394 cyw43_arch_lwip_begin();
395 httpd_init();
396 http_set_cgi_handlers(CGI_HANDLERS, LWIP_ARRAYSIZE(CGI_HANDLERS));
397 http_set_ssi_handler(ssi_example_ssi_handler, SSI_TAGS, LWIP_ARRAYSIZE(SSI_TAGS));
398
399 // Set up HTTPS on top of the same httpd instance. Uses a self-signed
400 // cert (see certs_der.h / generate_cert.sh) - browsers will show a
401 // "not private" warning on first visit since it's not CA-signed; that's
402 // expected for a self-generated cert and can be bypassed/accepted or
403 // the cert can be installed as trusted on the client.
404 s_TlsConfig = altcp_tls_create_config_server_privkey_cert(
405 s_TlsKey, sizeof(s_TlsKey),
406 NULL, 0, /* private key is not password-protected */
407 s_TlsCert, sizeof(s_TlsCert));
408 if (s_TlsConfig == NULL)
409 {
410 printf("Failed to create TLS config - HTTPS disabled, HTTP still available\n");
411 }
412 else
413 {
414 httpd_inits(s_TlsConfig);
415 printf("HTTPS server listening on port %d\n", HTTPD_SERVER_PORT_HTTPS);
416 }
417 cyw43_arch_lwip_end();
418}
419
420static bool ConnectWiFi()
421{
422 printf("Connecting to WiFi...\n");
423 if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000))
424 {
425 printf("failed to connect.\n");
426 return false;
427 }
428 else
429 {
430 printf("Connected.\n");
431 }
432 printf("\nReady, running httpd at %s\n", ip4addr_ntoa(netif_ip4_addr(netif_list)));
433
434 // Record the connect time for the "uptime" SSI tag.
435 s_ConnectedTime = get_absolute_time();
436
437 return true;
438}
439
440// Owns Wi-Fi connect and httpd/mDNS server setup, driven by control-flag events
441// rather than the original's while(true) superloop. It doesn't drive the cyw43
442// driver itself - async_context_stk's own worker task (spun up inside
443// cyw43_arch_init()) does that - so this task's loop just needs to stay alive
444// and react to flags after setup.
445class WifiHttpdTask : public stk::Task<TASK_STACK_SIZE, stk::ACCESS_PRIVILEGED>
446{
447private:
448 void Run() override
449 {
450 bool running = true;
451 while (running)
452 {
453 const uint32_t raised = s_ControlFlags.Wait(FLAG_CONNECT_WIFI | FLAG_LED_UPDATE | FLAG_INIT_NET | FLAG_SHUTDOWN_NET, stk::sync::EventFlags::OPT_WAIT_ANY, stk::WAIT_INFINITE);
455 {
456 continue;
457 }
458
459 if (raised & FLAG_LED_UPDATE)
460 {
461 cyw43_arch_lwip_begin();
462 cyw43_gpio_set(&cyw43_state, 0, s_LedOn);
463 cyw43_arch_lwip_end();
464 }
465 if (raised & FLAG_CONNECT_WIFI)
466 {
467 if (!ConnectWiFi())
468 {
469 RequestConnectWiFi();
470 }
471 }
472 if (raised & FLAG_INIT_NET)
473 {
474 if (InitNetwork())
475 {
476 InitServer();
477 RequestConnectWiFi();
478 }
479 else
480 {
481 RequestInitNetwork();
482 }
483 }
484 if (raised & FLAG_SHUTDOWN_NET)
485 {
487 RequestInitNetwork();
488 }
489 }
490 }
491};
492
494{
495 using namespace stk;
496
497 // Bring up stdio for logging.
498 stdio_init_all();
499
500 // Enable dynamic task registration and inter-task sync, plus tickless idle
501 // where the platform supports it.
502 static constexpr uint8_t KernelMode = KERNEL_DYNAMIC | KERNEL_SYNC | (STK_TICKLESS_IDLE ? KERNEL_TICKLESS : 0);
503
504 // Task budget: WifiHttpdTask + TimerHost + async_context_stk's worker tasks +
505 // lwIP's own sys_thread_new()-spawned tcpip thread (sized by
506 // LWIP_STK_THREAD_POOL_SIZE). Note: LWIP_STK_NETCONN_SEM_MAX_THREADS is NOT a
507 // task count - it sizes sys_arch's TId-keyed side-table for
508 // LWIP_NETCONN_SEM_PER_THREAD and has no bearing on kernel.AddTask() capacity.
509 static constexpr size_t tasks_count = 1U + stk::time::TimerHost::TASK_COUNT + ASYNC_CONTEXT_STK_TASKS + LWIP_STK_THREAD_POOL_SIZE;
510
511 // Allocate the scheduling kernel with priority-based scheduling (sched::SwitchStrategyFP32).
513 static stk::time::TimerHost timer_host;
514 static WifiHttpdTask task;
515
516 kernel.Initialize();
517
518 timer_host.Initialize(&kernel, stk::ACCESS_USER);
519
520 // Register the task with the kernel.
521 kernel.AddTask(&task);
522
523 // init mbedTLS threading
524 stk_mbedtls_threading_init();
525
526 // Wire the kernel into lwIP's sys_arch port - must happen before lwip_init().
527 sys_arch_set_kernel(&kernel);
528
529 // Wire the kernel and timer host into the cyw43 port - must happen before cyw43_arch_init().
530 cyw43_arch_stk_preinit(&kernel, &timer_host);
531
532 // Kick off network init once the task starts running; safe to request before kernel.Start().
533 RequestInitNetwork();
534
535 // Start the scheduler - this runs the registered task and blocks here permanently.
536 kernel.Start();
537
538 // Unreachable: kernel.Start() never returns.
539 STK_ASSERT(false);
540}
541
542// mbedTLS specific:
543
544extern "C" int __mbedtls_platform_get_entropy(psa_driver_get_entropy_flags_t flags, size_t *estimate_bits,
545 unsigned char *output, size_t output_size)
546{
547 /* We don't implement any special flags */
548 if (flags != 0)
549 {
550 return PSA_ERROR_NOT_SUPPORTED;
551 }
552
553 if (output == NULL || estimate_bits == NULL)
554 {
555 return PSA_ERROR_INVALID_ARGUMENT;
556 }
557
558 /* Sample physical noise bits from ROSC */
559 for (size_t i = 0; i < output_size; i++)
560 {
561 uint8_t random_byte = 0;
562 for (int b = 0; b < 8; b++)
563 {
564 random_byte = (random_byte << 1) | (rosc_hw->randombit & 1);
565 }
566 output[i] = random_byte;
567 }
568
569 /* Set the estimated entropy bits gathered (8 bits per byte) */
570 *estimate_bits = 8 * output_size;
571
572 return 0; // Success
573}
574
575#ifdef DEBUG
576extern "C" const char *mbedtls_ssl_states_str(mbedtls_ssl_states state)
577{
578 switch (state)
579 {
580 case MBEDTLS_SSL_HELLO_REQUEST: return "HELLO_REQUEST";
581 case MBEDTLS_SSL_CLIENT_HELLO: return "CLIENT_HELLO";
582 case MBEDTLS_SSL_SERVER_HELLO: return "SERVER_HELLO";
583 case MBEDTLS_SSL_SERVER_CERTIFICATE: return "SERVER_CERTIFICATE";
584 case MBEDTLS_SSL_SERVER_KEY_EXCHANGE: return "SERVER_KEY_EXCHANGE";
585 case MBEDTLS_SSL_CERTIFICATE_REQUEST: return "CERTIFICATE_REQUEST";
586 case MBEDTLS_SSL_SERVER_HELLO_DONE: return "SERVER_HELLO_DONE";
587 case MBEDTLS_SSL_CLIENT_CERTIFICATE: return "CLIENT_CERTIFICATE";
588 case MBEDTLS_SSL_CLIENT_KEY_EXCHANGE: return "CLIENT_KEY_EXCHANGE";
589 case MBEDTLS_SSL_CERTIFICATE_VERIFY: return "CERTIFICATE_VERIFY";
590 case MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC: return "CLIENT_CHANGE_CIPHER_SPEC";
591 case MBEDTLS_SSL_CLIENT_FINISHED: return "CLIENT_FINISHED";
592 case MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC: return "SERVER_CHANGE_CIPHER_SPEC";
593 case MBEDTLS_SSL_SERVER_FINISHED: return "SERVER_FINISHED";
594 case MBEDTLS_SSL_FLUSH_BUFFERS: return "FLUSH_BUFFERS";
595 case MBEDTLS_SSL_HANDSHAKE_WRAPUP: return "HANDSHAKE_WRAPUP";
596 case MBEDTLS_SSL_HANDSHAKE_OVER: return "HANDSHAKE_OVER";
597 default: return "UNKNOWN_STATE";
598 }
599}
600
601extern "C" const char *mbedtls_ssl_named_group_to_str(uint16_t group_id)
602{
603 switch (group_id)
604 {
605 case MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1: return "secp256r1";
606 case MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1: return "secp384r1";
607 case MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1: return "secp521r1";
608 case MBEDTLS_SSL_IANA_TLS_GROUP_X25519: return "x25519";
609 case MBEDTLS_SSL_IANA_TLS_GROUP_X448: return "x448";
610 case MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048: return "ffdhe2048";
611 case MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072: return "ffdhe3072";
612 default: return "UNKNOWN_GROUP";
613 }
614}
615
616extern "C" const char *mbedtls_ssl_sig_alg_to_str(uint16_t sig_alg)
617{
618 switch (sig_alg)
619 {
620 /* RSA PKCS#1 v1.5 */
621 case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA256: return "rsa_pkcs1_sha256";
622 case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA384: return "rsa_pkcs1_sha384";
623 case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA512: return "rsa_pkcs1_sha512";
624
625 /* ECDSA */
626 case MBEDTLS_TLS1_3_SIG_ECDSA_SECP256R1_SHA256: return "ecdsa_secp256r1_sha256";
627 case MBEDTLS_TLS1_3_SIG_ECDSA_SECP384R1_SHA384: return "ecdsa_secp384r1_sha384";
628 case MBEDTLS_TLS1_3_SIG_ECDSA_SECP521R1_SHA512: return "ecdsa_secp521r1_sha512";
629
630 /* RSA-PSS */
631 case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256: return "rsa_pss_rsae_sha256";
632 case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384: return "rsa_pss_rsae_sha384";
633 case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512: return "rsa_pss_rsae_sha512";
634
635 /* EdDSA */
636 case MBEDTLS_TLS1_3_SIG_ED25519: return "ed25519";
637 case MBEDTLS_TLS1_3_SIG_ED448: return "ed448";
638
639 default: return "unknown_sig_alg";
640 }
641}
642#endif
const unsigned char s_TlsCert[]
const unsigned char s_TlsKey[]
#define LWIP_HTTPD_SSI_MULTIPART
Definition lwipopts.h:23
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:715
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:532
Collection of synchronization primitives (stk::sync namespace).
Collection of time-related primitives (stk::time namespace).
Namespace of STK package.
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details)....
Definition stk_common.h:37
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:274
@ KERNEL_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
Definition stk_common.h:51
@ KERNEL_SYNC
Synchronization support (see Event).
Definition stk_common.h:50
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
Definition stk_common.h:48
EventFlagsT< uint32_t > EventFlags
Default event flags group with a 32-bit flags word (31 usable flags, bit 31 reserved).
Concrete implementation of IKernel.
Definition stk.h:102
void Start() override
Start the scheduler. This call does not return until all tasks have exited (KERNEL_DYNAMIC mode) or i...
Definition stk.h:1999
EAddResult AddTask(ITask *user_task) override
Register task for a soft real-time (SRT) scheduling.
Definition stk.h:1465
void Initialize(uint32_t resolution_us=PERIODICITY_DEFAULT) override
Initialize kernel.
Definition stk.h:1425
Partial implementation of the user task.
Definition stk_helper.h:98
T Set(T flags)
Set one or more flags.
static constexpr uint32_t OPT_WAIT_ANY
T Wait(T flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout_ticks=WAIT_INFINITE)
Wait for one or more flags to be set.
static bool IsError(uint32_t result)
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kerne...
EAddResult Initialize(IKernel *kernel, EAccessMode mode, const Config &cfg=Config())
Initialize timer host instance.
@ TASK_COUNT
total number of tasks serving this instance
void Run() override
Entry point of the user task.
static const char * SSI_TAGS[]
static bool ConnectWiFi()
static void InitServer()
static void ShutdownNetwork()
const char WIFI_PASSWORD[]
void httpd_init(void)
static bool InitNetwork()
const char WIFI_SSID[]
static bool ConnectWiFi()
static void InitServer()
int __mbedtls_platform_get_entropy(psa_driver_get_entropy_flags_t flags, size_t *estimate_bits, unsigned char *output, size_t output_size)
static void ShutdownNetwork()
static bool InitNetwork()
#define TASK_STACK_SIZE