Commit 7b05d700 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

CS_P_ESP_LWIP -> CS_P_ESP8266;add CS_P_NXP_KINETIS

LWIP part has been finally fully split from the ESP part, and ESP
platform defs reduced to bare minimum. It is now possible to use LWIP
in either low-level or socket mode without any ESP dependencies,
and NXP Kinetis platform is the first to make use of it.

PUBLISHED_FROM=4a9055897609c812296bdab5b4943ffde641ced2
parent f328907d
...@@ -5,6 +5,5 @@ title: Platform specific ...@@ -5,6 +5,5 @@ title: Platform specific
Mongoose tries to detect the target platform whenever possible, but in some cases you have Mongoose tries to detect the target platform whenever possible, but in some cases you have
to explicitly declare some peculiarities of your target, such as: to explicitly declare some peculiarities of your target, such as:
- `MG_LWIP`: use LWIP networking stack
- `MG_CC3200`: enable workarounds for the TI CC3200 target. - `MG_CC3200`: enable workarounds for the TI CC3200 target.
- `MG_ESP8266`: enable workarounds for the ESP8266 target, add `RTOS_SDK` to specify the RTOS SDK flavour. - `MG_ESP8266`: enable workarounds for the ESP8266 target, add `RTOS_SDK` to specify the RTOS SDK flavour.
...@@ -25,7 +25,7 @@ endif ...@@ -25,7 +25,7 @@ endif
# #
DEFINES += -DCS_PLATFORM=3 \ DEFINES += -DCS_PLATFORM=3 \
-DMG_NO_BSD_SOCKETS=1 \ -DMG_NO_BSD_SOCKETS=1 \
-DRTOS_SDK -DMG_LWIP -DLWIP_TIMEVAL_PRIVATE=0 \ -DRTOS_SDK \
-DMG_INTERNAL= -DMG_INTERNAL=
############################################################# #############################################################
......
...@@ -2976,12 +2976,12 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int type, ...@@ -2976,12 +2976,12 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int type,
socklen_t sa_len = socklen_t sa_len =
(sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6); (sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6);
sock_t sock = INVALID_SOCKET; sock_t sock = INVALID_SOCKET;
#if !defined(MG_LWIP) #if !MG_LWIP
int on = 1; int on = 1;
#endif #endif
if ((sock = socket(sa->sa.sa_family, type, proto)) != INVALID_SOCKET && if ((sock = socket(sa->sa.sa_family, type, proto)) != INVALID_SOCKET &&
#if !defined(MG_LWIP) /* LWIP doesn't support either */ #if !MG_LWIP /* LWIP doesn't support either */
#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE)
/* "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" http://goo.gl/RmrFTm */ /* "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" http://goo.gl/RmrFTm */
!setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on, !setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on,
...@@ -3004,7 +3004,7 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int type, ...@@ -3004,7 +3004,7 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int type,
!bind(sock, &sa->sa, sa_len) && !bind(sock, &sa->sa, sa_len) &&
(type == SOCK_DGRAM || listen(sock, SOMAXCONN) == 0)) { (type == SOCK_DGRAM || listen(sock, SOMAXCONN) == 0)) {
#if !defined(MG_LWIP) #if !MG_LWIP
mg_set_non_blocking_mode(sock); mg_set_non_blocking_mode(sock);
/* In case port was set to 0, get the real port number */ /* In case port was set to 0, get the real port number */
(void) getsockname(sock, &sa->sa, &sa_len); (void) getsockname(sock, &sa->sa, &sa_len);
...@@ -3021,7 +3021,7 @@ static void mg_write_to_socket(struct mg_connection *nc) { ...@@ -3021,7 +3021,7 @@ static void mg_write_to_socket(struct mg_connection *nc) {
struct mbuf *io = &nc->send_mbuf; struct mbuf *io = &nc->send_mbuf;
int n = 0; int n = 0;
#ifdef MG_LWIP #if MG_LWIP
/* With LWIP we don't know if the socket is ready */ /* With LWIP we don't know if the socket is ready */
if (io->len == 0) return; if (io->len == 0) return;
#endif #endif
...@@ -3440,7 +3440,7 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) { ...@@ -3440,7 +3440,7 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
(FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) | (FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) |
(FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0); (FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0);
} }
#ifdef MG_LWIP #if MG_LWIP
/* With LWIP socket emulation layer, we don't get write events */ /* With LWIP socket emulation layer, we don't get write events */
fd_flags |= _MG_F_FD_CAN_WRITE; fd_flags |= _MG_F_FD_CAN_WRITE;
#endif #endif
...@@ -7813,7 +7813,7 @@ void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, ...@@ -7813,7 +7813,7 @@ void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
if (inet_ntop(sa->sa.sa_family, addr, start, capacity) == NULL) { if (inet_ntop(sa->sa.sa_family, addr, start, capacity) == NULL) {
*buf = '\0'; *buf = '\0';
} }
#elif defined(_WIN32) || defined(MG_LWIP) #elif defined(_WIN32) || MG_LWIP
/* Only Windoze Vista (and newer) have inet_ntop() */ /* Only Windoze Vista (and newer) have inet_ntop() */
strncpy(buf, inet_ntoa(sa->sin.sin_addr), len); strncpy(buf, inet_ntoa(sa->sin.sin_addr), len);
#else #else
...@@ -11331,6 +11331,7 @@ void mg_lwip_ssl_do_hs(struct mg_connection *nc); ...@@ -11331,6 +11331,7 @@ void mg_lwip_ssl_do_hs(struct mg_connection *nc);
void mg_lwip_ssl_send(struct mg_connection *nc); void mg_lwip_ssl_send(struct mg_connection *nc);
void mg_lwip_ssl_recv(struct mg_connection *nc); void mg_lwip_ssl_recv(struct mg_connection *nc);
#if LWIP_TCP_KEEPALIVE
void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle, void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
int interval, int count) { int interval, int count) {
if (nc->sock == INVALID_SOCKET || nc->flags & MG_F_UDP) { if (nc->sock == INVALID_SOCKET || nc->flags & MG_F_UDP) {
...@@ -11347,6 +11348,9 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle, ...@@ -11347,6 +11348,9 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
tpcb->so_options &= ~SOF_KEEPALIVE; tpcb->so_options &= ~SOF_KEEPALIVE;
} }
} }
#elif !defined(MG_NO_LWIP_TCP_KEEPALIVE)
#warning LWIP TCP keepalive is disabled. Please consider enabling it.
#endif /* LWIP_TCP_KEEPALIVE */
static err_t mg_lwip_tcp_conn_cb(void *arg, struct tcp_pcb *tpcb, err_t err) { static err_t mg_lwip_tcp_conn_cb(void *arg, struct tcp_pcb *tpcb, err_t err) {
struct mg_connection *nc = (struct mg_connection *) arg; struct mg_connection *nc = (struct mg_connection *) arg;
...@@ -11358,7 +11362,9 @@ static err_t mg_lwip_tcp_conn_cb(void *arg, struct tcp_pcb *tpcb, err_t err) { ...@@ -11358,7 +11362,9 @@ static err_t mg_lwip_tcp_conn_cb(void *arg, struct tcp_pcb *tpcb, err_t err) {
} }
struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock; struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
cs->err = err; cs->err = err;
#if LWIP_TCP_KEEPALIVE
if (err == 0) mg_lwip_set_keepalive_params(nc, 60, 10, 6); if (err == 0) mg_lwip_set_keepalive_params(nc, 60, 10, 6);
#endif
#ifdef SSL_KRYPTON #ifdef SSL_KRYPTON
if (err == 0 && nc->ssl != NULL) { if (err == 0 && nc->ssl != NULL) {
SSL_set_fd(nc->ssl, (intptr_t) nc); SSL_set_fd(nc->ssl, (intptr_t) nc);
...@@ -11559,7 +11565,9 @@ static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) { ...@@ -11559,7 +11565,9 @@ static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) {
tcp_err(newtpcb, mg_lwip_tcp_error_cb); tcp_err(newtpcb, mg_lwip_tcp_error_cb);
tcp_sent(newtpcb, mg_lwip_tcp_sent_cb); tcp_sent(newtpcb, mg_lwip_tcp_sent_cb);
tcp_recv(newtpcb, mg_lwip_tcp_recv_cb); tcp_recv(newtpcb, mg_lwip_tcp_recv_cb);
#if LWIP_TCP_KEEPALIVE
mg_lwip_set_keepalive_params(nc, 60, 10, 6); mg_lwip_set_keepalive_params(nc, 60, 10, 6);
#endif
#ifdef SSL_KRYPTON #ifdef SSL_KRYPTON
if (lc->ssl_ctx != NULL) { if (lc->ssl_ctx != NULL) {
nc->ssl = SSL_new(lc->ssl_ctx); nc->ssl = SSL_new(lc->ssl_ctx);
......
...@@ -44,12 +44,13 @@ ...@@ -44,12 +44,13 @@
#define CS_P_CUSTOM 0 #define CS_P_CUSTOM 0
#define CS_P_UNIX 1 #define CS_P_UNIX 1
#define CS_P_WINDOWS 2 #define CS_P_WINDOWS 2
#define CS_P_ESP_LWIP 3 #define CS_P_ESP8266 3
#define CS_P_CC3200 4 #define CS_P_CC3200 4
#define CS_P_MSP432 5 #define CS_P_MSP432 5
#define CS_P_CC3100 6 #define CS_P_CC3100 6
#define CS_P_MBED 7 #define CS_P_MBED 7
#define CS_P_WINCE 8 #define CS_P_WINCE 8
#define CS_P_NXP_KINETIS 9
/* If not specified explicitly, we guess platform by defines. */ /* If not specified explicitly, we guess platform by defines. */
#ifndef CS_PLATFORM #ifndef CS_PLATFORM
...@@ -67,6 +68,8 @@ ...@@ -67,6 +68,8 @@
#define CS_PLATFORM CS_P_WINDOWS #define CS_PLATFORM CS_P_WINDOWS
#elif defined(__MBED__) #elif defined(__MBED__)
#define CS_PLATFORM CS_P_MBED #define CS_PLATFORM CS_P_MBED
#elif defined(FRDM_K64F) || defined(FREEDOM)
#define CS_PLATFORM CS_P_NXP_KINETIS
#endif #endif
#ifndef CS_PLATFORM #ifndef CS_PLATFORM
...@@ -81,11 +84,12 @@ ...@@ -81,11 +84,12 @@
/* Amalgamated: #include "common/platforms/platform_unix.h" */ /* Amalgamated: #include "common/platforms/platform_unix.h" */
/* Amalgamated: #include "common/platforms/platform_windows.h" */ /* Amalgamated: #include "common/platforms/platform_windows.h" */
/* Amalgamated: #include "common/platforms/platform_esp_lwip.h" */ /* Amalgamated: #include "common/platforms/platform_esp8266.h" */
/* Amalgamated: #include "common/platforms/platform_cc3200.h" */ /* Amalgamated: #include "common/platforms/platform_cc3200.h" */
/* Amalgamated: #include "common/platforms/platform_cc3100.h" */ /* Amalgamated: #include "common/platforms/platform_cc3100.h" */
/* Amalgamated: #include "common/platforms/platform_mbed.h" */ /* Amalgamated: #include "common/platforms/platform_mbed.h" */
/* Amalgamated: #include "common/platforms/platform_wince.h" */ /* Amalgamated: #include "common/platforms/platform_wince.h" */
/* Amalgamated: #include "common/platforms/platform_nxp_kinetis.h" */
/* Common stuff */ /* Common stuff */
...@@ -407,46 +411,26 @@ typedef struct stat cs_stat_t; ...@@ -407,46 +411,26 @@ typedef struct stat cs_stat_t;
#endif /* CS_PLATFORM == CS_P_UNIX */ #endif /* CS_PLATFORM == CS_P_UNIX */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_ */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
#line 1 "common/platforms/platform_esp_lwip.h" #line 1 "common/platforms/platform_esp8266.h"
#endif #endif
#ifndef CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_ /*
#define CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_ * Copyright (c) 2014-2016 Cesanta Software Limited
#if CS_PLATFORM == CS_P_ESP_LWIP * All rights reserved
*/
#ifndef CS_COMMON_PLATFORMS_PLATFORM_ESP8266_H_
#define CS_COMMON_PLATFORMS_PLATFORM_ESP8266_H_
#if CS_PLATFORM == CS_P_ESP8266
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <fcntl.h> #include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
#include <machine/endian.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <lwip/err.h>
#include <lwip/ip_addr.h>
#include <lwip/inet.h>
#include <lwip/netdb.h>
#include <lwip/dns.h>
#ifndef LWIP_PROVIDE_ERRNO
#include <errno.h>
#endif
#define LWIP_TIMEVAL_PRIVATE 0
#if LWIP_SOCKET
#include <lwip/sockets.h>
#define SOMAXCONN 10
#else
/* We really need the definitions from sockets.h. */
#undef LWIP_SOCKET
#define LWIP_SOCKET 1
#include <lwip/sockets.h>
#undef LWIP_SOCKET
#define LWIP_SOCKET 0
#endif
typedef int sock_t;
#define INVALID_SOCKET (-1)
#define SIZE_T_FMT "u" #define SIZE_T_FMT "u"
typedef struct stat cs_stat_t; typedef struct stat cs_stat_t;
#define DIRSEP '/' #define DIRSEP '/'
...@@ -456,26 +440,23 @@ typedef struct stat cs_stat_t; ...@@ -456,26 +440,23 @@ typedef struct stat cs_stat_t;
#define __cdecl #define __cdecl
#define _FILE_OFFSET_BITS 32 #define _FILE_OFFSET_BITS 32
unsigned long os_random(void); #define MG_LWIP 1
#define random os_random
#ifndef RTOS_SDK #ifdef RTOS_SDK
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL # define MG_NET_IF MG_NET_IF_SOCKET
struct mg_mgr;
struct mg_connection;
uint32_t mg_lwip_get_poll_delay_ms(struct mg_mgr *mgr);
void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
int interval, int count);
#else #else
#define MG_NET_IF MG_NET_IF_SOCKET # define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
#endif #endif
/* struct timeval is defined in sys/time.h. */
#define LWIP_TIMEVAL_PRIVATE 0
#ifndef CS_ENABLE_STDIO #ifndef CS_ENABLE_STDIO
#define CS_ENABLE_STDIO 1 #define CS_ENABLE_STDIO 1
#endif #endif
#endif /* CS_PLATFORM == CS_P_ESP_LWIP */ #endif /* CS_PLATFORM == CS_P_ESP8266 */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_ */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_ESP8266_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
#line 1 "common/platforms/platform_cc3100.h" #line 1 "common/platforms/platform_cc3100.h"
#endif #endif
...@@ -1074,6 +1055,94 @@ const char *strerror(); ...@@ -1074,6 +1055,94 @@ const char *strerror();
#endif /* CS_PLATFORM == CS_P_WINCE */ #endif /* CS_PLATFORM == CS_P_WINCE */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_WINCE_H_ */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_WINCE_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
#line 1 "common/platforms/platform_nxp_kinetis.h"
#endif
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_COMMON_PLATFORMS_PLATFORM_NXP_KINETIS_H_
#define CS_COMMON_PLATFORMS_PLATFORM_NXP_KINETIS_H_
#if CS_PLATFORM == CS_P_NXP_KINETIS
#include <ctype.h>
#include <inttypes.h>
#include <string.h>
#include <sys/time.h>
#define SIZE_T_FMT "u"
typedef struct stat cs_stat_t;
#define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT "lld"
#define INT64_X_FMT "llx"
#define __cdecl
#define MG_LWIP 1
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
/* struct timeval is defined in sys/time.h. */
#define LWIP_TIMEVAL_PRIVATE 0
#endif /* CS_PLATFORM == CS_P_NXP_KINETIS */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_NXP_KINETIS_H_ */
#ifdef MG_MODULE_LINES
#line 1 "common/platforms/lwip/mg_lwip.h"
#endif
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_COMMON_PLATFORMS_LWIP_MG_LWIP_H_
#define CS_COMMON_PLATFORMS_LWIP_MG_LWIP_H_
#ifndef MG_LWIP
#define MG_LWIP 0
#endif
#if MG_LWIP
#include <lwip/opt.h>
#include <lwip/err.h>
#include <lwip/ip_addr.h>
#include <lwip/inet.h>
#include <lwip/netdb.h>
#include <lwip/dns.h>
#ifndef LWIP_PROVIDE_ERRNO
#include <errno.h>
#endif
#if LWIP_SOCKET
# include <lwip/sockets.h>
#else
/* We really need the definitions from sockets.h. */
# undef LWIP_SOCKET
# define LWIP_SOCKET 1
# include <lwip/sockets.h>
# undef LWIP_SOCKET
# define LWIP_SOCKET 0
#endif
#define INVALID_SOCKET (-1)
#define SOMAXCONN 10
typedef int sock_t;
#if MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL
struct mg_mgr;
struct mg_connection;
uint32_t mg_lwip_get_poll_delay_ms(struct mg_mgr *mgr);
void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
int interval, int count);
#endif
#endif /* MG_LWIP */
#endif /* CS_COMMON_PLATFORMS_LWIP_MG_LWIP_H_ */
#ifdef MG_MODULE_LINES
#line 1 "common/cs_time.h" #line 1 "common/cs_time.h"
#endif #endif
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment