From 548ca04bbf246432bbf819c547ca60b6bdf237ac Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 11 May 2022 11:19:52 +0200 Subject: [PATCH 1/6] Define lwIP's s32/u32 to int s32/u32 were previously defined as long, but long can be 64 bits in host mode, so this commit reduces valgrind complaints and increase coherency. --- cores/esp8266/IPAddress.h | 13 ++----------- libraries/ESP8266WiFi/src/WiFiServer.cpp | 2 +- libraries/ESP8266WiFi/src/WiFiServer.h | 9 +++++---- tests/host/common/user_interface.cpp | 2 +- tools/sdk/lwip2/builder | 2 +- tools/sdk/lwip2/include/lwip-err-t.h | 4 ++-- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index c070118889..4a5cbbc8a1 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -69,7 +69,6 @@ class IPAddress: public Printable { IPAddress(const IPAddress& from); IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); IPAddress(uint32_t address) { ctor32(address); } - IPAddress(u32_t address) { ctor32(address); } IPAddress(int address) { ctor32(address); } IPAddress(const uint8_t *address); @@ -80,16 +79,14 @@ class IPAddress: public Printable { // to a four-byte uint8_t array is expected operator uint32_t() const { return isV4()? v4(): (uint32_t)0; } operator uint32_t() { return isV4()? v4(): (uint32_t)0; } - operator u32_t() const { return isV4()? v4(): (u32_t)0; } - operator u32_t() { return isV4()? v4(): (u32_t)0; } bool isSet () const; operator bool () const { return isSet(); } // <- operator bool () { return isSet(); } // <- both are needed // generic IPv4 wrapper to uint32-view like arduino loves to see it - const u32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const) - u32_t& v4() { return ip_2_ip4(&_ip)->addr; } + const uint32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const) + uint32_t& v4() { return ip_2_ip4(&_ip)->addr; } bool operator==(const IPAddress& addr) const { return ip_addr_cmp(&_ip, &addr._ip); @@ -100,15 +97,9 @@ class IPAddress: public Printable { bool operator==(uint32_t addr) const { return isV4() && v4() == addr; } - bool operator==(u32_t addr) const { - return isV4() && v4() == addr; - } bool operator!=(uint32_t addr) const { return !(isV4() && v4() == addr); } - bool operator!=(u32_t addr) const { - return !(isV4() && v4() == addr); - } bool operator==(const uint8_t* addr) const; int operator>>(int n) const { diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index bfe2377220..2ec0b00977 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -212,7 +212,7 @@ void WiFiServer::_discard(ClientContext* client) { DEBUGV("WS:dis\r\n"); } -long WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, long err) { +err_t WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, err_t err) { return reinterpret_cast(arg)->_accept(newpcb, err); } diff --git a/libraries/ESP8266WiFi/src/WiFiServer.h b/libraries/ESP8266WiFi/src/WiFiServer.h index 081a952bb3..891d193401 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.h +++ b/libraries/ESP8266WiFi/src/WiFiServer.h @@ -23,13 +23,14 @@ #define wifiserver_h extern "C" { - #include "wl_definitions.h" + #include struct tcp_pcb; } -#include "Server.h" -#include "IPAddress.h" +#include +#include +#include // lwIP-v2 backlog facility allows to keep memory safe by limiting the // maximum number of incoming *pending clients*. Default number of possibly @@ -106,7 +107,7 @@ class WiFiServer { long _accept(tcp_pcb* newpcb, long err); void _discard(ClientContext* client); - static long _s_accept(void *arg, tcp_pcb* newpcb, long err); + static err_t _s_accept(void *arg, tcp_pcb* newpcb, err_t err); static void _s_discard(void* server, ClientContext* ctx); }; diff --git a/tests/host/common/user_interface.cpp b/tests/host/common/user_interface.cpp index 05f90c704a..afb8ed3740 100644 --- a/tests/host/common/user_interface.cpp +++ b/tests/host/common/user_interface.cpp @@ -182,7 +182,7 @@ extern "C" { auto test_ipv4 = lwip_ntohl(*(uint32_t*)&((struct sockaddr_in*)ifa->ifa_addr)->sin_addr); - mockverbose(" IPV4 (0x%08lx)", test_ipv4); + mockverbose(" IPV4 (0x%08x)", test_ipv4); if ((test_ipv4 & 0xff000000) == 0x7f000000) // 127./8 mockverbose(" (local, ignored)"); diff --git a/tools/sdk/lwip2/builder b/tools/sdk/lwip2/builder index 450bb63c1b..3ab4b442b7 160000 --- a/tools/sdk/lwip2/builder +++ b/tools/sdk/lwip2/builder @@ -1 +1 @@ -Subproject commit 450bb63c1bc8b35770ca7f246945cf383569f52f +Subproject commit 3ab4b442b76f86e21ef068b1cb00eb1714679851 diff --git a/tools/sdk/lwip2/include/lwip-err-t.h b/tools/sdk/lwip2/include/lwip-err-t.h index d4a832ab20..e546e16b71 100644 --- a/tools/sdk/lwip2/include/lwip-err-t.h +++ b/tools/sdk/lwip2/include/lwip-err-t.h @@ -4,8 +4,8 @@ typedef unsigned char u8_t; typedef signed char s8_t; typedef unsigned short u16_t; typedef signed short s16_t; -typedef unsigned long u32_t; -typedef signed long s32_t; +typedef unsigned int u32_t; +typedef signed int s32_t; typedef unsigned long mem_ptr_t; #define LWIP_ERR_T s32_t typedef uint32_t sys_prot_t; From 53baec47a9934af2afdc63ad92f1441d78b5ab20 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 11 May 2022 12:19:16 +0200 Subject: [PATCH 2/6] some lads like to use `unsigned long` for 32 bits IPv4 addresses --- cores/esp8266/IPAddress.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index 4a5cbbc8a1..894d431c68 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -69,6 +69,7 @@ class IPAddress: public Printable { IPAddress(const IPAddress& from); IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); IPAddress(uint32_t address) { ctor32(address); } + IPAddress(unsigned long address) { ctor32(address); } IPAddress(int address) { ctor32(address); } IPAddress(const uint8_t *address); @@ -97,9 +98,15 @@ class IPAddress: public Printable { bool operator==(uint32_t addr) const { return isV4() && v4() == addr; } + bool operator==(unsigned long addr) const { + return isV4() && v4() == (uint32_t)addr; + } bool operator!=(uint32_t addr) const { return !(isV4() && v4() == addr); } + bool operator!=(unsigned long addr) const { + return isV4() && v4() != (uint32_t)addr; + } bool operator==(const uint8_t* addr) const; int operator>>(int n) const { From 63885d45f6941319acf9785bfe8b3088020a5838 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 11 May 2022 16:08:48 +0200 Subject: [PATCH 3/6] fix lwIP's `sys_now()` return type --- tools/sdk/lwip2/builder | 2 +- tools/sdk/lwip2/include/arch/cc.h | 11 ++++++++++- tools/sdk/lwip2/include/arch/sys_arch.h | 5 ----- tools/sdk/lwip2/include/lwip-git-hash.h | 2 +- tools/sdk/lwip2/include/lwip/sys.h | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) delete mode 100644 tools/sdk/lwip2/include/arch/sys_arch.h diff --git a/tools/sdk/lwip2/builder b/tools/sdk/lwip2/builder index 3ab4b442b7..2fe97b6c40 160000 --- a/tools/sdk/lwip2/builder +++ b/tools/sdk/lwip2/builder @@ -1 +1 @@ -Subproject commit 3ab4b442b76f86e21ef068b1cb00eb1714679851 +Subproject commit 2fe97b6c402bbb4e913b6697daa6fb5d492b859c diff --git a/tools/sdk/lwip2/include/arch/cc.h b/tools/sdk/lwip2/include/arch/cc.h index 1b879c84cd..583ebcded2 100644 --- a/tools/sdk/lwip2/include/arch/cc.h +++ b/tools/sdk/lwip2/include/arch/cc.h @@ -85,7 +85,16 @@ typedef uint32_t sys_prot_t; /////////////////////////////// //// MISSING -#define sys_now millis // arduino wire millis() definition returns 32 bits like sys_now() does +// transparent wrapper for millis()'s return value type from ulong to u32 +#if __cplusplus +extern "C" { +#endif +extern unsigned long millis(); +inline __attribute__((always_inline)) u32_t sys_now () { return (u32_t)millis(); } +#if __cplusplus +} +#endif + #define LWIP_RAND r_rand // old lwip uses this useful undocumented function #define IPSTR "%d.%d.%d.%d" #define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ diff --git a/tools/sdk/lwip2/include/arch/sys_arch.h b/tools/sdk/lwip2/include/arch/sys_arch.h deleted file mode 100644 index abcf8afd02..0000000000 --- a/tools/sdk/lwip2/include/arch/sys_arch.h +++ /dev/null @@ -1,5 +0,0 @@ - -#ifndef MYSYSARCH_H -#define MYSYSARCH_H - -#endif // MYSYSARCH_H \ No newline at end of file diff --git a/tools/sdk/lwip2/include/lwip-git-hash.h b/tools/sdk/lwip2/include/lwip-git-hash.h index 96c8999789..13ece5f6f8 100644 --- a/tools/sdk/lwip2/include/lwip-git-hash.h +++ b/tools/sdk/lwip2/include/lwip-git-hash.h @@ -1,5 +1,5 @@ // generated by makefiles/make-lwip2-hash #ifndef LWIP_HASH_H #define LWIP_HASH_H -#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-58-g450bb63" +#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-60-g2fe97b6" #endif // LWIP_HASH_H diff --git a/tools/sdk/lwip2/include/lwip/sys.h b/tools/sdk/lwip2/include/lwip/sys.h index 168e465baa..e03e164aec 100644 --- a/tools/sdk/lwip2/include/lwip/sys.h +++ b/tools/sdk/lwip2/include/lwip/sys.h @@ -443,7 +443,7 @@ u32_t sys_jiffies(void); * Not implementing this function means you cannot use some modules (e.g. TCP * timestamps, internal timeouts for NO_SYS==1). */ -u32_t sys_now(void); +//u32_t sys_now(void); /* Critical Region Protection */ /* These functions must be implemented in the sys_arch.c file. From a1605d3b986acde3b6ee062f83eec91d589a86ac Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 12 May 2022 23:29:59 +0200 Subject: [PATCH 4/6] fix C declarations --- tools/sdk/lwip2/builder | 2 +- tools/sdk/lwip2/include/arch/cc.h | 8 ++++---- tools/sdk/lwip2/include/lwip-git-hash.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/sdk/lwip2/builder b/tools/sdk/lwip2/builder index 2fe97b6c40..679577b22f 160000 --- a/tools/sdk/lwip2/builder +++ b/tools/sdk/lwip2/builder @@ -1 +1 @@ -Subproject commit 2fe97b6c402bbb4e913b6697daa6fb5d492b859c +Subproject commit 679577b22f47e287d277606feed0d66ef865fbb8 diff --git a/tools/sdk/lwip2/include/arch/cc.h b/tools/sdk/lwip2/include/arch/cc.h index 583ebcded2..76335b6f8d 100644 --- a/tools/sdk/lwip2/include/arch/cc.h +++ b/tools/sdk/lwip2/include/arch/cc.h @@ -86,12 +86,12 @@ typedef uint32_t sys_prot_t; //// MISSING // transparent wrapper for millis()'s return value type from ulong to u32 -#if __cplusplus +#ifdef __cplusplus extern "C" { #endif -extern unsigned long millis(); -inline __attribute__((always_inline)) u32_t sys_now () { return (u32_t)millis(); } -#if __cplusplus +extern unsigned long millis(void); // arduino definition +inline __attribute__((always_inline)) u32_t sys_now (void) { return (u32_t)millis(); } +#ifdef __cplusplus } #endif diff --git a/tools/sdk/lwip2/include/lwip-git-hash.h b/tools/sdk/lwip2/include/lwip-git-hash.h index 13ece5f6f8..fe8698cbf2 100644 --- a/tools/sdk/lwip2/include/lwip-git-hash.h +++ b/tools/sdk/lwip2/include/lwip-git-hash.h @@ -1,5 +1,5 @@ // generated by makefiles/make-lwip2-hash #ifndef LWIP_HASH_H #define LWIP_HASH_H -#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-60-g2fe97b6" +#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-61-g679577b" #endif // LWIP_HASH_H From 61db936baa02a83d5828d2e6dda5e623db468830 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 15 May 2022 21:23:09 +0200 Subject: [PATCH 5/6] merge upstream (lwip2) update on sys_now() definition --- tools/sdk/lwip2/builder | 2 +- tools/sdk/lwip2/include/arch/cc.h | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/sdk/lwip2/builder b/tools/sdk/lwip2/builder index 679577b22f..66f84a603e 160000 --- a/tools/sdk/lwip2/builder +++ b/tools/sdk/lwip2/builder @@ -1 +1 @@ -Subproject commit 679577b22f47e287d277606feed0d66ef865fbb8 +Subproject commit 66f84a603ee3070467f119b5e2be5209ec22351f diff --git a/tools/sdk/lwip2/include/arch/cc.h b/tools/sdk/lwip2/include/arch/cc.h index 76335b6f8d..0b73cba842 100644 --- a/tools/sdk/lwip2/include/arch/cc.h +++ b/tools/sdk/lwip2/include/arch/cc.h @@ -85,16 +85,21 @@ typedef uint32_t sys_prot_t; /////////////////////////////// //// MISSING -// transparent wrapper for millis()'s return value type from ulong to u32 +// Arduino Core exposes time func with a generic type #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -extern unsigned long millis(void); // arduino definition -inline __attribute__((always_inline)) u32_t sys_now (void) { return (u32_t)millis(); } +unsigned long millis(void); #ifdef __cplusplus } #endif +// b/c we have conflicting typedefs of u32_t and ulong and can't substitute funcs, +// forcibly cast the `millis()` result to lwip's version of u32_t +// (previous version was `#define sys_now millis`) +#define sys_now() ((u32_t)millis()) + #define LWIP_RAND r_rand // old lwip uses this useful undocumented function #define IPSTR "%d.%d.%d.%d" #define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ From 62d0ef1d20ffeebbd0c2b8469959991b80817872 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 15 May 2022 21:27:07 +0200 Subject: [PATCH 6/6] matching lwIP api (2/2) --- libraries/ESP8266WiFi/src/WiFiServer.cpp | 2 +- libraries/ESP8266WiFi/src/WiFiServer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index 2ec0b00977..acc0528389 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -186,7 +186,7 @@ T* slist_append_tail(T* head, T* item) { return head; } -long WiFiServer::_accept(tcp_pcb* apcb, long err) { +err_t WiFiServer::_accept(tcp_pcb* apcb, err_t err) { (void) err; DEBUGV("WS:ac\r\n"); diff --git a/libraries/ESP8266WiFi/src/WiFiServer.h b/libraries/ESP8266WiFi/src/WiFiServer.h index 891d193401..03f32b24e1 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.h +++ b/libraries/ESP8266WiFi/src/WiFiServer.h @@ -104,7 +104,7 @@ class WiFiServer { using ClientType = WiFiClient; protected: - long _accept(tcp_pcb* newpcb, long err); + err_t _accept(tcp_pcb* newpcb, err_t err); void _discard(ClientContext* client); static err_t _s_accept(void *arg, tcp_pcb* newpcb, err_t err);