|
|
@@ -186,7 +186,7 @@ extern "C" {
|
|
|
#define calloc(a, b) mg_calloc(a, b)
|
|
|
#define free(a) vPortFree(a)
|
|
|
#define malloc(a) pvPortMalloc(a)
|
|
|
-#define strdup(s) ((char *) mg_strdup(mg_str(s)).buf)
|
|
|
+#define strdup(s) mg_mprintf("%s", s)
|
|
|
|
|
|
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
|
|
|
static inline void *mg_calloc(size_t cnt, size_t size) {
|
|
|
@@ -288,7 +288,7 @@ extern uint32_t rt_time_get(void);
|
|
|
#include "cmsis_os2.h" // keep this include
|
|
|
#endif
|
|
|
|
|
|
-#define strdup(s) ((char *) mg_strdup(mg_str(s)).buf)
|
|
|
+#define strdup(s) mg_mprintf("%s", s)
|
|
|
|
|
|
#if defined(__ARMCC_VERSION)
|
|
|
#define mode_t size_t
|
|
|
@@ -549,6 +549,7 @@ int sscanf(const char *, const char *, ...);
|
|
|
|
|
|
#include <FreeRTOS_IP.h>
|
|
|
#include <FreeRTOS_Sockets.h>
|
|
|
+#include <FreeRTOS_errno_TCP.h> // contents to be moved and file removed, some day
|
|
|
|
|
|
#define MG_SOCKET_TYPE Socket_t
|
|
|
#define MG_INVALID_SOCKET FREERTOS_INVALID_SOCKET
|
|
|
@@ -580,7 +581,6 @@ int sscanf(const char *, const char *, ...);
|
|
|
|
|
|
#define sockaddr_in freertos_sockaddr
|
|
|
#define sockaddr freertos_sockaddr
|
|
|
-#define sin_addr sin_address.ulIP_IPv4
|
|
|
#define accept(a, b, c) FreeRTOS_accept((a), (b), (c))
|
|
|
#define connect(a, b, c) FreeRTOS_connect((a), (b), (c))
|
|
|
#define bind(a, b, c) FreeRTOS_bind((a), (b), (c))
|
|
|
@@ -707,7 +707,7 @@ struct timeval {
|
|
|
#endif
|
|
|
|
|
|
#ifndef MG_ENABLE_IPV6
|
|
|
-#define MG_ENABLE_IPV6 0
|
|
|
+#define MG_ENABLE_IPV6 1
|
|
|
#endif
|
|
|
|
|
|
#ifndef MG_IPV6_V6ONLY
|
|
|
@@ -861,7 +861,6 @@ struct mg_str mg_str_n(const char *s, size_t n);
|
|
|
int mg_casecmp(const char *s1, const char *s2);
|
|
|
int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
|
|
|
int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2);
|
|
|
-struct mg_str mg_strdup(const struct mg_str s);
|
|
|
bool mg_match(struct mg_str str, struct mg_str pattern, struct mg_str *caps);
|
|
|
bool mg_span(struct mg_str s, struct mg_str *a, struct mg_str *b, char delim);
|
|
|
|
|
|
@@ -1052,6 +1051,7 @@ uint16_t mg_ntohs(uint16_t net);
|
|
|
uint32_t mg_ntohl(uint32_t net);
|
|
|
uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len);
|
|
|
uint64_t mg_millis(void); // Return milliseconds since boot
|
|
|
+uint64_t mg_now(void); // Return milliseconds since Epoch
|
|
|
bool mg_path_is_sane(const struct mg_str path);
|
|
|
|
|
|
#define mg_htons(x) mg_ntohs(x)
|
|
|
@@ -1935,116 +1935,6 @@ typedef uint64_t mg_uecc_word_t;
|
|
|
|
|
|
#endif /* _UECC_TYPES_H_ */
|
|
|
// End of uecc BSD-2
|
|
|
-// portable8439 v1.0.1
|
|
|
-// Source: https://github.com/DavyLandman/portable8439
|
|
|
-// Licensed under CC0-1.0
|
|
|
-// Contains poly1305-donna e6ad6e091d30d7f4ec2d4f978be1fcfcbce72781 (Public
|
|
|
-// Domain)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-#ifndef __PORTABLE_8439_H
|
|
|
-#define __PORTABLE_8439_H
|
|
|
-#if defined(__cplusplus)
|
|
|
-extern "C" {
|
|
|
-#endif
|
|
|
-
|
|
|
-// provide your own decl specificier like -DPORTABLE_8439_DECL=ICACHE_RAM_ATTR
|
|
|
-#ifndef PORTABLE_8439_DECL
|
|
|
-#define PORTABLE_8439_DECL
|
|
|
-#endif
|
|
|
-
|
|
|
-/*
|
|
|
- This library implements RFC 8439 a.k.a. ChaCha20-Poly1305 AEAD
|
|
|
-
|
|
|
- You can use this library to avoid attackers mutating or reusing your
|
|
|
- encrypted messages. This does assume you never reuse a nonce+key pair and,
|
|
|
- if possible, carefully pick your associated data.
|
|
|
-*/
|
|
|
-
|
|
|
-// Make sure we are either nested in C++ or running in a C99+ compiler
|
|
|
-#if !defined(__cplusplus) && !defined(_MSC_VER) && \
|
|
|
- (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
|
|
|
-#error "C99 or newer required"
|
|
|
-#endif
|
|
|
-
|
|
|
-// #if CHAR_BIT > 8
|
|
|
-// # error "Systems without native octals not suppoted"
|
|
|
-// #endif
|
|
|
-
|
|
|
-#if defined(_MSC_VER) || defined(__cplusplus)
|
|
|
-// add restrict support is possible
|
|
|
-#if (defined(_MSC_VER) && _MSC_VER >= 1900) || defined(__clang__) || \
|
|
|
- defined(__GNUC__)
|
|
|
-#define restrict __restrict
|
|
|
-#else
|
|
|
-#define restrict
|
|
|
-#endif
|
|
|
-#endif
|
|
|
-
|
|
|
-#define RFC_8439_TAG_SIZE (16)
|
|
|
-#define RFC_8439_KEY_SIZE (32)
|
|
|
-#define RFC_8439_NONCE_SIZE (12)
|
|
|
-
|
|
|
-/*
|
|
|
- Encrypt/Seal plain text bytes into a cipher text that can only be
|
|
|
- decrypted by knowing the key, nonce and associated data.
|
|
|
-
|
|
|
- input:
|
|
|
- - key: RFC_8439_KEY_SIZE bytes that all parties have agreed
|
|
|
- upon beforehand
|
|
|
- - nonce: RFC_8439_NONCE_SIZE bytes that should never be repeated
|
|
|
- for the same key. A counter or a pseudo-random value are fine.
|
|
|
- - ad: associated data to include with calculating the tag of the
|
|
|
- cipher text. Can be null for empty.
|
|
|
- - plain_text: data to be encrypted, pointer + size should not overlap
|
|
|
- with cipher_text pointer
|
|
|
-
|
|
|
- output:
|
|
|
- - cipher_text: encrypted plain_text with a tag appended. Make sure to
|
|
|
- allocate at least plain_text_size + RFC_8439_TAG_SIZE
|
|
|
-
|
|
|
- returns:
|
|
|
- - size of bytes written to cipher_text, can be -1 if overlapping
|
|
|
- pointers are passed for plain_text and cipher_text
|
|
|
-*/
|
|
|
-PORTABLE_8439_DECL size_t mg_chacha20_poly1305_encrypt(
|
|
|
- uint8_t *restrict cipher_text, const uint8_t key[RFC_8439_KEY_SIZE],
|
|
|
- const uint8_t nonce[RFC_8439_NONCE_SIZE], const uint8_t *restrict ad,
|
|
|
- size_t ad_size, const uint8_t *restrict plain_text, size_t plain_text_size);
|
|
|
-
|
|
|
-/*
|
|
|
- Decrypt/unseal cipher text given the right key, nonce, and additional data.
|
|
|
-
|
|
|
- input:
|
|
|
- - key: RFC_8439_KEY_SIZE bytes that all parties have agreed
|
|
|
- upon beforehand
|
|
|
- - nonce: RFC_8439_NONCE_SIZE bytes that should never be repeated for
|
|
|
- the same key. A counter or a pseudo-random value are fine.
|
|
|
- - ad: associated data to include with calculating the tag of the
|
|
|
- cipher text. Can be null for empty.
|
|
|
- - cipher_text: encrypted message.
|
|
|
-
|
|
|
- output:
|
|
|
- - plain_text: data to be encrypted, pointer + size should not overlap
|
|
|
- with cipher_text pointer, leave at least enough room for
|
|
|
- cipher_text_size - RFC_8439_TAG_SIZE
|
|
|
-
|
|
|
- returns:
|
|
|
- - size of bytes written to plain_text, -1 signals either:
|
|
|
- - incorrect key/nonce/ad
|
|
|
- - corrupted cipher_text
|
|
|
- - overlapping pointers are passed for plain_text and cipher_text
|
|
|
-*/
|
|
|
-PORTABLE_8439_DECL size_t mg_chacha20_poly1305_decrypt(
|
|
|
- uint8_t *restrict plain_text, const uint8_t key[RFC_8439_KEY_SIZE],
|
|
|
- const uint8_t nonce[RFC_8439_NONCE_SIZE],
|
|
|
- const uint8_t *restrict cipher_text, size_t cipher_text_size);
|
|
|
-#if defined(__cplusplus)
|
|
|
-}
|
|
|
-#endif
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
struct mg_connection;
|
|
|
@@ -2265,7 +2155,7 @@ void mg_http_serve_ssi(struct mg_connection *c, const char *root,
|
|
|
#define MG_TLS_CUSTOM 4 // Custom implementation
|
|
|
|
|
|
#ifndef MG_TLS
|
|
|
-#define MG_TLS MG_TLS_BUILTIN
|
|
|
+#define MG_TLS MG_TLS_OPENSSL
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@@ -2375,8 +2265,6 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url,
|
|
|
void mg_sntp_request(struct mg_connection *c);
|
|
|
int64_t mg_sntp_parse(const unsigned char *buf, size_t len);
|
|
|
|
|
|
-uint64_t mg_now(void); // Return milliseconds since Epoch
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2683,16 +2571,6 @@ struct mg_tcpip_driver {
|
|
|
bool (*up)(struct mg_tcpip_if *); // Up/down status
|
|
|
};
|
|
|
|
|
|
-typedef void (*mg_tcpip_event_handler_t)(struct mg_tcpip_if *ifp, int ev,
|
|
|
- void *ev_data);
|
|
|
-
|
|
|
-enum {
|
|
|
- MG_TCPIP_EV_ST_CHG, // state change uint8_t * (&ifp->state)
|
|
|
- MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr
|
|
|
- MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr
|
|
|
- MG_TCPIP_EV_USER // Starting ID for user events
|
|
|
-};
|
|
|
-
|
|
|
// Network interface
|
|
|
struct mg_tcpip_if {
|
|
|
uint8_t mac[6]; // MAC address. Must be set to a valid MAC
|
|
|
@@ -2701,13 +2579,10 @@ struct mg_tcpip_if {
|
|
|
bool enable_dhcp_client; // Enable DCHP client
|
|
|
bool enable_dhcp_server; // Enable DCHP server
|
|
|
bool enable_get_gateway; // DCHP server sets client as gateway
|
|
|
- bool enable_req_dns; // DCHP client requests DNS server
|
|
|
- bool enable_req_sntp; // DCHP client requests SNTP server
|
|
|
bool enable_crc32_check; // Do a CRC check on RX frames and strip it
|
|
|
bool enable_mac_check; // Do a MAC check on RX frames
|
|
|
struct mg_tcpip_driver *driver; // Low level driver
|
|
|
void *driver_data; // Driver-specific data
|
|
|
- mg_tcpip_event_handler_t fn; // User-specified event handler function
|
|
|
struct mg_mgr *mgr; // Mongoose event manager
|
|
|
struct mg_queue recv_queue; // Receive queue
|
|
|
uint16_t mtu; // Interface MTU
|
|
|
@@ -2977,14 +2852,8 @@ struct mg_tcpip_driver_stm32f_data {
|
|
|
#endif
|
|
|
|
|
|
|
|
|
-#if MG_ENABLE_TCPIP
|
|
|
-#if !defined(MG_ENABLE_DRIVER_STM32H)
|
|
|
-#define MG_ENABLE_DRIVER_STM32H 0
|
|
|
-#endif
|
|
|
-#if !defined(MG_ENABLE_DRIVER_MCXN)
|
|
|
-#define MG_ENABLE_DRIVER_MCXN 0
|
|
|
-#endif
|
|
|
-#if MG_ENABLE_DRIVER_STM32H || MG_ENABLE_DRIVER_MCXN
|
|
|
+#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_STM32H) && \
|
|
|
+ MG_ENABLE_DRIVER_STM32H
|
|
|
|
|
|
struct mg_tcpip_driver_stm32h_data {
|
|
|
// MDC clock divider. MDC clock is derived from HCLK, must not exceed 2.5MHz
|
|
|
@@ -2997,8 +2866,7 @@ struct mg_tcpip_driver_stm32h_data {
|
|
|
// 35-60 MHz HCLK/26 3
|
|
|
// 150-250 MHz HCLK/102 4 <-- value for max speed HSI
|
|
|
// 250-300 MHz HCLK/124 5 <-- value for Nucleo-H* on CSI
|
|
|
- // 300-500 MHz HCLK/204 6
|
|
|
- // 500-800 MHz HCLK/324 7
|
|
|
+ // 110, 111 Reserved
|
|
|
int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5
|
|
|
|
|
|
uint8_t phy_addr; // PHY address
|
|
|
@@ -3030,7 +2898,6 @@ struct mg_tcpip_driver_stm32h_data {
|
|
|
} while (0)
|
|
|
|
|
|
#endif
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_TM4C) && MG_ENABLE_DRIVER_TM4C
|
|
|
@@ -3057,6 +2924,9 @@ struct mg_tcpip_driver_tm4c_data {
|
|
|
|
|
|
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_W5500) && MG_ENABLE_DRIVER_W5500
|
|
|
|
|
|
+#undef MG_ENABLE_TCPIP_DRIVER_INIT
|
|
|
+#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
|
|
+
|
|
|
#endif
|
|
|
|
|
|
|